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;}
252 IntervalLimiter m_attack_interval;
253 core::aabbox3d<f32> m_selection_box;
254 scene::IMeshSceneNode *m_node;
257 SmoothTranslator pos_translator;
258 float m_damage_visual_timer;
259 bool m_damage_texture_enabled;
266 class FireflyCAO : public ClientActiveObject
270 virtual ~FireflyCAO();
274 return ACTIVEOBJECT_TYPE_FIREFLY;
277 static ClientActiveObject* create();
279 void addToScene(scene::ISceneManager *smgr);
280 void removeFromScene();
281 void updateLight(u8 light_at_pos);
282 v3s16 getLightPosition();
283 void updateNodePos();
285 void step(float dtime, ClientEnvironment *env);
287 void processMessage(const std::string &data);
289 void initialize(const std::string &data);
291 core::aabbox3d<f32>* getSelectionBox()
292 {return &m_selection_box;}
297 core::aabbox3d<f32> m_selection_box;
298 scene::IMeshSceneNode *m_node;
301 SmoothTranslator pos_translator;
308 class MobV2CAO : public ClientActiveObject
316 return ACTIVEOBJECT_TYPE_MOBV2;
319 static ClientActiveObject* create();
321 void addToScene(scene::ISceneManager *smgr);
322 void removeFromScene();
323 void updateLight(u8 light_at_pos);
324 v3s16 getLightPosition();
325 void updateNodePos();
327 void step(float dtime, ClientEnvironment *env);
329 void processMessage(const std::string &data);
331 void initialize(const std::string &data);
333 core::aabbox3d<f32>* getSelectionBox()
334 {return &m_selection_box;}
336 {return pos_translator.vect_show;}
337 //{return m_position;}
338 bool doShowSelectionBox(){return false;}
340 // If returns true, punch will not be sent to the server
341 bool directReportPunch(const std::string &toolname, v3f dir);
344 void setLooks(const std::string &looks);
346 IntervalLimiter m_attack_interval;
347 core::aabbox3d<f32> m_selection_box;
348 scene::MyBillboardSceneNode *m_node;
350 std::string m_texture_name;
352 SmoothTranslator pos_translator;
354 float m_walking_unset_timer;
357 float m_damage_visual_timer;
360 float m_shooting_unset_timer;
363 bool m_bright_shooting;
364 std::string m_sprite_type;
365 int m_simple_anim_frames;
366 float m_simple_anim_frametime;
367 bool m_lock_full_brightness;
368 int m_player_hit_damage;
369 float m_player_hit_distance;
370 float m_player_hit_interval;
371 float m_player_hit_timer;
373 Settings *m_properties;