Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 2, 2014, 8:38:07 PM (10 years ago)
Author:
noep
Message:

Cleaned up the process passing the collisionshape which was hit to the Pawn. Started implementation of ModularSpaceShip and ShipPart.

Location:
code/branches/modularships/src/orxonox
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/src/orxonox/CMakeLists.txt

    r9348 r10011  
    3232  PlayerManager.cc
    3333  Radar.cc
     34  ShipPart.cc
    3435#  Test.cc
    3536
  • code/branches/modularships/src/orxonox/Scene.cc

    r9996 r10011  
    201201            // Note: This is a global variable which we assign a static function.
    202202            // TODO: Check whether this (or anything about Bullet) works with multiple physics engine instances.
    203             gContactAddedCallback = &Scene::customCollisionCallback;
     203            gContactAddedCallback = &Scene::collisionCallback;
    204204        }
    205205        else if (!wantPhysics && hasPhysics())
     
    349349        SmartPtr<WorldEntity> object1 = static_cast<WorldEntity*>(colObj1->getUserPointer());
    350350
     351        // get the CollisionShape pointers
     352        const btCollisionShape* cs0 = colObj0->getCollisionShape();
     353        const btCollisionShape* cs1 = colObj1->getCollisionShape();
     354
    351355        // false means that bullet will assume we didn't modify the contact
    352356        bool modified = false;
    353357        if (object0->isCollisionCallbackActive())
    354             modified |= object0->collidesAgainst(object1, cp);
     358            modified |= object0->collidesAgainst(object1, cs1, cp);
    355359        if (object1->isCollisionCallbackActive())
    356             modified |= object1->collidesAgainst(object0, cp);
     360            modified |= object1->collidesAgainst(object0, cs0, cp);
    357361
    358362        return modified;
    359363    }
    360 
    361     /* ADDED static*/ bool Scene::customCollisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0, int partId0,
    362                                              int index0, const btCollisionObject* colObj1, int partId1, int index1)
    363     {
    364         // get the WorldEntity pointers
    365         SmartPtr<WorldEntity> object0 = static_cast<WorldEntity*>(colObj0->getUserPointer());
    366         SmartPtr<WorldEntity> object1 = static_cast<WorldEntity*>(colObj1->getUserPointer());
    367 
    368         // get the CollisionShape pointers
    369         const btCollisionShape* cs0 = colObj0->getCollisionShape();
    370         const btCollisionShape* cs1 = colObj1->getCollisionShape();
    371 
    372         // false means that bullet will assume we didn't modify the contact
    373         bool modified = false;
    374         if (object0->isCollisionCallbackActive())
    375             modified |= object0->customCollidesAgainst(object1, cs1, cp);
    376         if (object1->isCollisionCallbackActive())
    377             modified |= object1->customCollidesAgainst(object0, cs0, cp);
    378 
    379         return modified;
    380     }
    381364}
  • code/branches/modularships/src/orxonox/ShipPart.cc

    r10007 r10011  
    3535#include "core/XMLPort.h"
    3636#include "network/NetworkFunction.h"
     37#include "items/Item.h"
     38#include "worldentities/pawns/Pawn.h"
     39#include "gametypes/Gametype.h"
     40#include "worldentities/pawns/ModularSpaceShip.h"
    3741
    3842
     
    4246
    4347    ShipPart::ShipPart(Context* context)
     48        : Item(context)
    4449    {
    45         //RegisterObject(ShipPart);
     50        RegisterObject(ShipPart);
    4651    }
    4752
     
    5156    }
    5257
     58
     59    /**
     60    @brief
     61        Add a StaticEntity to the ShipPart.
     62    @param engine
     63        A pointer to the StaticEntity to be added.
     64    */
     65    void ShipPart::addEntity(StaticEntity* entity)
     66    {
     67        OrxAssert(entity != NULL, "The Entity cannot be NULL.");
     68        this->entityList_.push_back(entity);
     69        //part->addToSpaceShip(this); //FIXME: (noep) add
     70    }
     71
     72    /**
     73    @brief
     74        Get the i-th StaticEntity of the ShipPart.
     75    @return
     76        Returns a pointer to the i-the StaticEntity. NULL if there is no StaticEntity with that index.
     77    */
     78    StaticEntity* ShipPart::getEntity(unsigned int index)
     79    {
     80        if(this->entityList_.size() >= index)
     81            return NULL;
     82        else
     83            return this->entityList_[index];
     84    }
     85
     86    void ShipPart::setDamageAbsorption(float value)
     87    {
     88        this->damageAbsorption_ = value;
     89    }
     90
     91    /**
     92    @brief
     93        Sets the health of the ShipPart.
     94    */
     95    void ShipPart::setHealth(float health)
     96    {
     97        this->health_ = health;
     98    }
     99
     100    /**
     101    @brief
     102        Handles a received hit.
     103    */
     104    void ShipPart::handleHit(float damage, float healthdamage, float shielddamage, Pawn* originator)
     105    {
     106        if (parent_->getGametype() && parent_->getGametype()->allowPawnDamage(parent_, originator))
     107        {
     108            if (shielddamage >= parent_->getShieldHealth())
     109            {
     110                parent_->setShieldHealth(0);
     111                this->setHealth(this->health_ - (healthdamage + damage) * this->damageAbsorption_);
     112                parent_->setHealth(parent_->getHealth() - (healthdamage + damage) * (1 - this->damageAbsorption_));
     113            }
     114            else
     115            {
     116                parent_->setShieldHealth(parent_->getShieldHealth() - shielddamage);
     117
     118                // remove remaining shieldAbsorpton-Part of damage from shield
     119                shielddamage = damage * parent_->getShieldAbsorption();
     120                shielddamage = std::min(parent_->getShieldHealth(),shielddamage);
     121                parent_->setShieldHealth(parent_->getShieldHealth() - shielddamage);
     122
     123                // set remaining damage to health
     124                this->setHealth(this->health_ - ((damage - shielddamage) - healthdamage) * this->damageAbsorption_);
     125                parent_->setHealth(parent_->getHealth() - ((damage - shielddamage) - healthdamage) * (1- this->damageAbsorption_));
     126            }
     127        }
     128    }
     129
     130
     131    /**
     132    @brief
     133        Adds the ShipPart to the input SpaceShip.
     134    @param ship
     135        A pointer to the SpaceShip to which the ShipPart is added.
     136    */
     137    /*void ShipPart::addToSpaceShip(ModularSpaceShip* ship)
     138    {
     139        this->parent_ = ship;
     140
     141        if (ship)
     142        {
     143            this->parentID_ = ship->getObjectID();
     144            if (!ship->hasShipPart(this))
     145                ship->addShipPart(this);
     146        }
     147    }*/
     148
    53149}
  • code/branches/modularships/src/orxonox/ShipPart.h

    r10007 r10011  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "items/Item.h"
    3334
    3435#include <string>
     
    3839{ // tolua_export
    3940    class _OrxonoxExport ShipPart // tolua_export
     41        : public Item
    4042    { // tolua_export
    4143
     
    4446            virtual ~ShipPart();
    4547
     48            //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     49
     50            virtual void handleHit(float damage, float healthdamage, float shielddamage, Pawn* originator);
     51
     52            //virtual void attachTo(Pawn* newParent);
     53            //virtual void detach();
     54
     55            void addEntity(StaticEntity* entity);
     56            StaticEntity* getEntity(unsigned int index);
     57
     58            virtual void setDamageAbsorption(float value);
     59            inline float getDamageAbsorption()
     60                { return this->damageAbsorption_; }
     61
     62            virtual void setHealth(float health);
     63            inline void addHealth(float health)
     64                { this->setHealth(this->health_ + health); }
     65            inline void removeHealth(float health)
     66                { this->setHealth(this->health_ - health); }
     67            inline float getHealth() const
     68                { return this->health_; }
     69
     70            // FIXME: (noep) Why doesn't this work? Works fine in Engine.h
     71            //void addToSpaceShip(ModularSpaceShip* ship);
     72
    4673        protected:
     74            Pawn* parent_;
     75            unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on.
    4776
     77            float damageAbsorption_;
     78            float health_;
    4879
    4980        private:
    50 
     81            std::vector<StaticEntity*> entityList_; // list of all entities which belong to this part
    5182
    5283    }; // tolua_export
  • code/branches/modularships/src/orxonox/worldentities/MovableEntity.cc

    r9995 r10011  
    7272    }
    7373
    74     bool MovableEntity::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
     74    bool MovableEntity::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
    7575    {
    7676        if (GameMode::isMaster() && enableCollisionDamage_)
     
    8080            {
    8181                float damage = this->collisionDamage_ * (victim->getVelocity() - this->getVelocity()).length();
    82                 victim->hit(0, contactPoint, damage);
     82                victim->hit(0, contactPoint, ownCollisionShape, damage);
    8383            }
    8484        }
     
    8686        return false;
    8787    }
    88 
    89     bool MovableEntity::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
    90     {
    91         if (GameMode::isMaster() && enableCollisionDamage_)
    92         {
    93             Pawn* victim = orxonox_cast<Pawn*>(otherObject);
    94             if (victim)
    95             {
    96                 float damage = this->collisionDamage_ * (victim->getVelocity() - this->getVelocity()).length();
    97                 victim->customHit(0, contactPoint, ownCollisionShape, damage);
    98             }
    99         }
    100 
    101         return false;
    102     }
    103 
    10488
    10589    void MovableEntity::registerVariables()
  • code/branches/modularships/src/orxonox/worldentities/MovableEntity.h

    r9995 r10011  
    4747
    4848            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    49             virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
    50             virtual bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
     49            virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint);
    5150
    5251            using WorldEntity::setPosition;
  • code/branches/modularships/src/orxonox/worldentities/WorldEntity.h

    r9997 r10011  
    374374                Condition is that enableCollisionCallback() was called.
    375375            */
    376             virtual inline bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
    377                 { return false; } /* With false, Bullet assumes no modification to the collision objects. */
    378 
    379             virtual inline bool customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
     376            virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
    380377                { return false; } /* With false, Bullet assumes no modification to the collision objects. */
    381378
  • code/branches/modularships/src/orxonox/worldentities/pawns/CMakeLists.txt

    r7163 r10011  
    44  Pawn.cc
    55  SpaceShip.cc
     6  ModularSpaceShip.cc
    67  TeamBaseMatchBase.cc
    78  Destroyer.cc
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc

    r10007 r10011  
    250250    }
    251251
    252     void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator)
    253     {
     252    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
     253    {
     254        orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
     255
     256        int collisionShapeIndex = this->isMyCollisionShape(cs);
     257        orxout() << collisionShapeIndex << endl;
     258
    254259        // Applies multiplier given by the DamageBoost Pickup.
    255260        if (originator)
     
    280285    }
    281286
    282     void Pawn::customDamage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
    283     {
    284         orxout() << "damage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl;
    285 
    286         int collisionShapeIndex = this->isMyCollisionShape(cs);
    287         orxout() << collisionShapeIndex << endl;
    288 
    289         // Applies multiplier given by the DamageBoost Pickup.
    290         if (originator)
    291             damage *= originator->getDamageMultiplier();
    292 
    293         if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    294         {
    295             if (shielddamage >= this->getShieldHealth())
    296             {
    297                 this->setShieldHealth(0);
    298                 this->setHealth(this->health_ - (healthdamage + damage));
    299             }
    300             else
    301             {
    302                 this->setShieldHealth(this->shieldHealth_ - shielddamage);
    303 
    304                 // remove remaining shieldAbsorpton-Part of damage from shield
    305                 shielddamage = damage * this->shieldAbsorption_;
    306                 shielddamage = std::min(this->getShieldHealth(),shielddamage);
    307                 this->setShieldHealth(this->shieldHealth_ - shielddamage);
    308 
    309                 // set remaining damage to health
    310                 this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
    311             }
    312 
    313             this->lastHitOriginator_ = originator;
    314         }
    315     }
    316 
    317287// TODO: Still valid?
    318288/* HIT-Funktionen
     
    320290
    321291*/
    322     void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage)
     292    void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
    323293    {
    324294        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    325295        {
    326             this->damage(damage, healthdamage, shielddamage, originator);
     296            this->damage(damage, healthdamage, shielddamage, originator, cs);
    327297            this->setVelocity(this->getVelocity() + force);
    328298        }
    329299    }
    330300
    331     void Pawn::customHit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
     301    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
    332302    {
    333303        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    334304        {
    335             this->customDamage(damage, healthdamage, shielddamage, originator, cs);
    336             this->setVelocity(this->getVelocity() + force);
    337         }
    338     }
    339 
    340     void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage)
    341     {
    342         if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    343         {
    344             this->damage(damage, healthdamage, shielddamage, originator);
    345 
    346             if ( this->getController() )
    347                 this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
    348         }
    349     }
    350 
    351     void Pawn::customHit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
    352     {
    353         if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    354         {
    355             this->customDamage(damage, healthdamage, shielddamage, originator, cs);
     305            this->damage(damage, healthdamage, shielddamage, originator, cs);
    356306
    357307            if ( this->getController() )
     
    620570    }
    621571
    622     // WIP function that (once I get it working) determines to which attached entity a collisionshape belongs.
    623     // Shame that this doesn't seem to work as intended. It behaves differently (different number of childshapes) every reload. D:
     572
    624573    int Pawn::isMyCollisionShape(const btCollisionShape* cs)
    625574    {
     
    628577
    629578        // e.g. "Box 4: Searching for CS 0x1ad49200"
    630         orxout() << this->getRadarName() << ": Searching for btCS* " << cs << endl;
     579        orxout() << this->getName() << ": Searching for btCS* " << cs << endl;
    631580        // e.g. "Box 4 is WorldEntityCollisionShape 0x126dd060"
    632         orxout() << "  " << this->getRadarName() << " is WorldEntityCollisionShape* " << ownWECS << endl;
     581        orxout() << "  " << this->getName() << " is WorldEntityCollisionShape* " << ownWECS << endl;
    633582        // e.g. "Box 4 is WorldEntity 0x126dd060"
    634         orxout() << "  " << this->getRadarName() << " is WorldEntity* " << this << endl;
     583        orxout() << "  " << this->getName() << " is WorldEntity* " << this << endl;
    635584        // e.g. "Box 4 is objectID 943"
    636         orxout() << "  " << this->getRadarName() << " is objectID " << this->getObjectID() << endl;
     585        orxout() << "  " << this->getName() << " is objectID " << this->getObjectID() << endl;
    637586
    638587        // List all attached Objects
    639         orxout() << "  " << this->getRadarName() << " has the following Objects attached:" << endl;
     588        orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
    640589        for (int i=0; i<10; i++)
    641590        {
    642591            if (this->getAttachedObject(i)==NULL)
    643592                break;
    644             orxout() << " " << i << ": " << this->getAttachedObject(i);
     593            orxout() << " " << i << ": " << this->getAttachedObject(i) << " (" << this->getAttachedObject(i)->getName() << ")";
    645594            if(!orxonox_cast<Model*>(this->getAttachedObject(i)))
    646595                orxout() << " (SE)";
     
    648597        }
    649598
    650         if (this->health_ < 800)
    651             this->detach(this->getAttachedObject(2));
    652599
    653600        // print child shapes of this WECS
     
    656603        int temp = entityOfCollisionShape(cs);
    657604        if (temp==0)
    658             orxout() << this->getRadarName() << " has been hit on it's main body." << endl;
    659         else
    660             orxout() << this->getRadarName() << " has been hit on the attached entity no. " << temp << endl;
     605            orxout() << this->getName() << " has been hit on it's main body." << endl;
     606        else
     607            orxout() << this->getName() << " has been hit on the attached entity no. " << temp << endl;
    661608
    662609        // end
     
    680627
    681628                // pointer to the btCollisionShape
    682                 printSpaces(indent+2);  orxout() << "m_userPointer*: " << cs->getChildShape(i)->getUserPointer() << endl;
     629                printSpaces(indent+2);  orxout() << "m_userPointer*: " << cs->getChildShape(i)->getUserPointer() << " (name_: " << ((BaseObject*)(cs->getChildShape(i)->getUserPointer()))->getName() << ")" << endl;
    683630            }
    684631
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h

    r10007 r10011  
    126126            //virtual void hit(Pawn* originator, const Vector3& force, float damage);
    127127            //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
    128             virtual void hit(Pawn* originator, const Vector3& force, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
    129             virtual void customHit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
    130             virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
    131             virtual void customHit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     128            virtual void hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
     129            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
    132130
    133131            virtual void kill();
     
    198196
    199197            //virtual void damage(float damage, Pawn* originator = 0);
    200             virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL);
    201             virtual void customDamage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL);
     198            virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL);
    202199
    203200            bool bAlive_;
Note: See TracChangeset for help on using the changeset viewer.