From b460d84ee26b4f63dc80ce75b6eb9dd05041e23e Mon Sep 17 00:00:00 2001 From: Marisa the Magician Date: Mon, 13 Jun 2022 10:05:16 +0200 Subject: [PATCH] Less naive PickWeapon rewrite. --- language.version | 4 ++-- zscript/swwm_player.zsc | 25 ++++++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/language.version b/language.version index d49cdb008..5de7ac52d 100644 --- a/language.version +++ b/language.version @@ -1,3 +1,3 @@ [default] -SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r117 \cu(Mon 13 Jun 09:38:41 CEST 2022)\c-"; -SWWM_SHORTVER="\cw1.3pre r117 \cu(2022-06-13 09:38:41)\c-"; +SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r118 \cu(Mon 13 Jun 10:05:16 CEST 2022)\c-"; +SWWM_SHORTVER="\cw1.3pre r118 \cu(2022-06-13 10:05:16)\c-"; diff --git a/zscript/swwm_player.zsc b/zscript/swwm_player.zsc index c4c6601cc..05f90a141 100644 --- a/zscript/swwm_player.zsc +++ b/zscript/swwm_player.zsc @@ -3179,11 +3179,9 @@ Class Demolitionist : PlayerPawn // // I could rewrite PickNextWeapon and PickPrevWeapon as well, but nah // those always call CheckAmmo so it's fine - override Weapon PickWeapon( int slot, bool checkammo ) + private Weapon TraverseSlot( int slot, bool checkammo, int start, int end, Weapon cur ) { - int slotsize = player.weapons.SlotSize(slot); - let cur = player.ReadyWeapon; - for ( int i=slotsize-1; i>=0; i-- ) + for ( int i=start; i>=end; i-- ) { let type = player.weapons.GetWeapon(slot,i); let w = Weapon(player.mo.FindInventory(type)); @@ -3195,7 +3193,24 @@ Class Demolitionist : PlayerPawn || w.CheckAmmo(Weapon.EitherFire,false) ) return w; } - return cur; + return null; + } + override Weapon PickWeapon( int slot, bool checkammo ) + { + int slotsize = player.weapons.SlotSize(slot); + let cur = player.ReadyWeapon; + bool found = false; + int cs, ci; + if ( cur ) [found, cs, ci] = player.weapons.LocateWeapon(cur.GetClass()); + if ( found && (cs == slot) ) + { + // traverse the slot down from current index + let w = TraverseSlot(slot,checkammo,ci-1,0,cur); + if ( !w ) w = TraverseSlot(slot,checkammo,slotsize-1,ci+1,cur); + return w?w:cur; + } + let w = TraverseSlot(slot,checkammo,slotsize-1,0,cur); + return w?w:cur; } override void MarkPrecacheSounds() {