Changeset 6405 for code/branches/pickup2/src/modules
- Timestamp:
- Dec 23, 2009, 8:27:17 PM (15 years ago)
- Location:
- code/branches/pickup2/src/modules
- Files:
-
- 6 added
- 2 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup2/src/modules/CMakeLists.txt
r5929 r6405 29 29 ADD_SUBDIRECTORY(objects) 30 30 ADD_SUBDIRECTORY(overlays) 31 ADD_SUBDIRECTORY(pickup) 31 32 ADD_SUBDIRECTORY(pong) 32 33 ADD_SUBDIRECTORY(questsystem) -
code/branches/pickup2/src/modules/pickup/PickupSpawner.cc
r5953 r6405 23 23 * Daniel 'Huty' Haggenmueller 24 24 * Co-authors: 25 * ...25 * Damian 'Mozork' Frick 26 26 * 27 27 */ … … 34 34 #include "PickupSpawner.h" 35 35 36 #include "BaseItem.h"37 38 36 #include "core/CoreIncludes.h" 39 #include "core/GUIManager.h" // HACK; see below37 //#include "core/GUIManager.h" // HACK; see below 40 38 #include "core/Template.h" 41 39 #include "core/XMLPort.h" 42 40 #include "worldentities/pawns/Pawn.h" 43 #include "PickupInventory.h" // HACK; Only for hack, remove later41 //#include "PickupInventory.h" // HACK; Only for hack, remove later 44 42 45 43 … … 47 45 { 48 46 49 const float PickupSpawner::bounceSpeed_s = 6.0f;50 const float PickupSpawner::rotationSpeed_s = 1.0f;51 const float PickupSpawner::bounceDistance_s = 4.0f;47 // const float PickupSpawner::bounceSpeed_s = 6.0f; 48 // const float PickupSpawner::rotationSpeed_s = 1.0f; 49 // const float PickupSpawner::bounceDistance_s = 4.0f; 52 50 53 51 CreateFactory(PickupSpawner); … … 64 62 } 65 63 66 PickupSpawner::PickupSpawner(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator)64 PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator) 67 65 { 68 66 this->initialize(); 69 67 70 //TODO: Does this actually work? 71 this->itemTemplateName_ = item->getIdentifier()->getName(); 72 this->itemTemplate_ = Template::getTemplate(this->itemTemplateName_); 68 this->pickup_ = pickup; 73 69 74 70 this->triggerDistance_ = triggerDistance; … … 81 77 RegisterObject(PickupSpawner); 82 78 83 this->itemTemplate_ = NULL; 79 this->pickup_ = NULL; 80 84 81 this->triggerDistance_ = 20; 85 this->respawnTime_ = 0 .0f;86 this->tickSum_ = 0 .0f;82 this->respawnTime_ = 0; 83 this->tickSum_ = 0; 87 84 this->maxSpawnedItems_ = INF; 88 85 this->spawnsRemaining_ = INF; … … 110 107 SUPER(PickupSpawner, XMLPort, xmlelement, mode); 111 108 112 XMLPortParam(PickupSpawner, "item", setItemTemplateName, getItemTemplateName, xmlelement, mode); 109 XMLPortObject(PickupSpawner, Pickupable, "pickup", addPickupable, getPickupable, xmlelement, mode); 110 113 111 XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode); 114 112 XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode); … … 119 117 // Load the GUI image as soon as the PickupSpawner gets loaded 120 118 // = less delays while running 121 BaseObject* newObject = this->itemTemplate_->getBaseclassIdentifier()->fabricate(this);122 BaseItem* asItem = orxonox_cast<BaseItem*>(newObject);123 if (asItem)124 {125 asItem->addTemplate(this->itemTemplate_);126 PickupInventory::getImageForItem(asItem);127 newObject->destroy();128 }119 // BaseObject* newObject = this->itemTemplate_->getBaseclassIdentifier()->fabricate(this); 120 // BaseItem* asItem = orxonox_cast<BaseItem*>(newObject); 121 // if (asItem) 122 // { 123 // asItem->addTemplate(this->itemTemplate_); 124 // PickupInventory::getImageForItem(asItem); 125 // newObject->destroy(); 126 // } 129 127 130 128 // & load the GUI itself too, along with some empty windows 131 129 // = even less delays 132 GUIManager::getInstance().showGUI("PickupInventory"); 133 GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")"); 134 PickupInventory::getSingleton(); 130 // GUIManager::getInstance().showGUI("PickupInventory"); 131 // GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")"); 132 // PickupInventory::getSingleton(); 133 } 134 135 void PickupSpawner::addPickupable(Pickupable* pickup) 136 { 137 if(this->pickup_ != NULL) 138 { 139 COUT(1) << "addPickupable called, with this->pickup_ already set." << std::endl; 140 return; 141 } 142 if(pickup == NULL) 143 { 144 COUT(1) << "Argument of addPickupable is NULL." << std::endl; 145 return; 146 } 147 148 this->pickup_ = pickup; 149 } 150 151 Pickupable* PickupSpawner::getPickupable(void) 152 { 153 return this->pickup_; 135 154 } 136 155 … … 139 158 Invoked when the activity has changed. Sets visibility of attached objects. 140 159 */ 141 void PickupSpawner::changedActivity() 142 { 143 SUPER(PickupSpawner, changedActivity); 144 145 for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) 146 (*it)->setVisible(this->isActive()); 147 } 148 149 /** 150 @brief 151 Set the template name of the item to spawn, also loads the template. 152 @param name 153 Name of the new template. 154 */ 155 void PickupSpawner::setItemTemplateName(const std::string& name) 156 { 157 this->itemTemplateName_ = name; 158 this->itemTemplate_ = Template::getTemplate(name); 159 } 160 // void PickupSpawner::changedActivity() 161 // { 162 // SUPER(PickupSpawner, changedActivity); 163 // 164 // for (std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) 165 // (*it)->setVisible(this->isActive()); 166 // } 160 167 161 168 void PickupSpawner::setMaxSpawnedItems(int items) … … 171 178 Time since last tick. 172 179 */ 173 //TODO: Replace this with a real DistanceTrigger .180 //TODO: Replace this with a real DistanceTrigger? 174 181 void PickupSpawner::tick(float dt) 175 182 { 183 //! If the PickupSpawner is active. 176 184 if (this->isActive()) 177 185 { 178 //! Triggers as soon as a Pawn is in the specified distance.186 //! Iterate trough all Pawns. 179 187 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 180 188 { 181 189 Vector3 distance = it->getWorldPosition() - this->getWorldPosition(); 182 if (distance.length() < this->triggerDistance_) 190 //! If a Pawn, that fits the target-range of the item spawned by this Pickup, is in trigger-distance. 191 if (distance.length() < this->triggerDistance_ && this->pickup_->isTarget(*it)) 192 { 183 193 this->trigger(*it); 194 } 184 195 } 185 196 186 197 //! Animation. 187 this->yaw(Radian(rotationSpeed_s*dt));188 this->tickSum_ += bounceSpeed_s*dt;189 this->translate(Vector3(0,bounceDistance_s*dt*sin(this->tickSum_),0));190 if (this->tickSum_ > 2*Ogre::Math::PI)191 this->tickSum_ -= 2*Ogre::Math::PI;198 // this->yaw(Radian(rotationSpeed_s*dt)); 199 // this->tickSum_ += bounceSpeed_s*dt; 200 // this->translate(Vector3(0,bounceDistance_s*dt*sin(this->tickSum_),0)); 201 // if (this->tickSum_ > 2*Ogre::Math::PI) 202 // this->tickSum_ -= 2*Ogre::Math::PI; 192 203 } 193 204 } … … 205 216 void PickupSpawner::trigger(Pawn* pawn) 206 217 { 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. 218 //TODO: If private, isActive doesn't need to be tested anymore. 219 if (this->isActive()) //!< Checks whether PickupItem is active. 220 { 221 Pickupable* pickup = this->getPickup(); 222 if (pickup != NULL) //!< If everything went ok, and pickup is not NULL. 211 223 { 212 item->setPickupIdentifier(this->itemTemplateName_); //TODO: Needed? 213 item->addTemplate(this->itemTemplate_); //TODO: Does what? 214 215 if(item->pickedUp(pawn)) 216 { 217 COUT(3) << this->itemTemplateName_ << " got picked up." << std::endl; 218 219 220 if(this->spawnsRemaining_ != INF) 221 { 222 this->spawnsRemaining_--; 223 } 224 225 if (this->spawnsRemaining_ != 0 && this->respawnTime_ > 0.0f) 226 { 227 this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this))); 228 229 this->setActive(false); 230 this->fireEvent(); 231 } 224 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn); 225 if(carrier == NULL) 226 { 227 COUT(1) << "This is bad. Pawn isn't PickupCarrier." << std::endl; 228 return; 229 } 230 231 if(pickup->pickup(carrier)) 232 { 233 COUT(3) << "Pickup got picked up." << std::endl; 234 235 this->decrementSpawnsRemaining(); 232 236 } 233 237 else 234 238 { 235 item->destroy();239 pickup->destroy(); 236 240 } 237 241 } 238 242 } 239 240 if(this->spawnsRemaining_ == 0) 243 } 244 245 void PickupSpawner::decrementSpawnsRemaining(void) 246 { 247 if(this->spawnsRemaining_ != INF) 248 { 249 this->spawnsRemaining_--; 250 } 251 if(this->spawnsRemaining_ != 0 && this->respawnTime_ > 0) 252 { 253 //TODO: Nicer? 254 this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this))); 255 256 this->setActive(false); 257 this->fireEvent(); 258 } 259 else 241 260 { 242 261 COUT(3) << "PickupSpawner empty, selfdistruct initialized." << std::endl; 243 262 this->setActive(false); 244 this->destroy(); 245 } 246 } 247 248 /** 249 @brief 250 Creates a BaseItem of the type specified by the PickupSpawner.263 this->destroy(); //TODO: Implement destroy(). 264 } 265 } 266 267 /** 268 @brief 269 Creates a new Pickupable. 251 270 @return 252 The BaseItemcreated.271 The Pickupable created. 253 272 */ 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); 273 Pickupable* PickupSpawner::getPickup(void) 274 { 275 if(this->spawnsRemaining_ == 0) 276 { 277 COUT(1) << "Massive Error: PickupSpawner still alive until having spawned last item." << std::endl; 278 return NULL; 279 } 280 281 Pickupable* pickup = this->pickup_->clone(); 282 return pickup; 258 283 } 259 284 -
code/branches/pickup2/src/modules/pickup/PickupSpawner.h
r5953 r6405 35 35 #define _PickupSpawner_H__ 36 36 37 #include " OrxonoxPrereqs.h"37 #include "pickup/PickupPrereqs.h" 38 38 39 39 #include <string> … … 41 41 #include "tools/interfaces/Tickable.h" 42 42 #include "worldentities/StaticEntity.h" 43 #include "interfaces/Pickupable.h" 43 44 44 45 namespace orxonox … … 51 52 { 52 53 public: 53 //TODO: Add limit of items spawned here. Also possibility to spawn collections?54 //TODO: Add limit of items spawned here. 54 55 PickupSpawner(BaseObject* creator); 55 PickupSpawner(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems);56 PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems); 56 57 virtual ~PickupSpawner(); 57 58 … … 59 60 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupSpawner through XML. 60 61 virtual void tick(float dt); 61 62 void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough.63 void respawnTimerCallback(); //!< Method called when the timer runs out.64 65 /**66 @brief Get the template name for the item to spawn.67 @return Returns the name of the template of the item to spawn.68 */69 inline const std::string& getItemTemplateName() const70 { return this->itemTemplateName_; }71 void setItemTemplateName(const std::string& name); //!< Set the template name of the item to spawn.72 73 /**74 @brief Get the template for the item to spawn.75 @return Returns the template of the item to spawn.76 */77 inline Template* getItemTemplate() const78 { return this->itemTemplate_; }79 62 80 63 /** … … 110 93 111 94 protected: 112 virtual BaseItem* getItem(void); 95 virtual Pickupable* getPickup(void); 96 97 void addPickupable(Pickupable* pickup); 98 Pickupable* getPickupable(void); 99 100 void decrementSpawnsRemaining(void); 113 101 114 102 private: 115 103 void initialize(void); 104 105 void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough. 106 void respawnTimerCallback(); //!< Method called when the timer runs out. 116 107 117 std::string itemTemplateName_; //!< Template name of the item to spawn.118 Template* itemTemplate_; //!< Template of the item to spawn.108 109 Pickupable* pickup_; 119 110 120 111 int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner. -
code/branches/pickup2/src/modules/weapons/projectiles/Projectile.cc
r5929 r6405 123 123 124 124 float dmg = this->damage_; 125 if (this->owner_) 126 dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); 125 //TODO: Remove. 126 // if (this->owner_) 127 // dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); 127 128 128 129 Pawn* victim = orxonox_cast<Pawn*>(otherObject);
Note: See TracChangeset
for help on using the changeset viewer.