Changeset 10670 for code/branches/AI_HS15/src/orxonox/controllers
- Timestamp:
- Oct 19, 2015, 4:01:54 PM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 4 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 -
code/branches/AI_HS15/src/orxonox/controllers/AIController.h
r10654 r10670 54 54 55 55 Timer actionTimer_; //<! Regularly calls action(). 56 std::vector<AIController*> enemies, allies; 56 std::vector<WeakPtr<AIController> > enemies_, allies_; 57 Vector3* desiredRelativePosition_; 58 Vector3* currentRelativePosition_; 57 59 }; 58 60 } -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
r10652 r10670 278 278 } 279 279 280 Vector2 coord = get2DView coordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);280 Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 281 281 float distance = (target - this->getControllableEntity()->getPosition()).length(); 282 282 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); … … 703 703 } 704 704 } 705 /** 706 @brief If master, set the desired relative position of slaves (Vector3) in respect to a master for all the slaves. 707 */ 708 void FormationController::setDesiredPositionOfSlaves() 709 { 710 if (this->state_ != MASTER) 711 return; 712 switch (this->formationMode_){ 713 case ATTACK: 714 for(std::vector<FormationController*>::iterator it = slaves_.begin(), float i = 0; it != slaves_.end(); it++, ++i) 715 { 716 (*it)->desiredPosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0); 717 718 } 719 break; 720 case NORMAL: 721 722 break; 723 case DEFEND: 724 725 break; 726 } 727 728 } 705 729 706 730 /** … … 1070 1094 return; 1071 1095 1072 Vector2 coord = get2DView coordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);1096 Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 1073 1097 float distance = (target - this->getControllableEntity()->getPosition()).length(); 1074 1098 -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
r10631 r10670 70 70 { return this->maxFormationSize_; } 71 71 72 72 /** 73 @brief If master, set the desired position of slaves (Vector2) for all the slaves. 74 */ 75 inline void setDesiredPositionOfSlaves(); 76 73 77 inline void setPassive(bool passive) 74 78 { this->passive_ = passive; } … … 92 96 inline FormationMode getFormationMode() const 93 97 { return this->formationMode_; } 94 98 95 99 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 96 100
Note: See TracChangeset
for help on using the changeset viewer.