]> git.lizzy.rs Git - minetest.git/blob - src/server/luaentity_sao.h
Settings: Remove unused functions
[minetest.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         void getStaticData(std::string *result) const;
46         u16 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
47                         ServerActiveObject *puncher = nullptr,
48                         float time_from_last_punch = 1000000.0f);
49         void rightClick(ServerActiveObject *clicker);
50         void setPos(const v3f &pos);
51         void moveTo(v3f pos, bool continuous);
52         float getMinimumSavedMovement();
53         std::string getDescription();
54         void setHP(s32 hp, const PlayerHPChangeReason &reason);
55         u16 getHP() const;
56
57         /* LuaEntitySAO-specific */
58         void setVelocity(v3f velocity);
59         void addVelocity(v3f velocity) { m_velocity += velocity; }
60         v3f getVelocity();
61         void setAcceleration(v3f acceleration);
62         v3f getAcceleration();
63
64         void setTextureMod(const std::string &mod);
65         std::string getTextureMod() const;
66         void setSprite(v2s16 p, int num_frames, float framelength,
67                         bool select_horiz_by_yawpitch);
68         std::string getName();
69         bool getCollisionBox(aabb3f *toset) const;
70         bool getSelectionBox(aabb3f *toset) const;
71         bool collideWithObjects() const;
72
73 private:
74         std::string getPropertyPacket();
75         void sendPosition(bool do_interpolate, bool is_movement_end);
76         std::string generateSetTextureModCommand() const;
77         static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
78                         f32 framelength, bool select_horiz_by_yawpitch);
79
80         std::string m_init_name;
81         std::string m_init_state;
82         bool m_registered = false;
83
84         v3f m_velocity;
85         v3f m_acceleration;
86
87         v3f m_last_sent_position;
88         v3f m_last_sent_velocity;
89         v3f m_last_sent_rotation;
90         float m_last_sent_position_timer = 0.0f;
91         float m_last_sent_move_precision = 0.0f;
92         std::string m_current_texture_modifier = "";
93 };