DI-Guy Lua AI SDK
 All Classes Files Functions Variables Groups Pages
luaCharacter Class Reference

The base class of all the diguyCharacter's lua representation. More...

Inheritance diagram for luaCharacter:
luaDirectedAI luaIED luaMiddleEastBaseClass luaMissileRPG luaMolotov luaPoolOBlood luaSimplePedestrian luaSimpleSoldier luaSmartProp luaVehicle

Public Member Functions

UI Accessors
 get_ui_signals ()
 This function returns a comma separated list of signals that the agent is currently willing to accept. More...
 
 get_ui_state_label ()
 This function returns a string that the DI-Guy Scenario UI will add onto the end of the state name label. More...
 
FrameWork Functions
 one_time_init ()
 This function is called when a mind is first created, currently no ops. More...
 
 init (arg0, arg1, arg2)
 This function is called at t=0 or when a mind is created, currently no ops. More...
 
 reset ()
 This function resets the luaCharacter representation, called by c++ on scenario reset. More...
 
 destroy ()
 This function is called by C++ when the character is destroyed. Overload it to trigger any world cleanup on destruction. More...
 
 die_now ()
 This function is called when the character is killed. Overload it to trigger any final events or agent clean up on death. More...
 
 draw ()
 This function is called by diguy scenario to draw a lua object Overload it to create your own Drawing behavior. More...
 
 entry_point ()
 This function is called by the state manager as the entry point into the lua state machine. Overload it to create your own HFSM. More...
 
Miscellaneous and Convenience Functions
 send_message_to_character (to, from, msg_type, message, params)
 Send a message from a character to a character, will automatically send message over network. More...
 
Coroutine Management Functions
 state_manager (sender, message_type, message, params)
 This is the main entry point from C++ into the lua framework. More...
 
Sleep Management Functions
 sleep (duration)
 
 sleep_until (wake_time)
 
 sleep_ignore_messages (duration)
 This is a simple sleep function, it will put the character to sleep for the duration specified. Messages will not be processed. More...
 
 sleep_process_messages (duration, message_handler)
 This is a sleep function that can take a message_handler function. More...
 
 wait_for_message (message_to_wait_for, message_handler, bg_check_func, bg_freq)
 This is a sleep function that will wait a long time and only wake up when a specific message is recieved. More...
 
 wait_for_multichoice (...)
 This is a sleep function that will wait a long time and only wake up when one of a few specific messages are recieved. More...
 
UI Agent Picking Functions
 internal_get_user_selected (options)
 Internal support function used by other picking functions. More...
 
 get_user_selected_point (_options)
 Function returns a point in the world, picked via the UI. More...
 
 get_user_selected_character (_options)
 Function returns a character in the world, picked via the ui. More...
 
UI Agent Moveto Functions
 simple_move_to_state (x, y, z, message_handler, bg_check_func, bg_check_freq, force_a_star)
 This function implements a simple move to state. More...
 
 simple_move_to_path_state (path, message_handler, bg_check_func, bg_check_freq, force_a_star)
 
State Management functions
 get_state_name (state_function, object)
 Convenience function for printing the name of a state, given a function_pointer. More...
 
 begin_state (_name)
 Convenience function for storing the current state in the luaCharacter. More...
 
 get_current_and_previous_states ()
 Convenience function for debugging. Returns comma-separated list of recent states. More...
 
 is_new_state (ret)
 Convenience function for checking if the argument is a new state table. More...
 
 invoke_state (new_state, cleanup_function, extra_info)
 Convenience function for doing a tail call function invokation. More...
 
Experimental
 draw_path ()
 Function that draws the character's current path object. More...
 
 draw_line_from_self ()
 Function draws a line from self to the point under the mouse, plus it either a circle under the mouse point. More...
 
 get_user_selected_path (message, use_default_ui_draw_function)
 Function returns a string and a path clicked in the world, picked via the UI. More...
 
 scheduler_heartbeat ()
 Experimental - heartbeat function for the post event sceduler. More...
 
 add_scheduled_event (callback_data)
 Experimental - adds a function to happen in the future. More...
 
 update_scheduler ()
 
 process_messages_enroute (message_obj)
 

Public Attributes

userdata character
 a pointer to the underlying character; More...
 
coroutine state_coroutine
 a microthread that holds the current state of the VM; More...
 
 MESSAGE_HANDLED = -1
 
Constructor Template String
 init_code =
 Constructor Template String. More...
 
local character = this_scenario->find_character("CHARACTER_NAME")
 
 DERIVED_CLASS = BASE_CLASS->new(character)
 

