diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-12-29 14:49:02 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-29 14:49:02 -0700 |
commit | 162ccd918698f53ef9ff7ba80091969d93aa789d (patch) | |
tree | b01d84a31a5fec69a07cdbef75fa777529dfacc7 /src/gamestate.cpp | |
parent | 533310f646f1b1a00250a361f627967c420f1eef (diff) | |
download | stage-162ccd918698f53ef9ff7ba80091969d93aa789d.tar.gz stage-162ccd918698f53ef9ff7ba80091969d93aa789d.tar.bz2 stage-162ccd918698f53ef9ff7ba80091969d93aa789d.tar.xz stage-162ccd918698f53ef9ff7ba80091969d93aa789d.zip |
Situation code actually processes now.
Most of the AstNode types are unhandled yet.
Diffstat (limited to 'src/gamestate.cpp')
-rw-r--r-- | src/gamestate.cpp | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 25b53b8..cd6414c 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp | |||
@@ -24,6 +24,28 @@ void GameState::parse( class AstBranch *pAst ) | |||
24 | delete lsLocal.peekPop(); | 24 | delete lsLocal.peekPop(); |
25 | } | 25 | } |
26 | 26 | ||
27 | void GameState::init() | ||
28 | { | ||
29 | Variable vStart = pGame->getParam("start"); | ||
30 | if( vStart.getType() != Variable::tSituation ) | ||
31 | throw Bu::ExceptionBase("game.start is not set to a situation name."); | ||
32 | |||
33 | gotoSituation( vStart.getString() ); | ||
34 | } | ||
35 | |||
36 | void GameState::gotoSituation( const Bu::String &sName ) | ||
37 | { | ||
38 | Situation *pSit = pGame->getSituation( sName ); | ||
39 | sCurSituation = sName; | ||
40 | if( !hsSituation.has( sName ) ) | ||
41 | { | ||
42 | hsSituation.insert( sName, new Scope() ); | ||
43 | pSit->exec( *this, Situation::modeSetup ); | ||
44 | } | ||
45 | |||
46 | pSit->exec( *this, Situation::modeEnter ); | ||
47 | } | ||
48 | |||
27 | void GameState::callFunction( const Bu::String &sName ) | 49 | void GameState::callFunction( const Bu::String &sName ) |
28 | { | 50 | { |
29 | pGame->getFunction( sName )->call( *this ); | 51 | pGame->getFunction( sName )->call( *this ); |
@@ -74,6 +96,21 @@ void GameState::setVariable( const Bu::String &sName, const Variable &v, | |||
74 | throw Bu::ExceptionBase("Really bad scopeid passed into setVariable"); | 96 | throw Bu::ExceptionBase("Really bad scopeid passed into setVariable"); |
75 | } | 97 | } |
76 | 98 | ||
99 | Variable GameState::deref( const Variable &src ) | ||
100 | { | ||
101 | if( src.getType() == Variable::tVariable ) | ||
102 | return getVariable( src.getString() ); | ||
103 | return src; | ||
104 | } | ||
105 | |||
106 | Variable GameState::popDeref() | ||
107 | { | ||
108 | Variable v = lStack.peekPop(); | ||
109 | if( v.getType() == Variable::tVariable ) | ||
110 | return getVariable( v.getString() ); | ||
111 | return v; | ||
112 | } | ||
113 | |||
77 | void GameState::parse( const AstBranch::NodeList &lCode ) | 114 | void GameState::parse( const AstBranch::NodeList &lCode ) |
78 | { | 115 | { |
79 | for( AstBranch::NodeList::const_iterator i = lCode.begin(); i; i++ ) | 116 | for( AstBranch::NodeList::const_iterator i = lCode.begin(); i; i++ ) |
@@ -88,9 +125,23 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
88 | case AstNode::tCompGtEq: | 125 | case AstNode::tCompGtEq: |
89 | case AstNode::tCompLtEq: | 126 | case AstNode::tCompLtEq: |
90 | case AstNode::tStore: | 127 | case AstNode::tStore: |
128 | { | ||
129 | Variable y = popDeref(); | ||
130 | Variable dst = pop(); | ||
131 | setVariable( dst.getString(), y ); | ||
132 | } | ||
133 | break; | ||
134 | |||
91 | case AstNode::tAnd: | 135 | case AstNode::tAnd: |
92 | case AstNode::tOr: | 136 | case AstNode::tOr: |
93 | case AstNode::tPlus: | 137 | case AstNode::tPlus: |
138 | { | ||
139 | Variable y = popDeref(); | ||
140 | Variable x = popDeref(); | ||
141 | lStack.push( x + y ); | ||
142 | } | ||
143 | break; | ||
144 | |||
94 | case AstNode::tMinus: | 145 | case AstNode::tMinus: |
95 | case AstNode::tDivide: | 146 | case AstNode::tDivide: |
96 | case AstNode::tMultiply: | 147 | case AstNode::tMultiply: |
@@ -103,9 +154,6 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
103 | 154 | ||
104 | // tLeafLiteral | 155 | // tLeafLiteral |
105 | case AstNode::tVarName: | 156 | case AstNode::tVarName: |
106 | lStack.push( dynamic_cast<const AstLeafLiteral *>(*i)->getValue() ); | ||
107 | break; | ||
108 | |||
109 | case AstNode::tLiteral: | 157 | case AstNode::tLiteral: |
110 | lStack.push( dynamic_cast<const AstLeafLiteral *>(*i)->getValue() ); | 158 | lStack.push( dynamic_cast<const AstLeafLiteral *>(*i)->getValue() ); |
111 | break; | 159 | break; |