- Timestamp:
- Mar 4, 2010, 11:56:26 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup3/src/modules/pickup/PickupCollection.cc
r6421 r6466 72 72 SUPER(PickupCollection, XMLPort, xmlelement, mode); 73 73 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. 75 75 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 } 76 88 } 77 89 … … 114 126 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 115 127 { 116 (*it)-> changedUsed();128 (*it)->setUsed(this->isUsed()); 117 129 } 118 130 } 119 131 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() 128 133 { 129 if(this->isUsed()) 130 return false; 134 SUPER(PickupCollection, changedCarrier); 131 135 132 bool success = true; 133 //! Set all Pickupables to used. 136 //! Change the carrier for all Pickupables this PickupCollection consists of. 134 137 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 135 138 { 136 if(!(*it)->use()) 137 { 138 success = false; 139 } 139 (*it)->setCarrier(this->getCarrier()); 140 140 } 141 142 this->changedUsed();143 144 return success;145 }146 147 /**148 @brief149 Puts the PickupCollection out of use.150 @return151 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 @brief175 Is invoked when the pickup is picked up.176 @param carrier177 The PickupCarrier that is picking up this pickup.178 @return179 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 @brief201 Drop the pickup.202 @return203 Return true if successful.204 */205 bool PickupCollection::drop(void)206 {207 this->unuse();208 this->setOwner(NULL);209 210 //TODO: Create new Pickupspawner/DroppedPickup211 return true;212 141 } 213 142 214 143 //TODO: Steal description from Pickupable. 215 Pickupable* PickupCollection::clone()144 void PickupCollection::clone(OrxonoxClass* item) 216 145 { 217 Template* collectionTemplate = Template::getTemplate(this->getIdentifier()->getName());218 BaseObject* newObject = collectionTemplate->getBaseclassIdentifier()->fabricate(this);146 if(item == NULL) 147 item = new PickupCollection(this); 219 148 220 PickupCollection* newCollection = dynamic_cast<PickupCollection*>(newObject); 149 SUPER(PickupCollection, clone, item); 150 151 PickupCollection* pickup = dynamic_cast<PickupCollection*>(item); 221 152 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 222 153 { 223 154 Pickupable* newPickup = (*it)->clone(); 224 newCollection->pickups_.push_back(newPickup);155 pickup->addPickupable(newPickup); 225 156 } 226 227 Pickupable* pickup = dynamic_cast<Pickupable*>(newCollection); 228 return pickup; 157 158 pickup->initializeIdentifier(); 229 159 } 230 160
Note: See TracChangeset
for help on using the changeset viewer.