From 19dfd8432021f421e984791a55df5383641c7476 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 1 Oct 2023 10:33:07 +0200 Subject: [PATCH] use global stat manager in SW --- source/core/mapinfo.h | 5 +++++ source/games/sw/src/coolg.cpp | 4 ++-- source/games/sw/src/coolie.cpp | 2 +- source/games/sw/src/game.cpp | 10 +++------- source/games/sw/src/game.h | 4 ---- source/games/sw/src/ninja.cpp | 3 --- source/games/sw/src/panel.cpp | 12 ++---------- source/games/sw/src/player.cpp | 6 +----- source/games/sw/src/save.cpp | 4 ---- source/games/sw/src/sbar.cpp | 5 +---- source/games/sw/src/sector.cpp | 7 ++----- source/games/sw/src/weapon.cpp | 3 +-- wadsrc/static/zscript/games/sw/swgame.zs | 2 -- 13 files changed, 18 insertions(+), 49 deletions(-) diff --git a/source/core/mapinfo.h b/source/core/mapinfo.h index eb63f5a8a..3dca68d48 100644 --- a/source/core/mapinfo.h +++ b/source/core/mapinfo.h @@ -295,6 +295,11 @@ struct MapLocals superSecrets.add(playerno, amount); } + void addFrags(int playerno, int amount) + { + // todo + } + }; diff --git a/source/games/sw/src/coolg.cpp b/source/games/sw/src/coolg.cpp index 5a1ec782f..8990795d9 100644 --- a/source/games/sw/src/coolg.cpp +++ b/source/games/sw/src/coolg.cpp @@ -564,7 +564,7 @@ int NewCoolg(DSWActor* actor) actorNew->user.__legacyState.Attrib = &CoolgAttrib; // special case - TotalKillable++; + Level.addKillCount(); CoolgCommon(actorNew); return 0; @@ -589,7 +589,7 @@ int DoCoolgBirth(DSWActor* actor) EnemyDefaults(actor, &CoolgActionSet, &CoolgPersonality); // special case - TotalKillable--; + Level.addKillCount(-1); actor->user.Flags |= (SPR_NO_SCAREDZ|SPR_XFLIP_TOGGLE); CoolgCommon(actor); diff --git a/source/games/sw/src/coolie.cpp b/source/games/sw/src/coolie.cpp index 199560da3..1d9a6f132 100644 --- a/source/games/sw/src/coolie.cpp +++ b/source/games/sw/src/coolie.cpp @@ -381,7 +381,7 @@ void EnemyDefaults(DSWActor* actor, ACTOR_ACTION_SET* action, PERSONALITY* perso break; default: { - TotalKillable++; + Level.addKillCount(); } break; diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp index bae095c57..50dd56153 100644 --- a/source/games/sw/src/game.cpp +++ b/source/games/sw/src/game.cpp @@ -162,7 +162,6 @@ short screenpeek = 0; int GodMode = false; short Skill = 2; -int TotalKillable; const GAME_SET gs_defaults = { @@ -356,7 +355,7 @@ void InitLevelGlobals(void) void InitLevelGlobals2(void) { InitTimingVars(); - TotalKillable = 0; + Level.clearStats(); Bunny_Count = 0; FinishAnim = false; } @@ -642,11 +641,8 @@ void GameInterface::LevelCompleted(MapRecord* map, int skill) STAT_Update(map == nullptr); SummaryInfo info{}; + Level.fillSummary(info); - info.kills = Player[screenpeek].Kills; - info.maxkills = TotalKillable; - info.secrets = Player[screenpeek].SecretsFound; - info.maxsecrets = LevelSecrets; info.time = PlayClock / 120; @@ -825,7 +821,7 @@ int StdRandomRange(int range) GameStats GameInterface::getStats() { PLAYER* pp = Player + myconnectindex; - return { pp->Kills, TotalKillable, pp->SecretsFound, LevelSecrets, PlayClock / 120, 0 }; + return { Level.kills.got, Level.kills.max, Level.secrets.got, Level.secrets.max, PlayClock / 120, 0 }; } void GameInterface::FreeLevelData() diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 2ba0ceb15..be0fbd34c 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1656,8 +1656,6 @@ void LoadSaveMsg(const char *msg); void UpdateStatusBar(); int32_t registerosdcommands(void); -extern short LevelSecrets; -extern int TotalKillable; extern int OrigCommPlayers; extern uint8_t PlayerGravity; @@ -1809,9 +1807,7 @@ struct PLAYER // Death stuff uint16_t DeathType; - int16_t Kills; int16_t KilledPlayer[MAX_SW_PLAYERS_REG]; - int16_t SecretsFound; // Health int16_t Armor; diff --git a/source/games/sw/src/ninja.cpp b/source/games/sw/src/ninja.cpp index a9b7965ab..01d9c72f6 100644 --- a/source/games/sw/src/ninja.cpp +++ b/source/games/sw/src/ninja.cpp @@ -2135,12 +2135,10 @@ void PlayerLevelReset(PLAYER* pp) COVER_SetReverb(0); // Turn off any echoing that may have been going before pp->Reverb = 0; - pp->SecretsFound = 0; pp->WpnFirstType = WPN_SWORD; //PlayerUpdateHealth(pp, 500); //pp->Armor = 0; //PlayerUpdateArmor(pp, 0); - pp->Kills = 0; pp->KillerActor = nullptr;; pp->NightVision = false; pp->StartColor = 0; @@ -2277,7 +2275,6 @@ void PlayerGameReset(PLAYER* pp) pp->TestNukeInit = false; pp->InitingNuke = false; pp->NukeInitialized = false; - pp->SecretsFound = 0; pp->WpnReloadState = 2; pp->WpnAmmo[WPN_STAR] = 30; diff --git a/source/games/sw/src/panel.cpp b/source/games/sw/src/panel.cpp index 2c99ba1f2..52a47f5a0 100644 --- a/source/games/sw/src/panel.cpp +++ b/source/games/sw/src/panel.cpp @@ -449,20 +449,12 @@ void PlayerUpdateKills(PLAYER* pp, short value) // for everyone on the same team if (opp != pp && opp->actor->user.spal == pp->actor->user.spal) { - opp->Kills += value; - if (opp->Kills > 999) - opp->Kills = 0; - if (opp->Kills < -99) - opp->Kills = -99; + Level.addFrags(pnum, value); } } } - pp->Kills += value; - if (pp->Kills > 999) - pp->Kills = 0; - if (pp->Kills < -99) - pp->Kills = -99; + Level.addFrags(pp->pnum, value); } //--------------------------------------------------------------------------- diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp index 2c0daa50a..924472b76 100644 --- a/source/games/sw/src/player.cpp +++ b/source/games/sw/src/player.cpp @@ -6695,8 +6695,7 @@ void MultiPlayLimits(void) { TRAVERSE_CONNECT(pnum) { - pp = Player + pnum; - if (pp->Kills >= gNet.KillLimit) + if (Level.kills.player[pnum] >= gNet.KillLimit) { Done = true; } @@ -6884,7 +6883,6 @@ void InitAllPlayers(void) pp->climb_ndx = 10; pp->KillerActor = nullptr; - pp->Kills = 0; pp->bcnt = 0; pp->UziShellLeftAlt = 0; pp->UziShellRightAlt = 0; @@ -7313,8 +7311,6 @@ DEFINE_FIELD_X(SWPlayer, PLAYER, InventoryActive) DEFINE_FIELD_X(SWPlayer, PLAYER, DiveTics) DEFINE_FIELD_X(SWPlayer, PLAYER, DiveDamageTics) DEFINE_FIELD_X(SWPlayer, PLAYER, DeathType) -DEFINE_FIELD_X(SWPlayer, PLAYER, Kills) -DEFINE_FIELD_X(SWPlayer, PLAYER, SecretsFound) DEFINE_FIELD_X(SWPlayer, PLAYER, Armor) DEFINE_FIELD_X(SWPlayer, PLAYER, MaxHealth) DEFINE_FIELD_X(SWPlayer, PLAYER, UziShellLeftAlt) diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index d400889e8..beecad958 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -526,10 +526,8 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PLAYER& w, PLAYER* ("DiveTics", w.DiveTics) ("DiveDamageTics", w.DiveDamageTics) ("DeathType", w.DeathType) - ("Kills", w.Kills) ("Killer", w.KillerActor) .Array("KilledPlayer", w.KilledPlayer, countof(w.KilledPlayer)) - ("SecretsFound", w.SecretsFound) ("Armor", w.Armor) ("MaxHealth", w.MaxHealth) ("UziShellLeftAlt", w.UziShellLeftAlt) @@ -1129,10 +1127,8 @@ void GameInterface::SerializeGameState(FSerializer& arc) ("LoWangsQueueHead", LoWangsQueueHead) .Array("LoWangsQueue", LoWangsQueue, countof(LoWangsQueue)) ("PlayClock", PlayClock) - ("TotalKillable", TotalKillable) ("net", gNet) ("gs", gs) - ("LevelSecrets", LevelSecrets) ("Bunny_Count", Bunny_Count) ("GodMode", GodMode) ("FinishTimer", FinishTimer) diff --git a/source/games/sw/src/sbar.cpp b/source/games/sw/src/sbar.cpp index d6978d1c0..c79ffcdd1 100644 --- a/source/games/sw/src/sbar.cpp +++ b/source/games/sw/src/sbar.cpp @@ -84,10 +84,7 @@ void UpdateStatusBar() } SummaryInfo info{}; - info.kills = Player[screenpeek].Kills; - info.maxkills = TotalKillable; - info.secrets = Player[screenpeek].SecretsFound; - info.maxsecrets = LevelSecrets; + Level.fillSummary(info); info.time = Scale(PlayClock, 1000, 120); info.totaltime = STAT_GetTotalTime(); diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index b98b915fb..245428aff 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -61,7 +61,6 @@ enum void DoPlayerBeginForceJump(PLAYER*); sectortype* FindNextSectorByTag(sectortype* sect, int tag); -short LevelSecrets; bool TestVatorMatchActive(short match); bool TestSpikeMatchActive(short match); bool TestRotatorMatchActive(short match); @@ -413,8 +412,6 @@ void SectorSetup(void) memset(SineWaveFloor, 0, sizeof(SineWaveFloor)); memset(SpringBoard, 0, sizeof(SpringBoard)); - LevelSecrets = 0; - for(auto§: sector) { auto const sectp = § @@ -475,7 +472,7 @@ void SectorSetup(void) switch (tag) { case TAG_SECRET_AREA_TRIGGER: - LevelSecrets++; + Level.addSecretCount(); break; case TAG_DOOR_SLIDING: @@ -1915,7 +1912,7 @@ void TriggerSecret(sectortype* sectp, PLAYER* pp) PutStringInfo(pp, GStrings("TXTS_SECRET")); // always give to the first player - Player->SecretsFound++; + Level.addSecret(myconnectindex); sectp->lotag = 0; } diff --git a/source/games/sw/src/weapon.cpp b/source/games/sw/src/weapon.cpp index ee2a28d26..592e11b0a 100644 --- a/source/games/sw/src/weapon.cpp +++ b/source/games/sw/src/weapon.cpp @@ -4548,8 +4548,7 @@ void UpdateSinglePlayKills(DSWActor* actor) case GIRLNINJA_RUN_R0: case SKULL_R0: case BETTY_R0: - // always give kills to the first player - Player->Kills++; + Level.addKill(-1); break; } } diff --git a/wadsrc/static/zscript/games/sw/swgame.zs b/wadsrc/static/zscript/games/sw/swgame.zs index 54f8feed7..e95ccb033 100644 --- a/wadsrc/static/zscript/games/sw/swgame.zs +++ b/wadsrc/static/zscript/games/sw/swgame.zs @@ -263,10 +263,8 @@ struct SWPlayer native // Death stuff native uint16 DeathType; - native int16 Kills; //native int16 Killer; //who killed me //native int16 KilledPlayer[MAX_SW_PLAYERS_REG]; - native int16 SecretsFound; // Health native int16 Armor;