Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Pawn.cc @ 2274

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

The SpaceShips HUD is working again (Speedbar and Radar)

  • Property svn:eol-style set to native
File size: 3.9 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->setRadarObjectColour(ColourValue::Red);
65        this->setRadarObjectShape(RadarViewable::Dot);
66
67        this->registerVariables();
68    }
69
70    Pawn::~Pawn()
71    {
72    }
73
74    void Pawn::XMLPort(Element& xmlelement, XMLPort::Mode mode)
75    {
76        SUPER(Pawn, XMLPort, xmlelement, mode);
77
78        XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
79        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
80        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
81    }
82
83    void Pawn::registerVariables()
84    {
85        REGISTERDATA(this->bAlive_, direction::toclient);
86        REGISTERDATA(this->health_, direction::toclient);
87    }
88
89    void Pawn::tick(float dt)
90    {
91        SUPER(Pawn, tick, dt);
92
93        if (this->health_ <= 0)
94            this->death();
95    }
96
97    void Pawn::setHealth(float health)
98    {
99        this->health_ = min(health, this->maxHealth_);
100    }
101
102    void Pawn::damage(float damage, Pawn* originator)
103    {
104        this->setHealth(this->health_ - damage);
105        this->lastHitOriginator_ = originator;
106
107        // play damage effect
108    }
109
110    void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
111    {
112        this->damage(damage, originator);
113        this->setVelocity(this->getVelocity() + force);
114
115        // play hit effect
116    }
117
118    void Pawn::kill()
119    {
120        this->damage(this->health_);
121        this->death();
122    }
123
124    void Pawn::spawn()
125    {
126        // play spawn effect
127    }
128
129    void Pawn::death()
130    {
131        this->bAlive_ = false;
132        if (this->getGametype())
133            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
134        if (this->getPlayer())
135            this->getPlayer()->stopControl(this);
136
137        delete this;
138
139        // play death effect
140    }
141
142    void Pawn::fire()
143    {
144        if (this->weaponSystem_)
145            this->weaponSystem_->fire();
146    }
147
148    void Pawn::postSpawn()
149    {
150        this->setHealth(this->initialHealth_);
151        this->spawn();
152    }
153}
Note: See TracBrowser for help on using the repository browser.