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

Location:
code/branches/particles2/src/modules/weapons
Files:
2 edited
2 copied
2 moved

Legend:

Unmodified
Added
Removed
  • code/branches/particles2/src/modules/weapons/projectiles/CMakeLists.txt

    r5781 r6065  
    44  Projectile.cc
    55  LightningGunProjectile.cc
     6  Rocket.cc
    67)
  • 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   
  • code/branches/particles2/src/modules/weapons/projectiles/Rocket.h

    r6059 r6065  
    3232#include "OrxonoxPrereqs.h"
    3333#include "worldentities/ControllableEntity.h"
    34 #include "controllers/RocketController.h"
    3534
    3635namespace orxonox
    3736{
     37    class ConeCollisionShape;
    3838
    3939    /**
     
    5252            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a Rocket through XML.
    5353            virtual void tick(float dt); //!< Defines which actions the Rocket has to take in each tick.
    54 
    5554           
    56             virtual void moveFrontBack(const Vector2& value);
    57             virtual void moveRightLeft(const Vector2& value);
    58             virtual void moveUpDown(const Vector2& value);
     55            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     56            void destroyObject();
     57           
     58            virtual void moveFrontBack(const Vector2& value){}
     59            virtual void moveRightLeft(const Vector2& value){}
     60            virtual void moveUpDown(const Vector2& value){}
    5961
    6062            virtual void rotateYaw(const Vector2& value);
     
    100102            { this->rotateRoll(Vector2(value, 0)); }
    101103           
    102             /**
    103             @brief Sets the primary thrust to the input amount.
    104             @param thrust The amount of thrust.
    105             */
    106             inline void setPrimaryThrust( float thrust )
    107                 { this->primaryThrust_=thrust; }     
    108             // place your set-functions here.
    109             // - hint: auxiliary thrust, rotation thrust.
    110            
    111             /**
    112             @brief Gets the primary thrust to the input amount.
    113             @preturn The amount of thrust.
    114             */
    115             inline float getPrimaryThrust()
    116                 { return this->primaryThrust_; }
    117             // place your get-functions here.
     104            void setOwner(Pawn* owner);
     105            inline Pawn* getOwner() const
     106                { return this->owner_; }
     107               
     108            inline void setDamage(float damage)
     109                { this->damage_ = damage; }
     110            inline float getDamage() const
     111                { return this->damage_; }
    118112           
    119113        private:
    120             RocketController *myController_; //!< The controller of the Rocket.
     114            WeakPtr<Pawn> owner_;
     115            Vector3 localAngularVelocity_;
     116            float damage_;
     117            bool bDestroy_;
    121118           
    122             btVector3 localLinearAcceleration_; //!< The linear acceleration that is used to move the Rocket the next tick.
    123             btVector3 localAngularAcceleration_; //!< The linear angular acceleration that is used to move the Rocket the next tick.
    124             float primaryThrust_; //!< The amount of primary thrust. This is just used, when moving forward.
    125             float auxilaryThrust_; //!< The amount of auxilary thrust. Used for all other movements (except for rotations).
    126             float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.
     119            Model* model_;
     120            ConeCollisionShape* collisionShape_;
     121            Timer destroyTimer_;
     122            float lifetime_;
    127123    };
    128124
  • code/branches/particles2/src/modules/weapons/weaponmodes/CMakeLists.txt

    r5781 r6065  
    55  HsW01.cc
    66  LightningGun.cc
     7  RocketFire.cc
    78)
  • code/branches/particles2/src/modules/weapons/weaponmodes/RocketFire.cc

    r6059 r6065  
    2727 */
    2828
    29 #include "FusionFire.h"
     29#include "RocketFire.h"
    3030
    3131#include "util/Math.h"
    3232#include "core/CoreIncludes.h"
    33 #include "weapons/projectiles/BillboardProjectile.h"
     33#include "weapons/projectiles/Rocket.h"
    3434
    3535#include "weaponsystem/Weapon.h"
     
    3939namespace orxonox
    4040{
    41     CreateFactory(FusionFire);
     41    CreateFactory(RocketFire);
    4242
    43     FusionFire::FusionFire(BaseObject* creator) : WeaponMode(creator)
     43    RocketFire::RocketFire(BaseObject* creator) : WeaponMode(creator)
    4444    {
    45         RegisterObject(FusionFire);
     45        RegisterObject(RocketFire);
    4646
    47         this->reloadTime_ = 1.0;
     47        this->reloadTime_ = 0.20;
    4848        this->bParallelReload_ = false;
    49         this->damage_ = 40;
    50         this->speed_ = 1250;
     49        this->damage_ = 100;
     50        this->speed_ = 500;
    5151
    52         this->setMunitionName("FusionMunition");
     52        this->setMunitionName("RocketMunition");
    5353    }
    5454
    55     void FusionFire::fire()
     55    void RocketFire::fire()
    5656    {
    57         BillboardProjectile* projectile = new BillboardProjectile(this);
     57        Rocket* rocket = new Rocket(this);
    5858
    59         projectile->setOrientation(this->getMuzzleOrientation());
    60         projectile->setPosition(this->getMuzzlePosition());
    61         projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
    62         projectile->scale(5);
     59        rocket->setOrientation(this->getMuzzleOrientation());
     60        rocket->setPosition(this->getMuzzlePosition());
     61        rocket->setVelocity(this->getMuzzleDirection() * this->speed_);
     62        rocket->scale(2);
    6363
    64         projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
    65         projectile->setDamage(this->getDamage());
    66         projectile->setColour(ColourValue(1.0f, 0.7f, 0.3f, 1.0f));
     64        rocket->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
     65        rocket->setDamage(this->getDamage());
    6766    }
    6867}
  • code/branches/particles2/src/modules/weapons/weaponmodes/RocketFire.h

    r6059 r6065  
    2727 */
    2828
    29 #ifndef _FusionFire_H__
    30 #define _FusionFire_H__
     29#ifndef _RocketFire_H__
     30#define _RocketFire_H__
    3131
    3232#include "weapons/WeaponsPrereqs.h"
     
    3535namespace orxonox
    3636{
    37     class _WeaponsExport FusionFire : public WeaponMode
     37    class _WeaponsExport RocketFire : public WeaponMode
    3838    {
    3939        public:
    40             FusionFire(BaseObject* creator);
    41             virtual ~FusionFire() {}
     40            RocketFire(BaseObject* creator);
     41            virtual ~RocketFire() {}
    4242
    4343            virtual void fire();
     
    4848}
    4949
    50 #endif /* _FusionFire_H__ */
     50#endif /* _RocketFire_H__ */
Note: See TracChangeset for help on using the changeset viewer.