Browse Source

Einiege Aktionen implementiert

Kolja Strohm 5 years ago
parent
commit
b08fd8a2f4

+ 529 - 0
StickmanWorldOnline/Aktionen.cpp

@@ -0,0 +1,529 @@
+#include "Aktionen.h"
+#include "Trigger.h"
+#include "Spiel.h"
+
+Aktion::Aktion( AktionTyp typ )
+    : Variable( AKTION )
+{
+    this->typ = typ;
+}
+
+Aktion::~Aktion()
+{}
+
+
+KonstantNichts::KonstantNichts()
+    : Aktion( KONSTANT_NICHTS )
+{}
+
+bool KonstantNichts::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zMemory->setVar( "__return__", new Variable( NICHTS ) );
+    return 1;
+}
+
+
+KonstantInteger::KonstantInteger( int val )
+    : Aktion( KONSTANT_INTEGER )
+{
+    this->value = val;
+}
+
+bool KonstantInteger::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zMemory->setVar( "__return__", new Integer( value ) );
+    return 1;
+}
+
+
+KonstantBoolean::KonstantBoolean( bool val )
+    : Aktion( KONSTANT_BOOLEAN )
+{
+    value = val;
+}
+
+bool KonstantBoolean::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zMemory->setVar( "__return__", new Boolean( value ) );
+    return 1;
+}
+
+
+KonstantString::KonstantString( Text val )
+    : Aktion( KONSTANT_STRING )
+{
+    value = val;
+}
+
+bool KonstantString::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zMemory->setVar( "__return__", new String( value ) );
+    return 1;
+}
+
+
+KonstantFloat::KonstantFloat( float val )
+    : Aktion( KONSTANT_FLOAT )
+{
+    value = val;
+}
+
+bool KonstantFloat::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zMemory->setVar( "__return__", new Float( value ) );
+    return 1;
+}
+
+
+KonstantVariable::KonstantVariable( Text name )
+    : Aktion( KONSTANT_VARIABLE )
+{
+    this->name = name;
+}
+
+bool KonstantVariable::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    if( zMemory->zVariable( name ) )
+        zMemory->setVar( "__return__", zMemory->getVariable( name ) );
+    else if( zEreignis->zParameter( name ) )
+        zMemory->setVar( "__return__", zEreignis->zParameter( name ) );
+    else if( zSpiel->zVariable( name ) )
+        zMemory->setVar( "__return__", zSpiel->getVariable( name ) );
+    else
+        zMemory->setVar( "__return__", new Variable( NICHTS ) );
+    return 1;
+}
+
+
+Warten::Warten( Aktion *seconds )
+    : Aktion( WARTEN )
+{
+    this->seconds = seconds;
+}
+
+Warten::~Warten()
+{
+    seconds->release();
+}
+
+bool Warten::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    bool finished = seconds->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount );
+    if( finished )
+    {
+        Variable *t = zMemory->zVariable( "__return__" );
+        if( !t || t->getVariableTyp() != FLOAT )
+        {
+            zPC->stepOut();
+            return 1;
+        }
+        waitCount += ( (Float *)t )->getValue();
+    }
+    return finished;
+}
+
+
+WennDannSonst::WennDannSonst( Aktion *wenn, Aktion *dann, Aktion *sonst )
+    : Aktion( WENN_DANN_SONST )
+{
+    this->wenn = wenn;
+    this->dann = dann;
+    this->sonst = sonst;
+}
+
+WennDannSonst::~WennDannSonst()
+{
+    wenn->release();
+    if( dann )
+        dann->release();
+    if( sonst )
+        sonst->release();
+}
+
+bool WennDannSonst::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        bool finished = wenn->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount );
+        if( finished )
+        {
+            Variable *ret = zMemory->zVariable( "__return__" );
+            zPC->count();
+            if( !isTrue( ret ) )
+            {
+                zPC->count();
+                if( !sonst )
+                {
+                    zPC->stepOut();
+                    return 1;
+                }
+            }
+            else
+            {
+                if( !dann )
+                {
+                    zPC->stepOut();
+                    return 1;
+                }
+            }
+        }
+    }
+    if( zPC->currentPosition() == 1 && waitCount <= 0 )
+    {
+        bool finished = dann->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount );
+        if( finished )
+        {
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    if( zPC->currentPosition() == 2 && waitCount <= 0 )
+    {
+        bool finished = sonst->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount );
+        if( finished )
+        {
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+SetVariable::SetVariable( Text name, Aktion *value )
+    : Aktion( SET_VARIABLE )
+{
+    this->name = name;
+    this->value = value;
+}
+
+SetVariable::~SetVariable()
+{
+    value->release();
+}
+
+bool SetVariable::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    bool finished = value->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount );
+    if( finished )
+    {
+        if( zMemory->zVariable( name ) || zEreignis->zParameter( name ) || !zSpiel->zVariable( name ) )
+            zMemory->setVar( name, zMemory->getVariable( "__return__" ) );
+        else
+            zSpiel->setVariable( name, zMemory->getVariable( "__return__" ) );
+    }
+    return finished;
+}
+
+
+TriggerAktion::TriggerAktion( Aktion *number, Aktion *triggerName )
+    : Aktion( TRIGGER_AKTION )
+{
+    this->number = number;
+    trigger = triggerName;
+}
+
+TriggerAktion::~TriggerAktion()
+{
+    number->release();
+    trigger->release();
+}
+
+bool TriggerAktion::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( number->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( trigger->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != TRIGGER )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            int id = ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue();
+            if( id >= ( (Trigger *)t )->getAktionAnzahl() )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R0__", ( (Trigger *)t )->getAktion( id ) );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 2 && waitCount <= 0 )
+    {
+        if( ( (Aktion *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+SpielerNachricht::SpielerNachricht( Aktion *spieler, Aktion *nachricht )
+    : Aktion( SPIELER_NACHRICHT )
+{
+    this->spieler = spieler;
+    this->nachricht = nachricht;
+}
+
+SpielerNachricht::~SpielerNachricht()
+{
+    spieler->release();
+    nachricht->release();
+}
+
+bool SpielerNachricht::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( spieler->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( nachricht->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( t->getVariableTyp() != STRING )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            // this is handeld on client side directly (no need to send the message to the player)
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+DisplayText::DisplayText( Aktion *x, Aktion *y, Aktion *f, Aktion *dauer, Aktion *nachricht )
+    : Aktion( DISPLAY_TEXT )
+{
+    this->x = x;
+    this->y = y;
+    this->color = f;
+    this->dauer = dauer;
+    this->nachricht = nachricht;
+}
+
+DisplayText::~DisplayText()
+{
+    x->release();
+    y->release();
+    color->release();
+    dauer->release();
+    nachricht->release();
+}
+
+bool DisplayText::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( dauer->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != FLOAT )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R2__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 3 && waitCount <= 0 )
+    {
+        if( color->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || ( t->getVariableTyp() != INTEGER ) )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            zMemory->setVar( zPC->getUniqueString() + "R3__", t->getThis() );
+            zPC->count();
+        }
+    }
+    if( zPC->currentPosition() == 4 && waitCount <= 0 )
+    {
+        if( color->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || ( t->getVariableTyp() != STRING ) )
+            {
+                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__" );
+            // do nothing because the server does not need to show text
+            zPC->stepOut();
+            return 1;
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}
+
+
+SpielPause::SpielPause( Aktion *paused )
+    : Aktion( SPIEL_PAUSE )
+{
+    this->paused = paused;
+}
+
+SpielPause::~SpielPause()
+{
+    paused->release();
+}
+
+bool SpielPause::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    if( paused->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+    {
+        Variable *t = zMemory->zVariable( "__return__" );
+        if( !t || ( t->getVariableTyp() != BOOLEAN ) )
+            return 1;
+        zSpiel->setPausiert( ( (Boolean *)t )->getValue() );
+        return 1;
+    }
+}
+
+
+SpielEnde::SpielEnde( Aktion *gewinnerTeam )
+    : Aktion( SPIEL_ENDE )
+{
+    this->gewinnerTeam = gewinnerTeam;
+}
+
+SpielEnde::~SpielEnde()
+{
+    gewinnerTeam->release();
+}
+
+bool SpielEnde::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    if( gewinnerTeam->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+    {
+        Variable *t = zMemory->zVariable( "__return__" );
+        if( !t || ( t->getVariableTyp() != TEAM && t->getVariableTyp() != NICHTS ) )
+            return 1;
+        zSpiel->setEnde( t->getVariableTyp() == NICHTS ? 0 : (Team*)t );
+        return 1;
+    }
+}
+
+
+SpielerSetLevel::SpielerSetLevel( Aktion *level, Aktion *spieler )
+    : Aktion( SPIELER_SET_LEVEL )
+{
+    this->level = level;
+    this->spieler = spieler;
+}
+
+SpielerSetLevel::~SpielerSetLevel()
+{
+    level->release();
+    spieler->release();
+}
+
+bool SpielerSetLevel::runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount )
+{
+    zPC->stepIn();
+    if( zPC->currentPosition() == 0 )
+    {
+        if( level->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( spieler->runNext( zSpiel, zEreignis, zMemory, zPC, waitCount ) )
+        {
+            Variable *t = zMemory->zVariable( "__return__" );
+            if( !t || t->getVariableTyp() != SPIELER )
+            {
+                zPC->stepOut();
+                return 1;
+            }
+            ( (Spieler *)t )->setLevel( ( (Integer *)zMemory->zVariable( zPC->getUniqueString() + "R0__" ) )->getValue() );
+        }
+    }
+    zPC->stepOut();
+    return 0;
+}

+ 2 - 4
StickmanWorldOnline/Aktionen.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include "Variablen.h"
+#include <Array.h>
 
 class Spiel;
 class Ereignis;
@@ -223,19 +224,16 @@ enum AktionTyp
     SEQUENZ
 };
 
-class Aktion
+class Aktion : public Variable
 {
 private:
     AktionTyp typ;
-    int ref;
 
 public:
     Aktion( AktionTyp typ );
     virtual ~Aktion();
     // gibt 1 zurück, wenn die aktion vollständig ausgeführt wurde
     virtual bool runNext( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemory, ProgramCounter *zPC, double &waitCount ) = 0;
-    Aktion *getThis();
-    Aktion *release();
 };
 
 class KonstantNichts : public Aktion

+ 4 - 4
StickmanWorldOnline/Ereignis.cpp

@@ -20,22 +20,22 @@ void Ereignis::addParameter( const char *name, Variable *var )
     params.add( new VarPointer( name, var ) );
 }
 
-VarPointer *Ereignis::getParameter( const char *name ) const
+Variable *Ereignis::getParameter( const char *name ) const
 {
     for( auto v = params.getIterator(); v; v++ )
     {
         if( v->getName().istGleich( name ) )
-            return v->getThis();
+            return v->getVariable();
     }
     return 0;
 }
 
-VarPointer *Ereignis::zParameter( const char *name ) const
+Variable *Ereignis::zParameter( const char *name ) const
 {
     for( auto v = params.getIterator(); v; v++ )
     {
         if( v->getName().istGleich( name ) )
-            return v;
+            return v->zVariable();
     }
     return 0;
 }

+ 2 - 2
StickmanWorldOnline/Ereignis.h

@@ -44,8 +44,8 @@ public:
     ~Ereignis();
     EreignisTyp getTyp() const;
     void addParameter( const char *name, Variable *var );
-    VarPointer *getParameter( const char *name ) const;
-    VarPointer *zParameter( const char *name ) const;
+    Variable *getParameter( const char *name ) const;
+    Variable *zParameter( const char *name ) const;
     Ereignis *getThis();
     Ereignis *release();
 };

+ 7 - 0
StickmanWorldOnline/Spiel.cpp

@@ -353,6 +353,8 @@ void Spiel::setPausiert( bool pausiert )
 
 void Spiel::tick( double zeit )
 {
+    if( pause )
+        zeit = 0;
     // spieler bewegungen
     for( auto s = spieler.getIterator(); s; s++ )
     {
@@ -892,6 +894,11 @@ double Spiel::getRand()
     return randG.rand();
 }
 
+int Spiel::getTickCount() const
+{
+    return gameTicks;
+}
+
 StatistikV *Spiel::getStatistik() const
 {
     return stat->getThis();

+ 2 - 0
StickmanWorldOnline/Spiel.h

@@ -116,6 +116,8 @@ public:
     Trigger *getTrigger( int id ) const;
     int getNextId();
     double getRand();
+    int getTickCount() const;
+    void setEnde( Team *zGewinner );
     // constant
     StatistikV *getStatistik() const override;
     // Reference Counting 

+ 2 - 0
StickmanWorldOnline/Spieler.h

@@ -101,6 +101,8 @@ public:
     void setGeschossTempo( float tempo );
     void setArmor( float armor );
     void setLebensRegeneration( float reg );
+    // setzt alle eigenschafften, die mit dem level gesetzt werden entsprechend
+    void setLevel( int level );
     float getLebensRegenneration() const;
     float getArmor() const;
     float getGeschossTempo() const;

+ 1 - 0
StickmanWorldOnline/StickmanWorldOnline.vcxproj

@@ -77,6 +77,7 @@
     <IncludePath>..\..\..\..\..\Allgemein\Framework;..\..\..\..\..\Allgemein\Network\Network;../../../Framework/release;../../../Network/release;..\Linie;$(IncludePath)</IncludePath>
   </PropertyGroup>
   <ItemGroup>
+    <ClCompile Include="Aktionen.cpp" />
     <ClCompile Include="Bariere.cpp" />
     <ClCompile Include="Base.cpp" />
     <ClCompile Include="BosheitRune.cpp" />

+ 3 - 0
StickmanWorldOnline/StickmanWorldOnline.vcxproj.filters

@@ -132,6 +132,9 @@
     <ClCompile Include="Trigger.cpp">
       <Filter>Spiel\Auslöser</Filter>
     </ClCompile>
+    <ClCompile Include="Aktionen.cpp">
+      <Filter>Spiel\Auslöser</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="SpielKlasse.h">

+ 10 - 22
StickmanWorldOnline/Trigger.cpp

@@ -121,7 +121,7 @@ ProgramCounter::ProgramCounter()
 ProgramCounter::~ProgramCounter()
 {}
 
-void ProgramCounter::stepInto()
+void ProgramCounter::stepIn()
 {
     depth++;
     if( current.getEintragAnzahl() <= depth )
@@ -140,6 +140,14 @@ void ProgramCounter::stepOut()
     depth--;
 }
 
+Text ProgramCounter::getUniqueString() const
+{
+    Text ret = "__";
+    for( int i = 0; i < depth; i++ )
+        ret += Text( current.get( i ) ) + "__";
+    return ret;
+}
+
 int ProgramCounter::currentPosition() const
 {
     return current.get( depth );
@@ -187,27 +195,7 @@ bool Bedingung::check( Spiel *zSpiel, Ereignis *zEreignis )
     LocalMemory m;
     while( !expression->runNext( zSpiel, zEreignis, &m, &c, wait ) );
     Variable *var = m.zVariable( "__return__" );
-    if( !var )
-        return 0;
-    switch( var->getVariableTyp() )
-    {
-    case NICHTS:
-        return 0;
-    case INTEGER:
-        return ( (Integer *)var )->getValue() != 0;
-    case BOOLEAN:
-        return ( (Boolean *)var )->getValue();
-    case STRING:
-        return ( (String *)var )->getValue().getLength();
-    case FLOAT:
-        return ( (Float *)var )->getValue() != 0;
-    case TASTE:
-        return ( (Integer *)var )->getValue() != 0;
-    case GEGENSTAND_TYP:
-        return ( (GegenstandTypVar *)var )->getValue() != KEIN_GEGENSTAND;
-    default:
-        return 1;
-    }
+    return isTrue( var );
 }
 
 Bedingung *Bedingung::getThis()

+ 2 - 1
StickmanWorldOnline/Trigger.h

@@ -54,9 +54,10 @@ private:
 public:
     ProgramCounter();
     ~ProgramCounter();
-    void stepInto();
+    void stepIn();
     void count();
     void stepOut();
+    Text getUniqueString() const;
     int currentPosition() const;
     ProgramCounter *getThis();
     ProgramCounter *release();

+ 27 - 0
StickmanWorldOnline/Variablen.cpp

@@ -1,4 +1,5 @@
 #include "Variablen.h"
+#include "Gegenstand.h"
 
 
 Variable::Variable( VariableTyp typ )
@@ -29,6 +30,32 @@ Variable *Variable::release()
 }
 
 
+bool isTrue( Variable *v )
+{
+    if( !v )
+        return 0;
+    switch( v->getVariableTyp() )
+    {
+    case NICHTS:
+        return 0;
+    case INTEGER:
+        return ( (Integer *)v )->getValue() != 0;
+    case BOOLEAN:
+        return ( (Boolean *)v )->getValue();
+    case STRING:
+        return ( (String *)v )->getValue().getLength();
+    case FLOAT:
+        return ( (Float *)v )->getValue() != 0;
+    case TASTE:
+        return ( (Integer *)v )->getValue() != 0;
+    case GEGENSTAND_TYP:
+        return ( (GegenstandTypVar *)v )->getValue() != KEIN_GEGENSTAND;
+    default:
+        return 1;
+    }
+}
+
+
 Integer::Integer( int value, bool taste )
     : Variable( taste ? TASTE : INTEGER )
 {

+ 4 - 1
StickmanWorldOnline/Variablen.h

@@ -27,7 +27,8 @@ enum VariableTyp
     TUNNEL,
     UMLENKUNG,
     TRIGGER,
-    FEUERBALL_TREFFER
+    FEUERBALL_TREFFER,
+    AKTION
 };
 
 class Variable
@@ -44,6 +45,8 @@ public:
     Variable *release();
 };
 
+bool isTrue( Variable *v );
+
 class Integer : public Variable
 {
 private: