Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sagerjFS16/src/orxonox/weaponsystem/WeaponPack.cc @ 11618

Last change on this file since 11618 was 11174, checked in by sagerj, 8 years ago

everything beneath weaponmode changed to push/release - wm modified only need to implement timer/ticker

  • Property svn:eol-style set to native
File size: 4.4 KB
RevLine 
[2710]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Martin Polak
24 *   Co-authors:
[2915]25 *      ...
26 *
[2710]27 */
28
[2912]29#include "WeaponPack.h"
[2710]30
31#include "core/CoreIncludes.h"
32#include "core/XMLPort.h"
33
[2912]34#include "Weapon.h"
[2914]35#include "WeaponSystem.h"
[2915]36#include "DefaultWeaponmodeLink.h"
[2912]37
[2710]38namespace orxonox
39{
[9667]40    RegisterClass(WeaponPack);
[2710]41
[9667]42    WeaponPack::WeaponPack(Context* context) : BaseObject(context)
[2710]43    {
44        RegisterObject(WeaponPack);
45
[11071]46        this->weaponSystem_ = nullptr;
[2710]47    }
48
49    WeaponPack::~WeaponPack()
50    {
[6417]51        if (this->isInitialized())
[2915]52        {
[6417]53            if( this->weaponSystem_ )
54                this->weaponSystem_->removeWeaponPack(this);
[2915]55
56            while (!this->weapons_.empty())
[5929]57                (*this->weapons_.begin())->destroy();
[2915]58
59            for (std::set<DefaultWeaponmodeLink*>::iterator it = this->links_.begin(); it != this->links_.end(); )
[5929]60                (*(it++))->destroy();
[2915]61        }
[2710]62    }
63
[2912]64    void WeaponPack::XMLPort(Element& xmlelement, XMLPort::Mode mode)
[2710]65    {
[2912]66        SUPER(WeaponPack, XMLPort, xmlelement, mode);
67
[2918]68        XMLPortObjectExtended(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode, false, false);
[2915]69        XMLPortObject(WeaponPack, DefaultWeaponmodeLink, "links", addDefaultWeaponmodeLink, getDefaultWeaponmodeLink, xmlelement, mode);
[2912]70    }
71
[10650]72    /**
73    @brief
74        Fire all weapons in this WeaponSet with the defined weaponmode.
75    */
[11174]76    void WeaponPack::push(unsigned int weaponmode)
[2912]77    {
[11071]78        for (Weapon* weapon : this->weapons_)
[11174]79            weapon->push(weaponmode);
[2710]80    }
81
[11164]82    void WeaponPack::release(unsigned int weaponmode)
83    {
84        for (Weapon* weapon : this->weapons_)
85            weapon->release(weaponmode);
86    }
87
[10650]88    /**
89    @brief
90        Reload all weapons in this WeaponSet.
91    */
[2918]92    void WeaponPack::reload()
93    {
[11071]94        for (Weapon* weapon : this->weapons_)
95            weapon->reload();
[2918]96    }
97
[2914]98    void WeaponPack::addWeapon(Weapon * weapon)
[2710]99    {
[2914]100        if (!weapon)
101            return;
[2710]102
[6417]103        this->weapons_.push_back(weapon);
[2914]104        weapon->setWeaponPack(this);
[2710]105    }
106
[2915]107    void WeaponPack::removeWeapon(Weapon * weapon)
108    {
109        if (!weapon)
110            return;
111
[6417]112        std::vector<Weapon*>::iterator it = std::find(this->weapons_.begin(), this->weapons_.end(), weapon);
113        assert(it != this->weapons_.end());
114        this->weapons_.erase(it);
[11071]115        weapon->setWeaponPack(nullptr);
[2915]116    }
117
[2914]118    Weapon * WeaponPack::getWeapon(unsigned int index) const
[2710]119    {
[2914]120        unsigned int i = 0;
[2710]121
[11071]122        for (Weapon* weapon : this->weapons_)
[2914]123        {
124            if (i == index)
[11071]125                return weapon;
[2914]126            ++i;
127        }
[2710]128
[11071]129        return nullptr;
[2710]130    }
131
[2915]132    void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link)
133    {
134        this->links_.insert(link);
135    }
136
137    DefaultWeaponmodeLink* WeaponPack::getDefaultWeaponmodeLink(unsigned int index) const
138    {
139        unsigned int i = 0;
[11071]140        for (DefaultWeaponmodeLink* link : this->links_)
[2915]141        {
142            if (i == index)
[11071]143                return link;
[2915]144
145            ++i;
146        }
[11071]147        return nullptr;
[2915]148    }
149
150    unsigned int WeaponPack::getDesiredWeaponmode(unsigned int firemode) const
151    {
[11071]152        for (DefaultWeaponmodeLink* link : this->links_)
153            if (link->getFiremode() == firemode)
154                return link->getWeaponmode();
[2915]155
156        return WeaponSystem::WEAPON_MODE_UNASSIGNED;
157    }
[2918]158
159    void WeaponPack::notifyWeapons()
160    {
[11071]161        for (Weapon* weapon : this->weapons_)
162            weapon->setWeaponPack(this);
[2918]163    }
[11052]164
165    void WeaponPack::updateMunition()
166    {
[11071]167        for (Weapon* weapon : this->weapons_)
168            weapon->updateMunition();
[11052]169    }
[2710]170}
Note: See TracBrowser for help on using the repository browser.