17 _render = std::move(render);
24 _ai_char_pool.push_back(ai_char);
25 ai_char->_window_render = _render;
26 ai_char->_world =
this;
29 void AIWorld::remove_ai_char(std::string name) {
30 AICharPool::iterator it;
31 for (it = _ai_char_pool.begin(); it != _ai_char_pool.end(); ++it) {
33 if (ai_char->_name == name) {
34 nassertv(ai_char->_world ==
this);
35 ai_char->_world =
nullptr;
36 _ai_char_pool.erase(it);
41 remove_ai_char_from_flock(std::move(name));
44 void AIWorld::remove_ai_char_from_flock(std::string name) {
46 for (
Flock *flock : _flock_pool) {
47 if (ai_char->_ai_char_flock_id == flock->get_id()) {
48 for (
size_t j = 0; j < flock->_ai_char_list.size(); ++j) {
49 if (flock->_ai_char_list[j]->_name == name) {
50 flock->_ai_char_list.erase(flock->_ai_char_list.begin() + j);
65 std::cout << ai_char->_name << std::endl;
86 for(
unsigned int i = 0; i < flock->_ai_char_list.size(); ++i) {
87 this->add_ai_char(flock->_ai_char_list[i]);
90 _flock_pool.push_back(flock);
97 for(
unsigned int i=0; i < _flock_pool.size(); ++i) {
98 if(_flock_pool[i]->get_id() == flock_id) {
99 return *_flock_pool[i];
102 Flock *null_flock =
nullptr;
110 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
111 if(_flock_pool[i]->get_id() == flock_id) {
112 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
113 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock_activate");
114 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock");
115 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->_flock_group =
nullptr;
117 _flock_pool.erase(_flock_pool.begin() + i);
128 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
129 if(_flock_pool[i]->get_id() == flock_id) {
130 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
131 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock_activate");
132 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock");
143 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
144 if(_flock_pool[i]->get_id() == flock_id) {
145 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
146 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_on(
"flock_activate");
158 _obstacles.push_back(obstacle);
166 for(
unsigned int i = 0; i <= _obstacles.size(); ++i) {
167 if(_obstacles[i] == obstacle) {
168 _obstacles.erase(_obstacles.begin() + i);
void flock_on(unsigned int flock_id)
This function turns on the flock behavior.
void remove_flock(unsigned int flock_id)
This function removes the flock behavior completely.
void add_obstacle(NodePath obstacle)
This function adds the nodepath as an obstacle that is needed by the obstacle avoidance behavior.
void update()
The AIWorld update function calls the update function of all the AI characters which have been added ...
void print_list()
This function prints the names of the AI characters that have been added to the AIWorld.
void add_flock(Flock *flock)
This function adds all the AI characters in the Flock object to the AICharPool.
This class is used to define the flock attributes and the AI characters which are part of the flock.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void flock_off(unsigned int flock_id)
This function turns off the flock behavior temporarily.
void remove_obstacle(NodePath obstacle)
This function removes the nodepath from the obstacles list that is needed by the obstacle avoidance b...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
void update()
Each character's update will update its AI and physics based on his resultant steering force.
Flock get_flock(unsigned int flock_id)
This function returns a handle to the Flock whose id is passed.