From 0433eb31936fc72486e9a81732d5bcd38cf5808a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 2 Jan 2012 00:26:29 -0700 Subject: Variables upconvert on add now. It's not perfect, but it's decent for now, and early testing. --- bloodfields.stage | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/variable.cpp | 17 ++++++ src/variable.h | 5 +- test.stage | 8 ++- 4 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 bloodfields.stage diff --git a/bloodfields.stage b/bloodfields.stage new file mode 100644 index 0000000..81ff6e1 --- /dev/null +++ b/bloodfields.stage @@ -0,0 +1,162 @@ +game.title = "Bloodfields"; + +global +{ + command: "quit" + { + exit(); + } +} + +situation <> +{ + setup + { + player.hpMax = 10; + player.hpCur = player.hpMax; + player.xp = 0; + player.attack = 3; + + global.bJustTravelled = false; + + goto( <> ); + } +} + +function status() +{ + display('You have ' + player.hpCur + ' of ' + player.hpMax + ' hp.'); +} + +function look() +{ + if( exists(global.enemy) )then + { + display('''You are standing in a field of wheat. You see a ''' + + global.enemy['name'] + ''' in front of you.'''); + } + else + { + display('''You are standing in a field of wheat.'''); + } +// status(); +} + +function mkEnemy() +{ + global.enemy = { + 'name': 'Snail', + 'weapon': 'Tooth', + 'attack': 3, + 'hp': 5 + }; +} + +function rollAttack( attack ) +{ + return( random( attack-attack/3, attack+attack/3 ) ); +} + +function playerAttack() +{ + damage = rollAttack( player.attack ); + global.enemy['hp'] = global.enemy['hp'] - damage; + display('You strike the ' + global.enemy['name'] + ' for ' + damage + + ' damage.'); + if global.enemy['hp'] <= 0 then + { + display('You killed the ' + global.enemy['name'] + '!'); + delete( global.enemy ); + } +} + +function enemyAttack() +{ + damage = rollAttack( global.enemy['attack'] ); + player.hpCur -= damage; + display("The " + global.enemy['name'] + ' strikes you for ' + damage + + ' damage.'); + if player.hpCur <= 0 then + { + display('The ' + global.enemy['name'] + ' killed you!'); + exit(); + } +} + +situation <> +{ + enter + { + delete( global.enemy ); + + display('You wander aimlessly through the seemingly endless field of wheat.'); + + select = random(1,3); + if select == 1 then + { + mkEnemy(); + display('''There's a ''' + global.enemy['name'] + ''' here!'''); + } + + global.bJustTravelled = true; + + goto( <> ); + } +} + +situation <> +{ + command: "attack" + { + if exists(global.enemy) then + { + playerAttack(); + goto( <> ); + } + else + { + display('''There's nothing here to attack...'''); + } + } + + command: "look" + { + look(); + } + + command: "walk" + { + if not exists(global.enemy) then + { + goto( <> ); + } + else + { + display("You can't walk around with an enemy in front of you! + You can try to flee if you'd like..."); + } + } + + setup + { + look(); + } + + enter + { + if not global.bJustTravelled then + { + if exists( global.enemy ) then + { + enemyAttack(); + } + status(); +// look(); + } + else + { + } + global.bJustTravelled = false; + } +} + 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 { if( eType != rhs.eType ) { + Type eNew = bestType( eType, rhs.eType ); + + if( eType != eNew ) + { + return to( eNew ) + rhs; + } + else + { + return *this + rhs.to( eNew ); + } throw VariableException("Adding between dissimilar types is not yet supported."); } else @@ -868,6 +878,13 @@ void Variable::deinitType() iValue = 0; } +Variable::Type Variable::bestType( Variable::Type t1, Variable::Type t2 ) const +{ + Type tBest = Bu::max( t1, t2 ); + + return tBest; +} + template<> uint32_t Bu::__calcHashCode( const Variable &k ) { 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: tBool, tInt, tFloat, - tString, tSituation, tVariable, tVarPtr, tList, - tDictionary + tDictionary, + tString, }; public: @@ -90,6 +90,7 @@ public: private: void initType(); void deinitType(); + Type bestType( Type t1, Type t2 ) const; private: Type eType; diff --git a/test.stage b/test.stage index 3fe467c..66a9b70 100644 --- a/test.stage +++ b/test.stage @@ -17,7 +17,13 @@ situation <> { setup { - display( random( 1, 3 ) ); + stuff = {}; + stuff['bob'] = {'joe': 'hi', 'sub': {1: 5, 2: 8} }; + stuff['bob']['sub'][55] = "aoeu"; + stuff['bob'] = 'hia'; + stuff['joe'] = stuff['bob']; + stuff['joe'] += 'aoeu'; + display( stuff['bob']['sub'][55] ); exit(); } -- cgit v1.2.3