use global stat manager in Exhumed

This commit is contained in:
Christoph Oelckers 2023-10-01 10:17:27 +02:00
parent 3e821c5849
commit da3df98484
19 changed files with 39 additions and 44 deletions

View file

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "engine.h"
#include "sequence.h"
#include "sound.h"
#include "mapinfo.h"
#include <assert.h>
BEGIN_PS_NS
@ -109,7 +110,7 @@ void BuildAnubis(DExhumedActor* ap, const DVector3& pos, sectortype* pSector, DA
ap->nSeqFile = "anubis";
runlist_AddRunRec(NewRun, ap, 0x90000);
nCreaturesTotal++;
Level.addKillCount();
}
//---------------------------------------------------------------------------
@ -425,7 +426,7 @@ void AIAnubis::Damage(RunListEvent* ev)
ap->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
ap->nHealth = 0;
nCreaturesKilled++;
Level.addKill(-1);
if (nAction < 11)
{

View file

@ -116,8 +116,6 @@ void MySetView(int x1, int y1, int x2, int y2);
char sHollyStr[40];
int nCreaturesKilled = 0, nCreaturesTotal = 0;
int nFreeze;
int nSnakeCam = -1;
@ -528,7 +526,7 @@ bool GameInterface::CanSave()
::GameStats GameInterface::getStats()
{
return { nCreaturesKilled, nCreaturesTotal, 0, 0, PlayClock / 120, 0 };
return { Level.kills.got, Level.kills.max, Level.secrets.got, Level.secrets.max, PlayClock / 120, 0 };
}
::GameInterface* CreateInterface()
@ -581,9 +579,7 @@ void SerializeState(FSerializer& arc)
InitEnergyTile();
}
arc ("creaturestotal", nCreaturesTotal)
("creatureskilled", nCreaturesKilled)
("freeze", nFreeze)
arc ("freeze", nFreeze)
("snakecam", nSnakeCam)
("clockval", nClockVal)
("redticks", nRedTicks)

View file

@ -37,6 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "texinfo.h"
#include "player.h"
#include "texids.h"
#include "mapinfo.h"
BEGIN_PS_NS
@ -107,8 +108,6 @@ extern int nNetTime;
extern int nTotalPlayers;
extern int nCreaturesTotal, nCreaturesKilled;
extern int lLocalButtons;
extern int nEnergyTowers;

View file

@ -196,7 +196,7 @@ void BuildFish(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector,
pActor->spr.intowner = runlist_AddRunRec(pActor->spr.lotag - 1, pActor, 0x120000);
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x120000);
nCreaturesTotal++;
Level.addKillCount();
}
//---------------------------------------------------------------------------
@ -304,7 +304,7 @@ void AIFish::Damage(RunListEvent* ev)
if (pActor->nHealth <= 0)
{
pActor->nHealth = 0;
nCreaturesKilled++;
Level.addKill(-1);
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;

View file

@ -191,9 +191,8 @@ void GameInterface::LevelCompleted(MapRecord *to_map, int skill)
}
}
SummaryInfo info{};
info.kills = nCreaturesKilled;
info.maxkills = nCreaturesTotal;
info.supersecrets = nBestLevel;
Level.fillSummary(info);
info.supersecrets = nBestLevel;// hacky override
info.time = PlayClock * GameTicRate / 120;
if (to_map) selectedlevelnew = to_map->levelNumber;
ShowIntermission(currentLevel, to_map, &info, [=](bool)

View file

@ -117,8 +117,7 @@ uint8_t LoadLevel(MapRecord* map)
// init stuff
{
StopAllSounds();
nCreaturesKilled = 0;
nCreaturesTotal = 0;
Level.clearStats();
nFreeze = 0;
pSpiritSprite = nullptr;
PlayClock = 0;

View file

@ -145,7 +145,7 @@ void BuildLava(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector,
pActor->spr.intowner = runlist_AddRunRec(pActor->spr.lotag - 1, pActor, 0x150000);
pActor->nRun = runlist_AddRunRec(NewRun, pActor, 0x150000);
nCreaturesTotal++;
Level.addKillCount();
}
void AILavaDude::Draw(RunListEvent* ev)
@ -178,7 +178,7 @@ void AILavaDude::Damage(RunListEvent* ev)
pActor->nAction = 5;
pActor->nFrame = 0;
nCreaturesKilled++;
Level.addKill(-1);
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
}

View file

@ -86,7 +86,7 @@ void BuildLion(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector,
pActor->nSeqFile = "lion";
nCreaturesTotal++;
Level.addKillCount();
}
void AILion::Draw(RunListEvent* ev)
@ -127,7 +127,7 @@ void AILion::Damage(RunListEvent* ev)
pActor->nHealth = 0;
nCreaturesKilled++;
Level.addKill(-1);
if (nAction < 10)
{

View file

@ -87,7 +87,7 @@ void BuildMummy(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector,
pActor->nSeqFile = "mummy";
nCreaturesTotal++;
Level.addKillCount();
}
//---------------------------------------------------------------------------
@ -379,7 +379,7 @@ void AIMummy::Tick(RunListEvent* ev)
pActor->nHealth = 300;
pActor->pTarget = nullptr;
nCreaturesTotal++;
Level.addKillCount();
}
return;
}
@ -465,7 +465,7 @@ void AIMummy::Damage(RunListEvent* ev)
{
pActor->nHealth = 0;
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
nCreaturesKilled++;
Level.addKill(-1);
DropMagic(pActor);

View file

@ -1210,7 +1210,7 @@ void BuildQueen(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector,
runlist_AddRunRec(NewRun, nQueen, 0x1A0000);
nCreaturesTotal++;
Level.addKillCount();
}
void SetQueenSpeed(DExhumedActor* pActor, int nSpeed)
@ -1549,7 +1549,7 @@ void AIQueen::Damage(RunListEvent* ev)
QueenList[nQueen].nHealth = 0;
QueenList[nQueen].nIndex = 5;
nCreaturesKilled++;
Level.addKill(-1);
break;
}

