- refactoring of R_PointToAngle2 when used to calculate direction between two actors.

This commit is contained in:
Christoph Oelckers 2016-01-10 20:46:26 +01:00
parent 1e2ce9a622
commit 2c0f64cf9f
31 changed files with 92 additions and 115 deletions

View file

@ -612,7 +612,7 @@ extern FDropItemPtrArray DropItemList;
void FreeDropItemChain(FDropItem *chain); void FreeDropItemChain(FDropItem *chain);
int StoreDropItemChain(FDropItem *chain); int StoreDropItemChain(FDropItem *chain);
fixed_t P_AproxDistance (fixed_t dx, fixed_t dy); // since we cannot include p_local here... fixed_t P_AproxDistance (fixed_t dx, fixed_t dy); // since we cannot include p_local here...
angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2); // same reason here with r_defs.h
// Map Object definition. // Map Object definition.
@ -889,6 +889,26 @@ public:
return xs_RoundToInt(FVector3(x - other->x, y - other->y, z - other->z).Length()); return xs_RoundToInt(FVector3(x - other->x, y - other->y, z - other->z).Length());
} }
angle_t AngleTo(AActor *other, bool absolute = false) const
{
return R_PointToAngle2(x, y, other->x, other->y);
}
angle_t AngleTo(AActor *other, fixed_t oxofs, fixed_t oyofs, bool absolute = false) const
{
return R_PointToAngle2(x, y, other->x + oxofs, other->y + oyofs);
}
fixed_t AngleTo(fixed_t otherx, fixed_t othery, AActor *ref = NULL)
{
return R_PointToAngle2(x, y, otherx, othery);
}
fixed_t AngleXYTo(fixed_t myx, fixed_t myy, AActor *other, bool absolute = false)
{
return R_PointToAngle2(myx, myy, other->x, other->y);
}
inline void SetFriendPlayer(player_t *player); inline void SetFriendPlayer(player_t *player);
bool IsVisibleToPlayer() const; bool IsVisibleToPlayer() const;

View file

@ -123,7 +123,7 @@ bool DBot::Check_LOS (AActor *to, angle_t vangle)
if (vangle == 0) if (vangle == 0)
return false; //Looker seems to be blind. return false; //Looker seems to be blind.
return absangle(R_PointToAngle2 (player->mo->x, player->mo->y, to->x, to->y) - player->mo->angle) <= vangle/2; return absangle(player->mo->AngleTo(to) - player->mo->angle) <= vangle/2;
} }
//------------------------------------- //-------------------------------------
@ -220,14 +220,14 @@ shootmissile:
dist = player->mo->AproxDistance (enemy); dist = player->mo->AproxDistance (enemy);
m = dist / GetDefaultByType (player->ReadyWeapon->ProjectileType)->Speed; m = dist / GetDefaultByType (player->ReadyWeapon->ProjectileType)->Speed;
bglobal.SetBodyAt (enemy->x + enemy->velx*m*2, enemy->y + enemy->vely*m*2, enemy->z, 1); bglobal.SetBodyAt (enemy->x + enemy->velx*m*2, enemy->y + enemy->vely*m*2, enemy->z, 1);
angle = R_PointToAngle2 (player->mo->x, player->mo->y, bglobal.body1->x, bglobal.body1->y); angle = player->mo->AngleTo(bglobal.body1);
if (Check_LOS (enemy, SHOOTFOV)) if (Check_LOS (enemy, SHOOTFOV))
no_fire = false; no_fire = false;
} }
else else
{ {
//Other weapons, mostly instant hit stuff. //Other weapons, mostly instant hit stuff.
angle = R_PointToAngle2 (player->mo->x, player->mo->y, enemy->x, enemy->y); angle = player->mo->AngleTo(enemy);
aiming_penalty = 0; aiming_penalty = 0;
if (enemy->flags & MF_SHADOW) if (enemy->flags & MF_SHADOW)
aiming_penalty += (pr_botdofire()%25)+10; aiming_penalty += (pr_botdofire()%25)+10;
@ -263,7 +263,6 @@ shootmissile:
cmd->ucmd.buttons |= BT_ATTACK; cmd->ucmd.buttons |= BT_ATTACK;
} }
//Prevents bot from jerking, when firing automatic things with low skill. //Prevents bot from jerking, when firing automatic things with low skill.
//player->mo->angle = R_PointToAngle2(player->mo->x, player->mo->y, player->enemy->x, player->enemy->y);
} }
bool FCajunMaster::IsLeader (player_t *player) bool FCajunMaster::IsLeader (player_t *player)
@ -518,7 +517,7 @@ angle_t DBot::FireRox (AActor *enemy, ticcmd_t *cmd)
{ {
if (bglobal.FakeFire (actor, bglobal.body1, cmd) >= SAFE_SELF_MISDIST) if (bglobal.FakeFire (actor, bglobal.body1, cmd) >= SAFE_SELF_MISDIST)
{ {
ang = R_PointToAngle2 (actor->x, actor->y, bglobal.body1->x, bglobal.body1->y); ang = actor->AngleTo(bglobal.body1);
return ang; return ang;
} }
} }
@ -528,7 +527,7 @@ angle_t DBot::FireRox (AActor *enemy, ticcmd_t *cmd)
{ {
if (bglobal.FakeFire (player->mo, enemy, cmd) >= SAFE_SELF_MISDIST) if (bglobal.FakeFire (player->mo, enemy, cmd) >= SAFE_SELF_MISDIST)
{ {
ang = R_PointToAngle2(player->mo->x, player->mo->y, enemy->x, enemy->y); ang = player->mo->AngleTo(enemy);
return ang; return ang;
} }
} }

