diff options
Diffstat (limited to 'src/gamestate.cpp')
| -rw-r--r-- | src/gamestate.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/gamestate.cpp b/src/gamestate.cpp index a3758ce..fa014ac 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp | |||
| @@ -65,6 +65,19 @@ void GameState::callFunction( const Bu::String &sName ) | |||
| 65 | pGame->getFunction( sName )->call( *this ); | 65 | pGame->getFunction( sName )->call( *this ); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | void GameState::execCommand( const Bu::String &sCmd ) | ||
| 69 | { | ||
| 70 | Bu::StringList lCmd = tokenize( sCmd ); | ||
| 71 | |||
| 72 | if( !pGame->getSituation( sCurSituation )->execCommand( *this, lCmd ) ) | ||
| 73 | { | ||
| 74 | if( !pGame->execCommand( *this, lCmd ) ) | ||
| 75 | { | ||
| 76 | throw Bu::ExceptionBase("No such command exists."); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 68 | bool GameState::hasVariable( const Bu::String &sName, ScopeId id ) | 81 | bool GameState::hasVariable( const Bu::String &sName, ScopeId id ) |
| 69 | { | 82 | { |
| 70 | switch( id ) | 83 | switch( id ) |
| @@ -169,6 +182,39 @@ Variable GameState::deref( const Variable &src ) | |||
| 169 | return src; | 182 | return src; |
| 170 | } | 183 | } |
| 171 | 184 | ||
| 185 | Bu::StringList GameState::tokenize( const Bu::String &sSrc ) | ||
| 186 | { | ||
| 187 | Bu::StringList lRet; | ||
| 188 | Bu::String sToken; | ||
| 189 | bool bWs = true; | ||
| 190 | Bu::String::const_iterator i = sSrc.begin(); | ||
| 191 | |||
| 192 | while( i ) | ||
| 193 | { | ||
| 194 | for(; i; i++ ) | ||
| 195 | { | ||
| 196 | if( *i != ' ' && *i != '\t' && *i != '\n' && *i != '\r' ) | ||
| 197 | break; | ||
| 198 | } | ||
| 199 | for(; i; i++ ) | ||
| 200 | { | ||
| 201 | if( i == ' ' || i == '\t' || *i == '\n' || *i == '\r' ) | ||
| 202 | { | ||
| 203 | break; | ||
| 204 | } | ||
| 205 | |||
| 206 | sToken.append( *i ); | ||
| 207 | } | ||
| 208 | if( sToken.getSize() > 0 ) | ||
| 209 | { | ||
| 210 | lRet.append( sToken ); | ||
| 211 | sToken.clear(); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | return lRet; | ||
| 216 | } | ||
| 217 | |||
| 172 | Variable GameState::popDeref() | 218 | Variable GameState::popDeref() |
| 173 | { | 219 | { |
| 174 | Variable v = lStack.peekPop(); | 220 | Variable v = lStack.peekPop(); |
| @@ -245,6 +291,15 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
| 245 | setVariable( r.sName, y, r.sid ); | 291 | setVariable( r.sName, y, r.sid ); |
| 246 | } | 292 | } |
| 247 | break; | 293 | break; |
| 294 | |||
| 295 | case AstNode::tStoreRev: | ||
| 296 | { | ||
| 297 | Variable dst = pop(); | ||
| 298 | Variable y = popDeref(); | ||
| 299 | VariableRef r = dst.getVariableRef(); | ||
| 300 | setVariable( r.sName, y, r.sid ); | ||
| 301 | } | ||
| 302 | break; | ||
| 248 | 303 | ||
| 249 | case AstNode::tAnd: | 304 | case AstNode::tAnd: |
| 250 | { | 305 | { |
