Changeset 6607 for code/branches/ppspickups1/src/modules
- Timestamp:
- Mar 22, 2010, 10:45:09 PM (15 years ago)
- Location:
- code/branches/ppspickups1/src/modules/pickup
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ppspickups1/src/modules/pickup/Pickup.cc
r6540 r6607 39 39 #include "DroppedPickup.h" 40 40 41 #include "tools/Timer.h" 42 41 43 namespace orxonox 42 44 { 43 45 44 46 /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate"; 45 47 /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse"; 46 48 /*static*/ const std::string Pickup::durationTypeOnce_s = "once"; 47 49 /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous"; 48 50 49 51 Pickup::Pickup(BaseObject* creator) : BaseObject(creator) 50 52 { 51 53 RegisterObject(Pickup); 52 54 53 55 this->initialize(); 54 56 } 55 57 56 58 Pickup::~Pickup() 57 59 { 58 59 } 60 60 61 } 62 61 63 /** 62 64 @brief … … 68 70 this->durationType_ = pickupDurationType::once; 69 71 } 70 72 71 73 /** 72 74 @brief … … 74 76 */ 75 77 void Pickup::initializeIdentifier(void) 76 { 78 { 77 79 std::string val1 = this->getActivationType(); 78 80 std::string type1 = "activationType"; 79 81 this->pickupIdentifier_->addParameter(type1, val1); 80 82 81 83 std::string val2 = this->getDurationType(); 82 84 std::string type2 = "durationType"; 83 85 this->pickupIdentifier_->addParameter(type2, val2); 84 86 } 85 87 86 88 /** 87 89 @brief … … 94 96 XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode); 95 97 XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode); 96 98 97 99 this->initializeIdentifier(); 98 100 } 99 101 100 102 /** 101 103 @brief … … 116 118 } 117 119 } 118 120 119 121 /** 120 122 @brief … … 135 137 } 136 138 } 137 139 138 140 /** 139 141 @brief … … 157 159 } 158 160 } 159 161 160 162 /** 161 163 @brief … … 179 181 } 180 182 } 181 183 182 184 /** 183 185 @brief … … 188 190 { 189 191 SUPER(Pickup, changedPickedUp); 190 192 191 193 //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up. 192 194 if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate()) … … 195 197 } 196 198 } 197 199 198 200 /** 199 201 @brief … … 206 208 if(item == NULL) 207 209 item = new Pickup(this); 208 210 209 211 SUPER(Pickup, clone, item); 210 212 211 213 Pickup* pickup = dynamic_cast<Pickup*>(item); 212 214 pickup->setActivationTypeDirect(this->getActivationTypeDirect()); 213 215 pickup->setDurationTypeDirect(this->getDurationTypeDirect()); 214 216 215 217 pickup->initializeIdentifier(); 216 218 } 217 219 218 220 /** 219 221 @brief … … 231 233 return true; 232 234 } 233 235 236 /** 237 @brief 238 Starts the Pickup duration Timer. 239 */ 240 bool Pickup::startPickupTimer(float durationTime) 241 { 242 if (durationTime<=0) 243 { 244 COUT(1) << "Invalid durationTime in pickup." << std::endl; 245 return false; 246 } 247 if (false) /* How to check if Timer already running? */ 248 { 249 COUT(1) << "Pickup durationTimer already in use." << std::endl; 250 return false; 251 } 252 this->durationTimer_.setTimer(durationTime, false, createExecutor(createFunctor(&Pickup::PickupTimerCallBack, this))); 253 return true; 254 } 234 255 } -
code/branches/ppspickups1/src/modules/pickup/Pickup.h
r6540 r6607 42 42 #include "interfaces/Pickupable.h" 43 43 44 #include "tools/Timer.h" 45 44 46 namespace orxonox 45 47 { … … 54 56 }; 55 57 } 56 58 57 59 //! Enum for the duration tyoe. 58 60 namespace pickupDurationType … … 64 66 }; 65 67 } 66 68 67 69 /** 68 70 @brief … … 74 76 class _PickupExport Pickup : public Pickupable, public BaseObject 75 77 { 76 78 77 79 protected: 78 80 Pickup(BaseObject* creator); //!< Constructor. 79 81 80 82 public: 81 83 virtual ~Pickup(); //!< Destructor. 82 84 83 85 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 84 86 85 87 /** 86 88 @brief Get the activation type of the pickup. … … 95 97 inline pickupDurationType::Value getDurationTypeDirect(void) 96 98 { return this->durationType_; } 97 99 98 100 const std::string& getActivationType(void); //!< Get the activation type of the pickup. 99 101 const std::string& getDurationType(void); //!< Get the duration type of the pickup. 100 102 101 103 /** 102 104 @brief Get whether the activation type is 'immediate'. … … 123 125 inline bool isContinuous(void) 124 126 { return this->getDurationTypeDirect() == pickupDurationType::continuous; } 125 127 126 128 virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around. 127 129 128 130 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the Pickup. 129 131 130 132 protected: 131 133 void initializeIdentifier(void); 132 134 133 135 virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable. 134 136 137 bool startPickupTimer(float durationTime); 138 139 virtual void PickupTimerCallBack(void) {} 140 135 141 /** 136 142 @brief Set the activation type of the pickup. … … 145 151 inline void setDurationTypeDirect(pickupDurationType::Value type) 146 152 { this->durationType_ = type; } 147 153 148 154 void setActivationType(const std::string& type); //!< Set the activation type of the pickup. 149 155 void setDurationType(const std::string& type); //!< Set the duration type of the pickup 150 156 151 157 private: 152 158 void initialize(void); //!< Initializes the member variables. 153 159 154 160 pickupActivationType::Value activationType_; //!< The activation type of the Pickup. 155 161 pickupDurationType::Value durationType_; //!< The duration type of the pickup. 156 162 157 163 static const std::string activationTypeImmediate_s; 158 164 static const std::string activationTypeOnUse_s; 159 165 static const std::string durationTypeOnce_s; 160 166 static const std::string durationTypeContinuous_s; 161 167 168 float durationTime_; 169 Timer durationTimer_; 162 170 }; 163 171 164 172 } 165 173 #endif // _Pickup_H__ -
code/branches/ppspickups1/src/modules/pickup/PickupPrereqs.h
r6524 r6607 73 73 class PickupRepresentation; 74 74 class PickupSpawner; 75 75 76 76 //items 77 77 class HealthPickup; 78 78 class MetaPickup; 79 79 class SpeedPickup; 80 80 81 } 81 82 -
code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.cc
r6575 r6607 38 38 #include "util/StringUtils.h" 39 39 40 #include "worldentities/pawns/Pawn.h" 40 #include "worldentities/pawns/SpaceShip.h" 41 #include "items/Engine.h" 41 42 #include "pickup/PickupIdentifier.h" 42 43 … … 123 124 /** 124 125 @brief 125 Is called every tick.126 Does count down the duration of the SpeedPickup.127 @param dt128 The duration of the last tick.129 */130 void SpeedPickup::tick(float dt)131 {132 if(this->isUsed())133 {134 Pawn* pawn = this->carrierToPawnHelper();135 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.136 this->destroy();137 138 //! Calculate the remaining duration of the Pickup139 float duration=this->getDuration()-dt;140 this->setDuration(duration);141 142 //! If duration is over143 if(this->getDuration() < 0)144 {145 this->setUsed(false);146 }147 }148 }149 150 /**151 @brief152 126 Is called when the pickup has transited from used to unused or the other way around. 153 127 */ … … 163 137 if(this->isUsed()) 164 138 { 165 if(this->isOnce()) 166 { 167 Pawn* pawn = this->carrierToPawnHelper(); 168 if(pawn == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 169 this->destroy(); 170 171 //! The pickup has been used up. 172 this->setUsed(false); 173 } 174 } 175 else 176 { 177 //! If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused. 178 if(this->isOnce() || (this->isContinuous() && this->getDuration() < 0)) 179 { 139 this->startPickupTimer(this->getDuration()); 140 141 Engine* engine = this->carrierToEngineHelper(); 142 if(engine == NULL) //!< If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 180 143 this->destroy(); 181 } 182 } 183 } 144 engine->setSpeedAdd(this->getSpeedAdd()); 145 engine->setSpeedMultiply(this->getSpeedMultiply()); 146 } 147 } 148 149 184 150 185 151 /** … … 189 155 A pointer to the Pawn, or NULL if the conversion failed. 190 156 */ 191 Pawn* SpeedPickup::carrierToPawnHelper(void)157 Engine* SpeedPickup::carrierToEngineHelper(void) 192 158 { 193 159 PickupCarrier* carrier = this->getCarrier(); 194 Pawn* pawn = dynamic_cast<Pawn*>(carrier);195 196 if( pawn== NULL)160 SpaceShip* ship = dynamic_cast<SpaceShip*>(carrier); 161 162 if(ship == NULL) 197 163 { 198 164 COUT(1) << "Invalid PickupCarrier in SpeedPickup." << std::endl; 199 165 } 200 201 return pawn; 166 else 167 { 168 return ship->getEngine(); 169 } 170 171 return 0; 202 172 } 203 173 … … 238 208 { 239 209 COUT(1) << "Invalid duration in SpeedPickup." << std::endl; 240 this->duration_ = 0 .0;210 this->duration_ = 0; 241 211 } 242 212 } … … 250 220 void SpeedPickup::setSpeedAdd(float speedAdd) 251 221 { 252 if(speedAdd > 0.0f)222 if(speedAdd >= 0.0f) 253 223 { 254 224 this->speedAdd_ = speedAdd; … … 269 239 void SpeedPickup::setSpeedMultiply(float speedMultiply) 270 240 { 271 if(speedMultiply != 0 .0f)241 if(speedMultiply != 0) 272 242 { 273 243 this->speedMultiply_ = speedMultiply; … … 279 249 } 280 250 } 251 252 void SpeedPickup::PickupTimerCallBack(void) { 253 COUT(2) << "Timer ended!" << std::endl; 254 } 281 255 } -
code/branches/ppspickups1/src/modules/pickup/items/SpeedPickup.h
r6574 r6607 57 57 Eric Beier 58 58 */ 59 class _PickupExport SpeedPickup : public Pickup , public Tickable59 class _PickupExport SpeedPickup : public Pickup 60 60 { 61 61 public: … … 65 65 66 66 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML. 67 virtual void tick(float dt); //!< Is called every tick.68 67 69 68 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. … … 80 79 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 81 80 82 void setDuration(float duration); //!< Sets the duration81 void setDuration(float duration); 83 82 void setSpeedAdd(float speedAdd); 84 83 void setSpeedMultiply(float speedMultiply); 85 84 86 87 85 private: 88 86 void initialize(void); //!< Initializes the member variables. 89 Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 87 void PickupTimerCallBack(void); //!< Function that gets called when timer ends. 88 Engine* carrierToEngineHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 90 89 91 90 float duration_; //!< The health that is transferred to the Pawn.
Note: See TracChangeset
for help on using the changeset viewer.