Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc @ 2912

Last change on this file since 2912 was 2912, checked in by landauf, 15 years ago

Several small adjustments in the weaponsystem (like additional const keyword, includes moved from .h to .cc where possible, …)

Firemode is now an unsigned int instead of an Enum. Instead of "fire" and "altFire" use "fire 0" and "fire 1"

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
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:
25 *      ... *
26 */
27
28#include "OrxonoxStableHeaders.h"
29#include "WeaponPack.h"
30
31#include "core/CoreIncludes.h"
32#include "core/XMLPort.h"
33#include "objects/worldentities/pawns/Pawn.h"
34
35#include "Weapon.h"
36#include "WeaponSlot.h"
37
38namespace orxonox
39{
40    CreateFactory(WeaponPack);
41
42    WeaponPack::WeaponPack(BaseObject* creator) : BaseObject(creator)
43    {
44        RegisterObject(WeaponPack);
45
46        this->weaponSystem_ = 0;
47        this->firemode_ = 0;
48
49COUT(0) << "+WeaponPack" << std::endl;
50    }
51
52    WeaponPack::~WeaponPack()
53    {
54COUT(0) << "~WeaponPack" << std::endl;
55    }
56
57    void WeaponPack::XMLPort(Element& xmlelement, XMLPort::Mode mode)
58    {
59        SUPER(WeaponPack, XMLPort, xmlelement, mode);
60
61        XMLPortObject(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);
62        XMLPortParam(WeaponPack, "firemode", setFireMode, getFireMode, xmlelement, mode);
63    }
64
65    int WeaponPack::getSize() const
66    {
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_;
91    }
92
93    void WeaponPack::addWeapon(Weapon * weapon)
94    {
95        this->weapons_.push_back(weapon);
96    }
97
98    const Weapon * WeaponPack::getWeapon(unsigned int index) const
99    {
100        return weapons_[index];
101    }
102
103    void WeaponPack::setWeaponSystemToAllWeapons(WeaponSystem * weaponSystem)
104    {
105        for (size_t i = 0; i < this->weapons_.size(); i++)
106            this->weapons_[i]->setWeaponSystem(weaponSystem);
107    }
108
109    void WeaponPack::attachNeededMunitionToAllWeapons()
110    {
111        for (size_t i = 0; i < this->weapons_.size(); i++)
112        {
113            this->weapons_[i]->attachNeededMunition(weapons_[i]->getMunitionType());
114            this->weapons_[i]->setWeapon();
115        }
116    }
117}
Note: See TracBrowser for help on using the repository browser.