summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2010-08-09 17:53:10 +0000
committerSimon Howard2010-08-09 17:53:10 +0000
commitf3d3b03870a6842e104c67ce6fc7edfde89d77ec (patch)
treee826ee27d68eef429854a1894f30f02b33b093eb /src
parentf291db8f1456b9d1be47eae0ac34bcf0546ce151 (diff)
downloadchocolate-doom-f3d3b03870a6842e104c67ce6fc7edfde89d77ec.tar.gz
chocolate-doom-f3d3b03870a6842e104c67ce6fc7edfde89d77ec.tar.bz2
chocolate-doom-f3d3b03870a6842e104c67ce6fc7edfde89d77ec.zip
Add weapon cycling bindings for mouse and joystick buttons. Add weapon
cycling bindings to configuration file and setup tool. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1953
Diffstat (limited to 'src')
-rw-r--r--src/g_game.c65
-rw-r--r--src/m_config.c44
2 files changed, 100 insertions, 9 deletions
diff --git a/src/g_game.c b/src/g_game.c
index 1e163716..bf9560db 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -198,6 +198,9 @@ int mousebstraferight = -1;
int mousebbackward = -1;
int mousebuse = -1;
+int mousebprevweapon = -1;
+int mousebnextweapon = -1;
+
// Control whether if a mouse button is double clicked, it acts like
// "use" has been pressed
@@ -210,6 +213,9 @@ int joybspeed = 2;
int joybstrafeleft = -1;
int joybstraferight = -1;
+int joybprevweapon = -1;
+int joybnextweapon = -1;
+
// fraggle: Disallow mouse and joystick movement to cause forward/backward
// motion. Specified with the '-novert' command line parameter.
// This is an int to allow saving to config file
@@ -262,11 +268,13 @@ static const struct
#define SLOWTURNTICS 6
#define NUMKEYS 256
+#define MAX_JOY_BUTTONS 20
+#define MAX_MOUSE_BUTTONS 3
static boolean gamekeydown[NUMKEYS];
static int turnheld; // for accelerative turning
-static boolean mousearray[4];
+static boolean mousearray[MAX_MOUSE_BUTTONS + 1];
static boolean *mousebuttons = &mousearray[1]; // allow [-1]
// mouse values are used once
@@ -280,8 +288,6 @@ static int dclicktime2;
static boolean dclickstate2;
static int dclicks2;
-#define MAX_JOY_BUTTONS 20
-
// joystick values are repeated
static int joyxmove;
static int joyymove;
@@ -815,7 +821,6 @@ void G_DoLoadLevel (void)
players[consoleplayer].message = "Press escape to quit.";
}
}
-
static void SetJoyButtons(unsigned int buttons_mask)
{
@@ -823,10 +828,54 @@ static void SetJoyButtons(unsigned int buttons_mask)
for (i=0; i<MAX_JOY_BUTTONS; ++i)
{
- joybuttons[i] = (buttons_mask & (1 << i)) != 0;
+ int button_on = (buttons_mask & (1 << i)) != 0;
+
+ // Detect button press:
+
+ if (!joybuttons[i] && button_on)
+ {
+ // Weapon cycling:
+
+ if (i == joybprevweapon)
+ {
+ next_weapon = -1;
+ }
+ else if (i == joybnextweapon)
+ {
+ next_weapon = 1;
+ }
+ }
+
+ joybuttons[i] = button_on;
}
}
-
+
+static void SetMouseButtons(unsigned int buttons_mask)
+{
+ int i;
+
+ for (i=0; i<MAX_MOUSE_BUTTONS; ++i)
+ {
+ unsigned int button_on = (buttons_mask & (1 << i)) != 0;
+
+ // Detect button press:
+
+ if (!mousebuttons[i] && button_on)
+ {
+ if (i == mousebprevweapon)
+ {
+ next_weapon = -1;
+ }
+ else if (i == mousebnextweapon)
+ {
+ next_weapon = 1;
+ }
+ }
+
+ mousebuttons[i] = button_on;
+ }
+}
+
//
// G_Responder
// Get info needed to make ticcmd_ts for the players.
@@ -927,9 +976,7 @@ boolean G_Responder (event_t* ev)
return false; // always let key up events filter down
case ev_mouse:
- mousebuttons[0] = ev->data1 & 1;
- mousebuttons[1] = ev->data1 & 2;
- mousebuttons[2] = ev->data1 & 4;
+ SetMouseButtons(ev->data1);
mousex = ev->data2*(mouseSensitivity+5)/10;
mousey = ev->data3*(mouseSensitivity+5)/10;
return true; // eat events
diff --git a/src/m_config.c b/src/m_config.c
index b2e52e7f..2065700e 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -148,6 +148,8 @@ extern int key_weapon5;
extern int key_weapon6;
extern int key_weapon7;
extern int key_weapon8;
+extern int key_prevweapon;
+extern int key_nextweapon;
extern int key_message_refresh;
extern int key_demo_quit;
@@ -164,6 +166,9 @@ extern int mousebstraferight;
extern int mousebbackward;
extern int mousebuse;
+extern int mousebprevweapon;
+extern int mousebnextweapon;
+
extern int dclick_use;
extern int joybfire;
@@ -173,6 +178,9 @@ extern int joybspeed;
extern int joybstrafeleft;
extern int joybstraferight;
+extern int joybprevweapon;
+extern int joybnextweapon;
+
extern int viewwidth;
extern int viewheight;
@@ -748,6 +756,18 @@ static default_t extra_defaults_list[] =
CONFIG_VARIABLE_INT(joyb_straferight, joybstraferight),
//!
+ // Joystick button to cycle to the previous weapon.
+ //
+
+ CONFIG_VARIABLE_INT(joyb_prevweapon, joybprevweapon),
+
+ //!
+ // Joystick button to cycle to the next weapon.
+ //
+
+ CONFIG_VARIABLE_INT(joyb_nextweapon, joybnextweapon),
+
+ //!
// Mouse button to strafe left.
//
@@ -772,6 +792,18 @@ static default_t extra_defaults_list[] =
CONFIG_VARIABLE_INT(mouseb_backward, mousebbackward),
//!
+ // Mouse button to cycle to the previous weapon.
+ //
+
+ CONFIG_VARIABLE_INT(mouseb_prevweapon, mousebprevweapon),
+
+ //!
+ // Mouse button to cycle to the next weapon.
+ //
+
+ CONFIG_VARIABLE_INT(mouseb_nextweapon, mousebnextweapon),
+
+ //!
// If non-zero, double-clicking a mouse button acts like pressing
// the "use" key to use an object in-game, eg. a door or switch.
//
@@ -1062,6 +1094,18 @@ static default_t extra_defaults_list[] =
CONFIG_VARIABLE_KEY(key_weapon8, key_weapon8),
//!
+ // Key to cycle to the previous weapon.
+ //
+
+ CONFIG_VARIABLE_KEY(key_prevweapon, key_prevweapon),
+
+ //!
+ // Key to cycle to the next weapon.
+ //
+
+ CONFIG_VARIABLE_KEY(key_nextweapon, key_nextweapon),
+
+ //!
// Key to re-display last message.
//