Less naive PickWeapon rewrite.

This commit is contained in:
Mari the Deer 2022-06-13 10:05:16 +02:00
commit 717462db5c
2 changed files with 22 additions and 7 deletions

View file

@ -1,3 +1,3 @@
[default]
SWWM_MODVER="\cyDEMOLITIONIST \cw1.2.25 \cu(Mon 13 Jun 09:40:34 CEST 2022)\c-";
SWWM_SHORTVER="\cw1.2.25 \cu(2022-06-13 09:40:34)\c-";
SWWM_MODVER="\cyDEMOLITIONIST \cw1.2.26 \cu(Mon 13 Jun 10:08:05 CEST 2022)\c-";
SWWM_SHORTVER="\cw1.2.26 \cu(2022-06-13 10:08:05)\c-";

View file

@ -3216,11 +3216,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));
@ -3232,7 +3230,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()
{