[Orxonox-commit 5633] r10293 - code/trunk/src/modules/weapons/projectiles

landauf at orxonox.net landauf at orxonox.net
Sun Mar 1 20:59:15 CET 2015


Author: landauf
Date: 2015-03-01 20:59:15 +0100 (Sun, 01 Mar 2015)
New Revision: 10293

Modified:
   code/trunk/src/modules/weapons/projectiles/BasicProjectile.cc
   code/trunk/src/modules/weapons/projectiles/BasicProjectile.h
Log:
avoid collisions between projectiles of a turret and the parent-pawn to which the turret is attached

Modified: code/trunk/src/modules/weapons/projectiles/BasicProjectile.cc
===================================================================
--- code/trunk/src/modules/weapons/projectiles/BasicProjectile.cc	2015-03-01 14:27:01 UTC (rev 10292)
+++ code/trunk/src/modules/weapons/projectiles/BasicProjectile.cc	2015-03-01 19:59:15 UTC (rev 10293)
@@ -81,7 +81,7 @@
     {
         if (!this->bDestroy_ && GameMode::isMaster())
         {
-            if (otherObject == this->getShooter() || otherObject->isA(Class(BasicProjectile))) // Prevents you from shooting yourself or other projectiles
+            if (this->isObjectRelatedToShooter(otherObject) || otherObject->isA(Class(BasicProjectile))) // Prevents you from shooting yourself or other projectiles
                 return false;
 
             this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else.
@@ -140,7 +140,21 @@
         return false;
     }
 
+    /**
+     * Returns true if otherObject is equal to the shooter or if one of otherObject's parents is equal to the shooter or if one of the shooter's parent is equal to otherObject.
+     */
+    bool BasicProjectile::isObjectRelatedToShooter(WorldEntity* otherObject)
+    {
+        for (WorldEntity* shooter = this->getShooter(); shooter != NULL; shooter = shooter->getParent())
+            if (otherObject == shooter)
+                return true;
+        for (WorldEntity* object = otherObject; object != NULL; object = object->getParent())
+            if (otherObject == this->getShooter())
+                return true;
 
+        return false;
+    }
+
     /**
     @brief
         Check whether the projectile needs to be destroyed and destroys it if so.

Modified: code/trunk/src/modules/weapons/projectiles/BasicProjectile.h
===================================================================
--- code/trunk/src/modules/weapons/projectiles/BasicProjectile.h	2015-03-01 14:27:01 UTC (rev 10292)
+++ code/trunk/src/modules/weapons/projectiles/BasicProjectile.h	2015-03-01 19:59:15 UTC (rev 10293)
@@ -122,6 +122,8 @@
             void destroyCheck(void);
 
         private:
+            bool isObjectRelatedToShooter(WorldEntity* otherObject);
+
             WeakPtr<Pawn> shooter_; //!< The entity that fired the projectile.
 
             float damage_; //!< The amount of normal damage. Normal damage can be (partially) absorbed by shields.




More information about the Orxonox-commit mailing list