Changeset 10793
- Timestamp:
- Nov 10, 2015, 4:37:34 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/CommonController.cc
r10789 r10793 55 55 this->executingMoveToPoint_ = false; 56 56 57 this->maneuverType_ = ManeuverType::NONE; 57 58 RegisterObject(CommonController); 58 59 } … … 116 117 } 117 118 } 118 119 void CommonController::chooseManeuverType() 120 { 121 122 if (this->target_ && this->bHasPositionOfTarget_ && this->getControllableEntity()) 123 { 124 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 125 Vector3 myForwardVector = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT; 126 float myDotProduct = diffVector.dotProduct(myForwardVector); 127 128 Vector3 opponentForwardVector = this->target_->getOrientation() * WorldEntity::FRONT; 129 float opponentDotProduct = diffVector.dotProduct(opponentForwardVector); 130 131 132 switch ((myDotProduct > 0) - (myDotProduct < 0)) 133 { 134 case 1: 135 { 136 switch ((opponentDotProduct > 0) - (opponentDotProduct < 0)) 137 { 138 case 1: 139 { 140 this->maneuverType_ = ManeuverType::OFFENSIVE; 141 break; 142 } 143 case 0: 144 { 145 this->maneuverType_ = ManeuverType::OFFENSIVE; 146 break; 147 } 148 case -1: 149 { 150 this->maneuverType_ = ManeuverType::NEUTRAL; 151 break; 152 } 153 } 154 break; 155 } 156 case 0: 157 { 158 switch ((opponentDotProduct > 0) - (opponentDotProduct < 0)) 159 { 160 case 1: 161 { 162 this->maneuverType_ = ManeuverType::OFFENSIVE; 163 break; 164 } 165 case 0: 166 { 167 this->maneuverType_ = ManeuverType::NEUTRAL; 168 break; 169 } 170 case -1: 171 { 172 this->maneuverType_ = ManeuverType::DEFENCIVE; 173 break; 174 } 175 } 176 177 break; 178 } 179 case -1: 180 { 181 switch ((opponentDotProduct > 0) - (opponentDotProduct < 0)) 182 { 183 case 1: 184 { 185 this->maneuverType_ = ManeuverType::NEUTRAL; 186 break; 187 } 188 case 0: 189 { 190 this->maneuverType_ = ManeuverType::DEFENCIVE; 191 break; 192 } 193 case -1: 194 { 195 this->maneuverType_ = ManeuverType::DEFENCIVE; 196 break; 197 } 198 } 199 break; 200 } 201 } 202 } 203 if (this->getControllableEntity() && !this->target_) 204 { 205 this->maneuverType_ = ManeuverType::NONE; 206 } 207 orxout (internal_error) << "ManeuverType = " << this->maneuverType_ << endl; 208 } 119 209 bool CommonController::setWingman (CommonController* wingman) 120 210 { … … 130 220 this->target_ = target; 131 221 orxout (internal_error) << " TARGET SET " << endl; 132 if (target) 133 this->targetPosition_ = target->getPosition(); 134 } 135 136 222 223 if (this->target_ ) 224 { 225 this->setPositionOfTarget(target_->getWorldPosition()); 226 227 } 228 } 229 bool CommonController::hasTarget() 230 { 231 if (this->target_) 232 return true; 233 return false; 234 } 235 void CommonController::setPositionOfTarget(const Vector3& target) 236 { 237 this->positionOfTarget_ = target; 238 this->bHasPositionOfTarget_ = true; 239 } 240 void CommonController::setOrientationOfTarget(const Quaternion& orient) 241 { 242 this->orientationOfTarget_=orient; 243 this->bHasOrientationOfTarget_=true; 244 } 137 245 138 246 void CommonController::setTargetPosition(const Vector3& target) … … 370 478 371 479 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 480 372 481 if (pawn) 373 pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT)); 482 //pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT)); 483 pawn->setAimPosition(this->targetPosition_); 374 484 375 485 this->getControllableEntity()->fire(0); -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10789 r10793 111 111 112 112 void setTarget(ControllableEntity* target); 113 113 bool hasTarget(); 114 114 void setTargetOrientation(const Quaternion& orient); 115 115 void setTargetOrientation(ControllableEntity* target); … … 153 153 Quaternion targetOrientation_; 154 154 155 155 void setPositionOfTarget(const Vector3& target); 156 void setOrientationOfTarget(const Quaternion& orient); 156 157 bool bHasPositionOfTarget_; 157 158 Vector3 positionOfTarget_; … … 165 166 166 167 168 void chooseManeuverType(); 167 169 168 170 FormationMode::Value formationMode_; -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10789 r10793 57 57 void DivisionController::tick(float dt) 58 58 { 59 if (this->target_ ) 60 { 61 this->setPositionOfTarget(target_->getWorldPosition()); 62 63 } 59 64 /*if (this->target_) 60 65 { … … 82 87 Vector3* pos = new Vector3(4000,1000,2000); 83 88 this->setTargetPosition(*pos);*/ 84 85 setTargetPositionOfFollower(); 86 setTargetPositionOfWingman(); 89 90 /* if (!this->target_) 91 { 92 93 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 94 { 95 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*it)->getTeam()) 96 continue; 97 98 99 100 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) 101 { 102 this->setTarget(*it); 103 } 104 } 105 }*/ 106 this->chooseManeuverType(); 107 switch (this->maneuverType_) 108 { 109 case ManeuverType::NONE: 110 { 111 setTargetPositionOfFollower(); 112 setTargetPositionOfWingman(); 113 break; 114 } 115 case ManeuverType::DEFENSIVE: 116 { 117 this->gunsD(); 118 } 119 case ManeuverType::OFFENSIVE: 120 { 121 this->attack(); 122 } 123 } 124 87 125 if (!executingMoveToPoint_) 88 126 { -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10789 r10793 80 80 } 81 81 }*/ 82 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 83 { 84 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam()) 85 continue; 86 87 for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it) 88 { 89 if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget()) 90 { 91 (*it)->setTarget(*itP); 92 } 93 94 } 95 96 } 82 97 83 98 }
Note: See TracChangeset
for help on using the changeset viewer.