Changeset 7549 for code/trunk
- Timestamp:
- Oct 16, 2010, 2:18:45 PM (14 years ago)
- Location:
- code/trunk/src/modules/pickup
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/pickup/DroppedPickup.cc
r7494 r7549 70 70 71 71 this->setPosition(carrier->getCarrierPosition()); 72 this->setActive(false); 73 74 //TODO: Do more elegantly. 75 this->startRespawnTimer(); 72 this->block(carrier, DEFAULT_BLOCKED_TIME); 76 73 } 77 74 -
code/trunk/src/modules/pickup/DroppedPickup.h
r7533 r7549 64 64 virtual Pickupable* getPickup(void); //!< Creates the Pickupable that is going to get picked up. 65 65 66 private: 67 static const unsigned int DEFAULT_BLOCKED_TIME = 10; //!< The default time a PickupCarrier is blocked from picking up the pickupable again, after it has dropped it. 68 66 69 }; 67 70 } -
code/trunk/src/modules/pickup/PickupManager.cc
r7548 r7549 75 75 RegisterObject(PickupManager); 76 76 77 //TODO: Only create if isMaster().78 77 this->defaultRepresentation_ = new PickupRepresentation(); 79 78 … … 356 355 357 356 // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns. 358 //TODO: Needs to be added to server even if is was not picked up by it?359 357 if(GameMode::isStandalone() || Host::getPlayerID() == clientId) 360 358 { -
code/trunk/src/modules/pickup/PickupSpawner.cc
r7548 r7549 108 108 { 109 109 this->triggerDistance_ = 10; 110 this->respawnTime_ = 0; //TODO: Smart? Shouldn't we have a better mechanism to prevent unwanted multiple pickups?110 this->respawnTime_ = 5.0f; 111 111 this->maxSpawnedItems_ = INF; 112 112 this->spawnsRemaining_ = INF; … … 151 151 PickupRepresentation* representation = PickupManager::getInstance().getRepresentation(this->pickup_->getPickupIdentifier()); 152 152 this->attach(representation->getSpawnerRepresentation(this)); 153 this->setActive(true); //TODO: Needed?153 this->setActive(true); 154 154 } 155 155 } … … 183 183 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) 184 184 185 // Remove PickupCarriers from the blocked list if they have exceeded their time. 186 for(std::map<PickupCarrier*, std::time_t>::iterator it = this->blocked_.begin(); it != this->blocked_.end(); ) 187 { 188 std::map<PickupCarrier*, std::time_t>::iterator temp = it; 189 it++; 190 if(temp->second < std::time(0)) 191 this->blocked_.erase(temp); 192 } 193 185 194 // Iterate trough all Pawns. 186 for 195 for(ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 187 196 { 188 197 Vector3 distance = it->getWorldPosition() - this->getWorldPosition(); 189 198 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(*it); 190 // If a P awn, that fits the target-range of the item spawned by this Pickup, is in trigger-distance.191 if (distance.length() < this->triggerDistance_ && carrier != NULL)199 // If a PickupCarrier, that fits the target-range of the Pickupable spawned by this PickupSpawnder, is in trigger-distance and the carrier is not blocked. 200 if(distance.length() < this->triggerDistance_ && carrier != NULL && this->blocked_.find(carrier) == this->blocked_.end()) 192 201 { 193 202 if(carrier->isTarget(this->pickup_)) … … 292 301 293 302 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn); 294 if(carrier == NULL) 295 { 296 COUT(1) << "This is bad. Pawn isn't PickupCarrier." << std::endl; 297 return; 298 } 299 303 assert(carrier); 304 305 // If the Pawn isn't a target of the Pickupable. 300 306 if(!carrier->isTarget(this->pickup_)) 301 307 { … … 307 313 Pickupable* pickup = this->getPickup(); 308 314 315 this->block(carrier); 316 309 317 assert(pickup); 310 318 assert(target); -
code/trunk/src/modules/pickup/PickupSpawner.h
r7547 r7549 38 38 #include "PickupPrereqs.h" 39 39 40 #include <map> 40 41 #include <string> 41 42 #include "tools/Timer.h" … … 102 103 inline int getMaxSpawnedItems(void) const 103 104 { return this->maxSpawnedItems_; } 104 105 105 106 106 protected: 107 107 void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns. 108 void startRespawnTimer(void); 108 void startRespawnTimer(void); //!< Invoked by the timer, re-activates the PickupSpawner. 109 110 /** 111 @brief Helper method. Adds a PickupCarrier to the list of PickupCarrier that are blocked form getting a Pickupable from the PickupSpawner for a specified time. 112 @param carrier A pointer to the PickupCarrier to be blocked. 113 @param time The time for which the Pawn is blocked. Default is 5. 114 */ 115 void block(PickupCarrier* carrier, unsigned int time = DEFAULT_BLOCKED_TIME) 116 { this->blocked_.insert(std::pair<PickupCarrier*, std::time_t>(carrier, std::time(0)+time)); } 109 117 110 118 /** … … 142 150 float respawnTime_; //!< Time after which this gets re-actived. 143 151 Timer respawnTimer_; //!< Timer used for re-activating. 152 std::map<PickupCarrier*, std::time_t> blocked_; 144 153 145 154 bool selfDestruct_; //!< True if the PickupSpawner is selfdestructing. 146 155 147 156 static const int INF = -1; //!< Constant for infinity. 157 static const unsigned int DEFAULT_BLOCKED_TIME = 5; //!< The default time a PickupCarrier is blocked after picking up a Pickupable. 148 158 }; 149 159 }
Note: See TracChangeset
for help on using the changeset viewer.