Selaa lähdekoodia

Aktionen zum Steuern von Geschossen implementiert

Kolja Strohm 5 vuotta sitten
vanhempi
commit
d981381e85

+ 359 - 5
StickmanWorldOnline/Aktionen.cpp

@@ -2430,7 +2430,7 @@ bool TriggerSetEnabled::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory
                 zPC->stepOut();
                 return 1;
             }
-            ( (Trigger *)t )->setAktiv( ( (Boolean *)zMemory->getVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Trigger *)t )->setAktiv( ( (Boolean *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
             zPC->stepOut();
             return 1;
         }
@@ -2480,7 +2480,7 @@ bool TeamSetPunkte::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zM
                 zPC->stepOut();
                 return 1;
             }
-            ( (Team *)t )->setPunkte( ( (Integer *)zMemory->getVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Team *)t )->setPunkte( ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
             zPC->stepOut();
             return 1;
         }
@@ -2597,7 +2597,7 @@ bool TimerSetPause::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zM
                 zPC->stepOut();
                 return 1;
             }
-            ( (Timer *)t )->setPause( ( (Boolean *)zMemory->getVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Timer *)t )->setPause( ( (Boolean *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
             zPC->stepOut();
             return 1;
         }
@@ -2676,7 +2676,7 @@ bool TimerSetZeit::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMe
                 zPC->stepOut();
                 return 1;
             }
-            ( (Timer *)t )->setZeit( ( (Float *)zMemory->getVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Timer *)t )->setZeit( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
             zPC->stepOut();
             return 1;
         }
@@ -2726,7 +2726,361 @@ bool TimerSetSichtbar::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory
                 zPC->stepOut();
                 return 1;
             }
