Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2232 for code/branches/weapon2


Ignore:
Timestamp:
Nov 19, 2008, 7:07:36 PM (16 years ago)
Author:
polakma
Message:

added new features to munition.h and weapon.h. tried to fix projectiles (still doesn't compile)

Location:
code/branches/weapon2/src/orxonox
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapon2/src/orxonox/CMakeLists.txt

    r2203 r2232  
    9292  objects/weaponSystem/weapons/LaserGun.cc
    9393  objects/weaponSystem/munitions/LaserGunMunition.cc
    94 #  objects/weaponSystem/projectiles/BillboardProjectile.cc
    95 #  objects/weaponSystem/projectiles/ParticleProjectile.cc
    96 #  objects/weaponSystem/projectiles/Projectile.cc
     94  objects/weaponSystem/projectiles/BillboardProjectile.cc
     95  objects/weaponSystem/projectiles/ParticleProjectile.cc
     96  objects/weaponSystem/projectiles/Projectile.cc
    9797
    9898  objects/worldentities/triggers/Trigger.cc
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.cc

    r2203 r2232  
    4646    }
    4747
     48    unsigned int Munition::getBullets()
     49    { return this->bullets_; }
    4850
    49     void Munition::decrementBullets()
     51    unsigned int Munition::getMagazines()
     52    { return this->magazines_; }
     53
     54    void Munition::setMaxBullets(unsigned int amount)
     55    { this->maxBullets_ = amount; }
     56
     57    void Munition::setMaxMagazines(unsigned int amount)
     58    { this->maxMagazines_ = amount; }
     59
     60    void Munition::removeBullets(unsigned int amount, Weapon * parentWeapon)
    5061    {
    51         this->bullets--;
     62        //if actual magazine is empty, decrement it and set the bullets amount to full (masBullets_)
     63        if ( this->bullets_ == 0 )
     64        {
     65            this->removeMagazines(1);
     66            parentWeapon->magazineTimer();
     67            this->bullets_ = this->maxBullets_;
     68        }
     69        else
     70            this->bullets_ = this->bullets_ - amount;
    5271    }
    53     void Munition::decrementMagazines()
     72
     73    void Munition::removeMagazines(unsigned int amount)
    5474    {
    55         this->magazines--;
     75        if ( this->magazines_ == 0 )
     76        {
     77            if ( this->bullets_ == 0 )
     78                {
     79                    //no bullets and no magazines
     80                }
     81            else
     82            {
     83                //what to do when there are no more magazines?
     84            }
     85        }
     86        else
     87            this->magazines_ = this->magazines_ - amount; }
     88
     89    void Munition::addBullets(unsigned int amount)
     90    {
     91        if ( this->bullets_ == this->maxBullets_ )
     92        {
     93            //cannot add bullets to actual magazine
     94        }
     95        else
     96            this->bullets_ = this->bullets_ + amount;
    5697    }
    57     void Munition::incrementBullets()
     98
     99    void Munition::addMagazines(unsigned int amount)
    58100    {
    59         this->bullets++;
    60     }
    61     void Munition::incrementMagazines()
    62     {
    63         this->magazines++;
     101        if ( this->magazines_ == this->maxMagazines_ )
     102        {
     103            //no more capacity for another magazine
     104        }
     105        else
     106            this->magazines_ = this->magazines_ + amount;
    64107    }
    65108
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.h

    r2203 r2232  
    3434#include "core/BaseObject.h"
    3535
     36#include "Weapon.h"
     37
    3638
    3739namespace orxonox
     
    4547            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4648
    47             void decrementBullets();
    48             void decrementMagazines();
    49             void incrementBullets();
    50             void incrementMagazines();
     49            void setMaxBullets(unsigned int amount);
     50            void setMaxMagazines(unsigned int amount);
     51
     52            unsigned int getBullets();
     53            unsigned int getMagazines();
     54
     55            void removeBullets(unsigned int k, Weapon * parentWeapon);
     56            void removeMagazines(unsigned int k);
     57            void addBullets(unsigned int k);
     58            void addMagazines(unsigned int k);
    5159
    5260        private:
    53             int bullets;
    54             int magazines;
     61            unsigned int bullets_;
     62            unsigned int magazines_;
     63            unsigned int maxBullets_;
     64            unsigned int maxMagazines_;
    5565    };
    5666}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.cc

    r2203 r2232  
    4040    {
    4141        RegisterObject(Weapon);
    42         this->weaponReadyToShoot_ = true;
     42        this->bulletReadyToShoot_ = true;
     43        this->magazineReadyToShoot_ = true;
    4344        this->setParentWeaponSystem();
    4445    }
     
    5152    void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5253    {
    53 
     54        SUPER(Weapon, XMLPort, xmlelement, mode);
    5455    }
    5556
     
    5859
    5960    }
    60     void Weapon::timer()
     61
     62
     63    void Weapon::bulletTimer()
    6164    {
    62         this->reloadTimer_.setTimer( this->loadingTime_ , false , this , createExecutor(createFunctor(&Weapon::reloaded)));
     65        this->bulletReloadTimer_.setTimer( this->bulletLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
     66    }
     67    void Weapon::magazineTimer()
     68    {
     69        this->magazineReloadTimer_.setTimer( this->magazineLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
    6370    }
    6471
    65     void Weapon::reloaded()
    66     {
     72    void Weapon::bulletReloaded()
     73    { this->bulletReadyToShoot_ = true; }
    6774
    68         this->weaponReadyToShoot_ = true;
    69     }
     75    void Weapon::magazineReloaded()
     76    { this->magazineReadyToShoot_ = true; }
     77
    7078
    7179    void Weapon::attachNeededMunition(std::string munitionName)
    7280    {
    73         //if munition type already exist attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem
     81        //if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem
    7482        if ( this->parentWeaponSystem_->getMunitionType(munitionName) )
    7583            this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionName);
     
    93101    {   return this->munition_; }
    94102
    95     void Weapon::setLoadingTime(float loadingTime)
    96     {   this->loadingTime_ = loadingTime;   }
     103    void Weapon::setBulletLoadingTime(float loadingTime)
     104    {   this->bulletLoadingTime_ = loadingTime;   }
    97105
    98     float Weapon::getLoadingTime()
    99     {   return this->loadingTime_;  }
     106    float Weapon::getBulletLoadingTime()
     107    {   return this->bulletLoadingTime_;  }
    100108
    101     void Weapon::setWeaponReadyToShoot(bool b)
    102     {   this->weaponReadyToShoot_ = b;   }
     109    void Weapon::setMagazineLoadingTime(float loadingTime)
     110    {   this->magazineLoadingTime_ = loadingTime;   }
    103111
    104     bool Weapon::getWeaponReadyToShoot()
    105     {   return this->weaponReadyToShoot_;    }
    106     Timer<Weapon> * Weapon::getTimer()
    107     {   return &this->reloadTimer_;   }
     112    float Weapon::getMagazineLoadingTime()
     113    {   return this->magazineLoadingTime_;  }
     114
     115    void Weapon::setBulletReadyToShoot(bool b)
     116    {   this->bulletReadyToShoot_ = b;   }
     117
     118    bool Weapon::getBulletReadyToShoot()
     119    {   return this->bulletReadyToShoot_;    }
     120
     121    void Weapon::setMagazineReadyToShoot(bool b)
     122    {   this->magazineReadyToShoot_ = b;   }
     123
     124    bool Weapon::getMagazineReadyToShoot()
     125    {   return this->magazineReadyToShoot_;    }
     126
     127    Timer<Weapon> * Weapon::getBulletTimer()
     128    {   return &this->bulletReloadTimer_;   }
     129
     130    Timer<Weapon> * Weapon::getMagazineTimer()
     131    {   return &this->magazineReloadTimer_;   }
    108132}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.h

    r2203 r2232  
    5151
    5252            virtual void fire();
    53             void timer();
    54             void reloaded();
     53            void bulletTimer();
     54            void magazineTimer();
     55            void bulletReloaded();
     56            void magazineReloaded();
    5557            void attachNeededMunition(std::string munitionType);
    5658
     
    5860            virtual void setParentWeaponSystem();
    5961            Munition * getAttachedMunition();
    60             void setLoadingTime(float loadingTime);
    61             float getLoadingTime();
    62             void setWeaponReadyToShoot(bool b);
    63             bool getWeaponReadyToShoot();
    64             Timer<Weapon> *getTimer();
     62            void setBulletLoadingTime(float loadingTime);
     63            float getBulletLoadingTime();
     64            void setMagazineLoadingTime(float loadingTime);
     65            float getMagazineLoadingTime();
     66            void setBulletReadyToShoot(bool b);
     67            bool getBulletReadyToShoot();
     68            void setMagazineReadyToShoot(bool b);
     69            bool getMagazineReadyToShoot();
     70            Timer<Weapon> *getBulletTimer();
     71            Timer<Weapon> *getMagazineTimer();
    6572
    6673            inline void setParentWeaponSlot(WeaponSlot *parentWeaponSlot)
     
    7077
    7178        private:
    72             bool weaponReadyToShoot_;
    73             float loadingTime_;
     79            bool bulletReadyToShoot_;
     80            bool magazineReadyToShoot_;
     81            float bulletLoadingTime_;
     82            float magazineLoadingTime_;
    7483            Munition *munition_;
    7584
     
    7786            WeaponSystem *parentWeaponSystem_;
    7887            SubclassIdentifier<Munition> munitionIdentifier_;
    79             Timer<Weapon> reloadTimer_;
     88            Timer<Weapon> bulletReloadTimer_;
     89            Timer<Weapon> magazineReloadTimer_;
    8090    };
    8191}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2145 r2232  
    4444        this->parentWeaponSystem_ = 0;
    4545
     46        /* will be made with XML
    4647        for (int i=0;i<k;i++)
    4748        {
    4849            attachWeaponSlot(new WeaponSlot(this));
    4950        }
     51        */
    5052    }
    5153
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSlot.cc

    r2203 r2232  
    5252    }
    5353
    54     void WeaponSlot::attachWeapon(Weapon *weaponPointer)
    55     {
    56         this->attachedWeapon_ = weaponPointer;
    57     }
    58 
    5954
    6055    /*sets the munition type
     
    6762    }
    6863
     64
    6965    void WeaponSlot::fire()
    7066    {
     
    7268    }
    7369
     70
     71    //XMLPort functions
    7472    void WeaponSlot::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7573    {
    7674        SUPER(WeaponSlot, XMLPort, xmlelement, mode);
     75        XMLPortObject(WeaponSlot, Weapon, "attached-weapon", attachWeapon, getAttachedWeapon, xmlelement, mode);
    7776    }
    7877
     78    void WeaponSlot::attachWeapon(Weapon *weaponPointer)
     79    {   this->attachedWeapon_ = weaponPointer;   }
     80
     81    Weapon * WeaponSlot::getAttachedWeapon(unsigned int index) const
     82    {   return this->attachedWeapon_;   }
     83
     84
    7985}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/WeaponSlot.h

    r2203 r2232  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "core/BaseObject.h"
    35 
    3634#include "Weapon.h"
    37 #include "../worldentities/PositionableEntity.h"
     35#include "objects/worldentities/PositionableEntity.h"
    3836
    3937namespace orxonox
     
    4846
    4947            void attachWeapon(Weapon *weaponPointer);
     48            Weapon * getAttachedWeapon(unsigned int index) const;
    5049            void setAmmoType(bool isUnlimited);
    5150            void fire();
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.h

    r2186 r2232  
    4747
    4848        private:
    49             int bullets_;
    50             int magazines_;
    51             int maxBullets_;
    52             int maxMagazines_;
    5349
    5450
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc

    r2099 r2232  
    4242        RegisterObject(BillboardProjectile);
    4343
    44         this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
    45         this->attachObject(this->billboard_.getBillboardSet());
     44        this->billboard_.setBillboardSet(this->scenemanager_, "Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
     45        //this->attachObject(this->billboard_.getBillboardSet());
    4646        this->scale(0.5);
    4747    }
     
    4949    BillboardProjectile::~BillboardProjectile()
    5050    {
    51         if (this->isInitialized() && this->owner_)
    52             this->detachObject(this->billboard_.getBillboardSet());
     51        //if (this->isInitialized() && this->owner_)
     52            //this->detachObject(this->billboard_.getBillboardSet());
    5353    }
    5454
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.h

    r2099 r2232  
    4747            virtual void changedVisibility();
    4848
     49            inline Ogre::SceneManager* getSceneManager()
     50            { return this->scenemanager_; }
     51
    4952        private:
    5053            BillboardSet billboard_;
     54            Ogre::SceneManager* scenemanager_;
    5155    };
    5256}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc

    r2099 r2232  
    3030#include "ParticleProjectile.h"
    3131
    32 #include "SpaceShip.h"
     32#include "../../worldentities/pawns/SpaceShip.h"
    3333#include "core/CoreIncludes.h"
    3434#include "core/ConfigValueIncludes.h"
     
    4242        RegisterObject(ParticleProjectile);
    4343
    44         this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal);
     44        this->particles_ = new ParticleInterface(this->getSceneManager(), "Orxonox/shot2", LODParticle::normal);
    4545        this->particles_->addToSceneNode(this->getNode());
    4646        this->particles_->setKeepParticlesInLocalSpace(true);
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc

    r2100 r2232  
    5454        this->smokeTemplateName_ = "Orxonox/smoke4";
    5555
    56         this->setStatic(false);
     56        //this->setStatic(false);
    5757        this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
    5858
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc

    r2203 r2232  
    4444
    4545        //set weapon properties here
    46         this->setLoadingTime(0.5);
     46        //this->setLoadingTime(0.5);
    4747
    4848        //Hack --> will be loaded by XML
     
    5656    void LaserGun::fire()
    5757    {
    58         if ( this->getWeaponReadyToShoot() )
     58        if ( this->getBulletReadyToShoot() && this->getMagazineReadyToShoot() )
    5959        {
    60             this->setWeaponReadyToShoot(false);
    6160
    62             Weapon::timer();
     61
    6362
    6463            //take munition
    65             this->getAttachedMunition()->decrementBullets();
     64            this->getAttachedMunition()->removeBullets(1,this);
     65            Weapon::bulletTimer();
     66            this->setBulletReadyToShoot(false);
    6667
    6768            //create projectile
    68             //BillboardProjectile* projectile = new ParticleProjectile(this);
     69            BillboardProjectile* projectile = new ParticleProjectile(this,this);
    6970            //projectile->setColour(this->getProjectileColour());
    7071        }
  • code/branches/weapon2/src/orxonox/tools/BillboardSet.h

    r2087 r2232  
    5252            inline Ogre::BillboardSet* getBillboardSet()
    5353                { return this->billboardSet_; }
     54            inline Ogre::SceneManager* getSceneManager()
     55                { return this->scenemanager_; }
    5456
    5557            const std::string& getName() const;
Note: See TracChangeset for help on using the changeset viewer.