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.

File:
1 edited

Legend:

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