1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Customizeable max breath for players (#6411)

* Customizeable maximal breath for players
This commit is contained in:
SmallJoker 2017-09-15 12:18:47 +02:00 committed by Loïc Blot
parent 7640749d68
commit edbc533414
11 changed files with 57 additions and 47 deletions

View file

@ -89,11 +89,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Size of player's main inventory
#define PLAYER_INVENTORY_SIZE (8 * 4)
// Maximum hit points of a player
// Default maximum hit points of a player
#define PLAYER_MAX_HP_DEFAULT 20
// Maximal breath of a player
#define PLAYER_MAX_BREATH 11
// Default maximal breath of a player
#define PLAYER_MAX_BREATH_DEFAULT 11
// Number of different files to try to save a player to if the first fails
// (because of a case-insensitive filesystem)

View file

@ -797,6 +797,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id
assert(m_peer_id != 0); // pre-condition
m_prop.hp_max = PLAYER_MAX_HP_DEFAULT;
m_prop.breath_max = PLAYER_MAX_BREATH_DEFAULT;
m_prop.physical = false;
m_prop.weight = 75;
m_prop.collisionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f);
@ -817,6 +818,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id
m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS;
m_prop.can_zoom = true;
m_hp = m_prop.hp_max;
m_breath = m_prop.breath_max;
}
PlayerSAO::~PlayerSAO()
@ -943,7 +945,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
MapNode n = m_env->getMap().getNodeNoEx(p);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
// If player is alive & no drowning, breath
if (m_hp > 0 && m_breath < PLAYER_MAX_BREATH && c.drowning == 0)
if (m_hp > 0 && m_breath < m_prop.breath_max && c.drowning == 0)
setBreath(m_breath + 1);
}
@ -1274,7 +1276,7 @@ void PlayerSAO::setBreath(const u16 breath, bool send)
if (m_player && breath != m_breath)
m_player->setDirty(true);
m_breath = MYMIN(breath, PLAYER_MAX_BREATH);
m_breath = MYMIN(breath, m_prop.breath_max);
if (send)
m_env->getGameDef()->SendPlayerBreath(this);

View file

@ -397,7 +397,7 @@ private:
std::set<std::string> m_privs;
bool m_is_singleplayer;
u16 m_breath = PLAYER_MAX_BREATH;
u16 m_breath = PLAYER_MAX_BREATH_DEFAULT;
f32 m_pitch = 0.0f;
f32 m_fov = 0.0f;
s16 m_wanted_range = 0.0f;

View file

@ -173,7 +173,7 @@ private:
// ***** End of variables for temporary option *****
bool m_can_jump = false;
u16 m_breath = PLAYER_MAX_BREATH;
u16 m_breath = PLAYER_MAX_BREATH_DEFAULT;
f32 m_yaw = 0.0f;
f32 m_pitch = 0.0f;
bool camera_barely_in_ceiling = false;

View file

@ -34,6 +34,7 @@ std::string ObjectProperties::dump()
{
std::ostringstream os(std::ios::binary);
os << "hp_max=" << hp_max;
os << ", breath_max=" << breath_max;
os << ", physical=" << physical;
os << ", collideWithObjects=" << collideWithObjects;
os << ", weight=" << weight;
@ -108,6 +109,7 @@ void ObjectProperties::serialize(std::ostream &os) const
os << serializeString(wield_item);
writeU8(os, can_zoom);
writeS8(os, glow);
writeU16(os, breath_max);
// Add stuff only at the bottom.
// Never remove anything, because we don't want new versions of this
@ -155,5 +157,9 @@ void ObjectProperties::deSerialize(std::istream &is)
infotext = deSerializeString(is);
wield_item = deSerializeString(is);
can_zoom = readU8(is);
glow = readS8(is);
try {
glow = readS8(is);
breath_max = readU16(is);
} catch (SerializationError &e) {}
}

View file

@ -27,11 +27,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct ObjectProperties
{
// Values are BS=1
s16 hp_max = 1;
u16 breath_max = 0;
bool physical = false;
bool collideWithObjects = true;
float weight = 5.0f;
// Values are BS=1
aabb3f collisionbox = aabb3f(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f);
aabb3f selectionbox = aabb3f(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f);
bool pointable = true;

View file

@ -193,6 +193,7 @@ void read_object_properties(lua_State *L, int index,
if (getintfield(L, -1, "hp_max", hp_max))
prop->hp_max = (s16)rangelim(hp_max, 0, S16_MAX);
getintfield(L, -1, "breath_max", prop->breath_max);
getboolfield(L, -1, "physical", prop->physical);
getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects);
@ -306,6 +307,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
lua_newtable(L);
lua_pushnumber(L, prop->hp_max);
lua_setfield(L, -2, "hp_max");
lua_pushnumber(L, prop->breath_max);
lua_setfield(L, -2, "breath_max");
lua_pushboolean(L, prop->physical);
lua_setfield(L, -2, "physical");
lua_pushboolean(L, prop->collideWithObjects);

View file

@ -2542,7 +2542,7 @@ void Server::RespawnPlayer(u16 peer_id)
<< " respawns" << std::endl;
playersao->setHP(playersao->accessObjectProperties()->hp_max);
playersao->setBreath(PLAYER_MAX_BREATH);
playersao->setBreath(playersao->accessObjectProperties()->breath_max);
bool repositioned = m_script->on_respawnplayer(playersao);
if (!repositioned) {