Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 9, 2014, 9:01:44 PM (10 years ago)
Author:
noep
Message:

Modified collision-detecting-process, such that collisions can be traced back to single child-CollisionShapes of Compound-CollisionShapes

Location:
code/branches/modularships/src/modules/weapons/projectiles
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.cc

    r9667 r9995  
    141141    }
    142142
     143    bool BasicProjectile::customProcessCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs)
     144        {
     145            if (!this->bDestroy_ && GameMode::isMaster())
     146            {
     147                if (otherObject == this->getShooter()) // Prevents you from shooting yourself
     148                    return false;
     149
     150                this->bDestroy_ = true; // If something is hit, the object is destroyed and can't hit something else.
     151                                        // The projectile is destroyed by its tick()-function (in the following tick).
     152
     153                Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is NULL
     154
     155                WorldEntity* entity = orxonox_cast<WorldEntity*>(this);
     156                assert(entity); // The projectile must not be a WorldEntity.
     157
     158                // If visual effects after destruction cause problems, put this block below the effects code block
     159                if (victim)
     160                {
     161                    victim->customHit(this->getShooter(), contactPoint, cs, this->getDamage(), this->getHealthDamage(), this->getShieldDamage());
     162                    victim->startReloadCountdown();
     163                }
     164
     165                // Visual effects for being hit, depending on whether the shield is hit or not
     166                if (this->getShooter()) // If the owner does not exist (anymore?), no effects are displayed.
     167                {
     168                    // Damping and explosion effect is only played if the victim is no Pawn (see cast above)
     169                    // or if the victim is a Pawn, has no shield left, is still alive and any damage goes to the health
     170                    if (!victim || (victim && !victim->hasShield() && victim->getHealth() > 0.0f && (this->getDamage() > 0.0f || this->getHealthDamage() > 0.0f)))
     171                    {
     172                        {
     173                            ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
     174                            effect->setPosition(entity->getPosition());
     175                            effect->setOrientation(entity->getOrientation());
     176                            effect->setDestroyAfterLife(true);
     177                            effect->setSource("Orxonox/explosion3");
     178                            effect->setLifetime(2.0f);
     179                        }
     180                        // Second effect with same condition
     181                        {
     182                            ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
     183                            effect->setPosition(entity->getPosition());
     184                            effect->setOrientation(entity->getOrientation());
     185                            effect->setDestroyAfterLife(true);
     186                            effect->setSource("Orxonox/smoke4");
     187                            effect->setLifetime(3.0f);
     188                        }
     189                    }
     190
     191                    // victim->isAlive() is not false until the next tick, so getHealth() > 0 is used instead
     192                    if (victim && victim->hasShield() && (this->getDamage() > 0.0f || this->getShieldDamage() > 0.0f) && victim->getHealth() > 0.0f)
     193                    {
     194                        ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getContext());
     195                        effect->setDestroyAfterLife(true);
     196                        effect->setSource("Orxonox/Shield");
     197                        effect->setLifetime(0.5f);
     198                        victim->attach(effect);
     199                    }
     200                }
     201                return true;
     202            }
     203            return false;
     204        }
     205
    143206    /**
    144207    @brief
  • code/branches/modularships/src/modules/weapons/projectiles/BasicProjectile.h

    r9667 r9995  
    120120        protected:
    121121            bool processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     122            bool customProcessCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs);
    122123            void destroyCheck(void);
    123124
  • code/branches/modularships/src/modules/weapons/projectiles/Projectile.cc

    r9667 r9995  
    9393    }
    9494
     95    bool Projectile::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
     96    {
     97        return this->customProcessCollision(otherObject, contactPoint, cs);
     98    }
     99
    95100}
  • code/branches/modularships/src/modules/weapons/projectiles/Projectile.h

    r9667 r9995  
    6565            virtual void tick(float dt);
    6666            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     67            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
    6768
    6869        private:
  • code/branches/modularships/src/modules/weapons/projectiles/Rocket.cc

    r9667 r9995  
    196196    }
    197197
     198    bool Rocket::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
     199    {
     200        return this->customProcessCollision(otherObject, contactPoint, cs);
     201    }
     202
    198203    /**
    199204    @brief
  • code/branches/modularships/src/modules/weapons/projectiles/Rocket.h

    r9667 r9995  
    6565
    6666            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     67            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
    6768            virtual void destroyObject(void);
    6869            void destructionEffect();
  • code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.cc

    r9667 r9995  
    177177    }
    178178
     179    bool SimpleRocket::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
     180    {
     181        return this->customProcessCollision(otherObject, contactPoint, cs);
     182    }
     183
    179184    /**
    180185    @brief
  • code/branches/modularships/src/modules/weapons/projectiles/SimpleRocket.h

    r9667 r9995  
    6565
    6666            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     67            virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
    6768
    6869            void disableFire(); //!< Method to disable the fire and stop all acceleration
Note: See TracChangeset for help on using the changeset viewer.