- Timestamp:
- Nov 10, 2015, 4:37:34 PM (9 years ago)
- File:
-
- 1 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);
Note: See TracChangeset
for help on using the changeset viewer.