Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2009, 12:05:01 AM (16 years ago)
Author:
landauf
Message:

More changes in the WeaponSystem:

  • WeaponSets can now contain several WeaponPacks
  • WeaponPacks can now belong to several WeaponSets

(until now this seemingly was a 1:1 relationship… now it's n:m)

  • Started support for multiple weaponmodes
  • Added some code to the destructor of some classes… according to some legends, this helps destroying objects. (WeaponSets and WeaponPacks weren't deleted before…)

Not yet finished, but I have to synchronize desktop computer and notebook.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc

    r2912 r2914  
    3535#include "Weapon.h"
    3636#include "WeaponSlot.h"
     37#include "WeaponSystem.h"
    3738
    3839namespace orxonox
     
    4546
    4647        this->weaponSystem_ = 0;
    47         this->firemode_ = 0;
    4848
    4949COUT(0) << "+WeaponPack" << std::endl;
     
    5353    {
    5454COUT(0) << "~WeaponPack" << std::endl;
     55
     56        if (this->isInitialized() && this->weaponSystem_)
     57            this->weaponSystem_->removeWeaponPack(this);
    5558    }
    5659
     
    6063
    6164        XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);
    62         XMLPortParam(WeaponPack, "firemode", setFireMode, getFireMode, xmlelement, mode);
    6365    }
    6466
    65     int WeaponPack::getSize() const
     67    void WeaponPack::fire(unsigned int weaponmode)
    6668    {
    67         return this->weapons_.size();
    68     }
    69 
    70     void WeaponPack::fire()
    71     {
    72         for (int i=0; i < (int) this->weapons_.size(); i++)
    73         {
    74             this->weapons_[i]->getAttachedToWeaponSlot()->fire();
    75         }
    76     }
    77 
    78     Weapon * WeaponPack::getWeaponPointer(unsigned int n) const
    79     {
    80         return this->weapons_[n];
    81     }
    82 
    83     void WeaponPack::setFireMode(unsigned int firemode)
    84     {
    85         this->firemode_ = firemode;
    86     }
    87 
    88     unsigned int WeaponPack::getFireMode() const
    89     {
    90         return this->firemode_;
     69        for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     70            (*it)->fire();
    9171    }
    9272
    9373    void WeaponPack::addWeapon(Weapon * weapon)
    9474    {
    95         this->weapons_.push_back(weapon);
     75        if (!weapon)
     76            return;
     77
     78        this->weapons_.insert(weapon);
     79        weapon->setWeaponPack(this);
    9680    }
    9781
    98     const Weapon * WeaponPack::getWeapon(unsigned int index) const
     82    Weapon * WeaponPack::getWeapon(unsigned int index) const
    9983    {
    100         return weapons_[index];
     84        unsigned int i = 0;
     85
     86        for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     87        {
     88            if (i == index)
     89                return (*it);
     90            ++i;
     91        }
     92
     93        return 0;
    10194    }
    10295
    10396    void WeaponPack::setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem)
    10497    {
    105         for (size_t i = 0; i < this->weapons_.size(); i++)
    106             this->weapons_[i]->setWeaponSystem(weaponSystem);
     98        for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
     99            (*it)->setWeaponSystem(weaponSystem);
    107100    }
    108101
    109102    void WeaponPack::attachNeededMunitionToAllWeapons()
    110103    {
    111         for (size_t i = 0; i < this->weapons_.size(); i++)
     104        for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)
    112105        {
    113             this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType());
    114             this->weapons_[i]->setWeapon();
     106            (*it)->attachNeededMunition((*it)->getMunitionType());
     107            (*it)->setWeapon();
    115108        }
    116109    }
Note: See TracChangeset for help on using the changeset viewer.