OpenXcom Forum

Modding => Work In Progress => Topic started by: robin on January 16, 2017, 11:58:51 pm

Title: spawn aliens randomly for a given rank ?
Post by: robin 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Solarius Scorch 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: robin 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Nord 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)
Title: Re: spawn aliens randomly for a given rank ?
Post by: Meridian 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Hobbes 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: robin 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!
Title: Re: spawn aliens randomly for a given rank ?
Post by: Solarius Scorch on January 18, 2017, 01:40:55 am
Well, I also have Spitters, so... :P
Title: Re: spawn aliens randomly for a given rank ?
Post by: robin 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Solarius Scorch 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Meridian 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 ?

Title: Re: spawn aliens randomly for a given rank ?
Post by: robin 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Solarius Scorch 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...
Title: Re: spawn aliens randomly for a given rank ?
Post by: Meridian 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.
Title: Re: spawn aliens randomly for a given rank ?
Post by: robin on January 21, 2017, 11:13:03 am
That was fast.
I'm definitely going to use it.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Eddie on January 25, 2017, 04:33:37 pm
Quote
[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...

I can think of a scenario. To create more different deployments from the same race. I guess I have to explain that a bit...

A weakness of xcom mission generation is that deployments are too predictable. For the first UFO of a mission the race is a surprise, but for all following UFOs, if you know what UFO it is, you know more or less exactly what you will face.
With random option 2, you can mix it up a bit. You can do things like adding the odd tough enemy. Say a 10% chance on a sectoid crew that a sectoid soldier will be a muton instead. If surprise is the intention, option 2 works only well with low probabilities. But if you have like a 50% chance, the deployments become predictable again.

Option 1 can be used to create more surprises for the player. Like mixed crews.
Simplyfied example: Two ranks, each rank has all races in them with equal probability (sectoid, floater, snakemen, muton, ethereal), deploy 10 aliens per rank for a total of 20. With option 2 the deployment will give you 4 members of each race on average. With option 1, you would only see two races. So option 1 would generate very unpredictable deployments, while option 2 would create deployments that are more pedictable.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Hobbes on January 25, 2017, 06:43:08 pm
I can think of a scenario. To create more different deployments from the same race. I guess I have to explain that a bit...

A weakness of xcom mission generation is that deployments are too predictable. For the first UFO of a mission the race is a surprise, but for all following UFOs, if you know what UFO it is, you know more or less exactly what you will face.

You can do this already with alternative alienDeployments for UFOs although it requires slightly more work. You'll need to define several variants for each UFO (STR_MEDIUM_SCOUT_1, STR_MEDIUM_SCOUT_2, etc.), then create variants of alienMissions using those alternative UFOs, and finally setting up the alienDeployments with your choice of ranks. If you create just 3 variants for each UFO then the player will always be uncertain of which one he'll be facing.

Quote
With random option 2, you can mix it up a bit. You can do things like adding the odd tough enemy. Say a 10% chance on a sectoid crew that a sectoid soldier will be a muton instead. If surprise is the intention, option 2 works only well with low probabilities. But if you have like a 50% chance, the deployments become predictable again.

The issue here is that you risk facing tougher enemies like Mutons right from the 1st month. Which is perfectly acceptable if that is your goal, but if you're sticking to the original race progression then this solution won't work.

Quote
Option 1 can be used to create more surprises for the player. Like mixed crews.
Simplyfied example: Two ranks, each rank has all races in them with equal probability (sectoid, floater, snakemen, muton, ethereal), deploy 10 aliens per rank for a total of 20. With option 2 the deployment will give you 4 members of each race on average. With option 1, you would only see two races. So option 1 would generate very unpredictable deployments, while option 2 would create deployments that are more pedictable.

Mixed crews are nice to have but you should consider also that players will be expecting to face crews of a single race, like vanilla. On the earlier versions of my Area 51 mod I had almost 200 alienRaces defined, where you'd have the vanilla Sectoid, but then all sorts of mixtures, like Sectoids/Floaters, Sectoids and Sectopods or Chryssalids instead of Cyberdiscs, etc. But the feedback I got from players was that the mixed crews were OK but they were missing the single race crews, which were still possible to appear but at a much lower probability.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Nord on December 19, 2018, 06:53:29 am
A question: Which alienRank should i use in alenDeployement section to spawn these random race members?
Title: Re: spawn aliens randomly for a given rank ?
Post by: Hobbes on December 19, 2018, 04:45:11 pm
A question: Which alienRank should i use in alenDeployement section to spawn these random race members?

Are trying to use the "membersRandom" option with the vanilla game?
Title: Re: spawn aliens randomly for a given rank ?
Post by: Nord on December 19, 2018, 05:14:05 pm
No, just can not understand a syntax.
membersRandom defines units in race description. Then we must place these units on map. In alienDeployements section. How?
Title: Re: spawn aliens randomly for a given rank ?
Post by: Hobbes on December 19, 2018, 05:29:11 pm
No, just can not understand a syntax.
membersRandom defines units in race description. Then we must place these units on map. In alienDeployements section. How?

You can't use alienDeployments to place units in a map, you'll need to edit the map blocks and add spawn nodes
Title: Re: spawn aliens randomly for a given rank ?
Post by: Nord on December 20, 2018, 02:14:54 am
Routes define WHERE to place units. And alienDeployement define WHO will be placed.
Title: Re: spawn aliens randomly for a given rank ?
Post by: The Reaver of Darkness on December 20, 2018, 05:45:20 am
Example:

Code: [Select]
    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]

