Changeset 6421 for code/branches/pickup3/src/modules
- Timestamp:
- Dec 26, 2009, 10:06:54 AM (15 years ago)
- Location:
- code/branches/pickup3/src/modules
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup3/src/modules/pickup/DroppedItem.cc
r6419 r6421 29 29 #include "DroppedItem.h" 30 30 31 #include "util/Math.h"32 31 #include "core/CoreIncludes.h" 33 #include "core/Executor.h" 34 #include "BaseItem.h" 35 #include "graphics/Billboard.h" 32 #include "interfaces/Pickupable.h" 36 33 #include "graphics/Model.h" 37 #include "worldentities/pawns/Pawn.h"38 34 39 35 namespace orxonox 40 36 { 41 CreateFactory(DroppedItem); //TODO: This isn't needed, is it?42 43 37 /** 44 38 @brief … … 47 41 DroppedItem::DroppedItem(BaseObject* creator) : PickupSpawner(creator) 48 42 { 49 RegisterObject(DroppedItem);43 this->initialize(); 50 44 } 51 45 52 DroppedItem::DroppedItem(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems) : PickupSpawner(creator, item, triggerDistance, respawnTime, maxSpawnedItems) 46 DroppedItem::DroppedItem(BaseObject* creator, Pickupable* item, const Vector3& position, float triggerDistance) : PickupSpawner(creator, item, triggerDistance, 0, 1) 47 { 48 this->initialize(); 49 50 this->createDrop(position); 51 } 52 53 void DroppedItem::initialize(void) 53 54 { 54 55 RegisterObject(DroppedItem); 55 this->item_ = item; 56 57 this->gotPickedUp_ = false; 56 58 } 57 59 … … 62 64 DroppedItem::~DroppedItem() 63 65 { 64 66 if(this->gotPickedUp_ && this->pickup_ != NULL) 67 { 68 this->pickup_ = NULL; 69 } 65 70 } 66 71 67 BaseItem* DroppedItem::getItem(void)72 Pickupable* DroppedItem::getPickup(void) 68 73 { 69 return this->item_; 74 return this->pickup_; 75 } 76 77 void DroppedItem::createDrop(const Vector3& position) 78 { 79 this->setPosition(position); 80 81 //TODO: Make this work. 82 //const Model& model = PickupManager::getModel(item->getPickupIdentifier()); 83 //this->attach(model); 70 84 } 71 85 72 /** 73 @brief 74 75 */ 86 //TODO: Remove. 76 87 //TODO: Comment. 77 88 //Each pickup should have a XML template where the Model and Billboard, and so on, is specified. 78 /*static*/ DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive) 79 { 80 //TODO: triggerDistance? 81 float triggerDistance = 20.0; 82 DroppedItem* droppedItem = new DroppedItem(item, item, triggerDistance, 0, 1); 83 84 //TODO: Do this somehwere else? 85 Model* model = new Model(item); 86 Billboard* billboard = new Billboard(item); 89 // /*static*/ DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive) 90 // { 91 // //TODO: triggerDistance? 92 // float triggerDistance = 20.0; 93 // DroppedItem* droppedItem = new DroppedItem(item, item, triggerDistance, 0, 1); 94 // 95 // //TODO: Do this somehwere else? 96 // Model* model = new Model(item); 97 // Billboard* billboard = new Billboard(item); 98 // 99 // model->setMeshSource("sphere.mesh"); 100 // model->setScale(3.0f); 101 // 102 // billboard->setMaterial("Examples/Flare"); 103 // billboard->setColour(flareColour); 104 // billboard->setScale(0.5f); 105 // 106 // droppedItem->setPosition(position); 107 // droppedItem->attach(model); 108 // droppedItem->attach(billboard); 109 // 110 // COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl; 111 // 112 // return droppedItem; 113 // } 87 114 88 model->setMeshSource("sphere.mesh");89 model->setScale(3.0f);90 91 billboard->setMaterial("Examples/Flare");92 billboard->setColour(flareColour);93 billboard->setScale(0.5f);94 95 droppedItem->setPosition(position);96 droppedItem->attach(model);97 droppedItem->attach(billboard);98 99 COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << ',' << position.y << ',' << position.z << ")." << std::endl;100 101 return droppedItem;102 }103 104 /**105 @brief106 107 */108 115 //TODO: See one function above. 109 DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive)110 {111 Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f);112 return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive);113 }116 // DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour, float timeToLive) 117 // { 118 // Vector3 after = pawn->getPosition() + pawn->getOrientation() * Vector3(0.0f, 0.0f, 50.0f); 119 // return DroppedItem::createDefaultDrop(item, after, flareColour, timeToLive); 120 // } 114 121 } -
code/branches/pickup3/src/modules/pickup/DroppedItem.h
r6419 r6421 35 35 #define _DroppedItem_H__ 36 36 37 #include " OrxonoxPrereqs.h"37 #include "pickup/PickupPrereqs.h" 38 38 39 39 #include "PickupSpawner.h" … … 45 45 public: 46 46 DroppedItem(BaseObject* creator); 47 DroppedItem(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems);47 DroppedItem(BaseObject* creator, Pickupable* item, const Vector3& position, float triggerDistance); 48 48 virtual ~DroppedItem(); 49 49 50 static DroppedItem* createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour = ColourValue(0.5f, 1.0f, 0.3f), float timeToLive = 0);51 static DroppedItem* createDefaultDrop(BaseItem* item, Pawn* pawn, const ColourValue& flareColour = ColourValue(0.5f, 1.0f, 0.3f), float timeToLive = 0);52 53 50 protected: 54 virtual BaseItem* getItem(void);55 51 virtual Pickupable* getPickup(void); 52 56 53 private: 57 58 BaseItem* item_; //!< The dropped item. 54 void initialize(void); 55 void createDrop(const Vector3& position); 56 57 bool gotPickedUp_; 59 58 60 59 }; -
code/branches/pickup3/src/modules/pickup/PickupCollection.cc
r6420 r6421 58 58 { 59 59 //! Destroy all Pickupables constructing this PickupCollection. 60 for(std:: list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)60 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 61 61 { 62 62 delete *it; … … 89 89 return false; 90 90 91 this->pickups_. insert(pickup);91 this->pickups_.push_back(pickup); 92 92 return true; 93 93 } … … 101 101 Returns a pointer to the Pickupable at the index given by index. 102 102 */ 103 Pickupable* PickupCollection::getPickupable(unsigned int index)103 const Pickupable* PickupCollection::getPickupable(unsigned int index) 104 104 { 105 105 return this->pickups_[index]; //TODO. Does this work? … … 112 112 113 113 //! Change used for all Pickupables this PickupCollection consists of. 114 for(std:: list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)114 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 115 115 { 116 116 (*it)->changedUsed(); … … 132 132 bool success = true; 133 133 //! Set all Pickupables to used. 134 for(std:: list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)134 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 135 135 { 136 136 if(!(*it)->use()) … … 158 158 bool success = true; 159 159 //! Set all Pickupables to unused. 160 for(std:: list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)160 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 161 161 { 162 162 if(!(*it)->unuse()) … … 187 187 return false; 188 188 } 189 for(std:: list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)189 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 190 190 { 191 191 (*it)->setOwner(carrier); … … 219 219 220 220 PickupCollection* newCollection = dynamic_cast<PickupCollection*>(newObject); 221 for(std:: list<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)221 for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) 222 222 { 223 223 Pickupable* newPickup = (*it)->clone(); -
code/branches/pickup3/src/modules/pickup/PickupCollection.h
r6420 r6421 69 69 70 70 bool addPickupable(Pickupable* pickup); 71 Pickupable* getPickupable(unsigned int index);71 const Pickupable* getPickupable(unsigned int index); 72 72 73 73 private: 74 74 75 std:: list<Pickupable*> pickups_;75 std::vector<Pickupable*> pickups_; 76 76 77 77 }; -
code/branches/pickup3/src/modules/pickup/PickupPrereqs.h
r6420 r6421 66 66 { 67 67 68 class DroppedItem; 68 69 class PickupCollection; 69 70 class PickupSpawner; -
code/branches/pickup3/src/modules/pickup/PickupSpawner.cc
r6419 r6421 53 53 /** 54 54 @brief 55 Constructor. Registers thePickupSpawner.55 Constructor. Creates a blank PickupSpawner. 56 56 @param creator 57 57 Pointer to the object which created this item. … … 62 62 } 63 63 64 /** 65 @brief 66 Constructor, Creates a fully functional PickupSpawner. 67 @param creator 68 The creator of this PickupSpawner. 69 @param pickup 70 The Pickupable to be spawned by this PickupSpawner. 71 @param triggerDistance 72 The distance at which the PickupSpawner will trigger. 73 @param respawnTime 74 The minimum time between two spawns. 75 @param maySpawnedItems 76 The maximum number of items spawned by this PickupSpawner. 77 */ 64 78 PickupSpawner::PickupSpawner(BaseObject* creator, Pickupable* pickup, float triggerDistance, float respawnTime, int maxSpawnedItems) : StaticEntity(creator) 65 79 { … … 73 87 } 74 88 89 /** 90 @brief 91 Registers the object and sets some default values. 92 */ 75 93 void PickupSpawner::initialize(void) 76 94 { … … 92 110 PickupSpawner::~PickupSpawner() 93 111 { 94 112 if(this->pickup_ != NULL) 113 delete this->pickup_; 95 114 } 96 115 … … 107 126 SUPER(PickupSpawner, XMLPort, xmlelement, mode); 108 127 109 XMLPortObject(PickupSpawner, Pickupable, "pickup", addPickupable, getPickupable, xmlelement, mode);128 XMLPortObject(PickupSpawner, Pickupable, "pickup", setPickupable, getPickupable, xmlelement, mode); 110 129 111 130 XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode); … … 128 147 // & load the GUI itself too, along with some empty windows 129 148 // = even less delays 130 // GUIManager:: showGUI("PickupInventory");131 // GUIManager:: hideGUI("PickupInventory");149 // GUIManager::getInstance().showGUI("PickupInventory"); 150 // GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")"); 132 151 // PickupInventory::getSingleton(); 133 152 } 134 153 135 void PickupSpawner::addPickupable(Pickupable* pickup) 154 /** 155 @brief 156 Sets a Pickupable for the PickupSpawner to spawn. 157 @param pickup 158 The Pickupable to be set. 159 */ 160 void PickupSpawner::setPickupable(Pickupable* pickup) 136 161 { 137 162 if(this->pickup_ != NULL) … … 149 174 } 150 175 151 Pickupable* PickupSpawner::getPickupable(void) 176 /** 177 @brief 178 Get the Pickupable that is spawned by this PickupSpawner. 179 @return 180 Returns the Pickupable that is spawned by this PickupSpawner. 181 */ 182 const Pickupable* PickupSpawner::getPickupable(void) 152 183 { 153 184 return this->pickup_; … … 166 197 // } 167 198 199 /** 200 @brief 201 Sets the maximum number of spawned items. 202 @param items 203 The maximum number of spawned items to be set. 204 */ 168 205 void PickupSpawner::setMaxSpawnedItems(int items) 169 206 { … … 243 280 } 244 281 282 /** 283 @brief 284 Decrements the number of remaining spawns. 285 Sets the PickupSpawner to inactive for the duration of the respawnTime. 286 Destroys the PickupSpawner if the number of remaining spawns has reached zero. 287 288 */ 245 289 void PickupSpawner::decrementSpawnsRemaining(void) 246 290 { … … 251 295 if(this->spawnsRemaining_ != 0 && this->respawnTime_ > 0) 252 296 { 253 //TODO: Nicer? 297 //TODO: Nicer? Does this even work? 254 298 this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this))); 255 299 -
code/branches/pickup3/src/modules/pickup/PickupSpawner.h
r6419 r6421 57 57 virtual ~PickupSpawner(); 58 58 59 virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty).59 //virtual void changedActivity(); //!< Invoked when activity has changed (set visibilty). 60 60 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupSpawner through XML. 61 61 virtual void tick(float dt); … … 87 87 { this->respawnTime_ = time; } 88 88 89 89 /** 90 @brief Get the maximum number of items that will be spawned by this PickupSpawner. 91 @return Returns the maximum number of items spawned by this PickupSpawner. 92 */ 90 93 inline int getMaxSpawnedItems(void) 91 94 { return this->maxSpawnedItems_; } … … 95 98 virtual Pickupable* getPickup(void); 96 99 97 void addPickupable(Pickupable* pickup);98 Pickupable* getPickupable(void);100 void setPickupable(Pickupable* pickup); 101 const Pickupable* getPickupable(void); 99 102 100 103 void decrementSpawnsRemaining(void); 104 105 Pickupable* pickup_; //!< The pickup to be spawned. 101 106 102 107 private: … … 105 110 void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough. 106 111 void respawnTimerCallback(); //!< Method called when the timer runs out. 107 108 109 Pickupable* pickup_;110 112 111 113 int maxSpawnedItems_; //!< Maximum number of items spawned by this PickupSpawner. -
code/branches/pickup3/src/modules/weapons/projectiles/Rocket.cc
r6417 r6421 201 201 202 202 float dmg = this->damage_; 203 if (this->owner_) 204 dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); 203 //TODO: This souldn't be necessary here. 204 //if (this->owner_) 205 // dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); 205 206 206 207 Pawn* victim = orxonox_cast<Pawn*>(otherObject);
Note: See TracChangeset
for help on using the changeset viewer.