From 1a6dea5a0bbf660a21666a85036d469ded3154b4 Mon Sep 17 00:00:00 2001 From: Yamagi Date: Mon, 30 Mar 2020 13:55:02 +0200 Subject: [PATCH] Add `coop_pickup_weapons`, allow a weapon to be taken several times. In coop a weapon can be picked up only once. That's annoying, because in coop ammunition is sparse and not getting the ammunition that comes with a weapons make things worse. When `coop_pickup_weapons` is set to `1` a weapon may be picked up if: 1) The player doesn't have the weapon in their inventory. 2) No other player has already picked it up. --- doc/040_cvarlist.md | 8 ++++++++ src/game/g_main.c | 1 + src/game/header/local.h | 2 ++ src/game/player/weapon.c | 7 ++++--- src/game/savegame/savegame.c | 1 + 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/040_cvarlist.md b/doc/040_cvarlist.md index fc1a50ea..4f078eaf 100644 --- a/doc/040_cvarlist.md +++ b/doc/040_cvarlist.md @@ -113,6 +113,14 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable` spawned in maps (in fact, some official Ground Zero maps contain these entities). This cvar is set to 0 by default. +* **coop_pickup_weapons**: In coop a weapon can be picked up only once. + For example, if the player already has the shotgun they cannot pickup + a second shotgun found at a later time, thus not getting the ammo that + comes with it. This breaks the balacing. If set to `1` a weapon can be + picked up if a) the player doesn't have it or b) it wasn't already + picked up by another player. Defaults to `0`. + + ## Audio * **al_device**: OpenAL device to use. In most cases there's no need to diff --git a/src/game/g_main.c b/src/game/g_main.c index e2f0f359..bafc33fd 100644 --- a/src/game/g_main.c +++ b/src/game/g_main.c @@ -40,6 +40,7 @@ edict_t *g_edicts; cvar_t *deathmatch; cvar_t *coop; +cvar_t *coop_pickup_weapons; cvar_t *dmflags; cvar_t *skill; cvar_t *fraglimit; diff --git a/src/game/header/local.h b/src/game/header/local.h index 27c3ef38..7e81160b 100644 --- a/src/game/header/local.h +++ b/src/game/header/local.h @@ -72,6 +72,7 @@ #define FL_TEAMSLAVE 0x00000400 /* not the first on the team */ #define FL_NO_KNOCKBACK 0x00000800 #define FL_POWER_ARMOR 0x00001000 /* power armor (if any) is active */ +#define FL_COOP_TAKEN 0x00002000 /* Another client has already taken it */ #define FL_RESPAWN 0x80000000 /* used for item respawning */ #define FRAMETIME 0.1 @@ -507,6 +508,7 @@ extern edict_t *g_edicts; extern cvar_t *maxentities; extern cvar_t *deathmatch; extern cvar_t *coop; +extern cvar_t *coop_pickup_weapons; extern cvar_t *dmflags; extern cvar_t *skill; extern cvar_t *fraglimit; diff --git a/src/game/player/weapon.c b/src/game/player/weapon.c index d1c1fcfd..25eb4a03 100644 --- a/src/game/player/weapon.c +++ b/src/game/player/weapon.c @@ -184,7 +184,8 @@ Pickup_Weapon(edict_t *ent, edict_t *other) if ((((int)(dmflags->value) & DF_WEAPONS_STAY) || coop->value) && other->client->pers.inventory[index]) { - if (!(ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM))) + if (!(ent->spawnflags & (DROPPED_ITEM | DROPPED_PLAYER_ITEM)) && + (!coop_pickup_weapons->value || (ent->flags & FL_COOP_TAKEN))) { return false; /* leave the weapon for others to pickup */ } @@ -223,14 +224,14 @@ Pickup_Weapon(edict_t *ent, edict_t *other) if (coop->value) { ent->flags |= FL_RESPAWN; + ent->flags |= FL_COOP_TAKEN; } } } if ((other->client->pers.weapon != ent->item) && (other->client->pers.inventory[index] == 1) && - (!deathmatch->value || - (other->client->pers.weapon == FindItem("blaster")))) + (!deathmatch->value || (other->client->pers.weapon == FindItem("blaster")))) { other->client->newweapon = ent->item; } diff --git a/src/game/savegame/savegame.c b/src/game/savegame/savegame.c index 090a0603..0770fa7e 100644 --- a/src/game/savegame/savegame.c +++ b/src/game/savegame/savegame.c @@ -232,6 +232,7 @@ InitGame(void) maxspectators = gi.cvar("maxspectators", "4", CVAR_SERVERINFO); deathmatch = gi.cvar("deathmatch", "0", CVAR_LATCH); coop = gi.cvar("coop", "0", CVAR_LATCH); + coop_pickup_weapons = gi.cvar("coop_pickup_weapons", "0", 0); skill = gi.cvar("skill", "1", CVAR_LATCH); maxentities = gi.cvar("maxentities", "1024", CVAR_LATCH);