Skip to content

Commit

Permalink
Vertical Target Lock-on setting
Browse files Browse the repository at this point in the history
Additionally, some reformatting.
  • Loading branch information
MrAlaux committed Jan 13, 2025
1 parent 3e78983 commit f940a8f
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## New Features

- **_'RIOTMODE'_** cheat, to make enemies attack all sentient entities
- **_Vertical Target Lock-on_** setting
- **_Message Fadeout_** setting
- **_Weapon Bob Speed_** setting
- **_Bob [Weapon] While Switching_** setting
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ For these settings, their CVAR names are provided alongside the _CFG-only_ label
- **Crouching/ducking** (default key: <kbd>C</kbd>) [i.b. ZDoom]
- Includes support for crouching-player sprites, named `PLYC`; must be provided by the user
- **_View Height_** setting, which allows to enter a custom POV height value in the [32, 56] range [i.b. Brutal Doom]
- **_Vertical Target Lock-on_** setting, to make the camera automatically lock onto targets vertically [i.b. Rise of the Triad]
- **Flinching** setting, to flinch upon landing and/or taking damage
- **_Explosion Shake Effect_** setting (intensity determined by the CFG-only `explosion_shake_intensity_pct` CVAR) [i.b. Doom Retro]
- **_Subtle Idle Bobbing/Breathing_** setting [p.f. International Doom]
Expand Down
7 changes: 7 additions & 0 deletions src/mn_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -3786,6 +3786,12 @@ static void ChangeViewHeight(void)
oldviewheight = viewheight_value;
}

static void ToggleVerticalLockon(void)
{
if (!(vertical_lockon || mouselook || padlook))
{ players[displayplayer].centering = true; }
}

static const char *over_under_strings[] = {
"Off", "Player Only", "All Things", NULL
};
Expand Down Expand Up @@ -3813,6 +3819,7 @@ setup_menu_t gen_settings7[] = {
{"Nugget - View", S_SKIP|S_TITLE, N_X, M_SPC},

{"View Height", S_NUM |S_STRICT, N_X, M_SPC, {"viewheight_value"}, .action = ChangeViewHeight},
{"Vertical Target Lock-on", S_ONOFF |S_STRICT, N_X, M_SPC, {"vertical_lockon"}, .action = ToggleVerticalLockon},
{"Flinch upon", S_CHOICE|S_STRICT, N_X, M_SPC, {"flinching"}, .strings_id = str_flinching},
{"Explosion Shake Effect", S_ONOFF |S_STRICT, N_X, M_SPC, {"explosion_shake"}},
{"Subtle Idle Bobbing/Breathing", S_ONOFF |S_STRICT, N_X, M_SPC, {"breathing"}},
Expand Down
52 changes: 46 additions & 6 deletions src/p_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,6 @@ static const inline fixed_t thingheight (const mobj_t *const thing, const mobj_t
return thing->height; // [Nugget] Removed `actualheight`
}

// [Nugget] Factored out from `p_user.c`
fixed_t P_PitchToSlope(const fixed_t pitch)
{
return pitch ? -finetangent[(ANG90 - pitch) >> ANGLETOFINESHIFT] : 0;
}

// [Nugget] Over/Under /------------------------------------------------------

int over_under;
Expand Down Expand Up @@ -1664,6 +1658,48 @@ fixed_t attackrange;

static fixed_t aimslope;

// [Nugget] /-----------------------------------------------------------------

// Factored out from `p_user.c`
fixed_t P_PitchToSlope(const fixed_t pitch)
{
return pitch ? -finetangent[(ANG90 - pitch) >> ANGLETOFINESHIFT] : 0;
}

fixed_t P_SlopeToPitch(const fixed_t slope)
{
if (!slope) { return 0; }

int closest = 0;
fixed_t closest_diff = abs(finetangent[closest] - slope);

for (int i = 1; i < FINEANGLES/2; i++)
{
if (abs(finetangent[i] - slope) < closest_diff)
{
closest = i;
closest_diff = abs(finetangent[i] - slope);
}
}

return (closest << ANGLETOFINESHIFT) - ANG90;
}

static fixed_t linetarget_topslope = 0,
linetarget_bottomslope = 0;

fixed_t P_GetLinetargetTopSlope(void)
{
return linetarget_topslope;
}

fixed_t P_GetLinetargetBottomSlope(void)
{
return linetarget_bottomslope;
}

// [Nugget] -----------------------------------------------------------------/

// slopes to top and bottom of target
// killough 4/20/98: make static instead of using ones in p_sight.c

Expand Down Expand Up @@ -1760,6 +1796,10 @@ static boolean PTR_AimTraverse (intercept_t *in)
aimslope = (thingtopslope+thingbottomslope)/2;
linetarget = th;

// [Nugget]
linetarget_topslope = thingtopslope;
linetarget_bottomslope = thingbottomslope;

return false; // don't go any farther
}

Expand Down
3 changes: 3 additions & 0 deletions src/p_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ extern fixed_t attackrange;
// [Nugget] ==================================================================

fixed_t P_PitchToSlope(const fixed_t pitch);
fixed_t P_SlopeToPitch(const fixed_t slope);
fixed_t P_GetLinetargetTopSlope(void);
fixed_t P_GetLinetargetBottomSlope(void);

void P_PositionChasecam(fixed_t z, fixed_t dist, fixed_t slope); // Chasecam

