From 9eca08fd928e9259ba5f0701e5d7d62446586a80 Mon Sep 17 00:00:00 2001 From: Jaime Moreira Date: Thu, 7 Dec 2023 20:51:49 -0300 Subject: [PATCH] Faster "weapprev" and "weapnext" behavior These commands can now "count" how many times they have been called, similar to how "cycleweap" operates after #865. This allows for changing to different weapons, instead of just going "one down" or "one up". New cvar "g_quick_swap" allows to enable/disable this behavior. --- doc/040_cvarlist.md | 6 +++++ src/game/g_cmds.c | 50 ++++++++++++++++++++---------------- src/game/g_main.c | 1 + src/game/header/local.h | 1 + src/game/savegame/savegame.c | 1 + 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/doc/040_cvarlist.md b/doc/040_cvarlist.md index 27f63781..8fbe76be 100644 --- a/doc/040_cvarlist.md +++ b/doc/040_cvarlist.md @@ -222,6 +222,12 @@ Set `0` by default. single player, the same way as in multiplayer. This cvar only works if the game.dll implements this behaviour. +* **g_quick_weap**: If set to `1`, both *weapprev* and *weapnext* + commands will "count" how many times they have been called, making + possible to skip weapons by quickly tapping one of these keys. + By default this cvar is set to `0`, and will only work if the + game.dll implements this behaviour. + * **g_swap_speed**: Sets the speed of the "changing weapon" animation. Default is `1`. If set to `2`, it will be double the speed, `3` is the triple... up until the max of `8`, since there are at least 2 diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index ff0539fb..2f03e824 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -732,17 +732,25 @@ Cmd_WeapPrev_f(edict_t *ent) cl = ent->client; - if (!cl->pers.weapon) + if (g_quick_weap->value && cl->newweapon) + { + it = cl->newweapon; + } + else if (cl->pers.weapon) + { + it = cl->pers.weapon; + } + else { return; } - selected_weapon = ITEM_INDEX(cl->pers.weapon); + selected_weapon = ITEM_INDEX(it); - /* scan for the next valid one */ + /* scan for the next valid one */ for (i = 1; i <= MAX_ITEMS; i++) { - index = (selected_weapon + i) % MAX_ITEMS; + index = (selected_weapon + MAX_ITEMS - i) % MAX_ITEMS; if (!cl->pers.inventory[index]) { @@ -751,19 +759,14 @@ Cmd_WeapPrev_f(edict_t *ent) it = &itemlist[index]; - if (!it->use) - { - continue; - } - - if (!(it->flags & IT_WEAPON)) + if (!it->use || !(it->flags & IT_WEAPON)) { continue; } it->use(ent, it); - if (cl->pers.weapon == it) + if (cl->newweapon == it) { return; /* successful */ } @@ -785,17 +788,25 @@ Cmd_WeapNext_f(edict_t *ent) cl = ent->client; - if (!cl->pers.weapon) + if (g_quick_weap->value && cl->newweapon) + { + it = cl->newweapon; + } + else if (cl->pers.weapon) + { + it = cl->pers.weapon; + } + else { return; } - selected_weapon = ITEM_INDEX(cl->pers.weapon); + selected_weapon = ITEM_INDEX(it); - /* scan for the next valid one */ + /* scan for the next valid one */ for (i = 1; i <= MAX_ITEMS; i++) { - index = (selected_weapon + MAX_ITEMS - i) % MAX_ITEMS; + index = (selected_weapon + i) % MAX_ITEMS; if (!cl->pers.inventory[index]) { @@ -804,19 +815,14 @@ Cmd_WeapNext_f(edict_t *ent) it = &itemlist[index]; - if (!it->use) - { - continue; - } - - if (!(it->flags & IT_WEAPON)) + if (!it->use || !(it->flags & IT_WEAPON)) { continue; } it->use(ent, it); - if (cl->pers.weapon == it) + if (cl->newweapon == it) { return; /* successful */ } diff --git a/src/game/g_main.c b/src/game/g_main.c index e422e0c1..e16356c9 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -88,6 +88,7 @@ cvar_t *gib_on; cvar_t *aimfix; cvar_t *g_machinegun_norecoil; +cvar_t *g_quick_weap; cvar_t *g_swap_speed; void G_RunFrame(void); diff --git a/src/game/header/local.h b/src/game/header/local.h index d52ddc6a..85d94f3d 100644 --- a/src/game/header/local.h +++ b/src/game/header/local.h @@ -551,6 +551,7 @@ extern cvar_t *sv_maplist; extern cvar_t *aimfix; extern cvar_t *g_machinegun_norecoil; +extern cvar_t *g_quick_weap; extern cvar_t *g_swap_speed; #define world (&g_edicts[0]) diff --git a/src/game/savegame/savegame.c b/src/game/savegame/savegame.c index 0f929fff..8385d98f 100644 --- a/src/game/savegame/savegame.c +++ b/src/game/savegame/savegame.c @@ -246,6 +246,7 @@ InitGame(void) /* others */ aimfix = gi.cvar("aimfix", "0", CVAR_ARCHIVE); g_machinegun_norecoil = gi.cvar("g_machinegun_norecoil", "0", CVAR_ARCHIVE); + g_quick_weap = gi.cvar("g_quick_weap", "0", CVAR_ARCHIVE); g_swap_speed = gi.cvar("g_swap_speed", "1", 0); /* items */