Panda3D
Public Types | Public Member Functions | Public Attributes | List of all members
AIBehaviors Class Reference

This class implements all the steering behaviors of the AI framework, such as seek, flee, pursue, evade, wander and flock. More...

#include "aiBehaviors.h"

Public Types

enum  _behavior_type {
  _none = 0x00000, _seek = 0x00002, _flee = 0x00004, _flee_activate = 0x00100,
  _arrival = 0x00008, _arrival_activate = 0x01000, _wander = 0x00010, _pursue = 0x00040,
  _evade = 0x00080, _evade_activate = 0x00800, _flock = 0x00200, _flock_activate = 0x00400,
  _obstacle_avoidance = 0x02000, _obstacle_avoidance_activate = 0x04000
}
 

Public Member Functions

void accumulate_force (std::string force_type, LVecBase3 force)
 This function updates the individual steering forces for each of the ai characters. More...
 
void add_dynamic_obstacle (NodePath obstacle)
 This function starts the pathfinding obstacle navigation for the passed in obstacle. More...
 
void add_static_obstacle (NodePath obstacle)
 This function allows the user to dynamically add obstacles to the game environment. More...
 
void add_to_path (LVecBase3 pos)
 This function adds positions to the path to follow. More...
 
void arrival (double distance=10.0)
 This function activates arrival. More...
 
std::string behavior_status (std::string ai_type)
 This function returns the status of an AI Type whether it is active, paused or disabled. More...
 
LVecBase3 calculate_prioritized ()
 This function updates the main steering force for the ai character using the accumulate function and checks for max force and arrival force. More...
 
int char_to_int (std::string ai_type)
 This function is used to derive int values from the ai types strings. More...
 
LVecBase3 do_flock ()
 This function contains the logic for flocking behavior. More...
 
void evade (NodePath target_object, double panic_distance=10.0, double relax_distance=10.0, float evade_wt=1.0)
 This function activates evade_activate. More...
 
void flee (NodePath target_object, double panic_distance=10.0, double relax_distance=10.0, float flee_wt=1.0)
 This function activates flee_activate and creates an object of the Flee class. More...
 
void flee (LVecBase3 pos, double panic_distance=10.0, double relax_distance=10.0, float flee_wt=1.0)
 
void flock (float flock_wt)
 This function activates flock. More...
 
void flock_activate ()
 This function checks whether any other behavior exists to work with flock. More...
 
void init_path_find (const char *navmesh_filename)
 This function activates path finding in the character. More...
 
bool is_conflict ()
 Checks for conflict between steering forces. More...
 
bool is_off (_behavior_type bt)
 This function returns true if an aiBehavior is off. More...
 
bool is_off (std::string ai_type)
 This function returns true if pathfollow or pathfinding is off. More...
 
bool is_on (_behavior_type bt)
 This function returns true if an aiBehavior is on. More...
 
bool is_on (std::string ai_type)
 This function returns true if pathfollow or pathfinding is on. More...
 
void obstacle_avoidance (float feeler_length=1.0)
 This function activates obstacle avoidance for a given character. More...
 
void path_find_to (LVecBase3 pos, std::string type="normal")
 This function checks for the source and target in the navigation mesh for its availability and then finds the best path via the A* algorithm Then it calls the path follower to make the object follow the path. More...
 
void path_find_to (NodePath target, std::string type="normal")
 This function checks for the source and target in the navigation mesh for its availability and then finds the best path via the A* algorithm Then it calls the path follower to make the object follow the path. More...
 
void path_follow (float follow_wt)
 This function activates path following. More...
 
void pause_ai (std::string ai_type)
 This function pauses individual or all the AIs. More...
 
void pursue (NodePath target_object, float pursue_wt=1.0)
 This function activates pursue. More...
 
void remove_ai (std::string ai_type)
 This function removes individual or all the AIs. More...
 
void resume_ai (std::string ai_type)
 This function resumes individual or all the AIs. More...
 
void seek (NodePath target_object, float seek_wt=1.0)
 This function activates seek and makes an object of the Seek class. More...
 
