Merge branch 'modify-throw-threshold' into 'master'

Make ticcmd throwdir -1, 0, or 1, add deadzone

See merge request KartKrew/Kart!1802
This commit is contained in:
AJ Martinez 2024-01-13 00:39:07 +00:00
commit 3b610b140c
6 changed files with 36 additions and 33 deletions

View file

@ -4799,7 +4799,7 @@ static void FuzzTiccmd(ticcmd_t* target)
{ {
target->forwardmove = P_RandomRange(PR_FUZZ, -MAXPLMOVE, MAXPLMOVE); target->forwardmove = P_RandomRange(PR_FUZZ, -MAXPLMOVE, MAXPLMOVE);
target->turning = P_RandomRange(PR_FUZZ, -KART_FULLTURN, KART_FULLTURN); target->turning = P_RandomRange(PR_FUZZ, -KART_FULLTURN, KART_FULLTURN);
target->throwdir = P_RandomRange(PR_FUZZ, -KART_FULLTURN, KART_FULLTURN); target->throwdir = P_RandomRange(PR_FUZZ, -1, 1);
target->buttons = P_RandomRange(PR_FUZZ, 0, 255); target->buttons = P_RandomRange(PR_FUZZ, 0, 255);
// Make fuzzed players more likely to do impactful things // Make fuzzed players more likely to do impactful things

View file

@ -164,7 +164,7 @@ class TiccmdBuilder
cmd->forwardmove = clamp(cmd->forwardmove, MAXPLMOVE); cmd->forwardmove = clamp(cmd->forwardmove, MAXPLMOVE);
cmd->turning = clamp(cmd->turning, KART_FULLTURN); cmd->turning = clamp(cmd->turning, KART_FULLTURN);
cmd->throwdir = clamp(cmd->throwdir, KART_FULLTURN); cmd->throwdir = clamp(cmd->throwdir, 1);
// Send leveltime when this tic was generated to the server for control lag calculations. // Send leveltime when this tic was generated to the server for control lag calculations.
// Only do this when in a level. Also do this after the hook, so that it can't overwrite this. // Only do this when in a level. Also do this after the hook, so that it can't overwrite this.
@ -338,9 +338,12 @@ class TiccmdBuilder
} }
// But forward/backward IS used for aiming. // But forward/backward IS used for aiming.
if (joystickvector.yaxis != 0) // throwdir > 0 throws forward, throwdir < 0 throws backward
// but we always use -1, 0 or 1 for consistency here.
// this allows the throw deadzone to be adjusted in the future without breaking demos
if (std::abs(joystickvector.yaxis) > JOYAXISRANGE / 2)
{ {
cmd->throwdir -= (joystickvector.yaxis * KART_FULLTURN) / JOYAXISRANGE; cmd->throwdir = -std::clamp(joystickvector.yaxis, -1, 1);
} }
} }

View file

@ -1206,10 +1206,10 @@ static void K_BotTrick(const player_t *player, ticcmd_t *cmd, const botcontrolle
cmd->turning = -KART_FULLTURN; cmd->turning = -KART_FULLTURN;
break; break;
case TMBOTTR_UP: case TMBOTTR_UP:
cmd->throwdir = KART_FULLTURN; cmd->throwdir = 1;
break; break;
case TMBOTTR_DOWN: case TMBOTTR_DOWN:
cmd->throwdir = -KART_FULLTURN; cmd->throwdir = -1;
break; break;
} }
} }

View file

@ -366,7 +366,7 @@ static boolean K_BotGenericPressItem(const player_t *player, ticcmd_t *cmd, SINT
return false; return false;
} }
cmd->throwdir = KART_FULLTURN * dir; cmd->throwdir = std::clamp(static_cast<int>(dir), -1, 1);
cmd->buttons |= BT_ATTACK; cmd->buttons |= BT_ATTACK;
//player->botvars.itemconfirm = 0; //player->botvars.itemconfirm = 0;
return true; return true;
@ -1023,7 +1023,7 @@ static void K_BotItemBallhog(const player_t *player, ticcmd_t *cmd)
if (hold == true) if (hold == true)
{ {
cmd->throwdir = KART_FULLTURN * throwdir; cmd->throwdir = std::clamp(static_cast<int>(throwdir), -1, 1);
cmd->buttons |= BT_ATTACK; cmd->buttons |= BT_ATTACK;
} }
} }

View file

@ -12608,11 +12608,12 @@ void K_MoveKartPlayer(player_t *player, boolean onground)
const angle_t angledelta = FixedAngle(36*FRACUNIT); const angle_t angledelta = FixedAngle(36*FRACUNIT);
angle_t baseangle = player->mo->angle + angledelta/2; angle_t baseangle = player->mo->angle + angledelta/2;
INT16 aimingcompare = abs(cmd->throwdir) - abs(cmd->turning); boolean throwing = cmd->throwdir != 0;
INT16 turnmagnitude = abs(cmd->turning);
// Uses cmd->turning over steering intentionally. // Uses cmd->turning over steering intentionally.
#define TRICKTHRESHOLD (KART_FULLTURN/4) #define TRICKTHRESHOLD (KART_FULLTURN/4)
if (aimingcompare < -TRICKTHRESHOLD) // side trick if (abs(turnmagnitude) > TRICKTHRESHOLD && !throwing) // side trick
{ {
S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2); S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2);
player->dotrickfx = true; player->dotrickfx = true;
@ -12651,7 +12652,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground)
P_SetPlayerMobjState(player->mo, S_KART_FAST_LOOK_R); P_SetPlayerMobjState(player->mo, S_KART_FAST_LOOK_R);
} }
} }
else if (aimingcompare > TRICKTHRESHOLD) // forward/back trick else if (abs(turnmagnitude) <= TRICKTHRESHOLD && throwing) // forward/back trick
{ {
S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2); S_StartSoundAtVolume(player->mo, sfx_trick0, 255/2);
player->dotrickfx = true; player->dotrickfx = true;

View file

@ -4131,12 +4131,11 @@ void P_PlayerThink(player_t *player)
// Save the dir the player is holding // Save the dir the player is holding
// to allow items to be thrown forward or backward. // to allow items to be thrown forward or backward.
{ {
const INT16 threshold = 0; //(KART_FULLTURN / 2); if (cmd->throwdir > 0)
if (cmd->throwdir > threshold)
{ {
player->throwdir = 1; player->throwdir = 1;
} }
else if (cmd->throwdir < -threshold) else if (cmd->throwdir < 0)
{ {
player->throwdir = -1; player->throwdir = -1;
} }