View file

@ -35,7 +35,7 @@ void DBot::Roam (ticcmd_t *cmd)
if (Reachable(dest)) if (Reachable(dest))
{ // Straight towards it. { // Straight towards it.
angle = R_PointToAngle2(player->mo->x, player->mo->y, dest->x, dest->y); angle = player->mo->AngleTo(dest);
} }
else if (player->mo->movedir < 8) // turn towards movement direction if not there yet else if (player->mo->movedir < 8) // turn towards movement direction if not there yet
{ {

View file

@ -99,7 +99,7 @@ void DBot::ThinkForMove (ticcmd_t *cmd)
if (missile && (player->mo->AproxDistance(missile)<AVOID_DIST)) //try avoid missile got from P_Mobj.c thinking part. if (missile && (player->mo->AproxDistance(missile)<AVOID_DIST)) //try avoid missile got from P_Mobj.c thinking part.
{ {
Pitch (missile); Pitch (missile);
angle = R_PointToAngle2(player->mo->x, player->mo->y, missile->x, missile->y); angle = player->mo->AngleTo(missile);
cmd->ucmd.sidemove = sleft ? -SIDERUN : SIDERUN; cmd->ucmd.sidemove = sleft ? -SIDERUN : SIDERUN;
cmd->ucmd.forwardmove = -FORWARDRUN; //Back IS best. cmd->ucmd.forwardmove = -FORWARDRUN; //Back IS best.
@ -165,7 +165,7 @@ void DBot::ThinkForMove (ticcmd_t *cmd)
sleft = !sleft; sleft = !sleft;
} }
angle = R_PointToAngle2(player->mo->x, player->mo->y, enemy->x, enemy->y); angle = player->mo->AngleTo(enemy);
if (player->ReadyWeapon == NULL || if (player->ReadyWeapon == NULL ||
player->mo->AproxDistance(enemy) > player->mo->AproxDistance(enemy) >
@ -206,7 +206,7 @@ void DBot::ThinkForMove (ticcmd_t *cmd)
goto roam; goto roam;
} }
angle = R_PointToAngle2(player->mo->x, player->mo->y, mate->x, mate->y); angle = player->mo->AngleTo(mate);
matedist = player->mo->AproxDistance(mate); matedist = player->mo->AproxDistance(mate);
if (matedist > (FRIEND_DIST*2)) if (matedist > (FRIEND_DIST*2))
@ -241,7 +241,7 @@ void DBot::ThinkForMove (ticcmd_t *cmd)
(pr_botmove()%100)>skill.isp) && player->ReadyWeapon != NULL && !(player->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON)) (pr_botmove()%100)>skill.isp) && player->ReadyWeapon != NULL && !(player->ReadyWeapon->WeaponFlags & WIF_WIMPY_WEAPON))
dest = enemy;//Dont let enemy kill the bot by supressive fire. So charge enemy. dest = enemy;//Dont let enemy kill the bot by supressive fire. So charge enemy.
else //hide while t_fight, but keep view at enemy. else //hide while t_fight, but keep view at enemy.
angle = R_PointToAngle2(player->mo->x, player->mo->y, enemy->x, enemy->y); angle = player->mo->AngleTo(enemy);
} //Just a monster, so kill it. } //Just a monster, so kill it.
else else
dest = enemy; dest = enemy;

View file

@ -3145,8 +3145,8 @@ void FParser::SF_MoveCamera(void)
} }
// set step variables based on distance and speed // set step variables based on distance and speed
mobjangle = R_PointToAngle2(cam->x, cam->y, target->x, target->y); mobjangle = cam->AngleTo(target);
xydist = R_PointToDist2(target->x - cam->x, target->y - cam->y); xydist = cam->Distance2D(target);
xstep = FixedMul(finecosine[mobjangle >> ANGLETOFINESHIFT], movespeed); xstep = FixedMul(finecosine[mobjangle >> ANGLETOFINESHIFT], movespeed);
ystep = FixedMul(finesine[mobjangle >> ANGLETOFINESHIFT], movespeed); ystep = FixedMul(finesine[mobjangle >> ANGLETOFINESHIFT], movespeed);

View file

