- rework of weapon input to use common features in shared code.

This also adds stubs for all unimplemented features in the games for easier addition.
This commit is contained in:
Christoph Oelckers 2020-08-27 00:53:35 +02:00
parent 89f5b26988
commit 10df3e094a
14 changed files with 177 additions and 162 deletions

View file

@ -525,14 +525,16 @@ void ProcessFrame(void)
char buffer[128]; char buffer[128];
for (int i = connecthead; i >= 0; i = connectpoint2[i]) for (int i = connecthead; i >= 0; i = connectpoint2[i])
{ {
gPlayer[i].input.syncFlags.value &= ~flag_buttonmask; auto& inp = gPlayer[i].input;
gPlayer[i].input.syncFlags.value |= gFifoInput[gNetFifoTail & 255][i].syncFlags.value; auto oldactions = inp.actions;
int newweap = gFifoInput[gNetFifoTail & 255][i].getNewWeapon(); auto oldflags = inp.syncFlags.value;
if (newweap) gPlayer[i].newWeapon = newweap;
gPlayer[i].input.fvel = gFifoInput[gNetFifoTail&255][i].fvel; inp = gFifoInput[gNetFifoTail & 255][i];
gPlayer[i].input.q16avel = gFifoInput[gNetFifoTail&255][i].q16avel; inp.actions |= oldactions & SB_INTERFACE_MASK; // should be everything non-button and non-weapon
gPlayer[i].input.svel = gFifoInput[gNetFifoTail&255][i].svel; inp.syncFlags.value |= oldflags & ~flag_buttonmask;
gPlayer[i].input.q16horz = gFifoInput[gNetFifoTail&255][i].q16horz;
int newweap = inp.getNewWeapon();
if (newweap > 0 && newweap < WeaponSel_MaxBlood) gPlayer[i].newWeapon = newweap;
} }
gNetFifoTail++; gNetFifoTail++;

View file

@ -150,8 +150,7 @@ void ctrlGetInput(void)
gInput.syncFlags.quit = 1; gInput.syncFlags.quit = 1;
gInput.syncFlags.value |= BitsToSend.value; gInput.syncFlags.value |= BitsToSend.value;
if (WeaponToSend != 0) ApplyGlobalInput(gInput, &info);
gInput.SetNewWeapon(WeaponToSend);
BitsToSend.value = 0; BitsToSend.value = 0;
WeaponToSend = 0; WeaponToSend = 0;
@ -345,27 +344,9 @@ void ctrlGetInput(void)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static int ccmd_slot(CCmdFuncPtr parm)
{
if (parm->numparms != 1) return CCMD_SHOWHELP;
auto slot = atoi(parm->parms[0]);
if (slot >= 1 && slot <= 10)
{
WeaponToSend = slot;
return CCMD_OK;
}
return CCMD_SHOWHELP;
}
void registerinputcommands() void registerinputcommands()
{ {
C_RegisterFunction("slot", "slot <weaponslot>: select a weapon from the given slot (1-10)", ccmd_slot);
C_RegisterFunction("weapprev", nullptr, [](CCmdFuncPtr)->int { if (gPlayer[myconnectindex].nextWeapon == 0) BitsToSend.prevWeapon = 1; return CCMD_OK; });
C_RegisterFunction("weapnext", nullptr, [](CCmdFuncPtr)->int { if (gPlayer[myconnectindex].nextWeapon == 0) BitsToSend.nextWeapon = 1; return CCMD_OK; });
C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend.pause = 1; sendPause = true; return CCMD_OK; }); C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend.pause = 1; sendPause = true; return CCMD_OK; });
C_RegisterFunction("proximitybombs", nullptr, [](CCmdFuncPtr)->int { WeaponToSend = 11; return CCMD_OK; });
C_RegisterFunction("remotebombs", nullptr, [](CCmdFuncPtr)->int { WeaponToSend = 12; return CCMD_OK; });
C_RegisterFunction("jumpboots", nullptr, [](CCmdFuncPtr)->int { BitsToSend.useJumpBoots = 1; return CCMD_OK; }); C_RegisterFunction("jumpboots", nullptr, [](CCmdFuncPtr)->int { BitsToSend.useJumpBoots = 1; return CCMD_OK; });
C_RegisterFunction("medkit", nullptr, [](CCmdFuncPtr)->int { BitsToSend.useMedKit = 1; return CCMD_OK; }); C_RegisterFunction("medkit", nullptr, [](CCmdFuncPtr)->int { BitsToSend.useMedKit = 1; return CCMD_OK; });
C_RegisterFunction("centerview", nullptr, [](CCmdFuncPtr)->int { BitsToSend.lookCenter = 1; return CCMD_OK; }); C_RegisterFunction("centerview", nullptr, [](CCmdFuncPtr)->int { BitsToSend.lookCenter = 1; return CCMD_OK; });

