Changeset 7127 for code/branches/presentation3/src/modules/pickup
- Timestamp:
- Jun 9, 2010, 9:32:58 PM (14 years ago)
- Location:
- code/branches/presentation3/src/modules/pickup
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/modules/pickup/DroppedPickup.cc
r6540 r7127 41 41 namespace orxonox 42 42 { 43 43 44 44 CreateFactory(DroppedPickup); 45 45 46 46 /** 47 47 @brief … … 51 51 { 52 52 RegisterObject(DroppedPickup); 53 53 54 54 } 55 55 … … 67 67 */ 68 68 DroppedPickup::DroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance) : PickupSpawner(creator, pickup, triggerDistance, 5, 1) 69 { 69 { 70 70 RegisterObject(DroppedPickup); 71 71 72 72 this->setPosition(carrier->getCarrierPosition()); 73 73 this->setActive(false); 74 74 75 75 //TODO: Do more elegantly. 76 76 this->startRespawnTimer(); -
code/branches/presentation3/src/modules/pickup/DroppedPickup.h
r6540 r7127 41 41 namespace orxonox 42 42 { 43 43 44 44 /** 45 45 @brief -
code/branches/presentation3/src/modules/pickup/Pickup.h
r7008 r7127 165 165 private: 166 166 void initialize(void); //!< Initializes the member variables. 167 167 168 168 //TODO: Problems, when there are more Timers needed? Solutions? 169 169 Timer durationTimer_; //!< Timer at the disposal of each Class implementing Pickup. -
code/branches/presentation3/src/modules/pickup/PickupCollection.cc
r7094 r7127 42 42 namespace orxonox 43 43 { 44 44 45 45 CreateFactory(PickupCollection); 46 46 … … 52 52 { 53 53 RegisterObject(PickupCollection); 54 54 55 55 this->pickupCollectionIdentifier_ = new PickupCollectionIdentifier(this); 56 56 } 57 57 58 58 /** 59 59 @brief … … 69 69 } 70 70 } 71 71 72 72 /** 73 73 @brief … … 77 77 { 78 78 SUPER(PickupCollection, XMLPort, xmlelement, mode); 79 79 80 80 XMLPortObject(PickupCollection, Pickupable, "pickupables", addPickupable, getPickupable, xmlelement, mode); 81 81 82 82 this->initializeIdentifier(); 83 83 } 84 84 85 85 /** 86 86 @brief … … 94 94 } 95 95 } 96 96 97 97 /** 98 98 @brief … … 103 103 { 104 104 SUPER(PickupCollection, changedUsed); 105 105 106 106 //! Change used for all Pickupables this PickupCollection consists of. 107 107 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) … … 110 110 } 111 111 } 112 112 113 113 /** 114 114 @brief … … 119 119 { 120 120 SUPER(PickupCollection, changedCarrier); 121 121 122 122 //! Change the PickupCarrier for all Pickupables this PickupCollection consists of. 123 123 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) … … 126 126 } 127 127 } 128 128 129 129 /** 130 130 @brief … … 135 135 { 136 136 SUPER(PickupCollection, changedPickedUp); 137 137 138 138 //! Change the pickedUp status for all Pickupables this PickupCollection consists of. 139 139 for(std::vector<WeakPtr<Pickupable> >::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) … … 142 142 } 143 143 } 144 144 145 145 /** 146 146 @brief … … 154 154 if(item == NULL) 155 155 item = new PickupCollection(this); 156 156 157 157 SUPER(PickupCollection, clone, item); 158 158 159 159 PickupCollection* pickup = dynamic_cast<PickupCollection*>(item); 160 160 //! Clone all Pickupables this PickupCollection consist of. … … 167 167 pickup->initializeIdentifier(); 168 168 } 169 169 170 170 /** 171 171 @brief … … 183 183 return false; 184 184 } 185 185 186 186 return true; 187 187 } 188 188 189 189 /** 190 190 @brief … … 198 198 return this->pickupCollectionIdentifier_; 199 199 } 200 200 201 201 /** 202 202 @brief … … 211 211 if(pickup == NULL) 212 212 return false; 213 213 214 214 WeakPtr<Pickupable> ptr = pickup; //!< Create a weak pointer to be able to test in the constructor if the Pointer is still valid. 215 215 this->pickups_.push_back(ptr); 216 216 return true; 217 217 } 218 218 219 219 /** 220 220 @brief … … 229 229 return this->pickups_[index].get(); 230 230 } 231 231 232 232 /** 233 233 @brief … … 245 245 return true; 246 246 } 247 247 248 248 } -
code/branches/presentation3/src/modules/pickup/PickupCollection.h
r6731 r7127 53 53 class _PickupExport PickupCollection : public Pickupable, public BaseObject 54 54 { 55 55 56 56 public: 57 57 58 58 PickupCollection(BaseObject* creator); //!< Default Constructor. 59 59 virtual ~PickupCollection(); //!< Destructor. 60 60 61 61 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates an instance of this Class through XML. 62 62 … … 64 64 virtual void changedCarrier(void); //!< Is called when the pickup has changed its PickupCarrier. 65 65 virtual void changedPickedUp(void); //!< Is called when the pickup has transited from picked up to dropped or the other way around. 66 66 67 67 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 68 68 69 69 virtual bool isTarget(PickupCarrier* carrier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this PickupCollection. 70 70 71 71 virtual const PickupIdentifier* getPickupIdentifier(void); //!< Get the PickupIdentifier of this PickupCollection. 72 72 73 73 bool addPickupable(Pickupable* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection. 74 74 const Pickupable* getPickupable(unsigned int index); //!< Get the Pickupable at the given index. 75 75 76 76 protected: 77 77 void initializeIdentifier(void); //!< Initializes the PickupIdentifier for this pickup. 78 78 79 79 virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 80 80 81 81 PickupCollectionIdentifier* pickupCollectionIdentifier_; //!< The PickupCollectionIdentifier of this PickupCollection. Is used to distinguish different PickupCollections amongst themselves. 82 82 83 83 private: 84 84 85 85 std::vector<WeakPtr<Pickupable> > pickups_; //!< The list of the pointers of all the Pickupables this PickupCollection consists of. They are weak pointers to facilitate testing, whether the pointers are still valid. 86 86 87 87 }; 88 88 89 89 } 90 90 -
code/branches/presentation3/src/modules/pickup/PickupCollectionIdentifier.cc
r6538 r7127 38 38 namespace orxonox 39 39 { 40 40 41 41 /** 42 42 @brief … … 47 47 RegisterObject(PickupCollectionIdentifier); 48 48 } 49 49 50 50 /** 51 51 @brief … … 54 54 PickupCollectionIdentifier::~PickupCollectionIdentifier() 55 55 { 56 56 57 57 } 58 58 … … 70 70 PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier); 71 71 const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp); 72 72 73 73 //! If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared. 74 74 if(collectionIdentifier == NULL) … … 76 76 return this->PickupIdentifier::compare(identifier); 77 77 } 78 78 79 79 //! If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller. 80 80 if(this->identifiers_.size() != collectionIdentifier->identifiers_.size()) 81 81 return this->identifiers_.size()-collectionIdentifier->identifiers_.size(); 82 82 83 83 //! Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller. 84 84 std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin(); 85 85 for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++) 86 86 { 87 87 88 88 if((*it)->compare(*it2) < 0) 89 89 return -1; … … 91 91 return 1; 92 92 } 93 93 94 94 //! Means they are equal. 95 95 return 0; 96 96 } 97 97 98 98 /** 99 99 @brief … … 106 106 this->identifiers_.insert(identifier); 107 107 } 108 108 109 109 } 110 110 -
code/branches/presentation3/src/modules/pickup/PickupCollectionIdentifier.h
r6538 r7127 54 54 class _PickupExport PickupCollectionIdentifier : public PickupIdentifier 55 55 { 56 56 57 57 public: 58 58 PickupCollectionIdentifier(Pickupable* pickup); //!< Constructor. 59 59 ~PickupCollectionIdentifier(); //!< Destructor. 60 60 61 61 virtual int compare(const PickupIdentifier* identifier) const; //!< Compares a PickupCollectionIdentifier with a PickupIdentifier. 62 62 63 63 void addPickup(const PickupIdentifier* identifier); //!< Add a Pickupable to the PickupCollectionIdentifier. 64 64 65 65 private: 66 66 std::set<const PickupIdentifier*, PickupIdentifierCompare> identifiers_; //!< The set of PickupIdentifiers of the Pickupables the PickupCollection with this PickupCollectionIdentifier consists of, ordered by the rule set by PickupIdentifierCompare. 67 67 68 68 }; 69 69 70 70 } 71 71 -
code/branches/presentation3/src/modules/pickup/PickupManager.cc
r7110 r7127 51 51 // Register tolua_open function when loading the library 52 52 DeclareToluaInterface(Pickup); 53 53 54 54 ManageScopedSingleton(PickupManager, ScopeID::Root, false); 55 55 56 56 /*static*/ const std::string PickupManager::guiName_s = "PickupInventory"; 57 57 58 58 /** 59 59 @brief … … 69 69 } 70 70 this->defaultRepresentation_ = new PickupRepresentation(); 71 71 72 72 COUT(3) << "PickupManager created." << std::endl; 73 73 } 74 74 75 75 /** 76 76 @brief … … 82 82 if(this->defaultRepresentation_ != NULL) 83 83 this->defaultRepresentation_->destroy(); 84 84 85 85 this->representations_.clear(); 86 86 87 87 COUT(3) << "PickupManager destroyed." << std::endl; 88 88 } 89 89 90 90 /** 91 91 @brief … … 100 100 */ 101 101 bool PickupManager::registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation) 102 { 102 { 103 103 if(identifier == NULL || representation == NULL || this->representations_.find(identifier) != this->representations_.end()) //!< If the Pickupable already has a Representation registered. 104 104 return false; 105 105 106 106 this->representations_[identifier] = representation; 107 107 108 108 COUT(4) << "PickupRepresentation " << representation << " registered with the PickupManager." << std::endl; 109 109 return true; 110 110 } 111 111 112 112 /** 113 113 @brief … … 121 121 */ 122 122 bool PickupManager::unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation) 123 { 123 { 124 124 if(identifier == NULL || representation == NULL) 125 125 return false; 126 126 127 127 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier); 128 128 if(it == this->representations_.end()) //!< If the Pickupable is not registered in the first place. 129 129 return false; 130 130 131 131 this->representations_.erase(it); 132 132 133 133 COUT(4) << "PickupRepresentation " << representation << " unregistered with the PickupManager." << std::endl; 134 134 return true; 135 135 } 136 136 137 137 /** 138 138 @brief … … 151 151 return this->defaultRepresentation_; 152 152 } 153 153 154 154 return it->second; 155 155 } … … 158 158 { 159 159 this->pickupsList_.clear(); 160 160 161 161 PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s); 162 162 PickupCarrier* carrier = NULL; … … 221 221 if(pickup == NULL || it == this->pickupsList_.end() || it->second.get() == NULL) 222 222 return; 223 223 224 224 if(!pickup->isPickedUp()) 225 225 return; … … 229 229 pickup->setUsed(use); 230 230 } 231 231 232 232 } -
code/branches/presentation3/src/modules/pickup/PickupManager.h
r6996 r7127 60 60 { // tolua_export 61 61 friend class Singleton<PickupManager>; 62 62 63 63 public: 64 64 PickupManager(); 65 65 virtual ~PickupManager(); 66 66 67 67 static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export 68 68 69 69 bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. 70 70 bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents. 71 71 PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier. 72 72 73 73 // tolua_begin 74 74 int getNumPickups(void); … … 80 80 bool isValidPickup(orxonox::Pickupable* pickup) { std::map<Pickupable*, WeakPtr<Pickupable> >::iterator it = this->pickupsList_.find(pickup); if(it == this->pickupsList_.end()) return false; return it->second.get() != NULL; } 81 81 // tolua_end 82 82 83 83 private: 84 84 static PickupManager* singletonPtr_s; 85 85 static const std::string guiName_s; 86 86 87 87 PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation. 88 88 std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations. … … 92 92 93 93 std::vector<PickupCarrier*>* getAllCarriers(PickupCarrier* carrier); 94 94 95 95 }; // tolua_export 96 96 97 97 } // tolua_export 98 98 -
code/branches/presentation3/src/modules/pickup/PickupPrereqs.h
r7034 r7127 65 65 namespace orxonox 66 66 { 67 67 68 68 class DroppedPickup; 69 69 class Pickup; -
code/branches/presentation3/src/modules/pickup/PickupRepresentation.cc
r6725 r7127 41 41 namespace orxonox 42 42 { 43 43 44 44 CreateFactory(PickupRepresentation); 45 45 46 46 /** 47 47 @brief … … 52 52 { 53 53 RegisterObject(PickupRepresentation); 54 54 55 55 this->initialize(); 56 56 } 57 57 58 58 /** 59 59 @brief … … 63 63 { 64 64 RegisterObject(PickupRepresentation); 65 65 66 66 this->initialize(); 67 67 } 68 68 69 69 /** 70 70 @brief … … 75 75 if(this->spawnerRepresentation_ != NULL) 76 76 this->spawnerRepresentation_->destroy(); 77 77 78 78 if(this->pickup_ != NULL) 79 79 PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this); 80 80 } 81 81 82 82 /** 83 83 @brief … … 91 91 this->inventoryRepresentation_ = "Default"; 92 92 } 93 93 94 94 /** 95 95 @brief … … 99 99 { 100 100 SUPER(PickupRepresentation, XMLPort, xmlelement, mode); 101 101 102 102 XMLPortParam(PickupRepresentation, "pickupName", setPickupName, getPickupName, xmlelement, mode); 103 103 XMLPortParam(PickupRepresentation, "pickupDescription", setPickupDescription, getPickupDescription, xmlelement, mode); … … 106 106 XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode); 107 107 XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode); 108 108 109 109 PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents. 110 110 111 111 if(this->spawnerRepresentation_ != NULL) 112 112 this->spawnerRepresentation_->setVisible(false); 113 113 114 114 COUT(4) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << std::endl; 115 115 } 116 116 117 117 /** 118 118 @brief … … 136 136 this->addTemplate(this->spawnerTemplate_); 137 137 } 138 138 139 139 StaticEntity* representation = this->spawnerRepresentation_; 140 140 representation->setVisible(true); 141 141 142 142 this->addTemplate(this->spawnerTemplate_); 143 143 this->spawnerRepresentation_->setVisible(false); 144 144 145 145 return representation; 146 146 } 147 147 148 148 /** 149 149 @brief … … 171 171 return representation; 172 172 } 173 173 174 174 } -
code/branches/presentation3/src/modules/pickup/PickupRepresentation.h
r6711 r7127 56 56 : public BaseObject 57 57 { // tolua_export 58 58 59 59 public: 60 60 PickupRepresentation(); //!< Constructor 61 61 PickupRepresentation(BaseObject* creator); //!< Default constructor. 62 62 virtual ~PickupRepresentation(); //!< Destructor. 63 63 64 64 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 65 65 66 66 /** 67 67 @brief Set the name of the Pickupable represented by this PickupRepresentation. … … 102 102 inline void setPickup(Pickupable* pickup) 103 103 { this->pickup_ = pickup; } 104 104 105 105 /** 106 106 @brief Get the name of the Pickupable represented by this PickupRepresentation. … … 138 138 inline const Pickupable* getPickup(unsigned int index) 139 139 { if(index == 0) return this->pickup_; return NULL; } 140 140 141 141 StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner. 142 142 143 143 private: 144 144 void initialize(void); //!< Initializes the member variables of this PickupRepresentation. 145 145 StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner); //!< Get the default spawnerRepresentation for a specific PickupSpawner. 146 146 147 147 std::string name_; //!< The name of the Pickupable represented by this PickupRepresentation. 148 148 std::string description_; //!< The description of the Pickupable represented by this PickupRepresentation. … … 150 150 StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation. 151 151 std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. TODO: Exact format and placement of image? 152 152 153 153 Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation. 154 154 155 155 }; // tolua_export 156 156 157 157 } // tolua_export 158 158 159 159 #endif // _PickupRepresentation_H__ -
code/branches/presentation3/src/modules/pickup/PickupSpawner.cc
r7086 r7127 55 55 { 56 56 RegisterObject(PickupSpawner); 57 57 58 58 this->initialize(); 59 59 } … … 76 76 { 77 77 RegisterObject(PickupSpawner); 78 78 79 79 this->initialize(); 80 80 81 81 this->pickup_ = pickup; 82 82 … … 84 84 this->respawnTime_ = respawnTime; 85 85 this->setMaxSpawnedItems(maxSpawnedItems); 86 86 87 87 if(this->pickup_ == NULL) 88 88 { … … 132 132 133 133 XMLPortObject(PickupSpawner, Pickupable, "pickup", setPickupable, getPickupable, xmlelement, mode); 134 134 135 135 XMLPortParam(PickupSpawner, "triggerDistance", setTriggerDistance, getTriggerDistance, xmlelement, mode); 136 136 XMLPortParam(PickupSpawner, "respawnTime", setRespawnTime, getRespawnTime, xmlelement, mode); 137 137 XMLPortParam(PickupSpawner, "maxSpawnedItems", setMaxSpawnedItems, getMaxSpawnedItems, xmlelement, mode); 138 138 139 139 if(this->pickup_ == NULL) 140 140 { … … 150 150 } 151 151 } 152 152 153 153 /** 154 154 @brief … … 161 161 this->setVisible(this->isActive()); 162 162 } 163 163 164 164 /** 165 165 @brief … … 172 172 { 173 173 SUPER(PickupSpawner, tick, dt); 174 174 175 175 //! If the PickupSpawner is active. 176 176 if (this->isActive()) 177 177 { 178 178 SmartPtr<PickupSpawner> temp = this; // create a smart pointer to keep the PickupSpawner alive until we iterated through all Pawns (in case a Pawn takes the last pickup) 179 179 180 180 //! Iterate trough all Pawns. 181 181 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) … … 191 191 } 192 192 } 193 193 194 194 /** 195 195 @brief … … 203 203 this->spawnsRemaining_ = items; 204 204 } 205 205 206 206 /** 207 207 @brief … … 230 230 } 231 231 } 232 232 233 233 /** 234 234 @brief … … 239 239 this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this))); 240 240 } 241 241 242 242 /** 243 243 @brief … … 258 258 return; 259 259 } 260 260 261 261 this->pickup_ = pickup; 262 262 } 263 263 264 264 /** 265 265 @brief … … 285 285 { 286 286 COUT(4) << "PickupSpawner (&" << this << ") triggered and active." << std::endl; 287 287 288 288 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(pawn); 289 289 if(carrier == NULL) … … 292 292 return; 293 293 } 294 294 295 295 if(!carrier->isTarget(this->pickup_)) 296 296 { … … 298 298 return; 299 299 } 300 300 301 301 PickupCarrier* target = carrier->getTarget(this->pickup_); 302 302 Pickupable* pickup = this->getPickup(); 303 303 304 304 if(target != NULL && pickup != NULL) 305 305 { … … 317 317 if(target == NULL) 318 318 COUT(1) << "PickupSpawner (&" << this << "): Pickupable has no target." << std::endl; 319 319 320 320 if(pickup == NULL) 321 321 { … … 335 335 @return 336 336 The Pickupable created. 337 */ 337 */ 338 338 Pickupable* PickupSpawner::getPickup(void) 339 339 { … … 343 343 return NULL; 344 344 } 345 345 346 346 Pickupable* pickup = this->pickup_->clone(); 347 347 return pickup; -
code/branches/presentation3/src/modules/pickup/PickupSpawner.h
r6540 r7127 101 101 protected: 102 102 void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns. 103 103 104 104 void startRespawnTimer(void); 105 105 106 106 virtual Pickupable* getPickup(void); //!< Creates a new Pickupable. 107 107 108 108 void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn. 109 109 const Pickupable* getPickupable(void); //!< Get the Pickupable that is spawned by this PickupSpawner. 110 110 111 111 Pickupable* pickup_; //!< The pickup to be spawned. 112 112 113 113 private: 114 114 void initialize(void); 115 115 116 116 void trigger(Pawn* pawn); //!< Method called when a Pawn is close enough. 117 117 void respawnTimerCallback(); //!< Method called when the timer runs out. -
code/branches/presentation3/src/modules/pickup/items/DronePickup.cc
r7034 r7127 49 49 50 50 CreateFactory(DronePickup); 51 51 52 52 /** 53 53 @brief … … 57 57 { 58 58 RegisterObject(DronePickup); 59 59 60 60 this->initialize(); 61 61 } 62 62 63 63 /** 64 64 @brief … … 67 67 DronePickup::~DronePickup() 68 68 { 69 69 70 70 } 71 71 72 72 /** 73 @brief 73 @brief 74 74 Initializes the member variables. 75 75 */ … … 80 80 this->droneTemplate_ = ""; 81 81 } 82 82 83 83 /** 84 84 @brief … … 91 91 this->pickupIdentifier_->addParameter(type, val); 92 92 } 93 93 94 94 /** 95 95 @brief … … 100 100 SUPER(DronePickup, XMLPort, xmlelement, mode); 101 101 XMLPortParam(DronePickup, "droneTemplate", setDroneTemplate, getDroneTemplate, xmlelement, mode); 102 102 103 103 this->initializeIdentifier(); 104 104 } 105 105 106 106 void DronePickup::setDroneTemplate(std::string templatename){ 107 107 droneTemplate_ = templatename; 108 } 109 108 } 109 110 110 const std::string& DronePickup::getDroneTemplate() const 111 111 { … … 120 120 { 121 121 SUPER(DronePickup, changedUsed); 122 122 123 123 //! If the pickup is not picked up nothing must be done. 124 124 if(!this->isPickedUp()) 125 125 return; 126 126 127 127 //! If the pickup has transited to used. 128 128 if(this->isUsed()) … … 132 132 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 133 133 this->destroy(); 134 134 135 135 //Attach to pawn 136 136 Drone* drone = new Drone(pawn->getCreator()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something) … … 143 143 droneController->setOwner(pawn); 144 144 } 145 145 146 146 Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30); 147 147 drone->setPosition(spawnPosition); 148 148 149 149 //! The pickup has been used up. 150 150 this->setUsed(false); … … 159 159 } 160 160 } 161 161 162 162 /** 163 163 @brief … … 170 170 PickupCarrier* carrier = this->getCarrier(); 171 171 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 172 172 173 173 if(pawn == NULL) 174 174 { 175 175 COUT(1) << "Invalid PickupCarrier in DronePickup." << std::endl; 176 176 } 177 177 178 178 return pawn; 179 179 } 180 180 181 181 /** 182 182 @brief … … 189 189 if(item == NULL) 190 190 item = new DronePickup(this); 191 191 192 192 SUPER(DronePickup, clone, item); 193 193 194 194 DronePickup* pickup = dynamic_cast<DronePickup*>(item); 195 195 pickup->setDroneTemplate(this->getDroneTemplate()); 196 196 197 197 pickup->initializeIdentifier(); 198 198 } -
code/branches/presentation3/src/modules/pickup/items/DronePickup.h
r7034 r7127 47 47 48 48 namespace orxonox { 49 49 50 50 51 51 class _PickupExport DronePickup : public Pickup, public Tickable 52 52 { 53 53 public: 54 54 55 55 DronePickup(BaseObject* creator); //!< Constructor. 56 56 virtual ~DronePickup(); //!< Destructor. 57 57 58 58 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a DronePickup object through XML. 59 59 60 60 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 61 61 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 62 62 63 63 void setDroneTemplate(std::string templatename); 64 const std::string& getDroneTemplate() const; 65 64 const std::string& getDroneTemplate() const; 65 66 66 protected: 67 67 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 68 68 69 69 private: 70 70 void initialize(void); //!< Initializes the member variables. 71 71 std::string droneTemplate_; 72 72 Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 73 74 73 75 74 75 76 76 }; 77 77 } -
code/branches/presentation3/src/modules/pickup/items/HealthPickup.cc
r7008 r7127 45 45 namespace orxonox 46 46 { 47 47 48 48 /*static*/ const std::string HealthPickup::healthTypeLimited_s = "limited"; 49 49 /*static*/ const std::string HealthPickup::healthTypeTemporary_s = "temporary"; 50 50 /*static*/ const std::string HealthPickup::healthTypePermanent_s = "permanent"; 51 51 52 52 CreateFactory(HealthPickup); 53 53 54 54 /** 55 55 @brief … … 59 59 { 60 60 RegisterObject(HealthPickup); 61 61 62 62 this->initialize(); 63 63 } 64 64 65 65 /** 66 66 @brief … … 69 69 HealthPickup::~HealthPickup() 70 70 { 71 72 } 73 74 /** 75 @brief 71 72 } 73 74 /** 75 @brief 76 76 Initializes the member variables. 77 77 */ 78 78 void HealthPickup::initialize(void) 79 { 79 { 80 80 this->health_ = 0; 81 81 this->healthRate_ = 0; … … 83 83 this->maxHealthSave_ = 0; 84 84 this->maxHealthOverwrite_ = 0; 85 85 86 86 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 87 87 } 88 88 89 89 /** 90 90 @brief … … 98 98 std::string val1 = stream.str(); 99 99 this->pickupIdentifier_->addParameter(type1, val1); 100 100 101 101 std::string val2 = this->getHealthType(); 102 102 std::string type2 = "healthType"; 103 103 this->pickupIdentifier_->addParameter(type2, val2); 104 104 105 105 stream.clear(); 106 106 stream << this->getHealthRate(); … … 109 109 this->pickupIdentifier_->addParameter(type3, val3); 110 110 } 111 111 112 112 /** 113 113 @brief … … 117 117 { 118 118 SUPER(HealthPickup, XMLPort, xmlelement, mode); 119 119 120 120 XMLPortParam(HealthPickup, "health", setHealth, getHealth, xmlelement, mode); 121 121 XMLPortParam(HealthPickup, "healthRate", setHealthRate, getHealthRate, xmlelement, mode); 122 122 XMLPortParam(HealthPickup, "healthType", setHealthType, getHealthType, xmlelement, mode); 123 123 124 124 if(!this->isContinuous()) 125 125 this->healthRate_ = 0.0; 126 126 127 127 this->initializeIdentifier(); 128 128 } 129 129 130 130 /** 131 131 @brief … … 138 138 { 139 139 SUPER(HealthPickup, tick, dt); 140 140 141 141 if(this->isContinuous() && this->isUsed()) 142 142 { … … 144 144 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 145 145 this->destroy(); 146 146 147 147 //! Calculate the health that is added this tick. 148 148 float health = dt*this->getHealthRate(); … … 152 152 float fullHealth = pawn->getHealth() + health; 153 153 this->setHealth(this->getHealth()-health); 154 154 155 155 switch(this->getHealthTypeDirect()) 156 156 { … … 173 173 COUT(1) << "Invalid healthType in HealthPickup." << std::endl; 174 174 } 175 175 176 176 //! If all health has been transfered. 177 177 if(this->getHealth() == 0) … … 181 181 } 182 182 } 183 183 184 184 /** 185 185 @brief … … 193 193 if(!this->isPickedUp()) 194 194 return; 195 195 196 196 //! If the pickup has transited to used. 197 197 if(this->isUsed()) … … 202 202 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 203 203 this->destroy(); 204 204 205 205 float health = 0; 206 206 switch(this->getHealthTypeDirect()) … … 226 226 COUT(1) << "Invalid healthType in HealthPickup." << std::endl; 227 227 } 228 228 229 229 //! The pickup has been used up. 230 230 this->setUsed(false); … … 237 237 PickupCarrier* carrier = this->getCarrier(); 238 238 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 239 239 240 240 if(pawn == NULL) 241 241 { … … 244 244 return; 245 245 } 246 246 247 247 if(pawn->getMaxHealth() == this->maxHealthOverwrite_) 248 248 { … … 252 252 } 253 253 } 254 254 255 255 //! If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused. 256 256 if(this->isOnce() || (this->isContinuous() && this->getHealth() == 0)) … … 260 260 } 261 261 } 262 262 263 263 /** 264 264 @brief … … 271 271 PickupCarrier* carrier = this->getCarrier(); 272 272 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 273 273 274 274 if(pawn == NULL) 275 275 { 276 276 COUT(1) << "Invalid PickupCarrier in HealthPickup." << std::endl; 277 277 } 278 278 279 279 return pawn; 280 280 } 281 281 282 282 /** 283 283 @brief … … 297 297 pickup->setHealthRate(this->getHealthRate()); 298 298 pickup->setHealthTypeDirect(this->getHealthTypeDirect()); 299 299 300 300 pickup->initializeIdentifier(); 301 301 } 302 302 303 303 /** 304 304 @brief … … 322 322 } 323 323 } 324 324 325 325 /** 326 326 @brief … … 341 341 } 342 342 } 343 343 344 344 /** 345 345 @brief … … 356 356 else 357 357 { 358 COUT(1) << "Invalid healthSpeed in HealthPickup." << std::endl; 359 } 360 } 361 358 COUT(1) << "Invalid healthSpeed in HealthPickup." << std::endl; 359 } 360 } 361 362 362 /** 363 363 @brief -
code/branches/presentation3/src/modules/pickup/items/HealthPickup.h
r6709 r7127 45 45 46 46 namespace orxonox { 47 47 48 48 //! Enum for the type of the HealthPickup 49 49 namespace pickupHealthType … … 56 56 }; 57 57 } 58 58 59 59 /** 60 60 @brief … … 71 71 { 72 72 public: 73 73 74 74 HealthPickup(BaseObject* creator); //!< Constructor. 75 75 virtual ~HealthPickup(); //!< Destructor. 76 76 77 77 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML. 78 78 virtual void tick(float dt); //!< Is called every tick. 79 79 80 80 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 81 81 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 82 82 83 83 /** 84 84 @brief Get the health that is transfered to the Pawn upon usage of this pickup. … … 93 93 inline float getHealthRate(void) 94 94 { return this->healthRate_; } 95 95 96 96 /** 97 97 @brief Get the type of HealthPickup, this pickup is. 98 @return Returns the health type as an enum. 98 @return Returns the health type as an enum. 99 99 */ 100 100 inline pickupHealthType::Value getHealthTypeDirect(void) 101 101 { return this->healthType_; } 102 102 const std::string& getHealthType(void); //!< Get the health type of this pickup. 103 103 104 104 protected: 105 105 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. … … 107 107 void setHealth(float health); //!< Sets the health. 108 108 void setHealthRate(float speed); //!< Set the rate at which health is transferred if the pickup is continuous. 109 109 110 110 /** 111 111 @brief Set the health type of this pickup. … … 115 115 { this->healthType_ = type; } 116 116 void setHealthType(std::string type); //!< Set the type of the HealthPickup. 117 117 118 118 private: 119 119 void initialize(void); //!< Initializes the member variables. 120 120 Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 121 121 122 122 float health_; //!< The health that is transferred to the Pawn. 123 123 float healthRate_; //!< The rate at which the health is transferred. … … 125 125 float maxHealthOverwrite_; //!< Helper to remember with which value we overwrote the maxHealh, to detect if someone else changed it as well. 126 126 pickupHealthType::Value healthType_; //!< The type of the HealthPickup. 127 127 128 128 //! Strings for the health types. 129 129 static const std::string healthTypeLimited_s; 130 130 static const std::string healthTypeTemporary_s; 131 131 static const std::string healthTypePermanent_s; 132 132 133 133 }; 134 134 } -
code/branches/presentation3/src/modules/pickup/items/InvisiblePickup.h
r7112 r7127 44 44 45 45 namespace orxonox { 46 46 47 47 /** 48 48 @brief … … 57 57 { 58 58 public: 59 59 60 60 InvisiblePickup(BaseObject* creator); //!< Constructor. 61 61 virtual ~InvisiblePickup(); //!< Destructor. … … 63 63 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 64 64 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 65 65 66 66 /** 67 67 @brief Checks whether the Pawn is invisible. … … 72 72 inline float getDuration() 73 73 { return this->duration_; } 74 74 75 75 protected: 76 76 bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again. … … 78 78 void initializeIdentifier(void); 79 79 virtual void pickupTimerCallback(void); //!< Function that gets called when the timer ends. 80 80 81 81 private: 82 82 void initialize(void); //!< Initializes the member variables. -
code/branches/presentation3/src/modules/pickup/items/MetaPickup.cc
r6709 r7127 40 40 41 41 namespace orxonox { 42 42 43 43 CreateFactory(MetaPickup); 44 44 45 45 //! Setting the static variables to their values. 46 46 /*static*/ const std::string MetaPickup::metaTypeNone_s = "none"; 47 47 /*static*/ const std::string MetaPickup::metaTypeUse_s = "use"; 48 48 /*static*/ const std::string MetaPickup::metaTypeDrop_s = "drop"; 49 49 50 50 /** 51 51 @brief … … 55 55 { 56 56 RegisterObject(MetaPickup); 57 57 58 58 this->initialize(); 59 59 } 60 60 61 61 /** 62 62 @brief … … 65 65 MetaPickup::~MetaPickup() 66 66 { 67 68 } 69 67 68 } 69 70 70 /** 71 71 @brief … … 75 75 { 76 76 this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier()); 77 77 78 78 this->setActivationTypeDirect(pickupActivationType::immediate); 79 79 this->setDurationTypeDirect(pickupDurationType::once); 80 80 this->metaType_ = pickupMetaType::none; 81 81 } 82 82 83 83 /** 84 84 @brief … … 91 91 this->pickupIdentifier_->addParameter(type, val); 92 92 } 93 93 94 94 /** 95 95 @brief … … 99 99 { 100 100 SUPER(MetaPickup, XMLPort, xmlelement, mode); 101 101 102 102 XMLPortParam(MetaPickup, "metaType", setMetaType, getMetaType, xmlelement, mode); 103 103 104 104 this->initializeIdentifier(); 105 105 } 106 106 107 107 /** 108 108 @brief … … 113 113 { 114 114 SUPER(MetaPickup, changedUsed); 115 115 116 116 //! If the MetaPickup transited to used. 117 117 if(this->isUsed()) … … 144 144 } 145 145 } 146 146 147 147 /** 148 148 @brief … … 155 155 if(item == NULL) 156 156 item = new MetaPickup(this); 157 157 158 158 SUPER(MetaPickup, clone, item); 159 159 160 160 MetaPickup* pickup = dynamic_cast<MetaPickup*>(item); 161 161 pickup->setMetaTypeDirect(this->getMetaTypeDirect()); 162 162 163 163 pickup->initializeIdentifier(); 164 164 } 165 165 166 166 /** 167 167 @brief … … 184 184 } 185 185 } 186 186 187 187 /** 188 188 @brief … … 206 206 } 207 207 } 208 208 209 209 } -
code/branches/presentation3/src/modules/pickup/items/MetaPickup.h
r6709 r7127 51 51 }; 52 52 } 53 53 54 54 /** 55 55 @brief … … 60 60 class _PickupExport MetaPickup : public Pickup 61 61 { 62 62 63 63 public: 64 64 MetaPickup(BaseObject* creator); //!< Constructor. Registers and initializes the object. 65 65 virtual ~MetaPickup(); //!< Destructor. 66 66 67 67 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a MetaPickup object through XML. 68 68 69 69 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 70 70 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 71 71 72 72 /** 73 73 @brief Returns the meta type of the MetaPickup. … … 77 77 { return this->metaType_; } 78 78 const std::string& getMetaType(void); //!< Get the meta type of this MetaPickup. 79 79 80 80 protected: 81 81 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 82 82 83 83 /** 84 84 @brief Set the meta type of the MetaPickup. … … 88 88 { this->metaType_ = type; } 89 89 void setMetaType(const std::string& type); //!< Set the meta type of this MetaPickup. 90 90 91 91 private: 92 92 void initialize(void); //!< Initializes the member variables. 93 93 94 94 pickupMetaType::Value metaType_; //!< The meta type of the MetaPickup, determines which actions are taken. 95 95 96 96 //! Static strings for the meta types. 97 97 static const std::string metaTypeNone_s; 98 98 static const std::string metaTypeUse_s; 99 99 static const std::string metaTypeDrop_s; 100 101 100 101 102 102 }; 103 103 -
code/branches/presentation3/src/modules/pickup/items/ShieldPickup.cc
r6998 r7127 79 79 PickupCarrier* carrier = this->getCarrier(); 80 80 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 81 81 82 82 if(pawn == NULL) 83 83 { … … 86 86 return pawn; 87 87 } 88 88 89 89 /** 90 90 @brief … … 117 117 std::string val2 = stream.str(); 118 118 this->pickupIdentifier_->addParameter(type2, val2); 119 119 120 120 stream.clear(); 121 121 stream << this->getShieldAbsorption(); … … 269 269 270 270 void ShieldPickup::pickupTimerCallback(void) 271 { 271 { 272 272 this->setUsed(false); 273 273 } -
code/branches/presentation3/src/modules/pickup/items/SpeedPickup.cc
r6755 r7127 137 137 if(engine == NULL) //!< If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed. 138 138 this->destroy(); 139 139 140 140 //! If the pickup has transited to used. 141 141 if(this->isUsed()) … … 156 156 engine->setSpeedAdd(0.0f); 157 157 engine->setSpeedMultiply(1.0f); 158 158 159 159 if(this->isOnce()) 160 160 { … … 186 186 COUT(1) << "Invalid PickupCarrier in SpeedPickup." << std::endl; 187 187 } 188 188 189 189 return engine; 190 190 } … … 269 269 270 270 void SpeedPickup::pickupTimerCallback(void) 271 { 271 { 272 272 this->setUsed(false); 273 273 } -
code/branches/presentation3/src/modules/pickup/items/SpeedPickup.h
r6709 r7127 78 78 protected: 79 79 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 80 80 81 81 virtual void pickupTimerCallback(void); //!< Function that gets called when timer ends. 82 82
Note: See TracChangeset
for help on using the changeset viewer.