@ -59,10 +59,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Punch)
if (linetarget) if (linetarget)
{ {
S_Sound (self, CHAN_WEAPON, "*fist", 1, ATTN_NORM); S_Sound (self, CHAN_WEAPON, "*fist", 1, ATTN_NORM);
self->angle = R_PointToAngle2 (self->x, self->angle = self->AngleTo(linetarget);
self->y,
linetarget->x,
linetarget->y);
} }
} }
@ -218,8 +215,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Saw)
// turn to face target // turn to face target
if (!(Flags & SF_NOTURN)) if (!(Flags & SF_NOTURN))
{ {
angle = R_PointToAngle2(self->x, self->y, angle = self->AngleTo(linetarget);
linetarget->x, linetarget->y);
if (angle - self->angle > ANG180) if (angle - self->angle > ANG180)
{ {
if (angle - self->angle < (angle_t)(-ANG90 / 20)) if (angle - self->angle < (angle_t)(-ANG90 / 20))

View file

@ -77,7 +77,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Tracer)
return; return;
// change angle // change angle
exact = R_PointToAngle2 (self->x, self->y, dest->x, dest->y); exact = self->AngleTo(dest);
if (exact != self->angle) if (exact != self->angle)
{ {

View file

@ -276,7 +276,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_M_Saw)
S_Sound (self, CHAN_WEAPON, hitsound, 1, ATTN_NORM); S_Sound (self, CHAN_WEAPON, hitsound, 1, ATTN_NORM);
// turn to face target // turn to face target
angle = R_PointToAngle2 (self->x, self->y, linetarget->x, linetarget->y); angle = self->AngleTo(linetarget);
if (angle - self->angle > ANG180) if (angle - self->angle > ANG180)
{ {
if (angle - self->angle < (angle_t)(-ANG90/20)) if (angle - self->angle < (angle_t)(-ANG90/20))
@ -326,7 +326,8 @@ static void MarinePunch(AActor *self, int damagemul)
if (linetarget) if (linetarget)
{ {
S_Sound (self, CHAN_WEAPON, "*fist", 1, ATTN_NORM); S_Sound (self, CHAN_WEAPON, "*fist", 1, ATTN_NORM);
self->angle = R_PointToAngle2 (self->x, self->y, linetarget->x, linetarget->y); self->angle = self->AngleTo(linetarget);
} }
} }

View file

@ -178,8 +178,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_BeakAttackPL1)
P_LineAttack (player->mo, angle, MELEERANGE, slope, damage, NAME_Melee, "BeakPuff", true, &linetarget); P_LineAttack (player->mo, angle, MELEERANGE, slope, damage, NAME_Melee, "BeakPuff", true, &linetarget);
if (linetarget) if (linetarget)
{ {
player->mo->angle = R_PointToAngle2 (player->mo->x, player->mo->angle = player->mo->AngleTo(linetarget);
player->mo->y, linetarget->x, linetarget->y);
} }
P_PlayPeck (player->mo); P_PlayPeck (player->mo);
player->chickenPeck = 12; player->chickenPeck = 12;
@ -211,8 +210,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_BeakAttackPL2)
P_LineAttack (player->mo, angle, MELEERANGE, slope, damage, NAME_Melee, "BeakPuff", true, &linetarget); P_LineAttack (player->mo, angle, MELEERANGE, slope, damage, NAME_Melee, "BeakPuff", true, &linetarget);
if (linetarget) if (linetarget)
{ {
player->mo->angle = R_PointToAngle2 (player->mo->x, player->mo->angle = player->mo->AngleTo(linetarget);
player->mo->y, linetarget->x, linetarget->y);
} }
P_PlayPeck (player->mo); P_PlayPeck (player->mo);
player->chickenPeck = 12; player->chickenPeck = 12;

View file

@ -90,8 +90,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_StaffAttack)
{ {
//S_StartSound(player->mo, sfx_stfhit); //S_StartSound(player->mo, sfx_stfhit);
// turn to face target // turn to face target
self->angle = R_PointToAngle2 (self->x, self->angle = self->AngleTo(linetarget);
self->y, linetarget->x, linetarget->y);
} }
} }
@ -307,8 +306,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GauntletAttack)
S_Sound (self, CHAN_AUTO, "weapons/gauntletshit", 1, ATTN_NORM); S_Sound (self, CHAN_AUTO, "weapons/gauntletshit", 1, ATTN_NORM);
} }
// turn to face target // turn to face target
angle = R_PointToAngle2 (self->x, self->y, angle = self->AngleTo(linetarget);
linetarget->x, linetarget->y);
if (angle-self->angle > ANG180) if (angle-self->angle > ANG180)
{ {
if ((int)(angle-self->angle) < -ANG90/20) if ((int)(angle-self->angle) < -ANG90/20)
@ -648,8 +646,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_DeathBallImpact)
} }
else else
{ // Seek { // Seek
angle = R_PointToAngle2(self->x, self->y, self->angle = self->AngleTo(target);
target->x, target->y);
newAngle = true; newAngle = true;
} }
} }
@ -662,8 +659,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_DeathBallImpact)
if (linetarget && self->target != linetarget) if (linetarget && self->target != linetarget)
{ {
self->tracer = linetarget; self->tracer = linetarget;
angle = R_PointToAngle2 (self->x, self->y, angle = self->AngleTo(linetarget);
linetarget->x, linetarget->y);
newAngle = true; newAngle = true;
break; break;
} }

View file

@ -33,13 +33,13 @@ void BlastActor (AActor *victim, fixed_t strength, fixed_t speed, AActor * Owner
return; return;
} }
angle = R_PointToAngle2 (Owner->x, Owner->y, victim->x, victim->y); angle = Owner->AngleTo(victim);
angle >>= ANGLETOFINESHIFT; angle >>= ANGLETOFINESHIFT;
victim->velx = FixedMul (speed, finecosine[angle]); victim->velx = FixedMul (speed, finecosine[angle]);
victim->vely = FixedMul (speed, finesine[angle]); victim->vely = FixedMul (speed, finesine[angle]);
// Spawn blast puff // Spawn blast puff
ang = R_PointToAngle2 (victim->x, victim->y, Owner->x, Owner->y); ang = victim->AngleTo(Owner);
ang >>= ANGLETOFINESHIFT; ang >>= ANGLETOFINESHIFT;
x = victim->x + FixedMul (victim->radius+FRACUNIT, finecosine[ang]); x = victim->x + FixedMul (victim->radius+FRACUNIT, finecosine[ang]);
y = victim->y + FixedMul (victim->radius+FRACUNIT, finesine[ang]); y = victim->y + FixedMul (victim->radius+FRACUNIT, finesine[ang]);

View file

