Changeset 10848 for code/branches/campaignHS15/src
- Timestamp:
- Nov 24, 2015, 1:47:43 PM (9 years ago)
- Location:
- code/branches/campaignHS15/src/orxonox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10847 r10848 122 122 return CommonController::getName (this->getProtect()); 123 123 } 124 std::string CommonController::getName( ControllableEntity* entity)124 std::string CommonController::getName(Pawn* entity) 125 125 { 126 126 std::string name = entity->getName(); … … 291 291 Vector3 position; 292 292 std::string targetName; 293 this->actionpoints_.push_back(actionpoint); 293 294 294 if (static_cast<Actionpoint*> (actionpoint)) 295 295 { 296 296 Actionpoint* ap = static_cast<Actionpoint*> (actionpoint); 297 297 298 actionName = ap->getActionXML(); 298 targetName = ap->get 299 targetName = ap->getName(); 300 position = ap->getWorldPosition(); 301 299 302 Action::Value value; 300 303 301 if ( valUpper== "FIGHT" )304 if ( actionName == "FIGHT" ) 302 305 { 303 306 value = Action::FIGHT; 304 307 305 308 } 306 else if ( valUpper== "FLY" )309 else if ( actionName == "FLY" ) 307 310 { 308 311 value = Action::FLY; 309 312 310 313 } 311 else if ( valUpper== "PROTECT" )314 else if ( actionName == "PROTECT" ) 312 315 { 313 316 value = Action::PROTECT; 314 317 315 318 } 316 else if ( valUpper== "NONE" )319 else if ( actionName == "NONE" ) 317 320 { 318 321 value = Action::NONE; 319 322 320 323 } 321 else if ( valUpper== "FIGHTALL" )324 else if ( actionName == "FIGHTALL" ) 322 325 { 323 326 value = Action::FIGHTALL; 324 327 325 328 } 326 else if ( valUpper== "ATTACK" )329 else if ( actionName == "ATTACK" ) 327 330 { 328 331 value = Action::ATTACK; 332 329 333 330 334 } 331 335 else 332 336 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." ); 333 this->setAction( value ); 334 } 335 else 336 { 337 actionName = "FLY"; 338 } 337 //this->setAction( value ); 338 parsedActionpoints_.push_back( std::make_tuple (value, targetName, position) ); 339 } 340 else 341 { 342 parsedActionpoints_.push_back( 343 std::make_tuple (Action::FLY, "", actionpoint->getWorldPosition()) ); 344 } 345 this->actionpoints_.push_back(actionpoint); 346 339 347 340 348 } … … 377 385 return 0; 378 386 } 387 //POST: this starts doing what was asked by the last element of parsedActionpoints_, 388 //if last element was failed to be parsed, next element will be executed. 389 void CommonController::executeActionpoint() 390 { 391 if (!this->parsedActionpoints_.empty()) 392 { 393 this->action_ = std::get<0>( this->parsedActionpoints_.back() ); 394 395 switch ( this->action_ ) 396 { 397 case Action::FIGHT: 398 { 399 break; 400 } 401 case Action::FLY: 402 { 403 this->setTargetPosition(std::get<2>( this->parsedActionpoints_.back() )); 404 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 405 { 406 this->nextActionpoint(); 407 this->executeActionpoint(); 408 } 409 break; 410 } 411 case Action::PROTECT: 412 { 413 std::string protectName = std::get<1>( this->parsedActionpoints_.back() ); 414 415 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 416 { 417 if (CommonController::getName(*itP) == protectName) 418 { 419 this->setProtect (static_cast<ControllableEntity*>(*itP)); 420 } 421 } 422 if (!this->getProtect()) 423 { 424 this->nextActionpoint(); 425 this->executeActionpoint(); 426 } 427 break; 428 } 429 case Action::NONE: 430 { 431 break; 432 } 433 case Action::FIGHTALL: 434 { 435 break; 436 } 437 case Action::ATTACK: 438 { 439 std::string targetName = std::get<1>( this->parsedActionpoints_.back() ); 440 441 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 442 { 443 if (CommonController::getName(*itP) == targetName) 444 { 445 this->setTarget (static_cast<ControllableEntity*>(*itP)); 446 } 447 } 448 if (!this->getTarget()) 449 { 450 this->nextActionpoint(); 451 this->executeActionpoint(); 452 } 453 break; 454 } 455 default: 456 break; 457 } 458 459 460 } 461 else 462 { 463 this->setTarget(0); 464 this->setTargetPosition(this->getControllableEntity()->getWorldPosition()); 465 this->action_ = Action::NONE; 466 } 467 } 468 void CommonController::nextActionpoint() 469 { 470 if (!this->parsedActionpoints_.empty()) 471 { 472 this->parsedActionpoints_.pop_back(); 473 } 474 this->setAction(Action::NONE); 475 } 476 379 477 void CommonController::maneuver() 380 478 { -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10847 r10848 138 138 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt); 139 139 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ; 140 static std::string getName( ControllableEntity* entity ) ;140 static std::string getName( Pawn* entity ) ; 141 141 142 142 float squaredDistanceToTarget() const; … … 207 207 Rank::Value rank_; 208 208 std::string protectName_; 209 std::string targetName_; 209 210 Action::Value action_; 210 211 int attackRange_; -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10847 r10848 97 97 { 98 98 ControllableEntity* newTarget = this->closestTarget(); 99 if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 100 { 101 this->backupAction(); 102 this->setAction (Action::FIGHT, newTarget); 103 } 104 } 105 } 99 if ( newTarget && 100 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_ ) 101 { 102 // this->backupAction(); 103 // this->setAction (Action::FIGHT, newTarget); 104 this->parsedActionpoints_.push_back( 105 std::make_tuple (Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO) ); 106 } 107 } 108 } 109 106 110 //action is NONE whenever ships finishes current action, 107 111 //if it was fighting before because enemies were close, resume what it was doing … … 109 113 if (this->action_ == Action::NONE) 110 114 { 111 if (this->bBackuped_) 112 { 113 this->restoreAction(); 114 } else if (!this->actionpoints_.empty()) 115 { 116 this->popAction(); 117 } 118 } 115 116 } 117 118 this->executeActionpoint(); 119 120 //this->action_ is what I am actually executing, this->target_ is what I am 121 //actually attacking, etc. 122 123 //after action is finished, .pop_back() is to be called. 119 124 if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL) 120 125 { … … 122 127 { 123 128 //----find a target---- 129 ControllableEntity* newTarget = this->closestTarget(); 124 130 if (this->action_ == Action::FIGHT) 125 131 { 126 ControllableEntity* newTarget = this->closestTarget();127 132 if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_) 128 133 { … … 131 136 else 132 137 { 133 this->setAction (Action::NONE); 138 this->nextActionpoint(); 139 return; 134 140 } 135 141 } 136 142 else if (this->action_ == Action::FIGHTALL) 137 143 { 138 this->setClosestTarget(); 144 if (newTarget) 145 { 146 this->setAction (Action::FIGHTALL, newTarget); 147 } 148 else 149 { 150 this->nextActionpoint(); 151 return; 152 } 139 153 } 140 154 … … 146 160 if (diffVector.length() > this->attackRange_) 147 161 { 148 this->setTargetPositionOfWingman(); 149 this->setTargetPositionOfFollower(); 162 if (this->action_ == Action::FIGHT) 163 { 164 this->nextActionpoint(); 165 return; 166 } 167 else 168 { 169 this->setTargetPositionOfWingman(); 170 this->setTargetPositionOfFollower(); 171 } 172 150 173 } 151 174 else … … 154 177 if (this->myWingman_) 155 178 { 156 this->myWingman_->setAction ( Action::FIGHT, this->target_);179 this->myWingman_->setAction (this->action_, this->target_); 157 180 } 158 181 if (this->myFollower_) 159 182 { 160 this->myFollower_->setAction ( Action::FIGHT);183 this->myFollower_->setAction (this->action_); 161 184 } 162 185 … … 180 203 else if (this->action_ == Action::PROTECT) 181 204 { 182 if (!this->getProtect()) 183 { 184 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) 185 { 186 if ((*itP)->getName() == this->protectName_) 187 { 188 this->setProtect (static_cast<ControllableEntity*>(*itP)); 189 } 190 } 191 if (!this->getProtect()) 192 { 193 this->setAction (Action::NONE); 194 } 195 } 196 else 197 { 198 /* if (this->myWingman_) 199 this->myWingman_->setAction (Action::PROTECT, this->getProtect()); 200 if (this->myFollower_) 201 this->myFollower_->setAction (Action::PROTECT, this->getProtect()); 202 */ 203 Vector3* targetRelativePosition; 204 205 targetRelativePosition = new Vector3 (0, 0, 500); 206 207 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 208 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition))); 209 this->setTargetPosition(targetAbsolutePosition); 205 /* if (this->myWingman_) 206 this->myWingman_->setAction (Action::PROTECT, this->getProtect()); 207 if (this->myFollower_) 208 this->myFollower_->setAction (Action::PROTECT, this->getProtect()); 209 */ 210 Vector3* targetRelativePosition; 210 211 211 this->setTargetPositionOfWingman(); 212 this->setTargetPositionOfFollower(); 213 } 214 212 targetRelativePosition = new Vector3 (0, 0, 500); 213 214 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 215 (this->getProtect()->getWorldOrientation()* (*targetRelativePosition))); 216 this->setTargetPosition(targetAbsolutePosition); 217 218 this->setTargetPositionOfWingman(); 219 this->setTargetPositionOfFollower(); 220 } 221 else if (this->action_ == Action::ATTACK) 222 { 223 if (this->hasTarget()) 224 { 225 //----fly in formation if far enough---- 226 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 227 if (diffVector.length() > this->attackRange_) 228 { 229 this->setTargetPositionOfWingman(); 230 this->setTargetPositionOfFollower(); 231 } 232 else 233 { 234 //----wingmans shall support the fire of their leaders---- 235 if (this->myWingman_) 236 { 237 this->myWingman_->setAction (this->action_, this->target_); 238 } 239 if (this->myFollower_) 240 { 241 this->myFollower_->setAction (this->action_); 242 } 243 244 } 245 246 } 247 if (this->hasTarget()) 248 { 249 //----choose where to go---- 250 this->maneuver(); 251 //----fire if you can---- 252 this->bShooting_ = this->canFire(); 253 } 215 254 } 216 255 -
code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
r10847 r10848 91 91 void setEnemy( ControllableEntity* enemy); 92 92 ControllableEntity* getEnemy(); 93 std::string getName() 94 { 95 if (actionName_ != "") 96 return actionName_; 97 else if (protectName_ != "") 98 return protectName_; 99 else if (enemyName_ != "") 100 return enemyName_; 101 else 102 return ""; 103 } 93 104 //----["Waypoints" data]---- 94 105 void setTargetPosition(const Vector3& target);
Note: See TracChangeset
for help on using the changeset viewer.