Let Settings accept a const char* directly
[oweals/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
27 /*
28         SmoothTranslator
29 */
30
31 struct SmoothTranslator
32 {
33         v3f vect_old;
34         f32 anim_counter;
35         f32 anim_time;
36         f32 anim_time_counter;
37         v3f vect_show;
38         v3f vect_aim;
39
40         SmoothTranslator():
41                 vect_old(0,0,0),
42                 anim_counter(0),
43                 anim_time(0),
44                 anim_time_counter(0),
45                 vect_show(0,0,0),
46                 vect_aim(0,0,0)
47         {}
48
49         void init(v3f vect)
50         {
51                 vect_old = vect;
52                 vect_show = vect;
53                 vect_aim = vect;
54         }
55
56         void update(v3f vect_new)
57         {
58                 vect_old = vect_show;
59                 vect_aim = vect_new;
60                 if(anim_time < 0.001 || anim_time > 1.0)
61                         anim_time = anim_time_counter;
62                 else
63                         anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
64                 anim_time_counter = 0;
65                 anim_counter = 0;
66         }
67
68         void translate(f32 dtime)
69         {
70                 anim_time_counter = anim_time_counter + dtime;
71                 anim_counter = anim_counter + dtime;
72                 v3f vect_move = vect_aim - vect_old;
73                 f32 moveratio = 1.0;
74                 if(anim_time > 0.001)
75                         moveratio = anim_time_counter / anim_time;
76                 // Move a bit less than should, to avoid oscillation
77                 moveratio = moveratio * 0.8;
78                 if(moveratio > 1.5)
79                         moveratio = 1.5;
80                 vect_show = vect_old + vect_move * moveratio;
81         }
82 };
83
84
85 /*
86         TestCAO
87 */
88
89 class TestCAO : public ClientActiveObject
90 {
91 public:
92         TestCAO();
93         virtual ~TestCAO();
94         
95         u8 getType() const
96         {
97                 return ACTIVEOBJECT_TYPE_TEST;
98         }
99         
100         static ClientActiveObject* create();
101
102         void addToScene(scene::ISceneManager *smgr);
103         void removeFromScene();
104         void updateLight(u8 light_at_pos);
105         v3s16 getLightPosition();
106         void updateNodePos();
107
108         void step(float dtime, ClientEnvironment *env);
109
110         void processMessage(const std::string &data);
111
112 private:
113         scene::IMeshSceneNode *m_node;
114         v3f m_position;
115 };
116
117 /*
118         ItemCAO
119 */
120
121 class ItemCAO : public ClientActiveObject
122 {
123 public:
124         ItemCAO();
125         virtual ~ItemCAO();
126         
127         u8 getType() const
128         {
129                 return ACTIVEOBJECT_TYPE_ITEM;
130         }
131         
132         static ClientActiveObject* create();
133
134         void addToScene(scene::ISceneManager *smgr);
135         void removeFromScene();
136         void updateLight(u8 light_at_pos);
137         v3s16 getLightPosition();
138         void updateNodePos();
139
140         void step(float dtime, ClientEnvironment *env);
141
142         void processMessage(const std::string &data);
143
144         void initialize(const std::string &data);
145         
146         core::aabbox3d<f32>* getSelectionBox()
147                 {return &m_selection_box;}
148         v3f getPosition()
149                 {return m_position;}
150
151 private:
152         core::aabbox3d<f32> m_selection_box;
153         scene::IMeshSceneNode *m_node;
154         v3f m_position;
155         std::string m_inventorystring;
156 };
157
158 /*
159         RatCAO
160 */
161
162 class RatCAO : public ClientActiveObject
163 {
164 public:
165         RatCAO();
166         virtual ~RatCAO();
167         
168         u8 getType() const
169         {
170                 return ACTIVEOBJECT_TYPE_RAT;
171         }
172         
173         static ClientActiveObject* create();
174
175         void addToScene(scene::ISceneManager *smgr);
176         void removeFromScene();
177         void updateLight(u8 light_at_pos);
178         v3s16 getLightPosition();
179         void updateNodePos();
180
181         void step(float dtime, ClientEnvironment *env);
182
183         void processMessage(const std::string &data);
184
185         void initialize(const std::string &data);
186         
187         core::aabbox3d<f32>* getSelectionBox()
188                 {return &m_selection_box;}
189         v3f getPosition()
190                 {return pos_translator.vect_show;}
191                 //{return m_position;}
192
193 private:
194         core::aabbox3d<f32> m_selection_box;
195         scene::IMeshSceneNode *m_node;
196         v3f m_position;
197         float m_yaw;
198         SmoothTranslator pos_translator;
199 };
200
201 /*
202         Oerkki1CAO
203 */
204
205 class Oerkki1CAO : public ClientActiveObject
206 {
207 public:
208         Oerkki1CAO();
209         virtual ~Oerkki1CAO();
210         
211         u8 getType() const
212         {
213                 return ACTIVEOBJECT_TYPE_OERKKI1;
214         }
215         
216         static ClientActiveObject* create();
217
218         void addToScene(scene::ISceneManager *smgr);
219         void removeFromScene();
220         void updateLight(u8 light_at_pos);
221         v3s16 getLightPosition();
222         void updateNodePos();
223
224         void step(float dtime, ClientEnvironment *env);
225
226         void processMessage(const std::string &data);
227
228         void initialize(const std::string &data);
229         
230         core::aabbox3d<f32>* getSelectionBox()
231                 {return &m_selection_box;}
232         v3f getPosition()
233                 {return pos_translator.vect_show;}
234                 //{return m_position;}
235
236 private:
237         IntervalLimiter m_attack_interval;
238         core::aabbox3d<f32> m_selection_box;
239         scene::IMeshSceneNode *m_node;
240         v3f m_position;
241         float m_yaw;
242         SmoothTranslator pos_translator;
243         float m_damage_visual_timer;
244         bool m_damage_texture_enabled;
245 };
246
247 /*
248         FireflyCAO
249 */
250
251 class FireflyCAO : public ClientActiveObject
252 {
253 public:
254         FireflyCAO();
255         virtual ~FireflyCAO();
256         
257         u8 getType() const
258         {
259                 return ACTIVEOBJECT_TYPE_FIREFLY;
260         }
261         
262         static ClientActiveObject* create();
263
264         void addToScene(scene::ISceneManager *smgr);
265         void removeFromScene();
266         void updateLight(u8 light_at_pos);
267         v3s16 getLightPosition();
268         void updateNodePos();
269
270         void step(float dtime, ClientEnvironment *env);
271
272         void processMessage(const std::string &data);
273
274         void initialize(const std::string &data);
275         
276         core::aabbox3d<f32>* getSelectionBox()
277                 {return &m_selection_box;}
278         v3f getPosition()
279                 {return m_position;}
280
281 private:
282         core::aabbox3d<f32> m_selection_box;
283         scene::IMeshSceneNode *m_node;
284         v3f m_position;
285         float m_yaw;
286         SmoothTranslator pos_translator;
287 };
288
289
290 #endif
291