18 Arrival::Arrival(
AICharacter *ai_ch,
double distance) {
21 _arrival_distance = distance;
22 _arrival_done =
false;
44 direction_to_target = _ai_char->get_ai_behaviors()->_pursue_obj->_pursue_target.
get_pos(_ai_char->_window_render) - _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render);
47 direction_to_target = _ai_char->get_ai_behaviors()->_seek_obj->_seek_position - _ai_char->_ai_char_np.
get_pos(_ai_char->_window_render);
49 distance = direction_to_target.
length();
51 _arrival_direction = direction_to_target;
54 if(
int(distance) == 0) {
55 _ai_char->_steering->_steering_force =
LVecBase3(0.0, 0.0, 0.0);
56 _ai_char->_steering->_arrival_force =
LVecBase3(0.0, 0.0, 0.0);
58 if(_ai_char->_steering->_seek_obj != NULL) {
59 _ai_char->_steering->
turn_off(
"arrival");
60 _ai_char->_steering->
turn_on(
"arrival_activate");
66 _arrival_done =
false;
69 double u = _ai_char->get_velocity().
length();
70 LVecBase3 desired_force = ((u * u) / (2 * distance)) * _ai_char->get_mass();
72 if(_ai_char->_steering->_seek_obj != NULL) {
73 return(desired_force);
76 if(_ai_char->_steering->_pursue_obj != NULL) {
78 if(distance > _arrival_distance) {
79 _ai_char->_steering->
turn_off(
"arrival");
80 _ai_char->_steering->
turn_on(
"arrival_activate");
84 return(desired_force);
87 cout<<
"Arrival works only with seek and pursue"<<endl;
103 dirn = (_ai_char->_ai_char_np.
get_pos(_ai_char->_window_render) - _ai_char->get_ai_behaviors()->_pursue_obj->_pursue_target.
get_pos(_ai_char->_window_render));
106 dirn = (_ai_char->_ai_char_np.
get_pos(_ai_char->_window_render) - _ai_char->get_ai_behaviors()->_seek_obj->_seek_position);
108 double distance = dirn.
length();
110 if(distance < _arrival_distance && _ai_char->_steering->_steering_force.length() > 0) {
111 _ai_char->_steering->
turn_off(
"arrival_activate");
112 _ai_char->_steering->
turn_on(
"arrival");
114 if(_ai_char->_steering->
is_on(_ai_char->_steering->_seek)) {
115 _ai_char->_steering->
turn_off(
"seek");
118 if(_ai_char->_steering->
is_on(_ai_char->_steering->_pursue)) {
119 _ai_char->_steering->
pause_ai(
"pursue");
void pause_ai(string ai_type)
This function pauses individual or all the AIs.
This is the base class for all three-component vectors and points.
LVecBase3 do_arrival()
This function performs the arrival and returns an arrival force which is used in the calculate_priori...
void turn_off(string ai_type)
This function turns off any aiBehavior which is passed as a string.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
void turn_on(string ai_type)
This function turns on any aiBehavior which is passed as a string.
float length() const
Returns the length of the vector, by the Pythagorean theorem.
bool is_on(_behavior_type bt)
This function returns true if an aiBehavior is on.
bool normalize()
Normalizes the vector in place.
void resume_ai(string ai_type)
This function resumes individual or all the AIs.
void arrival_activate()
This function checks for whether the target is within the arrival distance.