- Timestamp:
- Oct 19, 2015, 4:01:54 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
r10654 r10670 86 86 } 87 87 88 88 89 if (this->state_ == SLAVE && this->formationMode_ == ATTACK) 89 90 { … … 108 109 //------------------------------------------------------- 109 110 //collect data for AI behaviour 110 Vector3 meanOfEnemies; 111 Vector3 meanOfAllies; 111 Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0); 112 Vector3* meanOfAlliesPtr = new Vector3(0.0,0.0,0.0); 113 Vector3 meanOfAllies = *meanOfAlliesPtr; 114 Vector3 meanOfEnemies = *meanOfEnemiesPtr; 115 112 116 113 117 for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it) … … 121 125 if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt)) 122 126 { 123 enemies .push_back(*it);127 enemies_.push_back(*it); 124 128 } 125 129 else { 126 allies .push_back(*it);130 allies_.push_back(*it); 127 131 } 128 132 } 129 if (enemies.size() != 0 && allies.size() != 0){ 130 for (std::vector<AIController*>::iterator it = enemies.begin() ; it != enemies.end(); ++it) 131 meanOfEnemies += (*it)->getControllableEntity()->getPosition(); 132 meanOfEnemies /= enemies.size(); 133 for (std::vector<AIController*>::iterator it = allies.begin() ; it != allies.end(); ++it) 134 meanOfAllies += (*it)->getControllableEntity()->getPosition(); 135 meanOfAllies /= allies.size(); 136 //orxout(internal_error) << "There are " << enemiesCounter << " enemies, mean position is " << meanOfEnemies << endl; 137 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl; 138 orxout(internal_error) << "mean of Allies is " << meanOfAllies << ", with a size " << allies.size() << endl; 139 orxout(internal_error) << "mean of Enemies is " << meanOfEnemies << ", with a size " << enemies.size() << endl; 133 if (enemies_.size() != 0 && allies_.size() != 0){ 134 for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it) 135 meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition(); 136 137 meanOfEnemies /= enemies_.size(); 138 139 for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it) 140 meanOfAllies += (*it)->getControllableEntity()->getWorldPosition(); 141 142 meanOfAllies /= allies_.size(); 143 144 //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl; 145 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl; 146 orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl; 147 orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl; 140 148 } 141 149 //------------------------------------------------------- 142 150 143 151 //Decide which formationMode to choose 144 152 this->setFormationMode(ATTACK); 145 146 this->commandSlaves(); 153 this->setDesiredPositionOfSlaves(); 154 155 //this->commandSlaves(); 147 156 148 157 if (this->specificMasterAction_ != NONE) … … 184 193 } 185 194 } 186 allies .clear();187 enemies .clear();195 allies_.clear(); 196 enemies_.clear(); 188 197 } 189 198 … … 196 205 float maxrand = 100.0f / ACTION_INTERVAL; 197 206 ControllableEntity* controllable = this->getControllableEntity(); 207 if (this->state_ == SLAVE) 208 { 209 Vector3 desiredAbsolutePosition = this->myMaster_->getControllableEntity()->getWorldPosition() + this->myMaster_->getControllableEntity()->getWorldOrientation()*desiredRelativePosition_; 210 211 orxonox::WeakPtr<MovableEntity> waypoint = new MovableEntity(this->center_->getContext()); 212 waypoint->setPosition(desiredAbsolutePosition); 213 214 this->addWaypoint(waypoint); 215 } 198 216 //DOES: Either move to the waypoint or search for a Point of interest 199 217 if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
Note: See TracChangeset
for help on using the changeset viewer.