Expand Down
82 changes: 82 additions & 0 deletions src/p_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
#include "st_widgets.h"

// [Nugget]
#include "d_items.h"
#include "m_input.h"
#include "p_maputl.h"
#include "s_sound.h"
#include "sounds.h"

Expand Down Expand Up @@ -671,6 +673,9 @@ void P_PlayerThink (player_t* player)
player->mo->flags &= ~MF_JUSTATTACKED;
}

if (STRICTMODE(vertical_lockon) && !(mouselook || padlook))
{ player->centering = false; }

// [crispy] center view
#define CENTERING_VIEW_ANGLE (4 * ANG1)

Expand Down Expand Up @@ -738,6 +743,83 @@ void P_PlayerThink (player_t* player)
return;
}

if (STRICTMODE(vertical_lockon) && !(mouselook || padlook))
{
if (player != &players[displayplayer])
{
player->pitch = 0;
}
else {
static int oldtic = -1;
static int lock_time = 0;

if (gametic - oldtic > 1) { lock_time = 0; }

{
const angle_t an = player->mo->angle;
const ammotype_t ammo = weaponinfo[player->readyweapon].ammo;
const fixed_t range = (ammo == am_noammo
&& !(player->readyweapon == wp_fist
&& player->cheats & CF_SAITAMA))
? MELEERANGE
: 16 * 64 * FRACUNIT * NOTCASUALPLAY(comp_longautoaim+1);

const boolean intercepts_overflow_enabled = overflow[emu_intercepts].enabled;
overflow[emu_intercepts].enabled = false;

int mask = (demo_version >= DV_MBF) ? MF_FRIEND : 0;

do {
P_AimLineAttack(player->mo, an, range, mask);

if (!vertical_aiming && (!no_hor_autoaim || ammo == am_clip || ammo == am_shell))
{
if (!linetarget)
{ P_AimLineAttack(player->mo, an + (1 << 26), range, mask); }

if (!linetarget)
{ P_AimLineAttack(player->mo, an - (1 << 26), range, mask); }
}
} while (mask && (mask = 0, !linetarget));

overflow[emu_intercepts].enabled = intercepts_overflow_enabled;
}

if (linetarget) { lock_time = 21; } // 0.6s

fixed_t target_pitch = 0;

if (lock_time)
{
if (linetarget)
{
fixed_t slope = FixedDiv(linetarget->z - player->mo->z,
P_AproxDistance(player->mo->x - linetarget->x,
player->mo->y - linetarget->y));

slope = BETWEEN(P_GetLinetargetBottomSlope(),
P_GetLinetargetTopSlope(),
slope);

target_pitch = P_SlopeToPitch(slope);
target_pitch = BETWEEN(-MAX_PITCH_ANGLE, MAX_PITCH_ANGLE, target_pitch);
}
else { target_pitch = player->pitch; }
}

const fixed_t step = MAX(ANG1, abs(player->pitch - target_pitch) / 4);

if (player->pitch < target_pitch)
{ player->pitch = MIN(target_pitch, player->pitch + step); }
else
{ player->pitch = MAX(target_pitch, player->pitch - step); }

if (lock_time) { lock_time--; }

oldtic = gametic;
}
}

// [Nugget] Slow Motion /---------------------------------------------------

static boolean slowMoKeyDown = false;
Expand Down
7 changes: 6 additions & 1 deletion src/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ int extra_level_brightness; // level brightness feature

// CVARs ---------------------------------------------------------------------

boolean vertical_lockon;

boolean flip_levels;
static int lowres_pixel_width;
static int lowres_pixel_height;
Expand Down Expand Up @@ -1241,7 +1243,7 @@ void R_SetupFrame (player_t *player)
}

if ((use_localview || (freecam_on && freecam_mode == FREECAM_CAM)) // [Nugget] Freecam
&& raw_input && !player->centering)
&& raw_input && !player->centering && (mouselook || padlook)) // [Nugget]
{
basepitch = player->pitch + localview.pitch;
basepitch = BETWEEN(-MAX_PITCH_ANGLE, MAX_PITCH_ANGLE, basepitch);
Expand Down Expand Up @@ -1905,6 +1907,9 @@ void R_BindRenderVariables(void)
M_BindNum("flinching", &flinching, NULL, 0, 0, 3, ss_gen, wad_yes,
"Flinch player view (0 = Off; 1 = Upon landing; 2 = Upon taking damage; 3 = Upon either)");

M_BindBool("vertical_lockon", &vertical_lockon, NULL,
false, ss_gen, wad_yes, "Camera automatically locks onto targets vertically");

M_BindBool("explosion_shake", &explosion_shake, NULL,
false, ss_gen, wad_yes, "Explosions shake the view");

Expand Down
2 changes: 2 additions & 0 deletions src/r_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ void R_SetViewSize(int blocks); // Called by M_Responder.

// [Nugget] /=================================================================

extern boolean vertical_lockon;

extern boolean flip_levels;
extern boolean nightvision_visor;
extern int fake_contrast;
Expand Down
2 changes: 1 addition & 1 deletion src/st_stuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ void ST_Ticker(void)

UpdateNughudStacks();

if (hud_crosshair)
if (hud_crosshair_on) // [Nugget] Crosshair toggle
{
HU_UpdateCrosshair();
}
Expand Down

0 comments on commit f940a8f

Please sign in to comment.