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.

Location:
code/trunk/src/modules/weapons/projectiles
Files:
15 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}
  • code/trunk/src/modules/weapons/projectiles/BasicProjectile.h

    r8706 r8855  
    2727 */
    2828
     29/**
     30    @file BasicProjectile.h
     31    @brief Definition of the BasicProjectile class.
     32*/
     33
    2934#ifndef _BasicProjectile_H__
    3035#define _BasicProjectile_H__
     
    3237#include "weapons/WeaponsPrereqs.h"
    3338
    34 #include "tools/Timer.h"
     39#include "worldentities/pawns/Pawn.h"
     40
    3541#include "core/OrxonoxClass.h"
    3642
    3743namespace orxonox
    3844{
     45
     46    /**
     47    @brief
     48        Baseclass of all projectiles. Defines the damage the projectile does.
     49
     50    @author
     51        Simon Miescher
     52    @ingroup WeaponsProjectiles
     53    */
    3954    class _WeaponsExport BasicProjectile : public virtual OrxonoxClass
    4055    {
    4156        public:
    4257            BasicProjectile();
    43 
    4458            virtual ~BasicProjectile();
    4559
    46             static bool basicCollidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint, Pawn* owner, BasicProjectile* this_);
    47 
    48             void basicDestroyObject();
    49 
     60            /**
     61            @brief Set the normal damage done by this projectile.
     62                   Normal damage can be (partially) absorbed by shields.
     63            @param damage The amount of damage. Must be non-negative.
     64            */
    5065            inline void setDamage(float damage)
    51                 { this->damage_ = damage;  }
     66                { if(damage >= 0.0f)  { this->damage_ = damage; return; } COUT(1) << "The input projectile damage must be non-negative. Ignoring..." << endl; }
     67            /**
     68            @brief Get the normal damage done by this projectile.
     69                   Normal damage can be (partially) absorbed by shields.
     70            @return Returns the amount of damage. Is non-negative.
     71            */
    5272            inline float getDamage() const
    5373                { return this->damage_; }
    5474
     75            /**
     76            @brief Set the health-damage done by this projectile.
     77                   Health-damage cannot be absorbed by shields.
     78            @param healthdamage The amount of damage. Must be non-negative.
     79            */
    5580            inline void setHealthDamage(float healthdamage)
    56                 { this->healthdamage_ = healthdamage; }
     81                { if(healthdamage >= 0.0f)  { this->healthdamage_ = healthdamage; return; } COUT(1) << "The input projectile health-damage must be non-negative. Ignoring..." << endl; }
     82            /**
     83            @brief Get the health-damage done by this projectile.
     84                   Health-damage cannot be absorbed by shields.
     85            @return healthdamage The amount of damage. Is non-negative.
     86            */
    5787            inline float getHealthDamage() const
    5888                { return this->healthdamage_; }
    5989
     90            /**
     91            @brief Set the shield-damage done by this projectile.
     92                   Shield-damage only reduces shield health.
     93            @param shielddamage The amount of damage. Must be non-negative.
     94            */
    6095            inline void setShieldDamage(float shielddamage)
    61                 { this->shielddamage_ = shielddamage;  } //ShieldDamage wird korrekt gesettet vom XML-File
     96                { if(shielddamage >= 0.0f)  { this->shielddamage_ = shielddamage; return; } COUT(1) << "The input projectile shield-damage must be non-negative. Ignoring..." << endl; }
     97            /**
     98            @brief Get the shield-damage done by this projectile.
     99                   Shield-damage only reduces shield health.
     100            @param shielddamage The amount of damage. Is non-negative.
     101            */
    62102            inline float getShieldDamage() const
    63103                { return this->shielddamage_; }
    64104
     105            /**
     106            @brief Set the entity that fired the projectile.
     107            @param shooter A pointer to the Pawn that fired the projectile.
     108            */
     109            virtual void setShooter(Pawn* shooter)
     110                { this->shooter_ = shooter; }
     111            /**
     112            @brief Get the entity that fired the projectile.
     113            @return Returns a pointer to the Pawn that fired the projectile.
     114            */
     115            inline Pawn* getShooter(void)
     116                { return this->shooter_; }
    65117
    66             inline void setBDestroy(bool bDestroy)
    67                 { this->bDestroy_ = bDestroy;  }
    68             inline float getBDestroy() const
    69                 { return this->bDestroy_; }
     118            virtual void destroyObject(void);
    70119
     120        protected:
     121            bool processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     122            void destroyCheck(void);
    71123
    72124        private:
    73 //            WeakPtr<Pawn> owner_; //owner cannot be set in BasicProjectile, because it's already defined in MobileEntity and Movable Entity
     125            WeakPtr<Pawn> shooter_; //!< The entity that fired the projectile.
    74126
    75             float damage_;
    76             float healthdamage_;
    77             float shielddamage_;
     127            float damage_; //!< The amount of normal damage. Normal damage can be (partially) absorbed by shields.
     128            float healthdamage_; //!< The amount of health-damage. Health-damage cannot be absorbed by shields.
     129            float shielddamage_; //!< The amount of shield-damage. Shield-damage only reduces shield health.
    78130
    79             bool bDestroy_;
     131            bool bDestroy_; //!< Boolean, to check whether a projectile should be destroyed.
    80132    };
    81133}
  • code/trunk/src/modules/weapons/projectiles/BillboardProjectile.cc

    r6502 r8855  
    2727 */
    2828
     29/**
     30    @file BillboardProjectile.h
     31    @brief Implementation of the BillboardProjectile class.
     32*/
     33
    2934#include "BillboardProjectile.h"
    3035
     
    4449        {
    4550            assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity
     51
     52            // Create the billboard.
    4653            this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(0.5f, 0.5f, 0.7f, 0.8f), 1);
    4754            this->attachOgreObject(this->billboard_.getBillboardSet());
     
    5764    }
    5865
     66    /**
     67    @brief
     68        Set the colour of the BillboardProjectile.
     69    @param colour
     70        The colour to be set.
     71    */
    5972    void BillboardProjectile::setColour(const ColourValue& colour)
    6073    {
     
    6275    }
    6376
     77    /**
     78    @brief
     79        Set the material of the BillboardProjectile.
     80    @param material
     81        The material name.
     82    */
    6483    void BillboardProjectile::setMaterial(const std::string& material)
    6584    {
     
    6786    }
    6887
     88    /**
     89    @brief
     90        Is called when the visibility of the BillboardProjectile has changed.
     91    */
    6992    void BillboardProjectile::changedVisibility()
    7093    {
    7194        SUPER(BillboardProjectile, changedVisibility);
    7295
     96        // Also change the visibility of the billboard.
    7397        this->billboard_.setVisible(this->isVisible());
    7498    }
  • code/trunk/src/modules/weapons/projectiles/BillboardProjectile.h

    r5781 r8855  
    2727 */
    2828
     29/**
     30    @file BillboardProjectile.h
     31    @brief Definition of the BillboardProjectile class.
     32*/
     33
    2934#ifndef _BillboardProjectile_H__
    3035#define _BillboardProjectile_H__
     
    3843namespace orxonox
    3944{
     45
     46    /**
     47    @brief
     48        A BillboardProjectile is a projectile that is represented by a Billboard.
     49
     50    @author
     51        Fabian 'x3n' Landau
     52    @ingroup WeaponsProjectiles
     53    */
    4054    class _WeaponsExport BillboardProjectile : public Projectile
    4155    {
     
    4963
    5064        private:
    51             BillboardSet billboard_;
     65            BillboardSet billboard_; //!< The billboard that represents the projectile.
    5266    };
    5367}
  • code/trunk/src/modules/weapons/projectiles/CMakeLists.txt

    r8706 r8855  
    11ADD_SOURCE_FILES(WEAPONS_SRC_FILES
     2  BasicProjectile.cc
    23  BillboardProjectile.cc
    34  ParticleProjectile.cc
     
    67  Rocket.cc
    78  SimpleRocket.cc
    8   BasicProjectile.cc
    99)
  • code/trunk/src/modules/weapons/projectiles/LightningGunProjectile.cc

    r8729 r8855  
    2727 */
    2828
     29/**
     30    @file LightningGunProjectile.h
     31    @brief Implementation of the LightningGunProjectile class.
     32*/
     33
    2934#include "LightningGunProjectile.h"
    3035
    31 #include "util/Convert.h"
    3236#include "core/CoreIncludes.h"
    3337#include "core/command/Executor.h"
     38#include "util/Convert.h"
    3439
    3540namespace orxonox
     
    5358    }
    5459
     60    /**
     61    @brief
     62        Set the material.
     63    @param material
     64        The name of the material. Material names with 1 to 8 appended must exist.
     65    */
    5566    void LightningGunProjectile::setMaterial(const std::string& material)
    5667    {
     
    6071    }
    6172
     73    /**
     74    @brief
     75        Change the texture.
     76    */
    6277    void LightningGunProjectile::changeTexture()
    6378    {
  • code/trunk/src/modules/weapons/projectiles/LightningGunProjectile.h

    r5929 r8855  
    2727 */
    2828
     29/**
     30    @file LightningGunProjectile.h
     31    @brief Definition of the LightningGunProjectile class.
     32*/
     33
    2934#ifndef _LightningGunProjectile_H__
    3035#define _LightningGunProjectile_H__
     
    3843namespace orxonox
    3944{
     45
     46    /**
     47    @brief
     48        The LightningGunProjectile is a projectile that is represented by a looped series of billboards.
     49       
     50    @author
     51        Joel Smely
     52    @ingroup WeaponsProjectiles
     53    */
    4054    class _WeaponsExport LightningGunProjectile : public BillboardProjectile
    4155    {
     
    4660            virtual void setMaterial(const std::string& material);
    4761
    48         protected:
     62        private:
     63            void registerVariables();
    4964            void changeTexture();
    50             unsigned int textureIndex_;
    51             unsigned int maxTextureIndex_;
    52             Timer textureTimer_;
    53             std::string materialBase_;
    54       private:
    55             void registerVariables();
     65           
     66            unsigned int textureIndex_; //!< The current index of the texture. (i.e. the index of the currently displayed texture)
     67            unsigned int maxTextureIndex_; //!< The maximal index.
     68            Timer textureTimer_; //!< A timer that loops and changes textures each time it expires.
     69            std::string materialBase_; //!< The base name of the material.
    5670    };
    5771}
  • code/trunk/src/modules/weapons/projectiles/ParticleProjectile.cc

    r5929 r8855  
    2727 */
    2828
     29/**
     30    @file ParticleProjectile.h
     31    @brief Implementation of the ParticleProjectile class.
     32*/
     33
    2934#include "ParticleProjectile.h"
    3035
    3136#include <OgreParticleEmitter.h>
     37#include "core/CoreIncludes.h"
    3238#include "tools/ParticleInterface.h"
    33 #include "core/CoreIncludes.h"
    3439#include "Scene.h"
    3540
     
    4449        if (GameMode::showsGraphics())
    4550        {
     51            // Create the particles.
    4652            this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::Normal);
    4753            this->attachOgreObject(this->particles_->getParticleSystem());
     
    6369    }
    6470
     71    /**
     72    @brief
     73        Is called when the visibility of the ParticleProjectile has changed.
     74    */
    6575    void ParticleProjectile::changedVisibility()
    6676    {
    6777        SUPER(ParticleProjectile, changedVisibility);
    6878
     79        // Change the visibility of the particles.
    6980        if (this->particles_)
    7081            this->particles_->setEnabled(this->isVisible());
  • code/trunk/src/modules/weapons/projectiles/ParticleProjectile.h

    r5781 r8855  
    2727 */
    2828
     29/**
     30    @file ParticleProjectile.h
     31    @brief Definition of the ParticleProjectile class.
     32*/
     33
    2934#ifndef _ParticleProjectile_H__
    3035#define _ParticleProjectile_H__
     
    3540namespace orxonox
    3641{
     42
     43    /**
     44    @brief
     45        A projectile that is represented by particles.
     46    @author
     47        Fabian 'x3n' Landau
     48    @ingroup WeaponsProjectiles
     49    */
    3750    class _WeaponsExport ParticleProjectile : public BillboardProjectile
    3851    {
     
    4356
    4457        private:
    45             ParticleInterface* particles_;
     58            ParticleInterface* particles_; //!< The particles.
    4659    };
    4760}
  • code/trunk/src/modules/weapons/projectiles/Projectile.cc

    r8706 r8855  
    2727 */
    2828
     29/**
     30    @file Projectile.h
     31    @brief Implementation of the Projectile class.
     32*/
     33
    2934#include "Projectile.h"
    3035
     36#include "core/ConfigValueIncludes.h"
    3137#include "core/CoreIncludes.h"
    32 #include "core/ConfigValueIncludes.h"
    3338#include "core/GameMode.h"
    3439#include "core/command/Executor.h"
     40
    3541#include "objects/collisionshapes/SphereCollisionShape.h"
    3642#include "worldentities/pawns/Pawn.h"
    37 #include "graphics/ParticleSpawner.h"
    3843
    3944namespace orxonox
     
    4651
    4752        this->setConfigValues();
    48         this->owner_ = 0;
    4953
    5054        // Get notification about collisions
    5155        if (GameMode::isMaster())
    5256        {
    53             this->setMass(1.0);
     57            this->setMass(1.0f);
    5458            this->enableCollisionCallback();
    5559            this->setCollisionResponse(false);
     
    5761
    5862            SphereCollisionShape* shape = new SphereCollisionShape(this);
    59             shape->setRadius(20);
     63            shape->setRadius(20.0f);
    6064            this->attachCollisionShape(shape);
    6165
    62             this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Projectile::destroyObject, this)));
     66            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
    6367        }
    6468    }
     
    7074    void Projectile::setConfigValues()
    7175    {
    72         SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
     76        SetConfigValue(lifetime_, 4.0f).description("The time in seconds a projectile stays alive");
    7377    }
    7478
     
    8185            return;
    8286
    83         if (this->getBDestroy())
    84             this->destroy(); // TODO: use a scheduler instead of deleting the object right here in tick()
     87        this->destroyCheck();
    8588    }
    8689
    87     void Projectile::destroyObject()
     90    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
    8891    {
    89         if (GameMode::isMaster())
    90             this->destroy();
     92        return this->processCollision(otherObject, contactPoint);
    9193    }
    9294
    93     /* Calls the collidesAgainst function of BasicProjectile
    94      */
    95     bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
    96     {
    97         return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this);
    98     }
    99 
    100     void Projectile::setOwner(Pawn* owner)
    101     {
    102         this->owner_ = owner;
    103     }
    10495}
  • code/trunk/src/modules/weapons/projectiles/Projectile.h

    r8706 r8855  
    2727 */
    2828
     29/**
     30    @file Projectile.h
     31    @brief Definition of the Projectile class.
     32*/
     33
    2934#ifndef _Projectile_H__
    3035#define _Projectile_H__
     
    3944namespace orxonox
    4045{
     46
     47    /**
     48    @brief
     49        Represents all 'standard' projectiles.
     50
     51    @author
     52        Fabian 'x3n' Landau
     53    @author
     54        Simon Miescher
     55    @ingroup WeaponsProjectiles
     56    */
    4157    class _WeaponsExport Projectile : public MovableEntity, public BasicProjectile
    4258    {
     
    4662
    4763            void setConfigValues();
    48             void destroyObject();
    4964
    5065            virtual void tick(float dt);
    5166            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
    5267
    53             void setOwner(Pawn* owner);
    54             inline Pawn* getOwner() const
    55                 { return this->owner_; }
    56 
    57 
    5868        private:
    59             WeakPtr<Pawn> owner_;
    60             float lifetime_;
    61             Timer destroyTimer_;
     69            float lifetime_; //!< The time the projectile exists.
     70            Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out.
    6271    };
    6372}
  • code/trunk/src/modules/weapons/projectiles/Rocket.cc

    r8738 r8855  
    2727 */
    2828
     29/**
     30    @file Rocket.h
     31    @brief Implementation of the Rocket class.
     32*/
     33
    2934#include "Rocket.h"
    3035
     
    3338#include "core/CoreIncludes.h"
    3439#include "core/XMLPort.h"
     40
     41#include "Scene.h"
     42#include "controllers/Controller.h"
     43#include "graphics/Model.h"
     44#include "graphics/ParticleSpawner.h"
     45#include "infos/PlayerInfo.h"
     46#include "objects/collisionshapes/ConeCollisionShape.h"
     47#include "sound/WorldSound.h"
    3548#include "worldentities/CameraPosition.h"
    3649#include "worldentities/pawns/Pawn.h"
    37 #include "graphics/ParticleSpawner.h"
    38 #include "graphics/Model.h"
    39 #include "objects/collisionshapes/ConeCollisionShape.h"
    40 #include "infos/PlayerInfo.h"
    41 #include "controllers/Controller.h"
    42 #include "sound/WorldSound.h"
    43 #include "Scene.h"
    4450
    4551namespace orxonox
    4652{
    4753    CreateFactory(Rocket);
    48     // create the factory for the Rocket
    4954
    5055    /**
     
    5762        , RadarViewable(creator, static_cast<WorldEntity*>(this))
    5863    {
    59         RegisterObject(Rocket);// - register the Rocket class to the core
     64        RegisterObject(Rocket);// Register the Rocket class to the core
    6065
    6166        this->localAngularVelocity_ = 0;
    62         this->lifetime_ = 100;
     67        this->lifetime_ = 100.0f;
    6368
    6469        if (GameMode::isMaster())
     
    6772            this->setVelocity(0,0,-100);
    6873
     74            // Create rocket model
    6975            Model* model = new Model(this);
    7076            model->setMeshSource("rocket.mesh");
    7177            model->scale(0.7f);
    7278            this->attach(model);
     79
     80            // Add effects.
    7381            ParticleEmitter* fire = new ParticleEmitter(this);
    7482            this->attach(fire);
     
    8088            this->setCollisionType(Kinematic);
    8189
     90            // Add collision shape
    8291            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
    8392            collisionShape->setRadius(3);
     
    8594            this->attachCollisionShape(collisionShape);
    8695
    87             this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
    88 
     96            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
     97
     98            // Add sound
    8999            this->defSndWpnEngine_ = new WorldSound(this);
    90100            this->defSndWpnEngine_->setLooping(true);
     
    105115        }
    106116
     117        // Add camera
    107118        CameraPosition* camPosition = new CameraPosition(this);
    108119        camPosition->setPosition(0,4,15);
     
    141152    /**
    142153    @brief
    143         Method for creating a Rocket through XML.
    144     */
    145     void Rocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    146     {
    147         // this calls the XMLPort function of the parent class
    148         SUPER(Rocket, XMLPort, xmlelement, mode);
    149     }
    150 
    151     void Rocket::setOwner(Pawn* owner)
    152     {
    153         this->owner_ = owner;
    154         this->player_ = this->getOwner()->getPlayer();
    155         this->getOwner()->getPlayer()->startTemporaryControl(this);
     154        Sets the entity that fired the Rocket.
     155    @param shooter
     156        A pointer to the Pawn that fired the Rocket.
     157    */
     158    void Rocket::setShooter(Pawn* shooter)
     159    {
     160        this->BasicProjectile::setShooter(shooter);
     161       
     162        this->player_ = this->getShooter()->getPlayer();
     163        this->getShooter()->getPlayer()->startTemporaryControl(this);
    156164
    157165        if( GameMode::isMaster() )
     
    179187        }
    180188
    181         if( GameMode::isMaster() )
    182         {
    183             if( this->getBDestroy() )
    184                 this->destroy();
    185 
    186         }
    187     }
    188 
    189     /* Calls the collidesAgainst function of BasicProjectile
    190      */
     189       this->destroyCheck();
     190    }
     191
    191192    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
    192193    {
    193         return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this);
    194     }
    195 
    196     void Rocket::destroyObject()
    197     {
    198         if (GameMode::isMaster())
    199         {
    200             if(this->defSndWpnEngine_->isPlaying())
    201             {
    202                 this->defSndWpnEngine_->stop();
    203             }
    204             this->destroy();
    205         }
    206     }
    207 
     194        return this->processCollision(otherObject, contactPoint);
     195    }
     196
     197    /**
     198    @brief
     199        Destroys the Rocket and stops the sound,
     200    */
     201    void Rocket::destroyObject(void)
     202    {
     203        if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying())
     204            this->defSndWpnEngine_->stop();
     205
     206        this->BasicProjectile::destroyObject();
     207    }
     208
     209    /**
     210    @brief
     211        Destroys the Rocket upon pressing "fire".
     212    */
    208213    void Rocket::fired(unsigned int firemode)
    209214    {
    210         this->destroy();
    211     }
    212 
     215        this->destroyObject();
     216    }
     217
     218    /**
     219    @brief
     220        The effects that are displayed, when the Rocket is destroyed.
     221    */
    213222    void Rocket::destructionEffect()
    214223    {
    215224        ParticleSpawner *effect1, *effect2;
    216         if( this->getOwner() )
    217         {
    218             effect1 = new ParticleSpawner(this->getOwner()->getCreator());
    219             effect2 = new ParticleSpawner(this->getOwner()->getCreator());
     225        if(this->getShooter())
     226        {
     227            effect1 = new ParticleSpawner(this->getShooter()->getCreator());
     228            effect2 = new ParticleSpawner(this->getShooter()->getCreator());
    220229        }
    221230        else
  • code/trunk/src/modules/weapons/projectiles/Rocket.h

    r8738 r8855  
    2727 */
    2828
     29/**
     30    @file Rocket.h
     31    @brief Definition of the Rocket class.
     32*/
     33
    2934#ifndef _Rocket_H__
    3035#define _Rocket_H__
     
    3338
    3439#include "tools/Timer.h"
     40
     41#include "interfaces/RadarViewable.h"
    3542#include "worldentities/ControllableEntity.h"
    36 #include "interfaces/RadarViewable.h"
    3743
    3844#include "BasicProjectile.h"
     
    4450    /**
    4551    @brief
    46         Rocket, that is made to move upon a specified pattern.
    47         This class was constructed for the PPS tutorial.
     52        Rocket that can be steered by the player.
     53
    4854    @author
    4955        Oli Scheuss
     56    @ingroup WeaponsProjectiles
    5057    */
    5158    class _WeaponsExport Rocket : public ControllableEntity, public BasicProjectile, public RadarViewable
     
    5562            virtual ~Rocket();
    5663
    57             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a Rocket through XML.
    5864            virtual void tick(float dt); //!< Defines which actions the Rocket has to take in each tick.
    5965
    6066            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
    61             void destroyObject();
     67            virtual void destroyObject(void);
    6268            void destructionEffect();
    6369
    64             virtual void moveFrontBack(const Vector2& value){}
    65             virtual void moveRightLeft(const Vector2& value){}
    66             virtual void moveUpDown(const Vector2& value){}
     70            virtual void moveFrontBack(const Vector2& value) {}
     71            virtual void moveRightLeft(const Vector2& value) {}
     72            virtual void moveUpDown(const Vector2& value) {}
    6773
    6874            virtual void rotateYaw(const Vector2& value);
     
    7581            */
    7682            inline void moveFrontBack(float value)
    77             { this->moveFrontBack(Vector2(value, 0)); }
     83                { this->moveFrontBack(Vector2(value, 0)); }
    7884            /**
    7985            @brief Moves the Rocket in the Right/Left-direction by the specifed amount.
     
    8187            */
    8288            inline void moveRightLeft(float value)
    83             { this->moveRightLeft(Vector2(value, 0)); }
     89                { this->moveRightLeft(Vector2(value, 0)); }
    8490            /**
    8591            @brief Moves the Rocket in the Up/Down-direction by the specifed amount.
     
    8793            */
    8894            inline void moveUpDown(float value)
    89             { this->moveUpDown(Vector2(value, 0)); }
     95                { this->moveUpDown(Vector2(value, 0)); }
    9096
    9197            /**
     
    94100            */
    95101            inline void rotateYaw(float value)
    96             { this->rotateYaw(Vector2(value, 0)); }
     102                { this->rotateYaw(Vector2(value, 0)); }
    97103            /**
    98104            @brief Rotates the Rocket around the x-axis by the specifed amount.
     
    100106            */
    101107            inline void rotatePitch(float value)
    102             { this->rotatePitch(Vector2(value, 0)); }
     108                { this->rotatePitch(Vector2(value, 0)); }
    103109            /**
    104110            @brief Rotates the Rocket around the z-axis by the specifed amount.
     
    106112            */
    107113            inline void rotateRoll(float value)
    108             { this->rotateRoll(Vector2(value, 0)); }
     114                { this->rotateRoll(Vector2(value, 0)); }
    109115
    110             void setOwner(Pawn* owner);
    111             inline Pawn* getOwner() const
    112                 { return this->owner_; }
     116            virtual void setShooter(Pawn* shooter);
    113117
    114118            virtual void fired(unsigned int firemode);
    115119
    116120        private:
    117             WeakPtr<Pawn> owner_;
    118             Vector3 localAngularVelocity_;
     121            Vector3 localAngularVelocity_; //!< Variable to temporarily store accumulated steering command input.
    119122
    120             WeakPtr<PlayerInfo> player_;
    121             Timer destroyTimer_;
    122             float lifetime_;
     123            WeakPtr<PlayerInfo> player_; //!< The player that controls the Rocket.
     124            Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out.
     125            float lifetime_; //!< The time the projectile exists.
    123126
    124             WorldSound* defSndWpnEngine_;
    125             WorldSound* defSndWpnLaunch_;
     127            WorldSound* defSndWpnEngine_; //!< Engine sound.
     128            WorldSound* defSndWpnLaunch_; //!< Launch sound.
    126129    };
    127130
  • code/trunk/src/modules/weapons/projectiles/SimpleRocket.cc

    r8738 r8855  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss
     23 *      Gabriel Nadler
    2424 *   Co-authors:
    2525 *      simonmie
     
    2727 */
    2828
     29/**
     30    @file SimpleRocket.h
     31    @brief Implementation of the SimpleRocket class.
     32*/
     33
     34
    2935#include "SimpleRocket.h"
    3036
     
    3339#include "core/CoreIncludes.h"
    3440#include "core/XMLPort.h"
     41#include "util/Debug.h"
     42
     43#include "controllers/Controller.h"
     44#include "graphics/Model.h"
     45#include "graphics/ParticleSpawner.h"
     46#include "infos/PlayerInfo.h"
     47#include "objects/collisionshapes/ConeCollisionShape.h"
    3548#include "worldentities/pawns/Pawn.h"
    36 #include "graphics/ParticleSpawner.h"
    37 #include "graphics/Model.h"
    38 #include "objects/collisionshapes/ConeCollisionShape.h"
    39 #include "infos/PlayerInfo.h"
    40 #include "controllers/Controller.h"
     49#include "sound/WorldSound.h"
     50
    4151#include "weapons/RocketController.h"
    42 #include "sound/WorldSound.h"
    43 #include "util/Debug.h"
    4452
    4553namespace orxonox
     
    5361        , RadarViewable(creator, static_cast<WorldEntity*>(this))
    5462    {
    55         RegisterObject(SimpleRocket);// - register the SimpleRocket class to the core
     63        RegisterObject(SimpleRocket);// Register the SimpleRocket class to the core
    5664
    5765        this->localAngularVelocity_ = 0;
    58         this->lifetime_ = 10;
    59 
    60         this->setMass(15);
    61 //        COUT(4) << "simplerocket constructed\n";
     66        this->lifetime_ = 10.f;
     67
     68        this->setMass(15.0);
    6269
    6370        if (GameMode::isMaster())
    6471        {
    6572            this->setCollisionType(WorldEntity::Kinematic);
    66             this->fuel_=true;
    67 
     73            this->fuel_ = true;
     74
     75            // Create rocket model.
    6876            Model* model = new Model(this);
    6977            model->setMeshSource("rocket.mesh");
     
    7179            this->attach(model);
    7280
     81            // Add effects.
    7382            this->fire_ = new ParticleEmitter(this);
    7483            this->attach(this->fire_);
     
    8089            this->setCollisionType(Kinematic);
    8190
     91            // Add collision shape.
    8292            // TODO: fix the orientation and size of this collision shape to match the rocket
    8393            ConeCollisionShape* collisionShape = new ConeCollisionShape(this);
     
    8696            collisionShape->setHeight(5);
    8797            this->attachCollisionShape(collisionShape);
    88             this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&SimpleRocket::destroyObject, this)));
     98           
     99            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
    89100        }
    90101
     
    97108
    98109    /**
    99     * @brief updates state of rocket, disables fire if no fuel
    100     * @param dt tick-length
     110    @brief
     111        Updates state of rocket, disables fire if no fuel
     112    @param dt
     113        tick-length
    101114    */
    102115    void SimpleRocket::tick(float dt)
    103116    {
    104 
    105117        SUPER(SimpleRocket, tick, dt);
    106         if ( GameMode::isMaster() )
     118       
     119        if (GameMode::isMaster())
    107120        {
    108 
    109 
    110121            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
    111122            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
    112123            this->localAngularVelocity_ = 0;
    113124
    114 
    115125            if (this->fuel_)
    116126            {
    117                 if (this->destroyTimer_.getRemainingTime()<  (static_cast<float>(this->FUEL_PERCENTAGE)/100) *this->lifetime_ )
    118                     this->fuel_=false;
     127                if (this->destroyTimer_.getRemainingTime() < this->FUEL_PERCENTAGE*this->lifetime_ )
     128                    this->fuel_ = false;
    119129            } else
    120130                this->disableFire();
    121 
    122             if( this->getBDestroy() )
    123                 this->destroy();
    124131        }
    125132
    126     }
    127 
    128     /**
    129     * @brief Sets the Acceleration to 0 and detaches the fire
    130     * @return void
     133        this->destroyCheck();
     134    }
     135
     136    /**
     137    @brief
     138        Sets the Acceleration to 0 and detaches the fire.
    131139    */
    132140    void SimpleRocket::disableFire()
     
    136144    }
    137145
    138     /**s
     146    /**
    139147    @brief
    140148        Destructor. Destroys controller, if present and kills sounds, if playing.
     
    153161    /**
    154162    @brief
    155         Method for creating a SimpleRocket through XML.
    156     */
    157     void SimpleRocket::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    158     {
    159         // this calls the XMLPort function of the parent class
    160         SUPER(SimpleRocket, XMLPort, xmlelement, mode);
    161     }
    162 
    163     void SimpleRocket::setOwner(Pawn* owner)
    164     {
    165         this->owner_ = owner;
    166         this->player_ = this->getOwner()->getPlayer();
    167     }
    168 
    169 
    170     /* Calls the collidesAgainst function of BasicProjectile
    171      */
     163        Set the entity that fired the SimpleRocket.
     164    @param shooter
     165        A pointer to the Pawn that fired the SimpleRocket.
     166    */
     167    void SimpleRocket::setShooter(Pawn* shooter)
     168    {
     169        BasicProjectile::setShooter(shooter);
     170       
     171        this->player_ = this->getShooter()->getPlayer();
     172    }
     173
    172174    bool SimpleRocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
    173175    {
    174         return BasicProjectile::basicCollidesAgainst(otherObject,contactPoint,this->getOwner(),this);
    175     }
    176 
    177     void SimpleRocket::destroyObject()
    178     {
    179         if (GameMode::isMaster())
    180         {
    181             this->destroy();
    182         }
     176        return this->processCollision(otherObject, contactPoint);
    183177    }
    184178
  • code/trunk/src/modules/weapons/projectiles/SimpleRocket.h

    r8738 r8855  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss
     23 *      Gabriel Nadler
    2424 *   Co-authors:
    2525 *      simonmie
    2626 *
    2727 */
     28
     29/**
     30    @file SimpleRocket.h
     31    @brief Definition of the SimpleRocket class.
     32*/
    2833
    2934#ifndef _SimpleRocket_H__
     
    3338
    3439#include "tools/Timer.h"
    35 #include "worldentities/ControllableEntity.h"
     40
    3641#include "graphics/ParticleSpawner.h"
    3742#include "interfaces/RadarViewable.h"
     43#include "worldentities/ControllableEntity.h"
    3844
    3945#include "BasicProjectile.h"
     
    4551    /**
    4652    @brief
    47         SimpleRocket, follows direction from a Rocketcontroller, has fuel for 80% of its lifetime, afterwards it's fire disappears.
     53        SimpleRocket is a target seeking, intelligent rocket. It follows its target until it either hits something or runs out of fuel.
     54        The steering is done by the RocketController.
    4855    @author
    49        Gabriel Nadler (Original file: Oli Scheuss)
     56       Gabriel Nadler
     57    @ingroup WeaponsProjectiles
    5058    */
    5159    class _WeaponsExport SimpleRocket : public ControllableEntity, public BasicProjectile, public RadarViewable
     
    5563            virtual ~SimpleRocket();
    5664            virtual void tick(float dt);
    57             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a SimpleRocket through XML.
    5865
    5966            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
    60             void destroyObject();
    6167
    6268            void disableFire(); //!< Method to disable the fire and stop all acceleration
     
    7682            */
    7783            inline void moveFrontBack(float value)
    78             { this->moveFrontBack(Vector2(value, 0)); }
     84                { this->moveFrontBack(Vector2(value, 0)); }
    7985            /**
    8086            @brief Moves the SimpleRocket in the Right/Left-direction by the specifed amount.
     
    8288            */
    8389            inline void moveRightLeft(float value)
    84             { this->moveRightLeft(Vector2(value, 0)); }
     90                { this->moveRightLeft(Vector2(value, 0)); }
    8591            /**
    8692            @brief Moves the SimpleRocket in the Up/Down-direction by the specifed amount.
     
    8894            */
    8995            inline void moveUpDown(float value)
    90             { this->moveUpDown(Vector2(value, 0)); }
     96                { this->moveUpDown(Vector2(value, 0)); }
    9197
    9298            /**
     
    95101            */
    96102            inline void rotateYaw(float value)
    97             { this->rotateYaw(Vector2(value, 0)); }
     103                { this->rotateYaw(Vector2(value, 0)); }
    98104            /**
    99105            @brief Rotates the SimpleRocket around the x-axis by the specifed amount.
     
    101107            */
    102108            inline void rotatePitch(float value)
    103             {
    104                 this->rotatePitch(Vector2(value, 0)); }
     109                { this->rotatePitch(Vector2(value, 0)); }
    105110            /**
    106111            @brief Rotates the SimpleRocket around the z-axis by the specifed amount.
     
    108113            */
    109114            inline void rotateRoll(float value)
    110             {
    111                 this->rotateRoll(Vector2(value, 0)); }
     115                { this->rotateRoll(Vector2(value, 0)); }
    112116
    113             void setOwner(Pawn* owner);
    114             inline Pawn* getOwner() const
    115                 { return this->owner_; }
     117            virtual void setShooter(Pawn* shooter);
    116118
    117119            inline bool hasFuel() const
    118             { return this->fuel_; }
     120                { return this->fuel_; }
    119121
    120122
    121123        private:
    122             WeakPtr<Pawn> owner_;
    123             Vector3 localAngularVelocity_;
     124            static const float FUEL_PERCENTAGE = 0.8f; //!< Percentage of lifetime the rocket has fuel
     125           
     126            Vector3 localAngularVelocity_; //!< Variable to temporarily store accumulated steering command input.
    124127            bool fuel_; //!< Bool is true while the rocket "has fuel"
    125128
    126 
    127             WeakPtr<PlayerInfo> player_;
    128             Timer destroyTimer_;
    129             float lifetime_;
    130             static const int FUEL_PERCENTAGE=80; //!<Percentage of Lifetime the rocket has fuel
     129            WeakPtr<PlayerInfo> player_; //!< The player the SimpleRocket belongs to.
     130            Timer destroyTimer_; //!< Timer to destroy the projectile after its lifetime has run out.
     131            float lifetime_; //!< The time the projectile exists.
    131132
    132133            ParticleEmitter* fire_; //!< Fire-Emittor
    133 
    134 
    135 
    136134    };
    137135
Note: See TracChangeset for help on using the changeset viewer.