- Timestamp:
- Oct 14, 2009, 4:36:56 PM (16 years ago)
- Location:
- code/branches/pickup2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2
- Property svn:mergeinfo changed
/code/branches/pickup2 (added) merged: 5942 /code/trunk (added) merged: 5900-5901,5923,5929,5936-5938,5940
- Property svn:mergeinfo changed
-
code/branches/pickup2/src/orxonox/pickup/PickupSpawner.cc
r5947 r5953 46 46 namespace orxonox 47 47 { 48 48 49 const float PickupSpawner::bounceSpeed_s = 6.0f; 49 50 const float PickupSpawner::rotationSpeed_s = 1.0f; … … 60 61 PickupSpawner::PickupSpawner(BaseObject* creator) : StaticEntity(creator) 61 62 { 63 this->initialize(); 64 } 65 66 PickupSpawner::PickupSpawner(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator) 67 { 68 this->initialize(); 69 70 //TODO: Does this actually work? 71 this->itemTemplateName_ = item->getIdentifier()->getName(); 72 this->itemTemplate_ = Template::getTemplate(this->itemTemplateName_); 73 74 this->triggerDistance_ = triggerDistance; 75 this->respawnTime_ = respawnTime; 76 this->setMaxSpawnedItems(maxSpawnedItems); 77 } 78 79 void PickupSpawner::initialize(void) 80 { 62 81 RegisterObject(PickupSpawner); 63 82 64 this->itemTemplate_ = 0;83 this->itemTemplate_ = NULL; 65 84 this->triggerDistance_ = 20; 66 85 this->respawnTime_ = 0.0f; 67 86 this->tickSum_ = 0.0f; 87 this->maxSpawnedItems_ = INF; 88 this->spawnsRemaining_ = INF; 68 89 } 69 90 … … 92 113 XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode); 93 114 XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode); 115 XMLPortParam(PickupSpawner, "maxSpawnedItems", setMaxSpawnedItems, getMaxSpawnedItems, xmlelement, mode); 94 116 95 117 //TODO: Kill hack. … … 137 159 } 138 160 161 void PickupSpawner::setMaxSpawnedItems(int items) 162 { 163 this->maxSpawnedItems_ = items; 164 this->spawnsRemaining_ = items; 165 } 166 139 167 /** 140 168 @brief … … 148 176 if (this->isActive()) 149 177 { 178 //! Triggers as soon as a Pawn is in the specified distance. 150 179 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 151 180 { … … 154 183 this->trigger(*it); 155 184 } 185 186 //! Animation. 156 187 this->yaw(Radian(rotationSpeed_s*dt)); 157 188 this->tickSum_ += bounceSpeed_s*dt; … … 174 205 void PickupSpawner::trigger(Pawn* pawn) 175 206 { 176 if (this->isActive() && this->itemTemplate_ && this->itemTemplate_->getBaseclassIdentifier()) 177 { 178 BaseObject* newObject = this->itemTemplate_->getBaseclassIdentifier()->fabricate(this); 179 BaseItem* asItem = orxonox_cast<BaseItem*>(newObject); 180 if (asItem) 207 if (this->isActive() && this->itemTemplate_ && this->itemTemplate_->getBaseclassIdentifier()) //!< Checks whether PickupItem is active, amongst other things. 208 { 209 BaseItem* item = this->getItem(); 210 if (item != NULL) //!< If the conversion was successful. 181 211 { 182 asItem->setPickupIdentifier(this->itemTemplateName_);183 asItem->addTemplate(this->itemTemplate_);184 185 if (asItem->pickedUp(pawn))212 item->setPickupIdentifier(this->itemTemplateName_); //TODO: Needed? 213 item->addTemplate(this->itemTemplate_); //TODO: Does what? 214 215 if(item->pickedUp(pawn)) 186 216 { 187 217 COUT(3) << this->itemTemplateName_ << " got picked up." << std::endl; 188 218 189 if (this->respawnTime_ > 0.0f) 219 220 if(this->spawnsRemaining_ != INF) 221 { 222 this->spawnsRemaining_--; 223 } 224 225 if (this->spawnsRemaining_ != 0 && this->respawnTime_ > 0.0f) 190 226 { 191 227 this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this))); … … 196 232 } 197 233 else 198 newObject->destroy(); 234 { 235 item->destroy(); 236 } 199 237 } 200 238 } 239 240 if(this->spawnsRemaining_ == 0) 241 { 242 COUT(3) << "PickupSpawner empty, selfdistruct initialized." << std::endl; 243 this->setActive(false); 244 this->destroy(); 245 } 246 } 247 248 /** 249 @brief 250 Creates a BaseItem of the type specified by the PickupSpawner. 251 @return 252 The BaseItem created. 253 */ 254 BaseItem* PickupSpawner::getItem(void) 255 { 256 BaseObject* newItem = this->itemTemplate_->getBaseclassIdentifier()->fabricate(this); //!< Creates new object of specified item type. 257 return orxonox_cast<BaseItem*>(newItem); 201 258 } 202 259
Note: See TracChangeset
for help on using the changeset viewer.