[Orxonox-commit 2168] r6884 - in code/branches/ppspickups3: data/levels data/levels/includes data/levels/templates src/modules/pickup/items src/orxonox/worldentities/pawns
benedict at orxonox.net
benedict at orxonox.net
Mon May 10 16:23:29 CEST 2010
Author: benedict
Date: 2010-05-10 16:23:29 +0200 (Mon, 10 May 2010)
New Revision: 6884
Modified:
code/branches/ppspickups3/data/levels/includes/pickups.oxi
code/branches/ppspickups3/data/levels/pickup.oxw
code/branches/ppspickups3/data/levels/templates/pickup_representation_templates.oxt
code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.cc
code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.h
code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.cc
code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.h
Log:
did the shield pickup. upload for testing
Modified: code/branches/ppspickups3/data/levels/includes/pickups.oxi
===================================================================
--- code/branches/ppspickups3/data/levels/includes/pickups.oxi 2010-05-10 14:17:20 UTC (rev 6883)
+++ code/branches/ppspickups3/data/levels/includes/pickups.oxi 2010-05-10 14:23:29 UTC (rev 6884)
@@ -1,4 +1,16 @@
+<!-- Shield pickups -->
+<PickupRepresentation
+ pickupName = "Super Shield Pickup"
+ pickupDescription = "Gives you a shield with 1000000 helath points for 5 minutes"
+ inventoryRepresentation = "SmallHealth"
+ spawnerTemplate = "supershieldpickupRepresentation"
+>
+ <pickup>
+ <ShieldPickup template=supershieldpickup />
+ </pickup>
+</PickupRepresentation>
+
<!-- Health pickups -->
<PickupRepresentation
Modified: code/branches/ppspickups3/data/levels/pickup.oxw
===================================================================
--- code/branches/ppspickups3/data/levels/pickup.oxw 2010-05-10 14:17:20 UTC (rev 6883)
+++ code/branches/ppspickups3/data/levels/pickup.oxw 2010-05-10 14:23:29 UTC (rev 6884)
@@ -25,6 +25,15 @@
<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" />
<SpawnPoint position="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+
+ <!-- Shield pickups -->
+
+ <PickupSpawner position="-50,50,-100" triggerDistance="10" respawnTime="5" maxSpawnedItems="10">
+ <pickup>
+ <ShieldPickup template=supershieldpickup />
+ </pickup>
+ </PickupSpawner>
+
<!-- Health pickups -->
<PickupSpawner position="-25,0,-100" triggerDistance="10" respawnTime="30" maxSpawnedItems="10">
Modified: code/branches/ppspickups3/data/levels/templates/pickup_representation_templates.oxt
===================================================================
--- code/branches/ppspickups3/data/levels/templates/pickup_representation_templates.oxt 2010-05-10 14:17:20 UTC (rev 6883)
+++ code/branches/ppspickups3/data/levels/templates/pickup_representation_templates.oxt 2010-05-10 14:23:29 UTC (rev 6884)
@@ -1,4 +1,31 @@
+<!-- Shield pickups: -->
+<Template name=supershieldpickupRepresentation>
+ <PickupRepresentation>
+ <spawner-representation>
+ <StaticEntity>
+ <attached>
+ <Billboard position="0,0,0" colour="1,1,1" material="Sphere2" scale=0.1>
+ <attached>
+ <Billboard position="0,0,0" colour="1,1,1" material="Shield" scale=10 />
+ </attached>
+ </Billboard>
+ </attached>
+ </StaticEntity>
+ </spawner-representation>
+ </PickupRepresentation>
+</Template>
+
+<Template name=supershieldpickup>
+ <ShieldPickup
+ absorption = 1
+ duration = 6000
+ shieldhealth = 1000000
+ activationType = "immediate"
+ durationType = "once"
+ />
+</Template>
+
<!-- Health pickups: -->
<Template name=smallhealthpickupRepresentation>
@@ -137,110 +164,110 @@
<!-- Speed pickups -->
-<Template name=smallspeedpickupRepresentation>
- <PickupRepresentation>
- <spawner-representation>
- <StaticEntity>
- <attached>
- <Billboard position="0,0,0" colour="0.99,0.96,0.52" material="Sphere2" scale=0.1>
- <attached>
- <Billboard position="0,0,0" colour="0.98,0.94,0.22" material="3arrowsup" scale=0.3 />
- </attached>
- </Billboard>
- </attached>
- </StaticEntity>
- </spawner-representation>
- </PickupRepresentation>
-</Template>
-
-<Template name=smallspeedpickup>
- <SpeedPickup
- duration = 10.0
- speedAdd = 0.0
- SpeedMultiply = 10.0
- activationType = "immediate"
- durationType = "once"
- />
-</Template>
-
-<Template name=mediumspeedpickupRepresentation>
- <PickupRepresentation>
- <spawner-representation>
- <StaticEntity>
- <attached>
- <Billboard position="0,0,0" colour="0.99,0.96,0.52" material="Sphere2" scale=0.1>
- <attached>
- <Billboard position="0,0,0" colour="0.98,0.94,0.22" material="3arrowsup" scale=0.5 />
- </attached>
- </Billboard>
- </attached>
- </StaticEntity>
- </spawner-representation>
- </PickupRepresentation>
-</Template>
-
-<Template name=mediumspeedpickup>
- <SpeedPickup
- duration = 10.0
- speedAdd = 0.0
- SpeedMultiply = 25.0
- activationType = "immediate"
- durationType = "once"
- />
-</Template>
-
-<Template name=hugespeedpickupRepresentation>
- <PickupRepresentation>
- <spawner-representation>
- <StaticEntity>
- <attached>
- <Billboard position="0,0,0" colour="0.99,0.96,0.52" material="Sphere2" scale=0.1>
- <attached>
- <Billboard position="0,0,0" colour="0.98,0.94,0.22" material="3arrowsup" scale=0.7 />
- </attached>
- </Billboard>
- </attached>
- </StaticEntity>
- </spawner-representation>
- </PickupRepresentation>
-</Template>
-
-<Template name=hugespeedpickup>
- <SpeedPickup
- duration = 10.0
- speedAdd = 0.0
- SpeedMultiply = 50.0
- activationType = "immediate"
- durationType = "once"
- />
-</Template>
-
-<Template name=smalljumppickupRepresentation>
- <PickupRepresentation>
- <spawner-representation>
- <StaticEntity>
- <attached>
- <Billboard position="0,0,0" colour="0.99,0.96,0.52" material="Sphere2" scale=0.1>
- <attached>
- <Billboard position="0,0,0" colour="1,0,0" material="3arrowsup" scale=0.3 />
- </attached>
- </Billboard>
- </attached>
- </StaticEntity>
- </spawner-representation>
- </PickupRepresentation>
-</Template>
-
-<Template name=smalljumppickup>
- <SpeedPickup
- duration = 0.7
- speedAdd = 5000.0
- SpeedMultiply = 1.0
- activationType = "immediate"
- durationType = "once"
- />
+<Template name=smallspeedpickupRepresentation>
+ <PickupRepresentation>
+ <spawner-representation>
+ <StaticEntity>
+ <attached>
+ <Billboard position="0,0,0" colour="0.99,0.96,0.52" material="Sphere2" scale=0.1>
+ <attached>
+ <Billboard position="0,0,0" colour="0.98,0.94,0.22" material="3arrowsup" scale=0.3 />
+ </attached>
+ </Billboard>
+ </attached>
+ </StaticEntity>
+ </spawner-representation>
+ </PickupRepresentation>
</Template>
+<Template name=smallspeedpickup>
+ <SpeedPickup
+ duration = 10.0
+ speedAdd = 0.0
+ SpeedMultiply = 10.0
+ activationType = "immediate"
+ durationType = "once"
+ />
+</Template>
+
+<Template name=mediumspeedpickupRepresentation>
+ <PickupRepresentation>
+ <spawner-representation>
+ <StaticEntity>
+ <attached>
+ <Billboard position="0,0,0" colour="0.99,0.96,0.52" material="Sphere2" scale=0.1>
+ <attached>
+ <Billboard position="0,0,0" colour="0.98,0.94,0.22" material="3arrowsup" scale=0.5 />
+ </attached>
+ </Billboard>
+ </attached>
+ </StaticEntity>
+ </spawner-representation>
+ </PickupRepresentation>
+</Template>
+
+<Template name=mediumspeedpickup>
+ <SpeedPickup
+ duration = 10.0
+ speedAdd = 0.0
+ SpeedMultiply = 25.0
+ activationType = "immediate"
+ durationType = "once"
+ />
+</Template>
+
+<Template name=hugespeedpickupRepresentation>
+ <PickupRepresentation>
+ <spawner-representation>
+ <StaticEntity>
+ <attached>
+ <Billboard position="0,0,0" colour="0.99,0.96,0.52" material="Sphere2" scale=0.1>
+ <attached>
+ <Billboard position="0,0,0" colour="0.98,0.94,0.22" material="3arrowsup" scale=0.7 />
+ </attached>
+ </Billboard>
+ </attached>
+ </StaticEntity>
+ </spawner-representation>
+ </PickupRepresentation>
+</Template>
+
+<Template name=hugespeedpickup>
+ <SpeedPickup
+ duration = 10.0
+ speedAdd = 0.0
+ SpeedMultiply = 50.0
+ activationType = "immediate"
+ durationType = "once"
+ />
+</Template>
+
+<Template name=smalljumppickupRepresentation>
+ <PickupRepresentation>
+ <spawner-representation>
+ <StaticEntity>
+ <attached>
+ <Billboard position="0,0,0" colour="0.99,0.96,0.52" material="Sphere2" scale=0.1>
+ <attached>
+ <Billboard position="0,0,0" colour="1,0,0" material="3arrowsup" scale=0.3 />
+ </attached>
+ </Billboard>
+ </attached>
+ </StaticEntity>
+ </spawner-representation>
+ </PickupRepresentation>
+</Template>
+
+<Template name=smalljumppickup>
+ <SpeedPickup
+ duration = 0.7
+ speedAdd = 5000.0
+ SpeedMultiply = 1.0
+ activationType = "immediate"
+ durationType = "once"
+ />
+</Template>
+
<!-- Invisible pickups -->
<Template name=smallinvisiblepickupRepresentation>
Modified: code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.cc
===================================================================
--- code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.cc 2010-05-10 14:17:20 UTC (rev 6883)
+++ code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.cc 2010-05-10 14:23:29 UTC (rev 6884)
@@ -70,11 +70,31 @@
/**
@brief
+ Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
+ @return
+ A pointer to the Pawn, or NULL if the conversion failed.
+ */
+ Pawn* ShieldPickup::carrierToPawnHelper(void)
+ {
+ PickupCarrier* carrier = this->getCarrier();
+ Pawn* pawn = dynamic_cast<Pawn*>(carrier);
+
+ if(pawn == NULL)
+ {
+ COUT(1) << "Invalid PickupCarrier in ShieldPickup." << std::endl;
+ }
+ return pawn;
+ }
+
+ /**
+ @brief
Initializes the member variables.
*/
void ShieldPickup::initialize(void)
{
this->duration_ = 0.0f;
+ this->shieldAbsorption_ = 0.0f;
+ this->shieldHealth_ = 0.0f;
this->addTarget(ClassIdentifier<Engine>::getIdentifier());
}
@@ -91,11 +111,17 @@
std::string val1 = stream.str();
this->pickupIdentifier_->addParameter(type1, val1);
-// stream.clear();
-// stream << this->getShieldAdd();
-// std::string type2 = "ShieldAdd";
-// std::string val2 = stream.str();
-// this->pickupIdentifier_->addParameter(type2, val2);
+ stream.clear();
+ stream << this->getShieldHealth();
+ std::string type2 = "ShieldHealth";
+ std::string val2 = stream.str();
+ this->pickupIdentifier_->addParameter(type2, val2);
+
+ stream.clear();
+ stream << this->getShieldAbsorption();
+ std::string type3 = "ShieldAbsorption";
+ std::string val3 = stream.str();
+ this->pickupIdentifier_->addParameter(type3, val3);
}
@@ -108,6 +134,8 @@
SUPER(ShieldPickup, XMLPort, xmlelement, mode);
XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);
+ XMLPortParam(ShieldPickup, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode);
+ XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode);
this->initializeIdentifier();
}
@@ -123,6 +151,43 @@
//! If the pickup is not picked up nothing must be done.
if(!this->isPickedUp())
return;
+
+ Pawn* pawn = this->carrierToPawnHelper();
+ if(pawn == NULL)
+ this->destroy();
+
+ //! If the pickup has transited to used.
+ if(this->isUsed())
+ {
+ if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() > 0.0f)
+ {
+ this->getTimer()->unpauseTimer();
+ }
+ else
+ {
+ this->startPickupTimer(this->getDuration());
+ }
+ pawn->setShieldAbsorption(this->getShieldAbsorption());
+ pawn->setShieldHealth(this->getShieldHealth());
+ }
+ else
+ {
+ pawn->setShieldAbsorption(0.0f);
+ this->setShieldHealth(pawn->getShieldHealth());
+ pawn->setShieldHealth(0.0f);
+
+ if(this->isOnce())
+ {
+ if(!this->getTimer()->isActive() && this->getTimer()->getRemainingTime() == this->getDuration())
+ {
+ this->destroy();
+ }
+ else
+ {
+ this->getTimer()->pauseTimer();
+ }
+ }
+ }
}
/**
@@ -140,12 +205,51 @@
ShieldPickup* pickup = dynamic_cast<ShieldPickup*>(item);
pickup->setDuration(this->getDuration());
-
+ pickup->setShieldAbsorption(this->getShieldAbsorption());
+ pickup->setShieldHealth(this->getShieldHealth());
pickup->initializeIdentifier();
}
/**
@brief
+ Sets the percentage the shield absorbs of the dealt damage.
+ @param shieldAbsorption
+ The shieldAbsorption. Has to be between 0 and 1
+ */
+ void ShieldPickup::setShieldAbsorption(float shieldAbsorption)
+ {
+ if (shieldAbsorption>=0 && shieldAbsorption<=1)
+ {
+ this->shieldAbsorption_=shieldAbsorption;
+ }
+ else
+ {
+ COUT(1) << "Invalid Absorption in ShieldPickup." << std::endl;
+ this->shieldAbsorption_=0;
+ }
+ }
+
+ /**
+ @brief
+ Sets the health of the shield.
+ @param shieldHealth
+ The shieldHealth
+ */
+ void ShieldPickup::setShieldHealth(float shieldHealth)
+ {
+ if (shieldHealth>=0)
+ {
+ this->shieldHealth_=shieldHealth;
+ }
+ else
+ {
+ COUT(1) << "Invalid Shieldhealth in ShieldPickup." << std::endl;
+ this->shieldHealth_=0;
+ }
+ }
+
+ /**
+ @brief
Sets the duration.
@param duration
The duration
Modified: code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.h
===================================================================
--- code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.h 2010-05-10 14:17:20 UTC (rev 6883)
+++ code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.h 2010-05-10 14:23:29 UTC (rev 6884)
@@ -1,3 +1,4 @@
+
/*
* ORXONOX - the hottest 3D action shooter ever to exist
* > www.orxonox.net <
@@ -48,9 +49,9 @@
@brief
A Pickup which can add a Shield to the Pawn.
- 1) The Shield multiplier:
- The additional (forward) Shield:
- 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.
+ 1) The percentage: The percentage the shield takes from the damage dealt to a Pawn
+ 2) The hit points: The amount of damage points a shield can teake before collapsing
+ 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.
4) The duration: the activation time of the pickup.
@author
@@ -70,21 +71,28 @@
inline float getDuration(void)
{ return this->duration_; }
+ inline float getShieldHealth()
+ { return this->shieldHealth_; }
+ inline float getShieldAbsorption()
+ { return this->shieldAbsorption_; }
-
protected:
void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
-
+
virtual void pickupTimerCallback(void); //!< Function that gets called when timer ends.
void setDuration(float duration);
+ void setShieldHealth(float shieldHealth);
+ void setShieldAbsorption(float shieldAbsorption);
-
private:
void initialize(void); //!< Initializes the member variables.
- Engine* carrierToEngineHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
+ Pawn* carrierToPawnHelper(void); //!< Helper to transform the PickupCarrier to a Pawn, and throw an error message if the conversion fails.
float duration_; //!< The health that is transferred to the Pawn.
+ float shieldHealth_;
+ float shieldAbsorption_; // Has to be between 0 and 1
+
};
}
Modified: code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.cc 2010-05-10 14:17:20 UTC (rev 6883)
+++ code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.cc 2010-05-10 14:23:29 UTC (rev 6884)
@@ -63,6 +63,8 @@
this->health_ = 0;
this->maxHealth_ = 0;
this->initialHealth_ = 0;
+ this->shieldHealth_ = 0;
+ this->shieldAbsorption_ = 0;
this->lastHitOriginator_ = 0;
@@ -104,6 +106,10 @@
XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
+
+ XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
+ XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
+
XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
@@ -115,11 +121,13 @@
void Pawn::registerVariables()
{
- registerVariable(this->bAlive_, VariableDirection::ToClient);
- registerVariable(this->health_, VariableDirection::ToClient);
- registerVariable(this->initialHealth_, VariableDirection::ToClient);
- registerVariable(this->bReload_, VariableDirection::ToServer);
- registerVariable(this->aimPosition_, Bidirectionality::ServerMaster, 0, true);
+ registerVariable(this->bAlive_, VariableDirection::ToClient);
+ registerVariable(this->health_, VariableDirection::ToClient);
+ registerVariable(this->initialHealth_, VariableDirection::ToClient);
+ registerVariable(this->shieldHealth_, VariableDirection::ToClient);
+ registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
+ registerVariable(this->bReload_, VariableDirection::ToServer);
+ registerVariable(this->aimPosition_, Bidirectionality::ServerMaster, 0, true);
}
void Pawn::tick(float dt)
@@ -158,13 +166,30 @@
{
if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
{
- this->setHealth(this->health_ - damage);
+ //share the dealt damage to the shield and the Pawn.
+ float shielddamage = damage*this->shieldAbsorption_;
+ float healthdamage = damage*(1-this->shieldAbsorption_);
+
+ // In case the shield can not take all the shield damage.
+ if (shielddamage > this->getShieldHealth())
+ {
+ healthdamage += shielddamage-this->getShieldHealth();
+ this->setShieldHealth(0);
+ }
+
+ this->setHealth(this->health_ - healthdamage);
+
+ if (this->getShieldHealth() > 0)
+ {
+ this->setShieldHealth(this->shieldHealth_ - shielddamage);
+ }
+
this->lastHitOriginator_ = originator;
// play damage effect
}
}
-
+
void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
{
if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
Modified: code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.h 2010-05-10 14:17:20 UTC (rev 6883)
+++ code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.h 2010-05-10 14:23:29 UTC (rev 6884)
@@ -72,6 +72,16 @@
inline float getInitialHealth() const
{ return this->initialHealth_; }
+ inline void setShieldHealth(float shieldHealth)
+ { this->shieldHealth_ = shieldHealth; }
+ inline float getShieldHealth()
+ { return this->shieldHealth_; }
+
+ inline void setShieldAbsorption(float shieldAbsorption)
+ { this->shieldAbsorption_ = shieldAbsorption; }
+ inline float getShieldAbsorption()
+ { return this->shieldAbsorption_; }
+
inline ControllableEntity* getLastHitOriginator() const
{ return this->lastHitOriginator_; }
@@ -140,6 +150,8 @@
float health_;
float maxHealth_;
float initialHealth_;
+ float shieldHealth_;
+ float shieldAbsorption_; // Has to be between 0 and 1
Pawn* lastHitOriginator_;
More information about the Orxonox-commit
mailing list