Author Topic: [DONE] Support for HWPs without fixed ammo (+ auto-recovery of non-fixed ammo)  (Read 1228 times)

Offline zRrr

  • Sergeant
  • **
  • Posts: 31
    • View Profile
Currently debriefing screen handles recovery of HWP ammo in separate branch of code. That branch does not work with multiple ammo slots, or other fixed weapons, that may be built-in in hwp armor, so any clips loaded are lost, even if they were not used.

This is an issue for Piratez. Piratez use hwps for special characters, because they can be used as research prerequisite, event triggers, etc. Recent updates introduced two characters (Lady Gudrun The Sorceress and Red Mage Ascendant) that shoot bunch of spells, using several ammo slots and action to slot mapping. Ammo for them is expensive and losing it just because it was loaded is a bit sad.

Reproduction: make HWP with several ammo slots and access to inventory. Go to battle, load all extra ammo, abort. Observe loss of clips in base inventory. I've attached mod with multiple hwps that take HC-AP, AC-AP and pistol clips for built-in second weapon.

I've tried to fix it, by moving recovery code into DebriefingState::recoverItems, and I think it works, as in 'game does not crash and I get expected number of clips back after mission'. Patch also enables merge of used hwp clips, which is difference from OXC, but does not affect unmodded games.

https://github.com/zrrr111/oxce-hwp-ammo-recovery/commit/0530b1ed822725741992f46383c2a4f062e249c3

edit 2024/04/21: moved some comments into github comments, added more testcases for multistage missions.
« Last Edit: April 21, 2024, 08:51:57 pm by zRrr »

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9098
    • View Profile
Re: Improve ammo recovery for HWPs during debriefing
« Reply #1 on: August 15, 2024, 05:26:20 pm »
Your commit is probably OK, but:

1/ there are a lot of cases to re-test... and from previous painful experience I know that any change in DebriefingState (or DogfightState) creates twice as many bugs as it solves

-> I'll try to rework your commit to be even smaller, so that I don't have to re-test so many cases.

2/ I want to be backwards-compatible not only with OXC and xcom1/xcom2 ruleset; but wherever possible also with older versions of OXCE and any existing mods for OXC/OXCE

-> I'll try to keep the primary HWP ammo recovery code unchanged.


PS: thanks for making a test mod and for all the comments in the code... both did help.

Offline zRrr

  • Sergeant
  • **
  • Posts: 31
    • View Profile
Re: Improve ammo recovery for HWPs during debriefing
« Reply #2 on: August 15, 2024, 09:52:24 pm »
Thanks for looking into this

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9098
    • View Profile
Done.
https://github.com/MeridianOXC/OpenXcom/commit/88e5a812b90d32cf40518b3ef1a8753131e38d30

At the end, I decided to recover fixed ammo and non-fixed ammo in different ways.
This should be the least invasive way.

As a bonus, you can now have HWPs without any fixed ammo (`vehicleFixedAmmoSlot: -1`).

Piratez's Lady Gudrun The Sorceress and Red Mage Ascendant should use that option for equipment and recovery to work correctly:

Code: [Select]
items:
  - type: STR_RED_MAGE_ASC_30
    vehicleFixedAmmoSlot: -1
  - type: STR_DOCTOR_X_A70
    vehicleFixedAmmoSlot: -1


@zRrr: I have tested it on those 2 piratez units, and on all xcom1/xcom2 HWPs, so far so good... when/if you have time, please retest also on your test data
« Last Edit: August 16, 2024, 04:59:42 pm by Meridian »

Offline zRrr

  • Sergeant
  • **
  • Posts: 31
    • View Profile
Ran my tests, everything worked as expected.
« Last Edit: August 17, 2024, 12:15:55 am by zRrr »