Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9656 was 9656, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy bache back with no conflicts

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