mirror of
https://github.com/ZDoom/qzdoom.git
synced 2025-03-10 11:11:51 +00:00
This commit is contained in:
parent
220845066a
commit
c2610fcb60
7 changed files with 70 additions and 46 deletions
|
@ -1469,13 +1469,13 @@ double FLevelLocals::PlayersRangeFromSpot (FPlayerStart *spot)
|
||||||
if (!playeringame[i] || !players[i].mo || players[i].health <= 0)
|
if (!playeringame[i] || !players[i].mo || players[i].health <= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
distance = players[i].mo->Distance2D(spot->pos.X, spot->pos.Y);
|
distance = players[i].mo->Distance2DSquared(spot->pos.X, spot->pos.Y);
|
||||||
|
|
||||||
if (distance < closest)
|
if (distance < closest)
|
||||||
closest = distance;
|
closest = distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
return closest;
|
return sqrt(closest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [RH] Select the deathmatch spawn spot farthest from everyone.
|
// [RH] Select the deathmatch spawn spot farthest from everyone.
|
||||||
|
|
|
@ -862,6 +862,11 @@ public:
|
||||||
return (Pos().XY() - otherpos).LengthSquared();
|
return (Pos().XY() - otherpos).LengthSquared();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Distance2DSquared(double x, double y) const
|
||||||
|
{
|
||||||
|
return DVector2(X() - x, Y() - y).LengthSquared();
|
||||||
|
}
|
||||||
|
|
||||||
double Distance2D(AActor *other, bool absolute = false)
|
double Distance2D(AActor *other, bool absolute = false)
|
||||||
{
|
{
|
||||||
DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this);
|
DVector2 otherpos = absolute ? other->Pos() : other->PosRelative(this);
|
||||||
|
|
|
@ -2241,8 +2241,9 @@ DEFINE_ACTION_FUNCTION(AActor, CheckLOF)
|
||||||
{
|
{
|
||||||
if (range > 0 && !(flags & CLOFF_CHECKPARTIAL))
|
if (range > 0 && !(flags & CLOFF_CHECKPARTIAL))
|
||||||
{
|
{
|
||||||
double distance = self->Distance3D(target);
|
double distance_squared = self->Distance3DSquared(target);
|
||||||
if (distance > range)
|
|
||||||
|
if (distance_squared > (range * range) )
|
||||||
{
|
{
|
||||||
ACTION_RETURN_BOOL(false);
|
ACTION_RETURN_BOOL(false);
|
||||||
}
|
}
|
||||||
|
@ -2458,13 +2459,14 @@ DEFINE_ACTION_FUNCTION(AActor, CheckIfTargetInLOS)
|
||||||
{
|
{
|
||||||
ACTION_RETURN_BOOL(false);
|
ACTION_RETURN_BOOL(false);
|
||||||
}
|
}
|
||||||
double distance = self->Distance3D(target);
|
double distance_squared = self->Distance3DSquared(target);
|
||||||
|
|
||||||
if (dist_max && (distance > dist_max))
|
if (dist_max && (distance_squared > (dist_max * dist_max) ) )
|
||||||
{
|
{
|
||||||
ACTION_RETURN_BOOL(false);
|
ACTION_RETURN_BOOL(false);
|
||||||
}
|
}
|
||||||
if (dist_close && (distance < dist_close))
|
|
||||||
|
if (dist_close && (distance_squared < (dist_close * dist_close) ) )
|
||||||
{
|
{
|
||||||
if (flags & JLOSF_CLOSENOJUMP)
|
if (flags & JLOSF_CLOSENOJUMP)
|
||||||
{
|
{
|
||||||
|
@ -2549,16 +2551,16 @@ DEFINE_ACTION_FUNCTION(AActor, CheckIfInTargetLOS)
|
||||||
ACTION_RETURN_BOOL(false);
|
ACTION_RETURN_BOOL(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
double distance = self->Distance3D(target);
|
double distance_squared = self->Distance3DSquared(target);
|
||||||
|
|
||||||
if (dist_max && (distance > dist_max))
|
if (dist_max && dist_max >= 0 && (distance_squared > (dist_max * dist_max) ) )
|
||||||
{
|
{
|
||||||
ACTION_RETURN_BOOL(false);
|
ACTION_RETURN_BOOL(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool doCheckSight = !(flags & JLOSF_NOSIGHT);
|
bool doCheckSight = !(flags & JLOSF_NOSIGHT);
|
||||||
|
|
||||||
if (dist_close && (distance < dist_close))
|
if (dist_close && dist_close >= 0 && (distance_squared < (dist_close * dist_close) ) )
|
||||||
{
|
{
|
||||||
if (flags & JLOSF_CLOSENOJUMP)
|
if (flags & JLOSF_CLOSENOJUMP)
|
||||||
{
|
{
|
||||||
|
@ -3413,7 +3415,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_WolfAttack)
|
||||||
|
|
||||||
// Target can dodge if it can see enemy
|
// Target can dodge if it can see enemy
|
||||||
DAngle angle = absangle(self->target->Angles.Yaw, self->target->AngleTo(self));
|
DAngle angle = absangle(self->target->Angles.Yaw, self->target->AngleTo(self));
|
||||||
bool dodge = (P_CheckSight(self->target, self) && angle < 30. * 256. / 360.); // 30 byteangles ~ 21°
|
bool dodge = (P_CheckSight(self->target, self) && angle < 30. * 256. / 360.); // 30 byteangles ~ 21<EFBFBD>
|
||||||
|
|
||||||
// Distance check is simplistic
|
// Distance check is simplistic
|
||||||
DVector2 vec = self->Vec2To(self->target);
|
DVector2 vec = self->Vec2To(self->target);
|
||||||
|
|
|
@ -140,8 +140,9 @@ static void NoiseMarkSector(sector_t *sec, AActor *soundtarget, bool splash, AAc
|
||||||
// [RH] Set this in the actors in the sector instead of the sector itself.
|
// [RH] Set this in the actors in the sector instead of the sector itself.
|
||||||
for (AActor *actor = sec->thinglist; actor != NULL; actor = actor->snext)
|
for (AActor *actor = sec->thinglist; actor != NULL; actor = actor->snext)
|
||||||
{
|
{
|
||||||
if (actor != soundtarget && (!splash || !(actor->flags4 & MF4_NOSPLASHALERT)) &&
|
if(actor != soundtarget && (!splash || !(actor->flags4 & MF4_NOSPLASHALERT)) &&
|
||||||
(!maxdist || (actor->Distance2D(emitter) <= maxdist)))
|
(!maxdist ||
|
||||||
|
(maxdist >= 0 && actor->Distance2DSquared(emitter) <= (maxdist * maxdist) ) ) )
|
||||||
{
|
{
|
||||||
actor->LastHeard = soundtarget;
|
actor->LastHeard = soundtarget;
|
||||||
}
|
}
|
||||||
|
@ -456,7 +457,7 @@ int P_Move (AActor *actor)
|
||||||
|
|
||||||
if ((actor->flags6 & MF6_JUMPDOWN) && target &&
|
if ((actor->flags6 & MF6_JUMPDOWN) && target &&
|
||||||
!(target->IsFriend(actor)) &&
|
!(target->IsFriend(actor)) &&
|
||||||
actor->Distance2D(target) < 144 &&
|
actor->Distance2DSquared(target) < (144 * 144) &&
|
||||||
pr_dropoff() < 235)
|
pr_dropoff() < 235)
|
||||||
{
|
{
|
||||||
dropoff = 2;
|
dropoff = 2;
|
||||||
|
@ -944,16 +945,21 @@ void P_NewChaseDir(AActor * actor)
|
||||||
if (actor->flags3 & MF3_AVOIDMELEE)
|
if (actor->flags3 & MF3_AVOIDMELEE)
|
||||||
{
|
{
|
||||||
bool ismeleeattacker = false;
|
bool ismeleeattacker = false;
|
||||||
double dist = actor->Distance2D(target);
|
|
||||||
|
double distance_squared = actor->Distance2DSquared(target);
|
||||||
if (target->player == NULL)
|
if (target->player == NULL)
|
||||||
{
|
{
|
||||||
ismeleeattacker = (target->MissileState == NULL && dist < (target->meleerange + target->radius)*2);
|
//in its own variable because otherwise it looks bad
|
||||||
|
double meele_squared = (target->meleerange + target->radius) * 2 * (target->meleerange + target->radius) * 2;
|
||||||
|
ismeleeattacker = (target->MissileState == NULL && distance_squared < meele_squared);
|
||||||
}
|
}
|
||||||
else if (target->player->ReadyWeapon != NULL)
|
else if (target->player->ReadyWeapon != NULL)
|
||||||
{
|
{
|
||||||
// melee range of player weapon is a parameter of the action function and cannot be checked here.
|
// melee range of player weapon is a parameter of the action function and cannot be checked here.
|
||||||
// Add a new weapon property?
|
// Add a new weapon property?
|
||||||
ismeleeattacker = ((target->player->ReadyWeapon->IntVar(NAME_WeaponFlags) & WIF_MELEEWEAPON) && dist < 192);
|
ismeleeattacker = ((target->player->ReadyWeapon->IntVar(NAME_WeaponFlags) & WIF_MELEEWEAPON) &&
|
||||||
|
//192 is an unknown constant here
|
||||||
|
distance_squared < (192 * 192) );
|
||||||
}
|
}
|
||||||
if (ismeleeattacker)
|
if (ismeleeattacker)
|
||||||
{
|
{
|
||||||
|
@ -1163,12 +1169,12 @@ int P_IsVisible(AActor *lookee, AActor *other, INTBOOL allaround, FLookExParams
|
||||||
fov = allaround ? 0. : 180.;
|
fov = allaround ? 0. : 180.;
|
||||||
}
|
}
|
||||||
|
|
||||||
double dist = lookee->Distance2D (other);
|
double distance_squared = lookee->Distance2DSquared(other);
|
||||||
|
//square distance here...
|
||||||
if (maxdist && dist > maxdist)
|
if (maxdist && maxdist >= 0 && distance_squared > (maxdist * maxdist) )
|
||||||
return false; // [KS] too far
|
return false; // [KS] too far
|
||||||
|
//...and here because other number are squared
|
||||||
if (mindist && dist < mindist)
|
if (mindist && mindist >= 0 && distance_squared < (mindist * mindist) )
|
||||||
return false; // [KS] too close
|
return false; // [KS] too close
|
||||||
|
|
||||||
if (fov != 0)
|
if (fov != 0)
|
||||||
|
@ -1179,7 +1185,7 @@ int P_IsVisible(AActor *lookee, AActor *other, INTBOOL allaround, FLookExParams
|
||||||
{
|
{
|
||||||
// if real close, react anyway
|
// if real close, react anyway
|
||||||
// [KS] but respect minimum distance rules
|
// [KS] but respect minimum distance rules
|
||||||
if (mindist || dist > lookee->meleerange + lookee->radius)
|
if (mindist || distance_squared > ( (lookee->meleerange + lookee->radius) * (lookee->meleerange + lookee->radius) ) )
|
||||||
return false; // outside of fov
|
return false; // outside of fov
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1214,7 +1220,7 @@ int P_LookForMonsters (AActor *actor)
|
||||||
{ // Not a valid monster
|
{ // Not a valid monster
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (mo->Distance2D (actor) > MONS_LOOK_RANGE)
|
if (mo->Distance2DSquared(actor) > (MONS_LOOK_RANGE * MONS_LOOK_RANGE) )
|
||||||
{ // Out of range
|
{ // Out of range
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1721,7 +1727,7 @@ int P_LookForPlayers (AActor *actor, INTBOOL allaround, FLookExParams *params)
|
||||||
if ((player->mo->flags & MF_SHADOW && !(actor->Level->i_compatflags & COMPATF_INVISIBILITY)) ||
|
if ((player->mo->flags & MF_SHADOW && !(actor->Level->i_compatflags & COMPATF_INVISIBILITY)) ||
|
||||||
player->mo->flags3 & MF3_GHOST)
|
player->mo->flags3 & MF3_GHOST)
|
||||||
{
|
{
|
||||||
if (player->mo->Distance2D (actor) > 128 && player->mo->Vel.XY().LengthSquared() < 5*5)
|
if (player->mo->Distance2DSquared(actor) > (128 * 128) && player->mo->Vel.XY().LengthSquared() < (5 * 5) )
|
||||||
{ // Player is sneaking - can't detect
|
{ // Player is sneaking - can't detect
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1882,7 +1888,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_LookEx)
|
||||||
PARAM_STATE (seestate)
|
PARAM_STATE (seestate)
|
||||||
|
|
||||||
AActor *targ = NULL; // Shuts up gcc
|
AActor *targ = NULL; // Shuts up gcc
|
||||||
double dist;
|
double distance_squared;//Not used anywhere, except distance checking
|
||||||
if (fov == 0) fov = 180.;
|
if (fov == 0) fov = 180.;
|
||||||
FLookExParams params = { fov, minseedist, maxseedist, maxheardist, flags, seestate };
|
FLookExParams params = { fov, minseedist, maxseedist, maxheardist, flags, seestate };
|
||||||
|
|
||||||
|
@ -1923,10 +1929,10 @@ DEFINE_ACTION_FUNCTION(AActor, A_LookEx)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dist = self->Distance2D (targ);
|
distance_squared = self->Distance2DSquared(targ);
|
||||||
|
|
||||||
// [KS] If the target is too far away, don't respond to the sound.
|
// [KS] If the target is too far away, don't respond to the sound.
|
||||||
if (maxheardist && dist > maxheardist)
|
if (maxheardist && maxheardist > 0 && distance_squared > (maxheardist * maxheardist) )
|
||||||
{
|
{
|
||||||
targ = NULL;
|
targ = NULL;
|
||||||
self->LastHeard = nullptr;
|
self->LastHeard = nullptr;
|
||||||
|
@ -1994,10 +2000,10 @@ DEFINE_ACTION_FUNCTION(AActor, A_LookEx)
|
||||||
{
|
{
|
||||||
if (self->flags & MF_AMBUSH)
|
if (self->flags & MF_AMBUSH)
|
||||||
{
|
{
|
||||||
dist = self->Distance2D (self->target);
|
distance_squared = self->Distance2D (self->target);
|
||||||
if (P_CheckSight (self, self->target, SF_SEEPASTBLOCKEVERYTHING) &&
|
if (P_CheckSight (self, self->target, SF_SEEPASTBLOCKEVERYTHING) &&
|
||||||
(!minseedist || dist > minseedist) &&
|
(!minseedist || (minseedist >= 0 && distance_squared > (minseedist * minseedist) ) ) &&
|
||||||
(!maxseedist || dist < maxseedist))
|
(!maxseedist || (maxseedist >= 0 && distance_squared < (maxseedist * maxseedist) ) ) )
|
||||||
{
|
{
|
||||||
goto seeyou;
|
goto seeyou;
|
||||||
}
|
}
|
||||||
|
@ -2430,8 +2436,8 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi
|
||||||
{
|
{
|
||||||
actor->FastChaseStrafeCount = 0;
|
actor->FastChaseStrafeCount = 0;
|
||||||
actor->Vel.X = actor->Vel.Y = 0;
|
actor->Vel.X = actor->Vel.Y = 0;
|
||||||
double dist = actor->Distance2D (actor->target);
|
double distance_squared = actor->Distance2DSquared(actor->target);
|
||||||
if (dist < CLASS_BOSS_STRAFE_RANGE)
|
if (distance_squared < (CLASS_BOSS_STRAFE_RANGE * CLASS_BOSS_STRAFE_RANGE) )
|
||||||
{
|
{
|
||||||
if (pr_chase() < 100)
|
if (pr_chase() < 100)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1355,10 +1355,10 @@ bool PIT_CheckThing(FMultiBlockThingsIterator &it, FMultiBlockThingsIterator::Ch
|
||||||
fabs(thing->Y() - oldpos.Y) < (thing->radius + tm.thing->radius))
|
fabs(thing->Y() - oldpos.Y) < (thing->radius + tm.thing->radius))
|
||||||
|
|
||||||
{
|
{
|
||||||
double newdist = thing->Distance2D(cres.Position.X, cres.Position.Y);
|
double newdist_squared = thing->Distance2DSquared(cres.Position.X, cres.Position.Y);
|
||||||
double olddist = thing->Distance2D(oldpos.X, oldpos.Y);
|
double olddist_squared = thing->Distance2DSquared(oldpos.X, oldpos.Y);
|
||||||
|
|
||||||
if (newdist > olddist)
|
if (newdist_squared > olddist_squared)
|
||||||
{
|
{
|
||||||
// unblock only if there's already a vertical overlap (or both actors are flagged not to overlap)
|
// unblock only if there's already a vertical overlap (or both actors are flagged not to overlap)
|
||||||
unblocking = (tm.thing->Top() > thing->Z() && tm.thing->Z() < topz) || (tm.thing->flags3 & thing->flags3 & MF3_DONTOVERLAP);
|
unblocking = (tm.thing->Top() > thing->Z() && tm.thing->Z() < topz) || (tm.thing->flags3 & thing->flags3 & MF3_DONTOVERLAP);
|
||||||
|
@ -2066,15 +2066,20 @@ void P_FakeZMovement(AActor *mo)
|
||||||
{ // float down towards target if too close
|
{ // float down towards target if too close
|
||||||
if (!(mo->flags & MF_SKULLFLY) && !(mo->flags & MF_INFLOAT))
|
if (!(mo->flags & MF_SKULLFLY) && !(mo->flags & MF_INFLOAT))
|
||||||
{
|
{
|
||||||
double dist = mo->Distance2D(mo->target);
|
double dist_squared = mo->Distance2DSquared(mo->target);
|
||||||
|
//still need delta intact, because it can be negative
|
||||||
|
//and square of a real number always positive
|
||||||
double delta = mo->target->Center() - mo->Z();
|
double delta = mo->target->Center() - mo->Z();
|
||||||
if (delta < 0 && dist < -(delta * 3))
|
//why it multiplies by 3 in original function?
|
||||||
|
double delta_squared = delta * delta * 3 * 3;
|
||||||
|
if (delta < 0 && dist_squared < -(delta_squared) )
|
||||||
mo->AddZ(-mo->FloatSpeed);
|
mo->AddZ(-mo->FloatSpeed);
|
||||||
else if (delta > 0 && dist < (delta * 3))
|
|
||||||
|
else if (delta > 0 && dist_squared < (delta_squared) )
|
||||||
mo->AddZ(mo->FloatSpeed);
|
mo->AddZ(mo->FloatSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mo->player && mo->flags&MF_NOGRAVITY && (mo->Z() > mo->floorz) && !mo->IsNoClip2())
|
if (mo->player && mo->flags & MF_NOGRAVITY && (mo->Z() > mo->floorz) && !mo->IsNoClip2())
|
||||||
{
|
{
|
||||||
mo->AddZ(DAngle(4.5 * mo->Level->maptime).Sin());
|
mo->AddZ(DAngle(4.5 * mo->Level->maptime).Sin());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2369,7 +2369,7 @@ void P_MonsterFallingDamage (AActor *mo)
|
||||||
|
|
||||||
void P_ZMovement (AActor *mo, double oldfloorz)
|
void P_ZMovement (AActor *mo, double oldfloorz)
|
||||||
{
|
{
|
||||||
double dist;
|
double distance_squared;//not used anywhere except height adjusting block
|
||||||
double delta;
|
double delta;
|
||||||
double oldz = mo->Z();
|
double oldz = mo->Z();
|
||||||
double grav = mo->GetGravity();
|
double grav = mo->GetGravity();
|
||||||
|
@ -2481,11 +2481,17 @@ void P_ZMovement (AActor *mo, double oldfloorz)
|
||||||
{ // float down towards target if too close
|
{ // float down towards target if too close
|
||||||
if (!(mo->flags & (MF_SKULLFLY | MF_INFLOAT)))
|
if (!(mo->flags & (MF_SKULLFLY | MF_INFLOAT)))
|
||||||
{
|
{
|
||||||
dist = mo->Distance2D (mo->target);
|
//same code block from P_FakeZMovement/vice versa???
|
||||||
delta = (mo->target->Center()) - mo->Z();
|
double dist_squared = mo->Distance2DSquared(mo->target);
|
||||||
if (delta < 0 && dist < -(delta*3))
|
//still need delta intact, because it can be negative
|
||||||
|
//and square of a real number always positive
|
||||||
|
double delta = mo->target->Center() - mo->Z();
|
||||||
|
//why it multiplies by 3 in original function?
|
||||||
|
double delta_squared = delta * delta * 3 * 3;
|
||||||
|
if (delta < 0 && dist_squared < -(delta_squared) )
|
||||||
mo->AddZ(-mo->FloatSpeed);
|
mo->AddZ(-mo->FloatSpeed);
|
||||||
else if (delta > 0 && dist < (delta*3))
|
|
||||||
|
else if (delta > 0 && dist_squared < (delta_squared) )
|
||||||
mo->AddZ(mo->FloatSpeed);
|
mo->AddZ(mo->FloatSpeed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -613,7 +613,7 @@ int P_Thing_CheckProximity(FLevelLocals *Level, AActor *self, PClass *classname,
|
||||||
// [MC]Make sure it's in range and respect the desire for Z or not. The function forces it to use
|
// [MC]Make sure it's in range and respect the desire for Z or not. The function forces it to use
|
||||||
// Z later for ensuring CLOSEST and FARTHEST flags are respected perfectly.
|
// Z later for ensuring CLOSEST and FARTHEST flags are respected perfectly.
|
||||||
// Ripped from sphere checking in A_RadiusGive (along with a number of things).
|
// Ripped from sphere checking in A_RadiusGive (along with a number of things).
|
||||||
if ((ref->Distance2D(mo) < distance &&
|
if ((ref->Distance2DSquared(mo) < (distance * distance) &&
|
||||||
((flags & CPXF_NOZ) ||
|
((flags & CPXF_NOZ) ||
|
||||||
((ref->Z() > mo->Z() && ref->Z() - mo->Top() < distance) ||
|
((ref->Z() > mo->Z() && ref->Z() - mo->Top() < distance) ||
|
||||||
(ref->Z() <= mo->Z() && mo->Z() - ref->Top() < distance)))))
|
(ref->Z() <= mo->Z() && mo->Z() - ref->Top() < distance)))))
|
||||||
|
|
Loading…
Reference in a new issue