#include <basenpc.h>
Public Types | |
| typedef std::map< std::string, Goal * > | GoalMap |
| typedef GoalMap::allocator_type::value_type | GoalMapping |
| typedef dtUtil::Functor< bool, TYPELIST_2(double, WorldState *) | Action ) |
| typedef std::map< std::string, Action > | ActionMap |
Public Member Functions | |
| BaseNPC (const std::string &pName) | |
| void | InitNPC () |
| InitNPC() must be called before spawn use OnInitNPC() for derived initialize behavior calls InitializeFSM() and RegisterActions(). | |
| void | SpawnNPC () |
| SpawnNPC() sets the WorldState of the NPC to be equal to the WorldState template (SetWSTemplate()) it then sets a goal from the goal list if it does not already have one and changes the state to NPC_STATE_SPAWN. | |
| void | KillNPC () |
| KillNPC() puts the character in the sleep state so it no longer does processing on update and changes the state to NPC_STATE_DIE. | |
| void | SetSleeping (bool pIsSleeping) |
| Sets the NPC into the Sleep state which does nothing on update. | |
| virtual void | Update (double dt) |
| Update should be called every frame calls ExecutePlan which will run a plan if one has been generated Updates the state machine which may change states based on input. | |
| bool | LoadNPCScript (const std::string &pFileName) |
| Loads Operators, Goals and Conditionals from an NPCScript file see UnitTestsDtAI for an example. | |
| bool | SetGoal (const std::string &pGoal) |
| Sets the current goal by name, the goal is used during GeneratePlan if the user has not overridden IsDesiredState(). | |
| void | GeneratePlan () |
| GeneratePlan() uses the Planner to generate a plan the plan is a list of Operators which can be added manually or added through LoadNPCScript with a valid script file the plan is created to be of minimal cost (uses RemainingCost()) and satisfy the IsDesiredState() function. | |
| void | RegisterAction (const std::string &pName, Action pAction) |
| Actions are function pointers called by name during ExecutePlan() there must be an action registered for every Operator with the same name returned by the Operators GetName() function. | |
| void | AddOperator (Operator *pOperator) |
| Operators define what the NPC can do and how it affects the NPC's state Operators are used to chain together in order to satisfy a Goal they can be added manually or added by LoadNPCScript(). | |
| void | AddGoal (const std::string &pName, Goal *pGoal) |
| Goals are used to control an NPC's behavior they evaluate a WorldState and return whether or not the WorldState completes the Goal Goals can be added manually or added through LoadNPCScript(). | |
| const Planner::OperatorList & | GetPlan () const |
| GetPlan() returns the last plan generated through GeneratePlan() where a plan is just a list of Operators designed to achieve a specific Goal. | |
| const WorldState & | GetWSTemplate () const |
| GetWSTemplate() returns the template of the WorldState for this NPC a WorldState Template can be thought of as the initial state of the NPC. | |
| WorldState & | GetWSTemplate () |
| void | SetWSTemplate (const WorldState &pWS) |
| Sets the template used for this NPC's initial state since this wipes out previous state template it is recommended to do a GetWSTemplate() and then add the appropriate state variables. | |
| const std::string & | GetName () const |
| Returns the name of this NPC. | |
Protected Member Functions | |
| virtual | ~BaseNPC () |
| virtual void | SelectState (double dt) |
| Override this to set the initial state of the NPC after it is spawned. | |
| bool | ExecuteAction (const std::string &pAction, double dt, WorldState *pWS) |
| Runs an action of specifed name, where an action is a function that modifies the NPC's WorldState. | |
| virtual void | ExecutePlan (double dt) |
| Calls GeneratePlan if no plan exists Proceeds to run each Action registered with a specific name of an Operator moving to call the next Action when the current one returns true called on Update(). | |
| void | InitializeFSM () |
| Sets up the FSM with the basic states DEFAULT, SPAWN, IDLE, DIE as defined in NPCState.h. | |
| virtual void | OnInitializeFSM () |
| Override OnInitializeFSM() to add states and transitions specific to your NPC. | |
| virtual void | OnInit () |
| Called on InitNPC(). | |
| virtual void | RegisterActions () |
| Override to register function pointers with strings which correspond to the name of this NPC's Operators using RegisterAction() NOTE: In order to run a generated plan you must override this and register an Action for each potential Operator. | |
| virtual float | RemainingCost (const WorldState *pWS) const |
| Used by the planner on GeneratePlan should estimate the cost remaining to achieve the desired goal the more accurate this is, the more optimized the algorithm will be able to generate a plan. | |
| virtual bool | IsDesiredState (const WorldState *pWS) const |
| Used by the planner on GeneratePlan returns true when the WorldState passed in is desirable the default implementation uses a specific Goal to evaluate the plan and determine if certain conditionals are met. | |
Protected Attributes | |
| bool | mSleeping |
| const std::string | mName |
| FSM | mStateMachine |
| ActionMap | mActions |
| Planner | mPlanner |
| PlannerHelper | mHelper |
| WorldState | mWSTemplate |
| GoalMap | mGoals |
| GoalMapping * | mCurrentGoal |
| Planner::OperatorList | mCurrentPlan |
| typedef std::map<std::string, Goal*> dtAI::BaseNPC::GoalMap |
| typedef GoalMap::allocator_type::value_type dtAI::BaseNPC::GoalMapping |
| typedef dtUtil::Functor<bool,TYPELIST_2(double, WorldState*) dtAI::BaseNPC::Action) |
| typedef std::map<std::string, Action> dtAI::BaseNPC::ActionMap |
| dtAI::BaseNPC::BaseNPC | ( | const std::string & | pName | ) |
| dtAI::BaseNPC::~BaseNPC | ( | ) | [protected, virtual] |
| void dtAI::BaseNPC::InitNPC | ( | ) |
InitNPC() must be called before spawn use OnInitNPC() for derived initialize behavior calls InitializeFSM() and RegisterActions().
| void dtAI::BaseNPC::SpawnNPC | ( | ) |
SpawnNPC() sets the WorldState of the NPC to be equal to the WorldState template (SetWSTemplate()) it then sets a goal from the goal list if it does not already have one and changes the state to NPC_STATE_SPAWN.
| void dtAI::BaseNPC::KillNPC | ( | ) |
KillNPC() puts the character in the sleep state so it no longer does processing on update and changes the state to NPC_STATE_DIE.
| void dtAI::BaseNPC::SetSleeping | ( | bool | pIsSleeping | ) |
Sets the NPC into the Sleep state which does nothing on update.
| void dtAI::BaseNPC::Update | ( | double | dt | ) | [virtual] |
Update should be called every frame calls ExecutePlan which will run a plan if one has been generated Updates the state machine which may change states based on input.
| bool dtAI::BaseNPC::LoadNPCScript | ( | const std::string & | pFileName | ) |
Loads Operators, Goals and Conditionals from an NPCScript file see UnitTestsDtAI for an example.
| bool dtAI::BaseNPC::SetGoal | ( | const std::string & | pGoal | ) |
Sets the current goal by name, the goal is used during GeneratePlan if the user has not overridden IsDesiredState().
| void dtAI::BaseNPC::GeneratePlan | ( | ) |
GeneratePlan() uses the Planner to generate a plan the plan is a list of Operators which can be added manually or added through LoadNPCScript with a valid script file the plan is created to be of minimal cost (uses RemainingCost()) and satisfy the IsDesiredState() function.
| void dtAI::BaseNPC::RegisterAction | ( | const std::string & | pName, | |
| Action | pAction | |||
| ) |
Actions are function pointers called by name during ExecutePlan() there must be an action registered for every Operator with the same name returned by the Operators GetName() function.
| void dtAI::BaseNPC::AddOperator | ( | Operator * | pOperator | ) |
Operators define what the NPC can do and how it affects the NPC's state Operators are used to chain together in order to satisfy a Goal they can be added manually or added by LoadNPCScript().
| void dtAI::BaseNPC::AddGoal | ( | const std::string & | pName, | |
| Goal * | pGoal | |||
| ) |
Goals are used to control an NPC's behavior they evaluate a WorldState and return whether or not the WorldState completes the Goal Goals can be added manually or added through LoadNPCScript().
| const Planner::OperatorList & dtAI::BaseNPC::GetPlan | ( | ) | const |
GetPlan() returns the last plan generated through GeneratePlan() where a plan is just a list of Operators designed to achieve a specific Goal.
| const WorldState & dtAI::BaseNPC::GetWSTemplate | ( | ) | const |
GetWSTemplate() returns the template of the WorldState for this NPC a WorldState Template can be thought of as the initial state of the NPC.
| WorldState & dtAI::BaseNPC::GetWSTemplate | ( | ) |
| void dtAI::BaseNPC::SetWSTemplate | ( | const WorldState & | pWS | ) |
Sets the template used for this NPC's initial state since this wipes out previous state template it is recommended to do a GetWSTemplate() and then add the appropriate state variables.
| const std::string & dtAI::BaseNPC::GetName | ( | ) | const |
Returns the name of this NPC.
| void dtAI::BaseNPC::SelectState | ( | double | dt | ) | [protected, virtual] |
Override this to set the initial state of the NPC after it is spawned.
| bool dtAI::BaseNPC::ExecuteAction | ( | const std::string & | pAction, | |
| double | dt, | |||
| WorldState * | pWS | |||
| ) | [protected] |
Runs an action of specifed name, where an action is a function that modifies the NPC's WorldState.
| void dtAI::BaseNPC::ExecutePlan | ( | double | dt | ) | [protected, virtual] |
| void dtAI::BaseNPC::InitializeFSM | ( | ) | [protected] |
Sets up the FSM with the basic states DEFAULT, SPAWN, IDLE, DIE as defined in NPCState.h.
| void dtAI::BaseNPC::OnInitializeFSM | ( | ) | [protected, virtual] |
Override OnInitializeFSM() to add states and transitions specific to your NPC.
| void dtAI::BaseNPC::OnInit | ( | ) | [protected, virtual] |
Called on InitNPC().
| void dtAI::BaseNPC::RegisterActions | ( | ) | [protected, virtual] |
Override to register function pointers with strings which correspond to the name of this NPC's Operators using RegisterAction() NOTE: In order to run a generated plan you must override this and register an Action for each potential Operator.
| float dtAI::BaseNPC::RemainingCost | ( | const WorldState * | pWS | ) | const [protected, virtual] |
Used by the planner on GeneratePlan should estimate the cost remaining to achieve the desired goal the more accurate this is, the more optimized the algorithm will be able to generate a plan.
| bool dtAI::BaseNPC::IsDesiredState | ( | const WorldState * | pWS | ) | const [protected, virtual] |
Used by the planner on GeneratePlan returns true when the WorldState passed in is desirable the default implementation uses a specific Goal to evaluate the plan and determine if certain conditionals are met.
bool dtAI::BaseNPC::mSleeping [protected] |
const std::string dtAI::BaseNPC::mName [protected] |
FSM dtAI::BaseNPC::mStateMachine [protected] |
ActionMap dtAI::BaseNPC::mActions [protected] |
Planner dtAI::BaseNPC::mPlanner [protected] |
PlannerHelper dtAI::BaseNPC::mHelper [protected] |
WorldState dtAI::BaseNPC::mWSTemplate [protected] |
GoalMap dtAI::BaseNPC::mGoals [protected] |
GoalMapping* dtAI::BaseNPC::mCurrentGoal [protected] |
Planner::OperatorList dtAI::BaseNPC::mCurrentPlan [protected] |