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/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
Note: See TracChangeset for help on using the changeset viewer.