summaryrefslogtreecommitdiff
path: root/src/heretic
diff options
context:
space:
mode:
authorSimon Howard2011-10-15 17:17:43 +0000
committerSimon Howard2011-10-15 17:17:43 +0000
commitdee1ed97a1c031a9c055088c53fd4189d09d81ab (patch)
tree0173fc3e372fc52f92d59d14c177ef6789c4e54a /src/heretic
parentef848275bcf6dd978499cfc6a28cc81256a82447 (diff)
downloadchocolate-doom-dee1ed97a1c031a9c055088c53fd4189d09d81ab.tar.gz
chocolate-doom-dee1ed97a1c031a9c055088c53fd4189d09d81ab.tar.bz2
chocolate-doom-dee1ed97a1c031a9c055088c53fd4189d09d81ab.zip
Add weapon cycling keys for Heretic.
Subversion-branch: /branches/v2-branch Subversion-revision: 2430
Diffstat (limited to 'src/heretic')
-rw-r--r--src/heretic/g_game.c107
1 files changed, 99 insertions, 8 deletions
diff --git a/src/heretic/g_game.c b/src/heretic/g_game.c
index 69a3d5b7..74942653 100644
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -165,6 +165,28 @@ static int *weapon_keys[] =
&key_weapon7
};
+// Set to -1 or +1 to switch to the previous or next weapon.
+
+static int next_weapon = 0;
+
+// Used for prev/next weapon keys.
+
+static const struct
+{
+ weapontype_t weapon;
+ weapontype_t weapon_num;
+} weapon_order_table[] = {
+ { wp_staff, wp_staff },
+ { wp_gauntlets, wp_staff },
+ { wp_goldwand, wp_goldwand },
+ { wp_crossbow, wp_crossbow },
+ { wp_blaster, wp_blaster },
+ { wp_skullrod, wp_skullrod },
+ { wp_phoenixrod, wp_phoenixrod },
+ { wp_mace, wp_mace },
+ { wp_beak, wp_beak },
+};
+
#define SLOWTURNTICS 6
#define NUMKEYS 256
@@ -210,6 +232,51 @@ int G_CmdChecksum(ticcmd_t *cmd)
}
*/
+static boolean WeaponSelectable(weapontype_t weapon)
+{
+ if (weapon == wp_beak)
+ {
+ return false;
+ }
+
+ return players[consoleplayer].weaponowned[weapon];
+}
+
+static int G_NextWeapon(int direction)
+{
+ weapontype_t weapon;
+ int i;
+
+ // Find index in the table.
+
+ if (players[consoleplayer].pendingweapon == wp_nochange)
+ {
+ weapon = players[consoleplayer].readyweapon;
+ }
+ else
+ {
+ weapon = players[consoleplayer].pendingweapon;
+ }
+
+ for (i=0; i<arrlen(weapon_order_table); ++i)
+ {
+ if (weapon_order_table[i].weapon == weapon)
+ {
+ break;
+ }
+ }
+
+ // Switch weapon.
+
+ do
+ {
+ i += direction;
+ i = (i + arrlen(weapon_order_table)) % arrlen(weapon_order_table);
+ } while (!WeaponSelectable(weapon_order_table[i].weapon));
+
+ return weapon_order_table[i].weapon_num;
+}
+
/*
====================
=
@@ -411,18 +478,33 @@ 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)
- {
- int key = *weapon_keys[i];
+ // If the previous or next weapon button is pressed, the
+ // next_weapon variable is set to change weapons when
+ // we generate a ticcmd. Choose a new weapon.
+ // (Can't weapon cycle when the player is a chicken)
- if (gamekeydown[key])
+ if (players[consoleplayer].chickenTics == 0 && next_weapon != 0)
+ {
+ i = G_NextWeapon(next_weapon);
+ 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
@@ -676,6 +758,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: