Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10023 for code/branches


Ignore:
Timestamp:
Apr 9, 2014, 9:50:45 PM (11 years ago)
Author:
noep
Message:

ShipParts can "die" and detach the corresponding Entity while doing so. Issue: The Entity being detached while a hit on a collisionshape is being handled causes a runtime-error.

Location:
code/branches/modularships
Files:
9 edited

Legend:

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

    r10011 r10023  
    9898    </ModularSpaceShip>
    9999   
    100     <ModularSpaceShip position="0,-1000,-200">
     100    <ModularSpaceShip position="0,-1000,-200" health="1000" maxhealth="2000" initialhealth="1000">
    101101      <templates>
    102102        <Template link=HeavyCruiser />
  • code/branches/modularships/data/levels/templates/HeavyCruiser.oxt

    r10019 r10023  
    1111   explosionchunks        = 6
    1212
    13    health            = 100
    14    maxhealth         = 200
    15    initialhealth     = 100
     13   health            = 1000
     14   maxhealth         = 2000
     15   initialhealth     = 1000
    1616
    1717   shieldhealth        = 100
     
    5151   
    5252    <parts>
    53         <ShipPart name="frontL" />
    54         <ShipPart name="frontR" />
     53        <ShipPart name="frontL" health="100" damageabsorption="0.5" />
     54        <ShipPart name="frontR" health="100" damageabsorption="0.5" />
     55        <ShipPart name="partL" health="100" damageabsorption="0.5" />
     56        <ShipPart name="partR" health="100" damageabsorption="0.5" />
     57        <ShipPart name="sidearmL" health="201" damageabsorption="0.2" />
     58        <ShipPart name="sidearmLfront" health="100" damageabsorption="0.5" />
     59        <ShipPart name="sidearmR" health="200" damageabsorption="0.2" />
     60        <ShipPart name="sidearmRfront" health="100" damageabsorption="0.5" />
    5561    </parts>
    5662   
     
    6167            <attached>
    6268                <Model mesh="HeavyCruiser_frontL.mesh" direction="-1,0,0" position="0,0,0" scale="40"/>
     69                <BlinkingBillboard position="-75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
     70                <BlinkingBillboard position="-74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
     71                <BlinkingBillboard position="-73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
    6372            </attached>
    6473            <collisionShapes>
     
    7180            <attached>
    7281                <Model mesh="HeavyCruiser_frontR.mesh" direction="-1,0,0" position="0,0,0" scale="40"/>
     82                <BlinkingBillboard position="75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
     83                <BlinkingBillboard position="74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
     84                <BlinkingBillboard position="73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
    7385            </attached>
    7486            <collisionShapes>
     
    176188        </StaticEntity>   
    177189
    178             <!-- bay1 lights -->
    179         <BlinkingBillboard position="75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
    180         <BlinkingBillboard position="-75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
    181         <BlinkingBillboard position="74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
    182         <BlinkingBillboard position="-74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
    183         <BlinkingBillboard position="73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
    184         <BlinkingBillboard position="-73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
    185190            <!-- front position lights -->
    186191        <BlinkingBillboard position="67,-5,-240" material="Examples/Flare" colour="0, 0.7, 0, 0.1" amplitude=0.3 frequency=0.15 phase=0 quadratic=1 />
  • code/branches/modularships/src/orxonox/OrxonoxPrereqs.h

    r9348 r10023  
    142142
    143143    // items
     144    class ShipPart;
    144145    class Engine;
    145146    class Item;
     
    189190    class Pawn;
    190191    class SpaceShip;
     192    class ModularSpaceShip;
    191193    class Spectator;
    192194    class TeamBaseMatchBase;
  • code/branches/modularships/src/orxonox/items/ShipPart.cc

    r10019 r10023  
    3737#include "Item.h"
    3838#include "worldentities/pawns/Pawn.h"
     39#include "worldentities/pawns/ModularSpaceShip.h"
    3940#include "gametypes/Gametype.h"
    4041#include "worldentities/StaticEntity.h"
     
    5657    }
    5758
     59    void ShipPart::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     60    {
     61        SUPER(ShipPart, XMLPort, xmlelement, mode);
     62
     63        XMLPortParam(ShipPart, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
     64        XMLPortParam(ShipPart, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
     65        XMLPortParam(ShipPart, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
     66
     67        XMLPortParam(ShipPart, "damageabsorption", setDamageAbsorption, getDamageAbsorption, xmlelement, mode).defaultValues(0.5);
     68
     69        /*
     70        XMLPortParam(ShipPart, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
     71        XMLPortParam(ShipPart, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
     72        XMLPortParam(ShipPart, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
     73        XMLPortParam(ShipPart, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
     74
     75        XMLPortParam(ShipPart, "sShipPartparticlesource", setSShipPartParticleSource, getSShipPartParticleSource, xmlelement, mode);
     76        XMLPortParam(ShipPart, "sShipPartparticleduration", setSShipPartParticleDuration, getSShipPartParticleDuration, xmlelement, mode).defaultValues(3.0f);
     77        XMLPortParam(ShipPart, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
     78
     79        XMLPortParam(ShipPart, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
     80        XMLPortParam(ShipPart, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
     81
     82        XMLPortParam(ShipPart, "explosionSound",  setExplosionSound,  getExplosionSound,  xmlelement, mode);
     83
     84        XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode );
     85        */
     86    }
     87
     88    void ShipPart::death()
     89    {
     90        this->parent_->removeShipPart(this);
     91    }
    5892
    5993    /**
     
    112146    {
    113147        this->damageAbsorption_ = value;
     148    }
     149
     150    void ShipPart::setParent(ModularSpaceShip* ship)
     151    {
     152        this->parent_ = ship;
    114153    }
    115154
     
    152191            }
    153192        }
     193        if (this->health_ < 0)
     194            this->death();
     195        orxout() << "Health of ShipPart " << this->getName() << " is " << this->getHealth() << endl;
    154196    }
    155197
  • code/branches/modularships/src/orxonox/items/ShipPart.h

    r10019 r10023  
    4646            virtual ~ShipPart();
    4747
    48             //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     48            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4949
    5050            virtual void handleHit(float damage, float healthdamage, float shielddamage, Pawn* originator);
     51
     52            virtual void death();
    5153
    5254            //virtual void attachTo(Pawn* newParent);
     
    6365                { return this->damageAbsorption_; }
    6466
     67            void setParent(ModularSpaceShip* ship);
     68            inline ModularSpaceShip* getParent()
     69                { return this->parent_; }
     70
    6571            virtual void setHealth(float health);
    6672            inline void addHealth(float health)
     
    7177                { return this->health_; }
    7278
     79            inline void setMaxHealth(float maxhealth)
     80                { this->maxHealth_ = maxhealth; this->setHealth(this->health_); }
     81            inline float getMaxHealth() const
     82                { return this->maxHealth_; }
     83
     84            inline void setInitialHealth(float initialhealth)
     85                { this->initialHealth_ = initialhealth; this->setHealth(initialhealth); }
     86            inline float getInitialHealth() const
     87                { return this->initialHealth_; }
     88
    7389
    7490            // FIXME: (noep) Why doesn't this work? Works fine in Engine.h
     
    7692
    7793        protected:
    78             Pawn* parent_;
     94            ModularSpaceShip* parent_;
    7995            unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on.
    8096
    8197            float damageAbsorption_;
    8298            float health_;
     99            float maxHealth_;
     100            float initialHealth_;
    83101
    84102        private:
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10019 r10023  
    8888                if((this->partList_[j]->getName() == this->getAttachedObject(i)->getName()) && !this->partList_[j]->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
    8989                {
     90                    // The Entity is added to the part's entityList_
    9091                    this->partList_[j]->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
     92                    // An entry in the partMap_ is created, assigning the part to the entity.
     93                    this->addPartEntityAssignment((StaticEntity*)(this->getAttachedObject(i)), this->partList_[j]);
    9194                    orxout() << "A matching part-entity-pair with name " << this->partList_[j]->getName() << " was found!" << endl;
    9295                    this->partList_[j]->printEntities(); // FIXME: (noep) remove debug
     
    9497            }
    9598        }
     99
     100        orxout() << "List of all assignments:" << endl;
     101        for (std::map<StaticEntity*, ShipPart*>::const_iterator it = this->partMap_.begin(); it != this->partMap_.end(); ++it)
     102                {
     103                    orxout() << "Entity: " << it->first << "   Part: " << it->second << endl;
     104                }
    96105    }
    97106
     
    143152        orxout() << "UserPtr of said collisionShape: " << cs->getUserPointer() << endl;
    144153
    145         // List all attached Objects
     154
     155            // Print all attached objects & parts
     156        /*
    146157        orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
    147         for (int i=0; i<10; i++)
     158
     159        for (int i=0; i<50; i++)
    148160        {
    149161            if (this->getAttachedObject(i)==NULL)
     
    157169        {
    158170            orxout() << "  " << i << ": " << this->partList_[i] << " (" << this->partList_[i]->getName() << ")" << endl;
    159         }
     171        }*/
     172
    160173
    161174        //int collisionShapeIndex = this->isMyCollisionShape(cs);
    162175        //orxout() << collisionShapeIndex << endl;
    163176
    164         orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
     177        //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
     178
     179        orxout() << "CP_start" << endl;
    165180
    166181        if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
    167182            this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
    168         //else
    169         //    SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
     183        else
     184            SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
     185
     186        orxout() << "CP_end" << endl;
    170187
    171188        /*
     
    208225        OrxAssert(part != NULL, "The ShipPart cannot be NULL.");
    209226        this->partList_.push_back(part);
     227        part->setParent(this);
    210228        //part->addToSpaceShip(this); //FIXME: (noep) add
    211229        this->updatePartAssignment();
     
    242260    }
    243261
     262    void ModularSpaceShip::removeShipPart(ShipPart* part)
     263    {
     264        // Remove the part from the partList_
     265        std::vector<ShipPart*>::iterator it = this->partList_.begin();
     266        for(unsigned int i = 0; i < this->partList_.size(); i++)
     267        {
     268            if(this->partList_[i] == part)
     269                this->partList_.erase(it);
     270            it++;
     271        }
     272        // Remove the part-entity assignment and detach the Entity of this ShipPart
     273        for (std::map<StaticEntity*, ShipPart*>::iterator itt = this->partMap_.begin(); itt != this->partMap_.end(); ++itt)
     274        {
     275            if (itt->second == part)
     276            {
     277                this->detach(itt->first);
     278                this->partMap_.erase(itt);
     279            }
     280        }
     281    }
     282
    244283}
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h

    r10019 r10023  
    4848    /**
    4949    @brief
    50         The ModularSpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
     50        The SpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
     51        The ModularSpaceShip is an extension of a @ref orxonox::SpaceShip SpaceShip, which uses @ref orxonox::ShipPart ShipParts to allow entities attached to it to be destroyed individually.
    5152
    5253        There are several parameters that define the behavior of the ModularSpaceShip>
     
    5657        - The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again tow parameters that can be specified. The <b>lift</b> which is the lift force that is applied. And the <b>stallSpeed</b> which is the forward speed after which no more lift is generated.
    5758
    58         As mentioned @ref orxonox::Engine Engines can be mounted on the ModularSpaceShip. Here is a (primitive) example of a ModularSpaceShip defined in XML:
     59        As mentioned @ref orxonox::Engine Engines can be mounted on the ModularSpaceShip.
     60        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.
     61        Here is a (primitive) example of a ModularSpaceShip defined in XML:
    5962        @code
    6063        <ModularSpaceShip
     
    7780            angularDamping    = 0.9999999
    7881            >
     82                <attached>
     83                    <StaticEntity name="wing"  . . .  />
     84                    <StaticEntity name="tail" . . . />
     85                </attached>
     86                <parts>
     87                    <ShipPart name="wing" . . . />
     88                    <ShipPart name="tail" . . . />
     89                </parts>
    7990                <engines>
    8091                    <Engine />
     
    8596
    8697    @author
    87         Fabian 'x3n' Landau
     98        Fabian 'x3n' Landau, Noe Pedrazzini
    8899    */
    89100    class _OrxonoxExport ModularSpaceShip : public SpaceShip
     
    105116            ShipPart* getShipPart(unsigned int index);
    106117            bool hasShipPart(ShipPart* part) const;
     118            void removeShipPart(ShipPart* part);
    107119
    108120            virtual void updatePartAssignment();
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc

    r10011 r10023  
    252252    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
    253253    {
    254         orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
    255 
    256         int collisionShapeIndex = this->isMyCollisionShape(cs);
    257         orxout() << collisionShapeIndex << endl;
     254        //FIXME: (noep) remove debug
     255        //orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
     256
     257        //int collisionShapeIndex = this->isMyCollisionShape(cs);
     258        //orxout() << collisionShapeIndex << endl;
    258259
    259260        // Applies multiplier given by the DamageBoost Pickup.
     
    587588        // List all attached Objects
    588589        orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
    589         for (int i=0; i<10; i++)
     590        for (int i=0; i<50; i++)
    590591        {
    591592            if (this->getAttachedObject(i)==NULL)
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h

    r10019 r10023  
    229229            unsigned int numexplosionchunks_;
    230230
    231             virtual int isMyCollisionShape(const btCollisionShape* cs);
     231            virtual int isMyCollisionShape(const btCollisionShape* cs); // FIXME: (noep) remove debug
    232232            void printBtChildShapes(btCompoundShape* cs, int indent, int subshape); // FIXME: (noep) remove debug
    233233            void printSpaces(int num);   // FIXME: (noep) remove debug
Note: See TracChangeset for help on using the changeset viewer.