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 |
|
Functions relating to the Manager and its control over the various defined forces
-
random_army_manager:new_force(stringforce key) -
Adds a new force to the random army manager
Parameters:
1
stringa unique key for this new force
Returns:
booleanReturns 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(stringkey of the force, stringkey of the unit, numberweight 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
stringkey of the force
2
stringkey of the unit
3
numberweight value
Returns:
nil
defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 72
-
random_army_manager:add_mandatory_unit(key of the force
string,key of the unit
string,amount of these units
number
) -
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
stringkey of the force
2
stringkey of the unit
3
numberamount of these units
Returns:
nil
defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 89
-
random_army_manager:set_faction(stringkey of the force, stringkey 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
stringkey of the force
2
stringkey of the faction
Returns:
nil
defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 106
-
random_army_manager:generate_force(key of the force
string,amount of units
number,pass true to return the force as a table
boolean
) -
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
stringkey of the force
2
numberamount of units
3
booleanfalse to get a comma separated string
Returns:
objectEither 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(stringkey of the force) -
Remove an existing force from the force list
Parameters:
1
stringkey of the force
Returns:
nil
defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 166
-
random_army_manager:mandatory_unit_count(stringkey of the force) -
Returns the amount of mandatory units specified in this force
Parameters:
1
stringkey of the force
Returns:
nil
defined in ../working_data/script/_lib/lib_campaign_random_army.lua, line 180