Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/single_player_map/src/world_entities/world_entity.h @ 8939

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

world entity on ground function

File size: 8.7 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; };
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 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
74/** @returns a reference to the obb tree of this worldentity */
75  inline BVTree* getOBBTree() const { return this->obbTree; };
76  void drawBVTree(int depth, int drawMode) const;
77  inline AABB* getModelAABB() { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
78
79  /* --- Collision Reaction Block --- */
80  void subscribeReaction(CREngine::CRType type);
81  void subscribeReaction(CREngine::CRType type, long target1);
82  void subscribeReaction(CREngine::CRType type, long target1, long target2);
83  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3);
84  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4);
85
86  void unsubscribeReaction(CREngine::CRType type);
87  void unsubscribeReaction();
88
89  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
90  bool registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall = false);
91  /** @return true if there is at least on collision reaction subscribed */
92  inline bool isReactive() const { return this->bReactive; }
93
94  CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
95
96  /** @returns true if this entity is standing on ground (BSP model) */
97  bool isOnGround() const { return this->isOnGround(); }
98  /** @param flag: marks if this entity is standing on ground */
99  void setOnGround(bool flag) { this->bOnGround = flag; }
100
101  virtual void hit(float damage);
102  virtual void destroy();
103
104
105  /* @returns the Count of Faces on this WorldEntity */
106  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
107  //  void addAbility(Ability* ability);
108  //  void removeAbility(Ability* ability);
109  //  void setCharacterAttributes(CharacterAttributes* charAttr);
110  //  CharacterAttributes* getCharacterAttributes();
111
112  /* --- Object Manager Block --- */
113  void toList(OM_LIST list);
114
115  void toReflectionList();
116  void removeFromReflectionList();
117
118  /** @returns a Reference to the objectListNumber to set. */
119  OM_LIST& getOMListNumber() { return this->objectListNumber; }
120  /** @returns a Reference to the Iterator */
121  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
122
123  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
124  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
125
126
127  /* --- Character Attribute Block --- */
128  /** @returns the damage dealt by this world entity */
129  float getDamage() const { return this->damage; }
130  /** sets the damage dealt to @param damage damage per second */
131  void setDamage(float damage) { this->damage = damage; }
132  /** @returns the Energy of the entity */
133  float getHealth() const { return this->health; };
134  /** @returns the Maximum energy this entity can be charged with */
135  float getHealthMax() const { return this->healthMax; }
136  float increaseHealth(float health);
137  float decreaseHealth(float health);
138  void increaseHealthMax(float increaseHealth);
139  OrxGui::GLGuiWidget* getHealthWidget();
140  bool hasHealthWidget() const { return this->healthWidget; };
141
142  virtual void varChangeHandler( std::list<int> & id );
143
144
145  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
146  /* --- Physics Interface --- */
147  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
148  inline float getMass() const { return this->physicsInterface.getMass(); }
149  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
150  inline void setVelocity(const Vector& vel) { this->velocity = vel; }
151
152
153  /* --- Misc Stuff Block --- */
154  void debugWE() { this->debugEntity(); }
155  ;  ///FIXME
156  void debugEntity() const;
157
158
159protected:
160  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
161  void setHealthWidgetVisibilit(bool visibility);
162  void setHealthMax(float healthMax);
163  void createHealthWidget();
164
165  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
166private:
167  void updateHealthWidget();
168
169private:
170  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
171  float                   damage;             //!< the damage dealt to other objects by colliding.
172  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
173  float                   healthMax;          //!< The Maximal energy this entity can take.
174  OrxGui::GLGuiBar*       healthWidget;       //!< The Slider (if wanted).
175
176  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
177  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
178  std::string             modelLODName;       //!< the name of the model lod file
179  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
180  AABBTreeNode*           aabbNode;           //!< the tree node of the first level of a axis aligned bounding boxes tree: model dimension
181
182  bool                    bCollide;           //!< If it should be considered for the collisiontest.
183  bool                    bVisible;           //!< If it should be visible.
184
185  OM_LIST                 objectListNumber;                //!< The ObjectList from ObjectManager this Entity is in.
186  ObjectManager::EntityList::iterator objectListIterator;  //!< The iterator position of this Entity in the given list of the ObjectManager.
187  OM_LIST                 lastObjectListNumber;            //!< the last ObjectList from the ObjectManager this Entity was is in
188
189
190
191  float                   scaling;                         //!< model's scaling factor
192  int                     scaling_handle;                  //!< handle for syncing var
193
194  std::string             modelFileName;                   //!< model's file name
195  int                     modelFileName_handle;            //!< handle for syncing var
196
197  CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
198  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
199
200  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
201  bool                    bOnGround;                       //!< true if this entity is standing on the ground
202
203  protected:
204  Vector                  velocity;                        //!< speed of the entity
205
206};
207
208#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.