- FAFcansee refactoring, part 1.

This commit is contained in:
Christoph Oelckers 2022-08-21 16:57:51 +02:00
parent 6ee24a2213
commit 5b7b8233e7
4 changed files with 37 additions and 20 deletions

View file

@ -216,13 +216,7 @@ int DoActorNoise(ANIMATOR* Action, DSWActor* actor)
bool CanSeePlayer(DSWActor* actor)
{
// if actor can still see the player
int look_height = int_ActorZOfTop(actor);
if (actor->user.targetActor && FAFcansee(actor->int_pos().X, actor->int_pos().Y, look_height, actor->sector(), actor->user.targetActor->int_pos().X, actor->user.targetActor->int_pos().Y, int_ActorUpperZ(actor->user.targetActor), actor->user.targetActor->sector()))
return true;
else
return false;
return actor->user.targetActor && FAFcansee(ActorVectOfTop(actor), actor->sector(), ActorUpperVect(actor->user.targetActor), actor->user.targetActor->sector());
}
int CanHitPlayer(DSWActor* actor)
@ -239,7 +233,7 @@ int CanHitPlayer(DSWActor* actor)
auto targ = actor->user.targetActor;
// get angle to target
ang = getangle(targ->int_pos().X - actor->int_pos().X, targ->int_pos().Y - actor->int_pos().Y);
ang = getangle(targ->spr.pos - actor->spr.pos);
// get x,yvect
xvect = bcos(ang);
@ -279,7 +273,6 @@ int DoActorPickClosePlayer(DSWActor* actor)
int pnum;
PLAYER* pp;
// if actor can still see the player
int look_height = int_ActorZOfTop(actor);
bool found = false;
int i;
@ -353,7 +346,8 @@ int DoActorPickClosePlayer(DSWActor* actor)
DISTANCE(actor->spr.pos, pp->pos, dist, a, b, c);
DSWActor* plActor = pp->actor;
if (dist < near_dist && FAFcansee(actor->int_pos().X, actor->int_pos().Y, look_height, actor->sector(), plActor->int_pos().X, plActor->int_pos().Y, int_ActorUpperZ(plActor), plActor->sector()))
if (dist < near_dist && FAFcansee(ActorVectOfTop(actor), actor->sector(), ActorUpperVect(plActor), plActor->sector()))
{
near_dist = dist;
actor->user.targetActor = pp->actor;
@ -379,7 +373,7 @@ TARGETACTOR:
DISTANCE(actor->spr.pos, itActor->spr.pos, dist, a, b, c);
if (dist < near_dist && FAFcansee(actor->int_pos().X, actor->int_pos().Y, look_height, actor->sector(), itActor->int_pos().X, itActor->int_pos().Y, int_ActorUpperZ(itActor), itActor->sector()))
if (dist < near_dist && FAFcansee(ActorVectOfTop(actor), actor->sector(), ActorUpperVect(itActor), itActor->sector()))
{
near_dist = dist;
actor->user.targetActor = itActor;

View file

@ -832,7 +832,7 @@ int DoBunnyBeginJumpAttack(DSWActor* actor)
DSWActor* target = actor->user.targetActor;
int tang;
tang = getangle(target->int_pos().X - actor->int_pos().X, target->int_pos().Y - actor->int_pos().Y);
tang = getangle(target->spr.pos - actor->spr.pos);
Collision coll = move_sprite(actor, bcos(tang, -7), bsin(tang, -7),
0L, actor->user.int_ceiling_dist(), actor->user.int_floor_dist(), CLIPMASK_ACTOR, ACTORMOVETICS);
@ -893,7 +893,6 @@ void DoPickCloseBunny(DSWActor* actor)
int dist, near_dist = 1000, a,b,c;
// if actor can still see the player
int look_height = int_ActorZOfTop(actor);
bool ICanSee = false;
SWStatIterator it(STAT_ENEMY);
@ -907,7 +906,7 @@ void DoPickCloseBunny(DSWActor* actor)
if (dist > near_dist) continue;
ICanSee = FAFcansee(actor->int_pos().X, actor->int_pos().Y, look_height, actor->sector(), itActor->int_pos().X, itActor->int_pos().Y, int_ActorUpperZ(itActor), itActor->sector());
ICanSee = FAFcansee(ActorVectOfTop(actor), actor->sector(), ActorUpperVect(itActor), itActor->sector());
if (ICanSee && dist < near_dist && itActor->user.ID == BUNNY_RUN_R0)
{
@ -1002,7 +1001,7 @@ int DoBunnyQuickJump(DSWActor* actor)
if (pp == Player+myconnectindex)
{
choose_snd = StdRandomRange(2<<8)>>8;
if (FAFcansee(actor->int_pos().X,actor->int_pos().Y,int_ActorZOfTop(actor),actor->sector(),pp->int_ppos().X, pp->int_ppos().Y, pp->int_ppos().Z, pp->cursector) && Facing(actor, actor->user.targetActor))
if (FAFcansee(ActorVectOfTop(actor),actor->sector(),pp->pos, pp->cursector) && Facing(actor, actor->user.targetActor))
PlayerSound(fagsnds[choose_snd], v3df_doppler|v3df_follow|v3df_dontpan,pp);
}
}
@ -1017,8 +1016,8 @@ int DoBunnyQuickJump(DSWActor* actor)
if (pp == Player+myconnectindex)
{
choose_snd = StdRandomRange(3<<8)>>8;
if (FAFcansee(actor->int_pos().X,actor->int_pos().Y,int_ActorZOfTop(actor),actor->sector(),pp->int_ppos().X, pp->int_ppos().Y, pp->int_ppos().Z, pp->cursector) && Facing(actor, actor->user.targetActor))
PlayerSound(straightsnds[choose_snd], v3df_doppler|v3df_follow|v3df_dontpan,pp);
if (FAFcansee(ActorVectOfTop(actor), actor->sector(), pp->pos, pp->cursector) && Facing(actor, actor->user.targetActor))
PlayerSound(straightsnds[choose_snd], v3df_doppler | v3df_follow | v3df_dontpan, pp);
}
}
}

