Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8188 was 8186, checked in by bensch, 19 years ago

trunk: merged the branche bsp_model back here

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