From 9f92b2d9a3a63b6bae65863d961a4796e5ff5c50 Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Wed, 24 Mar 2021 19:34:23 +0100 Subject: [PATCH] Carried Ammo Fabricators can now auto-use themselves. --- language.version | 4 +-- zscript/items/swwm_ammoextra.zsc | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/language.version b/language.version index 49b4f4cad..6c8b9ff1b 100644 --- a/language.version +++ b/language.version @@ -1,3 +1,3 @@ [default] -SWWM_MODVER="\chSWWM \czGZ\c- \cw0.9.11b-pre r404 \cu(Wed 24 Mar 19:00:07 CET 2021)\c-"; -SWWM_SHORTVER="\cw0.9.11b-pre r404 \cu(2021-03-24 19:00:07)\c-"; +SWWM_MODVER="\chSWWM \czGZ\c- \cw0.9.11b-pre r404 \cu(Wed 24 Mar 19:34:23 CET 2021)\c-"; +SWWM_SHORTVER="\cw0.9.11b-pre r404 \cu(2021-03-24 19:34:23)\c-"; diff --git a/zscript/items/swwm_ammoextra.zsc b/zscript/items/swwm_ammoextra.zsc index b2e8446b3..bc84c41fe 100644 --- a/zscript/items/swwm_ammoextra.zsc +++ b/zscript/items/swwm_ammoextra.zsc @@ -151,6 +151,52 @@ Class AmmoFabricator : Inventory abstract return given; } + override void DoEffect() + { + Super.DoEffect(); + if ( !Owner || !bAUTOACTIVATE ) return; + bool shouldautouse = false; + if ( swwm_enforceautouseammo == 1 ) shouldautouse = true; + else if ( swwm_enforceautouseammo == -1 ) shouldautouse = false; + else shouldautouse = CVar.GetCVar('swwm_autouseammo',Owner.player).GetBool(); + if ( !shouldautouse ) return; + // fabricators of lower tiers, for priority checking + Array others; + for ( Inventory i=Owner.inv; i; i=i.inv ) + { + if ( !(i is 'AmmoFabricator') || (i == self) || !i.bAUTOACTIVATE || (AmmoFabricator(i).maxunitprice >= maxunitprice) ) continue; + others.Push(AmmoFabricator(i)); + } + // check if owner lacks ammo, autouse if we can afford its unit price + bool used = false; + Actor o = Owner; + for ( Inventory i=o.inv; i; i=i.inv ) + { + if ( !(i is 'Ammo') || (i.Amount > (i.MaxAmount/3)) || (i.Stamina <= 0) || (i.Stamina > maxunitprice) ) continue; + // ignore if there's a cheaper fabricator than us that can afford it ("wait our turn", basically) + bool lowprio = false; + for ( int j=0; j others[j].maxunitprice ) continue; + lowprio = true; + break; + } + if ( lowprio ) continue; + // hit it + while ( (Amount > 0) && FabricateAmmo() ) + { + used = true; + Amount--; + } + if ( Amount <= 0 ) + { + DepleteOrDestroy(); + break; + } + } + if ( used && (o.player == players[consoleplayer]) ) o.A_StartSound(UseSound,CHAN_ITEMEXTRA); + } + override bool Use( bool pickup ) { bool shouldautouse = false;