[2072] | 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 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "Pawn.h" |
---|
| 31 | |
---|
| 32 | #include "core/CoreIncludes.h" |
---|
| 33 | #include "core/XMLPort.h" |
---|
| 34 | #include "util/Math.h" |
---|
| 35 | #include "objects/infos/PlayerInfo.h" |
---|
| 36 | #include "objects/gametypes/Gametype.h" |
---|
| 37 | |
---|
[2145] | 38 | |
---|
[2072] | 39 | namespace orxonox |
---|
| 40 | { |
---|
| 41 | CreateFactory(Pawn); |
---|
| 42 | |
---|
| 43 | Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator) |
---|
| 44 | { |
---|
| 45 | RegisterObject(Pawn); |
---|
| 46 | |
---|
| 47 | this->bAlive_ = false; |
---|
| 48 | |
---|
| 49 | this->health_ = 0; |
---|
| 50 | this->maxHealth_ = 0; |
---|
| 51 | this->initialHealth_ = 0; |
---|
| 52 | |
---|
| 53 | this->lastHitOriginator_ = 0; |
---|
| 54 | |
---|
[2145] | 55 | //WeaponSystem |
---|
| 56 | weaponSystem_ = new WeaponSystem(this); |
---|
[2327] | 57 | /* |
---|
[2273] | 58 | WeaponSet * weaponSet1 = new WeaponSet(this,1); |
---|
[2098] | 59 | this->weaponSystem_->attachWeaponSet(weaponSet1); |
---|
[2288] | 60 | //totally bad solution... |
---|
| 61 | weaponSet1->setParentWeaponSystem(weaponSystem_); |
---|
[2327] | 62 | */ |
---|
[2098] | 63 | |
---|
[2072] | 64 | this->registerVariables(); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | Pawn::~Pawn() |
---|
| 68 | { |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 72 | { |
---|
| 73 | SUPER(Pawn, XMLPort, xmlelement, mode); |
---|
| 74 | |
---|
| 75 | XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100); |
---|
| 76 | XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200); |
---|
| 77 | XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100); |
---|
| 78 | |
---|
[2288] | 79 | XMLPortObject(Pawn, WeaponSlot, "weaponslots", setWeaponSlot, getWeaponSlot, xmlelement, mode); |
---|
[2308] | 80 | XMLPortObject(Pawn, WeaponSet, "weaponsets", setWeaponSet, getWeaponSet, xmlelement, mode); |
---|
[2319] | 81 | XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode); |
---|
[2288] | 82 | |
---|
| 83 | } |
---|
| 84 | |
---|
[2072] | 85 | void Pawn::registerVariables() |
---|
| 86 | { |
---|
| 87 | REGISTERDATA(this->bAlive_, network::direction::toclient); |
---|
| 88 | REGISTERDATA(this->health_, network::direction::toclient); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void Pawn::tick(float dt) |
---|
| 92 | { |
---|
| 93 | SUPER(Pawn, tick, dt); |
---|
| 94 | |
---|
| 95 | if (this->health_ <= 0) |
---|
| 96 | this->death(); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | void Pawn::setHealth(float health) |
---|
| 100 | { |
---|
| 101 | this->health_ = min(health, this->maxHealth_); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | void Pawn::damage(float damage, Pawn* originator) |
---|
| 105 | { |
---|
| 106 | this->setHealth(this->health_ - damage); |
---|
| 107 | this->lastHitOriginator_ = originator; |
---|
| 108 | |
---|
| 109 | // play damage effect |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | void Pawn::hit(Pawn* originator, const Vector3& force, float damage) |
---|
| 113 | { |
---|
| 114 | this->damage(damage, originator); |
---|
| 115 | this->setVelocity(this->getVelocity() + force); |
---|
| 116 | |
---|
| 117 | // play hit effect |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | void Pawn::kill() |
---|
| 121 | { |
---|
| 122 | this->damage(this->health_); |
---|
| 123 | this->death(); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | void Pawn::spawn() |
---|
| 127 | { |
---|
| 128 | // play spawn effect |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | void Pawn::death() |
---|
| 132 | { |
---|
| 133 | this->bAlive_ = false; |
---|
| 134 | if (this->getGametype()) |
---|
| 135 | this->getGametype()->pawnKilled(this, this->lastHitOriginator_); |
---|
| 136 | if (this->getPlayer()) |
---|
| 137 | this->getPlayer()->stopControl(this); |
---|
| 138 | |
---|
| 139 | delete this; |
---|
| 140 | |
---|
| 141 | // play death effect |
---|
| 142 | } |
---|
| 143 | |
---|
[2145] | 144 | void Pawn::fire(WeaponMode::Enum fireMode) |
---|
[2098] | 145 | { |
---|
[2288] | 146 | COUT(0) << "Pawn::fire" << std::endl; |
---|
[2098] | 147 | if (this->weaponSystem_) |
---|
[2145] | 148 | this->weaponSystem_->fire(fireMode); |
---|
[2098] | 149 | } |
---|
| 150 | |
---|
[2072] | 151 | void Pawn::postSpawn() |
---|
| 152 | { |
---|
| 153 | this->setHealth(this->initialHealth_); |
---|
| 154 | this->spawn(); |
---|
| 155 | } |
---|
[2288] | 156 | |
---|
[2308] | 157 | |
---|
[2319] | 158 | |
---|
[2288] | 159 | void Pawn::setWeaponSlot(WeaponSlot * wSlot) |
---|
[2327] | 160 | { |
---|
| 161 | COUT(0) << "Pawn::setWeaponSlot" << std::endl; |
---|
| 162 | this->weaponSystem_->attachWeaponSlot(wSlot); } |
---|
[2288] | 163 | WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const |
---|
[2308] | 164 | { return this->weaponSystem_->getWeaponSlotPointer(index); } |
---|
[2319] | 165 | |
---|
[2308] | 166 | void Pawn::setWeaponPack(WeaponPack * wPack) |
---|
[2327] | 167 | { |
---|
| 168 | COUT(0) << "Pawn::setWeaponPack" << std::endl; |
---|
[2337] | 169 | this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() ); |
---|
| 170 | wPack->setParentWeaponSystem(this->weaponSystem_); |
---|
| 171 | wPack->setWeaponSystemToAllWeapons(this->weaponSystem_); |
---|
| 172 | } |
---|
| 173 | |
---|
[2319] | 174 | WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const |
---|
| 175 | { return this->weaponSystem_->getWeaponPackPointer(firemode); } |
---|
| 176 | |
---|
[2308] | 177 | void Pawn::setWeaponSet(WeaponSet * wSet) |
---|
[2327] | 178 | { |
---|
| 179 | COUT(0) << "Pawn::setWeaponSet" << std::endl; |
---|
| 180 | this->weaponSystem_->attachWeaponSet(wSet); } |
---|
[2308] | 181 | WeaponSet * Pawn::getWeaponSet(unsigned int index) const |
---|
| 182 | { return this->weaponSystem_->getWeaponSetPointer(index); } |
---|
| 183 | |
---|
[2072] | 184 | } |
---|