Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: merged the cr branche to trunk

File size: 7.6 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 "physics_interface.h"
19
20
21
22// FORWARD DECLARATION
23namespace OrxSound { class SoundBuffer; class SoundSource; }
24namespace OrxGui { class GLGuiWidget; class GLGuiBar; };
25
26class BVTree;
27class BoundingVolume;
28class Model;
29class CollisionHandle;
30class Collision;
31class Plane;
32
33
34//class CharacterAttributes;
35
36
37//! Basis-class all interactive stuff in the world is derived from
38class WorldEntity : public PNode
39{
40public:
41  WorldEntity();
42  virtual ~WorldEntity ();
43
44  virtual void loadParams(const TiXmlElement* root);
45
46  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
47  void setModel(Model* model, unsigned int modelNumber = 0);
48  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
49
50  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
51
52  /** @param visibility if the Entity should be visible (been draw) */
53  void setVisibiliy (bool visibility) { this->bVisible = visibility; };
54  /** @returns true if the entity is visible, false otherwise */
55  inline bool isVisible() const { return this->bVisible; };
56
57  virtual void reset();
58
59  virtual void postSpawn ();
60  virtual void leaveWorld ();
61  virtual void destroy() {};
62
63  virtual void tick (float time);
64  virtual void draw () const;
65
66  /* --- Collision Detection Block  --- */
67  bool buildObbTree(int depth);
68  virtual void collidesWith (WorldEntity* entity, const Vector& location);
69  virtual void collidesWithGround(const Vector& location);
70  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
71
72
73/** @returns a reference to the obb tree of this worldentity */
74  inline BVTree* getOBBTree() const { return this->obbTree; };
75  void drawBVTree(int depth, int drawMode) const;
76
77  /* --- Collision Reaction Block --- */
78  void subscribeReaction(CREngine::CRType type);
79  void subscribeReaction(CREngine::CRType type, long target1);
80  void subscribeReaction(CREngine::CRType type, long target1, long target2);
81  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3);
82  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4);
83
84  void unsubscribeReaction(CREngine::CRType type);
85  void unsubscribeReaction();
86
87  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
88  bool registerCollision(WorldEntity* entity, Plane* plane, Vector position);
89  /** @return true if there is at least on collision reaction subscribed */
90  inline bool isReactive() const { return this->bReactive; }
91
92  CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
93
94
95  /* @returns the Count of Faces on this WorldEntity */
96  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
97  //  void addAbility(Ability* ability);
98  //  void removeAbility(Ability* ability);
99  //  void setCharacterAttributes(CharacterAttributes* charAttr);
100  //  CharacterAttributes* getCharacterAttributes();
101
102  /* --- Object Manager Block --- */
103  void toList(OM_LIST list);
104
105  void toReflectionList();
106  void removeFromReflectionList();
107
108  /** @returns a Reference to the objectListNumber to set. */
109  OM_LIST& getOMListNumber() { return this->objectListNumber; }
110  /** @returns a Reference to the Iterator */
111  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
112
113  /* --- Network Block --- */
114  int       writeState(const byte* data, int length, int sender);
115  int       readState(byte* data, int maxLength );
116
117  /* --- Character Attribute Block --- */
118  /** @returns the damage dealt by this world entity */
119  float getDamage() const { return this->damage; }
120  /** sets the damage dealt to @param damage damage per second */
121  void setDamage(float damage) { this->damage = damage; }
122  /** @returns the Energy of the entity */
123  float getHealth() const { return this->health; };
124  /** @returns the Maximum energy this entity can be charged with */
125  float getHealthMax() const { return this->healthMax; }
126  float increaseHealth(float health);
127  float decreaseHealth(float health);
128  void increaseHealthMax(float increaseHealth);
129  OrxGui::GLGuiWidget* getHealthWidget();
130  bool hasHealthWidget() const { return this->healthWidget; };
131
132  virtual void varChangeHandler( std::list<int> & id );
133
134
135  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
136  /* --- Physics Interface --- */
137  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
138  inline float getMass() const { return this->physicsInterface.getMass(); }
139  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
140
141
142  /* --- Misc Stuff Block --- */
143  void debugWE() { this->debugEntity(); }
144  ;  ///FIXME
145  void debugEntity() const;
146
147
148protected:
149  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
150  void setHealthWidgetVisibilit(bool visibility);
151  void setHealthMax(float healthMax);
152  void createHealthWidget();
153
154  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
155private:
156  void updateHealthWidget();
157
158private:
159  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
160  float                   damage;             //!< the damage dealt to other objects by colliding.
161  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
162  float                   healthMax;          //!< The Maximal energy this entity can take.
163  OrxGui::GLGuiBar*       healthWidget;       //!< The Slider (if wanted).
164
165  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
166  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
167  std::string             modelLODName;       //!< the name of the model lod file
168  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
169
170  bool                    bCollide;           //!< If it should be considered for the collisiontest.
171  bool                    bVisible;           //!< If it should be visible.
172
173  OM_LIST                 objectListNumber;                //!< The ObjectList from ObjectManager this Entity is in.
174  ObjectManager::EntityList::iterator objectListIterator;  //!< The iterator position of this Entity in the given list of the ObjectManager.
175
176
177
178  float                   scaling;                         //!< model's scaling factor
179  int                     scaling_handle;                  //!< handle for syncing var
180
181  std::string             modelFileName;                   //!< model's file name
182  int                     modelFileName_handle;            //!< handle for syncing var
183
184  CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
185  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
186
187  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
188
189};
190
191#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.