Changeset 7162 for code/branches/presentation3
- Timestamp:
- Aug 8, 2010, 8:53:52 PM (14 years ago)
- Location:
- code/branches/presentation3
- Files:
-
- 2 added
- 29 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/data/gui/scripts/PickupInventory.lua
r7072 r7162 54 54 useButton:setText("unuse") 55 55 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked") 56 if pickup:isUsable() == false then 57 useButton:setEnabled(false) 58 end 56 59 else 57 60 useButton:setText("use") 58 61 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked") 62 if pickup:isUnusable() == false then 63 useButton:setEnabled(false) 64 end 59 65 end 60 66 … … 130 136 useButton:setText("use") 131 137 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseButton_clicked") 138 if pickup:isUsable() == false then 139 useButton:setEnabled(false) 140 end 132 141 else 133 142 useButton:setText("unuse") 134 143 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseButton_clicked") 144 if pickup:isUnusable() == false then 145 useButton:setEnabled(false) 146 end 135 147 end 136 148 item:addChildWindow(useButton) … … 229 241 useButton:setText("use") 230 242 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUseDetailButton_clicked") 243 if pickup:isUsable() == false then 244 useButton:setEnabled(false) 245 end 231 246 else 232 247 useButton:setText("unuse") 233 248 orxonox.GUIManager:subscribeEventHelper(useButton, "Clicked", P.name .. ".InventoryUnuseDetailButton_clicked") 249 if pickup:isUnusable() == false then 250 useButton:setEnabled(false) 251 end 234 252 end 235 253 wrapper:addChildWindow(useButton) -
code/branches/presentation3/data/levels/pickups.oxw
r7083 r7162 136 136 </PickupSpawner> 137 137 138 <PickupSpawner position="25,75,-125" triggerDistance="10" respawnTime="5" maxSpawnedItems="10"> 139 <pickup> 140 <MetaPickup metaType="destroy" /> 141 </pickup> 142 </PickupSpawner> 143 144 <PickupSpawner position="50,75,-125" triggerDistance="10" respawnTime="5" maxSpawnedItems="10"> 145 <pickup> 146 <MetaPickup metaType="destroyCarrier" /> 147 </pickup> 148 </PickupSpawner> 149 138 150 <!-- Pickup Collection pickups --> 139 151 … … 162 174 > 163 175 <pickup> 164 <HealthPickup health=50 activationType="onUse" durationType="once"/>176 <HealthPickup health=500 activationType=immediate healthRate=10 durationType=continuous /> 165 177 </pickup> 166 178 </PickupRepresentation> … … 168 180 <PickupSpawner position="-50,0,-125" respawnTime="60" triggerDistance="20" maxSpawnedItems="5"> 169 181 <pickup> 170 <HealthPickup health=50 activationType=onUse durationType=once/>182 <HealthPickup health=500 activationType=immediate healthRate=10 durationType=continuous /> 171 183 </pickup> 172 184 </PickupSpawner> -
code/branches/presentation3/src/modules/pickup/CMakeLists.txt
r7135 r7162 1 1 SET_SOURCE_FILES(PICKUP_SRC_FILES 2 CollectiblePickup.cc 2 3 DroppedPickup.cc 3 4 Pickup.cc -
code/branches/presentation3/src/modules/pickup/Pickup.cc
r7129 r7162 194 194 195 195 //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up. 196 if(this-> getCarrier() != NULL && this->isPickedUp() && this->isImmediate())196 if(this->isPickedUp() && this->isImmediate()) 197 197 { 198 198 this->setUsed(true); -
code/branches/presentation3/src/modules/pickup/Pickup.h
r7129 r7162 40 40 #include "core/XMLPort.h" 41 41 42 #include " interfaces/Pickupable.h"42 #include "CollectiblePickup.h" 43 43 44 44 #include "tools/Timer.h" … … 74 74 Damian 'Mozork' Frick 75 75 */ 76 class _PickupExport Pickup : public Pickupable, public BaseObject76 class _PickupExport Pickup : public CollectiblePickup, public BaseObject 77 77 { 78 78 -
code/branches/presentation3/src/modules/pickup/PickupCollection.cc
r7127 r7162 35 35 #include "core/XMLPort.h" 36 36 #include "interfaces/PickupCarrier.h" 37 #include "CollectiblePickup.h" 37 38 #include "DroppedPickup.h" 38 39 #include "PickupCollectionIdentifier.h" … … 54 55 55 56 this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this); 57 this->usedCounter_ = 0; 58 this->pickedUpCounter_ = 0; 59 this->disabledCounter_ = 0; 60 this->processingUsed_ = false; 61 this->processingPickedUp_ = false; 56 62 } 57 63 … … 62 68 PickupCollection::~PickupCollection() 63 69 { 64 //! Destroy all Pickupables constructing this PickupCollection. 65 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 66 { 67 if((*it).get() != NULL) 68 (*it).get()->destroy(); 69 } 70 // Destroy all Pickupables constructing this PickupCollection. 71 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 72 { 73 (*it)->removeFromCollection(); 74 (*it)->destroy(); 75 } 76 this->pickups_.clear(); 70 77 } 71 78 … … 78 85 SUPER(PickupCollection, XMLPort, xmlelement, mode); 79 86 80 XMLPortObject(PickupCollection, Pickupable, "pickupables", addPickupable, getPickupable, xmlelement, mode);87 XMLPortObject(PickupCollection, CollectiblePickup, "pickupables", addPickupable, getPickupable, xmlelement, mode); 81 88 82 89 this->initializeIdentifier(); … … 89 96 void PickupCollection::initializeIdentifier(void) 90 97 { 91 for(std::vector< WeakPtr<Pickupable>>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)92 { 93 this->pickupCollectionIdentifier_->addPickup((*it) .get()->getPickupIdentifier());98 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 99 { 100 this->pickupCollectionIdentifier_->addPickup((*it)->getPickupIdentifier()); 94 101 } 95 102 } … … 104 111 SUPER(PickupCollection, changedUsed); 105 112 106 //! Change used for all Pickupables this PickupCollection consists of. 107 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 108 { 109 (*it).get()->setUsed(this->isUsed()); 110 } 113 this->processingUsed_ = true; 114 // Change used for all Pickupables this PickupCollection consists of. 115 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 116 { 117 (*it)->setUsed(this->isUsed()); 118 } 119 this->processingUsed_ = false; 120 121 this->changedUsedAction(); 122 } 123 124 /** 125 @brief 126 Helper method. 127 Checks whether due to changes in the used status of the pickups of this PickupCollection the used status of this PickupCollection has to change as well. 128 */ 129 void PickupCollection::changedUsedAction(void) 130 { 131 if(this->processingUsed_) 132 return; 133 134 // If all the pickups are not in use but the PickupCollection is. 135 if(this->usedCounter_ == 0 && this->isUsed()) 136 this->setUsed(false); 137 138 // If all the enabled pickups are in use but the PickupCollection is not. 139 if(this->usedCounter_ != 0 && this->usedCounter_ == this->pickups_.size()-this->disabledCounter_ && !this->isUsed()) 140 this->setUsed(true); 111 141 } 112 142 … … 120 150 SUPER(PickupCollection, changedCarrier); 121 151 122 //! Change the PickupCarrier for all Pickupables this PickupCollection consists of. 123 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 124 { 125 (*it).get()->setCarrier(this->getCarrier()->getTarget(*it), true); 152 // Change the PickupCarrier for all Pickupables this PickupCollection consists of. 153 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 154 { 155 if(this->getCarrier() == NULL) 156 (*it)->setCarrier(NULL); 157 else 158 (*it)->setCarrier(this->getCarrier()->getTarget(*it)); 126 159 } 127 160 } … … 136 169 SUPER(PickupCollection, changedPickedUp); 137 170 138 //! Change the pickedUp status for all Pickupables this PickupCollection consists of. 139 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 140 { 141 (*it).get()->setPickedUp(this->isPickedUp()); 142 } 171 this->processingPickedUp_ = true; 172 // Change the pickedUp status for all Pickupables this PickupCollection consists of. 173 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 174 { 175 (*it)->setPickedUp(this->isPickedUp()); 176 } 177 this->processingPickedUp_ = false; 178 179 this->changedPickedUpAction(); 180 } 181 182 /** 183 @brief 184 Helper method. 185 Checks whether due to changes in the picked up status of the pickups of this PickupCollection the picked up status of this PickupCollection has to change as well. 186 */ 187 void PickupCollection::changedPickedUpAction(void) 188 { 189 if(this->processingPickedUp_) 190 return; 191 192 // If at least all the enabled pickups of this PickupCollection are no longer picked up. 193 if(this->pickedUpCounter_ <= this->disabledCounter_ && this->isPickedUp()) 194 this->Pickupable::destroy(); 195 196 // If the PickupCollection is no longer picked up. 197 if(!this->isPickedUp()) 198 this->pickedUpCounter_ = 0; 143 199 } 144 200 … … 158 214 159 215 PickupCollection* pickup = dynamic_cast<PickupCollection*>(item); 160 //! Clone all Pickupables this PickupCollection consist of. 161 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 162 { 163 Pickupable* newPickup = (*it).get()->clone(); 164 pickup->addPickupable(newPickup); 216 // Clone all Pickupables this PickupCollection consist of. 217 for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 218 { 219 Pickupable* newPickup = (*it)->clone(); 220 CollectiblePickup* collectible = static_cast<CollectiblePickup*>(newPickup); 221 pickup->addPickupable(collectible); 165 222 } 166 223 … … 178 235 bool PickupCollection::isTarget(PickupCarrier* carrier) const 179 236 { 180 for(std::vector< WeakPtr<Pickupable>>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)181 { 182 if(!carrier->isTarget( (*it).get()))237 for(std::vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 238 { 239 if(!carrier->isTarget(*it)) 183 240 return false; 184 241 } … … 207 264 Returns true if successful, 208 265 */ 209 bool PickupCollection::addPickupable( Pickupable* pickup)266 bool PickupCollection::addPickupable(CollectiblePickup* pickup) 210 267 { 211 268 if(pickup == NULL) 212 269 return false; 213 270 214 WeakPtr<Pickupable> ptr = pickup; //!< Create a weak pointer to be able to test in the constructor if the Pointer is still valid.215 this->pickups_.push_back(p tr);271 pickup->addToCollection(this); 272 this->pickups_.push_back(pickup); 216 273 return true; 217 274 } … … 227 284 const Pickupable* PickupCollection::getPickupable(unsigned int index) 228 285 { 229 return this->pickups_[index].get(); 286 return this->pickups_[index]; 287 } 288 289 /** 290 @brief 291 Informs the PickupCollection, that one of its pickups has changed its used status to the input value. 292 This is used internally by the CollectiblePickup class. 293 @param changed 294 The value the used status has changed to. 295 */ 296 void PickupCollection::pickupChangedUsed(bool changed) 297 { 298 if(changed) 299 this->usedCounter_++; 300 else 301 this->usedCounter_--; 302 303 this->changedUsedAction(); 304 } 305 306 /** 307 @brief 308 Informs the PickupCollection, that one of its pickups has changed its picked up status to the input value. 309 This is used internally by the CollectiblePickup class. 310 @param changed 311 The value the picked up status has changed to. 312 */ 313 void PickupCollection::pickupChangedPickedUp(bool changed) 314 { 315 if(changed) 316 this->pickedUpCounter_++; 317 else 318 this->pickedUpCounter_--; 319 320 this->changedPickedUpAction(); 321 } 322 323 /** 324 @brief 325 Informs the PickupCollection, that one of its pickups has been disabled. 326 This is used internally by the CollectiblePickup class. 327 */ 328 void PickupCollection::pickupDisabled(void) 329 { 330 this->disabledCounter_++; 230 331 } 231 332 -
code/branches/presentation3/src/modules/pickup/PickupCollection.h
r7127 r7162 37 37 #include "PickupPrereqs.h" 38 38 39 #include "interfaces/Pickupable.h"40 39 #include "core/BaseObject.h" 40 #include "CollectiblePickup.h" 41 41 42 42 #include <list> … … 47 47 /** 48 48 @brief 49 The PickupCollection combines different Pickupables to a coherent, single pickup and makes the seem (from the outside looking in) just as if they were just one Pickupable.49 The PickupCollection combines different Pickupables to a coherent, single pickup and makes them seem (from the outside looking in) just as if they were just one Pickupable. 50 50 @author 51 51 Damian 'Mozork' Frick 52 52 */ 53 class _PickupExport PickupCollection : public Pickupable, public BaseObject53 class _PickupExport PickupCollection : public CollectiblePickup, public BaseObject 54 54 { 55 55 56 56 public: 57 58 57 PickupCollection(BaseObject* creator); //!< Default Constructor. 59 58 virtual ~PickupCollection(); //!< Destructor. … … 71 70 virtual const PickupIdentifier* getPickupIdentifier(void); //!< Get the PickupIdentifier of this PickupCollection. 72 71 73 bool addPickupable( Pickupable* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection.72 bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection. 74 73 const Pickupable* getPickupable(unsigned int index); //!< Get the Pickupable at the given index. 74 75 void pickupChangedUsed(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its used status to the input value. 76 void pickupChangedPickedUp(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its picked up status to the input value. 77 void pickupDisabled(void); //!< Informs the PickupCollection, that one of its pickups has been disabled. 75 78 76 79 protected: … … 82 85 83 86 private: 87 void changedUsedAction(void); //!< Helper method. 88 void changedPickedUpAction(void); //!< Helper method. 89 90 std::vector<CollectiblePickup*> pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid. 84 91 85 std::vector<WeakPtr<Pickupable> > pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid. 92 unsigned int usedCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are in use. 93 unsigned int pickedUpCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are picked up. 94 unsigned int disabledCounter_; //!< Keeps track of the number of pickups of this PickupCollection, that are disabled. 95 96 bool processingUsed_; //!< Boolean to ensure, that the PickupCollection doesn't update its used status while its internal state is inconsistent. 97 bool processingPickedUp_; //!< Boolean to ensure, that the PickupCollection doesn't update its picked upp status while its internal state is inconsistent. 86 98 87 99 }; -
code/branches/presentation3/src/modules/pickup/PickupCollectionIdentifier.cc
r7129 r7162 67 67 int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const 68 68 { 69 // !Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.69 // Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier. 70 70 PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier); 71 71 const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp); 72 72 73 // !If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.73 // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared. 74 74 if(collectionIdentifier == NULL) 75 75 { … … 77 77 } 78 78 79 // !If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.79 // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller. 80 80 if(this->identifiers_.size() != collectionIdentifier->identifiers_.size()) 81 81 return this->identifiers_.size()-collectionIdentifier->identifiers_.size(); 82 82 83 // !Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.83 // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller. 84 84 std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin(); 85 85 for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++) -
code/branches/presentation3/src/modules/pickup/PickupManager.cc
r7150 r7162 43 43 #include "infos/PlayerInfo.h" 44 44 #include "worldentities/pawns/Pawn.h" 45 #include "CollectiblePickup.h" 45 46 #include "PickupRepresentation.h" 46 47 … … 64 65 RegisterRootObject(PickupManager); 65 66 67 //TODO: This doesn't work, yet. 66 68 if( GameMode::showsGraphics() ) 67 69 { … … 172 174 for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++) 173 175 { 174 this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup))); 176 CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(*pickup); 177 if(collectible == NULL || !collectible->isInCollection()) 178 this->pickupsList_.insert(std::pair<Pickupable*, WeakPtr<Pickupable> >(*pickup, WeakPtr<Pickupable>(*pickup))); 175 179 } 176 180 } -
code/branches/presentation3/src/modules/pickup/PickupPrereqs.h
r7136 r7162 66 66 { 67 67 68 class CollectiblePickup; 68 69 class DroppedPickup; 69 70 class Pickup; -
code/branches/presentation3/src/modules/pickup/PickupRepresentation.h
r7129 r7162 149 149 std::string spawnerTemplate_; //!< The name of the template of this PickupRepresentation. 150 150 StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation. 151 std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. TODO: Exact format and placement of image?151 std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. 152 152 153 153 Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation. -
code/branches/presentation3/src/modules/pickup/PickupSpawner.cc
r7150 r7162 107 107 this->maxSpawnedItems_ = INF; 108 108 this->spawnsRemaining_ = INF; 109 this->selfDestruct_ = false; 109 110 } 110 111 … … 115 116 PickupSpawner::~PickupSpawner() 116 117 { 117 if(this-> pickup_ != NULL)118 if(this->selfDestruct_ && this->pickup_ != NULL) 118 119 this->pickup_->destroy(); 119 120 } … … 176 177 if (this->isActive()) 177 178 { 178 SmartPtr<PickupSpawner> temp = this; // create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup)179 SmartPtr<PickupSpawner> temp = this; //Create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup) 179 180 180 181 //! Iterate trough all Pawns. … … 305 306 { 306 307 if(pickup->pickup(target)) 307 {308 308 this->decrementSpawnsRemaining(); 309 }310 309 else 311 310 { 311 this->selfDestruct_ = true; 312 312 pickup->destroy(); 313 313 } … … 319 319 320 320 if(pickup == NULL) 321 {322 321 COUT(1) << "PickupSpawner (&" << this << "): getPickup produced an error, no Pickupable created." << std::endl; 323 }324 322 else 325 323 { 324 this->selfDestruct_ = true; 326 325 pickup->destroy(); 327 326 } -
code/branches/presentation3/src/modules/pickup/PickupSpawner.h
r7127 r7162 125 125 Timer respawnTimer_; //!< Timer used for re-activating. 126 126 127 bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing. 128 127 129 static const int INF = -1; //!< Constant for infinity. 128 130 }; -
code/branches/presentation3/src/modules/pickup/items/DronePickup.cc
r7127 r7162 131 131 Pawn* pawn = this->carrierToPawnHelper(); 132 132 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 133 this-> destroy();133 this->Pickupable::destroy(); 134 134 135 135 //Attach to pawn … … 155 155 if(this->isOnce() || (this->isContinuous() )) 156 156 { 157 this-> destroy();157 this->Pickupable::destroy(); 158 158 } 159 159 } -
code/branches/presentation3/src/modules/pickup/items/HealthPickup.cc
r7127 r7162 143 143 Pawn* pawn = this->carrierToPawnHelper(); 144 144 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 145 this-> destroy();145 this->Pickupable::destroy(); 146 146 147 147 //! Calculate the health that is added this tick. … … 191 191 192 192 //! If the pickup is not picked up nothing must be done. 193 if(!this->isPickedUp()) 193 if(!this->isPickedUp()) //TODO: Needed? 194 194 return; 195 195 … … 201 201 Pawn* pawn = this->carrierToPawnHelper(); 202 202 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 203 this-> destroy();203 this->Pickupable::destroy(); 204 204 205 205 float health = 0; … … 241 241 { 242 242 COUT(1) << "Something went horribly wrong in Health Pickup. PickupCarrier is no Pawn." << std::endl; 243 this-> destroy();243 this->Pickupable::destroy(); 244 244 return; 245 245 } … … 256 256 if(this->isOnce() || (this->isContinuous() && this->getHealth() == 0)) 257 257 { 258 this-> destroy();258 this->Pickupable::destroy(); 259 259 } 260 260 } -
code/branches/presentation3/src/modules/pickup/items/InvisiblePickup.cc
r7129 r7162 133 133 if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration()) 134 134 { 135 this-> destroy();135 this->Pickupable::destroy(); 136 136 } 137 137 else -
code/branches/presentation3/src/modules/pickup/items/MetaPickup.cc
r7150 r7162 34 34 #include "core/CoreIncludes.h" 35 35 #include "core/XMLPort.h" 36 #include "worldentities/pawns/Pawn.h" 36 37 #include "interfaces/PickupCarrier.h" 37 38 #include "pickup/PickupIdentifier.h" … … 47 48 /*static*/ const std::string MetaPickup::metaTypeUse_s = "use"; 48 49 /*static*/ const std::string MetaPickup::metaTypeDrop_s = "drop"; 50 /*static*/ const std::string MetaPickup::metaTypeDestroy_s = "destroy"; 51 /*static*/ const std::string MetaPickup::metaTypeDestroyCarrier_s = "destroyCarrier"; 49 52 50 53 /** … … 120 123 if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL) 121 124 { 125 if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier) 126 { 127 Pawn* pawn = orxonox_cast<Pawn*>(carrier); 128 pawn->kill(); 129 return; 130 } 122 131 std::set<Pickupable*> pickups = carrier->getPickups(); 123 //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending o the meta type.132 //! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending on the meta type. 124 133 for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++) 125 134 { … … 136 145 if(pickup != NULL && pickup != this) 137 146 { 138 pickup->drop(carrier); 147 pickup->drop(); 148 } 149 } 150 if(this->getMetaTypeDirect() == pickupMetaType::destroy) 151 { 152 if(pickup != NULL && pickup != this) 153 { 154 pickup->Pickupable::destroy(); 139 155 } 140 156 } 141 157 } 142 158 } 143 this-> destroy();159 this->Pickupable::destroy(); 144 160 } 145 161 } … … 180 196 case pickupMetaType::drop: 181 197 return MetaPickup::metaTypeDrop_s; 198 case pickupMetaType::destroy: 199 return MetaPickup::metaTypeDestroy_s; 200 case pickupMetaType::destroyCarrier: 201 return MetaPickup::metaTypeDestroyCarrier_s; 182 202 default: 183 203 return BLANKSTRING; … … 205 225 this->setMetaTypeDirect(pickupMetaType::drop); 206 226 } 227 else if(type == MetaPickup::metaTypeDestroy_s) 228 { 229 this->setMetaTypeDirect(pickupMetaType::destroy); 230 } 231 else if(type == MetaPickup::metaTypeDestroyCarrier_s) 232 { 233 this->setMetaTypeDirect(pickupMetaType::destroyCarrier); 234 } 235 else 236 COUT(2) << "Invalid metaType '" << type << "' in MetaPickup." << std::endl; 207 237 } 208 238 -
code/branches/presentation3/src/modules/pickup/items/MetaPickup.h
r7127 r7162 48 48 none, 49 49 use, 50 drop 50 drop, 51 destroy, 52 destroyCarrier 51 53 }; 52 54 } … … 54 56 /** 55 57 @brief 56 The MetaPickup is a pickup that can, depending on the parameters, either drop all pickups of the PickupCarrier that picks it up, or use all the unused pickups of the PickupCarrier, that picks it up. The parameter to set for this is the metaType and it can be used with the values 'none', 'drop' and 'use'. 58 The MetaPickup is a pickup that can, depending on the parameter 'metaType', do different things. If the 'metaType' is set to 59 1) 'use', all the pickups, the PickupCarrier has, are immediately set to used upon pickup of the MetaPickup. 60 2) 'drop', all the pickups, the PickupCarrier has, are immediately dropped upon pickup of the MetaPickup. 61 3) 'destroy', all the pickups, the PickupCarrier has, are immediately destroyed upon pickup of the MetaPickup. 62 4) 'destroyCarrier', the PickupCarrier is immediately destroyed upon pickup of the MetaPickup. 57 63 @author 58 64 Damian 'Mozork' Frick … … 98 104 static const std::string metaTypeUse_s; 99 105 static const std::string metaTypeDrop_s; 106 static const std::string metaTypeDestroy_s; 107 static const std::string metaTypeDestroyCarrier_s; 100 108 101 109 -
code/branches/presentation3/src/modules/pickup/items/ShieldPickup.cc
r7127 r7162 155 155 Pawn* pawn = this->carrierToPawnHelper(); 156 156 if(pawn == NULL) 157 this-> destroy();157 this->Pickupable::destroy(); 158 158 159 159 //! If the pickup has transited to used. … … 181 181 if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration()) 182 182 { 183 this-> destroy();183 this->Pickupable::destroy(); 184 184 } 185 185 else -
code/branches/presentation3/src/modules/pickup/items/SpeedPickup.cc
r7127 r7162 136 136 Engine* engine = this->carrierToEngineHelper(); 137 137 if(engine == NULL) //!< If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed. 138 this-> destroy();138 this->Pickupable::destroy(); 139 139 140 140 //! If the pickup has transited to used. … … 161 161 if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration()) 162 162 { 163 this-> destroy();163 this->Pickupable::destroy(); 164 164 } 165 165 else -
code/branches/presentation3/src/orxonox/CameraManager.cc
r7161 r7162 68 68 void CameraManager::requestFocus(Camera* camera) 69 69 { 70 COUT(0) << "bliub" << endl;71 70 // notify old camera (if it exists) 72 71 if (!this->cameraList_.empty()) -
code/branches/presentation3/src/orxonox/gametypes/Dynamicmatch.cc
r7076 r7162 102 102 103 103 bool Dynamicmatch::allowPawnDamage(Pawn* victim, Pawn* originator) 104 { //TODO: static and fading message for the "human" player's 104 { 105 //TODO: static and fading message for the "human" player's 105 106 if (!originator||!victim) 106 107 return false; -
code/branches/presentation3/src/orxonox/interfaces/InterfaceCompilation.cc
r7127 r7162 59 59 { 60 60 RegisterRootObject(PickupCarrier); 61 62 this->setCarrierName("PickupCarrier");63 61 } 64 62 65 63 PickupCarrier::~PickupCarrier() 66 64 { 65 66 } 67 68 void PickupCarrier::preDestroy(void) 69 { 67 70 std::set<Pickupable*>::iterator it = this->pickups_.begin(); 71 std::set<Pickupable*>::iterator temp; 68 72 while(it != this->pickups_.end()) 69 73 { 70 (*it)->destroy(); 74 (*it)->carrierDestroyed(); 75 temp = it; 71 76 it = this->pickups_.begin(); 77 if(it == temp) // Infinite loop avoidance, in case the pickup wasn't removed from the carrier somewhere in the carrierDestroy() procedure. 78 { 79 COUT(2) << "Oops. In a PickupCarrier, while cleaning up, a Pickupable (&" << (*temp) << ") didn't unregister itself as it should have." << std::endl;; 80 it++; 81 } 72 82 } 73 83 -
code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h
r7150 r7162 79 79 PickupCarrier(); //!< Constructor. 80 80 virtual ~PickupCarrier(); //!< Destructor. 81 void preDestroy(void); 81 82 82 83 /** … … 138 139 virtual const Vector3& getCarrierPosition(void) = 0; 139 140 140 /**141 @brief Get the name of this PickupCarrier.142 @return Returns the name as a string.143 */144 const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export145 146 141 protected: 147 142 /** … … 160 155 161 156 /** 157 @brief Get all Pickupables this PickupCarrier has. 158 @return Returns the set of all Pickupables this PickupCarrier has. 159 */ 160 std::set<Pickupable*>& getPickups(void) 161 { return this->pickups_; } 162 163 private: 164 std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier. 165 166 /** 162 167 @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier. 163 168 @param pickup A pointer to the pickup to be added. … … 165 170 */ 166 171 bool addPickup(Pickupable* pickup) 167 { return this->pickups_.insert(pickup).second; } 172 { 173 COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl; 174 return this->pickups_.insert(pickup).second; 175 } 168 176 169 177 /** … … 173 181 */ 174 182 bool removePickup(Pickupable* pickup) 175 { return this->pickups_.erase(pickup) == 1; }176 177 /**178 @brief Get all Pickupables this PickupCarrier has.179 @return Returns the set of all Pickupables this PickupCarrier has.180 */181 std::set<Pickupable*>& getPickups(void)182 { return this->pickups_; }183 184 /**185 @brief Set the name of this PickupCarrier.186 The name needs to be set in the constructor of every class inheriting from PickupCarrier, by calling setCarrierName().187 @param name The name to be set.188 */189 void setCarrierName(const std::string& name)190 { this->carrierName_ = name; }191 192 private:193 std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.194 std::string carrierName_; //!< The name of the PickupCarrier, as displayed in the PickupInventory.195 196 /**197 @brief Get the number of carrier children this PickupCarrier has.198 @return Returns the number of carrier children.199 */200 unsigned int getNumCarrierChildren(void)201 183 { 202 std::vector<PickupCarrier*>* list = this->getCarrierChildren(); 203 unsigned int size = list->size(); 204 delete list; 205 return size; 206 } 207 208 /** 209 @brief Get the index-th child of this PickupCarrier. 210 @param index The index of the child to return. 211 @return Returns the index-th child. 212 */ 213 PickupCarrier* getCarrierChild(unsigned int index) 214 { 215 std::vector<PickupCarrier*>* list = this->getCarrierChildren(); 216 if(list->size() < index) 217 return NULL; 218 PickupCarrier* carrier = (*list)[index]; 219 delete list; 220 return carrier; 221 } 222 223 /** 224 @brief Get the number of Pickupables this PickupCarrier carries. 225 @return returns the number of pickups. 226 */ 227 unsigned int getNumPickups(void) 228 { return this->pickups_.size(); } 229 230 /** 231 @brief Get the index-th Pickupable of this PickupCarrier. 232 @param index The index of the Pickupable to return. 233 @return Returns the index-th pickup. 234 */ 235 Pickupable* getPickup(unsigned int index) 236 { 237 std::set<Pickupable*>::iterator it; 238 for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++) 239 index--; 240 if(it == this->pickups_.end()) 241 return NULL; 242 return *it; 184 COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl; 185 return this->pickups_.erase(pickup) == 1; 243 186 } 244 187 -
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 -
code/branches/presentation3/src/orxonox/interfaces/Pickupable.h
r7150 r7162 95 95 virtual void changedPickedUp(void) {} 96 96 97 bool pickup(PickupCarrier* carrier); 98 bool drop(bool createSpawner = true); 97 /** 98 @brief Returns whether the Pickupable can be used. 99 @return Returns true if it can be used. 100 */ 101 inline bool isUsable(void) { return this->enabled_; } // tolua_export 102 103 /** 104 @brief Returns whether the Pickupable can be unused. 105 @return Returns true if it can be unused. 106 */ 107 inline bool isUnusable(void) { return this->enabled_; } // tolua_export 108 109 /** 110 @brief Returns whether the Pickupable is enabled. 111 Once a Pickupable is disabled it cannot be enabled again. A Pickupable that is disabled can neither be used nor unused. 112 @return Returns true if the Pickupable is enabled. 113 */ 114 inline bool isEnabled(void) 115 { return this->enabled_; } 116 117 bool pickup(PickupCarrier* carrier); //!< Can be called to pick up a Pickupable. 118 bool drop(bool createSpawner = true); //!< Can be called to drop a Pickupable. 99 119 100 120 virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup. … … 115 135 bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input. 116 136 bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up. 117 bool setCarrier(PickupCarrier* carrier, bool tell = false); //!< Sets the carrier of the pickup. 137 //TODO: private? 138 bool setCarrier(PickupCarrier* carrier, bool tell = true); //!< Sets the carrier of the pickup. 139 140 //TODO: private? 141 virtual void carrierDestroyed(void); //!< Is called by the PickupCarrier when it is being destroyed. 142 143 void destroy(void); //!< Is called internally within the pickup module to destroy pickups. 118 144 119 145 protected: … … 122 148 */ 123 149 void initializeIdentifier(void) {} 150 151 virtual void preDestroy(void); //!< A method that is called by OrxonoxClass::destroy() before the object is actually destroyed. 152 virtual void destroyPickup(void); //!< Destroys a Pickupable. 153 154 /** 155 @brief Sets the Pickuapble to disabled. 156 */ 157 inline void setDisabled(void) 158 { this->enabled_ = false; } 124 159 125 160 /** … … 136 171 private: 137 172 138 bool used_; //!< Whether the pickupis currently in use or not.139 bool pickedUp_; //!< Whether the pickupis currently picked up or not.173 bool used_; //!< Whether the Pickupable is currently in use or not. 174 bool pickedUp_; //!< Whether the Pickupable is currently picked up or not. 140 175 141 PickupCarrier* carrier_; //!< The carrier of the pickup. 142 std::list<Identifier*> targets_; //!< The possible targets of this pickup. 176 bool enabled_; //!< Whether the Pickupable is enabled or not. 177 178 PickupCarrier* carrier_; //!< The PickupCarrier of the Pickupable. 179 std::list<Identifier*> targets_; //!< The possible targets of this Pickupable. 180 181 bool beingDestroyed_; //!< Is true if the Pickupable is in the process of being destroyed. 143 182 144 183 // For implementing the Rewardable interface: -
code/branches/presentation3/src/orxonox/items/Engine.cc
r6711 r7162 64 64 this->boostBlur_ = 0; 65 65 66 this->setCarrierName("Engine");67 66 this->speedAdd_ = 0.0; 68 67 this->speedMultiply_ = 1.0; -
code/branches/presentation3/src/orxonox/pickup/PickupIdentifier.cc
r7129 r7162 105 105 } 106 106 107 //! We iterate through all parameters and compar their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings.107 //! We iterate through all parameters and compare their values (which are strings). The first parameter is the most significant. The ordering is once again established by the alphabetical comparison of the two value strings. 108 108 for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++) 109 109 { -
code/branches/presentation3/src/orxonox/worldentities/pawns/Pawn.cc
r7153 r7162 83 83 this->weaponSystem_ = 0; 84 84 85 this->setCarrierName("Pawn");86 87 85 this->setRadarObjectColour(ColourValue::Red); 88 86 this->setRadarObjectShape(RadarViewable::Dot);
Note: See TracChangeset
for help on using the changeset viewer.