Changeset 7163 for code/trunk/src/modules/pickup/PickupSpawner.cc
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/pickup/PickupSpawner.cc
r6711 r7163 55 55 { 56 56 RegisterObject(PickupSpawner); 57 57 58 58 this->initialize(); 59 59 } … … 76 76 { 77 77 RegisterObject(PickupSpawner); 78 78 79 79 this->initialize(); 80 80 81 81 this->pickup_ = pickup; 82 82 … … 84 84 this->respawnTime_ = respawnTime; 85 85 this->setMaxSpawnedItems(maxSpawnedItems); 86 86 87 87 if(this->pickup_ == NULL) 88 88 { … … 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 } … … 132 133 133 134 XMLPortObject(PickupSpawner, Pickupable, "pickup", setPickupable, getPickupable, xmlelement, mode); 134 135 135 136 XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode); 136 137 XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode); 137 138 XMLPortParam(PickupSpawner, "maxSpawnedItems", setMaxSpawnedItems, getMaxSpawnedItems, xmlelement, mode); 138 139 139 140 if(this->pickup_ == NULL) 140 141 { … … 150 151 } 151 152 } 152 153 153 154 /** 154 155 @brief … … 161 162 this->setVisible(this->isActive()); 162 163 } 163 164 164 165 /** 165 166 @brief … … 172 173 { 173 174 SUPER(PickupSpawner, tick, dt); 174 175 175 176 //! If the PickupSpawner is active. 176 177 if (this->isActive()) 177 178 { 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) 180 178 181 //! Iterate trough all Pawns. 179 182 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) … … 189 192 } 190 193 } 191 194 192 195 /** 193 196 @brief … … 201 204 this->spawnsRemaining_ = items; 202 205 } 203 206 204 207 /** 205 208 @brief … … 223 226 else 224 227 { 225 COUT( 3) << "PickupSpawnerempty, selfdestruct initialized." << std::endl;228 COUT(4) << "PickupSpawner (&" << this << ") empty, selfdestruct initialized." << std::endl; 226 229 this->setActive(false); 227 230 this->destroy(); 228 231 } 229 232 } 230 233 231 234 /** 232 235 @brief … … 237 240 this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this))); 238 241 } 239 242 240 243 /** 241 244 @brief … … 248 251 if(this->pickup_ != NULL) 249 252 { 250 COUT(1) << "In PickupSpawner : setPickupable called, with this->pickup_ already set." << std::endl;253 COUT(1) << "In PickupSpawner (&" << this << "): setPickupable called, with this->pickup_ already set." << std::endl; 251 254 return; 252 255 } 253 256 if(pickup == NULL) 254 257 { 255 COUT(1) << "In PickupSpawner : Argument of setPickupable is NULL." << std::endl;258 COUT(1) << "In PickupSpawner (&" << this << "): Argument of setPickupable is NULL." << std::endl; 256 259 return; 257 260 } 258 261 259 262 this->pickup_ = pickup; 260 263 } 261 264 262 265 /** 263 266 @brief … … 282 285 if (this->isActive()) //!< Checks whether PickupSpawner is active. 283 286 { 284 COUT( 3) << "PickupSpawnertriggered and active." << std::endl;285 287 COUT(4) << "PickupSpawner (&" << this << ") triggered and active." << std::endl; 288 286 289 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn); 287 290 if(carrier == NULL) … … 290 293 return; 291 294 } 292 295 293 296 if(!carrier->isTarget(this->pickup_)) 294 297 { 295 COUT(4) << "PickupSpawner triggered but Pawn wasn't a target of the Pickupable." << std::endl;298 COUT(4) << "PickupSpawner (&" << this << ") triggered but Pawn wasn't a target of the Pickupable." << std::endl; 296 299 return; 297 300 } 298 301 299 302 PickupCarrier* target = carrier->getTarget(this->pickup_); 300 303 Pickupable* pickup = this->getPickup(); 301 304 302 305 if(target != NULL && pickup != NULL) 303 306 { 304 if(target->pickup(pickup)) 305 { 307 if(pickup->pickup(target)) 306 308 this->decrementSpawnsRemaining(); 307 }308 309 else 309 310 { 311 this->selfDestruct_ = true; 310 312 pickup->destroy(); 311 313 } … … 314 316 { 315 317 if(target == NULL) 316 COUT(1) << "PickupSpawner : Pickupable has no target." << std::endl;317 318 COUT(1) << "PickupSpawner (&" << this << "): Pickupable has no target." << std::endl; 319 318 320 if(pickup == NULL) 319 { 320 COUT(1) << "PickupSpawner: getPickup produced an error, no Pickupable created." << std::endl; 321 } 321 COUT(1) << "PickupSpawner (&" << this << "): getPickup produced an error, no Pickupable created." << std::endl; 322 322 else 323 323 { 324 this->selfDestruct_ = true; 324 325 pickup->destroy(); 325 326 } … … 333 334 @return 334 335 The Pickupable created. 335 */ 336 */ 336 337 Pickupable* PickupSpawner::getPickup(void) 337 338 { … … 341 342 return NULL; 342 343 } 343 344 344 345 Pickupable* pickup = this->pickup_->clone(); 345 346 return pickup; … … 352 353 void PickupSpawner::respawnTimerCallback() 353 354 { 354 COUT( 3) << "PickupSpawnerreactivated." << std::endl;355 COUT(4) << "PickupSpawner (&" << this << ") reactivated." << std::endl; 355 356 356 357 this->setActive(true);
Note: See TracChangeset
for help on using the changeset viewer.