]> git.lizzy.rs Git - minetest.git/blob - src/content_cao.h
Improve mobv2
[minetest.git] / src / content_cao.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef CONTENT_CAO_HEADER
21 #define CONTENT_CAO_HEADER
22
23 #include "clientobject.h"
24 #include "content_object.h"
25 #include "utility.h" // For IntervalLimiter
26 class Settings;
27 #include "MyBillboardSceneNode.h"
28
29 /*
30         SmoothTranslator
31 */
32
33 struct SmoothTranslator
34 {
35         v3f vect_old;
36         v3f vect_show;
37         v3f vect_aim;
38         f32 anim_counter;
39         f32 anim_time;
40         f32 anim_time_counter;
41
42         SmoothTranslator():
43                 vect_old(0,0,0),
44                 vect_show(0,0,0),
45                 vect_aim(0,0,0),
46                 anim_counter(0),
47                 anim_time(0),
48                 anim_time_counter(0)
49         {}
50
51         void init(v3f vect)
52         {
53                 vect_old = vect;
54                 vect_show = vect;
55                 vect_aim = vect;
56                 anim_counter = 0;
57                 anim_time = 0;
58                 anim_time_counter = 0;
59         }
60
61         void sharpen()
62         {
63                 init(vect_show);
64         }
65
66         void update(v3f vect_new)
67         {
68                 vect_old = vect_show;
69                 vect_aim = vect_new;
70                 if(anim_time < 0.001 || anim_time > 1.0)
71                         anim_time = anim_time_counter;
72                 else
73                         anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
74                 anim_time_counter = 0;
75                 anim_counter = 0;
76         }
77
78         void translate(f32 dtime)
79         {
80                 anim_time_counter = anim_time_counter + dtime;
81                 anim_counter = anim_counter + dtime;
82                 v3f vect_move = vect_aim - vect_old;
83                 f32 moveratio = 1.0;
84                 if(anim_time > 0.001)
85                         moveratio = anim_time_counter / anim_time;
86                 // Move a bit less than should, to avoid oscillation
87                 moveratio = moveratio * 0.5;
88                 if(moveratio > 1.5)
89                         moveratio = 1.5;
90                 vect_show = vect_old + vect_move * moveratio;
91         }
92
93         bool is_moving()
94         {
95                 return ((anim_time_counter / anim_time) < 1.4);
96         }
97 };
98
99
100 /*
101         TestCAO
102 */
103
104 class TestCAO : public ClientActiveObject
105 {
106 public:
107         TestCAO();
108         virtual ~TestCAO();
109         
110         u8 getType() const
111         {
112                 return ACTIVEOBJECT_TYPE_TEST;
113         }
114         
115         static ClientActiveObject* create();
116
117         void addToScene(scene::ISceneManager *smgr);
118         void removeFromScene();
119         void updateLight(u8 light_at_pos);
120         v3s16 getLightPosition();
121         void updateNodePos();
122
123         void step(float dtime, ClientEnvironment *env);
124
125         void processMessage(const std::string &data);
126
127 private:
128         scene::IMeshSceneNode *m_node;
129         v3f m_position;
130 };
131
132 /*
133         ItemCAO
134 */
135
136 class ItemCAO : public ClientActiveObject
137 {
138 public:
139         ItemCAO();
140         virtual ~ItemCAO();
141         
142         u8 getType() const
143         {
144                 return ACTIVEOBJECT_TYPE_ITEM;
145         }
146         
147         static ClientActiveObject* create();
148
149         void addToScene(scene::ISceneManager *smgr);
150         void removeFromScene();
151         void updateLight(u8 light_at_pos);
152         v3s16 getLightPosition();
153         void updateNodePos();
154
155         void step(float dtime, ClientEnvironment *env);
156
157         void processMessage(const std::string &data);
158
159         void initialize(const std::string &data);
160         
161         core::aabbox3d<f32>* getSelectionBox()
162                 {return &m_selection_box;}
163         v3f getPosition()
164                 {return m_position;}
165
166 private:
167         core::aabbox3d<f32> m_selection_box;
168         scene::IMeshSceneNode *m_node;
169         v3f m_position;
170         std::string m_inventorystring;
171 };
172
173 /*
174         RatCAO
175 */
176
177 class RatCAO : public ClientActiveObject
178 {
179 public:
180         RatCAO();
181         virtual ~RatCAO();
182         
183         u8 getType() const
184         {
185                 return ACTIVEOBJECT_TYPE_RAT;
186         }
187         
188         static ClientActiveObject* create();
189
190         void addToScene(scene::ISceneManager *smgr);
191         void removeFromScene();
192         void updateLight(u8 light_at_pos);
193         v3s16 getLightPosition();
194         void updateNodePos();
195
196         void step(float dtime, ClientEnvironment *env);
197
198         void processMessage(const std::string &data);
199
200         void initialize(const std::string &data);
201         
202         core::aabbox3d<f32>* getSelectionBox()
203                 {return &m_selection_box;}
204         v3f getPosition()
205                 {return pos_translator.vect_show;}
206                 //{return m_position;}
207
208 private:
209         core::aabbox3d<f32> m_selection_box;
210         scene::IMeshSceneNode *m_node;
211         v3f m_position;
212         float m_yaw;
213         SmoothTranslator pos_translator;
214 };
215
216 /*
217         Oerkki1CAO
218 */
219
220 class Oerkki1CAO : public ClientActiveObject
221 {
222 public:
223         Oerkki1CAO();
224         virtual ~Oerkki1CAO();
225         
226         u8 getType() const
227         {
228                 return ACTIVEOBJECT_TYPE_OERKKI1;
229         }
230         
231         static ClientActiveObject* create();
232
233         void addToScene(scene::ISceneManager *smgr);
234         void removeFromScene();
235         void updateLight(u8 light_at_pos);
236         v3s16 getLightPosition();
237         void updateNodePos();
238
239         void step(float dtime, ClientEnvironment *env);
240
241         void processMessage(const std::string &data);
242
243         void initialize(const std::string &data);
244         
245         core::aabbox3d<f32>* getSelectionBox()
246                 {return &m_selection_box;}
247         v3f getPosition()
248                 {return pos_translator.vect_show;}
249                 //{return m_position;}
250
251 private:
252         IntervalLimiter m_attack_interval;
253         core::aabbox3d<f32> m_selection_box;
254         scene::IMeshSceneNode *m_node;
255         v3f m_position;
256         float m_yaw;
257         SmoothTranslator pos_translator;
258         float m_damage_visual_timer;
259         bool m_damage_texture_enabled;
260 };
261
262 /*
263         FireflyCAO
264 */
265
266 class FireflyCAO : public ClientActiveObject
267 {
268 public:
269         FireflyCAO();
270         virtual ~FireflyCAO();
271         
272         u8 getType() const
273         {
274                 return ACTIVEOBJECT_TYPE_FIREFLY;
275         }
276         
277         static ClientActiveObject* create();
278
279         void addToScene(scene::ISceneManager *smgr);
280         void removeFromScene();
281         void updateLight(u8 light_at_pos);
282         v3s16 getLightPosition();
283         void updateNodePos();
284
285         void step(float dtime, ClientEnvironment *env);
286
287         void processMessage(const std::string &data);
288
289         void initialize(const std::string &data);
290         
291         core::aabbox3d<f32>* getSelectionBox()
292                 {return &m_selection_box;}
293         v3f getPosition()
294                 {return m_position;}
295
296 private:
297         core::aabbox3d<f32> m_selection_box;
298         scene::IMeshSceneNode *m_node;
299         v3f m_position;
300         float m_yaw;
301         SmoothTranslator pos_translator;
302 };
303
304 /*
305         MobV2CAO
306 */
307
308 class MobV2CAO : public ClientActiveObject
309 {
310 public:
311         MobV2CAO();
312         virtual ~MobV2CAO();
313         
314         u8 getType() const
315         {
316                 return ACTIVEOBJECT_TYPE_MOBV2;
317         }
318         
319         static ClientActiveObject* create();
320
321         void addToScene(scene::ISceneManager *smgr);
322         void removeFromScene();
323         void updateLight(u8 light_at_pos);
324         v3s16 getLightPosition();
325         void updateNodePos();
326
327         void step(float dtime, ClientEnvironment *env);
328
329         void processMessage(const std::string &data);
330
331         void initialize(const std::string &data);
332         
333         core::aabbox3d<f32>* getSelectionBox()
334                 {return &m_selection_box;}
335         v3f getPosition()
336                 {return pos_translator.vect_show;}
337                 //{return m_position;}
338         bool doShowSelectionBox(){return false;}
339
340         // If returns true, punch will not be sent to the server
341         bool directReportPunch(const std::string &toolname, v3f dir);
342
343 private:
344         void setLooks(const std::string &looks);
345         
346         IntervalLimiter m_attack_interval;
347         core::aabbox3d<f32> m_selection_box;
348         scene::MyBillboardSceneNode *m_node;
349         v3f m_position;
350         std::string m_texture_name;
351         float m_yaw;
352         SmoothTranslator pos_translator;
353         bool m_walking;
354         float m_walking_unset_timer;
355         float m_walk_timer;
356         int m_walk_frame;
357         float m_damage_visual_timer;
358         u8 m_last_light;
359         bool m_shooting;
360         float m_shooting_unset_timer;
361         v2f m_sprite_size;
362         float m_sprite_y;
363         bool m_bright_shooting;
364         std::string m_sprite_type;
365         int m_simple_anim_frames;
366         float m_simple_anim_frametime;
367         bool m_lock_full_brightness;
368         int m_player_hit_damage;
369         float m_player_hit_distance;
370         float m_player_hit_interval;
371         float m_player_hit_timer;
372
373         Settings *m_properties;
374 };
375
376
377 #endif
378