View file

@ -1331,7 +1331,7 @@ void ProcessInput(PLAYER *pPlayer)
pPlayer->q16horiz = mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime*8, 1024))>>15), fix16_from_int(120)); pPlayer->q16horiz = mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime*8, 1024))>>15), fix16_from_int(120));
} }
if (pPlayer->curWeapon) if (pPlayer->curWeapon)
pInput->SetNewWeapon(pPlayer->curWeapon); pInput->setNewWeapon(pPlayer->curWeapon);
if (pInput->syncFlags.action) if (pInput->syncFlags.action)
{ {
if (bSeqStat) if (bSeqStat)

View file

@ -119,8 +119,8 @@ struct PLAYER
char hasFlag; char hasFlag;
short used2[8]; // ?? short used2[8]; // ??
int damageControl[7]; int damageControl[7];
char curWeapon; int8_t curWeapon;
char nextWeapon; int8_t nextWeapon;
int weaponTimer; int weaponTimer;
int weaponState; int weaponState;
int weaponAmmo; //rename int weaponAmmo; //rename

View file

@ -2026,9 +2026,9 @@ void WeaponProcess(PLAYER *pPlayer) {
pPlayer->newWeapon = pPlayer->nextWeapon; pPlayer->newWeapon = pPlayer->nextWeapon;
pPlayer->nextWeapon = 0; pPlayer->nextWeapon = 0;
} }
if (pPlayer->input.syncFlags.nextWeapon) if (pPlayer->input.getNewWeapon() == WeaponSel_Next)
{ {
pPlayer->input.syncFlags.nextWeapon = 0; pPlayer->input.setNewWeapon(0);
pPlayer->weaponState = 0; pPlayer->weaponState = 0;
pPlayer->nextWeapon = 0; pPlayer->nextWeapon = 0;
int t; int t;
@ -2042,9 +2042,9 @@ void WeaponProcess(PLAYER *pPlayer) {
} }
pPlayer->newWeapon = weapon; pPlayer->newWeapon = weapon;
} }
if (pPlayer->input.syncFlags.prevWeapon) else if (pPlayer->input.getNewWeapon() == WeaponSel_Prev)
{ {
pPlayer->input.syncFlags.prevWeapon = 0; pPlayer->input.setNewWeapon(0);
pPlayer->weaponState = 0; pPlayer->weaponState = 0;
pPlayer->nextWeapon = 0; pPlayer->nextWeapon = 0;
int t; int t;
@ -2058,6 +2058,10 @@ void WeaponProcess(PLAYER *pPlayer) {
} }
pPlayer->newWeapon = weapon; pPlayer->newWeapon = weapon;
} }
else if (pPlayer->input.getNewWeapon() == WeaponSel_Alt)
{
// todo
}
if (pPlayer->weaponState == -1) if (pPlayer->weaponState == -1)
{ {
pPlayer->weaponState = 0; pPlayer->weaponState = 0;

View file

@ -41,6 +41,8 @@
#include"packet.h" #include"packet.h"
#include "gamecontrol.h" #include "gamecontrol.h"
static int WeaponToSend = 0;
//========================================================================== //==========================================================================
// //
// //
@ -220,3 +222,58 @@ void SetupGameButtons()
buttonMap.SetButtons(actions, NUM_ACTIONS); buttonMap.SetButtons(actions, NUM_ACTIONS);
} }
//==========================================================================
//
//
//
//==========================================================================
CCMD(slot)
{
// The max differs between games so we have to handle this here.
int max = (g_gameType & GAMEFLAG_PSEXHUMED) || (g_gameType & (GAMEFLAG_DUKE | GAMEFLAG_SHAREWARE)) == (GAMEFLAG_DUKE | GAMEFLAG_SHAREWARE) ? 7 : (g_gameType & GAMEFLAG_BLOOD) ? 12 : 10;
if (argv.argc() != 2)
{
Printf("slot <weaponslot>: select a weapon from the given slot (1-%d)", max);
}
auto slot = atoi(argv[1]);
if (slot >= 1 && slot <= max)
{
WeaponToSend = slot;
}
}
CCMD(weapprev)
{
WeaponToSend = WeaponSel_Prev;
}
CCMD(weapnext)
{
WeaponToSend = WeaponSel_Next;
}
CCMD(weapalt)
{
WeaponToSend = WeaponSel_Alt; // Only used by SW - should also be made usable by Blood ans Duke which put multiple weapons in the same slot.
}
void ApplyGlobalInput(InputPacket& input, ControlInfo *info)
{
if (WeaponToSend != 0) input.setNewWeapon(WeaponToSend);
WeaponToSend = 0;
if (info)
{
if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info->dz > 0) input.setNewWeapon(WeaponSel_Prev);
if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info->dz < 0) input.setNewWeapon(WeaponSel_Next);
}
if (buttonMap.ButtonDown(gamefunc_Dpad_Select))
{
// This eats the controller input for regular use
info->dx = 0;
info->dz = 0;
info->dyaw = 0;
}
}

