summaryrefslogtreecommitdiff
path: root/src/gamestate.h
blob: 8ff92f5d26db8b0b17ab069eb3eee0d7484d74ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef GAME_STATE_H
#define GAME_STATE_H

#include "astbranch.h"
#include "variable.h"
#include "scope.h"
#include "enums.h"

class Game;
class Interface;

namespace Gats
{
	class Object;
	class Dictionary;
	class List;
}

class GameState
{
public:
	GameState( Game *pGame, Interface *pIface );
	virtual ~GameState();

	Gats::Dictionary *toGats() const;
	void fromGats( Gats::Dictionary *pRoot );

	Interface *getInterface() { return pIface; }

	void parse( class AstBranch *pAst );

	void init();

	void gotoSituation( const Bu::String &sName );

	Variable pop() { return lStack.peekPop(); }
	Variable popDeref();
	void push( const Variable &v ) { lStack.push( v ); }

	void callFunction( const Bu::String &sName );
	void execCommand( const Bu::String &sCmd );

	bool hasVariable( const Bu::String &sName, ScopeId id );
	void delVariable( const Bu::String &sName, ScopeId id );
	Variable &getVariable( const Bu::String &sName, ScopeId id=sidLocal );
	void setVariable( const Bu::String &sName, const Variable &v, ScopeId id=sidLocal );

	Variable &deref( Variable &src, bool bCreate=false );
	Bu::StringList tokenize( const Bu::String &sSrc );

	void exit();
	bool isRunning() const { return bRunning; }
	Bu::String getPrompt() const { return sPrompt; }

private:
	void parse( const AstBranch::NodeList &lCode );

	Gats::Object *scopeToGats( const Scope *pSrc ) const;
	Gats::Object *variableToGats( const Variable &rVar ) const;
	void gatsToScope( Gats::Dictionary *pRoot, Scope *pSrc ) const;
	Variable gatsToVariable( Gats::List *pLst ) const;

private:
	typedef Bu::List<Scope *> ScopeList;
	typedef Bu::Hash<Bu::String, Scope *> ScopeHash;
	Game *pGame;
	Interface *pIface;
	Scope sGlobal;
	Scope sPlayer;
	ScopeList lsLocal;
	ScopeHash hsSituation;
	Bu::String sCurSituation;

	bool bEscape;
	bool bRunning;
	bool bReturnOnly;
	Bu::String sPrompt;

	VariableList lStack;
};

#endif