summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--demo.stage28
-rw-r--r--src/functionjoin.cpp36
-rw-r--r--src/functionjoin.h16
-rw-r--r--src/functionkeys.cpp32
-rw-r--r--src/functionkeys.h16
-rw-r--r--src/functionstring.cpp17
-rw-r--r--src/functionstring.h16
-rw-r--r--src/game.cpp6
8 files changed, 146 insertions, 21 deletions
diff --git a/demo.stage b/demo.stage
index c644522..852deee 100644
--- a/demo.stage
+++ b/demo.stage
@@ -31,21 +31,10 @@ global
31 { 31 {
32 if exists(situation.exits) then 32 if exists(situation.exits) then
33 { 33 {
34 out = "Obvious exits are: "; 34 display( "Obvious exits are: " + join(
35 bFirst = true; 35 keys( situation.exits ),
36 for each dir : dest in situation.exits do 36 ", "
37 { 37 ) );
38 if bFirst then
39 {
40 bFirst = false;
41 }
42 else
43 {
44 out += ", ";
45 }
46 out += dir;
47 }
48 display( out );
49 } 38 }
50 else 39 else
51 { 40 {
@@ -77,17 +66,13 @@ global
77 */ 66 */
78 command: "inventory" 67 command: "inventory"
79 { 68 {
80 out = 'You are carrying: '; 69 out = 'You are carrying: ' + join( player.inventory, ", " );
81 for each item in player.inventory do
82 {
83 out += " " + item;
84 }
85 display( out ); 70 display( out );
86 } 71 }
87 72
88 // You should always have a global exit, quit, escape, something for 73 // You should always have a global exit, quit, escape, something for
89 // dev-testing at least. 74 // dev-testing at least.
90 command: "exit" 75 command: "quit"
91 { 76 {
92 exit(); 77 exit();
93 } 78 }
@@ -147,6 +132,7 @@ situation <<beachCenter>>
147 'east': <<beachEast>>, 132 'east': <<beachEast>>,
148 'west': <<beachWest>> 133 'west': <<beachWest>>
149 }; 134 };
135 situation.items = ['stick'];
150 } 136 }
151 enter 137 enter
152 { 138 {
diff --git a/src/functionjoin.cpp b/src/functionjoin.cpp
new file mode 100644
index 0000000..71ee879
--- /dev/null
+++ b/src/functionjoin.cpp
@@ -0,0 +1,36 @@
1#include "functionjoin.h"
2
3#include "gamestate.h"
4
5#include <bu/sio.h>
6using namespace Bu;
7
8FunctionJoin::FunctionJoin()
9{
10}
11
12FunctionJoin::~FunctionJoin()
13{
14}
15
16void FunctionJoin::call( class GameState &gState )
17{
18 Variable vSep = gState.popDeref().to( Variable::tString );
19 Variable vLst = gState.popDeref();
20
21 if( vLst.getType() != Variable::tList )
22 throw Bu::ExceptionBase("First parameter of join must be a list.");
23
24 Bu::String sOut;
25 for( Variable::VariableArray::const_iterator i = vLst.getList().begin();
26 i; i++ )
27 {
28 if( i != vLst.getList().begin() )
29 sOut += vSep.getString();
30 sOut += (*i).to( Variable::tString ).getString();
31 }
32
33
34 gState.push( sOut );
35}
36
diff --git a/src/functionjoin.h b/src/functionjoin.h
new file mode 100644
index 0000000..7c46e7f
--- /dev/null
+++ b/src/functionjoin.h
@@ -0,0 +1,16 @@
1#ifndef FUNCTION_JOIN_H
2#define FUNCTION_JOIN_H
3
4#include "function.h"
5
6class FunctionJoin : public Function
7{
8public:
9 FunctionJoin();
10 virtual ~FunctionJoin();
11
12 virtual Bu::String getName() const { return "join"; }
13 virtual void call( class GameState &gState );
14};
15
16#endif
diff --git a/src/functionkeys.cpp b/src/functionkeys.cpp
new file mode 100644
index 0000000..12c1098
--- /dev/null
+++ b/src/functionkeys.cpp
@@ -0,0 +1,32 @@
1#include "functionkeys.h"
2
3#include "gamestate.h"
4
5#include <bu/sio.h>
6using namespace Bu;
7
8FunctionKeys::FunctionKeys()
9{
10}
11
12FunctionKeys::~FunctionKeys()
13{
14}
15
16void FunctionKeys::call( class GameState &gState )
17{
18 Variable vDict = gState.popDeref();
19
20 if( vDict.getType() != Variable::tDictionary )
21 throw Bu::ExceptionBase("Parameter to keys must be a dictionary.");
22
23 Variable vLst( Variable::tList );
24 for( Variable::VariableHash::const_iterator i = vDict.getHash().begin();
25 i; i++ )
26 {
27 vLst += i.getKey();
28 }
29
30 gState.push( vLst );
31}
32
diff --git a/src/functionkeys.h b/src/functionkeys.h
new file mode 100644
index 0000000..ccc3bdd
--- /dev/null
+++ b/src/functionkeys.h
@@ -0,0 +1,16 @@
1#ifndef FUNCTION_KEYS_H
2#define FUNCTION_KEYS_H
3
4#include "function.h"
5
6class FunctionKeys : public Function
7{
8public:
9 FunctionKeys();
10 virtual ~FunctionKeys();
11
12 virtual Bu::String getName() const { return "keys"; }
13 virtual void call( class GameState &gState );
14};
15
16#endif
diff --git a/src/functionstring.cpp b/src/functionstring.cpp
new file mode 100644
index 0000000..ca5a3aa
--- /dev/null
+++ b/src/functionstring.cpp
@@ -0,0 +1,17 @@
1#include "functionstring.h"
2
3#include "gamestate.h"
4
5FunctionString::FunctionString()
6{
7}
8
9FunctionString::~FunctionString()
10{
11}
12
13void FunctionString::call( class GameState &gState )
14{
15 gState.push( gState.popDeref().to( Variable::tString ) );
16}
17
diff --git a/src/functionstring.h b/src/functionstring.h
new file mode 100644
index 0000000..36e4f51
--- /dev/null
+++ b/src/functionstring.h
@@ -0,0 +1,16 @@
1#ifndef FUNCTION_STRING_H
2#define FUNCTION_STRING_H
3
4#include "function.h"
5
6class FunctionString : public Function
7{
8public:
9 FunctionString();
10 virtual ~FunctionString();
11
12 virtual Bu::String getName() const { return "string"; }
13 virtual void call( class GameState &gState );
14};
15
16#endif
diff --git a/src/game.cpp b/src/game.cpp
index 4971c4b..37989bd 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -8,6 +8,9 @@
8#include "functioninteger.h" 8#include "functioninteger.h"
9#include "functionfloat.h" 9#include "functionfloat.h"
10#include "functiondebugstring.h" 10#include "functiondebugstring.h"
11#include "functionstring.h"
12#include "functionjoin.h"
13#include "functionkeys.h"
11 14
12Game::Game() 15Game::Game()
13{ 16{
@@ -20,6 +23,9 @@ Game::Game()
20 addFunction( new FunctionInteger() ); 23 addFunction( new FunctionInteger() );
21 addFunction( new FunctionFloat() ); 24 addFunction( new FunctionFloat() );
22 addFunction( new FunctionDebugString() ); 25 addFunction( new FunctionDebugString() );
26 addFunction( new FunctionString() );
27 addFunction( new FunctionJoin() );
28 addFunction( new FunctionKeys() );
23} 29}
24 30
25Game::~Game() 31Game::~Game()