Data/Behaviors/Spawn

## Spawn

(Editor Screenshot) needs pic of hatchery launching mutant larvae

### Description

Periodically spawns units at a predefined offset relative to the unit with this behaviour

* It is very important to know that the spawned unit's model strictly obeys to the "Selection Layer" rule, which will cause the "Select Larva" button to favor the selection of certain units above others, and not all of them at once. If selecting multiple spawned units at once is required, make sure to set them the same selection layer on their model.

### Hint

* Use requirements to make the spawning conditional

## Example Usage

### Hatchery - Spawn Larvae

The behaviour on all the zerg main buildings that is responsible for spawning larvae. Spawns additional larvae when there are Hatchery - Spawn Mutant Larvae buff stacks from the ability of the queen on the structure.

### Modding Methodology for Morph/Moving Spawners by Wonder Rem:

It has been a struggle to keep track of the spawned units when the Spawner "Morphs" into a movable unit. Hence, a work around has been developped to solve it.

This kinds of acts exactly as an Arm Magazine ability does with its leash coponent, but it gives some more possiblities, such as not locking the external magazine units to exact offset positions. It is mostly used to move their leash center point location.

* The problem was that, when a unit that can spawn those unit morphed into another unit, the spawned units became "forgotten"/"uncalculated anymore" in the spawn limit, and re-morphing the spawner back to another position (or even the same) reseted the spawn limit, hence leaving the previous spawns back on the previous locations and spawning further new units in addtion of the previous ones.
* This is made for spawns that have a **LEASHED** Wander behavior. Otherwise, don't bother using this.
* Usually, at the spawning event, those spawned units can be ordered to move, and as long they have a "Leashed" wander behavior, they will head back to their spawn points once they have no commands. The ordeal was the following: when I attempted to move the spawner unit, the spawned units remained loyal to their original spawn point, making it nearly impossible to have their position update according to the spawner's new location. However, it is possible to do.

First things first, the Spawn behavior requires to apply a buff behavior on those spawns to keep track of both locations, here's the how to:

1. On the spawn behavior, create an Apply Behavior effect (put the validator: **target not dead** on it to avoid lags caused by death) that puts buff behavior on the spawns. On that behavior A, put a validator (remove) that is a unit type that requires the caster to be the X unit that spawned them. Also add as effect initial an apply behavior that puts the desired Wander behavior. Make sure it is leashed.
2. When the validator fails (of the spawner morphing into another unit), the behavior A will be removed, and you need to put an effect final: Apply Behavior again (with **target not dead** validation), that adds another buff behavior. That behavior B must have the initial effect to remove behavior any Wander buff on the target. Now, put a Validator (remove) on that second behavior that requires the caster NOT to be the spawner. Also add a periodic Issue order effect at each 0.5 second period that orders to move to caster point. Also add a modification flag: State Flag: Uncommandable. It is wishable that the spawned unit moves faster than its spawner.
3. When the validator fails (of the spawner morphing back to spawner unit type), the behavior B will be removed, and you need to put an effect final: Apply behavior that puts the Behavior A back.
4. Make sure that the other unit in which the caster spawner can morph into has the same spawn behavior, so that it doesn't lose track of its current spawns.
5. Disabling a spawn behavior doesn't work. I tried it, and it does not reset the leash point. It has to be removed, and re-added.
6. Other fixes that can be done: the requirement on the spawn behavior can require the spawner unit as "Completed at Unit" to solve 2 things: It will halt the spawning process at construction (when the construction ends, the spawns would insta create the first unit even if it has a delay), and it also prevents the spawner from Spawning units when it is morphed into the movable version.
7. It might be possible to build this old set up with a "Track unit" system, however it has not been innovated, yet.

Example units that could use this: Spine/Spore Crawlers, Flying Terran buildings, Burrowing Zerg units.

## Fields Description

### Behavior - Alignment

* Determines if the behaviour texture appears green (Positive), white (Neutral) or red (Negative)

### Behavior - Categories

* Permanent
* Restorable
* Temporary
* These are Filters, used kind of like Unit Attributes. Used by Behavior - Modification - Behavior Categories Disabled/Enabled.

### Behavior - Center

* The offset from the center of the unit with this behaviour that is used as the center to spawn units at
* (Unknown) if local or absolute relative to the global map grid

### Behavior - Info Array

#### Count

* The number of each unit from the Behavior - Info Array - Units spawned at each spawning event

#### Effect

* Effect applied to each unit from the Behavior - Info Array - Units spawned
* With the Larvae Swarm ability of the queen, this field is used to remove a stack of the Hatchery - Spawn Mutant Larvae counter buff each time a larvae is spawned from the ability

#### Max Count

Seems to be an individual limit for the info array.

* Testing with multiple arrays seems to indicated that the max count being in the prior array will prevent the other arrays from spawning. A better way to control the spawns amount overall is to use the **Limit** field instead.
* Note that at least with the Spawn Larva behavior, higher MaxCount values causes buggy selection behavior with multiple hatcheries. e.g. with a MaxCount of 24 and limit of 100, if you select 2 hatcheries then click "Select Larvae", only one of the hatchery's larvae will be selected. Even with a MaxCount of 6 and enough hatcheries, selecting larvae doesn't work as expected.

#### Requirement

* Requirements that must be met for spawning to occur
* This is what is used to limit normal Larvae spawning to a max of 3 and the Larvae Swarm larvae to the number of Hatchery - Spawn Mutant Larvae buff stacks

#### Units

* What unit type from the Units data type that is spawned at each spawning event

### Behavior - Offset

The offsets from the Behavior - Center at which spawned units can randomly appear

* This field is mandatory for the spawns to be allowed to be spawned. Having a greater limit of spawns requires this field to have as many entries as the limit of spawns.

### Behavior - Requirements

* The requirements that need to be met to enable the behavior

### Cost - Cost +

* Standard cost fields associated with applying/using the behavior
* (Unknown) if functional

### Effect - Effect

* Effect applied to any unit spawned by this behaviour

### Stats - Flags

* Hidden determines if the behaviour icon is hidden or visible in the UI

### Stats - Flags (Spawn)

* **Hide Count:** When selecting the spawner in subgroup, hides the little numeric value telling how many spawned units are currently owned by it. It appears on the group icon image on the UI.
	+ It appears that leaving hiding this count will also prevent the Command Button on unit from displaying any "Select Larva" command. This is probably a bug.

* **Ignore Morph:** If the spawned unit should morph (example burrow down), the resulting unit will still account for the max amount of spawns allowed. If not enabled, a unit that is morphed will not be considered and may result the spawner to generate nearly infinity amounts of addtional spawns.
* **Kill Spawn On Death:** Kills any units spawned by this behavior when the spawning unit with it dies. If the spawned unit has a buff behavior with "Cannot Die", the death may be defied.

### Stats - Limit

* Maximum number of spawns of any kind that this behavior can have alive at one time

### Stats - Range

* Maximum distance from the spawning unit that a unit can be spawned at

### Stats - Slop

* Maximum distance from the intended spawning location a unit can spawn if the location is blocked/unpathable

### UI - Display Countdown

* Displays the countdown before the next spawned unit is created.

### UI - Tooltip

* The text displayed if the mouse cursor is moved over the behaviour icon ingame

## Related

* Effects
* Units
* Requirements