aliens

Author Topic: [DONE][Suggestion] Ammo priority for automatic weapon loading in equipment screen  (Read 672 times)

Offline Darox

  • Squaddie
  • *
  • Posts: 5
    • View Profile
Guns in the base/craft storage are automatically loaded with ammo if possible, but what determines which ammo is selected when multiple types are available?

I have two different sets of rifles that have shared ammo, and are also able to use pistol ammo of their same type.
Code: ("Set A") [Select]
    compatibleAmmo:
      - STR_RIFLE_CLIP_A
      - STR_PISTOL_CLIP_A
Code: ("Set B") [Select]
    compatibleAmmo:
      - STR_RIFLE_CLIP_B
      - STR_PISTOL_CLIP_B

Ideally both groups of rifles would be loaded with rifle ammo by default, but for whatever reason Set A defaults to the pistol ammo and Set B defaults to rifle ammo. Changing listOrder doesn't have any effect and nothing else in the ruleset reference seems relevant.

Is there a way to change the default ammo selection?

Offline Darox

  • Squaddie
  • *
  • Posts: 5
    • View Profile
Re: Ammo priority for automatic loading in equipment screen
« Reply #1 on: February 26, 2025, 06:00:00 am »
After some more experimentation it appears that the default ammo chosen is determined by the initial load order of items as they get read from .rul files. This creates several problems, both because I am creating a submod and cannot easily rearrange the load order of items and because some of those items have scripts attached to them in separate .rul files.

Deleting all of the ammo items and then recreating them again in full in my mod and having to include every script that touches the item in the same .rul file to ensure it loads properly is extremely awkward, so I guess this has changed into a request/suggestion thread asking that the default ammo choice for loading weapons in craft/base loadouts is determined by whichever item is first in the compatibleAmmo: list, making it much easier for modders to determine and change which ammo is selected.
« Last Edit: February 26, 2025, 08:50:01 am by Darox »

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9415
    • View Profile
Re: Ammo priority for automatic loading in equipment screen
« Reply #2 on: February 26, 2025, 10:04:19 am »
After some more experimentation it appears that the default ammo chosen is determined by the initial load order of items as they get read from .rul files.

Not quite.
In OXCE, it is determined by the order of ruleset objects in memory (i.e. "practically random").
If you start the game a few times and load the same save before battle, you'll eventually see that it loads a different ammo under the same circumstances.

...so I guess this has changed into a request/suggestion thread asking that the default ammo choice for loading weapons in craft/base loadouts is determined by whichever item is first in the compatibleAmmo: list, making it much easier for modders to determine and change which ammo is selected.

I'll check, no promises yet.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9415
    • View Profile
Re: Ammo priority for automatic loading in equipment screen
« Reply #3 on: February 26, 2025, 11:07:17 am »
I can add loading priority by some ammo attribute relatively easily, for example by ammo item's `listOrder`.
Is that enough?

FYI, in OXC it is by ammo item type (e.g. STR_xxx) alphabetically.
For me that is also "practically random", so listOrder would be preferred since modders can change it easier than type.


Adding loading priority by some weapon attribute (e.g. `compatibleAmmo` list) would be a lot harder.
Also in OXCE, there is not 1 compatibleAmmo list, but 4, one for each ammo slot.

Offline Darox

  • Squaddie
  • *
  • Posts: 5
    • View Profile
Re: Ammo priority for automatic loading in equipment screen
« Reply #4 on: February 26, 2025, 12:14:31 pm »
I would be more than happy with listOrder, that's an understandable and controllable option.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9415
    • View Profile
Re: [Suggestion] Ammo priority for automatic loading in equipment screen
« Reply #5 on: February 26, 2025, 02:55:02 pm »
I will add a new parameter `loadOrder`.
(if not specified by the mod(der), the `loadOrder` will have the same value as `listOrder`)

So that load order doesn't impact list display order (i.e. so you can still display pistols above rifles, but load rifle ammo before pistol ammo).

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3436
  • Posts: 421
    • View Profile
Re: [Suggestion] Ammo priority for automatic loading in equipment screen
« Reply #6 on: February 27, 2025, 05:12:42 pm »
One problem I see if two items have same ammo available and I want load in different order in each weapon.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9415
    • View Profile
I will add a new parameter `loadOrder`.
(if not specified by the mod(der), the `loadOrder` will have the same value as `listOrder`)

So that load order doesn't impact list display order (i.e. so you can still display pistols above rifles, but load rifle ammo before pistol ammo).

Implemented: https://github.com/MeridianOXC/OpenXcom/commit/861d7085e9983c543f3eef48096461409d4b2acc

Sample ruleset:

Code: [Select]
items:
  - type: STR_SMALL_ROCKET
    loadOrder: 30
  - type: STR_LARGE_ROCKET
    loadOrder: 20
  - type: STR_INCENDIARY_ROCKET
    loadOrder: 10