void seek (LVecBase3 pos, float seek_wt=1.0)
 
void start_follow (std::string type="normal")
 This function starts the path follower. More...
 
void turn_off (std::string ai_type)
 This function turns off any aiBehavior which is passed as a string. More...
 
void turn_on (std::string ai_type)
 This function turns on any aiBehavior which is passed as a string. More...
 
void wander (double wander_radius=5.0, int flag=0, double aoe=0.0, float wander_weight=1.0)
 This function activates wander. More...
 

Public Attributes

AICharacter_ai_char
 
LVecBase3 _arrival_force
 
Arrival_arrival_obj
 
int _behaviors_flags
 
bool _conflict
 
LVecBase3 _evade_force
 
ListEvade::iterator _evade_itr
 
ListEvade _evade_list
 
Evade_evade_obj
 
LVecBase3 _flee_force
 
ListFlee::iterator _flee_itr
 
ListFlee _flee_list
 
Flee_flee_obj
 
bool _flock_done
 
LVecBase3 _flock_force
 
Flock_flock_group
 
float _flock_weight
 
LVecBase3 _obstacle_avoidance_force
 
ObstacleAvoidance_obstacle_avoidance_obj
 
PathFind_path_find_obj
 
PathFollow_path_follow_obj
 
bool _previous_conflict
 
LVecBase3 _pursue_force
 
Pursue_pursue_obj
 
LVecBase3 _seek_force
 
Seek_seek_obj
 
LVecBase3 _steering_force
 
LVecBase3 _wander_force
 
Wander_wander_obj
 

Detailed Description

This class implements all the steering behaviors of the AI framework, such as seek, flee, pursue, evade, wander and flock.

Each steering behavior has a weight which is used when more than one type of steering behavior is acting on the same ai character. The weight decides the contribution of each type of steering behavior. The AICharacter class has a handle to an object of this class and this allows to invoke the steering behaviors via the AICharacter. This class also provides functionality such as pausing, resuming and removing the AI behaviors of an AI character at anytime.

Definition at line 44 of file aiBehaviors.h.

Member Function Documentation

◆ accumulate_force()

void AIBehaviors::accumulate_force ( std::string  force_type,
LVecBase3  force 
)

This function updates the individual steering forces for each of the ai characters.

These accumulated forces are eventually what comprise the resultant steering force of the character.

Definition at line 109 of file aiBehaviors.cxx.

Referenced by calculate_prioritized().

◆ add_dynamic_obstacle()

void AIBehaviors::add_dynamic_obstacle ( NodePath  obstacle)

This function starts the pathfinding obstacle navigation for the passed in obstacle.

Definition at line 875 of file aiBehaviors.cxx.

References PathFind::dynamic_avoid().

◆ add_static_obstacle()

void AIBehaviors::add_static_obstacle ( NodePath  obstacle)

This function allows the user to dynamically add obstacles to the game environment.

The function will update the nodes within the bounding volume of the obstacle as non-traversable. Hence will not be considered by the pathfinding algorithm.

Definition at line 867 of file aiBehaviors.cxx.

References PathFind::add_obstacle_to_mesh().

◆ add_to_path()

void AIBehaviors::add_to_path ( LVecBase3  pos)

This function adds positions to the path to follow.

Definition at line 821 of file aiBehaviors.cxx.

References PathFollow::add_to_path().

Referenced by PathFind::trace_path().

◆ arrival()

void AIBehaviors::arrival ( double  distance = 10.0)

This function activates arrival.

This is the function we want the user to call for arrival to be done.

Definition at line 672 of file aiBehaviors.cxx.

References turn_on().

◆ behavior_status()

string AIBehaviors::behavior_status ( std::string  ai_type)

This function returns the status of an AI Type whether it is active, paused or disabled.

It returns -1 if an invalid string is passed.

Definition at line 883 of file aiBehaviors.cxx.

References char_to_int(), and is_on().

◆ calculate_prioritized()

LVecBase3 AIBehaviors::calculate_prioritized ( )

This function updates the main steering force for the ai character using the accumulate function and checks for max force and arrival force.

