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
41 f32 anim_time_counter;
60 anim_time_counter = 0;
68 void update(v3f vect_new, bool is_end_position=false)
70 aim_is_end = is_end_position;
73 if(anim_time < 0.001 || anim_time > 1.0)
74 anim_time = anim_time_counter;
76 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
77 anim_time_counter = 0;
81 void translate(f32 dtime)
83 anim_time_counter = anim_time_counter + dtime;
84 anim_counter = anim_counter + dtime;
85 v3f vect_move = vect_aim - vect_old;
88 moveratio = anim_time_counter / anim_time;
89 // Move a bit less than should, to avoid oscillation
90 moveratio = moveratio * 0.5;
94 if(moveratio > move_end)
96 vect_show = vect_old + vect_move * moveratio;
101 return ((anim_time_counter / anim_time) < 1.4);
110 class TestCAO : public ClientActiveObject
118 return ACTIVEOBJECT_TYPE_TEST;
121 static ClientActiveObject* create();
123 void addToScene(scene::ISceneManager *smgr);
124 void removeFromScene();
125 void updateLight(u8 light_at_pos);
126 v3s16 getLightPosition();
127 void updateNodePos();
129 void step(float dtime, ClientEnvironment *env);
131 void processMessage(const std::string &data);
134 scene::IMeshSceneNode *m_node;
142 class ItemCAO : public ClientActiveObject
150 return ACTIVEOBJECT_TYPE_ITEM;
153 static ClientActiveObject* create();
155 void addToScene(scene::ISceneManager *smgr);
156 void removeFromScene();
157 void updateLight(u8 light_at_pos);
158 v3s16 getLightPosition();
159 void updateNodePos();
161 void step(float dtime, ClientEnvironment *env);
163 void processMessage(const std::string &data);
165 void initialize(const std::string &data);
167 core::aabbox3d<f32>* getSelectionBox()
168 {return &m_selection_box;}
173 core::aabbox3d<f32> m_selection_box;
174 scene::IMeshSceneNode *m_node;
176 std::string m_inventorystring;
183 class RatCAO : public ClientActiveObject
191 return ACTIVEOBJECT_TYPE_RAT;
194 static ClientActiveObject* create();
196 void addToScene(scene::ISceneManager *smgr);
197 void removeFromScene();
198 void updateLight(u8 light_at_pos);
199 v3s16 getLightPosition();
200 void updateNodePos();
202 void step(float dtime, ClientEnvironment *env);
204 void processMessage(const std::string &data);
206 void initialize(const std::string &data);
208 core::aabbox3d<f32>* getSelectionBox()
209 {return &m_selection_box;}
211 {return pos_translator.vect_show;}
212 //{return m_position;}
215 core::aabbox3d<f32> m_selection_box;
216 scene::IMeshSceneNode *m_node;
219 SmoothTranslator pos_translator;
226 class Oerkki1CAO : public ClientActiveObject
230 virtual ~Oerkki1CAO();
234 return ACTIVEOBJECT_TYPE_OERKKI1;
237 static ClientActiveObject* create();
239 void addToScene(scene::ISceneManager *smgr);
240 void removeFromScene();
241 void updateLight(u8 light_at_pos);
242 v3s16 getLightPosition();
243 void updateNodePos();
245 void step(float dtime, ClientEnvironment *env);
247 void processMessage(const std::string &data);
249 void initialize(const std::string &data);
251 core::aabbox3d<f32>* getSelectionBox()
252 {return &m_selection_box;}
254 {return pos_translator.vect_show;}
255 //{return m_position;}
257 // If returns true, punch will not be sent to the server
258 bool directReportPunch(const std::string &toolname, v3f dir);
261 IntervalLimiter m_attack_interval;
262 core::aabbox3d<f32> m_selection_box;
263 scene::IMeshSceneNode *m_node;
266 SmoothTranslator pos_translator;
267 float m_damage_visual_timer;
268 bool m_damage_texture_enabled;
275 class FireflyCAO : public ClientActiveObject
279 virtual ~FireflyCAO();
283 return ACTIVEOBJECT_TYPE_FIREFLY;
286 static ClientActiveObject* create();
288 void addToScene(scene::ISceneManager *smgr);
289 void removeFromScene();
290 void updateLight(u8 light_at_pos);
291 v3s16 getLightPosition();
292 void updateNodePos();
294 void step(float dtime, ClientEnvironment *env);
296 void processMessage(const std::string &data);
298 void initialize(const std::string &data);
300 core::aabbox3d<f32>* getSelectionBox()
301 {return &m_selection_box;}
306 core::aabbox3d<f32> m_selection_box;
307 scene::IMeshSceneNode *m_node;
310 SmoothTranslator pos_translator;
317 class MobV2CAO : public ClientActiveObject
325 return ACTIVEOBJECT_TYPE_MOBV2;
328 static ClientActiveObject* create();
330 void addToScene(scene::ISceneManager *smgr);
331 void removeFromScene();
332 void updateLight(u8 light_at_pos);
333 v3s16 getLightPosition();
334 void updateNodePos();
336 void step(float dtime, ClientEnvironment *env);
338 void processMessage(const std::string &data);
340 void initialize(const std::string &data);
342 core::aabbox3d<f32>* getSelectionBox()
343 {return &m_selection_box;}
345 {return pos_translator.vect_show;}
346 //{return m_position;}
347 bool doShowSelectionBox(){return false;}
349 // If returns true, punch will not be sent to the server
350 bool directReportPunch(const std::string &toolname, v3f dir);
353 void setLooks(const std::string &looks);
355 IntervalLimiter m_attack_interval;
356 core::aabbox3d<f32> m_selection_box;
357 scene::MyBillboardSceneNode *m_node;
359 std::string m_texture_name;
361 SmoothTranslator pos_translator;
363 float m_walking_unset_timer;
366 float m_damage_visual_timer;
369 float m_shooting_unset_timer;
372 bool m_bright_shooting;
373 std::string m_sprite_type;
374 int m_simple_anim_frames;
375 float m_simple_anim_frametime;
376 bool m_lock_full_brightness;
377 int m_player_hit_damage;
378 float m_player_hit_distance;
379 float m_player_hit_interval;
380 float m_player_hit_timer;
382 Settings *m_properties;
389 struct LuaEntityProperties;
391 class LuaEntityCAO : public ClientActiveObject
395 virtual ~LuaEntityCAO();
399 return ACTIVEOBJECT_TYPE_LUAENTITY;
402 static ClientActiveObject* create();
404 void addToScene(scene::ISceneManager *smgr);
405 void removeFromScene();
406 void updateLight(u8 light_at_pos);
407 v3s16 getLightPosition();
408 void updateNodePos();
410 void step(float dtime, ClientEnvironment *env);
412 void processMessage(const std::string &data);
414 void initialize(const std::string &data);
416 core::aabbox3d<f32>* getSelectionBox()
417 {return &m_selection_box;}
419 {return pos_translator.vect_show;}
422 core::aabbox3d<f32> m_selection_box;
423 scene::IMeshSceneNode *m_meshnode;
424 scene::MyBillboardSceneNode *m_spritenode;
427 struct LuaEntityProperties *m_prop;
428 SmoothTranslator pos_translator;