Browse Source

Aktionen zum Steuern von Umlenkungen implementiert

Kolja Strohm 5 years ago
parent
commit
49945abbe5

+ 409 - 6
StickmanWorldOnline/Aktionen.cpp

@@ -419,10 +419,10 @@ bool DisplayText::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMem
                 zPC->stepOut();
                 return 1;
             }
-            Float *xv = (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" );
-            Float *yv = (Float *)zMemory->zVariable( zPC->getUniqueString() + "R1__" );
-            Float *dauerv = (Float *)zMemory->zVariable( zPC->getUniqueString() + "R2__" );
-            Integer *farbev = (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R3__" );
+            //Float *xv = (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" );
+            //Float *yv = (Float *)zMemory->zVariable( zPC->getUniqueString() + "R1__" );
+            //Float *dauerv = (Float *)zMemory->zVariable( zPC->getUniqueString() + "R2__" );
+            //Integer *farbev = (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R3__" );
             // do nothing because the server does not need to show text
             zPC->stepOut();
             return 1;
@@ -454,6 +454,7 @@ bool SpielPause::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemo
         zSpiel->setPausiert( ( (Boolean *)t )->getValue() );
         return 1;
     }
+    return 0;
 }
 
 
@@ -478,6 +479,7 @@ bool SpielEnde::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemor
         zSpiel->setEnde( t->getVariableTyp() == NICHTS ? 0 : (Team *)t );
         return 1;
     }
+    return 0;
 }
 
 
@@ -1365,7 +1367,7 @@ bool DropSetMaxTime::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *z
                 zPC->stepOut();
                 return 1;
             }
-            ( (Drop *)t )->setMaxTime( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Drop *)t )->setMaxTime( ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
             zPC->stepOut();
             return 1;
         }
@@ -1797,7 +1799,7 @@ SchalterAktivieren::~SchalterAktivieren()
     schalter->release();
 }
 
