Generated Battle
The generated battle system is designed to allow scripters to create battles of moderate complexity relatively cheaply. The central premise of the generated battle system is that events are directed without needing to refer to the individual units, which would be the case with full battle scripts. Instead, orders are given and conditions are detected at army level (or across the battle as a whole). This limits the complexity of what can be done but allows for a much simpler interface. The generated battle system is used to script most/all quest battles.
A generated_battle object is created first with generated_battle:new, and from that multiple generated_army objects are created using calls to generated_battle:get_army, one for each conceptual army on the battlefield. A conceptual army may be an entire army in the conventional sense, or it may be a collection of units within an army grouped together by a common script_name.
Commands are given through the use of messages, built on the script_messager system. Once created, the generated_battle object and generated_army objects can be instructed to listen for certain messages, and act in some manner when they are received. Additionally, the generated_battle and generated_army objects can be instructed to trigger messages when certain conditions are met e.g. when under attack. Using these tools, scripted scenarios of surprising complexity may be constructed relatively easily.
The message listeners a generated_battle object provides can be viewed here: Message Listeners, and the messages it can generate can be viewed here: Message Generation. The message listeners a generated_army object provides can be viewed here: Message Listeners, and the messages it can generate can be viewed here: Message Generation.
Example:
A simple generate battle script that sets up two opposing armies. The army in the second alliance is set to defend a position at the start of the battle and then rout when it takes 50% casualties
load_script_libraries();
bm = battle_manager:new(empire_battle:new());
-- declare generated battle object
gb = generated_battle:new(
false, -- screen starts black
true, -- prevent deployment for player
true, -- prevent deployment for ai
nil, -- intro cutscene function
false -- debug mode
);
-- declare generated army objects
ga_player_01 = gb:get_army(gb:get_player_alliance_num());
ga_ai_01 = gb:get_army(gb:get_non_player_alliance_num());
-- ai defends position [-100, 400] when the battle starts
ga_ai_01:defend_on_message("battle_started", -100, 400, 100);
-- rout the enemy army over 10s when they take 50% casualties
ga_ai_01:message_on_casualties("rout_ai_army", 0.5);
ga_ai_01:rout_over_time_on_message("rout_ai_army", 10000);
| Loaded in Battle |
|
The generated battle object and other related objects send the following messages during battle automatically:
"deployment_started"when the deployment phase begins."battle_started"when the playable combat phase begins."battle_ending"when the VictoryCountdown phase begins (someone has won)."cutscene_ended"when anycutsceneends."generated_custscene_ended"when a generated cutscene ends."outro_camera_finished"when the outro camera movement on a generated cutscene intro has finished.
-
generated_battle:new(screen starts black
[boolean],prevent player deployment
[boolean],prevent ai deployment
[boolean],intro cutscene
[function],debug mode
[boolean]
) -
Creates a generated_battle. There should be only one of these per-battle script.
Parameters:
1
booleanoptional, default value=false
The screen starts black. This should match the prepare_for_fade_in flag in the battle setup, which always seems to be true for quest battles. Furthermore, this flag is only considered if no intro cutscene callback is specified.
2
booleanoptional, default value=false
Prevents player control during deployment.
3
booleanoptional, default value=false
Prevents deployment for the ai.
4
functionoptional, default value=nil
Intro cutscene callback. This is called when deployment phase ends, unless
generated_battle:set_cutscene_during_deploymentis set.5
booleanoptional, default value=false
Turns on debug mode, for more output.
Returns:
generated_battle
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 94
-
generated_battle:set_cutscene_during_deployment([booleanplay in deployment]) -
Sets the supplied intro cutscene callback specified in
generated_battle:newto play at the start of deployment, rather than at the end.Parameters:
1
booleanoptional, default value=true
play in deployment
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 380
-
generated_battle:has_battle_started() -
Returns
trueif the combat phase of the battle has started,falseotherwise.Returns:
booleanbattle has started
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 403
-
generated_battle:get_player_alliance_num() -
Returns the index of the alliance the player is a part of.
Returns:
numberindex
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 411
-
generated_battle:get_non_player_alliance_num() -
Returns the index of the enemy alliance to the player.
Returns:
numberindex
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 419
generated_battle:get_army is called to create generated_army objects.
-
generated_battle:get_army() -
Returns a
generated_armycorresponding to the supplied arguments. Use in one of two modes:
- Supply an alliance number, an army number, and (optionally) a script name. This is the original way armies were specified in quest battle scripts. Returns agenerated_armycorresponding to the supplied alliance/army numbers, containing all units where the name matches the supplied script name (or all of them if one was not supplied). WARNING: at time of writing the ordering of armies in an alliance beyond the first cannot be guaranteed if loading from campaign, so specifying an army index in this case may not be a good idea.
- Supply an alliance number and an optional script name. This supports the randomised ordering of armies in an alliance that we see from campaign.Returns:
booleanbattle has started is specified then it will be assumed that the script name is a blank string. No more than one army in the specified alliance can contain units with the supplied script name.generated_army
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 438
-
generated_battle:add_listener(stringmessage name, functioncallback to call, [booleanpersistent]) -
Allows the generated_battle object to listen for a message and trigger an arbitrary callback. The call gets passed to the underlying
script_messager- seescript_messager:add_listener.Parameters:
1
stringmessage name
2
functioncallback to call
3
booleanoptional, default value=false
persistent
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 596
-
generated_battle:remove_listener(stringmessage name) -
Removes any listener listening for a particular message. This call gets passed through to
script_messager:remove_listener.Parameters:
1
stringmessage name
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 606
-
generated_battle:advice_on_message(stringmessage, stringadvice key, [numberwait offset in ms]) -
Takes a string message, a string advice key, and an optional time offset in ms. Instruct the generated_battle to play a piece of advice on receipt of a message, with the optional time offset so that it doesn't happen robotically at the same moment as the message.
Parameters:
1
stringmessage
2
stringadvice key
3
numberoptional, default value=0
wait offset in ms
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 625
-
generated_battle:play_sound_on_message(message
string,sound
battle_sound_effect,position
[vector],wait offset
[number],end message
[string],minimum duration
[number]
) -
Instruct the generated_battle to play a sound on receipt of a message.
Parameters:
1
stringPlay the sound on receipt of this message.
2
battle_sound_effectSound file to play.
3
vectoroptional, default value=nil
Position at which to play the sound. Supply
nilto play the sound at the camera.4
numberoptional, default value=0
Delay between receipt of the message and the supplied sound starting to play, in ms.
5
stringoptional, default value=nil
Message to send when the sound has finished playing.
6
numberoptional, default value=500
Minimum duration of the sound in ms. This is only used if an end message is supplied, and is handy during development for when the sound has not been recorded.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 663
-
generated_battle:stop_sound_on_message(stringmessage, battle_sound_effectsound, [numberwait offset]) -
Instructs the generated_battle to stop a sound on receipt of a message.
Parameters:
1
stringStop the sound on receipt of this message.
2
battle_sound_effectSound file to stop.
3
numberoptional, default value=0
Delay between receipt of the message and the supplied sound being stopped, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 737
-
generated_battle:start_terrain_composite_scene_on_message(message
string,scene key
string,wait offset
[number],group name
[string],delay if queued
[number]
) -
Instructs the generated_battle to start a terrain composite scene on receipt of a message. Terrain composite scenes are general-purpose scene containers, capable of playing animations, sounds, vfx and more.
Parameters:
1
stringPlay the composite scene on receipt of this message.
2
stringComposite scene key.
3
numberoptional, default value=0
Delay between receipt of the message and the scene being started, in ms.
4
stringoptional, default value=false
Composite scene group name. If supplied, this prevents this composite scene being played at the same time as any other in the same group. See documentation for the underlying
battle_manager:start_terrain_composite_scenefunction for more information.5
numberoptional, default value=false
Delay before playing in ms if queued. This only applies if a group name is set. See
battle_manager:start_terrain_composite_scenefor more information.Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 775
-
generated_battle:stop_terrain_composite_scene_on_message(message
string,scene key
string,wait offset
[number]
) -
Instructs the generated_battle to stop a terrain composite scene on receipt of a message.
Parameters:
1
stringStop the composite scene on receipt of this message.
2
stringComposite scene key.
3
numberoptional, default value=0
Delay between receipt of the message and the scene being stopped, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 834
-
generated_battle:set_objective_on_message(message
string,objective key
string,wait offset
[number],objective param a
[number],objective param b
[number]
) -
Instructs the generated_battle to add a scripted obective to the objectives panel, or update an existing scripted objective, on receipt of a message. The scripted objective is automatically completed or failed when the battle ends, based on the winner of the battle.
Parameters:
1
stringAdd/update the objective on receipt of this message.
2
stringObjective key to add or update.
3
numberoptional, default value=0
Delay between receipt of the message and the objective being added/updated, in ms.
4
numberoptional, default value=nil
First numeric objective parameter, if required. See documentation for
objectives_manager:set_objective.5
numberoptional, default value=nil
Second numeric objective parameter, if required. See documentation for
objectives_manager:set_objective.Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 877
-
generated_battle:complete_objective_on_message(stringmessage, stringobjective key, [numberwait offset]) -
Instructs the generated_battle to mark a specified objective as complete, on receipt of a message. Note that objectives issued to the player are automatically completed if they win the battle.
Parameters:
1
stringComplete the objective on receipt of this message.
2
stringObjective key to complete.
3
numberoptional, default value=0
Delay between receipt of the message and the objective being completed, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 920
-
generated_battle:fail_objective_on_message(stringmessage, stringobjective key, [numberwait offset]) -
Instructs the generated_battle to mark a specified objective as failed, on receipt of a message. Note that objectives issued to the player are automatically failed if they lose the battle.
Parameters:
1
stringFail the objective on receipt of this message.
2
stringObjective key to fail.
3
numberoptional, default value=0
Delay between receipt of the message and the objective being failed, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 960
-
generated_battle:remove_objective_on_message(stringmessage, stringobjective key, [numberwait offset]) -
Instructs the generated_battle to remove a specified objective from the UI on receipt of a message.
Parameters:
1
stringRemove the objective on receipt of this message.
2
stringObjective key to remove.
3
numberoptional, default value=0
Delay between receipt of the message and the objective being removed, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1000
-
generated_battle:set_locatable_objective_on_message(message
string,objective key
string,wait offset
[number],camera position
vector,camera target
vector,camera move time
number
) -
Instructs the generated_battle to set a locatable objective on receipt of a message. See
battle_manager:set_locatable_objectivefor more details.Parameters:
1
stringAdd/update the locatable objective on receipt of this message.
2
stringObjective key to add or update.
3
numberoptional, default value=0
Delay between receipt of the message and the objective being added/updated, in ms.
4
vectorCamera position to zoom camera to when objective button is clicked.
5
vectorCamera target to zoom camera to when objective button is clicked.
6
numberTime the camera takes to pan to the objective when the objective button is clicked, in seconds.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1040
-
generated_battle:add_ping_icon_on_message(message
string,marker position
vector,marker type
number,wait offset
[number],duration
[number]
) -
Instructs the generated_battle to add a battlefield ping icon on receipt of a message. This is a marker that appears in 3D space and can be used to point out the location of objectives to the player.
Parameters:
1
stringAdd the ping icon on receipt of this message.
2
vectorMarker position.
3
numberMarker type. These have to be looked up from code.
4
numberoptional, default value=0
Delay between receipt of the message and the marker being added, in ms.
5
numberoptional, default value=nil
Duration that the marker should stay visible for, in ms. If not set then the marker stays on-screen until it is removed with
generated_battle:remove_ping_icon_on_message.Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1099
-
generated_battle:remove_ping_icon_on_message(stringmessage, vectormarker position, [numberwait offset]) -
Instructs the generated_battle to remove a battlefield ping icon on receipt of a message. The marker is specified by its position.
Parameters:
1
stringRemove the ping icon on receipt of this message.
2
vectorMarker position.
3
numberoptional, default value=0
Delay between receipt of the message and the marker being removed, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1160
-
generated_battle:fade_in_on_message(stringmessage, numberduration) -
Takes a string message, and a fade duration in seconds. Fades the scene from black to picture over the supplied duration when the supplied message is received.
Parameters:
1
stringmessage
2
numberduration
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1245
-
generated_battle:set_custom_loading_screen_on_message(stringmessage, numberduration) -
Takes a string message and a string custom loading screen key. Sets that loading screen key to be used as the loading screen on receipt of the string message. This is used to set a custom outro loading screen.
Parameters:
1
stringmessage
2
numberduration
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1270
-
generated_battle:start_terrain_effect_on_message(stringmessage, stringeffect name, [numberwait offset]) -
Instructs the generated_battle to start a terrain effect on receipt of a message.
Parameters:
1
stringStart the terrain effect on receipt of this message.
2
stringEffect name to start.
3
numberoptional, default value=0
Delay between receipt of the message and the effect being started, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1295
-
generated_battle:stop_terrain_effect_on_message(stringmessage, stringeffect name, [numberwait offset]) -
Instructs the generated_battle to stop a terrain effect on receipt of a message.
Parameters:
1
stringStop the terrain effect on receipt of this message.
2
stringEffect name to stop.
3
numberoptional, default value=0
Delay between receipt of the message and the effect being stopped, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1333
-
generated_battle:queue_help_on_message(message
string,objective key
string,display time
[number],display time
[number],wait offset
[number],high priority
[boolean],message on trigger
[string]
) -
Enqueues a help message for display on-screen on receipt of a message. The message appears above the army panel with a black background. See
Help Message Queuefor more information. Note that if the battle is ending, this message will not display.Parameters:
1
stringEnqueue the help message for display on receipt of this message.
2
stringMessage key, from the scripted_objectives table.
3
numberoptional, default value=10000
Time for which the help message should be displayed on-screen, in ms.
4
numberoptional, default value=2000
Time for which the help message should be displayed on-screen, in ms.
5
numberoptional, default value=0
Delay between receipt of the message and the help message being enqueued, in ms.
6
booleanoptional, default value=false
High priority advice gets added to the front of the help queue rather than the back.
7
stringoptional, default value=nil
Specifies a message to be sent when this help message is actually triggered for display.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1371
-
generated_battle:set_victory_countdown_on_message(stringmessage, numbercountdown time) -
Sets the victory countdown time for the battle to the specified value when the specified message is received. The victory countdown time is the grace period after the battle is deemed to have a victor, and before the battle formally ends, in which celebratory/commiseratory advice often plays. Set this to a negative number for the battle to never end after entering victory countdown phase, or 0 for it to end immediately.
Note that it's possible to set a negative victory countdown period, then enter the phase, then set a victory countdown period of zero to end the battle immediately.Parameters:
1
stringSet victory countdown on receipt of this message.
2
numberVictory countdown time in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1443
-
generated_battle:block_message_on_message(stringmessage, stringmessage to block, [booleanshould block]) -
Blocks or unblocks a message from being triggered, on receipt of a message. Scripts listening for a blocked message will not be notified when that message is triggered. See
script_messager:block_messagefor more information.Parameters:
1
stringPerform the blocking or unblocking on receipt of this message.
2
stringMessage to block or unblock.
3
booleanoptional, default value=true
Should block the message. Set this to
falseto unblock a previously-blocked message.Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1475
-
generated_battle:message_on_all_messages_received(stringmessage, ...messages) -
Takes a subject message, and then one or more other messages. When all of these other messages are received, the subject message is sent.
Parameters:
1
stringSubject message to send.
2
...One or more string messages to receive.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1573
-
generated_battle:message_on_any_message_received(stringmessage, ...messages) -
Takes a subject message, and then one or more other messages. When any of these other messages are received, the subject message is sent.
Parameters:
1
stringSubject message to send.
2
...One or more string messages to receive.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1622
-
generated_battle:message_on_time_offset(message
string,wait time
number,start message
[string],cancel message
[string]
) -
Takes a string message and a wait time in ms. Waits for the specified interval and then triggers the message. If an optional start message is supplied as a third parameter then the timer will start when this message is received, otherwise it starts when the battle is started.
A cancellation message may be supplied as a fourth parameter - this will cancel the timer if the message is received (whether the timer has been started or not).Parameters:
1
Message to send.
2
Wait time in ms before sending the message.
3
optional, default value="battle_started"
Start message which begins the wait time countdown.
4
optional, default value=false
Cancellation message.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1661
Generated Army
A generated army object represents a conceptual army in a generated battle. This can mean an entire army in the conventional sense, or a collection of units within a conventional army, grouped together by the same script_name. A generated_army object can be created by calling generated_battle:get_army.
Each generated army object can be instructed to respond to trigger script messages when certain in-battle conditions are met (e.g. when a certain proportion of casualties has been taken, or the enemy is within a certain distance), or to respond to script messages triggered by other parts of the script by attacking/defending/moving and more. Using these tools, the actions that determine the course of events in a generated/quest battle can be laid out.
-
generated_army:get_script_name() -
Gets the script_name of the generated army.
Returns:
stringscript_name
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1963
-
generated_army:get_unitcontroller() -
Gets a unitcontroller with control over all units in the generated army. This can be useful for the intro cutscene which needs this to restrict player control.
Returns:
unitcontroller
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1971
-
generated_army:get_handicap() -
Returns the battle difficulty. See the documentation for
army:army_handicapfor possible return values.Returns:
numberarmy handicap
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1979
-
generated_army:get_first_scriptunit() -
Returns the first scriptunit of the generated army.
Returns:
script_unit
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1987
-
generated_army:get_most_westerly_scriptunit() -
Returns the
script_unitwithin the generated army positioned furthest to the west.Returns:
script_unit
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 1995
-
generated_army:get_most_easterly_scriptunit() -
Returns the
script_unitwithin the generated army positioned furthest to the east.Returns:
script_unit
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2017
-
generated_army:get_most_northerly_scriptunit() -
Returns the
script_unitwithin the generated army positioned furthest to the north.Returns:
script_unit
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2039
-
generated_army:get_most_southerly_scriptunit() -
Returns the
script_unitwithin the generated army positioned furthest to the south.Returns:
script_unit
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2061
-
generated_army:get_casualty_rate() -
Returns the amount of casualties this generated army has taken as a unary value e.g. 0.2 = 20% casualties.
Returns:
numbercasualties
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2083
-
generated_army:get_rout_proportion() -
Returns the unary proportion (0 - 1) of the units in this generated army that are routing e.g. 0.2 = 20% routing
Returns:
numberrout proportion
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2091
-
generated_army:get_shattered_proportion() -
Returns the unary proportion (0 - 1) of the units in this generated army that are shattered e.g. 0.2 = 20% routing
Returns:
numbershattered proportion
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2108
-
generated_army:are_unit_types_in_army() -
Returns true if any of the supplied unit types are present in the army, false otherwise.
Returns:
booleanarmy contains types
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2125
These commands directly call some function or give some instruction to the generated army without listening for a script message. They are mostly for use within intro cutscenes, or they may be used internally by the functions that listen for messages.
-
generated_army:set_visible_to_all([booleanvisible]) -
Sets the visibility on a
generated_army, so that they are visible in an intro cutscene.Parameters:
1
booleanoptional, default value=true
visible
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2163
-
generated_army:set_enabled([booleanenabled]) -
Sets whether a generated_army is enabled - when disabled, they will be invisible and effectively not exist. See
script_unit:set_enabled.Parameters:
1
booleanoptional, default value=true
enabled
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2175
-
generated_army:halt() -
Halts the generated_army.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2183
-
generated_army:celebrate() -
Orders the generated_army to celebrate.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2190
-
generated_army:taunt() -
Orders the generated_army to taunt.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2197
-
generated_army:play_sound_charge() -
Orders the generated_army to trigger the charge sound.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2204
-
generated_army:play_sound_taunt() -
Orders the generated_army to trigger the taunt sound.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2212
-
generated_army:add_ping_icon([numbericon type], [numberunit index], [numberduration]) -
Adds a ping icon to a unit within the generated army. See
script_unit:add_ping_icon.Parameters:
1
numberoptional, default value=8
Icon type. This is a numeric index defined in code.
2
numberoptional, default value=1
Index of unit within the army to add the ping icon to.
3
numberoptional, default value=nil
Duration to show the ping icon, in ms. Leave blank to show the icon indefinitely.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2220
-
generated_army:remove_ping_icon([numberunit index]) -
Removes a ping icon from a unit within the generated army.
Parameters:
1
numberoptional, default value=1
Index of unit within the army to remove the ping icon from.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2242
-
generated_army:teleport_to_start_location_offset([numberx offset], [numberz offset]) -
Teleports the generated army to a position offset from its start location. Supply no offset to teleport it directly to its start location.
Parameters:
1
numberoptional, default value=0
x offset
2
numberoptional, default value=0
z offset
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2262
-
generated_army:goto_start_location([booleanmove fast]) -
Instructs all the units in a generated army to move to the position/angle/width at which they started the battle.
Parameters:
1
booleanoptional, default value=false
move fast
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2292
-
generated_army:goto_location_offset(numberx offset, numberx offset, [booleanmove fast]) -
Instructs all units in a generated army to go to a location offset from their current position. Supply a numeric x/z offset and a boolean argument specifying whether they should run.
Parameters:
1
numberx offset in m
2
numberz offset in m
3
booleanoptional, default value=false
move fast
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2300
-
generated_army:move_to_position(vectorposition) -
Instructs all units in a generated army to move to a position under control of a
script_ai_planner. Seescript_ai_planner:move_to_position.Parameters:
1
vectorposition
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2312
-
generated_army:advance() -
Instructs all units in a generated army to advance upon the enemy.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2331
-
generated_army:attack() -
Instructs all units in a generated army to attack the enemy.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2349
-
generated_army:attack_force(script_unitsenemy force, [booleanforce attack]) -
Instructs all units in a generated army to attack a specific enemy force.
Parameters:
1
script_unitsenemy force
2
booleanoptional, default value=false
If set to true will use script planner attack, instead of move. Use with caution, this can get tripped by visibility.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2366
-
generated_army:defend(numberx co-ordinate, numbery co-ordinate, numberradius) -
Instructs all units in a generated army to defend a position.
Parameters:
1
numberx co-ordinate in m
2
numbery co-ordinate in m
3
numberradius
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2390
-
generated_army:release() -
Instructs the generated army to release control of all its units to the player/general ai.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2407
These functions listen for messages and issue commands to the generated army on their receipt. They are intended to be the primary method of causing armies to follow orders on the battlefield during open gameplay - use these instead of issuing direct orders where possible.
-
generated_army:teleport_to_start_location_offset_on_message(message
string,x offset
number,y offset y offset in m
number
) -
Teleports the units in the army to their start position with the supplied offset when the supplied message is received.
Parameters:
1
stringmessage
2
numberx offset in m
3
numbery offset y offset in m
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2440
-
generated_army:goto_start_location_on_message(stringmessage, [booleanmove fast]) -
Instructs the units in the army to move to the locations they started the battle at when the supplied message is received.
Parameters:
1
stringmessage
2
booleanoptional, default value=false
move fast
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2462
-
generated_army:goto_location_offset_on_message(message
string,x offset
number,z offset
number,move fast
boolean
) -
Instructs the units in the army to move relative to their current locations when the supplied message is received.
Parameters:
1
stringmessage
2
numberx offset in m
3
numberz offset in m
4
booleanmove fast
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2483
-
generated_army:set_enabled_on_message(stringmessage, booleanenabled) -
Sets the enabled status of a generated army on receipt of a message.
Parameters:
1
stringmessage
2
booleanenabled
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2507
-
generated_army:set_formation_on_message(stringmessage, stringformation, booleanrelease) -
Sets the formation of the units in the generated army to the supplied formation on receipt of a message. For valid formation strings, see documentation for
script_units:change_formation.Parameters:
1
stringMessage.
2
stringFormation name.
3
booleanset to
trueto release script control after issuing the command. Set this if the command is happening to the player's army.Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2525
-
generated_army:move_to_position_on_message(stringmessage, vectorposition) -
Instructs all units in a generated army to move to a position under control of a
script_ai_planneron receipt of a message. Seegenerated_army:move_to_position.Parameters:
1
stringmessage
2
vectorposition
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2557
-
generated_army:advance_on_message(stringmessage, [numberwait offset]) -
Orders the units in the generated army to advance on the enemy upon receipt of a supplied message.
Parameters:
1
stringMessage.
2
numberoptional, default value=0
Time to wait in ms after receipt of the message before issuing the advance order.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2583
-
generated_army:attack_on_message(stringmessage, [numberwait offset]) -
Orders the units in the generated army to attack the enemy upon receipt of a supplied message.
Parameters:
1
stringMessage.
2
numberoptional, default value=0
Time to wait after receipt of the message before issuing the attack order.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2621
-
generated_army:attack_force_on_message(message
string,target
generated_army,wait offset
[number],force attack
[boolean]
) -
Orders the units in the generated army to attack a specified enemy force upon receipt of a supplied message.
Parameters:
1
stringMessage.
2
generated_armyTarget force.
3
numberoptional, default value=0
Time to wait after receipt of the message before issuing the attack order.
4
booleanoptional, default value=false
If set to true will use script planner attack, instead of move. Use with caution, this can get tripped by visibility.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2659
-
generated_army:defend_on_message(message
string,x co-ordinate
number,x co-ordinate
number,radius
number,wait offset
[number]
) -
Orders the units in the generated army to defend a specified position upon receipt of a supplied message.
Parameters:
1
stringMessage.
2
numberx co-ordinate in m.
3
numbery co-ordinate in m.
4
numberDefence radius.
5
numberoptional, default value=0
Time to wait after receipt of the message before issuing the defend order.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2704
-
generated_army:release_on_message(stringmessage, [numberwait offset]) -
Releases script control of the units in the generated army to the player/general AI upon receipt of a supplied message.
Parameters:
1
stringMessage.
2
numberoptional, default value=0
Time to wait after receipt of the message before the units are released.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2755
-
generated_army:reinforce_on_message(messagestring, [wait offsetnumber]) -
Prevents the units in the generated army from entering the battlefield as reinforcements until the specified message is received, at which point they are deployed.
Parameters:
1
Message.
2
optional, default value=0
Time to wait after receipt of the message before issuing the reinforce order.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2788
-
generated_army:rout_over_time_on_message(stringmessage, numberperiod in ms) -
Routs the units in the generated army over the specified time period upon receipt of a supplied message. See
script_units:rout_over_time.Parameters:
1
stringMessage.
2
numberPeriod over which the units in the generated army should rout, in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2824
-
generated_army:withdraw_on_message(stringmessage) -
Withdraw the units in the generated army upon receipt of a supplied message.
Parameters:
1
stringMessage.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2854
-
generated_army:set_melee_mode_on_message(stringmessage, [booleanactivate], [booleanrelease]) -
Activates or deactivates melee mode on units within the generated army on receipt of a supplied message. An additional flag specifies whether script control of the units should be released afterwards - set this to true if the player is controlling this army.
Parameters:
1
stringMessage.
2
booleanoptional, default value=true
Should activate melee mode.
3
booleanoptional, default value=false
Release script control afterwards.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2873
-
generated_army:change_behaviour_active_on_message(message
string,behaviour
string,activate
[boolean],release
[boolean]
) -
Activates or deactivates a supplied behaviour on units within the generated army on receipt of a supplied message. An additional flag specifies whether script control of the units should be released afterwards - set this to true if the player is controlling this army.
Parameters:
1
stringMessage.
2
stringBehaviour to activate or deactivate. See documentation on
script_unit:change_behaviour_activefor a list of valid values.3
booleanoptional, default value=true
Should activate behaviour.
4
booleanoptional, default value=false
Release script control afterwards.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2898
-
generated_army:set_invincible_on_message(stringmessage, [booleaninvincibility]) -
Sets the units in the generated army to be invincible and fearless upon receipt of a supplied message.
Parameters:
1
stringmessage
2
booleanoptional, default value=true
invincibility
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2925
-
generated_army:refresh_on_message(stringmessage) -
Refreshes the ammunition and fatigue of units in the generated army upon receipt of a supplied message.
Parameters:
1
stringmessage
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2945
-
generated_army:deploy_at_random_intervals_on_message(message
string,min units
number,max units
number,min period
string,max period
string,cancel message
[string]
) -
Prevents the units in the generated army from deploying as reinforcements when called, and instructs them to enter the battlefield in random chunks upon receipt of a supplied message. Supply min/max values for the number of units to be deployed at one time, and a min/max period between deployment chunks. Each chunk will be of a random size between the supplied min/max, and will deploy onto the battlefield at a random interval between the supplied min/max period after the previous chunk. This process will repeat until all units in the generated army are deployed, or until the cancel message is received. See
script_units:deploy_at_random_intervalsfor more information.
A cancel message may also be supplied, which will stop the reinforcement process either before or after the trigger message is received.Parameters:
1
Trigger message.
2
Minimum number of units to deploy in chunk.
3
Maximum number of units to deploy in chunk.
4
Minimum duration between chunks.
5
Maximum duration between chunks.
6
optional, default value=nil
Cancel message. If specified, this stops the deployment once received.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 2964
-
generated_army:grant_infinite_ammo_on_message(stringmessage) -
Continually refills the ammunition of all units in the generated army upon receipt of the supplied message.
Parameters:
1
stringmessage
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3013
-
generated_army:add_ping_icon_on_message(message
string,icon type
[number],unit index
[number],duration
[number]
) -
Adds a ping marker to a specified unit within the generated army upon receipt of a supplied message.
Parameters:
1
stringTrigger message
2
numberoptional, default value=8
Icon type. This is a numeric index defined in code.
3
numberoptional, default value=1
The unit to apply the ping marker to is specified by their index value within the generated army, so 1 would be the first unit (usually the general).
4
numberoptional, default value=nil
Duration to display the ping icon for, in ms
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3034
-
generated_army:remove_ping_icon_on_message(stringmessage, [numberunit index]) -
Removes a ping marker from a specified unit within the generated army upon receipt of a supplied message.
Parameters:
1
stringTrigger message
2
numberoptional, default value=1
The unit to remove the ping marker from is specified by their index value within the generated army, so 1 would be the first unit (usually the general).
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3081
-
generated_army:add_winds_of_magic_on_message(stringmessage, numbermodification value) -
Adds an amount to the winds of magic reserve for the generated army upon receipt of a supplied message.
Parameters:
1
stringTrigger message.
2
numberWinds of Magic modification value.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3114
-
generated_army:set_always_visible_on_message(message
string,always visible
[boolean],release control
[boolean]
) -
On receipt of the supplied message, sets the army's visibility status to the supplied true or false value. True = the army will not be hidden by terrain LOS, false = the army can be (i.e. normal behaviour). Note that the target units will still be able to hide in forests or long grass. Also note that they may perform a fade in from the point this function is called, so may not be fully visible until several seconds later.
If the release_control flag is set to true, control of the sunits is released after the operation is performed. Do this if the army belongs to the player, otherwise they won't be able to control them.Parameters:
1
stringmessage
2
booleanoptional, default value=false
always visible
3
booleanoptional, default value=false
release control
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3140
-
generated_army:force_victory_on_message(stringmessage, [numberduration]) -
Forces the enemies of the generated army to rout over time upon receipt of the supplied message. After the enemies have all routed, this generated army will win the battle.
Parameters:
1
stringTrigger message.
2
numberoptional, default value=10000
Duration over which to rout the enemy in ms.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3181
-
generated_army:remove_on_message(stringmessage) -
Immediately kills and removes the units in the generated army upon receipt of the supplied message.
Parameters:
1
stringTrigger message.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3227
These functions listen for conditions and generate messages when they are met.
-
generated_army:message_on_casualties(stringmessage, numberunary threshold) -
Fires the supplied message when the casualty rate of this generated army equals or exceeds the supplied threshold.
Parameters:
1
stringMessage to trigger.
2
numberUnary threshold (between 0 and 1).
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3268
-
generated_army:message_on_proximity_to_enemy(stringmessage, numberthreshold distance) -
Triggers the supplied message when this generated army finds itself with the supplied distance of its enemy.
Parameters:
1
stringMessage to trigger.
2
numberThreshold distance in m.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3305
-
generated_army:message_on_proximity_to_ally(stringmessage, numberthreshold distance) -
Triggers the supplied message when this generated army finds itself with the supplied distance of any allied generated armies.
Parameters:
1
stringMessage to trigger.
2
numberThreshold distance in m.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3345
-
generated_army:message_on_proximity_to_position(stringmessage, vectorposition, numberthreshold distance) -
Triggers the supplied message when this generated army finds itself with the supplied distance of the supplied position.
Parameters:
1
stringMessage to trigger.
2
vectorTest position.
3
numberThreshold distance in m.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3390
-
generated_army:message_on_rout_proportion(stringmessage, numberthreshold) -
Triggers the supplied message when the proportion of units routing or dead in this generated army exceeds the supplied unary threshold.
Parameters:
1
stringMessage to trigger.
2
numberUnary threshold (0 - 1).
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3434
-
generated_army:message_on_shattered_proportion(stringmessage, numberthreshold) -
Triggers the supplied message when the proportion of units that are shattered in this generated army exceeds the supplied unary threshold.
Parameters:
1
stringMessage to trigger.
2
numberUnary threshold (0 - 1).
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3471
-
generated_army:message_on_deployed(stringmessage) -
Triggers the supplied message when the units in the generated army are all fully deployed.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3508
-
generated_army:message_on_any_deployed(stringmessage) -
Triggers the supplied message when any of the units in the generated army have deployed.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3537
-
generated_army:message_on_seen_by_enemy(stringmessage) -
Triggers the supplied message when any of the units in the generated army have become visible to the enemy.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3566
-
generated_army:message_on_commander_death(stringmessage) -
Triggers the supplied message when the commander of the army corresponding to this generated army has died. Note that the commander of the army may not be in this generated army.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3604
-
generated_army:message_on_commander_dead_or_routing(stringmessage) -
Triggers the supplied message when the commanding unit within this generated army is either dead or routing. If no commanding unit exists in the generated army, this function will throw a script error.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3633
-
generated_army:message_on_commander_dead_or_shattered(stringmessage) -
Triggers the supplied message when the commanding unit within this generated army is either dead or shattered. If no commanding unit is present, this function will throw a script error.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3679
-
generated_army:message_on_under_attack(stringmessage) -
Triggers the supplied message when any of the units in this generated army come under attack.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3725
-
generated_army:message_on_alliance_not_active_on_battlefield(stringmessage) -
Triggers the supplied message if none of the units in the alliance to which this generated army belongs are a) deployed and b) not routing, shattered or dead
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3757
-
generated_army:message_on_victory(stringmessage) -
Triggers the supplied message if this generated army wins the battle.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3817
-
generated_army:message_on_defeat(stringmessage) -
Triggers the supplied message if this generated army loses the battle.
Parameters:
1
stringMessage to trigger.
Returns:
nil
defined in ../working_data/script/_lib/lib_generated_battle.lua, line 3836