- WpnGoal + sprite_num.

This commit is contained in:
Christoph Oelckers 2021-11-01 18:10:38 +01:00
parent 8336f689dd
commit 8780be4ee4
5 changed files with 56 additions and 61 deletions

View file

@ -1132,6 +1132,7 @@ struct USER
DSWActor* flameActor;
DSWActor* attachActor; // attach to sprite if needed - electro snake
DSWActor* flagOwnerActor;
DSWActor* WpnGoalActor;
int Flags;
int Flags2;
@ -1192,7 +1193,6 @@ struct USER
short DamageTics;
short BladeDamageTics;
short WpnGoal;
unsigned int Radius; // for distance checking
int OverlapZ; // for z overlap variable
@ -1539,23 +1539,18 @@ extern TPointer<SECT_USER> SectUser[MAXSECTORS];
SECT_USERp SpawnSectUser(short sectnum);
typedef struct
{
unsigned int size, checksum;
} MEM_HDR,*MEM_HDRp;
# define CallocMem(size, num) M_Calloc(size, num)
# define FreeMem(ptr) M_Free(ptr)
typedef struct
typedef struct TARGET_SORT
{
short sprite_num;
DSWActor* actor;
short dang;
int dist;
int weight;
} TARGET_SORT, *TARGET_SORTp;
} *TARGET_SORTp;
#define MAX_TARGET_SORT 16
enum { MAX_TARGET_SORT = 16 };
extern TARGET_SORT TargetSort[MAX_TARGET_SORT];
extern unsigned TargetSortCount;

View file

