aliens

Author Topic: [DONE][Suggestion] Add support for randomized (weighted) unit built-in weapon sets  (Read 2430 times)

Offline Surrealistik

  • Colonel
  • ****
  • Posts: 486
    • View Profile
It would be nice if we could designate a set of loadouts/weapon sets that are randomly selected for a unit at each tech level, along with weighting values to make them more or less likely to be picked relative to other options at that tech level.

This would prevent us from having to messily kludge it by creating alternate versions/duplicates of the same unit simply for loadout variation.

Essentially adding the following parameters to builtInWeaponSets:

techLevel: Defaults to 1. The level of tech that this loadout is eligible for random selection in. If there are no loadouts eligible for a given tech level, it will default to selecting from eligible options for the tech level immediately prior (so if there are no techLevel 3 loadouts, it will default to techLevel 2 loadouts, and so on).

Weight: Defaults to 1. The relative chance of this loadout being picked if eligible for selection; final probability of a loadout being selected is equal to its weight divided by the total weight of all eligible loadouts. For example an eligible loadout with a weight of 50 while two other eligible loadouts have a weight of 30 and 10 would have a 62.5% chance of being selected: 50 / (50 + 30 + 10) = 0.625

maxPicks: Defaults to 0 (no limit). The maximum number of times this loadout can be picked. If a loadout hits its maximum, it can no longer be picked, and its weight is discounted for the purposes of determining pick probability.

minPicks: Defaults to 0 (no minimum). The minimum number of times this loadout can be picked. If the number of loadouts for a unit of this type remaining to be picked is equal to or less than the total amount of minPick loadouts for the appropriate tech level, it will automatically pick these options; they are prioritized according to weight. So if there are say 7 loadouts for a unit to be picked for a given tech level, and the total value of minPick loadouts is 5 (one loadout has a 3 minPick value, and another has a 2 minPick value), 5 of those loadouts will automatically be determined: 3 going to one minPick loadout, 2 going to the other minPick; the rest will be randomly determined by weights as normal. If there are only 4 loadouts to be picked and 5 minPick loadouts, they are randomly allocated from among the minpick options according to weight as normal; minPick loadout options that hit their quota from this pool are excluded from subsequent random allocations; in this example, if the loadout with a 2 minPick value is randomly selected twice, 'satisfying' it, the rest automatically go to the 3 minPick value loadout.

If there is only one loadout eligible for a tech level, it will be picked automatically regardless of the Weight value.

For example,

Code: [Select]
    builtInWeaponSets:
        techLevel: 1
        Weight: 30
        - STR_PISTOLS
        - STR_CHAOS_CLAWS
        - STR_PISTOL_CLIP_AP
        - STR_PISTOL_CLIP_AP
        - STR_ALIEN_GRENADE
        techLevel: 1
        Weight: 70
        - STR_PISTOLH
        - STR_CHAOS_CLAWS
        - STR_RIFLE_CLIP_AP
        - STR_RIFLE_CLIP_AP
        - STR_ALIEN_GRENADE
        - STR_KRAK_GRENADE
        techLevel: 1
        Weight: 30
        - STR_PISTOLS
        - STR_CHAOS_CLAWS
        - STR_PISTOL_CLIP_AP
        - STR_PISTOL_CLIP_AP
        - STR_ALIEN_GRENADE
        techLevel: 2
        Weight: 25
        minPicks: 2
        - STR_PLASMA_PISTOL
        - STR_CHAOS_CLAWS
        - STR_PLASMA_PISTOL_CLIP
        - STR_PLASMA_PISTOL_CLIP
        - STR_MGRENADE
        techLevel: 2
        Weight: 50
        - STR_PLASMA_RIFLE
        - STR_PLASMA_RIFLE_CLIP
        - STR_PLASMA_RIFLE_CLIP
        - STR_MGRENADE
        techLevel: 2
        Weight: 10
        maxPicks: 1
        - STR_MGRENADE
        - STR_MGRENADE
        - STR_MGRENADE
        - STR_MGRENADE
        - STR_MGRENADE
« Last Edit: June 19, 2024, 03:17:04 am by Surrealistik »

Offline Rangerh

  • Colonel
  • ****
  • Posts: 126
    • View Profile
A list of loadouts bound each to a techlevel is a great idea, as it would cut down on the need to add different versions of the exact same unit with just a different loadout to fit game progression.

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9078
    • View Profile
Re: [Suggestion] Add Support for Random Unit Loadouts Under builtInWeaponSets
« Reply #2 on: September 24, 2024, 10:20:56 pm »
Is this an OXC or OXCE suggestion?

EDIT: I've been informed Surrealistik is a ROSIGMA contributor, so I assume this is an OXCE suggestion... moved to OXCE subforum
« Last Edit: September 25, 2024, 10:25:40 am by Meridian »

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9078
    • View Profile
Re: [Suggestion] Add Support for Random Unit Loadouts Under builtInWeaponSets
« Reply #3 on: September 25, 2024, 10:32:26 am »
I wanted to write a long reply, but that would probably be counter-productive.
Long story short:
1. the suggestion as described cannot be done, the syntax is not a valid YAML
2. assuming (some other) valid YAML, `minPicks` is logically not doable, or at least not the way it's described
3. assuming (some other) valid YAML, `maxPicks` is doable, but it would complicate the code a LOT, probably not worth the effort

