Changeset 10805 for code/branches/AI_HS15/src/orxonox/controllers
- Timestamp:
- Nov 15, 2015, 4:47:35 PM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10803 r10805 55 55 this->executingManeuver_ = false; 56 56 this->executingMoveToPoint_ = false; 57 this->action_ = Action::FLY; 57 58 this->stopLookingAtTarget(); 58 59 this->maneuverType_ = ManeuverType::NONE; … … 63 64 CommonController::~CommonController() 64 65 { 66 orxout(internal_error) << "I died, my Rank is " << rank_ << endl; 65 67 } 66 68 … … 118 120 } 119 121 } 122 Action::Value CommonController::getAction () 123 { 124 return this->action_; 125 } 126 127 void CommonController::setAction (Action::Value action, ControllableEntity* target) 128 { 129 this->action_ = action; 130 if (action == Action::FIGHT) 131 { 132 if (target) 133 this->setTarget (target); 134 } 135 else if (action == Action::PROTECT) 136 { 137 } 138 } 139 void CommonController::setAction (Action::Value action, const Vector3& target) 140 { 141 this->action_ = action; 142 if (action == Action::FLY) 143 { 144 this->setTargetPosition (target); 145 } 146 else if (action == Action::PROTECT) 147 { 148 149 } 150 } 151 void CommonController::setAction (Action::Value action, const Vector3& target, const Quaternion& orient ) 152 { 153 this->action_ = action; 154 if (action == Action::FLY) 155 { 156 this->setTargetPosition (target); 157 this->setTargetOrientation (orient); 158 } 159 else if (action == Action::PROTECT) 160 { 161 162 } 163 } 120 164 void CommonController::maneuver() 121 165 { … … 145 189 146 190 //bool bThisIsLookingAtTarget = this->isLooking ( getControllableEntity(), this->target_, math::pi/4 ); 147 bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/ 8.0f );191 bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/5.0f ); 148 192 149 193 150 194 151 195 //too far? well, come closer then 152 if ( diffLength > 5000 )196 if ( diffLength > 3000 ) 153 197 { 154 198 if (diffLength < 6000) 155 199 { 156 this->bEngaging_ = true; 200 157 201 } 158 202 else 159 203 { 160 this->bEngaging_ = false;161 204 } 162 205 this->setTargetPosition( this->positionOfTarget_ ); 163 206 } 164 207 //too close? How do u expect to dodge anything? Just attack! 165 else if ( diffLength < 600 )208 else if ( diffLength < 500 ) 166 209 { 167 210 //at this point, just look and shoot 168 if ( diffLength < 300 )211 if ( diffLength < 250 ) 169 212 { 170 213 this->stopMoving(); … … 205 248 if ( this->getControllableEntity() && !this->target_ ) 206 249 { 207 this->bEngaging_ = false; 250 208 251 this->maneuverType_ = ManeuverType::NONE; 209 252 } 210 orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;253 //orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl; 211 254 } 212 255 ControllableEntity* CommonController::getTarget() … … 305 348 { 306 349 this->target_ = target; 307 orxout ( internal_error ) << " TARGET SET " << endl;350 //orxout ( internal_error ) << " TARGET SET " << endl; 308 351 309 352 if ( this->target_ ) … … 376 419 void CommonController::moveToPosition( const Vector3& target, float dt ) 377 420 { 378 float factor = 1; 379 if ( !this->getControllableEntity() ) 380 return; 381 if ( this->rank_ == Rank::DIVISIONLEADER ) 382 factor = 0.9; 383 if ( this->rank_ == Rank::SECTIONLEADER ) 384 factor = 0.95; 421 385 422 386 423 //100 is ( so far )the smallest tolerance ( empirically found )that can be reached, … … 421 458 } 422 459 423 this->getControllableEntity() ->moveFrontBack( SPEED *factor* dt );460 this->getControllableEntity() ->moveFrontBack( SPEED * dt ); 424 461 } 425 462 else … … 560 597 float squaredDistance = squaredDistanceToTarget(); 561 598 562 if ( squaredDistance < 25000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) {599 if ( squaredDistance < 9000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) { 563 600 return true; 564 601 } -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10803 r10805 65 65 }; 66 66 67 } 68 namespace Action 69 { 70 enum Value 71 { 72 FLY, FIGHT, PROTECT 73 }; 67 74 } 68 75 //none for a formation flight … … 121 128 /*void spin(); 122 129 void turn180();*/ 123 130 Action::Value getAction (); 131 void setAction (Action::Value action, ControllableEntity* target); 132 void setAction (Action::Value action, const Vector3& target); 133 void setAction (Action::Value action, const Vector3& target, const Quaternion& orient ); 124 134 125 135 protected: … … 158 168 Quaternion targetOrientation_; 159 169 170 Vector3 destination_; 171 bool bHasDestination; 172 173 160 174 void stopMoving(); 161 175 void setPositionOfTarget(const Vector3& target); … … 170 184 //WeakPtr<ControllableEntity> thisEntity_; 171 185 186 187 188 Action::Value action_; 172 189 bool bEngaging_; 173 190 bool bShooting_; -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10803 r10805 51 51 DivisionController::~DivisionController() 52 52 { 53 54 53 } 55 54 … … 77 76 void DivisionController::action() 78 77 { 79 this->maneuver(); 80 this->bShooting_ = this->canFire(); 81 78 if (!this->target_) 79 { 80 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 81 { 82 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam()) 83 continue; 84 85 86 if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity() && !(this)->hasTarget() 87 && ((*itP)->getWorldPosition() - (this)->getControllableEntity()->getWorldPosition()).length() < 10000) 88 { 89 (this)->setAction(Action::FIGHT, *itP); 90 } 91 } 92 } 93 94 if (this->action_ == Action::FIGHT) 95 { 96 this->maneuver(); 97 this->bShooting_ = this->canFire(); 98 if (this->target_) 99 { 100 if (this->myWingman_) 101 { 102 this->myWingman_->setAction (Action::FIGHT, this->target_); 103 } 104 105 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 106 if (diffVector.length() > 3000) 107 { 108 this->setTargetPositionOfWingman(); 109 //this->setTargetPositionOfFollower(); 110 } 111 } 112 } 113 else if (this->action_ == Action::FLY) 114 { 115 this->setTargetPositionOfWingman(); 116 this->setTargetPositionOfFollower(); 117 } 118 else if (this->action_ == Action::PROTECT) 119 { 120 121 } 82 122 83 123 } … … 116 156 (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); 117 157 118 myWingman_->setTargetOrientation(orient); 119 myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); 158 myWingman_->setAction( Action::FLY, targetAbsolutePositionOfWingman, orient); 120 159 121 160 } … … 153 192 (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower))); 154 193 155 myFollower_->setTargetOrientation(orient); 156 myFollower_->setTargetPosition(targetAbsolutePositionOfFollower); 157 194 myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient ); 158 195 } 159 196 -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10793 r10805 87 87 for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it) 88 88 { 89 if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget()) 89 if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget() 90 && ((*itP)->getWorldPosition() - (*it)->getControllableEntity()->getWorldPosition()).length() < 10000) 90 91 { 91 (*it)->set Target(*itP);92 (*it)->setAction(Action::FIGHT, *itP); 92 93 } 93 94 … … 95 96 96 97 } 97 98 /*for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it) 99 { 100 Vector3* target = new Vector3 (0, 0, 2000); 101 (*it)->setAction (Action::FLY, *target); 102 } 103 */ 98 104 } 99 105 void FleetController::tick(float dt) -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10789 r10805 55 55 void SectionController::tick(float dt) 56 56 { 57 if (!this->isActive())57 if (!this->isActive()) 58 58 return; 59 60 61 59 if (this->bHasTargetPosition_) 62 60 { 63 61 this->moveToTargetPosition(dt); 64 62 } 65 if (this->bShooting_) 66 doFire(); 63 else if (this->bLookAtTarget_) 64 { 65 this->lookAtTarget(dt); 66 } 67 if (bShooting_) 68 { 69 this->doFire(); 70 } 67 71 68 72 SUPER(SectionController, tick, dt); … … 80 84 else 81 85 { 82 83 } 84 85 } 86 setTargetPositionOfWingman(); 87 if (this->target_ && this->myWingman_) 88 this->myWingman_->setTarget(this->target_); 89 if (canFire()) 90 this->bShooting_ = true; 86 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 87 { 88 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam()) 89 continue; 90 91 if (!this->myDivisionLeader_) 92 { 93 this->setAction(Action::FIGHT, (*itP)); 94 break; 95 } 96 97 } 98 } 99 100 } 91 101 else 92 this->bShooting_ = false; 102 { 103 if (this->myDivisionLeader_->getAction() == Action::FIGHT) 104 { 105 if (this->myDivisionLeader_->hasTarget()) 106 { 107 if (this->myDivisionLeader_->hasWingman() && (!this->hasTarget() || this->getTarget() == this->myDivisionLeader_->getTarget())) 108 { 109 bool foundTarget = false; 110 Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition(); 111 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 112 { 113 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam()) 114 continue; 115 116 if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 && 117 ((*itP)->getWorldPosition() - divisionTargetPosition).length() > 1000 && 118 (*itP) != this->myDivisionLeader_->getTarget()) 119 { 120 foundTarget = true; 121 this->setAction(Action::FIGHT, (*itP)); 122 orxout(internal_error) << "Found target" << endl; 123 break; 124 } 125 } 126 if (!foundTarget) 127 { 128 this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget()); 129 } 130 131 } 132 } 133 } 134 } 135 136 if (this->action_ == Action::FIGHT) 137 { 138 this->maneuver(); 139 this->bShooting_ = this->canFire(); 140 if (this->target_) 141 { 142 if (this->myWingman_) 143 { 144 this->myWingman_->setAction (Action::FIGHT, this->target_); 145 } 146 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 147 if (diffVector.length() > 3000) 148 { 149 this->setTargetPositionOfWingman(); 150 } 151 } 152 } 153 else if (this->action_ == Action::FLY) 154 { 155 this->setTargetPositionOfWingman(); 156 } 157 else if (this->action_ == Action::PROTECT) 158 { 159 160 } 93 161 94 162 … … 126 194 (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman))); 127 195 128 myWingman_->setTargetOrientation(orient); 129 myWingman_->setTargetPosition(targetAbsolutePositionOfWingman); 196 myWingman_->setAction (Action::FLY, targetAbsolutePositionOfWingman, orient); 130 197 131 198 } -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10789 r10805 111 111 void WingmanController::tick(float dt) 112 112 { 113 114 115 113 if (!this->isActive()) 116 114 return; 117 if (!this->target_)118 {119 //stay in formation120 }121 else122 {123 124 }125 115 if (this->bHasTargetPosition_) 126 116 { 127 117 this->moveToTargetPosition(dt); 128 } 129 130 if (this->bShooting_) 131 doFire(); 118 } 119 else if (this->bLookAtTarget_) 120 { 121 this->lookAtTarget(dt); 122 } 123 if (bShooting_) 124 { 125 this->doFire(); 126 } 132 127 133 128 SUPER(WingmanController, tick, dt); … … 144 139 else 145 140 { 146 //orxout(internal_error) << "0 leader" << endl; 147 141 if (!this->target_){ 142 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 143 { 144 if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam()) 145 continue; 146 this->setAction(Action::FIGHT, (*itP)); 147 break; 148 } 149 } 148 150 } 149 151 … … 153 155 154 156 } 155 if (canFire()) 156 this->bShooting_ = true; 157 else 158 this->bShooting_ = false; 157 158 if (this->action_ == Action::FIGHT) 159 { 160 this->maneuver(); 161 this->bShooting_ = this->canFire(); 162 if (this->target_) 163 { 164 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 165 if (diffVector.length() > 5000) 166 { 167 168 } 169 } 170 } 171 else if (this->action_ == Action::FLY) 172 { 173 174 } 175 else if (this->action_ == Action::PROTECT) 176 { 177 178 } 159 179 160 180 }
Note: See TracChangeset
for help on using the changeset viewer.