Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
luaentity_sao.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4// Copyright (C) 2013-2020 Minetest core developers & community
5
6#pragma once
7
8#include "unit_sao.h"
9
10class LuaEntitySAO : public UnitSAO
11{
12public:
13 LuaEntitySAO() = delete;
14 // Used by the environment to load SAO
15 LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data);
16 // Used by the Lua API
17 LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name,
18 const std::string &state) :
19 UnitSAO(env, pos),
20 m_init_name(name), m_init_state(state)
21 {
22 }
24
27 virtual void addedToEnvironment(u32 dtime_s);
28 void step(float dtime, bool send_recommended);
29 std::string getClientInitializationData(u16 protocol_version);
30
31 bool isStaticAllowed() const { return m_prop.static_save; }
32 bool shouldUnload() const { return true; }
33 void getStaticData(std::string *result) const;
34
35 u32 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
36 ServerActiveObject *puncher = nullptr,
37 float time_from_last_punch = 1000000.0f,
38 u16 initial_wear = 0);
39
40 void rightClick(ServerActiveObject *clicker);
41
42 void setPos(const v3f &pos);
43 void moveTo(v3f pos, bool continuous);
45
46 std::string getDescription();
47
48 void setHP(s32 hp, const PlayerHPChangeReason &reason);
49 u16 getHP() const;
50
51 /* LuaEntitySAO-specific */
52 void setVelocity(v3f velocity);
53 void addVelocity(v3f velocity) { m_velocity += velocity; }
55 void setAcceleration(v3f acceleration);
57
58 void setTextureMod(const std::string &mod);
59 std::string getTextureMod() const;
60 void setSprite(v2s16 p, int num_frames, float framelength,
61 bool select_horiz_by_yawpitch);
62 std::string getName();
63 bool getCollisionBox(aabb3f *toset) const;
64 bool getSelectionBox(aabb3f *toset) const;
65 bool collideWithObjects() const;
66
67protected:
68 void dispatchScriptDeactivate(bool removal);
77
78private:
79 std::string getPropertyPacket();
80 void sendPosition(bool do_interpolate, bool is_movement_end);
81 std::string generateSetTextureModCommand() const;
82 static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
83 f32 framelength, bool select_horiz_by_yawpitch);
84
85 std::string m_init_name;
86 std::string m_init_state;
87 bool m_registered = false;
88
91
97
98 std::string m_texture_modifier;
100};
ActiveObjectType
Definition activeobject.h:14
@ ACTIVEOBJECT_TYPE_GENERIC
Definition activeobject.h:28
@ ACTIVEOBJECT_TYPE_LUAENTITY
Definition activeobject.h:24
static v2f dir(const v2f &pos_dist)
Definition camera.cpp:191
Definition luaentity_sao.h:11
v3f m_last_sent_rotation
Definition luaentity_sao.h:94
std::string m_init_state
Definition luaentity_sao.h:86
void setSprite(v2s16 p, int num_frames, float framelength, bool select_horiz_by_yawpitch)
Definition luaentity_sao.cpp:475
v3f m_acceleration
Definition luaentity_sao.h:90
void dispatchScriptDeactivate(bool removal)
Definition luaentity_sao.cpp:111
std::string getName()
Definition luaentity_sao.cpp:488
void setPos(const v3f &pos)
Definition luaentity_sao.cpp:365
u32 punch(v3f dir, const ToolCapabilities *toolcap=nullptr, ServerActiveObject *puncher=nullptr, float time_from_last_punch=1000000.0f, u16 initial_wear=0)
Definition luaentity_sao.cpp:308
std::string generateSetTextureModCommand() const
Definition luaentity_sao.cpp:451
static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames, f32 framelength, bool select_horiz_by_yawpitch)
Definition luaentity_sao.cpp:461
std::string getClientInitializationData(u16 protocol_version)
Definition luaentity_sao.cpp:231
v3f m_velocity
Definition luaentity_sao.h:89
void setAcceleration(v3f acceleration)
Definition luaentity_sao.cpp:428
float getMinimumSavedMovement()
Definition luaentity_sao.cpp:382
v3f m_last_sent_position
Definition luaentity_sao.h:92
std::string getDescription()
Definition luaentity_sao.cpp:387
bool collideWithObjects() const
Definition luaentity_sao.cpp:559
v3f m_last_sent_velocity
Definition luaentity_sao.h:93
LuaEntitySAO()=delete
float m_last_sent_position_timer
Definition luaentity_sao.h:95
bool shouldUnload() const
Definition luaentity_sao.h:32
virtual void onMarkedForRemoval()
Definition luaentity_sao.h:73
~LuaEntitySAO()
Definition luaentity_sao.cpp:73
void sendPosition(bool do_interpolate, bool is_movement_end)
Definition luaentity_sao.cpp:498
ActiveObjectType getSendType() const
Definition luaentity_sao.h:26
void getStaticData(std::string *result) const
Definition luaentity_sao.cpp:275
bool isStaticAllowed() const
Definition luaentity_sao.h:31
std::string getTextureMod() const
Definition luaentity_sao.cpp:446
std::string m_init_name
Definition luaentity_sao.h:85
bool getCollisionBox(aabb3f *toset) const
Definition luaentity_sao.cpp:530
void moveTo(v3f pos, bool continuous)
Definition luaentity_sao.cpp:373
bool m_registered
Definition luaentity_sao.h:87
void setTextureMod(const std::string &mod)
Definition luaentity_sao.cpp:438
bool m_texture_modifier_sent
Definition luaentity_sao.h:99
void setHP(s32 hp, const PlayerHPChangeReason &reason)
Definition luaentity_sao.cpp:396
std::string getPropertyPacket()
Definition luaentity_sao.cpp:493
v3f getVelocity()
Definition luaentity_sao.cpp:423
bool getSelectionBox(aabb3f *toset) const
Definition luaentity_sao.cpp:547
std::string m_texture_modifier
Definition luaentity_sao.h:98
LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name, const std::string &state)
Definition luaentity_sao.h:17
void setVelocity(v3f velocity)
Definition luaentity_sao.cpp:418
void step(float dtime, bool send_recommended)
Definition luaentity_sao.cpp:120
ActiveObjectType getType() const
Definition luaentity_sao.h:25
virtual void onMarkedForDeactivation()
Definition luaentity_sao.h:69
float m_last_sent_move_precision
Definition luaentity_sao.h:96
virtual void addedToEnvironment(u32 dtime_s)
Definition luaentity_sao.cpp:84
void addVelocity(v3f velocity)
Definition luaentity_sao.h:53
u16 getHP() const
Definition luaentity_sao.cpp:413
void rightClick(ServerActiveObject *clicker)
Definition luaentity_sao.cpp:357
v3f getAcceleration()
Definition luaentity_sao.cpp:433
Definition serveractiveobject.h:41
Definition serverenvironment.h:219
Definition unit_sao.h:14
virtual void onMarkedForRemoval() override
Definition unit_sao.h:117
ObjectProperties m_prop
Definition unit_sao.h:105
virtual void onMarkedForDeactivation() override
Definition unit_sao.h:113
core::aabbox3d< f32 > aabb3f
Definition irr_aabb3d.h:11
core::vector2d< s16 > v2s16
Definition irr_v2d.h:12
core::vector3df v3f
Definition irr_v3d.h:11
bool static_save
Definition object_properties.h:54
Definition player_sao.h:227
Definition tool.h:46
static std::string p(std::string path)
Definition test_filesys.cpp:53