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 | |
---|
31 | #include "core/CoreIncludes.h" |
---|
32 | #include "core/XMLPort.h" |
---|
33 | #include "util/Debug.h" |
---|
34 | |
---|
35 | #include "Weapon.h" |
---|
36 | |
---|
37 | namespace orxonox |
---|
38 | { |
---|
39 | CreateFactory(Weapon); |
---|
40 | |
---|
41 | Weapon::Weapon(BaseObject* creator) : BaseObject(creator) |
---|
42 | { |
---|
43 | RegisterObject(Weapon); |
---|
44 | this->bulletReadyToShoot_ = true; |
---|
45 | this->magazineReadyToShoot_ = true; |
---|
46 | this->parentWeaponSystem_ = 0; |
---|
47 | this->parentWeaponSlot_ = 0; |
---|
48 | this->munition_ = 0; |
---|
49 | } |
---|
50 | |
---|
51 | Weapon::~Weapon() |
---|
52 | { |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
57 | { |
---|
58 | SUPER(Weapon, XMLPort, xmlelement, mode); |
---|
59 | XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode); |
---|
60 | } |
---|
61 | |
---|
62 | void Weapon::setWeapon() |
---|
63 | { |
---|
64 | this->bulletLoadingTime_ = 0.5; |
---|
65 | this->magazineLoadingTime_ = 3.0; |
---|
66 | this->munition_->setMaxMagazines(100); |
---|
67 | this->munition_->setMaxBullets(30); |
---|
68 | this->munition_->fillBullets(); |
---|
69 | this->munition_->fillMagazines(); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | void Weapon::fire() |
---|
74 | { |
---|
75 | COUT(0) << "LaserGun::fire, this=" << this << std::endl; |
---|
76 | if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ ) |
---|
77 | { |
---|
78 | COUT(0) << "LaserGun::fire - ready to shoot" << std::endl; |
---|
79 | |
---|
80 | this->bulletReadyToShoot_ = false; |
---|
81 | if ( this->munition_->bullets() ) |
---|
82 | { |
---|
83 | //shoot |
---|
84 | this->takeBullets(); |
---|
85 | this->createProjectile(); |
---|
86 | } |
---|
87 | //if there are no bullets, but magazines |
---|
88 | else if ( this->munition_->magazines() && !this->munition_->bullets() ) |
---|
89 | { |
---|
90 | this->takeMagazines(); |
---|
91 | } |
---|
92 | } |
---|
93 | else |
---|
94 | { |
---|
95 | COUT(0) << "LaserGun::fire - weapon not reloaded" << std::endl; |
---|
96 | } |
---|
97 | |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | void Weapon::bulletTimer(float bulletLoadingTime) |
---|
102 | { |
---|
103 | COUT(0) << "Weapon::bulletTimer started" << std::endl; |
---|
104 | this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); |
---|
105 | } |
---|
106 | void Weapon::magazineTimer(float magazineLoadingTime) |
---|
107 | { |
---|
108 | COUT(0) << "Weapon::magazineTimer started" << std::endl; |
---|
109 | this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); |
---|
110 | } |
---|
111 | |
---|
112 | void Weapon::bulletReloaded() |
---|
113 | { this->bulletReadyToShoot_ = true; } |
---|
114 | |
---|
115 | void Weapon::magazineReloaded() |
---|
116 | { |
---|
117 | this->munition_->fillBullets(); |
---|
118 | this->magazineReadyToShoot_ = true; |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | void Weapon::attachNeededMunition(std::string munitionName) |
---|
123 | { |
---|
124 | COUT(0) << "Weapon::attachNeededMunition, parentWeaponSystem=" << this->parentWeaponSystem_ << std::endl; |
---|
125 | //if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem |
---|
126 | if (this->parentWeaponSystem_) |
---|
127 | { |
---|
128 | COUT(0) << "Weapon::attachNeededMunition " << munitionName << std::endl; |
---|
129 | Munition* munition = this->parentWeaponSystem_->getMunitionType(munitionName); |
---|
130 | if ( munition ) |
---|
131 | this->munition_ = munition; |
---|
132 | else |
---|
133 | { |
---|
134 | //create new munition with identifier |
---|
135 | COUT(0) << "Weapon::attachNeededMunition, create new Munition of Type " << munitionName << std::endl; |
---|
136 | this->munitionIdentifier_ = ClassByString(munitionName); |
---|
137 | this->munition_ = this->munitionIdentifier_.fabricate(this); |
---|
138 | this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_); |
---|
139 | } |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | /*get and set functions |
---|
145 | * |
---|
146 | */ |
---|
147 | |
---|
148 | void Weapon::setMunitionType(std::string munitionType) |
---|
149 | { |
---|
150 | COUT(0) << "Weapon::setMunitionType (XMLPort) "<< munitionType << std::endl; |
---|
151 | this->munitionType_ = munitionType; } |
---|
152 | |
---|
153 | const std::string Weapon::getMunitionType() |
---|
154 | { return this->munitionType_; } |
---|
155 | |
---|
156 | Munition * Weapon::getAttachedMunition(std::string munitionType) |
---|
157 | { |
---|
158 | COUT(0) << "Weapon::getAttachedMunition, parentWeaponSystem_="<< this->parentWeaponSystem_ << std::endl; |
---|
159 | this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionType); |
---|
160 | COUT(0) << "Weapon::getAttachedMunition, munition_="<< this->munition_ << std::endl; |
---|
161 | return this->munition_; } |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | void Weapon::setBulletLoadingTime(float loadingTime) |
---|
166 | { this->bulletLoadingTime_ = loadingTime; } |
---|
167 | |
---|
168 | float Weapon::getBulletLoadingTime() |
---|
169 | { return this->bulletLoadingTime_; } |
---|
170 | |
---|
171 | void Weapon::setMagazineLoadingTime(float loadingTime) |
---|
172 | { this->magazineLoadingTime_ = loadingTime; } |
---|
173 | |
---|
174 | float Weapon::getMagazineLoadingTime() |
---|
175 | { return this->magazineLoadingTime_; } |
---|
176 | |
---|
177 | |
---|
178 | Timer<Weapon> * Weapon::getBulletTimer() |
---|
179 | { return &this->bulletReloadTimer_; } |
---|
180 | |
---|
181 | Timer<Weapon> * Weapon::getMagazineTimer() |
---|
182 | { return &this->magazineReloadTimer_; } |
---|
183 | |
---|
184 | void Weapon::takeBullets() { }; |
---|
185 | void Weapon::createProjectile() { }; |
---|
186 | void Weapon::takeMagazines() { }; |
---|
187 | |
---|
188 | } |
---|