Battle Manager
The battle_manager object is a lua wrapper for the battle object provided by the game code. The battle_manager provides access to all functionality provided by battle as well as numerous enhancements and extensions.
Any calls made to a battle_manager which aren't recognised as functions are passed to the underlying battle object. In this way, the battle_manager object automatically provides the full interface of a battle object.
| Loaded in Battle |
|
-
battle_manager:new() -
Creates a battle_manager object. The single parameter should be an
battlecode object, which can be created withempire_battle:new(). Only one battle_manager object may be created in a session - attempting to create a second just returns the first.Returns:
battle_manager
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 124
-
battle_manager:out(stringoutput) -
Prints a string to the debug output spool. The string is prepended with a timestamp.
Parameters:
1
stringoutput
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 258
-
battle_manager:get_tm() -
Directly access the timer_manager object the battle manager creates and stores internally. It shouldn't be necessary to do this too often, as the battle manager exposes its most useful functions.
Returns:
timer_manager
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 276
-
battle_manager:get_battle_ui_manager() -
Retrieves a handle to a
battle_ui_managerobject from the battle manager. One is created if it hasn't been created before.Returns:
battle_ui_manager
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 284
-
battle_manager:get_battle_folder() -
Returns the path to the battle script folder.
Returns:
stringpath
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 297
-
battle_manager:get_origin() -
Returns a vector position at the world origin.
Returns:
vectororigin
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 305
-
battle_manager:ui_component() -
A wrapper for ui_component. Searches the UI heirarchy and returns a uicomponent object with the supplied name. This overrides the base ui_component function provided by the underlying
battleobject, which returns a component object (which must be converted to be a UIComponent before use).Returns:
uicomponentui component, or false if not found
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 313
-
battle_manager:is_any_cutscene_running() -
Returns true if any cutscene object is currently showing a cutscene.
Returns:
booleanis cutscene running
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 351
-
battle_manager:is_any_unit_selected() -
Queries the UI and returns true if any unit cards are selected.
Returns:
booleanany unit selected
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 369
-
battle_manager:are_all_units_selected() -
Queries the UI and returns true if all unit cards are selected.
Returns:
booleanall units selected
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 398
-
battle_manager:get_player_alliance_num() -
Returns the alliance number of the player's alliance.
Returns:
integeralliance number
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 424
-
battle_manager:get_non_player_alliance_num() -
Returns the alliance number of the non-player alliance.
Returns:
integeralliance number
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 432
-
battle_manager:get_player_alliance() -
Returns the local player's alliance object.
Returns:
allianceplayer alliance
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 444
-
battle_manager:get_non_player_alliance() -
Returns the alliance object of the local player's enemy.
Returns:
allianceenemy alliance
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 452
-
battle_manager:player_is_attacker() -
Returns true if the local player is the attacker in the battle.
Returns:
booleanplayer is attacker
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 460
-
battle_manager:get_player_army() -
Returns the local player's army object.
Returns:
armyplayer's army
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 468
-
battle_manager:get_first_non_player_army() -
Returns the first army of the enemy alliance to the local player.
Returns:
armyenemy army
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 476
-
battle_manager:random_number([numbermax value]) -
Returns a random number. If no max value is supplied then the value returned is a float between 0 and 1. If a max value is supplied, then the value returned is an integer value from 1 to the max value. This is safe to use in multiplayer.
Parameters:
1
numberoptional, default value=nil
max value
Returns:
randomnumber
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 498
-
battle_manager:random_sort(numerically-indexed tabletable) -
Randomly sorts a numerically-indexed table. This is safe to use in multiplayer, but will destroy the supplied table. It is faster than
battle_manager:random_sort_copy.
Note that records in this table that are not arranged in an ascending numerical index will be lost.
Note also that the supplied table is overwritten with the randomly-sorted table, which is also returned as a return value.Parameters:
1
Numerically-indexed table. This will be overwritten by the returned, randomly-sorted table.
Returns:
randomly-sorted tabletable
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 512
-
battle_manager:random_sort_copy(numerically-indexed tabletable) -
Randomly sorts a numerically-indexed table. This is safe to use in multiplayer, and will preserve the original table, but it is marginally slower than
battle_manager:random_sort.
Note that records in the source table that are not arranged in an ascending numerical index will not be copied (they will not be deleted, however).Parameters:
1
Numerically-indexed table.
Returns:
randomly-sorted tabletable
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 541
-
battle_manager:setup_battle(functiondeployment end callback) -
Packaged function to set up a scripted battle on startup, and register a function to be called when the deployment phase ends (i.e. when battle starts).
setup_battlewill suppress a variety of unit sounds and steal input focus until the combat phase begins.Parameters:
1
functiondeployment end callback
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 576
-
battle_manager:register_phase_change_callback(stringphase change name, functioncallback) -
Registers a function to be called when a specified phase change occurs. Phase change notifications are sent to the script by the game when the battle changes phases, from 'Deployment' to 'Deployed' and on to 'VictoryCountdown' and 'Complete'. The battle manager writes debug output whenever a phase change occurs, regardless of whether any callback has been registered for it.
This wraps the underlying functionality provided bybattle:register_battle_phase_handler. See that function's documentation for a list of phase change events that may be listened for.Parameters:
1
stringphase change name
2
functioncallback
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 607
-
battle_manager:register_unit_selection_callback(unitsubject unit, functioncallback) -
Registers a function to be called when a specified unit is selected by the player.
Parameters:
1
unitsubject unit
2
functioncallback
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 662
-
battle_manager:unregister_unit_selection_callback(unitsubject unit) -
Unregisters a function registered with
battle_manager:register_unit_selection_callback.Parameters:
1
unitsubject unit
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 690
-
battle_manager:register_command_handler_callback(stringcommand, functioncallback, [stringcallback name]) -
Registers a function to be called when a command event is issued by the game. The function will be called with the command handler context supplied as a single argument, which can be queried for further information depending upon the command.
This wraps the underlying functionality provided bybattle:register_command_handler. See the documentation of that function for more information about what command events can be listened for, and what contextual information those events provide.Parameters:
1
stringCommand name to listen for.
2
functionCallback to call when the command is triggered by the game.
3
stringoptional, default value=nil
Optional name by which this callback handler can be removed.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 730
-
battle_manager:unregister_command_handler_callback(stringcommand name, stringcallback name) -
Unregisters a callback function registered with
battle_manager:register_command_handler_callback. The callback function is specified by the command name and callback name specified when setting the callback up.Parameters:
1
stringcommand name
2
stringcallback name
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 784
-
battle_manager:register_input_handler_callback(stringinput, functioncallback, [stringcallback name]) -
Registers a function to be called when an input event is issued by the game. This wraps the underlying functionality provided by
battle:register_input_handler. See the documentation of that function for more information about what input events can be listened for.Parameters:
1
stringInput name to listen for.
2
functionCallback to call when the input is triggered by the game.
3
stringoptional, default value=nil
Optional name by which this input handler can be removed.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 847
-
battle_manager:unregister_input_handler_callback(stringcommand name, stringcallback name) -
Unregisters a callback function registered with
battle_manager:register_input_handler_callback. The callback function is specified by the input name and callback name specified when setting the callback up.Parameters:
1
stringcommand name
2
stringcallback name
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 900
-
battle_manager:steal_escape_key_with_callback(stringcallback name, functioncallback) -
Steals the escape key if it wasn't stolen before, and registers a callback to be called if the player presses it. The callback entry must be registered with a unique string name, by which it may be cancelled later if desired.
Multiple escape key callbacks may be registered at one time, although only the most recently-registered callback is notified when the ESC key is pressed. Once an ESC key callback is called it is removed from the list, and the next ESC key press causes the next most recent callback to be notified, and so-on.Parameters:
1
stringcallback name
2
functioncallback
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 964
-
battle_manager:release_escape_key_with_callback(stringcallback name to cancel) -
Cancels an escape key callback registered with
battle_manager:steal_escape_key_with_callbackby name.Parameters:
1
stringcallback name to cancel
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1008
-
battle_manager:setup_victory_callback(functioncallback to call) -
Establishes a function to be called when the battle enters VictoryCountdown phase i.e. someone has won. This function also sets the duration of the victory countdown to infinite, meaning the battle will never end until
battle_manager:end_battleis called. This allows calling scripts to do things like set up an outro cutscene or play some advice that wouldn't fit into the standard victory countdown duration (10 seconds).Parameters:
1
functioncallback to call
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1069
-
battle_manager:end_battle() -
Causes a battle to immediately end when it enters the VictoryCountdown phase, or to immediately end if it is already in that phase. This function is most commonly used to end a battle that has entered the VictoryCountdown phase after
battle_manager:setup_victory_callbackhas been called.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1083
-
battle_manager:register_results_callbacks(player victory callback
function,player defeat callback
function
) -
Old-style battle-ending handlers. These can still be used but won't get called until the battle results screen is shown. Registers player victory and player defeat callbacks to be called at the end of the battle.
Parameters:
1
functionplayer victory callback
2
functionplayer defeat callback
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1090
-
battle_manager:slow_game_over_time(start game speed
number,target game speed
number,duration in ms
number,steps
number
) -
Changes game speed from one value to another over a total time (note that this will be elongated by the slowing action) over a given number of steps. Note that the script engine only updates once every 1/10th of a second so specifying steps of less than this will have weird results. Speeds are specified as multiples of normal game speed, so a value of 2 would be twice normal speed, 0.5 would be half, and so on.
Parameters:
1
numberstart game speed
2
numbertarget game speed
3
numberduration in ms
4
numbersteps
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1143
-
battle_manager:pause() -
Pauses the battle.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1187
These wrapper functions expose functionality provided by the timer_manager. It is highly recommended to use battle_manager:callback or battle_manager:repeat_callback in place of register_singleshot_timer and register_repeating_timer, the latter are mainly provided for legacy support.
-
battle_manager:callback(functioncallback to call, numberdelay in ms, [stringcallback name]) -
Exposes the callback function from the
timer_managerobject. Instructs the timer manager to call a supplied function after a supplied delay. A string name for the callback may also be supplied with which the callback may be later cancelled usingbattle_manager:remove_process.Parameters:
1
functioncallback to call
2
numberdelay in ms
3
stringoptional, default value=nil
callback name
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1241
-
battle_manager:repeat_callback(functioncallback to call, numberdelay in ms, [stringcallback name]) -
Exposes the repeat_callback function from the
timer_managerobject. Instructs the timer manager to call a supplied function after a supplied delay, and then repeatedly after the same delay. A string name for the callback may also be supplied with which the callback may be later cancelled usingbattle_manager:remove_process.Parameters:
1
functioncallback to call
2
numberdelay in ms
3
stringoptional, default value=nil
callback name
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1251
-
battle_manager:register_singleshot_timer(stringfunction name, numbertime in ms) -
Exposes the register_singleshot_timer function from the
timer_managerobject.Parameters:
1
stringfunction name
2
numbertime in ms
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1261
-
battle_manager:register_repeating_timer(stringfunction name, numbertime in ms) -
Exposes the register_repeating_timer function from the
timer_managerobject.Parameters:
1
stringfunction name
2
numbertime in ms
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1270
-
battle_manager:unregister_timer(stringfunction name) -
Exposes the unregister_timer function from the
timer_managerobject.Parameters:
1
stringfunction name
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1279
A watch is a process that continually polls a supplied condition. When it is true, the watch process waits for a supplied period, and then calls a supplied target function. Watches provide battle scripts with a fire-and-forget method of polling the state of the battle, and of being notified when that state changes in some crucial way.
-
battle_manager:watch(condition
function,condition
function,wait time
number,target callback
function,watch name
[string]
) -
Establishes a new watch. A supplied condition function is repeated tested and, when it returns true, a supplied target function is called. A wait period between the condition being met and the target being called must also be specified. A name for the watch may optionally be specified to allow other scripts to cancel it.
The condition must be a function that returns a value - when that value is true (or evaluates to true) then the watch condition is met. The watch then waits the supplied time offset, which is specified in ms as the second parameter, before calling the callback supplied in the third parameter.Parameters:
1
functioncondition
2
functionCondition. Must be a function that returns a value. When the returned value is true, or evaluates to true, then the watch condition is met.
3
numberTime in ms that the watch waits once the condition is met before triggering the target callback
4
functionTarget callback
5
stringoptional, default value=nil
Name for this watch process. Giving a watch a name allows it to be stopped/cancelled with
battle_manager:remove_process.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1300
-
battle_manager:remove_process(stringname) -
Stops and removes any watch OR callback with the supplied name. Returns true if any were found, false otherwise.
Parameters:
1
stringname
Returns:
booleanany removed
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1475
-
battle_manager:remove_process_from_watch_list(stringname) -
Stops and removes any watch with the supplied name. Returns true if any were found, false otherwise. Best practice is to use remove_process instead of this.
Parameters:
1
stringname
Returns:
booleanany removed
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1487
-
battle_manager:print_watch_list() -
Debug command to dump the watch list to the console output spool.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1515
-
battle_manager:clear_watches_and_callbacks() -
Cancels all running watches and callbacks. It's highly recommend to not call this except for debug purposes (and rarely, even then).
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1530
-
battle_manager:set_load_balancing() -
By default the watch system performs load balancing, where it tries to stagger its running watches so they don't all process on the same tick. If this is causes problems for any reason it can be disabled with
set_load_balancing. Supply a boolean parameter to enable or disable load balancing.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1545
The advisor queueing functionality allows the calling script to queue advisor messages so they don't clumsily collide with each other during playback.
-
battle_manager:queue_advisor(advice key
string,forced duration
[number],debug
[boolean],start callback
[function],start callback wait
[number],condition
[playback]
) -
Enqueues a line of advice for delivery to the player. If there is no other advice playing, or nothing is blocking the advisor system, then the advice gets delivered immediately. Otherwise, the supplied advice will be queued and shown at an appropriate time.
The function must be supplied an advice key from the advice_levels/advice_threads tables as its first parameter, unless the advisor entry is set to be debug (see below).Parameters:
1
stringAdvice key from the advice_levels/advice_threads table.
If the advice entry is set to be debug (see third parameter) the text supplied here will instead be shown directly in the advisor window (debug only)
2
numberoptional, default value=0
Forced duration in ms. This is a period that this advice must play for before another item of advice is allowed to start. By default, items of advice will only remain queued while the active advice is actually audibly playing, but by setting a duration the active advice can be held on-screen for longer than the length of its associated soundfile (unless it is closed by the player). This is useful during development to hold advice on-screen when no soundfile yet exists, and also for tutorial scripts which often wish to ensure that an item of advice is shown on-screen for a certain duration.
3
booleanoptional, default value=false
Sets whether the advice line is debug. If set to true, the text supplied as the first parameter is displayed in the advisor window as-is, without using it as a lookup key in the advice_levels table.
4
functionoptional, default value=nil
Start callback. If a function is supplied here it is called when the advice is actually played.
5
numberoptional, default value=0
Start callback wait period in ms. If a duration is specified it causes a delay between the advice being played and the start callback being called.
6
playbackoptional, default value=nil
Playback condition. If specified, it compels the advisor system to check this condition immediately before playing the advisor entry to decide whether to actually proceed. This must be supplied as a function block that returns a result. If this result evaluates to true, the advice is played.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1569
-
battle_manager:stop_advisor_queue([booleanclose advisor], [booleanforce immediate stop]) -
Cancels any running advice, and clears any subsequent advice that may be queued.
Parameters:
1
booleanoptional, default value=false
Closes the advisor if it's open
2
booleanoptional, default value=false
Forces immediate stop. By default the stopping action takes a short amount of time - the game seems happier with this. If set to true, this flag bypasses this behaviour. User beware.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1733
-
battle_manager:advice_cease() -
Stops the advisor queue and prevents any more advice from being queued. The advice system will only subsequently restart if
battle_manager:advice_resumeis called.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1758
-
battle_manager:advice_resume() -
Allows advice to resume after
battle_manager:advice_ceasehas been called.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1767
-
battle_manager:stop_advice_on_battle_end() -
Establishes a listener which stops the advice system as soon as the battle results panel appears.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1774
-
battle_manager:set_close_queue_advice([booleanvalue]) -
Sets whether the advisor system should close the advisor panel once an item of advice has finished playing. By default this is set to false, so use this function to turn this behaviour on.
Parameters:
1
booleanoptional, default value=true
value
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1796
-
battle_manager:has_advice_played_this_battle() -
Returns true if any advice has played in this battle session
Returns:
booleanadvice has played
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1808
-
battle_manager:modify_advice([booleanshow button], [booleanshow highlight]) -
Modifies the advisor panel to show the progress/close button in the bottom right, and also to highlight this button with an animated ring around it. This setting will persist across subsequent items of advice in a battle session until modified again.
Parameters:
1
booleanoptional, default value=false
Show progress/close button.
2
booleanoptional, default value=false
Show highlight on close button.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1816
-
battle_manager:progress_on_advice_dismissed(callback to call
function,delay
[number],highlight on finish
[boolean]
) -
Calls a supplied callback when the advisor panel is closed for any reason.
Parameters:
1
functionCallback to call.
2
numberoptional, default value=0
Delay in ms after the adisor closes before calling the callback.
3
booleanoptional, default value=false
Highlight the advisor close button upon finishing the currently-playing advice. This is useful for script that knows the advisor is playing, wants to highlight the close button when it finishes and be notified of when the player closes the advisor in any case.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1871
-
battle_manager:cancel_progress_on_advice_dismissed() -
Cancels a running
battle_manager:progress_on_advice_dismissedprocess.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1988
-
battle_manager:progress_on_advice_dismissed_immediate_highlight() -
Causes a
battle_manager:progress_on_advice_dismissedprocess that is listening for the advice to finish so that it can highlight the close button (i.e. the third parameter was set to true) to cancel this listener.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 1997
-
battle_manager:progress_on_advice_finished(functioncallback to call, [numberdelay], [numberplaytime]) -
Calls a supplied callback when the advisor has stopped playing an audible sound.
Parameters:
1
functionCallback to call.
2
numberoptional, default value=0
Delay in ms after the adisor stops before calling the callback.
3
numberoptional, default value=5000
Playing time for the advice item. This sets a time after which
battle_manager:progress_on_advice_finishedwill begin to actively poll whether the advice is still playing, as well as listening for the finish event. This is useful as it ensure this function works even during development when the advisor sound files have not yet been recorded.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2004
-
battle_manager:cancel_progress_on_advice_finished() -
Cancels a running
battle_manager:progress_on_advice_finishedprocess.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2070
Upon creation, the battle manager automatically creates an objectives manager object which it stores internally. Most of these functions provide a passthrough interface to the most commonly-used functions on the objectives manager. See the documentation on the objectives_manager page for more details.
Note that battle_manager:set_locatable_objective is native to the battle manager and is not related to the objectives manager.
-
battle_manager:set_objective(stringobjective key, [numberparam a], [numberparam b]) -
Pass-through function for
objectives_manager:set_objectiveon the objectives manager. Sets up a scripted objective for the player, which appears in the scripted objectives panel. This objective can then be updated, removed, or marked as completed or failed by the script at a later time.
A key to the scripted_objectives table must be supplied with set_objective, and optionally one or two numeric parameters to show some running count related to the objective. To update these parameter values later,set_objectivemay be re-called with the same objective key and updated values.Parameters:
1
stringObjective key, from the scripted_objectives table.
2
numberoptional, default value=nil] number param a, First numeric objective parameter. If set, the objective will be presented to the player in the form [objective text]: [param a
First numeric objective parameter. If set, the objective will be presented to the player in the form [objective text]: [param a]. Useful for showing a running count of something related to the objective.
3
numberoptional, default value=nil] number param b, Second numeric objective parameter. A value for the first must be set if this is used. If set, the objective will be presented to the player in the form [objective text]: [param a] / [param b
Second numeric objective parameter. A value for the first must be set if this is used. If set, the objective will be presented to the player in the form [objective text]: [param a] / [param b]. Useful for showing a running count of something related to the objective.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2094
-
battle_manager:complete_objective(stringobjective key) -
Pass-through function for
objectives_manager:complete_objectiveon the objectives manager. Marks a scripted objective as completed for the player to see. Note that it will remain on the scripted objectives panel until removed withbattle_manager:remove_objective.
Note also that is possible to mark an objective as complete before it has been registered withbattle_manager:set_objective- in this case, it is marked as complete as soon asbattle_manager:set_objectiveis called.Parameters:
1
stringObjective key, from the scripted_objectives table.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2105
-
battle_manager:fail_objective(stringobjective key) -
Pass-through function for
objectives_manager:fail_objectiveon the objectives manager. Marks a scripted objective as failed for the player to see. Note that it will remain on the scripted objectives panel until removed withbattle_manager:remove_objective.Parameters:
1
stringObjective key, from the scripted_objectives table.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2114
-
battle_manager:remove_objective(stringobjective key) -
Pass-through function for
objectives_manager:remove_objectiveon the objectives manager. Removes a scripted objective from the scripted objectives panel.Parameters:
1
stringObjective key, from the scripted_objectives table.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2122
-
battle_manager:activate_objective_chain(chain name
string,objective key
string,number param a
[number],number param b
[number]
) -
Pass-through function for
objectives_manager:activate_objective_chain. Starts a new objective chain - see the documentation on theobjectives_managerpage for more details.Parameters:
1
stringObjective chain name.
2
stringKey of initial objective, from the scripted_objectives table.
3
numberoptional, default value=nil
First numeric parameter - see the documentation for
battle_manager:set_objectivefor more details4
numberoptional, default value=nil
Second numeric parameter - see the documentation for
battle_manager:set_objectivefor more detailsReturns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2130
-
battle_manager:update_objective_chain(chain name
string,objective key
string,number param a
[number],number param b
[number]
) -
Pass-through function for
objectives_manager:update_objective_chain. Updates an existing objective chain - see the documentation on theobjectives_managerpage for more details.Parameters:
1
stringObjective chain name.
2
stringKey of initial objective, from the scripted_objectives table.
3
numberoptional, default value=nil
First numeric parameter - see the documentation for
battle_manager:set_objectivefor more details4
numberoptional, default value=nil
Second numeric parameter - see the documentation for
battle_manager:set_objectivefor more detailsReturns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2141
-
battle_manager:end_objective_chain(stringchain name) -
Pass-through function for
objectives_manager:end_objective_chain. Ends an existing objective chain - see the documentation on theobjectives_managerpage for more details.Parameters:
1
stringObjective chain name.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2152
-
battle_manager:reset_objective_chain(stringchain name) -
Pass-through function for
objectives_manager:reset_objective_chain. Resets an objective chain so that it may be called again - see the documentation on theobjectives_managerpage for more details.Parameters:
1
stringObjective chain name.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2160
-
battle_manager:set_locatable_objective(objective key
string,camera position
vector,camera target
vector,zoom duration
number
) -
Sets up a locatable objective in battle. This will appear in the scripted objectives list alongside a zoom-to button which, when clicked, will zoom the camera to a location on the battlefield. The key of the objective text, as well as the camera position/target and zoom duration must all be supplied. The button visibility, on-click listener, and camera movements are all handled in script (which means the camera movement doesn't work when paused..)
Parameters:
1
stringObjective key, from the scripted_objectives table.
2
vectorFinal camera position.
3
vectorFinal camera target.
4
numberDuration of camera movement in seconds.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2210
-
battle_manager:set_locatable_objective_callback(objective key
string,camera position generator
function,zoom duration
number
) -
Sets up a locatable objective in battle. This will appear in the scripted objectives list alongside a zoom-to button which, when clicked, will zoom the camera to a location on the battlefield. Whereas
battle_manager:set_locatable_objectiverequires static camera position/targets to be supplied, this function takes a function argument which, when called, should return abattle_vectorcamera position and abattle_vectorcamera target. This allows the camera position to be generated at runtime, to follow a unit for example.Parameters:
1
Objective key, from the scripted_objectives table.
2
Camera position generator function. When called, this should return two
battle_vectorvalues that specify the camera position and target to move to.3
Duration of camera movement in seconds.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2247
These functions provide a passthrough interface to the most commonly-used functions on the infotext manager, which the battle manager creates automatically.
-
battle_manager:add_infotext(objectfirst param, ...additional infotext strings) -
Pass-through function for
infotext_manager:add_infotext. Adds one or more lines of infotext to the infotext panel - see the documentation on theinfotext_managerpage for more details.Parameters:
1
objectCan be a string key from the advice_info_texts table, or a number specifying an initial delay in ms after the panel animates onscreen and the first infotext item is shown.
2
...Additional infotext strings to be shown.
add_infotextfades each of them on to the infotext panel in a visually-pleasing sequence.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2288
-
battle_manager:remove_infotext(stringinfotext key) -
Pass-through function for
infotext_manager:remove_infotext. Removes a line of infotext from the infotext panel.Parameters:
1
stringinfotext key
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2297
-
battle_manager:clear_infotext() -
Pass-through function for
infotext_manager:clear_infotext. Clears the infotext panel.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2305
-
battle_manager:show_subtitle(stringsubtitle key, [booleanfull key supplied], [booleanforce subtitle on]) -
Shows a cutscene subtitle on-screen.
Parameters:
1
stringsubtitle key
2
booleanoptional, default value=false
Full localised key supplied. If false, or if no value supplied, the script assumes that the key is from the scripted_subtitles table and pads the supplied key out accordingly.
If the key has been supplied in the full localisation format (i.e.
[table]_[field_of_text]_[key_from_table]), set this to true.3
booleanoptional, default value=false
Forces the subtitle to display, overriding the user's preferences.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2323
-
battle_manager:hide_subtitles() -
Hides any currently-shown subtitle.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2386
Help messages are used primarily in quest battles. They are text messages faded onto the HUD above the army panel, that persist for a time and then fade off. The battle manager queues them so they don't overwrite one another.
-
battle_manager:queue_help_message(key
string,duration
[number],fade time
[number],high priority
[boolean],play after battle victory
[boolean],callback
[function]
) -
Enqueues a help message for showing on-screen.
Parameters:
1
stringHelp message key, from the scripted_objectives table.
2
numberoptional, default value=5000
Duration that the message will persist on-screen for in ms. If this is specified then a fade time must also be set.
3
numberoptional, default value=2000
Time that the message will take to fade on/fade off in ms. If this is specified then a duration must also be set.
4
booleanoptional, default value=false
Set this to true to set this message to high priority. High priority messages are bumped to the top of the queue.
5
booleanoptional, default value=false
By default, help messages won't play after the battle has been won. Set this to true to allow this message to play after this point.
6
functionoptional, default value=nil
Callback to call when the message actually starts to show on-screen.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2417
-
battle_manager:enable_camera_movement([booleanenable movement]) -
Allows script to prevents player movement of the camera without stealing input - other game interactions are still permitted. Supply false as an argument to disable camera movement.
Parameters:
1
booleanoptional, default value=true
enable movement
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2549
-
battle_manager:cache_camera() -
Caches the current position/target of the camera for later retrieval.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2563
-
battle_manager:get_cached_camera_pos() -
Gets the cached position of the camera. This must be called after the position has been cached with
battle_manager:cache_camera(else it will return false).Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2572
-
battle_manager:get_cached_camera_targ() -
Gets the cached target of the camera. This must be called after the position has been cached with
battle_manager:cache_camera(else it will return false).Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2579
The camera movement tracker is used by some tutorial scripts to track how the player is moving the camera.
-
battle_manager:start_camera_movement_tracker() -
Starts the camera movement tracker. Only tutorial scripts which need to query camera tracker information need to do this.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2600
-
battle_manager:stop_camera_movement_tracker() -
Stops the camera movement tracker.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2612
-
battle_manager:get_camera_altitude_change() -
Gets the difference in camera altitude between now and when the tracker was started. The returned value is absolute (always positive).
Returns:
numberdifference in m
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2629
-
battle_manager:get_camera_distance_travelled() -
Gets the total distance the camera has travelled between now and when the tracker was started. This distance is not exact, but gives the calling script an indication of how much the player is moving the camera.
Returns:
numberdistance in m
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2644
-
battle_manager:show_ui([booleanshould show]) -
Shows/hides the battle UI from script.
Parameters:
1
booleanoptional, default value=true
should show
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2692
-
battle_manager:show_army([booleanshould show], [booleanimmediate]) -
Shows/hides the army panel.
Parameters:
1
booleanoptional, default value=true
Should show.
2
booleanoptional, default value=false
Hide immediately. If the first parameter is false and this is true, the panel will not animate offscreen but will instead immediately disappear.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2711
-
battle_manager:show_winds_of_magic_panel([booleanshould show], [booleanimmediate]) -
Shows/hides the winds of magic panel
Parameters:
1
booleanoptional, default value=true
Should show.
2
booleanoptional, default value=false
Hide immediately. If the first parameter is false and this is true, the panel will not animate offscreen but will instead immediately disappear.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2735
-
battle_manager:show_portrait_panel([booleanshould show], [booleanimmediate]) -
Shows/hides the unit portrait panel.
Parameters:
1
booleanoptional, default value=true
Should show.
2
booleanoptional, default value=false
Hide immediately. If the first parameter is false and this is true, the panel will not animate offscreen but will instead immediately disappear.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2759
-
battle_manager:show_top_bar([booleanshould show], [booleanimmediate]) -
Shows/hides the top bar on the battle interface.
Parameters:
1
booleanoptional, default value=true
Should show.
2
booleanoptional, default value=false
Hide immediately. If the first parameter is false and this is true, the panel will not animate offscreen but will instead immediately disappear.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2783
-
battle_manager:show_radar_frame([booleanshould show], [booleanimmediate]) -
Shows/hides the radar.
Parameters:
1
booleanoptional, default value=true
Should show.
2
booleanoptional, default value=false
Hide immediately. If the first parameter is false and this is true, the panel will not animate offscreen but will instead immediately disappear.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2807
-
battle_manager:show_start_battle_button([booleanshould show], [booleanis multiplayer]) -
Shows/hides the start battle button.
Parameters:
1
booleanoptional, default value=true
Should show.
2
booleanoptional, default value=false
Set this to true if this is a multiplayer battle.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2831
-
battle_manager:show_ui_options_panel([booleanshould show]) -
Shows/hides the ui options rollout panel.
Parameters:
1
booleanoptional, default value=true
should show
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2860
-
battle_manager:enable_spell_browser_button([booleanshould enable]) -
Enables/disables the spell browser button on the battle interface. A disabled button will still be visible, but greyed-out.
Parameters:
1
booleanoptional, default value=true
should enable
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2886
-
battle_manager:enable_ui_hiding([booleanshould enable]) -
Enables/disables UI hiding. With UI hiding disabled the player will not be able to hide the UI by pressing K or alt-K. This function does not prevent the script from being able to hide or show the UI.
Parameters:
1
booleanoptional, default value=true
should enable
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2911
-
battle_manager:is_ui_hiding_enabled() -
Returns false if UI hiding has been disabled with
battle_manager:enable_ui_hiding, otherwise true.Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2926
The Engagement monitor is a set of processes that continually query the battle state and either store information for other scripts to look up or trigger events for other scripts to listen to. The engagement monitor doesn't start automatically, but must be started by scripts that need the processing and information that it requires, mostly advice/tutorial scripts.
The Engagement monitor tracks the following information:
- the distance between the two alliances on the battlefield, which other scripts can query instead of continually working it out themselves which is potentially expensive.
- the number/proportion of the player's alliance that is engaged in melee/under fire.
- the average altitude of both the player and enemy alliance.
The Engagement monitor also triggers the following events:
- tScriptEventBattleArmiesEngaging, when the two sides close to within 100m or once more than 40% of the player's army is under fire.
- ScriptEventPlayerGeneralWounded, if the player's general is wounded (they must be invincible).
- ScriptEventPlayerGeneralDies, if the player's general dies (not invincible).
- ScriptEventEnemyGeneralWounded, if the enemy general is wounded (they must be invincible).
- ScriptEventEnemyGeneralDies, if the enemy general dies (not invincible).
- ScriptEventPlayerGeneralRouts, if the player's general routs.
- ScriptEventEnemyGeneralRouts, if the enemy general routs.
- ScriptEventPlayerUnitRouts, if one of the player's units routs.
- ScriptEventPlayerUnitRallies, if one of the player's units rallies.
- ScriptEventEnemyUnitRouts, if one of the enemy units routs.
It also triggers ScriptEventPlayerApproachingVictoryPoint as an approximation of the player approaching a victory point. The implementation for this can charitably be described as a best guess - it happens two minutes after the player docks to the walls or the gate.
-
battle_manager:start_engagement_monitor() -
Starts the engagement monitor. This must be called before the "Deployed" phase change occurs (i.e. before the end of deployment).
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 2962
-
battle_manager:get_distance_between_forces() -
Returns the cached distance between the two alliances.
battle_manager:start_engagement_monitormust have been called before the battle started for this to work.Returns:
numberdistance
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3318
-
battle_manager:get_num_units_engaged() -
Returns the number of units in the player's alliance engaged in melee.
battle_manager:start_engagement_monitormust have been called before the battle started for this to work.Returns:
numberengaged
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3330
-
battle_manager:get_proportion_engaged() -
Returns the proportion of units in the player's alliance engaged in melee. This proportion will be a unary value (0 - 1).
battle_manager:start_engagement_monitormust have been called before the battle started for this to work.Returns:
numberproportion engaged
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3342
-
battle_manager:get_num_units_under_fire() -
Returns the number of units in the player's alliance under missile fire.
battle_manager:start_engagement_monitormust have been called before the battle started for this to work.Returns:
numberunder fire
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3354
-
battle_manager:get_proportion_under_fire() -
Returns the proportion of units in the player's alliance engaged in melee. This proportion will be a unary value (0 - 1).
battle_manager:start_engagement_monitormust have been called before the battle started for this to work.Returns:
numberproportion engaged
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3366
-
battle_manager:get_player_army_altitude() -
Returns the average altitude of the player's army in m.
Returns:
numberaverage altitude
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3378
-
battle_manager:get_enemy_army_altitude() -
Returns the average altitude of the enemy army in m.
Returns:
numberaverage altitude
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3390
-
battle_manager:stop_engagement_monitor() -
Stops the engagement monitor.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3402
-
battle_manager:start_terrain_composite_scene(stringkey, [stringgroup name], [numberdelay]) -
Starts a composite scene with the supplied key. If an optional group name is set then this composite scene will not play if another from the same group is active, but will instead be enqueued. When a composite scene in a group stops and a second in the same group is enqueued, then that second scene will begin to play automatically.
Parameters:
1
stringComposite scene key.
2
stringoptional, default value=false
Composite group name.
3
numberoptional, default value=false
Delay in milliseconds to wait before starting if this composite scene becomes enqueued behind another (allowing a minimum time separation between composite scenes of the same group to be specified). This has no effect if no group name is specified.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3422
-
battle_manager:stop_terrain_composite_scene(stringkey) -
Stops a composite scene with the supplied key. If this composite scene was specified as belonging to a group when it was started, and other composite scenes in that group are enquened, then the next one will begin to play automatically (after an optional delay).
Parameters:
1
stringComposite scene key.
Returns:
nil
defined in ../working_data/script/_lib/lib_battle_manager.lua, line 3495