- Exhumed: Snake and Sequence

# Conflicts:
#	source/exhumed/src/save.cpp
This commit is contained in:
Christoph Oelckers 2020-11-30 00:18:32 +01:00
parent e8c56b1f9f
commit c1b478bf83
4 changed files with 50 additions and 52 deletions

View file

@ -456,23 +456,14 @@ struct Snake
short sC; short sC;
short nRun; short nRun;
// array?
char c[8]; char c[8];
/*
char c1;
char c2;
char c3;
char c4;
char c5;
char c6;
char c7;
char c8;
*/
short sE; short sE;
short nSnakePlayer;
}; };
extern Snake SnakeList[]; enum { kMaxSnakes = 50 };
extern FreeListArray<Snake, kMaxSnakes> SnakeList;
void InitSnakes(); void InitSnakes();
short GrabSnake(); short GrabSnake();

View file

@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS BEGIN_PS_NS
void SerializeSequence(FSerializer& arc);
void SerializeSnake(FSerializer& arc);
void SerializeSwitch(FSerializer& arc); void SerializeSwitch(FSerializer& arc);
void SerializeView(FSerializer& arc); void SerializeView(FSerializer& arc);
@ -61,6 +63,8 @@ void GameInterface::SerializeGameState(FSerializer& arc)
{ {
if (arc.BeginObject("exhumed")) if (arc.BeginObject("exhumed"))
{ {
SerializeSequence(arc);
SerializeSnake(arc);
SerializeSwitch(arc); SerializeSwitch(arc);
SerializeView(arc); SerializeView(arc);

View file

@ -635,12 +635,17 @@ int seq_PlotSequence(short nSprite, short edx, short nFrame, short ecx)
return nPict; return nPict;
} }
static SavegameHelper sghseq("sequence", void SerializeSequence(FSerializer& arc)
SV(nPilotLightFrame), {
SV(nPilotLightCount), if (arc.BeginObject("sequence"))
SV(nPilotLightBase), {
SV(nShadowWidth), arc("pilotlightframe", nPilotLightFrame)
SV(nFlameHeight), ("pilotlightcount", nPilotLightCount)
nullptr); ("pilotlightbase", nPilotLightBase)
("shadowwidth", nShadowWidth)
("flameheight", nFlameHeight)
.EndObject();
}
}
END_PS_NS END_PS_NS

View file

@ -29,42 +29,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS BEGIN_PS_NS
enum { kMaxSnakes = 50 }; FreeListArray<Snake, kMaxSnakes> SnakeList;
int nSnakeCount = 0;
int nSnakesFree;
short SnakeFree[kMaxSnakes];
short nPlayerSnake[kMaxPlayers]; short nPlayerSnake[kMaxPlayers];
Snake SnakeList[kMaxSnakes]; FSerializer& Serialize(FSerializer& arc, const char* keyname, Snake& w, Snake* def)
short nSnakePlayer[kMaxSnakes]; {
if (arc.BeginObject(keyname))
{
arc("enemy", w.nEnemy)
.Array("sprites", w.nSprites, kSnakeSprites)
("sc", w.sC)
("run", w.nRun)
.Array("c", w.c, countof(w.c))
("se", w.sE)
("player", w.nSnakePlayer)
.EndObject();
}
return arc;
}
void SerializeSnake(FSerializer& arc)
{
arc("snake", SnakeList);
arc.Array("playersnake", nPlayerSnake, PlayerCount);
}
static SavegameHelper sghsnake("snake",
SV(nSnakeCount),
SV(nSnakesFree),
SA(SnakeFree),
SA(nPlayerSnake),
SA(SnakeList),
SA(nSnakePlayer),
nullptr);
void InitSnakes() void InitSnakes()
{ {
nSnakeCount = 0; SnakeList.Clear();
for (int i = 0; i < kMaxSnakes; i++) {
SnakeFree[i] = i;
}
nSnakesFree = kMaxSnakes;
memset(nPlayerSnake, 0, sizeof(nPlayerSnake)); memset(nPlayerSnake, 0, sizeof(nPlayerSnake));
} }
short GrabSnake() short GrabSnake()
{ {
nSnakesFree--; return SnakeList.Get();
return SnakeFree[nSnakesFree];
} }
void DestroySnake(int nSnake) void DestroySnake(int nSnake)
@ -82,8 +82,7 @@ void DestroySnake(int nSnake)
mydeletesprite(nSprite); mydeletesprite(nSprite);
} }
SnakeFree[nSnakesFree] = nSnake; SnakeList.Release(nSnake);
nSnakesFree++;
if (nSnake == nSnakeCam) if (nSnake == nSnakeCam)
{ {
@ -116,8 +115,6 @@ void ExplodeSnakeSprite(int nSprite, short nPlayer)
int BuildSnake(short nPlayer, short zVal) int BuildSnake(short nPlayer, short zVal)
{ {
if (!nSnakesFree)
return -1;
zVal -= 1280; zVal -= 1280;
@ -182,6 +179,7 @@ int BuildSnake(short nPlayer, short zVal)
} }
short nSnake = GrabSnake(); short nSnake = GrabSnake();
if (nSnake == -1) return -1;
// GrabTimeSlot(3); // GrabTimeSlot(3);
@ -244,7 +242,7 @@ int BuildSnake(short nPlayer, short zVal)
SnakeList[nSnake].nEnemy = nTarget; SnakeList[nSnake].nEnemy = nTarget;
SnakeList[nSnake].sC = 1200; SnakeList[nSnake].sC = 1200;
SnakeList[nSnake].sE = 0; SnakeList[nSnake].sE = 0;
nSnakePlayer[nSnake] = nPlayer; SnakeList[nSnake].nSnakePlayer = nPlayer;
nPlayerSnake[nPlayer] = nSnake; nPlayerSnake[nPlayer] = nSnake;
if (bSnakeCam) if (bSnakeCam)
@ -262,7 +260,7 @@ int BuildSnake(short nPlayer, short zVal)
int FindSnakeEnemy(short nSnake) int FindSnakeEnemy(short nSnake)
{ {
short nPlayer = nSnakePlayer[nSnake]; short nPlayer = SnakeList[nSnake].nSnakePlayer;
short nPlayerSprite = PlayerList[nPlayer].nSprite; short nPlayerSprite = PlayerList[nPlayer].nSprite;
short nSprite = SnakeList[nSnake].nSprites[0]; // CHECKME short nSprite = SnakeList[nSnake].nSprites[0]; // CHECKME
@ -359,11 +357,11 @@ SEARCH_ENEMY:
if (nMov) if (nMov)
{ {
short nPlayer = nSnakePlayer[nSnake]; short nPlayer = SnakeList[nSnake].nSnakePlayer;
ExplodeSnakeSprite(SnakeList[nSnake].nSprites[0], nPlayer); ExplodeSnakeSprite(SnakeList[nSnake].nSprites[0], nPlayer);
nPlayerSnake[nPlayer] = -1; nPlayerSnake[nPlayer] = -1;
nSnakePlayer[nSnake] = -1; SnakeList[nSnake].nSnakePlayer = -1;
DestroySnake(nSnake); DestroySnake(nSnake);
} }