Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2273 was 2273, checked in by polakma, 15 years ago

small changes for tests

  • Property svn:eol-style set to native
File size: 3.7 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        this->weaponSystem_ = 0;
55
56        //WeaponSystem
57        weaponSystem_ = new WeaponSystem(this);
58        WeaponSet * weaponSet1 = new WeaponSet(this,1);
59        this->weaponSystem_->attachWeaponSet(weaponSet1);
60
61
62        this->registerVariables();
63    }
64
65    Pawn::~Pawn()
66    {
67    }
68
69    void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode)
70    {
71        SUPER(Pawn, XMLPort, xmlelement, mode);
72
73        XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
74        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
75        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
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    {
139        if (this->weaponSystem_)
140            this->weaponSystem_->fire(fireMode);
141    }
142
143    void Pawn::postSpawn()
144    {
145        this->setHealth(this->initialHealth_);
146        this->spawn();
147    }
148}
Note: See TracBrowser for help on using the repository browser.