@ -262,8 +262,7 @@ static void CHolyTailFollow (AActor *actor, fixed_t dist)
child = actor->tracer; child = actor->tracer;
if (child) if (child)
{ {
an = R_PointToAngle2(actor->x, actor->y, child->x, an = actor->AngleTo(child) >> ANGLETOFINESHIFT;
child->y)>>ANGLETOFINESHIFT;
oldDistance = child->AproxDistance (actor); oldDistance = child->AproxDistance (actor);
if (P_TryMove (child, actor->x+FixedMul(dist, finecosine[an]), if (P_TryMove (child, actor->x+FixedMul(dist, finecosine[an]),
actor->y+FixedMul(dist, finesine[an]), true)) actor->y+FixedMul(dist, finesine[an]), true))

View file

@ -73,7 +73,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_CStaffCheck)
P_LineAttack (pmo, angle, fixed_t(1.5*MELEERANGE), slope, damage, NAME_Melee, PClass::FindClass ("CStaffPuff"), false, &linetarget); P_LineAttack (pmo, angle, fixed_t(1.5*MELEERANGE), slope, damage, NAME_Melee, PClass::FindClass ("CStaffPuff"), false, &linetarget);
if (linetarget != NULL) if (linetarget != NULL)
{ {
pmo->angle = R_PointToAngle2 (pmo->x, pmo->y, linetarget->x, linetarget->y); pmo->angle = pmo->AngleTo(linetarget);
if (((linetarget->player && (!linetarget->IsTeammate (pmo) || level.teamdamage != 0))|| linetarget->flags3&MF3_ISMONSTER) if (((linetarget->player && (!linetarget->IsTeammate (pmo) || level.teamdamage != 0))|| linetarget->flags3&MF3_ISMONSTER)
&& (!(linetarget->flags2&(MF2_DORMANT|MF2_INVULNERABLE)))) && (!(linetarget->flags2&(MF2_DORMANT|MF2_INVULNERABLE))))
{ {
@ -103,7 +103,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_CStaffCheck)
P_LineAttack (pmo, angle, fixed_t(1.5*MELEERANGE), slope, damage, NAME_Melee, PClass::FindClass ("CStaffPuff"), false, &linetarget); P_LineAttack (pmo, angle, fixed_t(1.5*MELEERANGE), slope, damage, NAME_Melee, PClass::FindClass ("CStaffPuff"), false, &linetarget);
if (linetarget != NULL) if (linetarget != NULL)
{ {
pmo->angle = R_PointToAngle2 (pmo->x, pmo->y, linetarget->x, linetarget->y); pmo->angle = pmo->AngleTo(linetarget);
if ((linetarget->player && (!linetarget->IsTeammate (pmo) || level.teamdamage != 0)) || linetarget->flags3&MF3_ISMONSTER) if ((linetarget->player && (!linetarget->IsTeammate (pmo) || level.teamdamage != 0)) || linetarget->flags3&MF3_ISMONSTER)
{ {
newLife = player->health+(damage>>4); newLife = player->health+(damage>>4);

View file

@ -73,8 +73,7 @@ static void DragonSeek (AActor *actor, angle_t thresh, angle_t turnMax)
{ // attack the destination mobj if it's attackable { // attack the destination mobj if it's attackable
AActor *oldTarget; AActor *oldTarget;
if (absangle(actor->angle-R_PointToAngle2(actor->x, actor->y, if (absangle(actor->angle - actor->AngleTo(target)) < ANGLE_45/2)
target->x, target->y)) < ANGLE_45/2)
{ {
oldTarget = actor->target; oldTarget = actor->target;
actor->target = target; actor->target = target;
@ -99,8 +98,7 @@ static void DragonSeek (AActor *actor, angle_t thresh, angle_t turnMax)
{ {
AActor *bestActor = NULL; AActor *bestActor = NULL;
bestAngle = ANGLE_MAX; bestAngle = ANGLE_MAX;
angleToTarget = R_PointToAngle2(actor->x, actor->y, angleToTarget = actor->AngleTo(actor->target);
actor->target->x, actor->target->y);
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
{ {
if (!target->args[i]) if (!target->args[i])
@ -113,8 +111,7 @@ static void DragonSeek (AActor *actor, angle_t thresh, angle_t turnMax)
{ {
continue; continue;
} }
angleToSpot = R_PointToAngle2(actor->x, actor->y, angleToSpot = actor->AngleTo(mo);
mo->x, mo->y);
if (absangle(angleToSpot-angleToTarget) < bestAngle) if (absangle(angleToSpot-angleToTarget) < bestAngle)
{ {
bestAngle = absangle(angleToSpot-angleToTarget); bestAngle = absangle(angleToSpot-angleToTarget);
@ -190,8 +187,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_DragonFlight)
self->target = NULL; self->target = NULL;
return; return;
} }
angle = R_PointToAngle2(self->x, self->y, self->target->x, angle = self->AngleTo(self->target);
self->target->y);
if (absangle(self->angle-angle) < ANGLE_45/2 && self->CheckMeleeRange()) if (absangle(self->angle-angle) < ANGLE_45/2 && self->CheckMeleeRange())
{ {
int damage = pr_dragonflight.HitDice (8); int damage = pr_dragonflight.HitDice (8);

View file

@ -30,7 +30,7 @@ void AdjustPlayerAngle (AActor *pmo, AActor *linetarget)
angle_t angle; angle_t angle;
int difference; int difference;
angle = R_PointToAngle2 (pmo->x, pmo->y, linetarget->x, linetarget->y); angle = pmo->AngleTo(linetarget);
difference = (int)angle - (int)pmo->angle; difference = (int)angle - (int)pmo->angle;
if (abs(difference) > MAX_ANGLE_ADJUST) if (abs(difference) > MAX_ANGLE_ADJUST)
{ {

View file

@ -163,7 +163,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FiredChase)
{ {
if (pr_firedemonchase() < 30) if (pr_firedemonchase() < 30)
{ {
ang = R_PointToAngle2 (self->x, self->y, target->x, target->y); ang = self->AngleTo(target);
if (pr_firedemonchase() < 128) if (pr_firedemonchase() < 128)
ang += ANGLE_90; ang += ANGLE_90;
else else

View file

@ -79,7 +79,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FlyBuzz)
return; return;
} }
angle_t ang = R_PointToAngle2(self->x, self->y, targ->x, targ->y); angle_t ang = self->AngleTo(targ);
self->angle = ang; self->angle = ang;
self->args[0]++; self->args[0]++;
ang >>= ANGLETOFINESHIFT; ang >>= ANGLETOFINESHIFT;

View file

@ -109,8 +109,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_PotteryCheck)
if (playeringame[i]) if (playeringame[i])
{ {
AActor *pmo = players[i].mo; AActor *pmo = players[i].mo;
if (P_CheckSight (self, pmo) && (absangle(R_PointToAngle2 (pmo->x, if (P_CheckSight (self, pmo) && (absangle(pmo->AngleTo(self) - pmo->angle) <= ANGLE_45))
pmo->y, self->x, self->y) - pmo->angle) <= ANGLE_45))
{ // Previous state (pottery bit waiting state) { // Previous state (pottery bit waiting state)
self->SetState (self->state - 1); self->SetState (self->state - 1);
return; return;

View file

@ -485,7 +485,7 @@ AActor *P_SpawnKoraxMissile (fixed_t x, fixed_t y, fixed_t z,
z -= source->floorclip; z -= source->floorclip;
th = Spawn (type, x, y, z, ALLOW_REPLACE); th = Spawn (type, x, y, z, ALLOW_REPLACE);
th->target = source; // Originator th->target = source; // Originator
an = R_PointToAngle2(x, y, dest->x, dest->y); an = source->AngleXYTo(x, y, dest);
if (dest->flags & MF_SHADOW) if (dest->flags & MF_SHADOW)
{ // Invisible target { // Invisible target
an += pr_kmissile.Random2()<<21; an += pr_kmissile.Random2()<<21;

View file

@ -190,7 +190,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_LightningClip)
} }
else else
{ {
self->angle = R_PointToAngle2(self->x, self->y, target->x, target->y); self->angle = self->AngleTo(target);
self->velx = 0; self->velx = 0;
self->vely = 0; self->vely = 0;
P_ThrustMobj (self, self->angle, self->Speed>>1); P_ThrustMobj (self, self->angle, self->Speed>>1);

View file

@ -390,7 +390,7 @@ void P_MinotaurSlam (AActor *source, AActor *target)
fixed_t thrust; fixed_t thrust;
int damage; int damage;
angle = R_PointToAngle2 (source->x, source->y, target->x, target->y); angle = source->AngleTo(target);
angle >>= ANGLETOFINESHIFT; angle >>= ANGLETOFINESHIFT;
thrust = 16*FRACUNIT+(pr_minotaurslam()<<10); thrust = 16*FRACUNIT+(pr_minotaurslam()<<10);
target->velx += FixedMul (thrust, finecosine[angle]); target->velx += FixedMul (thrust, finecosine[angle]);

View file

@ -366,7 +366,7 @@ int FMugShot::UpdateState(player_t *player, StateFlags stateflags)
if (player->mo != NULL) if (player->mo != NULL)
{ {
// The next 12 lines are from the Doom statusbar code. // The next 12 lines are from the Doom statusbar code.
badguyangle = R_PointToAngle2(player->mo->x, player->mo->y, player->attacker->x, player->attacker->y); badguyangle = player->mo->AngleTo(player->attacker);
if (badguyangle > player->mo->angle) if (badguyangle > player->mo->angle)
{ {
// whether right or left // whether right or left

View file

@ -118,10 +118,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_JabDagger)
S_Sound (self, CHAN_WEAPON, S_Sound (self, CHAN_WEAPON,
linetarget->flags & MF_NOBLOOD ? "misc/metalhit" : "misc/meathit", linetarget->flags & MF_NOBLOOD ? "misc/metalhit" : "misc/meathit",
1, ATTN_NORM); 1, ATTN_NORM);
self->angle = R_PointToAngle2 (self->x, self->angle = self->AngleTo(linetarget);
self->y,
linetarget->x,
linetarget->y);
self->flags |= MF_JUSTATTACKED; self->flags |= MF_JUSTATTACKED;
P_DaggerAlert (self, linetarget); P_DaggerAlert (self, linetarget);
} }

View file

@ -1117,7 +1117,7 @@ void P_StartConversation (AActor *npc, AActor *pc, bool facetalker, bool saveang
if (facetalker) if (facetalker)
{ {
A_FaceTarget (npc); A_FaceTarget (npc);
pc->angle = R_PointToAngle2 (pc->x, pc->y, npc->x, npc->y); pc->angle = pc->AngleTo(npc);
} }
if ((npc->flags & MF_FRIENDLY) || (npc->flags4 & MF4_NOHATEPLAYERS)) if ((npc->flags & MF_FRIENDLY) || (npc->flags4 & MF4_NOHATEPLAYERS))
{ {

View file

@ -392,7 +392,7 @@ bool P_HitFriend(AActor * self)
if (self->flags&MF_FRIENDLY && self->target != NULL) if (self->flags&MF_FRIENDLY && self->target != NULL)
{ {
angle_t angle = R_PointToAngle2 (self->x, self->y, self->target->x, self->target->y); angle_t angle = self->AngleTo(self->target);
fixed_t dist = self->AproxDistance (self->target); fixed_t dist = self->AproxDistance (self->target);
P_AimLineAttack (self, angle, dist, &linetarget, 0, true); P_AimLineAttack (self, angle, dist, &linetarget, 0, true);
if (linetarget != NULL && linetarget != self->target) if (linetarget != NULL && linetarget != self->target)
@ -1160,7 +1160,7 @@ bool P_IsVisible(AActor *lookee, AActor *other, INTBOOL allaround, FLookExParams
if (fov && fov < ANGLE_MAX) if (fov && fov < ANGLE_MAX)
{ {
angle_t an = R_PointToAngle2 (lookee->x, lookee->y, other->x, other->y) - lookee->angle; angle_t an = lookee->AngleTo(other) - lookee->angle;
if (an > (fov / 2) && an < (ANGLE_MAX - (fov / 2))) if (an > (fov / 2) && an < (ANGLE_MAX - (fov / 2)))
{ {
@ -2389,7 +2389,7 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi
{ {
if (pr_chase() < 100) if (pr_chase() < 100)
{ {
angle_t ang = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y); angle_t ang = actor->AngleTo(actor->target);
if (pr_chase() < 128) ang += ANGLE_90; if (pr_chase() < 128) ang += ANGLE_90;
else ang -= ANGLE_90; else ang -= ANGLE_90;
actor->velx = 13 * finecosine[ang>>ANGLETOFINESHIFT]; actor->velx = 13 * finecosine[ang>>ANGLETOFINESHIFT];
@ -2743,7 +2743,7 @@ void A_Face (AActor *self, AActor *other, angle_t max_turn, angle_t max_pitch, a
self->flags &= ~MF_AMBUSH; self->flags &= ~MF_AMBUSH;
angle_t other_angle = R_PointToAngle2 (self->x, self->y, other->x, other->y); angle_t other_angle = self->AngleTo(other);
// 0 means no limit. Also, if we turn in a single step anyways, no need to go through the algorithms. // 0 means no limit. Also, if we turn in a single step anyways, no need to go through the algorithms.
// It also means that there is no need to check for going past the other. // It also means that there is no need to check for going past the other.
@ -2916,10 +2916,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_MonsterRail)
self->flags &= ~MF_AMBUSH; self->flags &= ~MF_AMBUSH;
self->angle = R_PointToAngle2 (self->x, self->angle = self->AngleTo(self->target);
self->y,
self->target->x,
self->target->y);
self->pitch = P_AimLineAttack (self, self->angle, MISSILERANGE, &linetarget, ANGLE_1*60, 0, self->target); self->pitch = P_AimLineAttack (self, self->angle, MISSILERANGE, &linetarget, ANGLE_1*60, 0, self->target);
if (linetarget == NULL) if (linetarget == NULL)
@ -2932,10 +2929,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_MonsterRail)
} }
// Let the aim trail behind the player // Let the aim trail behind the player
self->angle = R_PointToAngle2 (self->x, self->angle = self->AngleTo(self->target, -self->target->velx * 3, -self->target->vely * 3);
self->y,
self->target->x - self->target->velx * 3,
self->target->y - self->target->vely * 3);
if (self->target->flags & MF_SHADOW && !(self->flags6 & MF6_SEEINVISIBLE)) if (self->target->flags & MF_SHADOW && !(self->flags6 & MF6_SEEINVISIBLE))
{ {

View file

@ -1164,7 +1164,7 @@ int P_DamageMobj (AActor *target, AActor *inflictor, AActor *source, int damage,
} }
else else
{ {
ang = R_PointToAngle2 (origin->x, origin->y, target->x, target->y); ang = origin->AngleTo(target);
} }
// Calculate this as float to avoid overflows so that the // Calculate this as float to avoid overflows so that the

View file

@ -3066,7 +3066,7 @@ bool P_BounceActor(AActor *mo, AActor *BlockingMobj, bool ontop)
if (!ontop) if (!ontop)
{ {
fixed_t speed; fixed_t speed;
angle_t angle = R_PointToAngle2(BlockingMobj->x,BlockingMobj->y, mo->x, mo->y) + ANGLE_1*((pr_bounce() % 16) - 8); angle_t angle = BlockingMobj->AngleTo(mo) + ANGLE_1*((pr_bounce() % 16) - 8);
speed = P_AproxDistance(mo->velx, mo->vely); speed = P_AproxDistance(mo->velx, mo->vely);
speed = FixedMul(speed, mo->wallbouncefactor); // [GZ] was 0.75, using wallbouncefactor seems more consistent speed = FixedMul(speed, mo->wallbouncefactor); // [GZ] was 0.75, using wallbouncefactor seems more consistent
mo->angle = angle; mo->angle = angle;
@ -4084,7 +4084,7 @@ void P_TraceBleed(int damage, AActor *target, AActor *missile)
pitch = 0; pitch = 0;
} }
P_TraceBleed(damage, target->x, target->y, target->z + target->height / 2, P_TraceBleed(damage, target->x, target->y, target->z + target->height / 2,
target, R_PointToAngle2(missile->x, missile->y, target->x, target->y), target, missile->AngleTo(target),
pitch); pitch);
} }
@ -4853,7 +4853,7 @@ void P_RadiusAttack(AActor *bombspot, AActor *bombsource, int bombdamage, int bo
{ {
velz *= 0.8f; velz *= 0.8f;
} }
angle_t ang = R_PointToAngle2(bombspot->x, bombspot->y, thing->x, thing->y) >> ANGLETOFINESHIFT; angle_t ang = bombspot->AngleTo(thing) >> ANGLETOFINESHIFT;
thing->velx += fixed_t(finecosine[ang] * thrust); thing->velx += fixed_t(finecosine[ang] * thrust);
thing->vely += fixed_t(finesine[ang] * thrust); thing->vely += fixed_t(finesine[ang] * thrust);
if (!(flags & RADF_NODAMAGE)) if (!(flags & RADF_NODAMAGE))

View file

@ -1556,7 +1556,7 @@ int P_FaceMobj (AActor *source, AActor *target, angle_t *delta)
angle_t angle2; angle_t angle2;
angle1 = source->angle; angle1 = source->angle;
angle2 = R_PointToAngle2 (source->x, source->y, target->x, target->y); angle2 = source->AngleTo(target);
if (angle2 > angle1) if (angle2 > angle1)
{ {
diff = angle2 - angle1; diff = angle2 - angle1;
@ -2019,7 +2019,7 @@ fixed_t P_XYMovement (AActor *mo, fixed_t scrollx, fixed_t scrolly)
// Don't change the angle if there's THRUREFLECT on the monster. // Don't change the angle if there's THRUREFLECT on the monster.
if (!(BlockingMobj->flags7 & MF7_THRUREFLECT)) if (!(BlockingMobj->flags7 & MF7_THRUREFLECT))
{ {
angle = R_PointToAngle2(BlockingMobj->x, BlockingMobj->y, mo->x, mo->y); angle = BlockingMobj->AngleTo(mo);
bool dontReflect = (mo->AdjustReflectionAngle(BlockingMobj, angle)); bool dontReflect = (mo->AdjustReflectionAngle(BlockingMobj, angle));
// Change angle for deflection/reflection // Change angle for deflection/reflection
@ -3088,8 +3088,7 @@ bool AActor::IsOkayToAttack (AActor *link)
// to only allow the check to succeed if the enemy was in a ~84<38> FOV of the player // to only allow the check to succeed if the enemy was in a ~84<38> FOV of the player
if (flags3 & MF3_SCREENSEEKER) if (flags3 & MF3_SCREENSEEKER)
{ {
angle_t angle = R_PointToAngle2(Friend->x, angle_t angle = Friend->AngleTo(link) - Friend->angle;
Friend->y, link->x, link->y) - Friend->angle;
angle >>= 24; angle >>= 24;
if (angle>226 || angle<30) if (angle>226 || angle<30)
{ {
@ -5035,7 +5034,7 @@ AActor *P_SpawnPuff (AActor *source, const PClass *pufftype, fixed_t x, fixed_t
puff->target = source; puff->target = source;
if (source != NULL) puff->angle = R_PointToAngle2(x, y, source->x, source->y); if (source != NULL) puff->angle = puff->AngleTo(source);
// If a puff has a crash state and an actor was not hit, // If a puff has a crash state and an actor was not hit,
// it will enter the crash state. This is used by the StrifeSpark // it will enter the crash state. This is used by the StrifeSpark
@ -5782,7 +5781,7 @@ AActor * P_OldSpawnMissile(AActor * source, AActor * owner, AActor * dest, const
P_PlaySpawnSound(th, source); P_PlaySpawnSound(th, source);
th->target = owner; // record missile's originator th->target = owner; // record missile's originator
th->angle = an = R_PointToAngle2 (source->x, source->y, dest->x, dest->y); th->angle = an = source->AngleTo(dest);
an >>= ANGLETOFINESHIFT; an >>= ANGLETOFINESHIFT;
th->velx = FixedMul (th->Speed, finecosine[an]); th->velx = FixedMul (th->Speed, finecosine[an]);
th->vely = FixedMul (th->Speed, finesine[an]); th->vely = FixedMul (th->Speed, finesine[an]);

View file

@ -2233,7 +2233,7 @@ void DPusher::Tick ()
if ((speed > 0) && (P_CheckSight (thing, m_Source, SF_IGNOREVISIBILITY))) if ((speed > 0) && (P_CheckSight (thing, m_Source, SF_IGNOREVISIBILITY)))
{ {
angle_t pushangle = R_PointToAngle2 (thing->x, thing->y, sx, sy); angle_t pushangle = thing->AngleTo(sx, sy);
if (m_Source->GetClass()->TypeName == NAME_PointPusher) if (m_Source->GetClass()->TypeName == NAME_PointPusher)
pushangle += ANG180; // away pushangle += ANG180; // away
pushangle >>= ANGLETOFINESHIFT; pushangle >>= ANGLETOFINESHIFT;

View file

@ -304,7 +304,8 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char *type_nam
} }
else else
{ {
nolead: mobj->angle = R_PointToAngle2 (mobj->x, mobj->y, targ->x, targ->y); nolead:
mobj->angle = mobj->AngleTo(targ);
aim.Resize (fspeed); aim.Resize (fspeed);
mobj->velx = fixed_t(aim[0]); mobj->velx = fixed_t(aim[0]);
mobj->vely = fixed_t(aim[1]); mobj->vely = fixed_t(aim[1]);

View file

@ -1487,10 +1487,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomPunch)
if (!(flags & CPF_NOTURN)) if (!(flags & CPF_NOTURN))
{ {
// turn to face target // turn to face target
self->angle = R_PointToAngle2 (self->x, self->angle = self->AngleTo(linetarget);
self->y,
linetarget->x,
linetarget->y);
} }
if (flags & CPF_PULLIN) self->flags |= MF_JUSTATTACKED; if (flags & CPF_PULLIN) self->flags |= MF_JUSTATTACKED;
@ -1614,10 +1611,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomRailgun)
if (aim) if (aim)
{ {
self->angle = R_PointToAngle2 (self->x, self->angle = self->AngleTo(self->target);
self->y,
self->target->x,
self->target->y);
} }
self->pitch = P_AimLineAttack (self, self->angle, MISSILERANGE, &linetarget, ANGLE_1*60, 0, aim ? self->target : NULL); self->pitch = P_AimLineAttack (self, self->angle, MISSILERANGE, &linetarget, ANGLE_1*60, 0, aim ? self->target : NULL);
if (linetarget == NULL && aim) if (linetarget == NULL && aim)
@ -1631,9 +1625,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomRailgun)
// Let the aim trail behind the player // Let the aim trail behind the player
if (aim) if (aim)
{ {
saved_angle = self->angle = R_PointToAngle2 (self->x, self->y, saved_angle = self->angle = self->AngleTo(self->target, -self->target->velx * 3, -self->target->vely * 3);
self->target->x - self->target->velx * 3,
self->target->y - self->target->vely * 3);
if (aim == CRF_AIMDIRECT) if (aim == CRF_AIMDIRECT)
{ {
@ -1642,9 +1634,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomRailgun)
self->x += Spawnofs_XY * finecosine[self->angle]; self->x += Spawnofs_XY * finecosine[self->angle];
self->y += Spawnofs_XY * finesine[self->angle]; self->y += Spawnofs_XY * finesine[self->angle];
Spawnofs_XY = 0; Spawnofs_XY = 0;
self->angle = R_PointToAngle2 (self->x, self->y, self->angle = self->AngleTo(self->target,- self->target->velx * 3, -self->target->vely * 3);
self->target->x - self->target->velx * 3,
self->target->y - self->target->vely * 3);
} }
if (self->target->flags & MF_SHADOW) if (self->target->flags & MF_SHADOW)
@ -3357,7 +3347,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckLOF)
{ {
ang = self->angle; ang = self->angle;
} }
else ang = R_PointToAngle2 (x1, y1, target->x, target->y); else ang = self->AngleTo (target);
angle += ang; angle += ang;
@ -3576,11 +3566,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfTargetInLOS)
if (fov && (fov < ANGLE_MAX)) if (fov && (fov < ANGLE_MAX))
{ {
an = R_PointToAngle2 (viewport->x, an = viewport->AngleTo(target) - viewport->angle;
viewport->y,
target->x,
target->y)
- viewport->angle;
if (an > (fov / 2) && an < (ANGLE_MAX - (fov / 2))) if (an > (fov / 2) && an < (ANGLE_MAX - (fov / 2)))
{ {
@ -3654,11 +3640,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_JumpIfInTargetLOS)
if (fov && (fov < ANGLE_MAX)) if (fov && (fov < ANGLE_MAX))
{ {
an = R_PointToAngle2 (target->x, an = target->AngleTo(self) - target->angle;
target->y,
self->x,
self->y)
- target->angle;
if (an > (fov / 2) && an < (ANGLE_MAX - (fov / 2))) if (an > (fov / 2) && an < (ANGLE_MAX - (fov / 2)))
{ {
@ -4588,7 +4570,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_WolfAttack)
// Target can dodge if it can see enemy // Target can dodge if it can see enemy
angle_t angle = R_PointToAngle2(self->target->x, self->target->y, self->x, self->y) - self->target->angle; angle_t angle = self->target->AngleTo(self) - self->target->angle;
angle >>= 24; angle >>= 24;
bool dodge = (P_CheckSight(self->target, self) && (angle>226 || angle<30)); bool dodge = (P_CheckSight(self->target, self) && (angle>226 || angle<30));
@ -4627,7 +4609,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_WolfAttack)
dx = self->target->x; dx = self->target->x;
dy = self->target->y; dy = self->target->y;
dz = self->target->z + (self->target->height>>1); dz = self->target->z + (self->target->height>>1);
angle = R_PointToAngle2(dx, dy, self->x, self->y); angle = self->target->AngleTo(self);
dx += FixedMul(self->target->radius, finecosine[angle>>ANGLETOFINESHIFT]); dx += FixedMul(self->target->radius, finecosine[angle>>ANGLETOFINESHIFT]);
dy += FixedMul(self->target->radius, finesine[angle>>ANGLETOFINESHIFT]); dy += FixedMul(self->target->radius, finesine[angle>>ANGLETOFINESHIFT]);
@ -4662,7 +4644,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_WolfAttack)
if (spawnblood) if (spawnblood)
{ {
P_SpawnBlood(dx, dy, dz, angle, newdam > 0 ? newdam : damage, self->target); P_SpawnBlood(dx, dy, dz, angle, newdam > 0 ? newdam : damage, self->target);
P_TraceBleed(newdam > 0 ? newdam : damage, self->target, R_PointToAngle2(self->x, self->y, dx, dy), 0); P_TraceBleed(newdam > 0 ? newdam : damage, self->target, self->AngleTo(dx, dy, self->target), 0);
} }
} }
} }