Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

more oif starting procedures

File size: 20.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
211      std::string oifName = fileName.substr(0, fileName.length() - 3) + ".oif";
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{
268  PRINTF(0)("loading the oif File: %s", 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/**
[7927]319 * subscribes this world entity to a collision reaction
320 *  @param type the type of reaction to subscribe to
[8190]321 *  @param target1 a filter target (classID)
322 */
[10013]323void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
[8190]324{
[10013]325  this->_collisionFilter.subscribeReaction(type, target1);
[8190]326}
327
328
329/**
330 * subscribes this world entity to a collision reaction
331 *  @param type the type of reaction to subscribe to
332 *  @param target1 a filter target (classID)
333 */
[10013]334void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
[8190]335{
[10013]336  this->_collisionFilter.subscribeReaction(type, target1, target2);
[8190]337}
338
339
340/**
341 * subscribes this world entity to a collision reaction
342 *  @param type the type of reaction to subscribe to
343 *  @param target1 a filter target (classID)
344 */
[10013]345void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
[8190]346{
[10013]347  this->_collisionFilter.subscribeReaction(type, target1, target2, target3);
[8190]348}
349
350
351/**
352 * unsubscribes a specific reaction from the worldentity
353 *  @param type the reaction to unsubscribe
354 */
[10013]355void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type)
[8190]356{
[10013]357  this->_collisionFilter.unsubscribeReaction(type);
[8190]358}
359
360
361/**
362 * unsubscribes all collision reactions
363 */
[10013]364void WorldEntity::unsubscribeReactions()
[8190]365{
[10013]366  this->_collisionFilter.unsubscribeReactions();
[8190]367}
368
369
370/**
[6142]371 * @brief moves this entity to the List OM_List
372 * @param list the list to set this Entity to.
373 *
374 * this is the same as a call to State::getObjectManager()->toList(entity , list);
375 * directly, but with an easier interface.
376 *
377 * @todo inline this (peut etre)
378 */
379void WorldEntity::toList(OM_LIST list)
380{
381  State::getObjectManager()->toList(this, list);
382}
[5061]383
[9656]384void WorldEntity::toListS(const std::string& listName)
385{
386  OM_LIST id = ObjectManager::StringToOMList(listName);
387  if (id != OM_NULL)
388    this->toList(id);
389  else
390    PRINTF(2)("List %s not found\n", listName.c_str());
391}
392
393
[8037]394void WorldEntity::toReflectionList()
395{
396  State::getObjectManager()->toReflectionList( this );
397}
[6142]398
[8037]399void removeFromReflectionList()
400{
[9869]401  /// TODO
402  ///  State::getObject
[8037]403}
[6142]404
[4261]405/**
[4885]406 * sets the character attributes of a worldentity
[4836]407 * @param character attributes
[4885]408 *
409 * these attributes don't have to be set, only use them, if you need them
[2043]410*/
[5498]411//void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
412//{}
[2036]413
[3583]414
[2043]415/**
[5029]416 *  this function is called, when two entities collide
417 * @param entity: the world entity with whom it collides
418 *
419 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
420 */
421void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location)
422{
[5498]423  /**
424   * THIS IS A DEFAULT COLLISION-Effect.
425   * IF YOU WANT TO CREATE A SPECIFIC COLLISION ON EACH OBJECT
426   * USE::
427   * if (entity->isA(CL_WHAT_YOU_ARE_LOOKING_FOR)) { printf "dothings"; };
428   *
429   * You can always define a default Action.... don't be affraid just test it :)
430   */
[9406]431  //  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z);
[5029]432}
433
[2043]434
435/**
[8186]436 *  this function is called, when two entities collide
437 * @param entity: the world entity with whom it collides
438 *
439 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
440 */
441void WorldEntity::collidesWithGround(const Vector& location)
442{
[9406]443  PRINTF(0)("BSP_GROUND: %s collides \n", this->getClassCName() );
[8186]444}
445
446void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2)
447{
[8190]448
[9406]449  // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassCName() );
[8190]450
[8186]451  Vector v = this->getAbsDirX();
[8490]452  v.x *= 10.1;
453  v.y *= 10.1;
454  v.z *= 10.1;
455  Vector u = Vector(0.0,-20.0,0.0);
[8190]456
[8490]457
458  if(!(this->getAbsCoor().x == ray_2.x && this->getAbsCoor().y == ray_2.y && this->getAbsCoor().z == ray_2.z) )
[8186]459  {
[8190]460
[9869]461    this->setAbsCoor(ray_2 - v);
[8490]462
[8186]463  }
[9869]464  else
[8186]465  {
466    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)
467    {
[8190]468      this->setAbsCoor(feet -u );
[8186]469    }
[8190]470
471    this->setAbsCoor(ray_2 - v);
472
[8186]473  }
[8490]474
475
[8186]476}
477
478/**
[5498]479 *  this is called immediately after the Entity has been constructed, initialized and then Spawned into the World
[4885]480 *
[5498]481 */
[3229]482void WorldEntity::postSpawn ()
[6430]483{}
[2043]484
[3583]485
[2043]486/**
[6959]487 *  this method is called by the world if the WorldEntity leaves the game
[5498]488 */
[6959]489void WorldEntity::leaveWorld ()
[6430]490{}
[2043]491
[3583]492
[2190]493/**
[7085]494 * resets the WorldEntity to its initial values. eg. used for multiplayer games: respawning
495 */
496void WorldEntity::reset()
[9235]497{
498  this->setHealth( this->getHealthMax() );
499}
[7085]500
501/**
[4836]502 *  this method is called every frame
503 * @param time: the time in seconds that has passed since the last tick
[4885]504 *
505 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
[2043]506*/
[4570]507void WorldEntity::tick(float time)
[6430]508{}
[3583]509
[5498]510
[3583]511/**
[4836]512 *  the entity is drawn onto the screen with this function
[4885]513 *
514 * This is a central function of an entity: call it to let the entity painted to the screen.
515 * Just override this function with whatever you want to be drawn.
[3365]516*/
[5500]517void WorldEntity::draw() const
[3803]518{
[9406]519  //PRINTF(0)("(%s::%s)\n", this->getClassCName(), this->getName());
[6281]520  //  assert(!unlikely(this->models.empty()));
[6002]521  {
522    glMatrixMode(GL_MODELVIEW);
523    glPushMatrix();
[4570]524
[6002]525    /* translate */
526    glTranslatef (this->getAbsCoor ().x,
527                  this->getAbsCoor ().y,
528                  this->getAbsCoor ().z);
[6004]529    Vector tmpRot = this->getAbsDir().getSpacialAxis();
530    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[2043]531
[6004]532
533    // This Draws the LOD's
[7014]534    float cameraDistance = State::getCamera()->distance(this);
[6004]535    if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL)
[6002]536    {
[6222]537      this->models[2]->draw();
[6004]538    }
539    else if (cameraDistance > 10 && this->models.size() >= 2 && this->models[1] != NULL)
[6002]540    {
541      this->models[1]->draw();
[6004]542    }
543    else if (this->models.size() >= 1 && this->models[0] != NULL)
[6002]544    {
545      this->models[0]->draw();
546    }
[8724]547
[9869]548    //     if( this->aabbNode != NULL)
549    //       this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);
[8724]550
[6002]551    glPopMatrix();
552  }
[3803]553}
[3583]554
[6430]555/**
[6700]556 * @param health the Health to add.
557 * @returns the health left (this->healthMax - health+this->health)
[6430]558 */
[6700]559float WorldEntity::increaseHealth(float health)
[6430]560{
[6700]561  this->health += health;
562  if (this->health > this->healthMax)
[6430]563  {
[6700]564    float retHealth = this->healthMax - this->health;
565    this->health = this->healthMax;
566    this->updateHealthWidget();
567    return retHealth;
[6430]568  }
[6700]569  this->updateHealthWidget();
[6430]570  return 0.0;
571}
[6281]572
[5498]573/**
[6700]574 * @param health the Health to be removed
[6430]575 * @returns 0.0 or the rest, that was not substracted (bellow 0.0)
576 */
[6700]577float WorldEntity::decreaseHealth(float health)
[6430]578{
[6700]579  this->health -= health;
[6430]580
[6700]581  if (this->health < 0)
[6430]582  {
[6700]583    float retHealth = -this->health;
584    this->health = 0.0f;
585    this->updateHealthWidget();
586    return retHealth;
[6430]587  }
[6700]588  this->updateHealthWidget();
[6430]589  return 0.0;
590
591}
592
593/**
[6700]594 * @param maxHealth the maximal health that can be loaded onto the entity.
[6430]595 */
[6700]596void WorldEntity::setHealthMax(float healthMax)
[6430]597{
[6700]598  this->healthMax = healthMax;
599  if (this->health > this->healthMax)
[6430]600  {
[9406]601    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]602    this->health = this->healthMax;
[6430]603  }
[6700]604  this->updateHealthWidget();
[6430]605}
606
[6431]607/**
[6700]608 * @brief creates the HealthWidget
[6431]609 *
[6700]610 * since not all entities need an HealthWidget, it is only created on request.
[6431]611 */
[6700]612void WorldEntity::createHealthWidget()
[6430]613{
[6700]614  if (this->healthWidget == NULL)
[6430]615  {
[8974]616    this->healthWidget = new OrxGui::GLGuiEnergyWidget();
[8977]617    this->healthWidget->setDisplayedName(std::string(this->getClassName()) + " Energy:");
[6700]618    this->healthWidget->setSize2D(30,400);
619    this->healthWidget->setAbsCoor2D(10,100);
[6430]620
[6700]621    this->updateHealthWidget();
[6430]622  }
623  else
[9406]624    PRINTF(3)("Allready created the HealthWidget for %s::%s\n", this->getClassCName(), this->getCName());
[6430]625}
626
[6700]627void WorldEntity::increaseHealthMax(float increaseHealth)
[6440]628{
[6700]629  this->healthMax += increaseHealth;
630  this->updateHealthWidget();
[6440]631}
632
[6700]633
[7779]634OrxGui::GLGuiWidget* WorldEntity::getHealthWidget()
[6700]635{
636  this->createHealthWidget();
637  return this->healthWidget;
638}
639
[6431]640/**
[6700]641 * @param visibility shows or hides the health-bar
[6431]642 * (creates the widget if needed)
643 */
[6700]644void WorldEntity::setHealthWidgetVisibilit(bool visibility)
[6430]645{
[7198]646  if (visibility)
647  {
648    if (this->healthWidget != NULL)
649      this->healthWidget->show();
650    else
[6430]651    {
[7198]652      this->createHealthWidget();
653      this->updateHealthWidget();
654      this->healthWidget->show();
[6430]655    }
[7198]656  }
657  else if (this->healthWidget != NULL)
658    this->healthWidget->hide();
[6430]659}
660
[8724]661
[6431]662/**
[8724]663 * hit the world entity with
664 *  @param damage damage to be dealt
665 */
[9008]666void WorldEntity::hit(float damage, WorldEntity* killer)
[8724]667{
668  this->decreaseHealth(damage);
669
[9406]670  PRINTF(5)("Hit me: %s::%s now only %f/%f health\n", this->getClassCName(), this->getCName(), this->getHealth(), this->getHealthMax());
[8777]671
[8724]672  if( this->getHealth() > 0)
673  {
674    // any small explosion animaitions
675  }
676  else
677  {
[9235]678    this->destroy( killer );
[8724]679  }
680}
681
682
683/**
[8777]684 * destoys the world entity
685 */
[9235]686void WorldEntity::destroy(WorldEntity* killer)
[8777]687{
688  this->toList(OM_DEAD);
689}
690
691
692/**
[6700]693 * @brief updates the HealthWidget
[6431]694 */
[6700]695void WorldEntity::updateHealthWidget()
[6430]696{
[6700]697  if (this->healthWidget != NULL)
[6430]698  {
[6700]699    this->healthWidget->setMaximum(this->healthMax);
700    this->healthWidget->setValue(this->health);
[6430]701  }
702}
703
704
705/**
[5498]706 * DEBUG-DRAW OF THE BV-Tree.
707 * @param depth What depth to draw
708 * @param drawMode the mode to draw this entity under
709 */
[7711]710void WorldEntity::drawBVTree(int depth, int drawMode) const
[4684]711{
712  glMatrixMode(GL_MODELVIEW);
713  glPushMatrix();
714  /* translate */
715  glTranslatef (this->getAbsCoor ().x,
716                this->getAbsCoor ().y,
717                this->getAbsCoor ().z);
718  /* rotate */
[4998]719  Vector tmpRot = this->getAbsDir().getSpacialAxis();
720  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[4684]721
[7711]722
[4684]723  if (this->obbTree)
724    this->obbTree->drawBV(depth, drawMode);
[7711]725
726
[4684]727  glPopMatrix();
728}
[6341]729
[6424]730
[6341]731/**
[6424]732 * Debug the WorldEntity
733 */
734void WorldEntity::debugEntity() const
735{
[9406]736  PRINT(0)("WorldEntity %s::%s  (DEBUG)\n", this->getClassCName(), this->getCName());
[6424]737  this->debugNode();
[9656]738  PRINT(0)("List: %s ; ModelCount %d - ", ObjectManager::OMListToString(this->objectListNumber).c_str(), this->models.size());
[6424]739  for (unsigned int i = 0; i < this->models.size(); i++)
740  {
741    if (models[i] != NULL)
[9406]742      PRINT(0)(" : %d:%s", i, this->models[i]->getCName());
[6424]743  }
744  PRINT(0)("\n");
745
746}
747
748
749/**
[7954]750 * handler for changes on registred vars
751 * @param id id's which changed
[6341]752 */
[7954]753void WorldEntity::varChangeHandler( std::list< int > & id )
[6341]754{
[7954]755  if ( std::find( id.begin(), id.end(), modelFileName_handle ) != id.end() ||
756       std::find( id.begin(), id.end(), scaling_handle ) != id.end()
757     )
[6341]758  {
[7954]759    loadModel( modelFileName, scaling );
[6341]760  }
761
[9008]762  if ( std::find( id.begin(), id.end(), list_handle ) != id.end() )
763  {
764    this->toList( (OM_LIST)list_write );
765  }
[9235]766
[9110]767  if ( std::find( id.begin(), id.end(), health_handle ) != id.end() )
768  {
769    this->setHealth( health_write );
770  }
[9235]771
[9110]772  if ( std::find( id.begin(), id.end(), healthMax_handle ) != id.end() )
773  {
774    this->setHealthMax( healthMax_write );
775  }
[9008]776
[7954]777  PNode::varChangeHandler( id );
[6341]778}
779
Note: See TracBrowser for help on using the repository browser.