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
|
|
|
|
|
|
|
|
double elapsedInputTicks;
|
|
|
|
double scaleAdjustmentToInterval(double x) { return x * (120 / synctics) / (1000.0 / elapsedInputTicks); }
|
|
|
|
|
|
|
|
void DoPlayerTurn(PLAYERp pp, fix16_t *pq16ang, fix16_t q16angvel);
|
2020-08-26 22:00:50 +00:00
|
|
|
void DoPlayerHorizon(PLAYERp pp, fix16_t *pq16horiz, fix16_t q16horz);
|
2020-08-16 14:00:40 +00:00
|
|
|
|
|
|
|
|
2020-08-24 18:20:15 +00:00
|
|
|
void GameInterface::ResetFollowPos(bool)
|
|
|
|
{
|
|
|
|
auto pp = &Player[myconnectindex];
|
|
|
|
Follow_posx = pp->posx;
|
|
|
|
Follow_posy = pp->posy;
|
|
|
|
}
|
|
|
|
|
2020-08-16 14:00:40 +00:00
|
|
|
void
|
2020-08-26 15:12:48 +00:00
|
|
|
getinput(InputPacket *loc, SWBOOL tied)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
PLAYERp pp = Player + myconnectindex;
|
|
|
|
PLAYERp newpp = Player + myconnectindex;
|
|
|
|
|
|
|
|
#define TURBOTURNTIME (120/8)
|
|
|
|
#define NORMALTURN (12+6)
|
|
|
|
#define RUNTURN (28)
|
|
|
|
#define PREAMBLETURN 3
|
|
|
|
#define NORMALKEYMOVE 35
|
|
|
|
#define MAXVEL ((NORMALKEYMOVE*2)+10)
|
|
|
|
#define MAXSVEL ((NORMALKEYMOVE*2)+10)
|
|
|
|
#define MAXANGVEL 100
|
|
|
|
#define MAXHORIZVEL 128
|
|
|
|
#define SET_LOC_KEY(loc, sync_num, key_test) SET(loc, ((!!(key_test)) << (sync_num)))
|
|
|
|
|
|
|
|
static int32_t turnheldtime;
|
|
|
|
int32_t momx, momy;
|
|
|
|
|
|
|
|
extern SWBOOL MenuButtonAutoAim;
|
|
|
|
|
|
|
|
if (Prediction && CommEnabled)
|
|
|
|
{
|
|
|
|
newpp = ppp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double lastInputTicks;
|
|
|
|
|
2020-08-25 23:27:09 +00:00
|
|
|
auto const currentHiTicks = I_msTimeF();
|
2020-08-16 14:00:40 +00:00
|
|
|
elapsedInputTicks = currentHiTicks - lastInputTicks;
|
|
|
|
|
|
|
|
lastInputTicks = currentHiTicks;
|
|
|
|
|
|
|
|
ControlInfo info;
|
|
|
|
CONTROL_GetInput(&info);
|
|
|
|
|
|
|
|
if (paused)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If in 2D follow mode, scroll around using glob vars
|
|
|
|
// Tried calling this in domovethings, but key response it too poor, skips key presses
|
2020-08-24 17:36:17 +00:00
|
|
|
// Note: this get called only during follow mode
|
2020-08-25 16:28:50 +00:00
|
|
|
if (!tied && automapFollow && automapMode != am_off && pp == Player + myconnectindex && !Prediction)
|
2020-08-16 14:00:40 +00:00
|
|
|
MoveScrollMode2D(Player + myconnectindex);
|
|
|
|
|
|
|
|
// !JIM! Added M_Active() so that you don't move at all while using menus
|
2020-08-24 17:36:17 +00:00
|
|
|
if (M_Active() || automapFollow)
|
2020-08-16 14:00:40 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int32_t turnamount;
|
|
|
|
int32_t keymove;
|
|
|
|
|
|
|
|
// The function DoPlayerTurn() scales the player's q16angvel by 1.40625, so store as constant
|
|
|
|
// and use to scale back player's aim and ang values for a consistent feel between games.
|
|
|
|
float const angvelScale = 1.40625f;
|
|
|
|
float const aimvelScale = 1.203125f;
|
|
|
|
|
|
|
|
// Shadow Warrior has a ticrate of 40, 25% more than the other games, so store below constant
|
|
|
|
// for dividing controller input to match speed input speed of other games.
|
|
|
|
float const ticrateScale = 0.75f;
|
|
|
|
|
2020-08-26 22:53:35 +00:00
|
|
|
ApplyGlobalInput(*loc, &info);
|
|
|
|
|
2020-08-29 11:32:14 +00:00
|
|
|
bool 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-08-26 22:53:35 +00:00
|
|
|
|
2020-08-28 22:57:07 +00:00
|
|
|
if (loc->actions & SB_RUN)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
|
|
|
if (pp->sop_control)
|
|
|
|
turnamount = RUNTURN * 3;
|
|
|
|
else
|
|
|
|
turnamount = RUNTURN;
|
|
|
|
|
|
|
|
keymove = NORMALKEYMOVE << 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pp->sop_control)
|
|
|
|
turnamount = NORMALTURN * 3;
|
|
|
|
else
|
|
|
|
turnamount = NORMALTURN;
|
|
|
|
|
|
|
|
keymove = NORMALKEYMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tied)
|
|
|
|
keymove = 0;
|
|
|
|
|
|
|
|
int32_t svel = 0, vel = 0;
|
2020-08-26 22:00:50 +00:00
|
|
|
fix16_t q16horz = 0, q16angvel = 0;
|
2020-08-16 14:00:40 +00:00
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe) && !pp->sop)
|
|
|
|
{
|
|
|
|
svel -= (info.mousex * ticrateScale) * 4.f;
|
|
|
|
svel -= info.dyaw * keymove;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
q16angvel = fix16_sadd(q16angvel, fix16_from_float(info.mousex / angvelScale));
|
|
|
|
q16angvel = fix16_sadd(q16angvel, fix16_from_dbl(scaleAdjustmentToInterval((info.dyaw * ticrateScale) / angvelScale)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mouseaim)
|
2020-08-26 22:00:50 +00:00
|
|
|
q16horz = fix16_ssub(q16horz, fix16_from_float(info.mousey / aimvelScale));
|
2020-08-16 14:00:40 +00:00
|
|
|
else
|
|
|
|
vel -= (info.mousey * ticrateScale) * 8.f;
|
|
|
|
|
|
|
|
if (in_mouseflip)
|
2020-08-26 22:00:50 +00:00
|
|
|
q16horz = -q16horz;
|
2020-08-16 14:00:40 +00:00
|
|
|
|
2020-08-26 22:00:50 +00:00
|
|
|
q16horz -= fix16_from_dbl(scaleAdjustmentToInterval((info.dpitch * ticrateScale) / aimvelScale));
|
2020-08-16 14:00:40 +00:00
|
|
|
svel -= info.dx * keymove;
|
|
|
|
vel -= info.dz * keymove;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe) && !pp->sop)
|
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Left))
|
|
|
|
svel -= -keymove;
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Right))
|
|
|
|
svel -= keymove;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && pp->sop))
|
|
|
|
{
|
|
|
|
turnheldtime += synctics;
|
|
|
|
if (PedanticMode)
|
|
|
|
{
|
|
|
|
if (turnheldtime >= TURBOTURNTIME)
|
|
|
|
q16angvel -= fix16_from_int(turnamount);
|
|
|
|
else
|
|
|
|
q16angvel -= fix16_from_int(PREAMBLETURN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
q16angvel = fix16_ssub(q16angvel, fix16_from_float(scaleAdjustmentToInterval((turnheldtime >= TURBOTURNTIME) ? turnamount : PREAMBLETURN)));
|
|
|
|
}
|
|
|
|
else if (buttonMap.ButtonDown(gamefunc_Turn_Right) || (buttonMap.ButtonDown(gamefunc_Strafe_Right) && pp->sop))
|
|
|
|
{
|
|
|
|
turnheldtime += synctics;
|
|
|
|
if (PedanticMode)
|
|
|
|
{
|
|
|
|
if (turnheldtime >= TURBOTURNTIME)
|
|
|
|
q16angvel += fix16_from_int(turnamount);
|
|
|
|
else
|
|
|
|
q16angvel += fix16_from_int(PREAMBLETURN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
q16angvel = fix16_sadd(q16angvel, fix16_from_float(scaleAdjustmentToInterval((turnheldtime >= TURBOTURNTIME) ? turnamount : PREAMBLETURN)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
turnheldtime = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !pp->sop)
|
|
|
|
svel += keymove;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !pp->sop)
|
|
|
|
svel += -keymove;
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Forward))
|
|
|
|
{
|
|
|
|
vel += keymove;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buttonMap.ButtonDown(gamefunc_Move_Backward))
|
|
|
|
vel += -keymove;
|
|
|
|
|
|
|
|
q16angvel = fix16_clamp(q16angvel, -fix16_from_int(MAXANGVEL), fix16_from_int(MAXANGVEL));
|
2020-08-26 22:00:50 +00:00
|
|
|
q16horz = fix16_clamp(q16horz, -fix16_from_int(MAXHORIZVEL), fix16_from_int(MAXHORIZVEL));
|
2020-08-16 14:00:40 +00:00
|
|
|
|
|
|
|
void DoPlayerTeleportPause(PLAYERp pp);
|
|
|
|
if (PedanticMode)
|
|
|
|
{
|
|
|
|
q16angvel = fix16_floor(q16angvel);
|
2020-08-26 22:00:50 +00:00
|
|
|
q16horz = fix16_floor(q16horz);
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fix16_t prevcamq16ang = pp->camq16ang, prevcamq16horiz = pp->camq16horiz;
|
|
|
|
|
|
|
|
if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN))
|
|
|
|
DoPlayerTurn(pp, &pp->camq16ang, q16angvel);
|
|
|
|
if (TEST(pp->Flags2, PF2_INPUT_CAN_AIM))
|
2020-08-26 22:00:50 +00:00
|
|
|
DoPlayerHorizon(pp, &pp->camq16horiz, q16horz);
|
2020-08-16 14:00:40 +00:00
|
|
|
pp->oq16ang += pp->camq16ang - prevcamq16ang;
|
|
|
|
pp->oq16horiz += pp->camq16horiz - prevcamq16horiz;
|
|
|
|
}
|
|
|
|
|
2020-08-25 20:06:01 +00:00
|
|
|
loc->fvel += vel;
|
2020-08-16 14:00:40 +00:00
|
|
|
loc->svel += svel;
|
|
|
|
|
|
|
|
if (!tied)
|
|
|
|
{
|
2020-08-25 20:06:01 +00:00
|
|
|
vel = clamp(loc->fvel, -MAXVEL, MAXVEL);
|
2020-08-16 14:00:40 +00:00
|
|
|
svel = clamp(loc->svel, -MAXSVEL, MAXSVEL);
|
|
|
|
|
|
|
|
momx = mulscale9(vel, sintable[NORM_ANGLE(fix16_to_int(newpp->q16ang) + 512)]);
|
|
|
|
momy = mulscale9(vel, sintable[NORM_ANGLE(fix16_to_int(newpp->q16ang))]);
|
|
|
|
|
|
|
|
momx += mulscale9(svel, sintable[NORM_ANGLE(fix16_to_int(newpp->q16ang))]);
|
|
|
|
momy += mulscale9(svel, sintable[NORM_ANGLE(fix16_to_int(newpp->q16ang) + 1536)]);
|
|
|
|
|
2020-08-25 20:06:01 +00:00
|
|
|
loc->fvel = momx;
|
2020-08-16 14:00:40 +00:00
|
|
|
loc->svel = momy;
|
|
|
|
}
|
|
|
|
|
2020-08-25 20:06:01 +00:00
|
|
|
loc->q16avel += q16angvel;
|
2020-08-26 22:00:50 +00:00
|
|
|
loc->q16horz += q16horz;
|
2020-08-16 14:00:40 +00:00
|
|
|
|
|
|
|
|
2020-08-26 22:53:35 +00:00
|
|
|
if (loc->getNewWeapon() == WeaponSel_Next)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
|
|
|
USERp u = User[pp->PlayerSprite];
|
|
|
|
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;
|
|
|
|
for (i = start_weapon; TRUE; i++)
|
|
|
|
{
|
|
|
|
if (i >= MAX_WEAPONS_KEYS)
|
|
|
|
{
|
|
|
|
next_weapon = 13;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TEST(pp->WpnFlags, BIT(i)) && pp->WpnAmmo[i])
|
|
|
|
{
|
|
|
|
next_weapon = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:53:35 +00:00
|
|
|
loc->setNewWeapon(next_weapon + 1);
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
2020-08-26 22:53:35 +00:00
|
|
|
else if (loc->getNewWeapon() == WeaponSel_Prev)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
for (i = start_weapon; TRUE; i--)
|
|
|
|
{
|
|
|
|
if (i <= -1)
|
|
|
|
i = WPN_HEART;
|
|
|
|
|
|
|
|
if (TEST(pp->WpnFlags, BIT(i)) && pp->WpnAmmo[i])
|
|
|
|
{
|
|
|
|
prev_weapon = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-26 22:53:35 +00:00
|
|
|
loc->setNewWeapon(prev_weapon + 1);
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
2020-08-26 22:53:35 +00:00
|
|
|
else if (loc->getNewWeapon() == WeaponSel_Alt)
|
2020-08-16 14:00:40 +00:00
|
|
|
{
|
|
|
|
USERp u = User[pp->PlayerSprite];
|
|
|
|
short const which_weapon = u->WeaponNum + 1;
|
2020-08-26 22:53:35 +00:00
|
|
|
loc->setNewWeapon(which_weapon);
|
2020-08-16 14:00:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
END_SW_NS
|