diff options
Diffstat (limited to 'src/gamestate.cpp')
| -rw-r--r-- | src/gamestate.cpp | 50 | 
1 files changed, 48 insertions, 2 deletions
| diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 7649cac..25b53b8 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp | |||
| @@ -18,14 +18,60 @@ void GameState::parse( class AstBranch *pAst ) | |||
| 18 | { | 18 | { | 
| 19 | if( pAst->getType() != AstNode::tScope ) | 19 | if( pAst->getType() != AstNode::tScope ) | 
| 20 | throw Bu::ExceptionBase("Nope, nothing doing, you can't parse a non-scope AstBranch."); | 20 | throw Bu::ExceptionBase("Nope, nothing doing, you can't parse a non-scope AstBranch."); | 
| 21 | |||
| 22 | lsLocal.push( new Scope() ); | ||
| 21 | parse( pAst->getNodeList() ); | 23 | parse( pAst->getNodeList() ); | 
| 24 | delete lsLocal.peekPop(); | ||
| 22 | } | 25 | } | 
| 23 | 26 | ||
| 24 | void GameState::callFunction( const Bu::String &sName ) | 27 | void GameState::callFunction( const Bu::String &sName ) | 
| 25 | { | 28 | { | 
| 26 | lsLocal.push( new Scope() ); | ||
| 27 | pGame->getFunction( sName )->call( *this ); | 29 | pGame->getFunction( sName )->call( *this ); | 
| 28 | delete lsLocal.peekPop(); | 30 | } | 
| 31 | |||
| 32 | Variable GameState::getVariable( const Bu::String &sName, ScopeId id ) | ||
| 33 | { | ||
| 34 | switch( id ) | ||
| 35 | { | ||
| 36 | case sidLocal: | ||
| 37 | return lsLocal.peek()->get( sName ); | ||
| 38 | |||
| 39 | case sidGlobal: | ||
| 40 | return sGlobal.get( sName ); | ||
| 41 | |||
| 42 | case sidPlayer: | ||
| 43 | return sPlayer.get( sName ); | ||
| 44 | |||
| 45 | case sidSituation: | ||
| 46 | return hsSituation.get( sCurSituation )->get( sName ); | ||
| 47 | } | ||
| 48 | |||
| 49 | throw Bu::ExceptionBase("Really bad scopeid passed into getVariable"); | ||
| 50 | } | ||
| 51 | |||
| 52 | void GameState::setVariable( const Bu::String &sName, const Variable &v, | ||
| 53 | ScopeId id ) | ||
| 54 | { | ||
| 55 | switch( id ) | ||
| 56 | { | ||
| 57 | case sidLocal: | ||
| 58 | lsLocal.peek()->insert( sName, v ); | ||
| 59 | return; | ||
| 60 | |||
| 61 | case sidGlobal: | ||
| 62 | sGlobal.insert( sName, v ); | ||
| 63 | return; | ||
| 64 | |||
| 65 | case sidPlayer: | ||
| 66 | sPlayer.insert( sName, v ); | ||
| 67 | return; | ||
| 68 | |||
| 69 | case sidSituation: | ||
| 70 | hsSituation.get( sCurSituation )->insert( sName, v ); | ||
| 71 | return; | ||
| 72 | } | ||
| 73 | |||
| 74 | throw Bu::ExceptionBase("Really bad scopeid passed into setVariable"); | ||
| 29 | } | 75 | } | 
| 30 | 76 | ||
| 31 | void GameState::parse( const AstBranch::NodeList &lCode ) | 77 | void GameState::parse( const AstBranch::NodeList &lCode ) | 
