Enemy Spawn Logic

The scenario has 2 spawning systems that work in tandem to create a constant warfare feeling in the scenario, they are by no means perfect but function relatively stable and fulfill their purpose. The following sections will describe how they work in order to comprehend certain aspects of the mission parameters configuration, as well as to understand how to troubleshoot the system by either a server manager or session host.

### Ambient Spawn System

This first part of the spawn systems is what predominantly drives the combat in the scenario, and it takes care of spawning randomized unweighted enemy units that can belong to any of the 5 possible factions:

* BLUFOR (CDF militia)
* REDFOR (Orlov Gang)
* GREENFOR (Boris Gang)
* CIVILIAN (UN Operations)
* RENEGADES (Tourists Scavs)

Each faction has a predefined equipment and loot-pool in order to simulate "gang wars" into the environment. This system is controlled by THIS parameters.

##### How does it work?

The system evaluates during each loop iteration if there is any valid player in raid (They are not dead + They deployed using the raid system), if there is, the system will then consider the distances set for MIN and MAX spawn ranges, do a RNG roll to determine the enemy spawn position according to the player being evaluated and then assess the position selected. If the position is deemed valid, the enemy will be able to spawn into the world and will be added to the ***group control system***.

Note that position placement can sometimes be wonky due to REDUX creation conditions using too many non-standardized assets, like rocks to create pathways or grass flats to simulate underground environments. The mission will try its best not to spawn enemies in these positions but be aware its possible. If such is the case, it's more than likely than the enemies will be able to see and engage you, but not the other way around (single sided face geometry). The system also handles building occupation, if the position for spawn is close enough for a building with position defined in config, the units will be spawned inside one of the possible positions within.

### Group Control System

The group control system is a way for the mission to know if it can and should spawn more enemies into the environment, it serves as a manipulable threshold for the mission to know when too much is too much. It allows the ***Ambient Spawn System*** to keep on spawning enemies as long as thresholds have not been surpassed. It also doubles as a cleaning system for inactive enemy groups.

You can control the thresholds by changing the following parameters in THIS section:

* Handicap Ambient Spawner.
* Maximum AI groups assigned to the server by the ambient spawner.
* Maximum AI groups assigned to each headless client (if any) by the ambient spawner.
* Host AI groups multiplier for the ambient spawner.
* Server AI groups multiplier for the ambient spawner.
* Maximum AI groups until cleaner starts searching for inactive groups created by the ambient spawner.

##### How does it work?

Each time an ambient group is created, the Group control system will be increased until reaching its total threshold. As long as the threshold it's not surpassed, the group control will allow the ambient spawner to keep creating enemy groups in the environment. Once it reaches the threshold or goes over it, the ambient spawn will be paused until the number of active groups decreases below the threshold, allowing the spawner to work once more. This process is continuous and warranties that the player will have combat at constant intervals along the play session.

The group control system is embedded in the ambient spawner, and as such they act as a single entity in the mission. If the ambient spawned is not active, neither the group control system will be.

### Base Spawn System

This is the second part of the spawn systems and it's what controls the combat with "special units" in the scenario, and it takes care of spawning specialized, weighted enemy units that can belong to any of the possible custom threats:

* PMCs
* Bosses
* Minions
* Cultists
* Snipers
* Gang detachments

This system works with THIS parameters.

##### How does it work?

Inside some cities and POIs, the behavior of the Ambient spawner stays the same with the addition of a secondary spawner activation. This spawner works independently of the ambient spawner but it's also tied to the group control system, however, each possible location in where this spawner can be active has control variables that will drive the activation of it. During mission start, the server rolls a RNG in order to determine which control variables can be activated in the session, making the custom threat dynamic. Specifically speaking, there is another factor that can drive spawns, which is server starting daytime.

The activation of this spawn system is determined by the detection interval and the distance to the CENTER position of the POI, making it be radii-based spawning. It is recommended to leave a large-ish parameter set-up in regard to this, as the lower the distance to center, the more prone the players are to have enemies spawning atop of them.

The system will determine spawn position for custom threats based on either possible randomized area position, curated static positions, full building occupation, randomized roaming, randomized rendezvous points and posterior roaming, or area defense.

PMCs and Gang detachments are more susceptible to roaming or occupation, while the rest will most likely be on curated position and area defense.

### Mission Clean-Up

The Group Control System secondary function is to act as a customized garbage collector for the mission, each time the Ambient Spawn System tries to spawn a unit, the group control system will assess if clean-up is necessary and then if it's possible to do so. The customized garbage collector also activates when the mission detects that there is no more player in a raid.

##### How does it work?

Often, the system will become active once the threshold for the *Maximum AI groups until cleaner starts searching for inactive groups created by the ambient spawner* is reached or surpassed. Once this happens, dead/empty/null groups in the Groups Control System or other units marked for deletion will be removed from the environment.

Sometimes, this can result in distant fighting being broken by the cleaner, as the active combatants can be removed to free up space and save performance due to them not being within the proximity threshold for players. If this result annoying, it can be easily corrected by increasing the maximum spawn threshold for the Ambient Spawner System, although this could impact performance on the long run.

The other way for the system to activate is the mission detecting raids being empty. Once this happens, the Mission Clean-up will clear all the groups in the Group Control System, all the corpses (both players and enemy units), all the weapon holders (everything that is on the ground) and all the vehicle wrecks. This operation happens only once in order to clear up the environment from the ambient conflict ***BUT DOES NOT INCLUDE BOSSES CUSTOM THREAT UNITS***.

It is important to note that the system has VERY SPECIFIC considerations in order to consider a raid empty. For more info regarding this, consult THIS page.