mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
Improve interaction between cheat entry and player input
git-svn-id: https://svn.eduke32.com/eduke32@8369 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # source/duke3d/src/cheats.cpp # source/duke3d/src/player.cpp
This commit is contained in:
parent
cf0a74a888
commit
c851da92a6
3 changed files with 33 additions and 26 deletions
|
@ -22,9 +22,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
#include "ns.h" // Must come before everything else!
|
#include "ns.h" // Must come before everything else!
|
||||||
|
|
||||||
|
#include "cheats.h"
|
||||||
|
|
||||||
#include "duke3d.h"
|
#include "duke3d.h"
|
||||||
#include "osdcmds.h"
|
#include "osdcmds.h"
|
||||||
#include "cheats.h"
|
|
||||||
|
|
||||||
BEGIN_DUKE_NS
|
BEGIN_DUKE_NS
|
||||||
|
|
||||||
|
@ -242,10 +243,12 @@ static void G_CheatGetInv(DukePlayer_t *pPlayer)
|
||||||
static void end_cheat(DukePlayer_t * const pPlayer)
|
static void end_cheat(DukePlayer_t * const pPlayer)
|
||||||
{
|
{
|
||||||
pPlayer->cheat_phase = 0;
|
pPlayer->cheat_phase = 0;
|
||||||
|
g_cheatBufLen = 0;
|
||||||
inputState.keyFlushChars();
|
inputState.keyFlushChars();
|
||||||
|
KB_ClearKeysDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t cheatbuflen;
|
int g_cheatBufLen;
|
||||||
static int8_t cheatbuf[MAXCHEATLEN];
|
static int8_t cheatbuf[MAXCHEATLEN];
|
||||||
|
|
||||||
void G_DoCheats(void)
|
void G_DoCheats(void)
|
||||||
|
@ -311,31 +314,33 @@ void G_DoCheats(void)
|
||||||
if (!((ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')))
|
if (!((ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')))
|
||||||
{
|
{
|
||||||
pPlayer->cheat_phase = 0;
|
pPlayer->cheat_phase = 0;
|
||||||
|
g_cheatBufLen = 0;
|
||||||
// P_DoQuote(QUOTE_46,pPlayer);
|
// P_DoQuote(QUOTE_46,pPlayer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cheatbuf[cheatbuflen++] = (int8_t) ch;
|
cheatbuf[g_cheatBufLen++] = (int8_t) ch;
|
||||||
// This assertion is not obvious, but it should hold because of the
|
// This assertion is not obvious, but it should hold because of the
|
||||||
// cheat string matching logic below.
|
// cheat string matching logic below.
|
||||||
Bassert(cheatbuflen < (signed)sizeof(cheatbuf));
|
Bassert(g_cheatBufLen < (signed)sizeof(cheatbuf));
|
||||||
cheatbuf[cheatbuflen] = 0;
|
cheatbuf[g_cheatBufLen] = 0;
|
||||||
// inputState.ClearKeysDown();
|
// inputState.ClearKeysDown();
|
||||||
|
|
||||||
for (cheatNum=0; cheatNum < NUMCHEATCODES; cheatNum++)
|
for (cheatNum=0; cheatNum < NUMCHEATCODES; cheatNum++)
|
||||||
{
|
{
|
||||||
for (bssize_t j = 0; j<cheatbuflen; j++)
|
for (bssize_t j = 0; j<g_cheatBufLen; j++)
|
||||||
{
|
{
|
||||||
if (cheatbuf[j] == CheatStrings[cheatNum][j] || (CheatStrings[cheatNum][j] == '#' && ch >= '0' && ch <= '9'))
|
if (cheatbuf[j] == CheatStrings[cheatNum][j] || (CheatStrings[cheatNum][j] == '#' && ch >= '0' && ch <= '9'))
|
||||||
{
|
{
|
||||||
if (CheatStrings[cheatNum][j+1] == 0) goto FOUNDCHEAT;
|
if (CheatStrings[cheatNum][j+1] == 0) goto FOUNDCHEAT;
|
||||||
if (j == cheatbuflen-1) return;
|
if (j == g_cheatBufLen-1) return;
|
||||||
}
|
}
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pPlayer->cheat_phase = 0;
|
pPlayer->cheat_phase = 0;
|
||||||
|
g_cheatBufLen = 0;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FOUNDCHEAT:;
|
FOUNDCHEAT:;
|
||||||
|
@ -458,8 +463,7 @@ void G_DoCheats(void)
|
||||||
|
|
||||||
case CHEAT_ALLEN:
|
case CHEAT_ALLEN:
|
||||||
P_DoQuote(QUOTE_CHEAT_ALLEN, pPlayer);
|
P_DoQuote(QUOTE_CHEAT_ALLEN, pPlayer);
|
||||||
pPlayer->cheat_phase = 0;
|
end_cheat(pPlayer);
|
||||||
inputState.ClearKeyStatus(sc_N);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case CHEAT_CORNHOLIO:
|
case CHEAT_CORNHOLIO:
|
||||||
|
@ -622,8 +626,7 @@ void G_DoCheats(void)
|
||||||
|
|
||||||
case CHEAT_CASHMAN:
|
case CHEAT_CASHMAN:
|
||||||
ud.cashman = 1-ud.cashman;
|
ud.cashman = 1-ud.cashman;
|
||||||
inputState.ClearKeyStatus(sc_N);
|
end_cheat(pPlayer);
|
||||||
pPlayer->cheat_phase = 0;
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case CHEAT_ITEMS:
|
case CHEAT_ITEMS:
|
||||||
|
@ -666,7 +669,6 @@ void G_DoCheats(void)
|
||||||
|
|
||||||
case CHEAT_BETA:
|
case CHEAT_BETA:
|
||||||
P_DoQuote(QUOTE_CHEAT_BETA, pPlayer);
|
P_DoQuote(QUOTE_CHEAT_BETA, pPlayer);
|
||||||
inputState.ClearKeyStatus(sc_H);
|
|
||||||
end_cheat(pPlayer);
|
end_cheat(pPlayer);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -695,8 +697,8 @@ void G_DoCheats(void)
|
||||||
case CHEAT_RESERVED3:
|
case CHEAT_RESERVED3:
|
||||||
ud.eog = 1;
|
ud.eog = 1;
|
||||||
pPlayer->player_par = 0;
|
pPlayer->player_par = 0;
|
||||||
pPlayer->gm |= MODE_EOL;
|
pPlayer->gm |= MODE_EOL;;
|
||||||
inputState.keyFlushChars();
|
end_cheat(pPlayer);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -731,13 +733,14 @@ void G_DoCheats(void)
|
||||||
{
|
{
|
||||||
pPlayer->cheat_phase = 1;
|
pPlayer->cheat_phase = 1;
|
||||||
// P_DoQuote(QUOTE_25,pPlayer);
|
// P_DoQuote(QUOTE_25,pPlayer);
|
||||||
cheatbuflen = 0;
|
|
||||||
}
|
}
|
||||||
|
g_cheatBufLen = 0;
|
||||||
inputState.keyFlushChars();
|
inputState.keyFlushChars();
|
||||||
}
|
}
|
||||||
else if (pPlayer->cheat_phase != 0)
|
else if (pPlayer->cheat_phase != 0)
|
||||||
{
|
{
|
||||||
pPlayer->cheat_phase = 0;
|
pPlayer->cheat_phase = 0;
|
||||||
|
g_cheatBufLen = 0;
|
||||||
inputState.ClearKeyStatus((uint8_t) CheatKeys[0]);
|
inputState.ClearKeyStatus((uint8_t) CheatKeys[0]);
|
||||||
inputState.ClearKeyStatus((uint8_t) CheatKeys[1]);
|
inputState.ClearKeyStatus((uint8_t) CheatKeys[1]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,9 @@ BEGIN_DUKE_NS
|
||||||
#define MAXCHEATDESC 64
|
#define MAXCHEATDESC 64
|
||||||
#define NUMCHEATCODES (int32_t) ARRAY_SIZE(CheatStrings)
|
#define NUMCHEATCODES (int32_t) ARRAY_SIZE(CheatStrings)
|
||||||
|
|
||||||
extern void G_DoCheats(void);
|
void G_DoCheats(void);
|
||||||
extern void G_SetupCheats(void);
|
void G_SetupCheats(void);
|
||||||
|
extern int g_cheatBufLen;
|
||||||
|
|
||||||
enum cheatindex_t
|
enum cheatindex_t
|
||||||
{
|
{
|
||||||
|
|
|
@ -2894,7 +2894,7 @@ void P_GetInput(int const playerNum)
|
||||||
auto const pPlayer = g_player[playerNum].ps;
|
auto const pPlayer = g_player[playerNum].ps;
|
||||||
ControlInfo info;
|
ControlInfo info;
|
||||||
|
|
||||||
if ((pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !inputState.GetKeyStatus(sc_Pause)))
|
if (g_cheatBufLen > 1 || (pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !inputState.GetKeyStatus(sc_Pause)))
|
||||||
{
|
{
|
||||||
if (!(pPlayer->gm&MODE_MENU))
|
if (!(pPlayer->gm&MODE_MENU))
|
||||||
CONTROL_GetInput(&info);
|
CONTROL_GetInput(&info);
|
||||||
|
@ -3024,20 +3024,23 @@ void P_GetInput(int const playerNum)
|
||||||
int const sectorLotag = pPlayer->cursectnum != -1 ? sector[pPlayer->cursectnum].lotag : 0;
|
int const sectorLotag = pPlayer->cursectnum != -1 ? sector[pPlayer->cursectnum].lotag : 0;
|
||||||
int const crouchable = sectorLotag != 2 && (sectorLotag != 1 || pPlayer->spritebridge);
|
int const crouchable = sectorLotag != 2 && (sectorLotag != 1 || pPlayer->spritebridge);
|
||||||
|
|
||||||
if (pPlayer->cheat_phase == 0 && buttonMap.ButtonDown(gamefunc_Toggle_Crouch))
|
if (pPlayer->cheat_phase < 1)
|
||||||
{
|
{
|
||||||
pPlayer->crouch_toggle = !pPlayer->crouch_toggle && crouchable;
|
if (buttonMap.ButtonDown(gamefunc_Toggle_Crouch))
|
||||||
|
{
|
||||||
|
pPlayer->crouch_toggle = !pPlayer->crouch_toggle && crouchable;
|
||||||
|
|
||||||
if (crouchable)
|
if (crouchable)
|
||||||
buttonMap.ClearButton(gamefunc_Toggle_Crouch);
|
buttonMap.ClearButton(gamefunc_Toggle_Crouch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || pPlayer->jetpack_on || (!crouchable && pPlayer->on_ground))
|
if (buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Jump) || pPlayer->jetpack_on || (!crouchable && pPlayer->on_ground))
|
||||||
pPlayer->crouch_toggle = 0;
|
pPlayer->crouch_toggle = 0;
|
||||||
|
|
||||||
int const crouching = buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle;
|
int const crouching = buttonMap.ButtonDown(gamefunc_Crouch) || buttonMap.ButtonDown(gamefunc_Toggle_Crouch) || pPlayer->crouch_toggle;
|
||||||
|
|
||||||
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Jump) << SK_JUMP) | (crouching << SK_CROUCH);
|
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Jump) << SK_JUMP) | (crouching << SK_CROUCH);
|
||||||
|
}
|
||||||
|
|
||||||
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && input.fvel > 0)) << SK_AIM_UP;
|
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Aim_Up) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && input.fvel > 0)) << SK_AIM_UP;
|
||||||
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && input.fvel < 0)) << SK_AIM_DOWN;
|
localInput.bits |= (buttonMap.ButtonDown(gamefunc_Aim_Down) || (buttonMap.ButtonDown(gamefunc_Dpad_Aiming) && input.fvel < 0)) << SK_AIM_DOWN;
|
||||||
|
|
Loading…
Reference in a new issue