Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6430 in orxonox.OLD


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

orxonox/trunk: Energy System on WorldEntity-level

Location:
trunk/src/world_entities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/space_ships/space_ship.cc

    r6426 r6430  
    132132  cycle = 0.0;
    133133
     134  this->setMaxEnergy(100);
     135  this->setEnergy(80);
    134136
    135137  travelSpeed = 15.0;
     
    212214  this->attachCamera();
    213215
     216  this->setEnergyWidgetVisibilit(true);
    214217
    215218}
     
    220223  this->detachCamera();
    221224
     225  this->setEnergyWidgetVisibilit(false);
    222226
    223227}
     
    315319
    316320  //readjust
    317  
     321
    318322  /*
    319323    In the game "Yager" the spaceship gets readjusted when the player moves the mouse.
    320324    I (bknecht) go and check it out how they do it, we could probably use this also in Orxonox.
    321325  */
    322   //if (xMouse != 0 && yMouse != 0) 
    323  
     326  //if (xMouse != 0 && yMouse != 0)
     327
    324328  //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0)));
    325329  //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0)));
  • 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}
  • trunk/src/world_entities/world_entity.h

    r6424 r6430  
    2020class BVTree;
    2121class Model;
     22class GLGuiBar;
    2223
    2324//class CharacterAttributes;
     
    2728class WorldEntity : public PNode, public Synchronizeable
    2829{
    29  public:
    30   WorldEntity(const TiXmlElement* root = NULL);
     30public:
     31  WorldEntity();
    3132  virtual ~WorldEntity ();
    3233
     
    3536  void loadModel(const char* fileName, float scaling = 1.0f, unsigned int modelNumber = 0);
    3637  void setModel(Model* model, unsigned int modelNumber = 0);
    37   Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
     38Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
    3839
    3940  inline void loadMD2Texture(const char* fileName) { this->md2TextureFileName = fileName; }
     
    6162
    6263
    63   void debugWE() { this->debugEntity(); };  ///FIXME
     64  void debugWE() { this->debugEntity(); }
     65  ;  ///FIXME
    6466  void debugEntity() const;
    6567
     
    8284  int       readState(byte* data, int maxLength );
    8385
    84  protected:
    85   //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
     86  /** @returns the Energy of the entity */
     87  float getEnergy() const { return this->energy; };
     88  /** @returns the Maximum energy this entity can be charged with */
     89  float getMaxEnergy() const { return this->energyMax; }
     90  float addEnergy(float energy);
     91  float removeEnergy(float energy);
     92  void setMaxEnergy(float maxEnergy);
    8693
    8794
    88  private:
     95protected:
     96  void setEnergy(float energy) { this->energy = energy; };
     97  void setEnergyWidgetVisibilit(bool visibility);
     98  void createEnergyWidget();
     99  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
     100private:
     101  void updateEnergyWidget();
     102
     103private:
     104  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
     105  float                   energy;             //!< The Energy of this Entity, if the Entity has any energy at all.
     106  float                   energyMax;          //!< The Maximal energy this entity can take.
     107  GLGuiBar*               energyWidget;       //!< The Slider (if wanted).
     108
    89109  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
    90110  const char*             md2TextureFileName; //!< the file name of the md2 model texture, only if this
Note: See TracChangeset for help on using the changeset viewer.