aliens

Author Topic: spawn aliens randomly for a given rank ?  (Read 14940 times)

Offline robin

  • Commander
  • *****
  • Posts: 1225
  • ULTIMATE ROOKIE
    • View Profile
spawn aliens randomly for a given rank ?
« on: January 16, 2017, 11:58:51 pm »
The Spitter in my mod has several variants.
They're all "Spitters", so they ideally should represent a single rank within a given alien race.
Also, more simply, if I put one variant per rank I'd clog the alien race with Spitters, leaving too little room for other species of aliens (ranks are AFAIK a fixed number).

In ruleset terms I'd like to so something like this:

alienRaces:
  - id: STR_MY_ALIEN_RACE
    members:
      - STR_ALIEN_COMMANDER
      - STR_ALIEN_LEADER
      - STR_ALIEN_ENGINEER
      - STR_ALIEN_MEDIC
      - STR_ALIEN_NAVIGATOR
      - [STR_ALIEN_A, STR_ALIEN_B, STR_ALIEN_C]
      - STR_ALIEN_MONSTER
      - STR_ALIEN_TERRORIST

so when in the alienDeployments you have the following:

    data:
      - alienRank: 5
        lowQty: n
        highQty: n

means it will pick (AKA spawn) n aliens randomly from the [STR_ALIEN_A, STR_ALIEN_B, STR_ALIEN_C] list...
...but of course this is all fictional.

Question is: is there a way to obtain the same result somehow?

Thanks.
« Last Edit: January 17, 2017, 12:02:04 am by robin »

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11732
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: spawn aliens randomly for a given rank ?
« Reply #1 on: January 17, 2017, 12:18:24 am »
An interesting feature, modding-wise. I'm not sure I'd be using it, but it looks strangely attractive.

Offline robin

  • Commander
  • *****
  • Posts: 1225
  • ULTIMATE ROOKIE
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #2 on: January 17, 2017, 12:36:02 am »
An interesting feature, modding-wise. I'm not sure I'd be using it, but it looks strangely attractive.
We'll I'm not exactly requesting a feature, just asking if someone was able to achieve some kind of randomization, similar to that I described, within the current rules.

Also, the "builtInWeaponSets" option sort of makes up for it, since it enables me to mix terror units to normal units in every combination (inside an alien race), because I'm not tied to the alienDeployments itemSets anymore.

Offline Nord

  • Commander
  • *****
  • Posts: 1748
  • The Gate is open.
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #3 on: January 17, 2017, 10:58:37 am »
I see an ugly decision: many-many races with all but one same units, and randomization in race choosing(alienmissions or missionscripts)

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9106
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #4 on: January 17, 2017, 11:12:17 am »
We'll I'm not exactly requesting a feature, just asking if someone was able to achieve some kind of randomization, similar to that I described, within the current rules.

If you (or someone else) wanted, this feature (or something very similar) could be quite easily implemented.
Just say.

Offline Hobbes

  • Commander
  • *****
  • Posts: 2102
  • Infiltration subroutine in progress
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #5 on: January 17, 2017, 08:04:18 pm »
Also, more simply, if I put one variant per rank I'd clog the alien race with Spitters, leaving too little room for other species of aliens (ranks are AFAIK a fixed number).

You can have more than 8 ranks on each alienRace entry (on my Area 51 mod all the alienRaces have 12 ranks), so you could define the alienRace as:

Code: [Select]
alienRaces:
  - id: STR_MY_ALIEN_RACE
    members:
      - STR_ALIEN_COMMANDER
      - STR_ALIEN_LEADER
      - STR_ALIEN_ENGINEER
      - STR_ALIEN_MEDIC
      - STR_ALIEN_NAVIGATOR
      - STR_ALIEN_A
      - STR_ALIEN_B
      - STR_ALIEN_C
      - STR_ALIEN_MONSTER
      - STR_ALIEN_TERRORIST

But for it to work, you'll also need to adjust the alienDeployment entries where these extended alienRaces are used, such as:

