summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-12-30 23:07:59 -0700
committerMike Buland <eichlan@xagasoft.com>2011-12-30 23:07:59 -0700
commit70076bb00bdedb57405ed2ef27e2fec172e2f38a (patch)
tree4339853d972427b02bb4d51a88bcb665ba61307a
parent8bcb83035607371a2326374665e9cc56c662a783 (diff)
downloadstage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.gz
stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.bz2
stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.tar.xz
stage-70076bb00bdedb57405ed2ef27e2fec172e2f38a.zip
Well, +=, -= on dictionaries/lists works now.
-rw-r--r--demo.stage116
-rw-r--r--src/functiondisplay.cpp8
-rw-r--r--src/gamestate.cpp10
-rw-r--r--src/variable.cpp71
-rw-r--r--test.stage129
5 files changed, 187 insertions, 147 deletions
diff --git a/demo.stage b/demo.stage
index 67c6063..00e7d94 100644
--- a/demo.stage
+++ b/demo.stage
@@ -7,65 +7,135 @@ game.start = <<start>>;
7 7
8global 8global
9{ 9{
10 command: "take" item 10 command: "go" dir
11 { 11 {
12 if item in situation.items then 12 if exists(situation.exits) then
13 { 13 {
14 player.inventory += item; 14 if dir in situation.exits then
15 situation.items -= item; 15 {
16 display('''You pickup the ''' + item + 16 goto( situation.exits[dir] );
17 ''' and put it in your pocket.'''); 17 }
18 }
19 else
20 {
21 display('''You don't see anything like that here.''');
22 } 18 }
19 display('''You're not really sure how to do that...''');
23 } 20 }
24 21
25 command: "use" item 22 command: "exits"
26 { 23 {
27 if not item in player.inventory then 24 if exists(situation.exits) then
28 { 25 {
29 display('''You don't have anything like that in your pocket.'''); 26 out = "Obvious exits are: ";
27 bFirst = true;
28 for each dir : dest in situation.exits do
29 {
30 if bFirst then
31 {
32 bFirst = false;
33 }
34 else
35 {
36 out += ", ";
37 }
38 out += dir;
39 }
40 display( out );
30 } 41 }
31 else 42 else
32 { 43 {
44 display("There are no obvious exits.");
33 } 45 }
34 } 46 }
47
48 // You should always have a global exit, quit, escape, something for
49 // dev-testing at least.
50 command: "exit"
51 {
52 exit();
53 }
54}
55
56function square( x )
57{
58 return( x*x );
35} 59}
36 60
37situation <<main>> 61function sillyDisplay( txt, extra )
38{ 62{
39 command: "there" hi 63 display("!~! " + txt + " !~!");
64 if extra then
40 { 65 {
66 display("And then some extra!");
41 } 67 }
68 else
69 {
70 display("...no extra for you");
71 }
72}
73
74function myGoto( txt )
75{
76 display( txt );
77 goto( txt );
78}
79
80function getThing()
81{
82 display( situation.thing );
83}
84
85situation <<start>>
86{
42 setup 87 setup
43 { 88 {
44 player.inventory = []; 89 goto( <<diningRoom>> );
45 } 90 }
91
46 enter 92 enter
47 { 93 {
48 } 94 }
49} 95}
50 96
51function hello() 97situation <<diningRoom>>
52{ 98{
53 bob = 55 * 2 + 1; 99 setup
100 {
101 situation.exits = {
102 'south': <<livingRoom>>,
103 'east': <<kitchen>>
104 };
105 }
106 enter
107 {
108 display('''You are in the dining room, it's very nice and warm. There
109 is a big table and...stuff. Looks like the living room is south, and
110 the kitchen is to the east.''');
111 }
54} 112}
55 113
56situation <<start>> 114situation <<livingRoom>>
57{ 115{
116 setup
117 {
118 situation.exits = {
119 'north': <<diningRoom>>
120 };
121 }
58 enter 122 enter
59 { 123 {
60 display('''You are here, there is a wrench sitting on the table.'''); 124 display('''Living room!''');
61 test("use", bob );
62 } 125 }
63} 126}
64 127
65situation <<end>> 128situation <<kitchen>>
66{ 129{
130 setup
131 {
132 situation.exits = {
133 'west': <<diningRoom>>
134 };
135 }
136
67 enter 137 enter
68 { 138 {
69 goto( <<start>> ); 139 display('''Kitchen!''');
70 } 140 }
71} 141}
diff --git a/src/functiondisplay.cpp b/src/functiondisplay.cpp
index 4790844..ab37a08 100644
--- a/src/functiondisplay.cpp
+++ b/src/functiondisplay.cpp
@@ -15,10 +15,12 @@ FunctionDisplay::~FunctionDisplay()
15 15
16void FunctionDisplay::call( class GameState &gState ) 16void FunctionDisplay::call( class GameState &gState )
17{ 17{
18 Bu::String s = gState.popDeref().to( Variable::tString ).getString(); 18// Bu::String s = gState.popDeref().to( Variable::tString ).getString();
19 19
20 sio << format( s ) << sio.nl; 20// sio << format( s ) << sio.nl;
21// sio << "Display: " << v << sio.nl; 21
22 Variable v = gState.popDeref();
23 sio << "Display: " << v << sio.nl;
22} 24}
23 25
24Bu::String FunctionDisplay::format( const Bu::String &sSrc ) 26Bu::String FunctionDisplay::format( const Bu::String &sSrc )
diff --git a/src/gamestate.cpp b/src/gamestate.cpp
index bd3e638..4af49aa 100644
--- a/src/gamestate.cpp
+++ b/src/gamestate.cpp
@@ -427,8 +427,9 @@ void GameState::parse( const AstBranch::NodeList &lCode )
427 { 427 {
428 Variable y = popDeref(); 428 Variable y = popDeref();
429 Variable x = pop(); 429 Variable x = pop();
430 VariableRef r = x.getVariableRef(); 430 deref( x ) += y;
431 setVariable( r.sName, getVariable( r.sName, r.sid ) + y, r.sid ); 431// VariableRef r = x.getVariableRef();
432// setVariable( r.sName, getVariable( r.sName, r.sid ) + y, r.sid );
432 } 433 }
433 break; 434 break;
434 435
@@ -436,8 +437,9 @@ void GameState::parse( const AstBranch::NodeList &lCode )
436 { 437 {
437 Variable y = popDeref(); 438 Variable y = popDeref();
438 Variable x = pop(); 439 Variable x = pop();
439 VariableRef r = x.getVariableRef(); 440 deref( x ) -= y;
440 setVariable( r.sName, getVariable( r.sName, r.sid ) - y, r.sid ); 441// VariableRef r = x.getVariableRef();
442// setVariable( r.sName, getVariable( r.sName, r.sid ) - y, r.sid );
441 } 443 }
442 break; 444 break;
443 445
diff --git a/src/variable.cpp b/src/variable.cpp
index 1100c84..0ce9793 100644
--- a/src/variable.cpp
+++ b/src/variable.cpp
@@ -363,8 +363,77 @@ Variable &Variable::operator+=( const Variable &rhs )
363 return *this; 363 return *this;
364} 364}
365 365
366Variable &Variable::operator-=( const Variable &rhs )
367{
368 switch( eType )
369 {
370 case tNull:
371 throw VariableException("You cannot subtract nulls.");
372
373 case tBool:
374 throw VariableException("You cannot subtract bools.");
375
376 case tInt:
377 switch( rhs.eType )
378 {
379 case tInt:
380 iValue -= rhs.iValue;
381 break;
382
383 case tFloat:
384 {
385 double dTmp = iValue;
386 eType = tFloat;
387 fValue = dTmp - rhs.fValue;
388 }
389 break;
390
391 default:
392 throw VariableException("Int -= invalid...");
393 }
394 break;
395
396 case tFloat:
397 switch( rhs.eType )
398 {
399 case tInt:
400 fValue -= rhs.iValue;
401 break;
402
403 case tFloat:
404 fValue -= rhs.fValue;
405 break;
406
407 default:
408 throw VariableException("Int += invalid...");
409 }
410 break;
411
412 case tString:
413 throw VariableException("You cannot subtract strings.");
414 break;
415
416 case tSituation:
417 throw VariableException("You cannot subtract situations.");
418 break;
419
420 case tVariable:
421 throw VariableException("You cannot subtract variable names.");
422 break;
423
424 case tList:
425 (*lValue).erase( rhs );
426 break;
427
428 case tDictionary:
429 (*hValue).erase( rhs );
430 break;
431 }
432
433 return *this;
434}
435
366/* 436/*
367Variable &Variable::operator-=( const Variable &rhs );
368Variable &Variable::operator*=( const Variable &rhs ); 437Variable &Variable::operator*=( const Variable &rhs );
369Variable &Variable::operator/=( const Variable &rhs ); 438Variable &Variable::operator/=( const Variable &rhs );
370*/ 439*/
diff --git a/test.stage b/test.stage
index 00e7d94..9e5c00a 100644
--- a/test.stage
+++ b/test.stage
@@ -1,5 +1,5 @@
1 1
2game.title = "Demo game"; 2game.title = "Code Test";
3game.author = "Mike Buland"; 3game.author = "Mike Buland";
4game.version = 1; 4game.version = 1;
5game.revision = 0; 5game.revision = 0;
@@ -7,135 +7,32 @@ game.start = <<start>>;
7 7
8global 8global
9{ 9{
10 command: "go" dir
11 {
12 if exists(situation.exits) then
13 {
14 if dir in situation.exits then
15 {
16 goto( situation.exits[dir] );
17 }
18 }
19 display('''You're not really sure how to do that...''');
20 }
21
22 command: "exits"
23 {
24 if exists(situation.exits) then
25 {
26 out = "Obvious exits are: ";
27 bFirst = true;
28 for each dir : dest in situation.exits do
29 {
30 if bFirst then
31 {
32 bFirst = false;
33 }
34 else
35 {
36 out += ", ";
37 }
38 out += dir;
39 }
40 display( out );
41 }
42 else
43 {
44 display("There are no obvious exits.");
45 }
46 }
47
48 // You should always have a global exit, quit, escape, something for
49 // dev-testing at least.
50 command: "exit" 10 command: "exit"
51 { 11 {
52 exit(); 12 exit();
53 } 13 }
54} 14}
55 15
56function square( x )
57{
58 return( x*x );
59}
60
61function sillyDisplay( txt, extra )
62{
63 display("!~! " + txt + " !~!");
64 if extra then
65 {
66 display("And then some extra!");
67 }
68 else
69 {
70 display("...no extra for you");
71 }
72}
73
74function myGoto( txt )
75{
76 display( txt );
77 goto( txt );
78}
79
80function getThing()
81{
82 display( situation.thing );
83}
84
85situation <<start>> 16situation <<start>>
86{ 17{
87 setup 18 setup
88 { 19 {
89 goto( <<diningRoom>> ); 20 dict = {1: "Hello"};
90 } 21 dict['bob'] = 'yup';
91 22 display( dict );
92 enter 23 dict -= 1;
93 { 24 display( dict );
94 } 25
95} 26 lst = [55];
96 27 lst += 112;
97situation <<diningRoom>> 28 display( lst );
98{ 29 lst -= 55;
99 setup 30 display( lst );
100 { 31 exit();
101 situation.exits = {
102 'south': <<livingRoom>>,
103 'east': <<kitchen>>
104 };
105 }
106 enter
107 {
108 display('''You are in the dining room, it's very nice and warm. There
109 is a big table and...stuff. Looks like the living room is south, and
110 the kitchen is to the east.''');
111 } 32 }
112}
113 33
114situation <<livingRoom>>
115{
116 setup
117 {
118 situation.exits = {
119 'north': <<diningRoom>>
120 };
121 }
122 enter 34 enter
123 { 35 {
124 display('''Living room!''');
125 } 36 }
126} 37}
127 38
128situation <<kitchen>>
129{
130 setup
131 {
132 situation.exits = {
133 'west': <<diningRoom>>
134 };
135 }
136
137 enter
138 {
139 display('''Kitchen!''');
140 }
141}