Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 4, 2010, 11:56:26 AM (14 years ago)
Author:
dafrick
Message:

Lots of things done in pickups module. Compiles, but it seems, that I've also introduced an error preventing steering of the spaceship.

Location:
code/branches/pickup3/src/modules/pickup
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup3/src/modules/pickup/CMakeLists.txt

    r6420 r6466  
    11SET_SOURCE_FILES(PICKUP_SRC_FILES
     2  DroppedItem.cc
     3  Pickup.cc
    24  PickupCollection.cc
     5  PickupCollectionIdentifier.cc
     6  PickupManager.cc
     7  PickupRepresentation.cc
    38  PickupSpawner.cc
    49)
     10
     11ADD_SUBDIRECTORY(items)
    512
    613ORXONOX_ADD_LIBRARY(pickup
     
    1623  SOURCE_FILES ${PICKUP_SRC_FILES}
    1724)
    18 
  • code/branches/pickup3/src/modules/pickup/DroppedItem.cc

    r6421 r6466  
    7575    }
    7676   
     77    //TODO; Doesn't seem to be needed anymore, just put setPosition in the constructor.
    7778    void DroppedItem::createDrop(const Vector3& position)
    7879    {
  • code/branches/pickup3/src/modules/pickup/DroppedItem.h

    r6421 r6466  
    3535#define _DroppedItem_H__
    3636
    37 #include "pickup/PickupPrereqs.h"
     37#include "PickupPrereqs.h"
    3838
    3939#include "PickupSpawner.h"
  • code/branches/pickup3/src/modules/pickup/PickupCollection.cc

    r6421 r6466  
    7272        SUPER(PickupCollection, XMLPort, xmlelement, mode);
    7373       
    74         //TODO: Does this work? Problem could be, that Pickupable itself cannot be instantiated through XML...
     74        //TODO: Does this work? Problem could be, that Pickupable itself cannot be instantiated through XML, doubt that, though.
    7575        XMLPortObject(PickupCollection, PickupCollection, "pickupables", addPickupable, getPickupable, xmlelement, mode);
     76       
     77        this->initializeIdentifier();
     78    }
     79   
     80    void PickupCollection::initializeIdentifier(void)
     81    {
     82        this->pickupCollectionIdentifier_.addClass(this->getIdentifier());
     83       
     84        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     85        {
     86            this->pickupCollectionIdentifier_.addPickup((*it)->getPickupIdentifier());
     87        }
    7688    }
    7789   
     
    114126        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    115127        {
    116             (*it)->changedUsed();
     128            (*it)->setUsed(this->isUsed());
    117129        }
    118130    }
    119131   
    120     /**
    121     @brief
    122         Puts the PickupCollection in use.
    123     @return
    124         Returns true if successful.
    125     */
    126     //TODO: Revert if one fails? (same for unused)
    127     bool PickupCollection::use(void)
     132    void PickupCollection::changedCarrier()
    128133    {
    129         if(this->isUsed())
    130             return false;
     134        SUPER(PickupCollection, changedCarrier);
    131135       
    132         bool success = true;
    133         //! Set all Pickupables to used.
     136        //! Change the carrier for all Pickupables this PickupCollection consists of.
    134137        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    135138        {
    136             if(!(*it)->use())
    137             {
    138                 success = false;
    139             }
     139            (*it)->setCarrier(this->getCarrier());
    140140        }
    141        
    142         this->changedUsed();
    143        
    144         return success;
    145     }
    146    
    147     /**
    148     @brief
    149         Puts the PickupCollection out of use.
    150     @return
    151         Returns true if successful.
    152     */
    153     bool PickupCollection::unuse(void)
    154     {
    155         if(!this->isUsed())
    156             return false;
    157        
    158         bool success = true;
    159         //! Set all Pickupables to unused.
    160         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    161         {
    162             if(!(*it)->unuse())
    163             {
    164                 success = false;
    165             }
    166         }
    167        
    168         this->changedUsed();
    169        
    170         return success;
    171     }
    172 
    173     /**
    174     @brief
    175         Is invoked when the pickup is picked up.
    176     @param carrier
    177         The PickupCarrier that is picking up this pickup.
    178     @return
    179         Returns true if successful.
    180     */
    181     //TODO: Something should happen in the carrier as well, maybe just in the carrier. Owner might not be correct if the carrier hands the pickup down or up. Maybe even a Pawn as input instead fo a carrier. Or do this in Spawner?
    182     bool PickupCollection::pickup(PickupCarrier* carrier)
    183     {
    184         if(this->getOwner() != NULL)
    185         {
    186             COUT(2) << "Pickup wanted to get picked up by a new carrier, but it already has a carrier." << std::endl;
    187             return false;
    188         }
    189         for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    190         {
    191             (*it)->setOwner(carrier);
    192         }
    193        
    194         this->setOwner(carrier);
    195        
    196         return true;
    197     }
    198    
    199     /**
    200     @brief
    201         Drop the pickup.
    202     @return
    203         Return true if successful.
    204     */
    205     bool PickupCollection::drop(void)
    206     {
    207         this->unuse();
    208         this->setOwner(NULL);
    209        
    210         //TODO: Create new Pickupspawner/DroppedPickup
    211         return true;
    212141    }
    213142   
    214143    //TODO: Steal description from Pickupable.
    215     Pickupable* PickupCollection::clone()
     144    void PickupCollection::clone(OrxonoxClass* item)
    216145    {
    217         Template* collectionTemplate = Template::getTemplate(this->getIdentifier()->getName());
    218         BaseObject* newObject = collectionTemplate->getBaseclassIdentifier()->fabricate(this);
     146        if(item == NULL)
     147            item = new PickupCollection(this);
    219148       
    220         PickupCollection* newCollection = dynamic_cast<PickupCollection*>(newObject);
     149        SUPER(PickupCollection, clone, item);
     150       
     151        PickupCollection* pickup = dynamic_cast<PickupCollection*>(item);
    221152        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    222153        {
    223154            Pickupable* newPickup = (*it)->clone();
    224             newCollection->pickups_.push_back(newPickup);
     155            pickup->addPickupable(newPickup);
    225156        }
    226        
    227         Pickupable* pickup = dynamic_cast<Pickupable*>(newCollection);
    228         return pickup;
     157
     158        pickup->initializeIdentifier();
    229159    }
    230160   
  • code/branches/pickup3/src/modules/pickup/PickupCollection.h

    r6421 r6466  
    3030#define _PickupCollection_H__
    3131
    32 #include "pickup/PickupPrereqs.h"
     32#include "PickupPrereqs.h"
    3333
    3434#include "interfaces/Pickupable.h"
    3535#include "core/BaseObject.h"
    3636#include "core/XMLPort.h"
     37
     38#include "PickupCollectionIdentifier.h"
    3739
    3840#include <list>
     
    6062            virtual void changedUsed(void);
    6163           
    62             virtual bool use(void);
    63             virtual bool unuse(void);
     64            virtual void changedCarrier(void);
    6465           
    65             virtual bool pickup(PickupCarrier* carrier);
    66             virtual bool drop(void);
     66            virtual void clone(OrxonoxClass* item);
    6767           
    68             virtual Pickupable* clone(void);
     68            virtual const PickupIdentifier* getPickupIdentifier(void)
     69                { return &this->pickupCollectionIdentifier_; }
    6970           
    7071            bool addPickupable(Pickupable* pickup);
    7172            const Pickupable* getPickupable(unsigned int index);
     73           
     74        protected:
     75            void initializeIdentifier(void);
     76           
     77            PickupCollectionIdentifier pickupCollectionIdentifier_;
    7278           
    7379        private:
  • code/branches/pickup3/src/modules/pickup/PickupPrereqs.h

    r6421 r6466  
    6767
    6868    class DroppedItem;
     69    class Pickup;
    6970    class PickupCollection;
     71    class PickupCollectionIdentifier;
     72    class PickupManager;
     73    class PickupRepresentation;
    7074    class PickupSpawner;
     75   
     76    //items
     77    class HealthPickup;
    7178   
    7279}
  • code/branches/pickup3/src/modules/pickup/PickupSpawner.cc

    r6421 r6466  
    3939#include "core/XMLPort.h"
    4040#include "worldentities/pawns/Pawn.h"
     41#include "PickupManager.h"
     42#include "PickupRepresentation.h"
    4143//#include "PickupInventory.h"    // HACK; Only for hack, remove later
    4244
     
    5961    PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator)
    6062    {
     63        RegisterObject(PickupSpawner);
     64       
    6165        this->initialize();
     66       
     67        PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(NULL);
     68       
     69        COUT(1) << "MUP4 " << representation << std::endl;
     70        this->attach(representation->getSpawnerRepresentation(this));
     71       
     72        COUT(1) << "MUP6" << std::endl;
    6273    }
    6374
     
    7889    PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator)
    7990    {
     91        RegisterObject(PickupSpawner);
     92       
    8093        this->initialize();
    8194 
     
    8598        this->respawnTime_ = respawnTime;
    8699        this->setMaxSpawnedItems(maxSpawnedItems);
     100       
     101        PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier());
     102        this->attach(representation->getSpawnerRepresentation(this));
    87103    }
    88104
     
    93109    void PickupSpawner::initialize(void)
    94110    {
    95         RegisterObject(PickupSpawner);
    96 
    97111        this->pickup_ = NULL;
    98112       
     
    215229        Time since last tick.
    216230    */
    217     //TODO: Replace this with a real DistanceTrigger?
     231    //TODO: Replace this with a real DistanceTrigger? Or better with collisions?
    218232    void PickupSpawner::tick(float dt)
    219233    {
     
    259273            if (pickup != NULL) //!< If everything went ok, and pickup is not NULL.
    260274            {
     275                //TODO: Not correct anymore.
    261276                PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn);
    262277                if(carrier == NULL)
     
    266281                }
    267282               
    268                 if(pickup->pickup(carrier))
     283                if(carrier->pickup(pickup))
    269284                {
    270285                    COUT(3) << "Pickup got picked up." << std::endl;
  • code/branches/pickup3/src/modules/pickup/PickupSpawner.h

    r6421 r6466  
    3535#define _PickupSpawner_H__
    3636
    37 #include "pickup/PickupPrereqs.h"
     37#include "PickupPrereqs.h"
    3838
    3939#include <string>
Note: See TracChangeset for help on using the changeset viewer.