- Timestamp:
- Nov 23, 2015, 11:17:22 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10826 r10832 51 51 CommonController::CommonController( Context* context ): Controller( context ) 52 52 { 53 this->bSetupWorked = false;54 53 55 54 56 this->executingMoveToPoint_ = false;57 55 this->action_ = Action::FLY; 58 56 this->stopLookingAtTarget(); … … 71 69 SUPER( CommonController, XMLPort, xmlelement, mode ); 72 70 XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML, xmlelement, mode ); 73 71 XMLPortParam( CommonController, "action", setActionXML, getActionXML, xmlelement, mode ); 72 73 } 74 void CommonController::setActionXML( std::string val) 75 { 76 const std::string valUpper = getUppercase( val ); 77 Action::Value value; 78 79 if ( valUpper == "FIGHT" ) 80 value = Action::FIGHT; 81 else if ( valUpper == "FLY" ) 82 value = Action::FLY; 83 else if ( valUpper == "PROTECT" ) 84 value = Action::PROTECT; 85 else 86 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." ); 87 this->setAction( value ); 88 } 89 std::string CommonController::getActionXML() 90 { 91 switch ( this->action_ ) 92 { 93 case Action::FIGHT: 94 { 95 return "FIGHT"; 96 break; 97 } 98 case Action::FLY: 99 { 100 return "FLY"; 101 break; 102 } 103 case Action::PROTECT: 104 { 105 return "PROTECT"; 106 break; 107 } 108 default: 109 return "FIGHT"; 110 break; 111 } 74 112 } 75 113 void CommonController::setFormationModeXML( std::string val ) … … 118 156 return this->action_; 119 157 } 158 void CommonController::setAction (Action::Value action) 159 { 160 this->action_ = action; 161 } 120 162 121 163 void CommonController::setAction (Action::Value action, ControllableEntity* target) … … 156 198 } 157 199 } 200 void CommonController::setClosestTarget() 201 { 202 if (!this->getControllableEntity()) 203 return; 204 205 Pawn* closestTarget = 0; 206 float minDistance = std::numeric_limits<float>::infinity(); 207 208 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 209 { 210 if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) ) 211 continue; 212 213 float distance = CommonController::distance (*itP, this->getControllableEntity()); 214 if (distance < minDistance) 215 { 216 closestTarget = *itP; 217 minDistance = distance; 218 } 219 } 220 if (closestTarget) 221 { 222 (this)->setTarget(static_cast<ControllableEntity*>(closestTarget)); 223 } 224 } 158 225 void CommonController::maneuver() 159 226 { 160 counter++;161 162 if ( counter> 5)163 counter= 0;227 maneuverCounter_++; 228 229 if (maneuverCounter_ > 5) 230 maneuverCounter_ = 0; 164 231 if ( this->target_ && this->getControllableEntity()) 165 232 { … … 183 250 184 251 //bool bThisIsLookingAtTarget = this->isLooking ( getControllableEntity(), this->target_, math::pi/4 ); 185 bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/ 5.0f );252 bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/10.0f ); 186 253 187 254 … … 217 284 { 218 285 this->setTargetPosition( this->positionOfTarget_ ); 219 /* if ( counter== 0)286 /* if (maneuverCounter_ == 0) 220 287 { 221 288 this->setTargetPosition( this->positionOfTarget_ ); … … 231 298 { 232 299 233 if ( counter== 0)300 if (maneuverCounter_ == 0) 234 301 { 235 302 this->setTargetPosition( this->positionOfTarget_ ); … … 562 629 this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT, this->positionOfTarget_ ) < angle ); 563 630 } 564 bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) const631 bool CommonController::isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) 565 632 { 566 633 if ( !entityThatLooks || !entityBeingLookedAt ) … … 587 654 float squaredDistance = squaredDistanceToTarget(); 588 655 589 if ( squaredDistance < 9000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) {656 if ( squaredDistance < 9000000.0f && this->isLookingAtTarget( math::pi / 20.0f)) { 590 657 return true; 591 658 } … … 615 682 } 616 683 617 618 619 684 Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() ); 620 685
Note: See TracChangeset
for help on using the changeset viewer.