[v1.7.0+] Auto-Swap Ammo

A place to post your add ons and ideas for them

Moderator: Moderator

Post Reply
Message
Author
Zizzo
Sher'Tul Godslayer
Posts: 2521
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

[v1.7.0+] Auto-Swap Ammo

#1 Post by Zizzo »

Ammo capacities were nailed down back when it was assumed that the player would ony be shooting one arrow/shot at a time. Gunslingers, needless to say, will go through that ammo twice as fast, and triple-gunning Adventurers three times as fast. Uncanny Reload will buy you some time, but even that might not be enough in a protracted fight against a really tough boss (or, to pick a completely random example, a particularly stubborn eternal @#$%ing bone giant… :evil: ).

Now, T2 allows you to use ammo directly out of inventory if your quiver is empty, so the usual plan to avoid running out of ammo is simpy to carry several stacks. You can do that in T4 too, of course, but you have to spend a turn manually swapping in the new ammo when the old one runs out, and swapping them all back in one at a time to reload them can be a headache.

Well, my T2 module has an option to auto-wield ammo that you shoot from inventory, and with a bit of work, I figured I could get something like it to work here — hence my new Auto-Swap Ammo addon. Here's how it works:
  • Tag your wielded ammo with "AMMO:SWAP:primary" (without the quotes). In your inventory, tag any ammo that you want to use with auto-swapping with "AMMO:SWAP" (again, without quotes).
  • If you try to use an archery talent while your wielded ammo is empty, the game will pop up an inventory dialog listing your (non-empty) tagged ammos, to let you pick one to wield (or if there's only one, it'll just wield it directly). We hook in at the Archery:hasArcheryWeapon() level, which I think basically every archery-related talent calls at some point, so this should work for everything (he said, probably jynxing it… :oops: ).
  • When you're done and want to rest to reload your ammo, we do the reverse: if your wielded ammo is full and any of your tagged ammo in inventory isn't, the game will swap one in for it to reload it (random, I think, except that the "primary" ammo gets priority).
  • Finally, once all your tagged ammos are fully reloaded, if you aren't wielding the one tagged "primary", that one will get swapped back in.
Now, this one is pretty convoluted, so I might well have gotten something wrong; as always, here is a good place to report bugs.

[And I can see where some would consider this cheating, so it probably won't be a candidate for inclusion in ZOmnibus or ZOmnibus Lite.]

[Implementation notes:]

Code: Select all

Hooks:
  ToME:load [to hang our callbacks on the Shoot talent]
Superload:
  mod.class.interface.Archery:
    hasArcheryWeapon() [to auto-swap ammo when using talents]
"Blessed are the yeeks, for they shall inherit Arda..."

Zizzo
Sher'Tul Godslayer
Posts: 2521
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

Re: [v1.7.0+] Auto-Swap Ammo

#2 Post by Zizzo »

I knew that was too good to be true… :oops: Turns out turrets were trying to get in on our action and were trying (and failing messily) to trigger an ammo swap if they fired while the player had empty ammo. v1a appears to have that sorted out. We Apologize for the Error.™
"Blessed are the yeeks, for they shall inherit Arda..."

Zizzo
Sher'Tul Godslayer
Posts: 2521
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

Re: [v1.7.0+] Auto-Swap Ammo

#3 Post by Zizzo »

[sound F/X: forehead repeatedly striking desk] Found another corner case: the Rocket Pod talent also needs to be prevented from trying to prompt for new ammo if it fires while the player is wielding empty ammo. (Man, I really should have tested this thing with an Annihilator before releasing it… :oops: ) That should be covered in v1a.1, just pushed out; We Apologize for the Error.™
"Blessed are the yeeks, for they shall inherit Arda..."

Post Reply