Agent is an FSM with message handling capabilities. In addition to
states and actions, Agent supports incoming and outcoming boxes of
messages and a set of message handlers.
In the absence of incoming messages Agent works as an FSM. When Agent
finds a command in its inBox, it runs a handler function (if any).
Message handlers can change FSM state. To send a command to an Agent
other objects call functions sendCommand or postCommand (named by win32
functions). Only Dispatcher(s) or Collective that have the Agent as a
member can send commands to it. Also Agent can post messages (reports)
into its outBox using sendReport function. Only Agent's owner (a
Collective) or Dispatchers, to which Agent reports to, can check outBox
for reports.
Such organization divides responsibilities between objects in the game
and establishes communication flow: Collectives and Dispatchers send
commands to Agents, Agents send reports back.
| Method Summary |
| |
__init__(self,
name)
|
| |
clearInBox(self,
timeInc)
Removes messages with delay=0 from inBox. |
| |
clearOutBox(self,
timeInc)
Removes all messages with delay=0 from outBox. |
| |
executeCommands(self)
Calls handler for each message in the incoming box. |
| |
postCommand(self,
type,
delay,
paramsDict)
Places command into inBox. |
| |
sendCommand(self,
type,
delay,
paramsDict)
Sends a command with immediate invocation of a handler, if the handler
is available. |
| |
sendReport(self,
type,
delay,
paramsDict)
Places report message into outBox. |
| |
trace(self,
args)
|
| |
update(self,
timeInc)
Handles all incoming messages and then updates FSM. |
| Inherited from FSM |
| |
setAction(self)
Looks for the action by key=self.currState, sets it if found. |
| |
setState(self,
state)
Sets the current action function in addition to just changing the
state variable. |
| |
updateAction(self,
timeInc)
Calls current action function if it is set. |