Changeset 10849 for code/branches/campaignHS15
- Timestamp:
- Nov 24, 2015, 5:21:03 PM (9 years ago)
- Location:
- code/branches/campaignHS15
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/data/levels/AITest.oxw
r10847 r10849 32 32 33 33 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> 34 <TeamSpawnPoint team= 1position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />34 <TeamSpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff /> 35 35 36 36 <!-- … … 53 53 <!-- <ActionPoint position="12,34,56" action="FIGHT" enemy="ss" /> 54 54 --> 55 <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1">55 <!-- <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1"> 56 56 <templates> 57 57 <Template link=spaceshipassff /> … … 61 61 </DivisionController> 62 62 </controller> 63 </SpaceShip> 64 <SpaceShip position=" 0, 1500, -1000" lookat="0,0,0" team=0name="ss2">63 </SpaceShip> --> 64 <SpaceShip position="-2000, 1500, -1000" lookat="0,0,0" team=1 name="ss2"> 65 65 <templates> 66 66 <Template link=spaceshipassff /> 67 67 </templates> 68 68 <controller> 69 <DivisionController team=1 2>69 <DivisionController team=1> 70 70 <actionpoints> 71 <Actionpoint position="12,34,56" action="PROTECT" protectMe=true /> 72 <Actionpoint position="12,34,56" action="FLY" /> 71 <Actionpoint position="-1000,750,-500" action="PROTECt" protect="fuck" /> 72 <Actionpoint position="-1000,750,-500" action="ATTACK" enemy="ss3" /> 73 <Actionpoint position="-1000,750,-500" action="FLY" /> 74 <Actionpoint position="0,0,0" action="FLY" /> 73 75 </actionpoints> 74 76 </DivisionController> 75 77 </controller> 76 78 </SpaceShip> 77 79 <SpaceShip position="0, 0, 0" lookat="0,0,0" team=2 name="ss4"> 80 <templates> 81 <Template link=spaceshipassff /> 82 </templates> 83 </SpaceShip> 84 <SpaceShip position="1000, 300, 200" lookat="0,0,0" team=2 name="ss3"> 85 <templates> 86 <Template link=spaceshipassff /> 87 </templates> 88 </SpaceShip> 89 <SpaceShip position="-500, -300, -300" lookat="0,0,0" team=1 name="fuck"> 90 <templates> 91 <Template link=spaceshipassff /> 92 </templates> 93 </SpaceShip> 78 94 <!-- <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0" team=0> 79 95 <templates> -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
r10848 r10849 58 58 CommonController::CommonController( Context* context ): Controller( context ) 59 59 { 60 this->action_ = Action::FLY; 60 this->squaredaccuracy_ = 500; 61 this->action_ = Action::NONE; 61 62 this->stopLookingAtTarget(); 62 this->attackRange_ = 2500;63 this->attackRange_ = 800; 63 64 RegisterObject( CommonController ); 64 65 } … … 69 70 //orxout(internal_error) << "I died, my Rank is " << rank_ << endl; 70 71 } 71 void CommonController::backupAction() 72 { 73 this->actionpoints_.push_back (this->currentActionpoint_); 74 } 75 void CommonController::restoreAction() 76 { 77 this->currentActionpoint_ = this->actionpoints_.back(); 78 this->actionpoints_.pop_back(); 79 } 80 void CommonController::popAction() 81 { 82 this->currentActionpoint_ = actionpoints_.back(); 83 actionpoints_.pop_back(); 84 } 85 72 73 86 74 void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode ) 87 75 { … … 120 108 if (!this->getProtect()) 121 109 return "noProtectWasSet"; 122 return CommonController::getName ( this->getProtect());110 return CommonController::getName (orxonox_cast<Pawn*>(this->getProtect())); 123 111 } 124 112 std::string CommonController::getName(Pawn* entity) … … 256 244 { 257 245 this->action_ = action; 258 if (action == Action::FIGHT )246 if (action == Action::FIGHT || action == Action::FIGHTALL || action == Action::ATTACK) 259 247 { 260 248 if (target) … … 334 322 } 335 323 else 336 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val+ "'." );324 ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." ); 337 325 //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()) ); 326 Point p = { value, targetName, position }; 327 parsedActionpoints_.push_back(p); 328 orxout(internal_error) << "Pushed " << p.action << endl; 329 } 330 else 331 { 332 Point p = { Action::FLY, "", actionpoint->getWorldPosition() }; 333 parsedActionpoints_.push_back(p); 344 334 } 345 335 this->actionpoints_.push_back(actionpoint); … … 357 347 void CommonController::setClosestTarget() 358 348 { 359 this->setTarget ( closestTarget());360 } 361 ControllableEntity* CommonController::closestTarget()349 this->setTarget (static_cast<ControllableEntity*>( closestTarget() ) ); 350 } 351 Pawn* CommonController::closestTarget() 362 352 { 363 353 if (!this->getControllableEntity()) … … 381 371 if (closestTarget) 382 372 { 383 return static_cast<ControllableEntity*>(closestTarget);373 return closestTarget; 384 374 } 385 375 return 0; … … 391 381 if (!this->parsedActionpoints_.empty()) 392 382 { 393 this->action_ = std::get<0>( this->parsedActionpoints_.back() );383 this->action_ = this->parsedActionpoints_.back().action; 394 384 395 385 switch ( this->action_ ) … … 401 391 case Action::FLY: 402 392 { 403 this->setTargetPosition( std::get<2>( this->parsedActionpoints_.back() ));393 this->setTargetPosition( this->parsedActionpoints_.back().position ); 404 394 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 405 395 { … … 411 401 case Action::PROTECT: 412 402 { 413 std::string protectName = std::get<1>( this->parsedActionpoints_.back() );403 std::string protectName = this->parsedActionpoints_.back().name; 414 404 415 405 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) … … 437 427 case Action::ATTACK: 438 428 { 439 std::string targetName = std::get<1>( this->parsedActionpoints_.back() );429 std::string targetName = this->parsedActionpoints_.back().name; 440 430 441 431 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP) … … 443 433 if (CommonController::getName(*itP) == targetName) 444 434 { 435 orxout(internal_error) << "Attacking" << endl; 445 436 this->setTarget (static_cast<ControllableEntity*>(*itP)); 446 437 } … … 465 456 this->action_ = Action::NONE; 466 457 } 458 orxout(internal_error) << "Executing action " << this->getActionXML() << endl; 467 459 } 468 460 void CommonController::nextActionpoint() -
code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
r10848 r10849 65 65 NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK 66 66 }; 67 67 68 } 69 70 struct Point { 71 Action::Value action; 72 std::string name; 73 Vector3 position; 74 } ; 75 76 77 68 78 69 79 … … 171 181 void doFire(); 172 182 void setClosestTarget(); 173 ControllableEntity* closestTarget();183 Pawn* closestTarget(); 174 184 175 185 bool bShooting_; … … 200 210 std::vector<WeakPtr<WorldEntity> > actionpoints_; 201 211 float squaredaccuracy_; 202 <tuple<Action::Value ,std::string ,Vector3 > > currentActionpoint_; 203 std::vector<tuple<Action::Value ,std::string ,Vector3 > > parsedActionpoints_; 212 Point currentActionpoint_; 213 std::vector<Point > parsedActionpoints_; 214 void executeActionpoint(); 215 void nextActionpoint(); 204 216 //----[/Actionpoint information]---- 205 217 //----["Private" variables]---- -
code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
r10848 r10849 28 28 29 29 #include "DivisionController.h" 30 30 #include "infos/PlayerInfo.h" 31 31 32 32 namespace orxonox … … 93 93 if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL) 94 94 { 95 if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) ||96 !this->target_)97 { 98 ControllableEntity* newTarget = this->closestTarget();95 if ( (this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) 96 || !this->target_ ) 97 { 98 Pawn* newTarget = this->closestTarget(); 99 99 if ( newTarget && 100 CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_ ) 100 CommonController::distance (this->getControllableEntity(), static_cast<ControllableEntity*>(newTarget)) 101 <= this->attackRange_ ) 101 102 { 102 103 // this->backupAction(); 103 104 // this->setAction (Action::FIGHT, newTarget); 104 this->parsedActionpoints_.push_back( 105 std::make_tuple (Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO) ); 105 Point p = { Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO }; 106 this->parsedActionpoints_.push_back(p); 107 this->executeActionpoint(); 106 108 } 107 109 } … … 113 115 if (this->action_ == Action::NONE) 114 116 { 115 116 } 117 118 this->executeActionpoint(); 117 this->executeActionpoint(); 118 } 119 119 120 120 121 //this->action_ is what I am actually executing, this->target_ is what I am … … 142 143 else if (this->action_ == Action::FIGHTALL) 143 144 { 144 if (newTarget )145 if (newTarget && newTarget->getController()) 145 146 { 146 147 this->setAction (Action::FIGHTALL, newTarget); … … 158 159 //----fly in formation if far enough---- 159 160 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 161 162 160 163 if (diffVector.length() > this->attackRange_) 161 164 { … … 198 201 else if (this->action_ == Action::FLY) 199 202 { 203 204 if (this->squaredDistanceToTarget() <= this->squaredaccuracy_) 205 { 206 orxout(internal_error) << "arrived"; 207 this->nextActionpoint(); 208 return; 209 } 200 210 this->setTargetPositionOfWingman(); 201 211 this->setTargetPositionOfFollower(); … … 203 213 else if (this->action_ == Action::PROTECT) 204 214 { 215 if (!this->getProtect()) 216 { 217 this->nextActionpoint(); 218 return; 219 } 205 220 /* if (this->myWingman_) 206 221 this->myWingman_->setAction (Action::PROTECT, this->getProtect()); … … 218 233 this->setTargetPositionOfWingman(); 219 234 this->setTargetPositionOfFollower(); 235 220 236 } 221 237 else if (this->action_ == Action::ATTACK) 222 238 { 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 } 239 if (!this->hasTarget()) 240 { 241 this->nextActionpoint(); 242 return; 243 } 244 //----fly in formation if far enough---- 245 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 246 if (diffVector.length() > this->attackRange_) 247 { 248 this->setTargetPositionOfWingman(); 249 this->setTargetPositionOfFollower(); 250 } 251 else 252 { 253 //----wingmans shall support the fire of their leaders---- 254 if (this->myWingman_) 255 { 256 this->myWingman_->setAction (this->action_, this->target_); 257 } 258 if (this->myFollower_) 259 { 260 this->myFollower_->setAction (this->action_); 261 } 262 263 } 264 265 //----choose where to go---- 266 this->maneuver(); 267 //----fire if you can---- 268 this->bShooting_ = this->canFire(); 254 269 } 255 270
Note: See TracChangeset
for help on using the changeset viewer.