From 86e1bf18264555c814864beeb03da41542b5471b Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 17 Jan 2024 15:59:01 +0100 Subject: [PATCH] Add per-node climb speed modifier --- doc/lua_api.md | 7 ++++ games/devtest/mods/testnodes/properties.lua | 41 ++++++++++++++++++++- src/client/localplayer.cpp | 11 ++++-- src/client/localplayer.h | 1 + src/nodedef.cpp | 9 ++++- src/nodedef.h | 2 + src/script/common/c_content.cpp | 4 ++ 7 files changed, 68 insertions(+), 7 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index fde2e726f4a90..72b108be0c22f 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9381,6 +9381,13 @@ Used by `minetest.register_node`. -- (see `liquid_move_physics`), the movement speed will also be -- affected by the `movement_liquid_*` settings. + climb_factor = 1.0, + -- The speed at which a climbable node can be climbed is multiplied + -- with this number. Must not be negative. No effect if node isn't + -- climbable. + -- Note: To set the base climbing speed in your game, + -- change the setting "movement_speed_climb". + buildable_to = false, -- If true, placed nodes can replace this node floodable = false, diff --git a/games/devtest/mods/testnodes/properties.lua b/games/devtest/mods/testnodes/properties.lua index a688d3814d869..e5817b812eaa2 100644 --- a/games/devtest/mods/testnodes/properties.lua +++ b/games/devtest/mods/testnodes/properties.lua @@ -209,6 +209,41 @@ minetest.register_node("testnodes:climbable", { groups = {dig_immediate=3}, }) +minetest.register_node("testnodes:climbable_fast", { + description = S("Fast Climbable Node").."\n".. + S("You can climb up and down, faster than usual"), + climbable = true, + climb_factor = 2.0, + walkable = false, + + + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + tiles = {"testnodes_climbable_top.png^[colorize:#FFFFFF:140","testnodes_climbable_top.png^[colorize:#FFFFFF:140","testnodes_climbable_side.png^[colorize:#FFFFFF:140"}, + use_texture_alpha = "clip", + drawtype = "nodebox", + node_box = climbable_nodebox, + groups = {dig_immediate=3}, +}) +minetest.register_node("testnodes:climbable_slow", { + description = S("Slow Climbable Node").."\n".. + S("You can climb up and down, slower than usual"), + climbable = true, + climb_factor = 0.5, + walkable = false, + + + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + tiles = {"testnodes_climbable_top.png^[colorize:#000000:140","testnodes_climbable_top.png^[colorize:#000000:140","testnodes_climbable_side.png^[colorize:#000000:140"}, + use_texture_alpha = "clip", + drawtype = "nodebox", + node_box = climbable_nodebox, + groups = {dig_immediate=3}, +}) + -- Climbable only downwards with sneak key minetest.register_node("testnodes:climbable_nojump", { description = S("Downwards-climbable Node").."\n".. @@ -227,7 +262,8 @@ minetest.register_node("testnodes:climbable_nojump", { minetest.register_node("testnodes:climbable_nodescend", { - description = S("Upwards-climbable Node"), + description = S("Upwards-climbable Node").."\n".. + S("You can climb only upwards"), climbable = true, walkable = false, @@ -241,7 +277,8 @@ minetest.register_node("testnodes:climbable_nodescend", { }) minetest.register_node("testnodes:climbable_nodescend_nojump", { - description = S("Horizontal-only Climbable Node"), + description = S("Horizontal-only Climbable Node").."\n".. + S("You hold on to this node but can't climb vertically"), climbable = true, walkable = false, diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index da87e9b171767..c10822bb6137c 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -336,6 +336,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, } else { is_climbing = (nodemgr->get(node.getContent()).climbable || nodemgr->get(node2.getContent()).climbable) && !free_move; + if (is_climbing) { + node_climb_factor = nodemgr->get(node.getContent()).climb_factor; + } } /* @@ -613,7 +616,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env) speedV.Y = -speed_walk; swimming_vertical = true; } else if (is_climbing && !m_disable_descend) { - speedV.Y = -movement_speed_climb * physics_override.speed_climb; + speedV.Y = -movement_speed_climb * physics_override.speed_climb * node_climb_factor; } else { // If not free movement but fast is allowed, aux1 is // "Turbo button" @@ -649,9 +652,9 @@ void LocalPlayer::applyControl(float dtime, Environment *env) swimming_vertical = true; } else if (is_climbing && !m_disable_descend) { if (fast_climb) - speedV.Y = -speed_fast; + speedV.Y = -speed_fast * node_climb_factor; else - speedV.Y = -movement_speed_climb * physics_override.speed_climb; + speedV.Y = -movement_speed_climb * physics_override.speed_climb * node_climb_factor; } } } @@ -704,7 +707,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env) if (fast_climb) speedV.Y = speed_fast; else - speedV.Y = movement_speed_climb * physics_override.speed_climb; + speedV.Y = movement_speed_climb * physics_override.speed_climb * node_climb_factor; } } diff --git a/src/client/localplayer.h b/src/client/localplayer.h index fbccb159152cd..4fa805ecd2f62 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -77,6 +77,7 @@ class LocalPlayer : public Player // Slows down the player when moving through u8 move_resistance = 0; bool is_climbing = false; + f32 node_climb_factor = 1.0f; bool swimming_vertical = false; bool swimming_pitch = false; diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 2914cc3aa9bc3..e0ebe7ba5b26b 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -426,6 +426,7 @@ void ContentFeatures::reset() move_resistance = 0; liquid_move_physics = false; post_effect_color_shaded = false; + climb_factor = 1.0; } void ContentFeatures::setAlphaFromLegacy(u8 legacy_alpha) @@ -553,6 +554,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const writeU8(os, move_resistance); writeU8(os, liquid_move_physics); writeU8(os, post_effect_color_shaded); + writeF32(os, climb_factor); } void ContentFeatures::deSerialize(std::istream &is, u16 protocol_version) @@ -683,7 +685,12 @@ void ContentFeatures::deSerialize(std::istream &is, u16 protocol_version) if (is.eof()) throw SerializationError(""); post_effect_color_shaded = tmp; - } catch (SerializationError &e) {}; + + f32 ftmp = readF32(is); + if (is.eof()) + throw SerializationError(""); + climb_factor = ftmp; + } catch(SerializationError &e) {}; } #ifndef SERVER diff --git a/src/nodedef.h b/src/nodedef.h index de713a1ad3a8e..974e059a1b4aa 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -402,6 +402,8 @@ struct ContentFeatures bool diggable; // Player can climb these bool climbable; + // Climb speed factor + f32 climb_factor; // Player can build on these bool buildable_to; // Player cannot build to these (placement prediction disabled) diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 988094b9f2325..2a23bbfbe1572 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -966,6 +966,8 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) errorstream << "Field \"liquid_move_physics\": Invalid type!" << std::endl; } lua_pop(L, 1); + + getfloatfield(L, index, "climb_factor", f.climb_factor); } void push_content_features(lua_State *L, const ContentFeatures &c) @@ -1099,6 +1101,8 @@ void push_content_features(lua_State *L, const ContentFeatures &c) lua_setfield(L, -2, "move_resistance"); lua_pushboolean(L, c.liquid_move_physics); lua_setfield(L, -2, "liquid_move_physics"); + lua_pushnumber(L, c.climb_factor); + lua_setfield(L, -2, "climb_factor"); } /******************************************************************************/