Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

fixed parentWeaponSystem-Pointer for all WeaponPacks and its Weapons

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