diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 330ab7099..72f39f399 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -2946,7 +2946,7 @@ static bool actKillModernDude(DBloodActor* actor, DAMAGE_TYPE damageType) { auto pSprite = &actor->s(); auto pXSprite = &actor->x(); - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); removeDudeStuff(pSprite); if (pXSprite->txID <= 0 || getNextIncarnation(pXSprite) == nullptr) { @@ -3343,7 +3343,7 @@ static void modernCustomDudeDeath(DBloodActor* actor, int nSeq, int damageType) int dudeToGib = (actCheckRespawn(actor)) ? -1 : ((nSeq == 3) ? nDudeToGibClient2 : nDudeToGibClient1); if (nSeq == 3) { - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); if (pExtra->availDeaths[kDmgBurn] == 3) seqSpawn((15 + Random(2)) + pXSprite->data2, actor, dudeToGib); else if (pExtra->availDeaths[kDmgBurn] == 2) seqSpawn(16 + pXSprite->data2, actor, dudeToGib); else if (pExtra->availDeaths[kDmgBurn] == 1) seqSpawn(15 + pXSprite->data2, actor, dudeToGib); diff --git a/source/games/blood/src/ai.cpp b/source/games/blood/src/ai.cpp index cc78a1d20..92e6a57d8 100644 --- a/source/games/blood/src/ai.cpp +++ b/source/games/blood/src/ai.cpp @@ -1052,7 +1052,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType if (pSprite->type == kDudeModernCustom) { - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); if (nDmgType == kDamageBurn) { if (pXSprite->health > (uint32_t)pDudeInfo->fleeHealth) return nDamage; @@ -1273,7 +1273,7 @@ void RecoilDude(DBloodActor* actor) #ifdef NOONE_EXTENSIONS case kDudeModernCustom: { - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); int rChance = getRecoilChance(pSprite); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); int rChance = getRecoilChance(pSprite); if (pExtra->canElectrocute && pDudeExtra->teslaHit && !spriteIsUnderwater(pSprite, false)) { @@ -1668,7 +1668,7 @@ void aiProcessDudes(void) #ifdef NOONE_EXTENSIONS case kDudeModernCustom: case kDudeModernCustomBurning: { - GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); if (pExtra->slaveCount > 0) updateTargetOfSlaves(pSprite); if (pExtra->nLifeLeech >= 0) updateTargetOfLeech(pSprite); if (pXSprite->stateTimer == 0 && pXSprite->aiState && pXSprite->aiState->nextState diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index d6f352ece..c6080e06f 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -123,7 +123,7 @@ static void forcePunch(DBloodActor* actor) { auto pXSprite = &actor->x(); auto pSprite = &actor->s(); - if (gGenDudeExtra[pSprite->index].forcePunch && seqGetStatus(3, pSprite->extra) == -1) + if (actor->genDudeExtra().forcePunch && seqGetStatus(3, pSprite->extra) == -1) punchCallback(0, actor); } @@ -146,7 +146,7 @@ static bool genDudeAdjustSlope(DBloodActor* actor, int dist, int weaponType, int { int fStart = 0; int fEnd = 0; - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); unsigned int clipMask = (weaponType == kGenDudeWeaponMissile) ? CLIPMASK0 : CLIPMASK1; for (int i = -8191; i < 8192; i += by) @@ -185,7 +185,8 @@ GENDUDEEXTRA* genDudeExtra(spritetype* pGenDude) { } void genDudeUpdate(spritetype* pSprite) { - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); + auto actor = &bloodActors[pSprite->index]; + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); for (int i = 0; i < kGenDudePropertyMax; i++) { if (pExtra->updReq[i]) genDudePrepare(pSprite, i); } @@ -239,7 +240,7 @@ void genDudeAttack1(int, DBloodActor* actor) int dx, dy, dz; actor->xvel() = actor->yvel() = 0; - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); short dispersion = pExtra->baseDispersion; if (inDuck(pXSprite->aiState)) dispersion = ClipLow(dispersion >> 1, kGenDudeMinDispesion); @@ -322,8 +323,8 @@ static void ThrowThing(DBloodActor* actor, bool impact) if (!(pTarget->type >= kDudeBase && pTarget->type < kDudeMax)) return; - short curWeapon = gGenDudeExtra[sprite[pXSprite->reference].index].curWeapon; - short weaponType = gGenDudeExtra[sprite[pXSprite->reference].index].weaponType; + int curWeapon = actor->genDudeExtra().curWeapon; + int weaponType = actor->genDudeExtra().weaponType; if (weaponType != kGenDudeWeaponThrow) return; const THINGINFO* pThinkInfo = &thingInfo[curWeapon - kThingBase]; @@ -401,7 +402,7 @@ static void ThrowThing(DBloodActor* actor, bool impact) pXThing->Proximity = true; pXThing->stateTimer = 1; - gGenDudeExtra[pSprite->index].nLifeLeech = pThing->index; + actor->genDudeExtra().nLifeLeech = pThing->index; evPost(pThing->index, 3, 80, kCallbackLeechStateTimer); return; } @@ -520,7 +521,7 @@ static void unicultThinkChase(DBloodActor* actor) //aiChooseDirection(actor,getangle(dx, dy)); aiGenDudeChooseDirection(pSprite, pXSprite, getangle(dx, dy), xvelocity, yvelocity); - GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); if (!pExtra->canAttack) { if (pExtra->canWalk) aiSetTarget(actor, actor); // targeting self??? @@ -558,8 +559,8 @@ static void unicultThinkChase(DBloodActor* actor) actor->dudeSlope = DivScale(pTarget->z - pSprite->z, dist, 10); - short curWeapon = gGenDudeExtra[pSprite->index].curWeapon; - short weaponType = gGenDudeExtra[pSprite->index].weaponType; + int curWeapon = actor->genDudeExtra().curWeapon; + int weaponType = actor->genDudeExtra().weaponType; spritetype* pLeech = leechIsDropped(pSprite); const VECTORDATA* meleeVector = &gVectorData[22]; if (weaponType == kGenDudeWeaponThrow) @@ -653,7 +654,7 @@ static void unicultThinkChase(DBloodActor* actor) } else { int vdist; int mdist; int defDist; - defDist = vdist = mdist = gGenDudeExtra[pSprite->index].fireDist; + defDist = vdist = mdist = actor->genDudeExtra().fireDist; if (weaponType == kGenDudeWeaponHitscan) { if ((vdist = gVectorData[curWeapon].maxDist) <= 0) @@ -667,7 +668,7 @@ static void unicultThinkChase(DBloodActor* actor) aiSetTarget(actor, pSprite->x, pSprite->y, pSprite->z); return; } - else if (gGenDudeExtra[pSprite->index].slaveCount > gGameOptions.nDifficulty || dist < meleeVector->maxDist) + else if (actor->genDudeExtra().slaveCount > gGameOptions.nDifficulty || dist < meleeVector->maxDist) { if (dist <= meleeVector->maxDist) { @@ -1071,7 +1072,7 @@ void aiGenDudeMoveForward(DBloodActor* actor) auto pXSprite = &actor->x(); auto pSprite = &actor->s(); DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type); - GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); int maxTurn = pDudeInfo->angSpeed * 4 >> 4; if (pExtra->canFly) @@ -1168,11 +1169,13 @@ void aiGenDudeNewState(spritetype* pSprite, AISTATE* pAIState) { Printf(PRINT_HIGH, "!xspriRangeIsFine(pSprite->extra)"); return; } + auto actor = &bloodActors[pSprite->index]; XSPRITE* pXSprite = &xsprite[pSprite->extra]; // redirect dudes which cannot walk to non-walk states - if (!gGenDudeExtra[pSprite->index].canWalk) { + if (!actor->genDudeExtra().canWalk) + { if (pAIState == &genDudeDodgeL || pAIState == &genDudeDodgeShortL || pAIState == &genDudeDodgeShorterL) pAIState = &genDudeRecoilL; @@ -1234,7 +1237,7 @@ bool playGenDudeSound(spritetype* pSprite, int mode) { const GENDUDESND* sndInfo =& gCustomDudeSnd[mode]; bool gotSnd = false; short sndStartId = xsprite[pSprite->extra].sysData1; int rand = sndInfo->randomRange; int sndId = (sndStartId <= 0) ? sndInfo->defaultSndId : sndStartId + sndInfo->sndIdOffset; - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); // let's check if there same sounds already played by other dudes // so we won't get a lot of annoying screams in the same time and ensure sound played in it's full length (if not interruptable) @@ -1966,8 +1969,10 @@ void updateTargetOfSlaves(spritetype* pSprite) { return; } + auto actor = &bloodActors[pSprite->index]; XSPRITE* pXSprite = &xsprite[pSprite->extra]; - GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); short* slave = pExtra->slave; + GENDUDEEXTRA* pExtra = &actor->genDudeExtra(); + short* slave = pExtra->slave; spritetype* pTarget = (pXSprite->target_i >= 0 && IsDudeSprite(&sprite[pXSprite->target_i])) ? &sprite[pXSprite->target_i] : NULL; XSPRITE* pXTarget = (pTarget != NULL && xspriRangeIsFine(pTarget->extra) && xsprite[pTarget->extra].health > 0) ? &xsprite[pTarget->extra] : NULL; diff --git a/source/games/blood/src/aiunicult.h b/source/games/blood/src/aiunicult.h index d42b7e09a..d0ff3135e 100644 --- a/source/games/blood/src/aiunicult.h +++ b/source/games/blood/src/aiunicult.h @@ -195,7 +195,6 @@ struct GENDUDEEXTRA extern GENDUDEEXTRA gGenDudeExtra[kMaxSprites]; -GENDUDEEXTRA* genDudeExtra(spritetype* pGenDude); XSPRITE* getNextIncarnation(XSPRITE* pXSprite); void killDudeLeech(spritetype* pLeech); void removeLeech(spritetype* pLeech, bool delSprite = true); diff --git a/source/games/blood/src/nnexts.cpp b/source/games/blood/src/nnexts.cpp index 856b75a41..6f982d104 100644 --- a/source/games/blood/src/nnexts.cpp +++ b/source/games/blood/src/nnexts.cpp @@ -3760,6 +3760,7 @@ bool condCheckDude(XSPRITE* pXCond, int cmpOp, bool PUSH) { if (objType != OBJ_SPRITE || !spriRangeIsFine(objIndex)) condError(pXCond, "Object #%d (objType: %d) is not a sprite!", objIndex, objType); + auto actor = &bloodActors[objIndex]; spritetype* pSpr = &sprite[objIndex]; if (!xsprIsFine(pSpr) || pSpr->type == kThingBloodChunks) condError(pXCond, "Object #%d (objType: %d) is dead!", objIndex, objType); @@ -3846,12 +3847,12 @@ bool condCheckDude(XSPRITE* pXCond, int cmpOp, bool PUSH) { case kDudeModernCustomBurning: switch (cond) { case 20: // life leech is thrown? - var = genDudeExtra(pSpr)->nLifeLeech; + var = actor->genDudeExtra().nLifeLeech; if (!spriRangeIsFine(var)) return false; else if (PUSH) condPush(pXCond, OBJ_SPRITE, var); return true; case 21: // life leech is destroyed? - var = genDudeExtra(pSpr)->nLifeLeech; + var = actor->genDudeExtra().nLifeLeech; if (!spriRangeIsFine(var) && pSpr->owner == kMaxSprites - 1) return true; else if (PUSH) condPush(pXCond, OBJ_SPRITE, var); return false; @@ -3859,19 +3860,19 @@ bool condCheckDude(XSPRITE* pXCond, int cmpOp, bool PUSH) { return condCmp(gGenDudeExtra[pSpr->index].slaveCount, arg1, arg2, cmpOp); case 23: // check if dude can... switch (arg3) { - case 1: return genDudeExtra(pSpr)->canAttack; - case 2: return genDudeExtra(pSpr)->canBurn; - case 3: return genDudeExtra(pSpr)->canDuck; - case 4: return genDudeExtra(pSpr)->canElectrocute; - case 5: return genDudeExtra(pSpr)->canFly; - case 6: return genDudeExtra(pSpr)->canRecoil; - case 7: return genDudeExtra(pSpr)->canSwim; - case 8: return genDudeExtra(pSpr)->canWalk; + case 1: return actor->genDudeExtra().canAttack; + case 2: return actor->genDudeExtra().canBurn; + case 3: return actor->genDudeExtra().canDuck; + case 4: return actor->genDudeExtra().canElectrocute; + case 5: return actor->genDudeExtra().canFly; + case 6: return actor->genDudeExtra().canRecoil; + case 7: return actor->genDudeExtra().canSwim; + case 8: return actor->genDudeExtra().canWalk; default: condError(pXCond, "Invalid argument %d", arg3); break; } break; case 24: // compare weapon dispersion - return condCmp(genDudeExtra(pSpr)->baseDispersion, arg1, arg2, cmpOp); + return condCmp(actor->genDudeExtra().baseDispersion, arg1, arg2, cmpOp); } break; default: