Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 15, 2014, 3:53:11 PM (10 years ago)
Author:
noep
Message:

Expanded functionality of PartDestructionEvents, fixed cursor not showing when flying a ModularSpaceShip

File:
1 edited

Legend:

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

    r10055 r10058  
    8383    void PartDestructionEvent::execute()
    8484    {
    85         orxout() << "Executing PartDestructionEvent " << this->getName() << endl;
    86 
    8785        // Do not execute if this event is invalid
    8886        if(!isValid())
     
    109107                this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate()));
    110108                break;
     109            case rotationthrust:
     110                this->parent_->getParent()->setRotationThrust(operate(this->parent_->getParent()->getRotationThrust()));
     111                break;
    111112            default:
    112113                break;
     
    120121            switch (this->targetParam_) {
    121122            case null:
    122                 for(unsigned int i = 0; i < this->parent_->getParent()->getEngineList().size(); i++) // FIXME: (noep) segfault on .size()
    123                 {
    124                     if(this->parent_->getParent()->getEngine(i)->getName() == this->targetName_)
    125                     {
    126                         orxout() << "engine found" << endl;
    127                         this->parent_->getParent()->removeEngine(this->parent_->getParent()->getEngine(i));
    128                         break;
    129                     }
    130                 }
     123                this->parent_->getParent()->removeEngine(this->parent_->getParent()->getEngineByName(targetName_));
    131124                break;
    132125            case boostfactor:
    133                 for(unsigned int i = 0; i < this->parent_->getParent()->getEngineList().size(); i++)
    134                 {
    135                     if(this->parent_->getParent()->getEngine(i)->getName() == this->targetName_)
    136                         this->parent_->getParent()->getEngine(i)->setBoostFactor(operate(this->parent_->getParent()->getEngine(i)->getBoostFactor()));
    137                     break;
    138                 }
     126                this->parent_->getParent()->getEngineByName(targetName_)->setBoostFactor(operate(this->parent_->getParent()->getEngineByName(targetName_)->getBoostFactor()));
     127                break;
     128            case speedfront:
     129                this->parent_->getParent()->getEngineByName(targetName_)->setMaxSpeedFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getMaxSpeedFront()));
     130                break;
     131            case accelerationfront:
     132                this->parent_->getParent()->getEngineByName(targetName_)->setAccelerationFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getAccelerationFront()));
     133                break;
     134            default:
     135                break;
     136            }
     137            this->setValid(false);
     138            return;
     139        }
     140
     141        if (this->targetType_ == "part")
     142        {
     143            switch (this->targetParam_) {
     144            case null:
     145                this->parent_->getParent()->getShipPartByName(targetName_)->setEventExecution(false);
     146                this->parent_->getParent()->killShipPart(targetName_);
    139147                break;
    140148            default:
     
    159167    void PartDestructionEvent::setTargetType(std::string type)
    160168    {
    161         if ((type == "ship") || (type == "engine") || (type == "weapon"))
     169        if ((type == "ship") || (type == "engine") || (type == "weapon") || (type == "part"))
    162170        {
    163171            this->targetType_ = type;
     
    166174
    167175        // Error, if invalid target-type was entered.
    168         orxout(internal_warning) << "\"" << type << "\" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon" << endl;
     176        orxout(internal_warning) << "\"" << type << "\" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon part" << endl;
    169177        this->setValid(false);
    170178        return;
     
    229237        // weapon:
    230238
    231         // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate
     239        // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate rotationthrust
    232240        if (this->targetType_ == "ship")
    233241        {
     
    247255                return;
    248256            }
    249 
    250             orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate boostpower boostpowerrate" << endl;
     257            if (param == "rotationthrust")
     258            {
     259                this->targetParam_ = rotationthrust;
     260                return;
     261            }
     262
     263            orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate boostpower boostpowerrate rotationthrust" << endl;
     264            return;
     265        }
     266
     267        if (this->targetType_ == "part")
     268        {
     269            if (param == "NULL")
     270            {
     271                this->targetParam_ = null;
     272                return;
     273            }
     274
     275            orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"part\". Valid types are: NULL (set operation to \"destroy\")" << endl;
    251276            return;
    252277        }
     
    265290    {
    266291        // * + - destroy
    267         if ((operation == "*") || (operation == "+") || (operation == "-") || (operation == "destroy"))
     292        if ((operation == "*") || (operation == "+") || (operation == "-") || (operation == "set") || (operation == "destroy"))
    268293        {
    269294            this->operation_ = operation;
     
    271296        }
    272297        this->operation_ = "NULL";
    273         orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - destroy" << endl;
     298        orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - set destroy" << endl;
    274299    }
    275300
     
    292317        The value which should be modified
    293318    @return
    294         Returns the product / sum / difference of input and configured value, or 0 if the operation is "destroy"
     319        Returns the product / sum / difference of input and configured value,
     320        the configured value if the operation is "set",
     321        or 0 if the operation is "destroy"
    295322    */
    296323    float PartDestructionEvent::operate(float input)
     
    302329        if (this->operation_ == "-")
    303330            return input - this->value_;
     331        if (this->operation_ == "set")
     332            return this->value_;
    304333        if (this->operation_ == "destroy")
    305334        {
Note: See TracChangeset for help on using the changeset viewer.