Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Location:
code/branches/modularships/src/orxonox
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/src/orxonox/controllers/NewHumanController.cc

    r9939 r10058  
    220220                if (!controlPaused_ )
    221221                {
    222                     if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
     222                    if (this->getControllableEntity() && ((this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || (this->getControllableEntity()->isExactlyA(ClassByString("ModularSpaceShip")))) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
    223223                        this->showOverlays();
    224224                    else if (this->getControllableEntity() &&  this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
     
    498498        this->controlMode_ = 0;
    499499        this->centerCursor();
    500         if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
     500        if (this->getControllableEntity() && ((this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || (this->getControllableEntity()->isExactlyA(ClassByString("ModularSpaceShip")))) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
    501501        {
    502502            this->showOverlays_ = true;
  • 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        {
  • code/branches/modularships/src/orxonox/items/PartDestructionEvent.h

    r10055 r10058  
    9090                boostpower,         // Amount of available boost
    9191                boostpowerrate,     // Recharge-rate of boost
     92                rotationthrust,
    9293                boostfactor,
    9394                speedfront,
  • code/branches/modularships/src/orxonox/items/ShipPart.cc

    r10055 r10058  
    5252        RegisterObject(ShipPart);
    5353        this->setAlive(true);
     54        this->setEventExecution(true);
    5455    }
    5556
     
    103104        this->setAlive(false);
    104105
    105         // Execute all destruction events
    106         for (unsigned int i = 0; i < this->eventList_.size(); i++)
    107         {
    108             orxout() << "executing" << endl;
    109             this->getDestructionEvent(i)->execute();
     106        if(eventExecution_)
     107        {
     108            // Execute all destruction events
     109            for (unsigned int i = 0; i < this->eventList_.size(); i++)
     110            {
     111                this->getDestructionEvent(i)->execute();
     112            }
    110113        }
    111114
  • code/branches/modularships/src/orxonox/items/ShipPart.h

    r10055 r10058  
    7878                { return this->alive_; }
    7979
     80            inline void setEventExecution(bool var)
     81                { this->eventExecution_ = var; }
     82            inline bool isEventExecution()
     83                { return this->eventExecution_; }
     84
    8085            virtual void setHealth(float health);
    8186            inline void addHealth(float health)
     
    114119
    115120            bool alive_;
     121            bool eventExecution_;
    116122
    117123
  • code/branches/modularships/src/orxonox/worldentities/StaticEntity.cc

    r9667 r10058  
    3434#include "util/OrxAssert.h"
    3535#include "core/CoreIncludes.h"
     36#include "worldentities/BigExplosion.h"
    3637
    3738namespace orxonox
     
    115116        worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w));
    116117    }
     118
    117119}
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10055 r10058  
    4040
    4141#include "items/ShipPart.h"
     42#include "items/Engine.h"
    4243#include "worldentities/StaticEntity.h"
    4344#include "collisionshapes/WorldEntityCollisionShape.h"
     
    230231    /**
    231232    @brief
     233        Looks for an attached ShipPart with a certain name.
     234    @param name
     235        The name of the ShipPart to be returned.
     236    @return
     237        Pointer to the ShipPart with the given name, or NULL if not found.
     238    */
     239    ShipPart* ModularSpaceShip::getShipPartByName(std::string name)
     240    {
     241        for(std::vector<ShipPart*>::iterator it = this->partList_.begin(); it != this->partList_.end(); ++it)
     242        {
     243            if(orxonox_cast<ShipPart*>(*it)->getName() == name)
     244            {
     245                return orxonox_cast<ShipPart*>(*it);
     246            }
     247        }
     248        orxout(internal_warning) << "Couldn't find ShipPart with name \"" << name << "\"." << endl;
     249        return NULL;
     250    }
     251
     252    /**
     253    @brief
    232254        Check whether the SpaceShip has a particular Engine.
    233255    @param engine
     
    285307    /**
    286308    @brief
     309        Looks for an attached Engine with a certain name.
     310    @param name
     311        The name of the engine to be returned.
     312    @return
     313        Pointer to the engine with the given name, or NULL if not found.
     314    */
     315    Engine* ModularSpaceShip::getEngineByName(std::string name)
     316    {
     317        for(std::vector<Engine*>::iterator it = this->engineList_.begin(); it != this->engineList_.end(); ++it)
     318        {
     319            if(orxonox_cast<Engine*>(*it)->getName() == name)
     320            {
     321                return orxonox_cast<Engine*>(*it);
     322            }
     323        }
     324        orxout(internal_warning) << "Couldn't find Engine with name \"" << name << "\"." << endl;
     325        return NULL;
     326    }
     327
     328    /**
     329    @brief
    287330        Detaches a child WorldEntity from this instance.
    288331    */
     
    297340
    298341        // collision shapes
    299         orxout() << "MSS: detach()" << endl;
    300342
    301343        //this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
     
    314356
    315357        object->notifyDetached();
    316         orxout() << "MSS: detach() completed." << endl;
    317358    }
    318359}
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h

    r10055 r10058  
    117117            void addShipPart(ShipPart* part);
    118118            ShipPart* getShipPart(unsigned int index);
     119            ShipPart* getShipPartByName(std::string name);
    119120            bool hasShipPart(ShipPart* part) const;
    120121            void removeShipPart(ShipPart* part);
    121122
     123            inline void setRotationThrust(float val)
     124                { this->rotationThrust_ = val; }
     125            inline float getRotationThrust()
     126                { return this->rotationThrust_; }
     127
     128            Engine* getEngineByName(std::string name);
    122129            void detach(WorldEntity* object);
    123130
  • code/branches/modularships/src/orxonox/worldentities/pawns/SpaceShip.h

    r9667 r10058  
    270270            float stallSpeed_; //!< The forward speed where no more lift is added.
    271271
     272            std::vector<Engine*> engineList_; //!< The list of all Engines mounted on this SpaceShip.
     273
    272274        private:
    273275            void registerVariables();
     
    284286            void backupCamera(); // Save the original position and orientation of the camera.
    285287            void resetCamera(); // Reset the camera to its original position.
    286 
    287             std::vector<Engine*> engineList_; //!< The list of all Engines mounted on this SpaceShip.
    288288
    289289            Timer timer_;                          //!< Timer for the cooldown duration.
Note: See TracChangeset for help on using the changeset viewer.