Good, eh? The remainder of this chapter will demonstrate how agents can
be given the ability to handle messages like this. But before we can figure
out how to transmit them and handle them, the first thing to do is to define
exactly what a message is.
The Telegram Structure
A message is simply an enumerated type. This could be just about any
thing. You could have agents sending messages like
Msg_MoveToPosition,orMsg_HelpNeeded. Additional information also needs
to be packaged along with the message. For example, we should record
information about who sent it, who the recipient is, what the actual mes
sage is, a time stamp, and so forth. To do this, all the relevant information
is kept together in a structure called
Telegram. The code is shown below.
Examine each member variable and get a feel for what sort of information
the game agents will be passing around.
//the entity that sent this telegram
//the entity that is to receive this telegram
//the message itself. These are all enumerated in the file
//messages can be dispatched immediately or delayed for a specified amount
//of time. If a delay is necessary, this field is stamped with the time
//the message should be dispatched.
//any additional information that may accompany the message
/* CONSTRUCTORS OMITTED */
The Telegram structure should be reusable, but because it’s impossible to
know in advance what sort of additional information future game designs
will need to pass in a message, a void pointer
ExtraInfo is provided. This
can be used to pass any amount of additional information between charac
ters. For example, if a platoon leader sends the message
to all his men, ExtraInfo can be used to store the coordinates of that
70 | Chapter 2
Adding Messaging Capabilities to Your FSM