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 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "WeaponSet.h" |
---|
31 | |
---|
32 | #include "core/CoreIncludes.h" |
---|
33 | #include "core/XMLPort.h" |
---|
34 | |
---|
35 | #include "WeaponSystem.h" |
---|
36 | #include "WeaponPack.h" |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | CreateFactory(WeaponSet); |
---|
41 | |
---|
42 | WeaponSet::WeaponSet(BaseObject* creator) : BaseObject(creator) |
---|
43 | { |
---|
44 | RegisterObject(WeaponSet); |
---|
45 | |
---|
46 | this->weaponSystem_ = 0; |
---|
47 | this->desiredFiremode_ = WeaponSystem::FIRE_MODE_UNASSIGNED; |
---|
48 | |
---|
49 | COUT(0) << "+WeaponSet" << std::endl; |
---|
50 | } |
---|
51 | |
---|
52 | WeaponSet::~WeaponSet() |
---|
53 | { |
---|
54 | COUT(0) << "~WeaponSet" << std::endl; |
---|
55 | |
---|
56 | if (this->isInitialized() && this->weaponSystem_) |
---|
57 | this->weaponSystem_->removeWeaponSet(this); |
---|
58 | } |
---|
59 | |
---|
60 | void WeaponSet::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
61 | { |
---|
62 | SUPER(WeaponSet, XMLPort, xmlelement, mode); |
---|
63 | |
---|
64 | XMLPortParam(WeaponSet, "firemode", setDesiredFiremode, getDesiredFiremode, xmlelement, mode); |
---|
65 | } |
---|
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 | */ |
---|
104 | |
---|
105 | void WeaponSet::fire() |
---|
106 | { |
---|
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); |
---|
111 | } |
---|
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 | } |
---|
131 | } |
---|