Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/world_entity.h

Last change on this file was 10698, checked in by snellen, 17 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 14.3 KB
RevLine 
[4680]1/*!
[4885]2 * @file world_entity.h
3 * Definition of the basic WorldEntity
[7711]4 */
[2036]5
[3224]6#ifndef _WORLD_ENTITY_H
7#define _WORLD_ENTITY_H
[2036]8
[3365]9#include "p_node.h"
[5996]10#include "synchronizeable.h"
11#include "model.h"
[2036]12
[7927]13#include "cr_engine.h"
[10013]14#include "collision_filter.h"
[6142]15#include "object_manager.h"
[5511]16#include "glincl.h"
17
[8724]18#include "aabb_tree_node.h"
19
[8190]20#include "physics_interface.h"
[7927]21
[10147]22#include <vector>
[7927]23
[8190]24
[4885]25// FORWARD DECLARATION
[7460]26namespace OrxSound { class SoundBuffer; class SoundSource; }
[10368]27namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; class GLGuiEnergyWidgetVertical; };
[10013]28namespace CoRe { class Collision; }
[7779]29
[5143]30class BVTree;
[8190]31class BoundingVolume;
[8724]32class AABBTreeNode;
[5511]33class Model;
[10368]34class Track;
35class TiXmlElement;
[6440]36
[10147]37class ObjectInformationFile;
38class MountPoint;
[7927]39
[10147]40
[4885]41//! Basis-class all interactive stuff in the world is derived from
[6498]42class WorldEntity : public PNode
[4680]43{
[9869]44  ObjectListDeclaration(WorldEntity);
[10013]45
[6430]46public:
47  WorldEntity();
[3221]48  virtual ~WorldEntity ();
[3365]49
[6512]50  virtual void loadParams(const TiXmlElement* root);
[5994]51
[7711]52  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
[9235]53  void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);}
[5994]54  void setModel(Model* model, unsigned int modelNumber = 0);
[10013]55  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
[5994]56
[10314]57  void loadMountPoints(const std::string& fileName);
[7221]58  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
[6222]59
[10147]60  void addMountPoint(MountPoint* mountPoint);
61  void addMountPoint(int slot, MountPoint* mountPoint);
62  void mount(int slot, WorldEntity* entity);
63  void unmount(int slot);
64
[10540]65
66
[4885]67  /** @param visibility if the Entity should be visible (been draw) */
[10511]68  void setVisibility (bool visibility) { this->bVisible = visibility; };
[4885]69  /** @returns true if the entity is visible, false otherwise */
[5511]70  inline bool isVisible() const { return this->bVisible; };
[5026]71
[7085]72  virtual void reset();
[3583]73
[3229]74  virtual void postSpawn ();
[6959]75  virtual void leaveWorld ();
[3583]76
[5501]77  virtual void tick (float time);
78  virtual void draw () const;
[10391]79  void draw(const Model* model) const;
[10314]80  void debugDrawMountPoints() const;
[6005]81
[7927]82  /* --- Collision Detection Block  --- */
[7711]83  bool buildObbTree(int depth);
[5029]84  virtual void collidesWith (WorldEntity* entity, const Vector& location);
[8186]85  virtual void collidesWithGround(const Vector& location);
86  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
87
[9869]88  /** @returns a reference to the obb tree of this worldentity */
[7711]89  inline BVTree* getOBBTree() const { return this->obbTree; };
[9235]90  inline void setOBBTree(OBBTree* tree) { /*if( this->obbTree != NULL) delete this->obbTree;*/ this->obbTree = (BVTree*)tree; }
[7711]91  void drawBVTree(int depth, int drawMode) const;
[9235]92  inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
[5501]93
[10013]94  virtual void hit(float damage, WorldEntity* killer);
95
96
[7927]97  /* --- Collision Reaction Block --- */
[10013]98  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1);
99  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
100  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
[6424]101
[10013]102  void unsubscribeReaction(CoRe::CREngine::ReactionType type);
103  void unsubscribeReactions();
[6424]104
[8190]105  /** @return true if there is at least on collision reaction subscribed */
[10013]106  inline bool isReactive() const { return this->_collisionFilter.isReactive(); }
[8190]107
[10013]108  /** @param worldEntity the world entity to be checked @returns true if there is a collisionreaction registered for the worldEntity */
109  inline bool isReactive( const WorldEntity& worldEntity) const { return this->_collisionFilter(worldEntity); }
110  /** @param worldEntity the world entity to be checked @param type special reaction type @returns true if collision reaction reg. */
111  inline bool isReactive( const WorldEntity& worldEntity, const CoRe::CREngine::ReactionType& type) const
112  { return this->_collisionFilter(worldEntity, type); }
[8190]113
[10013]114
115  const CoRe::CollisionFilter& getCollisionFilter(CoRe::CREngine::ReactionType type) const { return this->_collisionFilter; }
116
[9003]117  /** @returns true if this entity is standing on ground (BSP model) */
[10013]118  bool isOnGround() const { return this->_bOnGround; }
[9003]119  /** @param flag: marks if this entity is standing on ground */
[10013]120  void setOnGround(bool flag) { this->_bOnGround = flag; }
[9003]121
[9235]122  virtual void destroy( WorldEntity* killer );
[8190]123
[8724]124
[5510]125  /* @returns the Count of Faces on this WorldEntity */
126  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
127  //  void addAbility(Ability* ability);
128  //  void removeAbility(Ability* ability);
129  //  void setCharacterAttributes(CharacterAttributes* charAttr);
130  //  CharacterAttributes* getCharacterAttributes();
[4680]131
[7927]132  /* --- Object Manager Block --- */
[6142]133  void toList(OM_LIST list);
[9656]134  void toListS(const std::string& listName);
[8037]135
136  void toReflectionList();
137  void removeFromReflectionList();
138
[6142]139  /** @returns a Reference to the objectListNumber to set. */
140  OM_LIST& getOMListNumber() { return this->objectListNumber; }
141  /** @returns a Reference to the Iterator */
[7370]142  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
[6222]143
[8894]144  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
[10013]145  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
[8894]146
147
[7927]148  /* --- Character Attribute Block --- */
[9298]149  /** @returns the scaling of the model */
[10013]150  float getScaling(){return this->scaling;}
[8190]151  /** @returns the damage dealt by this world entity */
152  float getDamage() const { return this->damage; }
153  /** sets the damage dealt to @param damage damage per second */
154  void setDamage(float damage) { this->damage = damage; }
[6430]155  /** @returns the Energy of the entity */
[6700]156  float getHealth() const { return this->health; };
[6430]157  /** @returns the Maximum energy this entity can be charged with */
[6700]158  float getHealthMax() const { return this->healthMax; }
159  float increaseHealth(float health);
160  float decreaseHealth(float health);
161  void increaseHealthMax(float increaseHealth);
[7779]162  OrxGui::GLGuiWidget* getHealthWidget();
[10698]163  OrxGui::GLGuiWidget* getImplantWidget();
164  OrxGui::GLGuiWidget* getShieldWidget();
165  OrxGui::GLGuiWidget* getElectronicWidget();
[10368]166  bool hasHealthWidget() const { return this->healthWidget != NULL; };
[8190]167
[10698]168  float getShield() const { return this->shield; };
169  float getShieldMax() const { return this->shieldMax; };
170  float increaseShield(float shield);
171  float decreaseShield(float shield);
172  bool getShieldActive() { return this->bShieldActive; };
173
174  float getElectronic() const { return this->electronic; };
175  float getElectronicMax() const { return this->electronicMax; };
176  float increaseElectronic(float electronic);
177  float decreaseElectronic(float electronic);
178
179  bool systemFailure() {  return (this->electronic < float(rand())/float(RAND_MAX) * this->electronicTH); };
180
181  void resetElectronic() { this->electronic = this->electronicMax; };
182  void resetShield()  { this->shield = this->shieldMax; this->bShieldActive = true; };
183  void resetHealth() { this->health = this->healthMax; };
184
185  void createHealthWidget();
186  void createShieldWidget();
187  void createElectronicWidget();
188
189  void regen(float time);
190
191  void loadShield(float cur, float max, float th, float regen)
192      { this->setShield(cur); this->setShieldMax(max); this->setShieldTH(th); this->setShieldRegen(regen); };
193  void loadHealth(float cur, float max, float regen = 0) { this->setHealth(cur); this->setHealthMax(max); this->setHealthRegen(regen); };
194  void loadElectronic(float cur, float max, float th, float regen)
195      { this->setElectronic(cur); this->setElectronicMax(max); this->setElectronicTH(th); this->setElectronicRegen(regen); };
196
197
[7954]198  virtual void varChangeHandler( std::list<int> & id );
[6430]199
[8190]200
201  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
202  /* --- Physics Interface --- */
203  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
204  inline float getMass() const { return this->physicsInterface.getMass(); }
205  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
[8490]206  inline void setVelocity(const Vector& vel) { this->velocity = vel; }
[8190]207
208
[7927]209  /* --- Misc Stuff Block --- */
210  void debugWE() { this->debugEntity(); }
211  ;  ///FIXME
212  void debugEntity() const;
[10540]213
[10498]214  void pauseTrack(bool stop);
[7927]215
[10698]216//   void updateHealthWidget();
217//   void updateElectronicWidget();
218//   void updateShieldWidget();
[7927]219
[6430]220protected:
[10698]221  inline void setHealth(float health) { this->health = health; this->updateHealthWidget();};
222  void setHealthWidgetVisibility(bool visibility);
[6700]223  void setHealthMax(float healthMax);
[10698]224//   void createHealthWidget();
225//   void createShieldWidget();
226//   void createElectronicWidget();
227  void setHealthRegen(float regen) { this->healthRegen = regen; };
228  void createImplantWidget();
[10013]229    //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
[7711]230
[10698]231  void setShield(float shield) { this->shield = shield; };
232  void setShieldMax(float shield) { this->shieldMax = shield; };
233  void setShieldTH(float th) { this->shieldTH = th; };
234  void setShieldRegen(float regen) { this->shieldRegen = regen; };
235  void setShieldActive(bool active) { this->bShieldActive = active; };
236
237  void setElectronic(float electronic) { this->electronic = electronic; };
238  void setElectronicMax(float electronic) { this->electronicMax = electronic; };
239  void setElectronicTH(float th) { this->electronicTH = th; };
240  void setElectronicRegen(float regen) { this->electronicRegen = regen; };
241
[10449]242  inline void drawDebugTrack(int flag) { this->bDrawTrack = (bool)flag; }
243  inline bool isDrawTrack() const { return this->bDrawTrack; }
[10013]244
[6430]245private:
[6700]246  void updateHealthWidget();
[10698]247  void updateElectronicWidget();
248  void updateShieldWidget();
[10368]249  void addTrack(const TiXmlElement* root);
[5994]250
[10013]251
[10540]252
[10698]253protected:
254  std::vector<MountPoint*> mountPoints;       //!< A list with mount points for this model
255  std::map<int, MountPoint*> mountPointMap;
[10540]256
257
258
[6430]259private:
[10698]260
261  //!< TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
262  //!< started transfering shield/electronic/health from spaceship to WE! (nico, 4.Jun.07)
263
[8190]264  float                   damage;             //!< the damage dealt to other objects by colliding.
[6700]265  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
[10698]266  float                   healthMax;          //!< The Maximal energy this entity can take.
267  float                                         implantEnergy;          //!< energy of implants
268  float                   healthRegen;        //!< Regeneration Rate of Health, mesured in units per second
[10368]269  OrxGui::GLGuiEnergyWidgetVertical* healthWidget;    //!< The Slider (if wanted).
[10698]270  OrxGui::GLGuiEnergyWidgetVertical* implantWidget; 
[6341]271
[10698]272  float       shield;             //!< current shield
273  float       shieldMax;          //!< maximum shield
274  float       shieldRegen;        //!< shield regeneration rate per second
275  float       shieldTH;           //!< shield threshhold for reactivation
276  bool        bShieldActive;      //!< wheather the shield is working
277  OrxGui::GLGuiEnergyWidgetVertical* shieldWidget; //!< holds the widget that shows the shield bar
278
279  float       electronic;         //!< current electronic
280  float       electronicMax;      //!< maximum electronic
281  float       electronicRegen;    //!< electronic regenration rate per tick
282  float       electronicTH;       //!< Threshhold for electronic failure
283  OrxGui::GLGuiEnergyWidgetVertical* electronicWidget; //!< holds the widget that shows the electronic bar
284
285
[6142]286  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
[10147]287  ObjectInformationFile*  oiFile;             //!< Reference to the object information file discribing the model of this WE
[7221]288  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
289  std::string             modelLODName;       //!< the name of the model lod file
[6142]290  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
[8724]291  AABBTreeNode*           aabbNode;           //!< the tree node of the first level of a axis aligned bounding boxes tree: model dimension
[4680]292
[6142]293  bool                    bCollide;           //!< If it should be considered for the collisiontest.
294  bool                    bVisible;           //!< If it should be visible.
295
[8190]296  OM_LIST                 objectListNumber;                //!< The ObjectList from ObjectManager this Entity is in.
297  ObjectManager::EntityList::iterator objectListIterator;  //!< The iterator position of this Entity in the given list of the ObjectManager.
[8894]298  OM_LIST                 lastObjectListNumber;            //!< the last ObjectList from the ObjectManager this Entity was is in
[6142]299
[10013]300  /* collision reaction stuff */
301  CoRe::CollisionFilter   _collisionFilter;                //!< filter for collision event filtering (not every entity listens to all collisions)
302  bool                    _bOnGround;                      //!< flag true if the object is on the ground
[6341]303
[10013]304  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
[6341]305
[10013]306  /* network help structures */
[8190]307  float                   scaling;                         //!< model's scaling factor
308  int                     scaling_handle;                  //!< handle for syncing var
309
310  std::string             modelFileName;                   //!< model's file name
311  int                     modelFileName_handle;            //!< handle for syncing var
312
[9008]313  int                     list_write;                      //!< entity's list
314  int                     list_handle;                     //!< handle for list changes
[9235]315
[9110]316  float                   health_write;
317  int                     health_handle;
[9235]318
[9110]319  float                   healthMax_write;
320  int                     healthMax_handle;
[10698]321 
[9008]322
[8190]323
324
[10698]325
[9869]326protected:
[8490]327  Vector                  velocity;                        //!< speed of the entity
[10368]328  Track*                  entityTrack;                     //!< this is the track this entity follows (or NULL if none)
[10449]329  bool                    bDrawTrack;                      //!< if true draws the debug track
[8490]330
[2036]331};
332
[3224]333#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.