Code: [Select]
  - type: STR_TERROR_MISSION
    data:
      - alienRank: 5
        lowQty: 4
        highQty: 8
        dQty: 1
      - alienRank: 3
        lowQty: 3
        highQty: 3
        dQty: 1
      - alienRank: 1
        lowQty: 1
        highQty: 1
        dQty: 0
      - alienRank: 6
        lowQty: 0
        highQty: 1
        dQty: 1
      - alienRank: 7
        lowQty: 0
        highQty: 1
        dQty: 1
      - alienRank: 8
        lowQty: 0
        highQty: 1
        dQty: 1
      - alienRank: 9
        lowQty: 0
        highQty: 1
        dQty: 1

However, there's one major caveat that you need to be aware concerning the spawning of the additional ranks: the map files can only contain information about 8 ranks, so what OXC does to place these units is that it considers all additional ranks (8 and 9 on this example) as rank 0, which is used on the map files to spawn alien scouts (units that start outside the UFO), terror units and civilians. So, if you have rank 8, 9 or more, they'll only spawn on route nodes assigned to rank 0.

The way I solved this issue in Area 51 was that I simply assigned the 4 additional ranks only to terror units, so those will always spawn on correct locations. But you can also use enlarged alienRaces to spawn non-terror units of ranks 8 or more, if you use builtInWeaponSets to ensure that they'll start equipped with weapons (assuming that you don't want to assign weapons to those ranks through alienDeployments). However, remember that those non-terror units will always be spawned in rank 0 nodes.

One final suggestion I make is that you either convert all alienRaces to the enlarged format, or there's a risk that an alienDeployment will require the enlarged alienRace to work but the missionScript will randomly assign it a vanilla alienRace, and the missing ranks will cause the game to crash. But, if you limit the enlarged alienRaces to specific alienDeployments you don't run this risk.
« Last Edit: January 17, 2017, 08:12:57 pm by Hobbes »

Offline robin

  • Commander
  • *****
  • Posts: 1225
  • ULTIMATE ROOKIE
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #6 on: January 17, 2017, 11:20:26 pm »
If you (or someone else) wanted, this feature (or something very similar) could be quite easily implemented.
Just say.
Thanks for the availability.
I'd honestly use it only for the spitters, so a very specific and limited problem.
Let's wait and see if other modders find more concrete uses for this feature; I can manage with Hobbes' workaround (enlarged races) if I am the only one with this issue.


-cut-
Very useful, thanks!

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11732
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: spawn aliens randomly for a given rank ?
« Reply #7 on: January 18, 2017, 01:40:55 am »
Well, I also have Spitters, so... :P

Offline robin

  • Commander
  • *****
  • Posts: 1225
  • ULTIMATE ROOKIE
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #8 on: January 19, 2017, 10:56:32 pm »
Well, I also have Spitters, so... :P
:P

I can see this feature used anytime you need variety (even if only visual) for a specific unit (or rank), and you don't want to waste multiple ranks.

Example: male/female versions of the same unit. Currently AFAIK you have to use two ranks, one for the male version and one for the female (I actually do this too in my mod, having male/females version for a bunch of human units).
With this feature you could do something like

  - id: STR_ARMY
    members:
      [...]
      - [STR_SOLDIER_MALE, STR_SOLDIER_FEMALE]
      [...]

so a single rank is used to spawn a random amount of males/females soldiers.. which makes sense on paper.

Maybe there are better solutions for this problem. All this is from the top of my head.

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11732
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: spawn aliens randomly for a given rank ?
« Reply #9 on: January 19, 2017, 11:20:13 pm »
Actually we discussed a similar idea on the Piratez channel on Discord, and my idea was exactly that. So, yeah, I'd like that a lot - if only for more varied human enemies.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9106
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #10 on: January 20, 2017, 08:01:22 pm »
means it will pick (AKA spawn) n aliens randomly from the [STR_ALIEN_A, STR_ALIEN_B, STR_ALIEN_C] list...

So, if n=5

1/ would you expect 5 aliens of the same randomly chosen type... e.g. 5x STR_ALIEN_B

2/ or would you expect a mix of different types... e.g. 2x STR_ALIEN_A + 2x STR_ALIEN_B + 1x STR_SLIEN_C

I already did the first option... but then I thought, you may have meant option 2 ?


