From ea74370463bdfc4a079f5a3128c8c29c92abe2dd Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Wed, 17 Feb 2021 19:39:44 +0100 Subject: [PATCH] Mod keys now attach their replacements, which are hidden. This should fix a lot of dumb scripts that use CheckInventory to get keys. --- language.version | 4 ++-- zscript/swwm_hud.zsc | 21 +++++++++++++++++++++ zscript/swwm_kbase.zsc | 18 +++++++++++++++++- zscript/swwm_keys.zsc | 16 ++++++++++++++++ zscript/swwm_player.zsc | 5 ++--- 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/language.version b/language.version index 8dff97407..a29aa1a57 100644 --- a/language.version +++ b/language.version @@ -1,3 +1,3 @@ [default] -SWWM_MODVER="\chSWWM \czGZ\c- \cw0.9.11b-pre r282 \cu(Wed 17 Feb 09:37:08 CET 2021)\c-"; -SWWM_SHORTVER="\cw0.9.11b-pre r282 \cu(2021-02-17 09:37:08)\c-"; +SWWM_MODVER="\chSWWM \czGZ\c- \cw0.9.11b-pre r283 \cu(Wed 17 Feb 19:39:44 CET 2021)\c-"; +SWWM_SHORTVER="\cw0.9.11b-pre r283 \cu(2021-02-17 19:39:44)\c-"; diff --git a/zscript/swwm_hud.zsc b/zscript/swwm_hud.zsc index b66fdb1ea..5f08a4060 100644 --- a/zscript/swwm_hud.zsc +++ b/zscript/swwm_hud.zsc @@ -935,10 +935,31 @@ Class SWWMStatusBar : BaseStatusBar int colc = 0; double colh = 0; int n = Key.GetKeyTypeCount(); + Array klist; for ( int i=0; i pc = klist[i].Species; + if ( !pc ) continue; + for ( int j=0; j= j ) i--; + } + } + for ( int i=0; i pc = invlist[i].Species; + if ( !pc ) continue; + for ( int j=0; j= j ) i--; + } } // collectibles, sorted by name Array cols; diff --git a/zscript/swwm_keys.zsc b/zscript/swwm_keys.zsc index 7d02d369f..631b5a6b0 100644 --- a/zscript/swwm_keys.zsc +++ b/zscript/swwm_keys.zsc @@ -23,6 +23,22 @@ Class SWWMKey : Key abstract } } + override void AttachToOwner( Actor other ) + { + Super.AttachToOwner(other); + // also attach the vanilla key that we replace, mainly for script compatibility + Class pc = Species; + if ( pc ) + { + let p = Inventory(Spawn(pc)); + if ( Owner is 'Demolitionist' ) + Demolitionist(Owner).key_reentrant = true; // avoid infinite loop + p.AttachToOwner(Owner); + if ( Owner is 'Demolitionist' ) + Demolitionist(Owner).key_reentrant = false; + } + } + override bool Use( bool pickup ) { if ( Owner.player && !propagated ) diff --git a/zscript/swwm_player.zsc b/zscript/swwm_player.zsc index 26f50b105..c7f6d6e11 100644 --- a/zscript/swwm_player.zsc +++ b/zscript/swwm_player.zsc @@ -2004,13 +2004,12 @@ Class Demolitionist : PlayerPawn override void AddInventory( Inventory item ) { // hackaround for replaced keys - if ( item is 'Key' ) + if ( (item is 'Key') && !key_reentrant ) { let rep = (Class)(GetReplacement(item.GetClass())); if ( rep && (item.GetClass() != rep) ) { - item.Destroy(); - // add the new key instead + // also add the new key Actor whom = player?player.mo:PlayerPawn(self); if ( !whom.FindInventory(rep) ) {