Browse Source

Auto schaltung/verschiebung von barieren hinzugefügt

Kolja Strohm 4 years ago
parent
commit
1abb26eb4a

+ 1 - 1
StickmanWorldOnline/Aktionen.cpp

@@ -1134,7 +1134,7 @@ void IntegerZufall::run( Spiel *zSpiel, Ereignis *zEreignis, LocalMemory *zMemor
 {
     int mi = ( (Integer *)zParam( 0 ) )->getValue();
     int ma = ( (Integer *)zParam( 1 ) )->getValue();
-    setReturn( new Integer( (int)( zSpiel->getRand() * ( (__int64)ma - mi ) + mi ) ) );
+    setReturn( new Integer( (int)( zSpiel->getRand() * ( (double)ma - mi ) + mi ) ) );
 }
 
 

+ 56 - 0
StickmanWorldOnline/Spiel.cpp

@@ -62,6 +62,8 @@ Spiel::Spiel()
     zuletztBenutzterTunnel = 0;
     zuletztBenutzteUmlenkung = 0;
     resources = 0;
+    nextAutoVerschiebung = 10;
+    nextAutoSchaltung = 10;
     ref = 1;
 }
 
@@ -159,6 +161,60 @@ bool Spiel::istAmLeben() const
 void Spiel::tick()
 {
     rZeit -= TICK;// spieler bewegungen
+    nextAutoVerschiebung -= TICK;
+    nextAutoSchaltung -= TICK;
+    if( nextAutoVerschiebung <= 0 )
+    {
+        nextAutoVerschiebung += 30 + randG.rand() * 30;
+        int anz = 0;
+        for( auto b = barieren.getIterator(); b; b++ )
+        {
+            if( b->hatStyle( Bariere::Style::AutoVerschiebung ) )
+                anz++;
+        }
+        if( anz )
+        {
+            int rand = (int)( randG.rand() * anz );
+            for( auto b = barieren.getIterator(); b; b++ )
+            {
+                if( b->hatStyle( Bariere::Style::AutoVerschiebung ) )
+                {
+                    if( rand == 0 )
+                    {
+                        b->startAutoVerschiebung( this );
+                        break;
+                    }
+                    rand--;
+                }
+            }
+        }
+    }
+    if( nextAutoSchaltung <= 0 )
+    {
+        nextAutoSchaltung += 30 + randG.rand() * 30;
+        int anz = 0;
+        for( auto b = barieren.getIterator(); b; b++ )
+        {
+            if( b->hatStyle( Bariere::Style::AutoSchaltung ) )
+                anz++;
+        }
+        if( anz )
+        {
+            int rand = (int)( randG.rand() * anz );
+            for( auto b = barieren.getIterator(); b; b++ )
+            {
+                if( b->hatStyle( Bariere::Style::AutoSchaltung ) )
+                {
+                    if( rand == 0 )
+                    {
+                        b->startAutoSchaltung( this );
+                        break;
+                    }
+                    rand--;
+                }
+            }
+        }
+    }
     for( auto s = spieler.getIterator(); s; s++ )
     {
         s->move( TICK );

+ 2 - 0
StickmanWorldOnline/Spiel.h

@@ -99,6 +99,8 @@ private:
     int spielerNummer;
     char *tasten;
     bool pause;
+    double nextAutoVerschiebung;
+    double nextAutoSchaltung;
     int ref;
 
     bool istAmLeben() const;

+ 3 - 1
StickmanWorldOnline/Spieler.cpp

@@ -511,8 +511,10 @@ void Spieler::tick( double zeit, Spiel *zSpiel )
         {
             Resource *t = e->getCurrentResource();
             if( t )
+            {
                 r->release();
-            r = t;
+                r = t;
+            }
         }
         currentNext -= zeit;
         if( currentNext <= 0 )