diff options
author | Wuzzy <wuzzy2@mail.ru> | 2021-04-11 15:09:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-11 17:09:37 +0200 |
commit | 4b8209d9a44425156ba89a4763f63ea088daccb3 (patch) | |
tree | 62c0553a778b53b7a36535adc3ac2b8145b3ca69 /src | |
parent | 0abc1e98edb87b2e23eecccfd6b1393ac7fb4f56 (diff) | |
download | minetest-4b8209d9a44425156ba89a4763f63ea088daccb3.tar.gz minetest-4b8209d9a44425156ba89a4763f63ea088daccb3.tar.bz2 minetest-4b8209d9a44425156ba89a4763f63ea088daccb3.zip |
Modifying fall damage via armor group (#11080)
Adds a new fall_damage_add_percent armor group which influences the fall damage in addition to the existing node group.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/clientenvironment.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index fc7cbe254..1bdf5390d 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -235,7 +235,16 @@ void ClientEnvironment::step(float dtime) &player_collisions); } - bool player_immortal = lplayer->getCAO() && lplayer->getCAO()->isImmortal(); + bool player_immortal = false; + f32 player_fall_factor = 1.0f; + GenericCAO *playercao = lplayer->getCAO(); + if (playercao) { + player_immortal = playercao->isImmortal(); + int addp_p = itemgroup_get(playercao->getGroups(), + "fall_damage_add_percent"); + // convert armor group into an usable fall damage factor + player_fall_factor = 1.0f + (float)addp_p / 100.0f; + } for (const CollisionInfo &info : player_collisions) { v3f speed_diff = info.new_speed - info.old_speed;; @@ -248,17 +257,20 @@ void ClientEnvironment::step(float dtime) speed_diff.Z = 0; f32 pre_factor = 1; // 1 hp per node/s f32 tolerance = BS*14; // 5 without damage - f32 post_factor = 1; // 1 hp per node/s if (info.type == COLLISION_NODE) { const ContentFeatures &f = m_client->ndef()-> get(m_map->getNode(info.node_p)); - // Determine fall damage multiplier - int addp = itemgroup_get(f.groups, "fall_damage_add_percent"); - pre_factor = 1.0f + (float)addp / 100.0f; + // Determine fall damage modifier + int addp_n = itemgroup_get(f.groups, "fall_damage_add_percent"); + // convert node group to an usable fall damage factor + f32 node_fall_factor = 1.0f + (float)addp_n / 100.0f; + // combine both player fall damage modifiers + pre_factor = node_fall_factor * player_fall_factor; } float speed = pre_factor * speed_diff.getLength(); - if (speed > tolerance && !player_immortal) { - f32 damage_f = (speed - tolerance) / BS * post_factor; + + if (speed > tolerance && !player_immortal && pre_factor > 0.0f) { + f32 damage_f = (speed - tolerance) / BS; u16 damage = (u16)MYMIN(damage_f + 0.5, U16_MAX); if (damage != 0) { damageLocalPlayer(damage, true); |