Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/scriptchanges/src/world_entities/world_entity.h @ 10451

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

merged branche mount_point to trunk. this will add mount point abilities, bsp transparency fix and some other smaller stuff to this trunk

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