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;
60 anim_time_counter = 0;
69 void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
71 aim_is_end = is_end_position;
74 if(update_interval > 0){
75 anim_time = update_interval;
77 if(anim_time < 0.001 || anim_time > 1.0)
78 anim_time = anim_time_counter;
80 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
82 anim_time_counter = 0;
86 void translate(f32 dtime)
88 anim_time_counter = anim_time_counter + dtime;
89 anim_counter = anim_counter + dtime;
90 v3f vect_move = vect_aim - vect_old;
93 moveratio = anim_time_counter / anim_time;
94 // Move a bit less than should, to avoid oscillation
95 moveratio = moveratio * 0.5;
99 if(moveratio > move_end)
100 moveratio = move_end;
101 vect_show = vect_old + vect_move * moveratio;
106 return ((anim_time_counter / anim_time) < 1.4);
115 class TestCAO : public ClientActiveObject
118 TestCAO(IGameDef *gamedef);
123 return ACTIVEOBJECT_TYPE_TEST;
126 static ClientActiveObject* create(IGameDef *gamedef);
128 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
129 void removeFromScene();
130 void updateLight(u8 light_at_pos);
131 v3s16 getLightPosition();
132 void updateNodePos();
134 void step(float dtime, ClientEnvironment *env);
136 void processMessage(const std::string &data);
139 scene::IMeshSceneNode *m_node;
147 class ItemCAO : public ClientActiveObject
150 ItemCAO(IGameDef *gamedef);
155 return ACTIVEOBJECT_TYPE_ITEM;
158 static ClientActiveObject* create(IGameDef *gamedef);
160 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
161 void removeFromScene();
162 void updateLight(u8 light_at_pos);
163 v3s16 getLightPosition();
164 void updateNodePos();
166 void step(float dtime, ClientEnvironment *env);
168 void processMessage(const std::string &data);
170 void initialize(const std::string &data);
172 core::aabbox3d<f32>* getSelectionBox()
173 {return &m_selection_box;}
178 core::aabbox3d<f32> m_selection_box;
179 scene::IMeshSceneNode *m_node;
181 std::string m_inventorystring;
188 class RatCAO : public ClientActiveObject
191 RatCAO(IGameDef *gamedef);
196 return ACTIVEOBJECT_TYPE_RAT;
199 static ClientActiveObject* create(IGameDef *gamedef);
201 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
202 void removeFromScene();
203 void updateLight(u8 light_at_pos);
204 v3s16 getLightPosition();
205 void updateNodePos();
207 void step(float dtime, ClientEnvironment *env);
209 void processMessage(const std::string &data);
211 void initialize(const std::string &data);
213 core::aabbox3d<f32>* getSelectionBox()
214 {return &m_selection_box;}
216 {return pos_translator.vect_show;}
217 //{return m_position;}
220 core::aabbox3d<f32> m_selection_box;
221 scene::IMeshSceneNode *m_node;
224 SmoothTranslator pos_translator;
231 class Oerkki1CAO : public ClientActiveObject
234 Oerkki1CAO(IGameDef *gamedef);
235 virtual ~Oerkki1CAO();
239 return ACTIVEOBJECT_TYPE_OERKKI1;
242 static ClientActiveObject* create(IGameDef *gamedef);
244 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
245 void removeFromScene();
246 void updateLight(u8 light_at_pos);
247 v3s16 getLightPosition();
248 void updateNodePos();
250 void step(float dtime, ClientEnvironment *env);
252 void processMessage(const std::string &data);
254 void initialize(const std::string &data);
256 core::aabbox3d<f32>* getSelectionBox()
257 {return &m_selection_box;}
259 {return pos_translator.vect_show;}
260 //{return m_position;}
262 // If returns true, punch will not be sent to the server
263 bool directReportPunch(const std::string &toolname, v3f dir);
266 IntervalLimiter m_attack_interval;
267 core::aabbox3d<f32> m_selection_box;
268 scene::IMeshSceneNode *m_node;
271 SmoothTranslator pos_translator;
272 float m_damage_visual_timer;
273 bool m_damage_texture_enabled;
280 class FireflyCAO : public ClientActiveObject
283 FireflyCAO(IGameDef *gamedef);
284 virtual ~FireflyCAO();
288 return ACTIVEOBJECT_TYPE_FIREFLY;
291 static ClientActiveObject* create(IGameDef *gamedef);
293 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
294 void removeFromScene();
295 void updateLight(u8 light_at_pos);
296 v3s16 getLightPosition();
297 void updateNodePos();
299 void step(float dtime, ClientEnvironment *env);
301 void processMessage(const std::string &data);
303 void initialize(const std::string &data);
305 core::aabbox3d<f32>* getSelectionBox()
306 {return &m_selection_box;}
311 core::aabbox3d<f32> m_selection_box;
312 scene::IMeshSceneNode *m_node;
315 SmoothTranslator pos_translator;
322 class MobV2CAO : public ClientActiveObject
325 MobV2CAO(IGameDef *gamedef);
330 return ACTIVEOBJECT_TYPE_MOBV2;
333 static ClientActiveObject* create(IGameDef *gamedef);
335 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
336 void removeFromScene();
337 void updateLight(u8 light_at_pos);
338 v3s16 getLightPosition();
339 void updateNodePos();
341 void step(float dtime, ClientEnvironment *env);
343 void processMessage(const std::string &data);
345 void initialize(const std::string &data);
347 core::aabbox3d<f32>* getSelectionBox()
348 {return &m_selection_box;}
350 {return pos_translator.vect_show;}
351 //{return m_position;}
352 bool doShowSelectionBox(){return false;}
354 // If returns true, punch will not be sent to the server
355 bool directReportPunch(const std::string &toolname, v3f dir);
358 void setLooks(const std::string &looks);
360 IntervalLimiter m_attack_interval;
361 core::aabbox3d<f32> m_selection_box;
362 scene::MyBillboardSceneNode *m_node;
364 std::string m_texture_name;
366 SmoothTranslator pos_translator;
368 float m_walking_unset_timer;
371 float m_damage_visual_timer;
374 float m_shooting_unset_timer;
377 bool m_bright_shooting;
378 std::string m_sprite_type;
379 int m_simple_anim_frames;
380 float m_simple_anim_frametime;
381 bool m_lock_full_brightness;
382 int m_player_hit_damage;
383 float m_player_hit_distance;
384 float m_player_hit_interval;
385 float m_player_hit_timer;
387 Settings *m_properties;
394 struct LuaEntityProperties;
396 class LuaEntityCAO : public ClientActiveObject
399 LuaEntityCAO(IGameDef *gamedef);
400 virtual ~LuaEntityCAO();
404 return ACTIVEOBJECT_TYPE_LUAENTITY;
407 static ClientActiveObject* create(IGameDef *gamedef);
409 void addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc);
410 void removeFromScene();
411 void updateLight(u8 light_at_pos);
412 v3s16 getLightPosition();
413 void updateNodePos();
415 void step(float dtime, ClientEnvironment *env);
417 void processMessage(const std::string &data);
419 void initialize(const std::string &data);
421 core::aabbox3d<f32>* getSelectionBox()
422 {return &m_selection_box;}
424 {return pos_translator.vect_show;}
427 core::aabbox3d<f32> m_selection_box;
428 scene::IMeshSceneNode *m_meshnode;
429 scene::MyBillboardSceneNode *m_spritenode;
434 struct LuaEntityProperties *m_prop;
435 SmoothTranslator pos_translator;