Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed WeaponPack attaching

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