- Exhumed: Rat

This commit is contained in:
Christoph Oelckers 2020-11-29 20:39:27 +01:00
parent d92428d217
commit 4543982e54
2 changed files with 52 additions and 37 deletions

View file

@ -25,11 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS BEGIN_PS_NS
enum { kMaxRats = 50 };
short nMinChunk; short nMinChunk;
short nPlayerPic; short nPlayerPic;
short nRatCount;
short nMaxChunk; short nMaxChunk;
struct Rat struct Rat
@ -39,11 +36,12 @@ struct Rat
short nSprite; short nSprite;
short nRun; short nRun;
short nTarget; short nTarget;
short f; short nCount;
short g; short nIndex;
}; };
Rat RatList[kMaxRats];
TArray<Rat> RatList;
static actionSeq RatSeq[] = { static actionSeq RatSeq[] = {
{0, 1}, {0, 1},
@ -53,18 +51,37 @@ static actionSeq RatSeq[] = {
{0, 1} {0, 1}
}; };
FSerializer& Serialize(FSerializer& arc, const char* keyname, Rat& w, Rat* def)
{
if (arc.BeginObject(keyname))
{
arc("run", w.nRun)
("frame", w.nFrame)
("action", w.nAction)
("sprite", w.nSprite)
("target", w.nTarget)
("count", w.nCount)
("index", w.nIndex)
.EndObject();
}
return arc;
}
static SavegameHelper sgh("rat", void SerializeRat(FSerializer& arc)
SV(nMinChunk), {
SV(nPlayerPic), if (arc.BeginObject("rat"))
SV(nRatCount), {
SV(nMaxChunk), arc("minchunk", nMinChunk)
SA(RatList), ("maxchunk", nMaxChunk)
nullptr); ("playerpic", nPlayerPic)
("list", RatList)
.EndObject();
}
}
void InitRats() void InitRats()
{ {
nRatCount = 0; RatList.Clear();
nMinChunk = 9999; nMinChunk = 9999;
nMaxChunk = -1; nMaxChunk = -1;
@ -90,11 +107,7 @@ void SetRatVel(short nSprite)
int BuildRat(short nSprite, int x, int y, int z, short nSector, int nAngle) int BuildRat(short nSprite, int x, int y, int z, short nSector, int nAngle)
{ {
if (nRatCount >= kMaxRats) { auto nRat = RatList.Reserve(1);
return -1;
}
short nRat = nRatCount++;
if (nSprite < 0) if (nSprite < 0)
{ {
@ -138,8 +151,8 @@ int BuildRat(short nSprite, int x, int y, int z, short nSector, int nAngle)
RatList[nRat].nFrame = 0; RatList[nRat].nFrame = 0;
RatList[nRat].nSprite = nSprite; RatList[nRat].nSprite = nSprite;
RatList[nRat].nTarget = -1; RatList[nRat].nTarget = -1;
RatList[nRat].f = RandomSize(5); RatList[nRat].nCount = RandomSize(5);
RatList[nRat].g = RandomSize(3); RatList[nRat].nIndex = RandomSize(3);
sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nRat | 0x240000); sprite[nSprite].owner = runlist_AddRunRec(sprite[nSprite].lotag - 1, nRat | 0x240000);
@ -253,8 +266,8 @@ void FuncRat(int a, int nDamage, int nRun)
case 0: case 0:
{ {
RatList[nRat].f--; RatList[nRat].nCount--;
if (RatList[nRat].f > 0) { if (RatList[nRat].nCount > 0) {
return; return;
} }
@ -273,10 +286,10 @@ void FuncRat(int a, int nDamage, int nRun)
} }
RatList[nRat].nFrame ^= 1; RatList[nRat].nFrame ^= 1;
RatList[nRat].f = RandomSize(5) + 4; RatList[nRat].nCount = RandomSize(5) + 4;
RatList[nRat].g--; RatList[nRat].nIndex--;
if (RatList[nRat].g <= 0) if (RatList[nRat].nIndex <= 0)
{ {
short nFoodSprite = FindFood(nSprite); short nFoodSprite = FindFood(nSprite);
if (nFoodSprite == -1) { if (nFoodSprite == -1) {
@ -289,7 +302,7 @@ void FuncRat(int a, int nDamage, int nRun)
SetRatVel(nSprite); SetRatVel(nSprite);
RatList[nRat].nAction = 1; RatList[nRat].nAction = 1;
RatList[nRat].g = 900; RatList[nRat].nIndex = 900;
RatList[nRat].nFrame = 0; RatList[nRat].nFrame = 0;
} }
@ -297,9 +310,9 @@ void FuncRat(int a, int nDamage, int nRun)
} }
case 1: case 1:
{ {
RatList[nRat].g--; RatList[nRat].nIndex--;
if (RatList[nRat].g <= 0) if (RatList[nRat].nIndex <= 0)
{ {
RatList[nRat].nAction = 2; RatList[nRat].nAction = 2;
RatList[nRat].nFrame = 0; RatList[nRat].nFrame = 0;
@ -316,13 +329,13 @@ void FuncRat(int a, int nDamage, int nRun)
if (xVal >= 50 || yVal >= 50) if (xVal >= 50 || yVal >= 50)
{ {
RatList[nRat].f--; RatList[nRat].nCount--;
if (RatList[nRat].f < 0) if (RatList[nRat].nCount < 0)
{ {
PlotCourseToSprite(nSprite, nTarget); PlotCourseToSprite(nSprite, nTarget);
SetRatVel(nSprite); SetRatVel(nSprite);
RatList[nRat].f = 32; RatList[nRat].nCount = 32;
} }
return; return;
@ -330,7 +343,7 @@ void FuncRat(int a, int nDamage, int nRun)
RatList[nRat].nAction = 0; RatList[nRat].nAction = 0;
RatList[nRat].nFrame = 0; RatList[nRat].nFrame = 0;
RatList[nRat].g = RandomSize(3); RatList[nRat].nIndex = RandomSize(3);
sprite[nSprite].xvel = 0; sprite[nSprite].xvel = 0;
sprite[nSprite].yvel = 0; sprite[nSprite].yvel = 0;
@ -342,14 +355,14 @@ void FuncRat(int a, int nDamage, int nRun)
MoveCreature(nSprite); MoveCreature(nSprite);
} }
RatList[nRat].f--; RatList[nRat].nCount--;
if (RatList[nRat].f <= 0) if (RatList[nRat].nCount <= 0)
{ {
RatList[nRat].nTarget = FindFood(nSprite); RatList[nRat].nTarget = FindFood(nSprite);
if (RatList[nRat].nTarget <= -1) if (RatList[nRat].nTarget <= -1)
{ {
RatList[nRat].f = RandomSize(6); RatList[nRat].nCount = RandomSize(6);
if (sprite[nSprite].xvel || sprite[nSprite].yvel) if (sprite[nSprite].xvel || sprite[nSprite].yvel)
{ {
sprite[nSprite].xvel = 0; sprite[nSprite].xvel = 0;
@ -366,7 +379,7 @@ void FuncRat(int a, int nDamage, int nRun)
PlotCourseToSprite(nSprite, RatList[nRat].nTarget); PlotCourseToSprite(nSprite, RatList[nRat].nTarget);
SetRatVel(nSprite); SetRatVel(nSprite);
RatList[nRat].nAction = 1; RatList[nRat].nAction = 1;
RatList[nRat].g = 900; RatList[nRat].nIndex = 900;
RatList[nRat].nFrame = 0; RatList[nRat].nFrame = 0;
return; return;
} }

View file

@ -34,6 +34,7 @@ void SerializeFish(FSerializer& arc);
void SerializeLavadude(FSerializer& arc); void SerializeLavadude(FSerializer& arc);
void SerializeLion(FSerializer& arc); void SerializeLion(FSerializer& arc);
void SerializeMummy(FSerializer& arc); void SerializeMummy(FSerializer& arc);
void SerializeRat(FSerializer& arc);
void SerializeSpider(FSerializer& arc); void SerializeSpider(FSerializer& arc);
@ -56,6 +57,7 @@ void GameInterface::SerializeGameState(FSerializer& arc)
SerializeLavadude(arc); SerializeLavadude(arc);
SerializeLion(arc); SerializeLion(arc);
SerializeMummy(arc); SerializeMummy(arc);
SerializeRat(arc);
SerializeSpider(arc); SerializeSpider(arc);
} }