View file

@ -11,6 +11,7 @@
#include "d_event.h" #include "d_event.h"
#include "m_joy.h" #include "m_joy.h"
#include "gamecvars.h" #include "gamecvars.h"
#include "packet.h"
struct ControlInfo struct ControlInfo
@ -98,3 +99,5 @@ enum GameFunction_t
}; };
void SetupGameButtons(); void SetupGameButtons();
void ApplyGlobalInput(InputPacket& input, ControlInfo *info);

View file

@ -4,14 +4,15 @@
#include "fix16.h" #include "fix16.h"
#include "tflags.h" #include "tflags.h"
enum ESyncBits_ : uint32_t enum ESyncBits_ : uint32_t
{ {
SB_FIRST_WEAPON_BIT = 1 << 0, SB_FIRST_WEAPON_BIT = 1 << 0,
SB_WEAPONMASK_BITS = (15u * SB_FIRST_WEAPON_BIT), // Weapons take up 4 bits SB_WEAPONMASK_BITS = (15u * SB_FIRST_WEAPON_BIT), // Weapons take up 4 bits
SB_INTERFACE_BITS = (SB_WEAPONMASK_BITS) SB_BUTTON_MASK = 0, // all input from buttons (i.e. active while held)
SB_INTERFACE_MASK = 0, // all input from CCMDs
SB_INTERFACE_BITS = (SB_WEAPONMASK_BITS | SB_INTERFACE_MASK)
}; };
// enforce type safe operations on the input bits. // enforce type safe operations on the input bits.
@ -27,6 +28,20 @@ enum
}; };
enum
{
// The maximum valid weapons for the respective games.
WeaponSel_Max = 10,
WeaponSel_MaxExhumed = 7,
WeaponSel_MaxBlood = 12,
// Use named constants instead of magic values for these. The maximum of the supported games is 12 weapons for Blood so these 3 are free.
// Should there ever be need for more weapons to select, the bit field needs to be expanded.
WeaponSel_Next = 13,
WeaponSel_Prev = 14,
WeaponSel_Alt = 15
};
enum EDukeSyncBits_ : uint32_t enum EDukeSyncBits_ : uint32_t
{ {
SKB_JUMP = 1 << 0, SKB_JUMP = 1 << 0,
@ -88,8 +103,6 @@ union SYNCFLAGS
unsigned int prevItem : 1; unsigned int prevItem : 1;
unsigned int nextItem : 1; unsigned int nextItem : 1;
unsigned int useItem : 1; unsigned int useItem : 1;
unsigned int prevWeapon : 1;
unsigned int nextWeapon : 1;
unsigned int holsterWeapon : 1; unsigned int holsterWeapon : 1;
unsigned int lookCenter : 1; unsigned int lookCenter : 1;
unsigned int lookLeft : 1; unsigned int lookLeft : 1;
@ -193,8 +206,10 @@ struct InputPacket
return (actions & SB_WEAPONMASK_BITS).GetValue(); return (actions & SB_WEAPONMASK_BITS).GetValue();
} }
void SetNewWeapon(int weap) void setNewWeapon(int weap)
{ {
actions = (actions & ~SB_WEAPONMASK_BITS) | (ESyncBits::FromInt(weap) & SB_WEAPONMASK_BITS); actions = (actions & ~SB_WEAPONMASK_BITS) | (ESyncBits::FromInt(weap) & SB_WEAPONMASK_BITS);
} }
}; };

View file

