Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc @ 10011

Last change on this file since 10011 was 10011, checked in by noep, 11 years ago

Cleaned up the process passing the collisionshape which was hit to the Pawn. Started implementation of ModularSpaceShip and ShipPart.

File size: 5.0 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 *      Noe Pedrazzini
26 *
27 */
28
29#include "ModularSpaceShip.h"
30
31#include <BulletDynamics/Dynamics/btRigidBody.h>
32
33#include "core/CoreIncludes.h"
34#include "core/config/ConfigValueIncludes.h"
35#include "core/Template.h"
36#include "core/XMLPort.h"
37#include "util/Math.h"
38#include "gametypes/Gametype.h"
39
40#include "ShipPart.h"
41
42
43
44namespace orxonox
45{
46    RegisterClass(ModularSpaceShip);
47
48    ModularSpaceShip::ModularSpaceShip(Context* context) : SpaceShip(context)
49    {
50        RegisterObject(ModularSpaceShip);
51
52        this->registerVariables();
53
54    }
55
56    ModularSpaceShip::~ModularSpaceShip()
57    {
58        if (this->isInitialized())
59        {
60
61        }
62    }
63
64    void ModularSpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
65    {
66        SUPER(ModularSpaceShip, XMLPort, xmlelement, mode);
67        XMLPortObject(ModularSpaceShip, ShipPart, "parts", addShipPart, getShipPart, xmlelement, mode);
68    }
69
70    void ModularSpaceShip::registerVariables()
71    {
72        return;
73    }
74
75    void ModularSpaceShip::updatePartAssignment()
76    {
77
78    }
79
80    //FIXME: (noep) finish
81    // void ModularSpaceShip::attach
82
83    void ModularSpaceShip::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
84    {
85        orxout() << "Mdamage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl;
86        orxout() << "Attached parts:" << endl;
87        for(unsigned int i=0; i < this->partList_.size(); i++)
88        {
89            orxout() << "  " << i << ": " << this->partList_[i] << " (" << this->partList_[i]->getName() << ")" << endl;
90        }
91
92        int collisionShapeIndex = this->isMyCollisionShape(cs);
93        orxout() << collisionShapeIndex << endl;
94
95        // Applies multiplier given by the DamageBoost Pickup.
96        if (originator)
97            damage *= originator->getDamageMultiplier();
98
99        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
100        {
101            if (shielddamage >= this->getShieldHealth())
102            {
103                this->setShieldHealth(0);
104                this->setHealth(this->health_ - (healthdamage + damage));
105            }
106            else
107            {
108                this->setShieldHealth(this->shieldHealth_ - shielddamage);
109
110                // remove remaining shieldAbsorpton-Part of damage from shield
111                shielddamage = damage * this->shieldAbsorption_;
112                shielddamage = std::min(this->getShieldHealth(),shielddamage);
113                this->setShieldHealth(this->shieldHealth_ - shielddamage);
114
115                // set remaining damage to health
116                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
117            }
118
119            this->lastHitOriginator_ = originator;
120        }
121    }
122
123    /**
124    @brief
125        Add a ShipPart to the SpaceShip.
126    @param engine
127        A pointer to the ShipPart to be added.
128    */
129    void ModularSpaceShip::addShipPart(ShipPart* part)
130    {
131        OrxAssert(part != NULL, "The ShipPart cannot be NULL.");
132        this->partList_.push_back(part);
133        //part->addToSpaceShip(this); //FIXME: (noep) add
134        this->updatePartAssignment();
135    }
136
137    /**
138    @brief
139        Get the i-th ShipPart of the SpaceShip.
140    @return
141        Returns a pointer to the i-the ShipPart. NULL if there is no ShipPart with that index.
142    */
143    ShipPart* ModularSpaceShip::getShipPart(unsigned int index)
144    {
145        if(this->partList_.size() >= index)
146            return NULL;
147        else
148            return this->partList_[index];
149    }
150
151    /**
152    @brief
153        Check whether the SpaceShip has a particular Engine.
154    @param engine
155        A pointer to the Engine to be checked.
156    */
157    bool ModularSpaceShip::hasShipPart(ShipPart* part) const
158    {
159        for(unsigned int i = 0; i < this->partList_.size(); i++)
160        {
161            if(this->partList_[i] == part)
162                return true;
163        }
164        return false;
165    }
166
167}
Note: See TracBrowser for help on using the repository browser.