27 _ai_char_pool->append(ai_char);
28 ai_char->_window_render = _render;
29 ai_char->_world =
this;
32 void AIWorld::remove_ai_char(
string name) {
33 _ai_char_pool->del(name);
34 remove_ai_char_from_flock(name);
37 void AIWorld::remove_ai_char_from_flock(
string name) {
39 ai_pool = _ai_char_pool->_head;
40 while((ai_pool) != NULL) {
41 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
42 if(ai_pool->_ai_char->_ai_char_flock_id == _flock_pool[i]->get_id()) {
43 for(
unsigned int j = 0; j<_flock_pool[i]->_ai_char_list.size(); ++j) {
44 if(_flock_pool[i]->_ai_char_list[j]->_name == name) {
45 _flock_pool[i]->_ai_char_list.erase(_flock_pool[i]->_ai_char_list.begin() + j);
51 ai_pool = ai_pool->_next;
55 void AIWorld::print_list() {
68 ai_pool = _ai_char_pool->_head;
70 while((ai_pool)!=NULL) {
71 ai_pool->_ai_char->
update();
72 ai_pool = ai_pool->_next;
87 for(
unsigned int i = 0; i < flock->_ai_char_list.size(); ++i) {
88 this->add_ai_char(flock->_ai_char_list[i]);
91 _flock_pool.push_back(flock);
102 for(
unsigned int i=0; i < _flock_pool.size(); ++i) {
103 if(_flock_pool[i]->get_id() == flock_id) {
104 return *_flock_pool[i];
107 Flock *null_flock = NULL;
119 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
120 if(_flock_pool[i]->get_id() == flock_id) {
121 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
122 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock_activate");
123 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock");
124 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->_flock_group = NULL;
126 _flock_pool.erase(_flock_pool.begin() + i);
141 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
142 if(_flock_pool[i]->get_id() == flock_id) {
143 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
144 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock_activate");
145 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock");
160 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
161 if(_flock_pool[i]->get_id() == flock_id) {
162 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
163 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_on(
"flock_activate");
170 AICharPool::AICharPool() {
174 AICharPool::~AICharPool() {
189 while( q->_next != NULL) {
200 void AICharPool::del(
string name) {
210 if(q->_next == NULL) {
211 if(q->_ai_char->_name == name) {
220 if( q->_ai_char->_name == name) {
249 cout<<q->_ai_char->_name<<endl;
263 _obstacles.push_back(obstacle);
275 for(
unsigned int i = 0; i <= _obstacles.size(); ++i) {
276 if(_obstacles[i] == obstacle) {
277 _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 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...
void print_list()
This function prints the ai characters in the AICharPool.
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...
This class implements a linked list of AI Characters allowing the user to add and delete characters f...
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.