Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom weapon slots feature #1923

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ set(WOOF_SOURCES
w_zip.c
wi_stuff.c wi_stuff.h
wi_interlvl.c wi_interlvl.h
ws_stuff.c ws_stuff.h
z_zone.c z_zone.h)

# Standard target definition
Expand Down
24 changes: 16 additions & 8 deletions src/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "v_flextran.h"
#include "v_fmt.h"
#include "v_video.h"
#include "ws_stuff.h"
#include "z_zone.h"

//jff 1/7/98 default automap colors added
Expand Down Expand Up @@ -794,7 +795,7 @@ boolean AM_Responder

if (!automapactive)
{
if (M_InputActivated(input_map))
if (M_InputActivated(input_map) && !WS_Override())
{
AM_Start ();
viewactive = false;
Expand All @@ -808,22 +809,22 @@ boolean AM_Responder
rc = true;
// phares
if (M_InputActivated(input_map_right)) // |
if (!followplayer) // V
if (!followplayer && !WS_HoldOverride()) // V
buttons_state[PAN_RIGHT] = 1;
else
rc = false;
else if (M_InputActivated(input_map_left))
if (!followplayer)
if (!followplayer && !WS_HoldOverride())
buttons_state[PAN_LEFT] = 1;
else
rc = false;
else if (M_InputActivated(input_map_up))
if (!followplayer)
if (!followplayer && !WS_HoldOverride())
buttons_state[PAN_UP] = 1;
else
rc = false;
else if (M_InputActivated(input_map_down))
if (!followplayer)
if (!followplayer && !WS_HoldOverride())
buttons_state[PAN_DOWN] = 1;
else
rc = false;
Expand Down Expand Up @@ -851,9 +852,16 @@ boolean AM_Responder
}
else if (M_InputActivated(input_map))
{
bigstate = 0;
viewactive = true;
AM_Stop ();
if (!WS_Override())
{
bigstate = 0;
viewactive = true;
AM_Stop ();
}
else
{
rc = false;
}
}
else if (M_InputActivated(input_map_gobig))
{
Expand Down
2 changes: 2 additions & 0 deletions src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "v_video.h"
#include "w_wad.h"
#include "wi_stuff.h"
#include "ws_stuff.h"
#include "z_zone.h"

// DEHacked support - Ty 03/09/97
Expand Down Expand Up @@ -2439,6 +2440,7 @@ void D_DoomMain(void)
G_UpdateGamepadVariables();
G_UpdateMouseVariables();
R_UpdateViewAngleFunction();
WS_Init();

MN_ResetTimeScale();

Expand Down
1 change: 1 addition & 0 deletions src/doomkeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// This is the stuff configured by Setup.Exe.
// Most key data are simple ascii (uppercased).
//
#define NUMKEYS 256
#define KEY_RIGHTARROW 0xae
#define KEY_LEFTARROW 0xac
#define KEY_UPARROW 0xad
Expand Down
31 changes: 24 additions & 7 deletions src/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#include "version.h"
#include "w_wad.h"
#include "wi_stuff.h"
#include "ws_stuff.h"
#include "z_zone.h"

#define SAVEGAMESIZE 0x20000
Expand Down Expand Up @@ -188,7 +189,6 @@ static boolean dclick_use;
#define TURBOTHRESHOLD 0x32
#define SLOWTURNTICS 6
#define QUICKREVERSE 32768 // 180 degree reverse // phares
#define NUMKEYS 256

fixed_t forwardmove[2] = {0x19, 0x32};
fixed_t default_sidemove[2] = {0x18, 0x28};
Expand Down Expand Up @@ -857,6 +857,10 @@ void G_BuildTiccmd(ticcmd_t* cmd)
boom_weapon_state_injection = false;
newweapon = P_SwitchWeapon(&players[consoleplayer]); // phares
}
else if (WS_SlotSelected())
{
newweapon = WS_SlotWeapon();
}
else if (M_InputGameActive(input_lastweapon))
{
newweapon = LastWeapon();
Expand Down Expand Up @@ -899,6 +903,7 @@ void G_BuildTiccmd(ticcmd_t* cmd)

// [FG] prev/next weapon keys and buttons
next_weapon = 0;
WS_ClearSharedEvent();

// [FG] double click acts as "use"
if (dclick)
Expand Down Expand Up @@ -946,6 +951,7 @@ void G_ClearInput(void)
memset(&basecmd, 0, sizeof(basecmd));
I_ResetRelativeMouseState();
I_ResetAllRumbleChannels();
WS_Reset();
}

//
Expand Down Expand Up @@ -1316,6 +1322,23 @@ boolean G_MovementResponder(event_t *ev)

boolean G_Responder(event_t* ev)
{
WS_UpdateState(ev);

// killough 9/29/98: reformatted
if (gamestate == GS_LEVEL
&& (HU_Responder(ev) || // chat ate the event
ST_Responder(ev) || // status window ate it
AM_Responder(ev) || // automap ate it
WS_Responder(ev))) // weapon slots ate it
{
return true;
}

if (M_ShortcutResponder(ev))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why is it necessary to move ShortcutResponder here? I want to refactor it someday, the “function keys” belong to mn_menu.c and the rest somewhere else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anything break with this change? If weapon slots are enabled, they have to conditionally override other inputs. For example, if I hold RB, I don't want PadX to toggle stats.

The input priority in Woof (and most Doom ports to be fair) is a little confusing. It seems like most of the ShortcutResponder inputs don't belong in the menu responder at all. And there are menu related inputs in the game responder. Reviewing this in the future is probably a good idea.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The input priority in Woof (and most Doom ports to be fair) is a little confusing. It seems like most of the ShortcutResponder inputs don't belong in the menu responder at all. And there are menu related inputs in the game responder. Reviewing this in the future is probably a good idea.

I agree.

Does anything break with this change?

Probably not, but there are many “shortcut keys” to check.

{
return true;
}

// allow spy mode changes even during the demo
// killough 2/22/98: even during DM demo
//
Expand Down Expand Up @@ -1346,12 +1369,6 @@ boolean G_Responder(event_t* ev)
return true;
}

// killough 9/29/98: reformatted
if (gamestate == GS_LEVEL && (HU_Responder(ev) || // chat ate the event
ST_Responder(ev) || // status window ate it
AM_Responder(ev))) // automap ate it
return true;

// any other key pops up menu if in demos
//
// killough 8/2/98: enable automap in -timedemo demos
Expand Down
21 changes: 20 additions & 1 deletion src/i_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

static SDL_GameController *gamepad;
static boolean gyro_supported;
static joy_platform_t platform;

// [FG] adapt joystick button and axis handling from Chocolate Doom 3.0

Expand Down Expand Up @@ -265,9 +266,27 @@ static joy_platform_t GetSwitchSubPlatform(void)
return PLATFORM_SWITCH_PRO;
}

