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