mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-22 19:38:06 -04:00
Implement crosshair target lock-on (#814)
* Implement crosshair target lock-on * Calculate lock-on offset in `R_ProjectSprite()` * Introduce `HU_UpdateCrosshairLock()` * A couple of changes * More changes * Update lock offset just once per tic
This commit is contained in:
parent
94efdea7c3
commit
6b4e76c6d9
@ -226,6 +226,7 @@ static void HU_InitCrosshair(void);
|
||||
int hud_crosshair;
|
||||
boolean hud_crosshair_health;
|
||||
boolean hud_crosshair_target;
|
||||
boolean hud_crosshair_lockon; // [Alaux] Crosshair locks on target
|
||||
int hud_crosshair_color;
|
||||
int hud_crosshair_target_color;
|
||||
|
||||
@ -1010,14 +1011,16 @@ static void HU_InitCrosshair(void)
|
||||
|
||||
crosshair.w = SHORT(crosshair.patch->width)/2;
|
||||
crosshair.h = SHORT(crosshair.patch->height)/2;
|
||||
crosshair.x = ORIGWIDTH/2;
|
||||
}
|
||||
else
|
||||
crosshair.patch = NULL;
|
||||
}
|
||||
|
||||
mobj_t *crosshair_target; // [Alaux] Lock crosshair on target
|
||||
|
||||
static void HU_UpdateCrosshair(void)
|
||||
{
|
||||
crosshair.x = ORIGWIDTH/2;
|
||||
crosshair.y = (screenblocks <= 10) ? (ORIGHEIGHT-ST_HEIGHT)/2 : ORIGHEIGHT/2;
|
||||
|
||||
if (hud_crosshair_health)
|
||||
@ -1036,12 +1039,14 @@ static void HU_UpdateCrosshair(void)
|
||||
else
|
||||
crosshair.cr = colrngs[hud_crosshair_color];
|
||||
|
||||
if (STRICTMODE(hud_crosshair_target))
|
||||
if (STRICTMODE(hud_crosshair_target || hud_crosshair_lockon))
|
||||
{
|
||||
angle_t an = plr->mo->angle;
|
||||
ammotype_t ammo = weaponinfo[plr->readyweapon].ammo;
|
||||
fixed_t range = (ammo == am_noammo) ? MELEERANGE : 16*64*FRACUNIT;
|
||||
boolean intercepts_overflow_enabled = overflow[emu_intercepts].enabled;
|
||||
|
||||
crosshair_target = linetarget = NULL;
|
||||
|
||||
overflow[emu_intercepts].enabled = false;
|
||||
P_AimLineAttack(plr->mo, an, range, 0);
|
||||
@ -1053,14 +1058,23 @@ static void HU_UpdateCrosshair(void)
|
||||
P_AimLineAttack(plr->mo, an -= 2<<26, range, 0);
|
||||
}
|
||||
overflow[emu_intercepts].enabled = intercepts_overflow_enabled;
|
||||
|
||||
crosshair_target = linetarget;
|
||||
|
||||
if (linetarget && !(linetarget->flags & MF_SHADOW))
|
||||
if (hud_crosshair_target && crosshair_target
|
||||
&& !(crosshair_target->flags & MF_SHADOW))
|
||||
{
|
||||
crosshair.cr = colrngs[hud_crosshair_target_color];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HU_UpdateCrosshairLock(int x, int y)
|
||||
{
|
||||
crosshair.x += x;
|
||||
crosshair.y += y;
|
||||
}
|
||||
|
||||
static void HU_DrawCrosshair(void)
|
||||
{
|
||||
if (plr->playerstate != PST_LIVE ||
|
||||
|
@ -96,6 +96,12 @@ extern int crispy_hud;
|
||||
extern int hud_crosshair;
|
||||
extern boolean hud_crosshair_health;
|
||||
extern boolean hud_crosshair_target;
|
||||
|
||||
// [Alaux] Lock crosshair on target
|
||||
extern boolean hud_crosshair_lockon;
|
||||
extern mobj_t *crosshair_target;
|
||||
void HU_UpdateCrosshairLock(int x, int y);
|
||||
|
||||
extern int hud_crosshair_color;
|
||||
extern int hud_crosshair_target_color;
|
||||
|
||||
|
@ -3300,6 +3300,7 @@ enum {
|
||||
stat2_xhair,
|
||||
stat2_xhairhealth,
|
||||
stat2_xhairtarget,
|
||||
stat2_xhairlockon,
|
||||
stat2_xhaircolor,
|
||||
stat2_xhairtcolor,
|
||||
};
|
||||
@ -3308,6 +3309,7 @@ static void M_UpdateCrosshairItems (void)
|
||||
{
|
||||
DISABLE_ITEM(!hud_crosshair, stat_settings2[stat2_xhairhealth]);
|
||||
DISABLE_ITEM(!STRICTMODE(hud_crosshair), stat_settings2[stat2_xhairtarget]);
|
||||
DISABLE_ITEM(!STRICTMODE(hud_crosshair), stat_settings2[stat2_xhairlockon]);
|
||||
DISABLE_ITEM(!hud_crosshair, stat_settings2[stat2_xhaircolor]);
|
||||
DISABLE_ITEM(!STRICTMODE(hud_crosshair && hud_crosshair_target),
|
||||
stat_settings2[stat2_xhairtcolor]);
|
||||
@ -3343,6 +3345,7 @@ setup_menu_t stat_settings2[] =
|
||||
{"ENABLE CROSSHAIR", S_CHOICE,m_null,M_X,M_Y+stat2_xhair*M_SPC, {"hud_crosshair"}, 0, M_UpdateCrosshairItems, crosshair_str},
|
||||
{"COLOR BY PLAYER HEALTH",S_YESNO, m_null,M_X,M_Y+stat2_xhairhealth*M_SPC, {"hud_crosshair_health"}},
|
||||
{"HIGHLIGHT ON TARGET", S_YESNO, m_null,M_X,M_Y+stat2_xhairtarget*M_SPC, {"hud_crosshair_target"}, 0, M_UpdateCrosshairItems},
|
||||
{"LOCK ON TARGET", S_YESNO, m_null,M_X,M_Y+stat2_xhairlockon*M_SPC, {"hud_crosshair_lockon"}},
|
||||
{"DEFAULT COLOR", S_CRITEM,m_null,M_X,M_Y+stat2_xhaircolor*M_SPC, {"hud_crosshair_color"}, 0, NULL, hudcolor_str},
|
||||
{"HIGHLIGHT COLOR", S_CRITEM,m_null,M_X,M_Y+stat2_xhairtcolor*M_SPC, {"hud_crosshair_target_color"}, 0, NULL, hudcolor_str},
|
||||
|
||||
|
@ -2044,6 +2044,13 @@ default_t defaults[] = {
|
||||
"1 to change crosshair color on target"
|
||||
},
|
||||
|
||||
{
|
||||
"hud_crosshair_lockon",
|
||||
(config_t *) &hud_crosshair_lockon, NULL,
|
||||
{0}, {0,1}, number, ss_stat, wad_no,
|
||||
"1 to lock crosshair on target"
|
||||
},
|
||||
|
||||
{
|
||||
"hud_crosshair_color",
|
||||
(config_t *) &hud_crosshair_color, NULL,
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "r_things.h"
|
||||
#include "r_bmaps.h" // [crispy] R_BrightmapForTexName()
|
||||
#include "m_swap.h"
|
||||
#include "hu_stuff.h" // [Alaux] Lock crosshair on target
|
||||
|
||||
#define MINZ (FRACUNIT*4)
|
||||
#define BASEYCENTER 100
|
||||
@ -548,6 +549,19 @@ void R_ProjectSprite (mobj_t* thing)
|
||||
flip = !flip;
|
||||
}
|
||||
|
||||
// [Alaux] Lock crosshair on target
|
||||
if (STRICTMODE(hud_crosshair_lockon) && thing == crosshair_target)
|
||||
{
|
||||
HU_UpdateCrosshairLock
|
||||
(
|
||||
FixedMul(tx, xscale >> hires) >> FRACBITS,
|
||||
(FixedMul(viewz - (interpz + crosshair_target->height/2), xscale >> hires) >> FRACBITS)
|
||||
+ (viewplayer->lookdir / MLOOKUNIT + viewplayer->recoilpitch)
|
||||
);
|
||||
|
||||
crosshair_target = NULL; // Don't update it again until next tic
|
||||
}
|
||||
|
||||
// calculate edges of the shape
|
||||
// [crispy] fix sprite offsets for mirrored sprites
|
||||
tx -= flip ? spritewidth[lump] - spriteoffset[lump] : spriteoffset[lump];
|
||||
|
Loading…
x
Reference in New Issue
Block a user