Improved direct vertical aiming and height calculations (#1213)

* Fix autoaim for direct vertical aiming

* Increase autoaim range for direct vertical aiming

* Calculate `actualheight` from current sprite

* Use `actualheight` for lock-on crosshair

* Use `actualheight` for check/aim/shoot

* Remove unused `spriteheight`

* Revert "Fix autoaim for direct vertical aiming"

This reverts commit 3a82190a6a0806f2f031ff23ccf61381b1924279.

* Revert "Increase autoaim range for direct vertical aiming"

This reverts commit 6c0e819567bcd0518709146ba1e97fd53b0653db.
This commit is contained in:
ceski 2023-09-23 11:21:16 -07:00 committed by GitHub
parent e1e8e06e96
commit d9ee850ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 39 deletions

View File

@ -173,13 +173,13 @@ static void CalcDistance(const mobj_t *listener, const mobj_t *source,
// Treat monsters and projectiles as point sources.
src->point_source = (source->thinker.function.v != (actionf_v)P_DegenMobjThinker &&
source->info && source->info->actualheight);
source->info && source->actualheight);
if (src->point_source)
{
fixed_t adz;
// Vertical distance is from player's view to middle of source's sprite.
src->z = source->z + (source->info->actualheight >> 1);
src->z = source->z + (source->actualheight >> 1);
adz = abs((listener->player->viewz >> FRACBITS) - (src->z >> FRACBITS));
CalcHypotenuse(distxy, adz, dist);
}

View File

@ -1524,8 +1524,6 @@ typedef struct
int bloodcolor; // [FG] colored blood and gibs
// DEHEXTRA
mobjtype_t droppeditem; // mobj to drop after death
// [crispy] height of the spawnstate's first sprite in pixels
int actualheight;
} mobjinfo_t;
#define NO_ALTSPEED -1

View File

@ -491,6 +491,13 @@ static boolean P_ProjectileImmune(mobj_t *target, mobj_t *source)
);
}
// [FG] mobj or actual sprite height
static const inline fixed_t thingheight (const mobj_t *const thing, const mobj_t *const cond)
{
return (direct_vertical_aiming && cond && cond->player && thing->actualheight > thing->height) ?
thing->actualheight : thing->height;
}
static boolean PIT_CheckThing(mobj_t *thing) // killough 3/26/98: make static
{
fixed_t blockdist;
@ -565,13 +572,9 @@ static boolean PIT_CheckThing(mobj_t *thing) // killough 3/26/98: make static
if (tmthing->flags & MF_MISSILE || (tmthing->flags & MF_BOUNCES &&
!(tmthing->flags & MF_SOLID)))
{
// [crispy] mobj or actual sprite height
const fixed_t thingheight = (direct_vertical_aiming && tmthing->target && tmthing->target->player) ?
thing->info->actualheight : thing->height;
// see if it went over / under
if (tmthing->z > thing->z + thingheight)
if (tmthing->z > thing->z + thingheight(thing, tmthing->target))
return true; // overhead
if (tmthing->z+tmthing->height < thing->z)
@ -1487,7 +1490,7 @@ static boolean PTR_AimTraverse (intercept_t *in)
// check angles to see if the thing can be aimed at
dist = FixedMul(attackrange, in->frac);
thingtopslope = FixedDiv(th->z+th->height - shootz , dist);
thingtopslope = FixedDiv(th->z+thingheight(th, shootthing) - shootz , dist);
if (thingtopslope < bottomslope)
return true; // shot over the thing
@ -1615,12 +1618,7 @@ static boolean PTR_ShootTraverse(intercept_t *in)
// check angles to see if the thing can be aimed at
dist = FixedMul (attackrange, in->frac);
{
// [crispy] mobj or actual sprite height
const fixed_t thingheight = (direct_vertical_aiming && shootthing->player) ?
th->info->actualheight : th->height;
thingtopslope = FixedDiv (th->z+thingheight - shootz , dist);
}
thingtopslope = FixedDiv (th->z+thingheight(th, shootthing) - shootz , dist);
if (thingtopslope < aimslope)
return true; // shot over the thing

View File

@ -108,6 +108,12 @@ boolean P_SetMobjState(mobj_t* mobj,statenum_t state)
if (tempstate)
Z_Free(tempstate);
// [FG] update object's actual height
if (ret)
{
mobj->actualheight = spritetopoffset[sprites[mobj->sprite].spriteframes[mobj->frame & FF_FRAMEMASK].lump[0]];
}
return ret;
}
@ -883,28 +889,8 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
mobj->intflags &= ~MIF_FLIP;
}
// [crispy] height of the spawnstate's first sprite in pixels
if (!info->actualheight)
{
const spritedef_t *const sprdef = &sprites[mobj->sprite];
if (!sprdef->numframes || !(mobj->flags & (MF_SOLID|MF_SHOOTABLE)))
{
info->actualheight = info->height;
}
else
{
spriteframe_t *sprframe;
int lump;
patch_t *patch;
sprframe = &sprdef->spriteframes[mobj->frame & FF_FRAMEMASK];
lump = sprframe->lump[0];
patch = W_CacheLumpNum(lump + firstspritelump, PU_CACHE);
info->actualheight = SHORT(patch->height) << FRACBITS;
}
}
// [FG] initialize object's actual height
mobj->actualheight = spritetopoffset[sprites[st->sprite].spriteframes[st->frame & FF_FRAMEMASK].lump[0]];
P_AddThinker(&mobj->thinker);

View File

@ -379,6 +379,9 @@ typedef struct mobj_s
// [FG] colored blood and gibs
int bloodcolor;
// [FG] height of the sprite in pixels
int actualheight;
} mobj_t;
// External declarations (fomerly in p_local.h) -- killough 5/2/98

View File

@ -497,6 +497,9 @@ static void saveg_read_mobj_t(mobj_t *str)
{
str->bloodcolor = 0;
}
// [FG] height of the sprite in pixels
str->actualheight = spritetopoffset[sprites[str->sprite].spriteframes[str->frame & FF_FRAMEMASK].lump[0]];
}
static void saveg_write_mobj_t(mobj_t *str)

View File

@ -648,7 +648,7 @@ void R_ProjectSprite (mobj_t* thing)
HU_UpdateCrosshairLock
(
BETWEEN(0, viewwidth - 1, (centerxfrac + FixedMul(txc, xscale)) >> FRACBITS),
BETWEEN(0, viewheight - 1, (centeryfrac + FixedMul(viewz - interpz - crosshair_target->height/2, xscale)) >> FRACBITS)
BETWEEN(0, viewheight - 1, (centeryfrac + FixedMul(viewz - interpz - crosshair_target->actualheight/2, xscale)) >> FRACBITS)
);
crosshair_target = NULL; // Don't update it again until next tic