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 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 |
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.
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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.
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
void AIBehaviors::turn_on | ( | std::string | ai_type | ) |
This function turns on any aiBehavior which is passed as a string.
Definition at line 1160 of file aiBehaviors.cxx.
References char_to_int().
Referenced by arrival(), Arrival::arrival_activate(), evade(), Evade::evade_activate(), flee(), Flee::flee_activate(), flock(), flock_activate(), obstacle_avoidance(), ObstacleAvoidance::obstacle_avoidance_activate(), pursue(), resume_ai(), seek(), and 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().