Skip to content

Commit

Permalink
Implement the option to extend the player shoot range (on by default)
Browse files Browse the repository at this point in the history
If enabled, extends the following player attack limits:
    - Max shoot/hitscan distance, from '2048' to '8192'.
    - Max auto-aim distance, from '1024' to '8192'.
    - Max BFG spray/tracer distance, from '1024' to '2048'.
  • Loading branch information
BodbDearg committed Aug 29, 2021
1 parent 5bc0eba commit f372030
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 26 deletions.
2 changes: 1 addition & 1 deletion game/Doom/Base/i_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ texture_t gTex_CONNECT;

// The current network protocol version.
// Should be incremented whenever the data format being transmitted changes, or when updates might cause differences in game behavior.
static constexpr int32_t NET_PROTOCOL_VERSION = 12;
static constexpr int32_t NET_PROTOCOL_VERSION = 13;

// Game ids for networking
static constexpr int32_t NET_GAMEID_DOOM = 0xAA11AA22;
Expand Down
22 changes: 13 additions & 9 deletions game/Doom/Game/p_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ static constexpr fixed_t MAXRADIUS = 32 * FRACUNIT;
static constexpr fixed_t ONFLOORZ = INT32_MIN;
static constexpr fixed_t ONCEILINGZ = INT32_MAX;

static constexpr int32_t MAXHEALTH = 100; // Default maximum health for the player
static constexpr fixed_t VIEWHEIGHT = 41 * FRACUNIT; // Height of the view off the ground
static constexpr fixed_t GRAVITY = 4 * FRACUNIT; // Gravity strength: same as Jaguar Doom
static constexpr fixed_t MELEERANGE = 70 * FRACUNIT; // Range for melee attacks
static constexpr fixed_t USERANGE = 70 * FRACUNIT; // Range for using things
static constexpr fixed_t MISSILERANGE = 2048 * FRACUNIT; // Maximum range for missile attacks
static constexpr fixed_t MAXMOVE = 16 * FRACUNIT; // Maximum movement amount in one go: larger moves must be split up unto multiple smaller moves
static constexpr fixed_t FLOATSPEED = 8 * FRACUNIT; // Speed of floating up or down to meet the player for floating monsters
static constexpr int32_t BASETHRESHOLD = 100; // How long for an AI to follow a target for (tics) - was about 3 seconds on PC, much longer on PSX. Conversion bug?
static constexpr int32_t MAXHEALTH = 100; // Default maximum health for the player
static constexpr fixed_t VIEWHEIGHT = 41 * FRACUNIT; // Height of the view off the ground
static constexpr fixed_t GRAVITY = 4 * FRACUNIT; // Gravity strength: same as Jaguar Doom
static constexpr fixed_t MELEERANGE = 70 * FRACUNIT; // Range for melee attacks
static constexpr fixed_t USERANGE = 70 * FRACUNIT; // Range for using things
static constexpr fixed_t MISSILERANGE = 2048 * FRACUNIT; // Maximum range for most hitscan attacks
static constexpr fixed_t MAXMOVE = 16 * FRACUNIT; // Maximum movement amount in one go: larger moves must be split up unto multiple smaller moves
static constexpr fixed_t FLOATSPEED = 8 * FRACUNIT; // Speed of floating up or down to meet the player for floating monsters
static constexpr int32_t BASETHRESHOLD = 100; // How long for an AI to follow a target for (tics) - was about 3 seconds on PC, much longer on PSX. Conversion bug?

#if PSYDOOM_MODS
static constexpr fixed_t EXT_MISSILERANGE = 8192 * FRACUNIT; // PsyDoom: extended hitscan attack and auto-aim range for the player (only)
#endif

