Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/mount_points/src/world_entities/world_entity.cc @ 10057

Last change on this file since 10057 was 10057, checked in by patrick, 17 years ago

mount point connection

File size: 21.0 KB
RevLine 
[2036]1
2
[4570]3/*
[2036]4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
[2190]15   co-programmer: Christian Meyer
[2036]16*/
[5300]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
[2036]18
19#include "world_entity.h"
[5208]20#include "shell_command.h"
[5143]21
[9869]22#include "util/loading/resource_manager.h"
23#include "resource_obj.h"
[8490]24#include "md2/md2Model.h"
25#include "md3/md3_model.h"
[10052]26#include "oif/object_information_file.h"
[8490]27
[8724]28#include "aabb_tree_node.h"
29
[7193]30#include "util/loading/load_param.h"
[4682]31#include "obb_tree.h"
[3608]32
[8974]33#include "elements/glgui_energywidget.h"
[6430]34
[6002]35#include "state.h"
[7014]36#include "camera.h"
[6002]37
[10013]38#include "collision_filter.h"
[8190]39#include "collision_event.h"
[8777]40#include "game_rules.h"
41#include "kill.h"
[9869]42#include "debug.h"
[7927]43
[9869]44#include "projectiles/projectile.h"
[7927]45
[5208]46SHELL_COMMAND(model, WorldEntity, loadModel)
[6430]47->describe("sets the Model of the WorldEntity")
[7711]48->defaultValues("models/ships/fighter.obj", 1.0f);
[5208]49
[6424]50SHELL_COMMAND(debugEntity, WorldEntity, debugWE);
[5208]51
[9869]52
53ObjectListDefinition(WorldEntity);
[2043]54/**
[4836]55 *  Loads the WordEntity-specific Part of any derived Class
[5498]56 *
57 * @param root: Normally NULL, as the Derived Entities define a loadParams Function themeselves,
58 *              that can calls WorldEntities loadParams for itself.
59 */
[6430]60WorldEntity::WorldEntity()
[10013]61  : Synchronizeable(), _collisionFilter(this)
[2190]62{
[9869]63  this->registerObject(this, WorldEntity::_objectList);
[4597]64
[4682]65  this->obbTree = NULL;
[8724]66  this->aabbNode = NULL;
[6700]67  this->healthWidget = NULL;
68  this->healthMax = 1.0f;
69  this->health = 1.0f;
[8190]70  this->damage = 0.0f; // no damage dealt by a default entity
[6695]71  this->scaling = 1.0f;
[10053]72  this->oiFile = NULL;
[4261]73
[6695]74  /* OSOLETE */
75  this->bVisible = true;
76  this->bCollide = true;
77
[6142]78  this->objectListNumber = OM_INIT;
[9003]79  this->lastObjectListNumber = OM_INIT;
[6142]80
[10013]81  this->_bOnGround = false;
[8190]82
83  // registering default reactions:
[10013]84  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID());
[8190]85
[6142]86  this->toList(OM_NULL);
[9235]87
[10013]88  this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
89  this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
90  this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
91  this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
[9235]92
[10013]93  this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
94  this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
[2190]95}
[2043]96
97/**
[4836]98 *  standard destructor
[2043]99*/
[2190]100WorldEntity::~WorldEntity ()
[2036]101{
[7125]102  State::getObjectManager()->toList(this, OM_INIT);
103
104  // Delete the model (unregister it with the ResourceManager)
105  for (unsigned int i = 0; i < this->models.size(); i++)
106    this->setModel(NULL, i);
107
[10053]108  if( this->oiFile)
109    delete this->oiFile;
110
[5498]111  // Delete the obbTree
[5302]112  if( this->obbTree != NULL)
[4814]113    delete this->obbTree;
[5994]114
[6700]115  if (this->healthWidget != NULL)
116    delete this->healthWidget;
[8190]117
[10013]118  this->unsubscribeReactions();
[3531]119}
120
[5498]121/**
122 * loads the WorldEntity Specific Parameters.
123 * @param root: the XML-Element to load the Data From
124 */
[4436]125void WorldEntity::loadParams(const TiXmlElement* root)
126{
[5498]127  // Do the PNode loading stuff
[6512]128  PNode::loadParams(root);
[5498]129
[6222]130  LoadParam(root, "md2texture", this, WorldEntity, loadMD2Texture)
[6430]131  .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)")
[7198]132  .defaultValues("");
[6222]133
[4436]134  // Model Loading
[5671]135  LoadParam(root, "model", this, WorldEntity, loadModel)
[6430]136  .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)")
[7198]137  .defaultValues("", 1.0f, 0);
[6430]138
[6700]139  LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax)
140  .describe("The Maximum health that can be loaded onto this entity")
[7198]141  .defaultValues(1.0f);
[6430]142
[6700]143  LoadParam(root, "health", this, WorldEntity, setHealth)
144  .describe("The Health the WorldEntity has at this moment")
[7198]145  .defaultValues(1.0f);
[9656]146
147  LoadParam(root, "list", this, WorldEntity, toListS);
[4436]148}
149
[6222]150
[3531]151/**
[4885]152 * loads a Model onto a WorldEntity
[4836]153 * @param fileName the name of the model to load
[5057]154 * @param scaling the Scaling of the model
[7711]155 *
156 * FIXME
157 * @todo: separate the obb tree generation from the model
[7221]158 */
[7711]159void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber, unsigned int obbTreeDepth)
[4261]160{
[6695]161  this->modelLODName = fileName;
[6424]162  this->scaling = scaling;
[7954]163
164  std::string name = fileName;
165
[9869]166  if (  name.find( Resources::ResourceManager::getInstance()->mainGlobalPath().name() ) == 0 )
[7954]167  {
[9869]168    name.erase(Resources::ResourceManager::getInstance()->mainGlobalPath().name().size());
[7954]169  }
170
171  this->modelFileName = name;
172
[7221]173  if (!fileName.empty())
[6142]174  {
[6430]175    // search for the special character # in the LoadParam
[7221]176    if (fileName.find('#') != std::string::npos)
[6222]177    {
[7221]178      PRINTF(4)("Found # in %s... searching for LOD's\n", fileName.c_str());
179      std::string lodFile = fileName;
180      unsigned int offset = lodFile.find('#');
[6720]181      for (unsigned int i = 0; i < 3; i++)
[6005]182      {
[7221]183        lodFile[offset] = 48+(int)i;
[9869]184        if (Resources::ResourceManager::getInstance()->checkFileInMainPath( lodFile))
[6222]185          this->loadModel(lodFile, scaling, i);
[6005]186      }
[6222]187      return;
188    }
[6720]189    if (this->scaling <= 0.0)
[6424]190    {
[7193]191      PRINTF(1)("YOU GAVE ME A CRAPY SCALE resetting to 1.0\n");
[6720]192      this->scaling = 1.0;
[6424]193    }
[9869]194    /// LOADING AN OBJ FILE
[7221]195    if(fileName.find(".obj") != std::string::npos)
[6222]196    {
[7221]197      PRINTF(4)("fetching OBJ file: %s\n", fileName.c_str());
[10052]198      // creating the model and loading it
[9869]199      StaticModel* model = new StaticModel();
200      *model = ResourceOBJ(fileName, this->scaling);
201      if (model->getVertexCount() > 0)
202      {
203        this->setModel(model, modelNumber);
204        if( modelNumber == 0 /* FIXME && !this->isA(CL_WEAPON) */)
205          this->buildObbTree(obbTreeDepth);
206      }
[7221]207      else
[9869]208        delete model;
[10052]209
210      // now get the object information file for this model, if any
[10055]211      std::string oifName = fileName.substr(0, fileName.length() - 4) + ".oif";
[10052]212      this->loadObjectInformationFile( oifName);
[6222]213    }
[9869]214    /// LOADING AN MD2-model
[7221]215    else if(fileName.find(".md2") != std::string::npos)
[6222]216    {
[7221]217      PRINTF(4)("fetching MD2 file: %s\n", fileName.c_str());
[7055]218      Model* m = new MD2Model(fileName, this->md2TextureFileName, this->scaling);
[6430]219      //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0);
[6222]220      this->setModel(m, 0);
[7068]221
222      if( m != NULL)
[7711]223        this->buildObbTree(obbTreeDepth);
[6222]224    }
[9869]225    /// LOADING AN MD3-MODEL.
[9235]226    else if(fileName.find(".md3") != std::string::npos)
[8490]227    {
228      PRINTF(4)("fetching MD3 file: %s\n", fileName.c_str());
[9869]229//      Model* m = new md3::MD3Model(fileName, this->scaling);
230//      this->setModel(m, 0);
[8490]231
[9869]232      //       if( m != NULL)
233      //         this->buildObbTree(obbTreeDepth);
[8490]234    }
[4732]235  }
236  else
[6341]237  {
[5995]238    this->setModel(NULL);
[6341]239  }
[4261]240}
241
[5061]242/**
[5994]243 * sets a specific Model for the Object.
244 * @param model The Model to set
245 * @param modelNumber the n'th model in the List to get.
246 */
247void WorldEntity::setModel(Model* model, unsigned int modelNumber)
248{
[5995]249  if (this->models.size() <= modelNumber)
250    this->models.resize(modelNumber+1, NULL);
251
252  if (this->models[modelNumber] != NULL)
[6004]253  {
[9869]254    delete this->models[modelNumber];
[5994]255  }
[6222]256
[5995]257  this->models[modelNumber] = model;
[5994]258}
259
260
[10052]261
[5994]262/**
[10052]263 * loads the object information file for this model
264 * @param fileName the name of the file
265 */
266void WorldEntity::loadObjectInformationFile(const std::string& fileName)
267{
[10055]268  PRINTF(0)("loading the oif File: %s\n", fileName.c_str());
[10053]269
270  this->oiFile = new ObjectInformationFile(fileName);
[10052]271}
272
273
274/**
[5061]275 * builds the obb-tree
276 * @param depth the depth to calculate
277 */
[7711]278bool WorldEntity::buildObbTree(int depth)
[5061]279{
[9494]280  if( this->obbTree != NULL)
281  {
[5428]282    delete this->obbTree;
[9494]283    this->obbTree = NULL;
284  }
[5428]285
[5995]286  if (this->models[0] != NULL)
[7711]287    this->obbTree = new OBBTree(depth, models[0]->getModelInfo(), this);
[5428]288  else
289  {
[7711]290    PRINTF(1)("could not create obb-tree, because no model was loaded yet\n");
[5428]291    this->obbTree = NULL;
292    return false;
293  }
[8724]294
295
296  // create the axis aligned bounding box
297  if( this->aabbNode != NULL)
298  {
299    delete this->aabbNode;
300    this->aabbNode = NULL;
301  }
302
[9869]303  if( this->models[0] != NULL)
304  {
[8724]305    this->aabbNode = new AABBTreeNode();
306    this->aabbNode->spawnBVTree(this->models[0]);
307  }
[9494]308  else
309  {
310    PRINTF(1)("could not create aabb bounding box, because no model was loaded yet\n");
311    this->aabbNode = NULL;
312    return false;
313  }
[8724]314  return true;
[5061]315}
[5057]316
[7927]317
[6142]318/**
[10056]319 * adds a mount point to the end of the list
320 * @param mountPoint point to be added
321 */
322void WorldEntity::addMountPoint(MountPoint* mountPoint)
323{
[10057]324  // add the mount point at the last position
325  this->mountPoints.push_back(mountPoint);
[10056]326}
327
328/**
329 * adds a mount point to a world entity
330 * @param mountPoint point to be added
331 */
332void WorldEntity::addMountPoint(int slot, MountPoint* mountPoint)
333{
[10057]334  if( this->mountPoints[slot] != NULL)
335  {
336    PRINTF(0)("adding a mount point to a slot, that already exists! ignoring - maybe some object do not get connected well (object: %s)", this->getClassCName());
337  }
[10056]338
[10057]339  // just connect the mount point
340  this->mountPoints[slot] = mountPoint;
[10056]341}
342
343
344/**
345 * mounts a world entity on a specified mount point (~socket)
346 * @param entity entity to be connected
347 */
348void WorldEntity::mount(int slot, WorldEntity* entity)
349{
350
351}
352
353
354/**
355 * removes a mount point from a specified mount point
356 * @param mountPoint entity to be unconnected
357 */
358void WorldEntity::unmount(int slot)
359{
360}
361
362
363/**
[7927]364 * subscribes this world entity to a collision reaction
365 *  @param type the type of reaction to subscribe to
[8190]366 *  @param target1 a filter target (classID)
367 */
[10013]368void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
[8190]369{
[10013]370  this->_collisionFilter.subscribeReaction(type, target1);
[8190]371}
372
373
374/**
375 * subscribes this world entity to a collision reaction
376 *  @param type the type of reaction to subscribe to
377 *  @param target1 a filter target (classID)
378 */
[10013]379void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
[8190]380{
[10013]381  this->_collisionFilter.subscribeReaction(type, target1, target2);
[8190]382}
383
384
385/**
386 * subscribes this world entity to a collision reaction
387 *  @param type the type of reaction to subscribe to
388 *  @param target1 a filter target (classID)
389 */
[10013]390void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
[8190]391{
[10013]392  this->_collisionFilter.subscribeReaction(type, target1, target2, target3);
[8190]393}
394
395
396/**
397 * unsubscribes a specific reaction from the worldentity
398 *  @param type the reaction to unsubscribe
399 */
[10013]400void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type)
[8190]401{
[10013]402  this->_collisionFilter.unsubscribeReaction(type);
[8190]403}
404
405
406/**
407 * unsubscribes all collision reactions
408 */
[10013]409void WorldEntity::unsubscribeReactions()
[8190]410{
[10013]411  this->_collisionFilter.unsubscribeReactions();
[8190]412}
413
414
415/**
[6142]416 * @brief moves this entity to the List OM_List
417 * @param list the list to set this Entity to.
418 *
419 * this is the same as a call to State::getObjectManager()->toList(entity , list);
420 * directly, but with an easier interface.
421 *
422 * @todo inline this (peut etre)
423 */
424void WorldEntity::toList(OM_LIST list)
425{
426  State::getObjectManager()->toList(this, list);
427}
[5061]428
[9656]429void WorldEntity::toListS(const std::string& listName)
430{
431  OM_LIST id = ObjectManager::StringToOMList(listName);
432  if (id != OM_NULL)
433    this->toList(id);
434  else
435    PRINTF(2)("List %s not found\n", listName.c_str());
436}
437
438
[8037]439void WorldEntity::toReflectionList()
440{
441  State::getObjectManager()->toReflectionList( this );
442}
[6142]443
[8037]444void removeFromReflectionList()
445{
[9869]446  /// TODO
447  ///  State::getObject
[8037]448}
[6142]449
[4261]450/**
[4885]451 * sets the character attributes of a worldentity
[4836]452 * @param character attributes
[4885]453 *
454 * these attributes don't have to be set, only use them, if you need them
[2043]455*/
[5498]456//void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
457//{}
[2036]458
[3583]459
[2043]460/**
[5029]461 *  this function is called, when two entities collide
462 * @param entity: the world entity with whom it collides
463 *
464 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
465 */
466void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location)
467{
[5498]468  /**
469   * THIS IS A DEFAULT COLLISION-Effect.
470   * IF YOU WANT TO CREATE A SPECIFIC COLLISION ON EACH OBJECT
471   * USE::
472   * if (entity->isA(CL_WHAT_YOU_ARE_LOOKING_FOR)) { printf "dothings"; };
473   *
474   * You can always define a default Action.... don't be affraid just test it :)
475   */
[9406]476  //  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z);
[5029]477}
478
[2043]479
480/**
[8186]481 *  this function is called, when two entities collide
482 * @param entity: the world entity with whom it collides
483 *
484 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
485 */
486void WorldEntity::collidesWithGround(const Vector& location)
487{
[9406]488  PRINTF(0)("BSP_GROUND: %s collides \n", this->getClassCName() );
[8186]489}
490
491void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2)
492{
[8190]493
[9406]494  // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassCName() );
[8190]495
[8186]496  Vector v = this->getAbsDirX();
[8490]497  v.x *= 10.1;
498  v.y *= 10.1;
499  v.z *= 10.1;
500  Vector u = Vector(0.0,-20.0,0.0);
[8190]501
[8490]502
503  if(!(this->getAbsCoor().x == ray_2.x && this->getAbsCoor().y == ray_2.y && this->getAbsCoor().z == ray_2.z) )
[8186]504  {
[8190]505
[9869]506    this->setAbsCoor(ray_2 - v);
[8490]507
[8186]508  }
[9869]509  else
[8186]510  {
511    if(ray_1.x == this->getAbsCoor().x + v.x && ray_1.y == this->getAbsCoor().y + v.y + 0.1 && ray_1.z ==this->getAbsCoor().z + v.z)
512    {
[8190]513      this->setAbsCoor(feet -u );
[8186]514    }
[8190]515
516    this->setAbsCoor(ray_2 - v);
517
[8186]518  }
[8490]519
520
[8186]521}
522
523/**
[5498]524 *  this is called immediately after the Entity has been constructed, initialized and then Spawned into the World
[4885]525 *
[5498]526 */
[3229]527void WorldEntity::postSpawn ()
[6430]528{}
[2043]529
[3583]530
[2043]531/**
[6959]532 *  this method is called by the world if the WorldEntity leaves the game
[5498]533 */
[6959]534void WorldEntity::leaveWorld ()
[6430]535{}
[2043]536
[3583]537
[2190]538/**
[7085]539 * resets the WorldEntity to its initial values. eg. used for multiplayer games: respawning
540 */
541void WorldEntity::reset()
[9235]542{
543  this->setHealth( this->getHealthMax() );
544}
[7085]545
546/**
[4836]547 *  this method is called every frame
548 * @param time: the time in seconds that has passed since the last tick
[4885]549 *
550 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
[2043]551*/
[4570]552void WorldEntity::tick(float time)
[6430]553{}
[3583]554
[5498]555
[3583]556/**
[4836]557 *  the entity is drawn onto the screen with this function
[4885]558 *
559 * This is a central function of an entity: call it to let the entity painted to the screen.
560 * Just override this function with whatever you want to be drawn.
[3365]561*/
[5500]562void WorldEntity::draw() const
[3803]563{
[9406]564  //PRINTF(0)("(%s::%s)\n", this->getClassCName(), this->getName());
[6281]565  //  assert(!unlikely(this->models.empty()));
[6002]566  {
567    glMatrixMode(GL_MODELVIEW);
568    glPushMatrix();
[4570]569
[6002]570    /* translate */
571    glTranslatef (this->getAbsCoor ().x,
572                  this->getAbsCoor ().y,
573                  this->getAbsCoor ().z);
[6004]574    Vector tmpRot = this->getAbsDir().getSpacialAxis();
575    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[2043]576
[6004]577
578    // This Draws the LOD's
[7014]579    float cameraDistance = State::getCamera()->distance(this);
[6004]580    if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL)
[6002]581    {
[6222]582      this->models[2]->draw();
[6004]583    }
584    else if (cameraDistance > 10 && this->models.size() >= 2 && this->models[1] != NULL)
[6002]585    {
586      this->models[1]->draw();
[6004]587    }
588    else if (this->models.size() >= 1 && this->models[0] != NULL)
[6002]589    {
590      this->models[0]->draw();
591    }
[8724]592
[9869]593    //     if( this->aabbNode != NULL)
594    //       this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);
[8724]595
[6002]596    glPopMatrix();
597  }
[3803]598}
[3583]599
[6430]600/**
[6700]601 * @param health the Health to add.
602 * @returns the health left (this->healthMax - health+this->health)
[6430]603 */
[6700]604float WorldEntity::increaseHealth(float health)
[6430]605{
[6700]606  this->health += health;
607  if (this->health > this->healthMax)
[6430]608  {
[6700]609    float retHealth = this->healthMax - this->health;
610    this->health = this->healthMax;
611    this->updateHealthWidget();
612    return retHealth;
[6430]613  }
[6700]614  this->updateHealthWidget();
[6430]615  return 0.0;
616}
[6281]617
[5498]618/**
[6700]619 * @param health the Health to be removed
[6430]620 * @returns 0.0 or the rest, that was not substracted (bellow 0.0)
621 */
[6700]622float WorldEntity::decreaseHealth(float health)
[6430]623{
[6700]624  this->health -= health;
[6430]625
[6700]626  if (this->health < 0)
[6430]627  {
[6700]628    float retHealth = -this->health;
629    this->health = 0.0f;
630    this->updateHealthWidget();
631    return retHealth;
[6430]632  }
[6700]633  this->updateHealthWidget();
[6430]634  return 0.0;
635
636}
637
638/**
[6700]639 * @param maxHealth the maximal health that can be loaded onto the entity.
[6430]640 */
[6700]641void WorldEntity::setHealthMax(float healthMax)
[6430]642{
[6700]643  this->healthMax = healthMax;
644  if (this->health > this->healthMax)
[6430]645  {
[9406]646    PRINTF(3)("new maxHealth is bigger as the old health. Did you really intend to do this for (%s::%s)\n", this->getClassCName(), this->getCName());
[6700]647    this->health = this->healthMax;
[6430]648  }
[6700]649  this->updateHealthWidget();
[6430]650}
651
[6431]652/**
[6700]653 * @brief creates the HealthWidget
[6431]654 *
[6700]655 * since not all entities need an HealthWidget, it is only created on request.
[6431]656 */
[6700]657void WorldEntity::createHealthWidget()
[6430]658{
[6700]659  if (this->healthWidget == NULL)
[6430]660  {
[8974]661    this->healthWidget = new OrxGui::GLGuiEnergyWidget();
[8977]662    this->healthWidget->setDisplayedName(std::string(this->getClassName()) + " Energy:");
[6700]663    this->healthWidget->setSize2D(30,400);
664    this->healthWidget->setAbsCoor2D(10,100);
[6430]665
[6700]666    this->updateHealthWidget();
[6430]667  }
668  else
[9406]669    PRINTF(3)("Allready created the HealthWidget for %s::%s\n", this->getClassCName(), this->getCName());
[6430]670}
671
[6700]672void WorldEntity::increaseHealthMax(float increaseHealth)
[6440]673{
[6700]674  this->healthMax += increaseHealth;
675  this->updateHealthWidget();
[6440]676}
677
[6700]678
[7779]679OrxGui::GLGuiWidget* WorldEntity::getHealthWidget()
[6700]680{
681  this->createHealthWidget();
682  return this->healthWidget;
683}
684
[6431]685/**
[6700]686 * @param visibility shows or hides the health-bar
[6431]687 * (creates the widget if needed)
688 */
[6700]689void WorldEntity::setHealthWidgetVisibilit(bool visibility)
[6430]690{
[7198]691  if (visibility)
692  {
693    if (this->healthWidget != NULL)
694      this->healthWidget->show();
695    else
[6430]696    {
[7198]697      this->createHealthWidget();
698      this->updateHealthWidget();
699      this->healthWidget->show();
[6430]700    }
[7198]701  }
702  else if (this->healthWidget != NULL)
703    this->healthWidget->hide();
[6430]704}
705
[8724]706
[6431]707/**
[8724]708 * hit the world entity with
709 *  @param damage damage to be dealt
710 */
[9008]711void WorldEntity::hit(float damage, WorldEntity* killer)
[8724]712{
713  this->decreaseHealth(damage);
714
[9406]715  PRINTF(5)("Hit me: %s::%s now only %f/%f health\n", this->getClassCName(), this->getCName(), this->getHealth(), this->getHealthMax());
[8777]716
[8724]717  if( this->getHealth() > 0)
718  {
719    // any small explosion animaitions
720  }
721  else
722  {
[9235]723    this->destroy( killer );
[8724]724  }
725}
726
727
728/**
[8777]729 * destoys the world entity
730 */
[9235]731void WorldEntity::destroy(WorldEntity* killer)
[8777]732{
733  this->toList(OM_DEAD);
734}
735
736
737/**
[6700]738 * @brief updates the HealthWidget
[6431]739 */
[6700]740void WorldEntity::updateHealthWidget()
[6430]741{
[6700]742  if (this->healthWidget != NULL)
[6430]743  {
[6700]744    this->healthWidget->setMaximum(this->healthMax);
745    this->healthWidget->setValue(this->health);
[6430]746  }
747}
748
749
750/**
[5498]751 * DEBUG-DRAW OF THE BV-Tree.
752 * @param depth What depth to draw
753 * @param drawMode the mode to draw this entity under
754 */
[7711]755void WorldEntity::drawBVTree(int depth, int drawMode) const
[4684]756{
757  glMatrixMode(GL_MODELVIEW);
758  glPushMatrix();
759  /* translate */
760  glTranslatef (this->getAbsCoor ().x,
761                this->getAbsCoor ().y,
762                this->getAbsCoor ().z);
763  /* rotate */
[4998]764  Vector tmpRot = this->getAbsDir().getSpacialAxis();
765  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[4684]766
[7711]767
[4684]768  if (this->obbTree)
769    this->obbTree->drawBV(depth, drawMode);
[7711]770
771
[4684]772  glPopMatrix();
773}
[6341]774
[6424]775
[6341]776/**
[6424]777 * Debug the WorldEntity
778 */
779void WorldEntity::debugEntity() const
780{
[9406]781  PRINT(0)("WorldEntity %s::%s  (DEBUG)\n", this->getClassCName(), this->getCName());
[6424]782  this->debugNode();
[9656]783  PRINT(0)("List: %s ; ModelCount %d - ", ObjectManager::OMListToString(this->objectListNumber).c_str(), this->models.size());
[6424]784  for (unsigned int i = 0; i < this->models.size(); i++)
785  {
786    if (models[i] != NULL)
[9406]787      PRINT(0)(" : %d:%s", i, this->models[i]->getCName());
[6424]788  }
789  PRINT(0)("\n");
790
791}
792
793
794/**
[7954]795 * handler for changes on registred vars
796 * @param id id's which changed
[6341]797 */
[7954]798void WorldEntity::varChangeHandler( std::list< int > & id )
[6341]799{
[7954]800  if ( std::find( id.begin(), id.end(), modelFileName_handle ) != id.end() ||
801       std::find( id.begin(), id.end(), scaling_handle ) != id.end()
802     )
[6341]803  {
[7954]804    loadModel( modelFileName, scaling );
[6341]805  }
806
[9008]807  if ( std::find( id.begin(), id.end(), list_handle ) != id.end() )
808  {
809    this->toList( (OM_LIST)list_write );
810  }
[9235]811
[9110]812  if ( std::find( id.begin(), id.end(), health_handle ) != id.end() )
813  {
814    this->setHealth( health_write );
815  }
[9235]816
[9110]817  if ( std::find( id.begin(), id.end(), healthMax_handle ) != id.end() )
818  {
819    this->setHealthMax( healthMax_write );
820  }
[9008]821
[7954]822  PNode::varChangeHandler( id );
[6341]823}
824
Note: See TracBrowser for help on using the repository browser.