Changeset 7150 for code/branches/presentation3
- Timestamp:
- Jun 18, 2010, 8:54:01 PM (14 years ago)
- Location:
- code/branches/presentation3/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/modules/pickup/PickupManager.cc
r7129 r7150 212 212 if(pickup != NULL && carrier != NULL) 213 213 { 214 carrier->drop(pickup);214 pickup->drop(carrier); 215 215 } 216 216 } -
code/branches/presentation3/src/modules/pickup/PickupSpawner.cc
r7127 r7150 304 304 if(target != NULL && pickup != NULL) 305 305 { 306 if( target->pickup(pickup))306 if(pickup->pickup(target)) 307 307 { 308 308 this->decrementSpawnsRemaining(); -
code/branches/presentation3/src/modules/pickup/items/MetaPickup.cc
r7127 r7150 136 136 if(pickup != NULL && pickup != this) 137 137 { 138 carrier->drop(pickup);138 pickup->drop(carrier); 139 139 } 140 140 } -
code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h
r7129 r7150 81 81 82 82 /** 83 @brief Can be called to pick up a Pickupable.84 @param pickup A pointer to the Pickupable.85 @return Returns true if the Pickupable was picked up, false if not.86 */87 bool pickup(Pickupable* pickup)88 {89 bool pickedUp = this->pickups_.insert(pickup).second;90 if(pickedUp)91 {92 COUT(4) << "Picked up Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl;93 pickup->pickedUp(this);94 }95 return pickedUp;96 }97 98 /**99 @brief Can be called to drop a Pickupable.100 @param pickup A pointer to the Pickupable.101 @param drop If the Pickupable should just be removed from the PickupCarrier without further action, this can be set to false. true is default.102 @return Returns true if the Pickupable has been dropped, false if not.103 */104 bool drop(Pickupable* pickup, bool drop = true)105 {106 bool dropped = this->pickups_.erase(pickup) == 1;107 if(dropped && drop)108 {109 COUT(4) << "Dropping Pickupable " << pickup->getIdentifier()->getName() << "(&" << pickup << ")." << std::endl;110 pickup->dropped();111 }112 return dropped;113 }114 115 /**116 83 @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable. 117 84 @param pickup A pointer to the Pickupable. … … 193 160 194 161 /** 162 @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier. 163 @param pickup A pointer to the pickup to be added. 164 @return Returns true if successfull, false if the Pickupable was already present. 165 */ 166 bool addPickup(Pickupable* pickup) 167 { return this->pickups_.insert(pickup).second; } 168 169 /** 170 @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier. 171 @param pickup A pointer to the pickup to be removed. 172 @return Returns true if successfull, false if the Pickupable was not present in the list. 173 */ 174 bool removePickup(Pickupable* pickup) 175 { return this->pickups_.erase(pickup) == 1; } 176 177 /** 195 178 @brief Get all Pickupables this PickupCarrier has. 196 179 @return Returns the set of all Pickupables this PickupCarrier has. -
code/branches/presentation3/src/orxonox/interfaces/Pickupable.cc
r7129 r7150 69 69 this->setUsed(false); 70 70 71 if(this->isPickedUp() && this->getCarrier() != NULL)71 if(this->isPickedUp()) 72 72 { 73 this->getCarrier()->drop(this, false); 74 this->setCarrier(NULL); 73 this->drop(false); 75 74 } 76 75 … … 168 167 /** 169 168 @brief 170 Sets the Pickupable to picked up. 171 This method will be called by the PickupCarrier picking the Pickupable up. 169 Can be called to pick up a Pickupable. 172 170 @param carrier 173 The PickupCarrier that picked the Pickupable up. 174 @return 175 Returns false if, for some reason, the pickup could not be picked up, e.g. it was picked up already. 176 */ 177 bool Pickupable::pickedUp(PickupCarrier* carrier) 178 { 179 if(this->isPickedUp()) //!< If the Pickupable is already picked up. 180 return false; 171 A pointer to the PickupCarrier that picks up the Pickupable. 172 @return 173 Returns true if the Pickupable was picked up, false if not. 174 */ 175 bool Pickupable::pickup(PickupCarrier* carrier) 176 { 177 if(carrier == NULL || this->isPickedUp()) //!< If carrier is NULL or the Pickupable is already picked up. 178 return false; 179 180 if(!carrier->addPickup(this)) 181 { 182 COUT(3) << "A Pickupable (&" << this << ") was trying to be added to a PickupCarrier, but was already present." << std::endl; 183 return false; 184 } 181 185 182 186 COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl; 183 187 this->setCarrier(carrier); 184 188 this->setPickedUp(true); 189 return true; 190 } 191 192 /** 193 @brief 194 Can be called to drop a Pickupable. 195 @param createSpawner 196 If true a spawner is be created for the dropped Pickupable. True is default. 197 @return 198 Returns true if the Pickupable has been dropped, false if not. 199 */ 200 bool Pickupable::drop(bool createSpawner) 201 { 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? 206 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 209 COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl; 210 this->setUsed(false); 211 this->setPickedUp(false); 212 213 bool created = false; 214 if(createSpawner) 215 created = this->createSpawner(); 216 217 this->setCarrier(NULL); 218 219 if(!created && createSpawner) 220 { 221 this->destroy(); 222 } 223 185 224 return true; 186 225 } … … 229 268 /** 230 269 @brief 231 Sets the Pickupable to not picked up or dropped.232 This method will be called by the PickupCarrier dropping the Pickupable.233 @return234 Returns false if the pickup could not be dropped.235 */236 bool Pickupable::dropped(void)237 {238 if(!this->isPickedUp()) //!< If the Pickupable is not picked up.239 return false;240 241 COUT(4) << "Pickupable (&" << this << ") got dropped up by a PickupCarrier (&" << this->getCarrier() << ")." << std::endl;242 this->setUsed(false);243 this->setPickedUp(false);244 245 bool created = this->createSpawner();246 247 this->setCarrier(NULL);248 249 if(!created)250 {251 this->destroy();252 }253 254 return true;255 }256 257 /**258 @brief259 270 Creates a duplicate of the Pickupable. 260 271 @return … … 297 308 Pawn* pawn = static_cast<Pawn*>(entity); 298 309 PickupCarrier* carrier = static_cast<PickupCarrier*>(pawn); 299 return carrier->pickup(this);310 return this->pickup(carrier); 300 311 } 301 312 -
code/branches/presentation3/src/orxonox/interfaces/Pickupable.h
r7129 r7150 95 95 virtual void changedPickedUp(void) {} 96 96 97 bool pick edUp(PickupCarrier* carrier); //!< Sets the Pickupable to picked up.98 bool drop ped(void); //!< Sets the Pickupable to not picked up or dropped.97 bool pickup(PickupCarrier* carrier); 98 bool drop(bool createSpawner = true); 99 99 100 100 virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup.
Note: See TracChangeset
for help on using the changeset viewer.