View file

@ -91,7 +91,7 @@ void BuildRex(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector, D
// this isn't stored anywhere.
runlist_AddRunRec(NewRun, pActor, 0x180000);
nCreaturesTotal++;
Level.addKillCount();
}
//---------------------------------------------------------------------------
@ -148,7 +148,7 @@ void AIRex::Damage(RunListEvent* ev)
pActor->nHealth = 0;
nCreaturesKilled++;
Level.addKill(-1);
if (nAction < 6)
{

View file

@ -92,7 +92,7 @@ void BuildRoach(int nType, DExhumedActor* pActor, const DVector3& pos, sectortyp
pActor->nSeqFile = "roach";
nCreaturesTotal++;
Level.addKillCount();
}
//---------------------------------------------------------------------------
@ -166,7 +166,7 @@ void AIRoach::Damage(RunListEvent* ev)
pActor->nFrame = 0;
}
nCreaturesKilled++; // NOTE: This was incrementing in original code. Bug?
Level.addKill(-1); // NOTE: This was incrementing in original code. Bug?
}
else
{

View file

@ -1842,7 +1842,7 @@ void runlist_DamageEnemy(DExhumedActor* pActor, DExhumedActor* pActor2, int nDam
return;
}
int nPreCreaturesKilled = nCreaturesKilled;
int nPreCreaturesKilled = Level.kills.got;
RunListEvent ev{};
ev.pOtherActor = pActor2;
@ -1850,13 +1850,16 @@ void runlist_DamageEnemy(DExhumedActor* pActor, DExhumedActor* pActor2, int nDam
runlist_SendMessage(nRun, -1, &ExhumedAI::Damage, &ev);
// is there now one less creature? (has one died)
if (nPreCreaturesKilled < nCreaturesKilled && pActor2 != nullptr)
if (nPreCreaturesKilled < Level.kills.got && pActor2 != nullptr)
{
if (pActor2->spr.statnum != 100) {
return;
}
int nPlayer = GetPlayerFromActor(pActor2);
// Due to the horrible setup we can award the kill to the player only here. Yuck!
Level.kills.player[nPlayer]++;
PlayerList[nPlayer].nTauntTimer--;
if (PlayerList[nPlayer].nTauntTimer <= 0)

View file

@ -91,7 +91,7 @@ void BuildScorp(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector,
pActor->nSeqFile = "scorp";
nCreaturesTotal++;
Level.addKillCount();
}
//---------------------------------------------------------------------------
@ -156,7 +156,7 @@ void AIScorp::Damage(RunListEvent* ev)
pActor->vel.Z = 0;
pActor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
nCreaturesKilled++;
Level.addKill(-1);
return;
}
else

View file

@ -95,7 +95,7 @@ void BuildSet(DExhumedActor* pActor, const DVector3& pos, sectortype* pSector, D
// this isn't stored anywhere.
runlist_AddRunRec(NewRun, pActor, 0x190000);
nCreaturesTotal++;
Level.addKillCount();
}
//---------------------------------------------------------------------------
@ -223,7 +223,7 @@ void AISet::Damage(RunListEvent* ev)
pActor->nHealth = 0;
nCreaturesKilled++;
Level.addKill(-1);
if (nAction < 10)
{

View file

@ -702,7 +702,7 @@ void UpdateCreepySounds()
nCreepyTimer--;
if (nCreepyTimer <= 0)
{
if (nCreaturesKilled < nCreaturesTotal && !(PlayerList[nLocalPlayer].pPlayerViewSect->Flag & 0x2000))
if (Level.kills.got < Level.kills.max && !(PlayerList[nLocalPlayer].pPlayerViewSect->Flag & 0x2000))
{
const auto creepySeq = getSequence("creepy");
const auto seqFrameSound = creepySeq->frames[totalmoves % creepySeq->frames.Size()].sound;

View file

@ -87,7 +87,7 @@ DExhumedActor* BuildSpider(DExhumedActor* spp, const DVector3& pos, sectortype*
spp->nSeqFile = "spider";
nCreaturesTotal++;
Level.addKillCount();
return spp;
}
@ -417,7 +417,7 @@ void AISpider::Damage(RunListEvent* ev)
spp->spr.cstat &= ~CSTAT_SPRITE_BLOCK_ALL;
nCreaturesKilled++;
Level.addKill(-1);
const auto spiderSeqs = getFileSeqs("spider");

View file

@ -88,9 +88,7 @@ void DrawStatusBar()
UpdateFrame();
}
SummaryInfo info{};
info.kills = nCreaturesKilled;
info.maxkills = nCreaturesTotal;
// got no secrets in the game
Level.fillSummary(info);
info.time = Scale(PlayClock, 1000, 120);
info.totaltime = STAT_GetTotalTime();

View file

@ -108,7 +108,7 @@ DExhumedActor* BuildWasp(DExhumedActor* pActor, const DVector3& pos, sectortype*
pActor->nSeqFile = "wasp";
nCreaturesTotal++;
Level.addKillCount();
return pActor;
}
@ -187,7 +187,7 @@ void AIWasp::Damage(RunListEvent* ev)
pActor->vel.Z = 2;
nCreaturesKilled++;
Level.addKill(-1);
}
pActor->nFrame = 0;
}