Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Continued working on ShipPart and ModularSpaceShip implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.