Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10055


Ignore:
Timestamp:
May 14, 2014, 8:25:08 PM (10 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
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/data/levels/ModularShipsTest1.oxw

    r10053 r10055  
    3131
    3232    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
    33     <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
     33    <!-- <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort /> -->
     34    <SpawnPoint team=0 position="-500,0,0" lookat="0,0,0" spawnclass=ModularSpaceShip pawndesign=HeavyCruiser />
    3435   
    3536    <MovableEntity position="0,0,0" collisionType=dynamic scale=1 linearDamping=0.8 angularDamping=0  collisiondamage=0.005 enablecollisiondamage=true>
  • code/branches/modularships/data/levels/templates/HeavyCruiser.oxt

    r10053 r10055  
    6161            </destructionevents>
    6262        </ShipPart>
    63         <ShipPart name="partL" initialhealth="10" damageabsorption="0.5" />
    64         <ShipPart name="partR" initialhealth="10" damageabsorption="0.5" />
    65         <ShipPart name="sidearmL" initialhealth="20" damageabsorption="0.2" />
     63        <ShipPart name="partL" initialhealth="10" damageabsorption="0.5">
     64            <destructionevents>
     65                <PartDestructionEvent targetType="ship" targetParam="boostpowerrate" operation="-" value="0.5" message="One of your ship's generators was destroyed!"/>
     66            </destructionevents>
     67        </ShipPart>
     68        <ShipPart name="partR" initialhealth="10" damageabsorption="0.5">
     69            <destructionevents>
     70                <PartDestructionEvent targetType="ship" targetParam="boostpowerrate" operation="-" value="0.5" message="One of your ship's generators was destroyed!"/>
     71            </destructionevents>
     72        </ShipPart>
     73        <ShipPart name="sidearmL" initialhealth="20" damageabsorption="0.2">
     74            <destructionevents>
     75                <!-- <PartDestructionEvent targetType="engine" targetName="HeavyCruiser_sidearmL_engine1" operation="destroy"/> -->
     76            </destructionevents>
     77        </ShipPart>
    6678        <ShipPart name="sidearmLfront" initialhealth="10" damageabsorption="0.5" />
    6779        <ShipPart name="sidearmR" initialhealth="20" damageabsorption="0.2" />
  • code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc

    r10053 r10055  
    3838#include "worldentities/pawns/Pawn.h"
    3939#include "worldentities/pawns/ModularSpaceShip.h"
     40#include "items/Engine.h"
    4041#include "gametypes/Gametype.h"
     42#include "chat/ChatManager.h"
    4143
    4244
     
    6365        XMLPortParam(PartDestructionEvent, "targetType", setTargetType, getTargetType, xmlelement, mode).defaultValues("NULL");
    6466        XMLPortParam(PartDestructionEvent, "targetName", setTargetName, getTargetName, xmlelement, mode).defaultValues("NULL");
     67        XMLPortParam(PartDestructionEvent, "operation", setOperation, getOperation, xmlelement, mode).defaultValues("NULL");
    6568        XMLPortParam(PartDestructionEvent, "targetParam", setTargetParam, getTargetParam, xmlelement, mode).defaultValues("NULL");
    66         XMLPortParam(PartDestructionEvent, "operation", setOperation, getOperation, xmlelement, mode).defaultValues("NULL");
    6769        XMLPortParam(PartDestructionEvent, "value", setEventValue, getEventValue, xmlelement, mode).defaultValues(0);
     70        XMLPortParam(PartDestructionEvent, "message", setMessage, getMessage, xmlelement, mode).defaultValues("NULL");
    6871
    6972        /*
     
    7477    }
    7578
     79    /**
     80    @brief
     81        Executes this event.
     82    */
    7683    void PartDestructionEvent::execute()
    7784    {
     85        orxout() << "Executing PartDestructionEvent " << this->getName() << endl;
     86
    7887        // Do not execute if this event is invalid
    7988        if(!isValid())
     
    8392        }
    8493
     94        // Output the destruction-message to the chat
     95        if(this->message_ != "NULL")
     96            ChatManager::message(this->message_);
     97
     98        // Modify parameters as configured for all cases
    8599        if (this->targetType_ == "ship")
    86100        {
     
    89103                this->parent_->getParent()->setShieldHealth(operate(this->parent_->getParent()->getShieldHealth()));
    90104                break;
     105            case boostpower:
     106                this->parent_->getParent()->setInitialBoostPower(operate(this->parent_->getParent()->getInitialBoostPower()));
     107                break;
     108            case boostpowerrate:
     109                this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate()));
     110                break;
    91111            default:
    92112                break;
     
    95115            return;
    96116        }
     117
     118        if (this->targetType_ == "engine")
     119        {
     120            switch (this->targetParam_) {
     121            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                }
     131                break;
     132            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                }
     139                break;
     140            default:
     141                break;
     142            }
     143            this->setValid(false);
     144            return;
     145        }
    97146    }
    98147
     
    102151    }
    103152
     153    /**
     154    @brief
     155        Set type of the target
     156    @param param
     157        The desired target-type as string. Valid target-types: ship engine weapon
     158    */
    104159    void PartDestructionEvent::setTargetType(std::string type)
    105160    {
    106         // ship engine weapon
    107161        if ((type == "ship") || (type == "engine") || (type == "weapon"))
    108162        {
     
    129183    }
    130184
     185    /**
     186    @brief
     187        Set the operation to be applied.
     188    @param param
     189        The desired parameter as string. Valid parameters: c.f. @ref orxnox::PartDestructionEvent::TargetParam
     190    */
    131191    void PartDestructionEvent::setTargetParam(std::string param)
    132192    {
     193        // A target-type needs to be defined in order to choose a parameter.
    133194        if (this->targetType_ == "NULL")
    134195        {
     
    138199        }
    139200
    140         // ship: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate
    141 
    142         // engine:
     201        // engine: NULL boostfactor speedfront accelerationfront
     202        if (this->targetType_ == "engine")
     203        {
     204            if (param == "NULL")
     205            {
     206                this->targetParam_ = null;
     207                return;
     208            }
     209            if (param == "boostfactor")
     210            {
     211                this->targetParam_ = boostfactor;
     212                return;
     213            }
     214            if (param == "speedfront")
     215            {
     216                this->targetParam_ = speedfront;
     217                return;
     218            }
     219            if (param == "accelerationfront")
     220            {
     221                this->targetParam_ = accelerationfront;
     222                return;
     223            }
     224
     225            orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"engine\". Valid types are: boostfactor speedfront accelerationfront" << endl;
     226            return;
     227        }
    143228
    144229        // weapon:
    145230
     231        // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate
    146232        if (this->targetType_ == "ship")
    147233        {
     
    151237                return;
    152238            }
    153 
    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;
     239            if (param == "boostpower")
     240            {
     241                this->targetParam_ = boostpower;
     242                return;
     243            }
     244            if (param == "boostpowerrate")
     245            {
     246                this->targetParam_ = boostpowerrate;
     247                return;
     248            }
     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;
    155251            return;
    156252        }
     
    160256    }
    161257
     258    /**
     259    @brief
     260        Set the operation to be applied.
     261    @param operation
     262        The desired operator as string. Valid operators: * + - destroy
     263    */
    162264    void PartDestructionEvent::setOperation(std::string operation)
    163265    {
     
    172274    }
    173275
     276    /**
     277    @brief
     278        Set the message to be shown upon execution of the vent.
     279    @param msg
     280        The desired message as string.
     281    */
     282    void PartDestructionEvent::setMessage(std::string msg)
     283    {
     284        this->message_ = msg;
     285    }
     286
     287
     288    /**
     289    @brief
     290        Apply the configured operation and value to an input.
     291    @param input
     292        The value which should be modified
     293    @return
     294        Returns the product / sum / difference of input and configured value, or 0 if the operation is "destroy"
     295    */
    174296    float PartDestructionEvent::operate(float input)
    175297    {
     
    187309    }
    188310
     311    /**
     312    @brief
     313        Sets the value applied with the chosen operation.
     314    @param value
     315        The value as float.
     316    */
    189317    void PartDestructionEvent::setEventValue(float value)
    190318    {
  • code/branches/modularships/src/orxonox/items/PartDestructionEvent.h

    r10053 r10055  
    3838namespace orxonox // tolua_export
    3939{ // tolua_export
     40    /**
     41        @brief
     42            In order to assign attached entities to a ShipPart, a ShipPart with the same name as the corresponding entity needs to be created in the <parts> tag.
     43            Here is a (primitive) example of a ModularSpaceShip with ShipParts and PartDestructionEvents defined in XML:
     44            @code
     45            <ModularSpaceShip
     46                ...
     47                >
     48                    <attached>
     49                        <StaticEntity name="generator"  . . .  />
     50                        <StaticEntity name="tail" . . . />
     51                    </attached>
     52                    <parts>
     53                        <ShipPart name="generator" . . . >
     54                            <destructionevents>
     55                                <PartDestructionEvent targetType="ship" targetParam="boostpowerrate" operation="-" value="0.5" message="Your boost-regeneration is reduced!" />
     56                            </destructionevents>
     57                        </ShipPart>
     58                        <ShipPart name="tail" . . . >
     59                            <destructionevents>
     60                                <PartDestructionEvent ... />
     61                            </destructionevents>
     62                        </ShipPart>
     63                    </parts>
     64                    <engines>
     65                        <Engine />
     66                        <Engine />
     67                    </engines>
     68                </ModularSpaceShip>
     69            @endcode
     70
     71        @author
     72            Fabian 'x3n' Landau, Noe Pedrazzini
     73        */
    4074    class _OrxonoxExport PartDestructionEvent // tolua_export
    4175        : public Item
     
    4478        public:
    4579
     80            /**
     81                @brief
     82                    List of all allowed parameters.
     83                */
    4684            enum TargetParam
    4785            {
     
    5088                shieldabsorption,
    5189                shieldrechargerate,
     90                boostpower,         // Amount of available boost
     91                boostpowerrate,     // Recharge-rate of boost
     92                boostfactor,
     93                speedfront,
     94                accelerationfront,
    5295                null
    5396            };
     
    85128                { return this->operation_; }
    86129
     130            void setMessage(std::string msg);
     131            inline std::string getMessage()
     132                { return this->message_; }
     133
    87134            float operate(float input);
    88135
     
    95142        private:
    96143
    97             ShipPart* parent_;
    98             bool valid_;
     144            ShipPart* parent_;          //!< Pointer to the ShipPart this event belongs to
     145            bool valid_;                //!< Whether this event is valid or not.
    99146
    100             std::string targetType_;
    101             std::string targetName_;
    102             TargetParam targetParam_;
    103             std::string operation_;
     147            std::string targetType_;    //!< The type of the target. (ship weapon engine)
     148            std::string targetName_;    //!< The name of the target.
     149            TargetParam targetParam_;   //!< The parameter to be modified
     150            std::string operation_;     //!< The operation to be applied
     151            float value_;               //!< The value used to do the operation
     152            std::string message_;       //!< The message which is shown in chat when the event is executed.
    104153
    105             float value_;
    106154
    107155
  • code/branches/modularships/src/orxonox/items/ShipPart.cc

    r10053 r10055  
    9090    }
    9191
     92    /**
     93    @brief
     94        Is called when the ShipPart dies.
     95        Executes PartDestructionEvents.
     96        Tells the ModularSpaceShip to remove this ShipPart.
     97    */
    9298    void ShipPart::death()
    9399    {
  • code/branches/modularships/src/orxonox/items/ShipPart.h

    r10053 r10055  
    102102        protected:
    103103            ModularSpaceShip* parent_;
    104             unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on.
     104            unsigned int parentID_;     // Object ID of the SpaceShip the Part is mounted on.
    105105
    106106            float damageAbsorption_;
     
    110110
    111111        private:
    112             std::vector<StaticEntity*> entityList_; // list of all entities which belong to this part
     112            std::vector<StaticEntity*> entityList_;         // List of all entities which belong to this part
    113113            std::vector<PartDestructionEvent*> eventList_;  // The list of all PartDestructionEvent assigned to this ShipPart.
    114114
  • 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.