Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/world_entities/world_entity.cc @ 9889

Last change on this file since 9889 was 9889, checked in by patrick, 18 years ago

added namspacing to collision reaction. now comes the harder part :D

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