I tried to extract the gist of the request and came up with three requirements:
1. support more than one option per "item set" (in the request incorrectly called "tech level") -- Terminology on ufopaedia.org
2. add weights
3. (my own addition) support named "weapon sets" to cut down on copy-paste

Proposed new syntax is attached as picture.
Does that look useful?
« Last Edit: September 29, 2024, 12:36:06 pm by Meridian »

Offline Buscher

  • Colonel
  • ****
  • Posts: 168
    • View Profile
Re: [Suggestion] Add Support for Random Unit Loadouts Under builtInWeaponSets
« Reply #4 on: September 25, 2024, 11:40:49 am »
It does look useful and should fit 99 % of the bill in my opinion. The proposed YAML syntax looks fine and easy to use.

As far as I understand the goal is to have something similar to mapScripts (blocks, freqs, maxUses) but for weapon loadouts. Depending on how the settings for `minPicks` and `maxPicks` is used, it's possible to have funny behaviours for small and huge number of enemies. For example if you spawn only two enemy units in battleScape and weapon set 1 has minPicks: 1 while weapon set 2 has minPicks: 3, which set should get preference? Of course you can do that with weights again but I assume that a lot of unintentional behaviour/edge cases show up which makes writing the feature/modding/debugging issues unnecessarily hard.

In general the way Meridian proposes (weight only, no min or max) should be good enough for most (read 99 %) of the scenarios and help cut down duplicated units which have different builtInWeaponSets. We (ROSIGMA) currently consider to pick these duplicated units via `membersRandom` as part of `alienRaces` to have seemingly random loadouts with special considerations for faction specific weaponry (The four Chaos Gods, Eldar, etc.). I assume that `maxPicks` is mainly for very dangerous weapons (read Blaster Bomb level or any above average weaponry) which are probably linked to more elite units anyway and can probably be done with elite tier of units which are limited by `alienRank` in `alienDeployments`.

As a side note, ROSIGMA doesn't use the itemSets as part of alienDeployments. They are empty lists (due to multiple faction specific weapons, etc.). Mainly builtInWeaponSets are used instead.

Offline Surrealistik

  • Colonel
  • ****
  • Posts: 486
    • View Profile
Re: [Suggestion] Add Support for Random Unit Loadouts Under builtInWeaponSets
« Reply #5 on: September 26, 2024, 11:04:13 am »
I wanted to write a long reply, but that would probably be counter-productive.
Long story short:
1. the suggestion as described cannot be done, the syntax is not a valid YAML
2. assuming (some other) valid YAML, `minPicks` is logically not doable, or at least not the way it's described
3. assuming (some other) valid YAML, `maxPicks` is doable, but it would complicate the code a LOT, probably not worth the effort

I tried to extract the gist of the request and came up with three requirements:
1. support more than one option per "item set" (in the request incorrectly called "tech level") -- Terminology on ufopaedia.org
2. add weights
3. (my own addition) support named "weapon sets" to cut down on copy-paste

Proposed new syntax is attached as picture.
Does that look useful?

Looks good! Should cover most use cases.

Online Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9078
    • View Profile
Done.

Sample ruleset:

Code: [Select]
weaponSets:  # these can be re-used for any unit
  - type: MY_WEAPON_SET_1
    weapons: [STR_PISTOL, STR_PISTOL_CLIP]
  - type: MY_WEAPON_SET_2
    weapons: [STR_RIFLE, STR_RIFLE_CLIP, STR_GRENADE]
  - type: MY_WEAPON_SET_3
    weapons: [STR_LASER_RIFLE, STR_HIGH_EXPLOSIVE]
  - type: MY_WEAPON_SET_4
    weapons: [STR_HEAVY_CANNON, STR_HC_HE_AMMO]
  - type: MY_WEAPON_SET_5
    weapons: [STR_ROCKET_LAUNCHER, STR_LARGE_ROCKET, STR_MEDI_KIT]

Code: [Select]
units:
  - type: STR_SECTOID_SOLDIER
    weightedBuiltInWeaponSets:
      - # item set 0 (easy)
        MY_WEAPON_SET_1: 50
        MY_WEAPON_SET_2: 30
        MY_WEAPON_SET_3: 20
      - # item set 1 (dangerous)
        MY_WEAPON_SET_2: 20
        MY_WEAPON_SET_3: 60
        MY_WEAPON_SET_4: 20
      - # item set 2 (deadly)
        MY_WEAPON_SET_4: 50
        MY_WEAPON_SET_5: 50

Tip: You don't need to duplicate entries if you have the same stuff in each item set.
If item set X is missing, the game will look for an item set with a lower number than X.

Code: [Select]
  - type: STR_SECTOID_NAVIGATOR
    weightedBuiltInWeaponSets:
      - # item set 0, 1 and 2 (easy, dangerous and deadly)
        MY_WEAPON_SET_2: 50
        MY_WEAPON_SET_4: 50