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