Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2011, 9:41:29 PM (13 years ago)
Author:
dafrick
Message:

Merging game immersion branch into presentation branch.

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/worldentities/pawns/Pawn.cc

    r8579 r8580  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      simonmie
    2626 *
    2727 */
     
    6464        this->maxHealth_ = 0;
    6565        this->initialHealth_ = 0;
     66
    6667        this->shieldHealth_ = 0;
     68        this->initialShieldHealth_ = 0;
     69        this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max
    6770        this->shieldAbsorption_ = 0.5;
     71
     72        this->reloadRate_ = 0;
     73        this->reloadWaitTime_ = 1.0f;
     74        this->reloadWaitCountdown_ = 0;
    6875
    6976        this->lastHitOriginator_ = 0;
     
    109116
    110117        XMLPortParam(Pawn, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
     118        XMLPortParam(Pawn, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
     119        XMLPortParam(Pawn, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
    111120        XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
    112121
     
    118127        XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode);
    119128        XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode);
     129
     130        XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
     131        XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
    120132    }
    121133
     
    124136        registerVariable(this->bAlive_,           VariableDirection::ToClient);
    125137        registerVariable(this->health_,           VariableDirection::ToClient);
    126         registerVariable(this->initialHealth_,    VariableDirection::ToClient);
     138        registerVariable(this->maxHealth_,        VariableDirection::ToClient);
    127139        registerVariable(this->shieldHealth_,     VariableDirection::ToClient);
     140        registerVariable(this->maxShieldHealth_,  VariableDirection::ToClient);
    128141        registerVariable(this->shieldAbsorption_, VariableDirection::ToClient);
    129142        registerVariable(this->bReload_,          VariableDirection::ToServer);
     
    137150        this->bReload_ = false;
    138151
     152        // TODO: use the existing timer functions instead
     153        if(this->reloadWaitCountdown_ > 0)
     154        {
     155            this->decreaseReloadCountdownTime(dt);
     156        }
     157        else
     158        {
     159            this->addShieldHealth(this->getReloadRate() * dt);
     160            this->resetReloadCountdown();
     161        }
     162
    139163        if (GameMode::isMaster())
     164        {
    140165            if (this->health_ <= 0 && bAlive_)
    141166            {
    142                 this->fireEvent(); // Event to notify anyone who want's to know about the death.
     167                this->fireEvent(); // Event to notify anyone who wants to know about the death.
    143168                this->death();
    144169            }
     170        }
    145171    }
    146172
     
    168194    }
    169195
     196
    170197    void Pawn::setHealth(float health)
    171198    {
    172         this->health_ = std::min(health, this->maxHealth_);
    173     }
    174 
    175     void Pawn::damage(float damage, Pawn* originator)
     199        this->health_ = std::min(health, this->maxHealth_); //Health can't be set to a value bigger than maxHealth, otherwise it will be reduced at first hit
     200    }
     201
     202    void Pawn::setShieldHealth(float shieldHealth)
     203    {
     204        this->shieldHealth_ = std::min(shieldHealth, this->maxShieldHealth_);
     205    }
     206
     207    void Pawn::setMaxShieldHealth(float maxshieldhealth)
     208    {
     209        this->maxShieldHealth_ = maxshieldhealth;
     210    }
     211
     212    void Pawn::setReloadRate(float reloadrate)
     213    {
     214        this->reloadRate_ = reloadrate;
     215    }
     216
     217    void Pawn::setReloadWaitTime(float reloadwaittime)
     218    {
     219        this->reloadWaitTime_ = reloadwaittime;
     220    }
     221
     222    void Pawn::decreaseReloadCountdownTime(float dt)
     223    {
     224        this->reloadWaitCountdown_ -= dt;
     225    }
     226
     227    void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator)
    176228    {
    177229        if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
    178230        {
    179             //share the dealt damage to the shield and the Pawn.
    180             float shielddamage = damage*this->shieldAbsorption_;
    181             float healthdamage = damage*(1-this->shieldAbsorption_);
    182 
    183             // In case the shield can not take all the shield damage.
    184             if (shielddamage > this->getShieldHealth())
     231            if (shielddamage >= this->getShieldHealth())
    185232            {
    186                 healthdamage += shielddamage-this->getShieldHealth();
    187233                this->setShieldHealth(0);
     234                this->setHealth(this->health_ - (healthdamage + damage));
    188235            }
    189 
    190             this->setHealth(this->health_ - healthdamage);
    191 
    192             if (this->getShieldHealth() > 0)
     236            else
    193237            {
    194238                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     239
     240                // remove remaining shieldAbsorpton-Part of damage from shield
     241                shielddamage = damage * this->shieldAbsorption_;
     242                shielddamage = std::min(this->getShieldHealth(),shielddamage);
     243                this->setShieldHealth(this->shieldHealth_ - shielddamage);
     244
     245                // set remaining damage to health
     246                this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
    195247            }
    196248
    197249            this->lastHitOriginator_ = originator;
    198 
    199             // play damage effect
    200         }
    201     }
    202 
    203     void Pawn::hit(Pawn* originator, const Vector3& force, float damage)
     250        }
     251    }
     252
     253// TODO: Still valid?
     254/* HIT-Funktionen
     255    Die hit-Funktionen muessen auch in src/orxonox/controllers/Controller.h angepasst werden! (Visuelle Effekte)
     256
     257*/
     258
     259    void Pawn::hit(Pawn* originator, const Vector3& force, float damage, float healthdamage, float shielddamage)
    204260    {
    205261        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    206262        {
    207             this->damage(damage, originator);
     263            this->damage(damage, healthdamage, shielddamage, originator);
    208264            this->setVelocity(this->getVelocity() + force);
    209 
    210             // play hit effect
    211         }
    212     }
    213 
    214     void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage)
     265        }
     266    }
     267
     268
     269    void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage, float healthdamage, float shielddamage)
    215270    {
    216271        if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    217272        {
    218             this->damage(damage, originator);
     273            this->damage(damage, healthdamage, shielddamage, originator);
    219274
    220275            if ( this->getController() )
    221                 this->getController()->hit(originator, contactpoint, damage);
    222 
    223             // play hit effect
    224         }
    225     }
     276                this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
     277        }
     278    }
     279
    226280
    227281    void Pawn::kill()
Note: See TracChangeset for help on using the changeset viewer.