@ -46,6 +46,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "screenjob.h" #include "screenjob.h"
#include "c_console.h" #include "c_console.h"
#include "cheathandler.h" #include "cheathandler.h"
#include "inputstate.h"
#include "core/menu/menu.h" #include "core/menu/menu.h"
BEGIN_PS_NS BEGIN_PS_NS
@ -466,6 +467,23 @@ void GameMove(void)
totalmoves++; totalmoves++;
} }
static int SelectNextWeapon(int weap2)
{
// todo
return 0;
}
static int SelectPrevWeapon(int weap2)
{
// todo
return 0;
}
static int SelectAltWeapon(int weap2)
{
// todo
return 0;
}
void GameTicker() void GameTicker()
{ {
@ -496,6 +514,19 @@ void GameTicker()
lPlayerXVel -= (lPlayerXVel >> 5) + (lPlayerXVel >> 6); lPlayerXVel -= (lPlayerXVel >> 5) + (lPlayerXVel >> 6);
lPlayerYVel -= (lPlayerYVel >> 5) + (lPlayerYVel >> 6); lPlayerYVel -= (lPlayerYVel >> 5) + (lPlayerYVel >> 6);
} }
int weap2 = localInput.getNewWeapon();
if (weap2 == WeaponSel_Next)
{
weap2 = SelectNextWeapon(weap2);
}
else if (weap2 == WeaponSel_Prev)
{
weap2 = SelectPrevWeapon(weap2);
}
else if (weap2 == WeaponSel_Alt)
{
weap2 = SelectAltWeapon(weap2);
}
sPlayerInput[nLocalPlayer].xVel = lPlayerXVel; sPlayerInput[nLocalPlayer].xVel = lPlayerXVel;
sPlayerInput[nLocalPlayer].yVel = lPlayerYVel; sPlayerInput[nLocalPlayer].yVel = lPlayerYVel;
@ -503,7 +534,6 @@ void GameTicker()
sPlayerInput[nLocalPlayer].buttons = lLocalButtons | lLocalCodes; sPlayerInput[nLocalPlayer].buttons = lLocalButtons | lLocalCodes;
int weap = sPlayerInput[nLocalPlayer].getNewWeapon(); int weap = sPlayerInput[nLocalPlayer].getNewWeapon();
sPlayerInput[nLocalPlayer].actions = localInput.actions; sPlayerInput[nLocalPlayer].actions = localInput.actions;
int weap2 = localInput.getNewWeapon();
if (weap2 <= 0 || weap2 > 7) sPlayerInput[nLocalPlayer].SetNewWeapon(weap); if (weap2 <= 0 || weap2 > 7) sPlayerInput[nLocalPlayer].SetNewWeapon(weap);
sPlayerInput[nLocalPlayer].nTarget = besttarget; sPlayerInput[nLocalPlayer].nTarget = besttarget;

View file

@ -31,7 +31,7 @@ BEGIN_PS_NS
extern short bPlayerPan; extern short bPlayerPan;
extern short bLockPan; extern short bLockPan;
int WeaponToSend, BitsToSend; int BitsToSend;
bool g_MyAimMode; bool g_MyAimMode;
short nInputStack = 0; short nInputStack = 0;
@ -187,6 +187,12 @@ void PlayerInterruptKeys(bool after)
return; return;
} }
if (!after)
{
ApplyGlobalInput(localInput, &info);
}
// JBF: Run key behaviour is selectable // JBF: Run key behaviour is selectable
int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run));
int const turnAmount = playerRunning ? 12 : 8; int const turnAmount = playerRunning ? 12 : 8;
@ -280,13 +286,6 @@ void PlayerInterruptKeys(bool after)
localInput.q16avel = fix16_sadd(localInput.q16avel, input_angle); localInput.q16avel = fix16_sadd(localInput.q16avel, input_angle);
if (!after)
{
if (WeaponToSend > 0)
localInput.SetNewWeapon(WeaponToSend);
WeaponToSend = 0;
}
if (!nFreeze) if (!nFreeze)
{ {
PlayerList[nLocalPlayer].q16angle = fix16_sadd(PlayerList[nLocalPlayer].q16angle, input_angle) & 0x7FFFFFF; PlayerList[nLocalPlayer].q16angle = fix16_sadd(PlayerList[nLocalPlayer].q16angle, input_angle) & 0x7FFFFFF;
@ -380,33 +379,16 @@ void PlayerInterruptKeys(bool after)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static int ccmd_slot(CCmdFuncPtr parm)
{
if (parm->numparms != 1) return CCMD_SHOWHELP;
auto slot = atoi(parm->parms[0]);
if (slot >= 1 && slot <= 7)
{
WeaponToSend = slot;
return CCMD_OK;
}
return CCMD_SHOWHELP;
}
int ccmd_centerview(CCmdFuncPtr parm); int ccmd_centerview(CCmdFuncPtr parm);
void registerinputcommands() void registerinputcommands()
{ {
C_RegisterFunction("slot", "slot <weaponslot>: select a weapon from the given slot (1-10)", ccmd_slot);
C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { /*BitsToSend |= SKB_PAUSE;*/ sendPause = true; return CCMD_OK; }); C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { /*BitsToSend |= SKB_PAUSE;*/ sendPause = true; return CCMD_OK; });
C_RegisterFunction("centerview", nullptr, ccmd_centerview); C_RegisterFunction("centerview", nullptr, ccmd_centerview);
C_RegisterFunction("invprev", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) SetPrevItem(nLocalPlayer); return CCMD_OK; }); C_RegisterFunction("invprev", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) SetPrevItem(nLocalPlayer); return CCMD_OK; });
C_RegisterFunction("invnext", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) SetNextItem(nLocalPlayer); return CCMD_OK; }); C_RegisterFunction("invnext", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) SetNextItem(nLocalPlayer); return CCMD_OK; });
C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) UseCurItem(nLocalPlayer); return CCMD_OK; }); C_RegisterFunction("invuse", nullptr, [](CCmdFuncPtr)->int { if (PlayerList[nLocalPlayer].nHealth > 0) UseCurItem(nLocalPlayer); return CCMD_OK; });
// todo: These still need to be implemented.
C_RegisterFunction("weapprev", nullptr, [](CCmdFuncPtr)->int { /*WeaponToSend = 11;*/ return CCMD_OK; });
C_RegisterFunction("weapnext", nullptr, [](CCmdFuncPtr)->int { /*WeaponToSend = 12;*/ return CCMD_OK; });
// These are only here to silence the engine when the keys bound to them are pressed. The functions do not exist. // These are only here to silence the engine when the keys bound to them are pressed. The functions do not exist.
C_RegisterFunction("turnaround", nullptr, [](CCmdFuncPtr)->int { return CCMD_OK; }); C_RegisterFunction("turnaround", nullptr, [](CCmdFuncPtr)->int { return CCMD_OK; });
@ -417,7 +399,6 @@ void registerinputcommands()
// This is called from ImputState::ClearAllInput and resets all static state being used here. // This is called from ImputState::ClearAllInput and resets all static state being used here.
void GameInterface::clearlocalinputstate() void GameInterface::clearlocalinputstate()
{ {
WeaponToSend = 0;
BitsToSend = 0; BitsToSend = 0;
} }

