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
31 struct SmoothTranslator
36 f32 anim_time_counter;
56 void update(v3f vect_new)
60 if(anim_time < 0.001 || anim_time > 1.0)
61 anim_time = anim_time_counter;
63 anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
64 anim_time_counter = 0;
68 void translate(f32 dtime)
70 anim_time_counter = anim_time_counter + dtime;
71 anim_counter = anim_counter + dtime;
72 v3f vect_move = vect_aim - vect_old;
75 moveratio = anim_time_counter / anim_time;
76 // Move a bit less than should, to avoid oscillation
77 moveratio = moveratio * 0.8;
80 vect_show = vect_old + vect_move * moveratio;
89 class TestCAO : public ClientActiveObject
97 return ACTIVEOBJECT_TYPE_TEST;
100 static ClientActiveObject* create();
102 void addToScene(scene::ISceneManager *smgr);
103 void removeFromScene();
104 void updateLight(u8 light_at_pos);
105 v3s16 getLightPosition();
106 void updateNodePos();
108 void step(float dtime, ClientEnvironment *env);
110 void processMessage(const std::string &data);
113 scene::IMeshSceneNode *m_node;
121 class ItemCAO : public ClientActiveObject
129 return ACTIVEOBJECT_TYPE_ITEM;
132 static ClientActiveObject* create();
134 void addToScene(scene::ISceneManager *smgr);
135 void removeFromScene();
136 void updateLight(u8 light_at_pos);
137 v3s16 getLightPosition();
138 void updateNodePos();
140 void step(float dtime, ClientEnvironment *env);
142 void processMessage(const std::string &data);
144 void initialize(const std::string &data);
146 core::aabbox3d<f32>* getSelectionBox()
147 {return &m_selection_box;}
152 core::aabbox3d<f32> m_selection_box;
153 scene::IMeshSceneNode *m_node;
155 std::string m_inventorystring;
162 class RatCAO : public ClientActiveObject
170 return ACTIVEOBJECT_TYPE_RAT;
173 static ClientActiveObject* create();
175 void addToScene(scene::ISceneManager *smgr);
176 void removeFromScene();
177 void updateLight(u8 light_at_pos);
178 v3s16 getLightPosition();
179 void updateNodePos();
181 void step(float dtime, ClientEnvironment *env);
183 void processMessage(const std::string &data);
185 void initialize(const std::string &data);
187 core::aabbox3d<f32>* getSelectionBox()
188 {return &m_selection_box;}
190 {return pos_translator.vect_show;}
191 //{return m_position;}
194 core::aabbox3d<f32> m_selection_box;
195 scene::IMeshSceneNode *m_node;
198 SmoothTranslator pos_translator;
205 class Oerkki1CAO : public ClientActiveObject
209 virtual ~Oerkki1CAO();
213 return ACTIVEOBJECT_TYPE_OERKKI1;
216 static ClientActiveObject* create();
218 void addToScene(scene::ISceneManager *smgr);
219 void removeFromScene();
220 void updateLight(u8 light_at_pos);
221 v3s16 getLightPosition();
222 void updateNodePos();
224 void step(float dtime, ClientEnvironment *env);
226 void processMessage(const std::string &data);
228 void initialize(const std::string &data);
230 core::aabbox3d<f32>* getSelectionBox()
231 {return &m_selection_box;}
233 {return pos_translator.vect_show;}
234 //{return m_position;}
237 IntervalLimiter m_attack_interval;
238 core::aabbox3d<f32> m_selection_box;
239 scene::IMeshSceneNode *m_node;
242 SmoothTranslator pos_translator;
243 float m_damage_visual_timer;
244 bool m_damage_texture_enabled;
251 class FireflyCAO : public ClientActiveObject
255 virtual ~FireflyCAO();
259 return ACTIVEOBJECT_TYPE_FIREFLY;
262 static ClientActiveObject* create();
264 void addToScene(scene::ISceneManager *smgr);
265 void removeFromScene();
266 void updateLight(u8 light_at_pos);
267 v3s16 getLightPosition();
268 void updateNodePos();
270 void step(float dtime, ClientEnvironment *env);
272 void processMessage(const std::string &data);
274 void initialize(const std::string &data);
276 core::aabbox3d<f32>* getSelectionBox()
277 {return &m_selection_box;}
282 core::aabbox3d<f32> m_selection_box;
283 scene::IMeshSceneNode *m_node;
286 SmoothTranslator pos_translator;