diff --git a/source/exhumed/src/anubis.cpp b/source/exhumed/src/anubis.cpp index 4d42b7b06..732ef30a3 100644 --- a/source/exhumed/src/anubis.cpp +++ b/source/exhumed/src/anubis.cpp @@ -32,9 +32,7 @@ struct Anubis short nAction; short nSprite; short nTarget; - short f; - short g; - short h; + short nCount; }; static TArray AnubisList; @@ -67,9 +65,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, Anubis& w, Anubis* ("action", w.nAction) ("sprite", w.nSprite) ("target", w.nTarget) - ("f", w.f) - ("g", w.g) - ("h", w.h) + ("count", w.nCount) .EndObject(); } return arc; @@ -151,7 +147,7 @@ int BuildAnubis(int nSprite, int x, int y, int z, int nSector, int nAngle, uint8 ap->nFrame = 0; ap->nSprite = nSprite; ap->nTarget = -1; - ap->g = 0; + ap->nCount = 0; sp->owner = runlist_AddRunRec(sp->lotag - 1, nAnubis | 0x90000); @@ -276,13 +272,13 @@ void FuncAnubis(int a, int nDamage, int nRun) default: { - if (ap->g) + if (ap->nCount) { - ap->g--; + ap->nCount--; } else { - ap->g = 60; + ap->nCount = 60; if (nTarget > -1) // NOTE: nTarget can be -1. this check wasn't in original code. TODO: demo compatiblity? { @@ -308,7 +304,7 @@ void FuncAnubis(int a, int nDamage, int nRun) if (nTarget == -1) { ap->nAction = 0; - ap->g = 50; + ap->nCount = 50; } else { @@ -405,7 +401,7 @@ void FuncAnubis(int a, int nDamage, int nRun) { ap->nAction = 0; ap->nFrame = 0; - ap->g = 100; + ap->nCount = 100; ap->nTarget = -1; sp->xvel = 0; diff --git a/source/exhumed/src/fish.cpp b/source/exhumed/src/fish.cpp index d81090e15..ad43f1d1f 100644 --- a/source/exhumed/src/fish.cpp +++ b/source/exhumed/src/fish.cpp @@ -25,14 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS -enum -{ - kMaxFishes = 128, - kMaxChunks = 128 -}; - -short FishCount = 0; - static actionSeq FishSeq[] = { {8, 0}, {8, 0}, @@ -46,9 +38,6 @@ static actionSeq FishSeq[] = { {39, 1} }; -short nChunksFree; - -int nFreeChunk[kMaxChunks] = { 0 }; struct Fish { @@ -57,59 +46,72 @@ struct Fish short nAction; short nSprite; short nTarget; - short field_A; - short field_C; + short nCount; short nRun; }; struct Chunk { short nSprite; - short field_2; - short field_4; - short field_6; + short nIndex; + short nSeqIndex; }; -Fish FishList[kMaxFishes]; -Chunk FishChunk[kMaxChunks]; +TArray FishList; +TArray FishChunk; -static SavegameHelper sghfish("fish", - SV(FishCount), - SV(nChunksFree), - SA(nFreeChunk), - SA(FishList), - SA(FishChunk), - nullptr); +FSerializer& Serialize(FSerializer& arc, const char* keyname, Fish& w, Fish* def) +{ + if (arc.BeginObject(keyname)) + { + arc("health", w.nHealth) + ("frame", w.nFrame) + ("action", w.nAction) + ("sprite", w.nSprite) + ("target", w.nTarget) + ("run", w.nRun) + ("count", w.nCount) + .EndObject(); + } + return arc; +} +FSerializer& Serialize(FSerializer& arc, const char* keyname, Chunk& w, Chunk* def) +{ + if (arc.BeginObject(keyname)) + { + arc ("sprite", w.nSprite) + ("index", w.nIndex) + ("seqindex", w.nSeqIndex) + .EndObject(); + } + return arc; +} + +void SerializeFish(FSerializer& arc) +{ + arc("fish", FishList) + ("fishchunk", FishChunk); +} void InitFishes() { - FishCount = 0; - nChunksFree = kMaxChunks; - - for (int i = 0; i < kMaxChunks; i++) { - nFreeChunk[i] = i; - } + FishList.Clear(); + FishChunk.Clear(); } int BuildFishLimb(short nFish, short edx) { - if (nChunksFree <= 0) { - return -1; - } - short nSprite = FishList[nFish].nSprite; - nChunksFree--; - - int nFree = nFreeChunk[nChunksFree]; + int nFree = FishChunk.Reserve(1); int nSprite2 = insertsprite(sprite[nSprite].sectnum, 99); assert(nSprite2 >= 0 && nSprite2 < kMaxSprites); FishChunk[nFree].nSprite = nSprite2; - FishChunk[nFree].field_4 = edx + 40; - FishChunk[nFree].field_2 = RandomSize(3) % SeqSize[SeqOffsets[kSeqFish] + edx + 40]; + FishChunk[nFree].nSeqIndex = edx + 40; + FishChunk[nFree].nIndex = RandomSize(3) % SeqSize[SeqOffsets[kSeqFish] + edx + 40]; sprite[nSprite2].x = sprite[nSprite].x; sprite[nSprite2].y = sprite[nSprite].y; @@ -125,7 +127,7 @@ int BuildFishLimb(short nFish, short edx) sprite[nSprite2].yoffset = 0; sprite[nSprite2].zvel = (-(RandomByte() + 512)) * 2; - seq_GetSeqPicnum(kSeqFish, FishChunk[nFree].field_4, 0); + seq_GetSeqPicnum(kSeqFish, FishChunk[nFree].nSeqIndex, 0); sprite[nSprite2].picnum = edx; sprite[nSprite2].lotag = runlist_HeadRun() + 1; @@ -151,7 +153,7 @@ void FuncFishLimb(int a, int, int nRun) short nSprite = FishChunk[nFish].nSprite; assert(nSprite >= 0 && nSprite < kMaxSprites); - int nSeq = SeqOffsets[kSeqFish] + FishChunk[nFish].field_4; + int nSeq = SeqOffsets[kSeqFish] + FishChunk[nFish].nSeqIndex; int nMessage = a & kMessageMask; @@ -159,15 +161,15 @@ void FuncFishLimb(int a, int, int nRun) { case 0x20000: { - sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, FishChunk[nFish].field_2); + sprite[nSprite].picnum = seq_GetSeqPicnum2(nSeq, FishChunk[nFish].nIndex); Gravity(nSprite); - FishChunk[nFish].field_2++; + FishChunk[nFish].nIndex++; - if (FishChunk[nFish].field_2 >= SeqSize[nSeq]) + if (FishChunk[nFish].nIndex >= SeqSize[nSeq]) { - FishChunk[nFish].field_2 = 0; + FishChunk[nFish].nIndex = 0; if (RandomBit()) { BuildBlood(sprite[nSprite].x, sprite[nSprite].y, sprite[nSprite].z, sprite[nSprite].sectnum); } @@ -208,7 +210,7 @@ void FuncFishLimb(int a, int, int nRun) case 0x90000: { - seq_PlotSequence(a & 0xFFFF, nSeq, FishChunk[nFish].field_2, 1); + seq_PlotSequence(a & 0xFFFF, nSeq, FishChunk[nFish].nIndex, 1); return; } } @@ -216,12 +218,7 @@ void FuncFishLimb(int a, int, int nRun) int BuildFish(int nSprite, int x, int y, int z, int nSector, int nAngle) { - short nFish = FishCount; - FishCount++; - - if (nFish >= kMaxFishes) { - return -1; - } + int nFish = FishList.Reserve(1); if (nSprite == -1) { @@ -264,7 +261,7 @@ int BuildFish(int nSprite, int x, int y, int z, int nSector, int nAngle) FishList[nFish].nHealth = 200; FishList[nFish].nSprite = nSprite; FishList[nFish].nTarget = -1; - FishList[nFish].field_C = 60; + FishList[nFish].nCount = 60; FishList[nFish].nFrame = 0; sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nFish | 0x120000); @@ -315,7 +312,7 @@ void DestroyFish(short nFish) void FuncFish(int a, int nDamage, int nRun) { short nFish = RunData[nRun].nVal; - assert(nFish >= 0 && nFish < kMaxFishes); + assert(nFish >= 0 && nFish < (int)FishList.Size()); short nSprite = FishList[nFish].nSprite; short nAction = FishList[nFish].nAction; @@ -349,7 +346,7 @@ void FuncFish(int a, int nDamage, int nRun) return; } - FishList[nFish].field_C = 10; + FishList[nFish].nCount = 10; } // fall through fallthrough__; @@ -396,7 +393,7 @@ void FuncFish(int a, int nDamage, int nRun) FishList[nFish].nAction = 4; FishList[nFish].nFrame = 0; - FishList[nFish].field_C += 10; + FishList[nFish].nCount += 10; } return; @@ -429,8 +426,8 @@ void FuncFish(int a, int nDamage, int nRun) case 0: { - FishList[nFish].field_C--; - if (FishList[nFish].field_C <= 0) + FishList[nFish].nCount--; + if (FishList[nFish].nCount <= 0) { nTarget = FindPlayer(nSprite, 60); if (nTarget >= 0) @@ -442,7 +439,7 @@ void FuncFish(int a, int nDamage, int nRun) int nAngle = GetMyAngle(sprite[nTarget].x - sprite[nSprite].x, sprite[nTarget].z - sprite[nSprite].z); sprite[nSprite].zvel = bsin(nAngle, -5); - FishList[nFish].field_C = RandomSize(6) + 90; + FishList[nFish].nCount = RandomSize(6) + 90; } else { @@ -459,8 +456,8 @@ void FuncFish(int a, int nDamage, int nRun) case 2: case 3: { - FishList[nFish].field_C--; - if (FishList[nFish].field_C <= 0) + FishList[nFish].nCount--; + if (FishList[nFish].nCount <= 0) { IdleFish(nFish, 0); return; diff --git a/source/exhumed/src/lion.cpp b/source/exhumed/src/lion.cpp index 95874e725..e90ce21ae 100644 --- a/source/exhumed/src/lion.cpp +++ b/source/exhumed/src/lion.cpp @@ -52,8 +52,8 @@ struct Lion short nAction; short nSprite; short nTarget; - short _f; - short _g; + short nIndex; + short nCount; }; Lion LionList[kMaxLions]; @@ -121,8 +121,8 @@ int BuildLion(short nSprite, int x, int y, int z, short nSector, short nAngle) LionList[nLion].nFrame = 0; LionList[nLion].nSprite = nSprite; LionList[nLion].nTarget = -1; - LionList[nLion]._g = 0; - LionList[nLion]._f = nLion; + LionList[nLion].nCount = 0; + LionList[nLion].nIndex = nLion; sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nLion | 0x130000); @@ -220,7 +220,7 @@ void FuncLion(int a, int nDamage, int nRun) { PlotCourseToSprite(nSprite, nTarget); LionList[nLion].nAction = 5; - LionList[nLion]._g = RandomSize(3); + LionList[nLion].nCount = RandomSize(3); sprite[nSprite].ang = (sprite[nSprite].ang - (RandomSize(1) << 8)) + (RandomSize(1) << 8); // NOTE: no angle mask in original code } else @@ -271,7 +271,7 @@ void FuncLion(int a, int nDamage, int nRun) case 0: case 1: { - if ((LionList[nLion]._f & 0x1F) == (totalmoves & 0x1F)) + if ((LionList[nLion].nIndex & 0x1F) == (totalmoves & 0x1F)) { if (nTarget < 0) { @@ -292,8 +292,8 @@ void FuncLion(int a, int nDamage, int nRun) if (nAction) { - LionList[nLion]._g--; - if (LionList[nLion]._g <= 0) + LionList[nLion].nCount--; + if (LionList[nLion].nCount <= 0) { if (RandomBit()) { @@ -307,7 +307,7 @@ void FuncLion(int a, int nDamage, int nRun) sprite[nSprite].yvel = 0; } - LionList[nLion]._g = 100; + LionList[nLion].nCount = 100; } } @@ -316,7 +316,7 @@ void FuncLion(int a, int nDamage, int nRun) case 2: { - if ((totalmoves & 0x1F) == (LionList[nLion]._f & 0x1F)) + if ((totalmoves & 0x1F) == (LionList[nLion].nIndex & 0x1F)) { PlotCourseToSprite(nSprite, nTarget); @@ -388,7 +388,7 @@ void FuncLion(int a, int nDamage, int nRun) if (nTarget == -1) { LionList[nLion].nAction = 1; - LionList[nLion]._g = 50; + LionList[nLion].nCount = 50; } else { @@ -424,11 +424,11 @@ void FuncLion(int a, int nDamage, int nRun) case 5: // Jump away when damaged { - LionList[nLion]._g--; - if (LionList[nLion]._g <= 0) + LionList[nLion].nCount--; + if (LionList[nLion].nCount <= 0) { sprite[nSprite].zvel = -4000; - LionList[nLion]._g = 0; + LionList[nLion].nCount = 0; int x = sprite[nSprite].x; int y = sprite[nSprite].y; @@ -492,7 +492,7 @@ void FuncLion(int a, int nDamage, int nRun) { LionList[nLion].nAction = 7; sprite[nSprite].ang = (GetWallNormal(nMov & 0x3FFF) + 1024) & kAngleMask; - LionList[nLion]._g = RandomSize(4); + LionList[nLion].nCount = RandomSize(4); return; } else if ((nMov & 0xC000) == 0xC000) @@ -521,11 +521,11 @@ void FuncLion(int a, int nDamage, int nRun) case 7: { - LionList[nLion]._g--; + LionList[nLion].nCount--; - if (LionList[nLion]._g <= 0) + if (LionList[nLion].nCount <= 0) { - LionList[nLion]._g = 0; + LionList[nLion].nCount = 0; if (nTarget > -1) { PlotCourseToSprite(nSprite, nTarget); @@ -588,7 +588,7 @@ void FuncLion(int a, int nDamage, int nRun) { LionList[nLion].nAction = 1; LionList[nLion].nFrame = 0; - LionList[nLion]._g = 100; + LionList[nLion].nCount = 100; LionList[nLion].nTarget = -1; sprite[nSprite].xvel = 0; sprite[nSprite].yvel = 0; diff --git a/source/exhumed/src/save.cpp b/source/exhumed/src/save.cpp index 7ec886f13..7cb20af9b 100644 --- a/source/exhumed/src/save.cpp +++ b/source/exhumed/src/save.cpp @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_PS_NS void SerializeAnubis(FSerializer& arc); +void SerializeFish(FSerializer& arc); void SerializeSpider(FSerializer& arc); @@ -48,6 +49,7 @@ bool GameInterface::SaveGame() void GameInterface::SerializeGameState(FSerializer& arc) { SerializeAnubis(arc); + SerializeFish(arc); SerializeSpider(arc); }