-bool SchalterAktivieren::runNext( Spiel * zSpiel, Ereignis * zEreignis, LocalMemory * zMemory, ProgramCounter * zPC, double &waitCount )
+bool SchalterAktivieren::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
 {
     if( schalter->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
     {
@@ -1812,3 +1814,404 @@ bool SchalterAktivieren::runNext( Spiel * zSpiel, Ereignis * zEreignis, LocalMem
     }
     return 0;
 }
+
+
+TunnelSetPosition::TunnelSetPosition( Aktion *x, Aktion *y, Aktion *tunnel )
+    : Aktion( TUNNEL_SET_POSITION )
+{
+    this->x = x;
+    this->y = y;
+    this->tunnel = tunnel;
+}
+
+TunnelSetPosition::~TunnelSetPosition()
+{
+    x->release();
+    y->release();
+    tunnel->release();
+}
+
+bool TunnelSetPosition::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( tunnel->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != TUNNEL )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Tunnel *)t )->setX( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Tunnel *)t )->setY( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R1__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+TunnelSetZielPosition::TunnelSetZielPosition( Aktion *x, Aktion *y, Aktion *tunnel )
+    : Aktion( TUNNEL_SET_ZIEL_POSITION )
+{
+    this->x = x;
+    this->y = y;
+    this->tunnel = tunnel;
+}
+
+TunnelSetZielPosition::~TunnelSetZielPosition()
+{
+    x->release();
+    y->release();
+    tunnel->release();
+}
+
+bool TunnelSetZielPosition::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() != INTEGER )
+            {
+                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() != INTEGER )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R1__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 2 && waitCount <= 0 )
+    {
+        if( tunnel->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != TUNNEL )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Tunnel *)t )->setZielX( ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Tunnel *)t )->setZielY( ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R1__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+TunnelSetErlaubt::TunnelSetErlaubt( Aktion *erlaubt, Aktion *tunnel )
+    : Aktion( TUNNEL_SET_ERLAUBT )
+{
+    this->erlaubt = erlaubt;
+    this->tunnel = tunnel;
+}
+
+TunnelSetErlaubt::~TunnelSetErlaubt()
+{
+    erlaubt->release();
+    tunnel->release();
+}
+
+bool TunnelSetErlaubt::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( erlaubt->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != BOOLEAN )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( tunnel->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != TUNNEL )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Tunnel *)t )->setAktiv( ( (Boolean *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+UmlenkungSetPosition::UmlenkungSetPosition( Aktion *x, Aktion *y, Aktion *umlenkung )
+    : Aktion( UMLENKUNG_SET_POSITION )
+{
+    this->x = x;
+    this->y = y;
+    this->umlenkung = umlenkung;
+}
+
+UmlenkungSetPosition::~UmlenkungSetPosition()
+{
+    x->release();
+    y->release();
+    umlenkung->release();
+}
+
+bool UmlenkungSetPosition::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( umlenkung->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != UMLENKUNG )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Umlenkung *)t )->setX( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Umlenkung *)t )->setY( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R1__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+UmlenkungSetRichtung::UmlenkungSetRichtung( Aktion *richtung, Aktion *umlenkung )
+    : Aktion( UMLENKUNG_SET_RICHTUNG )
+{
+    this->richtung = richtung;
+    this->umlenkung = umlenkung;
+}
+
+UmlenkungSetRichtung::~UmlenkungSetRichtung()
+{
+    richtung->release();
+    umlenkung->release();
+}
+
+bool UmlenkungSetRichtung::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( umlenkung->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != UMLENKUNG )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Umlenkung *)t )->setRichtung( getRichtungFromString( ( (String *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() ) );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+UmlenkungSetMaxAbk::UmlenkungSetMaxAbk( Aktion *abk, Aktion *umlenkung )
+    : Aktion( UMLENKUNG_SET_MAX_ABK )
+{
+    this->abk = abk;
+    this->umlenkung = umlenkung;
+}
+
+UmlenkungSetMaxAbk::~UmlenkungSetMaxAbk()
+{
+    abk->release();
+    umlenkung->release();
+}
+
+bool UmlenkungSetMaxAbk::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() != INTEGER )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( umlenkung->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != UMLENKUNG )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Umlenkung *)t )->setMaxAbklingzeit( ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+UmlenkungSetEnabled::UmlenkungSetEnabled( Aktion *enabled, Aktion *umlenkung )
+    : Aktion( UMLENKUNG_SET_ERLAUBT )
+{
+    this->enabled = enabled;
+    this->umlenkung = umlenkung;
+}
+
+UmlenkungSetEnabled::~UmlenkungSetEnabled()
+{
+    enabled->release();
+    umlenkung->release();
+}
+
+bool UmlenkungSetEnabled::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( enabled->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != BOOLEAN )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( umlenkung->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != UMLENKUNG )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Umlenkung *)t )->setAktiv( ( (Boolean *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}

+ 14 - 0
StickmanWorldOnline/GameObject.cpp

@@ -14,6 +14,20 @@ Richtung invert( Richtung r )
     return r;
 }
 
+Richtung getRichtungFromString( Text str )
+{
+    if( str.istGleich( "OBEN" ) )
+        return OBEN;
+    if( str.istGleich( "LINKS" ) )
+        return LINKS;
+    if( str.istGleich( "UNTEN" ) )
+        return UNTEN;
+    if( str.istGleich( "RECHTS" ) )
+        return RECHTS;
+    return MITTE;
+}
+
+
 GameObject::GameObject( VariableTyp typ, int x, int y, int width, int height )
     : Variable( typ )
 {

+ 2 - 0
StickmanWorldOnline/GameObject.h

@@ -13,6 +13,8 @@ enum Richtung
 
 Richtung invert( Richtung r );
 
+Richtung getRichtungFromString( Text str );
+
 class GameObject : public Variable
 {
 protected: