- route all access to genDudeExtra through the method in DBloodActor

This commit is contained in:
Christoph Oelckers 2021-08-31 21:38:51 +02:00
parent cdacf8e470
commit 062b3dbf76
5 changed files with 38 additions and 33 deletions

View file

@ -2946,7 +2946,7 @@ static bool actKillModernDude(DBloodActor* actor, DAMAGE_TYPE damageType)
{ {
auto pSprite = &actor->s(); auto pSprite = &actor->s();
auto pXSprite = &actor->x(); auto pXSprite = &actor->x();
GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
removeDudeStuff(pSprite); removeDudeStuff(pSprite);
if (pXSprite->txID <= 0 || getNextIncarnation(pXSprite) == nullptr) 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); int dudeToGib = (actCheckRespawn(actor)) ? -1 : ((nSeq == 3) ? nDudeToGibClient2 : nDudeToGibClient1);
if (nSeq == 3) if (nSeq == 3)
{ {
GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
if (pExtra->availDeaths[kDmgBurn] == 3) seqSpawn((15 + Random(2)) + pXSprite->data2, actor, dudeToGib); 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] == 2) seqSpawn(16 + pXSprite->data2, actor, dudeToGib);
else if (pExtra->availDeaths[kDmgBurn] == 1) seqSpawn(15 + pXSprite->data2, actor, dudeToGib); else if (pExtra->availDeaths[kDmgBurn] == 1) seqSpawn(15 + pXSprite->data2, actor, dudeToGib);

View file

@ -1052,7 +1052,7 @@ int aiDamageSprite(DBloodActor* source, DBloodActor* actor, DAMAGE_TYPE nDmgType
if (pSprite->type == kDudeModernCustom) if (pSprite->type == kDudeModernCustom)
{ {
GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
if (nDmgType == kDamageBurn) if (nDmgType == kDamageBurn)
{ {
if (pXSprite->health > (uint32_t)pDudeInfo->fleeHealth) return nDamage; if (pXSprite->health > (uint32_t)pDudeInfo->fleeHealth) return nDamage;
@ -1273,7 +1273,7 @@ void RecoilDude(DBloodActor* actor)
#ifdef NOONE_EXTENSIONS #ifdef NOONE_EXTENSIONS
case kDudeModernCustom: 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)) if (pExtra->canElectrocute && pDudeExtra->teslaHit && !spriteIsUnderwater(pSprite, false))
{ {
@ -1668,7 +1668,7 @@ void aiProcessDudes(void)
#ifdef NOONE_EXTENSIONS #ifdef NOONE_EXTENSIONS
case kDudeModernCustom: case kDudeModernCustom:
case kDudeModernCustomBurning: { case kDudeModernCustomBurning: {
GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
if (pExtra->slaveCount > 0) updateTargetOfSlaves(pSprite); if (pExtra->slaveCount > 0) updateTargetOfSlaves(pSprite);
if (pExtra->nLifeLeech >= 0) updateTargetOfLeech(pSprite); if (pExtra->nLifeLeech >= 0) updateTargetOfLeech(pSprite);
if (pXSprite->stateTimer == 0 && pXSprite->aiState && pXSprite->aiState->nextState if (pXSprite->stateTimer == 0 && pXSprite->aiState && pXSprite->aiState->nextState

View file

@ -123,7 +123,7 @@ static void forcePunch(DBloodActor* actor)
{ {
auto pXSprite = &actor->x(); auto pXSprite = &actor->x();
auto pSprite = &actor->s(); 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); punchCallback(0, actor);
} }
@ -146,7 +146,7 @@ static bool genDudeAdjustSlope(DBloodActor* actor, int dist, int weaponType, int
{ {
int fStart = 0; int fStart = 0;
int fEnd = 0; int fEnd = 0;
GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
unsigned int clipMask = (weaponType == kGenDudeWeaponMissile) ? CLIPMASK0 : CLIPMASK1; unsigned int clipMask = (weaponType == kGenDudeWeaponMissile) ? CLIPMASK0 : CLIPMASK1;
for (int i = -8191; i < 8192; i += by) for (int i = -8191; i < 8192; i += by)
@ -185,7 +185,8 @@ GENDUDEEXTRA* genDudeExtra(spritetype* pGenDude) {
} }
void genDudeUpdate(spritetype* pSprite) { void genDudeUpdate(spritetype* pSprite) {
GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); auto actor = &bloodActors[pSprite->index];
GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
for (int i = 0; i < kGenDudePropertyMax; i++) { for (int i = 0; i < kGenDudePropertyMax; i++) {
if (pExtra->updReq[i]) genDudePrepare(pSprite, i); if (pExtra->updReq[i]) genDudePrepare(pSprite, i);
} }
@ -239,7 +240,7 @@ void genDudeAttack1(int, DBloodActor* actor)
int dx, dy, dz; int dx, dy, dz;
actor->xvel() = actor->yvel() = 0; actor->xvel() = actor->yvel() = 0;
GENDUDEEXTRA* pExtra = genDudeExtra(pSprite); GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
short dispersion = pExtra->baseDispersion; short dispersion = pExtra->baseDispersion;
if (inDuck(pXSprite->aiState)) if (inDuck(pXSprite->aiState))
dispersion = ClipLow(dispersion >> 1, kGenDudeMinDispesion); dispersion = ClipLow(dispersion >> 1, kGenDudeMinDispesion);
@ -322,8 +323,8 @@ static void ThrowThing(DBloodActor* actor, bool impact)
if (!(pTarget->type >= kDudeBase && pTarget->type < kDudeMax)) if (!(pTarget->type >= kDudeBase && pTarget->type < kDudeMax))
return; return;
short curWeapon = gGenDudeExtra[sprite[pXSprite->reference].index].curWeapon; int curWeapon = actor->genDudeExtra().curWeapon;
short weaponType = gGenDudeExtra[sprite[pXSprite->reference].index].weaponType; int weaponType = actor->genDudeExtra().weaponType;
if (weaponType != kGenDudeWeaponThrow) return; if (weaponType != kGenDudeWeaponThrow) return;
const THINGINFO* pThinkInfo = &thingInfo[curWeapon - kThingBase]; const THINGINFO* pThinkInfo = &thingInfo[curWeapon - kThingBase];
@ -401,7 +402,7 @@ static void ThrowThing(DBloodActor* actor, bool impact)
pXThing->Proximity = true; pXThing->Proximity = true;
pXThing->stateTimer = 1; pXThing->stateTimer = 1;
gGenDudeExtra[pSprite->index].nLifeLeech = pThing->index; actor->genDudeExtra().nLifeLeech = pThing->index;
evPost(pThing->index, 3, 80, kCallbackLeechStateTimer); evPost(pThing->index, 3, 80, kCallbackLeechStateTimer);
return; return;
} }
@ -520,7 +521,7 @@ static void unicultThinkChase(DBloodActor* actor)
//aiChooseDirection(actor,getangle(dx, dy)); //aiChooseDirection(actor,getangle(dx, dy));
aiGenDudeChooseDirection(pSprite, pXSprite, getangle(dx, dy), xvelocity, yvelocity); aiGenDudeChooseDirection(pSprite, pXSprite, getangle(dx, dy), xvelocity, yvelocity);
GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
if (!pExtra->canAttack) if (!pExtra->canAttack)
{ {
if (pExtra->canWalk) aiSetTarget(actor, actor); // targeting self??? 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); actor->dudeSlope = DivScale(pTarget->z - pSprite->z, dist, 10);
short curWeapon = gGenDudeExtra[pSprite->index].curWeapon; int curWeapon = actor->genDudeExtra().curWeapon;
short weaponType = gGenDudeExtra[pSprite->index].weaponType; int weaponType = actor->genDudeExtra().weaponType;
spritetype* pLeech = leechIsDropped(pSprite); spritetype* pLeech = leechIsDropped(pSprite);
const VECTORDATA* meleeVector = &gVectorData[22]; const VECTORDATA* meleeVector = &gVectorData[22];
if (weaponType == kGenDudeWeaponThrow) if (weaponType == kGenDudeWeaponThrow)
@ -653,7 +654,7 @@ static void unicultThinkChase(DBloodActor* actor)
} else { } else {
int vdist; int mdist; int defDist; int vdist; int mdist; int defDist;
defDist = vdist = mdist = gGenDudeExtra[pSprite->index].fireDist; defDist = vdist = mdist = actor->genDudeExtra().fireDist;
if (weaponType == kGenDudeWeaponHitscan) { if (weaponType == kGenDudeWeaponHitscan) {
if ((vdist = gVectorData[curWeapon].maxDist) <= 0) if ((vdist = gVectorData[curWeapon].maxDist) <= 0)
@ -667,7 +668,7 @@ static void unicultThinkChase(DBloodActor* actor)
aiSetTarget(actor, pSprite->x, pSprite->y, pSprite->z); aiSetTarget(actor, pSprite->x, pSprite->y, pSprite->z);
return; 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) if (dist <= meleeVector->maxDist)
{ {
@ -1071,7 +1072,7 @@ void aiGenDudeMoveForward(DBloodActor* actor)
auto pXSprite = &actor->x(); auto pXSprite = &actor->x();
auto pSprite = &actor->s(); auto pSprite = &actor->s();
DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type); DUDEINFO* pDudeInfo = getDudeInfo(pSprite->type);
GENDUDEEXTRA* pExtra = &gGenDudeExtra[pSprite->index]; GENDUDEEXTRA* pExtra = &actor->genDudeExtra();
int maxTurn = pDudeInfo->angSpeed * 4 >> 4; int maxTurn = pDudeInfo->angSpeed * 4 >> 4;
if (pExtra->canFly) if (pExtra->canFly)
@ -1168,11 +1169,13 @@ void aiGenDudeNewState(spritetype* pSprite, AISTATE* pAIState) {
Printf(PRINT_HIGH, "!xspriRangeIsFine(pSprite->extra)"); Printf(PRINT_HIGH, "!xspriRangeIsFine(pSprite->extra)");
return; return;
} }
auto actor = &bloodActors[pSprite->index];
XSPRITE* pXSprite = &xsprite[pSprite->extra]; XSPRITE* pXSprite = &xsprite[pSprite->extra];
// redirect dudes which cannot walk to non-walk states // 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) if (pAIState == &genDudeDodgeL || pAIState == &genDudeDodgeShortL || pAIState == &genDudeDodgeShorterL)
pAIState = &genDudeRecoilL; pAIState = &genDudeRecoilL;
@ -1234,7 +1237,7 @@ bool playGenDudeSound(spritetype* pSprite, int mode) {
const GENDUDESND* sndInfo =& gCustomDudeSnd[mode]; bool gotSnd = false; const GENDUDESND* sndInfo =& gCustomDudeSnd[mode]; bool gotSnd = false;
short sndStartId = xsprite[pSprite->extra].sysData1; int rand = sndInfo->randomRange; short sndStartId = xsprite[pSprite->extra].sysData1; int rand = sndInfo->randomRange;
int sndId = (sndStartId <= 0) ? sndInfo->defaultSndId : sndStartId + sndInfo->sndIdOffset; 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 // 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) // 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; return;
} }
auto actor = &bloodActors[pSprite->index];
XSPRITE* pXSprite = &xsprite[pSprite->extra]; 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; 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; XSPRITE* pXTarget = (pTarget != NULL && xspriRangeIsFine(pTarget->extra) && xsprite[pTarget->extra].health > 0) ? &xsprite[pTarget->extra] : NULL;

View file

@ -195,7 +195,6 @@ struct GENDUDEEXTRA
extern GENDUDEEXTRA gGenDudeExtra[kMaxSprites]; extern GENDUDEEXTRA gGenDudeExtra[kMaxSprites];
GENDUDEEXTRA* genDudeExtra(spritetype* pGenDude);
XSPRITE* getNextIncarnation(XSPRITE* pXSprite); XSPRITE* getNextIncarnation(XSPRITE* pXSprite);
void killDudeLeech(spritetype* pLeech); void killDudeLeech(spritetype* pLeech);
void removeLeech(spritetype* pLeech, bool delSprite = true); void removeLeech(spritetype* pLeech, bool delSprite = true);

View file

@ -3760,6 +3760,7 @@ bool condCheckDude(XSPRITE* pXCond, int cmpOp, bool PUSH) {
if (objType != OBJ_SPRITE || !spriRangeIsFine(objIndex)) if (objType != OBJ_SPRITE || !spriRangeIsFine(objIndex))
condError(pXCond, "Object #%d (objType: %d) is not a sprite!", objIndex, objType); condError(pXCond, "Object #%d (objType: %d) is not a sprite!", objIndex, objType);
auto actor = &bloodActors[objIndex];
spritetype* pSpr = &sprite[objIndex]; spritetype* pSpr = &sprite[objIndex];
if (!xsprIsFine(pSpr) || pSpr->type == kThingBloodChunks) if (!xsprIsFine(pSpr) || pSpr->type == kThingBloodChunks)
condError(pXCond, "Object #%d (objType: %d) is dead!", objIndex, objType); condError(pXCond, "Object #%d (objType: %d) is dead!", objIndex, objType);
@ -3846,12 +3847,12 @@ bool condCheckDude(XSPRITE* pXCond, int cmpOp, bool PUSH) {
case kDudeModernCustomBurning: case kDudeModernCustomBurning:
switch (cond) { switch (cond) {
case 20: // life leech is thrown? case 20: // life leech is thrown?
var = genDudeExtra(pSpr)->nLifeLeech; var = actor->genDudeExtra().nLifeLeech;
if (!spriRangeIsFine(var)) return false; if (!spriRangeIsFine(var)) return false;
else if (PUSH) condPush(pXCond, OBJ_SPRITE, var); else if (PUSH) condPush(pXCond, OBJ_SPRITE, var);
return true; return true;
case 21: // life leech is destroyed? case 21: // life leech is destroyed?
var = genDudeExtra(pSpr)->nLifeLeech; var = actor->genDudeExtra().nLifeLeech;
if (!spriRangeIsFine(var) && pSpr->owner == kMaxSprites - 1) return true; if (!spriRangeIsFine(var) && pSpr->owner == kMaxSprites - 1) return true;
else if (PUSH) condPush(pXCond, OBJ_SPRITE, var); else if (PUSH) condPush(pXCond, OBJ_SPRITE, var);
return false; return false;
@ -3859,19 +3860,19 @@ bool condCheckDude(XSPRITE* pXCond, int cmpOp, bool PUSH) {
return condCmp(gGenDudeExtra[pSpr->index].slaveCount, arg1, arg2, cmpOp); return condCmp(gGenDudeExtra[pSpr->index].slaveCount, arg1, arg2, cmpOp);
case 23: // check if dude can... case 23: // check if dude can...
switch (arg3) { switch (arg3) {
case 1: return genDudeExtra(pSpr)->canAttack; case 1: return actor->genDudeExtra().canAttack;
case 2: return genDudeExtra(pSpr)->canBurn; case 2: return actor->genDudeExtra().canBurn;
case 3: return genDudeExtra(pSpr)->canDuck; case 3: return actor->genDudeExtra().canDuck;
case 4: return genDudeExtra(pSpr)->canElectrocute; case 4: return actor->genDudeExtra().canElectrocute;
case 5: return genDudeExtra(pSpr)->canFly; case 5: return actor->genDudeExtra().canFly;
case 6: return genDudeExtra(pSpr)->canRecoil; case 6: return actor->genDudeExtra().canRecoil;
case 7: return genDudeExtra(pSpr)->canSwim; case 7: return actor->genDudeExtra().canSwim;
case 8: return genDudeExtra(pSpr)->canWalk; case 8: return actor->genDudeExtra().canWalk;
default: condError(pXCond, "Invalid argument %d", arg3); break; default: condError(pXCond, "Invalid argument %d", arg3); break;
} }
break; break;
case 24: // compare weapon dispersion case 24: // compare weapon dispersion
return condCmp(genDudeExtra(pSpr)->baseDispersion, arg1, arg2, cmpOp); return condCmp(actor->genDudeExtra().baseDispersion, arg1, arg2, cmpOp);
} }
break; break;
default: default: