- Timestamp:
- May 10, 2010, 4:23:29 PM (15 years ago)
- Location:
- code/branches/ppspickups3
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ppspickups3/data/levels/includes/pickups.oxi
r6725 r6884 1 <!-- Shield pickups --> 2 3 <PickupRepresentation 4 pickupName = "Super Shield Pickup" 5 pickupDescription = "Gives you a shield with 1000000 helath points for 5 minutes" 6 inventoryRepresentation = "SmallHealth" 7 spawnerTemplate = "supershieldpickupRepresentation" 8 > 9 <pickup> 10 <ShieldPickup template=supershieldpickup /> 11 </pickup> 12 </PickupRepresentation> 1 13 2 14 <!-- Health pickups --> -
code/branches/ppspickups3/data/levels/pickup.oxw
r6731 r6884 26 26 <SpawnPoint position="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /> 27 27 28 29 <!-- Shield pickups --> 30 31 <PickupSpawner position="-50,50,-100" triggerDistance="10" respawnTime="5" maxSpawnedItems="10"> 32 <pickup> 33 <ShieldPickup template=supershieldpickup /> 34 </pickup> 35 </PickupSpawner> 36 28 37 <!-- Health pickups --> 29 38 -
code/branches/ppspickups3/data/levels/templates/pickup_representation_templates.oxt
r6712 r6884 1 <!-- Shield pickups: --> 2 3 <Template name=supershieldpickupRepresentation> 4 <PickupRepresentation> 5 <spawner-representation> 6 <StaticEntity> 7 <attached> 8 <Billboard position="0,0,0" colour="1,1,1" material="Sphere2" scale=0.1> 9 <attached> 10 <Billboard position="0,0,0" colour="1,1,1" material="Shield" scale=10 /> 11 </attached> 12 </Billboard> 13 </attached> 14 </StaticEntity> 15 </spawner-representation> 16 </PickupRepresentation> 17 </Template> 18 19 <Template name=supershieldpickup> 20 <ShieldPickup 21 absorption = 1 22 duration = 6000 23 shieldhealth = 1000000 24 activationType = "immediate" 25 durationType = "once" 26 /> 27 </Template> 1 28 2 29 <!-- Health pickups: --> -
code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.cc
r6869 r6884 71 71 /** 72 72 @brief 73 Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 74 @return 75 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 } 88 89 /** 90 @brief 73 91 Initializes the member variables. 74 92 */ … … 76 94 { 77 95 this->duration_ = 0.0f; 96 this->shieldAbsorption_ = 0.0f; 97 this->shieldHealth_ = 0.0f; 78 98 79 99 this->addTarget(ClassIdentifier<Engine>::getIdentifier()); … … 92 112 this->pickupIdentifier_->addParameter(type1, val1); 93 113 94 // stream.clear(); 95 // stream << this->getShieldAdd(); 96 // std::string type2 = "ShieldAdd"; 97 // std::string val2 = stream.str(); 98 // this->pickupIdentifier_->addParameter(type2, val2); 114 stream.clear(); 115 stream << this->getShieldHealth(); 116 std::string type2 = "ShieldHealth"; 117 std::string val2 = stream.str(); 118 this->pickupIdentifier_->addParameter(type2, val2); 119 120 stream.clear(); 121 stream << this->getShieldAbsorption(); 122 std::string type3 = "ShieldAbsorption"; 123 std::string val3 = stream.str(); 124 this->pickupIdentifier_->addParameter(type3, val3); 99 125 100 126 } … … 109 135 110 136 XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode); 137 XMLPortParam(ShieldPickup, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode); 138 XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode); 111 139 112 140 this->initializeIdentifier(); … … 124 152 if(!this->isPickedUp()) 125 153 return; 154 155 Pawn* pawn = this->carrierToPawnHelper(); 156 if(pawn == NULL) 157 this->destroy(); 158 159 //! If the pickup has transited to used. 160 if(this->isUsed()) 161 { 162 if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() > 0.0f) 163 { 164 this->getTimer()->unpauseTimer(); 165 } 166 else 167 { 168 this->startPickupTimer(this->getDuration()); 169 } 170 pawn->setShieldAbsorption(this->getShieldAbsorption()); 171 pawn->setShieldHealth(this->getShieldHealth()); 172 } 173 else 174 { 175 pawn->setShieldAbsorption(0.0f); 176 this->setShieldHealth(pawn->getShieldHealth()); 177 pawn->setShieldHealth(0.0f); 178 179 if(this->isOnce()) 180 { 181 if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration()) 182 { 183 this->destroy(); 184 } 185 else 186 { 187 this->getTimer()->pauseTimer(); 188 } 189 } 190 } 126 191 } 127 192 … … 141 206 ShieldPickup* pickup = dynamic_cast<ShieldPickup*>(item); 142 207 pickup->setDuration(this->getDuration()); 143 208 pickup->setShieldAbsorption(this->getShieldAbsorption()); 209 pickup->setShieldHealth(this->getShieldHealth()); 144 210 pickup->initializeIdentifier(); 211 } 212 213 /** 214 @brief 215 Sets the percentage the shield absorbs of the dealt damage. 216 @param shieldAbsorption 217 The shieldAbsorption. Has to be between 0 and 1 218 */ 219 void ShieldPickup::setShieldAbsorption(float shieldAbsorption) 220 { 221 if (shieldAbsorption>=0 && shieldAbsorption<=1) 222 { 223 this->shieldAbsorption_=shieldAbsorption; 224 } 225 else 226 { 227 COUT(1) << "Invalid Absorption in ShieldPickup." << std::endl; 228 this->shieldAbsorption_=0; 229 } 230 } 231 232 /** 233 @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 } 145 249 } 146 250 -
code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.h
r6869 r6884 1 1 2 /* 2 3 * ORXONOX - the hottest 3D action shooter ever to exist … … 49 50 A Pickup which can add a Shield to the Pawn. 50 51 51 1) The Shield multiplier: 52 The additional (forward) Shield: 53 2) The activation type: 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it.52 1) The percentage: The percentage the shield takes from the damage dealt to a Pawn 53 2) The hit points: The amount of damage points a shield can teake before collapsing 54 3) The activation type: 'immediate' or 'onUse'. defines if the item is used when it's picked up or only after the player chooses to use it. 54 55 4) The duration: the activation time of the pickup. 55 56 … … 71 72 inline float getDuration(void) 72 73 { return this->duration_; } 73 74 inline float getShieldHealth() 75 { return this->shieldHealth_; } 76 inline float getShieldAbsorption() 77 { return this->shieldAbsorption_; } 74 78 75 79 protected: 76 80 void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup. 77 81 78 82 virtual void pickupTimerCallback(void); //!< Function that gets called when timer ends. 79 83 80 84 void setDuration(float duration); 81 85 void setShieldHealth(float shieldHealth); 86 void setShieldAbsorption(float shieldAbsorption); 82 87 83 88 private: 84 89 void initialize(void); //!< Initializes the member variables. 85 Engine* carrierToEngineHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.90 Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails. 86 91 87 92 float duration_; //!< The health that is transferred to the Pawn. 93 float shieldHealth_; 94 float shieldAbsorption_; // Has to be between 0 and 1 95 88 96 }; 89 97 } -
code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.cc
r6711 r6884 64 64 this->maxHealth_ = 0; 65 65 this->initialHealth_ = 0; 66 this->shieldHealth_ = 0; 67 this->shieldAbsorption_ = 0; 66 68 67 69 this->lastHitOriginator_ = 0; … … 105 107 XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200); 106 108 XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100); 109 110 XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0); 111 XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0); 112 107 113 XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); 108 114 XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); … … 116 122 void Pawn::registerVariables() 117 123 { 118 registerVariable(this->bAlive_, VariableDirection::ToClient); 119 registerVariable(this->health_, VariableDirection::ToClient); 120 registerVariable(this->initialHealth_, VariableDirection::ToClient); 121 registerVariable(this->bReload_, VariableDirection::ToServer); 122 registerVariable(this->aimPosition_, Bidirectionality::ServerMaster, 0, true); 124 registerVariable(this->bAlive_, VariableDirection::ToClient); 125 registerVariable(this->health_, VariableDirection::ToClient); 126 registerVariable(this->initialHealth_, VariableDirection::ToClient); 127 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 128 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 129 registerVariable(this->bReload_, VariableDirection::ToServer); 130 registerVariable(this->aimPosition_, Bidirectionality::ServerMaster, 0, true); 123 131 } 124 132 … … 159 167 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 160 168 { 161 this->setHealth(this->health_ - damage); 169 //share the dealt damage to the shield and the Pawn. 170 float shielddamage = damage*this->shieldAbsorption_; 171 float healthdamage = damage*(1-this->shieldAbsorption_); 172 173 // In case the shield can not take all the shield damage. 174 if (shielddamage > this->getShieldHealth()) 175 { 176 healthdamage += shielddamage-this->getShieldHealth(); 177 this->setShieldHealth(0); 178 } 179 180 this->setHealth(this->health_ - healthdamage); 181 182 if (this->getShieldHealth() > 0) 183 { 184 this->setShieldHealth(this->shieldHealth_ - shielddamage); 185 } 186 162 187 this->lastHitOriginator_ = originator; 163 188 … … 165 190 } 166 191 } 167 192 168 193 void Pawn::hit(Pawn* originator, const Vector3& force, float damage) 169 194 { -
code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.h
r6711 r6884 73 73 { return this->initialHealth_; } 74 74 75 inline void setShieldHealth(float shieldHealth) 76 { this->shieldHealth_ = shieldHealth; } 77 inline float getShieldHealth() 78 { return this->shieldHealth_; } 79 80 inline void setShieldAbsorption(float shieldAbsorption) 81 { this->shieldAbsorption_ = shieldAbsorption; } 82 inline float getShieldAbsorption() 83 { return this->shieldAbsorption_; } 84 75 85 inline ControllableEntity* getLastHitOriginator() const 76 86 { return this->lastHitOriginator_; } … … 141 151 float maxHealth_; 142 152 float initialHealth_; 153 float shieldHealth_; 154 float shieldAbsorption_; // Has to be between 0 and 1 143 155 144 156 Pawn* lastHitOriginator_;
Note: See TracChangeset
for help on using the changeset viewer.