summaryrefslogtreecommitdiff
path: root/src/command.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/command.cpp')
-rw-r--r--src/command.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/command.cpp b/src/command.cpp
index e81d307..2def02f 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -1,6 +1,7 @@
1#include "command.h" 1#include "command.h"
2 2
3#include "astbranch.h" 3#include "astbranch.h"
4#include "gamestate.h"
4 5
5#include <bu/sio.h> 6#include <bu/sio.h>
6using namespace Bu; 7using namespace Bu;
@@ -25,6 +26,18 @@ void Command::addParam( const Bu::String &sValue )
25 lChunks.append( Chunk( false, sValue ) ); 26 lChunks.append( Chunk( false, sValue ) );
26} 27}
27 28
29Bu::StringList Command::getParamList() const
30{
31 Bu::StringList lRev;
32 for( ChunkList::const_iterator i = lChunks.begin(); i; i++ )
33 {
34 if( !(*i).bLiteral )
35 lRev.prepend( (*i).sValue );
36 }
37
38 return lRev;
39}
40
28void Command::setAst( class AstBranch *pAst ) 41void Command::setAst( class AstBranch *pAst )
29{ 42{
30 this->pAst = pAst; 43 this->pAst = pAst;
@@ -44,3 +57,39 @@ void Command::print()
44 sio << *pAst << sio.nl; 57 sio << *pAst << sio.nl;
45} 58}
46 59
60bool Command::matches( const Bu::StringList &lCmd )
61{
62 ChunkList::iterator iChunk = lChunks.begin();
63 Bu::StringList::const_iterator iCmd = lCmd.begin();
64
65 for( ; iChunk && iCmd; iChunk++, iCmd++ )
66 {
67 if( (*iChunk).bLiteral )
68 {
69 if( (*iChunk).sValue != *iCmd )
70 return false;
71 }
72 }
73
74 if( (bool)iChunk != (bool)iCmd )
75 return false;
76
77 return true;
78}
79
80void Command::exec( class GameState &gState, const Bu::StringList &lCmd )
81{
82 ChunkList::iterator iChunk = lChunks.begin();
83 Bu::StringList::const_iterator iCmd = lCmd.begin();
84
85 for( ; iChunk && iCmd; iChunk++, iCmd++ )
86 {
87 if( !(*iChunk).bLiteral )
88 {
89 gState.push( Variable( *iCmd ) );
90 }
91 }
92
93 gState.parse( pAst );
94}
95