Detailed Description

The base class of all the diguyCharacter's lua representation.

This class wraps a microthread (coroutine) which is responsible for providing a sleepable state machine.

Member Function Documentation

luaCharacter::add_scheduled_event ( callback_data  )

Experimental - adds a function to happen in the future.

local t = this_scenario:get_t()
local callback = function (self, data)
self.character:agent_accept_message(self.name, "signal", "run_away", 0)
end
local luaChar = find_lua_character(character);
luaChar:add_scheduled_event({t=t+2, callback=callback, name="flee", data={}});
luaCharacter::begin_state ( _name  )

Convenience function for storing the current state in the luaCharacter.

Parameters
_namename of current state
Returns
The string representation of the just started state. Cache locally to help see when a state began in the locals browser
luaCharacter::destroy ( )

This function is called by C++ when the character is destroyed. Overload it to trigger any world cleanup on destruction.

luaCharacter::die_now ( )

This function is called when the character is killed. Overload it to trigger any final events or agent clean up on death.

luaCharacter::draw ( )

This function is called by diguy scenario to draw a lua object Overload it to create your own Drawing behavior.

luaCharacter::draw_line_from_self ( )

Function draws a line from self to the point under the mouse, plus it either a circle under the mouse point.

Function renders a 3d line from the location of the luaCharacter to the location of the mouse point. This is a suitable draw_ui function for selecting a "move to" point, for example.

luaCharacter::draw_path ( )

Function that draws the character's current path object.

luaCharacter::entry_point ( )

This function is called by the state manager as the entry point into the lua state machine. Overload it to create your own HFSM.

luaCharacter::get_current_and_previous_states ( )

Convenience function for debugging. Returns comma-separated list of recent states.

Returns
a string
luaCharacter::get_state_name ( state_function  ,
object   
)

Convenience function for printing the name of a state, given a function_pointer.

Parameters
state_functionpointer to state_function
objectshould be nil when called by parent
luaCharacter::get_ui_signals ( )

This function returns a comma separated list of signals that the agent is currently willing to accept.

Normally this would just be nil or a simple string, overload this function to build a more complex system

luaCharacter::get_ui_state_label ( )

This function returns a string that the DI-Guy Scenario UI will add onto the end of the state name label.

Note

This function will be evaluated frequently when the feature is being used. ui_state_label can either be set at any point in your code or overload this function to build a more complex string.

Returns
String description of state.
luaCharacter::get_user_selected_character ( _options  )

Function returns a character in the world, picked via the ui.

This function can take time as the user clicks a character. The character effectively goes to sleep until they receive a valid click.

Takes an options table. Optional parameters are:

Parameters
options["message"]what to place in text label; defaults to "Select character with mouse"
options["pause_scenario"]whether the scenario should be paused during click retrieval; set to true or 1
luaCharacter::get_user_selected_path ( message  ,
use_default_ui_draw_function   
)

Function returns a string and a path clicked in the world, picked via the UI.

Function returns "ok" or "cancel" and a path in the world. This function can take time as the user clicks points. The character effectively goes to sleep until the right click happens

Takes a message Optional parameters are:

Parameters
messagewhat to place in text label defaults to: Click a path in the World, right click when done
use_default_ui_draw_functionset to true to use the build in path drawing function
luaCharacter::get_user_selected_point ( _options  )

Function returns a point in the world, picked via the UI.

Function returns x,y,z - a point in the world. This function can take time as the user clicks a point. The character effectively goes to sleep until they receive a valid click.

Takes an options table. Optional parameters are:

Parameters
options["message"]what to place in text label defaults to "Select Point In World"
options["pause_scenario"]whether the scenario should be paused during click retrieval; set to true or 1
luaCharacter::init ( arg0  ,
arg1  ,
arg2   
)

This function is called at t=0 or when a mind is created, currently no ops.

Parameters
arg0,arg1,arg2optional init arguments passed from c++ via create_lua_mind's additional args.
luaCharacter::internal_get_user_selected ( options  )

Internal support function used by other picking functions.

luaCharacter::invoke_state ( new_state  ,
cleanup_function  ,
extra_info   
)

Convenience function for doing a tail call function invokation.

Parameters
new_statereturn value from a process messages function
cleanup_functionfunction to run cleaning up the behavior of the current state
luaCharacter::is_new_state ( ret  )

Convenience function for checking if the argument is a new state table.

Parameters
retreturn value from a process messages function
Returns
true or false
luaCharacter::one_time_init ( )

