2020-08-16 14:00:40 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 1997, 2005 - 3D Realms Entertainment
|
|
|
|
|
|
|
|
This file is part of Shadow Warrior version 1.2
|
|
|
|
|
|
|
|
Shadow Warrior is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
Original Source: 1997 - Frank Maddin and Jim Norwood
|
|
|
|
Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "ns.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "network.h"
|
|
|
|
#include "gamecontrol.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "menu.h"
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_SW_NS
|
|
|
|
|
2020-09-07 10:20:41 +00:00
|
|
|
void DoPlayerHorizon(PLAYERp pp, fixed_t const q16horz, double const scaleAdjust);
|
2020-09-07 20:22:47 +00:00
|
|
|
void DoPlayerTurn(PLAYERp pp, fixed_t const q16avel, double const scaleAdjust);
|
2020-09-08 11:54:48 +00:00
|
|
|
void DoPlayerTurnVehicle(PLAYERp pp, fixed_t q16avel, int z, int floor_dist);
|
2020-09-09 13:00:43 +00:00
|
|
|
void DoPlayerTurnTurret(PLAYERp pp, fixed_t q16avel);
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-06 10:12:39 +00:00
|
|
|
static InputPacket loc;
|
2020-09-06 11:03:27 +00:00
|
|
|
static int32_t turnheldtime;
|
2020-09-02 18:56:09 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
InitNetVars(void)
|
|
|
|
{
|
|
|
|
loc = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InitTimingVars(void)
|
|
|
|
{
|
|
|
|
PlayClock = 0;
|
|
|
|
randomseed = 17L;
|
|
|
|
MoveSkip8 = 2;
|
|
|
|
MoveSkip2 = 0;
|
|
|
|
MoveSkip4 = 1; // start slightly offset so these
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-06 11:03:27 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TURBOTURNTIME = (120 / 8),
|
|
|
|
NORMALTURN = (12 + 6),
|
|
|
|
RUNTURN = (28),
|
|
|
|
PREAMBLETURN = 3,
|
|
|
|
NORMALKEYMOVE = 35,
|
2020-09-06 11:46:18 +00:00
|
|
|
MAXFVEL = ((NORMALKEYMOVE * 2) + 10),
|
2020-09-06 11:03:27 +00:00
|
|
|
MAXSVEL = ((NORMALKEYMOVE * 2) + 10),
|
|
|
|
MAXANGVEL = 100,
|
|
|
|
MAXHORIZVEL = 128
|
|
|
|
};
|
|
|
|
|
2020-09-06 10:52:58 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// handles the input bits
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static void processInputBits(PLAYERp const pp, ControlInfo* const hidInput, bool* mouseaim)
|
|
|
|
{
|
|
|
|
ApplyGlobalInput(loc, hidInput);
|
|
|
|
*mouseaim = !(loc.actions & SB_AIMMODE);
|
|
|
|
|
|
|
|
if (!CommEnabled)
|
|
|
|
{
|
|
|
|
// Go back to the source to set this - the old code here was catastrophically bad.
|
|
|
|
// this needs to be fixed properly - as it is this can never be compatible with demo playback.
|
|
|
|
|
|
|
|
if (mouseaim)
|
|
|
|
SET(Player[myconnectindex].Flags, PF_MOUSE_AIMING_ON);
|
|
|
|
else
|
|
|
|
RESET(Player[myconnectindex].Flags, PF_MOUSE_AIMING_ON);
|
|
|
|
|
|
|
|
if (cl_autoaim)
|
|
|
|
SET(Player[myconnectindex].Flags, PF_AUTO_AIM);
|
|
|
|
else
|
|
|
|
RESET(Player[myconnectindex].Flags, PF_AUTO_AIM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch))
|
|
|
|
{
|
|
|
|
// this shares a bit with another function so cannot be in the common code.
|
|
|
|
loc.actions |= SB_CROUCH_LOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 10:49:05 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// handles movement
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static void processWeapon(PLAYERp const pp)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
2020-09-06 10:49:05 +00:00
|
|
|
USERp u = User[pp->PlayerSprite];
|
2020-08-16 14:00:40 +00:00
|
|
|
int i;
|
2020-09-06 10:49:05 +00:00
|
|
|
|
|
|
|
if (loc.getNewWeapon() == WeaponSel_Next)
|
|
|
|
{
|
|
|
|
short next_weapon = u->WeaponNum + 1;
|
|
|
|
short start_weapon;
|
|
|
|
|
|
|
|
start_weapon = u->WeaponNum + 1;
|
|
|
|
|
|
|
|
if (u->WeaponNum == WPN_SWORD)
|
|
|
|
start_weapon = WPN_STAR;
|
|
|
|
|
|
|
|
if (u->WeaponNum == WPN_FIST)
|
|
|
|
{
|
|
|
|
next_weapon = 14;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
next_weapon = -1;
|
2020-09-09 17:52:52 +00:00
|
|
|
for (i = start_weapon; true; i++)
|
2020-09-06 10:49:05 +00:00
|
|
|
{
|
|
|
|
if (i >= MAX_WEAPONS_KEYS)
|
|
|
|
{
|
|
|
|
next_weapon = 13;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TEST(pp->WpnFlags, BIT(i)) && pp->WpnAmmo[i])
|
|
|
|
{
|
|
|
|
next_weapon = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loc.setNewWeapon(next_weapon + 1);
|
|
|
|
}
|
|
|
|
else if (loc.getNewWeapon() == WeaponSel_Prev)
|
|
|
|
{
|
|
|
|
USERp u = User[pp->PlayerSprite];
|
|
|
|
short prev_weapon = u->WeaponNum - 1;
|
|
|
|
short start_weapon;
|
|
|
|
|
|
|
|
start_weapon = u->WeaponNum - 1;
|
|
|
|
|
|
|
|
if (u->WeaponNum == WPN_SWORD)
|
|
|
|
{
|
|
|
|
prev_weapon = 13;
|
|
|
|
}
|
|
|
|
else if (u->WeaponNum == WPN_STAR)
|
|
|
|
{
|
|
|
|
prev_weapon = 14;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev_weapon = -1;
|
2020-09-09 17:52:52 +00:00
|
|
|
for (i = start_weapon; true; i--)
|
2020-09-06 10:49:05 +00:00
|
|
|
{
|
|
|
|
if (i <= -1)
|
|
|
|
i = WPN_HEART;
|
|
|
|
|
|
|
|
if (TEST(pp->WpnFlags, BIT(i)) && pp->WpnAmmo[i])
|
|
|
|
{
|
|
|
|
prev_weapon = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loc.setNewWeapon(prev_weapon + 1);
|
|
|
|
}
|
|
|
|
else if (loc.getNewWeapon() == WeaponSel_Alt)
|
|
|
|
{
|
|
|
|
USERp u = User[pp->PlayerSprite];
|
|
|
|
short const which_weapon = u->WeaponNum + 1;
|
|
|
|
loc.setNewWeapon(which_weapon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 11:03:27 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// handles movement
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-14 19:25:53 +00:00
|
|
|
static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool const mouseaim, bool allowkeys)
|
2020-09-06 11:03:27 +00:00
|
|
|
{
|
2020-09-06 11:30:47 +00:00
|
|
|
double const scaleAdjust = InputScale();
|
2020-09-06 11:46:18 +00:00
|
|
|
bool const strafeKey = buttonMap.ButtonDown(gamefunc_Strafe) && !pp->sop;
|
|
|
|
int32_t turnamount, keymove;
|
|
|
|
int32_t fvel = 0, svel = 0;
|
|
|
|
fixed_t q16avel = 0, q16horz = 0;
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-06 10:12:39 +00:00
|
|
|
if (loc.actions & SB_RUN)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
2020-09-06 11:46:18 +00:00
|
|
|
turnamount = pp->sop_control ? RUNTURN * 3 : RUNTURN;
|
2020-08-16 14:00:40 +00:00
|
|
|
keymove = NORMALKEYMOVE << 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-06 11:46:18 +00:00
|
|
|
turnamount = pp->sop_control ? NORMALTURN * 3 : NORMALTURN;
|
2020-08-16 14:00:40 +00:00
|
|
|
keymove = NORMALKEYMOVE;
|
|
|
|
}
|
|
|
|
|
2020-09-06 11:46:18 +00:00
|
|
|
if (strafeKey)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
2020-09-14 09:29:12 +00:00
|
|
|
svel -= xs_CRoundToInt((hidInput->mousex * 4.) + (scaleAdjust * (hidInput->dyaw * keymove)));
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-07 10:25:26 +00:00
|
|
|
q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw));
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mouseaim)
|
2020-09-07 10:25:26 +00:00
|
|
|
q16horz -= FloatToFixed(hidInput->mousey);
|
2020-08-16 14:00:40 +00:00
|
|
|
else
|
2020-09-07 10:25:26 +00:00
|
|
|
fvel -= xs_CRoundToInt(hidInput->mousey * 8.);
|
2020-08-16 14:00:40 +00:00
|
|
|
|
|
|
|
if (in_mouseflip)
|
2020-08-26 22:00:50 +00:00
|
|
|
q16horz = -q16horz;
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-07 10:25:26 +00:00
|
|
|
q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch);
|
2020-09-14 09:29:12 +00:00
|
|
|
svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keymove));
|
|
|
|
fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keymove));
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-14 19:25:53 +00:00
|
|
|
if (strafeKey || pp->sop)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && pp->sop))
|
|
|
|
{
|
|
|
|
turnheldtime += synctics;
|
2020-09-06 11:46:18 +00:00
|
|
|
q16avel -= FloatToFixed(scaleAdjust * (turnheldtime >= TURBOTURNTIME ? turnamount : PREAMBLETURN));
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
|
|
|
else if (buttonMap.ButtonDown(gamefunc_Turn_Right) || (buttonMap.ButtonDown(gamefunc_Strafe_Right) && pp->sop))
|
|
|
|
{
|
|
|
|
turnheldtime += synctics;
|
2020-09-06 11:46:18 +00:00
|
|
|
q16avel += FloatToFixed(scaleAdjust * (turnheldtime >= TURBOTURNTIME ? turnamount : PREAMBLETURN));
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
turnheldtime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:25:53 +00:00
|
|
|
if (allowkeys)
|
2020-09-14 08:54:03 +00:00
|
|
|
{
|
2020-09-14 19:25:53 +00:00
|
|
|
if (!pp->sop)
|
|
|
|
{
|
|
|
|
if (strafeKey)
|
|
|
|
{
|
|
|
|
if (abs(svel) < keymove)
|
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
|
|
|
svel += keymove;
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
|
|
|
svel -= keymove;
|
|
|
|
}
|
|
|
|
}
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-14 19:25:53 +00:00
|
|
|
if (abs(loc.svel) < keymove)
|
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Left))
|
|
|
|
svel += keymove;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Right))
|
|
|
|
svel -= keymove;
|
|
|
|
}
|
|
|
|
}
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-14 19:25:53 +00:00
|
|
|
if (abs(loc.fvel) < keymove)
|
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
|
|
|
fvel += keymove;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
|
|
|
fvel -= keymove;
|
|
|
|
}
|
2020-09-14 08:54:03 +00:00
|
|
|
}
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-06 11:46:18 +00:00
|
|
|
if (!cl_syncinput)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
|
|
|
if (TEST(pp->Flags2, PF2_INPUT_CAN_AIM))
|
2020-09-09 11:29:03 +00:00
|
|
|
{
|
2020-09-07 11:50:43 +00:00
|
|
|
DoPlayerHorizon(pp, q16horz, scaleAdjust);
|
2020-09-09 11:29:03 +00:00
|
|
|
}
|
2020-09-07 20:22:47 +00:00
|
|
|
|
2020-09-09 12:04:46 +00:00
|
|
|
if (pp->horizTarget)
|
|
|
|
{
|
|
|
|
fixed_t horizDelta = pp->horizTarget - pp->q16horiz;
|
|
|
|
pp->q16horiz += xs_CRoundToInt(scaleAdjust * horizDelta);
|
|
|
|
|
2020-09-10 10:26:19 +00:00
|
|
|
if (abs(pp->q16horiz - pp->horizTarget) < FRACUNIT)
|
2020-09-09 12:04:46 +00:00
|
|
|
{
|
|
|
|
pp->q16horiz = pp->horizTarget;
|
|
|
|
pp->horizTarget = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pp->horizAdjust)
|
2020-09-09 11:29:03 +00:00
|
|
|
{
|
2020-09-07 20:50:38 +00:00
|
|
|
pp->q16horiz += FloatToFixed(scaleAdjust * pp->horizAdjust);
|
2020-09-09 11:29:03 +00:00
|
|
|
}
|
2020-09-07 20:50:38 +00:00
|
|
|
|
2020-09-07 20:22:47 +00:00
|
|
|
if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_GENERAL))
|
2020-09-09 11:29:03 +00:00
|
|
|
{
|
2020-09-07 20:22:47 +00:00
|
|
|
DoPlayerTurn(pp, q16avel, scaleAdjust);
|
2020-09-09 11:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pp->angTarget)
|
|
|
|
{
|
|
|
|
fixed_t angDelta = GetDeltaQ16Angle(pp->angTarget, pp->q16ang);
|
|
|
|
pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * angDelta));
|
2020-09-07 20:22:47 +00:00
|
|
|
|
2020-09-10 10:26:19 +00:00
|
|
|
if (abs(pp->q16ang - pp->angTarget) < FRACUNIT)
|
2020-09-09 11:29:03 +00:00
|
|
|
{
|
|
|
|
pp->q16ang = pp->angTarget;
|
|
|
|
pp->angTarget = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pp->angAdjust)
|
|
|
|
{
|
2020-09-08 14:34:51 +00:00
|
|
|
pp->q16ang = (pp->q16ang + FloatToFixed(scaleAdjust * pp->angAdjust)) & 0x7FFFFFF;
|
2020-09-09 11:29:03 +00:00
|
|
|
}
|
2020-09-07 20:22:47 +00:00
|
|
|
|
2020-09-08 11:54:48 +00:00
|
|
|
if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_VEHICLE))
|
2020-09-09 11:29:03 +00:00
|
|
|
{
|
2020-09-08 11:54:48 +00:00
|
|
|
DoPlayerTurnVehicle(pp, q16avel, pp->posz + Z(10), labs(pp->posz + Z(10) - pp->sop->floor_loz));
|
2020-09-09 11:29:03 +00:00
|
|
|
}
|
2020-09-07 20:22:47 +00:00
|
|
|
|
2020-09-09 13:00:43 +00:00
|
|
|
if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_TURRET))
|
2020-09-09 11:29:03 +00:00
|
|
|
{
|
2020-09-09 13:00:43 +00:00
|
|
|
DoPlayerTurnTurret(pp, q16avel);
|
2020-09-09 11:29:03 +00:00
|
|
|
}
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 11:46:18 +00:00
|
|
|
loc.fvel = clamp(loc.fvel + fvel, -MAXFVEL, MAXFVEL);
|
2020-09-06 10:12:39 +00:00
|
|
|
loc.svel = clamp(loc.svel + svel, -MAXSVEL, MAXSVEL);
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-09-06 11:46:18 +00:00
|
|
|
loc.q16avel = clamp(loc.q16avel + q16avel, -IntToFixed(MAXANGVEL), IntToFixed(MAXANGVEL));
|
|
|
|
loc.q16horz = clamp(loc.q16horz + q16horz, -IntToFixed(MAXHORIZVEL), IntToFixed(MAXHORIZVEL));
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 10:17:54 +00:00
|
|
|
void GameInterface::GetInput(InputPacket *packet, ControlInfo* const hidInput)
|
2020-09-02 18:56:09 +00:00
|
|
|
{
|
2020-09-06 21:56:42 +00:00
|
|
|
if (paused || M_Active())
|
2020-09-06 11:03:27 +00:00
|
|
|
{
|
2020-09-06 11:57:33 +00:00
|
|
|
loc = {};
|
2020-09-06 11:03:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-06 10:49:05 +00:00
|
|
|
PLAYERp pp = &Player[myconnectindex];
|
2020-09-06 10:52:58 +00:00
|
|
|
bool mouseaim;
|
|
|
|
|
|
|
|
processInputBits(pp, hidInput, &mouseaim);
|
2020-09-14 19:25:53 +00:00
|
|
|
processMovement(pp, hidInput, mouseaim, packet != nullptr);
|
2020-09-06 10:49:05 +00:00
|
|
|
processWeapon(pp);
|
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
if (packet)
|
|
|
|
{
|
2020-09-06 19:19:49 +00:00
|
|
|
auto const ang = FixedToInt(pp->q16ang);
|
2020-09-06 11:47:00 +00:00
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
*packet = loc;
|
2020-09-06 11:47:00 +00:00
|
|
|
|
|
|
|
packet->fvel = mulscale9(loc.fvel, sintable[NORM_ANGLE(ang + 512)]) + mulscale9(loc.svel, sintable[NORM_ANGLE(ang)]);
|
|
|
|
packet->svel = mulscale9(loc.fvel, sintable[NORM_ANGLE(ang)]) + mulscale9(loc.svel, sintable[NORM_ANGLE(ang + 1536)]);
|
|
|
|
|
2020-09-02 18:56:09 +00:00
|
|
|
loc = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-16 14:00:40 +00:00
|
|
|
END_SW_NS
|