- Timestamp:
- Nov 24, 2015, 1:47:43 PM (8 years ago)
- File:
-
- 1 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 {
Note: See TracChangeset
for help on using the changeset viewer.