2011-06-26 05:48:56 -07:00
|
|
|
/*
|
2013-02-24 09:40:43 -08:00
|
|
|
Minetest
|
2013-02-24 10:38:45 -08:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2020-04-11 02:22:15 -07:00
|
|
|
Copyright (C) 2013-2020 Minetest core developers & community
|
2011-06-26 05:48:56 -07:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 07:56:56 -07: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 05:48:56 -07: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 07:56:56 -07:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-06-26 05:48:56 -07:00
|
|
|
|
2012-06-05 07:56:56 -07:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-06-26 05:48:56 -07: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 13:19:39 -07:00
|
|
|
#pragma once
|
2011-06-26 05:48:56 -07:00
|
|
|
|
2020-04-11 02:22:15 -07:00
|
|
|
#include "unit_sao.h"
|
2011-10-14 16:28:57 -07:00
|
|
|
|
2016-10-30 06:53:26 -07:00
|
|
|
class LuaEntitySAO : public UnitSAO
|
2011-11-11 09:33:17 -08:00
|
|
|
{
|
|
|
|
public:
|
2020-04-11 02:22:15 -07: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 09:33:17 -08:00
|
|
|
~LuaEntitySAO();
|
2022-05-26 12:32:51 -07:00
|
|
|
|
2020-04-11 02:22:15 -07:00
|
|
|
ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_LUAENTITY; }
|
|
|
|
ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
|
2012-09-09 07:12:29 -07:00
|
|
|
virtual void addedToEnvironment(u32 dtime_s);
|
2011-11-11 09:33:17 -08:00
|
|
|
void step(float dtime, bool send_recommended);
|
2012-11-26 14:47:03 -08:00
|
|
|
std::string getClientInitializationData(u16 protocol_version);
|
2022-05-26 12:32:51 -07:00
|
|
|
|
2020-04-11 02:22:15 -07:00
|
|
|
bool isStaticAllowed() const { return m_prop.static_save; }
|
2020-10-19 11:38:33 -07:00
|
|
|
bool shouldUnload() const { return true; }
|
2017-01-11 13:48:14 -08:00
|
|
|
void getStaticData(std::string *result) const;
|
2022-05-26 12:32:51 -07:00
|
|
|
|
2021-10-31 15:33:33 -07:00
|
|
|
u32 punch(v3f dir, const ToolCapabilities *toolcap = nullptr,
|
2020-04-11 02:22:15 -07:00
|
|
|
ServerActiveObject *puncher = nullptr,
|
2021-10-31 15:33:33 -07:00
|
|
|
float time_from_last_punch = 1000000.0f,
|
|
|
|
u16 initial_wear = 0);
|
2022-05-26 12:32:51 -07:00
|
|
|
|
2011-11-12 07:37:14 -08:00
|
|
|
void rightClick(ServerActiveObject *clicker);
|
2022-05-26 12:32:51 -07:00
|
|
|
|
2016-10-30 08:12:09 -07:00
|
|
|
void setPos(const v3f &pos);
|
2011-11-12 03:59:56 -08:00
|
|
|
void moveTo(v3f pos, bool continuous);
|
2011-11-12 05:14:24 -08:00
|
|
|
float getMinimumSavedMovement();
|
2022-05-26 12:32:51 -07:00
|
|
|
|
2012-03-04 11:08:03 -08:00
|
|
|
std::string getDescription();
|
2022-05-26 12:32:51 -07:00
|
|
|
|
2019-02-10 15:03:26 -08:00
|
|
|
void setHP(s32 hp, const PlayerHPChangeReason &reason);
|
|
|
|
u16 getHP() const;
|
2019-02-20 15:36:17 -08:00
|
|
|
|
2011-11-26 02:35:30 -08:00
|
|
|
/* LuaEntitySAO-specific */
|
2011-11-21 01:15:15 -08:00
|
|
|
void setVelocity(v3f velocity);
|
2020-04-11 02:22:15 -07:00
|
|
|
void addVelocity(v3f velocity) { m_velocity += velocity; }
|
2012-01-02 06:19:52 -08:00
|
|
|
v3f getVelocity();
|
2011-11-21 01:15:15 -08:00
|
|
|
void setAcceleration(v3f acceleration);
|
2011-11-26 18:31:05 -08:00
|
|
|
v3f getAcceleration();
|
2016-10-30 06:53:26 -07:00
|
|
|
|
2011-11-26 02:35:30 -08:00
|
|
|
void setTextureMod(const std::string &mod);
|
2017-01-14 10:32:10 -08:00
|
|
|
std::string getTextureMod() const;
|
2011-11-26 18:31:05 -08:00
|
|
|
void setSprite(v2s16 p, int num_frames, float framelength,
|
|
|
|
bool select_horiz_by_yawpitch);
|
2012-01-02 03:12:56 -08:00
|
|
|
std::string getName();
|
2017-01-09 11:39:45 -08:00
|
|
|
bool getCollisionBox(aabb3f *toset) const;
|
2016-07-23 12:11:20 -07:00
|
|
|
bool getSelectionBox(aabb3f *toset) const;
|
2017-01-09 11:39:45 -08:00
|
|
|
bool collideWithObjects() const;
|
2020-04-11 02:22:15 -07:00
|
|
|
|
2021-01-02 06:14:29 -08:00
|
|
|
protected:
|
|
|
|
void dispatchScriptDeactivate();
|
|
|
|
virtual void onMarkedForDeactivation() { dispatchScriptDeactivate(); }
|
|
|
|
virtual void onMarkedForRemoval() { dispatchScriptDeactivate(); }
|
|
|
|
|
2011-11-11 09:33:17 -08:00
|
|
|
private:
|
2012-03-29 07:46:21 -07:00
|
|
|
std::string getPropertyPacket();
|
2011-11-12 03:14:44 -08:00
|
|
|
void sendPosition(bool do_interpolate, bool is_movement_end);
|
2020-04-10 10:49:20 -07:00
|
|
|
std::string generateSetTextureModCommand() const;
|
2020-04-11 02:22:15 -07:00
|
|
|
static std::string generateSetSpriteCommand(v2s16 p, u16 num_frames,
|
|
|
|
f32 framelength, bool select_horiz_by_yawpitch);
|
2011-11-12 01:59:56 -08:00
|
|
|
|
2011-11-11 09:33:17 -08:00
|
|
|
std::string m_init_name;
|
|
|
|
std::string m_init_state;
|
2017-06-16 02:25:52 -07:00
|
|
|
bool m_registered = false;
|
2015-11-20 14:46:33 -08:00
|
|
|
|
2011-11-21 01:15:15 -08:00
|
|
|
v3f m_velocity;
|
|
|
|
v3f m_acceleration;
|
2016-10-30 06:53:26 -07:00
|
|
|
|
2011-11-12 01:59:56 -08:00
|
|
|
v3f m_last_sent_position;
|
2011-11-21 04:36:21 -08:00
|
|
|
v3f m_last_sent_velocity;
|
2018-11-28 00:38:50 -08:00
|
|
|
v3f m_last_sent_rotation;
|
2017-06-16 02:25:52 -07: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 09:33:17 -08:00
|
|
|
};
|