View file

@ -1772,6 +1772,11 @@ void FAFhitscan(int32_t x, int32_t y, int32_t z, sectortype* sect,
HitInfo& hit, int32_t clipmask);
bool FAFcansee(int32_t xs, int32_t ys, int32_t zs, sectortype* sects, int32_t xe, int32_t ye, int32_t ze, sectortype* secte);
inline bool FAFcansee(const DVector3& start, sectortype* sects, const DVector3& end, sectortype* secte)
{
return FAFcansee(int(start.X * worldtoint), int(start.Y * worldtoint), int(start.Z * zworldtoint), sects,
int(end.X * worldtoint), int(end.Y * worldtoint), int(end.Z * zworldtoint), secte);
}
void FAFgetzrange(vec3_t pos, sectortype* sect,
int32_t* hiz, Collision* ceilhit,
@ -1789,6 +1794,15 @@ inline void FAFgetzrange(vec3_t pos, sectortype* sect,
*loz = lo * zinttoworld;
}
inline void FAFgetzrange(const DVector3& pos, sectortype* sect,
double* hiz, Collision* ceilhit,
double* loz, Collision* florhit,
int32_t clipdist, int32_t clipmask)
{
vec3_t p = { int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint) };
FAFgetzrange(p, sect, hiz, ceilhit, loz, florhit, clipdist, clipmask);
}
void FAFgetzrangepoint(int32_t x, int32_t y, int32_t z, sectortype* sect,
int32_t* hiz, Collision* ceilhit,
int32_t* loz, Collision* florhit);
@ -2124,6 +2138,11 @@ inline double ActorZOfTop(DSWActor* actor)
return GetSpriteZOfTop(&actor->spr) * zinttoworld;
}
inline DVector3 ActorVectOfTop(DSWActor* actor)
{
return DVector3(actor->spr.pos.XY(), ActorZOfTop(actor));
}
inline int int_ActorZOfBottom(DSWActor* actor)
{
return GetSpriteZOfBottom(&actor->spr);
@ -2164,6 +2183,11 @@ inline double ActorUpperZ(DSWActor* actor)
return (ActorZOfTop(actor) + (ActorSizeZ(actor) * 0.25));
}
inline DVector3 ActorUpperVect(DSWActor* actor)
{
return DVector3(actor->spr.pos.XY(), ActorUpperZ(actor));
}
inline int int_ActorLowerZ(DSWActor* actor)
{
return (int_ActorZOfBottom(actor) - (int_ActorSizeZ(actor) >> 2));

View file

@ -1432,7 +1432,7 @@ int PlayerInitFlashBomb(PLAYER* pp)
if (!(actor->spr.cstat & CSTAT_SPRITE_BLOCK))
continue;
if (!FAFcansee(itActor->int_pos().X, itActor->int_pos().Y, itActor->int_pos().Z, itActor->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - int_ActorSizeZ(actor), actor->sector()))
if (!FAFcansee(itActor->spr.pos, itActor->sector(), actor->spr.pos.plusZ(-ActorSizeZ(actor)), actor->sector()))
continue;
damage = GetDamage(itActor, pp->actor, DMG_FLASHBOMB);
@ -1491,7 +1491,7 @@ int InitFlashBomb(DSWActor* actor)
if (!(actor->spr.cstat & CSTAT_SPRITE_BLOCK))
continue;
if (!FAFcansee(itActor->int_pos().X, itActor->int_pos().Y, itActor->int_pos().Z, itActor->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z - int_ActorSizeZ(actor), actor->sector()))
if (!FAFcansee(itActor->spr.pos, itActor->sector(), actor->spr.pos.plusZ(-ActorSizeZ(actor)), actor->sector()))
continue;
damage = GetDamage(itActor, actor, DMG_FLASHBOMB);
@ -1893,7 +1893,7 @@ DSWActor* DoFlagRangeTest(DSWActor* actor, int range)
if (!(itActor->spr.extra & SPRX_PLAYER_OR_ENEMY))
continue;
if (!FAFcansee(itActor->int_pos().X, itActor->int_pos().Y, itActor->int_pos().Z, itActor->sector(), actor->int_pos().X, actor->int_pos().Y, actor->int_pos().Z, actor->sector()))
if (!FAFcansee(itActor->spr.pos, itActor->sector(), actor->spr.pos, actor->sector()))
continue;
dist = FindDistance3D(actor->int_pos() - itActor->int_pos());