Changeset 7547 for code/trunk/src/modules/pickup
- Timestamp:
- Oct 16, 2010, 12:37:09 PM (14 years ago)
- Location:
- code/trunk/src/modules/pickup
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/pickup/CollectiblePickup.h
r7533 r7547 67 67 @return Returns true if the CollectiblePickup is part of a PickupCollection. 68 68 */ 69 bool isInCollection(void) 69 bool isInCollection(void) const 70 70 { return this->isInCollection_; } 71 71 -
code/trunk/src/modules/pickup/Pickup.cc
r7533 r7547 119 119 Returns a string containing the activation type. 120 120 */ 121 const std::string& Pickup::getActivationType(void) 121 const std::string& Pickup::getActivationType(void) const 122 122 { 123 123 switch(this->activationType_) … … 138 138 Returns a string containing the duration type. 139 139 */ 140 const std::string& Pickup::getDurationType(void) 140 const std::string& Pickup::getDurationType(void) const 141 141 { 142 142 switch(this->durationType_) -
code/trunk/src/modules/pickup/Pickup.h
r7533 r7547 40 40 #include "core/BaseObject.h" 41 41 #include "core/XMLPort.h" 42 #include "tools/Timer.h" 42 43 43 44 #include "CollectiblePickup.h" 44 45 #include "tools/Timer.h"46 45 47 46 namespace orxonox … … 83 82 84 83 Pickups ingeriting from this class can choose an activation type and a duration type. 85 - The <b>activation type</b> deals with what happens to the Pickup as soon as it is picked up. It can either be set to <em>immediate</em>, which means that the Pickup is activated/used immediately upon being picked up. Or to <em>onUse</em>, which means, that the Pickup will be activated/used if some outside entity (most commonly the player through the PickupInventory) decides to use it.86 - The <b>duration type</b> deals with whether the Pickup has a continuous effect or whether its effect is focused on a singular instant. It can either be set to <em>once</em>, which means, that the Pickup just has an effect (at a singular instant in time) and is done once that effect has been applied. Or to <em>continuous</em>, which means that the effect of the Pickup unfolds over some timespan.84 - The <b>activationType</b> deals with what happens to the Pickup as soon as it is picked up. It can either be set to <em>immediate</em>, which means that the Pickup is activated/used immediately upon being picked up. Or to <em>onUse</em>, which means, that the Pickup will be activated/used if some outside entity (most commonly the player through the PickupInventory) decides to use it. Default is <em>immediate</em>. 85 - The <b>durationType</b> deals with whether the Pickup has a continuous effect or whether its effect is focused on a singular instant. It can either be set to <em>once</em>, which means, that the Pickup just has an effect (at a singular instant in time) and is done once that effect has been applied. Or to <em>continuous</em>, which means that the effect of the Pickup unfolds over some timespan. Default is <em>once</em>. 87 86 88 87 If it were not an abstract class it could for example be used as follows in XML. … … 110 109 @return Returns the activation type of the Pickup. 111 110 */ 112 inline pickupActivationType::Value getActivationTypeDirect(void) 111 inline pickupActivationType::Value getActivationTypeDirect(void) const 113 112 { return this->activationType_; } 114 113 /** … … 116 115 @return Returns the duration type of the Pickup. 117 116 */ 118 inline pickupDurationType::Value getDurationTypeDirect(void) 117 inline pickupDurationType::Value getDurationTypeDirect(void) const 119 118 { return this->durationType_; } 120 119 121 const std::string& getActivationType(void) ; //!< Get the activation type of the Pickup.122 const std::string& getDurationType(void) ; //!< Get the duration type of the Pickup.120 const std::string& getActivationType(void) const; //!< Get the activation type of the Pickup. 121 const std::string& getDurationType(void) const; //!< Get the duration type of the Pickup. 123 122 124 123 /** … … 126 125 @return Returns true if the activation type is 'immediate'. 127 126 */ 128 inline bool isImmediate(void) 127 inline bool isImmediate(void) const 129 128 { return this->getActivationTypeDirect() == pickupActivationType::immediate; } 130 129 /** … … 132 131 @return Returns true if the activation type is 'onUse'. 133 132 */ 134 inline bool isOnUse(void) 133 inline bool isOnUse(void) const 135 134 { return this->getActivationTypeDirect() == pickupActivationType::onUse; } 136 135 /** … … 138 137 @return Returns true if the duration type is 'once'. 139 138 */ 140 inline bool isOnce(void) 139 inline bool isOnce(void) const 141 140 { return this->getDurationTypeDirect() == pickupDurationType::once; } 142 141 /** … … 144 143 @return Returns true if the duration type is 'continuous'. 145 144 */ 146 inline bool isContinuous(void) 145 inline bool isContinuous(void) const 147 146 { return this->getDurationTypeDirect() == pickupDurationType::continuous; } 148 147 149 148 virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around. 150 151 149 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the OrxonoxClass. 152 150 -
code/trunk/src/modules/pickup/PickupCollection.cc
r7533 r7547 235 235 Returns true if the PickupCarrier identified by the input PickupIdentififer it is a target of this PickupCollection, false if not. 236 236 */ 237 bool PickupCollection::isTarget( PickupCarrier* carrier) const237 bool PickupCollection::isTarget(const PickupCarrier* carrier) const 238 238 { 239 239 for(std::vector<CollectiblePickup*>::const_iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++) … … 253 253 Returns a pointer to the PickupIdentifier of this PickupCollection. 254 254 */ 255 const PickupIdentifier* PickupCollection::getPickupIdentifier(void) 255 const PickupIdentifier* PickupCollection::getPickupIdentifier(void) const 256 256 { 257 257 return this->pickupCollectionIdentifier_; … … 284 284 Returns a pointer to the Pickupable at the index given by index. 285 285 */ 286 const Pickupable* PickupCollection::getPickupable(unsigned int index) 286 const Pickupable* PickupCollection::getPickupable(unsigned int index) const 287 287 { 288 288 return this->pickups_[index]; -
code/trunk/src/modules/pickup/PickupCollection.h
r7533 r7547 38 38 #include "PickupPrereqs.h" 39 39 40 #include <list> 41 42 #include "CollectiblePickup.h" 40 43 #include "core/BaseObject.h" 41 #include "CollectiblePickup.h"42 43 #include <list>44 44 45 45 namespace orxonox … … 83 83 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input pickup. 84 84 85 virtual bool isTarget( PickupCarrier* carrier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this PickupCollection.85 virtual bool isTarget(const PickupCarrier* carrier) const; //!< Get whether a given class, represented by the input Identifier, is a target of this PickupCollection. 86 86 87 virtual const PickupIdentifier* getPickupIdentifier(void) ; //!< Get the PickupIdentifier of this PickupCollection.87 virtual const PickupIdentifier* getPickupIdentifier(void) const; //!< Get the PickupIdentifier of this PickupCollection. 88 88 89 89 bool addPickupable(CollectiblePickup* pickup); //!< Add the input Pickupable to list of Pickupables combined by this PickupCollection. 90 const Pickupable* getPickupable(unsigned int index) ; //!< Get the Pickupable at the given index.90 const Pickupable* getPickupable(unsigned int index) const; //!< Get the Pickupable at the given index. 91 91 92 92 void pickupChangedUsed(bool changed); //!< Informs the PickupCollection, that one of its pickups has changed its used status to the input value. -
code/trunk/src/modules/pickup/PickupManager.cc
r7539 r7547 389 389 @param pickup 390 390 A number identifying the Pickupable that changed its pickedUp status. 391 @param u nusable392 Whether the Pickupable's used status can be changed to u nused in the PickupInventory.391 @param usable 392 Whether the Pickupable's used status can be changed to used in the PickupInventory. 393 393 @param representationObjectId 394 394 The objectId identifying (over the network) the PickupRepresentation that represents this Pickupable. -
code/trunk/src/modules/pickup/PickupManager.h
r7540 r7547 39 39 40 40 #include <map> 41 42 41 #include "core/WeakPtr.h" 43 42 … … 75 74 The PickupManager class manages @ref orxonox::Pickupable "Pickupables". 76 75 77 It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their @ref orxonox::PickupIdentifier "PickupIdentifiers") to their respective @ref orxonox: PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref roxonox::Pickupable "Pickupables" for the covenience of the user.)76 It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their @ref orxonox::PickupIdentifier "PickupIdentifiers") to their respective @ref orxonox::PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref orxonox::Pickupable "Pickupables" for the covenience of the user.) 78 77 79 78 @section PickupManagerTechnicalDetails Technical details … … 89 88 - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with @ref orxonox::PickupIdentifier "PickupIdentifiers" and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list. 90 89 - The @ref orxonox::PickupManager::representationsNetworked_ "representationsNetworked_" list is the networked (hence the name) equivalent to the @ref orxonox::PickupManager::representations_ "representations_" list. It links an objectId of a @ref orxonox::PickupRepresentation "PickupRepresentation" to a @ref orxonox::PickupRepresentation "PickupRepresentation". This list is maintained on all hosts, each representation registers itself (in its constructor) with the PickupManager. Since the representations are synchronised they are created on each host. The "same" instance on each host is identified by the same objectId and that is why we store the representations with the objectId as key. We can then use this list to get a @ref orxonox::PickupRepresentation "PickupRepresentation" for a specific @ref orxonox::Pickupable "Pickupable" (or more precisely a number identifiying that particular pickup, but we'll see that, when we look at the next list) on a client to be used in the PickupInventory. 91 - The @ref orxonox::PickupManager::pickupInventoryContainers_ "pickupInventoryContainers_" list links a number identifying a @ref orxonox::Pickupable "Pickupable" to a data structure (the @ref orxonox::PickupInventoryContainer "PickupInventoryContainer"), which contains all necessary information about that @ref orxonox::Pickupable "Pickupable". This list is maintained on all hosts, a new container is inserted when a @ref orxonox::Pickupable "Pickupable" is picked up, but only if it has been picked up by the repsective host. This list is then used by the PickupInventory to access the required information and to get the correct @ref orxonox: .PickupRepresentation "PickupRepresentation".90 - The @ref orxonox::PickupManager::pickupInventoryContainers_ "pickupInventoryContainers_" list links a number identifying a @ref orxonox::Pickupable "Pickupable" to a data structure (the @ref orxonox::PickupInventoryContainer "PickupInventoryContainer"), which contains all necessary information about that @ref orxonox::Pickupable "Pickupable". This list is maintained on all hosts, a new container is inserted when a @ref orxonox::Pickupable "Pickupable" is picked up, but only if it has been picked up by the repsective host. This list is then used by the PickupInventory to access the required information and to get the correct @ref orxonox::PickupRepresentation "PickupRepresentation". 92 91 - The @ref orxonox::PickupManager::pickups_ "pickups_" list links a number identifiying a @ref orxonox::Pickupable "Pickupable" to a (weak pointer to a) @ref orxonox::Pickupable "Pickupable". It is only maintained by the server (or in standalone mode), to be able to use, unuse and drop @ref orxonox::Pickupable "Pickupables" through the PickupInventory. Since @ref orxonox::Pickupable "Pickupables" only exist on the server a client that wants to change a pickups status has so send a request over the network (with the number identifying the pickup) to the server and then the server facilitates the change, using this list to map from the identifyer to the actual @ref orxonox::Pickupable "Pickupable". 93 92 - The @ref orxonox::PickupManager::indexes_ "indexes_" list links a @ref orxonox::Pickupable "Pickupable" to the number identifying it. This is only maintained on the server (or in standalone mode), and is used for the inverse mapping of the previous list, which means the server uses it identify pickups on clients when it communicates changes in pickups to clients. … … 139 138 @return Returns the next PickupInventoryContainer in the list. 140 139 */ 141 orxonox::PickupInventoryContainer* popPickup(void)140 const orxonox::PickupInventoryContainer* popPickup(void) 142 141 { return (this->pickupsIterator_++)->second; } 143 142 … … 149 148 @return Returns true if the input Pickupable is still valid, false if not. 150 149 */ 151 bool isValidPickup(uint32_t pickup)150 const bool isValidPickup(uint32_t pickup) const 152 151 { return this->pickups_.find(pickup) != this->pickups_.end(); } 153 152 // tolua_end -
code/trunk/src/modules/pickup/PickupRepresentation.h
r7540 r7547 39 39 40 40 #include "core/XMLPort.h" 41 41 42 #include "interfaces/Pickupable.h" 42 43 #include "pickup/PickupIdentifier.h" … … 53 54 /** 54 55 @brief 55 The PickupRepresentation class represents a specific pickup type (identified by its @ref orxonox::PickupIdentifi fer "PickupIdentifier"). It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like.56 The PickupRepresentation class represents a specific pickup type (identified by its @ref orxonox::PickupIdentifier "PickupIdentifier"). It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like. 56 57 They are created through XML and are registered with the @ref orxonox::PickupManager "PickupManager". 57 58 … … 71 72 As you might have noticed, there is a parameter called <em>spawnerTemplate</em> and also another parameter called <em>inventoryRepresentation</em>. Let's first explain the second one, <em>inventoryRepresentation</em>. 72 73 - The <b>inventoryRepresentation</b> specifies the image that is displayed in the PickupInventory for the specific type of @ref orxonox::Pickupable "Pickupable". More technically, it is the name of an image located in the <code>PickupInventory.imageset</code>, which in turn is located in <code>data_extern/gui/imagesets/</code>. 73 - The <b>spawnerTemplate</b> specifies how the type of @ref orxonox::Pickupable "Pickupable" (or more precisely the @ref orxonox::PickupSpawner "PickupSpawner", that spawns that type of @ref orxonox::Pickupable "Pickupable") is displayed ingame. It is a @ref orx nox::Template "Template" defined in XML. The <em>spawnerTemplate</em> can be specified as follows (keep in mind, that the template needs to have been specified before the definition of the PickupRepresentation that uses it).74 - The <b>spawnerTemplate</b> specifies how the type of @ref orxonox::Pickupable "Pickupable" (or more precisely the @ref orxonox::PickupSpawner "PickupSpawner", that spawns that type of @ref orxonox::Pickupable "Pickupable") is displayed ingame. It is a @ref orxonox::Template "Template" defined in XML. The <em>spawnerTemplate</em> can be specified as follows (keep in mind, that the template needs to have been specified before the definition of the PickupRepresentation that uses it). 74 75 @code 75 76 <Template name="awesomePickupRepresentation"> … … 105 106 106 107 /** 108 @brief Get the name of the Pickupable represented by this PickupRepresentation. 109 @return Returns the name. 110 */ 111 inline const std::string& getPickupName(void) const { return this->name_; } // tolua_export 112 /** 113 @brief Get the description of the Pickupable represented by this PickupRepresentation. 114 @return Returns the description. 115 */ 116 inline const std::string& getPickupDescription(void) const { return this->description_; } // tolua_export 117 /** 118 @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation. 119 @return Returns the name of the spawnerTemplate. 120 */ 121 inline const std::string& getSpawnerTemplate(void) const 122 { return this->spawnerTemplate_; } 123 /** 124 @brief Get the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like. 125 @param index The index. 126 @return Returns (for index = 0) a pointer to the StaticEntity. For index > 0 it returns NULL. 127 */ 128 inline const StaticEntity* getSpawnerRepresentationIndex(unsigned int index) const 129 { if(index == 0) return this->spawnerRepresentation_; return NULL; } 130 /** 131 @brief Get the name of the image representing the pickup in the PickupInventory. 132 @return Returns the name of the image as a string. 133 */ 134 inline const std::string& getInventoryRepresentation(void) const { return this->inventoryRepresentation_; } // tolua_export 135 /** 136 @brief Get the Pickupable represented by this PickupRepresentation. 137 @param index The index. 138 @return Returns (for index = 0) a pointer to the Pickupable. For index > 0 it returns NULL. 139 */ 140 inline const Pickupable* getPickup(unsigned int index) const 141 { if(index == 0) return this->pickup_; return NULL; } 142 143 StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner. 144 145 protected: 146 /** 107 147 @brief Set the name of the Pickupable represented by this PickupRepresentation. 108 148 @param name The name. … … 142 182 inline void setPickup(Pickupable* pickup) 143 183 { this->pickup_ = pickup; } 144 145 /**146 @brief Get the name of the Pickupable represented by this PickupRepresentation.147 @return Returns the name.148 */149 inline const std::string& getPickupName(void) { return this->name_; } // tolua_export150 /**151 @brief Get the description of the Pickupable represented by this PickupRepresentation.152 @return Returns the description.153 */154 inline const std::string& getPickupDescription(void) { return this->description_; } // tolua_export155 /**156 @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation.157 @return Returns the name of the spawnerTemplate.158 */159 inline const std::string& getSpawnerTemplate(void)160 { return this->spawnerTemplate_; }161 /**162 @brief Get the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like.163 @param index The index.164 @return Returns (for index = 0) a pointer to the StaticEntity. For index > 0 it returns NULL.165 */166 inline const StaticEntity* getSpawnerRepresentationIndex(unsigned int index)167 { if(index == 0) return this->spawnerRepresentation_; return NULL; }168 /**169 @brief Get the name of the image representing the pickup in the PickupInventory.170 @return Returns the name of the image as a string.171 */172 inline const std::string& getInventoryRepresentation(void) { return this->inventoryRepresentation_; } // tolua_export173 /**174 @brief Get the Pickupable represented by this PickupRepresentation.175 @param index The index.176 @return Returns (for index = 0) a pointer to the Pickupable. For index > 0 it returns NULL.177 */178 inline const Pickupable* getPickup(unsigned int index)179 { if(index == 0) return this->pickup_; return NULL; }180 181 StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner.182 184 183 185 private: -
code/trunk/src/modules/pickup/PickupSpawner.cc
r7540 r7547 38 38 #include "core/Template.h" 39 39 #include "core/XMLPort.h" 40 40 41 #include "worldentities/pawns/Pawn.h" 42 41 43 #include "PickupManager.h" 42 44 #include "PickupRepresentation.h" … … 187 189 PickupCarrier* carrier = dynamic_cast<PickupCarrier*>(*it); 188 190 // If a Pawn, that fits the target-range of the item spawned by this Pickup, is in trigger-distance. 189 if (distance.length() < this->triggerDistance_ && carrier != NULL && carrier->isTarget(this->pickup_))191 if (distance.length() < this->triggerDistance_ && carrier != NULL) 190 192 { 191 this->trigger(*it); 193 if(carrier->isTarget(this->pickup_)) 194 this->trigger(*it); 192 195 } 193 196 } … … 270 273 Returns the Pickupable that is spawned by this PickupSpawner. 271 274 */ 272 const Pickupable* PickupSpawner::getPickupable(void) 275 const Pickupable* PickupSpawner::getPickupable(void) const 273 276 { 274 277 return this->pickup_; -
code/trunk/src/modules/pickup/PickupSpawner.h
r7540 r7547 39 39 40 40 #include <string> 41 42 41 #include "tools/Timer.h" 43 42 … … 92 91 { return this->triggerDistance_; } 93 92 /** 94 @brief Set the distance in which to trigger.95 @param value The new distance in which to trigger.96 */97 inline void setTriggerDistance(float value)98 { this->triggerDistance_ = value; }99 100 /**101 93 @brief Get the time to respawn. 102 94 @returns Returns the time after which this gets re-actived. … … 105 97 { return this->respawnTime_; } 106 98 /** 99 @brief Get the maximum number of items that will be spawned by this PickupSpawner. 100 @return Returns the maximum number of items spawned by this PickupSpawner. 101 */ 102 inline int getMaxSpawnedItems(void) const 103 { return this->maxSpawnedItems_; } 104 105 106 protected: 107 void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns. 108 void startRespawnTimer(void); 109 110 /** 111 @brief Set the distance in which to trigger. 112 @param value The new distance in which to trigger. 113 */ 114 inline void setTriggerDistance(float value) 115 { this->triggerDistance_ = value; } 116 /** 107 117 @brief Set the time to respawn. 108 118 @param time New time after which this gets re-actived. … … 110 120 inline void setRespawnTime(float time) 111 121 { this->respawnTime_ = time; } 112 113 /**114 @brief Get the maximum number of items that will be spawned by this PickupSpawner.115 @return Returns the maximum number of items spawned by this PickupSpawner.116 */117 inline int getMaxSpawnedItems(void)118 { return this->maxSpawnedItems_; }119 122 void setMaxSpawnedItems(int items); //!< Sets the maximum number of spawned items. 120 121 protected:122 void decrementSpawnsRemaining(void); //!< Decrements the number of remaining spawns.123 124 void startRespawnTimer(void);125 123 126 124 virtual Pickupable* getPickup(void); //!< Creates a new Pickupable. 127 125 128 126 void setPickupable(Pickupable* pickup); //!< Sets a Pickupable for the PickupSpawner to spawn. 129 const Pickupable* getPickupable(void) ; //!< Get the Pickupable that is spawned by this PickupSpawner.127 const Pickupable* getPickupable(void) const; //!< Get the Pickupable that is spawned by this PickupSpawner. 130 128 131 129 Pickupable* pickup_; //!< The pickup to be spawned. -
code/trunk/src/modules/pickup/items/DronePickup.cc
r7541 r7547 35 35 36 36 #include <sstream> 37 38 37 #include "core/CoreIncludes.h" 39 38 #include "core/XMLPort.h" 40 #include "util/StringUtils.h"41 39 42 40 #include "controllers/DroneController.h" 43 41 #include "pickup/PickupIdentifier.h" 42 #include "worldentities/Drone.h" 44 43 #include "worldentities/pawns/Pawn.h" 45 #include "worldentities/Drone.h"46 #include "worldentities/StaticEntity.h"47 44 48 45 namespace orxonox -
code/trunk/src/modules/pickup/items/DronePickup.h
r7541 r7547 48 48 @brief 49 49 The DronePickup adds a Drone to the Pawn upon being picked up. 50 50 51 It can be used in XML as follows: 51 52 @code … … 71 72 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 72 73 73 void setDroneTemplate(std::string templatename); //!< Set the droneTemplate.74 74 const std::string& getDroneTemplate() const; //!< Get the name of the droneTemplate. 75 75 76 76 protected: 77 77 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 78 79 void setDroneTemplate(std::string templatename); //!< Set the droneTemplate. 78 80 79 81 private: -
code/trunk/src/modules/pickup/items/HealthPickup.cc
r7541 r7547 34 34 #include "HealthPickup.h" 35 35 36 #include <sstream> 36 37 #include "core/CoreIncludes.h" 37 38 #include "core/XMLPort.h" 38 #include "util/StringUtils.h" 39 39 40 #include "pickup/PickupIdentifier.h" 40 41 #include "worldentities/pawns/Pawn.h" 41 #include "pickup/PickupIdentifier.h"42 43 #include <sstream>44 42 45 43 namespace orxonox … … 307 305 Returns the health type as a string. 308 306 */ 309 const std::string& HealthPickup::getHealthType(void) 307 const std::string& HealthPickup::getHealthType(void) const 310 308 { 311 309 switch(this->getHealthTypeDirect()) -
code/trunk/src/modules/pickup/items/HealthPickup.h
r7541 r7547 39 39 40 40 #include <string> 41 #include <worldentities/pawns/Pawn.h>42 #include "worldentities/StaticEntity.h"43 41 44 42 #include "pickup/Pickup.h" … … 65 63 /** 66 64 @brief 67 The Health Pickup is a Pickupable that can do (dependent upon the parameters) lots of different things to the health of a Pawn. 68 There are 4 parameters that can be chosen: 69 - The <b>health</b> The amount of health that (in a way dependent on the other parameters) is transferred to the Pawn. 70 - The <b>activation type</b> It can be chosen to be either <em>immediate</em> or <em>onUse</em>. The activation type essentially (as indicated by the name) defines when the health is transferred, either immediately after being picked up or only after the player uses it. 71 - The <b>duration type</b> It can be chosen to be either <em>once</em> or <em>continuous</em>. For <em>once</em> the specified health is transferred once to the Pawn, for <em>continuous</em> the set health is transferred over a span of time at a rate defined by the health rate parameter. 72 - The <b>health type</b> The health type can be chosen to be <em>limited</em>, <em>temporary</em> or <em>permanent</em>. <em>limited</em> means that the health is increased only to the maximum health of the Pawn. 'temporary' means that the maximum health is temporarily elevated but will be set back as soon as the pickup is no longer in use. <em>permanent</em> means that the maximum health of the Pawn is increased such that the health provided by the pickup will fit in and the maximum health stays that way. 65 The HealthPickup is a Pickupable that can do (dependent upon the parameters) lots of different things to the health of a Pawn. 66 There are 5 parameters that can be chosen: 67 - The @b activationType It can be chosen to be either <em>immediate</em> or <em>onUse</em>. The activation type essentially (as indicated by the name) defines when the health is transferred, either immediately after being picked up or only after the player uses it. The default is <em>immediate</em>. 68 - The @b durationType It can be chosen to be either <em>once</em> or <em>continuous</em>. For <em>once</em> the specified health is transferred once to the Pawn, for <em>continuous</em> the set health is transferred over a span of time at a rate defined by the health rate parameter. The default is <em>once</em>. 69 - The @b health The amount of health that (in a way dependent on the other parameters) is transferred to the Pawn. Default is 0. 70 - The @b healthType The health type can be chosen to be <em>limited</em>, <em>temporary</em> or <em>permanent</em>. <em>limited</em> means that the health is increased only to the maximum health of the Pawn. 'temporary' means that the maximum health is temporarily elevated but will be set back as soon as the pickup is no longer in use. <em>permanent</em> means that the maximum health of the Pawn is increased such that the health provided by the pickup will fit in and the maximum health stays that way. The default is <em>limited</em>. 71 - The @b healthRate If set to continuous, the health that is transferred per second is the <em>healthRate</em>. There is health transferred until the health set by <em>health</em> is depleted. The default is 0. 73 72 74 An exam le of a XML implementation of a HealthPickup would be:73 An example of a XML implementation of a HealthPickup would be: 75 74 @code 76 75 <HealthPickup … … 104 103 @return Returns the health. 105 104 */ 106 inline float getHealth(void) 105 inline float getHealth(void) const 107 106 { return this->health_; } 108 107 /** … … 110 109 @return Returns the rate. 111 110 */ 112 inline float getHealthRate(void) 111 inline float getHealthRate(void) const 113 112 { return this->healthRate_; } 114 113 … … 117 116 @return Returns the health type as an enum. 118 117 */ 119 inline pickupHealthType::Value getHealthTypeDirect(void) 118 inline pickupHealthType::Value getHealthTypeDirect(void) const 120 119 { return this->healthType_; } 121 const std::string& getHealthType(void) ; //!< Get the health type of this pickup.120 const std::string& getHealthType(void) const; //!< Get the health type of this pickup. 122 121 123 122 protected: -
code/trunk/src/modules/pickup/items/InvisiblePickup.cc
r7546 r7547 35 35 36 36 #include <sstream> 37 #include <OgreEntity.h> 38 #include <OgreAnimationState.h> 39 40 #include "util/StringUtils.h" 37 //#include <OgreEntity.h> 38 //#include <OgreAnimationState.h> 41 39 #include "core/CoreIncludes.h" 42 40 #include "core/XMLPort.h" 43 41 42 #include "pickup/PickupIdentifier.h" 44 43 #include "worldentities/pawns/Pawn.h" 45 #include "pickup/PickupIdentifier.h"46 44 47 45 namespace orxonox … … 68 66 } 69 67 70 68 /** 69 @brief 70 Initializes the member variables. 71 */ 72 void InvisiblePickup::initialize(void) 73 { 74 this->duration_ = 0.0f; 75 // Defines who is allowed to pick up the pickup. 76 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 77 } 78 79 /** 80 @brief 81 Initializes the PickupIdentifier of this pickup. 82 */ 71 83 void InvisiblePickup::initializeIdentifier(void) 72 84 { … … 80 92 /** 81 93 @brief 82 Initializes the member variables.83 */84 void InvisiblePickup::initialize(void)85 {86 this->duration_ = 0.0f;87 // Defines who is allowed to pick up the pickup.88 this->addTarget(ClassIdentifier<Pawn>::getIdentifier());89 }90 91 /**92 @brief93 94 Method for creating a HealthPickup object through XML. 94 95 */ … … 113 114 return; 114 115 116 // If the pickup has transited to used. 115 117 if (this->isUsed()) 116 118 { 119 // If its durationType is continuous, we set a Timer to be reminded, when the time has run out. 117 120 if(this->isContinuous()) 118 121 { … … 134 137 this->setInvisible(false); 135 138 139 // We destroy the pickup if either, the pickup has activationType immediate and durationType once or it has durationType continuous and the duration was exceeded. 136 140 if((!this->isContinuous() && this->isImmediate()) || (this->isContinuous() && !this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration())) 137 141 { 138 142 this->Pickupable::destroy(); 139 143 } 144 // We pause the Timer if the pickup is continuous and the duration is not yet exceeded, 140 145 else if(this->isContinuous() && this->durationTimer_.isActive()) 141 146 { … … 143 148 } 144 149 } 145 146 }147 148 /**149 @brief150 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.151 @return152 A pointer to the Pawn, or NULL if the conversion failed.153 */154 Pawn* InvisiblePickup::carrierToPawnHelper(void)155 {156 PickupCarrier* carrier = this->getCarrier();157 Pawn* pawn = dynamic_cast<Pawn*>(carrier);158 159 if(pawn == NULL)160 {161 COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl;162 }163 return pawn;164 150 } 165 151 … … 212 198 /** 213 199 @brief 200 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 201 @return 202 A pointer to the Pawn, or NULL if the conversion failed. 203 */ 204 Pawn* InvisiblePickup::carrierToPawnHelper(void) 205 { 206 PickupCarrier* carrier = this->getCarrier(); 207 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 208 209 if(pawn == NULL) 210 { 211 COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl; 212 } 213 return pawn; 214 } 215 216 /** 217 @brief 214 218 Sets the time the InvisibilityPickup will last. 215 219 @param duration -
code/trunk/src/modules/pickup/items/InvisiblePickup.h
r7545 r7547 40 40 #include <string> 41 41 42 #include <worldentities/pawns/Pawn.h>43 #include "worldentities/StaticEntity.h"44 42 #include "pickup/Pickup.h" 45 43 … … 49 47 @brief 50 48 A pickup that makes the Pawn invisible. 51 There are 2parameters that can be chosen:52 - The <b>activation type</b> It can be chosen to be either <em>immediate</em> or <em>onUse</em>. The activation type essentially (as indicated by the name) defines when the Pawn will be invisible, either immediately after being picked up or only after the player uses it.53 - The <b>duration type</b> It can be chosen to be either <em>once</em> or <em>continuous</em>. For <em>once</em> the InvisiblePickup just makes the Pawn invisible for as long as it is used, for <em>continuous</em> the Pawn is invisible for the specified duration.54 - The <b>duration</b> Specifies how long (in seconds) the invisibility lasts.49 There are 3 parameters that can be chosen: 50 - The @b activationType It can be chosen to be either <em>immediate</em> or <em>onUse</em>. The activation type essentially (as indicated by the name) defines when the Pawn will be invisible, either immediately after being picked up or only after the player uses it. The default is <em>immediate</em>. 51 - The @b durationType< It can be chosen to be either <em>once</em> or <em>continuous</em>. For <em>once</em> the InvisiblePickup just makes the Pawn invisible for as long as it is used, for <em>continuous</em> the Pawn is invisible for the specified duration. The default is <em>once</em>. 52 - The @b duration Specifies how long (in seconds) the invisibility lasts. The default is 0. 55 53 56 An exam le of a XML implementation of a InvisiblePickup would be:54 An example of a XML implementation of a InvisiblePickup would be: 57 55 @code 58 < HealthPickup56 <InvisiblePickup 59 57 activationType = "immediate" 60 58 durationType = "continuous" … … 83 81 @return Returns if the Pawn is invisible. 84 82 */ 85 inline bool getInvisibility(bool) 83 inline bool getInvisibility(bool) const 86 84 { return this->invisible_; } 87 85 /** … … 89 87 @return Returns the time in seconds the InvisibiltyPickup lasts. 90 88 */ 91 inline float getDuration(void) 89 inline float getDuration(void) const 92 90 { return this->duration_; } 93 91 94 92 protected: 95 void initializeIdentifier(void); 93 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 96 94 97 95 bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again. -
code/trunk/src/modules/pickup/items/MetaPickup.cc
r7533 r7547 34 34 #include "core/CoreIncludes.h" 35 35 #include "core/XMLPort.h" 36 #include "worldentities/pawns/Pawn.h" 36 37 37 #include "interfaces/PickupCarrier.h" 38 38 #include "pickup/PickupIdentifier.h" 39 #include "worldentities/pawns/Pawn.h" 39 40 40 41 #include "MetaPickup.h" … … 79 80 this->addTarget(ClassIdentifier<PickupCarrier>::getIdentifier()); 80 81 81 this->setActivationTypeDirect(pickupActivationType::immediate);82 82 this->setDurationTypeDirect(pickupDurationType::once); 83 83 this->metaType_ = pickupMetaType::none; … … 117 117 SUPER(MetaPickup, changedUsed); 118 118 119 // ! If the MetaPickup transited to used.120 if(this->isUsed() )119 // If the MetaPickup transited to used, and the metaType is not none. 120 if(this->isUsed() && this->metaType_ != pickupMetaType::none) 121 121 { 122 122 PickupCarrier* carrier = this->getCarrier(); 123 123 if(this->getMetaTypeDirect() != pickupMetaType::none && carrier != NULL) 124 124 { 125 // If the metaType is destroyCarrier, then the PickupCarrier is destroyed. 125 126 if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier) 126 127 { … … 131 132 } 132 133 std::set<Pickupable*> pickups = carrier->getPickups(); 133 // ! Set all Pickupables carried by the PickupCarrier either to used or drop them, depending on the meta type.134 // Iterate over all Pickupables of the PickupCarrier. 134 135 for(std::set<Pickupable*>::iterator it = pickups.begin(); it != pickups.end(); it++) 135 136 { 136 Pickup* pickup = dynamic_cast<Pickup*>(*it); 137 if(this->getMetaTypeDirect() == pickupMetaType::use) 137 Pickupable* pickup = (*it); 138 if(pickup == NULL || pickup == this) 139 continue; 140 141 // If the metaType is use, then the Pickupable is set to used. 142 if(this->getMetaTypeDirect() == pickupMetaType::use && !pickup->isUsed()) 138 143 { 139 if(pickup != NULL && pickup != this && pickup->isOnUse() && !pickup->isUsed()) 140 { 141 pickup->setUsed(true); 142 } 144 pickup->setUsed(true); 143 145 } 144 if(this->getMetaTypeDirect() == pickupMetaType::drop) 146 // If the metaType is drop, then the Pickupable is dropped. 147 else if(this->getMetaTypeDirect() == pickupMetaType::drop) 145 148 { 146 if(pickup != NULL && pickup != this) 147 { 148 pickup->drop(); 149 } 149 pickup->drop(); 150 150 } 151 if(this->getMetaTypeDirect() == pickupMetaType::destroy) 151 // If the metaType is destroy, then the Pickupable is destroyed. 152 else if(this->getMetaTypeDirect() == pickupMetaType::destroy) 152 153 { 153 if(pickup != NULL && pickup != this) 154 { 155 pickup->Pickupable::destroy(); 156 } 154 pickup->Pickupable::destroy(); 157 155 } 158 156 } … … 187 185 Returns a string with the meta type of the MetaPickup. 188 186 */ 189 const std::string& MetaPickup::getMetaType(void) 187 const std::string& MetaPickup::getMetaType(void) const 190 188 { 191 189 switch(this->getMetaTypeDirect()) -
code/trunk/src/modules/pickup/items/MetaPickup.h
r7533 r7547 42 42 namespace orxonox { 43 43 44 //! The meta type, deciding what the pickup does exactly. 44 /** 45 @brief 46 The meta type, specifying what the @ref orxonox::MetaPickup "MetaPickup" does exactly. 47 48 @ingroup PickupItems 49 */ 45 50 namespace pickupMetaType 46 51 { 47 52 enum Value 48 53 { 49 none, 50 use, 51 drop, 52 destroy, 53 destroyCarrier 54 none, //!< The @ref orxonox::MetaPickup "MetaPickup" does nothing. 55 use, //!< The @ref orxonox::MetaPickup "MetaPickup" uses all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables". 56 drop, //!< The @ref orxonox::MetaPickup "MetaPickup" drops all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables". 57 destroy, //!< The @ref orxonox::MetaPickup "MetaPickup" destroys all the @ref orxonox::PickupCarrier "PickupCarriers'" @ref orxonox::Pickupable "Pickupables". 58 destroyCarrier //!< The @ref orxonox::MetaPickup "MetaPickup" destroys the @ref orxonox::PickupCarrier "PickupCarrier". 54 59 }; 55 60 } … … 57 62 /** 58 63 @brief 59 The MetaPickup is a pickup that can, depending on the parameter 'metaType', do different things. If the 'metaType' is set to 60 - @b use All the pickups, the PickupCarrier has, are immediately set to used upon pickup of the MetaPickup. 61 - @b drop All the pickups, the PickupCarrier has, are immediately dropped upon pickup of the MetaPickup. 62 - @b destroy All the pickups, the PickupCarrier has, are immediately destroyed upon pickup of the MetaPickup. 63 - @b destroyCarrier The PickupCarrier is immediately destroyed upon pickup of the MetaPickup. 64 The MetaPickup is a Pickupable that can, depending on the parameter <em>metaTye</em>, do different things. If the <em>metaTye</em> is set to 65 - @b use All the @ref orxonox::Pickupable "Pickupables", the PickupCarrier has, are immediately set to used upon using the MetaPickup. 66 - @b drop All the @ref orxonox::Pickupable "Pickupables", the PickupCarrier has, are immediately dropped upon using the MetaPickup. 67 - @b destroy All the @ref orxonox::Pickupable "Pickupables", the PickupCarrier has, are immediately destroyed upon using the MetaPickup. 68 - @b destroyCarrier The PickupCarrier is immediately destroyed upon using the MetaPickup. 69 70 The default value is <em>none</em>, which basically does nothing. 71 72 The parameter <b>activation type</b> can be used to specify, whether the MetaPickup is used upon pickup (<em>immediate</em>) or not (<em>onUse</em>). With <em>immediate</em> being the default. 73 74 An example of a XML implementation of a MetaPickup would be: 75 @code 76 <MetaPickup 77 activationType = "immediate" 78 metaType = "use" 79 /> 80 @endcode 81 64 82 @author 65 83 Damian 'Mozork' Frick 84 85 @ingroup PickupItems 66 86 */ 67 87 class _PickupExport MetaPickup : public Pickup … … 81 101 @return Returns an enum with the meta type of the MetaPickup. 82 102 */ 83 inline pickupMetaType::Value getMetaTypeDirect(void) 103 inline pickupMetaType::Value getMetaTypeDirect(void) const 84 104 { return this->metaType_; } 85 const std::string& getMetaType(void) ; //!< Get the meta type of this MetaPickup.105 const std::string& getMetaType(void) const; //!< Get the meta type of this MetaPickup. 86 106 87 107 protected: -
code/trunk/src/modules/pickup/items/ShieldPickup.cc
r7208 r7547 34 34 #include "ShieldPickup.h" 35 35 36 #include <sstream> 36 37 #include "core/CoreIncludes.h" 37 38 #include "core/XMLPort.h" 38 #include "util/StringUtils.h" 39 40 #include "worldentities/pawns/SpaceShip.h" 41 #include "items/Engine.h" 39 42 40 #include "pickup/PickupIdentifier.h" 43 44 #include <sstream> 45 41 #include "worldentities/pawns/Pawn.h" 46 42 47 43 namespace orxonox … … 67 63 { 68 64 69 }70 71 /**72 @brief73 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.74 @return75 A pointer to the Pawn, or NULL if the conversion failed.76 */77 Pawn* ShieldPickup::carrierToPawnHelper(void)78 {79 PickupCarrier* carrier = this->getCarrier();80 Pawn* pawn = dynamic_cast<Pawn*>(carrier);81 82 if(pawn == NULL)83 {84 COUT(1) << "Invalid PickupCarrier in ShieldPickup." << std::endl;85 }86 return pawn;87 65 } 88 66 … … 134 112 SUPER(ShieldPickup, XMLPort, xmlelement, mode); 135 113 136 XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);137 114 XMLPortParam(ShieldPickup, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode); 138 115 XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode); 116 XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode); 139 117 140 118 this->initializeIdentifier(); … … 149 127 SUPER(ShieldPickup, changedUsed); 150 128 151 // !If the pickup is not picked up nothing must be done.129 // If the pickup is not picked up nothing must be done. 152 130 if(!this->isPickedUp()) 153 131 return; … … 157 135 this->Pickupable::destroy(); 158 136 159 // !If the pickup has transited to used.137 // If the pickup has transited to used. 160 138 if(this->isUsed()) 161 139 { 162 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f) 140 // If its durationType is continuous, we set a Timer to be reminded, when the time has run out. 141 if(this->isContinuous()) 163 142 { 164 this->durationTimer_.unpauseTimer(); 165 } 166 else 167 { 168 this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&ShieldPickup::pickupTimerCallback, this))); 143 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f) 144 { 145 this->durationTimer_.unpauseTimer(); 146 } 147 else 148 { 149 this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&ShieldPickup::pickupTimerCallback, this))); 150 } 169 151 } 170 152 pawn->setShieldAbsorption(this->getShieldAbsorption()); … … 177 159 pawn->setShieldHealth(0.0f); 178 160 179 if(this->isOnce()) 161 // We destroy the pickup if either, the pickup has activationType immediate and durationType once or it has durationType continuous and the duration was exceeded. 162 if((!this->isContinuous() && this->isImmediate()) || (this->isContinuous() && !this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration())) 180 163 { 181 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration()) 182 { 183 this->Pickupable::destroy(); 184 } 185 else 186 { 187 this->durationTimer_.pauseTimer(); 188 } 164 this->Pickupable::destroy(); 189 165 } 190 } 166 // We pause the Timer if the pickup is continuous and the duration is not yet exceeded, 167 else if(this->isContinuous() && this->durationTimer_.isActive()) 168 { 169 this->durationTimer_.pauseTimer(); 170 } 171 } 172 } 173 174 /** 175 @brief 176 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 177 @return 178 A pointer to the Pawn, or NULL if the conversion failed. 179 */ 180 Pawn* ShieldPickup::carrierToPawnHelper(void) 181 { 182 PickupCarrier* carrier = this->getCarrier(); 183 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 184 185 if(pawn == NULL) 186 { 187 COUT(1) << "Invalid PickupCarrier in ShieldPickup." << std::endl; 188 } 189 return pawn; 191 190 } 192 191 … … 213 212 /** 214 213 @brief 215 Sets the percentage the shield absorbs of the dealt damage. 214 Sets the duration. 215 @param duration 216 The duration in seconds. 217 */ 218 void ShieldPickup::setDuration(float duration) 219 { 220 if(duration >= 0.0f) 221 { 222 this->duration_ = duration; 223 } 224 else 225 { 226 COUT(1) << "Invalid duration in ShieldPickup." << std::endl; 227 this->duration_ = 0.0f; 228 } 229 } 230 231 /** 232 @brief 233 Sets the health of the shield. 234 @param shieldHealth 235 The shieldHealth. 236 */ 237 void ShieldPickup::setShieldHealth(float shieldHealth) 238 { 239 if (shieldHealth>=0) 240 { 241 this->shieldHealth_=shieldHealth; 242 } 243 else 244 { 245 COUT(1) << "Invalid Shieldhealth in ShieldPickup." << std::endl; 246 this->shieldHealth_=0; 247 } 248 } 249 250 /** 251 @brief 252 Sets the percentage the shield absorbs of the dealt damage. 216 253 @param shieldAbsorption 217 The shieldAbsorption. Has to be between 0 and 1254 The shieldAbsorption. Has to be between 0 and 1. 218 255 */ 219 256 void ShieldPickup::setShieldAbsorption(float shieldAbsorption) … … 232 269 /** 233 270 @brief 234 Sets the health of the shield. 235 @param shieldHealth 236 The shieldHealth 237 */ 238 void ShieldPickup::setShieldHealth(float shieldHealth) 239 { 240 if (shieldHealth>=0) 241 { 242 this->shieldHealth_=shieldHealth; 243 } 244 else 245 { 246 COUT(1) << "Invalid Shieldhealth in ShieldPickup." << std::endl; 247 this->shieldHealth_=0; 248 } 249 } 250 251 /** 252 @brief 253 Sets the duration. 254 @param duration 255 The duration 256 */ 257 void ShieldPickup::setDuration(float duration) 258 { 259 if(duration >= 0.0f) 260 { 261 this->duration_ = duration; 262 } 263 else 264 { 265 COUT(1) << "Invalid duration in ShieldPickup." << std::endl; 266 this->duration_ = 0.0f; 267 } 268 } 269 271 Helper method. Is called by the Timer as soon as it expires. 272 */ 270 273 void ShieldPickup::pickupTimerCallback(void) 271 274 { -
code/trunk/src/modules/pickup/items/ShieldPickup.h
r7493 r7547 40 40 41 41 #include <string> 42 #include "worldentities/pawns/Pawn.h"43 #include "worldentities/StaticEntity.h"44 42 45 43 #include "pickup/Pickup.h" … … 51 49 A Pickup which can add a Shield to the Pawn. 52 50 53 There are 4 parameters that can be cosen. 54 - The @b percentage The percentage the shield takes from the damage dealt to a Pawn 55 - The @b hit @b points The amount of damage points a shield can teake before collapsing 56 - The @b activation @b type 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it. 57 - The @b duration the activation time of the pickup. 51 There are 5 parameters that can be cosen. 52 - The @b shieldhealth< The amount of damage points a shield can take before collapsing. The default is 0. 53 - The @b shieldabsorption The percentage the shield takes from the damage dealt to a Pawn. The default is 0. 54 - The @b activationType, <em>immediate</em> or <em>onUse</em>. defines if the ShiedlPickup is used when it's picked up or only after the player chooses to use it. The default is <em>immediate</em>. 55 - The @b durationType, <em>once</em> means, that the shield will stay until it collapses, <em>continuous</em> means, that the shield only stays for a limited amount of time, specifiey by the duration. The default is <em>once</em>. 56 - The @b duration the time in seconds the shield is active at the most. The default is 0. 57 58 An example of a XML implementation of a ShieldPickup would be: 59 @code 60 <ShieldPickup 61 shieldhealth = 30 62 shieldabsorption = 0.8 63 activationType = "immediate" 64 durationtype = "continuous" 65 duration = 20.0 66 /> 67 @endcode 58 68 59 69 @author 60 70 Eric Beier 71 72 @ingroup PickupItems 61 73 */ 62 74 class _PickupExport ShieldPickup : public Pickup … … 72 84 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 73 85 74 inline float getDuration(void) 86 /** 87 @brief Get the duration, the time the shield is actvie at the most. 88 @return Returns the duration in seconds. 89 */ 90 inline float getDuration(void) const 75 91 { return this->duration_; } 76 inline float getShieldHealth() 92 /** 93 @brief Get the shield health, the amount of damage the shield can sustain. 94 @return Returns the shield health. 95 */ 96 inline float getShieldHealth() const 77 97 { return this->shieldHealth_; } 78 inline float getShieldAbsorption() 98 /** 99 @brief Get the shield absorption, the percentage of damage that is absorbed by the shield. 100 @return Returns the shield absorption. 101 */ 102 inline float getShieldAbsorption() const 79 103 { return this->shieldAbsorption_; } 80 104 81 105 protected: 82 106 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 107 void pickupTimerCallback(void); //!< Helper method. Is called by the Timer as soon as it expires. 83 108 84 void pickupTimerCallback(void); //!< Function that gets called when timer ends. 85 86 void setDuration(float duration); 87 void setShieldHealth(float shieldHealth); 88 void setShieldAbsorption(float shieldAbsorption); 109 void setDuration(float duration); //!< Sets the duration. 110 void setShieldHealth(float shieldHealth); //!< Sets the health of the shield. 111 void setShieldAbsorption(float shieldAbsorption); //!< Sets the percentage the shield absorbs of the dealt damage. 89 112 90 113 private: … … 95 118 96 119 float duration_; //!< The health that is transferred to the Pawn. 97 float shieldHealth_; 98 float shieldAbsorption_; // Has to be between 0 and 1120 float shieldHealth_; //!< The amount of damage the shield can sustain. 121 float shieldAbsorption_; //!< The percentage of damage that is absorbed by the shield. 99 122 100 123 }; -
code/trunk/src/modules/pickup/items/SpeedPickup.cc
r7401 r7547 34 34 #include "SpeedPickup.h" 35 35 36 #include <sstream> 36 37 #include "core/CoreIncludes.h" 37 38 #include "core/XMLPort.h" 38 #include "util/StringUtils.h" 39 40 #include "worldentities/pawns/SpaceShip.h" 39 41 40 #include "items/Engine.h" 42 41 #include "pickup/PickupIdentifier.h" 43 44 #include <sstream> 45 42 #include "worldentities/pawns/SpaceShip.h" 46 43 47 44 namespace orxonox … … 130 127 SUPER(SpeedPickup, changedUsed); 131 128 132 // !If the pickup is not picked up nothing must be done.129 // If the pickup is not picked up nothing must be done. 133 130 if(!this->isPickedUp()) 134 131 return; 135 132 136 133 Engine* engine = this->carrierToEngineHelper(); 137 if(engine == NULL) // !<If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed.134 if(engine == NULL) // If the PickupCarrier is no Engine, then this pickup is useless and therefore is destroyed. 138 135 this->Pickupable::destroy(); 139 136 140 // !If the pickup has transited to used.137 // If the pickup has transited to used. 141 138 if(this->isUsed()) 142 139 { 143 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f) 140 // If its durationType is continuous, we set a Timer to be reminded, when the time has run out. 141 if(this->isContinuous()) 144 142 { 145 this->durationTimer_.unpauseTimer(); 146 } 147 else 148 { 149 this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&SpeedPickup::pickupTimerCallback, this))); 150 } 151 engine->setSpeedAdd(this->getSpeedAdd()); 152 engine->setSpeedMultiply(this->getSpeedMultiply()); 153 } 154 else 155 { 156 engine->setSpeedAdd(0.0f); 157 engine->setSpeedMultiply(1.0f); 158 159 if(this->isOnce()) 160 { 161 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration()) 143 if(!this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() > 0.0f) 162 144 { 163 this-> Pickupable::destroy();145 this->durationTimer_.unpauseTimer(); 164 146 } 165 147 else 166 148 { 167 this->durationTimer_. pauseTimer();149 this->durationTimer_.setTimer(this->getDuration(), false, createExecutor(createFunctor(&SpeedPickup::pickupTimerCallback, this))); 168 150 } 151 } 152 153 engine->setSpeedAdd(this->getSpeedAdd()); 154 engine->setSpeedMultiply(this->getSpeedMultiply()); 155 } 156 else 157 { 158 engine->setSpeedAdd(0.0f); 159 engine->setSpeedMultiply(1.0f); 160 161 // We destroy the pickup if either, the pickup has activationType immediate and durationType once or it has durationType continuous and the duration was exceeded. 162 if((!this->isContinuous() && this->isImmediate()) || (this->isContinuous() && !this->durationTimer_.isActive() && this->durationTimer_.getRemainingTime() == this->getDuration())) 163 { 164 this->Pickupable::destroy(); 165 } 166 // We pause the Timer if the pickup is continuous and the duration is not yet exceeded, 167 else if(this->isContinuous() && this->durationTimer_.isActive()) 168 { 169 this->durationTimer_.pauseTimer(); 169 170 } 170 171 } … … 213 214 /** 214 215 @brief 215 Sets the duration .216 Sets the duration for which the SpeedPickup stays active. 216 217 @param duration 217 The duration 218 The duration in seconds. 218 219 */ 219 220 void SpeedPickup::setDuration(float duration) … … 232 233 /** 233 234 @brief 234 Sets the SpeedAdd235 Sets the speedAdd, the value that is added to the speed of the Pawn. 235 236 @param speedAdd 236 The added Speed237 The added speed. 237 238 */ 238 239 void SpeedPickup::setSpeedAdd(float speedAdd) … … 251 252 /** 252 253 @brief 253 Sets the SpeedMultiply254 Sets the speedMultiply, the factor by which the speed of the Pawn is multiplied. 254 255 @param speedMultiply 255 The multiplied Speed256 The factor by which the speed is mutiplied. 256 257 */ 257 258 void SpeedPickup::setSpeedMultiply(float speedMultiply) -
code/trunk/src/modules/pickup/items/SpeedPickup.h
r7493 r7547 39 39 40 40 #include <string> 41 #include "worldentities/pawns/Pawn.h"42 #include "worldentities/StaticEntity.h"43 41 44 42 #include "pickup/Pickup.h" … … 50 48 A Pickup which can manipulate the Speed of a Pawn. 51 49 52 There are 4 parameters that can be cosen: 53 - The @b speed @b multiplier 54 - The @b additional (forward) @b speed 55 - The @b activation @b type 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it. 56 - The @b duration The activation time of the pickup. 50 There are 5 parameters that can be cosen: 51 - The @b speedMultiply, specifies a factor by which the Spaceships speed is multiplied. The default is 1. 52 - The @b speedAdd, specifies a value that is added to the speed of the Spaceship. The default is 0. 53 - The @b activationType <em>immediate</em> or <em>onUse</em>, defines if the SpeedPickup is used when it's picked up or only after the player chooses to use it. The default is <em>immediate</em>. 54 - The @b durationType Can be either <em>once</em> or <em>continuous</em>. For <em>once</em> the SpeedPickup is just active for as long as it is used, for <em>continuous</em> the SpeedPickup is active only for the specified duration. The default is <em>once</em>. 55 - The @b duration The time in seconds the SpeedPickup is active at the most. The default is 0. 56 57 An example, how a SpeedPickup could be defined in XML could be: 58 @code 59 <SpeedPickup 60 speedMultiply = 2.0 61 speedAdd = 10.0 62 activationType = "immediate" 63 durationType = "continuous" 64 duration = 30.0 65 /> 66 @endcode 57 67 58 68 @author 59 69 Eric Beier 70 71 @ingroup PickupItems 60 72 */ 61 73 class _PickupExport SpeedPickup : public Pickup … … 71 83 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 72 84 73 inline float getDuration(void) 85 /** 86 @brief Get the duration, the time the SpeedPickup is active. 87 @return Returns the duration in seconds. 88 */ 89 inline float getDuration(void) const 74 90 { return this->duration_; } 75 inline float getSpeedAdd(void) 91 /** 92 @brief Get the value that is added to the speed of the Pawn. 93 @return Returns the speedAdd. 94 */ 95 inline float getSpeedAdd(void) const 76 96 { return this->speedAdd_; } 77 inline float getSpeedMultiply(void) 97 /** 98 @brief Get the factor by wich the speed of the Pawn is multplied. 99 @return Returns the speedMultiply. 100 */ 101 inline float getSpeedMultiply(void) const 78 102 { return this->speedMultiply_; } 79 103 80 104 protected: 81 105 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 82 83 106 void pickupTimerCallback(void); //!< Function that gets called when timer ends. 84 107 85 void setDuration(float duration); 86 void setSpeedAdd(float speedAdd); 87 void setSpeedMultiply(float speedMultiply); 108 void setDuration(float duration); //!< Sets the duration. 109 void setSpeedAdd(float speedAdd); //!< Sets the SpeedAdd, the value that is added to the speed of the Pawn. 110 void setSpeedMultiply(float speedMultiply); //!< Sets the speedMultiply, the factor by which the speed of the Pawn is multiplied. 88 111 89 112 private: … … 93 116 Timer durationTimer_; //!< Timer. 94 117 95 float duration_; //!< The health that is transferred to the Pawn.96 float speedAdd_; 97 float speedMultiply_; 118 float duration_; //!< The time in seconds for which the SpeedPickup stays active. 119 float speedAdd_; //!< The value that is added to the speed of the Pawn. 120 float speedMultiply_; //!< The factor by which the speed of the Pawn is multiplied. 98 121 }; 99 122 }
Note: See TracChangeset
for help on using the changeset viewer.