Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc @ 2087

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

merged objecthierarchy branch back to trunk

  • Property svn:eol-style set to native
File size: 3.3 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
38namespace orxonox
39{
40    CreateFactory(Pawn);
41
42    Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator)
43    {
44        RegisterObject(Pawn);
45
46        this->bAlive_ = false;
47
48        this->health_ = 0;
49        this->maxHealth_ = 0;
50        this->initialHealth_ = 0;
51
52        this->lastHitOriginator_ = 0;
53
54        this->registerVariables();
55    }
56
57    Pawn::~Pawn()
58    {
59    }
60
61    void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode)
62    {
63        SUPER(Pawn, XMLPort, xmlelement, mode);
64
65        XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
66        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
67        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
68    }
69
70    void Pawn::registerVariables()
71    {
72        REGISTERDATA(this->bAlive_, network::direction::toclient);
73        REGISTERDATA(this->health_, network::direction::toclient);
74    }
75
76    void Pawn::tick(float dt)
77    {
78        SUPER(Pawn, tick, dt);
79
80        if (this->health_ <= 0)
81            this->death();
82    }
83
84    void Pawn::setHealth(float health)
85    {
86        this->health_ = min(health, this->maxHealth_);
87    }
88
89    void Pawn::damage(float damage, Pawn* originator)
90    {
91        this->setHealth(this->health_ - damage);
92        this->lastHitOriginator_ = originator;
93
94        // play damage effect
95    }
96
97    void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
98    {
99        this->damage(damage, originator);
100        this->setVelocity(this->getVelocity() + force);
101
102        // play hit effect
103    }
104
105    void Pawn::kill()
106    {
107        this->damage(this->health_);
108        this->death();
109    }
110
111    void Pawn::spawn()
112    {
113        // play spawn effect
114    }
115
116    void Pawn::death()
117    {
118        this->bAlive_ = false;
119        if (this->getGametype())
120            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
121        if (this->getPlayer())
122            this->getPlayer()->stopControl(this);
123
124        delete this;
125
126        // play death effect
127    }
128
129    void Pawn::postSpawn()
130    {
131        this->setHealth(this->initialHealth_);
132        this->spawn();
133    }
134}
Note: See TracBrowser for help on using the repository browser.