Skip to content

Commit

Permalink
Fixed: checkMeleeRange() would forever fail if !cfg.netNoMaxZMonsterM…
Browse files Browse the repository at this point in the history
…eleeAttack due to the way the z height component was added to the distance calculation. Instead, do a z-height threshold check.
  • Loading branch information
danij committed Mar 28, 2008
1 parent 6c4146f commit 1670c19
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
11 changes: 5 additions & 6 deletions doomsday/plugins/jdoom/src/p_enemy.c
Expand Up @@ -129,12 +129,11 @@ static boolean checkMeleeRange(mobj_t *actor)
pl = actor->target;
dist = P_ApproxDistance(pl->pos[VX] - actor->pos[VX],
pl->pos[VY] - actor->pos[VY]);
if(!(cfg.netNoMaxZMonsterMeleeAttack))
{
// Account for Z height difference.
dist =
P_ApproxDistance(dist, pl->pos[VZ] + (pl->height /2) -
actor->pos[VZ] + (actor->height /2));
if(!cfg.netNoMaxZMonsterMeleeAttack)
{ // Account for Z height difference.
if(pl->pos[VZ] > actor->pos[VZ] + actor->height ||
pl->pos[VZ] + pl->height < actor->pos[VZ])
return false;
}

range = MELEERANGE - 20 + pl->info->radius;
Expand Down
16 changes: 8 additions & 8 deletions doomsday/plugins/jdoom64/src/p_enemy.c
Expand Up @@ -137,22 +137,22 @@ void P_NoiseAlert(mobj_t *target, mobj_t *emitter)
static boolean checkMeleeRange(mobj_t *actor)
{
mobj_t *pl;
float dist;
float range;
float dist, range;

if(!actor->target)
return false;

pl = actor->target;
dist = P_ApproxDistance(pl->pos[VX] - actor->pos[VX],
pl->pos[VY] - actor->pos[VY]);
if(!(cfg.netNoMaxZMonsterMeleeAttack))
dist =
P_ApproxDistance(dist, (pl->pos[VZ] + pl->height /2) -
(actor->pos[VZ] + actor->height /2));
if(!cfg.netNoMaxZMonsterMeleeAttack)
{ // Account for Z height difference.
if(pl->pos[VZ] > actor->pos[VZ] + actor->height ||
pl->pos[VZ] + pl->height < actor->pos[VZ])
return false;
}

//range = MELEERANGE - 20 + pl->info->radius;
range = MELEERANGE - 14 + pl->info->radius; // Was 20, d64tc
range = MELEERANGE - 20 + pl->info->radius;
if(dist >= range)
return false;

Expand Down
16 changes: 9 additions & 7 deletions doomsday/plugins/jheretic/src/p_enemy.c
Expand Up @@ -139,21 +139,23 @@ void P_NoiseAlert(mobj_t *target, mobj_t *emitter)

boolean P_CheckMeleeRange(mobj_t *actor)
{
mobj_t *pl;
float dist, range;
mobj_t *pl;
float dist, range;

if(!actor->target)
return false;

pl = actor->target;
dist = P_ApproxDistance(pl->pos[VX] - actor->pos[VX],
pl->pos[VY] - actor->pos[VY]);
if(!cfg.netNoMaxZMonsterMeleeAttack)
{ // Account for Z height difference.
if(pl->pos[VZ] > actor->pos[VZ] + actor->height ||
pl->pos[VZ] + pl->height < actor->pos[VZ])
return false;
}

if(!(cfg.netNoMaxZMonsterMeleeAttack))
dist = P_ApproxDistance(dist, (pl->pos[VZ] + pl->height /2) -
(actor->pos[VZ] + actor->height /2));

range = (MELEERANGE - 20) + pl->info->radius;
range = MELEERANGE - 20 + pl->info->radius;
if(dist >= range)
return false;

Expand Down
11 changes: 6 additions & 5 deletions doomsday/plugins/jhexen/src/p_enemy.c
Expand Up @@ -184,11 +184,12 @@ boolean P_CheckMeleeRange(mobj_t *actor, boolean midrange)
pl = actor->target;
dist = P_ApproxDistance(pl->pos[VX] - actor->pos[VX],
pl->pos[VY] - actor->pos[VY]);

if(!(cfg.netNoMaxZMonsterMeleeAttack))
dist = P_ApproxDistance(dist,
(pl->pos[VZ] + pl->height /2) -
(actor->pos[VZ] + actor->height /2));
if(!cfg.netNoMaxZMonsterMeleeAttack)
{ // Account for Z height difference.
if(pl->pos[VZ] > actor->pos[VZ] + actor->height ||
pl->pos[VZ] + pl->height < actor->pos[VZ])
return false;
}

range = MELEERANGE - 20 + pl->info->radius;
if(midrange)
Expand Down
17 changes: 9 additions & 8 deletions doomsday/plugins/wolftc/src/p_enemy.c
Expand Up @@ -125,22 +125,23 @@ void P_NoiseAlert(mobj_t *target, mobj_t *emitter)

boolean P_CheckMeleeRange(mobj_t *actor)
{
mobj_t *pl;
fixed_t dist;
fixed_t range;
mobj_t *pl;
float dist, range;

if(!actor->target)
return false;

pl = actor->target;
dist = P_ApproxDistance(pl->pos[VX] - actor->pos[VX],
pl->pos[VY] - actor->pos[VY]);
if(!(cfg.netNoMaxZMonsterMeleeAttack))
dist =
P_ApproxDistance(dist, (pl->pos[VZ] + FLT2FIX(pl->height /2)) -
(actor->pos[VZ] + FLT2FIX(actor->height /2)));
if(!cfg.netNoMaxZMonsterMeleeAttack)
{ // Account for Z height difference.
if(pl->pos[VZ] > actor->pos[VZ] + actor->height ||
pl->pos[VZ] + pl->height < actor->pos[VZ])
return false;
}

range = FLT2FIX(MELEERANGE - 20) + pl->info->radius;
range = MELEERANGE - 20 + pl->info->radius;
if(dist >= range)
return false;

Expand Down

0 comments on commit 1670c19

Please sign in to comment.