From 55db5ca150539759ce38887c54944af0244fcc7c Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Thu, 21 Jan 2021 18:16:09 +0100 Subject: [PATCH] Add debug command to fix item max amounts mid-playthrough. --- language.version | 2 +- zscript/swwm_ammo.zsc | 11 +++--- zscript/swwm_handler.zsc | 76 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 6 deletions(-) diff --git a/language.version b/language.version index e3d89b6d6..ffc7c6748 100644 --- a/language.version +++ b/language.version @@ -1,2 +1,2 @@ [default] -SWWM_MODVER="\chSWWM \czGZ\c- \cw0.9.11b-pre r777 \cu(Thu 21 Jan 17:22:26 CET 2021)"; +SWWM_MODVER="\chSWWM \czGZ\c- \cw0.9.11b-pre r778 \cu(Thu 21 Jan 18:16:09 CET 2021)"; diff --git a/zscript/swwm_ammo.zsc b/zscript/swwm_ammo.zsc index 0a46de6ad..25068aa65 100644 --- a/zscript/swwm_ammo.zsc +++ b/zscript/swwm_ammo.zsc @@ -1678,7 +1678,6 @@ Class HammerspaceEmbiggener : Inventory double factor = (ammoitem.BackpackMaxAmount-ammoitem.default.MaxAmount)/double(MaxAmount); ammoitem.MaxAmount = int(ammoitem.default.MaxAmount+self.Amount*factor); } - else ammoitem.MaxAmount = int(ammoitem.default.MaxAmount*(1+self.Amount)); if ( (ammoitem.Amount > ammoitem.MaxAmount) && !sv_unlimited_pickup ) ammoitem.Amount = ammoitem.MaxAmount; ammoitem.AttachToOwner(other); @@ -1691,7 +1690,6 @@ Class HammerspaceEmbiggener : Inventory double factor = (ammoitem.BackpackMaxAmount-ammoitem.default.MaxAmount)/double(MaxAmount); ammoitem.MaxAmount = int(ammoitem.default.MaxAmount+self.Amount*factor); } - else ammoitem.MaxAmount = int(ammoitem.default.MaxAmount*(1+self.Amount)); if ( ammoitem.Amount < ammoitem.MaxAmount ) { ammoitem.Amount += amount; @@ -1718,7 +1716,6 @@ Class HammerspaceEmbiggener : Inventory double factor = (Ammo(i).BackpackMaxAmount-i.default.MaxAmount)/double(MaxAmount); i.MaxAmount = int(i.default.MaxAmount+Amount*factor); } - else i.MaxAmount = int(i.default.MaxAmount*(1+Amount)); int amount = Ammo(i).BackpackAmount; if ( !bIgnoreSkill ) amount = int(amount*G_SkillPropertyFloat(SKILLP_AmmoFactor)); i.Amount += amount; @@ -1734,7 +1731,6 @@ Class HammerspaceEmbiggener : Inventory double factor = (Ammo(item).BackpackMaxAmount-item.default.MaxAmount)/double(MaxAmount); item.MaxAmount = int(item.default.MaxAmount+Amount*factor); } - else item.MaxAmount = int(item.default.MaxAmount*1+Amount); if ( Ammo(item).BackpackMaxAmount > 0 ) item.MaxAmount = min(item.MaxAmount,Ammo(item).BackpackMaxAmount); } @@ -1748,7 +1744,12 @@ Class HammerspaceEmbiggener : Inventory { if ( !(i is 'Ammo') ) continue; i.MaxAmount = i.default.MaxAmount; - if ( i.Amount > i.MaxAmount ) i.Amount = i.MaxAmount; + if ( i.Amount > i.MaxAmount ) + { + int dropme = max(0,i.Amount-i.MaxAmount); + if ( dropme > 0 ) i.CreateTossable(dropme); + i.Amount = i.MaxAmount; + } } Super.DepleteOrDestroy(); } diff --git a/zscript/swwm_handler.zsc b/zscript/swwm_handler.zsc index 0f0192579..a2619a2ea 100644 --- a/zscript/swwm_handler.zsc +++ b/zscript/swwm_handler.zsc @@ -2513,6 +2513,82 @@ Class SWWMHandler : EventHandler } return; } + else if ( e.Name ~== "swwmfixitemcaps" ) + { + // this command is only really needed when I update item max amounts mid-playthrough + if ( multiplayer && (e.player != Net_Arbitrator) ) + { + if ( e.player == consoleplayer ) + Console.Printf("Only the net arbitrator can call this event."); + return; + } + for ( int i=0; i %d)",hams.GetTag(),hams.MaxAmount,hams.default.MaxAmount); + hams.MaxAmount = hams.default.MaxAmount; + hams.Amount = min(hams.Amount,hams.MaxAmount); + } + for ( Inventory inv=mo.inv; inv; inv=inv.inv ) + { + if ( inv is 'Ammo' ) + { + Ammo(inv).BackpackMaxAmount = Ammo(inv).default.BackpackMaxAmount; + int newmax = inv.default.MaxAmount; + if ( (hams.Amount > 0) && (Ammo(inv).BackpackMaxAmount > 0) ) + { + double factor = (Ammo(inv).BackpackMaxAmount-inv.default.MaxAmount)/double(hams.MaxAmount); + newmax = int(inv.default.MaxAmount+hams.Amount*factor); + } + if ( inv.MaxAmount != newmax ) + Console.Printf("Adjust %s capacity (%d -> %d)",inv.GetTag(),inv.MaxAmount,newmax); + int dropme = max(0,inv.Amount-newmax); + if ( dropme ) + { + Console.Printf("Dropped %dx %s.",dropme,inv.GetTag()); + // non-SWWM ammos won't subdivide, but whatever, this is a debug command + inv.CreateTossable(dropme); + } + inv.MaxAmount = newmax; + } + else if ( inv is 'MagAmmo' ) + { + if ( inv.MaxAmount != inv.default.MaxAmount ) + Console.Printf("Adjust %s capacity (%d -> %d)",inv.GetTag(),inv.MaxAmount,inv.default.MaxAmount); + // just drop the extras + int dropme = max(0,inv.Amount-inv.default.MaxAmount); + if ( dropme ) + { + Console.Printf("Dropped %dx %s.",dropme,inv.GetTag()); + inv.CreateTossable(dropme); + } + inv.MaxAmount = inv.default.MaxAmount; + } + else + { + if ( inv.MaxAmount != inv.default.MaxAmount ) + Console.Printf("Adjust %s capacity (%d -> %d)",inv.GetTag(),inv.MaxAmount,inv.default.MaxAmount); + // only drop droppables (obviously) + if ( !inv.bUNDROPPABLE && !inv.bUNTOSSABLE ) + { + int dropme = max(0,inv.Amount-inv.default.MaxAmount); + if ( dropme ) + { + Console.Printf("Dropped %dx %s.",dropme,inv.GetTag()); + for ( int j=0; j