shithub: rott

Download patch

ref: e02d630d4cc952b0e71f10b01d0377e1455fa1ac
parent: 90585736cf4c536224028466119d311446d1febd
author: levesqu8 <levesqu8@msu.edu>
date: Mon Oct 16 22:21:17 EDT 2017

Revert because stuff broke

This reverts commit 4354eb4c578d4536614333615b2edd1c51d71d88.

--- a/rott/Makefile
+++ b/rott/Makefile
@@ -82,7 +82,6 @@
 OBJS += byteordr.o
 OBJS += dukemusc.o
 OBJS += winrott.o
-OBJS += queue.o
 
 AUDIOLIB := audiolib/audiolib.a
 
--- a/rott/queue.c
+++ /dev/null
@@ -1,108 +1,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "Queue.h"
-
-//Fetched from https://codereview.stackexchange.com/questions/141238/implementing-a-generic-queue-in-c
-
-
-void queueInit(Queue *q, size_t memSize)
-{
-   q->sizeOfQueue = 0;
-   q->memSize = memSize;
-   q->head = q->tail = NULL;
-}
-
-int enqueue(Queue *q, const void *data)
-{
-    node *newNode = (node *)malloc(sizeof(node));
-
-    if(newNode == NULL)
-    {
-        return -1;
-    }
-
-    newNode->data = malloc(q->memSize);
-
-    if(newNode->data == NULL)
-    {
-        free(newNode);
-        return -1;
-    }
-
-    newNode->next = NULL;
-
-    memcpy(newNode->data, data, q->memSize);
-
-    if(q->sizeOfQueue == 0)
-    {
-        q->head = q->tail = newNode;
-    }
-    else
-    {
-        q->tail->next = newNode;
-        q->tail = newNode;
-    }
-
-    q->sizeOfQueue++;
-    return 0;
-}
-
-void dequeue(Queue *q, void *data)
-{
-    if(q->sizeOfQueue > 0)
-    {
-        node *temp = q->head;
-        memcpy(data, temp->data, q->memSize);
-
-        if(q->sizeOfQueue > 1)
-        {
-            q->head = q->head->next;
-        }
-        else
-        {
-            q->head = NULL;
-            q->tail = NULL;
-        }
-
-        q->sizeOfQueue--;
-        free(temp->data);
-        free(temp);
-    }
-}
-
-void queuePeek(Queue *q, void *data)
-{
-    if(q->sizeOfQueue > 0)
-    {
-       node *temp = q->head;
-       memcpy(data, temp->data, q->memSize);
-    }
-}
-
-void clearQueue(Queue *q)
-{
-  node *temp;
-
-  while(q->sizeOfQueue > 0)
-  {
-      temp = q->head;
-      q->head = temp->next;
-      free(temp->data);
-      free(temp);
-      q->sizeOfQueue--;
-  }
-
-  q->head = q->tail = NULL;
-}
-
-int getQueueSize(Queue *q)
-{
-    return q->sizeOfQueue;
-}
\ No newline at end of file
--- a/rott/queue.h
+++ /dev/null
@@ -1,28 +1,0 @@
-#ifndef QUEUE_H_INCLUDED
-#define QUEUE_H_INCLUDED
-
-//Fetched from https://codereview.stackexchange.com/questions/141238/implementing-a-generic-queue-in-c
-
-
-typedef struct Node
-{
-  void *data;
-  struct Node *next;
-}node;
-
-typedef struct QueueList
-{
-    int sizeOfQueue;
-    size_t memSize;
-    node *head;
-    node *tail;
-}Queue;
-
-void queueInit(Queue *q, size_t memSize);
-int enqueue(Queue *, const void *);
-void dequeue(Queue *, void *);
-void queuePeek(Queue *, void *);
-void clearQueue(Queue *);
-int getQueueSize(Queue *);
-
-#endif /* QUEUE_H_INCLUDED */
\ No newline at end of file
--- a/rott/rt_actor.c
+++ b/rott/rt_actor.c
@@ -58,7 +58,6 @@
 #include "fx_man.h"
 //MED
 #include "memcheck.h"
-#include "queue.h"
 
 
 
@@ -3633,20 +3632,44 @@
     
 }
 
-extern Queue enemiesToRes;
+extern resItem* enemiesToRes;
 extern unsigned int freeSlot;
