Changeset 6466 for code/branches/pickup3/src/orxonox
- Timestamp:
- Mar 4, 2010, 11:56:26 AM (15 years ago)
- Location:
- code/branches/pickup3/src/orxonox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup3/src/orxonox/CMakeLists.txt
r6419 r6466 47 47 ADD_SUBDIRECTORY(items) 48 48 ADD_SUBDIRECTORY(overlays) 49 ADD_SUBDIRECTORY(pickup) 49 50 ADD_SUBDIRECTORY(sound) 50 51 ADD_SUBDIRECTORY(weaponsystem) -
code/branches/pickup3/src/orxonox/OrxonoxPrereqs.h
r6419 r6466 135 135 class OrxonoxOverlay; 136 136 class OverlayGroup; 137 138 // pickup 139 class PickupIdentifier; 137 140 138 141 //sound -
code/branches/pickup3/src/orxonox/interfaces/CMakeLists.txt
r5781 r6466 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 InterfaceCompilation.cc 3 Pickupable.cc 3 4 RadarViewable.cc 4 5 ) -
code/branches/pickup3/src/orxonox/interfaces/InterfaceCompilation.cc
r6419 r6466 34 34 35 35 #include "GametypeMessageListener.h" 36 #include "Pickupable.h"37 36 #include "PickupCarrier.h" 38 37 #include "PlayerTrigger.h" … … 52 51 { 53 52 RegisterRootObject(GametypeMessageListener); 54 }55 56 //----------------------------57 // Pickupable58 //----------------------------59 Pickupable::Pickupable()60 {61 RegisterRootObject(Pickupable);62 63 this->used_ = false;64 this->owner_ = NULL;65 53 } 66 54 -
code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h
r6421 r6466 37 37 #include "OrxonoxPrereqs.h" 38 38 #include "core/OrxonoxClass.h" 39 #include "Pickupable.h" 39 40 40 41 #include <set> 42 #include <list> 41 43 42 44 namespace orxonox 43 45 { 44 46 45 class _OrxonoxExport PickupCarrier : public OrxonoxClass47 class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass 46 48 { 49 friend class Pickupable; 47 50 48 51 public: 49 52 PickupCarrier(); 50 53 virtual ~PickupCarrier() {} 54 55 //TODO: Secure uniqueness of each item in the set, if neccessary, check. 56 inline bool pickup(Pickupable* pickup) 57 { 58 bool pickedUp = this->pickups_.insert(pickup).second; 59 if(pickedUp) pickup->pickedUp(this); 60 return pickedUp; 61 } 62 63 inline bool drop(Pickupable* pickup) 64 { 65 bool dropped = this->pickups_.erase(pickup) == 1; 66 if(dropped) 67 { 68 pickup->dropped(); 69 //TODO: Create Spawner. 70 } 71 return dropped; 72 } 73 74 inline bool isTarget(Pickupable* pickup) 75 { 76 if(pickup->isTarget(this)) 77 return true; 78 const std::list<PickupCarrier*>* children = this->getChildren(); 79 for(std::list<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++) 80 { 81 if((*it)->isTarget(pickup)) 82 return true; 83 } 84 85 return false; 86 } 87 88 protected: 89 //TODO: Good return type? 90 virtual const std::list<PickupCarrier*>* getChildren(void) = 0; 91 virtual PickupCarrier* getParent(void) = 0; 51 92 52 93 private: 94 std::set<Pickupable*> pickups_; 53 95 54 std::set<Pickupable*> pickups_;55 96 56 97 }; -
code/branches/pickup3/src/orxonox/interfaces/Pickupable.h
r6419 r6466 38 38 #include "core/OrxonoxClass.h" 39 39 40 #include "core/Identifier.h"41 40 #include "core/Super.h" 42 #include "interfaces/PickupCarrier.h" 43 #include "worldentities/pawns/Pawn.h" 41 #include "pickup/PickupIdentifier.h" 44 42 #include <list> 45 43 46 44 namespace orxonox 47 45 { 48 49 //! Enum for the activation type.50 namespace pickupActivationType51 {52 enum Value53 {54 immediate,55 onUse,56 };57 }58 59 //! Enum for the duration tyoe.60 namespace pickupDurationType61 {62 enum Value63 {64 once,65 continuous,66 };67 }68 46 69 47 /** 70 48 @brief 71 An Interface (or more precisely an abstract Class) to model and managedifferent (all kinds of) pickups.49 An Interface (or more precisely an abstract Class) to model and represent different (all kinds of) pickups. 72 50 @author 73 51 Damian 'Mozork' Frick … … 76 54 class _OrxonoxExport Pickupable : virtual public OrxonoxClass 77 55 { 56 78 57 public: 79 58 Pickupable(); //!< Default constructor. 80 59 virtual ~Pickupable() {} //!< Default destructor. 81 82 /**83 @brief Get the activation type of the pickup.84 @return Returns the activation type of the pickup.85 */86 inline pickupActivationType::Value getActivationType(void)87 { return this->activationType_; }88 /**89 @brief Get the duration type of the pickup.90 @return Returns the duration type of the pickup.91 */92 inline pickupDurationType::Value getDurationType(void)93 { return this->durationType_; }94 60 95 61 /** 96 @brief Get the owner of the pickup.97 @return Returns a pointer to the owner of the pickup.62 @brief Get the carrier of the pickup. 63 @return Returns a pointer to the carrier of the pickup. 98 64 */ 99 inline PickupCarrier* get Owner(void)100 { return this-> owner_; }65 inline PickupCarrier* getCarrier(void) 66 { return this->carrier_; } 101 67 102 68 /** … … 107 73 { return this->used_; } 108 74 109 /** 110 @brief Get whether the given pawn is a target of this pickup. 111 @param pawn The Pawn of which it has to be determinde whether it is a target of this pickup. 112 @return Retruns true if the given Pawn is a target. 113 */ 114 //TODO: Determine whether Pawn includes all possible cases and if PickupCarrier wouldn't be better. 115 inline bool isTarget(Pawn* pawn) 116 { 117 Identifier* identifier = pawn->getIdentifier(); 118 for(std::list<Identifier*>::iterator it = this->targets_.begin(); it != this->targets_.end(); it++) 119 { 120 if(identifier->isA(*it)) 121 return true; 122 } 123 return false; 124 } 75 bool isTarget(PickupCarrier* carrier); 76 bool addTarget(PickupCarrier* target); 77 78 bool setUsed(bool used); 79 80 bool pickedUp(PickupCarrier* carrier); 81 bool dropped(void); 82 83 inline bool isPickedUp(void) 84 { return this->pickedUp_; } 85 86 Pickupable* clone(void); 87 88 virtual const PickupIdentifier* getPickupIdentifier(void) 89 { return &this->pickupIdentifier_; } 125 90 126 /** 127 @brief Should be called when the pickup has transitetd from used to unused or the other way around. 128 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changeUsed method. 129 */ 130 virtual inline void changedUsed(void) 131 { 132 if(this->isUsed()) 133 this->used_ = false; 134 else 135 this->used_ = true; 136 } 137 138 /** 139 @brief Sets the pickup to used and makes sure the effects of the pickup take effect at the right places. 140 This method needs to be implemented by any Class inheriting from Pickupable. 141 @return Returns false if for some reason the method could not take effect, e.g. because it is already in use, or some other circumstance. 142 */ 143 virtual bool use(void) = 0; 144 /** 145 @brief Sets the pickup to unused and makes sure the effects of the pickup no longer take effect. 146 This method needs to be implemented by any Class inheriting from Pickupable. 147 @return Returns false if for some reason the method could not take effect, e.g. because the pickup is already unused, or some other circumstance. 148 */ 149 virtual bool unuse(void) = 0; 91 virtual void clone(OrxonoxClass* item); 150 92 151 93 /** 152 @brief Adds the pickup to the input PickupCarrier. 153 This method needs to be implemented by any Class inheriting from Pickupable. 154 @return Returns false if, for some reason, the pickup could not be picked up. 94 @brief Should be called when the pickup has transited from used to unused or the other way around. 95 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedUsed); to their changdeUsed method. 155 96 */ 156 //TODO: Maybe better in PickupCarrier? 157 virtual bool pickup(PickupCarrier* carrier) = 0; 158 /** 159 @brief Drops the pickup. Creates a PickupSpawner at the place the Pickup has been dropped. 160 This method needs to be implemented by any Class inheriting from Pickupable. 161 @return Returns false if the pickup could not be dropped. 162 */ 163 //TODO: Probably could be done here? 164 virtual bool drop(void) = 0; 97 virtual void changedUsed(void) {} 165 98 166 99 /** 167 @brief Creates a duplicate of the pickup. 168 This method needs to e implemented by any Class inheriting from Pickupable. 169 @return Returns the clone of this pickup as a pointer to a Pickupable. 100 @brief Should be called when the pickup has transited from picked up to dropped or the other way around. 101 Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method. 170 102 */ 171 //TODO: Would be nicer if standard case was implemented here. 172 virtual Pickupable* clone(void) = 0; 103 virtual void changedCarrier(void) {} 173 104 174 /** 175 @brief Sets the owner of the pickup. 176 @param owner Sets the input PickupCarrier as the owner of the pickup. 177 */ 178 //TODO: Protected? Check for NULL and return true/false? 179 inline void setOwner(PickupCarrier* owner) 180 { this->owner_ = owner; } 105 bool setCarrier(PickupCarrier* carrier); 106 107 protected: 108 void initializeIdentifier(void) {} 109 110 PickupIdentifier pickupIdentifier_; 181 111 182 112 private: 183 184 pickupActivationType::Value activationType_; //!< The activation type of the Pickup. 185 pickupDurationType::Value durationType_; //!< The duration type of the pickup. 113 inline void setPickedUp(bool pickedUp) 114 { this->pickedUp_ = pickedUp; } 186 115 187 116 bool used_; //!< Whether the pickup is currently in use or not. 117 bool pickedUp_; //!< Whether the pickup is currently picked up or not. 188 118 189 PickupCarrier* owner_; //!< The owner of the pickup.119 PickupCarrier* carrier_; //!< The owner of the pickup. 190 120 std::list<Identifier*> targets_; //!< The possible targets of this pickup. 191 121 192 122 }; 193 123 194 SUPER_FUNCTION(10, Pickupable, changedUsed, true) 124 SUPER_FUNCTION(10, Pickupable, changedUsed, false); 125 SUPER_FUNCTION(12, Pickupable, changedCarrier, false); 195 126 } 196 127 -
code/branches/pickup3/src/orxonox/pickup/CMakeLists.txt
r6419 r6466 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 BaseItem.cc 3 EquipmentItem.cc 4 ModifierPickup.cc 5 PassiveItem.cc 6 PickupCollection.cc 7 PickupInventory.cc 8 UsableItem.cc 2 PickupIdentifier.cc 9 3 ) 10 4 11 ADD_SUBDIRECTORY(items) -
code/branches/pickup3/src/orxonox/worldentities/pawns/Pawn.h
r6419 r6466 33 33 34 34 #include <string> 35 #include "interfaces/PickupCarrier.h" 35 36 #include "interfaces/RadarViewable.h" 36 37 #include "worldentities/ControllableEntity.h" 37 //TODO: Remove.38 //#include "pickup/PickupCollection.h"39 38 40 39 namespace orxonox 41 40 { 42 class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable 41 class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable, public PickupCarrier 43 42 { 44 43 friend class WeaponSystem; … … 139 138 //TODO: Remove. 140 139 //PickupCollection pickups_; 140 virtual const std::list<PickupCarrier*>* getChildren(void) 141 { return new std::list<PickupCarrier*>(); } 142 virtual PickupCarrier* getParent(void) 143 { return NULL; } 141 144 142 145 float health_;
Note: See TracChangeset
for help on using the changeset viewer.