-
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#pragma once
+
#include "constants.h"
#include "network/networkprotocol.h"
#include "unit_sao.h"
#include "util/numeric.h"
+#include "util/pointedthing.h"
/*
PlayerSAO needs some internals exposed.
{
float m_pool = 15.0f;
float m_max = 15.0f;
+
public:
LagPool() = default;
void setMax(float new_max)
{
m_max = new_max;
- if(m_pool > new_max)
+ if (m_pool > new_max)
m_pool = new_max;
}
void add(float dtime)
{
m_pool -= dtime;
- if(m_pool < 0)
+ if (m_pool < 0)
m_pool = 0;
}
- void empty()
- {
- m_pool = m_max;
- }
+ void empty() { m_pool = m_max; }
bool grab(float dtime)
{
- if(dtime <= 0)
+ if (dtime <= 0)
return true;
- if(m_pool + dtime > m_max)
+ if (m_pool + dtime > m_max)
return false;
m_pool += dtime;
return true;
PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
bool is_singleplayer);
- ActiveObjectType getType() const
- { return ACTIVEOBJECT_TYPE_PLAYER; }
- ActiveObjectType getSendType() const
- { return ACTIVEOBJECT_TYPE_GENERIC; }
- std::string getDescription();
+ ActiveObjectType getType() const override { return ACTIVEOBJECT_TYPE_PLAYER; }
+ ActiveObjectType getSendType() const override { return ACTIVEOBJECT_TYPE_GENERIC; }
+ std::string getDescription() override;
/*
Active object <-> environment interface
*/
- void addedToEnvironment(u32 dtime_s);
- void removingFromEnvironment();
- bool isStaticAllowed() const { return false; }
- std::string getClientInitializationData(u16 protocol_version);
- void getStaticData(std::string *result) const;
- void step(float dtime, bool send_recommended);
- void setBasePosition(const v3f &position);
- void setPos(const v3f &pos);
- void moveTo(v3f pos, bool continuous);
+ void addedToEnvironment(u32 dtime_s) override;
+ void removingFromEnvironment() override;
+ bool isStaticAllowed() const override { return false; }
+ bool shouldUnload() const override { return false; }
+ std::string getClientInitializationData(u16 protocol_version) override;
+ void getStaticData(std::string *result) const override;
+ void step(float dtime, bool send_recommended) override;
+ void setBasePosition(v3f position);
+ void setPos(const v3f &pos) override;
+ void moveTo(v3f pos, bool continuous) override;
void setPlayerYaw(const float yaw);
// Data should not be sent at player initialization
void setPlayerYawAndSend(const float yaw);
Interaction interface
*/
- u16 punch(v3f dir,
- const ToolCapabilities *toolcap,
- ServerActiveObject *puncher,
- float time_from_last_punch);
- void rightClick(ServerActiveObject *clicker) {}
- void setHP(s32 hp, const PlayerHPChangeReason &reason);
+ u32 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
+ float time_from_last_punch, u16 initial_wear = 0) override;
+ void rightClick(ServerActiveObject *clicker) override;
+ void setHP(s32 hp, const PlayerHPChangeReason &reason) override
+ {
+ return setHP(hp, reason, false);
+ }
+ void setHP(s32 hp, const PlayerHPChangeReason &reason, bool from_client);
void setHPRaw(u16 hp) { m_hp = hp; }
- s16 readDamage();
u16 getBreath() const { return m_breath; }
void setBreath(const u16 breath, bool send = true);
/*
Inventory interface
*/
- Inventory *getInventory() const;
- InventoryLocation getInventoryLocation() const;
- void setInventoryModified() {}
- std::string getWieldList() const { return "main"; }
- u16 getWieldIndex() const;
- ItemStack getWieldedItem(ItemStack *selected, ItemStack *hand = nullptr) const;
- bool setWieldedItem(const ItemStack &item);
+ Inventory *getInventory() const override;
+ InventoryLocation getInventoryLocation() const override;
+ void setInventoryModified() override {}
+ std::string getWieldList() const override { return "main"; }
+ u16 getWieldIndex() const override;
+ ItemStack getWieldedItem(ItemStack *selected, ItemStack *hand = nullptr) const override;
+ bool getOffhandWieldedItem(ItemStack *offhand, ItemStack *place, IItemDefManager *itemdef_manager, PointedThing pointed) const;
+ bool setWieldedItem(const ItemStack &item) override;
+ bool setOffhandWieldedItem(const ItemStack &item);
/*
PlayerSAO-specific
// Cheat prevention
- v3f getLastGoodPosition() const
- {
- return m_last_good_position;
- }
+ v3f getLastGoodPosition() const { return m_last_good_position; }
float resetTimeFromLastPunch()
{
float r = m_time_from_last_punch;
m_nocheat_dig_pos = p;
m_nocheat_dig_time = 0;
}
- v3s16 getNoCheatDigPos()
- {
- return m_nocheat_dig_pos;
- }
- float getNoCheatDigTime()
- {
- return m_nocheat_dig_time;
- }
- void noCheatDigEnd()
- {
- m_nocheat_dig_pos = v3s16(32767, 32767, 32767);
- }
- LagPool& getDigPool()
- {
- return m_dig_pool;
- }
+ v3s16 getNoCheatDigPos() { return m_nocheat_dig_pos; }
+ float getNoCheatDigTime() { return m_nocheat_dig_time; }
+ void noCheatDigEnd() { m_nocheat_dig_pos = v3s16(32767, 32767, 32767); }
+ LagPool &getDigPool() { return m_dig_pool; }
void setMaxSpeedOverride(const v3f &vel);
// Returns true if cheated
bool checkMovementCheat();
// Other
- void updatePrivileges(const std::set<std::string> &privs,
- bool is_singleplayer)
+ void updatePrivileges(const std::set<std::string> &privs, bool is_singleplayer)
{
m_privs = privs;
m_is_singleplayer = is_singleplayer;
}
- bool getCollisionBox(aabb3f *toset) const;
- bool getSelectionBox(aabb3f *toset) const;
- bool collideWithObjects() const { return true; }
+ bool getCollisionBox(aabb3f *toset) const override;
+ bool getSelectionBox(aabb3f *toset) const override;
+ bool collideWithObjects() const override { return true; }
void finalize(RemotePlayer *player, const std::set<std::string> &privs);
v3f getEyeOffset() const;
float getZoomFOV() const;
- inline Metadata &getMeta() { return m_meta; }
+ inline SimpleMetadata &getMeta() { return m_meta; }
private:
std::string getPropertyPacket();
f32 m_fov = 0.0f;
s16 m_wanted_range = 0.0f;
- Metadata m_meta;
+ SimpleMetadata m_meta;
+
public:
- float m_physics_override_speed = 1.0f;
- float m_physics_override_jump = 1.0f;
- float m_physics_override_gravity = 1.0f;
- bool m_physics_override_sneak = true;
- bool m_physics_override_sneak_glitch = false;
- bool m_physics_override_new_move = true;
bool m_physics_override_sent = false;
};
-
-struct PlayerHPChangeReason {
- enum Type : u8 {
+struct PlayerHPChangeReason
+{
+ enum Type : u8
+ {
SET_HP,
+ SET_HP_MAX, // internal type to allow distinguishing hp reset and damage (for effects)
PLAYER_PUNCH,
FALL,
NODE_DAMAGE,
// For NODE_DAMAGE
std::string node;
- inline bool hasLuaReference() const
- {
- return lua_reference >= 0;
- }
+ inline bool hasLuaReference() const { return lua_reference >= 0; }
bool setTypeFromString(const std::string &typestr)
{
{
switch (type) {
case PlayerHPChangeReason::SET_HP:
+ case PlayerHPChangeReason::SET_HP_MAX:
return "set_hp";
case PlayerHPChangeReason::PLAYER_PUNCH:
return "punch";
}
}
- PlayerHPChangeReason(Type type):
- type(type)
- {}
+ PlayerHPChangeReason(Type type) : type(type) {}
- PlayerHPChangeReason(Type type, ServerActiveObject *object):
+ PlayerHPChangeReason(Type type, ServerActiveObject *object) :
type(type), object(object)
- {}
+ {
+ }
- PlayerHPChangeReason(Type type, std::string node):
- type(type), node(node)
- {}
+ PlayerHPChangeReason(Type type, std::string node) : type(type), node(node) {}
};