Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2391 for code/branches/weapon2


Ignore:
Timestamp:
Dec 10, 2008, 5:30:39 PM (16 years ago)
Author:
polakma
Message:

fixed projectile, particle effect, reloadingTimer and magazineTimer

Location:
code/branches/weapon2/src/orxonox/objects
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.cc

    r2379 r2391  
    4646    }
    4747
    48     bool Munition::bullets()
     48    unsigned int Munition::bullets()
    4949    {
    5050        if (this->bullets_ > 0)
    51             return true;
     51            return bullets_;
    5252        else
    53             return false;
     53            return 0;
    5454    }
    5555
    56     bool Munition::magazines()
     56    unsigned int Munition::magazines()
    5757    {
    5858        if (this->magazines_ > 0)
    59             return true;
     59            return magazines_;
    6060        else
    61             return false;
     61            return 0;
    6262    }
    6363
     
    6868    { this->maxMagazines_ = amount; }
    6969
    70     void Munition::removeBullets(unsigned int amount, Weapon * parentWeapon)
     70    void Munition::removeBullets(unsigned int amount)
    7171    {
    72         if ( this->bullets_ == 0 )
    73         {
    74             this->removeMagazines(1);
    75             parentWeapon->magazineTimer(0);
    76             this->bullets_ = this->maxBullets_;
    77         }
    78         else
     72        if ( this->bullets_ != 0 )
    7973            this->bullets_ = this->bullets_ - amount;
    8074    }
     
    8276    void Munition::removeMagazines(unsigned int amount)
    8377    {
    84         if ( this->magazines_ == 0 )
    85         {
    86             if ( this->bullets_ == 0 )
    87                 {
    88                     //no bullets and no magazines
    89                 }
    90             else
    91             {
    92                 //what to do when there are no more magazines?
    93             }
    94         }
    95         else
     78        if ( this->magazines_ != 0 )
    9679            this->magazines_ = this->magazines_ - amount;
    9780    }
     
    120103    void Munition::fillBullets()
    121104    {
     105COUT(0) << "Munition::fillBullets maxBullets_=" << this->maxBullets_ << std::endl;
    122106        this->bullets_ = this->maxBullets_;
    123107    }
     
    130114    void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    131115    {
    132 
     116        SUPER(Munition, XMLPort, xmlelement, mode);
    133117    }
    134118
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.h

    r2379 r2391  
    5353            void fillMagazines();
    5454
    55             bool bullets();
    56             bool magazines();
     55            unsigned int bullets();
     56            unsigned int magazines();
    5757
    58             void removeBullets(unsigned int k, Weapon * parentWeapon);
     58            void removeBullets(unsigned int k);
    5959            void removeMagazines(unsigned int k);
    6060            void addBullets(unsigned int k);
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.cc

    r2379 r2391  
    3939    CreateFactory(Weapon);
    4040
    41     Weapon::Weapon(BaseObject* creator) : BaseObject(creator)
     41    Weapon::Weapon(BaseObject* creator) : PositionableEntity(creator)
    4242    {
    4343        RegisterObject(Weapon);
     
    4747        this->parentWeaponSlot_ = 0;
    4848        this->munition_ = 0;
     49        this->bulletLoadingTime_ = 0;
     50        this->magazineLoadingTime_ = 0;
     51        this->bReloading_ = false;
    4952    }
    5053
     
    6265    void Weapon::setWeapon()
    6366    {
     67COUT(0) << "LaserGun::setWeapon" << std::endl;
    6468        this->bulletLoadingTime_ = 0.5;
    6569        this->magazineLoadingTime_ = 3.0;
    6670        this->munition_->setMaxMagazines(100);
    67         this->munition_->setMaxBullets(30);
     71        this->munition_->setMaxBullets(6);
    6872        this->munition_->fillBullets();
    6973        this->munition_->fillMagazines();
     
    7478    {
    7579COUT(0) << "LaserGun::fire, this=" << this << std::endl;
    76         if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ )
     80        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
    7781        {
    7882COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
    79 
     83COUT(0) << "LaserGun::fire - bullets" << this->munition_->bullets() << std::endl;
    8084            this->bulletReadyToShoot_ = false;
    81             if ( this->munition_->bullets() )
     85            if ( this->munition_->bullets() > 0)
    8286            {
    8387                //shoot
     
    8690            }
    8791            //if there are no bullets, but magazines
    88             else if ( this->munition_->magazines() && !this->munition_->bullets() )
    89             {
     92            else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
     93            {
     94COUT(0) << "LaserGun::fire - no bullets" << std::endl;
    9095                this->takeMagazines();
     96            }
     97            else
     98            {
     99COUT(0) << "LaserGun::fire - no magazines" << std::endl;
     100                //actions
    91101            }
    92102        }
     
    94104        {
    95105COUT(0) << "LaserGun::fire - weapon not reloaded" << std::endl;
     106            //actions
    96107        }
    97108
     
    102113    {
    103114COUT(0) << "Weapon::bulletTimer started" << std::endl;
     115        this->bReloading_ = true;
    104116        this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
    105117    }
     
    107119    {
    108120COUT(0) << "Weapon::magazineTimer started" << std::endl;
     121        this->bReloading_ = true;
    109122        this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
    110123    }
    111124
    112125    void Weapon::bulletReloaded()
    113     { this->bulletReadyToShoot_ = true; }
     126    {
     127        this->bReloading_ = false;
     128        this->bulletReadyToShoot_ = true;
     129    }
    114130
    115131    void Weapon::magazineReloaded()
    116     {
     132    {
     133        this->bReloading_ = false;
    117134        this->munition_->fillBullets();
    118135        this->magazineReadyToShoot_ = true;
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.h

    r2379 r2391  
    4040#include "Munition.h"
    4141
     42#include "objects/worldentities/PositionableEntity.h"
     43
    4244namespace orxonox
    4345{
    44     class _OrxonoxExport Weapon : public BaseObject
     46    class _OrxonoxExport Weapon : public PositionableEntity
    4547    {
    4648        public:
     
    8284                { return this->parentWeaponSystem_; };
    8385
    84             //in future by XMLPort,
     86            //in future by XMLPort
    8587            virtual void setWeapon();
    8688
     
    9294            float bulletLoadingTime_;
    9395            float magazineLoadingTime_;
     96            bool bReloading_;
     97
    9498            Munition *munition_;
    9599            std::string munitionType_;
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponPack.cc

    r2366 r2391  
    7575    void WeaponPack::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7676    {
     77        SUPER(WeaponPack, XMLPort, xmlelement, mode);
     78
    7779        XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);
    7880        XMLPortParam(WeaponPack, "firemode", setFireMode, getFireMode, xmlelement, mode);
     
    115117        {
    116118            this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType());
     119            //hack!
     120            this->weapons_[i]->setWeapon();
    117121        }
    118122
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2366 r2391  
    6868            {
    6969                //at the moment this function only works for one weaponPack in the entire WeaponSystem...
    70                 if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() != 0 ) //if slot not full
     70                if ( this->parentWeaponSystem_->getWeaponSlotPointer(i)->getAttachedWeapon() == 0 ) //if slot not full
    7171                {
    7272                    this->setWeaponSlots_.push_back( this->parentWeaponSystem_->getWeaponSlotPointer(i) );
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSlot.cc

    r2327 r2391  
    7373    void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7474    {
    75 
     75        SUPER(WeaponSlot, XMLPort, xmlelement, mode);
    7676    }
    7777
    78     void WeaponSlot::attachWeapon(Weapon *weaponPointer)
    79     {   this->attachedWeapon_ = weaponPointer;   }
     78    void WeaponSlot::attachWeapon(Weapon *weapon)
     79    {
     80        this->attachedWeapon_ = weapon;
     81        this->attach(weapon);
     82COUT(0) << "WeaponSlot::attachWeapon position=" << this->getWorldPosition() << std::endl;
     83    }
    8084
    8185    Weapon * WeaponSlot::getAttachedWeapon() const
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSlot.h

    r2319 r2391  
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4646
    47             void attachWeapon(Weapon *weaponPointer);
     47            void attachWeapon(Weapon *weapon);
    4848            Weapon * getAttachedWeapon() const;
    4949            void setAmmoType(bool isUnlimited);
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2366 r2391  
    145145    void WeaponSystem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    146146    {
    147 
     147        SUPER(WeaponSystem, XMLPort, xmlelement, mode);
    148148    }
    149149
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc

    r2367 r2391  
    4545        assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity
    4646
    47         this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
    48         //this->attachObject(this->billboard_.getBillboardSet());
    49         this->scale(0.5);
     47        this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(0.5, 0.5, 0.7, 0.8), 1);
     48        this->getNode()->attachObject(this->billboard_.getBillboardSet());
     49        this->scale(0.2);
    5050    }
    5151
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc

    r2368 r2391  
    4343        RegisterObject(ParticleProjectile);
    4444
    45         this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot2", LODParticle::normal);
     45        this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot2_small", LODParticle::normal);
    4646        this->particles_->addToSceneNode(this->getNode());
    47         this->particles_->setKeepParticlesInLocalSpace(true);
     47        //this->particles_->setKeepParticlesInLocalSpace(true);
    4848
     49        this->particles_->getAllEmitters()->setDirection(-WorldEntity::FRONT);
    4950        /*
    5051        if (this->owner_)
     
    7677        this->particles_->setEnabled(this->isVisible());
    7778    }
    78 
    79     bool ParticleProjectile::create(){
    80       if(!Projectile::create())
    81         return false;
    82       this->particles_->getAllEmitters()->setDirection(-this->getOrientation()*Vector3(1,0,0));
    83       return true;
    84     }
    8579}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.h

    r2272 r2391  
    4646            void setConfigValues();
    4747
    48             virtual bool create();
    49 
    5048        private:
    5149            ParticleInterface* particles_;
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc

    r2379 r2391  
    4848        RegisterObject(Projectile);
    4949
     50COUT(0) << "Projectile::Projectile" << std::endl;
     51
    5052        this->setConfigValues();
    5153        this->explosionTemplateName_ = "Orxonox/explosion3";
     
    5355
    5456        //this->setStatic(false);
    55         this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
     57//        this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
    5658
    5759        /*
     
    121123        delete this;
    122124    }
    123 
    124     bool Projectile::create(){
    125       return WorldEntity::create();
    126     }
    127125}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/Projectile.h

    r2272 r2391  
    4545            virtual void tick(float dt);
    4646
    47             virtual bool create();
    48 
    4947        protected:
    5048            Projectile(BaseObject* creator);
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc

    r2379 r2391  
    4444    {
    4545        RegisterObject(LaserGun);
     46
     47        //in future XMLPort
     48        this->speed_ = 250;
     49
    4650    }
    4751
     
    5256    void LaserGun::takeBullets()
    5357    {
    54         this->munition_->removeBullets(1,this);
     58COUT(0) << "LaserGun::takeBullets" << std::endl;
     59        this->munition_->removeBullets(1);
    5560        this->bulletTimer(this->bulletLoadingTime_);
    5661    }
     
    6469    void LaserGun::createProjectile()
    6570    {
     71COUT(0) << "LaserGun::createProjectile" << std::endl;
    6672        BillboardProjectile* projectile = new ParticleProjectile(this);
    67         projectile->setOrientation(projectile->getOrientation());
    68         projectile->setPosition(projectile->getWorldPosition());
     73        projectile->setOrientation(this->getWorldOrientation());
     74        projectile->setPosition(this->getWorldPosition());
    6975        projectile->setVelocity(WorldEntity::FRONT * this->speed_);
    7076    }
  • code/branches/weapon2/src/orxonox/objects/worldentities/MovableEntity.cc

    r2087 r2391  
    7575        {
    7676            this->velocity_ += (dt * this->acceleration_);
    77             this->node_->translate(dt * this->velocity_);
     77            this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
    7878
    7979            this->rotationRate_ += (dt * this->momentum_);
  • code/branches/weapon2/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2379 r2391  
    153153    {   
    154154COUT(0) << "Pawn::setWeaponSlot" << std::endl;
     155        this->attach(wSlot);
    155156        this->weaponSystem_->attachWeaponSlot(wSlot);   }
     157
    156158    WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const
    157159    {   return this->weaponSystem_->getWeaponSlotPointer(index);    }
Note: See TracChangeset for help on using the changeset viewer.