Changeset 5953 for code/branches/pickup2/src/orxonox/pickup/DroppedItem.cc
- 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/DroppedItem.cc
r5947 r5953 39 39 namespace orxonox 40 40 { 41 CreateFactory(DroppedItem); 41 CreateFactory(DroppedItem); //TODO: This isn't needed, is it? 42 42 43 43 /** … … 45 45 Constructor. Registers object and sets default values. 46 46 */ 47 DroppedItem::DroppedItem(BaseObject* creator) : StaticEntity(creator)47 DroppedItem::DroppedItem(BaseObject* creator) : PickupSpawner(creator) 48 48 { 49 49 RegisterObject(DroppedItem); 50 } 50 51 51 this->triggerDistance_ = 20.0f; 52 this->timeToLive_ = 0; 53 this->item_ = NULL; 52 DroppedItem::DroppedItem(BaseObject* creator, BaseItem* item, float triggerDistance, float respawnTime, int maxSpawnedItems) : PickupSpawner(creator, item, triggerDistance, respawnTime, maxSpawnedItems) 53 { 54 RegisterObject(DroppedItem); 55 this->item_ = item; 54 56 } 55 57 … … 58 60 Default destructor. 59 61 */ 60 //TODO: Destroy something?61 62 DroppedItem::~DroppedItem() 62 63 { … … 64 65 } 65 66 66 /** 67 @brief 68 Checks whether any pawn is in triggerDistance of the Item and calls this->trigger if so. 69 @param dt 70 The duration of the last time interval. 71 */ 72 //TODO: Replace this with a DistanceTrigger! 73 void DroppedItem::tick(float dt) 67 BaseItem* DroppedItem::getItem(void) 74 68 { 75 if (this->item_) 76 { 77 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) //!< Iterate through all Pawns. 78 { 79 Vector3 distance = it->getWorldPosition() - this->getWorldPosition(); 80 if (distance.length() < this->triggerDistance_) 81 this->trigger(*it); 82 } 83 } 84 } 85 86 /** 87 @brief 88 Called when the DroppedItem is triggered. Adds the item to the triggering pawn. 89 */ 90 void DroppedItem::trigger(Pawn* pawn) 91 { 92 if (this->item_->pickedUp(pawn)) //If pickup was successful. 93 { 94 COUT(3) << "DroppedItem '" << this->item_->getPickupIdentifier() << "' picked up." << std::endl; 95 this->destroy(); 96 } 97 } 98 99 /** 100 @brief 101 Creates a timer to call this->timerCallback() at expiration of timeToLive. 102 */ 103 //TODO: Better Comments. 104 void DroppedItem::createTimer() 105 { 106 if (this->timeToLive_ > 0) 107 { 108 this->timer_.setTimer(this->timeToLive_, false, createExecutor(createFunctor(&DroppedItem::timerCallback, this)), false); 109 } 110 } 111 112 /** 113 @brief 114 Destroys the item. Called by the set timer upon its expiration. 115 */ 116 //TODO: Choose better function name if this doesn't create dependency inconsistencies. e.g. this->destroy() or this->timeOut() 117 //Make certain that only one pawn has the same item, because if not, deliting the item would lead to a possible segfault. 118 //If the item is destroyed here, shouldn't it be destroyed in the destructor as well? 119 void DroppedItem::timerCallback() 120 { 121 if (this->item_) 122 { 123 COUT(3) << "Delete DroppedItem with '" << this->item_->getPickupIdentifier() << "'" << std::endl; 124 this->item_->destroy(); 125 } 126 127 this->destroy(); 69 return this->item_; 128 70 } 129 71 … … 133 75 */ 134 76 //TODO: Comment. 135 //This is for pawns dropping items they have...136 //Probably better to create a spawner with only 1 item in it.137 //Various different thigs are done here, which in my opinion should eighter be done in XML or some where else, preferably in XML.138 77 //Each pickup should have a XML template where the Model and Billboard, and so on, is specified. 139 //The position, item and timetoLive should be specified by this Classes XMLPort function.140 //These adjustments above, will very likely create inkonsistencies in the level files, possibly templates.141 78 /*static*/ DroppedItem* DroppedItem::createDefaultDrop(BaseItem* item, const Vector3& position, const ColourValue& flareColour, float timeToLive) 142 79 { 143 DroppedItem* drop = new DroppedItem(item); 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? 144 85 Model* model = new Model(item); 145 86 Billboard* billboard = new Billboard(item); … … 152 93 billboard->setScale(0.5f); 153 94 154 drop->setPosition(position); 155 drop->attach(model); 156 drop->attach(billboard); 157 158 drop->setItem(item); 159 160 drop->setTimeToLive(timeToLive); 161 drop->createTimer(); 95 droppedItem->setPosition(position); 96 droppedItem->attach(model); 97 droppedItem->attach(billboard); 162 98 163 99 COUT(3) << "Created DroppedItem for '" << item->getPickupIdentifier() << "' at (" << position.x << "," << position.y << "," << position.z << ")." << std::endl; 164 100 165 return drop ;101 return droppedItem; 166 102 } 167 103
Note: See TracChangeset
for help on using the changeset viewer.