Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/world_entities/world_entity.h @ 9896

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

more design, thinner interface

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