Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 18, 2009, 6:14:52 PM (16 years ago)
Author:
landauf
Message:

Added many new features in the Munition class:

  • there are now 3 modes: a) every weapon has it's own magazine b) all weapons use the same magazin c) no magazines, just a big munition pool
  • the Munition class handles the reloading of the magazine

Split the Weapon class into Weapon and WeaponMode. WeaponMode creates the fire of the Weapon. A weapon can own several WeaponModes (for example primary and secondary fire). But it's also possible to have a weapon with several muzzles which all fire at the same time (there's a WeaponMode for each muzzle).

Renamed LaserGun to LaserFire and Fusion to FusionFire. They inherit now from WeaponMode.

Changed the code in the Weapon class to use the new Munition functionality.

Added ReplenishingMunition, a subclass of Munition that replenishes itself (used for LaserGunMunition).

Added a reload command to reload magazines.

Location:
code/branches/weapons/src/orxonox/objects
Files:
4 added
2 deleted
25 edited
4 moved

Legend:

Unmodified
Added
Removed
  • code/branches/weapons/src/orxonox/objects/controllers/HumanController.cc

    r2912 r2918  
    4646    SetConsoleCommand(HumanController, rotateRoll,    true).setAsInputCommand();
    4747    SetConsoleCommand(HumanController, fire,          true).keybindMode(KeybindMode::OnHold);
     48    SetConsoleCommand(HumanController, reload,        true);
    4849    SetConsoleCommand(HumanController, boost,         true).keybindMode(KeybindMode::OnHold);
    4950    SetConsoleCommand(HumanController, greet,         true);
     
    114115    }
    115116
     117    void HumanController::reload()
     118    {
     119        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
     120            HumanController::localController_s->controllableEntity_->reload();
     121    }
     122
    116123    void HumanController::boost()
    117124    {
  • code/branches/weapons/src/orxonox/objects/controllers/HumanController.h

    r2912 r2918  
    5252
    5353            static void fire(unsigned int firemode);
     54            static void reload();
    5455
    5556            static void boost();
  • code/branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt

    r2915 r2918  
    22  Munition.cc
    33  Weapon.cc
     4  WeaponMode.cc
    45  WeaponPack.cc
    56  WeaponSet.cc
  • code/branches/weapons/src/orxonox/objects/weaponSystem/Munition.cc

    r2912 r2918  
    2020 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    2121 *
    22  *   Author:
     22 *   Authors:
    2323 *      Martin Polak
     24 *      Fabian 'x3n' Landau
    2425 *   Co-authors:
    2526 *      ...
     
    4041        RegisterObject(Munition);
    4142
     43        this->maxMunitionPerMagazine_ = 10;
     44        this->maxMagazines_ = 10;
     45        this->magazines_ = 10;
     46
     47        this->bUseSeparateMagazines_ = false;
     48        this->bStackMunition_ = true;
     49        this->bAllowMunitionRefilling_ = true;
     50        this->bAllowMultiMunitionRemovementUnderflow_ = true;
     51
     52        this->reloadTime_ = 0;
     53
    4254COUT(0) << "+Munition" << std::endl;
    4355    }
     
    4557    Munition::~Munition()
    4658    {
     59        for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)
     60            delete it->second;
     61
    4762COUT(0) << "~Munition" << std::endl;
    4863    }
    4964
    50     unsigned int Munition::bullets()
    51     {
    52         if (this->bullets_ > 0)
    53             return bullets_;
     65    Munition::Magazine* Munition::getMagazine(WeaponMode* user) const
     66    {
     67        if (this->bUseSeparateMagazines_)
     68        {
     69            // For separated magazines we definitively need a given user
     70            if (!user)
     71                return 0;
     72
     73            // Use the map to get the magazine assigned to the given user
     74            std::map<WeaponMode*, Magazine*>::const_iterator it = this->currentMagazines_.find(user);
     75            if (it != this->currentMagazines_.end())
     76                return it->second;
     77        }
     78        else
     79        {
     80            // We don't use separate magazines for each user, so just take the first magazine
     81            if (this->currentMagazines_.size() > 0)
     82                return this->currentMagazines_.begin()->second;
     83        }
     84
     85        return 0;
     86    }
     87
     88    unsigned int Munition::getNumMunition(WeaponMode* user) const
     89    {
     90        Magazine* magazine = this->getMagazine(user);
     91        if (magazine)
     92        {
     93            if (this->bStackMunition_)
     94                // With stacked munition every magazine contributes to the total amount
     95                return this->maxMunitionPerMagazine_ * this->magazines_ + magazine->munition_;
     96            else
     97                // Wihtout stacked munition we just consider the current magazine
     98                return magazine->munition_;
     99        }
     100        return 0;
     101    }
     102
     103    unsigned int Munition::getNumMunitionInCurrentMagazine(WeaponMode* user) const
     104    {
     105        // In contrast to getNumMunition() we really just consider the current magazine, even if we're stacking munition
     106        Magazine* magazine = this->getMagazine(user);
     107        if (magazine)
     108            return magazine->munition_;
    54109        else
    55110            return 0;
    56111    }
    57112
    58     unsigned int Munition::magazines()
    59     {
    60         if (this->magazines_ > 0)
    61             return magazines_;
    62         else
    63             return 0;
    64     }
    65 
    66     void Munition::setMaxBullets(unsigned int amount)
    67     { this->maxBullets_ = amount; }
    68 
    69     void Munition::setMaxMagazines(unsigned int amount)
    70     { this->maxMagazines_ = amount; }
    71 
    72     void Munition::removeBullets(unsigned int amount)
    73     {
    74         if ( this->bullets_ != 0 )
    75             this->bullets_ = this->bullets_ - amount;
    76     }
    77 
    78     void Munition::removeMagazines(unsigned int amount)
    79     {
    80         if ( this->magazines_ != 0 )
    81             this->magazines_ = this->magazines_ - amount;
    82     }
    83 
    84     void Munition::addBullets(unsigned int amount)
    85     {
    86         if ( this->bullets_ == this->maxBullets_ )
    87         {
    88             //cannot add bullets to actual magazine
    89         }
    90         else
    91             this->bullets_ = this->bullets_ + amount;
    92     }
    93 
    94     void Munition::addMagazines(unsigned int amount)
    95     {
    96         if ( this->magazines_ == this->maxMagazines_ )
    97         {
    98             //no more capacity for another magazine
    99         }
    100         else
    101             this->magazines_ = this->magazines_ + amount;
    102     }
    103 
    104 
    105     void Munition::fillBullets()
    106     {
    107         this->bullets_ = this->maxBullets_;
    108     }
    109 
    110     void Munition::fillMagazines()
    111     {
    112         this->magazines_ = this->maxMagazines_;
     113    unsigned int Munition::getNumMagazines() const
     114    {
     115        if (this->bStackMunition_)
     116        {
     117            // If we stack munition and the current magazine is still full, it counts too
     118            Magazine* magazine = this->getMagazine(0);
     119            if (magazine && magazine->munition_ == this->maxMunitionPerMagazine_)
     120                return this->magazines_ + 1;
     121        }
     122
     123        return this->magazines_;
     124    }
     125
     126    unsigned int Munition::getMaxMunition() const
     127    {
     128        if (this->bStackMunition_)
     129            return this->maxMunitionPerMagazine_ * this->maxMagazines_;
     130        else
     131            return this->maxMunitionPerMagazine_;
     132    }
     133
     134    bool Munition::canTakeMunition(unsigned int amount, WeaponMode* user) const
     135    {
     136        Magazine* magazine = this->getMagazine(user);
     137        if (magazine && magazine->bLoaded_)
     138        {
     139            unsigned int munition = magazine->munition_;
     140
     141            // If we stack munition, we con't care about the current magazine - we just need enough munition in total
     142            if (this->bStackMunition_)
     143                munition += this->maxMunitionPerMagazine_ * this->magazines_;
     144
     145            if (munition == 0)
     146                // Absolutely no munition - no chance to take munition
     147                return false;
     148            else if (this->bAllowMultiMunitionRemovementUnderflow_)
     149                // We're not empty AND we allow underflow, so this will always work
     150                return true;
     151            else
     152                // We don't allow underflow, so we have to check the amount
     153                return (munition >= amount);
     154        }
     155        return false;
     156    }
     157
     158    bool Munition::takeMunition(unsigned int amount, WeaponMode* user)
     159    {
     160        if (!this->canTakeMunition(amount, user))
     161            return false;
     162
     163        Magazine* magazine = this->getMagazine(user);
     164        if (magazine && magazine->bLoaded_)
     165        {
     166            if (magazine->munition_ >= amount)
     167            {
     168                // Enough munition
     169                magazine->munition_ -= amount;
     170                return true;
     171            }
     172            else
     173            {
     174                // Not enough munition
     175                if (this->bStackMunition_)
     176                {
     177                    // We stack munition, so just take what we can and then load the next magazine
     178                    amount -= magazine->munition_;
     179                    magazine->munition_ = 0;
     180
     181                    if (this->reload(0))
     182                        // Successfully reloaded, continue recursively
     183                        return this->takeMunition(amount, 0);
     184                    else
     185                        // We don't have more magazines, so let's just hope we allow underflow
     186                        return this->bAllowMultiMunitionRemovementUnderflow_;
     187                }
     188                else
     189                {
     190                    // We don't stack, so we can only take munition if this is allowed
     191                    if (magazine->munition_ > 0 && this->bAllowMultiMunitionRemovementUnderflow_)
     192                    {
     193                        magazine->munition_ -= 0;
     194                        return true;
     195                    }
     196                }
     197            }
     198        }
     199        return false;
     200    }
     201
     202    bool Munition::canReload() const
     203    {
     204        // As long as we have enough magazines (and don't stack munition) we can reload
     205        return (this->magazines_ > 0 && !this->bStackMunition_);
     206    }
     207
     208    bool Munition::needReload(WeaponMode* user) const
     209    {
     210        Magazine* magazine = this->getMagazine(user);
     211        if (magazine)
     212        {
     213            if (this->bStackMunition_)
     214                // With stacked munition, we never have to reload
     215                return false;
     216            else
     217                // We need to reload if an already loaded magazine is empty
     218                return (magazine->bLoaded_ && magazine->munition_ == 0);
     219        }
     220        else
     221            // No magazine - we definitively need to reload
     222            return true;
     223    }
     224
     225    bool Munition::reload(WeaponMode* user, bool bUseReloadTime)
     226    {
     227        // Don't reload if we're already reloading
     228        Magazine* magazine = this->getMagazine(user);
     229        if (magazine && !magazine->bLoaded_)
     230            return false;
     231
     232        // Check if we actually can reload
     233        if (this->magazines_ == 0)
     234            return false;
     235
     236        // If we use separate magazines for each user, we definitively need a user given
     237        if (this->bUseSeparateMagazines_ && !user)
     238            return false;
     239
     240        // If we don't use separate magazines, set user to 0
     241        if (!this->bUseSeparateMagazines_)
     242            user = 0;
     243
     244        // Remove the current magazine for the given user
     245        std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user);
     246        if (it != this->currentMagazines_.end())
     247        {
     248            delete it->second;
     249            this->currentMagazines_.erase(it);
     250        }
     251
     252        // Load a new magazine
     253        this->currentMagazines_[user] = new Magazine(this, bUseReloadTime);
     254        this->magazines_--;
     255
     256        return true;
     257    }
     258
     259    bool Munition::canAddMunition(unsigned int amount) const
     260    {
     261        if (!this->bAllowMunitionRefilling_)
     262            return false;
     263
     264        if (this->bStackMunition_)
     265        {
     266            // If we stack munition, we can always add munition until we reach the limit
     267            return (this->getNumMunition(0) < this->getMaxMunition());
     268        }
     269        else
     270        {
     271            // Return true if any of the current magazines is not full (loading counts as full although it returns 0 munition)
     272            for (std::map<WeaponMode*, Magazine*>::const_iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)
     273                if (it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_)
     274                    return true;
     275        }
     276
     277        return false;
     278    }
     279
     280    bool Munition::addMunition(unsigned int amount)
     281    {
     282        if (!this->canAddMunition(amount))
     283            return false;
     284
     285        if (this->bStackMunition_)
     286        {
     287            // Stacking munition means, if a magazine gets full, the munition adds to a new magazine
     288            Magazine* magazine = this->getMagazine(0);
     289            if (magazine)
     290            {
     291                // Add the whole amount
     292                magazine->munition_ += amount;
     293
     294                // Add new magazines if the current magazine is overfull
     295                while (magazine->munition_ > this->maxMunitionPerMagazine_)
     296                {
     297                    magazine->munition_ -= this->maxMunitionPerMagazine_;
     298                    this->magazines_++;
     299                }
     300
     301                // If we reached the limit, reduze both magazines and munition to the maximum
     302                if (this->magazines_ >= this->maxMagazines_)
     303                {
     304                    this->magazines_ = this->maxMagazines_ - 1;
     305                    magazine->munition_ = this->maxMunitionPerMagazine_;
     306                }
     307
     308                return true;
     309            }
     310
     311            // Something went wrong
     312            return false;
     313        }
     314        else
     315        {
     316            // Share the munition equally to the current magazines
     317            while (amount > 0)
     318            {
     319                bool change = false;
     320                for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)
     321                {
     322                    // Add munition if the magazine isn't full (but only to loaded magazines)
     323                    if (amount > 0 && it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_)
     324                    {
     325                        it->second->munition_++;
     326                        amount--;
     327                        change = true;
     328                    }
     329                }
     330
     331                // If there was no change in a loop, all magazines are full (or locked due to loading)
     332                if (!change)
     333                    break;
     334            }
     335
     336            return true;
     337        }
     338    }
     339
     340    bool Munition::canAddMagazines(unsigned int amount) const
     341    {
     342        if (this->bStackMunition_)
     343            // If we stack munition, we can always add new magazines because they contribute directly to the munition
     344            return (this->getNumMunition(0) < this->getMaxMunition());
     345        else
     346            // If we don't stack munition, we're more limited
     347            return ((this->currentMagazines_.size() + this->magazines_) < this->maxMagazines_);
     348    }
     349
     350    bool Munition::addMagazines(unsigned int amount)
     351    {
     352        if (!this->canAddMagazines(amount))
     353            return false;
     354
     355        // Calculate how many magazines are needed
     356        int needed_magazines = this->maxMagazines_ - this->magazines_ - this->currentMagazines_.size();
     357
     358        // If zero or less magazines are needed, we definitively don't need more magazines (unless we stack munition - then a magazine contributes directly to the munition)
     359        if (needed_magazines <= 0 && !this->bStackMunition_)
     360            return false;
     361
     362        if (amount <= needed_magazines)
     363        {
     364            // We need more magazines than we get, so just add them
     365            this->magazines_ += amount;
     366        }
     367        else
     368        {
     369            // We get more magazines than we need, so just add the needed amount
     370            this->magazines_ += needed_magazines;
     371            if (this->bStackMunition_)
     372            {
     373                // We stack munition, so the additional amount contributes directly to the munition of the current magazine
     374                Magazine* magazine = this->getMagazine(0);
     375                if (magazine)
     376                    magazine->munition_ = this->maxMunitionPerMagazine_;
     377            }
     378        }
     379
     380        return true;
     381    }
     382
     383    bool Munition::canRemoveMagazines(unsigned int amount) const
     384    {
     385        if (this->bStackMunition_)
     386        {
     387            if (this->magazines_ >= amount)
     388            {
     389                // We have enough magazines
     390                return true;
     391            }
     392            else if (this->magazines_ == amount - 1)
     393            {
     394                // We lack one magazine, check if the current magazine is still full, if yes we're fine
     395                Magazine* magazine = this->getMagazine(0);
     396                if (magazine && magazine->munition_ == this->maxMunitionPerMagazine_)
     397                    return true;
     398            }
     399            else
     400            {
     401                // We don't have enough magazines
     402                return false;
     403            }
     404        }
     405        else
     406        {
     407            // In case we're not stacking munition, just check the number of magazines
     408            return (this->magazines_ >= amount);
     409        }
     410    }
     411
     412    bool Munition::removeMagazines(unsigned int amount)
     413    {
     414        if (!this->canRemoveMagazines(amount))
     415            return false;
     416
     417        if (this->magazines_ >= amount)
     418        {
     419            // We have enough magazines, just remove the amount
     420            this->magazines_ -= amount;
     421        }
     422        else if (this->bStackMunition_)
     423        {
     424            // We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine
     425            this->magazines_ = 0;
     426            Magazine* magazine = this->getMagazine(0);
     427            if (magazine)
     428                magazine->munition_ = 0;
     429        }
     430
     431        return true;
     432    }
     433
     434    bool Munition::dropMagazine(WeaponMode* user)
     435    {
     436        // If we use separate magazines, we need a user
     437        if (this->bUseSeparateMagazines_ && !user)
     438            return false;
     439
     440        // If we don't use separate magazines, set user to 0
     441        if (!this->bUseSeparateMagazines_)
     442            user = 0;
     443
     444        // Remove the current magazine for the given user
     445        std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user);
     446        if (it != this->currentMagazines_.end())
     447        {
     448            delete it->second;
     449            this->currentMagazines_.erase(it);
     450            return true;
     451        }
     452
     453        return false;
     454    }
     455
     456
     457    /////////////////////
     458    // Magazine struct //
     459    /////////////////////
     460    Munition::Magazine::Magazine(Munition* munition, bool bUseReloadTime)
     461    {
     462        this->munition_ = 0;
     463        this->bLoaded_ = false;
     464
     465        if (bUseReloadTime && (munition->reloadTime_ > 0 || munition->bStackMunition_))
     466        {
     467            ExecutorMember<Magazine>* executor = createExecutor(createFunctor(&Magazine::loaded));
     468            executor->setDefaultValues(munition);
     469
     470            this->loadTimer_.setTimer(munition->reloadTime_, false, this, executor);
     471        }
     472        else
     473            this->loaded(munition);
     474    }
     475
     476    void Munition::Magazine::loaded(Munition* munition)
     477    {
     478        this->bLoaded_ = true;
     479        this->munition_ = munition->maxMunitionPerMagazine_;
    113480    }
    114481}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/Munition.h

    r2912 r2918  
    2020 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    2121 *
    22  *   Author:
     22 *   Authors:
    2323 *      Martin Polak
     24 *      Fabian 'x3n' Landau
    2425 *   Co-authors:
    2526 *      ...
     
    3132
    3233#include "OrxonoxPrereqs.h"
     34
     35#include <map>
     36
    3337#include "core/BaseObject.h"
     38#include "tools/Timer.h"
    3439
    3540namespace orxonox
     
    3742    class _OrxonoxExport Munition : public BaseObject
    3843    {
     44        struct Magazine
     45        {
     46            public:
     47                Magazine(Munition* munition, bool bUseReloadTime = true);
     48
     49                unsigned int munition_;
     50                Timer<Magazine> loadTimer_;
     51                bool bLoaded_;
     52
     53            private:
     54                void loaded(Munition* munition);
     55        };
     56
    3957        public:
    4058            Munition(BaseObject* creator);
    4159            virtual ~Munition();
    4260
    43             void setMaxBullets(unsigned int amount);
    44             void setMaxMagazines(unsigned int amount);
     61            unsigned int getNumMunition(WeaponMode* user) const;
     62            unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const;
     63            unsigned int getNumMagazines() const;
    4564
    46             void fillBullets();
    47             void fillMagazines();
     65            unsigned int getMaxMunition() const;
     66            inline unsigned int getMaxMagazines() const
     67                { return this->maxMagazines_; }
     68            inline unsigned int getMaxMunitionPerMagazine() const
     69                { return this->maxMunitionPerMagazine_; }
    4870
    49             unsigned int bullets();
    50             unsigned int magazines();
     71            bool canTakeMunition(unsigned int amount, WeaponMode* user) const;
     72            bool takeMunition(unsigned int amount, WeaponMode* user);
    5173
    52             void removeBullets(unsigned int k);
    53             void removeMagazines(unsigned int k);
    54             void addBullets(unsigned int k);
    55             void addMagazines(unsigned int k);
     74            bool canReload() const;
     75            bool needReload(WeaponMode* user) const;
     76            bool reload(WeaponMode* user, bool bUseReloadTime = true);
     77            inline float getReloadTime() const
     78                { return this->reloadTime_; }
     79
     80            bool canAddMunition(unsigned int amount) const;
     81            bool addMunition(unsigned int amount);
     82
     83            bool canAddMagazines(unsigned int amount) const;
     84            bool addMagazines(unsigned int amount);
     85
     86            bool canRemoveMagazines(unsigned int amount) const;
     87            bool removeMagazines(unsigned int amount);
     88
     89            bool dropMagazine(WeaponMode* user);
     90
     91        protected:
     92            unsigned int maxMunitionPerMagazine_;
     93            unsigned int maxMagazines_;
     94            unsigned int magazines_;
     95            std::map<WeaponMode*, Magazine*> currentMagazines_;
     96
     97            bool bUseSeparateMagazines_;
     98            bool bStackMunition_;
     99            bool bAllowMunitionRefilling_;
     100            bool bAllowMultiMunitionRemovementUnderflow_;
     101
     102            float reloadTime_;
    56103
    57104        private:
    58 
    59         protected:
    60             unsigned int bullets_;
    61             unsigned int magazines_;
    62             unsigned int maxBullets_;
    63             unsigned int maxMagazines_;
     105            Magazine* getMagazine(WeaponMode* user) const;
    64106    };
    65107}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc

    r2915 r2918  
    2222 *   Author:
    2323 *      Martin Polak
     24 *      Fabian 'x3n' Landau
    2425 *   Co-authors:
    2526 *      ...
     
    3334#include "core/XMLPort.h"
    3435
    35 #include "Munition.h"
     36#include "WeaponMode.h"
    3637#include "WeaponPack.h"
    3738#include "WeaponSystem.h"
     
    4546        RegisterObject(Weapon);
    4647
    47         this->bulletReadyToShoot_ = true;
    48         this->magazineReadyToShoot_ = true;
    49         this->weaponSystem_ = 0;
    5048        this->weaponPack_ = 0;
    5149        this->weaponSlot_ = 0;
    52         this->bulletLoadingTime_ = 0;
    53         this->magazineLoadingTime_ = 0;
    5450        this->bReloading_ = false;
    55         this->bulletAmount_= 0;
    56         this->magazineAmount_ = 0;
    57         this->munition_ = 0;
    58         this->unlimitedMunition_ = false;
    59         this->setObjectMode(0x0);
     51        this->reloadingWeaponmode_ = WeaponSystem::WEAPON_MODE_UNASSIGNED;
     52
     53        this->reloadTimer_.setTimer(0.0f, false, this, createExecutor(createFunctor(&Weapon::reloaded)));
     54        this->reloadTimer_.stopTimer();
    6055
    6156COUT(0) << "+Weapon" << std::endl;
     
    6560    {
    6661COUT(0) << "~Weapon" << std::endl;
    67         if (this->isInitialized() && this->weaponPack_)
    68             this->weaponPack_->removeWeapon(this);
     62
     63        if (this->isInitialized())
     64        {
     65            if (this->weaponPack_)
     66                this->weaponPack_->removeWeapon(this);
     67
     68            for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
     69                delete it->second;
     70        }
    6971    }
    7072
     
    7375        SUPER(Weapon, XMLPort, xmlelement, mode);
    7476
    75         XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode);
    76         XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode);
    77         XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode);
    78         XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode);
    79         XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode);
    80         XMLPortParam(Weapon, "unlimitedMunition", setUnlimitedMunition, getUnlimitedMunition, xmlelement, mode);
     77        XMLPortObject(Weapon, WeaponMode, "", addWeaponmode, getWeaponmode, xmlelement, mode);
    8178    }
    8279
    83     void Weapon::setWeapon()
     80    void Weapon::addWeaponmode(WeaponMode* weaponmode)
    8481    {
    85         this->munition_->fillBullets();
    86         this->munition_->fillMagazines();
     82        if (!weaponmode)
     83            return;
     84
     85        this->weaponmodes_.insert(std::pair<unsigned int, WeaponMode*>(weaponmode->getMode(), weaponmode));
     86        weaponmode->setWeapon(this);
    8787    }
    8888
    89     void Weapon::setMunition()
     89    WeaponMode* Weapon::getWeaponmode(unsigned int index) const
    9090    {
    91         this->munition_->setMaxBullets(this->bulletAmount_);
    92         this->munition_->setMaxMagazines(this->magazineAmount_);
     91        unsigned int i = 0;
     92        for (std::multimap<unsigned int, WeaponMode*>::const_iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
     93        {
     94            if (i == index)
     95                return it->second;
     96
     97            ++i;
     98        }
     99        return 0;
    93100    }
    94101
    95     void Weapon::fire()
     102    void Weapon::fire(unsigned int mode)
    96103    {
    97         if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_)
     104        // To avoid firing with more than one mode at the same time, we lock the weapon (reloading) for
     105        // all modes except the one which is currently reloading.
     106        //
     107        // Example:
     108        // WeaponMode A -> mode 0
     109        // WeaponMode B -> mode 0
     110        // WeaponMode C -> mode 1
     111        //
     112        // -> A and B can fire at the same time, but C has to wait until both (A and B) have reloaded
     113        // -> If C fires, A and B have to wait until C has reloaded
     114        //
     115        // Note: The reloading of each WeaponMode is internally handled by each A, B and C.
     116        //       The reloading of the weapon is only performed to avoid firing with different modes at the same time.
     117        if (this->bReloading_ && this->reloadingWeaponmode_ != mode)
     118            return;
     119
     120        std::multimap<unsigned int, WeaponMode*>::iterator start = this->weaponmodes_.lower_bound(mode);
     121        std::multimap<unsigned int, WeaponMode*>::iterator end   = this->weaponmodes_.upper_bound(mode);
     122
     123        for (std::multimap<unsigned int, WeaponMode*>::iterator it = start; it != end; ++it)
    98124        {
    99             this->bulletReadyToShoot_ = false;
    100             if ( this->unlimitedMunition_== true )
     125            float reloading_time = 0;
     126            if (it->second->fire(&reloading_time))
    101127            {
    102                 //shoot
    103                 this->reloadBullet();
    104                 this->createProjectile();
    105             }
    106             else
    107             {
    108                 if ( this->munition_->bullets() > 0)
    109                 {
    110                     //shoot and reload
    111                     this->takeBullets();
    112                     this->reloadBullet();
    113                     this->createProjectile();
    114                 }
    115                 //if there are no bullets, but magazines
    116                 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 )
    117                 {
    118                     //reload magazine
    119                     this->takeMagazines();
    120                     this->reloadMagazine();
    121                 }
    122                 else
    123                 {
    124                     //no magazines
    125                 }
    126             }
    127         }
    128         else
    129         {
    130             //weapon not reloaded
    131         }
     128                this->bReloading_ = true;
     129                this->reloadingWeaponmode_ = mode;
    132130
    133     }
    134 
    135 
    136     //weapon reloading
    137     void Weapon::bulletTimer(float bulletLoadingTime)
    138     {
    139         this->bReloading_ = true;
    140         this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded)));
    141     }
    142     void Weapon::magazineTimer(float magazineLoadingTime)
    143     {
    144         this->bReloading_ = true;
    145         this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded)));
    146     }
    147 
    148     void Weapon::bulletReloaded()
    149     {
    150         this->bReloading_ = false;
    151         this->bulletReadyToShoot_ = true;
    152     }
    153 
    154     void Weapon::magazineReloaded()
    155     {
    156         this->bReloading_ = false;
    157         this->munition_->fillBullets();
    158     }
    159 
    160 
    161 
    162     void Weapon::attachNeededMunition(const std::string& munitionName)
    163     {
    164         /*  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
    165         */
    166         if (this->weaponSystem_)
    167         {
    168             //getMunitionType returns 0 if there is no such munitionType
    169             Munition* munition = this->weaponSystem_->getMunitionType(munitionName);
    170             if ( munition )
    171             {
    172                 this->munition_ = munition;
    173                 this->setMunition();
    174             }
    175             else
    176             {
    177                 //create new munition with identifier because there is no such munitionType
    178                 this->munitionIdentifier_ = ClassByString(munitionName);
    179                 this->munition_ = this->munitionIdentifier_.fabricate(this);
    180                 this->weaponSystem_->setNewMunition(munitionName, this->munition_);
    181                 this->setMunition();
     131                this->reloadTimer_.setInterval(reloading_time);
     132                this->reloadTimer_.startTimer();
    182133            }
    183134        }
    184135    }
    185136
    186 
    187     Munition * Weapon::getAttachedMunition(const std::string& munitionType)
     137    void Weapon::reload()
    188138    {
    189         this->munition_ = this->weaponSystem_->getMunitionType(munitionType);
    190         return this->munition_;
     139        for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
     140            it->second->reload();
    191141    }
    192142
     143    void Weapon::reloaded()
     144    {
     145        this->bReloading_ = false;
     146        this->reloadingWeaponmode_ = WeaponSystem::WEAPON_MODE_UNASSIGNED;
     147    }
    193148
    194     //these function are defined in the weapon classes
    195     void Weapon::takeBullets() { };
    196     void Weapon::createProjectile() { };
    197     void Weapon::takeMagazines() { };
    198     void Weapon::reloadBullet() { };
    199     void Weapon::reloadMagazine() { };
    200 
    201 
    202     //get and set functions for XMLPort
    203     void Weapon::setMunitionType(const std::string& munitionType)
    204     {   this->munitionType_ = munitionType; }
    205 
    206     const std::string& Weapon::getMunitionType() const
    207     {   return this->munitionType_;  }
    208 
    209     void Weapon::setBulletLoadingTime(float loadingTime)
    210     {   this->bulletLoadingTime_ = loadingTime; }
    211 
    212     const float Weapon::getBulletLoadingTime() const
    213     {   return this->bulletLoadingTime_;  }
    214 
    215     void Weapon::setMagazineLoadingTime(float loadingTime)
    216     {   this->magazineLoadingTime_ = loadingTime; }
    217 
    218     const float Weapon::getMagazineLoadingTime() const
    219     {   return this->magazineLoadingTime_;  }
    220 
    221     void Weapon::setBulletAmount(unsigned int amount)
    222     {   this->bulletAmount_ = amount; }
    223 
    224     const unsigned int Weapon::getBulletAmount() const
    225     {   return this->bulletAmount_;  }
    226 
    227     void Weapon::setMagazineAmount(unsigned int amount)
    228     {   this->magazineAmount_ = amount; }
    229 
    230     const unsigned int Weapon::getMagazineAmount() const
    231     {   return this->magazineAmount_;   }
    232 
    233     void Weapon::setUnlimitedMunition(bool unlimitedMunition)
    234     {   this->unlimitedMunition_ = unlimitedMunition;   }
    235 
    236     const bool Weapon::getUnlimitedMunition() const
    237     {   return this->unlimitedMunition_;    }
    238 
     149    void Weapon::notifyWeaponModes()
     150    {
     151        for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
     152            it->second->setWeapon(this);
     153    }
    239154}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.h

    r2914 r2918  
    2222 *   Author:
    2323 *      Martin Polak
     24 *      Fabian 'x3n' Landau
    2425 *   Co-authors:
    2526 *      ...
     
    3435
    3536#include "tools/Timer.h"
    36 #include "core/Identifier.h"
    3737
    3838namespace orxonox
     
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4747
    48             virtual void fire();
    49             void attachNeededMunition(const std::string& munitionType);
    50             Munition * getAttachedMunition(const std::string& munitiontype);
     48            void fire(unsigned int mode);
     49            void reload();
    5150
    52             //reloading
    53             void bulletTimer(float bulletLoadingTime);
    54             void magazineTimer(float magazineLoadingTime);
    55             void bulletReloaded();
    56             void magazineReloaded();
     51            void addWeaponmode(WeaponMode* weaponmode);
     52            WeaponMode* getWeaponmode(unsigned int index) const;
    5753
    58             //XMLPort functions
    59             virtual void setMunitionType(const std::string& munitionType);
    60             virtual const std::string& getMunitionType() const;
    61             virtual void setBulletLoadingTime(float loadingTime);
    62             virtual const float getBulletLoadingTime() const;
    63             virtual void setMagazineLoadingTime(float loadingTime);
    64             virtual const float getMagazineLoadingTime() const;
    65             virtual void setBulletAmount(unsigned int amount);
    66             virtual const unsigned int getBulletAmount() const;
    67             virtual void setMagazineAmount(unsigned int amount);
    68             virtual const unsigned int getMagazineAmount() const;
    69             virtual void setUnlimitedMunition(bool unlimitedMunition);
    70             virtual const bool getUnlimitedMunition() const;
    71 
    72             //weapon actions
    73             virtual void takeBullets();
    74             virtual void takeMagazines();
    75             virtual void createProjectile();
    76             virtual void reloadBullet();
    77             virtual void reloadMagazine();
    78 
    79             //manually set or reset
    80             virtual void setWeapon();
    81             virtual void setMunition();
    82 
    83             inline void setWeaponSystem(WeaponSystem *weaponSystem)
    84                 { this->weaponSystem_ = weaponSystem; };
    85             inline WeaponSystem * getWeaponSystem() const
    86                 { return this->weaponSystem_; };
    87 
    88             inline void setWeaponPack(WeaponPack *weaponPack)
    89                 { this->weaponPack_ = weaponPack; };
     54            inline void setWeaponPack(WeaponPack * weaponPack)
     55                { this->weaponPack_ = weaponPack; this->notifyWeaponModes(); }
    9056            inline WeaponPack * getWeaponPack() const
    91                 { return this->weaponPack_; };
     57                { return this->weaponPack_; }
    9258
    9359            inline void setWeaponSlot(WeaponSlot * wSlot)
     
    9662                { return this->weaponSlot_; }
    9763
    98         protected:
     64        private:
     65            void reloaded();
     66            void notifyWeaponModes();
     67
     68            WeaponPack* weaponPack_;
     69            WeaponSlot* weaponSlot_;
     70            std::multimap<unsigned int, WeaponMode*> weaponmodes_;
     71
     72            Timer<Weapon> reloadTimer_;
    9973            bool bReloading_;
    100             bool bulletReadyToShoot_;
    101             bool magazineReadyToShoot_;
    102             bool unlimitedMunition_;
    103             float bulletLoadingTime_;
    104             float magazineLoadingTime_;
    105             unsigned int bulletAmount_;
    106             unsigned int magazineAmount_;
    107             std::string munitionType_;
    108 
    109             WeaponSlot * weaponSlot_;
    110             Munition * munition_;
    111             WeaponSystem * weaponSystem_;
    112             WeaponPack* weaponPack_;
    113 
    114             SubclassIdentifier<Munition> munitionIdentifier_;
    115 
    116             Timer<Weapon> bulletReloadTimer_;
    117             Timer<Weapon> magazineReloadTimer_;
     74            unsigned int reloadingWeaponmode_;
    11875    };
    11976}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc

    r2915 r2918  
    7272        SUPER(WeaponPack, XMLPort, xmlelement, mode);
    7373
    74         XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);
     74        XMLPortObjectExtended(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode, false, false);
    7575        XMLPortObject(WeaponPack, DefaultWeaponmodeLink, "links", addDefaultWeaponmodeLink, getDefaultWeaponmodeLink, xmlelement, mode);
    7676    }
     
    7979    {
    8080        for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    81             (*it)->fire();
     81            (*it)->fire(weaponmode);
     82    }
     83
     84    void WeaponPack::reload()
     85    {
     86        for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     87            (*it)->reload();
    8288    }
    8389
     
    114120    }
    115121
    116     void WeaponPack::setWeaponSystemToAllWeapons()
    117     {
    118         for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    119             (*it)->setWeaponSystem(this->weaponSystem_);
    120     }
    121 
    122     void WeaponPack::attachNeededMunitionToAllWeapons()
    123     {
    124         for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    125         {
    126             (*it)->attachNeededMunition((*it)->getMunitionType());
    127             (*it)->setWeapon();
    128         }
    129     }
    130 
    131122    void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link)
    132123    {
     
    155146        return WeaponSystem::WEAPON_MODE_UNASSIGNED;
    156147    }
     148
     149    void WeaponPack::notifyWeapons()
     150    {
     151        for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     152            (*it)->setWeaponPack(this);
     153    }
    157154}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h

    r2915 r2918  
    4848
    4949            void fire(unsigned int weaponmode);
     50            void reload();
    5051
    5152            void addWeapon(Weapon * weapon);
     
    6162            unsigned int getDesiredWeaponmode(unsigned int firemode) const;
    6263
    63             inline void setWeaponSystem(WeaponSystem *weaponSystem)
    64             {
    65                 this->weaponSystem_ = weaponSystem;
    66                 this->setWeaponSystemToAllWeapons();
    67                 this->attachNeededMunitionToAllWeapons();
    68             }
     64            inline void setWeaponSystem(WeaponSystem * weaponSystem)
     65                { this->weaponSystem_ = weaponSystem; this->notifyWeapons(); }
    6966            inline WeaponSystem * getWeaponSystem() const
    7067                { return this->weaponSystem_; }
    7168
    7269        private:
    73             void setWeaponSystemToAllWeapons();
    74             void attachNeededMunitionToAllWeapons();
     70            void notifyWeapons();
    7571
    7672            std::set<Weapon *> weapons_;
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc

    r2915 r2918  
    6464        XMLPortParam(WeaponSet, "firemode", setDesiredFiremode, getDesiredFiremode, xmlelement, mode);
    6565    }
    66 /*
    67     void WeaponSet::attachWeaponPack(WeaponPack *wPack)
    68     {
    69         if ( this->weaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->weaponSystem_->getWeaponSlotSize() ) )
    70         {
    71             this->attachedWeaponPack_ = wPack;
    72             int wPackWeapon = 0;    //WeaponCounter for Attaching
    73 
    74             //should be possible to choose which slot to use
    75             //attach every weapon of the weaponPack to a weaponSlot
    76             for (  int i=0; i < wPack->getSize() ; i++  )
    77             {
    78                 //at the moment this function only works for one weaponPack in the entire WeaponSystem...
    79                 //it also takes the first free weaponSlot...
    80                 if ( this->weaponSystem_->getWeaponSlot(i)->getAttachedWeapon() == 0 && this->weaponSystem_->getWeaponSlot(i) != 0) //if slot not full
    81                 {
    82                     this->setWeaponSlots_.push_back( this->weaponSystem_->getWeaponSlot(i) );
    83                     this->weaponSystem_->getWeaponSlot(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
    84                     this->weaponSystem_->getPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );
    85                     wPackWeapon++;
    86                 }
    87                 else
    88                 {
    89                     for (int k=0; k < this->weaponSystem_->getWeaponSlotSize(); k++)
    90                     {
    91                         if ( this->weaponSystem_->getWeaponSlot(k)->getAttachedWeapon() == 0 )
    92                         {
    93                             this->setWeaponSlots_.push_back( this->weaponSystem_->getWeaponSlot(k) );
    94                             this->weaponSystem_->getWeaponSlot(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );
    95                             this->weaponSystem_->getPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );
    96                             wPackWeapon++;
    97                         }
    98                     }
    99                 }
    100             }
    101         }
    102     }
    103 */
    10466
    10567    void WeaponSet::fire()
     
    10971            if (it->second != WeaponSystem::WEAPON_MODE_UNASSIGNED)
    11072                it->first->fire(it->second);
     73    }
     74
     75    void WeaponSet::reload()
     76    {
     77        // fire all WeaponPacks with their defined weaponmode
     78        for (std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.begin(); it != this->weaponpacks_.end(); ++it)
     79            it->first->reload();
    11180    }
    11281
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.h

    r2914 r2918  
    4747            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4848
    49 //            void attachWeaponPack(WeaponPack *wPack);
    50 
    5149            void fire();
     50            void reload();
    5251
    5352            void setWeaponmodeLink(WeaponPack* weaponpack, unsigned int weaponmode);
     
    6665
    6766        private:
    68             WeaponSystem *weaponSystem_;
     67            WeaponSystem * weaponSystem_;
    6968            unsigned int desiredFiremode_;
    7069            std::map<WeaponPack*, unsigned int> weaponpacks_;
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSlot.cc

    r2914 r2918  
    6464        SUPER(WeaponSlot, XMLPort, xmlelement, mode);
    6565
    66         // ...
     66        // In the future, there might be parameters like allowed weapon types or max size of the weapon
    6767    }
    6868
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc

    r2915 r2918  
    3737#include "WeaponSet.h"
    3838#include "Weapon.h"
     39#include "Munition.h"
    3940
    4041/* WeaponSystem
     
    6364                this->pawn_->setWeaponSystem(0);
    6465
    65 //            for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )
    66 //                delete (it++)->second;
    6766            while (!this->weaponSets_.empty())
    6867                delete (this->weaponSets_.begin()->second);
    6968
    70 //            for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )
    71 //                delete (*(it++));
    7269            while (!this->weaponPacks_.empty())
    7370                delete (*this->weaponPacks_.begin());
    7471
    75 //            for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )
    76 //                delete (*(it++));
    7772            while (!this->weaponSlots_.empty())
    7873                delete (*this->weaponSlots_.begin());
     74
     75            while (!this->munitions_.empty())
     76                { delete (this->munitions_.begin()->second); this->munitions_.erase(this->munitions_.begin()); }
    7977        }
    8078    }
     
    284282    }
    285283
    286     void WeaponSystem::setNewMunition(const std::string& munitionType, Munition * munitionToAdd)
    287     {
    288         this->munitionSet_[munitionType] = munitionToAdd;
    289     }
    290 
    291 
    292     //returns the Pointer to the munitionType, if this munitionType doesn't exist returns 0, see Weapon::attachNeededMunition
    293     Munition * WeaponSystem::getMunitionType(const std::string& munitionType) const
    294     {
    295         std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType);
    296         if (it != this->munitionSet_.end())
    297             return it->second;
    298         else
    299             return 0;
    300     }
    301 
    302284    void WeaponSystem::fire(unsigned int firemode)
    303285    {
     
    306288            it->second->fire();
    307289    }
     290
     291    void WeaponSystem::reload()
     292    {
     293        for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it)
     294            it->second->reload();
     295    }
     296
     297    Munition * WeaponSystem::getMunition(SubclassIdentifier<Munition> * identifier)
     298    {
     299        if (!identifier || !identifier->getIdentifier())
     300            return 0;
     301
     302        std::map<Identifier *, Munition *>::iterator it = this->munitions_.find(identifier->getIdentifier());
     303        if (it != this->munitions_.end())
     304        {
     305            return it->second;
     306        }
     307        else if (identifier->getIdentifier()->isA(Class(Munition)))
     308        {
     309            Munition* munition = identifier->fabricate(this);
     310            this->munitions_[identifier->getIdentifier()] = munition;
     311            return munition;
     312        }
     313        else
     314        {
     315            return 0;
     316        }
     317    }
    308318}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h

    r2915 r2918  
    6969
    7070            void fire(unsigned int firemode);
     71            void reload();
    7172
    72 
    73             void setNewMunition(const std::string& munitionType, Munition * munitionToAdd);
    74             void setNewSharedMunition(const std::string& munitionType, Munition * munitionToAdd);
    75             Munition * getMunitionType(const std::string& munitionType) const;
     73            Munition * getMunition(SubclassIdentifier<Munition> * identifier);
    7674
    7775            inline void setPawn(Pawn * pawn)
     
    9694            std::vector<WeaponSlot *> weaponSlots_;
    9795            std::set<WeaponPack *> weaponPacks_;
    98             std::map<std::string, Munition *> munitionSet_;
     96            std::map<Identifier *, Munition *> munitions_;
    9997            Pawn * pawn_;
    10098    };
  • code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/CMakeLists.txt

    r2893 r2918  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
     2  ReplenishingMunition.cc
    23  LaserGunMunition.cc
    34  FusionMunition.cc
  • code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/FusionMunition.cc

    r2912 r2918  
    4040        RegisterObject(FusionMunition);
    4141
    42         //default if not defined in XML
    43         this->maxBullets_ = 10;
    44         this->maxMagazines_ = 100;
     42        this->maxMunitionPerMagazine_ = 10;
     43        this->maxMagazines_ = 10;
     44        this->magazines_ = 10;
     45
     46        this->bUseSeparateMagazines_ = true;
     47        this->bStackMunition_ = false;
     48        this->reloadTime_ = 1.0f;
     49
     50        this->bAllowMunitionRefilling_ = true;
     51        this->bAllowMultiMunitionRemovementUnderflow_ = true;
    4552    }
    46 
    47     FusionMunition::~FusionMunition()
    48     {
    49     }
    50 
    51     void FusionMunition::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    52     {
    53 
    54     }
    55 
    5653}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/FusionMunition.h

    r2912 r2918  
    3939        public:
    4040            FusionMunition(BaseObject* creator);
    41             virtual ~FusionMunition();
    42 
    43             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    44 
    45 
    46         private:
    47 
    48 
     41            virtual ~FusionMunition() {}
    4942    };
    5043}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.cc

    r2912 r2918  
    3636    CreateFactory(LaserGunMunition);
    3737
    38     LaserGunMunition::LaserGunMunition(BaseObject* creator) : Munition(creator)
     38    LaserGunMunition::LaserGunMunition(BaseObject* creator) : ReplenishingMunition(creator)
    3939    {
    4040        RegisterObject(LaserGunMunition);
    4141
    42         //default if not defined in XML
    43         this->maxBullets_ = 40;
    44         this->maxMagazines_ = 100;
     42        this->maxMunitionPerMagazine_ = 20;
     43        this->maxMagazines_ = 1;
     44        this->magazines_ = 1;
     45
     46        this->bUseSeparateMagazines_ = false;
     47        this->bStackMunition_ = true;
     48
     49        this->bAllowMunitionRefilling_ = true;
     50        this->bAllowMultiMunitionRemovementUnderflow_ = true;
     51
     52        this->replenishIntervall_ = 0.5f;
     53        this->replenishMunitionAmount_ = 1;
    4554    }
    46 
    47     LaserGunMunition::~LaserGunMunition()
    48     {
    49     }
    50 
    51     void LaserGunMunition::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    52     {
    53 
    54     }
    55 
    5655}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.h

    r2912 r2918  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "objects/weaponSystem/Munition.h"
     33#include "ReplenishingMunition.h"
    3434
    3535namespace orxonox
    3636{
    37     class _OrxonoxExport LaserGunMunition : public Munition
     37    class _OrxonoxExport LaserGunMunition : public ReplenishingMunition
    3838    {
    3939        public:
    4040            LaserGunMunition(BaseObject* creator);
    41             virtual ~LaserGunMunition();
    42 
    43             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    44 
    45 
    46         private:
    47 
    48 
     41            virtual ~LaserGunMunition() {}
    4942    };
    5043}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc

    r2896 r2918  
    101101        if (!this->bDestroy_ && GameMode::isMaster())
    102102        {
     103            if (otherObject == this->owner_)
     104                return true;
     105
    103106            this->bDestroy_ = true;
    104107
  • code/branches/weapons/src/orxonox/objects/weaponSystem/projectiles/Projectile.h

    r2662 r2918  
    5151            virtual void destroyedPawn(Pawn* pawn);
    5252
     53            inline void setDamage(float damage)
     54                { this->damage_ = damage; }
     55            inline float getDamage() const
     56                { return this->damage_; }
     57
    5358            inline void setOwner(Pawn* owner)
    5459                { this->owner_ = owner; }
  • code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/CMakeLists.txt

    r2710 r2918  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
    2   Fusion.cc
    3   LaserGun.cc
    4 #  Missile.cc
     2  FusionFire.cc
     3  LaserFire.cc
    54)
  • code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/FusionFire.cc

    • Property svn:mergeinfo set to (toggle deleted branches)
      /code/branches/gui/src/orxonox/objects/weaponSystem/weapons/Fusion.ccmergedeligible
      /code/branches/pickups/src/orxonox/objects/weaponSystem/weapons/Fusion.ccmergedeligible
      /code/branches/pickups2/src/orxonox/objects/weaponSystem/weapons/Fusion.ccmergedeligible
      /code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.ccmergedeligible
      /code/branches/buildsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1874-2276,​2278-2400
      /code/branches/buildsystem2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2506-2658
      /code/branches/buildsystem3/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2662-2708
      /code/branches/ceguilua/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1802-1808
      /code/branches/core3/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1572-1739
      /code/branches/gcc43/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1580
      /code/branches/input/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1629-1636
      /code/branches/lodfinal/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2372-2411
      /code/branches/miniprojects/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2754-2824
      /code/branches/network/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2356
      /code/branches/network64/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2210-2355
      /code/branches/objecthierarchy/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1911-2085,​2100,​2110-2169
      /code/branches/objecthierarchy2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2171-2479
      /code/branches/overlay/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2117-2385
      /code/branches/physics/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1912-2055,​2107-2439
      /code/branches/physics_merge/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2436-2457
      /code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2369-2652,​2654-2660
      /code/branches/questsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1894-2088
      /code/branches/questsystem2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2107-2259
      /code/branches/script_trigger/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1295-1953,​1955
      /code/branches/weapon/src/orxonox/objects/weaponSystem/weapons/Fusion.cc1925-2094
      /code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc2107-2488
    r2914 r2918  
    2828
    2929#include "OrxonoxStableHeaders.h"
    30 #include "Fusion.h"
     30#include "FusionFire.h"
    3131
    3232#include "core/CoreIncludes.h"
     33#include "objects/weaponSystem/projectiles/BillboardProjectile.h"
    3334
    34 #include "objects/weaponSystem/Munition.h"
    35 #include "objects/weaponSystem/projectiles/ParticleProjectile.h"
     35#include "objects/weaponSystem/Weapon.h"
     36#include "objects/weaponSystem/WeaponPack.h"
    3637#include "objects/weaponSystem/WeaponSystem.h"
    3738
    3839namespace orxonox
    3940{
    40     CreateFactory(Fusion);
     41    CreateFactory(FusionFire);
    4142
    42     Fusion::Fusion(BaseObject* creator) : Weapon(creator)
     43    FusionFire::FusionFire(BaseObject* creator) : WeaponMode(creator)
    4344    {
    44         RegisterObject(Fusion);
     45        RegisterObject(FusionFire);
    4546
     47        this->reloadTime_ = 1.0;
     48        this->bParallelReload_ = false;
     49        this->damage_ = 40;
    4650        this->speed_ = 1250;
    4751
     52        this->setMunitionName("FusionMunition");
    4853    }
    4954
    50     Fusion::~Fusion()
     55    void FusionFire::fire()
    5156    {
    52     }
     57        BillboardProjectile* projectile = new BillboardProjectile(this);
    5358
    54     void Fusion::takeBullets()
    55     {
    56 //COUT(0) << "Fusion::takeBullets" << std::endl;
    57         this->munition_->removeBullets(1);
    58         this->bulletTimer(this->bulletLoadingTime_);
    59     }
     59        projectile->setOrientation(this->getMuzzleOrientation());
     60        projectile->setPosition(this->getMuzzlePosition());
     61        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
    6062
    61     void Fusion::takeMagazines()
    62     {
    63         this->munition_->removeMagazines(1);
    64         this->magazineTimer(this->magazineLoadingTime_);
    65     }
    66 
    67     void Fusion::createProjectile()
    68     {
    69 //COUT(0) << "Fusion::createProjectile" << std::endl;
    70         BillboardProjectile* projectile = new ParticleProjectile(this);
    71         projectile->setOrientation(this->getWorldOrientation());
    72         projectile->setPosition(this->getWorldPosition());
    73         projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_);
    74         projectile->setOwner(this->getWeaponSystem()->getPawn());
     63        projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
     64        projectile->setDamage(this->getDamage());
     65        projectile->setColour(ColourValue(1.0f, 0.7f, 0.3f, 1.0f));
    7566    }
    7667}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/FusionFire.h

    • Property svn:mergeinfo set to (toggle deleted branches)
      /code/branches/gui/src/orxonox/objects/weaponSystem/weapons/Fusion.hmergedeligible
      /code/branches/pickups/src/orxonox/objects/weaponSystem/weapons/Fusion.hmergedeligible
      /code/branches/pickups2/src/orxonox/objects/weaponSystem/weapons/Fusion.hmergedeligible
      /code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.hmergedeligible
      /code/branches/buildsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.h1874-2276,​2278-2400
      /code/branches/buildsystem2/src/orxonox/objects/weaponSystem/weapons/Fusion.h2506-2658
      /code/branches/buildsystem3/src/orxonox/objects/weaponSystem/weapons/Fusion.h2662-2708
      /code/branches/ceguilua/src/orxonox/objects/weaponSystem/weapons/Fusion.h1802-1808
      /code/branches/core3/src/orxonox/objects/weaponSystem/weapons/Fusion.h1572-1739
      /code/branches/gcc43/src/orxonox/objects/weaponSystem/weapons/Fusion.h1580
      /code/branches/input/src/orxonox/objects/weaponSystem/weapons/Fusion.h1629-1636
      /code/branches/lodfinal/src/orxonox/objects/weaponSystem/weapons/Fusion.h2372-2411
      /code/branches/miniprojects/src/orxonox/objects/weaponSystem/weapons/Fusion.h2754-2824
      /code/branches/network/src/orxonox/objects/weaponSystem/weapons/Fusion.h2356
      /code/branches/network64/src/orxonox/objects/weaponSystem/weapons/Fusion.h2210-2355
      /code/branches/objecthierarchy/src/orxonox/objects/weaponSystem/weapons/Fusion.h1911-2085,​2100,​2110-2169
      /code/branches/objecthierarchy2/src/orxonox/objects/weaponSystem/weapons/Fusion.h2171-2479
      /code/branches/overlay/src/orxonox/objects/weaponSystem/weapons/Fusion.h2117-2385
      /code/branches/physics/src/orxonox/objects/weaponSystem/weapons/Fusion.h1912-2055,​2107-2439
      /code/branches/physics_merge/src/orxonox/objects/weaponSystem/weapons/Fusion.h2436-2457
      /code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/Fusion.h2369-2652,​2654-2660
      /code/branches/questsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.h1894-2088
      /code/branches/questsystem2/src/orxonox/objects/weaponSystem/weapons/Fusion.h2107-2259
      /code/branches/script_trigger/src/orxonox/objects/weaponSystem/weapons/Fusion.h1295-1953,​1955
      /code/branches/weapon/src/orxonox/objects/weaponSystem/weapons/Fusion.h1925-2094
      /code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/Fusion.h2107-2488
    r2914 r2918  
    2727 */
    2828
    29 #ifndef _Fusion_H__
    30 #define _Fusion_H__
     29#ifndef _FusionFire_H__
     30#define _FusionFire_H__
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "objects/weaponSystem/Weapon.h"
     33#include "objects/weaponSystem/WeaponMode.h"
    3434
    3535namespace orxonox
    3636{
    37     class _OrxonoxExport Fusion : public Weapon
     37    class _OrxonoxExport FusionFire : public WeaponMode
    3838    {
    3939        public:
    40             Fusion(BaseObject* creator);
    41             virtual ~Fusion();
     40            FusionFire(BaseObject* creator);
     41            virtual ~FusionFire() {}
    4242
    43             virtual void takeBullets();
    44             virtual void takeMagazines();
    45             virtual void createProjectile();
     43            virtual void fire();
    4644
    4745        private:
    4846            float speed_;
    49 
    5047    };
    5148}
    5249
    53 #endif /* _Fusion_H__ */
     50#endif /* _FusionFire_H__ */
  • code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/LaserFire.cc

    • Property svn:mergeinfo set to (toggle deleted branches)
      /code/branches/gui/src/orxonox/objects/weaponSystem/weapons/LaserGun.ccmergedeligible
      /code/branches/lodfinal/src/orxonox/objects/weaponSystem/weapons/LaserGun.ccmergedeligible
      /code/branches/pickups/src/orxonox/objects/weaponSystem/weapons/LaserGun.ccmergedeligible
      /code/branches/pickups2/src/orxonox/objects/weaponSystem/weapons/LaserGun.ccmergedeligible
      /code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.ccmergedeligible
      /code/branches/buildsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1874-2276,​2278-2400
      /code/branches/buildsystem2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2506-2658
      /code/branches/buildsystem3/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2662-2708
      /code/branches/ceguilua/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1802-1808
      /code/branches/core3/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1572-1739
      /code/branches/gcc43/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1580
      /code/branches/input/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1629-1636
      /code/branches/miniprojects/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2754-2824
      /code/branches/network/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2356
      /code/branches/network64/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2210-2355
      /code/branches/objecthierarchy/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1911-2085,​2100,​2110-2169
      /code/branches/objecthierarchy2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2171-2479
      /code/branches/overlay/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2117-2385
      /code/branches/physics/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1912-2055,​2107-2439
      /code/branches/physics_merge/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2436-2457
      /code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2369-2652,​2654-2660
      /code/branches/questsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1894-2088
      /code/branches/questsystem2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2107-2259
      /code/branches/script_trigger/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1295-1953,​1955
      /code/branches/weapon/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc1925-2094
      /code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc2107-2488
    r2914 r2918  
    2828
    2929#include "OrxonoxStableHeaders.h"
    30 #include "LaserGun.h"
     30#include "LaserFire.h"
    3131
    3232#include "core/CoreIncludes.h"
     33#include "objects/weaponSystem/projectiles/ParticleProjectile.h"
    3334
    34 #include "objects/weaponSystem/Munition.h"
    35 #include "objects/weaponSystem/projectiles/ParticleProjectile.h"
     35#include "objects/weaponSystem/Weapon.h"
     36#include "objects/weaponSystem/WeaponPack.h"
    3637#include "objects/weaponSystem/WeaponSystem.h"
    3738
    3839namespace orxonox
    3940{
    40     CreateFactory(LaserGun);
     41    CreateFactory(LaserFire);
    4142
    42     LaserGun::LaserGun(BaseObject* creator) : Weapon(creator)
     43    LaserFire::LaserFire(BaseObject* creator) : WeaponMode(creator)
    4344    {
    44         RegisterObject(LaserGun);
     45        RegisterObject(LaserFire);
    4546
     47        this->reloadTime_ = 0.25;
     48        this->damage_ = 15;
    4649        this->speed_ = 1250;
    4750
     51        this->setMunitionName("LaserGunMunition");
    4852    }
    4953
    50     LaserGun::~LaserGun()
     54    void LaserFire::fire()
    5155    {
    52     }
     56        ParticleProjectile* projectile = new ParticleProjectile(this);
    5357
    54     void LaserGun::reloadBullet()
    55     {
    56         this->bulletTimer(this->bulletLoadingTime_);
    57     }
     58        projectile->setOrientation(this->getMuzzleOrientation());
     59        projectile->setPosition(this->getMuzzlePosition());
     60        projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
    5861
    59     void LaserGun::reloadMagazine()
    60     {
    61         this->magazineTimer(this->magazineLoadingTime_);
    62     }
    63 
    64     void LaserGun::takeBullets()
    65     {
    66         this->munition_->removeBullets(1);
    67     }
    68 
    69     void LaserGun::takeMagazines()
    70     {
    71         this->munition_->removeMagazines(1);
    72     }
    73 
    74     void LaserGun::createProjectile()
    75     {
    76         BillboardProjectile* projectile = new ParticleProjectile(this);
    77         projectile->setOrientation(this->getWorldOrientation());
    78         projectile->setPosition(this->getWorldPosition());
    79         projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_);
    80         projectile->setOwner(this->getWeaponSystem()->getPawn());
     62        projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
     63        projectile->setDamage(this->getDamage());
    8164    }
    8265}
  • code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/LaserFire.h

    • Property svn:mergeinfo set to (toggle deleted branches)
      /code/branches/gui/src/orxonox/objects/weaponSystem/weapons/LaserGun.hmergedeligible
      /code/branches/lodfinal/src/orxonox/objects/weaponSystem/weapons/LaserGun.hmergedeligible
      /code/branches/pickups/src/orxonox/objects/weaponSystem/weapons/LaserGun.hmergedeligible
      /code/branches/pickups2/src/orxonox/objects/weaponSystem/weapons/LaserGun.hmergedeligible
      /code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.hmergedeligible
      /code/branches/buildsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1874-2276,​2278-2400
      /code/branches/buildsystem2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2506-2658
      /code/branches/buildsystem3/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2662-2708
      /code/branches/ceguilua/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1802-1808
      /code/branches/core3/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1572-1739
      /code/branches/gcc43/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1580
      /code/branches/input/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1629-1636
      /code/branches/miniprojects/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2754-2824
      /code/branches/network/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2356
      /code/branches/network64/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2210-2355
      /code/branches/objecthierarchy/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1911-2085,​2100,​2110-2169
      /code/branches/objecthierarchy2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2171-2479
      /code/branches/overlay/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2117-2385
      /code/branches/physics/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1912-2055,​2107-2439
      /code/branches/physics_merge/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2436-2457
      /code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2369-2652,​2654-2660
      /code/branches/questsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1894-2088
      /code/branches/questsystem2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2107-2259
      /code/branches/script_trigger/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1295-1953,​1955
      /code/branches/weapon/src/orxonox/objects/weaponSystem/weapons/LaserGun.h1925-2094
      /code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h2107-2488
    r2914 r2918  
    2727 */
    2828
    29 #ifndef _LaserGun_H__
    30 #define _LaserGun_H__
     29#ifndef _LaserFire_H__
     30#define _LaserFire_H__
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "objects/weaponSystem/Weapon.h"
     33#include "objects/weaponSystem/WeaponMode.h"
    3434
    3535namespace orxonox
    3636{
    37     class _OrxonoxExport LaserGun : public Weapon
     37    class _OrxonoxExport LaserFire : public WeaponMode
    3838    {
    3939        public:
    40             LaserGun(BaseObject* creator);
    41             virtual ~LaserGun();
     40            LaserFire(BaseObject* creator);
     41            virtual ~LaserFire() {}
    4242
    43             virtual void takeBullets();
    44             virtual void takeMagazines();
    45             virtual void createProjectile();
    46             virtual void reloadBullet();
    47             virtual void reloadMagazine();
     43            virtual void fire();
    4844
    4945        private:
    5046            float speed_;
    51 
    5247    };
    5348}
    5449
    55 #endif /* _LaserGun_H__ */
     50#endif /* _LaserFire_H__ */
  • code/branches/weapons/src/orxonox/objects/worldentities/ControllableEntity.h

    r2912 r2918  
    8282
    8383            virtual void fire(unsigned int firemode) {}
     84            virtual void reload() {}
    8485
    8586            virtual void boost() {}
  • code/branches/weapons/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2914 r2918  
    5656        this->fire_ = 0x0;
    5757        this->firehack_ = 0x0;
     58        this->bReload_ = false;
    5859
    5960        this->health_ = 0;
     
    115116        registerVariable(this->initialHealth_, variableDirection::toclient);
    116117        registerVariable(this->fire_,          variableDirection::toserver);
     118        registerVariable(this->bReload_,       variableDirection::toserver);
    117119    }
    118120
     
    121123        SUPER(Pawn, tick, dt);
    122124
    123         if (this->weaponSystem_)
     125        if (this->weaponSystem_ && GameMode::isMaster())
    124126        {
    125127            for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++)
    126128                if (this->fire_ & WeaponSystem::getFiremodeMask(firemode))
    127129                    this->weaponSystem_->fire(firemode);
    128         }
     130
     131            if (this->bReload_)
     132                this->weaponSystem_->reload();
     133        }
     134
    129135        this->fire_ = this->firehack_;
    130136        this->firehack_ = 0x0;
     137        this->bReload_ = false;
    131138
    132139        if (this->health_ <= 0)
     
    258265    }
    259266
     267    void Pawn::reload()
     268    {
     269        this->bReload_ = true;
     270    }
     271
    260272    void Pawn::postSpawn()
    261273    {
  • code/branches/weapons/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2914 r2918  
    8181
    8282            virtual void fire(unsigned int firemode);
     83            virtual void reload();
    8384            virtual void postSpawn();
    8485
     
    131132            unsigned int fire_;
    132133            unsigned int firehack_;
     134            bool bReload_;
    133135
    134136            std::string spawnparticlesource_;
Note: See TracChangeset for help on using the changeset viewer.