Can I add the same unit multiple times to the list, in order to make that unit more likely to spawn?

Example:
Code: [Select]
    membersRandom:
      - [STR_SECTOID_COMMANDER,STR_SECTOID_COMMANDER,STR_SECTOID_COMMANDER,STR_ETHEREAL_COMMANDER,STR_FLOATER_COMMANDER]

edit: never mind, I answered my own question with a simple test. Yes it does work that way, unless I encountered very strange odds.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Nord on December 20, 2018, 07:46:32 am
Ah, got it. One must write a set of random members for all ranks. Was'nt clear from initial description. Thanks.
Title: Re: spawn aliens randomly for a given rank ?
Post by: Meridian on December 21, 2018, 01:53:18 pm
Routes define WHERE to place units. And alienDeployement define WHO will be placed.

No... as far as I know, routes (or better said nodes) define WHERE and WHO to spawn... alienDeployment says HOW MANY.

WHERE being a tile/position
WHO being an alien rank
HOW MANY being a range between min and max
Title: Re: spawn aliens randomly for a given rank ?
Post by: The Reaver of Darkness on December 26, 2018, 06:31:33 am
Yes, the spawn nodes on the map have rank values. As I understand it, a given rank alien can spawn on their own rank or lower. So if you make three commander spawn points and the map spawns one commander, it'll put it randomly on any of the three commander nodes. The commander can spawn on a navigator node if it needs to, but it'll prefer a commander node if one is available. The remaining two commander nodes will go unused. Let's say you have 2 medic nodes, 3 navigator nodes, and plenty of soldier nodes on your map. You change the craft data to spawn five medics: two go into medic nodes, three go into the navigator nodes, and all navigators are forced into soldier nodes. So when you walk into the cockpit, you find a bunch of physicians in there trying to fly the ship to the alien hospital. Probably why the thing crashed, amiright?

   The deployment ruleset determines the number of aliens that spawn, i.e. 2-5 d3: the 2-5 sets the base range. Easy difficulties (Beginner and Experienced) spawn the minimum, 2. Hard difficulty (Superhuman) spawns the maximum, 5. Medium difficulties (Veteran and Genius) spawn the amount that's halfway in between them. In this case it is 3.5, so it rounds down to 3. The d3 means that after the initial number is chosen, it rolls 0 to 3 more. So Easy spawns 2-5, Medium spawns 3-6, and Hard spawns 5-8.
   The rest of the deployment ruleset data determines the equipment sets that each rank will have at each tech level. By default there are three sets, corresponding to tech levels 0, 1, and 2. When the map spawns, the game goes to the alienItemLevels section of the ruleset and determines how advanced it is in the game, and scrolls down that many lines. The line chosen dictates the likelihood of each tech level spawning. So for example let's say our item level line reads [0, 0, 0, 0, 0, 0, 0, 1, 1, 2]. The game is spawning in a soldier, so it randomly selects a number from the line. We have a 70% chance of getting a 0, 20% chance we get 1, and 10% chance we get 2. Let's say the soldier's possible equipment sets are: 0) plasma pistol, 1) plasma rifle, 2) heavy plasma. We roll a 0 and this soldier is given that first equipment set, plasma pistol. So if the UFO has around ten or more soldiers, there's a good chance we'll see at least one heavy plasma on one. But other ranks may be different. An engineer might have equipment sets 0) plasma rifle, 1) heavy plasma, 2) heavy plasma, and then any engineers we see have a 70% chance of having a plasma rifle, 30% chance of having heavy plasma, and will never have a plasma pistol. So you can affect the weapon layout either by making it different between ranks, or by setting up your alienItemLevels.