Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10338 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
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"
[10013]14#include "collision_filter.h"
[6142]15#include "object_manager.h"
[5511]16#include "glincl.h"
17
[8724]18#include "aabb_tree_node.h"
19
[8190]20#include "physics_interface.h"
[7927]21
[10147]22#include <vector>
[7927]23
[8190]24
[4885]25// FORWARD DECLARATION
[7460]26namespace OrxSound { class SoundBuffer; class SoundSource; }
[8974]27namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; };
[10013]28namespace CoRe { class Collision; }
[7779]29
[5143]30class BVTree;
[8190]31class BoundingVolume;
[8724]32class AABBTreeNode;
[5511]33class Model;
[6440]34
[10147]35class ObjectInformationFile;
36class MountPoint;
[7927]37
[10147]38
[4885]39//! Basis-class all interactive stuff in the world is derived from
[6498]40class WorldEntity : public PNode
[4680]41{
[9869]42  ObjectListDeclaration(WorldEntity);
[10013]43
[6430]44public:
45  WorldEntity();
[3221]46  virtual ~WorldEntity ();
[3365]47
[6512]48  virtual void loadParams(const TiXmlElement* root);
[5994]49
[7711]50  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
[9235]51  void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);}
[5994]52  void setModel(Model* model, unsigned int modelNumber = 0);
[10013]53  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
[5994]54
[10314]55  void loadMountPoints(const std::string& fileName);
[7221]56  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
[6222]57
[10147]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
[4885]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 */
[5511]66  inline bool isVisible() const { return this->bVisible; };
[5026]67
[7085]68  virtual void reset();
[3583]69
[3229]70  virtual void postSpawn ();
[6959]71  virtual void leaveWorld ();
[3583]72
[5501]73  virtual void tick (float time);
74  virtual void draw () const;
[10314]75  void debugDrawMountPoints() const;
[6005]76
[7927]77  /* --- Collision Detection Block  --- */
[7711]78  bool buildObbTree(int depth);
[5029]79  virtual void collidesWith (WorldEntity* entity, const Vector& location);
[8186]80  virtual void collidesWithGround(const Vector& location);
81  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
82
[9869]83  /** @returns a reference to the obb tree of this worldentity */
[7711]84  inline BVTree* getOBBTree() const { return this->obbTree; };
[9235]85  inline void setOBBTree(OBBTree* tree) { /*if( this->obbTree != NULL) delete this->obbTree;*/ this->obbTree = (BVTree*)tree; }
[7711]86  void drawBVTree(int depth, int drawMode) const;
[9235]87  inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
[5501]88
[10013]89  virtual void hit(float damage, WorldEntity* killer);
90
91
[7927]92  /* --- Collision Reaction Block --- */
[10013]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);
[6424]96
[10013]97  void unsubscribeReaction(CoRe::CREngine::ReactionType type);
98  void unsubscribeReactions();
[6424]99
[8190]100  /** @return true if there is at least on collision reaction subscribed */
[10013]101  inline bool isReactive() const { return this->_collisionFilter.isReactive(); }
[8190]102
[10013]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); }
[8190]108
[10013]109
110  const CoRe::CollisionFilter& getCollisionFilter(CoRe::CREngine::ReactionType type) const { return this->_collisionFilter; }
111
[9003]112  /** @returns true if this entity is standing on ground (BSP model) */
[10013]113  bool isOnGround() const { return this->_bOnGround; }
[9003]114  /** @param flag: marks if this entity is standing on ground */
[10013]115  void setOnGround(bool flag) { this->_bOnGround = flag; }
[9003]116
[9235]117  virtual void destroy( WorldEntity* killer );
[8190]118
[8724]119
[5510]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();
[4680]126
[7927]127  /* --- Object Manager Block --- */
[6142]128  void toList(OM_LIST list);
[9656]129  void toListS(const std::string& listName);
[8037]130
131  void toReflectionList();
132  void removeFromReflectionList();
133
[6142]134  /** @returns a Reference to the objectListNumber to set. */
135  OM_LIST& getOMListNumber() { return this->objectListNumber; }
136  /** @returns a Reference to the Iterator */
[7370]137  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
[6222]138
[8894]139  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
[10013]140  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
[8894]141
142
[7927]143  /* --- Character Attribute Block --- */
[9298]144  /** @returns the scaling of the model */
[10013]145  float getScaling(){return this->scaling;}
[8190]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; }
[6430]150  /** @returns the Energy of the entity */
[6700]151  float getHealth() const { return this->health; };
[6430]152  /** @returns the Maximum energy this entity can be charged with */
[6700]153  float getHealthMax() const { return this->healthMax; }
154  float increaseHealth(float health);
155  float decreaseHealth(float health);
156  void increaseHealthMax(float increaseHealth);
[7779]157  OrxGui::GLGuiWidget* getHealthWidget();
[7064]158  bool hasHealthWidget() const { return this->healthWidget; };
[8190]159
[7954]160  virtual void varChangeHandler( std::list<int> & id );
[6430]161
[8190]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(); }
[8490]168  inline void setVelocity(const Vector& vel) { this->velocity = vel; }
[8190]169
170
[7927]171  /* --- Misc Stuff Block --- */
172  void debugWE() { this->debugEntity(); }
173  ;  ///FIXME
174  void debugEntity() const;
175
176
[6430]177protected:
[7095]178  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
[6700]179  void setHealthWidgetVisibilit(bool visibility);
180  void setHealthMax(float healthMax);
181  void createHealthWidget();
[10013]182    //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
[7711]183
[10013]184
[6430]185private:
[6700]186  void updateHealthWidget();
[5994]187
[10013]188
[6430]189private:
190  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
[8190]191  float                   damage;             //!< the damage dealt to other objects by colliding.
[6700]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.
[8974]194  OrxGui::GLGuiEnergyWidget* healthWidget;    //!< The Slider (if wanted).
[6341]195
[6142]196  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
[10147]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
[7221]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
[6142]201  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
[8724]202  AABBTreeNode*           aabbNode;           //!< the tree node of the first level of a axis aligned bounding boxes tree: model dimension
[4680]203
[6142]204  bool                    bCollide;           //!< If it should be considered for the collisiontest.
205  bool                    bVisible;           //!< If it should be visible.
206
[8190]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.
[8894]209  OM_LIST                 lastObjectListNumber;            //!< the last ObjectList from the ObjectManager this Entity was is in
[6142]210
[10013]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
[6341]214
[10013]215  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
[6341]216
[10013]217  /* network help structures */
[8190]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
[9008]224  int                     list_write;                      //!< entity's list
225  int                     list_handle;                     //!< handle for list changes
[9235]226
[9110]227  float                   health_write;
228  int                     health_handle;
[9235]229
[9110]230  float                   healthMax_write;
231  int                     healthMax_handle;
[9008]232
[8190]233
234
[9869]235protected:
[8490]236  Vector                  velocity;                        //!< speed of the entity
237
[2036]238};
239
[3224]240#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.