Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/modularships/src/orxonox/ShipPart.cc @ 10015

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

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

File size: 4.2 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 *      Noe Pedrazzini
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "ShipPart.h"
30
31#include <algorithm>
32
33#include "core/CoreIncludes.h"
34#include "core/GameMode.h"
35#include "core/XMLPort.h"
36#include "network/NetworkFunction.h"
37#include "items/Item.h"
38#include "worldentities/pawns/Pawn.h"
39#include "gametypes/Gametype.h"
40#include "worldentities/pawns/ModularSpaceShip.h"
41
42
43namespace orxonox
44{
45    RegisterClass(ShipPart);
46
47    ShipPart::ShipPart(Context* context)
48        : Item(context)
49    {
50        RegisterObject(ShipPart);
51    }
52
53    ShipPart::~ShipPart()
54    {
55
56    }
57
58
59    /**
60    @brief
61        Add a StaticEntity to the ShipPart.
62    @param engine
63        A pointer to the StaticEntity to be added.
64    */
65    void ShipPart::addEntity(StaticEntity* entity)
66    {
67        OrxAssert(entity != NULL, "The Entity cannot be NULL.");
68        this->entityList_.push_back(entity);
69        //part->addToSpaceShip(this); //FIXME: (noep) add
70    }
71
72    /**
73    @brief
74        Get the i-th StaticEntity of the ShipPart.
75    @return
76        Returns a pointer to the i-the StaticEntity. NULL if there is no StaticEntity with that index.
77    */
78    StaticEntity* ShipPart::getEntity(unsigned int index)
79    {
80        if(this->entityList_.size() >= index)
81            return NULL;
82        else
83            return this->entityList_[index];
84    }
85
86    void ShipPart::setDamageAbsorption(float value)
87    {
88        this->damageAbsorption_ = value;
89    }
90
91    /**
92    @brief
93        Sets the health of the ShipPart.
94    */
95    void ShipPart::setHealth(float health)
96    {
97        this->health_ = health;
98    }
99
100    /**
101    @brief
102        Handles a received hit.
103    */
104    void ShipPart::handleHit(float damage, float healthdamage, float shielddamage, Pawn* originator)
105    {
106        if (parent_->getGametype() && parent_->getGametype()->allowPawnDamage(parent_, originator))
107        {
108            if (shielddamage >= parent_->getShieldHealth())
109            {
110                parent_->setShieldHealth(0);
111                this->setHealth(this->health_ - (healthdamage + damage) * this->damageAbsorption_);
112                parent_->setHealth(parent_->getHealth() - (healthdamage + damage) * (1 - this->damageAbsorption_));
113            }
114            else
115            {
116                parent_->setShieldHealth(parent_->getShieldHealth() - shielddamage);
117
118                // remove remaining shieldAbsorpton-Part of damage from shield
119                shielddamage = damage * parent_->getShieldAbsorption();
120                shielddamage = std::min(parent_->getShieldHealth(),shielddamage);
121                parent_->setShieldHealth(parent_->getShieldHealth() - shielddamage);
122
123                // set remaining damage to health
124                this->setHealth(this->health_ - ((damage - shielddamage) - healthdamage) * this->damageAbsorption_);
125                parent_->setHealth(parent_->getHealth() - ((damage - shielddamage) - healthdamage) * (1- this->damageAbsorption_));
126            }
127        }
128    }
129
130
131    /**
132    @brief
133        Adds the ShipPart to the input SpaceShip.
134    @param ship
135        A pointer to the SpaceShip to which the ShipPart is added.
136    */
137    /*void ShipPart::addToSpaceShip(ModularSpaceShip* ship)
138    {
139        this->parent_ = ship;
140
141        if (ship)
142        {
143            this->parentID_ = ship->getObjectID();
144            if (!ship->hasShipPart(this))
145                ship->addShipPart(this);
146        }
147    }*/
148
149}
Note: See TracBrowser for help on using the repository browser.