ref: 74e95f3f2b632798d08be675f7fd7abb53303239
parent: dee1ed97a1c031a9c055088c53fd4189d09d81ab
author: Simon Howard <fraggle@gmail.com>
date: Sat Oct 15 13:39:33 EDT 2011
Add weapon cycling keys for Hexen. Subversion-branch: /branches/v2-branch Subversion-revision: 2431
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -144,6 +144,8 @@
&key_weapon4,
};
+static int next_weapon = 0;
+
#define SLOWTURNTICS 6
#define NUMKEYS 256
@@ -457,18 +459,44 @@
dclicks = 0; // clear double clicks if hit use button
}
- for (i=0; i<arrlen(weapon_keys); ++i)
+ // Weapon cycling. Switch to previous or next weapon.
+ // (Disabled when player is a pig).
+
+ if (players[consoleplayer].morphTics == 0 && next_weapon != 0)
{
- int key = *weapon_keys[i];
+ if (players[consoleplayer].pendingweapon == WP_NOCHANGE)
+ {
+ i = players[consoleplayer].readyweapon;
+ }
+ else
+ {
+ i = players[consoleplayer].pendingweapon;
+ }
- if (gamekeydown[key])
+ do {
+ i = (i + next_weapon) % NUMWEAPONS;
+ } while (!players[consoleplayer].weaponowned[i]);
+
+ cmd->buttons |= BT_CHANGE;
+ cmd->buttons |= i << BT_WEAPONSHIFT;
+ }
+ else
+ {
+ for (i=0; i<arrlen(weapon_keys); ++i)
{
- cmd->buttons |= BT_CHANGE;
- cmd->buttons |= i<<BT_WEAPONSHIFT;
- break;
+ int key = *weapon_keys[i];
+
+ if (gamekeydown[key])
+ {
+ cmd->buttons |= BT_CHANGE;
+ cmd->buttons |= i<<BT_WEAPONSHIFT;
+ break;
+ }
}
}
+ next_weapon = 0;
+
//
// mouse
//
@@ -710,6 +738,15 @@
if (ev->type == ev_mouse)
{
testcontrols_mousespeed = abs(ev->data2);
+ }
+
+ if (ev->type == ev_keydown && ev->data1 == key_prevweapon)
+ {
+ next_weapon = -1;
+ }
+ else if (ev->type == ev_keydown && ev->data1 == key_nextweapon)
+ {
+ next_weapon = 1;
}
switch (ev->type)