Changeset 10780 for code/branches/AI_HS15
- Timestamp:
- Nov 8, 2015, 6:19:12 PM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10764 r10780 36 36 #include "worldentities/pawns/SpaceShip.h" 37 37 38 38 #include "Scene.h" 39 #include <OgreRay.h> 40 #include <OgreSceneQuery.h> 41 #include <OgreCamera.h> 42 #include <OgreSceneManager.h> 39 43 namespace orxonox 40 44 { … … 47 51 { 48 52 this->bSetupWorked = false; 53 54 this->targetMask_.exclude(ClassByString("BaseObject")); 55 this->targetMask_.include(ClassByString("WorldEntity")); 56 this->targetMask_.exclude(ClassByString("Projectile")); 49 57 50 58 RegisterObject(CommonController); … … 234 242 } 235 243 } 236 orxout (internal_error) << "MOVING" <<endl ;237 244 238 245 this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor); … … 255 262 return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance); 256 263 } 257 264 bool CommonController::isLookingAtTarget(float angle) const 265 { 266 if (!this->getControllableEntity()) 267 return false; 268 269 return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle); 270 } 258 271 259 272 bool CommonController::canFire() 260 273 { 261 262 float tolerance = 50.0f; 263 264 //check pointers 265 if (!this->getControllableEntity() || !this->target_ || !this->target_->getControllableEntity()) 274 if ( this->bShooting_ && this->isCloseAtTarget(3000) && this->isLookingAtTarget(math::pi / 20.0f) ) 275 { 276 return true; 277 } 278 else 279 { 266 280 return false; 267 268 //check if this points in the direction of target_ 269 270 Vector3 myPosition = this->getControllableEntity()->getWorldPosition(); 271 Vector3 targetPosition = this->target_->getControllableEntity()->getWorldPosition(); 272 273 Vector3 differenceVector = targetPosition - myPosition; 274 float differenceLength = differenceVector.length(); 275 276 Vector3 myDirection = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT; 277 278 float angle = getAngle (myPosition, myDirection, targetPosition); 279 float heightLength = sin(angle) * differenceLength; 280 281 if (heightLength > tolerance) 282 return false; 283 284 285 286 //check if there are allies on the way 287 Vector3 allyPosition, allyDifference; 288 float allyDifferenceLength, allyAngle, allyHeightLength; 289 290 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 291 { 292 if (!it->getControllableEntity()) 293 continue; 294 if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam())) 295 { 296 allyPosition = it->getControllableEntity()->getWorldPosition(); 297 298 allyDifference = allyPosition - myPosition; 299 allyDifferenceLength = allyDifference.length(); 300 301 allyAngle = getAngle (myPosition, myDirection, allyPosition); 302 303 allyHeightLength = sin(allyAngle) * allyDifferenceLength; 304 305 if (allyAngle > math::pi /2) 306 continue; 307 if (allyHeightLength <= tolerance) 308 return false; 309 } 310 } 281 } 282 283 } 284 void CommonController::doFire() 285 { 286 if (!this->target_ || !this->getControllableEntity()) 287 return; 288 static const float hardcoded_projectile_speed = 750; 289 290 this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity()); 291 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 311 292 312 293 Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); 313 294 if (pawn) 314 pawn->setAimPosition( WorldEntity::FRONT);295 pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT)); 315 296 316 return true;317 318 }319 void CommonController::doFire()320 {321 297 this->getControllableEntity()->fire(0); 322 298 } -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10763 r10780 34 34 #include "worldentities/ControllableEntity.h" 35 35 #include "worldentities/pawns/Pawn.h" 36 #include "core/ClassTreeMask.h" 36 37 37 38 … … 164 165 ManeuverType::Value maneuverType_; 165 166 Maneuver::Value maneuver_; 167 168 ClassTreeMask targetMask_; 169 166 170 167 171 private: -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10763 r10780 68 68 this->moveToTargetPosition(); 69 69 } 70 70 if (this->bShooting_) 71 doFire(); 71 72 SUPER(DivisionController, tick, dt); 72 73 … … 97 98 } 98 99 */ 99 100 100 if (canFire()) 101 doFire(); 102 101 this->bShooting_ = true; 102 else 103 this->bShooting_ = false; 103 104 } 104 105 -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10762 r10780 63 63 this->moveToTargetPosition(); 64 64 } 65 65 if (this->bShooting_) 66 doFire(); 66 67 67 68 SUPER(SectionController, tick, dt); … … 86 87 if (this->target_ && this->myWingman_) 87 88 this->myWingman_->setTarget(this->target_); 88 89 89 if (canFire()) 90 doFire(); 90 this->bShooting_ = true; 91 else 92 this->bShooting_ = false; 91 93 92 94 -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10762 r10780 128 128 } 129 129 130 130 if (this->bShooting_) 131 doFire(); 131 132 132 133 SUPER(WingmanController, tick, dt); … … 152 153 153 154 } 154 155 155 if (canFire()) 156 doFire(); 156 this->bShooting_ = true; 157 else 158 this->bShooting_ = false; 159 157 160 } 158 161 -
code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc
r10731 r10780 299 299 } 300 300 301 302 301 void Pawn::kill() 303 302 { … … 320 319 } 321 320 322 323 321 void Pawn::death() 324 322 { … … 326 324 if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_)) 327 325 { 328 // Set bAlive_ to false and wait for PawnManagerto do the destruction326 // Set bAlive_ to false and wait for destroyLater() to do the destruction 329 327 this->bAlive_ = false; 328 this->destroyLater(); 330 329 331 330 this->setDestroyWhenPlayerLeft(false); … … 367 366 if (GameMode::isMaster()) 368 367 { 369 // this->deathEffect();368 this->deatheffect(); 370 369 this->goWithStyle(); 371 370 } … … 387 386 { 388 387 // play death effect 389 {388 /*{ 390 389 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 391 390 effect->setPosition(this->getPosition()); … … 410 409 effect->setSource("Orxonox/sparks"); 411 410 effect->setLifetime(4.0f); 412 } 411 }*/ 412 413 414 { 415 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 416 effect->setPosition(this->getPosition()); 417 effect->setOrientation(this->getOrientation()); 418 effect->setDestroyAfterLife(true); 419 effect->setSource("orxonox/explosion_flash2"); 420 effect->setLifetime(5.0f); 421 } 422 { 423 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 424 effect->setPosition(this->getPosition()); 425 effect->setOrientation(this->getOrientation()); 426 effect->setDestroyAfterLife(true); 427 effect->setSource("orxonox/explosion_flame2"); 428 effect->setLifetime(5.0f); 429 } 430 { 431 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 432 effect->setPosition(this->getPosition()); 433 effect->setOrientation(this->getOrientation()); 434 effect->setDestroyAfterLife(true); 435 effect->setSource("orxonox/explosion_shockwave2"); 436 effect->scale(20); 437 effect->setLifetime(5.0f); 438 }{ 439 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 440 effect->setPosition(this->getPosition()); 441 effect->setOrientation(this->getOrientation()); 442 effect->setDestroyAfterLife(true); 443 effect->setSource("orxonox/explosion_sparks2"); 444 effect->setLifetime(5.0f); 445 } 446 { 447 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 448 effect->setPosition(this->getPosition()); 449 effect->setOrientation(this->getOrientation()); 450 effect->setDestroyAfterLife(true); 451 effect->setSource("orxonox/explosion_streak2"); 452 effect->setLifetime(5.0f); 453 } 454 { 455 ParticleSpawner* effect = new ParticleSpawner(this->getContext()); 456 effect->setPosition(this->getPosition()); 457 effect->setOrientation(this->getOrientation()); 458 effect->setDestroyAfterLife(true); 459 effect->setSource("orxonox/explosion_afterglow"); 460 effect->scale(20); 461 effect->setLifetime(5.0f); 462 } 463 464 413 465 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) 414 466 { … … 418 470 } 419 471 472 /** 473 @brief 474 Check whether the Pawn has a @ref Orxonox::WeaponSystem and fire it with the specified firemode if it has one. 475 */ 420 476 void Pawn::fired(unsigned int firemode) 421 477 { -
code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h
r10731 r10780 39 39 40 40 namespace orxonox // tolua_export 41 { // tolua_export 41 { 42 /** 43 @brief 44 Everything in Orxonoy that has a health attribute is a Pawn. After a Pawn is spawned its health is set to 45 its initial health. In every call of the Pawns tick function the game checks whether the pawns health is at 46 or below zero. If it is, the pawn gets killed. 47 48 Pawns can carry pickups and fire weapons. The can also have shields. 49 50 Notice that every Pawn is a ControllableEntity. 51 */ 52 53 // tolua_export 42 54 class _OrxonoxExport Pawn // tolua_export 43 55 : public ControllableEntity, public RadarViewable, public PickupCarrier
Note: See TracChangeset
for help on using the changeset viewer.