Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged the branche playability into the trunk

File size: 10.4 KB
Line 
1/*!
2 * @file world_entity.h
3 * Definition of the basic WorldEntity
4 */
5
6#ifndef _WORLD_ENTITY_H
7#define _WORLD_ENTITY_H
8
9#include "p_node.h"
10#include "synchronizeable.h"
11#include "model.h"
12
13#include "cr_engine.h"
14#include "collision_filter.h"
15#include "object_manager.h"
16#include "glincl.h"
17
18#include "aabb_tree_node.h"
19
20#include "physics_interface.h"
21
22#include <vector>
23
24
25// FORWARD DECLARATION
26namespace OrxSound { class SoundBuffer; class SoundSource; }
27namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; class GLGuiEnergyWidgetVertical; };
28namespace CoRe { class Collision; }
29
30class BVTree;
31class BoundingVolume;
32class AABBTreeNode;
33class Model;
34class Track;
35class TiXmlElement;
36
37class ObjectInformationFile;
38class MountPoint;
39
40
41//! Basis-class all interactive stuff in the world is derived from
42class WorldEntity : public PNode
43{
44  ObjectListDeclaration(WorldEntity);
45
46public:
47  WorldEntity();
48  virtual ~WorldEntity ();
49
50  virtual void loadParams(const TiXmlElement* root);
51
52  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
53  void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);}
54  void setModel(Model* model, unsigned int modelNumber = 0);
55  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
56
57  void loadMountPoints(const std::string& fileName);
58  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
59
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
65  /** @param visibility if the Entity should be visible (been draw) */
66  void setVisibiliy (bool visibility) { this->bVisible = visibility; };
67  /** @returns true if the entity is visible, false otherwise */
68  inline bool isVisible() const { return this->bVisible; };
69
70  virtual void reset();
71
72  virtual void postSpawn ();
73  virtual void leaveWorld ();
74
75  virtual void tick (float time);
76  virtual void draw () const;
77  void debugDrawMountPoints() const;
78
79  /* --- Collision Detection Block  --- */
80  bool buildObbTree(int depth);
81  virtual void collidesWith (WorldEntity* entity, const Vector& location);
82  virtual void collidesWithGround(const Vector& location);
83  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
84
85  /** @returns a reference to the obb tree of this worldentity */
86  inline BVTree* getOBBTree() const { return this->obbTree; };
87  inline void setOBBTree(OBBTree* tree) { /*if( this->obbTree != NULL) delete this->obbTree;*/ this->obbTree = (BVTree*)tree; }
88  void drawBVTree(int depth, int drawMode) const;
89  inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
90
91  virtual void hit(float damage, WorldEntity* killer);
92
93
94  /* --- Collision Reaction Block --- */
95  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1);
96  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
97  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
98
99  void unsubscribeReaction(CoRe::CREngine::ReactionType type);
100  void unsubscribeReactions();
101
102  /** @return true if there is at least on collision reaction subscribed */
103  inline bool isReactive() const { return this->_collisionFilter.isReactive(); }
104
105  /** @param worldEntity the world entity to be checked @returns true if there is a collisionreaction registered for the worldEntity */
106  inline bool isReactive( const WorldEntity& worldEntity) const { return this->_collisionFilter(worldEntity); }
107  /** @param worldEntity the world entity to be checked @param type special reaction type @returns true if collision reaction reg. */
108  inline bool isReactive( const WorldEntity& worldEntity, const CoRe::CREngine::ReactionType& type) const
109  { return this->_collisionFilter(worldEntity, type); }
110
111
112  const CoRe::CollisionFilter& getCollisionFilter(CoRe::CREngine::ReactionType type) const { return this->_collisionFilter; }
113
114  /** @returns true if this entity is standing on ground (BSP model) */
115  bool isOnGround() const { return this->_bOnGround; }
116  /** @param flag: marks if this entity is standing on ground */
117  void setOnGround(bool flag) { this->_bOnGround = flag; }
118
119  virtual void destroy( WorldEntity* killer );
120
121
122  /* @returns the Count of Faces on this WorldEntity */
123  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
124  //  void addAbility(Ability* ability);
125  //  void removeAbility(Ability* ability);
126  //  void setCharacterAttributes(CharacterAttributes* charAttr);
127  //  CharacterAttributes* getCharacterAttributes();
128
129  /* --- Object Manager Block --- */
130  void toList(OM_LIST list);
131  void toListS(const std::string& listName);
132
133  void toReflectionList();
134  void removeFromReflectionList();
135
136  /** @returns a Reference to the objectListNumber to set. */
137  OM_LIST& getOMListNumber() { return this->objectListNumber; }
138  /** @returns a Reference to the Iterator */
139  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
140
141  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
142  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
143
144
145  /* --- Character Attribute Block --- */
146  /** @returns the scaling of the model */
147  float getScaling(){return this->scaling;}
148  /** @returns the damage dealt by this world entity */
149  float getDamage() const { return this->damage; }
150  /** sets the damage dealt to @param damage damage per second */
151  void setDamage(float damage) { this->damage = damage; }
152  /** @returns the Energy of the entity */
153  float getHealth() const { return this->health; };
154  /** @returns the Maximum energy this entity can be charged with */
155  float getHealthMax() const { return this->healthMax; }
156  float increaseHealth(float health);
157  float decreaseHealth(float health);
158  void increaseHealthMax(float increaseHealth);
159  OrxGui::GLGuiWidget* getHealthWidget();
160  bool hasHealthWidget() const { return this->healthWidget != NULL; };
161
162  virtual void varChangeHandler( std::list<int> & id );
163
164
165  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
166  /* --- Physics Interface --- */
167  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
168  inline float getMass() const { return this->physicsInterface.getMass(); }
169  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
170  inline void setVelocity(const Vector& vel) { this->velocity = vel; }
171
172
173  /* --- Misc Stuff Block --- */
174  void debugWE() { this->debugEntity(); }
175  ;  ///FIXME
176  void debugEntity() const;
177
178
179protected:
180  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
181  void setHealthWidgetVisibilit(bool visibility);
182  void setHealthMax(float healthMax);
183  void createHealthWidget();
184    //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
185
186
187private:
188  void updateHealthWidget();
189  void addTrack(const TiXmlElement* root);
190
191
192private:
193  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
194  float                   damage;             //!< the damage dealt to other objects by colliding.
195  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
196  float                   healthMax;          //!< The Maximal energy this entity can take.
197  OrxGui::GLGuiEnergyWidgetVertical* healthWidget;    //!< The Slider (if wanted).
198
199  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
200  ObjectInformationFile*  oiFile;             //!< Reference to the object information file discribing the model of this WE
201  std::vector<MountPoint*> mountPoints;       //!< A list with mount points for this model
202  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
203  std::string             modelLODName;       //!< the name of the model lod file
204  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
205  AABBTreeNode*           aabbNode;           //!< the tree node of the first level of a axis aligned bounding boxes tree: model dimension
206
207  bool                    bCollide;           //!< If it should be considered for the collisiontest.
208  bool                    bVisible;           //!< If it should be visible.
209
210  OM_LIST                 objectListNumber;                //!< The ObjectList from ObjectManager this Entity is in.
211  ObjectManager::EntityList::iterator objectListIterator;  //!< The iterator position of this Entity in the given list of the ObjectManager.
212  OM_LIST                 lastObjectListNumber;            //!< the last ObjectList from the ObjectManager this Entity was is in
213
214  /* collision reaction stuff */
215  CoRe::CollisionFilter   _collisionFilter;                //!< filter for collision event filtering (not every entity listens to all collisions)
216  bool                    _bOnGround;                      //!< flag true if the object is on the ground
217
218  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
219
220  /* network help structures */
221  float                   scaling;                         //!< model's scaling factor
222  int                     scaling_handle;                  //!< handle for syncing var
223
224  std::string             modelFileName;                   //!< model's file name
225  int                     modelFileName_handle;            //!< handle for syncing var
226
227  int                     list_write;                      //!< entity's list
228  int                     list_handle;                     //!< handle for list changes
229
230  float                   health_write;
231  int                     health_handle;
232
233  float                   healthMax_write;
234  int                     healthMax_handle;
235
236
237
238protected:
239  Vector                  velocity;                        //!< speed of the entity
240  Track*                  entityTrack;                     //!< this is the track this entity follows (or NULL if none)
241
242};
243
244#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.