Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged the bsp branche back to trunk

File size: 7.7 KB
RevLine 
[4680]1/*!
[4885]2 * @file world_entity.h
3 * Definition of the basic WorldEntity
[7711]4 */
[2036]5
[3224]6#ifndef _WORLD_ENTITY_H
7#define _WORLD_ENTITY_H
[2036]8
[3365]9#include "p_node.h"
[5996]10#include "synchronizeable.h"
11#include "model.h"
[2036]12
[7927]13#include "cr_engine.h"
[6142]14#include "object_manager.h"
[5511]15#include "glincl.h"
[5995]16#include <vector>
[5511]17
[8190]18#include "physics_interface.h"
[7927]19
20
[8190]21
[4885]22// FORWARD DECLARATION
[7460]23namespace OrxSound { class SoundBuffer; class SoundSource; }
[7779]24namespace OrxGui { class GLGuiWidget; class GLGuiBar; };
25
[5143]26class BVTree;
[8190]27class BoundingVolume;
[5511]28class Model;
[7927]29class CollisionHandle;
[8190]30class Collision;
[6440]31
[7927]32
[5498]33//class CharacterAttributes;
[4682]34
[5498]35
[4885]36//! Basis-class all interactive stuff in the world is derived from
[6498]37class WorldEntity : public PNode
[4680]38{
[6430]39public:
40  WorldEntity();
[3221]41  virtual ~WorldEntity ();
[3365]42
[6512]43  virtual void loadParams(const TiXmlElement* root);
[5994]44
[7711]45  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
[5994]46  void setModel(Model* model, unsigned int modelNumber = 0);
[6440]47  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
[5994]48
[7221]49  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
[6222]50
[4885]51  /** @param visibility if the Entity should be visible (been draw) */
52  void setVisibiliy (bool visibility) { this->bVisible = visibility; };
53  /** @returns true if the entity is visible, false otherwise */
[5511]54  inline bool isVisible() const { return this->bVisible; };
[5026]55
[7085]56  virtual void reset();
[3583]57
[3229]58  virtual void postSpawn ();
[6959]59  virtual void leaveWorld ();
[7076]60  virtual void destroy() {};
[3583]61
[5501]62  virtual void tick (float time);
63  virtual void draw () const;
[6005]64
[7927]65  /* --- Collision Detection Block  --- */
[7711]66  bool buildObbTree(int depth);
[5029]67  virtual void collidesWith (WorldEntity* entity, const Vector& location);
[8186]68  virtual void collidesWithGround(const Vector& location);
69  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
70
71
72/** @returns a reference to the obb tree of this worldentity */
[7711]73  inline BVTree* getOBBTree() const { return this->obbTree; };
74  void drawBVTree(int depth, int drawMode) const;
[5501]75
[7927]76  /* --- Collision Reaction Block --- */
[8190]77  void subscribeReaction(CREngine::CRType type);
78  void subscribeReaction(CREngine::CRType type, long target1);
79  void subscribeReaction(CREngine::CRType type, long target1, long target2);
80  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3);
81  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4);
[6424]82
[8190]83  void unsubscribeReaction(CREngine::CRType type);
84  void unsubscribeReaction();
[6424]85
[8190]86  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
[8490]87  bool registerCollision(WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position);
[8190]88  /** @return true if there is at least on collision reaction subscribed */
89  inline bool isReactive() const { return this->bReactive; }
90
91  CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
92
93
[5510]94  /* @returns the Count of Faces on this WorldEntity */
95  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
96  //  void addAbility(Ability* ability);
97  //  void removeAbility(Ability* ability);
98  //  void setCharacterAttributes(CharacterAttributes* charAttr);
99  //  CharacterAttributes* getCharacterAttributes();
[4680]100
[7927]101  /* --- Object Manager Block --- */
[6142]102  void toList(OM_LIST list);
[8037]103
104  void toReflectionList();
105  void removeFromReflectionList();
106
[6142]107  /** @returns a Reference to the objectListNumber to set. */
108  OM_LIST& getOMListNumber() { return this->objectListNumber; }
109  /** @returns a Reference to the Iterator */
[7370]110  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
[6222]111
[7927]112  /* --- Network Block --- */
[6341]113  int       writeState(const byte* data, int length, int sender);
114  int       readState(byte* data, int maxLength );
[6222]115
[7927]116  /* --- Character Attribute Block --- */
[8190]117  /** @returns the damage dealt by this world entity */
118  float getDamage() const { return this->damage; }
119  /** sets the damage dealt to @param damage damage per second */
120  void setDamage(float damage) { this->damage = damage; }
[6430]121  /** @returns the Energy of the entity */
[6700]122  float getHealth() const { return this->health; };
[6430]123  /** @returns the Maximum energy this entity can be charged with */
[6700]124  float getHealthMax() const { return this->healthMax; }
125  float increaseHealth(float health);
126  float decreaseHealth(float health);
127  void increaseHealthMax(float increaseHealth);
[7779]128  OrxGui::GLGuiWidget* getHealthWidget();
[7064]129  bool hasHealthWidget() const { return this->healthWidget; };
[8190]130
[7954]131  virtual void varChangeHandler( std::list<int> & id );
[6430]132
[8190]133
134  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
135  /* --- Physics Interface --- */
136  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
137  inline float getMass() const { return this->physicsInterface.getMass(); }
138  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
[8490]139  inline void setVelocity(const Vector& vel) { this->velocity = vel; }
[8190]140
141
[7927]142  /* --- Misc Stuff Block --- */
143  void debugWE() { this->debugEntity(); }
144  ;  ///FIXME
145  void debugEntity() const;
146
147
[6430]148protected:
[7095]149  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
[6700]150  void setHealthWidgetVisibilit(bool visibility);
151  void setHealthMax(float healthMax);
152  void createHealthWidget();
[7711]153
[5994]154  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
[6430]155private:
[6700]156  void updateHealthWidget();
[5994]157
[6430]158private:
159  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
[8190]160  float                   damage;             //!< the damage dealt to other objects by colliding.
[6700]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.
[7779]163  OrxGui::GLGuiBar*       healthWidget;       //!< The Slider (if wanted).
[6341]164
[6142]165  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
[7221]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
[6142]168  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
[4680]169
[6142]170  bool                    bCollide;           //!< If it should be considered for the collisiontest.
171  bool                    bVisible;           //!< If it should be visible.
172
[8190]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.
[6142]175
[6341]176
177
[8190]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
[8490]189
190  protected:
191  Vector                  velocity;                        //!< speed of the entity
192
[2036]193};
194
[3224]195#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.