Changeset 6475 for code/branches/pickup3/src/orxonox/interfaces
- Timestamp:
- Mar 5, 2010, 6:26:54 PM (15 years ago)
- Location:
- code/branches/pickup3/src/orxonox/interfaces
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
r6474 r6475 65 65 @return Returns true if the Pickupable was picked up, false if not. 66 66 */ 67 inlinebool pickup(Pickupable* pickup)67 bool pickup(Pickupable* pickup) 68 68 { 69 69 bool pickedUp = this->pickups_.insert(pickup).second; … … 78 78 @return Returns true if the Pickupable has been dropped, false if not. 79 79 */ 80 inlinebool drop(Pickupable* pickup)80 bool drop(Pickupable* pickup) 81 81 { 82 82 bool dropped = this->pickups_.erase(pickup) == 1; … … 84 84 { 85 85 pickup->dropped(); 86 //TODO: Create Spawner.87 86 } 88 87 return dropped; 89 88 } 90 89 91 inline bool isTarget(Pickupable* pickup) 90 /** 91 @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable. 92 @param pickup A pointer to the Pickupable. 93 @return Returns true if the PickupCarrier or one of its children is a target, false if not. 94 */ 95 //TODO: Use? 96 bool isTarget(const Pickupable* pickup) 92 97 { 93 if(pickup->isTarget(this)) 98 if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target. 94 99 return true; 95 const std::list<PickupCarrier*>* children = this->getChildren(); 100 101 //! Go recursively through all children to check whether they are a target. 102 std::list<PickupCarrier*>* children = this->getCarrierChildren(); 96 103 for(std::list<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++) 97 104 { … … 100 107 } 101 108 109 children->clear(); 110 delete children; 111 102 112 return false; 103 113 } 114 115 /** 116 @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable. 117 @param pickup A pounter to the Pickupable. 118 @return Returns a pointer to the PickupCarrier that is the target of the input Pickupable. 119 */ 120 PickupCarrier* getTarget(const Pickupable* pickup) 121 { 122 if(!this->isTarget(pickup)) 123 return NULL; 124 125 if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target. 126 return this; 127 128 //! Go recursively through all children to check whether they are the target. 129 std::list<PickupCarrier*>* children = this->getCarrierChildren(); 130 for(std::list<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++) 131 { 132 if(pickup->isTarget(*it)) 133 return *it; 134 } 135 136 children->clear(); 137 delete children; 138 139 return NULL; 140 } 104 141 105 protected: 106 //TODO: Good return type? 107 virtual const std::list<PickupCarrier*>* getChildren(void) = 0; 108 virtual PickupCarrier* getParent(void) = 0; 142 protected: 143 /** 144 @brief Get all direct children of this PickupSpawner. 145 This method needs to be implemented by any direct derivative class of PickupCarrier. 146 @return Returns a pointer to a list of all direct children. 147 */ 148 //TODO: Good return type? Maybe not const and destroyed in isTarget... 149 virtual std::list<PickupCarrier*>* getCarrierChildren(void) = 0; 150 /** 151 @brief Get the parent of this PickupSpawner 152 This method needs to be implemented by any direct derivative class of PickupCarrier. 153 @return Returns a pointer to the parent. 154 */ 155 virtual PickupCarrier* getCarrierParent(void) = 0; 156 /** 157 @brief Get the (absolute) position of the PickupCarrier. 158 This method needs to be implemented by any direct derivative class of PickupCarrier. 159 @return Returns the position as a Vector3. 160 */ 161 virtual const Vector3& getCarrierPosition(void) = 0; 109 162 110 163 private: 111 std::set<Pickupable*> pickups_; 164 std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier. 112 165 113 114 166 }; 115 116 167 } 117 168 -
code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc
r6474 r6475 36 36 #include "core/Identifier.h" 37 37 #include "core/CoreIncludes.h" 38 #include "pickup/PickupIdentifier.h" 38 39 #include "PickupCarrier.h" 39 40 … … 52 53 this->pickedUp_ = false; 53 54 this->carrier_ = NULL; 55 56 this->pickupIdentifier_ = new PickupIdentifier(); 54 57 } 55 58 … … 91 94 Returns true if the given PickupCarrier is a target. 92 95 */ 93 bool Pickupable::isTarget( PickupCarrier* carrier)96 bool Pickupable::isTarget(const PickupCarrier* carrier) const 94 97 { 95 98 Identifier* identifier = carrier->getIdentifier(); … … 156 159 this->setUsed(false); 157 160 this->setPickedUp(false); 161 162 bool created = this->createSpawner(this->getCarrier()->getCarrierPosition()); 163 158 164 this->setCarrier(NULL); 165 if(!created) 166 this->destroy(); 167 159 168 return true; 160 169 } -
code/branches/pickup3/src/orxonox/interfaces/Pickupable.h
r6474 r6475 39 39 #include <list> 40 40 #include "core/Super.h" 41 #include "pickup/PickupIdentifier.h"42 41 43 42 #include "core/OrxonoxClass.h" … … 83 82 bool dropped(void); //!< Sets the Pickupable to not picked up or dropped. 84 83 85 bool isTarget( PickupCarrier* carrier); //!< Get whether the given PickupCarrier is a target of this pickup.84 bool isTarget(const PickupCarrier* carrier) const; //!< Get whether the given PickupCarrier is a target of this pickup. 86 85 bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup. 87 86 … … 108 107 */ 109 108 virtual const PickupIdentifier* getPickupIdentifier(void) 110 { return &this->pickupIdentifier_; }109 { return this->pickupIdentifier_; } 111 110 112 111 virtual void destroy(void) … … 120 119 void initializeIdentifier(void) {} 121 120 121 /** 122 @brief Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 123 This method must be implemented by any class directly inheriting from Pickupable. It is most easily done by just creating a new DroppedPickup, e.g.: 124 DroppedPickup(BaseObject* creator, Pickupable* pickup, const Vector3& position, float triggerDistance); 125 @param position The position at which the PickupSpawner should be placed. 126 @return Returns true if a spawner was created, false if not. 127 */ 128 virtual bool createSpawner(const Vector3& position) = 0; 129 122 130 //TODO: Move to private and create get method in protected. 123 PickupIdentifier pickupIdentifier_; //!< The PickupIdentifier of this Pickupable.131 PickupIdentifier* pickupIdentifier_; //!< The PickupIdentifier of this Pickupable. 124 132 125 133 private:
Note: See TracChangeset
for help on using the changeset viewer.