It finally returns this steering force which is accessed by the update function in the AICharacter class.

Definition at line 164 of file aiBehaviors.cxx.

References accumulate_force(), Arrival::arrival_activate(), Arrival::do_arrival(), do_flock(), PathFollow::do_follow(), ObstacleAvoidance::do_obstacle_avoidance(), Pursue::do_pursue(), Seek::do_seek(), Wander::do_wander(), flock_activate(), is_conflict(), is_on(), and ObstacleAvoidance::obstacle_avoidance_activate().

Referenced by AICharacter::update().

◆ char_to_int()

int AIBehaviors::char_to_int ( std::string  ai_type)

This function is used to derive int values from the ai types strings.

Returns -1 if an invalid string is passed.

Definition at line 1101 of file aiBehaviors.cxx.

Referenced by behavior_status(), pause_ai(), remove_ai(), resume_ai(), turn_off(), and turn_on().

◆ do_flock()

LVecBase3 AIBehaviors::do_flock ( )

This function contains the logic for flocking behavior.

This is an emergent behavior and is obtained by combining three other behaviors which are separation, cohesion and alignment based on Craig Reynold's algorithm. Also, this behavior does not work by itself. It works only when combined with other steering behaviors such as wander, pursue, evade, seek and flee.

Definition at line 717 of file aiBehaviors.cxx.

Referenced by calculate_prioritized().

◆ evade()

void AIBehaviors::evade ( NodePath  target_object,
double  panic_distance = 10.0,
double  relax_distance = 10.0,
float  evade_wt = 1.0 
)

This function activates evade_activate.

Definition at line 661 of file aiBehaviors.cxx.

References turn_on().

◆ flee()

void AIBehaviors::flee ( NodePath  target_object,
double  panic_distance = 10.0,
double  relax_distance = 10.0,
float  flee_wt = 1.0 
)

This function activates flee_activate and creates an object of the Flee class.

This function is overloaded to accept a NodePath or an LVecBase3.

Definition at line 634 of file aiBehaviors.cxx.

References turn_on().

◆ flock()

void AIBehaviors::flock ( float  flock_wt)

This function activates flock.

This is the function we want the user to call for flock to be done.

Definition at line 692 of file aiBehaviors.cxx.

References turn_on().

◆ flock_activate()

void AIBehaviors::flock_activate ( )

This function checks whether any other behavior exists to work with flock.

When this is true, it calls the do_flock function.

Definition at line 703 of file aiBehaviors.cxx.

References is_on(), turn_off(), and turn_on().

Referenced by calculate_prioritized().

◆ init_path_find()

void AIBehaviors::init_path_find ( const char *  navmesh_filename)

This function activates path finding in the character.

This function accepts the meshdata in .csv format.

Definition at line 838 of file aiBehaviors.cxx.

References PathFind::set_path_find().

◆ is_conflict()

bool AIBehaviors::is_conflict ( )

Checks for conflict between steering forces.

If there is a conflict it returns 'true' and sets _conflict to 'true'. If there is no conflict it returns 'false' and sets _conflict to 'false'.

Definition at line 58 of file aiBehaviors.cxx.

References is_on().

Referenced by calculate_prioritized().

◆ is_off() [1/2]

bool AIBehaviors::is_off ( _behavior_type  bt)

This function returns true if an aiBehavior is off.

Definition at line 1358 of file aiBehaviors.cxx.

Referenced by AICharacter::update().

◆ is_off() [2/2]

bool AIBehaviors::is_off ( std::string  ai_type)

This function returns true if pathfollow or pathfinding is off.

Definition at line 1365 of file aiBehaviors.cxx.

◆ is_on() [1/2]

bool AIBehaviors::is_on ( _behavior_type  bt)

This function returns true if an aiBehavior is on.

Definition at line 1326 of file aiBehaviors.cxx.

Referenced by Arrival::arrival_activate(), behavior_status(), calculate_prioritized(), flock_activate(), is_conflict(), is_on(), and turn_off().

◆ is_on() [2/2]

