- Timestamp:
- Aug 8, 2010, 8:53:52 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/orxonox/interfaces/Pickupable.cc
r7150 r7162 58 58 59 59 this->pickupIdentifier_ = new PickupIdentifier(this); 60 this->beingDestroyed_ = false; 61 this->enabled_ = true; 60 62 } 61 63 … … 66 68 Pickupable::~Pickupable() 67 69 { 68 if(this->isUsed()) 69 this->setUsed(false); 70 71 if(this->isPickedUp()) 72 { 73 this->drop(false); 74 } 75 70 COUT(4) << "Pickupable (" << this->getIdentifier()->getName() << ") (&" << this << ") destroyed." << std::endl; 76 71 if(this->pickupIdentifier_ != NULL) 77 72 this->pickupIdentifier_->destroy(); 73 } 74 75 /** 76 @brief 77 A method that is called by OrxonoxClass::destroy() before the object is actually destroyed. 78 */ 79 void Pickupable::preDestroy(void) 80 { 81 this->beingDestroyed_ = true; 82 83 if(this->isPickedUp()) 84 this->drop(false); // Drops the pickup without creating a PickupSpawner. 85 } 86 87 /** 88 @brief 89 Is called internally within the pickup module to destroy pickups. 90 */ 91 void Pickupable::destroy(void) 92 { 93 this->destroyPickup(); 94 } 95 96 /** 97 @brief 98 Destroys a Pickupable. 99 If the Pickupable is already in the process of being destroyed a warning is displayed and this method is skipped. 100 */ 101 void Pickupable::destroyPickup(void) 102 { 103 if(!this->beingDestroyed_) 104 this->OrxonoxClass::destroy(); 105 else 106 COUT(2) << this->getIdentifier()->getName() << " may be unsafe. " << std::endl; 78 107 } 79 108 … … 88 117 bool Pickupable::setUsed(bool used) 89 118 { 90 if(this->used_ == used) 119 if(this->used_ == used || !this->isPickedUp()) // If either the used status of the Pickupable doesn't change or it isn't picked up. 120 return false; 121 122 if((!this->isUsable() && used) || (!this->isUnusable() && !used)) // If either the Pickupable is requested to be used but it is not usable or the Pickupable is requested to be unused, while it is not unusable. 91 123 return false; 92 124 … … 112 144 if(carrier == NULL) 113 145 return false; 146 114 147 return this->isTarget(carrier->getIdentifier()); 115 148 } … … 131 164 return true; 132 165 } 166 133 167 return false; 134 168 } … … 178 212 return false; 179 213 180 if(! carrier->addPickup(this))214 if(!this->setCarrier(carrier)) 181 215 { 182 216 COUT(3) << "A Pickupable (&" << this << ") was trying to be added to a PickupCarrier, but was already present." << std::endl; 183 217 return false; 184 218 } 185 219 220 this->setPickedUp(true); 186 221 COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl; 187 this->setCarrier(carrier);188 this->setPickedUp(true);189 222 return true; 190 223 } … … 194 227 Can be called to drop a Pickupable. 195 228 @param createSpawner 196 If true a spawner is be created for the dropped Pickupable. True is default.229 If true a spawner is to be created for the dropped Pickupable. True is default. 197 230 @return 198 231 Returns true if the Pickupable has been dropped, false if not. … … 200 233 bool Pickupable::drop(bool createSpawner) 201 234 { 202 if(!this->isPickedUp()) // !<If the Pickupable is not picked up.203 return false; 204 205 assert(this->getCarrier()); // !> The Carrier cannot be NULL at this point. //TODO: Too conservative?235 if(!this->isPickedUp()) // If the Pickupable is not picked up. 236 return false; 237 238 assert(this->getCarrier()); // The Carrier cannot be NULL at this point. 206 239 if(!this->getCarrier()->removePickup(this)) //TODO Shouldn't this be a little later? 207 COUT(2) << "Pickupable (&" << this << " ) is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl;208 240 COUT(2) << "Pickupable (&" << this << ", " << this->getIdentifier()->getName() << ") is being dropped, but it was not present in the PickupCarriers list of pickups." << std::endl; 241 209 242 COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl; 210 243 this->setUsed(false); … … 217 250 this->setCarrier(NULL); 218 251 219 if(!created && createSpawner) 220 { 252 if(!created && createSpawner) // If a PickupSpawner should have been created but wasn't. 221 253 this->destroy(); 222 }223 254 224 255 return true; … … 235 266 bool Pickupable::setPickedUp(bool pickedUp) 236 267 { 237 if(this->pickedUp_ == pickedUp) 268 if(this->pickedUp_ == pickedUp) // If the picked up status has not changed. 238 269 return false; 239 270 … … 241 272 242 273 this->pickedUp_ = pickedUp; 274 if(!pickedUp) // if the Pickupable has been dropped it unregisters itself with its PickupCarrier. 275 this->getCarrier()->removePickup(this); 243 276 this->changedPickedUp(); 244 277 GUIManager::getInstance().getLuaState()->doString("PickupInventory.update()"); … … 251 284 @param carrier 252 285 Sets the input PickupCarrier as the carrier of the pickup. 253 */ 254 inline bool Pickupable::setCarrier(PickupCarrier* carrier, bool tell) 255 { 256 if(this->carrier_ == carrier) 286 @param tell 287 If true (default) the pickup is added to the list of pickups in the PickupCarrier. 288 @return 289 Returns true if successful, false if not. 290 */ 291 bool Pickupable::setCarrier(orxonox::PickupCarrier* carrier, bool tell) 292 { 293 if(this->carrier_ == carrier) // If the PickupCarrier doesn't change. 257 294 return false; 258 295 259 296 COUT(4) << "Pickupable (&" << this << ") changed Carrier (& " << carrier << ")." << std::endl; 260 297 298 if(carrier != NULL && tell) 299 { 300 if(!carrier->addPickup(this)) 301 return false; 302 } 303 261 304 this->carrier_ = carrier; 262 305 this->changedCarrier(); 263 if(tell && carrier != NULL) 264 this->carrier_->pickups_.insert(this); 265 return true; 306 return true; 307 } 308 309 /** 310 @brief 311 Is called by the PickupCarrier when it is being destroyed. 312 */ 313 void Pickupable::carrierDestroyed(void) 314 { 315 this->destroy(); 266 316 } 267 317
Note: See TracChangeset
for help on using the changeset viewer.