void I_GetFaceButtons(int *buttons)
{
if (platform < PLATFORM_SWITCH)
{
buttons[0] = GAMEPAD_Y;
buttons[1] = GAMEPAD_A;
buttons[2] = GAMEPAD_X;
buttons[3] = GAMEPAD_B;
}
else
{
buttons[0] = GAMEPAD_X;
buttons[1] = GAMEPAD_B;
buttons[2] = GAMEPAD_Y;
buttons[3] = GAMEPAD_A;
}
}

static void UpdatePlatform(void)
{
joy_platform_t platform = joy_platform;
platform = joy_platform;

if (platform == PLATFORM_AUTO)
{
Expand Down
1 change: 1 addition & 0 deletions src/i_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum evtype_e;
int I_GetAxisState(int axis);
boolean I_UseGamepad(void);
boolean I_GyroSupported(void);
void I_GetFaceButtons(int *buttons);
void I_FlushGamepadSensorEvents(void);
void I_FlushGamepadEvents(void);
void I_SetSensorEventState(boolean condition);
Expand Down
4 changes: 4 additions & 0 deletions src/m_cheat.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "tables.h"
#include "u_mapinfo.h"
#include "w_wad.h"
#include "ws_stuff.h"

#define plyr (players+consoleplayer) /* the console player */

Expand Down Expand Up @@ -1312,6 +1313,9 @@ boolean M_CheatResponder(event_t *ev)
if (ev->type == ev_keydown && M_FindCheats(ev->data1.i))
return true;

if (WS_Override())
return false;

for (i = 0; i < arrlen(cheat_input); ++i)
{
if (M_InputActivated(cheat_input[i].input))
Expand Down
2 changes: 2 additions & 0 deletions src/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "r_main.h"
#include "st_stuff.h"
#include "w_wad.h"
#include "ws_stuff.h"
#include "z_zone.h"

//
Expand Down Expand Up @@ -133,6 +134,7 @@ void M_InitConfig(void)
G_BindEnemVariables();
G_BindCompVariables();
G_BindWeapVariables();
WS_BindVariables();

HU_BindHUDVariables();
ST_BindSTSVariables();
Expand Down
7 changes: 1 addition & 6 deletions src/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
CHOICE_VALUE = 0,
} mchoice_t;

typedef struct

Check warning on line 147 in src/mn_menu.c

View workflow job for this annotation

GitHub Actions / Clang-Tidy

src/mn_menu.c:147:9 [clang-analyzer-optin.performance.Padding]

Excessive padding in 'menuitem_t' (15 padding bytes, where 7 is optimal). Optimal fields order: routine, alttext, flags, status, rect, alphaKey, name, consider reordering the fields or adding explicit padding members
{
short status; // 0 = no cursor here, 1 = ok, 2 = arrows ok
char name[10];
Expand Down Expand Up @@ -2108,7 +2108,7 @@
// action based on the state of the system.
//

static boolean ShortcutResponder(const event_t *ev)
boolean M_ShortcutResponder(const event_t *ev)
{
// If there is no active menu displayed...

Expand Down Expand Up @@ -2823,11 +2823,6 @@
G_ScreenShot();
}

if (ShortcutResponder(ev))
{
return true;
}

// Pop-up Main menu?

if (!menuactive)
Expand Down
2 changes: 2 additions & 0 deletions src/mn_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct event_s;

boolean M_Responder(struct event_s *ev);

boolean M_ShortcutResponder(const struct event_s *ev);

// Called by main loop,
// only used for menu (skull cursor) animation.

Expand Down
Loading