Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/weapon2/src/orxonox/objects/worldentities/pawns/Pawn.cc @ 2391

Last change on this file since 2391 was 2391, checked in by polakma, 16 years ago

fixed projectile, particle effect, reloadingTimer and magazineTimer

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
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
38
39namespace 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
55        weaponSystem_ = new WeaponSystem(this);
56
57        this->registerVariables();
58    }
59
60    Pawn::~Pawn()
61    {
62    }
63
64    void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode)
65    {
66        SUPER(Pawn, XMLPort, xmlelement, mode);
67
68        XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
69        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
70        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
71
72        XMLPortObject(Pawn, WeaponSlot, "weaponslots", setWeaponSlot, getWeaponSlot, xmlelement, mode);
73        XMLPortObject(Pawn, WeaponSet, "weaponsets", setWeaponSet, getWeaponSet, xmlelement, mode);
74        XMLPortObject(Pawn, WeaponPack, "weapons", setWeaponPack, getWeaponPack, xmlelement, mode);
75
76        }
77
78    void Pawn::registerVariables()
79    {
80        REGISTERDATA(this->bAlive_, network::direction::toclient);
81        REGISTERDATA(this->health_, network::direction::toclient);
82    }
83
84    void Pawn::tick(float dt)
85    {
86        SUPER(Pawn, tick, dt);
87
88        if (this->health_ <= 0)
89            this->death();
90    }
91
92    void Pawn::setHealth(float health)
93    {
94        this->health_ = min(health, this->maxHealth_);
95    }
96
97    void Pawn::damage(float damage, Pawn* originator)
98    {
99        this->setHealth(this->health_ - damage);
100        this->lastHitOriginator_ = originator;
101
102        // play damage effect
103    }
104
105    void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
106    {
107        this->damage(damage, originator);
108        this->setVelocity(this->getVelocity() + force);
109
110        // play hit effect
111    }
112
113    void Pawn::kill()
114    {
115        this->damage(this->health_);
116        this->death();
117    }
118
119    void Pawn::spawn()
120    {
121        // play spawn effect
122    }
123
124    void Pawn::death()
125    {
126        this->bAlive_ = false;
127        if (this->getGametype())
128            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
129        if (this->getPlayer())
130            this->getPlayer()->stopControl(this);
131
132        delete this;
133
134        // play death effect
135    }
136
137    void Pawn::fire(WeaponMode::Enum fireMode)
138    {
139COUT(0) << "Pawn::fire" << std::endl;
140        if (this->weaponSystem_)
141            this->weaponSystem_->fire(fireMode);
142    }
143
144    void Pawn::postSpawn()
145    {
146        this->setHealth(this->initialHealth_);
147        this->spawn();
148    }
149
150
151
152    void Pawn::setWeaponSlot(WeaponSlot * wSlot)
153    {   
154COUT(0) << "Pawn::setWeaponSlot" << std::endl;
155        this->attach(wSlot);
156        this->weaponSystem_->attachWeaponSlot(wSlot);   }
157
158    WeaponSlot * Pawn::getWeaponSlot(unsigned int index) const
159    {   return this->weaponSystem_->getWeaponSlotPointer(index);    }
160   
161    void Pawn::setWeaponPack(WeaponPack * wPack)
162    {   
163COUT(0) << "Pawn::setWeaponPack" << std::endl;
164        wPack->setParentWeaponSystem(this->weaponSystem_);
165        wPack->setParentWeaponSystemToAllWeapons(this->weaponSystem_);
166        this->weaponSystem_->attachWeaponPack( wPack,wPack->getFireMode() );
167        wPack->attachNeededMunitionToAllWeapons();
168    }
169
170    WeaponPack * Pawn::getWeaponPack(unsigned int firemode) const
171    {   return this->weaponSystem_->getWeaponPackPointer(firemode);    }
172   
173    void Pawn::setWeaponSet(WeaponSet * wSet)
174    {   
175COUT(0) << "Pawn::setWeaponSet" << std::endl;
176        this->weaponSystem_->attachWeaponSet(wSet);   }
177    WeaponSet * Pawn::getWeaponSet(unsigned int index) const
178    {   return this->weaponSystem_->getWeaponSetPointer(index);    }
179
180}
Note: See TracBrowser for help on using the repository browser.