foxygit / doom Log in
commit 74e95f3f2b632798d08be675f7fd7abb53303239
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Oct 15 17:39:33 2011 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Oct 15 17:39:33 2011 +0000

    Add weapon cycling keys for Hexen.

    Subversion-branch: /branches/v2-branch
    Subversion-revision: 2431
---
 src/hexen/g_game.c | 49 +++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 6 deletions(-)

diff --git a/src/hexen/g_game.c b/src/hexen/g_game.c
index 5dcfb478..b1d9e6b1 100644
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -144,6 +144,8 @@ static int *weapon_keys[] =
     &key_weapon4,
 };

+static int next_weapon = 0;
+
 #define SLOWTURNTICS    6

 #define NUMKEYS 256
@@ -457,18 +459,44 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic)
         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;
+        }
+
+        do {
+            i = (i + next_weapon) % NUMWEAPONS;
+        } while (!players[consoleplayer].weaponowned[i]);

-        if (gamekeydown[key])
+        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
 //
@@ -712,6 +740,15 @@ boolean G_Responder(event_t * ev)
         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)
     {
         case ev_keydown: