From 5ee7505d119757f4fe446b7227430ba20bc159b0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 27 Aug 2021 12:55:16 +0200 Subject: [PATCH] - proper handling of actors in TRCONDITION. --- source/games/blood/src/callback.cpp | 12 ++----- source/games/blood/src/nnexts.cpp | 51 +++++++++++++++-------------- source/games/blood/src/nnexts.h | 7 ++-- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/source/games/blood/src/callback.cpp b/source/games/blood/src/callback.cpp index e7153413f..271e35fc5 100644 --- a/source/games/blood/src/callback.cpp +++ b/source/games/blood/src/callback.cpp @@ -743,16 +743,8 @@ void callbackCondition(DBloodActor* actor, int) for (unsigned i = 0; i < pCond->length; i++) { EVENT evn; evn.type = pCond->obj[i].type; - if (evn.type == SS_SPRITE) - { - evn.index_ = 0; - evn.actor = &bloodActors[pCond->obj[i].index]; - } - else - { - evn.actor = nullptr; - evn.index_ = pCond->obj[i].index; - } + evn.actor = pCond->obj[i].actor; + evn.index_ = pCond->obj[i].index_; evn.cmd = pCond->obj[i].cmd; evn.funcID = kCallbackCondition; useCondition(&sprite[pXSprite->reference], pXSprite, evn); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index c046f1f0f..df3d62c31 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -451,7 +451,8 @@ void nnExtResetGlobals() { for (int i = 0; i < gTrackingCondsCount; i++) { TRCONDITION* pCond = &gCondition[i]; for (unsigned k = 0; k < pCond->length; k++) { - pCond->obj[k].index = pCond->obj[k].cmd = 0; + pCond->obj[k].actor = nullptr; + pCond->obj[k].index_ = pCond->obj[k].cmd = 0; pCond->obj[k].type = -1; } @@ -813,7 +814,8 @@ void nnExtInitModernStuff(bool bSaveLoad) { condError(pXSprite, "Max(%d) objects to track reached for condition #%d, RXID: %d!"); pCond->obj[count].type = OBJ_SPRITE; - pCond->obj[count].index = index; + pCond->obj[count].index_ = 0; + pCond->obj[count].actor = &bloodActors[index]; pCond->obj[count++].cmd = cmd; } @@ -823,7 +825,8 @@ void nnExtInitModernStuff(bool bSaveLoad) { condError(pXSprite, "Max(%d) objects to track reached for condition #%d, RXID: %d!"); pCond->obj[count].type = OBJ_SECTOR; - pCond->obj[count].index = xsector[i].reference; + pCond->obj[count].actor = nullptr; + pCond->obj[count].index_ = xsector[i].reference; pCond->obj[count++].cmd = xsector[i].command; } @@ -842,7 +845,8 @@ void nnExtInitModernStuff(bool bSaveLoad) { condError(pXSprite, "Max(%d) objects to track reached for condition #%d, RXID: %d!"); pCond->obj[count].type = OBJ_WALL; - pCond->obj[count].index = xwall[i].reference; + pCond->obj[count].index_ = xwall[i].reference; + pCond->obj[count].actor = nullptr; pCond->obj[count++].cmd = xwall[i].command; } @@ -1055,17 +1059,8 @@ void nnExtProcessSuperSprites() { for (unsigned k = 0; k < pCond->length; k++) { EVENT evn; - // temporary mess. - if (pCond->obj[k].type == OBJ_SPRITE) - { - evn.actor = &bloodActors[pCond->obj[k].type]; - evn.index_ = 0; - } - else - { - evn.actor = nullptr; - evn.index_ = pCond->obj[k].index; - } + evn.actor = pCond->obj[k].actor; + evn.index_ = pCond->obj[k].index_; evn.cmd = pCond->obj[k].cmd; evn.type = pCond->obj[k].type; evn.funcID = kCallbackMax; @@ -1901,6 +1896,7 @@ void trPlayerCtrlStopScene(PLAYER* pPlayer) { void trPlayerCtrlLink(XSPRITE* pXSource, PLAYER* pPlayer, bool checkCondition) { + auto sourceactor = &bloodActors[pXSource->reference]; // save player's sprite index to let the tracking condition know it after savegame loading... pXSource->sysData1 = pPlayer->nSprite; @@ -1941,8 +1937,9 @@ void trPlayerCtrlLink(XSPRITE* pXSource, PLAYER* pPlayer, bool checkCondition) { // search for player control sprite and replace it with actual player sprite for (unsigned k = 0; k < pCond->length; k++) { - if (pCond->obj[k].type != OBJ_SPRITE || pCond->obj[k].index != pXSource->reference) continue; - pCond->obj[k].index = pPlayer->nSprite; + if (pCond->obj[k].type != OBJ_SPRITE || pCond->obj[k].actor != sourceactor) continue; + pCond->obj[k].actor = pPlayer->actor(); + pCond->obj[k].index_ = 0; pCond->obj[k].cmd = (uint8_t)pPlayer->pXSprite->command; break; } @@ -4126,20 +4123,26 @@ bool condCheckSprite(XSPRITE* pXCond, int cmpOp, bool PUSH) { } // this updates index of object in all conditions -void condUpdateObjectIndex(int objType, int oldIndex, int newIndex) { +void condUpdateObjectIndex(int objType, int oldIndex, int newIndex) +{ + // this only gets called for player respawns + auto oldActor = &bloodActors[oldIndex]; + auto newActor = &bloodActors[newIndex]; // update index in tracking conditions first - for (int i = 0; i < gTrackingCondsCount; i++) { + for (int i = 0; i < gTrackingCondsCount; i++) + { TRCONDITION* pCond = &gCondition[i]; - for (unsigned k = 0; k < pCond->length; k++) { - if (pCond->obj[k].type != objType || pCond->obj[k].index != oldIndex) continue; - pCond->obj[k].index = newIndex; + for (unsigned k = 0; k < pCond->length; k++) + { + if (pCond->obj[k].type != objType || pCond->obj[k].actor != oldActor) continue; + pCond->obj[k].actor = newActor; break; } - } + // puke... int oldSerial = condSerialize(objType, oldIndex); int newSerial = condSerialize(objType, newIndex); @@ -7998,7 +8001,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, OBJECTS_TO_TRACK& if (arc.BeginObject(keyname)) { arc("type", w.type, &nul.type) - ("index", w.index, &nul.index) + ("index", w.index_, &nul.index_) ("xrepeat", w.cmd, &nul.cmd) .EndObject(); } diff --git a/source/games/blood/src/nnexts.h b/source/games/blood/src/nnexts.h index ecf07cdf3..686289663 100644 --- a/source/games/blood/src/nnexts.h +++ b/source/games/blood/src/nnexts.h @@ -237,12 +237,13 @@ struct TRPLAYERCTRL { // this one for controlling the player using triggers (mov struct OBJECTS_TO_TRACK { int8_t type; uint8_t cmd; - int index; + unsigned int index_; + DBloodActor* actor; }; struct TRCONDITION { - signed int xindex; - unsigned int length; + int16_t xindex; + uint8_t length; OBJECTS_TO_TRACK obj[kMaxTracedObjects]; };