Move tool stuff to tool.{h,cpp}
[oweals/minetest.git] / src / content_cao.h
index e240d739265fddaf5796adf3918a60d9e227a996..5310127a6147556ad8231fe8c514e490ec227db0 100644 (file)
@@ -33,19 +33,21 @@ class Settings;
 struct SmoothTranslator
 {
        v3f vect_old;
+       v3f vect_show;
+       v3f vect_aim;
        f32 anim_counter;
        f32 anim_time;
        f32 anim_time_counter;
-       v3f vect_show;
-       v3f vect_aim;
+       bool aim_is_end;
 
        SmoothTranslator():
                vect_old(0,0,0),
+               vect_show(0,0,0),
+               vect_aim(0,0,0),
                anim_counter(0),
                anim_time(0),
                anim_time_counter(0),
-               vect_show(0,0,0),
-               vect_aim(0,0,0)
+               aim_is_end(true)
        {}
 
        void init(v3f vect)
@@ -53,16 +55,30 @@ struct SmoothTranslator
                vect_old = vect;
                vect_show = vect;
                vect_aim = vect;
+               anim_counter = 0;
+               anim_time = 0;
+               anim_time_counter = 0;
+               aim_is_end = true;
+       }
+
+       void sharpen()
+       {
+               init(vect_show);
        }
 
-       void update(v3f vect_new)
+       void update(v3f vect_new, bool is_end_position=false, float update_interval=-1)
        {
+               aim_is_end = is_end_position;
                vect_old = vect_show;
                vect_aim = vect_new;
-               if(anim_time < 0.001 || anim_time > 1.0)
-                       anim_time = anim_time_counter;
-               else
-                       anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
+               if(update_interval > 0){
+                       anim_time = update_interval;
+               } else {
+                       if(anim_time < 0.001 || anim_time > 1.0)
+                               anim_time = anim_time_counter;
+                       else
+                               anim_time = anim_time * 0.9 + anim_time_counter * 0.1;
+               }
                anim_time_counter = 0;
                anim_counter = 0;
        }
@@ -77,8 +93,11 @@ struct SmoothTranslator
                        moveratio = anim_time_counter / anim_time;
                // Move a bit less than should, to avoid oscillation
                moveratio = moveratio * 0.5;
-               if(moveratio > 1.5)
-                       moveratio = 1.5;
+               float move_end = 1.5;
+               if(aim_is_end)
+                       move_end = 1.0;
+               if(moveratio > move_end)
+                       moveratio = move_end;
                vect_show = vect_old + vect_move * moveratio;
        }
 
@@ -240,6 +259,9 @@ public:
                {return pos_translator.vect_show;}
                //{return m_position;}
 
+       // If returns true, punch will not be sent to the server
+       bool directReportPunch(const std::string &toolname, v3f dir);
+
 private:
        IntervalLimiter m_attack_interval;
        core::aabbox3d<f32> m_selection_box;
@@ -329,11 +351,17 @@ public:
                //{return m_position;}
        bool doShowSelectionBox(){return false;}
 
+       // If returns true, punch will not be sent to the server
+       bool directReportPunch(const std::string &toolname, v3f dir);
+
 private:
+       void setLooks(const std::string &looks);
+       
        IntervalLimiter m_attack_interval;
        core::aabbox3d<f32> m_selection_box;
        scene::MyBillboardSceneNode *m_node;
        v3f m_position;
+       std::string m_texture_name;
        float m_yaw;
        SmoothTranslator pos_translator;
        bool m_walking;
@@ -345,7 +373,7 @@ private:
        bool m_shooting;
        float m_shooting_unset_timer;
        v2f m_sprite_size;
-       v3f m_sprite_pos;
+       float m_sprite_y;
        bool m_bright_shooting;
        std::string m_sprite_type;
        int m_simple_anim_frames;
@@ -359,6 +387,52 @@ private:
        Settings *m_properties;
 };
 
+/*
+       LuaEntityCAO
+*/
+
+struct LuaEntityProperties;
+
+class LuaEntityCAO : public ClientActiveObject
+{
+public:
+       LuaEntityCAO();
+       virtual ~LuaEntityCAO();
+       
+       u8 getType() const
+       {
+               return ACTIVEOBJECT_TYPE_LUAENTITY;
+       }
+       
+       static ClientActiveObject* create();
+
+       void addToScene(scene::ISceneManager *smgr);
+       void removeFromScene();
+       void updateLight(u8 light_at_pos);
+       v3s16 getLightPosition();
+       void updateNodePos();
+
+       void step(float dtime, ClientEnvironment *env);
+
+       void processMessage(const std::string &data);
+
+       void initialize(const std::string &data);
+       
+       core::aabbox3d<f32>* getSelectionBox()
+               {return &m_selection_box;}
+       v3f getPosition()
+               {return pos_translator.vect_show;}
+
+private:
+       core::aabbox3d<f32> m_selection_box;
+       scene::IMeshSceneNode *m_meshnode;
+       scene::MyBillboardSceneNode *m_spritenode;
+       v3f m_position;
+       float m_yaw;
+       struct LuaEntityProperties *m_prop;
+       SmoothTranslator pos_translator;
+};
+
 
 #endif