3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #ifndef CONTENT_CAO_HEADER
21 #define CONTENT_CAO_HEADER
23 #include "clientobject.h"
24 #include "content_object.h"
25 #include "utility.h" // For IntervalLimiter
27 #include "MyBillboardSceneNode.h"
33 struct SmoothTranslator
38 f32 anim_time_counter;
58 void update(v3f vect_new)
62 if(anim_time < 0.001 || anim_time > 1.0)
63 anim_time = anim_time_counter;
65 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
66 anim_time_counter = 0;
70 void translate(f32 dtime)
72 anim_time_counter = anim_time_counter + dtime;
73 anim_counter = anim_counter + dtime;
74 v3f vect_move = vect_aim - vect_old;
77 moveratio = anim_time_counter / anim_time;
78 // Move a bit less than should, to avoid oscillation
79 moveratio = moveratio * 0.5;
82 vect_show = vect_old + vect_move * moveratio;
87 return ((anim_time_counter / anim_time) < 1.4);
96 class TestCAO : public ClientActiveObject
104 return ACTIVEOBJECT_TYPE_TEST;
107 static ClientActiveObject* create();
109 void addToScene(scene::ISceneManager *smgr);
110 void removeFromScene();
111 void updateLight(u8 light_at_pos);
112 v3s16 getLightPosition();
113 void updateNodePos();
115 void step(float dtime, ClientEnvironment *env);
117 void processMessage(const std::string &data);
120 scene::IMeshSceneNode *m_node;
128 class ItemCAO : public ClientActiveObject
136 return ACTIVEOBJECT_TYPE_ITEM;
139 static ClientActiveObject* create();
141 void addToScene(scene::ISceneManager *smgr);
142 void removeFromScene();
143 void updateLight(u8 light_at_pos);
144 v3s16 getLightPosition();
145 void updateNodePos();
147 void step(float dtime, ClientEnvironment *env);
149 void processMessage(const std::string &data);
151 void initialize(const std::string &data);
153 core::aabbox3d<f32>* getSelectionBox()
154 {return &m_selection_box;}
159 core::aabbox3d<f32> m_selection_box;
160 scene::IMeshSceneNode *m_node;
162 std::string m_inventorystring;
169 class RatCAO : public ClientActiveObject
177 return ACTIVEOBJECT_TYPE_RAT;
180 static ClientActiveObject* create();
182 void addToScene(scene::ISceneManager *smgr);
183 void removeFromScene();
184 void updateLight(u8 light_at_pos);
185 v3s16 getLightPosition();
186 void updateNodePos();
188 void step(float dtime, ClientEnvironment *env);
190 void processMessage(const std::string &data);
192 void initialize(const std::string &data);
194 core::aabbox3d<f32>* getSelectionBox()
195 {return &m_selection_box;}
197 {return pos_translator.vect_show;}
198 //{return m_position;}
201 core::aabbox3d<f32> m_selection_box;
202 scene::IMeshSceneNode *m_node;
205 SmoothTranslator pos_translator;
212 class Oerkki1CAO : public ClientActiveObject
216 virtual ~Oerkki1CAO();
220 return ACTIVEOBJECT_TYPE_OERKKI1;
223 static ClientActiveObject* create();
225 void addToScene(scene::ISceneManager *smgr);
226 void removeFromScene();
227 void updateLight(u8 light_at_pos);
228 v3s16 getLightPosition();
229 void updateNodePos();
231 void step(float dtime, ClientEnvironment *env);
233 void processMessage(const std::string &data);
235 void initialize(const std::string &data);
237 core::aabbox3d<f32>* getSelectionBox()
238 {return &m_selection_box;}
240 {return pos_translator.vect_show;}
241 //{return m_position;}
244 IntervalLimiter m_attack_interval;
245 core::aabbox3d<f32> m_selection_box;
246 scene::IMeshSceneNode *m_node;
249 SmoothTranslator pos_translator;
250 float m_damage_visual_timer;
251 bool m_damage_texture_enabled;
258 class FireflyCAO : public ClientActiveObject
262 virtual ~FireflyCAO();
266 return ACTIVEOBJECT_TYPE_FIREFLY;
269 static ClientActiveObject* create();
271 void addToScene(scene::ISceneManager *smgr);
272 void removeFromScene();
273 void updateLight(u8 light_at_pos);
274 v3s16 getLightPosition();
275 void updateNodePos();
277 void step(float dtime, ClientEnvironment *env);
279 void processMessage(const std::string &data);
281 void initialize(const std::string &data);
283 core::aabbox3d<f32>* getSelectionBox()
284 {return &m_selection_box;}
289 core::aabbox3d<f32> m_selection_box;
290 scene::IMeshSceneNode *m_node;
293 SmoothTranslator pos_translator;
300 class MobV2CAO : public ClientActiveObject
308 return ACTIVEOBJECT_TYPE_MOBV2;
311 static ClientActiveObject* create();
313 void addToScene(scene::ISceneManager *smgr);
314 void removeFromScene();
315 void updateLight(u8 light_at_pos);
316 v3s16 getLightPosition();
317 void updateNodePos();
319 void step(float dtime, ClientEnvironment *env);
321 void processMessage(const std::string &data);
323 void initialize(const std::string &data);
325 core::aabbox3d<f32>* getSelectionBox()
326 {return &m_selection_box;}
328 {return pos_translator.vect_show;}
329 //{return m_position;}
330 bool doShowSelectionBox(){return false;}
333 IntervalLimiter m_attack_interval;
334 core::aabbox3d<f32> m_selection_box;
335 scene::MyBillboardSceneNode *m_node;
338 SmoothTranslator pos_translator;
340 float m_walking_unset_timer;
343 float m_damage_visual_timer;
346 float m_shooting_unset_timer;
349 bool m_bright_shooting;
350 std::string m_sprite_type;
351 int m_simple_anim_frames;
352 float m_simple_anim_frametime;
353 bool m_lock_full_brightness;
354 int m_player_hit_damage;
355 float m_player_hit_distance;
356 float m_player_hit_interval;
357 float m_player_hit_timer;
359 Settings *m_properties;