Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc @ 2915

Last change on this file since 2915 was 2915, checked in by landauf, 15 years ago
  • switched back to std::vector for the WeaponSlots to keep them in the same order as in the XML file
  • added DefaultWeaponmodeLink, a class which links weaponmodes (a property of a Weapon or a WeaponPack) with firemodes (one firemode corresponds to one WeaponSet). This can be changed later (for example in a nice GUI), but DefaultWeaponmodeLink defines the default value.
  • Property svn:eol-style set to native
File size: 4.7 KB
RevLine 
[2049]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 *
[2049]27 */
28
29#include "OrxonoxStableHeaders.h"
[2912]30#include "WeaponSet.h"
[2049]31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34
[2914]35#include "WeaponSystem.h"
[2662]36#include "WeaponPack.h"
[2096]37
[2049]38namespace orxonox
39{
[2662]40    CreateFactory(WeaponSet);
41
[2914]42    WeaponSet::WeaponSet(BaseObject* creator) : BaseObject(creator)
[2049]43    {
[2096]44        RegisterObject(WeaponSet);
45
[2912]46        this->weaponSystem_ = 0;
[2914]47        this->desiredFiremode_ = WeaponSystem::FIRE_MODE_UNASSIGNED;
[2912]48
49COUT(0) << "+WeaponSet" << std::endl;
[2049]50    }
51
52    WeaponSet::~WeaponSet()
53    {
[2912]54COUT(0) << "~WeaponSet" << std::endl;
[2914]55
56        if (this->isInitialized() && this->weaponSystem_)
57            this->weaponSystem_->removeWeaponSet(this);
[2049]58    }
59
[2912]60    void WeaponSet::XMLPort(Element& xmlelement, XMLPort::Mode mode)
61    {
62        SUPER(WeaponSet, XMLPort, xmlelement, mode);
63
[2914]64        XMLPortParam(WeaponSet, "firemode", setDesiredFiremode, getDesiredFiremode, xmlelement, mode);
[2912]65    }
[2914]66/*
[2662]67    void WeaponSet::attachWeaponPack(WeaponPack *wPack)
[2096]68    {
[2912]69        if ( this->weaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->weaponSystem_->getWeaponSlotSize() ) )
[2096]70        {
[2662]71            this->attachedWeaponPack_ = wPack;
72            int wPackWeapon = 0;    //WeaponCounter for Attaching
[2912]73
[2662]74            //should be possible to choose which slot to use
[2893]75            //attach every weapon of the weaponPack to a weaponSlot
[2662]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...
[2893]79                //it also takes the first free weaponSlot...
[2912]80                if ( this->weaponSystem_->getWeaponSlot(i)->getAttachedWeapon() == 0 && this->weaponSystem_->getWeaponSlot(i) != 0) //if slot not full
[2662]81                {
[2912]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) );
[2662]85                    wPackWeapon++;
86                }
87                else
88                {
[2912]89                    for (int k=0; k < this->weaponSystem_->getWeaponSlotSize(); k++)
[2662]90                    {
[2912]91                        if ( this->weaponSystem_->getWeaponSlot(k)->getAttachedWeapon() == 0 )
[2662]92                        {
[2912]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) );
[2662]96                            wPackWeapon++;
97                        }
98                    }
99                }
100            }
[2096]101        }
102    }
[2914]103*/
[2096]104
[2662]105    void WeaponSet::fire()
[2096]106    {
[2914]107        // fire all WeaponPacks with their defined weaponmode
108        for (std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.begin(); it != this->weaponpacks_.end(); ++it)
109            if (it->second != WeaponSystem::WEAPON_MODE_UNASSIGNED)
110                it->first->fire(it->second);
[2096]111    }
[2914]112
113    void WeaponSet::setWeaponmodeLink(WeaponPack* weaponpack, unsigned int weaponmode)
114    {
115        this->weaponpacks_[weaponpack] = weaponmode;
116    }
117
118    void WeaponSet::removeWeaponmodeLink(WeaponPack* weaponpack)
119    {
120        this->weaponpacks_.erase(weaponpack);
121    }
122
123    unsigned int WeaponSet::getWeaponmodeLink(WeaponPack* weaponpack)
124    {
125        std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.find(weaponpack);
126        if (it != this->weaponpacks_.end())
127            return it->second;
128        else
129            return WeaponSystem::WEAPON_MODE_UNASSIGNED;
130    }
[2096]131}
Note: See TracBrowser for help on using the repository browser.