Changeset 6641 for code/branches/ppspickups2
- Timestamp:
- Mar 29, 2010, 4:33:22 PM (15 years ago)
- Location:
- code/branches/ppspickups2
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ppspickups2/data/levels/pickup_pps_invi.oxw
r6555 r6641 7 7 include("templates/spaceship_assff.oxt") 8 8 include("templates/spaceship_pirate.oxt") 9 include("templates/pickup_representation_templates .oxt")9 include("templates/pickup_representation_templates_invisible.oxt") 10 10 ?> 11 11 … … 20 20 21 21 <?lua 22 include("includes/pickups .oxi")22 include("includes/pickups_invisible.oxi") 23 23 ?> 24 25 <!-- 26 <PickupSpawner position="-100,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10"> 24 25 <PickupSpawner position="-75,0,-100" triggerDistance="10" respawnTime="5" maxSpawnedItems="10"> 27 26 <pickup> 28 <MetaPickup metaType="drop" /> 29 </pickup> 30 </PickupSpawner> 31 32 <PickupSpawner position="-75,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10"> 33 <pickup> 34 <MetaPickup metaType="use" /> 27 <InvisiblePickup template=invisiblepickup /> 35 28 </pickup> 36 29 </PickupSpawner> 37 30 38 <PickupSpawner position="-50,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">39 <pickup>40 <HealthPickup health=50 healthRate=5 durationType=continuous activationType=immediate healthType=permanent />41 </pickup>42 </PickupSpawner>43 44 <PickupSpawner position="-25,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">45 <pickup>46 <HealthPickup template=smallhealthpickup />47 </pickup>48 </PickupSpawner>49 50 <PickupSpawner position="0,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">51 <pickup>52 <HealthPickup template=mediumhealthpickup />53 </pickup>54 </PickupSpawner>55 56 <PickupSpawner position="25,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">57 <pickup>58 <HealthPickup template=hugehealthpickup />59 </pickup>60 </PickupSpawner>61 62 <PickupSpawner position="50,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">63 <pickup>64 <HealthPickup template=crazyhealthpickup />65 </pickup>66 </PickupSpawner>67 68 <PickupSpawner position="75,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">69 <pickup>70 <PickupCollection template=doublepickup />71 </pickup>72 </PickupSpawner>73 74 <PickupSpawner position="100,100,100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">75 <pickup>76 <HealthPickup health=50 healthRate=5 durationType=continuous activationType=immediate healthType=limited />77 </pickup>78 </PickupSpawner>79 -->80 31 81 32 <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" /> -
code/branches/ppspickups2/src/modules/pickup/Pickup.cc
r6540 r6641 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) /*TODO*/ 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/ppspickups2/src/modules/pickup/Pickup.h
r6540 r6641 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/ppspickups2/src/modules/pickup/items/CMakeLists.txt
r6524 r6641 2 2 HealthPickup.cc 3 3 MetaPickup.cc 4 InvisiblePickup.cc 4 5 ) -
code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.cc
r6555 r6641 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Benedict Simlinger 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 @file InvisiblePickup.cc 31 @brief Implementation of the InvisiblePickup class. 32 */ 33 34 #include "InvisiblePickup.h" 35 36 #include "core/CoreIncludes.h" 37 #include "core/XMLPort.h" 38 #include "util/StringUtils.h" 39 40 #include "worldentities/pawns/Pawn.h" 41 #include "pickup/PickupIdentifier.h" 42 43 #include <sstream> 44 45 namespace orxonox 46 { 47 48 49 CreateFactory(InvisiblePickup); 50 51 /** 52 @brief 53 Constructor. Registers the object and initializes the member variables. 54 */ 55 InvisiblePickup::InvisiblePickup(BaseObject* creator) : Pickup(creator) 56 { 57 RegisterObject(InvisiblePickup); 58 //! Defines who is allowed to pick up the pickup. 59 this->initialize(); 60 } 61 62 /** 63 @brief 64 Destructor. 65 */ 66 InvisiblePickup::~InvisiblePickup() 67 { 68 } 69 70 71 void InvisiblePickup::initializeIdentifier(void) 72 { 73 std::stringstream stream; 74 stream << this->getDuration(); 75 std::string type1 = "duration"; 76 std::string val1 = stream.str(); 77 this->pickupIdentifier_->addParameter(type1, val1); 78 } 79 80 /** 81 @brief 82 Initializes the member variables. 83 */ 84 void InvisiblePickup::initialize(void) 85 { 86 this->duration_ = 0.0; 87 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 88 } 89 90 91 92 93 /** 94 @brief 95 Method for creating a HealthPickup object through XML. 96 */ 97 void InvisiblePickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode) 98 { 99 SUPER(InvisiblePickup, XMLPort, xmlelement, mode); 100 XMLPortParam(InvisiblePickup, "duration", setDuration, getDuration, xmlelement, mode); 101 102 this->initializeIdentifier(); 103 } 104 105 106 /** 107 @brief 108 Is called when the pickup has transited from used to unused or the other way around. 109 */ 110 void InvisiblePickup::changedUsed(void) 111 { 112 SUPER(InvisiblePickup, changedUsed); 113 114 115 //! If the pickup is not picked up nothing must be done. 116 if(!this->isPickedUp()) 117 return; 118 if (this->isUsed()) 119 { 120 this->setInvisible(true); 121 this->startPickupTimer(this->getDuration()); 122 } 123 else 124 this->setInvisible(false); 125 126 } 127 128 /** 129 @brief 130 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 131 @return 132 A pointer to the Pawn, or NULL if the conversion failed. 133 */ 134 Pawn* InvisiblePickup::carrierToPawnHelper(void) 135 { 136 PickupCarrier* carrier = this->getCarrier(); 137 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 138 139 if(pawn == NULL) 140 { 141 COUT(1) << "Invalid PickupCarrier in InvisiblePickup." << std::endl; 142 } 143 return pawn; 144 } 145 146 /** 147 @brief 148 Creates a duplicate of the input OrxonoxClass. 149 @param item 150 A pointer to the Orxonox class. 151 */ 152 void InvisiblePickup::clone(OrxonoxClass*& item) 153 { 154 if(item == NULL) 155 item = new InvisiblePickup(this); 156 157 SUPER(InvisiblePickup, clone, item); 158 159 InvisiblePickup* pickup = dynamic_cast<InvisiblePickup*>(item); 160 pickup->setDuration(this->getDuration()); 161 pickup->initializeIdentifier(); 162 } 163 164 165 166 167 168 /** 169 @brief 170 Sets the invisibility. 171 @param health 172 The invisibility. 173 */ 174 bool InvisiblePickup::setInvisible(bool invisibility) 175 { 176 177 Pawn* pawn = this->carrierToPawnHelper(); 178 pawn->setVisible(!invisibility); 179 return 0; 180 } 181 182 183 184 /** 185 @brief 186 Sets the duration. 187 @param duration 188 The duration 189 */ 190 void InvisiblePickup::setDuration(float duration) 191 { 192 if(duration >= 0.0f) 193 { 194 this->duration_ = duration; 195 } 196 else 197 { 198 COUT(1) << "Invalid duration in InvisiblePickup." << std::endl; 199 this->duration_ = 0; 200 } 201 } 202 203 204 205 void InvisiblePickup::PickupTimerCallBack(void){ 206 this->setInvisible(false); 207 } 208 209 } -
code/branches/ppspickups2/src/modules/pickup/items/InvisiblePickup.h
r6555 r6641 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Benedict Simlinger 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 @file InvisiblePickup.h 31 @brief Declaration of the InvisiblePickup class. 32 */ 33 34 #ifndef _InvisiblePickup_H__ 35 #define _InvisiblePickup_H__ 36 37 #include "pickup/PickupPrereqs.h" 38 39 #include <string> 40 #include <worldentities/pawns/Pawn.h> 41 #include "worldentities/StaticEntity.h" 42 43 #include "pickup/Pickup.h" 44 45 namespace orxonox { 46 47 /** 48 @brief 49 A pickup that makes the Pawn invisible. 50 There are 2 parameters that can be chosen: 51 1) The activation type: It can be chosen to be either 'immediate' or 'onUse'. 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. 52 2) The duration type: It can be chosen how long the Pawn will be invisibel. 53 @author 54 Benedict Simlinger 55 */ 56 class _PickupExport InvisiblePickup : public Pickup 57 { 58 public: 59 60 InvisiblePickup(BaseObject* creator); //!< Constructor. 61 virtual ~InvisiblePickup(); //!< Destructor. 62 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); //!< Method for creating a HealthPickup object through XML. 63 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 64 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 65 66 /** 67 @brief Checks wether the Pawn is invisible. 68 @return Returns if the Pawn is invisible. 69 */ 70 inline bool getInvisibility(bool) 71 { return this->invisible_; } 72 inline float getDuration() 73 {return this->duration_;} 74 75 protected: 76 bool setInvisible(bool invisibility); //!< Set the Pawn to be invisible or visible again. 77 void setDuration(float duration); 78 void initializeIdentifier(void); 79 80 private: 81 void initialize(void); //!< Initializes the member variables. 82 Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 83 void PickupTimerCallBack(void); //!< Function that gets called when the timer ends. 84 bool invisible_; //!< Helper to remember wether the Pawn is invisible. 85 float duration_; //! Duration of invisibility. 86 }; 87 } 88 89 #endif // _InvisiblePickup_H__ -
code/branches/ppspickups2/src/orxonox/interfaces/PickupCarrier.h
r6540 r6641 48 48 { 49 49 50 //! Pre-declarations.51 class Pickup;52 class HealthPickup;53 class MetaPickup;54 50 55 51 /** … … 66 62 friend class HealthPickup; 67 63 friend class MetaPickup; 64 friend class InvisiblePickup; 68 65 69 66 public:
Note: See TracChangeset
for help on using the changeset viewer.