- owner stuff.

This reduces the number of direct references to spritetype.owner by half in the Blood code.
This commit is contained in:
Christoph Oelckers 2021-08-29 23:10:19 +02:00
parent 3b1ba88a41
commit 14ace49c3e
7 changed files with 80 additions and 62 deletions

View file

@ -3963,7 +3963,6 @@ static void actImpactMissile(DBloodActor* missileActor, int hitCode)
seqKill(missileActor);
if (hitCode == 3 && pSpriteHit && (pThingInfo || pDudeInfo))
{
int nOwner = pMissile->owner;
int nDamage = (15 + Random(7)) << 4;
actDamageSprite(missileOwner, actorHit, kDamageBullet, nDamage);
}
@ -4643,7 +4642,7 @@ static Collision MoveThing(DBloodActor* actor)
{
short bakCstat = pSprite->cstat;
pSprite->cstat &= ~257;
if ((pSprite->owner >= 0) && !cl_bloodvanillaexplosions && !VanillaMode())
if ((actor->GetOwner()) && !cl_bloodvanillaexplosions && !VanillaMode())
enginecompatibility_mode = ENGINECOMPATIBILITY_NONE; // improved clipmove accuracy
lhit = actor->hit.hit = ClipMove(&pSprite->pos, &nSector, actor->xvel() >> 12, actor->yvel() >> 12, pSprite->clipdist << 2, (pSprite->z - top) / 4, (bottom - pSprite->z) / 4, CLIPMASK0);
enginecompatibility_mode = bakCompat; // restore
@ -5765,7 +5764,7 @@ static void actCheckProximity()
default:
break;
}
if (pSprite->owner == -1) pSprite->owner = pSprite2->index;
if (actor->GetOwner() == nullptr) actor->SetOwner(dudeactor);
trTriggerSprite(actor, kCmdSpriteProximity);
}
}
@ -6637,7 +6636,7 @@ DBloodActor* actFireThing(DBloodActor* actor, int a2, int a3, int a4, int thingT
}
auto fired = actSpawnThing(pSprite->sectnum, x, y, z, thingType);
spritetype* pThing = &fired->s();
pThing->owner = pSprite->index;
fired->SetOwner(actor);
pThing->ang = pSprite->ang;
fired->xvel() = MulScale(a6, Cos(pThing->ang), 30);
fired->yvel() = MulScale(a6, Sin(pThing->ang), 30);
@ -6777,7 +6776,7 @@ DBloodActor* actFireMissile(DBloodActor* actor, int a2, int a3, int a4, int a5,
spawned->xvel() = MulScale(pMissileInfo->velocity, a4, 14);
spawned->yvel() = MulScale(pMissileInfo->velocity, a5, 14);
spawned->zvel() = MulScale(pMissileInfo->velocity, a6, 14);
pMissile->owner = pSprite->index;
spawned->SetOwner(actor);
pMissile->cstat |= 1;
spawned->SetTarget(nullptr);
evPostActor(spawned, 600, kCallbackRemove);
@ -7156,14 +7155,14 @@ void actFireVector(DBloodActor* shooter, int a2, int a3, int a4, int a5, int a6,
auto pFX2 = gFX.fxSpawnActor(pVectorData->surfHit[nSurf].fx2, nSector, x, y, z, 0);
if (pFX2 && gModernMap)
pFX2->s().owner = pShooter->index;
pFX2->SetOwner(shooter);
}
if (pVectorData->surfHit[nSurf].fx3 >= 0) {
auto pFX3 = gFX.fxSpawnActor(pVectorData->surfHit[nSurf].fx3, nSector, x, y, z, 0);
if (pFX3 && gModernMap)
pFX3->s().owner = pShooter->index;
pFX3->SetOwner(shooter);
}

View file

@ -1537,7 +1537,7 @@ void aiThinkTarget(DBloodActor* actor)
for (int p = connecthead; p >= 0; p = connectpoint2[p])
{
PLAYER* pPlayer = &gPlayer[p];
if (pSprite->owner == pPlayer->nSprite || pPlayer->pXSprite->health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0)
if (actor->GetOwner() == pPlayer->actor() || pPlayer->pXSprite->health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0)
continue;
int x = pPlayer->pSprite->x;
int y = pPlayer->pSprite->y;
@ -1585,7 +1585,7 @@ void aiLookForTarget(DBloodActor* actor)
for (int p = connecthead; p >= 0; p = connectpoint2[p])
{
PLAYER* pPlayer = &gPlayer[p];
if (pSprite->owner == pPlayer->nSprite || pPlayer->pXSprite->health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0)
if (actor->GetOwner() == pPlayer->actor() || pPlayer->pXSprite->health == 0 || powerupCheck(pPlayer, kPwUpShadowCloak) > 0)
continue;
int x = pPlayer->pSprite->x;
int y = pPlayer->pSprite->y;

View file

@ -264,8 +264,7 @@ void genDudeAttack1(int, DBloodActor* actor)
{
if ((spawned = actSpawnDude(actor, pExtra->curWeapon, dist + Random(dist), 0)) != NULL)
{
spritetype* pSpawned = &spawned->s();
pSpawned->owner = pSprite->index;
spawned->SetOwner(actor);
if (spawned->hasX())
{
@ -357,8 +356,8 @@ static void ThrowThing(DBloodActor* actor, bool impact)
auto const pXSpawned = &spawned->x();
if (pThinkInfo->picnum < 0 && pSpawned->type != kModernThingThrowableRock) pSpawned->picnum = 0;
pSpawned->owner = pSprite->index;
spawned->SetOwner(actor);
switch (curWeapon) {
case kThingNapalmBall:
pSpawned->xrepeat = pSpawned->yrepeat = 24;
@ -1915,7 +1914,7 @@ bool doExplosion(DBloodActor* actor, int nType)
pExplosion->type = nType;
pExplosion->cstat |= CSTAT_SPRITE_INVISIBLE;
pExplosion->owner = pSprite->index;
actExplosion->SetOwner(actor);
pExplosion->shade = -127;
pExplosion->yrepeat = pExplosion->xrepeat = pExpl->repeat;

View file

@ -83,7 +83,7 @@ void FlareBurst(DBloodActor* actor, int) // 2
pSpawn->xrepeat = pSpawn->yrepeat = 32;
pSpawn->type = kMissileFlareAlt;
pSpawn->clipdist = 2;
pSpawn->owner = pSprite->owner;
spawnedactor->SetOwner(actor);
int nAngle2 = (i<<11)/8;
int dx = 0;
int dy = mulscale30r(nRadius, Sin(nAngle2));
@ -244,7 +244,7 @@ void Respawn(DBloodActor* actor, int) // 9
assert(pSprite->owner >= 0 && pSprite->owner < kMaxStatus);
ChangeActorStat(actor, pSprite->owner);
pSprite->type = pSprite->inittype;
pSprite->owner = -1;
actor->SetOwner(nullptr);
pSprite->flags &= ~kHitagRespawn;
actor->xvel() = actor->yvel() = actor->zvel() = 0;
pXSprite->respawnPending = 0;
@ -503,19 +503,19 @@ void returnFlagToBase(DBloodActor* actor, int) // 17
{
if (!actor) return;
spritetype* pSprite = &actor->s();
auto owner = actor->GetOwner();
if (owner)
auto aOwner = actor->GetOwner();
if (aOwner)
{
switch (pSprite->type)
{
case kItemFlagA:
trTriggerSprite(owner, kCmdOn);
trTriggerSprite(aOwner, kCmdOn);
sndStartSample(8003, 255, 2, 0);
gBlueFlagDropped = false;
viewSetMessage("Blue Flag returned to base.");
break;
case kItemFlagB:
trTriggerSprite(owner, kCmdOn);
trTriggerSprite(aOwner, kCmdOn);
sndStartSample(8002, 255, 2, 0);
gRedFlagDropped = false;
viewSetMessage("Red Flag returned to base.");

View file

@ -195,7 +195,7 @@ int InsertSprite(int nSector, int nStat)
pSprite->cstat = 128;
pSprite->clipdist = 32;
pSprite->xrepeat = pSprite->yrepeat = 64;
pSprite->owner = -1;
actor->SetOwner(nullptr);
pSprite->extra = -1;
pSprite->index = nSprite;
actor->xvel() = actor->yvel() = actor->zvel() = 0;

View file

@ -1658,7 +1658,7 @@ int debrisGetFreeIndex(void)
//
//---------------------------------------------------------------------------
void debrisConcuss(DBloodActor* owner, int listIndex, int x, int y, int z, int dmg)
void debrisConcuss(DBloodActor* owneractor, int listIndex, int x, int y, int z, int dmg)
{
auto actor = gPhysSpritesList[listIndex];
if (actor != nullptr && actor->hasX())
@ -1668,7 +1668,7 @@ void debrisConcuss(DBloodActor* owner, int listIndex, int x, int y, int z, int d
dmg = scale(0x40000, dmg, 0x40000 + dx * dx + dy * dy + dz * dz);
bool thing = (pSprite->type >= kThingBase && pSprite->type < kThingMax);
int size = (tileWidth(pSprite->picnum) * pSprite->xrepeat * tileHeight(pSprite->picnum) * pSprite->yrepeat) >> 1;
if (xsprite[pSprite->extra].physAttr & kPhysDebrisExplode)
if (actor->x().physAttr & kPhysDebrisExplode)
{
if (actor->spriteMass.mass > 0)
{
@ -1683,7 +1683,7 @@ void debrisConcuss(DBloodActor* owner, int listIndex, int x, int y, int z, int d
pSprite->statnum = kStatThing; // temporary change statnum property
}
actDamageSprite(owner, actor, kDamageExplode, dmg);
actDamageSprite(owneractor, actor, kDamageExplode, dmg);
if (thing)
pSprite->statnum = kStatDecoration; // return statnum property back
@ -2914,25 +2914,35 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
pXSector->Underwater = (pXSource->data1) ? true : false;
spritetype* pLower = (gLowerLink[objIndex] >= 0) ? &sprite[gLowerLink[objIndex]] : NULL;
XSPRITE* pXLower = NULL; spritetype* pUpper = NULL; XSPRITE* pXUpper = NULL;
if (pLower) {
spritetype* pUpper = NULL; XSPRITE* pXUpper = NULL;
pXLower = &xsprite[pLower->extra];
auto aLower = getLowerLink(objIndex);
spritetype* pLower = nullptr;
XSPRITE* pXLower = nullptr;
if (aLower)
{
pLower = &aLower->s();
pXLower = &aLower->x();
// must be sure we found exact same upper link
for (int i = 0; i < kMaxSectors; i++) {
if (gUpperLink[i] < 0 || xsprite[sprite[gUpperLink[i]].extra].data1 != pXLower->data1) continue;
pUpper = &sprite[gUpperLink[i]]; pXUpper = &xsprite[pUpper->extra];
for (int i = 0; i < kMaxSectors; i++)
{
auto aUpper = getUpperLink(i);
if (aUpper == nullptr || aUpper->x().data1 != pXLower->data1) continue;
pUpper = &aUpper->s();
pXUpper = &aUpper->x();
break;
}
}
// treat sectors that have links, so warp can detect underwater status properly
if (pLower) {
if (pXSector->Underwater) {
switch (pLower->type) {
if (pLower)
{
if (pXSector->Underwater)
{
switch (pLower->type)
{
case kMarkerLowStack:
case kMarkerLowLink:
pXLower->sysData1 = pLower->type;
@ -2949,9 +2959,12 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
else pLower->type = kMarkerLowStack;
}
if (pUpper) {
if (pXSector->Underwater) {
switch (pUpper->type) {
if (pUpper)
{
if (pXSector->Underwater)
{
switch (pUpper->type)
{
case kMarkerUpStack:
case kMarkerUpLink:
pXUpper->sysData1 = pUpper->type;
@ -2977,13 +2990,16 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
continue;
PLAYER* pPlayer = getPlayerById(pSpr->type);
if (pXSector->Underwater) {
if (pXSector->Underwater)
{
if (pLower)
xsprite[pSpr->extra].medium = (pLower->type == kMarkerUpGoo) ? kMediumGoo : kMediumWater;
iactor->x().medium = (pLower->type == kMarkerUpGoo) ? kMediumGoo : kMediumWater;
if (pPlayer) {
if (pPlayer)
{
int waterPal = kMediumWater;
if (pLower) {
if (pLower)
{
if (pXLower->data2 > 0) waterPal = pXLower->data2;
else if (pLower->type == kMarkerUpGoo) waterPal = kMediumGoo;
}
@ -2993,10 +3009,12 @@ void usePropertiesChanger(DBloodActor* sourceactor, int objType, int objIndex, D
pPlayer->pXSprite->burnTime = 0;
}
} else {
xsprite[pSpr->extra].medium = kMediumNormal;
if (pPlayer) {
}
else
{
iactor->x().medium = kMediumNormal;
if (pPlayer)
{
pPlayer->posture = (!(pPlayer->input.actions & SB_CROUCH)) ? kPostureStand : kPostureCrouch;
pPlayer->nWaterPal = 0;
}
@ -3075,26 +3093,29 @@ void useTeleportTarget(DBloodActor* sourceactor, DBloodActor* actor)
if (pXSector->Underwater)
{
spritetype* pLink = (gLowerLink[pSource->sectnum] >= 0) ? &sprite[gLowerLink[pSource->sectnum]] : NULL;
if (pLink)
auto aLink = getLowerLink(pSource->sectnum);
spritetype* pLink = nullptr;
if (aLink)
{
// must be sure we found exact same upper link
for (int i = 0; i < kMaxSectors; i++) {
if (gUpperLink[i] < 0 || xsprite[sprite[gUpperLink[i]].extra].data1 != xsprite[pLink->extra].data1) continue;
pLink = &sprite[gUpperLink[i]];
for (int i = 0; i < kMaxSectors; i++)
{
auto aUpper = getUpperLink(i);
if (aUpper == nullptr || aUpper->x().data1 != aLink->x().data1) continue;
pLink = &aLink->s();
break;
}
}
if (pLink)
xsprite[pSprite->extra].medium = (pLink->type == kMarkerUpGoo) ? kMediumGoo : kMediumWater;
actor->x().medium = (pLink->type == kMarkerUpGoo) ? kMediumGoo : kMediumWater;
if (pPlayer)
{
int waterPal = kMediumWater;
if (pLink)
{
if (xsprite[pLink->extra].data2 > 0) waterPal = xsprite[pLink->extra].data2;
if (aLink->x().data2 > 0) waterPal = aLink->x().data2;
else if (pLink->type == kMarkerUpGoo) waterPal = kMediumGoo;
}
@ -3102,7 +3123,6 @@ void useTeleportTarget(DBloodActor* sourceactor, DBloodActor* actor)
pPlayer->posture = kPostureSwim;
pPlayer->pXSprite->burnTime = 0;
}
}
else
{
@ -3219,7 +3239,7 @@ void useEffectGen(DBloodActor* sourceactor, DBloodActor* actor)
if ((pEffect = gFX.fxSpawnActor((FX_ID)fxId, pSprite->sectnum, pSprite->x, pSprite->y, pos, 0)) != NULL)
{
auto pEffectSpr = &pEffect->s();
pEffectSpr->owner = pSource->index;
pEffect->SetOwner(sourceactor);
if (pSource->flags & kModernTypeFlag1)
{
@ -4540,7 +4560,7 @@ bool condCheckSprite(DBloodActor* aCond, int cmpOp, bool PUSH)
case 7: return condCmp(spriteGetSlope(pSpr), arg1, arg2, cmpOp);
case 10: return condCmp(pSpr->clipdist, arg1, arg2, cmpOp);
case 15:
if (!spriRangeIsFine(pSpr->owner)) return false;
if (!objActor->GetOwner()) return false;
else if (PUSH) condPush(aCond, OBJ_SPRITE, 0, objActor->GetOwner());
return true;
case 20: // stays in a sector?
@ -8440,7 +8460,7 @@ DBloodActor* aiPatrolSearchTargets(DBloodActor* actor)
sndy = emitter->y;
// sound attached to the sprite
if (pSpr->index != emitter->index && emitter->owner != pSpr->index)
if (pSpr != emitter && emitter->owner != pSpr->index)
{
if (!sectRangeIsFine(emitter->sectnum)) return false;
@ -9186,7 +9206,7 @@ void callbackUniMissileBurst(DBloodActor* actor, int) // 22
pBurst->xrepeat = pSprite->xrepeat / 2;
pBurst->yrepeat = pSprite->yrepeat / 2;
pBurst->ang = ((pSprite->ang + missileInfo[pSprite->type - kMissileBase].angleOfs) & 2047);
pBurst->owner = pSprite->owner;
burstactor->SetOwner(actor);
actBuildMissile(burstactor, actor);

View file

@ -2658,7 +2658,7 @@ void teslaHit(spritetype *pMissile, int a2)
int z = pMissile->z;
int nDist = 300;
int nSector = pMissile->sectnum;
auto owner = missileactor->GetOwner();
auto owneractor = missileactor->GetOwner();
const bool newSectCheckMethod = !cl_bloodvanillaexplosions && !VanillaMode(); // use new sector checking logic
GetClosestSpriteSectors(nSector, x, y, nDist, sectmap, nullptr, newSectCheckMethod);
bool v4 = true;
@ -2669,7 +2669,7 @@ void teslaHit(spritetype *pMissile, int a2)
BloodStatIterator it(kStatDude);
while (auto hitactor = it.Next())
{
if (hitactor != owner || v4)
if (hitactor != owneractor || v4)
{
spritetype *pHitSprite = &hitactor->s();
if (pHitSprite->flags&32)
@ -2679,9 +2679,9 @@ void teslaHit(spritetype *pMissile, int a2)
int dx = pMissile->x-pHitSprite->x;
int dy = pMissile->y-pHitSprite->y;
int nDamage = ClipLow((nDist-(ksqrt(dx*dx+dy*dy)>>4)+20)>>1, 10);
if (hitactor == owner)
if (hitactor == owneractor)
nDamage /= 2;
actDamageSprite(owner, hitactor, kDamageTesla, nDamage<<4);
actDamageSprite(owneractor, hitactor, kDamageTesla, nDamage<<4);
}
}
}
@ -2699,7 +2699,7 @@ void teslaHit(spritetype *pMissile, int a2)
int dx = pMissile->x-pHitSprite->x;
int dy = pMissile->y-pHitSprite->y;
int nDamage = ClipLow(nDist-(ksqrt(dx*dx+dy*dy)>>4)+20, 20);
actDamageSprite(owner, hitactor, kDamageTesla, nDamage << 4);
actDamageSprite(owneractor, hitactor, kDamageTesla, nDamage << 4);
}
}
}