Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2379


Ignore:
Timestamp:
Dec 10, 2008, 2:38:33 PM (15 years ago)
Author:
polakma
Message:

changed Weapon::fire and munition reloading

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

Legend:

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

    r2232 r2379  
    4646    }
    4747
    48     unsigned int Munition::getBullets()
    49     { return this->bullets_; }
     48    bool Munition::bullets()
     49    {
     50        if (this->bullets_ > 0)
     51            return true;
     52        else
     53            return false;
     54    }
    5055
    51     unsigned int Munition::getMagazines()
    52     { return this->magazines_; }
     56    bool Munition::magazines()
     57    {
     58        if (this->magazines_ > 0)
     59            return true;
     60        else
     61            return false;
     62    }
    5363
    5464    void Munition::setMaxBullets(unsigned int amount)
     
    6070    void Munition::removeBullets(unsigned int amount, Weapon * parentWeapon)
    6171    {
    62         //if actual magazine is empty, decrement it and set the bullets amount to full (masBullets_)
    6372        if ( this->bullets_ == 0 )
    6473        {
    6574            this->removeMagazines(1);
    66             parentWeapon->magazineTimer();
     75            parentWeapon->magazineTimer(0);
    6776            this->bullets_ = this->maxBullets_;
    6877        }
     
    8594        }
    8695        else
    87             this->magazines_ = this->magazines_ - amount; }
     96            this->magazines_ = this->magazines_ - amount;
     97    }
    8898
    8999    void Munition::addBullets(unsigned int amount)
     
    108118
    109119
     120    void Munition::fillBullets()
     121    {
     122        this->bullets_ = this->maxBullets_;
     123    }
     124   
     125    void Munition::fillMagazines()
     126    {
     127        this->magazines_ = this->maxMagazines_;
     128    }
     129   
    110130    void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    111131    {
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Munition.h

    r2337 r2379  
    5050            void setMaxMagazines(unsigned int amount);
    5151
    52             unsigned int getBullets();
    53             unsigned int getMagazines();
     52            void fillBullets();
     53            void fillMagazines();
     54
     55            bool bullets();
     56            bool magazines();
    5457
    5558            void removeBullets(unsigned int k, Weapon * parentWeapon);
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.cc

    r2366 r2379  
    6060    }
    6161
     62    void Weapon::setWeapon()
     63    {
     64        this->bulletLoadingTime_ = 0.5;
     65        this->magazineLoadingTime_ = 3.0;
     66        this->munition_->setMaxMagazines(100);
     67        this->munition_->setMaxBullets(30);
     68        this->munition_->fillBullets();
     69        this->munition_->fillMagazines();
     70    }
     71
     72
    6273    void Weapon::fire()
    6374    {
     75COUT(0) << "LaserGun::fire, this=" << this << std::endl;
     76        if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ )
     77        {
     78COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
     79
     80            this->bulletReadyToShoot_ = false;
     81            if ( this->munition_->bullets() )
     82            {
     83                //shoot
     84                this->takeBullets();
     85                this->createProjectile();
     86            }
     87            //if there are no bullets, but magazines
     88            else if ( this->munition_->magazines() && !this->munition_->bullets() )
     89            {
     90                this->takeMagazines();
     91            }
     92        }
     93        else
     94        {
     95COUT(0) << "LaserGun::fire - weapon not reloaded" << std::endl;
     96        }
    6497
    6598    }
    6699
    67100
    68     void Weapon::bulletTimer()
     101    void Weapon::bulletTimer(float bulletLoadingTime)
    69102    {
    70         this->bulletReloadTimer_.setTimer( this->bulletLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
     103COUT(0) << "Weapon::bulletTimer started" << std::endl;
     104        this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
    71105    }
    72     void Weapon::magazineTimer()
     106    void Weapon::magazineTimer(float magazineLoadingTime)
    73107    {
    74         this->magazineReloadTimer_.setTimer( this->magazineLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
     108COUT(0) << "Weapon::magazineTimer started" << std::endl;
     109        this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
    75110    }
    76111
     
    79114
    80115    void Weapon::magazineReloaded()
    81     { this->magazineReadyToShoot_ = true; }
     116    {
     117        this->munition_->fillBullets();
     118        this->magazineReadyToShoot_ = true;
     119    }
    82120
    83121
     
    104142
    105143
    106     /*get and set functions
     144     /*get and set functions
    107145     *
    108146     */
     
    123161return this->munition_; }
    124162
     163
     164
    125165    void Weapon::setBulletLoadingTime(float loadingTime)
    126166    {   this->bulletLoadingTime_ = loadingTime;   }
     
    135175    {   return this->magazineLoadingTime_;  }
    136176
    137     void Weapon::setBulletReadyToShoot(bool b)
    138     {   this->bulletReadyToShoot_ = b;   }
    139 
    140     bool Weapon::getBulletReadyToShoot()
    141     {   return this->bulletReadyToShoot_;    }
    142 
    143     void Weapon::setMagazineReadyToShoot(bool b)
    144     {   this->magazineReadyToShoot_ = b;   }
    145 
    146     bool Weapon::getMagazineReadyToShoot()
    147     {   return this->magazineReadyToShoot_;    }
    148177
    149178    Timer<Weapon> * Weapon::getBulletTimer()
     
    152181    Timer<Weapon> * Weapon::getMagazineTimer()
    153182    {   return &this->magazineReloadTimer_;   }
     183
     184    void Weapon::takeBullets() { };
     185    void Weapon::createProjectile() { };
     186    void Weapon::takeMagazines() { };
     187
    154188}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/Weapon.h

    r2366 r2379  
    5555
    5656            //reloading
    57             void bulletTimer();
    58             void magazineTimer();
     57            void bulletTimer(float bulletLoadingTime);
     58            void magazineTimer(float magazineLoadingTime);
    5959            void bulletReloaded();
    6060            void magazineReloaded();
     
    6363            void setMagazineLoadingTime(float loadingTime);
    6464            float getMagazineLoadingTime();
    65             void setBulletReadyToShoot(bool b);
    66             bool getBulletReadyToShoot();
    67             void setMagazineReadyToShoot(bool b);
    68             bool getMagazineReadyToShoot();
    6965            Timer<Weapon> *getBulletTimer();
    7066            Timer<Weapon> *getMagazineTimer();
     
    7268            virtual void setMunitionType(std::string munitionType);
    7369            virtual const std::string getMunitionType();
     70
     71            virtual void takeBullets();
     72            virtual void takeMagazines();
     73            virtual void createProjectile();
    7474
    7575            inline void setParentWeaponSlot(WeaponSlot *parentWeaponSlot)
     
    8181            inline WeaponSystem * getParentWeaponSystem()
    8282                { return this->parentWeaponSystem_; };
     83
     84            //in future by XMLPort,
     85            virtual void setWeapon();
    8386
    8487        private:
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc

    r2272 r2379  
    8585        if (!this->isActive())
    8686            return;
    87 
     87/*
    8888        float radius;
    8989        for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it)
     
    114114            }
    115115        }
     116*/
    116117    }
    117118
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc

    r2366 r2379  
    5050    }
    5151
    52     void LaserGun::fire()
     52    void LaserGun::takeBullets()
    5353    {
    54 COUT(0) << "LaserGun::fire, this=" << this << std::endl;
    55         if ( this->getBulletReadyToShoot() && this->getMagazineReadyToShoot() )
    56         {
    57 COUT(0) << "LaserGun::fire - ready to shoot" << std::endl;
    58             //take munition
    59             this->setBulletReadyToShoot(false);
    60             Weapon::bulletTimer();
    61             this->getAttachedMunition(this->munitionType_)->removeBullets(1,this);
    62 
    63             //create projectile
    64             BillboardProjectile* projectile = new ParticleProjectile(this);
    65             projectile->setOrientation(projectile->getOrientation());
    66             projectile->setPosition(projectile->getWorldPosition());
    67             projectile->setVelocity(WorldEntity::FRONT * this->speed_);
    68 
    69             //projectile->setColour(this->getProjectileColour());
    70         }
    71         else
    72         {
    73             //actions, when weapon is not reloaded if there are some
    74         }
     54        this->munition_->removeBullets(1,this);
     55        this->bulletTimer(this->bulletLoadingTime_);
    7556    }
    7657
     58    void LaserGun::takeMagazines()
     59    {
     60        this->munition_->removeMagazines(1);
     61        this->magazineTimer(this->magazineLoadingTime_);
     62    }
     63
     64    void LaserGun::createProjectile()
     65    {
     66        BillboardProjectile* projectile = new ParticleProjectile(this);
     67        projectile->setOrientation(projectile->getOrientation());
     68        projectile->setPosition(projectile->getWorldPosition());
     69        projectile->setVelocity(WorldEntity::FRONT * this->speed_);
     70    }
    7771}
  • code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h

    r2366 r2379  
    4747            LaserGun(BaseObject* creator);
    4848            virtual ~LaserGun();
    49 
    50             void fire();
     49           
     50            virtual void takeBullets();
     51            virtual void takeMagazines();
     52            virtual void createProjectile();
    5153
    5254        private:
  • code/branches/weapon2/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2366 r2379  
    5353        this->lastHitOriginator_ = 0;
    5454
    55         //WeaponSystem
    5655        weaponSystem_ = new WeaponSystem(this);
    57         /*
    58         WeaponSet * weaponSet1 = new WeaponSet(this,1);
    59         this->weaponSystem_->attachWeaponSet(weaponSet1);
    60         //totally bad solution...
    61         weaponSet1->setParentWeaponSystem(weaponSystem_);
    62         */
    6356
    6457        this->registerVariables();
Note: See TracChangeset for help on using the changeset viewer.