-            ( (Timer *)t )->setSichtbar( ( (Boolean *)zMemory->getVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Timer *)t )->setSichtbar( ( (Boolean *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+GeschossNeu::GeschossNeu( Aktion *x, Aktion *y, Aktion *typ, Aktion *richtung )
+    : Aktion( GESCHOSS_NEU )
+{
+    this->x = x;
+    this->y = y;
+    this->typ = typ;
+    this->richtung = richtung;
+}
+
+GeschossNeu::~GeschossNeu()
+{
+    x->release();
+    y->release();
+    typ->release();
+    richtung->release();
+}
+
+bool GeschossNeu::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( x->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != FLOAT )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( y->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != FLOAT )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R1__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 2 && waitCount <= 0 )
+    {
+        if( typ->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != GESCHOSS_TYP )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R2__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 3 && waitCount <= 0 )
+    {
+        if( richtung->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != RICHTUNG )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            Geschoss *g = new Geschoss( zSpiel->getNextId(), 0,
+                                        getGeschossTypFromString( ( (String *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() ),
+                                        getRichtungFromString( ( (String *)t )->getValue() ),
+                                        ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue(),
+                                        ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R1__" ) )->getValue(), 0 );
+            zSpiel->addGeschoss( (Geschoss *)g->getThis() );
+            zMemory->setVar( "__return__", g );
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+GeschossSetPosition::GeschossSetPosition( Aktion *x, Aktion *y, Aktion *geschoss )
+    : Aktion( GESCHOSS_SET_POSITION )
+{
+    this->x = x;
+    this->y = y;
+    this->geschoss = geschoss;
+}
+
+GeschossSetPosition::~GeschossSetPosition()
+{
+    x->release();
+    y->release();
+    geschoss->release();
+}
+
+bool GeschossSetPosition::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( x->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != FLOAT )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( y->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != FLOAT )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R1__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 2 && waitCount <= 0 )
+    {
+        if( geschoss->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != GESCHOSS )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Geschoss *)t )->setX( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Geschoss *)t )->setY( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R1__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+GeschossSetSpeed::GeschossSetSpeed( Aktion *speed, Aktion *geschoss )
+    : Aktion( GESCHOSS_SET_SPEED )
+{
+    this->speed = speed;
+    this->geschoss = geschoss;
+}
+
+GeschossSetSpeed::~GeschossSetSpeed()
+{
+    speed->release();
+    geschoss->release();
+}
+
+bool GeschossSetSpeed::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( speed->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != FLOAT )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( geschoss->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != GESCHOSS )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Geschoss *)t )->setSpeed( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+GeschossSetPlayer::GeschossSetPlayer( Aktion *player, Aktion *geschoss )
+    : Aktion( GESCHOSS_SET_PLAYER )
+{
+    this->player = player;
+    this->geschoss = geschoss;
+}
+
+GeschossSetPlayer::~GeschossSetPlayer()
+{
+    player->release();
+    geschoss->release();
+}
+
+bool GeschossSetPlayer::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( player->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != SPIELER )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( geschoss->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != GESCHOSS )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Geschoss *)t )->setBesitzer( ( (Spieler *)zMemory->getVariable( zPC->getUniqueString() + "R0__" ) ) );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+GeschossSetRichtung::GeschossSetRichtung( Aktion *richtung, Aktion *geschoss )
+    : Aktion( GESCHOSS_SET_RICHTUNG )
+{
+    this->richtung = richtung;
+    this->geschoss = geschoss;
+}
+
+GeschossSetRichtung::~GeschossSetRichtung()
+{
+    richtung->release();
+    geschoss->release();
+}
+
+bool GeschossSetRichtung::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( richtung->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != RICHTUNG )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( geschoss->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != GESCHOSS )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Geschoss *)t )->setRichtung( getRichtungFromString( ( (String *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() ) );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+GeschossSetType::GeschossSetType( Aktion *type, Aktion *geschoss )
+    : Aktion( GESCHOSS_SET_TYPE )
+{
+    this->type = type;
+    this->geschoss = geschoss;
+}
+
+GeschossSetType::~GeschossSetType()
+{
+    type->release();
+    geschoss->release();
+}
+
+bool GeschossSetType::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( type->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != GESCHOSS_TYP )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( geschoss->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != GESCHOSS )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Geschoss *)t )->setTyp( getGeschossTypFromString( ( (String *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() ) );
             zPC->stepOut();
             return 1;
         }

+ 14 - 0
StickmanWorldOnline/Geschoss.cpp

@@ -1,6 +1,20 @@
 #include "Geschoss.h"
 
 
+GeschossTyp getGeschossTypFromString( Text str )
+{
+    if( str.istGleich( "KUGEL" ) )
+        return GESCHOSS_KUGEL;
+    if( str.istGleich( "DRACHENAUGE" ) )
+        return GESCHOSS_DRACHENAUGE;
+    if( str.istGleich( "FEUERBALL" ) )
+        return GESCHOSS_FEUERBALL;
+    if( str.istGleich( "MINE" ) )
+        return GESCHOSS_MINE;
+    return GESCHOSS_PFEIL;
+}
+
+
 Geschoss::Geschoss( int id, float speed, GeschossTyp typ, Richtung r, int x, int y, Spieler *besitzer )
     : GameObject( GESCHOSS, x, y, 20, 20 )
 {

+ 5 - 0
StickmanWorldOnline/Geschoss.h

@@ -12,6 +12,8 @@ enum GeschossTyp
     GESCHOSS_MINE
 };
 
+GeschossTyp getGeschossTypFromString( Text str );
+
 #define PFEIL_DAMAGE 100
 #define KUGEL_DAMAGE 100
 
@@ -36,6 +38,9 @@ public:
     void addGeschossTreffer();
     void addTunnel();
     void addSchalter();
+    void setSpeed( float speed );
+    void setBesitzer( Spieler *besitzer );
+    void setTyp( GeschossTyp typ );
     void setRichtung( Richtung r );
     void tick( double zeit );
     GeschossTyp getTyp() const;

+ 2 - 1
StickmanWorldOnline/Variablen.h

@@ -23,6 +23,7 @@ enum VariableTyp
     GEGENSTAND,
     GEGENSTAND_TYP,
     GESCHOSS,
+    GESCHOSS_TYP,
     SCHIENE,
     TUNNEL,
     UMLENKUNG,
@@ -75,7 +76,7 @@ private:
     Text value;
 
 public:
-    String( const char *value, bool richtung = 0 );
+    String( const char *value, bool richtung = 0, bool geschossTyp = 0 );
     void setValue( Text value );
     const Text &getValue() const;
 };