Random Army Manager

Used to create and manage multiple random or semi-random army templates that can be generated at any time throughout the campaign.

Example Usage:

1) Create an army template

random_army_manager:new_force("my_template");

2) Add 4 units to this army that will always be used when generating this template

random_army_manager:add_mandatory_unit("my_template", "unit_key1", 4);

3) Add units to the template that can be randomly generated, with their weighting (that is their chance of being picked, this is not how many will be picked)

random_army_manager:add_unit("my_template", "unit_key1", 1);

random_army_manager:add_unit("my_template", "unit_key2", 1);

random_army_manager:add_unit("my_template", "unit_key3", 2);

4) Generate a random army of 6 units from this template

local force = ram:generate_force("my_template", 6, false);

Output: "unit_key1,unit_key1,unit_key1,unit_key1,unit_key2,unit_key3"

Loaded in Campaign loaded in campaign
Back to top

Random Army Manager Functions

Functions relating to the Manager and its control over the various defined forces

random_army_manager:new_force(string force key)

Adds a new force to the random army manager

Parameters:

1

string

a unique key for this new force

Returns:

  1. boolean Returns true if the force was created successfully

defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 44

random_army_manager:add_unit(string key of the force, string key of the unit, number weight value)

Adds a unit to a force, making it available for random selection if this force is generated. The weight value is an arbitrary figure that should be relative to other units in the force

Parameters:

1

string

key of the force

2

string

key of the unit

3

number

weight value

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 72

random_army_manager:add_mandatory_unit(
  string
key of the force,
  string
key of the unit,
  number
amount of these units
)

Adds a mandatory unit to a force composition, making it so that if this force is generated this unit will always be part of it

Parameters:

1

string

key of the force

2

string

key of the unit

3

number

amount of these units

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 89

random_army_manager:set_faction(string key of the force, string key of the faction)

Sets the faction key associated with this force - Allows you to store the faction key used to spawn the army from the force

Parameters:

1

string

key of the force

2

string

key of the faction

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 106

random_army_manager:generate_force(
  string
key of the force,
  number
amount of units,
  boolean
pass true to return the force as a table
)

This generates a force randomly, first taking into account the mandatory unit and then making random selection of units based on weighting. Returns an array of unit keys or a comma separated string for use in the create_force function if the last boolean value is passed as true

Parameters:

1

string

key of the force

2

number

amount of units

3

boolean

false to get a comma separated string

Returns:

  1. object Either a table containing the unit keys, or a comma separated string of units

defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 119

random_army_manager:remove_force(string key of the force)

Remove an existing force from the force list

Parameters:

1

string

key of the force

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 166

random_army_manager:mandatory_unit_count(string key of the force)

Returns the amount of mandatory units specified in this force

Parameters:

1

string

key of the force

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 180

Last updated 07/02/21 06:39:14