From 533310f646f1b1a00250a361f627967c420f1eef Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 29 Dec 2011 14:13:21 -0700 Subject: Situations & their modes are built. --- src/gamestate.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'src/gamestate.cpp') 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 ) { if( pAst->getType() != AstNode::tScope ) throw Bu::ExceptionBase("Nope, nothing doing, you can't parse a non-scope AstBranch."); + + lsLocal.push( new Scope() ); parse( pAst->getNodeList() ); + delete lsLocal.peekPop(); } void GameState::callFunction( const Bu::String &sName ) { - lsLocal.push( new Scope() ); pGame->getFunction( sName )->call( *this ); - delete lsLocal.peekPop(); +} + +Variable GameState::getVariable( const Bu::String &sName, ScopeId id ) +{ + switch( id ) + { + case sidLocal: + return lsLocal.peek()->get( sName ); + + case sidGlobal: + return sGlobal.get( sName ); + + case sidPlayer: + return sPlayer.get( sName ); + + case sidSituation: + return hsSituation.get( sCurSituation )->get( sName ); + } + + throw Bu::ExceptionBase("Really bad scopeid passed into getVariable"); +} + +void GameState::setVariable( const Bu::String &sName, const Variable &v, + ScopeId id ) +{ + switch( id ) + { + case sidLocal: + lsLocal.peek()->insert( sName, v ); + return; + + case sidGlobal: + sGlobal.insert( sName, v ); + return; + + case sidPlayer: + sPlayer.insert( sName, v ); + return; + + case sidSituation: + hsSituation.get( sCurSituation )->insert( sName, v ); + return; + } + + throw Bu::ExceptionBase("Really bad scopeid passed into setVariable"); } void GameState::parse( const AstBranch::NodeList &lCode ) -- cgit v1.2.3