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 | Weapon::Weapon(BaseObject* creator) : BaseObject(creator) |
---|
40 | { |
---|
41 | RegisterObject(Weapon); |
---|
42 | this->bulletReadyToShoot_ = true; |
---|
43 | this->magazineReadyToShoot_ = true; |
---|
44 | this->setParentWeaponSystem(); |
---|
45 | } |
---|
46 | |
---|
47 | Weapon::~Weapon() |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | void Weapon::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
53 | { |
---|
54 | SUPER(Weapon, XMLPort, xmlelement, mode); |
---|
55 | } |
---|
56 | |
---|
57 | void Weapon::fire() |
---|
58 | { |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | void Weapon::bulletTimer() |
---|
64 | { |
---|
65 | this->bulletReloadTimer_.setTimer( this->bulletLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); |
---|
66 | } |
---|
67 | void Weapon::magazineTimer() |
---|
68 | { |
---|
69 | this->magazineReloadTimer_.setTimer( this->magazineLoadingTime_ , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); |
---|
70 | } |
---|
71 | |
---|
72 | void Weapon::bulletReloaded() |
---|
73 | { this->bulletReadyToShoot_ = true; } |
---|
74 | |
---|
75 | void Weapon::magazineReloaded() |
---|
76 | { this->magazineReadyToShoot_ = true; } |
---|
77 | |
---|
78 | |
---|
79 | void Weapon::attachNeededMunition(std::string munitionName) |
---|
80 | { |
---|
81 | //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 |
---|
82 | if ( this->parentWeaponSystem_->getMunitionType(munitionName) ) |
---|
83 | this->munition_ = this->parentWeaponSystem_->getMunitionType(munitionName); |
---|
84 | else |
---|
85 | { |
---|
86 | //create new munition with identifier |
---|
87 | this->munitionIdentifier_ = ClassByString(munitionName); |
---|
88 | this->munition_ = this->munitionIdentifier_.fabricate(this); |
---|
89 | this->parentWeaponSystem_->setNewMunition(munitionName, this->munition_); |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | /*get and set functions |
---|
95 | * |
---|
96 | */ |
---|
97 | void Weapon::setParentWeaponSystem() |
---|
98 | { this->parentWeaponSystem_ = this->parentWeaponSlot_->getParentWeaponSet()->getParentWeaponSystem(); } |
---|
99 | |
---|
100 | Munition * Weapon::getAttachedMunition() |
---|
101 | { return this->munition_; } |
---|
102 | |
---|
103 | void Weapon::setBulletLoadingTime(float loadingTime) |
---|
104 | { this->bulletLoadingTime_ = loadingTime; } |
---|
105 | |
---|
106 | float Weapon::getBulletLoadingTime() |
---|
107 | { return this->bulletLoadingTime_; } |
---|
108 | |
---|
109 | void Weapon::setMagazineLoadingTime(float loadingTime) |
---|
110 | { this->magazineLoadingTime_ = loadingTime; } |
---|
111 | |
---|
112 | float Weapon::getMagazineLoadingTime() |
---|
113 | { return this->magazineLoadingTime_; } |
---|
114 | |
---|
115 | void Weapon::setBulletReadyToShoot(bool b) |
---|
116 | { this->bulletReadyToShoot_ = b; } |
---|
117 | |
---|
118 | bool Weapon::getBulletReadyToShoot() |
---|
119 | { return this->bulletReadyToShoot_; } |
---|
120 | |
---|
121 | void Weapon::setMagazineReadyToShoot(bool b) |
---|
122 | { this->magazineReadyToShoot_ = b; } |
---|
123 | |
---|
124 | bool Weapon::getMagazineReadyToShoot() |
---|
125 | { return this->magazineReadyToShoot_; } |
---|
126 | |
---|
127 | Timer<Weapon> * Weapon::getBulletTimer() |
---|
128 | { return &this->bulletReloadTimer_; } |
---|
129 | |
---|
130 | Timer<Weapon> * Weapon::getMagazineTimer() |
---|
131 | { return &this->magazineReloadTimer_; } |
---|
132 | } |
---|