- Timestamp:
- Aug 22, 2011, 3:05:26 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/weapons/projectiles/BasicProjectile.cc
r8767 r8855 27 27 */ 28 28 29 /** 30 @file BasicProjectile.h 31 @brief Implementation of the BasicProjectile class. 32 */ 33 29 34 #include "BasicProjectile.h" 30 35 31 36 #include "core/CoreIncludes.h" 32 #include "core/ConfigValueIncludes.h"33 37 #include "core/GameMode.h" 34 38 #include "core/command/Executor.h" 35 #include "objects/collisionshapes/SphereCollisionShape.h" 36 #include "worldentities/pawns/Pawn.h" 39 37 40 #include "graphics/ParticleSpawner.h" 38 #include "core/OrxonoxClass.h"39 41 40 42 namespace orxonox … … 46 48 BasicProjectile::BasicProjectile() : OrxonoxClass() 47 49 { 48 RegisterRootObject(BasicProjectile);// - register the BasicProjectile class to the core50 RegisterRootObject(BasicProjectile);// Register the BasicProjectile class to the core 49 51 50 52 this->bDestroy_ = false; … … 61 63 } 62 64 63 /* The function called when a projectile hits another thing. 64 * calls the hit-function, starts the reload countdown, displays visual effects 65 * hit is defined in src/orxonox/worldentities/pawns/pawn.cc 66 */ 67 bool BasicProjectile::basicCollidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint, Pawn* owner, BasicProjectile* this_) 65 /** 66 @brief 67 The function called when a projectile hits another thing. 68 Calls the hit-function, starts the reload countdown, displays visual hit effects defined in Pawn. 69 Needs to be called in the collidesAgainst() function by every Class directly inheriting from BasicProjectile. 70 @param otherObject 71 A pointer to the object the Projectile has collided against. 72 @param contactPoint 73 A btManifoldPoint indicating the point of contact/impact. 74 @return 75 Returns true if the collision resulted in a successful hit. 76 @see Pawn.h 77 */ 78 bool BasicProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint) 68 79 { 69 if (!this _->getBDestroy()&& GameMode::isMaster())80 if (!this->bDestroy_ && GameMode::isMaster()) 70 81 { 71 if (otherObject == owner) //prevents you from shooting yourself82 if (otherObject == this->getShooter()) // Prevents you from shooting yourself 72 83 return false; 73 84 74 this _->setBDestroy(true); // If something is hit, the object is destroyed and can't hit something else.75 85 this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else. 86 // The projectile is destroyed by its tick()-function (in the following tick). 76 87 77 Pawn* victim = orxonox_cast<Pawn*>(otherObject); // if otherObject isn't a Pawn, then victim is NULL88 Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is NULL 78 89 79 WorldEntity* entity = orxonox_cast<WorldEntity*>(this _);80 assert(entity); // entity must not be null90 WorldEntity* entity = orxonox_cast<WorldEntity*>(this); 91 assert(entity); // The projectile must not be a WorldEntity. 81 92 82 83 // if visual effects after destruction cause problems, put this block below the effects code block 93 // If visual effects after destruction cause problems, put this block below the effects code block 84 94 if (victim) 85 95 { 86 victim->hit( owner, contactPoint, this_->getDamage(), this_->getHealthDamage(), this_->getShieldDamage());96 victim->hit(this->getShooter(), contactPoint, this->getDamage(), this->getHealthDamage(), this->getShieldDamage()); 87 97 victim->startReloadCountdown(); 88 98 } 89 99 90 // visual effects for being hit, depending on whether the shield is hit or not91 if ( owner) //if the owner does not exist (anymore?), no effects are displayed.100 // Visual effects for being hit, depending on whether the shield is hit or not 101 if (this->getShooter()) // If the owner does not exist (anymore?), no effects are displayed. 92 102 { 93 // damping and explosion effect is only played if the victim is no pawn (see cast above)94 // or if the victim is a pawn, has no shield left, is still alive and any damage goes to the health95 if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0 && (this_->getDamage() > 0 || this_->getHealthDamage() > 0)))103 // Damping and explosion effect is only played if the victim is no Pawn (see cast above) 104 // or if the victim is a Pawn, has no shield left, is still alive and any damage goes to the health 105 if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0.0f && (this->getDamage() > 0.0f || this->getHealthDamage() > 0.0f))) 96 106 { 97 107 { 98 ParticleSpawner* effect = new ParticleSpawner( owner->getCreator());108 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator()); 99 109 effect->setPosition(entity->getPosition()); 100 110 effect->setOrientation(entity->getOrientation()); … … 103 113 effect->setLifetime(2.0f); 104 114 } 105 // second effect with same condition115 // Second effect with same condition 106 116 { 107 ParticleSpawner* effect = new ParticleSpawner( owner->getCreator());117 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator()); 108 118 effect->setPosition(entity->getPosition()); 109 119 effect->setOrientation(entity->getOrientation()); … … 115 125 116 126 // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead 117 if (victim && victim->hasShield() && (this _->getDamage() > 0 || this_->getShieldDamage() > 0) && victim->getHealth() > 0)127 if (victim && victim->hasShield() && (this->getDamage() > 0.0f || this->getShieldDamage() > 0.0f) && victim->getHealth() > 0.0f) 118 128 { 119 ParticleSpawner* effect = new ParticleSpawner( owner->getCreator());129 ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator()); 120 130 effect->setDestroyAfterLife(true); 121 131 effect->setSource("Orxonox/Shield"); … … 124 134 } 125 135 } 126 136 return true; 127 137 } 128 138 return false; 129 139 } 140 141 /** 142 @brief 143 Check whether the projectile needs to be destroyed and destroys it if so. 144 Needs to be called in the tick() by every Class directly inheriting from BasicProjectile, to make sure the projectile is destroyed after it has hit something. 145 */ 146 void BasicProjectile::destroyCheck(void) 147 { 148 if(GameMode::isMaster() && this->bDestroy_) 149 this->destroy(); 150 } 151 152 /** 153 @brief 154 Destroys the object. 155 */ 156 void BasicProjectile::destroyObject(void) 157 { 158 if(GameMode::isMaster()) 159 this->destroy(); 160 } 130 161 }
Note: See TracChangeset
for help on using the changeset viewer.