Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2014, 10:38:09 PM (11 years ago)
Author:
noep
Message:

Added explosions. (Because who doesn't love explosions.) Added printing health-status of shipparts to chat. Removed more debug-output.

Location:
code/branches/modularships/src/orxonox/items
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/src/orxonox/items/ShipPart.cc

    r10058 r10067  
    4141#include "worldentities/StaticEntity.h"
    4242#include "items/PartDestructionEvent.h"
     43#include "worldentities/BigExplosion.h"
     44#include "chat/ChatManager.h"
    4345
    4446
     
    7072        XMLPortParam(ShipPart, "damageabsorption", setDamageAbsorption, getDamageAbsorption, xmlelement, mode).defaultValues(0.5);
    7173
     74        XMLPortParamTemplate(ShipPart, "explosionposition", setExplosionPosition, getExplosionPosition, xmlelement, mode, Vector3);
     75
    7276        XMLPortObject(ShipPart, PartDestructionEvent, "destructionevents", addDestructionEvent, getDestructionEvent, xmlelement, mode);
    73 
    74         /*
    75         XMLPortParam(ShipPart, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
    76         XMLPortParam(ShipPart, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
    77         XMLPortParam(ShipPart, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
    78         XMLPortParam(ShipPart, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
    79 
    80         XMLPortParam(ShipPart, "sShipPartparticlesource", setSShipPartParticleSource, getSShipPartParticleSource, xmlelement, mode);
    81         XMLPortParam(ShipPart, "sShipPartparticleduration", setSShipPartParticleDuration, getSShipPartParticleDuration, xmlelement, mode).defaultValues(3.0f);
    82         XMLPortParam(ShipPart, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
    83 
    84         XMLPortParam(ShipPart, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
    85         XMLPortParam(ShipPart, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
    86 
    87         XMLPortParam(ShipPart, "explosionSound",  setExplosionSound,  getExplosionSound,  xmlelement, mode);
    88 
    89         XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode );
    90         */
    9177    }
    9278
     
    10288            return;
    10389
     90        this->explode();
    10491        this->setAlive(false);
    10592
     
    115102        // Remove this ShipPart from the parent.
    116103        this->parent_->removeShipPart(this);
    117         orxout() << this->getName() << " has died." << endl;
     104    }
     105
     106    void ShipPart::explode()
     107    {
     108        BigExplosion* chunk = new BigExplosion(this->getContext());
     109        chunk->setPosition(this->parent_->getPosition() + this->parent_->getOrientation() * (this->explosionPosition_));
     110        //chunk->setPosition(this->parent_->getPosition() + this->parent_->getOrientation() * Vector3(this->entityList_[0]->getLocalInertia()));
     111        chunk->setVelocity(this->parent_->getVelocity());
     112
     113        // this->explosionSound_->setPosition(this->parent_->getPosition());
     114        // this->explosionSound_->play();
    118115    }
    119116
     
    160157    }
    161158
    162     void ShipPart::printEntities()
    163     {
    164         orxout() << "ShipPart " << this->getName() << " has the following entities assigned:" << endl;
    165         for(unsigned int j = 0; j < this->entityList_.size(); j++)
    166         {
    167             orxout() << "  " << this->entityList_[j]->getName() << endl;
    168         }
    169     }
    170 
    171159    /**
    172160    @brief
     
    221209    void ShipPart::handleHit(float damage, float healthdamage, float shielddamage, Pawn* originator)
    222210    {
    223         orxout() << "ShipPart " <<this->getName() << " is handling a hit!" << endl;
    224 
    225211        if (parent_->getGametype() && parent_->getGametype()->allowPawnDamage(parent_, originator))
    226212        {
     
    247233        if (this->health_ < 0)
    248234            this->death();
    249         orxout() << "Health of ShipPart " << this->getName() << " is " << this->getHealth() << endl;
     235
     236        // (Ugly) Chatoutput of health, until a GUI for modularspaceships-shipparts is implemented.
     237        if (this->health_ < 0.2 * this->maxHealth_)
     238        {
     239            ChatManager::message("ShipPart " + this->getName() + " remaining health is 20%!");
     240            return;
     241        }
     242        if (this->health_ < 0.4 * this->maxHealth_)
     243        {
     244            ChatManager::message("ShipPart " + this->getName() + " remaining health is 40%!");
     245            return;
     246        }
     247        if (this->health_ < 0.6 * this->maxHealth_)
     248        {
     249            ChatManager::message("ShipPart " + this->getName() + " remaining health is 60%!");
     250            return;
     251        }
     252        if (this->health_ < 0.8 * this->maxHealth_)
     253        {
     254            ChatManager::message("ShipPart " + this->getName() + " remaining health is 80%!");
     255            return;
     256        }
    250257    }
    251258
  • code/branches/modularships/src/orxonox/items/ShipPart.h

    r10058 r10067  
    5252
    5353            virtual void death();
     54            virtual void explode();
    5455
    5556            //virtual void attachTo(Pawn* newParent);
     
    6263            void addDestructionEvent(PartDestructionEvent* event);
    6364            PartDestructionEvent* getDestructionEvent(unsigned int index);
    64 
    65             void printEntities(); // FIXME: (noep) remove debug
    6665
    6766            virtual void setDamageAbsorption(float value);
     
    101100                { return this->initialHealth_; }
    102101
     102            inline void setExplosionPosition(Vector3 pos)
     103                { this->explosionPosition_ = pos; }
     104            inline Vector3 getExplosionPosition()
     105                { return this->explosionPosition_; }
     106
    103107
    104108            // FIXME: (noep) Why doesn't this work? Works fine in Engine.h
     
    121125            bool eventExecution_;
    122126
     127            Vector3 explosionPosition_;
     128
    123129
    124130    }; // tolua_export
Note: See TracChangeset for help on using the changeset viewer.