Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 22, 2011, 3:05:26 PM (13 years ago)
Author:
dafrick
Message:

Cleaning up game immersion. Roughly documenting weapons module.

File:
1 edited

Legend:

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

    r8767 r8855  
    2727 */
    2828
     29/**
     30    @file BasicProjectile.h
     31    @brief Implementation of the BasicProjectile class.
     32*/
     33
    2934#include "BasicProjectile.h"
    3035
    3136#include "core/CoreIncludes.h"
    32 #include "core/ConfigValueIncludes.h"
    3337#include "core/GameMode.h"
    3438#include "core/command/Executor.h"
    35 #include "objects/collisionshapes/SphereCollisionShape.h"
    36 #include "worldentities/pawns/Pawn.h"
     39
    3740#include "graphics/ParticleSpawner.h"
    38 #include "core/OrxonoxClass.h"
    3941
    4042namespace orxonox
     
    4648    BasicProjectile::BasicProjectile() : OrxonoxClass()
    4749    {
    48         RegisterRootObject(BasicProjectile);// - register the BasicProjectile class to the core
     50        RegisterRootObject(BasicProjectile);// Register the BasicProjectile class to the core
    4951
    5052        this->bDestroy_ = false;
     
    6163    }
    6264
    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)
    6879    {
    69         if (!this_->getBDestroy() && GameMode::isMaster())
     80        if (!this->bDestroy_ && GameMode::isMaster())
    7081        {
    71             if (otherObject == owner) //prevents you from shooting yourself
     82            if (otherObject == this->getShooter()) // Prevents you from shooting yourself
    7283                return false;
    7384
    74             this_->setBDestroy(true); // If something is hit, the object is destroyed and can't hit something else.
    75                                       // The projectile is destroyed by its tick()-function (in the following tick).
     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).
    7687
    77             Pawn* victim = orxonox_cast<Pawn*>(otherObject); //if otherObject isn't a Pawn, then victim is NULL
     88            Pawn* victim = orxonox_cast<Pawn*>(otherObject); // If otherObject isn't a Pawn, then victim is NULL
    7889
    79             WorldEntity* entity = orxonox_cast<WorldEntity*>(this_);
    80             assert(entity); //entity must not be null
     90            WorldEntity* entity = orxonox_cast<WorldEntity*>(this);
     91            assert(entity); // The projectile must not be a WorldEntity.
    8192
    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
    8494            if (victim)
    8595            {
    86                 victim->hit(owner, contactPoint, this_->getDamage(), this_->getHealthDamage(), this_->getShieldDamage());
     96                victim->hit(this->getShooter(), contactPoint, this->getDamage(), this->getHealthDamage(), this->getShieldDamage());
    8797                victim->startReloadCountdown();
    8898            }
    8999
    90             // visual effects for being hit, depending on whether the shield is hit or not
    91             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.
    92102            {
    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 health
    95                 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)))
    96106                {
    97107                    {
    98                         ParticleSpawner* effect = new ParticleSpawner(owner->getCreator());
     108                        ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator());
    99109                        effect->setPosition(entity->getPosition());
    100110                        effect->setOrientation(entity->getOrientation());
     
    103113                        effect->setLifetime(2.0f);
    104114                    }
    105                         // second effect with same condition
     115                    // Second effect with same condition
    106116                    {
    107                         ParticleSpawner* effect = new ParticleSpawner(owner->getCreator());
     117                        ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator());
    108118                        effect->setPosition(entity->getPosition());
    109119                        effect->setOrientation(entity->getOrientation());
     
    115125
    116126                // 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)
    118128                {
    119                     ParticleSpawner* effect = new ParticleSpawner(owner->getCreator());
     129                    ParticleSpawner* effect = new ParticleSpawner(this->getShooter()->getCreator());
    120130                    effect->setDestroyAfterLife(true);
    121131                    effect->setSource("Orxonox/Shield");
     
    124134                }
    125135            }
    126 
     136            return true;
    127137        }
    128138        return false;
    129139    }
     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    }
    130161}
Note: See TracChangeset for help on using the changeset viewer.