- replaced tgt_sp wrapper.

This commit is contained in:
Christoph Oelckers 2021-10-31 00:53:23 +02:00
parent 84b83ad9b8
commit 0de816d308
11 changed files with 48 additions and 45 deletions

View file

@ -855,8 +855,8 @@ DoBunnyBeginJumpAttack(DSWActor* actor)
{
USER* u = actor->u();
int SpriteNum = u->SpriteNum;
SPRITEp sp = &sprite[SpriteNum];
SPRITEp psp = User[SpriteNum]->tgt_sp();
SPRITEp sp = &actor->s();
SPRITEp psp = &u->targetActor->s();
short tang;
tang = getangle(psp->x - sp->x, psp->y - sp->y);
@ -1145,7 +1145,7 @@ int DoBunnyRipHeart(DSWActor* actor)
int SpriteNum = u->SpriteNum;
SPRITEp sp = &sprite[SpriteNum];
SPRITEp tsp = u->tgt_sp();
SPRITEp tsp = &u->targetActor->s();
NewStateGroup(actor, sg_BunnyHeart);
u->WaitTics = 6 * 120;

View file

@ -432,8 +432,8 @@ int DoEelMatchPlayerZ(DSWActor* actor)
{
USER* u = actor->u();
int SpriteNum = u->SpriteNum;
SPRITEp sp = &sprite[SpriteNum];
SPRITEp tsp = User[SpriteNum]->tgt_sp();
SPRITEp sp = &actor->s();
SPRITEp tsp = &u->targetActor->s();
int zdiff,zdist;
int loz,hiz;
int dist,a,b,c;
@ -579,7 +579,7 @@ int DoEelMove(DSWActor* actor)
ASSERT(u->Rot != nullptr);
if (SpriteOverlap(SpriteNum, int16_t(u->tgt_sp() - sprite)))
if (SpriteOverlap(SpriteNum, u->targetActor->GetSpriteIndex()))
NewStateGroup(actor, u->ActorActionSet->CloseAttack[0]);
if (TEST(u->Flags,SPR_SLIDING))

View file

@ -1179,7 +1179,6 @@ struct USER
// target player for the enemy - can only handle one player at at time
//PLAYERp tgt_player;
DSWActor* targetActor;
SPRITEp tgt_sp();
// scaling
short scale_speed;
@ -2253,11 +2252,6 @@ Collision USER::hitCode() const
return Collision(ret);
}
SPRITEp USER::tgt_sp()
{
return targetActor == nullptr? nullptr : &targetActor->s();
}
inline int ActorUpper(DSWActor* actor)
{
return SPRITEp_UPPER(&actor->s());

View file

@ -352,7 +352,7 @@ int DoHornetMatchPlayerZ(short SpriteNum)
{
SPRITEp sp = &sprite[SpriteNum];
USERp u = User[SpriteNum].Data();
SPRITEp tsp = User[SpriteNum]->tgt_sp();
SPRITEp tsp = &u->targetActor->s();
int zdiff,zdist;
int loz,hiz;
@ -567,7 +567,7 @@ int DoCheckSwarm(DSWActor* actor)
if (!MoveSkip8) return 0; // Don't over check
if (!u->tgt_sp()) return 0;
if (!u->targetActor) return 0;
// Who's the closest meat!?
DoActorPickClosePlayer(actor);

View file

@ -1092,8 +1092,8 @@ DoRipperBeginJumpAttack(DSWActor* actor)
{
USER* u = actor->u();
int SpriteNum = u->SpriteNum;
SPRITEp sp = &sprite[SpriteNum];
SPRITEp psp = User[SpriteNum]->tgt_sp();
SPRITEp sp = &actor->s();
SPRITEp psp = &u->targetActor->s();
short tang;
tang = getangle(psp->x - sp->x, psp->y - sp->y);
@ -1215,7 +1215,7 @@ int DoRipperRipHeart(short SpriteNum)
SPRITEp sp = &sprite[SpriteNum];
USERp u = User[SpriteNum].Data();
SPRITEp tsp = u->tgt_sp();
SPRITEp tsp = &u->targetActor->s();
NewStateGroup(actor, sg_RipperHeart);
u->WaitTics = 6 * 120;

View file

@ -1098,7 +1098,7 @@ DoRipper2BeginJumpAttack(DSWActor* actor)
USER* u = actor->u();
int SpriteNum = u->SpriteNum;
SPRITEp sp = &sprite[SpriteNum];
SPRITEp psp = User[SpriteNum]->tgt_sp();
SPRITEp psp = &u->targetActor->s();
short tang;
tang = getangle(psp->x - sp->x, psp->y - sp->y);
@ -1222,7 +1222,7 @@ int DoRipper2RipHeart(short SpriteNum)
SPRITEp sp = &sprite[SpriteNum];
USERp u = User[SpriteNum].Data();
SPRITEp tsp = u->tgt_sp();
SPRITEp tsp = &u->targetActor->s();
NewStateGroup(actor, sg_Ripper2Heart);
u->WaitTics = 6 * 120;

View file

@ -397,7 +397,7 @@ int DoSkullJump(DSWActor* actor)
DISTANCE(sp->x, sp->y, u->targetActor->s().x, u->targetActor->s().y, dist, a, b, c);
if (dist < 1000 &&
SpriteOverlapZ(SpriteNum, short(u->tgt_sp() - sprite), Z(32)))
SpriteOverlapZ(SpriteNum, u->targetActor->GetSpriteIndex(), Z(32)))
{
UpdateSinglePlayKills(actor);
DoSkullBeginDeath(actor);
@ -812,7 +812,7 @@ int DoBettyJump(DSWActor* actor)
DISTANCE(sp->x, sp->y, u->targetActor->s().x, u->targetActor->s().y, dist, a, b, c);
if (dist < 1000 &&
SpriteOverlapZ(SpriteNum, short(u->tgt_sp() - sprite), Z(32)))
SpriteOverlapZ(SpriteNum, u->targetActor->GetSpriteIndex(), Z(32)))
{
UpdateSinglePlayKills(actor);
DoBettyBeginDeath(actor);

View file

@ -774,7 +774,7 @@ void KillSprite(int16_t SpriteNum)
while ((i = it.NextIndex()) >= 0)
{
auto itActor = &swActors[i];
if ((unsigned)i < MAXSPRITES && User[i].Data() != nullptr && User[i]->tgt_sp() == sp)
if ((unsigned)i < MAXSPRITES && User[i].Data() != nullptr && User[i]->targetActor == actor)
{
DoActorPickClosePlayer(itActor);
}

View file

@ -219,14 +219,14 @@ ActorFindTrack(short SpriteNum, int8_t player_dir, int track_type, short *track_
// to
if (player_dir == TOWARD_PLAYER)
{
if (!TrackTowardPlayer(u->tgt_sp(), t, tp))
if (!TrackTowardPlayer(&u->targetActor->s(), t, tp))
{
continue;
}
}
else if (player_dir == AWAY_FROM_PLAYER)
{
if (TrackTowardPlayer(u->tgt_sp(), t, tp))
if (TrackTowardPlayer(&u->targetActor->s(), t, tp))
{
continue;
}
@ -2937,7 +2937,7 @@ DoAutoTurretObject(SECTOR_OBJECTp sop)
u->WaitTics -= synctics;
// check for new player if doesn't have a target or time limit expired
if (!u->tgt_sp() || u->WaitTics < 0)
if (!u->targetActor || u->WaitTics < 0)
{
// 4 seconds
u->WaitTics = 4*120;

View file

@ -12814,9 +12814,10 @@ DoSerpRing(DSWActor* actor)
if (u->Counter2 > 0)
{
if (!User[ou->tgt_sp()-sprite].Data() ||
!User[ou->tgt_sp()-sprite]->PlayerP ||
!TEST(User[ou->tgt_sp()-sprite]->PlayerP->Flags, PF_DEAD))
auto tu = ou->targetActor->u();
if (!ou->targetActor->hasU() ||
!tu->PlayerP ||
!TEST(tu->PlayerP->Flags, PF_DEAD))
{
u->targetActor = ou->targetActor;
DISTANCE(sp->x, sp->y, u->targetActor->s().x, u->targetActor->s().y, dist, a,b,c);
@ -13911,9 +13912,10 @@ InitSumoStompAttack(short SpriteNum)
StatIterator it(StatDamageList[stat]);
while ((i = it.NextIndex()) >= 0)
{
auto itActor = &swActors[i];
tsp = &sprite[i];
if (tsp != u->tgt_sp())
if (itActor != u->targetActor)
break;
if (!TEST(tsp->extra, SPRX_PLAYER_OR_ENEMY))
@ -13944,29 +13946,29 @@ InitMiniSumoClap(short SpriteNum)
short reach;
if (!u->tgt_sp()) return 0;
if (!u->targetActor) return 0;
dist = Distance(sp->x, sp->y, u->targetActor->s().x, u->targetActor->s().y);
reach = 10000;
if (dist < CLOSE_RANGE_DIST_FUDGE(u->tgt_sp(), sp, 1000))
if (dist < CLOSE_RANGE_DIST_FUDGE(&u->targetActor->s(), sp, 1000))
{
if (SpriteOverlapZ(SpriteNum, short(u->tgt_sp() - sprite), Z(20)))
if (SpriteOverlapZ(SpriteNum, u->targetActor->GetSpriteIndex(), Z(20)))
{
if (FAFcansee(u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum,sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum))
{
PlaySound(DIGI_CGTHIGHBONE, sp, v3df_follow|v3df_dontpan);
DoDamage(short(u->tgt_sp() - sprite), SpriteNum);
DoDamage(u->targetActor->GetSpriteIndex(), SpriteNum);
}
}
}
else if (dist < CLOSE_RANGE_DIST_FUDGE(u->tgt_sp(), sp, reach))
else if (dist < CLOSE_RANGE_DIST_FUDGE(&u->targetActor->s(), sp, reach))
{
if (FAFcansee(u->targetActor->s().x,u->targetActor->s().y,ActorMid(u->targetActor),u->targetActor->s().sectnum,sp->x,sp->y,SPRITEp_MID(sp),sp->sectnum))
{
PlaySound(DIGI_30MMEXPLODE, sp, v3df_none);
SpawnFireballFlames(SpriteNum, short(u->tgt_sp() - sprite));
SpawnFireballFlames(SpriteNum, u->targetActor->GetSpriteIndex());
}
}
@ -14126,10 +14128,10 @@ AimHitscanToTarget(SPRITEp sp, int *z, short *ang, int z_ratio)
SPRITEp hp;
USERp hu;
if (!u->tgt_sp())
if (!u->targetActor)
return -1;
hit_sprite = short(u->tgt_sp() - sprite);
hit_sprite = u->targetActor->GetSpriteIndex();
hp = &sprite[hit_sprite];
hu = User[hit_sprite].Data();
@ -16911,13 +16913,14 @@ InitEelFire(DSWActor* actor)
StatIterator it(StatDamageList[stat]);
while ((i = it.NextIndex()) >= 0)
{
auto itActor = &swActors[i];
hp = &sprite[i];
hu = User[i].Data();
if (i == SpriteNum)
continue;
if (hp != u->tgt_sp())
if (itActor != u->targetActor)
continue;
if ((unsigned)FindDistance3D(sp->x - hp->x, sp->y - hp->y, sp->z - hp->z) > hu->Radius + u->Radius)
@ -19354,7 +19357,7 @@ InitEnemyFireball(DSWActor* actor)
ASSERT(SpriteNum >= 0);
tsp = u->tgt_sp();
tsp = &u->targetActor->s();
PlaySound(DIGI_FIREBALL1, sp, v3df_none);

View file

@ -804,7 +804,6 @@ SpawnZombie(PLAYERp pp, short Weapon)
SET(np->cstat, CSTAT_SPRITE_TRANSLUCENT);
DoActorPickClosePlayer(actorNew);
//nu->tgt_sp() = pp->SpriteP; // Make it target last killed player initially
// make immediately active
SET(nu->Flags, SPR_ACTIVE);
@ -868,7 +867,6 @@ SpawnZombie2(short Weapon)
SET(np->cstat, CSTAT_SPRITE_TRANSLUCENT);
DoActorPickClosePlayer(actorNew);
//nu->tgt_sp() = pp->SpriteP; // Make it target last killed player initially
// make immediately active
SET(nu->Flags, SPR_ACTIVE);
@ -897,8 +895,12 @@ DoZombieMove(DSWActor* actor)
return 0;
}
if (u->tgt_sp() && User[u->tgt_sp()-sprite].Data() && TEST(User[u->tgt_sp()-sprite]->Flags, PF_DEAD)) // JBF: added User[] null check
DoActorPickClosePlayer(actor);
if (u->targetActor && u->targetActor->hasU())
{
auto tu = u->targetActor->u();
if (TEST(tu->Flags, PF_DEAD)) // JBF: added User[] null check
DoActorPickClosePlayer(actor);
}
// jumping and falling
if (TEST(u->Flags, SPR_JUMPING | SPR_FALLING))
@ -948,8 +950,12 @@ NullZombie(DSWActor* actor)
return 0;
}
if (u->tgt_sp() && User[u->tgt_sp()-sprite].Data() && TEST(User[u->tgt_sp()-sprite]->Flags, PF_DEAD))
DoActorPickClosePlayer(actor);
if (u->targetActor && u->targetActor->hasU())
{
auto tu = u->targetActor->u();
if (TEST(tu->Flags, PF_DEAD)) // JBF: added User[] null check
DoActorPickClosePlayer(actor);
}
if (u->WaitTics > 0)
u->WaitTics -= ACTORMOVETICS;