Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 30, 2012, 11:08:17 PM (12 years ago)
Author:
landauf
Message:

merged branch presentation2012merge back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pickup/items/HealthPickup.cc

    r8864 r9348  
    3838#include "core/XMLPort.h"
    3939
    40 #include "pickup/PickupIdentifier.h"
    4140#include "worldentities/pawns/Pawn.h"
    4241
     
    8786    /**
    8887    @brief
    89         Initializes the PickupIdentifier of this pickup.
    90     */
    91     void HealthPickup::initializeIdentifier(void)
    92     {
    93         std::stringstream stream;
    94         stream << this->getHealth();
    95         std::string type1 = "health";
    96         std::string val1 = stream.str();
    97         this->pickupIdentifier_->addParameter(type1, val1);
    98 
    99         std::string val2 = this->getHealthType();
    100         std::string type2 = "healthType";
    101         this->pickupIdentifier_->addParameter(type2, val2);
    102 
    103         stream.clear();
    104         stream << this->getHealthRate();
    105         std::string val3 = stream.str();
    106         std::string type3 = "healthRate";
    107         this->pickupIdentifier_->addParameter(type3, val3);
    108     }
    109 
    110     /**
    111     @brief
    11288        Method for creating a HealthPickup object through XML.
    11389    */
     
    11894        XMLPortParam(HealthPickup, "health", setHealth, getHealth, xmlelement, mode);
    11995        XMLPortParam(HealthPickup, "healthRate", setHealthRate, getHealthRate, xmlelement, mode);
    120         XMLPortParam(HealthPickup, "healthType", setHealthType, getHealthType, xmlelement, mode);
     96        XMLPortParam(HealthPickup, "healthType", setHealthTypeAsString, getHealthTypeAsString, xmlelement, mode);
    12197
    12298        if(!this->isContinuous())
    123             this->healthRate_ = 0.0f;
    124 
    125         this->initializeIdentifier();
     99            this->setHealthRate(0.0f); // TODO: this logic should be inside tick(), not in XMLPort
    126100    }
    127101
     
    151125            this->setHealth(this->getHealth()-health);
    152126
    153             switch(this->getHealthTypeDirect())
     127            switch(this->getHealthType())
    154128            {
    155129                case pickupHealthType::permanent:
     
    198172
    199173                float health = 0.0f;
    200                 switch(this->getHealthTypeDirect())
     174                switch(this->getHealthType())
    201175                {
    202176                    case pickupHealthType::permanent:
     
    227201        else
    228202        {
    229             if(this->getHealthTypeDirect() == pickupHealthType::temporary)
     203            if(this->getHealthType() == pickupHealthType::temporary)
    230204            {
    231205                PickupCarrier* carrier = this->getCarrier();
    232                 Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     206                Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    233207
    234208                if(pawn == NULL)
     
    264238    {
    265239        PickupCarrier* carrier = this->getCarrier();
    266         Pawn* pawn = dynamic_cast<Pawn*>(carrier);
     240        Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    267241
    268242        if(pawn == NULL)
     
    270244
    271245        return pawn;
    272     }
    273 
    274     /**
    275     @brief
    276         Creates a duplicate of the input OrxonoxClass.
    277     @param item
    278         A pointer to the Orxonox class.
    279     */
    280     void HealthPickup::clone(OrxonoxClass*& item)
    281     {
    282         if(item == NULL)
    283             item = new HealthPickup(this);
    284 
    285         SUPER(HealthPickup, clone, item);
    286 
    287         HealthPickup* pickup = dynamic_cast<HealthPickup*>(item);
    288         pickup->setHealth(this->getHealth());
    289         pickup->setHealthRate(this->getHealthRate());
    290         pickup->setHealthTypeDirect(this->getHealthTypeDirect());
    291 
    292         pickup->initializeIdentifier();
    293246    }
    294247
     
    299252        Returns the health type as a string.
    300253    */
    301     const std::string& HealthPickup::getHealthType(void) const
    302     {
    303         switch(this->getHealthTypeDirect())
     254    const std::string& HealthPickup::getHealthTypeAsString(void) const
     255    {
     256        switch(this->getHealthType())
    304257        {
    305258            case pickupHealthType::limited:
     
    352305        The type as a string.
    353306    */
    354     void HealthPickup::setHealthType(std::string type)
     307    void HealthPickup::setHealthTypeAsString(const std::string& type)
    355308    {
    356309        if(type == HealthPickup::healthTypeLimited_s)
    357             this->setHealthTypeDirect(pickupHealthType::limited);
     310            this->setHealthType(pickupHealthType::limited);
    358311        else if(type == HealthPickup::healthTypeTemporary_s)
    359             this->setHealthTypeDirect(pickupHealthType::temporary);
     312            this->setHealthType(pickupHealthType::temporary);
    360313        else if(type == HealthPickup::healthTypePermanent_s)
    361             this->setHealthTypeDirect(pickupHealthType::permanent);
     314            this->setHealthType(pickupHealthType::permanent);
    362315        else
    363316            orxout(internal_error, context::pickups) << "Invalid healthType '" << type << "' in HealthPickup." << endl;
Note: See TracChangeset for help on using the changeset viewer.