2011-06-26 14:48:56 +02:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2020-04-11 11:22:15 +02:00
|
|
|
Copyright (C) 2013-2020 Minetest core developers & community
|
2011-06-26 14:48:56 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2011-06-26 14:48:56 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-06-26 14:48:56 +02:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-06-26 14:48:56 +02:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2011-06-26 14:48:56 +02:00
|
|
|
|
2020-04-11 11:22:15 +02:00
|
|
|
#include "unit_sao.h"
|
2011-10-15 01:28:57 +02:00
|
|
|
|
2016-10-30 14:53:26 +01:00
|
|
|
class LuaEntitySAO : public UnitSAO
|
2011-11-11 18:33:17 +01:00
|
|
|
{
|
|
|
|
public:
|
2020-04-11 11:22:15 +02:00
|
|
|
LuaEntitySAO() = delete;
|
|
|
|
// Used by the environment to load SAO
|
|
|
|
LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &data);
|
|
|
|
// Used by the Lua API
|
|
|
|
LuaEntitySAO(ServerEnvironment *env, v3f pos, const std::string &name,
|
|
|
|
const std::string &state) :
|
|
|
|
UnitSAO(env, pos),
|
|
|
|
m_init_name(name), m_init_state(state)
|
|
|
|
{
|
|
|
|
}
|
2011-11-11 18:33:17 +01:00
|
|
|
~LuaEntitySAO();
|
2022-05-26 21:32:51 +02:00
|
|
|
|
2020-04-11 11:22:15 +02:00
|
|
|
ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_LUAENTITY; }
|
|
|
|
ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
|
2012-09-09 16:12:29 +02:00
|
|
|
virtual void addedToEnvironment(u32 dtime_s);
|
2011-11-11 18:33:17 +01:00
|
|
|
void step(float dtime, bool send_recommended);
|
2012-11-26 23:47:03 +01:00
|
|
|
std::string getClientInitializationData(u16 protocol_version);
|
2022-05-26 21:32:51 +02:00
|
|
|
|
2020-04-11 11:22:15 +02:00
|
|
|
bool isStaticAllowed() const { return m_prop.static_save; }
|
2020-10-19 20:38:33 +02:00
|
|
|
bool shouldUnload() const { return true; }
|
2017-01-11 22:48:14 +01:00
|
|
|
void getStaticData(std::string *result) const;
|
2022-05-26 21:32:51 +02:00
|
|
|
|
2021-10-31 23:33:33 +01:00
|
|
|
u32 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
|
2020-04-11 11:22:15 +02:00
|
|
|
ServerActiveObject *puncher = nullptr,
|
2021-10-31 23:33:33 +01:00
|
|
|
float time_from_last_punch = 1000000.0f,
|
|
|
|
u16 initial_wear = 0);
|
2022-05-26 21:32:51 +02:00
|
|
|
|
2011-11-12 16:37:14 +01:00
|
|
|
void rightClick(ServerActiveObject *clicker);
|
2022-05-26 21:32:51 +02:00
|
|
|
|
2016-10-30 16:12:09 +01:00
|
|
|
void setPos(const v3f &pos);
|
2011-11-12 12:59:56 +01:00
|
|
|
void moveTo(v3f pos, bool continuous);
|
2011-11-12 14:14:24 +01:00
|
|
|
float getMinimumSavedMovement();
|
2022-05-26 21:32:51 +02:00
|
|
|
|
2012-03-04 20:08:03 +01:00
|
|
|
std::string getDescription();
|
2022-05-26 21:32:51 +02:00
|
|
|
|
2019-02-11 00:03:26 +01:00
|
|
|
void setHP(s32 hp, const PlayerHPChangeReason &reason);
|
|
|
|
u16 getHP() const;
|
2019-02-21 00:36:17 +01:00
|
|
|
|
2011-11-26 11:35:30 +01:00
|
|
|
/* LuaEntitySAO-specific */
|
2011-11-21 10:15:15 +01:00
|
|
|
void setVelocity(v3f velocity);
|
2020-04-11 11:22:15 +02:00
|
|
|
void addVelocity(v3f velocity) { m_velocity += velocity; }
|
2012-01-02 15:19:52 +01:00
|
|
|
v3f getVelocity();
|
2011-11-21 10:15:15 +01:00
|
|
|
void setAcceleration(v3f acceleration);
|
2011-11-27 03:31:05 +01:00
|
|
|
v3f getAcceleration();
|
2016-10-30 14:53:26 +01:00
|
|
|
|
2011-11-26 11:35:30 +01:00
|
|
|
void setTextureMod(const std::string &mod);
|
2017-01-14 19:32:10 +01:00
|
|
|
std::string getTextureMod() const;
|
2011-11-27 03:31:05 +01:00
|
|
|
void setSprite(v2s16 p, int num_frames, float framelength,
|
|
|
|
bool select_horiz_by_yawpitch);
|
2012-01-02 12:12:56 +01:00
|
|
|
std::string getName();
|
2017-01-09 20:39:45 +01:00
|
|
|
bool getCollisionBox(aabb3f *toset) const;
|
2016-07-23 21:11:20 +02:00
|
|
|
bool getSelectionBox(aabb3f *toset) const;
|
2017-01-09 20:39:45 +01:00
|
|
|
bool collideWithObjects() const;
|
2020-04-11 11:22:15 +02:00
|
|
|
|
2021-01-02 15:14:29 +01:00
|
|
|
protected:
|
2022-06-11 20:01:14 +02:00
|
|
|
void dispatchScriptDeactivate(bool removal);
|
|
|
|
virtual void onMarkedForDeactivation() { dispatchScriptDeactivate(false); }
|
|
|
|
virtual void onMarkedForRemoval() { dispatchScriptDeactivate(true); }
|
2021-01-02 15:14:29 +01:00
|
|
|
|
2011-11-11 18:33:17 +01:00
|
|
|
private:
|
2012-03-29 16:46:21 +02:00
|
|
|
std::string getPropertyPacket();
|
2011-11-12 12:14:44 +01:00
|
|
|
void sendPosition(bool do_interpolate, bool is_movement_end);
|
2020-04-10 19:49:20 +02:00
|
|
|
std::string generateSetTextureModCommand() const;
|
2020-04-11 11:22:15 +02:00
|
|
|
static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
|
|
|
|
f32 framelength, bool select_horiz_by_yawpitch);
|
2011-11-12 10:59:56 +01:00
|
|
|
|
2011-11-11 18:33:17 +01:00
|
|
|
std::string m_init_name;
|
|
|
|
std::string m_init_state;
|
2017-06-16 11:25:52 +02:00
|
|
|
bool m_registered = false;
|
2015-11-20 23:46:33 +01:00
|
|
|
|
2011-11-21 10:15:15 +01:00
|
|
|
v3f m_velocity;
|
|
|
|
v3f m_acceleration;
|
2016-10-30 14:53:26 +01:00
|
|
|
|
2011-11-12 10:59:56 +01:00
|
|
|
v3f m_last_sent_position;
|
2011-11-21 13:36:21 +01:00
|
|
|
v3f m_last_sent_velocity;
|
2018-11-28 09:38:50 +01:00
|
|
|
v3f m_last_sent_rotation;
|
2017-06-16 11:25:52 +02:00
|
|
|
float m_last_sent_position_timer = 0.0f;
|
|
|
|
float m_last_sent_move_precision = 0.0f;
|
|
|
|
std::string m_current_texture_modifier = "";
|
2011-11-11 18:33:17 +01:00
|
|
|
};
|