- 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( fixedvec3 pos = actor->Vec3Offset(
backx - FixedMul(actor->velx, pathdist), backx - FixedMul(actor->velx, pathdist),
backy - FixedMul(actor->vely, 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->x = pos.x;
particle->y = pos.y; particle->y = pos.y;
particle->z = pos.z; particle->z = pos.z;

View file

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