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

Overview. More...

Inheritance diagram for luaUrbanEntity:
luaCharacter luaUrbanCivilian luaVehicleMind

Public Member Functions

 begin_state (_state_name)
 Designate a state as having been entered. More...
 
 invoke_state (state_obj, _message_handler)
 Enter a child state. More...
 
 sleep_process_messages (duration, msg_handler)
 Puts the active coroutine to sleep for the number of seconds specified. More...
 
 send_message_up_state_chain (message)
 Chained message handler communication function. More...
 
 check_higher_state_interruption ()
 Checks if a higher state requests an interruption. More...
 
 pop_stored_message_response ()
 Retrieves message response from chained event handlers. More...
 
 mark_state_interruption (_interrupt)
 For use by chained message processors. More...
 
- Public Member Functions inherited from luaCharacter
 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...
 
 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...
 
 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...
 
 state_manager (sender, message_type, message, params)
 This is the main entry point from C++ into the lua framework. More...
 
 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...
 
 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...
 
 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)
 
 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...
 
 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

local goto_result = self->invoke_state({state=self.goto_point_state, arg1=dest_vec, arg2=approach_dist})
 
- Public Attributes inherited from luaCharacter
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
 
 init_code =
 Constructor Template String. More...
 
local character = this_scenario->find_character("CHARACTER_NAME")
 
 DERIVED_CLASS = BASE_CLASS->new(character)
 

Detailed Description

Overview.

The code that follows is a framework for a message processor chaining sytem. This is meant to work with the already-existing concept of parent and child states.

Consider the three following nested states, each called by its parent.

  • go_to_store_state()
  • walk_to_point_state() [how I get to the store]
  • have_conversation_state() [something I might stop and do while walking]

Sometimes, we want messages to be handled by the state we're currently in. For example, have_conversation_state() would handle messages related to a conversation with another characters.

However, sometimes it's useful to have a chain of message processing functions, each associated with a parent state that we have yet to return to. For example, walk_to_point_state() might designate a handler to pay attention to messages related to traffic. Even if the character is involved in a conversation, we might still want to respond in some way.

The chaining works by a parent state designating a message-processing function, before passing control to a child state. Any message not handled by the child state will be passed up to the parent's message processor (then up to that of the grandparent, etc). If the function is able to handle the message, it has three basic options:

  • Set flags that change the behavior of the mind
  • Save a message response object, which the parent state can pick up when the child state returns control.
  • Tell the child state to return immediately

Programmers using this framework must make several additions to their code

  • Always use invoke_state() to enter a child (pushdown) state
  • Provide invoke_state() with the parent state's message processing function, which will be called through chaining, if an incoming message isn't handled by a child state or a lower-level chained handler.
  • Upon returning from a sleep_process_messages() call, check for an interruption by a parent state. If one has occurred, cleanup and exit current state.
  • Upon return from an invoke_state() call, check if a message response object is waiting. If so, make appropriate use of it.

Member Function Documentation

luaUrbanEntity::begin_state ( _state_name  )

Designate a state as having been entered.

This associates a name with the current state on the state stack.

Parameters
_state_namestring, should match state function name
luaUrbanEntity::check_higher_state_interruption ( )

Checks if a higher state requests an interruption.

Determines if a chained message processor, called from sleep_process_messages, has requested an interruption. The state function calling this function should then clean itself up and return control to the parent state.

Returns
true if interrupt requested
luaUrbanEntity::invoke_state ( state_obj  ,
_message_handler   
)

Enter a child state.

Essentially calls a state function, but with extra book-keeping. The recommended calling method.

Parameters
state_objtable containing...
state - ref to child state function
arg1 - first argument to that function
arg2 - second argument to that function
arg3 - second argument to that function
message_handlerref to function to use as a chained message processor (optional). It will have a crack at any messages not processed by the active child state or by message processor functions lower on the chain.

Note that the message response object returned by message_handler won't be returned right away. Rather, it will be saved for later retrieval by the current state function, whenever control returns to it.

Returns
Return value
luaUrbanEntity::mark_state_interruption ( _interrupt  )

For use by chained message processors.

A chained message processor should call this function if control is to be returned to the associated state function. Child states will then be able to call check_higher_state_interruption() to determine if they * return control.

It's up to the programmer of a state to make sure it conforms to this scheme.

luaUrbanEntity::pop_stored_message_response ( )

Retrieves message response from chained event handlers.

Returns any message response object created by the chained message handler associated with the current state. The reponse will have been generated while some child state is in control. See above to understand the concepts.

Returns
Message handler response
luaUrbanEntity::send_message_up_state_chain ( message  )

Chained message handler communication function.

This function is used internally, but it can also be used by a child state to send a message up to parent states. The chained message processors associated with parents (if any) will attempt to respond in their turn. If any do, the response will be saved for later. It will also be returned.

Parameters
messagestandard message object
Returns
Response of a parent state's message handler
luaUrbanEntity::sleep_process_messages ( duration  ,
msg_handler   
)

Puts the active coroutine to sleep for the number of seconds specified.

Any messages received will be passed to the specified message handler. If that function doesn't handle them, they will be passed up the message processor chain (see above).

Note that the message handler is optional. If one isn't given, messages will still be sent up the chain.

Note also that msg_handler should return luaCharacter.MESSAGE_HANDLED if the sleeping should continue until the alloted time runs out. Otherwise, sleep_process_messages() will wake up.

Parameters
durationin seconds
msg_handlerthe handler

Member Data Documentation

local luaUrbanEntity::goto_result = self->invoke_state({state=self.goto_point_state, arg1=dest_vec, arg2=approach_dist})

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