Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6430 in orxonox.OLD for trunk/src/world_entities/world_entity.cc


Ignore:
Timestamp:
Jan 8, 2006, 12:14:49 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Energy System on WorldEntity-level

File:
1 edited

Legend:

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

    r6424 r6430  
    2727#include "obb_tree.h"
    2828
     29#include "glgui_bar.h"
     30
    2931#include "state.h"
    3032
     
    3234
    3335SHELL_COMMAND(model, WorldEntity, loadModel)
    34     ->describe("sets the Model of the WorldEntity")
    35     ->defaultValues(2, "models/ships/fighter.obj", 1.0);
     36->describe("sets the Model of the WorldEntity")
     37->defaultValues(2, "models/ships/fighter.obj", 1.0);
    3638
    3739SHELL_COMMAND(debugEntity, WorldEntity, debugWE);
     
    4345 *              that can calls WorldEntities loadParams for itself.
    4446 */
    45 WorldEntity::WorldEntity(const TiXmlElement* root)
    46   : Synchronizeable()
     47WorldEntity::WorldEntity()
     48    : Synchronizeable()
    4749{
    4850  this->setClassID(CL_WORLD_ENTITY, "WorldEntity");
    4951
    5052  this->obbTree = NULL;
     53  this->energyWidget = NULL;
     54  this->energyMax = 1.0f;
     55  this->energy = 1.0f;
    5156
    5257  this->md2TextureFileName = NULL;
    5358
    54   if (root != NULL)
    55     this->loadParams(root);
    5659
    5760  this->setVisibiliy(true);
     
    7275    delete this->obbTree;
    7376
     77  if (this->energyWidget != NULL)
     78    delete this->energyWidget;
     79
    7480  // Delete the model (unregister it with the ResourceManager)
    7581  for (unsigned int i = 0; i < this->models.size(); i++)
     
    8995
    9096  LoadParam(root, "md2texture", this, WorldEntity, loadMD2Texture)
    91       .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)")
    92       .defaultValues(1, NULL);
     97  .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)")
     98  .defaultValues(1, NULL);
    9399
    94100  // Model Loading
    95101  LoadParam(root, "model", this, WorldEntity, loadModel)
    96       .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)")
    97       .defaultValues(3, NULL, 1.0f, 0);
     102  .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)")
     103  .defaultValues(3, NULL, 1.0f, 0);
     104
     105  LoadParam(root, "maxEnergy", this, WorldEntity, setMaxEnergy)
     106  .describe("The Maximum energy that can be loaded onto this entity")
     107  .defaultValues(1, 1.0f);
     108
     109  LoadParam(root, "energy", this, WorldEntity, setEnergy)
     110  .describe("The Energy the WorldEntity has at this moment")
     111  .defaultValues(1, 1.0f);
    98112}
    99113
     
    111125  if ( fileName != NULL && strcmp(fileName, "") )
    112126  {
    113    // search for the special character # in the LoadParam
     127    // search for the special character # in the LoadParam
    114128    if (strchr(fileName, '#') != NULL)
    115129    {
     
    147161      PRINTF(4)("fetching MD2 file: %s\n", fileName);
    148162      Model* m = new MD2Model(fileName, this->md2TextureFileName);
    149         //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0);
     163      //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0);
    150164      this->setModel(m, 0);
    151165    }
     
    170184  {
    171185    Resource* resource = ResourceManager::getInstance()->locateResourceByPointer(this->models[modelNumber]);
    172 //     if (resource != NULL)
     186    //     if (resource != NULL)
    173187    ResourceManager::getInstance()->unload(resource, RP_LEVEL);
    174188  }
     
    179193
    180194
    181 //   if (this->model != NULL)
    182 //     this->buildObbTree(4);
     195  //   if (this->model != NULL)
     196  //     this->buildObbTree(4);
    183197}
    184198
     
    251265   * You can always define a default Action.... don't be affraid just test it :)
    252266   */
    253 //  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
     267  //  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
    254268}
    255269
     
    260274 */
    261275void WorldEntity::postSpawn ()
    262 {
    263 }
     276{}
    264277
    265278
     
    273286 */
    274287void WorldEntity::leftWorld ()
    275 {
    276 }
     288{}
    277289
    278290
     
    284296*/
    285297void WorldEntity::tick(float time)
    286 {
    287 }
     298{}
    288299
    289300
     
    296307void WorldEntity::draw() const
    297308{
    298     //PRINTF(0)("(%s::%s)\n", this->getClassName(), this->getName());
     309  //PRINTF(0)("(%s::%s)\n", this->getClassName(), this->getName());
    299310  //  assert(!unlikely(this->models.empty()));
    300311  {
     
    325336    }
    326337    glPopMatrix();
     338  }
     339}
     340
     341/**
     342 * @param energy the Energy to add.
     343 * @returns the energy left (this->energyMax - energy+this->energy)
     344 */
     345float WorldEntity::addEnergy(float energy)
     346{
     347  this->energy += energy;
     348  if (this->energy > this->energyMax)
     349  {
     350    float retEnergy = this->energyMax - this->energy;
     351    this->energy = this->energyMax;
     352    this->updateEnergyWidget();
     353    return retEnergy;
     354  }
     355  this->updateEnergyWidget();
     356  return 0.0;
     357}
     358
     359/**
     360 * @param energy the Energy to be removed
     361 * @returns 0.0 or the rest, that was not substracted (bellow 0.0)
     362 */
     363float WorldEntity::removeEnergy(float energy)
     364{
     365  this->energy -= energy;
     366
     367  if (this->energy < 0)
     368  {
     369    float retEnergy = -this->energy;
     370    this->energy = 0.0f;
     371    this->updateEnergyWidget();
     372    return retEnergy;
     373  }
     374  this->updateEnergyWidget();
     375  return 0.0;
     376
     377}
     378
     379/**
     380 * @param maxEnergy the maximal energy that can be loaded onto the entity.
     381 */
     382void WorldEntity::setMaxEnergy(float maxEnergy)
     383{
     384  this->energyMax = maxEnergy;
     385  if (this->energy > this->energyMax)
     386  {
     387    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());
     388    this->energy = this->energyMax;
     389  }
     390  this->updateEnergyWidget();
     391}
     392
     393void WorldEntity::createEnergyWidget()
     394{
     395  if (this->energyWidget == NULL)
     396  {
     397    this->energyWidget = new GLGuiBar();
     398    this->energyWidget->setSize2D(30,400);
     399    this->energyWidget->setAbsCoor2D(5,100);
     400
     401    this->updateEnergyWidget();
     402  }
     403  else
     404    PRINTF(3)("Allready created the EnergyWidget for %s::%s\n", this->getClassName(), this->getName());
     405}
     406
     407void WorldEntity::setEnergyWidgetVisibilit(bool visibility)
     408{
     409    if (visibility)
     410    {
     411      if (this->energyWidget != NULL)
     412        this->energyWidget->show();
     413      else
     414      {
     415        this->createEnergyWidget();
     416        this->updateEnergyWidget();
     417        this->energyWidget->show();
     418      }
     419    }
     420    else if (this->energyWidget != NULL)
     421      this->energyWidget->hide();
     422}
     423
     424void WorldEntity::updateEnergyWidget()
     425{
     426  if (this->energyWidget != NULL)
     427  {
     428    this->energyWidget->setMaximum(this->energyMax);
     429    this->energyWidget->setValue(this->energy);
    327430  }
    328431}
Note: See TracChangeset for help on using the changeset viewer.