-//extern STACK s;
-void AddEnemyToResurrectList(objtype * ob)
+void AddEnemyToResurrectList(resItem * res)
 {
-    ob->resurrectAtTime = DetermineTimeUntilEnemyIsResurrected(ob->obclass);
-    SetReverseDeathState(ob);
-    //freeSlot = pop();
-    enqueue(&enemiesToRes, ob);
+    int timeOfResurrect = DetermineTimeUntilEnemyIsResurrected(res->actor->obclass);
+    objtype * actor = res->actor;
+    SetReverseDeathState(actor);
+    if (ZomROTTResFreeSlots[freeSlot])
+    {
+        //FIND AN EMPTY SLOT
+        for(freeSlot; ZomROTTResFreeSlots[freeSlot] == false; freeSlot++)
+        {
+            if (freeSlot >= sizeof(*enemiesToRes))
+            {
+                Error("ZomROTT couldn't find a free slot to insert entry in!");
+            }
+        }
+    }
+    resItem newEntry;
+    
+    newEntry.actor = actor;
+    newEntry.isInitialized = 1;
+    newEntry.timeOfResurrect = timeOfResurrect;
+    
+    enemiesToRes[freeSlot] = newEntry;
+    ZomROTTResFreeSlots[freeSlot] = false;
 }
 
+void CleanUpResurrectList()
+{
+    memset(enemiesToRes, 0, sizeof(*enemiesToRes));
+    freeSlot = 0;
+}
+
 void FreeUpResurrectList()
 {
-    clearQueue(&enemiesToRes);
+    free(enemiesToRes);
+    free(ZomROTTResFreeSlots);
 }
 
 void SetAfterResurrectState(objtype * actor, statetype * doWhat)
@@ -3705,27 +3728,74 @@
     ConnectAreas();
 }
 
+
 void ResurrectEnemies()
 {   
-    objtype * actor;
+    resItem * thing;
     
-    int currTime = gamestate.TimeCount/VBLCOUNTER;
-    
-    int killTotal = gamestate.killtotal;
-    
     int index = 0;
-    
-    actor = enemiesToRes.head->data;
-    
-    if (currTime >= actor->resurrectAtTime)
+    for (thing = &enemiesToRes[0]; thing < &enemiesToRes[sizeof(*enemiesToRes)]; thing++, index++)
     {
-        //dequeue(&enemiesToRes, actor);
-        SD_PlaySoundRTP(SD_PLAYERSPAWNSND, actor->x, actor->y);
-        SpawnDuringGameWithState (actor->obclass,actor->tilex,actor->tiley,actor->dir, 1, actor->state);
-        dequeue(&enemiesToRes, actor);
+        if (thing->timeOfResurrect == 0)
+        {
+            continue;
+        }
+        else if (gamestate.TimeCount/(VBLCOUNTER) >= thing->timeOfResurrect && ZomROTTResFreeSlots[index] == false)
+        {
+            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->timeOfResurrect = 0;
+            ZomROTTResFreeSlots[index] = true;
+        }
     }
 }
 
+/*
+void SetStandAfterResurrect(objtype * actor)
+{
+    switch(actor->obclass)
+    {
+        case lowguardobj:
+            SetAfterResurrectState(actor, &s_lowgrdstand);
+            //actor->state = &s_lowgrdchase1;
+            break;
+        case highguardobj:
+            SetAfterResurrectState(actor, &s_highgrdstand);
+            //actor->state = &s_highgrdchase1;
+            break;
+        case strikeguardobj:
+            SetAfterResurrectState(actor, &s_strikestand);
+            //actor->state = &s_strikechase1;
+            break;
+        case blitzguardobj:
+            SetAfterResurrectState(actor, &s_blitzstand);
+            //actor->state = &s_blitzchase1;
+            break;
+        case triadenforcerobj:
+            SetAfterResurrectState(actor, &s_enforcerstand);
+            //actor->state = &s_enforcerchase1;
+            break;
+        case overpatrolobj:
+            SetAfterResurrectState(actor, &s_opstand);
+            //actor->state = &s_opchase1;
+            break;
+        case deathmonkobj:
+            SetAfterResurrectState(actor, &s_dmonkstand);
+            //actor->state = &s_dmonkchase1;
+            break;
+        case dfiremonkobj:
+            SetAfterResurrectState(actor, &s_firemonkstand);
+            //actor->state = &s_firemonkchase1;
+            break;
+        default:
+            Error("SetStandAfterResurrect was called with something that can't be handled!");
+            break;
+    }
+}
+*/
+
+
+
 void SpawnDuringGame (classtype which, int tilex, int tiley, int dir, int ambush)
 {   
     statetype *temp;
@@ -3775,16 +3845,14 @@
 
 void SaveResurrectList(byte ** buffer, int *size)
 {
-/*
-    byte*tptr;
+    byte * tptr;
     
     *size = sizeof(enemiesToRes);
     *buffer = (byte*)SafeMalloc(*size);
     tptr = *buffer;
     
-    memcpy(tptr, enemiesToRes, sizeof(enemiesToRes));
+    memcpy(tptr, enemiesToRes, sizeof(*enemiesToRes));
     tptr += sizeof(enemiesToRes);
-*/
 
 }
 
@@ -3826,7 +3894,11 @@
         
         memcpy(copyOfObject, ob, sizeof(objtype));
         
-        AddEnemyToResurrectList(copyOfObject);
+        resItem * thingToAdd = malloc(sizeof(resItem));
+        
+        thingToAdd->actor = copyOfObject;
+        
+        AddEnemyToResurrectList(thingToAdd);
     }
 
     if ((ob->obclass == patrolgunobj) && (ob->temp1 == -1))
