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
40 f32 anim_time_counter;
58 anim_time_counter = 0;
66 void update(v3f vect_new)
70 if(anim_time < 0.001 || anim_time > 1.0)
71 anim_time = anim_time_counter;
73 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
74 anim_time_counter = 0;
78 void translate(f32 dtime)
80 anim_time_counter = anim_time_counter + dtime;
81 anim_counter = anim_counter + dtime;
82 v3f vect_move = vect_aim - vect_old;
85 moveratio = anim_time_counter / anim_time;
86 // Move a bit less than should, to avoid oscillation
87 moveratio = moveratio * 0.5;
90 vect_show = vect_old + vect_move * moveratio;
95 return ((anim_time_counter / anim_time) < 1.4);
104 class TestCAO : public ClientActiveObject
112 return ACTIVEOBJECT_TYPE_TEST;
115 static ClientActiveObject* create();
117 void addToScene(scene::ISceneManager *smgr);
118 void removeFromScene();
119 void updateLight(u8 light_at_pos);
120 v3s16 getLightPosition();
121 void updateNodePos();
123 void step(float dtime, ClientEnvironment *env);
125 void processMessage(const std::string &data);
128 scene::IMeshSceneNode *m_node;
136 class ItemCAO : public ClientActiveObject
144 return ACTIVEOBJECT_TYPE_ITEM;
147 static ClientActiveObject* create();
149 void addToScene(scene::ISceneManager *smgr);
150 void removeFromScene();
151 void updateLight(u8 light_at_pos);
152 v3s16 getLightPosition();
153 void updateNodePos();
155 void step(float dtime, ClientEnvironment *env);
157 void processMessage(const std::string &data);
159 void initialize(const std::string &data);
161 core::aabbox3d<f32>* getSelectionBox()
162 {return &m_selection_box;}
167 core::aabbox3d<f32> m_selection_box;
168 scene::IMeshSceneNode *m_node;
170 std::string m_inventorystring;
177 class RatCAO : public ClientActiveObject
185 return ACTIVEOBJECT_TYPE_RAT;
188 static ClientActiveObject* create();
190 void addToScene(scene::ISceneManager *smgr);
191 void removeFromScene();
192 void updateLight(u8 light_at_pos);
193 v3s16 getLightPosition();
194 void updateNodePos();
196 void step(float dtime, ClientEnvironment *env);
198 void processMessage(const std::string &data);
200 void initialize(const std::string &data);
202 core::aabbox3d<f32>* getSelectionBox()
203 {return &m_selection_box;}
205 {return pos_translator.vect_show;}
206 //{return m_position;}
209 core::aabbox3d<f32> m_selection_box;
210 scene::IMeshSceneNode *m_node;
213 SmoothTranslator pos_translator;
220 class Oerkki1CAO : public ClientActiveObject
224 virtual ~Oerkki1CAO();
228 return ACTIVEOBJECT_TYPE_OERKKI1;
231 static ClientActiveObject* create();
233 void addToScene(scene::ISceneManager *smgr);
234 void removeFromScene();
235 void updateLight(u8 light_at_pos);
236 v3s16 getLightPosition();
237 void updateNodePos();
239 void step(float dtime, ClientEnvironment *env);
241 void processMessage(const std::string &data);
243 void initialize(const std::string &data);
245 core::aabbox3d<f32>* getSelectionBox()
246 {return &m_selection_box;}
248 {return pos_translator.vect_show;}
249 //{return m_position;}
251 // If returns true, punch will not be sent to the server
252 bool directReportPunch(const std::string &toolname, v3f dir);
255 IntervalLimiter m_attack_interval;
256 core::aabbox3d<f32> m_selection_box;
257 scene::IMeshSceneNode *m_node;
260 SmoothTranslator pos_translator;
261 float m_damage_visual_timer;
262 bool m_damage_texture_enabled;
269 class FireflyCAO : public ClientActiveObject
273 virtual ~FireflyCAO();
277 return ACTIVEOBJECT_TYPE_FIREFLY;
280 static ClientActiveObject* create();
282 void addToScene(scene::ISceneManager *smgr);
283 void removeFromScene();
284 void updateLight(u8 light_at_pos);
285 v3s16 getLightPosition();
286 void updateNodePos();
288 void step(float dtime, ClientEnvironment *env);
290 void processMessage(const std::string &data);
292 void initialize(const std::string &data);
294 core::aabbox3d<f32>* getSelectionBox()
295 {return &m_selection_box;}
300 core::aabbox3d<f32> m_selection_box;
301 scene::IMeshSceneNode *m_node;
304 SmoothTranslator pos_translator;
311 class MobV2CAO : public ClientActiveObject
319 return ACTIVEOBJECT_TYPE_MOBV2;
322 static ClientActiveObject* create();
324 void addToScene(scene::ISceneManager *smgr);
325 void removeFromScene();
326 void updateLight(u8 light_at_pos);
327 v3s16 getLightPosition();
328 void updateNodePos();
330 void step(float dtime, ClientEnvironment *env);
332 void processMessage(const std::string &data);
334 void initialize(const std::string &data);
336 core::aabbox3d<f32>* getSelectionBox()
337 {return &m_selection_box;}
339 {return pos_translator.vect_show;}
340 //{return m_position;}
341 bool doShowSelectionBox(){return false;}
343 // If returns true, punch will not be sent to the server
344 bool directReportPunch(const std::string &toolname, v3f dir);
347 void setLooks(const std::string &looks);
349 IntervalLimiter m_attack_interval;
350 core::aabbox3d<f32> m_selection_box;
351 scene::MyBillboardSceneNode *m_node;
353 std::string m_texture_name;
355 SmoothTranslator pos_translator;
357 float m_walking_unset_timer;
360 float m_damage_visual_timer;
363 float m_shooting_unset_timer;
366 bool m_bright_shooting;
367 std::string m_sprite_type;
368 int m_simple_anim_frames;
369 float m_simple_anim_frametime;
370 bool m_lock_full_brightness;
371 int m_player_hit_damage;
372 float m_player_hit_distance;
373 float m_player_hit_interval;
374 float m_player_hit_timer;
376 Settings *m_properties;
383 class LuaEntityCAO : public ClientActiveObject
387 virtual ~LuaEntityCAO();
391 return ACTIVEOBJECT_TYPE_LUAENTITY;
394 static ClientActiveObject* create();
396 void addToScene(scene::ISceneManager *smgr);
397 void removeFromScene();
398 void updateLight(u8 light_at_pos);
399 v3s16 getLightPosition();
400 void updateNodePos();
402 void step(float dtime, ClientEnvironment *env);
404 void processMessage(const std::string &data);
406 void initialize(const std::string &data);
408 core::aabbox3d<f32>* getSelectionBox()
409 {return &m_selection_box;}
414 core::aabbox3d<f32> m_selection_box;
415 scene::IMeshSceneNode *m_node;