| 1 |  | 
|---|
| 2 | /*! | 
|---|
| 3 |  * @file generic_npc.h | 
|---|
| 4 |  * generic npc object | 
|---|
| 5 |  */ | 
|---|
| 6 |  | 
|---|
| 7 | #ifndef _GENERIC_ENTITY_H | 
|---|
| 8 | #define _GENERIC_ENTITY_H | 
|---|
| 9 |  | 
|---|
| 10 | #include "npc.h" | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 | #include "sound_source.h" | 
|---|
| 14 |  | 
|---|
| 15 | #include <stack> | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 | namespace OrxSound{ class SoundSource; } | 
|---|
| 19 | namespace OrxSound{ class SoundBuffer; } | 
|---|
| 20 |  | 
|---|
| 21 | class TiXmlElement; | 
|---|
| 22 | class Animation3D; | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | class GenericNPC : public NPC | 
|---|
| 26 | { | 
|---|
| 27 |   ObjectListDeclaration(GenericNPC); | 
|---|
| 28 |  | 
|---|
| 29 |  | 
|---|
| 30 |  public: | 
|---|
| 31 |   GenericNPC(const TiXmlElement* root = NULL); | 
|---|
| 32 |   virtual ~GenericNPC (); | 
|---|
| 33 |  | 
|---|
| 34 |   virtual void loadParams(const TiXmlElement* root); | 
|---|
| 35 |  | 
|---|
| 36 |   /** sets the sound volume to @param vol: volume of the sound */ | 
|---|
| 37 |   inline void setVolume(float vol) { this->soundVolume = vol; } | 
|---|
| 38 |  | 
|---|
| 39 |  | 
|---|
| 40 |  | 
|---|
| 41 |   bool finalGoalReached() { return this->behaviourList->empty(); }; | 
|---|
| 42 |  | 
|---|
| 43 |   /* npc controlling functions to be Queued */ | 
|---|
| 44 |   /* walking functions */ | 
|---|
| 45 |   void walkTo(const Vector& coordinate); | 
|---|
| 46 |   void walkTo(float x, float y, float z); | 
|---|
| 47 |  | 
|---|
| 48 |   /* running functions */ | 
|---|
| 49 |   void runTo(const Vector& coordinate); | 
|---|
| 50 |   void runTo(float x, float y, float z); | 
|---|
| 51 |  | 
|---|
| 52 |   /* couching functinos */ | 
|---|
| 53 |   void crouchTo(const Vector& coordinate); | 
|---|
| 54 |   void crouchTo(float x, float y, float z); | 
|---|
| 55 |  | 
|---|
| 56 |   /* stopping the movement */ | 
|---|
| 57 |   void stop(); | 
|---|
| 58 |   void resume(); | 
|---|
| 59 |   void nextStep(); | 
|---|
| 60 |  | 
|---|
| 61 |   /* some oriantation functions */ | 
|---|
| 62 |   void lookAt(WorldEntity* worldEntity); | 
|---|
| 63 |   void turnTo(float qu, float qx, float qy, float qz); | 
|---|
| 64 |   void turnTo(float degreeInY); | 
|---|
| 65 |  | 
|---|
| 66 |   /* talking funcitons*/ | 
|---|
| 67 |   void talkTo(WorldEntity* worldEntity, int dialogNr); | 
|---|
| 68 |  | 
|---|
| 69 |   /* shooting functions */ | 
|---|
| 70 |   void shootAt(WorldEntity* entity); | 
|---|
| 71 |  | 
|---|
| 72 |  | 
|---|
| 73 |   /* some generic control funtions */ | 
|---|
| 74 |   void playAnimation(int animationIndex, int animPlaybackMode); | 
|---|
| 75 |   void playSound(const std::string& filename); | 
|---|
| 76 |  | 
|---|
| 77 |   virtual void tick (float time); | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 |   virtual void destroy(WorldEntity* killer); | 
|---|
| 81 |  | 
|---|
| 82 |   private: | 
|---|
| 83 |     void init(); | 
|---|
| 84 |  | 
|---|
| 85 |     void setAnimation(int animationIndex, int animPlaybackMode); | 
|---|
| 86 |     int getAnimation(); | 
|---|
| 87 |     bool isAnimationFinished(); | 
|---|
| 88 |     void setAnimationSpeed(float speed); | 
|---|
| 89 |  | 
|---|
| 90 |     void initNPC(); | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 |  private: | 
|---|
| 94 |  | 
|---|
| 95 |    typedef enum { | 
|---|
| 96 |     Walk, | 
|---|
| 97 |     Run, | 
|---|
| 98 |     Crouch, | 
|---|
| 99 |     Jump, | 
|---|
| 100 |     TurnTo, | 
|---|
| 101 |     LookAt, | 
|---|
| 102 |     TalkTo, | 
|---|
| 103 |  | 
|---|
| 104 |     Shoot, | 
|---|
| 105 |  | 
|---|
| 106 |  | 
|---|
| 107 |    } AnimType; | 
|---|
| 108 |  | 
|---|
| 109 |    typedef struct Anim | 
|---|
| 110 |    { | 
|---|
| 111 |      Vector        v; | 
|---|
| 112 |      Quaternion    q; | 
|---|
| 113 |  | 
|---|
| 114 |  | 
|---|
| 115 |      WorldEntity*  entity; | 
|---|
| 116 |      float         speed; | 
|---|
| 117 |  | 
|---|
| 118 |  | 
|---|
| 119 |      AnimType      type; | 
|---|
| 120 |    }; | 
|---|
| 121 |    typedef std::list<GenericNPC::Anim>     genNPCAnimList; | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 |  | 
|---|
| 125 |    OrxSound::SoundSource                   soundSource; | 
|---|
| 126 |    OrxSound::SoundBuffer                   soundBuffer; | 
|---|
| 127 |    float                                   soundVolume; | 
|---|
| 128 |  | 
|---|
| 129 |    std::list<GenericNPC::Anim>*            behaviourList; | 
|---|
| 130 |    std::stack<std::list<GenericNPC::Anim>*> animationStack; | 
|---|
| 131 |    Vector                                  destCoor; | 
|---|
| 132 |    Quaternion                              destDir; | 
|---|
| 133 |  | 
|---|
| 134 |    Animation3D*                            currentAnim; | 
|---|
| 135 |    float                                   time;          //!< Duration of the action | 
|---|
| 136 |    float                                   fallVelocity; | 
|---|
| 137 | }; | 
|---|
| 138 |  | 
|---|
| 139 | #endif /* _GENERIC_ENTITY_H */ | 
|---|