From 30a482e80e3228728f7d0559a7f9ced8956966a6 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Thu, 8 Sep 2022 13:59:18 -0700 Subject: [PATCH] NSVehicle: add two new overridable methods. (bool)PreventPlayerMovement and (bool)PreventPlayerFire --- base/src/shared/input.qc | 9 +++++++++ src/shared/NSVehicle.h | 2 ++ src/shared/NSVehicle.qc | 12 ++++++++++++ src/shared/player_pmove.qc | 12 +++++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/base/src/shared/input.qc b/base/src/shared/input.qc index 49dfa80a..670d62f8 100644 --- a/base/src/shared/input.qc +++ b/base/src/shared/input.qc @@ -41,6 +41,15 @@ Game_Input(player pl) return; } + NSVehicle veh = (NSVehicle)pl.vehicle; + bool canfire = true; + if (veh) + if (veh.PreventPlayerFire() == true) + canfire = false; + + if (canfire == false) + return; + if (input_buttons & INPUT_BUTTON0) Weapons_Primary(pl); else if (input_buttons & INPUT_BUTTON4) diff --git a/src/shared/NSVehicle.h b/src/shared/NSVehicle.h index 73297789..750cd2b7 100644 --- a/src/shared/NSVehicle.h +++ b/src/shared/NSVehicle.h @@ -63,6 +63,8 @@ class NSVehicle:NSSurfacePropEntity virtual float(void) DriverAnimation; virtual bool(void) CanDriverCrouch; + virtual bool(void) PreventPlayerMovement; + virtual bool(void) PreventPlayerFire; }; enumflags diff --git a/src/shared/NSVehicle.qc b/src/shared/NSVehicle.qc index fe4817a7..d9489a1c 100644 --- a/src/shared/NSVehicle.qc +++ b/src/shared/NSVehicle.qc @@ -77,6 +77,18 @@ NSVehicle::CanDriverCrouch(void) return (false); } +bool +NSVehicle::PreventPlayerMovement(void) +{ + return (true); +} + +bool +NSVehicle::PreventPlayerFire(void) +{ + return (true); +} + float NSVehicle::DriverAnimation(void) { diff --git a/src/shared/player_pmove.qc b/src/shared/player_pmove.qc index 48b4ad88..51b784b7 100644 --- a/src/shared/player_pmove.qc +++ b/src/shared/player_pmove.qc @@ -308,6 +308,7 @@ void NSClientPlayer::Physics_InputPreMove(void) { NSVehicle veh = (NSVehicle)vehicle; + bool canmove = true; /* when pressing the 'use' button, we also walk slower for precision */ if (input_buttons & INPUT_BUTTON5) { @@ -327,7 +328,16 @@ NSClientPlayer::Physics_InputPreMove(void) } } - if (flags & FL_FROZEN || movetype == MOVETYPE_NONE) { + /* find all the valid ways to freeze a player... */ + if (veh) + if (veh.PreventPlayerMovement() == true) + canmove = false; + + if (flags & FL_FROZEN || movetype == MOVETYPE_NONE) + canmove = false; + + /* freeze in place */ + if (canmove == false) { input_movevalues = [0,0,0]; input_buttons &= ~INPUT_BUTTON2; }