Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Continued working on ShipPart and ModularSpaceShip implementation

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

Legend:

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

    r10011 r10019  
    3232  PlayerManager.cc
    3333  Radar.cc
    34   ShipPart.cc
    3534#  Test.cc
    3635
  • code/branches/modularships/src/orxonox/items/CMakeLists.txt

    r5781 r10019  
    33  Engine.cc
    44  MultiStateEngine.cc
     5  ShipPart.cc
    56)
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc

    r10011 r10019  
    3838#include "gametypes/Gametype.h"
    3939
    40 #include "ShipPart.h"
     40#include "items/ShipPart.h"
     41#include "worldentities/StaticEntity.h"
     42#include <BulletCollision/CollisionShapes/btCollisionShape.h>
    4143
    4244
     
    7577    void ModularSpaceShip::updatePartAssignment()
    7678    {
    77 
     79        // iterate through all attached objects
     80        for (unsigned int i=0; i < 100; i++)
     81        {
     82            if (this->getAttachedObject(i) == NULL)
     83                break;
     84            // iterate through all attached parts
     85            for(unsigned int j = 0; j < this->partList_.size(); j++)
     86            {
     87                // if the name of the part matches the name of the object, add the object to that parts entitylist (unless it was already done).
     88                if((this->partList_[j]->getName() == this->getAttachedObject(i)->getName()) && !this->partList_[j]->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
     89                {
     90                    this->partList_[j]->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
     91                    orxout() << "A matching part-entity-pair with name " << this->partList_[j]->getName() << " was found!" << endl;
     92                    this->partList_[j]->printEntities(); // FIXME: (noep) remove debug
     93                }
     94            }
     95        }
     96    }
     97
     98    void ModularSpaceShip::attach(WorldEntity* object)
     99    {
     100        SpaceShip::attach(object);
     101        this->updatePartAssignment();
     102    }
     103
     104    void ModularSpaceShip::addPartEntityAssignment(StaticEntity* entity, ShipPart* part)
     105    {
     106        if (!entity || !part)
     107            return;
     108
     109        if (this->partMap_.find(entity) != this->partMap_.end())
     110                {
     111                    orxout(internal_warning) << "Assigning an Entity to multiple parts is not yet supported." << endl;
     112                    return;
     113                }
     114
     115        this->partMap_[entity] = part;
     116        orxout() << "New entity-part assignment created!" << endl;
     117    }
     118
     119    /**
     120    @brief
     121        Get the ShipPart an attached entity belongs to.
     122    @param entity
     123        The entity to be searched.
     124    @return
     125        Returns a pointer to the ShipPart the entity belongs to.
     126    */
     127    ShipPart* ModularSpaceShip::getPartOfEntity(StaticEntity* entity) const
     128    {
     129        for (std::map<StaticEntity*, ShipPart*>::const_iterator it = this->partMap_.begin(); it != this->partMap_.end(); ++it)
     130        {
     131            if (it->first == entity)
     132                return it->second;
     133        }
     134        return NULL;
    78135    }
    79136
     
    84141    {
    85142        orxout() << "Mdamage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl;
    86         orxout() << "Attached parts:" << endl;
     143        orxout() << "UserPtr of said collisionShape: " << cs->getUserPointer() << endl;
     144
     145        // List all attached Objects
     146        orxout() << "  " << this->getName() << " has the following Objects attached:" << endl;
     147        for (int i=0; i<10; i++)
     148        {
     149            if (this->getAttachedObject(i)==NULL)
     150                break;
     151            orxout() << " " << i << ": " << this->getAttachedObject(i) << " (" << this->getAttachedObject(i)->getName() << ")";
     152            orxout() << endl;
     153        }
     154
     155        orxout() << "  Attached ShipParts:" << endl;
    87156        for(unsigned int i=0; i < this->partList_.size(); i++)
    88157        {
     
    90159        }
    91160
    92         int collisionShapeIndex = this->isMyCollisionShape(cs);
    93         orxout() << collisionShapeIndex << endl;
    94 
     161        //int collisionShapeIndex = this->isMyCollisionShape(cs);
     162        //orxout() << collisionShapeIndex << endl;
     163
     164        orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
     165
     166        if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
     167            this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
     168        //else
     169        //    SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
     170
     171        /*
    95172        // Applies multiplier given by the DamageBoost Pickup.
    96173        if (originator)
     
    118195
    119196            this->lastHitOriginator_ = originator;
    120         }
     197        }*/
    121198    }
    122199
  • code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h

    r10011 r10019  
    4040
    4141#include "SpaceShip.h"
    42 #include "ShipPart.h"
     42#include "items/ShipPart.h"
     43#include <map>
    4344
    4445namespace orxonox
     
    9495            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    9596
     97            void attach(WorldEntity* object);
     98
     99            void addPartEntityAssignment(StaticEntity* entity, ShipPart* part);
     100            ShipPart* getPartOfEntity(StaticEntity* entity) const;
     101
    96102            virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL);
    97103
     
    108114            void registerVariables();
    109115            std::vector<ShipPart*> partList_;  // The list of all Parts mounted on this ModularSpaceShip.
     116            std::map<StaticEntity*, ShipPart*> partMap_;
    110117       
    111118    };
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h

    r10011 r10019  
    230230
    231231            virtual int isMyCollisionShape(const btCollisionShape* cs);
    232             void printBtChildShapes(btCompoundShape* cs, int indent, int subshape);
    233             void printSpaces(int num);
     232            void printBtChildShapes(btCompoundShape* cs, int indent, int subshape); // FIXME: (noep) remove debug
     233            void printSpaces(int num);   // FIXME: (noep) remove debug
    234234            int entityOfCollisionShape(const btCollisionShape* cs);
    235235
Note: See TracChangeset for help on using the changeset viewer.