shithub: rott

Download patch

ref: ef770bb2842cf0b3018326ee00fb94a798003973
parent: 482697a25274f008c951a2ef73d79dd018ab5018
author: levesqu8 <levesqu8@msu.edu>
date: Sun Oct 1 16:27:37 EDT 2017

wrote find empty slot code

--- a/rott/rt_actor.c
+++ b/rott/rt_actor.c
@@ -3622,11 +3622,11 @@
         case dfiremonkobj:
             return gamestate.TimeCount/VBLCOUNTER + 175;
             break;
-    
+        default:
+            Error("DeterminetimeUntilEnemyIsResurrected was given a case it couldn't handle");
+            break;
     }
-
-
-
+    
 }
 
 
@@ -3634,14 +3634,31 @@
 
 extern resItem* enemiesToRes;
 extern unsigned int freeSlot;
+int numOfNonGibbedEnemies = 0;
 void AddEnemyToResurrectList(resItem * res)
 {
     res->timeOfResurrect = DetermineTimeUntilEnemyIsResurrected(res->actor->obclass);
-    //res->timeOfResurrect = gamestate.TimeCount/VBLCOUNTER;
     objtype * actor = res->actor;
+    resItem* compareWith;
+    compareWith = 0;
     SetReverseDeathState(actor);
+    if (!ZomROTTResFreeSlots[freeSlot])
+    {
+        //FIND AN EMPTY SLOT
+        for(freeSlot; ZomROTTResFreeSlots[freeSlot] != false; freeSlot++)
+        {
+            if (freeSlot >= sizeof(*enemiesToRes))
+            {
+                freeSlot = 0;
+            }
+        }
+    }
+    res->isInitialized = 1;
+    
     enemiesToRes[freeSlot] = *res;
+    ZomROTTResFreeSlots[freeSlot] = false;
     freeSlot++;
+    numOfNonGibbedEnemies++;
 }
 
 void CleanUpResurrectList()
@@ -3653,6 +3670,7 @@
 void FreeUpResurrectList()
 {
     free(enemiesToRes);
+    free(ZomROTTResFreeSlots);
 }
 
 void SetAfterResurrectState(objtype * actor, statetype * doWhat)
@@ -3711,6 +3729,7 @@
     ConnectAreas();
 }
 
+
 void ResurrectEnemies()
 {   
     resItem * thing;
@@ -3719,17 +3738,22 @@
     {
         return;
     }
-    
-    for (thing = &enemiesToRes[0]; thing < &enemiesToRes[freeSlot]; thing++)
+    int index = 0;
+    for (thing = &enemiesToRes[0]; thing < &enemiesToRes[sizeof(*enemiesToRes)]; thing++)
     {
-        if (gamestate.TimeCount/(VBLCOUNTER) >= thing->timeOfResurrect)
+        if (thing->isInitialized == 0)
         {
+            continue;
+        }
+        else if (gamestate.TimeCount/(VBLCOUNTER) >= thing->timeOfResurrect)
+        {
             SD_PlaySoundRTP(SD_PLAYERSPAWNSND, thing->actor->x, thing->actor->y);
             SpawnDuringGameWithState (thing->actor->obclass,thing->actor->tilex,thing->actor->tiley,thing->actor->dir, 1, thing->actor->state);
-            thing = 0;
-            freeSlot--;
+            thing->isInitialized = 0;
+            ZomROTTResFreeSlots[index] = true;
         }   
-    }    
+        index++;
+    }
     //CleanUpResurrectList();
     
 }
--- a/rott/rt_actor.h
+++ b/rott/rt_actor.h
@@ -261,7 +261,7 @@
 
 typedef struct resStruct
 {
-    unsigned int timeBeforeResurrect;
+    short isInitialized;
     unsigned int timeOfResurrect;
     objtype * actor;
 } resItem;
@@ -303,6 +303,9 @@
     int     numgibs;
     boolean elevatormusicon;
 } misc_stuff;
+
+boolean * ZomROTTResFreeSlots;
+
 
 
 extern  boolean          ludicrousgibs;
--- a/rott/rt_main.c
+++ b/rott/rt_main.c
@@ -1857,6 +1857,7 @@
 
 
 extern boolean enableZomROTT;
+extern int numOfNonGibbedEnemies;
 void UpdateGameObjects ( void )
 {
     int j;
@@ -1893,7 +1894,7 @@
         UpdateLightning ();
         TriggerStuff();
         CheckCriticalStatics();
-        if (enableZomROTT)
+        if (enableZomROTT && numOfNonGibbedEnemies > 0)
             ResurrectEnemies();
 
         
--- a/rott/rt_ted.c
+++ b/rott/rt_ted.c
@@ -5666,18 +5666,23 @@
     DoLowMemoryConversionIconPlane ();
 }
 
-extern objtype * enemiesToRes = NULL;
-extern int freeSlot = 0;
+objtype * enemiesToRes = NULL;
+int freeSlot = 0;
+
+
 void SetupZomROTTStuff()
 {
+    resItem uninitializedRes;
+    uninitializedRes.isInitialized = false;
     if (enemiesToRes)
     {
         FreeUpResurrectList();
     }
     enemiesToRes = calloc(sizeof(resItem), gamestate.killtotal);
-    memset(enemiesToRes, 0, sizeof(enemiesToRes));
-    
-    freeSlot = 0;
+    memset(enemiesToRes, &uninitializedRes, sizeof(*enemiesToRes));
+    ZomROTTResFreeSlots = calloc(sizeof(int), gamestate.killtotal);
+    memset(ZomROTTResFreeSlots, true, sizeof(*ZomROTTResFreeSlots));
+    //freeSlot = 0;
 }
 
 /*
--