Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 15, 2009, 1:15:42 PM (15 years ago)
Author:
scheusso
Message:

cleaned up Rocket mess a bit
there is yet a bug if RocketFire is in weaponslot3

File:
1 moved

Legend:

Unmodified
Added
Removed
  • code/branches/particles2/src/modules/weapons/projectiles/Rocket.cc

    r6059 r6065  
    3131#include "core/XMLPort.h"
    3232#include "BulletDynamics/Dynamics/btRigidBody.h"
     33#include "worldentities/pawns/Pawn.h"
     34#include "graphics/ParticleSpawner.h"
     35#include "graphics/Model.h"
     36#include "objects/collisionshapes/ConeCollisionShape.h"
    3337
    3438namespace orxonox
     
    4347    Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator)
    4448    {
    45         this->myController_ = 0;
    46         // put your code in here:
    4749        RegisterObject(Rocket);// - register the Rocket class to the core
    4850       
    49         this->localLinearAcceleration_.setValue(0, 0, 0);
    50         this->localAngularAcceleration_.setValue(0, 0, 0);
    51         this->primaryThrust_  = 100;
    52         this->auxilaryThrust_ = 100;
    53         this->rotationThrust_ = 10;
     51        this->setCollisionType(WorldEntity::Kinematic);
     52        this->setVelocity(0,0,-100);
     53        this->model_ = new Model(this);
     54        this->model_->setMeshSource("can.mesh");
     55        this->attach(this->model_);
     56        this->lifetime_ = 100;
    5457       
    55         this->setCollisionType(WorldEntity::Kinematic);
    56        
    57         this->myController_ = new RocketController(static_cast<BaseObject*>(this)); //!< Creates a new controller and passes our this pointer to it as creator.
     58        if (GameMode::isMaster())
     59        {
     60            this->enableCollisionCallback();
     61            this->setCollisionResponse(false);
     62            this->setCollisionType(Kinematic);
     63
     64            this->collisionShape_ = new ConeCollisionShape(this);
     65            this->collisionShape_->setRadius(3);
     66            this->collisionShape_->setHeight(500);
     67            this->attachCollisionShape(this->collisionShape_);
     68
     69            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this)));
     70        }
    5871    }
    5972
     
    6477    Rocket::~Rocket()
    6578    {
    66         if( this->myController_ != NULL )
    67             this->myController_->destroy();
     79        if(this->isInitialized())
     80        {
     81            this->collisionShape_->destroy();
     82            this->model_->destroy();
     83        }
    6884    }
    6985
     
    7692        // this calls the XMLPort function of the parent class
    7793        SUPER(Rocket, XMLPort, xmlelement, mode);
    78 
    79         // put your code in here:
    80                 XMLPortParam(Rocket, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
    81                 //XMLPortParam(Rocket, "auxilaryThrust", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode);
    82                 //XMLPortParam(Rocket, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
    83         // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport
    84         // make sure that the set- and get-functions exist.
    85         // variables can be added by the following command
    86         // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode)
    87  
     94    }
     95   
     96    void Rocket::setOwner(Pawn* owner)
     97    {
     98        this->owner_ = owner;
    8899    }
    89100
     
    98109        SUPER(Rocket, tick, dt);
    99110       
    100         //if (this->hasLocalController())
    101         //{
    102             this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
    103             this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
    104             if (this->localLinearAcceleration_.z() > 0)
    105               this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
    106             else
    107               this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    108             this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    109             this->localLinearAcceleration_.setValue(0, 0, 0);
    110        
    111             this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
    112             this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    113             this->localAngularAcceleration_.setValue(0, 0, 0);
    114         //}
     111        this->setAngularVelocity(this->localAngularVelocity_);
    115112    }
    116113   
    117     /**
    118     @brief
    119         Moves the Rocket in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
    120     @param value
    121         The vector determining the amount of the movement.
    122     */
    123     void Rocket::moveFrontBack(const Vector2& value)
     114    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
    124115    {
    125         this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
     116        if (!this->bDestroy_ && GameMode::isMaster())
     117        {
     118            if (otherObject == this->owner_)
     119                return false;
     120
     121            this->bDestroy_ = true;
     122
     123            if (this->owner_)
     124            {
     125                {
     126                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
     127                    effect->setPosition(this->getPosition());
     128                    effect->setOrientation(this->getOrientation());
     129                    effect->setDestroyAfterLife(true);
     130                    effect->setSource("Orxonox/explosion3");
     131                    effect->setLifetime(2.0f);
     132                }
     133                {
     134                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
     135                    effect->setPosition(this->getPosition());
     136                    effect->setOrientation(this->getOrientation());
     137                    effect->setDestroyAfterLife(true);
     138                    effect->setSource("Orxonox/smoke4");
     139                    effect->setLifetime(3.0f);
     140                }
     141            }
     142
     143            float dmg = this->damage_;
     144            if (this->owner_)
     145                dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false);
     146
     147            Pawn* victim = orxonox_cast<Pawn*>(otherObject);
     148            if (victim)
     149                victim->damage(dmg, this->owner_);
     150        }
     151        return false;
    126152    }
    127 
    128     /**
    129     @brief
    130         Moves the Rocket in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
    131     @param value
    132         The vector determining the amount of the movement.
    133     */
    134     void Rocket::moveRightLeft(const Vector2& value)
     153   
     154    void Rocket::destroyObject()
    135155    {
    136         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    137     }
    138 
    139     /**
    140     @brief
    141         Moves the Rocket in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
    142     @param value
    143         The vector determining the amount of the movement.
    144     */
    145     void Rocket::moveUpDown(const Vector2& value)
    146     {
    147         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
     156        if (GameMode::isMaster())
     157            this->destroy();
    148158    }
    149159
     
    156166    void Rocket::rotateYaw(const Vector2& value)
    157167    {
    158         this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
     168        this->localAngularVelocity_.y = value.x;
    159169    }
    160170
     
    167177    void Rocket::rotatePitch(const Vector2& value)
    168178    {
    169         this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
     179        this->localAngularVelocity_.x = value.x;
    170180    }
    171181
     
    178188    void Rocket::rotateRoll(const Vector2& value)
    179189    {
    180         this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
     190        this->localAngularVelocity_.z = value.x;
    181191    }
    182192   
Note: See TracChangeset for help on using the changeset viewer.