diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 7d8c42e27..44c2fe282 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -525,14 +525,16 @@ void ProcessFrame(void) char buffer[128]; for (int i = connecthead; i >= 0; i = connectpoint2[i]) { - gPlayer[i].input.syncFlags.value &= ~flag_buttonmask; - gPlayer[i].input.syncFlags.value |= gFifoInput[gNetFifoTail & 255][i].syncFlags.value; - int newweap = gFifoInput[gNetFifoTail & 255][i].getNewWeapon(); - if (newweap) gPlayer[i].newWeapon = newweap; - gPlayer[i].input.fvel = gFifoInput[gNetFifoTail&255][i].fvel; - gPlayer[i].input.q16avel = gFifoInput[gNetFifoTail&255][i].q16avel; - gPlayer[i].input.svel = gFifoInput[gNetFifoTail&255][i].svel; - gPlayer[i].input.q16horz = gFifoInput[gNetFifoTail&255][i].q16horz; + auto& inp = gPlayer[i].input; + auto oldactions = inp.actions; + auto oldflags = inp.syncFlags.value; + + inp = gFifoInput[gNetFifoTail & 255][i]; + inp.actions |= oldactions & SB_INTERFACE_MASK; // should be everything non-button and non-weapon + inp.syncFlags.value |= oldflags & ~flag_buttonmask; + + int newweap = inp.getNewWeapon(); + if (newweap > 0 && newweap < WeaponSel_MaxBlood) gPlayer[i].newWeapon = newweap; } gNetFifoTail++; diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index ca622d62c..c0571cea4 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -150,8 +150,7 @@ void ctrlGetInput(void) gInput.syncFlags.quit = 1; gInput.syncFlags.value |= BitsToSend.value; - if (WeaponToSend != 0) - gInput.SetNewWeapon(WeaponToSend); + ApplyGlobalInput(gInput, &info); BitsToSend.value = 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() { - C_RegisterFunction("slot", "slot : 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("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("medkit", nullptr, [](CCmdFuncPtr)->int { BitsToSend.useMedKit = 1; return CCMD_OK; }); C_RegisterFunction("centerview", nullptr, [](CCmdFuncPtr)->int { BitsToSend.lookCenter = 1; return CCMD_OK; }); diff --git a/source/blood/src/player.cpp b/source/blood/src/player.cpp index d277249a8..f9a692621 100644 --- a/source/blood/src/player.cpp +++ b/source/blood/src/player.cpp @@ -1331,7 +1331,7 @@ void ProcessInput(PLAYER *pPlayer) pPlayer->q16horiz = mulscale16(0x8000-(Cos(ClipHigh(pPlayer->deathTime*8, 1024))>>15), fix16_from_int(120)); } if (pPlayer->curWeapon) - pInput->SetNewWeapon(pPlayer->curWeapon); + pInput->setNewWeapon(pPlayer->curWeapon); if (pInput->syncFlags.action) { if (bSeqStat) diff --git a/source/blood/src/player.h b/source/blood/src/player.h index f90fe6900..5fe05a22d 100644 --- a/source/blood/src/player.h +++ b/source/blood/src/player.h @@ -119,8 +119,8 @@ struct PLAYER char hasFlag; short used2[8]; // ?? int damageControl[7]; - char curWeapon; - char nextWeapon; + int8_t curWeapon; + int8_t nextWeapon; int weaponTimer; int weaponState; int weaponAmmo; //rename diff --git a/source/blood/src/weapon.cpp b/source/blood/src/weapon.cpp index 76cd93f5a..581486447 100644 --- a/source/blood/src/weapon.cpp +++ b/source/blood/src/weapon.cpp @@ -2026,9 +2026,9 @@ void WeaponProcess(PLAYER *pPlayer) { pPlayer->newWeapon = pPlayer->nextWeapon; 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->nextWeapon = 0; int t; @@ -2042,9 +2042,9 @@ void WeaponProcess(PLAYER *pPlayer) { } 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->nextWeapon = 0; int t; @@ -2058,6 +2058,10 @@ void WeaponProcess(PLAYER *pPlayer) { } pPlayer->newWeapon = weapon; } + else if (pPlayer->input.getNewWeapon() == WeaponSel_Alt) + { + // todo + } if (pPlayer->weaponState == -1) { pPlayer->weaponState = 0; diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index b437ba160..e9921e54a 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -41,6 +41,8 @@ #include"packet.h" #include "gamecontrol.h" +static int WeaponToSend = 0; + //========================================================================== // // @@ -220,3 +222,58 @@ void SetupGameButtons() 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 : 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; + } + +} \ No newline at end of file diff --git a/source/core/inputstate.h b/source/core/inputstate.h index 161fa31b8..221b48204 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -11,6 +11,7 @@ #include "d_event.h" #include "m_joy.h" #include "gamecvars.h" +#include "packet.h" struct ControlInfo @@ -98,3 +99,5 @@ enum GameFunction_t }; void SetupGameButtons(); +void ApplyGlobalInput(InputPacket& input, ControlInfo *info); + diff --git a/source/core/packet.h b/source/core/packet.h index 0ffbc6fb1..7942aa965 100644 --- a/source/core/packet.h +++ b/source/core/packet.h @@ -4,14 +4,15 @@ #include "fix16.h" #include "tflags.h" - enum ESyncBits_ : uint32_t { SB_FIRST_WEAPON_BIT = 1 << 0, 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. @@ -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 { SKB_JUMP = 1 << 0, @@ -88,8 +103,6 @@ union SYNCFLAGS unsigned int prevItem : 1; unsigned int nextItem : 1; unsigned int useItem : 1; - unsigned int prevWeapon : 1; - unsigned int nextWeapon : 1; unsigned int holsterWeapon : 1; unsigned int lookCenter : 1; unsigned int lookLeft : 1; @@ -193,8 +206,10 @@ struct InputPacket 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); } }; + + diff --git a/source/exhumed/src/exhumed.cpp b/source/exhumed/src/exhumed.cpp index 12c09a06b..78d7e0f17 100644 --- a/source/exhumed/src/exhumed.cpp +++ b/source/exhumed/src/exhumed.cpp @@ -46,6 +46,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "screenjob.h" #include "c_console.h" #include "cheathandler.h" +#include "inputstate.h" #include "core/menu/menu.h" BEGIN_PS_NS @@ -466,6 +467,23 @@ void GameMove(void) 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() { @@ -496,6 +514,19 @@ void GameTicker() lPlayerXVel -= (lPlayerXVel >> 5) + (lPlayerXVel >> 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].yVel = lPlayerYVel; @@ -503,7 +534,6 @@ void GameTicker() sPlayerInput[nLocalPlayer].buttons = lLocalButtons | lLocalCodes; int weap = sPlayerInput[nLocalPlayer].getNewWeapon(); sPlayerInput[nLocalPlayer].actions = localInput.actions; - int weap2 = localInput.getNewWeapon(); if (weap2 <= 0 || weap2 > 7) sPlayerInput[nLocalPlayer].SetNewWeapon(weap); sPlayerInput[nLocalPlayer].nTarget = besttarget; diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp index eb1d6fff9..fe48d7f34 100644 --- a/source/exhumed/src/input.cpp +++ b/source/exhumed/src/input.cpp @@ -31,7 +31,7 @@ BEGIN_PS_NS extern short bPlayerPan; extern short bLockPan; -int WeaponToSend, BitsToSend; +int BitsToSend; bool g_MyAimMode; short nInputStack = 0; @@ -187,6 +187,12 @@ void PlayerInterruptKeys(bool after) return; } + if (!after) + { + ApplyGlobalInput(localInput, &info); + } + + // JBF: Run key behaviour is selectable int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); int const turnAmount = playerRunning ? 12 : 8; @@ -280,13 +286,6 @@ void PlayerInterruptKeys(bool after) localInput.q16avel = fix16_sadd(localInput.q16avel, input_angle); - if (!after) - { - if (WeaponToSend > 0) - localInput.SetNewWeapon(WeaponToSend); - WeaponToSend = 0; - } - if (!nFreeze) { 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); void registerinputcommands() { - C_RegisterFunction("slot", "slot : 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("centerview", nullptr, ccmd_centerview); 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("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. 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. void GameInterface::clearlocalinputstate() { - WeaponToSend = 0; BitsToSend = 0; } diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 4343e7e05..4fa868bc2 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -39,7 +39,6 @@ source as it is released. BEGIN_DUKE_NS -static int WeaponToSend; static EDukeSyncBits BitsToSend; // State timer counters. @@ -146,7 +145,6 @@ void hud_input(int snum) { int i, k; uint8_t dainv; - unsigned int j; struct player_struct* p; short unk; @@ -339,16 +337,12 @@ void hud_input(int snum) if (dainv >= 1 && dainv < 8) FTA(invquotes[dainv - 1], p); } - j = PlayerNewWeapon(snum) - 1; - if (j >= 0) - { - int a = 0; - } - if (j > 0 && p->kickback_pic > 0) - p->wantweaponfire = j; + int weap = PlayerNewWeapon(snum); + if (weap > 1 && p->kickback_pic > 0) + p->wantweaponfire = weap - 1; // 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)) { @@ -467,7 +461,7 @@ void hud_input(int snum) { 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) { @@ -485,7 +479,7 @@ void hud_input(int snum) } else { - j = 10; + int j = 10; if (p->firstaid_amount > j) { p->firstaid_amount -= j; @@ -631,7 +625,7 @@ static void processInputBits(player_struct *p, ControlInfo &info) loc.sbits |= BitsToSend; 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_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 (in_mousemode || buttonMap.ButtonDown(gamefunc_Mouse_Aiming)) loc.sbits |= SKB_AIMMODE; - int j = WeaponToSend; - 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; + ApplyGlobalInput(loc, &info); } 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() { - C_RegisterFunction("slot", "slot : 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("steroids", nullptr, [](CCmdFuncPtr)->int { BitsToSend |= SKB_STEROIDS; 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. void GameInterface::clearlocalinputstate() { - WeaponToSend = 0; BitsToSend = 0; nonsharedtimer = 0; turnheldtime = 0; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 06cf66eb6..521f1540b 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -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]; 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 (j == 10 || j == 11) + if (weap == WeaponSel_Alt) + { + // todo + } + else if (weap == WeaponSel_Next || weap == WeaponSel_Prev) { 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; 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 (k == SHRINKER_WEAPON && (p->subweapon & (1 << GROW_WEAPON))) k = GROW_WEAPON; - if (isWorldTour() && k == FREEZE_WEAPON && (p->subweapon & (1 << FLAMETHROWER_WEAPON)) != 0) - k = FLAMETHROWER_WEAPON; + if (isWorldTour() && k == FREEZE_WEAPON && (p->subweapon & (1 << FLAMETHROWER_WEAPON)) != 0) + k = FLAMETHROWER_WEAPON; j = k; break; @@ -1186,10 +1190,10 @@ void selectweapon_d(int snum, int j) // playernum, weaponnum } } } + else j = weap - 1; k = -1; - if (j == HANDBOMB_WEAPON && p->ammo_amount[HANDBOMB_WEAPON] == 0) { k = headspritestat[1]; diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index abd1ba1bc..e176dab8f 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -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]; 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 (j == 10 || j == 11) + if (weap == WeaponSel_Alt) + { + // todo + } + else if (weap == WeaponSel_Next || weap == WeaponSel_Prev) { k = p->curr_weapon; if (isRRRA()) @@ -964,7 +968,7 @@ void selectweapon_r(int snum, int j) else if (k == BUZZSAW_WEAPON) k = THROWSAW_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; while (k >= 0 && k < 10) @@ -987,10 +991,10 @@ void selectweapon_r(int snum, int j) } } } + else j = weap - 1; k = -1; - if (j == DYNAMITE_WEAPON && p->ammo_amount[DYNAMITE_WEAPON] == 0) { k = headspritestat[1]; diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index b92554978..bb922ee02 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -36,7 +36,6 @@ BEGIN_SW_NS SWBOOL MultiPlayQuitFlag = FALSE; -int WeaponToSend = 0; int BitsToSend = 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. float const ticrateScale = 0.75f; + ApplyGlobalInput(*loc, &info); + + if (running) { 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_DOWN, buttonMap.ButtonDown(gamefunc_Look_Down)); - if (WeaponToSend > 0) - { - loc->SetNewWeapon(WeaponToSend); - WeaponToSend = 0; - } - else if (WeaponToSend == -1) + if (loc->getNewWeapon() == WeaponSel_Next) { USERp u = User[pp->PlayerSprite]; short next_weapon = u->WeaponNum + 1; short start_weapon; - WeaponToSend = 0; start_weapon = u->WeaponNum + 1; 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]; short prev_weapon = u->WeaponNum - 1; short start_weapon; - WeaponToSend = 0; - start_weapon = u->WeaponNum - 1; if (u->WeaponNum == WPN_SWORD) @@ -416,16 +410,13 @@ getinput(InputPacket *loc, SWBOOL tied) } } } - - SET(loc->bits, prev_weapon + 1); + loc->setNewWeapon(prev_weapon + 1); } - - if (false)//buttonMap.ButtonDown(gamefunc_Alt_Weapon)) will be renabled in an upcoming commit. + else if (loc->getNewWeapon() == WeaponSel_Alt) { - //buttonMap.ClearButton(gamefunc_Alt_Weapon); USERp u = User[pp->PlayerSprite]; 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() { - C_RegisterFunction("slot", "slot : 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("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; }); @@ -517,7 +491,6 @@ void registerinputcommands() // This is called from ImputState::ClearAllInput and resets all static state being used here. void GameInterface::clearlocalinputstate() { - WeaponToSend = 0; BitsToSend = 0; inv_hotkey = 0;