]> git.lizzy.rs Git - dragonfireclient.git/blob - src/server/luaentity_sao.h
87b664a8b282708acaaf717581f26df2d8b758e6
[dragonfireclient.git] / src / server / luaentity_sao.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013-2020 Minetest core developers & community
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #pragma once
22
23 #include "unit_sao.h"
24
25 class LuaEntitySAO : public UnitSAO
26 {
27 public:
28         LuaEntitySAO() = delete;
29         // Used by the environment to load SAO
30         LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data);
31         // Used by the Lua API
32         LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name,
33                         const std::string &state) :
34                         UnitSAO(env, pos),
35                         m_init_name(name), m_init_state(state)
36         {
37         }
38         ~LuaEntitySAO();
39         ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_LUAENTITY; }
40         ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
41         virtual void addedToEnvironment(u32 dtime_s);
42         void step(float dtime, bool send_recommended);
43         std::string getClientInitializationData(u16 protocol_version);
44         bool isStaticAllowed() const { return m_prop.static_save; }
45         bool shouldUnload() const { return true; }
46         void getStaticData(std::string *result) const;
47         u32 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
48                         ServerActiveObject *puncher = nullptr,
49                         float time_from_last_punch = 1000000.0f,
50                         u16 initial_wear = 0);
51         void rightClick(ServerActiveObject *clicker);
52         void setPos(const v3f &pos);
53         void moveTo(v3f pos, bool continuous);
54         float getMinimumSavedMovement();
55         std::string getDescription();
56         void setHP(s32 hp, const PlayerHPChangeReason &reason);
57         u16 getHP() const;
58
59         /* LuaEntitySAO-specific */
60         void setVelocity(v3f velocity);
61         void addVelocity(v3f velocity) { m_velocity += velocity; }
62         v3f getVelocity();
63         void setAcceleration(v3f acceleration);
64         v3f getAcceleration();
65
66         void setTextureMod(const std::string &mod);
67         std::string getTextureMod() const;
68         void setSprite(v2s16 p, int num_frames, float framelength,
69                         bool select_horiz_by_yawpitch);
70         std::string getName();
71         bool getCollisionBox(aabb3f *toset) const;
72         bool getSelectionBox(aabb3f *toset) const;
73         bool collideWithObjects() const;
74
75 protected:
76         void dispatchScriptDeactivate();
77         virtual void onMarkedForDeactivation() { dispatchScriptDeactivate(); }
78         virtual void onMarkedForRemoval() { dispatchScriptDeactivate(); }
79
80 private:
81         std::string getPropertyPacket();
82         void sendPosition(bool do_interpolate, bool is_movement_end);
83         std::string generateSetTextureModCommand() const;
84         static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
85                         f32 framelength, bool select_horiz_by_yawpitch);
86
87         std::string m_init_name;
88         std::string m_init_state;
89         bool m_registered = false;
90
91         v3f m_velocity;
92         v3f m_acceleration;
93
94         v3f m_last_sent_position;
95         v3f m_last_sent_velocity;
96         v3f m_last_sent_rotation;
97         float m_last_sent_position_timer = 0.0f;
98         float m_last_sent_move_precision = 0.0f;
99         std::string m_current_texture_modifier = "";
100 };