@@ -3897,7 +3969,6 @@
 {
     playertype *pstate;
     M_LINKSTATE(ob,pstate);
-
 
     ob->flags &= ~(FL_ELASTO|FL_GODMODE|FL_DOGMODE|FL_NOFRICTION|FL_RIDING);
 
--- a/rott/rt_actor.h
+++ b/rott/rt_actor.h
@@ -27,7 +27,6 @@
 //***************************************************************************
 
 #include "states.h"
-#include "queue.h"
 
 
 #define FL_SYNCED          0x400
@@ -257,10 +256,19 @@
     struct objstruct         *next, *prev;
     struct objstruct         *nextactive, *prevactive;
     struct objstruct         *nextinarea, *previnarea;
-    int resurrectAtTime;
+
 } objtype;
 
+typedef struct resStruct
+{
+    short isInitialized;
+    unsigned int timeOfResurrect;
+    objtype * actor;
+} resItem;
 
+
+
+
 typedef struct b_struct
 {   int   NMErotate;
     int   NMEdirstried;
@@ -295,6 +303,8 @@
     int     numgibs;
     boolean elevatormusicon;
 } misc_stuff;
+
+boolean * ZomROTTResFreeSlots;
 
 
 
--- a/rott/rt_cfg.c
+++ b/rott/rt_cfg.c
@@ -1774,7 +1774,7 @@
     SafeWriteString(file, "\n;\n");
     SafeWriteString(file, "; 1 - Enemies equipped with pistols have a chance of dropping an extra pistol when killed.\n");
     SafeWriteString(file, "; 0 - Enemies will not drop extra pistols at all. (Default)\n");
-    WriteParameter(file, "EnableExtraPistolDrops     ", enableExtraPistolDrops);
+    WriteParameter(file, "EnableExtraPistolDrop     ", enableExtraPistolDrops);
     
     // Write out MouseEnabled
 
--- a/rott/rt_game.c
+++ b/rott/rt_game.c
@@ -5239,7 +5239,7 @@
 //******************************************************************************
 
 
-extern objtype* enemiesToRes;
+extern resItem* enemiesToRes;
 extern unsigned int freeSlot;
 
 boolean LoadTheGame (int num, gamestorage_t * game)
@@ -5569,8 +5569,7 @@
     //ZomROTT Stuff
     if(enableZomROTT)
     {
-/*
-        enemiesToRes = calloc(sizeof(objtype), gamestate.killtotal);
+        enemiesToRes = calloc(sizeof(resItem), gamestate.killtotal);
         memset(enemiesToRes, 0, sizeof(*enemiesToRes));
         size = sizeof(enemiesToRes);
         memcpy(enemiesToRes, bufptr, size);
@@ -5582,7 +5581,6 @@
         {
             freeSlot++;
         }
-*/
     }
 
     // Set the viewsize
--- a/rott/rt_main.c
+++ b/rott/rt_main.c
@@ -1894,7 +1894,7 @@
         UpdateLightning ();
         TriggerStuff();
         CheckCriticalStatics();
-        if (enableZomROTT && gamestate.killcount > 0)
+        if (enableZomROTT)
         {
             ResurrectEnemies();
         }
--- a/rott/rt_ted.c
+++ b/rott/rt_ted.c
@@ -66,7 +66,6 @@
 #include "rt_net.h"
 //MED
 #include "memcheck.h"
-#include "queue.h"
 
 
 
@@ -5667,15 +5666,23 @@
     DoLowMemoryConversionIconPlane ();
 }
 
+objtype * enemiesToRes = NULL;
 int freeSlot = 0;
-Queue enemiesToRes;
+
+
 void SetupZomROTTStuff()
 {
-    if (enemiesToRes.head != NULL && enemiesToRes.tail != NULL)
+    resItem * uninitializedRes = malloc(sizeof(resItem));
+    uninitializedRes->isInitialized=false;
+    if (enemiesToRes)
     {
-        clearQueue(&enemiesToRes);
+        FreeUpResurrectList();
     }
-    queueInit(&enemiesToRes, sizeof(objtype));
+    enemiesToRes = calloc(sizeof(resItem), gamestate.killtotal);
+    memset(enemiesToRes, uninitializedRes, sizeof(*enemiesToRes));
+    ZomROTTResFreeSlots = calloc(sizeof(int), gamestate.killtotal);
+    memset(ZomROTTResFreeSlots, true, sizeof(*ZomROTTResFreeSlots));
+    //freeSlot = 0;
 }
 
 /*