Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 13, 2014, 11:45:47 AM (11 years ago)
Author:
noep
Message:

Fixed yet another segfault (which we hadn't seen yet).
Cleared emptyLevel, created two testlevels (testing with boxes)

File:
1 edited

Legend:

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

    r10052 r10053  
    4949    {
    5050        RegisterObject(PartDestructionEvent);
    51         this->isValid_ = false;
     51        this->setValid(true);
    5252    }
    5353
     
    7676    void PartDestructionEvent::execute()
    7777    {
    78         if(!this->isValid_)
     78        // Do not execute if this event is invalid
     79        if(!isValid())
    7980        {
    80             //orxout(internal_warning) <<
     81            orxout(internal_warning) << "Attempted to execute an invalid PartDestructionEvent!" << endl;
    8182            return;
    8283        }
    8384
     85        if (this->targetType_ == "ship")
     86        {
     87            switch (this->targetParam_) {
     88            case shieldhealth:
     89                this->parent_->getParent()->setShieldHealth(operate(this->parent_->getParent()->getShieldHealth()));
     90                break;
     91            default:
     92                break;
     93            }
     94            this->setValid(false);
     95            return;
     96        }
     97    }
    8498
     99    void PartDestructionEvent::setParent(ShipPart* part)
     100    {
     101        this->parent_ = part;
    85102    }
    86103
     
    95112
    96113        // Error, if invalid target-type was entered.
    97         orxout(internal_warning) << type << " is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon" << endl;
    98         this->isValid_ = false;
     114        orxout(internal_warning) << "\"" << type << "\" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon" << endl;
     115        this->setValid(false);
    99116        return;
    100117    }
     
    117134        {
    118135            orxout(internal_warning) << "No valid target-type defined. Cannot set target-param for this PartDestructionEvent." << endl;
    119             this->isValid_ = false;
     136            this->setValid(false);
    120137            return;
    121138        }
     
    131148            if (param == "shieldhealth")
    132149            {
    133                 this->targetParam_ = param;
     150                this->targetParam_ = shieldhealth;
    134151                return;
    135152            }
    136153
    137             orxout(internal_warning) << param << " is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate" << endl;
     154            orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate" << endl;
    138155            return;
    139156        }
     157
     158        orxout(internal_warning) << "No valid target-param defined. The chosen param is either invalid or not available for this target-type." << endl;
     159        this->setValid(false);
    140160    }
    141161
     
    143163    {
    144164        // * + - destroy
    145         this->operation_ = operation;
     165        if ((operation == "*") || (operation == "+") || (operation == "-") || (operation == "destroy"))
     166        {
     167            this->operation_ = operation;
     168            return;
     169        }
     170        this->operation_ = "NULL";
     171        orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - destroy" << endl;
     172    }
     173
     174    float PartDestructionEvent::operate(float input)
     175    {
     176        if (this->operation_ == "*")
     177            return input * this->value_;
     178        if (this->operation_ == "+")
     179            return input + this->value_;
     180        if (this->operation_ == "-")
     181            return input - this->value_;
     182        if (this->operation_ == "destroy")
     183        {
     184            return 0;
     185        }
     186        return 0;
    146187    }
    147188
Note: See TracChangeset for help on using the changeset viewer.