Game Development Reference
In-Depth Information
Implementing the NPC decision system
The NPCs in our e-learning game will need to be able to interact with the player and
the world in addition to following a user-defined path. While the path-following code
was easily encapsulated in one file, we will see that a general purpose solution to the
first problem requires a more intricate design.
Our solution will be modeled around and function similarly to a question-and-answer
system. A number of classes will be required for implementation:
npcCondition : This is the base class for a question that the NPCs logic will
ask about the player or the world.
npcResponse : This is the base class for a response that the NPCs logic will
invoke if a condition is found to be true.
npcInteraction : This container class will house the association of a con-
dition with a response. It will be responsible for testing if the condition is true
(whatever the condition may be) and for invoking the appropriate response
when that happens.
npcDecisionMgr : This class is the brain of the NPC. It will house a collection
of interactions and will ask these interactions to evaluate themselves. Since
each interaction responds to the state of the world individually, the brain only
needs to delegate this responsibility to each interaction! Simple, right?
To prove that our DecisionMgr system works, we will need a few more specializa-
tion helper classes. These will help us see the system in action and validate its beha-
vior.
condition_closerThanThresh : This is a condition script that checks if the
distance from object A to object B is less than a parameter. If it is, it returns
true.
Search WWH ::




Custom Search