bool AIBehaviors::is_on ( std::string  ai_type)

This function returns true if pathfollow or pathfinding is on.

Definition at line 1333 of file aiBehaviors.cxx.

References is_on().

◆ obstacle_avoidance()

void AIBehaviors::obstacle_avoidance ( float  obstacle_avoidance_weight = 1.0)

This function activates obstacle avoidance for a given character.

This is the function we want the user to call for obstacle avoidance to be performed.

Definition at line 805 of file aiBehaviors.cxx.

References turn_on().

◆ path_find_to() [1/2]

void AIBehaviors::path_find_to ( LVecBase3  pos,
std::string  type = "normal" 
)

This function checks for the source and target in the navigation mesh for its availability and then finds the best path via the A* algorithm Then it calls the path follower to make the object follow the path.

Definition at line 848 of file aiBehaviors.cxx.

References PathFind::path_find().

◆ path_find_to() [2/2]

void AIBehaviors::path_find_to ( NodePath  target,
std::string  type = "normal" 
)

This function checks for the source and target in the navigation mesh for its availability and then finds the best path via the A* algorithm Then it calls the path follower to make the object follow the path.

Definition at line 857 of file aiBehaviors.cxx.

References PathFind::path_find().

◆ path_follow()

void AIBehaviors::path_follow ( float  follow_wt)

This function activates path following.

This is the function we want the user to call for path following.

Definition at line 814 of file aiBehaviors.cxx.

Referenced by PathFind::path_find(), and PathFind::set_path_find().

◆ pause_ai()

void AIBehaviors::pause_ai ( std::string  ai_type)

This function pauses individual or all the AIs.

Definition at line 427 of file aiBehaviors.cxx.

References char_to_int(), and turn_off().

Referenced by Arrival::arrival_activate().

◆ pursue()

void AIBehaviors::pursue ( NodePath  target_object,
float  pursue_wt = 1.0 
)

This function activates pursue.

This is the function we want the user to call for pursue to be done.

Definition at line 652 of file aiBehaviors.cxx.

References turn_on().

Referenced by PathFollow::start().

◆ remove_ai()

void AIBehaviors::remove_ai ( std::string  ai_type)

This function removes individual or all the AIs.

Definition at line 311 of file aiBehaviors.cxx.

References char_to_int(), and turn_off().

Referenced by PathFind::path_find(), and PathFind::set_path_find().

◆ resume_ai()

void AIBehaviors::resume_ai ( std::string  ai_type)

This function resumes individual or all the AIs.

Definition at line 525 of file aiBehaviors.cxx.

References char_to_int(), turn_off(), and turn_on().

◆ seek()

void AIBehaviors::seek ( NodePath  target_object,
float  seek_wt = 1.0 
)

This function activates seek and makes an object of the Seek class.

This is the function we want the user to call for seek to be done. This function is overloaded to accept a NodePath or an LVecBase3.

Definition at line 620 of file aiBehaviors.cxx.

References turn_on().

◆ start_follow()

void AIBehaviors::start_follow ( std::string  type = "normal")

This function starts the path follower.

Definition at line 829 of file aiBehaviors.cxx.

References PathFollow::start().

Referenced by PathFind::path_find().

◆ turn_off()

void AIBehaviors::turn_off ( std::string  ai_type)

This function turns off any aiBehavior which is passed as a string.

Definition at line 1222 of file aiBehaviors.cxx.

References char_to_int(), and is_on().

Referenced by Arrival::arrival_activate(), Evade::evade_activate(), Flee::flee_activate(), flock_activate(), ObstacleAvoidance::obstacle_avoidance_activate(), pause_ai(), remove_ai(), and resume_ai().

◆ turn_on()

void AIBehaviors::turn_on ( std::string  ai_type)

◆ wander()

void AIBehaviors::wander ( double  wander_radius = 5.0,
int  flag = 0,
double  aoe = 0.0,
float  wander_weight = 1.0 
)

This function activates wander.

This is the function we want the user to call for flock to be done.

Definition at line 795 of file aiBehaviors.cxx.

References turn_on().


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