Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6700 in orxonox.OLD


Ignore:
Timestamp:
Jan 25, 2006, 3:10:17 PM (18 years ago)
Author:
bensch
Message:

trunk: Energy→Health

Location:
trunk/src/world_entities
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/playable.cc

    r6695 r6700  
    2222#include "state.h"
    2323
     24#include "world_entities/projectiles/projectile.h"
     25
    2426#include "power_ups/weapon_power_up.h"
    2527#include "power_ups/param_power_up.h"
     
    9799{
    98100  if (entity->isA(CL_PROJECTILE))
    99     this->removeEnergy(entity->getEnergy());
     101    this->decreaseHealth(entity->getHealth());
    100102
    101103  // EXTREME HACK
    102   if (this->getEnergy() == 0.0f)
     104  if (this->getHealth() == 0.0f)
    103105    this->deactivateNode();
    104106}
     
    166168    switch(ppu->getType()) {
    167169      case POWERUP_PARAM_HEALTH:
    168         this->addEnergy(ppu->getValue());
     170        this->increaseHealth(ppu->getValue());
    169171        return true;
    170172      case POWERUP_PARAM_MAX_HEALTH:
    171         this->setMaxEnergy(this->getMaxEnergy() + ppu->getValue());
     173        this->increaseHealthMax(ppu->getValue());
    172174        return true;
    173175    }
  • trunk/src/world_entities/player.cc

    r6443 r6700  
    5858  {
    5959      this->controllable = controllable;
    60       this->hud.setEnergyWidget(this->controllable->getEnergyWidget());
     60      this->hud.setEnergyWidget(this->controllable->getHealthWidget());
    6161      this->hud.setWeaponManager(this->controllable->getWeaponManager());
    6262      return true;
  • trunk/src/world_entities/projectiles/bomb.cc

    r6619 r6700  
    4646
    4747  this->setMinEnergy(1);
    48   this->setMaxEnergy(10);
     48  this->setHealthMax(10);
    4949
    5050  this->lifeSpan = 15;
  • trunk/src/world_entities/projectiles/guided_missile.cc

    r6637 r6700  
    4141
    4242  this->setMinEnergy(1);
    43   this->setMaxEnergy(10);
     43  this->setHealthMax(10);
    4444  this->lifeSpan = 10.0;
    4545  this->agility = 5;
  • trunk/src/world_entities/projectiles/laser.cc

    r6695 r6700  
    4747
    4848  this->setMinEnergy(1);
    49   this->setMaxEnergy(10);
     49  this->setHealthMax(10);
    5050  this->lifeSpan = 5.0;
    5151
  • trunk/src/world_entities/projectiles/rocket.cc

    r6628 r6700  
    4242
    4343  this->setMinEnergy(1);
    44   this->setMaxEnergy(10);
     44  this->setHealthMax(10);
    4545  this->lifeSpan = 5;
    4646
  • trunk/src/world_entities/projectiles/test_bullet.cc

    r6622 r6700  
    4242
    4343  this->setMinEnergy(1);
    44   this->setMaxEnergy(10);
     44  this->setHealthMax(10);
    4545  this->lifeSpan = 2;
    4646
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6696 r6700  
    143143//  cycle = 0.0;
    144144
    145   this->setMaxEnergy(100);
    146   this->setEnergy(80);
     145  this->setHealthMax(100);
     146  this->setHealth(80);
    147147
    148148  travelSpeed = 40.0;
  • trunk/src/world_entities/weapons/weapon.cc

    r6695 r6700  
    150150    Projectile* pj = dynamic_cast<Projectile*>(this->projectileFactory->resurrect());
    151151    this->minCharge = pj->getMinEnergy();
    152     this->maxCharge = pj->getMaxEnergy();
     152    this->maxCharge = pj->getHealthMax();
    153153    this->chargeable = pj->isChageable();
    154154    this->projectileFactory->kill(pj);
  • trunk/src/world_entities/world_entity.cc

    r6695 r6700  
    5151
    5252  this->obbTree = NULL;
    53   this->energyWidget = NULL;
    54   this->energyMax = 1.0f;
    55   this->energy = 1.0f;
     53  this->healthWidget = NULL;
     54  this->healthMax = 1.0f;
     55  this->health = 1.0f;
    5656  this->scaling = 1.0f;
    5757
     
    7777    delete this->obbTree;
    7878
    79   if (this->energyWidget != NULL)
    80     delete this->energyWidget;
     79  if (this->healthWidget != NULL)
     80    delete this->healthWidget;
    8181
    8282  // Delete the model (unregister it with the ResourceManager)
     
    105105  .defaultValues(3, NULL, 1.0f, 0);
    106106
    107   LoadParam(root, "maxEnergy", this, WorldEntity, setMaxEnergy)
    108   .describe("The Maximum energy that can be loaded onto this entity")
     107  LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax)
     108  .describe("The Maximum health that can be loaded onto this entity")
    109109  .defaultValues(1, 1.0f);
    110110
    111   LoadParam(root, "energy", this, WorldEntity, setEnergy)
    112   .describe("The Energy the WorldEntity has at this moment")
     111  LoadParam(root, "health", this, WorldEntity, setHealth)
     112  .describe("The Health the WorldEntity has at this moment")
    113113  .defaultValues(1, 1.0f);
    114114}
     
    343343
    344344/**
    345  * @param energy the Energy to add.
    346  * @returns the energy left (this->energyMax - energy+this->energy)
    347  */
    348 float WorldEntity::addEnergy(float energy)
    349 {
    350   this->energy += energy;
    351   if (this->energy > this->energyMax)
    352   {
    353     float retEnergy = this->energyMax - this->energy;
    354     this->energy = this->energyMax;
    355     this->updateEnergyWidget();
    356     return retEnergy;
    357   }
    358   this->updateEnergyWidget();
     345 * @param health the Health to add.
     346 * @returns the health left (this->healthMax - health+this->health)
     347 */
     348float WorldEntity::increaseHealth(float health)
     349{
     350  this->health += health;
     351  if (this->health > this->healthMax)
     352  {
     353    float retHealth = this->healthMax - this->health;
     354    this->health = this->healthMax;
     355    this->updateHealthWidget();
     356    return retHealth;
     357  }
     358  this->updateHealthWidget();
    359359  return 0.0;
    360360}
    361361
    362362/**
    363  * @param energy the Energy to be removed
     363 * @param health the Health to be removed
    364364 * @returns 0.0 or the rest, that was not substracted (bellow 0.0)
    365365 */
    366 float WorldEntity::removeEnergy(float energy)
    367 {
    368   this->energy -= energy;
    369 
    370   if (this->energy < 0)
    371   {
    372     float retEnergy = -this->energy;
    373     this->energy = 0.0f;
    374     this->updateEnergyWidget();
    375     return retEnergy;
    376   }
    377   this->updateEnergyWidget();
     366float WorldEntity::decreaseHealth(float health)
     367{
     368  this->health -= health;
     369
     370  if (this->health < 0)
     371  {
     372    float retHealth = -this->health;
     373    this->health = 0.0f;
     374    this->updateHealthWidget();
     375    return retHealth;
     376  }
     377  this->updateHealthWidget();
    378378  return 0.0;
    379379
     
    381381
    382382/**
    383  * @param maxEnergy the maximal energy that can be loaded onto the entity.
    384  */
    385 void WorldEntity::setMaxEnergy(float maxEnergy)
    386 {
    387   this->energyMax = maxEnergy;
    388   if (this->energy > this->energyMax)
    389   {
    390     PRINTF(3)("new maxEnergy is bigger as the old energy. Did you really intend to do this for (%s::%s)\n", this->getClassName(), this->getName());
    391     this->energy = this->energyMax;
    392   }
    393   this->updateEnergyWidget();
    394 }
    395 
    396 /**
    397  * @brief creates the EnergyWidget
    398  *
    399  * since not all entities need an EnergyWidget, it is only created on request.
    400  */
    401 void WorldEntity::createEnergyWidget()
    402 {
    403   if (this->energyWidget == NULL)
    404   {
    405     this->energyWidget = new GLGuiBar();
    406     this->energyWidget->setSize2D(30,400);
    407     this->energyWidget->setAbsCoor2D(10,100);
    408 
    409     this->updateEnergyWidget();
     383 * @param maxHealth the maximal health that can be loaded onto the entity.
     384 */
     385void WorldEntity::setHealthMax(float healthMax)
     386{
     387  this->healthMax = healthMax;
     388  if (this->health > this->healthMax)
     389  {
     390    PRINTF(3)("new maxHealth is bigger as the old health. Did you really intend to do this for (%s::%s)\n", this->getClassName(), this->getName());
     391    this->health = this->healthMax;
     392  }
     393  this->updateHealthWidget();
     394}
     395
     396/**
     397 * @brief creates the HealthWidget
     398 *
     399 * since not all entities need an HealthWidget, it is only created on request.
     400 */
     401void WorldEntity::createHealthWidget()
     402{
     403  if (this->healthWidget == NULL)
     404  {
     405    this->healthWidget = new GLGuiBar();
     406    this->healthWidget->setSize2D(30,400);
     407    this->healthWidget->setAbsCoor2D(10,100);
     408
     409    this->updateHealthWidget();
    410410  }
    411411  else
    412     PRINTF(3)("Allready created the EnergyWidget for %s::%s\n", this->getClassName(), this->getName());
    413 }
    414 
    415 GLGuiWidget* WorldEntity::getEnergyWidget()
    416 {
    417   this->createEnergyWidget();
    418   return this->energyWidget;
    419 }
    420 
    421 /**
    422  * @param visibility shows or hides the energy-bar
     412    PRINTF(3)("Allready created the HealthWidget for %s::%s\n", this->getClassName(), this->getName());
     413}
     414
     415void WorldEntity::increaseHealthMax(float increaseHealth)
     416{
     417  this->healthMax += increaseHealth;
     418  this->updateHealthWidget();
     419}
     420
     421
     422GLGuiWidget* WorldEntity::getHealthWidget()
     423{
     424  this->createHealthWidget();
     425  return this->healthWidget;
     426}
     427
     428/**
     429 * @param visibility shows or hides the health-bar
    423430 * (creates the widget if needed)
    424431 */
    425 void WorldEntity::setEnergyWidgetVisibilit(bool visibility)
     432void WorldEntity::setHealthWidgetVisibilit(bool visibility)
    426433{
    427434    if (visibility)
    428435    {
    429       if (this->energyWidget != NULL)
    430         this->energyWidget->show();
     436      if (this->healthWidget != NULL)
     437        this->healthWidget->show();
    431438      else
    432439      {
    433         this->createEnergyWidget();
    434         this->updateEnergyWidget();
    435         this->energyWidget->show();
     440        this->createHealthWidget();
     441        this->updateHealthWidget();
     442        this->healthWidget->show();
    436443      }
    437444    }
    438     else if (this->energyWidget != NULL)
    439       this->energyWidget->hide();
    440 }
    441 
    442 /**
    443  * @brief updates the EnergyWidget
    444  */
    445 void WorldEntity::updateEnergyWidget()
    446 {
    447   if (this->energyWidget != NULL)
    448   {
    449     this->energyWidget->setMaximum(this->energyMax);
    450     this->energyWidget->setValue(this->energy);
     445    else if (this->healthWidget != NULL)
     446      this->healthWidget->hide();
     447}
     448
     449/**
     450 * @brief updates the HealthWidget
     451 */
     452void WorldEntity::updateHealthWidget()
     453{
     454  if (this->healthWidget != NULL)
     455  {
     456    this->healthWidget->setMaximum(this->healthMax);
     457    this->healthWidget->setValue(this->health);
    451458  }
    452459}
  • trunk/src/world_entities/world_entity.h

    r6695 r6700  
    8787
    8888  /** @returns the Energy of the entity */
    89   float getEnergy() const { return this->energy; };
     89  float getHealth() const { return this->health; };
    9090  /** @returns the Maximum energy this entity can be charged with */
    91   float getMaxEnergy() const { return this->energyMax; }
    92   float addEnergy(float energy);
    93   float removeEnergy(float energy);
    94   void setMaxEnergy(float maxEnergy);
    95   GLGuiWidget* getEnergyWidget();
     91  float getHealthMax() const { return this->healthMax; }
     92  float increaseHealth(float health);
     93  float decreaseHealth(float health);
     94  void increaseHealthMax(float increaseHealth);
     95  GLGuiWidget* getHealthWidget();
    9696
    9797protected:
    98   void setEnergy(float energy) { this->energy = energy; };
    99   void setEnergyWidgetVisibilit(bool visibility);
    100   void createEnergyWidget();
     98  void setHealth(float health) { this->health = health; };
     99  void setHealthWidgetVisibilit(bool visibility);
     100  void setHealthMax(float healthMax);
     101  void createHealthWidget();
    101102  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
    102103private:
    103   void updateEnergyWidget();
     104  void updateHealthWidget();
    104105
    105106private:
    106107  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
    107   float                   energy;             //!< The Energy of this Entity, if the Entity has any energy at all.
    108   float                   energyMax;          //!< The Maximal energy this entity can take.
    109   GLGuiBar*               energyWidget;       //!< The Slider (if wanted).
     108  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
     109  float                   healthMax;          //!< The Maximal energy this entity can take.
     110  GLGuiBar*               healthWidget;       //!< The Slider (if wanted).
    110111
    111112  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
Note: See TracChangeset for help on using the changeset viewer.