Offline robin

  • Commander
  • *****
  • Posts: 1225
  • ULTIMATE ROOKIE
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #11 on: January 20, 2017, 10:40:42 pm »
So, if n=5

1/ would you expect 5 aliens of the same randomly chosen type... e.g. 5x STR_ALIEN_B

2/ or would you expect a mix of different types... e.g. 2x STR_ALIEN_A + 2x STR_ALIEN_B + 1x STR_SLIEN_C

I already did the first option... but then I thought, you may have meant option 2 ?
Yeah I meant option 2, a mix (don't know about Solarius though).
So if n=5:
2* STR_ALIEN_A +2* STR_ALIEN_B + 1* STR_ALIEN_C
or
4* STR_ALIEN_A + 1* STR_ALIEN_B + 0* STR_ALIEN_C
or
1* STR_ALIEN_A + 1* STR_ALIEN_B + 3* STR_ALIEN_C
and so on.

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11732
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: spawn aliens randomly for a given rank ?
« Reply #12 on: January 20, 2017, 11:12:23 pm »
I agree. Here's a quote of myself from the Discord channel:

Quote
[21:38] Solarius Scorch: I'm definitely more interested in the second option, because with the first, I could just as well make another race...(edytowane)
[21:39] Solarius Scorch: Plus, I'm not sure why I would want a random rank, but only with the same dudes. Can't think of a scenario...

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 9106
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #13 on: January 21, 2017, 10:18:01 am »
Yeah I meant option 2, a mix (don't know about Solarius though).
So if n=5:
2* STR_ALIEN_A +2* STR_ALIEN_B + 1* STR_ALIEN_C
or
4* STR_ALIEN_A + 1* STR_ALIEN_B + 0* STR_ALIEN_C
or
1* STR_ALIEN_A + 1* STR_ALIEN_B + 3* STR_ALIEN_C
and so on.

OK, done.

Source code: https://github.com/MeridianOXC/OpenXcom/commit/3b210888fbeb6a98f9a905d4be1e3ab8d00c1896
Will be part of next OXCE+ version.

Example:

Code: [Select]
alienRaces:
  - id: STR_SECTOID
    members:
      - STR_SECTOID_COMMANDER
      - STR_SECTOID_LEADER
      - STR_SECTOID_ENGINEER
      - STR_SECTOID_MEDIC
      - STR_SECTOID_NAVIGATOR
      - STR_SECTOID_SOLDIER
      - STR_CYBERDISC_TERRORIST
      - STR_CYBERDISC_TERRORIST
    membersRandom:
      - [STR_SECTOID_COMMANDER]
      - [STR_SECTOID_LEADER]
      - [STR_SECTOID_ENGINEER,STR_FLOATER_ENGINEER]
      - [STR_SECTOID_MEDIC,STR_FLOATER_MEDIC]
      - [STR_SECTOID_NAVIGATOR,STR_FLOATER_NAVIGATOR]
      - [STR_SECTOID_SOLDIER,STR_FLOATER_SOLDIER]
      - [STR_CYBERDISC_TERRORIST,STR_REAPER_TERRORIST]
      - [STR_CYBERDISC_TERRORIST,STR_REAPER_TERRORIST]

There is a new attribute "membersRandom", which allows you to define a list for each rank.

You just need one of the two attributes "members" or "membersRandom".... if both are present (like in this example), "membersRandom" is used and "members" is ignored.

Each item in the list has same probability, if you wanted to spawn more sectoid soldiers than floater soldiers, you could duplicate them in the list.
E.g. [STR_SECTOID_SOLDIER,STR_SECTOID_SOLDIER,STR_FLOATER_SOLDIER] will spawn twice as many sectoids as floaters, in average case.

PS: if you're wondering why I introduced a new attribute, it's because it's easier and backwards-compatible.
« Last Edit: January 21, 2017, 10:19:38 am by Meridian »

Offline robin

  • Commander
  • *****
  • Posts: 1225
  • ULTIMATE ROOKIE
    • View Profile
Re: spawn aliens randomly for a given rank ?
« Reply #14 on: January 21, 2017, 11:13:03 am »
That was fast.
I'm definitely going to use it.