Changeset 7547 for code/trunk/src/modules/pickup/items
- Timestamp:
- Oct 16, 2010, 12:37:09 PM (14 years ago)
- Location:
- code/trunk/src/modules/pickup/items
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
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.