Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 14, 2014, 8:25:08 PM (11 years ago)
Author:
noep
Message:

Cleaned up code. Added console command "ModularSpaceShip killshippart [string]" which allows manual destruction of a ShipPart by name. Added more functionality to PartDestructionEvents.

Location:
code/branches/modularships/src/orxonox/worldentities/pawns
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10054 r10055  
    3737#include "util/Math.h"
    3838#include "gametypes/Gametype.h"
     39#include "core/command/ConsoleCommand.h"
    3940
    4041#include "items/ShipPart.h"
     
    4849namespace orxonox
    4950{
     51    SetConsoleCommand("ModularSpaceShip", "killshippart", &ModularSpaceShip::killShipPart);
     52
    5053    RegisterClass(ModularSpaceShip);
    5154
     55    std::map<StaticEntity*, ShipPart*>* ModularSpaceShip::partMap_s = 0;
     56
    5257    ModularSpaceShip::ModularSpaceShip(Context* context) : SpaceShip(context)
    5358    {
     
    5560
    5661        this->registerVariables();
     62
     63        ModularSpaceShip::partMap_s = &(this->partMap_);
    5764
    5865    }
     
    7784    }
    7885
     86    /**
     87    @brief
     88        Searches for ShipParts matching to StaticEntities.
     89    */
    7990    void ModularSpaceShip::updatePartAssignment()
    8091    {
     
    115126    }
    116127
     128    /**
     129    @brief
     130        Creates a new assignment for the given StaticEntity and ShipPart in the partMap_
     131    @param entity
     132        A pointer to the StaticEntity
     133    @param part
     134        A pointer to the ShipPart.
     135    */
    117136    void ModularSpaceShip::addPartEntityAssignment(StaticEntity* entity, ShipPart* part)
    118137    {
     
    150169    }
    151170
    152     //FIXME: (noep) finish
    153     // void ModularSpaceShip::attach
    154 
     171    /**
     172    @brief
     173        If the damage occurred on an attached StaticEntity, the damage is given to the corresponding ShipPart to handle.
     174    */
    155175    void ModularSpaceShip::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
    156176    {
    157         /*orxout() << "Mdamage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl;
    158         orxout() << "UserPtr of said collisionShape: " << cs->getUserPointer() << endl;
    159 
    160 
    161             // Print all attached objects & parts
    162         /*
    163         orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
    164 
    165         for (int i=0; i<50; i++)
    166         {
    167             if (this->getAttachedObject(i)==NULL)
    168                 break;
    169             orxout() << " " << i << ": " << this->getAttachedObject(i) << " (" << this->getAttachedObject(i)->getName() << ")";
    170             orxout() << endl;
    171         }
    172 
    173         orxout() << "  Attached ShipParts:" << endl;
    174         for(unsigned int i=0; i < this->partList_.size(); i++)
    175         {
    176             orxout() << "  " << i << ": " << this->partList_[i] << " (" << this->partList_[i]->getName() << ")" << endl;
    177         }*/
    178 
    179 
    180         //int collisionShapeIndex = this->isMyCollisionShape(cs);
    181         //orxout() << collisionShapeIndex << endl;
    182 
    183         //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
    184 
    185177        if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
    186178            this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
    187179        else
    188180            SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
    189 
    190         /*
    191         // Applies multiplier given by the DamageBoost Pickup.
    192         if (originator)
    193             damage *= originator->getDamageMultiplier();
    194 
    195         if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    196         {
    197             if (shielddamage >= this->getShieldHealth())
    198             {
    199                 this->setShieldHealth(0);
    200                 this->setHealth(this->health_ - (healthdamage + damage));
    201             }
    202             else
    203             {
    204                 this->setShieldHealth(this->shieldHealth_ - shielddamage);
    205 
    206                 // remove remaining shieldAbsorpton-Part of damage from shield
    207                 shielddamage = damage * this->shieldAbsorption_;
    208                 shielddamage = std::min(this->getShieldHealth(),shielddamage);
    209                 this->setShieldHealth(this->shieldHealth_ - shielddamage);
    210 
    211                 // set remaining damage to health
    212                 this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
    213             }
    214 
    215             this->lastHitOriginator_ = originator;
    216         }*/
     181    }
     182
     183    /**
     184    @brief
     185        Kills the ShipPart with the given name. Used from the console-command "ModularSpaceShip killshippart [string]".
     186    @param name
     187        The name of the part to be killed.
     188    */
     189    void ModularSpaceShip::killShipPart(std::string name)
     190    {
     191        for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_s->begin(); it != ModularSpaceShip::partMap_s->end(); ++it)
     192        {
     193            if (it->second->getName() == name)
     194            {
     195                it->second->death();
     196                return;
     197            }
     198        }
     199        orxout(internal_warning) << "Could not apply damage to ShipPart \"" << name << "\". Part not found." << endl;
    217200    }
    218201
     
    261244    }
    262245
     246
     247    /**
     248    @brief
     249        Removes a ShipPart from the SpaceShip, destroying the corresponding StaticEntity
     250    @param part
     251        The ShipPart to be removed.
     252    */
    263253    void ModularSpaceShip::removeShipPart(ShipPart* part)
    264254    {
     
    309299        orxout() << "MSS: detach()" << endl;
    310300
    311         this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
     301        //this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
    312302        this->detachCollisionShape(object->collisionShape_);  // after succeeding, causes a crash in the collision handling
    313303        //this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h

    r10054 r10055  
    113113            virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL);
    114114
     115            static void killShipPart(std::string name);
     116
    115117            void addShipPart(ShipPart* part);
    116118            ShipPart* getShipPart(unsigned int index);
     
    127129        private:
    128130            void registerVariables();
    129             std::vector<ShipPart*> partList_;  // The list of all Parts mounted on this ModularSpaceShip.
    130             std::vector<SmartPtr<StaticEntity>*> entityPtrList_;
    131             std::vector<SmartPtr<CollisionShape>*> csPtrList_;
    132             std::map<StaticEntity*, ShipPart*> partMap_;
     131            std::vector<ShipPart*> partList_;                       // The list of all Parts mounted on this ModularSpaceShip.
     132            std::map<StaticEntity*, ShipPart*> partMap_;            // Map of Part-Entity-assignments
     133            static std::map<StaticEntity*, ShipPart*>* partMap_s;
    133134       
    134135    };
Note: See TracChangeset for help on using the changeset viewer.