View file

@ -39,7 +39,6 @@ source as it is released.
BEGIN_DUKE_NS BEGIN_DUKE_NS
static int WeaponToSend;
static EDukeSyncBits BitsToSend; static EDukeSyncBits BitsToSend;
// State timer counters. // State timer counters.
@ -146,7 +145,6 @@ void hud_input(int snum)
{ {
int i, k; int i, k;
uint8_t dainv; uint8_t dainv;
unsigned int j;
struct player_struct* p; struct player_struct* p;
short unk; short unk;
@ -339,16 +337,12 @@ void hud_input(int snum)
if (dainv >= 1 && dainv < 8) FTA(invquotes[dainv - 1], p); if (dainv >= 1 && dainv < 8) FTA(invquotes[dainv - 1], p);
} }
j = PlayerNewWeapon(snum) - 1; int weap = PlayerNewWeapon(snum);
if (j >= 0) if (weap > 1 && p->kickback_pic > 0)
{ p->wantweaponfire = weap - 1;
int a = 0;
}
if (j > 0 && p->kickback_pic > 0)
p->wantweaponfire = j;
// Here we have to be extra careful that the weapons do not get mixed up, so let's keep the code for Duke and RR completely separate. // Here we have to be extra careful that the weapons do not get mixed up, so let's keep the code for Duke and RR completely separate.
fi.selectweapon(snum, j); fi.selectweapon(snum, weap);
if (PlayerInput(snum, SKB_HOLSTER)) if (PlayerInput(snum, SKB_HOLSTER))
{ {
@ -467,7 +461,7 @@ void hud_input(int snum)
{ {
if (!isRR()) if (!isRR())
{ {
j = max_player_health - sprite[p->i].extra; int j = max_player_health - sprite[p->i].extra;
if ((unsigned int)p->firstaid_amount > j) if ((unsigned int)p->firstaid_amount > j)
{ {
@ -485,7 +479,7 @@ void hud_input(int snum)
} }
else else
{ {
j = 10; int j = 10;
if (p->firstaid_amount > j) if (p->firstaid_amount > j)
{ {
p->firstaid_amount -= j; p->firstaid_amount -= j;
@ -631,7 +625,7 @@ static void processInputBits(player_struct *p, ControlInfo &info)
loc.sbits |= BitsToSend; loc.sbits |= BitsToSend;
BitsToSend = 0; BitsToSend = 0;
if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) if (buttonMap.ButtonDown(gamefunc_Dpad_Select)) // todo: This must go to global code.
{ {
if (info.dx < 0 || info.dyaw < 0) loc.sbits |= SKB_INV_LEFT; if (info.dx < 0 || info.dyaw < 0) loc.sbits |= SKB_INV_LEFT;
if (info.dx > 0 || info.dyaw < 0) loc.sbits |= SKB_INV_RIGHT; if (info.dx > 0 || info.dyaw < 0) loc.sbits |= SKB_INV_RIGHT;
@ -657,23 +651,7 @@ static void processInputBits(player_struct *p, ControlInfo &info)
if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) loc.sbits |= SKB_QUICK_KICK; if (buttonMap.ButtonDown(gamefunc_Quick_Kick)) loc.sbits |= SKB_QUICK_KICK;
if (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) loc.sbits |= SKB_AIMMODE; if (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) loc.sbits |= SKB_AIMMODE;
int j = WeaponToSend; ApplyGlobalInput(loc, &info);
WeaponToSend = 0;
if (VOLUMEONE && (j >= 7 && j <= 10)) j = 0;
if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info.dz > 0) j = 11;
if (buttonMap.ButtonDown(gamefunc_Dpad_Select) && info.dz < 0) j = 12;
if (j) loc.SetNewWeapon(j);
}
if (buttonMap.ButtonDown(gamefunc_Dpad_Select))
{
// This eats the controller input for regular use
info.dx = 0;
info.dz = 0;
info.dyaw = 0;
} }
if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming)) if (buttonMap.ButtonDown(gamefunc_Dpad_Aiming))
@ -1188,24 +1166,8 @@ void GetInput()
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static int ccmd_slot(CCmdFuncPtr parm)
{
if (parm->numparms != 1) return CCMD_SHOWHELP;
auto slot = atoi(parm->parms[0]);
if (slot >= 1 && slot <= 10)
{
WeaponToSend = slot;
return CCMD_OK;
}
return CCMD_SHOWHELP;
}
void registerinputcommands() void registerinputcommands()
{ {
C_RegisterFunction("slot", "slot <weaponslot>: select a weapon from the given slot (1-10)", ccmd_slot);
C_RegisterFunction("weapprev", nullptr, [](CCmdFuncPtr)->int { WeaponToSend = 11; return CCMD_OK; });
C_RegisterFunction("weapnext", nullptr, [](CCmdFuncPtr)->int { WeaponToSend = 12; return CCMD_OK; });
C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_PAUSE; sendPause = true; return CCMD_OK; }); C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_PAUSE; sendPause = true; return CCMD_OK; });
C_RegisterFunction("steroids", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_STEROIDS; return CCMD_OK; }); C_RegisterFunction("steroids", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_STEROIDS; return CCMD_OK; });
C_RegisterFunction("nightvision", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_NIGHTVISION; return CCMD_OK; }); C_RegisterFunction("nightvision", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_NIGHTVISION; return CCMD_OK; });
@ -1224,7 +1186,6 @@ void registerinputcommands()
// This is called from ImputState::ClearAllInput and resets all static state being used here. // This is called from ImputState::ClearAllInput and resets all static state being used here.
void GameInterface::clearlocalinputstate() void GameInterface::clearlocalinputstate()
{ {
WeaponToSend = 0;
BitsToSend = 0; BitsToSend = 0;
nonsharedtimer = 0; nonsharedtimer = 0;
turnheldtime = 0; turnheldtime = 0;

View file

@ -1099,18 +1099,22 @@ void shoot_d(int i, int atwith)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void selectweapon_d(int snum, int j) // playernum, weaponnum void selectweapon_d(int snum, int weap) // playernum, weaponnum
{ {
int i, k; int i, j, k;
auto p = &ps[snum]; auto p = &ps[snum];
if (p->last_pissed_time <= (26 * 218) && p->show_empty_weapon == 0 && p->kickback_pic == 0 && p->quick_kick == 0 && sprite[p->i].xrepeat > 32 && p->access_incs == 0 && p->knee_incs == 0) if (p->last_pissed_time <= (26 * 218) && p->show_empty_weapon == 0 && p->kickback_pic == 0 && p->quick_kick == 0 && sprite[p->i].xrepeat > 32 && p->access_incs == 0 && p->knee_incs == 0)
{ {
if ((p->weapon_pos == 0 || (p->holster_weapon && p->weapon_pos == -9))) if ((p->weapon_pos == 0 || (p->holster_weapon && p->weapon_pos == -9)))
{ {
if (j == 10 || j == 11) if (weap == WeaponSel_Alt)
{
// todo
}
else if (weap == WeaponSel_Next || weap == WeaponSel_Prev)
{ {
k = p->curr_weapon; k = p->curr_weapon;
j = (j == 10 ? -1 : 1); // JBF: prev (-1) or next (1) weapon choice j = (weap == WeaponSel_Prev ? -1 : 1); // JBF: prev (-1) or next (1) weapon choice
i = 0; i = 0;
while ((k >= 0 && k < 10) || (PLUTOPAK && k == GROW_WEAPON && (p->subweapon & (1 << GROW_WEAPON)) != 0) while ((k >= 0 && k < 10) || (PLUTOPAK && k == GROW_WEAPON && (p->subweapon & (1 << GROW_WEAPON)) != 0)
@ -1146,8 +1150,8 @@ void selectweapon_d(int snum, int j) // playernum, weaponnum
if (PLUTOPAK) // JBF 20040116: so we don't select grower with v1.3d if (PLUTOPAK) // JBF 20040116: so we don't select grower with v1.3d
if (k == SHRINKER_WEAPON && (p->subweapon & (1 << GROW_WEAPON))) if (k == SHRINKER_WEAPON && (p->subweapon & (1 << GROW_WEAPON)))
k = GROW_WEAPON; k = GROW_WEAPON;
if (isWorldTour() && k == FREEZE_WEAPON && (p->subweapon & (1 << FLAMETHROWER_WEAPON)) != 0) if (isWorldTour() && k == FREEZE_WEAPON && (p->subweapon & (1 << FLAMETHROWER_WEAPON)) != 0)
k = FLAMETHROWER_WEAPON; k = FLAMETHROWER_WEAPON;
j = k; j = k;
break; break;
@ -1186,10 +1190,10 @@ void selectweapon_d(int snum, int j) // playernum, weaponnum
} }
} }
} }
else j = weap - 1;
k = -1; k = -1;
if (j == HANDBOMB_WEAPON && p->ammo_amount[HANDBOMB_WEAPON] == 0) if (j == HANDBOMB_WEAPON && p->ammo_amount[HANDBOMB_WEAPON] == 0)
{ {
k = headspritestat[1]; k = headspritestat[1];

View file

@ -947,15 +947,19 @@ void shoot_r(int i, int atwith)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void selectweapon_r(int snum, int j) void selectweapon_r(int snum, int weap)
{ {
int i, k; int i, j, k;
auto p = &ps[snum]; auto p = &ps[snum];
if (p->last_pissed_time <= (26 * 218) && p->show_empty_weapon == 0 && p->kickback_pic == 0 && p->quick_kick == 0 && sprite[p->i].xrepeat > 8 && p->access_incs == 0 && p->knee_incs == 0) if (p->last_pissed_time <= (26 * 218) && p->show_empty_weapon == 0 && p->kickback_pic == 0 && p->quick_kick == 0 && sprite[p->i].xrepeat > 8 && p->access_incs == 0 && p->knee_incs == 0)
{ {
if ((p->weapon_pos == 0 || (p->holster_weapon && p->weapon_pos == -9))) if ((p->weapon_pos == 0 || (p->holster_weapon && p->weapon_pos == -9)))
{ {
if (j == 10 || j == 11) if (weap == WeaponSel_Alt)
{
// todo
}
else if (weap == WeaponSel_Next || weap == WeaponSel_Prev)
{ {
k = p->curr_weapon; k = p->curr_weapon;
if (isRRRA()) if (isRRRA())
@ -964,7 +968,7 @@ void selectweapon_r(int snum, int j)
else if (k == BUZZSAW_WEAPON) k = THROWSAW_WEAPON; else if (k == BUZZSAW_WEAPON) k = THROWSAW_WEAPON;
else if (k == SLINGBLADE_WEAPON) k = KNEE_WEAPON; else if (k == SLINGBLADE_WEAPON) k = KNEE_WEAPON;
} }
j = (j == 10 ? -1 : 1); j = (weap == WeaponSel_Prev ? -1 : 1); // JBF: prev (-1) or next (1) weapon choice
i = 0; i = 0;
while (k >= 0 && k < 10) while (k >= 0 && k < 10)
@ -987,10 +991,10 @@ void selectweapon_r(int snum, int j)
} }
} }
} }
else j = weap - 1;
k = -1; k = -1;
if (j == DYNAMITE_WEAPON && p->ammo_amount[DYNAMITE_WEAPON] == 0) if (j == DYNAMITE_WEAPON && p->ammo_amount[DYNAMITE_WEAPON] == 0)
{ {
k = headspritestat[1]; k = headspritestat[1];

View file

@ -36,7 +36,6 @@ BEGIN_SW_NS
SWBOOL MultiPlayQuitFlag = FALSE; SWBOOL MultiPlayQuitFlag = FALSE;
int WeaponToSend = 0;
int BitsToSend = 0; int BitsToSend = 0;
int inv_hotkey = 0; int inv_hotkey = 0;
@ -172,6 +171,9 @@ getinput(InputPacket *loc, SWBOOL tied)
// for dividing controller input to match speed input speed of other games. // for dividing controller input to match speed input speed of other games.
float const ticrateScale = 0.75f; float const ticrateScale = 0.75f;
ApplyGlobalInput(*loc, &info);
if (running) if (running)
{ {
if (pp->sop_control) if (pp->sop_control)
@ -341,18 +343,12 @@ getinput(InputPacket *loc, SWBOOL tied)
SET_LOC_KEY(loc->bits, SK_LOOK_UP, buttonMap.ButtonDown(gamefunc_Look_Up)); SET_LOC_KEY(loc->bits, SK_LOOK_UP, buttonMap.ButtonDown(gamefunc_Look_Up));
SET_LOC_KEY(loc->bits, SK_LOOK_DOWN, buttonMap.ButtonDown(gamefunc_Look_Down)); SET_LOC_KEY(loc->bits, SK_LOOK_DOWN, buttonMap.ButtonDown(gamefunc_Look_Down));
if (WeaponToSend > 0) if (loc->getNewWeapon() == WeaponSel_Next)
{
loc->SetNewWeapon(WeaponToSend);
WeaponToSend = 0;
}
else if (WeaponToSend == -1)
{ {
USERp u = User[pp->PlayerSprite]; USERp u = User[pp->PlayerSprite];
short next_weapon = u->WeaponNum + 1; short next_weapon = u->WeaponNum + 1;
short start_weapon; short start_weapon;
WeaponToSend = 0;
start_weapon = u->WeaponNum + 1; start_weapon = u->WeaponNum + 1;
if (u->WeaponNum == WPN_SWORD) if (u->WeaponNum == WPN_SWORD)
@ -381,16 +377,14 @@ getinput(InputPacket *loc, SWBOOL tied)
} }
} }
SET(loc->bits, next_weapon + 1); loc->setNewWeapon(next_weapon + 1);
} }
else if (WeaponToSend == -2) else if (loc->getNewWeapon() == WeaponSel_Prev)
{ {
USERp u = User[pp->PlayerSprite]; USERp u = User[pp->PlayerSprite];
short prev_weapon = u->WeaponNum - 1; short prev_weapon = u->WeaponNum - 1;
short start_weapon; short start_weapon;
WeaponToSend = 0;
start_weapon = u->WeaponNum - 1; start_weapon = u->WeaponNum - 1;
if (u->WeaponNum == WPN_SWORD) if (u->WeaponNum == WPN_SWORD)
@ -416,16 +410,13 @@ getinput(InputPacket *loc, SWBOOL tied)
} }
} }
} }
loc->setNewWeapon(prev_weapon + 1);
SET(loc->bits, prev_weapon + 1);
} }
else if (loc->getNewWeapon() == WeaponSel_Alt)
if (false)//buttonMap.ButtonDown(gamefunc_Alt_Weapon)) will be renabled in an upcoming commit.
{ {
//buttonMap.ClearButton(gamefunc_Alt_Weapon);
USERp u = User[pp->PlayerSprite]; USERp u = User[pp->PlayerSprite];
short const which_weapon = u->WeaponNum + 1; short const which_weapon = u->WeaponNum + 1;
SET(loc->bits, which_weapon); loc->setNewWeapon(which_weapon);
} }
@ -480,25 +471,8 @@ getinput(InputPacket *loc, SWBOOL tied)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
static int ccmd_slot(CCmdFuncPtr parm)
{
if (parm->numparms != 1) return CCMD_SHOWHELP;
auto slot = atoi(parm->parms[0]);
if (slot >= 1 && slot <= 10)
{
WeaponToSend = slot;
return CCMD_OK;
}
return CCMD_SHOWHELP;
}
void registerinputcommands() void registerinputcommands()
{ {
C_RegisterFunction("slot", "slot <weaponslot>: select a weapon from the given slot (1-10)", ccmd_slot);
C_RegisterFunction("weapprev", nullptr, [](CCmdFuncPtr)->int { WeaponToSend = -2; return CCMD_OK; });
C_RegisterFunction("weapnext", nullptr, [](CCmdFuncPtr)->int { WeaponToSend = -1; return CCMD_OK; });
C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_PAUSE); sendPause = true; return CCMD_OK; }); C_RegisterFunction("pause", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= BIT(SK_PAUSE); sendPause = true; return CCMD_OK; });
C_RegisterFunction("smoke_bomb", nullptr, [](CCmdFuncPtr)->int { inv_hotkey = INVENTORY_CLOAK + 1; return CCMD_OK; }); C_RegisterFunction("smoke_bomb", nullptr, [](CCmdFuncPtr)->int { inv_hotkey = INVENTORY_CLOAK + 1; return CCMD_OK; });
C_RegisterFunction("nightvision", nullptr, [](CCmdFuncPtr)->int { inv_hotkey = INVENTORY_NIGHT_VISION + 1; return CCMD_OK; }); C_RegisterFunction("nightvision", nullptr, [](CCmdFuncPtr)->int { inv_hotkey = INVENTORY_NIGHT_VISION + 1; return CCMD_OK; });
@ -517,7 +491,6 @@ void registerinputcommands()
// This is called from ImputState::ClearAllInput and resets all static state being used here. // This is called from ImputState::ClearAllInput and resets all static state being used here.
void GameInterface::clearlocalinputstate() void GameInterface::clearlocalinputstate()
{ {
WeaponToSend = 0;
BitsToSend = 0; BitsToSend = 0;
inv_hotkey = 0; inv_hotkey = 0;