// Enum representing a movement direction (for AI actors)
enum dirtype_t : int32_t {
Expand Down
13 changes: 10 additions & 3 deletions game/Doom/Game/p_mobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,20 +619,27 @@ mobj_t* P_SpawnMissile(mobj_t& source, mobj_t& dest, const mobjtype_t type) noex
// Spawn a missile for the player and try to do a little auto-aim
//------------------------------------------------------------------------------------------------------------------------------------------
void P_SpawnPlayerMissile(mobj_t& source, const mobjtype_t missileType) noexcept {
// PsyDoom: aim range can be further extended
#if PSYDOOM_MODS
const fixed_t aimRange = (Game::gSettings.bUseExtendedPlayerShootRange) ? EXT_MISSILERANGE : 1024 * FRACUNIT;
#else
const fixed_t aimRange = 1024 * FRACUNIT;
#endif

// Figure out the vertical aim slope.
// If we don't hit a thing then do a bit of auto-aim and wiggle the aim a bit to try and hit something.
angle_t aimAngle = source.angle;
fixed_t aimSlope = P_AimLineAttack(source, aimAngle, 1024 * FRACUNIT);
fixed_t aimSlope = P_AimLineAttack(source, aimAngle, aimRange);

if (!gpLineTarget) {
constexpr angle_t AIM_WIGGLE = ANG45 / 8;

aimAngle = source.angle + AIM_WIGGLE;
aimSlope = P_AimLineAttack(source, aimAngle, 1024 * FRACUNIT);
aimSlope = P_AimLineAttack(source, aimAngle, aimRange);

if (!gpLineTarget) {
aimAngle = source.angle - AIM_WIGGLE;
aimSlope = P_AimLineAttack(source, aimAngle, 1024 * FRACUNIT);
aimSlope = P_AimLineAttack(source, aimAngle, aimRange);

// If we still haven't hit a thing after all these attempts then just shoot dead level ahead
if (!gpLineTarget) {
Expand Down
51 changes: 43 additions & 8 deletions game/Doom/Game/p_pspr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,15 +586,22 @@ void A_FirePlasma(player_t& player, [[maybe_unused]] pspdef_t& sprite) noexcept
// Saves the resulting vertical slope to 'gBulletSlope'.
//------------------------------------------------------------------------------------------------------------------------------------------
static void P_BulletSlope(mobj_t& mobj) noexcept {
gBulletSlope = P_AimLineAttack(mobj, mobj.angle, 1024 * FRACUNIT);
// PsyDoom: aim range can be further extended
#if PSYDOOM_MODS
const fixed_t aimRange = (Game::gSettings.bUseExtendedPlayerShootRange) ? EXT_MISSILERANGE : 1024 * FRACUNIT;
#else
const fixed_t aimRange = 1024 * FRACUNIT;
#endif

gBulletSlope = P_AimLineAttack(mobj, mobj.angle, aimRange);

constexpr angle_t AIM_WIGGLE = ANG45 / 8;

if (!gpLineTarget) {
gBulletSlope = P_AimLineAttack(mobj, mobj.angle + AIM_WIGGLE, 1024 * FRACUNIT);
gBulletSlope = P_AimLineAttack(mobj, mobj.angle + AIM_WIGGLE, aimRange);

if (!gpLineTarget) {
gBulletSlope = P_AimLineAttack(mobj, mobj.angle - AIM_WIGGLE, 1024 * FRACUNIT);
gBulletSlope = P_AimLineAttack(mobj, mobj.angle - AIM_WIGGLE, aimRange);
}
}
}
Expand All @@ -613,7 +620,14 @@ static void P_GunShot(mobj_t& mobj, const bool bAccurate) noexcept {
angle += ((angle_t) P_SubRandom()) << 18;
}

P_LineAttack(mobj, angle, MISSILERANGE, INT32_MAX, damage);
// PsyDoom: shoot range can be further extended
#if PSYDOOM_MODS
const fixed_t attackRange = (Game::gSettings.bUseExtendedPlayerShootRange) ? EXT_MISSILERANGE : MISSILERANGE;
#else
const fixed_t attackRange = MISSILERANGE;
#endif

P_LineAttack(mobj, angle, attackRange, INT32_MAX, damage);
}

//------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -646,8 +660,15 @@ void A_FireShotgun(player_t& player, [[maybe_unused]] pspdef_t& sprite) noexcept
// Do muzzle flash
P_SetPsprite(player, ps_flash, weaponInfo.flashstate);

// PsyDoom: shoot range can be further extended
#if PSYDOOM_MODS
const fixed_t attackRange = (Game::gSettings.bUseExtendedPlayerShootRange) ? EXT_MISSILERANGE : MISSILERANGE;
#else
const fixed_t attackRange = MISSILERANGE;
#endif

// Decide on vertical aim and fire the 7 shotgun pellets (4-16 damage each)
const fixed_t aimZSlope = P_AimLineAttack(playerMobj, playerMobj.angle, MISSILERANGE);
const fixed_t aimZSlope = P_AimLineAttack(playerMobj, playerMobj.angle, attackRange);

for (int32_t pelletIdx = 0; pelletIdx < 7; ++pelletIdx) {
// IMPORTANT: the cast to 'angle_t' (unsigned integer) before shifting is a *MUST* here for correct demo syncing!
Expand All @@ -656,7 +677,7 @@ void A_FireShotgun(player_t& player, [[maybe_unused]] pspdef_t& sprite) noexcept
const angle_t angleVariance = ((angle_t) P_SubRandom()) << 18;
const angle_t angle = playerMobj.angle + angleVariance;

P_LineAttack(playerMobj, angle, MISSILERANGE, aimZSlope, damage);
P_LineAttack(playerMobj, angle, attackRange, aimZSlope, damage);
}
}

Expand All @@ -678,6 +699,13 @@ void A_FireShotgun2(player_t& player, [[maybe_unused]] pspdef_t& sprite) noexcep
// Figure out the vertical aim slope
P_BulletSlope(playerMobj);

// PsyDoom: shoot range can be further extended
#if PSYDOOM_MODS
const fixed_t attackRange = (Game::gSettings.bUseExtendedPlayerShootRange) ? EXT_MISSILERANGE : MISSILERANGE;
#else
const fixed_t attackRange = MISSILERANGE;
#endif

// Fire all of the 20 shotgun pellets (5-15 damage each)
for (int32_t pelletIdx = 0; pelletIdx < 20; ++pelletIdx) {
// IMPORTANT: the cast to 'angle_t' (unsigned integer) before shifting is a *MUST* here for correct demo syncing!
Expand All @@ -687,7 +715,7 @@ void A_FireShotgun2(player_t& player, [[maybe_unused]] pspdef_t& sprite) noexcep
const angle_t angle = playerMobj.angle + angleVariance;
const fixed_t aimSlope = gBulletSlope + P_SubRandom() * 32;

P_LineAttack(playerMobj, angle, MISSILERANGE, aimSlope, damage);
P_LineAttack(playerMobj, angle, attackRange, aimSlope, damage);
}
}

Expand Down Expand Up @@ -745,11 +773,18 @@ void A_BFGSpray(mobj_t& mobj) noexcept {
ASSERT(mobj.target);
mobj_t& target = *mobj.target;

// PsyDoom: spray/tracer range can be further extended to '2048' units
#if PSYDOOM_MODS
const fixed_t attackRange = (Game::gSettings.bUseExtendedPlayerShootRange) ? 2048 * FRACUNIT : 1024 * FRACUNIT;
#else
const fixed_t attackRange = 1024 * FRACUNIT;
#endif

// Spawn explosions from -45 degrees relative to the player to +45 degrees
constexpr int32_t NUM_EXPLOSIONS = 40;

for (int32_t explosionIdx = 0; explosionIdx < NUM_EXPLOSIONS; ++explosionIdx) {
P_AimLineAttack(target, mobj.angle - ANG45 + (ANG90 / NUM_EXPLOSIONS) * explosionIdx, 1024 * FRACUNIT);
P_AimLineAttack(target, mobj.angle - ANG45 + (ANG90 / NUM_EXPLOSIONS) * explosionIdx, attackRange);
mobj_t* const pLineTarget = gpLineTarget;

if (!pLineTarget)
Expand Down
15 changes: 15 additions & 0 deletions game/PsyDoom/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ bool gbEnableSinglePlayerLevelTimer;
int32_t gUsePalTimings;
bool gbUseDemoTimings;
bool gbUseMoveInputLatencyTweak;
bool gbUseExtendedPlayerShootRange;
bool gbUseItemPickupFix;
bool gbUsePlayerRocketBlastFix;
bool gbUseSuperShotgunDelayTweak;
Expand Down Expand Up @@ -558,6 +559,20 @@ static const ConfigFieldHandler GAME_CFG_INI_HANDLERS[] = {
[](const IniUtils::Entry& iniEntry) { gbUseMoveInputLatencyTweak = iniEntry.getBoolValue(true); },
[]() { gbUseMoveInputLatencyTweak = true; }
},
{
"UseExtendedPlayerShootRange",
"#---------------------------------------------------------------------------------------------------\n"
"# If enabled, extends the following player attack limits:\n"
"# - Max shoot/hitscan distance, from '2048' to '8192'.\n"
"# - Max auto-aim distance, from '1024' to '8192'.\n"
"# - Max BFG spray/tracer distance, from '1024' to '2048'.\n"
"#\n"
"# Extending these limits can make combat on large open maps less frustrating.\n"
"#---------------------------------------------------------------------------------------------------",
"1", "\n",
[](const IniUtils::Entry& iniEntry) { gbUseExtendedPlayerShootRange = iniEntry.getBoolValue(true); },
[]() { gbUseExtendedPlayerShootRange = true; }
},
{
"UseItemPickupFix",
"#---------------------------------------------------------------------------------------------------\n"
Expand Down
1 change: 1 addition & 0 deletions game/PsyDoom/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern bool gbEnableSinglePlayerLevelTimer;
extern int32_t gUsePalTimings;
extern bool gbUseDemoTimings;
extern bool gbUseMoveInputLatencyTweak;
extern bool gbUseExtendedPlayerShootRange;
extern bool gbUseItemPickupFix;
extern bool gbUsePlayerRocketBlastFix;
extern bool gbUseSuperShotgunDelayTweak;
Expand Down
12 changes: 7 additions & 5 deletions game/PsyDoom/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ void getUserGameSettings(GameSettings& settings) noexcept {
settings.bUsePalTimings = (Config::gUsePalTimings != 0);
}

settings.bUseDemoTimings = Config::gbUseDemoTimings;
settings.bUsePlayerRocketBlastFix = Config::gbUsePlayerRocketBlastFix;
settings.bUseSuperShotgunDelayTweak = Config::gbUseSuperShotgunDelayTweak;
settings.bUseMoveInputLatencyTweak = Config::gbUseMoveInputLatencyTweak;
settings.bUseItemPickupFix = Config::gbUseItemPickupFix;
settings.bUseDemoTimings = Config::gbUseDemoTimings;
settings.bUseExtendedPlayerShootRange = Config::gbUseExtendedPlayerShootRange;
settings.bUsePlayerRocketBlastFix = Config::gbUsePlayerRocketBlastFix;
settings.bUseSuperShotgunDelayTweak = Config::gbUseSuperShotgunDelayTweak;
settings.bUseMoveInputLatencyTweak = Config::gbUseMoveInputLatencyTweak;
settings.bUseItemPickupFix = Config::gbUseItemPickupFix;

if (Config::gUseFinalDoomPlayerMovement < 0) {
settings.bUseFinalDoomPlayerMovement = (bFinalDoomDefaultRules) ? true : false; // Auto decide based on the game
Expand Down Expand Up @@ -150,6 +151,7 @@ void getClassicDemoGameSettings(GameSettings& settings) noexcept {
settings = {};
settings.bUsePalTimings = (gGameVariant == GameVariant::PAL);
settings.bUseDemoTimings = true;
settings.bUseExtendedPlayerShootRange = false;
settings.bUsePlayerRocketBlastFix = false;
settings.bUseSuperShotgunDelayTweak = false;
settings.bUseMoveInputLatencyTweak = false;
Expand Down
1 change: 1 addition & 0 deletions game/PsyDoom/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum class GameVariant : int32_t {
struct GameSettings {
uint8_t bUsePalTimings; // Use 50 Hz vblanks and other various timing adjustments for the PAL version of the game?
uint8_t bUseDemoTimings; // Force player logic to run at a consistent, but slower rate used by demos? (15 Hz for NTSC)
uint8_t bUseExtendedPlayerShootRange; // Extend player max shoot distance from '2048' to '8192' and auto aim distance from '1024' to '8192'? (similar range to ZDoom)
uint8_t bUsePlayerRocketBlastFix; // Apply the fix for the player sometimes not receiving splash damage from rocket blasts?
uint8_t bUseSuperShotgunDelayTweak; // Whether to apply the gameplay tweak that reduces the initial firing delay of the super shotgun
uint8_t bUseMoveInputLatencyTweak; // Use a tweak to player movement which tries to reduce input latency? This affects movement slightly.
Expand Down

0 comments on commit f372030

Please sign in to comment.