@ -1150,7 +1150,7 @@ DSWActor* DoPickTarget(DSWActor* actor, uint32_t max_delta_ang, int skip_targets
if (max_delta_ang == 0) max_delta_ang = 1;
TargetSortCount = 0;
TargetSort[0].sprite_num = -1;
TargetSort[0].actor = nullptr;
for (shp = StatDamageList; shp < &StatDamageList[SIZ(StatDamageList)]; shp++)
{
@ -1232,7 +1232,7 @@ DSWActor* DoPickTarget(DSWActor* actor, uint32_t max_delta_ang, int skip_targets
}
ts = &TargetSort[ndx];
ts->sprite_num = itActor->GetSpriteIndex();
ts->actor = itActor;
ts->dang = delta_ang;
ts->dist = dist;
// gives a value between 0 and 65535
@ -1251,7 +1251,7 @@ DSWActor* DoPickTarget(DSWActor* actor, uint32_t max_delta_ang, int skip_targets
if (TargetSortCount > 1)
qsort(&TargetSort, TargetSortCount, sizeof(TARGET_SORT), CompareTarget);
return TargetSort[0].sprite_num == -1? nullptr : &swActors[TargetSort[0].sprite_num];
return TargetSort[0].actor;
}
void DoPlayerResetMovement(PLAYERp pp)

View file

@ -886,7 +886,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, USER& w, USER* def
("Counter3", w.Counter3, def->Counter3)
("DamageTics", w.DamageTics, def->DamageTics)
("BladeDamageTics", w.BladeDamageTics, def->BladeDamageTics)
("WpnGoal", w.WpnGoal, def->WpnGoal)
("WpnGoal", w.WpnGoalActor, def->WpnGoalActor)
("Radius", w.Radius, def->Radius)
("OverlapZ", w.OverlapZ, def->OverlapZ)
("flame", w.flameActor, def->flameActor)

View file

@ -735,14 +735,14 @@ void KillSprite(int16_t SpriteNum)
for (stat = 0; stat < SIZ(MissileStats); stat++)
{
StatIterator it(MissileStats[stat]);
while ((i = it.NextIndex()) >= 0)
SWStatIterator it(MissileStats[stat]);
while (auto actor = it.Next())
{
mu = User[i].Data();
if (mu && mu->WpnGoal == SpriteNum)
if (!actor->hasU()) continue;
mu = actor->u();
if (mu->WpnGoalActor == actor)
{
mu->WpnGoal = -1;
mu->WpnGoalActor = nullptr;
}
}
}
@ -906,7 +906,7 @@ SpawnUser(short SpriteNum, short id, STATEp state)
u->ID = id;
u->Health = 100;
u->WpnGoal = -1; // for weapons
u->WpnGoalActor = nullptr;
u->attachActor = nullptr;
u->track = -1;
u->targetActor = Player[0].Actor();

View file

@ -5487,13 +5487,13 @@ ActorStdMissile(short SpriteNum, short Weapon)
}
// Reset the weapons target before dying
if (wu->WpnGoal >= 0)
auto goal = wu->WpnGoalActor;
if (goal != nullptr)
{
// attempt to see if it was killed
ASSERT(sprite[wu->WpnGoal].sectnum >= 0);
ASSERT(User[Weapon].Data());
// what if the target has been killed? This will crash!
RESET(User[wu->WpnGoal]->Flags, SPR_TARGETED);
ASSERT(goal->s().sectnum >= 0);
if (goal->hasU())
RESET(goal->u()->Flags, SPR_TARGETED);
}
return 0;
@ -8203,12 +8203,12 @@ int PickEnemyTarget(SPRITEp sp, short aware_range)
for (ts = TargetSort; ts < &TargetSort[TargetSortCount]; ts++)
{
if (ts->sprite_num >= 0)
if (ts->actor != nullptr)
{
if (ts->sprite_num == sp->owner || sprite[ts->sprite_num].owner == sp->owner)
if (ts->actor->GetSpriteIndex() == sp->owner || ts->actor->s().owner == sp->owner)
continue;
return ts->sprite_num;
return ts->actor->GetSpriteIndex();
}
}
@ -8230,7 +8230,7 @@ MissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int16_t d
if (u->WaitTics <= delay_tics)
u->WaitTics += MISSILEMOVETICS;
if (u->WpnGoal == -1)
if (u->WpnGoalActor == nullptr)
{
if (u->WaitTics > delay_tics)
{
@ -8244,7 +8244,7 @@ MissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int16_t d
{
USERp hu = User[hit_sprite].Data();
u->WpnGoal = hit_sprite;
u->WpnGoalActor = &swActors[hit_sprite];
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
@ -8253,16 +8253,16 @@ MissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int16_t d
{
USERp hu = actor->u();
u->WpnGoal = hitActor->GetSpriteIndex();
u->WpnGoalActor = hitActor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
}
}
if (u->WpnGoal >= 0)
if (u->WpnGoalActor != nullptr)
{
hp = &sprite[User[Weapon]->WpnGoal];
hp = &u->WpnGoalActor->s();
// move to correct angle
ang2tgt = getangle(hp->x - sp->x, hp->y - sp->y);
@ -8317,7 +8317,7 @@ ComboMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int1
if (u->WaitTics <= delay_tics)
u->WaitTics += MISSILEMOVETICS;
if (u->WpnGoal == -1)
if (u->WpnGoalActor == nullptr)
{
if (u->WaitTics > delay_tics)
{
@ -8327,17 +8327,17 @@ ComboMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int1
{
USERp hu = actor->u();
u->WpnGoal = hitActor->GetSpriteIndex();
u->WpnGoalActor = hitActor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
}
}
if (u->WpnGoal >= 0)
if (u->WpnGoalActor != nullptr)
{
int oz;
hp = &sprite[User[Weapon]->WpnGoal];
hp = &u->WpnGoalActor->s();
// move to correct angle
ang2tgt = getangle(hp->x - sp->x, hp->y - sp->y);
@ -8385,7 +8385,7 @@ VectorMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t turn_speed, int16_
if (u->WaitTics <= delay_tics)
u->WaitTics += MISSILEMOVETICS;
if (u->WpnGoal == -1)
if (u->WpnGoalActor == nullptr)
{
if (u->WaitTics > delay_tics)
{
@ -8397,7 +8397,7 @@ VectorMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t turn_speed, int16_
{
USERp hu = User[hit_sprite].Data();
u->WpnGoal = hit_sprite;
u->WpnGoalActor = &swActors[hit_sprite];
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
@ -8405,7 +8405,7 @@ VectorMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t turn_speed, int16_
{
USERp hu = User[hit_sprite].Data();
u->WpnGoal = hit_sprite;
u->WpnGoalActor = &swActors[hit_sprite];
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
@ -8417,14 +8417,14 @@ VectorMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t turn_speed, int16_
if ((hitActor = DoPickTarget(actor, aware_range1, false)) != nullptr)
{
USERp hu = actor->u();
u->WpnGoal = hitActor->GetSpriteIndex();
u->WpnGoalActor = hitActor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
else if ((hitActor = DoPickTarget(actor, aware_range2, false)) != nullptr)
{
USERp hu = actor->u();
u->WpnGoal = hitActor->GetSpriteIndex();
u->WpnGoalActor = hitActor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
@ -8432,10 +8432,10 @@ VectorMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t turn_speed, int16_
}
}
if (u->WpnGoal >= 0)
if (u->WpnGoalActor != nullptr)
{
int ox,oy,oz;
hp = &sprite[User[Weapon]->WpnGoal];
hp = &u->WpnGoalActor->s();
if (!hp) return 0;
@ -8479,7 +8479,7 @@ VectorWormSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range1, int16_t
if (u->WaitTics <= delay_tics)
u->WaitTics += MISSILEMOVETICS;
if (u->WpnGoal == -1)
if (u->WpnGoalActor == nullptr)
{
if (u->WaitTics > delay_tics)
{
@ -8487,24 +8487,24 @@ VectorWormSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range1, int16_t
if ((hitActor = DoPickTarget(actor, aware_range1, false)) != nullptr)
{
USERp hu = actor->u();
u->WpnGoal = hitActor->GetSpriteIndex();
u->WpnGoalActor = hitActor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
else if ((hitActor = DoPickTarget(actor, aware_range2, false)) != nullptr)
{
USERp hu = actor->u();
u->WpnGoal = hitActor->GetSpriteIndex();
u->WpnGoalActor = hitActor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
}
}
if (u->WpnGoal >= 0)
if (u->WpnGoalActor != nullptr)
{
int ox,oy,oz;
hp = &sprite[User[Weapon]->WpnGoal];
hp = &u->WpnGoalActor->s();
zh = SPRITEp_TOS(hp) + DIV4(SPRITEp_SIZE_Z(hp));
@ -8667,7 +8667,7 @@ DoPlasma(DSWActor* actor)
{
short hcstat = hsp->cstat;
if (hu && hit_sprite != u->WpnGoal)
if (hu && hit_sprite != u->WpnGoalActor->GetSpriteIndex())
{
sp->x = ox;
sp->y = oy;
@ -13937,7 +13937,7 @@ int WeaponAutoAim(SPRITEp sp, short Missile, short ang, bool test)
SPRITEp hp = &hitActor->s();
USERp hu = hitActor->u();
wu->WpnGoal = hitActor->GetSpriteIndex();
wu->WpnGoalActor = hitActor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
@ -14010,7 +14010,7 @@ WeaponAutoAimZvel(SPRITEp sp, short Missile, int *zvel, short ang, bool test)
SPRITEp hp = &hitActor->s();
USERp hu = hitActor->u();
wu->WpnGoal = hitActor->GetSpriteIndex();
wu->WpnGoalActor = hitActor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
@ -15477,10 +15477,10 @@ InitMicro(PLAYERp pp)
for (i = 0; i < MAX_MICRO; i++)
{
if (ts < &TargetSort[TargetSortCount] && ts->sprite_num >= 0)
if (ts < &TargetSort[TargetSortCount] && ts->actor != nullptr)
{
hp = &sprite[ts->sprite_num];
hu = User[ts->sprite_num].Data();
hp = &ts->actor->s();
hu = ts->actor->u();
ang = getangle(hp->x - nx, hp->y - ny);
@ -15566,7 +15566,7 @@ InitMicro(PLAYERp pp)
wp->zvel = (wp->xvel * (zh - wp->z)) / dist;
}
wu->WpnGoal = ts->sprite_num;
wu->WpnGoalActor = ts->actor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}
@ -17848,10 +17848,10 @@ InitTurretMicro(short SpriteNum, PLAYERp pp)
for (i = 0; i < MAX_TURRET_MICRO; i++)
{
if (ts < &TargetSort[TargetSortCount] && ts->sprite_num >= 0)
if (ts < &TargetSort[TargetSortCount] && ts->actor != nullptr)
{
hp = &sprite[ts->sprite_num];
hu = User[ts->sprite_num].Data();
hp = &ts->actor->s();
hu = ts->actor->u();
ang = getangle(hp->x - nx, hp->y - ny);
@ -17911,7 +17911,7 @@ InitTurretMicro(short SpriteNum, PLAYERp pp)
wp->zvel = (wp->xvel * (zh - wp->z)) / dist;
}
wu->WpnGoal = ts->sprite_num;
wu->WpnGoalActor = ts->actor;
SET(hu->Flags, SPR_TARGETED);
SET(hu->Flags, SPR_ATTACKED);
}