From 1cc5dbccb922413aab6f63999600fd857cee234a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 27 Aug 2021 17:09:55 +0200 Subject: [PATCH] - GetDataVal --- source/games/blood/src/nnexts.cpp | 44 ++++++++++++++++++++----------- source/games/blood/src/nnexts.h | 1 - 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 18d3766e7..5df63a1ce 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -847,7 +847,8 @@ void nnExtInitModernStuff(bool bSaveLoad) BloodStatIterator it(kStatModernCondition); while (auto iactor = it.Next()) { - spritetype* pSprite = &iactor->s(); XSPRITE* pXSprite = &iactor->x(); + spritetype* pSprite = &iactor->s(); + XSPRITE* pXSprite = &iactor->x(); if (pXSprite->busyTime <= 0 || pXSprite->isTriggered) continue; else if (gTrackingCondsCount >= kMaxTrackingConditions) @@ -932,28 +933,40 @@ void nnExtInitModernStuff(bool bSaveLoad) // The following functions required for random event features -//------------------------- -int nnExtRandom(int a, int b) { +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- + +int nnExtRandom(int a, int b) +{ if (!gAllowTrueRandom) return Random(((b + 1) - a)) + a; // used for better randomness in single player std::uniform_int_distribution dist_a_b(a, b); return dist_a_b(gStdRandom); } -int GetDataVal(spritetype* pSprite, int data) { - assert(xspriRangeIsFine(pSprite->extra)); +int GetDataVal(DBloodActor* actor, int data) +{ + if (!actor->hasX()) return -1; switch (data) { - case 0: return xsprite[pSprite->extra].data1; - case 1: return xsprite[pSprite->extra].data2; - case 2: return xsprite[pSprite->extra].data3; - case 3: return xsprite[pSprite->extra].data4; + case 0: return actor->x().data1; + case 1: return actor->x().data2; + case 2: return actor->x().data3; + case 3: return actor->x().data4; } return -1; } +//--------------------------------------------------------------------------- +// // tries to get random data field of sprite +// +//--------------------------------------------------------------------------- + int randomGetDataValue(XSPRITE* pXSprite, int randType) { if (pXSprite == NULL) return -1; int random = 0; int bad = 0; int maxRetries = kMaxRandomizeRetries; @@ -5360,7 +5373,7 @@ void seqTxSendCmdAll(XSPRITE* pXSource, int nIndex, COMMAND_ID cmd, bool modernS } } else { for (int i = 0; i <= 3; i++) { - pXSource->txID = GetDataVal(&sprite[pXSource->reference], i); + pXSource->txID = GetDataVal(&bloodActors[pXSource->reference], i); if (pXSource->txID <= 0 || pXSource->txID >= kChannelUserMax) continue; else if (!modernSend) evSendActor(actor, pXSource->txID, cmd); else modernTypeSendCommand(nIndex, pXSource->txID, cmd); @@ -5397,7 +5410,8 @@ void useRandomTx(XSPRITE* pXSource, COMMAND_ID cmd, bool setState) { void useSequentialTx(XSPRITE* pXSource, COMMAND_ID cmd, bool setState) { - spritetype* pSource = &sprite[pXSource->reference]; + auto sourceactor = &bloodActors[pXSource->reference]; + spritetype* pSource = &sourceactor->s(); bool range = txIsRanged(pXSource); int cnt = 3; int tx = 0; if (range) { @@ -5419,7 +5433,7 @@ void useSequentialTx(XSPRITE* pXSource, COMMAND_ID cmd, bool setState) { if (!range) { while (cnt-- >= 0) { // skip empty data fields if (pXSource->sysData1-- < 0) pXSource->sysData1 = 3; - if ((tx = GetDataVal(pSource, pXSource->sysData1)) <= 0) continue; + if ((tx = GetDataVal(sourceactor, pXSource->sysData1)) <= 0) continue; else break; } } else { @@ -5431,7 +5445,7 @@ void useSequentialTx(XSPRITE* pXSource, COMMAND_ID cmd, bool setState) { if (!range) { while (cnt-- >= 0) { // skip empty data fields if (pXSource->sysData1 > 3) pXSource->sysData1 = 0; - if ((tx = GetDataVal(pSource, pXSource->sysData1++)) <= 0) continue; + if ((tx = GetDataVal(sourceactor, pXSource->sysData1++)) <= 0) continue; else break; } } else { @@ -7814,13 +7828,13 @@ int listTx(XSPRITE* pXRedir, int tx) { } else { if (tx == -1) { for (int i = 0; i <= 3; i++) { - if ((tx = GetDataVal(&sprite[pXRedir->reference], i)) <= 0) continue; + if ((tx = GetDataVal(&bloodActors[pXRedir->reference], i)) <= 0) continue; else return tx; } } else { int saved = tx; bool savedFound = false; for (int i = 0; i <= 3; i++) { - tx = GetDataVal(&sprite[pXRedir->reference], i); + tx = GetDataVal(&bloodActors[pXRedir->reference], i); if (savedFound && tx > 0) return tx; else if (tx != saved) continue; else savedFound = true; diff --git a/source/games/blood/src/nnexts.h b/source/games/blood/src/nnexts.h index 0a4fef669..c74bac460 100644 --- a/source/games/blood/src/nnexts.h +++ b/source/games/blood/src/nnexts.h @@ -302,7 +302,6 @@ void nnExtTriggerObject(int objType, int objIndex, int command); // ------------------------------------------------------------------------- // spritetype* randomDropPickupObject(spritetype* pSprite, short prevItem); spritetype* randomSpawnDude(XSPRITE* pXSource, spritetype* pSprite, int a3, int a4); -int GetDataVal(spritetype* pSprite, int data); int randomGetDataValue(XSPRITE* pXSprite, int randType); void sfxPlayMissileSound(spritetype* pSprite, int missileId); void sfxPlayVectorSound(spritetype* pSprite, int vectorId);