Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6884


Ignore:
Timestamp:
May 10, 2010, 4:23:29 PM (14 years ago)
Author:
benedict
Message:

did the shield pickup. upload for testing

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>
    113
    214<!-- Health pickups -->
  • code/branches/ppspickups3/data/levels/pickup.oxw

    r6731 r6884  
    2626    <SpawnPoint position="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
    2727
     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   
    2837    <!-- Health pickups -->
    2938   
  • 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>
    128
    229<!-- Health pickups: -->
  • code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.cc

    r6869 r6884  
    7171    /**
    7272    @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
    7391        Initializes the member variables.
    7492    */
     
    7694    {
    7795        this->duration_ = 0.0f;
     96        this->shieldAbsorption_ = 0.0f;
     97        this->shieldHealth_ = 0.0f;
    7898
    7999        this->addTarget(ClassIdentifier<Engine>::getIdentifier());
     
    92112        this->pickupIdentifier_->addParameter(type1, val1);
    93113
    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);
    99125
    100126    }
     
    109135
    110136        XMLPortParam(ShieldPickup, "duration", setDuration, getDuration, xmlelement, mode);
     137        XMLPortParam(ShieldPickup, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode);
     138        XMLPortParam(ShieldPickup, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode);
    111139
    112140        this->initializeIdentifier();
     
    124152        if(!this->isPickedUp())
    125153            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        }
    126191    }
    127192
     
    141206        ShieldPickup* pickup = dynamic_cast<ShieldPickup*>(item);
    142207        pickup->setDuration(this->getDuration());
    143 
     208        pickup->setShieldAbsorption(this->getShieldAbsorption());
     209        pickup->setShieldHealth(this->getShieldHealth());
    144210        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        }
    145249    }
    146250
  • code/branches/ppspickups3/src/modules/pickup/items/ShieldPickup.h

    r6869 r6884  
     1
    12/*
    23 *   ORXONOX - the hottest 3D action shooter ever to exist
     
    4950        A Pickup which can add a Shield to the Pawn.
    5051
    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.
    5455        4) The duration: the activation time of the pickup.
    5556
     
    7172            inline float getDuration(void)
    7273                { return this->duration_; }
    73 
     74            inline float getShieldHealth()
     75                { return this->shieldHealth_; }
     76            inline float getShieldAbsorption()
     77                { return this->shieldAbsorption_; }
    7478
    7579        protected:
    7680            void initializeIdentifier(void); //!< Initializes the PickupIdentifier of this pickup.
    77            
     81
    7882            virtual void pickupTimerCallback(void); //!< Function that gets called when timer ends.
    7983
    8084            void setDuration(float duration);
    81 
     85            void setShieldHealth(float shieldHealth);
     86            void setShieldAbsorption(float shieldAbsorption);
    8287
    8388        private:
    8489            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.
    8691
    8792            float duration_; //!< The health that is transferred to the Pawn.
     93            float shieldHealth_;
     94            float shieldAbsorption_; // Has to be between 0 and 1
     95
    8896    };
    8997}
  • code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.cc

    r6711 r6884  
    6464        this->maxHealth_ = 0;
    6565        this->initialHealth_ = 0;
     66        this->shieldHealth_ = 0;
     67        this->shieldAbsorption_ = 0;
    6668
    6769        this->lastHitOriginator_ = 0;
     
    105107        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
    106108        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       
    107113        XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
    108114        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
     
    116122    void Pawn::registerVariables()
    117123    {
    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);
    123131    }
    124132
     
    159167        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    160168        {
    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
    162187            this->lastHitOriginator_ = originator;
    163188
     
    165190        }
    166191    }
    167 
     192   
    168193    void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
    169194    {
  • code/branches/ppspickups3/src/orxonox/worldentities/pawns/Pawn.h

    r6711 r6884  
    7373                { return this->initialHealth_; }
    7474
     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
    7585            inline ControllableEntity* getLastHitOriginator() const
    7686                { return this->lastHitOriginator_; }
     
    141151            float maxHealth_;
    142152            float initialHealth_;
     153            float shieldHealth_;
     154            float shieldAbsorption_; // Has to be between 0 and 1
    143155
    144156            Pawn* lastHitOriginator_;
Note: See TracChangeset for help on using the changeset viewer.