Generator
The generator module allows you to dynamically generate units, groups & static objects on the fly.
Example
The following example is lifted directly from the random_air_traffic module, because it uses generator
under the hood.
generator
:new()
:using_template(template) -- sets the template
:from_pool_of(pool_size):groups() -- sets the original count of groups available
:generate(max_groups):groups() -- sets how many groups to spawn at once
:every(20):seconds() -- sets the generation interval
:until_there_are(max_groups):groups() -- sets the maximum number of active groups
:at_random_locations(coordinates) -- sets the locations in which these groups could appear
:at_altitude(start_altitude) -- sets the altitude at which these groups appear
:with_rules_of_engagement(roe) -- sets the ROE for the groups
:with_reaction_to_threat(rtt) -- sets the RTT for the groups
:spawn() -- kicks it all off
generator:new
Initializes the generator.
Warning
You need to do this before each call to start in order for this module to work correctly.
generator:from_pool_of
generator:deep_clone
You won't typically need this however I've left this public just in case. Use this to create a deep, recursive clone of any table. Useful for spawning units and groups based on templates. Typically used by other generator functions.deep_clone
Warning
This function will not do the job of renaming the cloned groups so be careful when adding the group or unit to a coalition.deep_clone There is the generator:get_next_unit_name and generator:get_next_group_name to assist with this.
generator:groups
generator:generate
Generate count
groups everytime interval
elapses.
generator:every
Set the generation interval. When this elapses a series of checks are performed. If they pass, another generation of groups are spawned into the world.
generator:minutes
generator:seconds
generator:with_rules_of_engagement
generator:with_reaction_to_threat
generator:using_template
Set the group name you wish to target for generation.
generator:at_random_locations
Provide a table of coordinates to randomly choose when spawning units
generator:no_more_than
Limit the generation to have no more than max
units
generator:exactly
Limit the generation to have exactly count
units
generator:get_next_group_name
Given a group name baseName
as a template, find the next group name
generator:get_next_unit_name
Given a unit name baseName
as a template, find the next unit name
generator:with_starting_location
Set the starting position of generated spawns. Defaults to in air.
generator:with_home_base
generator:with_home_base
generator:at_altitude
generator:clone_group
Clones a template group template_group_name
to a new group name (format: template_group_name-N
) and new position.
generator:defending_zone
generator:refuelling_at
generator:spawn_over_time
Starts spawning groups over time, given the parameters set by other functions.position
You might use this with the using_group
, at_random_locations
, no_less_than
and no_more_than
functions.
Example