Panda3D
Public Types | Public Member Functions | Public Attributes

AIBehaviors Class Reference

List of all members.

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 (string force_type, LVecBase3f force)
 This function updates the individual steering forces for each of the ai characters.
void add_dynamic_obstacle (NodePath obstacle)
 This function starts the pathfinding obstacle navigation for the passed in obstacle.
void add_static_obstacle (NodePath obstacle)
 This function allows the user to dynamically add obstacles to the game environment.
void add_to_path (LVecBase3f pos)
 This function adds positions to the path to follow.
void arrival (double distance=10.0)
 This function activates arrival.
string behavior_status (string ai_type)
 This function returns the status of an AI Type whether it is active, paused or disabled.
LVecBase3f 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.
int char_to_int (string ai_type)
 This function is used to derive int values from the ai types strings.
LVecBase3f do_flock ()
 This function contains the logic for flocking behavior.
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.
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.
void flee (LVecBase3f 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.
void flock_activate ()
 This function checks whether any other behavior exists to work with flock.
void init_path_find (const char *navmesh_filename)
 This function activates path finding in the character.
bool is_conflict ()
 Checks for conflict between steering forces.
bool is_off (_behavior_type bt)
 This function returns true if an aiBehavior is off.
bool is_off (string ai_type)
 This function returns true if pathfollow or pathfinding is off.
bool is_on (string ai_type)
 This function returns true if pathfollow or pathfinding is on.
bool is_on (_behavior_type bt)
 This function returns true if an aiBehavior is on.
void obstacle_avoidance (float feeler_length=1.0)
 This function activates obstacle avoidance for a given character.
void path_find_to (LVecBase3f pos, 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.
void path_find_to (NodePath target, 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.
void path_follow (float follow_wt)
 This function activates path following.
void pause_ai (string ai_type)
 This function pauses individual or all the AIs.
void pursue (NodePath target_object, float pursue_wt=1.0)
 This function activates pursue.
void remove_ai (string ai_type)
 This function removes individual or all the AIs.
void resume_ai (string ai_type)
 This function resumes individual or all the AIs.
void seek (NodePath target_object, float seek_wt=1.0)
 This function activates seek and makes an object of the Seek class.
void seek (LVecBase3f pos, float seek_wt=1.0)
void start_follow (string type="normal")
 This function starts the path follower.
void turn_off (string ai_type)
 This function turns off any aiBehavior which is passed as a string.
void turn_on (string ai_type)
 This function turns on any aiBehavior which is passed as a string.
void wander (double wander_radius=5.0, int flag=0, double aoe=0.0, float wander_weight=1.0)
 This function activates wander.

Public Attributes

AICharacter_ai_char
LVecBase3f _arrival_force
Arrival_arrival_obj
int _behaviors_flags
bool _conflict
LVecBase3f _evade_force
ListEvade::iterator _evade_itr
ListEvade _evade_list
 This list is used if the ai character needs to evade from multiple onjects.
Evade_evade_obj
LVecBase3f _flee_force
ListFlee::iterator _flee_itr
ListFlee _flee_list
 This list is used if the ai character needs to flee from multiple onjects.
Flee_flee_obj
bool _flock_done
LVecBase3f _flock_force
Flock_flock_group
float _flock_weight
 Since Flock is a collective behavior the variables are declared within the AIBehaviors class.
LVecBase3f _obstacle_avoidance_force
ObstacleAvoidance_obstacle_avoidance_obj
PathFind_path_find_obj
PathFollow_path_follow_obj
bool _previous_conflict
LVecBase3f _pursue_force
Pursue_pursue_obj
LVecBase3f _seek_force
Seek_seek_obj
LVecBase3f _steering_force
LVecBase3f _wander_force
Wander_wander_obj

Detailed Description

Definition at line 52 of file aiBehaviors.h.


Member Function Documentation

void AIBehaviors::accumulate_force ( string  force_type,
LVecBase3f  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 114 of file aiBehaviors.cxx.

References LVecBase3f::length(), and LVecBase3f::normalize().

Referenced by calculate_prioritized().

void AIBehaviors::add_dynamic_obstacle ( NodePath  obstacle)

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

Definition at line 965 of file aiBehaviors.cxx.

References PathFind::dynamic_avoid().

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 953 of file aiBehaviors.cxx.

References PathFind::add_obstacle_to_mesh().

void AIBehaviors::add_to_path ( LVecBase3f  pos)

This function adds positions to the path to follow.

Definition at line 888 of file aiBehaviors.cxx.

References PathFollow::add_to_path().

Referenced by PathFind::trace_path().

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 714 of file aiBehaviors.cxx.

References turn_on().

string AIBehaviors::behavior_status ( 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 977 of file aiBehaviors.cxx.

References _evade_list, _flee_list, char_to_int(), and is_on().

LVecBase3f 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 172 of file aiBehaviors.cxx.

References _evade_list, _flee_list, _flock_weight, 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(), LVecBase3f::length(), LVecBase3f::normalize(), and ObstacleAvoidance::obstacle_avoidance_activate().

Referenced by AICharacter::update().

int AIBehaviors::char_to_int ( 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 1198 of file aiBehaviors.cxx.

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

LVecBase3f 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 772 of file aiBehaviors.cxx.

References NodePath::get_pos(), is_on(), LVecBase3f::length(), LVecBase3f::normalize(), turn_off(), and turn_on().

Referenced by calculate_prioritized().

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 699 of file aiBehaviors.cxx.

References _evade_list, and turn_on().

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 LVecBase3f.

Definition at line 664 of file aiBehaviors.cxx.

References _flee_list, and turn_on().

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 738 of file aiBehaviors.cxx.

References _flock_weight, and turn_on().

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 753 of file aiBehaviors.cxx.

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

Referenced by calculate_prioritized().

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 912 of file aiBehaviors.cxx.

References PathFind::set_path_find().

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 60 of file aiBehaviors.cxx.

References _flock_weight, is_on(), LVecBase3f::length(), and LVecBase3f::normalize().

Referenced by calculate_prioritized().

bool AIBehaviors::is_off ( string  ai_type)

This function returns true if pathfollow or pathfinding is off.

Definition at line 1486 of file aiBehaviors.cxx.

bool AIBehaviors::is_off ( _behavior_type  bt)

This function returns true if an aiBehavior is off.

Definition at line 1475 of file aiBehaviors.cxx.

Referenced by AICharacter::update().

bool AIBehaviors::is_on ( string  ai_type)

This function returns true if pathfollow or pathfinding is on.

Definition at line 1446 of file aiBehaviors.cxx.

References is_on().

bool AIBehaviors::is_on ( _behavior_type  bt)

This function returns true if an aiBehavior is on.

Definition at line 1435 of file aiBehaviors.cxx.

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

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 864 of file aiBehaviors.cxx.

References turn_on().

void AIBehaviors::path_find_to ( LVecBase3f  pos,
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 926 of file aiBehaviors.cxx.

References PathFind::path_find().

void AIBehaviors::path_find_to ( NodePath  target,
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 939 of file aiBehaviors.cxx.

References PathFind::path_find().

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 877 of file aiBehaviors.cxx.

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

void AIBehaviors::pause_ai ( string  ai_type)

This function pauses individual or all the AIs.

Definition at line 445 of file aiBehaviors.cxx.

References _evade_list, _flee_list, char_to_int(), and turn_off().

Referenced by Arrival::arrival_activate().

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 686 of file aiBehaviors.cxx.

References turn_on().

Referenced by PathFollow::start().

void AIBehaviors::remove_ai ( string  ai_type)

This function removes individual or all the AIs.

Definition at line 324 of file aiBehaviors.cxx.

References _evade_list, _flee_list, char_to_int(), and turn_off().

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

void AIBehaviors::resume_ai ( string  ai_type)

This function resumes individual or all the AIs.

Definition at line 547 of file aiBehaviors.cxx.

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

Referenced by Arrival::do_arrival().

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 LVecBase3f.

Definition at line 646 of file aiBehaviors.cxx.

References turn_on().

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

This function starts the path follower.

Definition at line 899 of file aiBehaviors.cxx.

References PathFollow::start().

Referenced by PathFind::path_find().

void AIBehaviors::turn_off ( string  ai_type)
void AIBehaviors::turn_on ( string  ai_type)
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 850 of file aiBehaviors.cxx.

References turn_on().


Member Data Documentation

This list is used if the ai character needs to evade from multiple onjects.

Definition at line 95 of file aiBehaviors.h.

Referenced by behavior_status(), calculate_prioritized(), evade(), pause_ai(), remove_ai(), and resume_ai().

This list is used if the ai character needs to flee from multiple onjects.

Definition at line 85 of file aiBehaviors.h.

Referenced by behavior_status(), calculate_prioritized(), flee(), pause_ai(), remove_ai(), and resume_ai().

Since Flock is a collective behavior the variables are declared within the AIBehaviors class.

Definition at line 102 of file aiBehaviors.h.

Referenced by calculate_prioritized(), flock(), and is_conflict().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations