Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/mount_points/src/world_entities/world_entity.h @ 10052

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

integrating loading to we

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