This function is called when a mind is first created, currently no ops.

luaCharacter::process_messages_enroute ( message_obj  )
luaCharacter::reset ( )

This function resets the luaCharacter representation, called by c++ on scenario reset.

This function resets the luaCharacter representation. It clears out the current state coroutine which will be recreated in the state_manager update function.

Note
This function MUST be called in overloaded derived classes:
luaCharacter::scheduler_heartbeat ( )

Experimental - heartbeat function for the post event sceduler.

luaCharacter::send_message_to_character ( to  ,
from  ,
msg_type  ,
message  ,
params   
)

Send a message from a character to a character, will automatically send message over network.

Send a message from a character to a character. The given "to" and "from" can be a character's name or the (diguy) character itself. This will handle transmitting to a character over the network if necessary.

luaCharacter::simple_move_to_path_state ( path  ,
message_handler  ,
bg_check_func  ,
bg_check_freq  ,
force_a_star   
)
luaCharacter::simple_move_to_state ( x  ,
y  ,
z  ,
message_handler  ,
bg_check_func  ,
bg_check_freq  ,
force_a_star   
)

This function implements a simple move to state.

Given a point in the world it either makes the character head directly there, or uses the navigation mesh to path plan there. The function can also take optional interruption values.

Parameters
message_handleroptional, function that receives messages and can decide to override the wait.
bg_check_funcoptional; a function that runs in the background; runs every bg_freq function should return a value to break out of wait.
bg_freqoptional; frequency of background check function; defaults to every 2 seconds.
force_a_staroptional; normally an agent that can see the target destination will use idle and set_desired_position(), set true to force the planner to be used
Returns
0 on success, -1 on failure
luaCharacter::sleep ( duration  )

This is a simple sleep function, it will put the character to sleep for the duration specified. The function will be interrupted if a message is received.

Note

Set self.print_debug_messages = 1 to cause this function to print debug messages.

Returns
Nil on success, if a message is received returns a luaMessageObject.
luaCharacter::sleep_ignore_messages ( duration  )

This is a simple sleep function, it will put the character to sleep for the duration specified. Messages will not be processed.

Returns
Nil on success
luaCharacter::sleep_process_messages ( duration  ,
message_handler   
)

This is a sleep function that can take a message_handler function.

When a message is received it is passed to the message_handler. The message_handler is responsible for processing the message and deciding if the sleep should be interrupted.

Parameters
durationhow long to sleep
message_handlerfunction used to assess if character should wake up.
Returns
Nil on success TODO: explain other retvals
luaCharacter::sleep_until ( wake_time  )

This is a simple sleep function, it will put the character to sleep until the absolute scenario time specified. The function will be interrupted if a message is received.

Note

Set self.print_debug_messages = 1 to cause this function to print debug messages.

Returns
Nil on success, if a message is received returns a luaMessageObject.
luaCharacter::state_manager ( sender  ,
message_type  ,
message  ,
params   
)

This is the main entry point from C++ into the lua framework.

Whenever the character wakes up or receives a message, this function is called to resume the underlying coroutine microthread. The lua side of diguyCharacter:agent_accept_message()

This function should not be overloaded.

Parameters
sender,message_type,message,paramsmatch the args to agent_accept_message
luaCharacter::update_scheduler ( )
luaCharacter::wait_for_message ( message_to_wait_for  ,
message_handler  ,
bg_check_func  ,
bg_freq   
)

This is a sleep function that will wait a long time and only wake up when a specific message is recieved.

Parameters
message_to_wait_fora string
message_handleroptional, function that receives messages and can decide to override the wait.
bg_check_funcoptional; a function that runs in the background; runs every bg_freq, function should return a value to break out of wait.
bg_freqoptional; frequency of background check function; defaults to every 2 seconds.
Returns
0 on success, otherwise returns either message hander's or bg_function's return value
secondary return: parameters of message being waited for
luaCharacter::wait_for_multichoice (   ...)

This is a sleep function that will wait a long time and only wake up when one of a few specific messages are recieved.

Member Data Documentation

userdata luaCharacter::character

a pointer to the underlying character;

local luaCharacter::character = this_scenario->find_character("CHARACTER_NAME")
luaCharacter::DERIVED_CLASS = BASE_CLASS->new(character)
luaCharacter::init_code =

Constructor Template String.

luaCharacter::MESSAGE_HANDLED = -1
coroutine luaCharacter::state_coroutine

a microthread that holds the current state of the VM;


The documentation for this class was generated from the following file: