From a04f909d0661d26777a2c1fecc7f2587b26fd2fe Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Sun, 12 Nov 2023 01:47:52 +0800 Subject: [PATCH] Add `sv_coopsharekeys` - in coop, picking up a key will distribute it to all online players --- src/d_main.cpp | 1 + src/doomdef.h | 1 + .../zscript/actors/inventory/inv_misc.zs | 22 +++++++++++++++++++ wadsrc/static/zscript/actors/player/player.zs | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 64d29bb5509..f1f55936334 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -573,6 +573,7 @@ CUSTOM_CVAR(Int, dmflags3, 0, CVAR_SERVERINFO | CVAR_NOINITCALL) } CVAR(Flag, sv_noplayerclip, dmflags3, DF3_NO_PLAYER_CLIP); +CVAR(Flag, sv_coopsharekeys, dmflags3, DF3_COOP_SHARE_KEYS); //========================================================================== // diff --git a/src/doomdef.h b/src/doomdef.h index 111bf7ad2cd..a2ae2f35e42 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -180,6 +180,7 @@ enum : unsigned enum : unsigned { DF3_NO_PLAYER_CLIP = 1 << 0, // Players can walk through and shoot through each other + DF3_COOP_SHARE_KEYS = 1 << 1, // Keys will be given to all players in coop }; // [RH] Compatibility flags. diff --git a/wadsrc/static/zscript/actors/inventory/inv_misc.zs b/wadsrc/static/zscript/actors/inventory/inv_misc.zs index 1d31022ad92..5fc4e3fe237 100644 --- a/wadsrc/static/zscript/actors/inventory/inv_misc.zs +++ b/wadsrc/static/zscript/actors/inventory/inv_misc.zs @@ -59,6 +59,28 @@ class Key : Inventory return false; } + override void AttachToOwner(Actor other) + { + Super.AttachToOwner(other); + + if (multiplayer && !deathmatch && sv_coopsharekeys) + { + for (int i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i]) + { + let pmo = players[i].mo; + + if (pmo == other) + continue; + + if (!pmo.FindInventory(GetClass())) + pmo.GiveInventoryType(GetClass()); + } + } + } + } + override bool ShouldStay () { return !!multiplayer; diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index 807835ebb1a..235b97c8daa 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -888,7 +888,7 @@ class PlayerPawn : Actor // inventory amount. let defitem = FindInventory (item.GetClass()); - if (sv_cooplosekeys && defitem == NULL && item is 'Key') + if ((sv_cooplosekeys && !sv_coopsharekeys) && defitem == NULL && item is 'Key') { item.Destroy(); }