Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10184 was 10184, checked in by patrick, 14 years ago

extended model again, added mounting point generation procedures now working on a nicer interface

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