- more coordinate refactoring in p_enemy.cpp.

This commit is contained in:
Christoph Oelckers 2016-01-17 22:13:17 +01:00
parent be91771abc
commit a65ff39872
3 changed files with 48 additions and 53 deletions

View File

@ -429,7 +429,7 @@ void P_RunEffect (AActor *actor, int effects)
fixedvec3 pos = actor->Vec3Offset(
backx - FixedMul(actor->velx, pathdist),
backy - FixedMul(actor->vely, pathdist),
backz - FixedMul(actor->velz, pathdist) + (M_Random() << 10);
backz - FixedMul(actor->velz, pathdist) + (M_Random() << 10));
particle->x = pos.x;
particle->y = pos.y;
particle->z = pos.z;

View File

@ -243,9 +243,9 @@ bool AActor::CheckMeleeRange ()
// [RH] Don't melee things too far above or below actor.
if (!(flags5 & MF5_NOVERTICALMELEERANGE))
{
if (pl->Z() > z + height)
if (pl->Z() > Z() + height)
return false;
if (pl->Z() + pl->height < z)
if (pl->Z() + pl->height < Z())
return false;
}
@ -473,8 +473,8 @@ bool P_Move (AActor *actor)
}
}
tryx = (origx = actor->x) + (deltax = FixedMul (speed, xspeed[actor->movedir]));
tryy = (origy = actor->y) + (deltay = FixedMul (speed, yspeed[actor->movedir]));
tryx = (origx = actor->X()) + (deltax = FixedMul (speed, xspeed[actor->movedir]));
tryy = (origy = actor->Y()) + (deltay = FixedMul (speed, yspeed[actor->movedir]));
// Like P_XYMovement this should do multiple moves if the step size is too large
@ -519,15 +519,14 @@ bool P_Move (AActor *actor)
// so make it switchable
if (nomonsterinterpolation)
{
actor->PrevX = actor->x;
actor->PrevY = actor->y;
actor->PrevZ = actor->z;
actor->PrevX = actor->X();
actor->PrevY = actor->Y();
actor->PrevZ = actor->Z();
}
if (try_ok && friction > ORIG_FRICTION)
{
actor->x = origx;
actor->y = origy;
actor->SetOrigin(origx, origy, actor->Z(), false);
movefactor *= FRACUNIT / ORIG_FRICTION_FACTOR / 4;
actor->velx += FixedMul (deltax, movefactor);
actor->vely += FixedMul (deltay, movefactor);
@ -543,12 +542,12 @@ bool P_Move (AActor *actor)
if (actor->Y() <= actor->floorz + actor->MaxStepHeight)
{
fixed_t savedz = actor->Z();
actor->z = actor->floorz;
actor->SetZ(actor->floorz);
// Make sure that there isn't some other actor between us and
// the floor we could get stuck in. The old code did not do this.
if (!P_TestMobjZ(actor))
{
actor->z = savedz;
actor->SetZ(savedz);
}
else
{ // The monster just hit the floor, so trigger any actions.
@ -568,10 +567,10 @@ bool P_Move (AActor *actor)
{ // must adjust height
fixed_t savedz = actor->Z();
if (actor->z < tm.floorz)
actor->z += actor->FloatSpeed;
if (actor->Z() < tm.floorz)
actor->SetZ(actor->Z() + actor->FloatSpeed);
else
actor->z -= actor->FloatSpeed;
actor->SetZ(actor->Z() - actor->FloatSpeed);
// [RH] Check to make sure there's nothing in the way of the float
@ -580,7 +579,7 @@ bool P_Move (AActor *actor)
actor->flags |= MF_INFLOAT;
return true;
}
actor->z = savedz;
actor->SetZ(savedz);
}
if (!spechit.Size ())
@ -812,28 +811,25 @@ void P_DoNewChaseDir (AActor *actor, fixed_t deltax, fixed_t deltay)
void P_NewChaseDir(AActor * actor)
{
fixed_t deltax;
fixed_t deltay;
fixedvec2 delta;
actor->strafecount = 0;
if ((actor->flags5&MF5_CHASEGOAL || actor->goal == actor->target) && actor->goal!=NULL)
{
deltax = actor->goal->x - actor->x;
deltay = actor->goal->y - actor->y;
delta = actor->Vec2To(actor->goal);
}
else if (actor->target != NULL)
{
deltax = actor->target->x - actor->x;
deltay = actor->target->y - actor->y;
delta = actor->Vec2To(actor->target);
if (!(actor->flags6 & MF6_NOFEAR))
{
if ((actor->target->player != NULL && (actor->target->player->cheats & CF_FRIGHTENING)) ||
(actor->flags4 & MF4_FRIGHTENED))
{
deltax = -deltax;
deltay = -deltay;
delta.x = -delta.x;
delta.y = -delta.y;
}
}
}
@ -877,7 +873,7 @@ void P_NewChaseDir(AActor * actor)
{
angle = R_PointToAngle2(0,0,line->dx,line->dy); // front side dropoff
}
else if (front == actor->z && back < actor->z - actor->MaxDropOffHeight)
else if (front == actor->Z() && back < actor->Z() - actor->MaxDropOffHeight)
{
angle = R_PointToAngle2(line->dx,line->dy,0,0); // back side dropoff
}
@ -946,12 +942,12 @@ void P_NewChaseDir(AActor * actor)
if (ismeleeattacker)
{
actor->strafecount = pr_enemystrafe() & 15;
deltax = -deltax, deltay = -deltay;
delta.x = -delta.x, delta.y = -delta.y;
}
}
}
P_DoNewChaseDir(actor, deltax, deltay);
P_DoNewChaseDir(actor, delta.x, delta.y);
// If strafing, set movecount to strafecount so that old Doom
// logic still works the same, except in the strafing part
@ -983,7 +979,7 @@ void P_RandomChaseDir (AActor *actor)
if (actor->flags & MF_FRIENDLY)
{
AActor *player;
fixed_t deltax, deltay;
fixedvec2 delta;
dirtype_t d[3];
if (actor->FriendPlayer != 0)
@ -1005,19 +1001,18 @@ void P_RandomChaseDir (AActor *actor)
{
if (pr_newchasedir() & 1 || !P_CheckSight (actor, player))
{
deltax = player->x - actor->x;
deltay = player->y - actor->y;
delta = actor->Vec2To(player);
if (deltax>128*FRACUNIT)
if (delta.x>128*FRACUNIT)
d[1]= DI_EAST;
else if (deltax<-128*FRACUNIT)
else if (delta.x<-128*FRACUNIT)
d[1]= DI_WEST;
else
d[1]=DI_NODIR;
if (deltay<-128*FRACUNIT)
if (delta.y<-128*FRACUNIT)
d[2]= DI_SOUTH;
else if (deltay>128*FRACUNIT)
else if (delta.y>128*FRACUNIT)
d[2]= DI_NORTH;
else
d[2]=DI_NODIR;
@ -1025,13 +1020,13 @@ void P_RandomChaseDir (AActor *actor)
// try direct route
if (d[1] != DI_NODIR && d[2] != DI_NODIR)
{
actor->movedir = diags[((deltay<0)<<1) + (deltax>0)];
actor->movedir = diags[((delta.y<0)<<1) + (delta.x>0)];
if (actor->movedir != turnaround && P_TryWalk(actor))
return;
}
// try other directions
if (pr_newchasedir() > 200 || abs(deltay) > abs(deltax))
if (pr_newchasedir() > 200 || abs(delta.y) > abs(delta.x))
{
swapvalues (d[1], d[2]);
}
@ -2474,8 +2469,8 @@ void A_DoChase (AActor *actor, bool fastchase, FState *meleestate, FState *missi
if ((!fastchase || !actor->FastChaseStrafeCount) && !dontmove)
{
// CANTLEAVEFLOORPIC handling was completely missing in the non-serpent functions.
fixed_t oldX = actor->x;
fixed_t oldY = actor->y;
fixed_t oldX = actor->X();
fixed_t oldY = actor->Y();
FTextureID oldFloor = actor->floorpic;
// chase towards player
@ -2526,11 +2521,12 @@ static bool P_CheckForResurrection(AActor *self, bool usevilestates)
if (self->movedir != DI_NODIR)
{
const fixed_t absSpeed = abs (self->Speed);
fixed_t viletryx = self->x + FixedMul (absSpeed, xspeed[self->movedir]);
fixed_t viletryy = self->y + FixedMul (absSpeed, yspeed[self->movedir]);
fixedvec2 viletry = self->Vec2Offset(
FixedMul (absSpeed, xspeed[self->movedir]),
FixedMul (absSpeed, yspeed[self->movedir]), true);
AActor *corpsehit;
FBlockThingsIterator it(FBoundingBox(viletryx, viletryy, 32*FRACUNIT));
FBlockThingsIterator it(FBoundingBox(viletry.x, viletry.y, 32*FRACUNIT));
while ((corpsehit = it.Next()))
{
FState *raisestate = corpsehit->GetRaiseState();
@ -2539,8 +2535,8 @@ static bool P_CheckForResurrection(AActor *self, bool usevilestates)
// use the current actor's radius instead of the Arch Vile's default.
fixed_t maxdist = corpsehit->GetDefault()->radius + self->radius;
if (abs(corpsehit->x - viletryx) > maxdist ||
abs(corpsehit->y - viletryy) > maxdist)
if (abs(corpsehit->X() - viletry.x) > maxdist ||
abs(corpsehit->Y() - viletry.y) > maxdist)
continue; // not actually touching
// Let's check if there are floors in between the archvile and its target
sector_t *vilesec = self->Sector;
@ -2783,12 +2779,11 @@ void A_Face (AActor *self, AActor *other, angle_t max_turn, angle_t max_pitch, a
{
// [DH] Don't need to do proper fixed->double conversion, since the
// result is only used in a ratio.
double dist_x = other->x - self->x;
double dist_y = other->y - self->y;
fixedvec2 dist = self->Vec2To(other);
// Positioning ala missile spawning, 32 units above foot level
fixed_t source_z = self->z + 32*FRACUNIT + self->GetBobOffset();
fixed_t target_z = other->z + 32*FRACUNIT + other->GetBobOffset();
fixed_t source_z = self->Z() + 32*FRACUNIT + self->GetBobOffset();
fixed_t target_z = other->Z() + 32*FRACUNIT + other->GetBobOffset();
// If the target z is above the target's head, reposition to the middle of
// its body.
@ -2809,8 +2804,8 @@ void A_Face (AActor *self, AActor *other, angle_t max_turn, angle_t max_pitch, a
target_z += pitch_offset;
double dist_z = target_z - source_z;
double dist = sqrt(dist_x*dist_x + dist_y*dist_y + dist_z*dist_z);
int other_pitch = (int)rad2bam(asin(dist_z / dist));
double ddist = sqrt(dist.x*dist.x + dist.y*dist.y + dist_z*dist_z);
int other_pitch = (int)rad2bam(asin(dist_z / ddist));
if (max_pitch != 0)
{
@ -2922,9 +2917,9 @@ DEFINE_ACTION_FUNCTION(AActor, A_MonsterRail)
if (linetarget == NULL)
{
// We probably won't hit the target, but aim at it anyway so we don't look stupid.
TVector2<double> xydiff(self->target->x - self->x, self->target->y - self->y);
double zdiff = (self->target->z + (self->target->height>>1)) -
(self->z + (self->height>>1) - self->floorclip);
TVector2<double> xydiff = self->Vec2To(self->target);
double zdiff = (self->target->Z() + (self->target->height>>1)) -
(self->Z() + (self->height>>1) - self->floorclip);
self->pitch = int(atan2(zdiff, xydiff.Length()) * ANGLE_180 / -M_PI);
}

View File

@ -3107,7 +3107,7 @@ FUNC(LS_GlassBreak)
{
glass = Spawn("GlassJunk", x, y, ONFLOORZ, ALLOW_REPLACE);
glass->z += 24 * FRACUNIT;
glass->SetZ(glass->z + 24 * FRACUNIT);
glass->SetState (glass->SpawnState + (pr_glass() % glass->health));
an = pr_glass() << (32-8);
glass->angle = an;