17 _render = std::move(render);
24 _ai_char_pool.push_back(ai_char);
25 ai_char->_window_render = _render;
26 ai_char->_world =
this;
29void 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));
44void 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 static Flock null_flock(0, 0.0, 0.0, 0, 0, 0);
103 nassertr(
false, null_flock);
111 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
112 if(_flock_pool[i]->get_id() == flock_id) {
113 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
114 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock_activate");
115 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock");
116 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->_flock_group =
nullptr;
118 _flock_pool.erase(_flock_pool.begin() + i);
129 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
130 if(_flock_pool[i]->get_id() == flock_id) {
131 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
132 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock_activate");
133 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_off(
"flock");
144 for(
unsigned int i = 0; i < _flock_pool.size(); ++i) {
145 if(_flock_pool[i]->get_id() == flock_id) {
146 for(
unsigned int j = 0; j < _flock_pool[i]->_ai_char_list.size(); ++j) {
147 _flock_pool[i]->_ai_char_list[j]->get_ai_behaviors()->turn_on(
"flock_activate");
159 _obstacles.push_back(obstacle);
167 for(
unsigned int i = 0; i <= _obstacles.size(); ++i) {
168 if(_obstacles[i] == obstacle) {
169 _obstacles.erase(_obstacles.begin() + i);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void update()
Each character's update will update its AI and physics based on his resultant steering force.
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.
void update()
The AIWorld update function calls the update function of all the AI characters which have been added ...
void remove_flock(unsigned int flock_id)
This function removes the flock behavior completely.
Flock get_flock(unsigned int flock_id)
This function returns a handle to the Flock whose id is passed.
void flock_off(unsigned int flock_id)
This function turns off the flock behavior temporarily.
void flock_on(unsigned int flock_id)
This function turns on the flock behavior.
void add_obstacle(NodePath obstacle)
This function adds the nodepath as an obstacle that is needed by the obstacle avoidance behavior.
void remove_obstacle(NodePath obstacle)
This function removes the nodepath from the obstacles list that is needed by the obstacle avoidance b...
This class is used to define the flock attributes and the AI characters which are part of the flock.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...