Selaa lähdekoodia

Aktionen zum steuern von BArieren und Schaltern implementiert

Kolja Strohm 5 vuotta sitten
vanhempi
commit
b394543810
2 muutettua tiedostoa jossa 315 lisäystä ja 2 poistoa
  1. 314 2
      StickmanWorldOnline/Aktionen.cpp
  2. 1 0
      StickmanWorldOnline/Bariere.h

+ 314 - 2
StickmanWorldOnline/Aktionen.cpp

@@ -1394,7 +1394,7 @@ DropSetArea::~DropSetArea()
     drop->release();
 }
 
-bool DropSetArea::runNext( Spiel * zSpiel, Ereignis * zEreignis, LocalMemory * zMemory, ProgramCounter * zPC, double &waitCount )
+bool DropSetArea::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
 {
     zPC->stepIn();
     if( zPC->currentPosition() == 0 )
@@ -1485,7 +1485,7 @@ DropDoDrop::DropDoDrop( Aktion *drop )
 DropDoDrop::~DropDoDrop()
 {}
 
-bool DropDoDrop::runNext( Spiel * zSpiel, Ereignis * zEreignis, LocalMemory * zMemory, ProgramCounter * zPC, double &waitCount )
+bool DropDoDrop::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
 {
     if( drop->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
     {
@@ -1500,3 +1500,315 @@ bool DropDoDrop::runNext( Spiel * zSpiel, Ereignis * zEreignis, LocalMemory * zM
     }
     return 0;
 }
+
+
+BariereSetEingeschaltet::BariereSetEingeschaltet( Aktion *eingeschaltet, Aktion *bariere )
+    : Aktion( BARIERE_SET_EINGESCHALTET )
+{
+    this->eingeschaltet = eingeschaltet;
+    this->bariere = bariere;
+}
+
+BariereSetEingeschaltet::~BariereSetEingeschaltet()
+{
+    eingeschaltet->release();
+    bariere->release();
+}
+
+bool BariereSetEingeschaltet::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( eingeschaltet->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( bariere->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != BARIERE )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Bariere *)t )->setEingeschaltet( ( (Boolean *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+BariereSetPosition::BariereSetPosition( Aktion *x, Aktion *y, Aktion *bariere )
+    : Aktion( BARIERE_SET_POSITION )
+{
+    this->x = x;
+    this->y = y;
+    this->bariere = bariere;
+}
+
+BariereSetPosition::~BariereSetPosition()
+{
+    x->release();
+    y->release();
+    bariere->release();
+}
+
+bool BariereSetPosition::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( bariere->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != BARIERE )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Bariere *)t )->setX( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Bariere *)t )->setY( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R1__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+BariereSetTeam::BariereSetTeam( Aktion *team, Aktion *bariere )
+    : Aktion( BARIERE_SET_TEAM )
+{
+    this->team = team;
+    this->bariere = bariere;
+}
+
+BariereSetTeam::~BariereSetTeam()
+{
+    team->release();
+    bariere->release();
+}
+
+bool BariereSetTeam::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( team->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != TEAM )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        if( bariere->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != BARIERE )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Bariere *)t )->setTeam( ( (Team *)zMemory->getVariable( zPC->getUniqueString() + "R0__" ) ) );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+SchalterSetPosition::SchalterSetPosition( Aktion *x, Aktion *y, Aktion *schalter )
+    : Aktion( SCHALTER_SET_POSITION )
+{
+    this->x = x;
+    this->y = y;
+    this->schalter = schalter;
+}
+
+SchalterSetPosition::~SchalterSetPosition()
+{
+    x->release();
+    y->release();
+    schalter->release();
+}
+
+bool SchalterSetPosition::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( schalter->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != SCHALTER )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Schalter *)t )->setX( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            ( (Schalter *)t )->setY( ( (Float *)zMemory->zVariable( zPC->getUniqueString() + "R1__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+SchalterSetErlaubt::SchalterSetErlaubt( Aktion *erlaubt, Aktion *schalter )
+    : Aktion( SCHALTER_SET_ERLAUBT )
+{
+    this->erlaubt = erlaubt;
+    this->schalter = schalter;
+}
+
+SchalterSetErlaubt::~SchalterSetErlaubt()
+{
+    erlaubt->release();
+    schalter->release();
+}
+
+bool SchalterSetErlaubt::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( schalter->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != SCHALTER )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Schalter *)t )->setAktive( ( (Boolean *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+SchalterAktivieren::SchalterAktivieren( Aktion *schalter )
+    : Aktion( SCHALTER_AKTIVIEREN )
+{
+    this->schalter = schalter;
+}
+
+SchalterAktivieren::~SchalterAktivieren()
+{
+    schalter->release();
+}
+
+bool SchalterAktivieren::runNext( Spiel * zSpiel, Ereignis * zEreignis, LocalMemory * zMemory, ProgramCounter * zPC, double &waitCount )
+{
+    if( schalter->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+    {
+        Variable *t = zMemory->zVariable( "__return__" );
+        if( !t || t->getVariableTyp() != SCHALTER )
+        {
+            zPC->stepOut();
+            return 1;
+        }
+        zSpiel->activateShalter( ( (Schalter *)t )->getId() );
+        return 1;
+    }
+    return 0;
+}

+ 1 - 0
StickmanWorldOnline/Bariere.h

@@ -40,6 +40,7 @@ public:
     void setAutoSchaltungMaxTime( int seconds );
     void startAutoSchaltung();
     void setTeam( Team *team );
+    void setEingeschaltet( bool eingeschaltet );
     void tick( double time, Spiel *zSpiel );
     bool hatStyle( int style ) const;
     int getVerschiebungAnzahl() const;