Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lodfinal/src/orxonox/objects/worldentities/pawns/Pawn.cc @ 2845

Last change on this file since 2845 was 2171, checked in by landauf, 16 years ago

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

  • Property svn:eol-style set to native
File size: 3.8 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#include "objects/weaponSystem/WeaponSystem.h"
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        this->weaponSystem_ = 0;
55
56        /*
57        //WeaponSystem
58        weaponSystem_ = new WeaponSystem();
59        WeaponSet * weaponSet1 = new WeaponSet(1);
60        this->weaponSystem_->attachWeaponSet(weaponSet1);
61        this->weaponSystem_->getWeaponSetPointer(0)->getWeaponSlotPointer(0)->setAmmoType(true);
62        */
63
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    }
79
80    void Pawn::registerVariables()
81    {
82        REGISTERDATA(this->bAlive_, direction::toclient);
83        REGISTERDATA(this->health_, direction::toclient);
84    }
85
86    void Pawn::tick(float dt)
87    {
88        SUPER(Pawn, tick, dt);
89
90        if (this->health_ <= 0)
91            this->death();
92    }
93
94    void Pawn::setHealth(float health)
95    {
96        this->health_ = min(health, this->maxHealth_);
97    }
98
99    void Pawn::damage(float damage, Pawn* originator)
100    {
101        this->setHealth(this->health_ - damage);
102        this->lastHitOriginator_ = originator;
103
104        // play damage effect
105    }
106
107    void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
108    {
109        this->damage(damage, originator);
110        this->setVelocity(this->getVelocity() + force);
111
112        // play hit effect
113    }
114
115    void Pawn::kill()
116    {
117        this->damage(this->health_);
118        this->death();
119    }
120
121    void Pawn::spawn()
122    {
123        // play spawn effect
124    }
125
126    void Pawn::death()
127    {
128        this->bAlive_ = false;
129        if (this->getGametype())
130            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
131        if (this->getPlayer())
132            this->getPlayer()->stopControl(this);
133
134        delete this;
135
136        // play death effect
137    }
138
139    void Pawn::fire()
140    {
141        if (this->weaponSystem_)
142            this->weaponSystem_->fire();
143    }
144
145    void Pawn::postSpawn()
146    {
147        this->setHealth(this->initialHealth_);
148        this->spawn();
149    }
150}
Note: See TracBrowser for help on using the repository browser.