diff options
-rw-r--r-- | bloodfields.stage | 162 | ||||
-rw-r--r-- | src/variable.cpp | 17 | ||||
-rw-r--r-- | src/variable.h | 5 | ||||
-rw-r--r-- | test.stage | 8 |
4 files changed, 189 insertions, 3 deletions
diff --git a/bloodfields.stage b/bloodfields.stage new file mode 100644 index 0000000..81ff6e1 --- /dev/null +++ b/bloodfields.stage | |||
@@ -0,0 +1,162 @@ | |||
1 | game.title = "Bloodfields"; | ||
2 | |||
3 | global | ||
4 | { | ||
5 | command: "quit" | ||
6 | { | ||
7 | exit(); | ||
8 | } | ||
9 | } | ||
10 | |||
11 | situation <<start>> | ||
12 | { | ||
13 | setup | ||
14 | { | ||
15 | player.hpMax = 10; | ||
16 | player.hpCur = player.hpMax; | ||
17 | player.xp = 0; | ||
18 | player.attack = 3; | ||
19 | |||
20 | global.bJustTravelled = false; | ||
21 | |||
22 | goto( <<field>> ); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | function status() | ||
27 | { | ||
28 | display('You have ' + player.hpCur + ' of ' + player.hpMax + ' hp.'); | ||
29 | } | ||
30 | |||
31 | function look() | ||
32 | { | ||
33 | if( exists(global.enemy) )then | ||
34 | { | ||
35 | display('''You are standing in a field of wheat. You see a ''' + | ||
36 | global.enemy['name'] + ''' in front of you.'''); | ||
37 | } | ||
38 | else | ||
39 | { | ||
40 | display('''You are standing in a field of wheat.'''); | ||
41 | } | ||
42 | // status(); | ||
43 | } | ||
44 | |||
45 | function mkEnemy() | ||
46 | { | ||
47 | global.enemy = { | ||
48 | 'name': 'Snail', | ||
49 | 'weapon': 'Tooth', | ||
50 | 'attack': 3, | ||
51 | 'hp': 5 | ||
52 | }; | ||
53 | } | ||
54 | |||
55 | function rollAttack( attack ) | ||
56 | { | ||
57 | return( random( attack-attack/3, attack+attack/3 ) ); | ||
58 | } | ||
59 | |||
60 | function playerAttack() | ||
61 | { | ||
62 | damage = rollAttack( player.attack ); | ||
63 | global.enemy['hp'] = global.enemy['hp'] - damage; | ||
64 | display('You strike the ' + global.enemy['name'] + ' for ' + damage + | ||
65 | ' damage.'); | ||
66 | if global.enemy['hp'] <= 0 then | ||
67 | { | ||
68 | display('You killed the ' + global.enemy['name'] + '!'); | ||
69 | delete( global.enemy ); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | function enemyAttack() | ||
74 | { | ||
75 | damage = rollAttack( global.enemy['attack'] ); | ||
76 | player.hpCur -= damage; | ||
77 | display("The " + global.enemy['name'] + ' strikes you for ' + damage + | ||
78 | ' damage.'); | ||
79 | if player.hpCur <= 0 then | ||
80 | { | ||
81 | display('The ' + global.enemy['name'] + ' killed you!'); | ||
82 | exit(); | ||
83 | } | ||
84 | } | ||
85 | |||
86 | situation <<travel>> | ||
87 | { | ||
88 | enter | ||
89 | { | ||
90 | delete( global.enemy ); | ||
91 | |||
92 | display('You wander aimlessly through the seemingly endless field of wheat.'); | ||
93 | |||
94 | select = random(1,3); | ||
95 | if select == 1 then | ||
96 | { | ||
97 | mkEnemy(); | ||
98 | display('''There's a ''' + global.enemy['name'] + ''' here!'''); | ||
99 | } | ||
100 | |||
101 | global.bJustTravelled = true; | ||
102 | |||
103 | goto( <<field>> ); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | situation <<field>> | ||
108 | { | ||
109 | command: "attack" | ||
110 | { | ||
111 | if exists(global.enemy) then | ||
112 | { | ||
113 | playerAttack(); | ||
114 | goto( <<field>> ); | ||
115 | } | ||
116 | else | ||
117 | { | ||
118 | display('''There's nothing here to attack...'''); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | command: "look" | ||
123 | { | ||
124 | look(); | ||
125 | } | ||
126 | |||
127 | command: "walk" | ||
128 | { | ||
129 | if not exists(global.enemy) then | ||
130 | { | ||
131 | goto( <<travel>> ); | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | display("You can't walk around with an enemy in front of you! | ||
136 | You can try to flee if you'd like..."); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | setup | ||
141 | { | ||
142 | look(); | ||
143 | } | ||
144 | |||
145 | enter | ||
146 | { | ||
147 | if not global.bJustTravelled then | ||
148 | { | ||
149 | if exists( global.enemy ) then | ||
150 | { | ||
151 | enemyAttack(); | ||
152 | } | ||
153 | status(); | ||
154 | // look(); | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | } | ||
159 | global.bJustTravelled = false; | ||
160 | } | ||
161 | } | ||
162 | |||
diff --git a/src/variable.cpp b/src/variable.cpp index a3fb4a2..965e1af 100644 --- a/src/variable.cpp +++ b/src/variable.cpp | |||
@@ -453,6 +453,16 @@ Variable Variable::operator+( const Variable &rhs ) const | |||
453 | { | 453 | { |
454 | if( eType != rhs.eType ) | 454 | if( eType != rhs.eType ) |
455 | { | 455 | { |
456 | Type eNew = bestType( eType, rhs.eType ); | ||
457 | |||
458 | if( eType != eNew ) | ||
459 | { | ||
460 | return to( eNew ) + rhs; | ||
461 | } | ||
462 | else | ||
463 | { | ||
464 | return *this + rhs.to( eNew ); | ||
465 | } | ||
456 | throw VariableException("Adding between dissimilar types is not yet supported."); | 466 | throw VariableException("Adding between dissimilar types is not yet supported."); |
457 | } | 467 | } |
458 | else | 468 | else |
@@ -868,6 +878,13 @@ void Variable::deinitType() | |||
868 | iValue = 0; | 878 | iValue = 0; |
869 | } | 879 | } |
870 | 880 | ||
881 | Variable::Type Variable::bestType( Variable::Type t1, Variable::Type t2 ) const | ||
882 | { | ||
883 | Type tBest = Bu::max( t1, t2 ); | ||
884 | |||
885 | return tBest; | ||
886 | } | ||
887 | |||
871 | template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k ) | 888 | template<> uint32_t Bu::__calcHashCode<Variable>( const Variable &k ) |
872 | { | 889 | { |
873 | switch( k.getType() ) | 890 | switch( k.getType() ) |
diff --git a/src/variable.h b/src/variable.h index 8741b28..2eedcbb 100644 --- a/src/variable.h +++ b/src/variable.h | |||
@@ -28,12 +28,12 @@ public: | |||
28 | tBool, | 28 | tBool, |
29 | tInt, | 29 | tInt, |
30 | tFloat, | 30 | tFloat, |
31 | tString, | ||
32 | tSituation, | 31 | tSituation, |
33 | tVariable, | 32 | tVariable, |
34 | tVarPtr, | 33 | tVarPtr, |
35 | tList, | 34 | tList, |
36 | tDictionary | 35 | tDictionary, |
36 | tString, | ||
37 | }; | 37 | }; |
38 | 38 | ||
39 | public: | 39 | public: |
@@ -90,6 +90,7 @@ public: | |||
90 | private: | 90 | private: |
91 | void initType(); | 91 | void initType(); |
92 | void deinitType(); | 92 | void deinitType(); |
93 | Type bestType( Type t1, Type t2 ) const; | ||
93 | 94 | ||
94 | private: | 95 | private: |
95 | Type eType; | 96 | Type eType; |
@@ -17,7 +17,13 @@ situation <<start>> | |||
17 | { | 17 | { |
18 | setup | 18 | setup |
19 | { | 19 | { |
20 | display( random( 1, 3 ) ); | 20 | stuff = {}; |
21 | stuff['bob'] = {'joe': 'hi', 'sub': {1: 5, 2: 8} }; | ||
22 | stuff['bob']['sub'][55] = "aoeu"; | ||
23 | stuff['bob'] = 'hia'; | ||
24 | stuff['joe'] = stuff['bob']; | ||
25 | stuff['joe'] += 'aoeu'; | ||
26 | display( stuff['bob']['sub'][55] ); | ||
21 | exit(); | 27 | exit(); |
22 | } | 28 | } |
23 | 29 | ||