- Timestamp:
- Jun 10, 2012, 11:01:40 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2012merge/src/modules/pickup/PickupCollection.cc
r9279 r9290 70 70 Destructor. Iterates through all Pickupables this PickupCollection consists of and destroys them if they haven't been already. 71 71 */ 72 PickupCollection::~ 72 PickupCollection::~PickupCollection() 73 73 { 74 74 // Destroy all Pickupables constructing this PickupCollection. 75 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)76 { 77 (*it)-> removeFromCollection();78 (*it)->destroy ();75 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 76 { 77 (*it)->wasRemovedFromCollection(); 78 (*it)->destroyPickup(); 79 79 } 80 80 this->pickups_.clear(); … … 93 93 94 94 XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode); 95 96 this->initializeIdentifier();97 }98 99 /**100 @brief101 Initializes the PickupIdentifier for this pickup.102 */103 void PickupCollection::initializeIdentifier(void)104 {105 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)106 {107 this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier());108 }109 95 } 110 96 … … 120 106 this->processingUsed_ = true; 121 107 // Change used for all Pickupables this PickupCollection consists of. 122 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)108 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 123 109 (*it)->setUsed(this->isUsed()); 124 110 … … 157 143 158 144 // Change the PickupCarrier for all Pickupables this PickupCollection consists of. 159 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)145 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 160 146 { 161 147 if(this->getCarrier() == NULL) … … 177 163 this->processingPickedUp_ = true; 178 164 // Change the pickedUp status for all Pickupables this PickupCollection consists of. 179 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)180 (* it)->setPickedUp(this->isPickedUp());165 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ) 166 (*(it++))->setPickedUp(this->isPickedUp()); 181 167 182 168 this->processingPickedUp_ = false; … … 220 206 PickupCollection* pickup = orxonox_cast<PickupCollection*>(item); 221 207 // Clone all Pickupables this PickupCollection consist of. 222 for(std:: vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)208 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 223 209 { 224 210 Pickupable* newPickup = (*it)->clone(); … … 226 212 pickup->addPickupable(collectible); 227 213 } 228 229 pickup->initializeIdentifier();230 214 } 231 215 … … 240 224 bool PickupCollection::isTarget(const PickupCarrier* carrier) const 241 225 { 242 for(std:: vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)226 for(std::list<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 243 227 { 244 228 if(!carrier->isTarget(*it)) … … 274 258 return false; 275 259 276 pickup->addToCollection(this);277 260 this->pickups_.push_back(pickup); 261 pickup->wasAddedToCollection(this); 278 262 return true; 279 263 } … … 289 273 const Pickupable* PickupCollection::getPickupable(unsigned int index) const 290 274 { 291 return this->pickups_[index]; 275 unsigned int count = 0; 276 for (std::list<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 277 { 278 if (count == index) 279 return *it; 280 else 281 ++count; 282 } 283 return NULL; 284 } 285 286 /** 287 @brief 288 Removes the Pickup from the Collection. 289 @param pickup 290 The Pickup to be removed. 291 @return 292 Returns true if the pickup was in the collection. 293 */ 294 bool PickupCollection::removePickupable(CollectiblePickup* pickup) 295 { 296 for(std::list<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); ++it) 297 { 298 if (*it == pickup) 299 { 300 this->pickups_.erase(it); 301 pickup->wasRemovedFromCollection(); 302 return true; 303 } 304 } 305 return false; 292 306 } 293 307
Note: See TracChangeset
for help on using the changeset viewer.