From a6cdcab128583ff09418b3567ddd5c2a72e06051 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Wed, 31 Oct 2018 22:40:08 +0200 Subject: [PATCH] Implemented loading/saving of line/sector health and health groups in savegames --- src/p_destructible.cpp | 48 +++++++++++++++++++++++++++++++ src/p_destructible.h | 4 ++- src/p_saveg.cpp | 6 ++++ src/p_sectors.cpp | 6 ++++ wadsrc/static/zscript/mapdata.txt | 8 ++++++ 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/p_destructible.cpp b/src/p_destructible.cpp index 998504a9a..039ee302c 100755 --- a/src/p_destructible.cpp +++ b/src/p_destructible.cpp @@ -9,6 +9,7 @@ #include "p_local.h" #include "p_maputl.h" #include "c_cvars.h" +#include "serializer.h" //========================================================================== // @@ -529,4 +530,51 @@ bool P_CheckSectorVulnerable(sector_t* sector, int part) if (texture == skyflatnum) return false; return true; +} + +/// + +FSerializer &Serialize(FSerializer &arc, const char *key, FHealthGroup& g, FHealthGroup *def) +{ + if (arc.BeginObject(key)) + { + arc("id", g.id) + ("health", g.health) + .EndObject(); + } + return arc; +} + +void P_SerializeHealthGroups(FSerializer& arc) +{ + // todo : stuff + if (arc.BeginArray("healthgroups")) + { + if (arc.isReading()) + { + TArray readGroups; + int sz = arc.ArraySize(); + for (int i = 0; i < sz; i++) + { + FHealthGroup grp; + arc(nullptr, grp); + FHealthGroup* existinggrp = P_GetHealthGroup(grp.id); + if (!existinggrp) + continue; + existinggrp->health = grp.health; + } + } + else + { + TMap::ConstIterator it(level.healthGroups); + TMap::ConstPair* pair; + while (it.NextPair(pair)) + { + FHealthGroup grp = pair->Value; + arc(nullptr, grp); + } + } + + arc.EndArray(); + } } \ No newline at end of file diff --git a/src/p_destructible.h b/src/p_destructible.h index 81b74faa8..c9c5e81ab 100755 --- a/src/p_destructible.h +++ b/src/p_destructible.h @@ -34,4 +34,6 @@ void P_GeometryLineAttack(FTraceResults& trace, AActor* thing, int damage, FName void P_GeometryRadiusAttack(AActor* bombspot, AActor* bombsource, int bombdamage, int bombdistance, FName damagetype, int fulldamagedistance); bool P_CheckLinedefVulnerable(line_t* line, int side, int part = -1); -bool P_CheckSectorVulnerable(sector_t* sector, int part); \ No newline at end of file +bool P_CheckSectorVulnerable(sector_t* sector, int part); + +void P_SerializeHealthGroups(FSerializer& arc); \ No newline at end of file diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 6248dab3e..93b583c58 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -56,6 +56,7 @@ #include "serializer.h" #include "g_levellocals.h" #include "events.h" +#include "p_destructible.h" //========================================================================== // @@ -74,6 +75,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, line_t &line, line_t * .Args("args", line.args, def->args, line.special) ("portalindex", line.portalindex, def->portalindex) ("locknumber", line.locknumber, def->locknumber) + ("health", line.health, def->health) // Unless the map loader is changed the sidedef references will not change between map loads so there's no need to save them. //.Array("sides", line.sidedef, 2) .EndObject(); @@ -293,6 +295,8 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t .Terrain("floorterrain", p.terrainnum[0], &def->terrainnum[0]) .Terrain("ceilingterrain", p.terrainnum[1], &def->terrainnum[1]) ("scrolls", scroll, nul) + ("healthfloor", p.healthfloor, def->healthfloor) + ("healthceiling", p.healthceiling, def->healthceiling) // GZDoom exclusive: .Array("reflect", p.reflect, def->reflect, 2, true) .EndObject(); @@ -991,6 +995,8 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) arc("sectorportals", level.sectorPortals); if (arc.isReading()) P_FinalizePortals(); + // [ZZ] serialize health groups + P_SerializeHealthGroups(arc); // [ZZ] serialize events E_SerializeEvents(arc); DThinker::SerializeThinkers(arc, hubload); diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 831062fc0..be86c87ef 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -2652,6 +2652,10 @@ DEFINE_FIELD_X(Sector, sector_t, damageamount) DEFINE_FIELD_X(Sector, sector_t, damageinterval) DEFINE_FIELD_X(Sector, sector_t, leakydamage) DEFINE_FIELD_X(Sector, sector_t, ZoneNumber) +DEFINE_FIELD_X(Sector, sector_t, healthceiling) +DEFINE_FIELD_X(Sector, sector_t, healthfloor) +DEFINE_FIELD_X(Sector, sector_t, healthceilinggroup) +DEFINE_FIELD_X(Sector, sector_t, healthfloorgroup) DEFINE_FIELD_X(Sector, sector_t, MoreFlags) DEFINE_FIELD_X(Sector, sector_t, Flags) DEFINE_FIELD_X(Sector, sector_t, SecActTarget) @@ -2675,6 +2679,8 @@ DEFINE_FIELD_X(Line, line_t, validcount) DEFINE_FIELD_X(Line, line_t, locknumber) DEFINE_FIELD_X(Line, line_t, portalindex) DEFINE_FIELD_X(Line, line_t, portaltransferred) +DEFINE_FIELD_X(Line, line_t, health) +DEFINE_FIELD_X(Line, line_t, healthgroup) DEFINE_FIELD_X(Side, side_t, sector) DEFINE_FIELD_X(Side, side_t, linedef) diff --git a/wadsrc/static/zscript/mapdata.txt b/wadsrc/static/zscript/mapdata.txt index f20a9b2eb..9dc42da22 100644 --- a/wadsrc/static/zscript/mapdata.txt +++ b/wadsrc/static/zscript/mapdata.txt @@ -156,6 +156,9 @@ struct Line native play native int locknumber; // [Dusk] lock number for special native readonly uint portalindex; native readonly uint portaltransferred; + + native readonly int health; + native readonly int healthgroup; native bool isLinePortal(); native bool isVisualPortal(); @@ -286,6 +289,11 @@ struct Sector native play native int16 leakydamage; native readonly uint16 ZoneNumber; + + native readonly int healthceiling; + native readonly int healthfloor; + native readonly int healthceilinggroup; + native readonly int healthfloorgroup; enum ESectorMoreFlags {