Skip to content

Commit 4b8209d

Browse files
authoredApr 11, 2021
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.
1 parent 0abc1e9 commit 4b8209d

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed
 

Diff for: ‎doc/lua_api.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,15 @@ to games.
17301730
* `3`: the node always gets the digging time 0 seconds (torch)
17311731
* `disable_jump`: Player (and possibly other things) cannot jump from node
17321732
or if their feet are in the node. Note: not supported for `new_move = false`
1733-
* `fall_damage_add_percent`: damage speed = `speed * (1 + value/100)`
1733+
* `fall_damage_add_percent`: modifies the fall damage suffered when hitting
1734+
the top of this node. There's also an armor group with the same name.
1735+
The final player damage is determined by the following formula:
1736+
damage =
1737+
collision speed
1738+
* ((node_fall_damage_add_percent + 100) / 100) -- node group
1739+
* ((player_fall_damage_add_percent + 100) / 100) -- player armor group
1740+
- (14) -- constant tolerance
1741+
Negative damage values are discarded as no damage.
17341742
* `falling_node`: if there is no walkable block under the node it will fall
17351743
* `float`: the node will not fall through liquids
17361744
* `level`: Can be used to give an additional sense of progression in the game.
@@ -1750,12 +1758,15 @@ to games.
17501758
`"toolrepair"` crafting recipe
17511759

17521760

1753-
### `ObjectRef` groups
1761+
### `ObjectRef` armor groups
17541762

17551763
* `immortal`: Skips all damage and breath handling for an object. This group
17561764
will also hide the integrated HUD status bars for players. It is
17571765
automatically set to all players when damage is disabled on the server and
17581766
cannot be reset (subject to change).
1767+
* `fall_damage_add_percent`: Modifies the fall damage suffered by players
1768+
when they hit the ground. It is analog to the node group with the same
1769+
name. See the node group above for the exact calculation.
17591770
* `punch_operable`: For entities; disables the regular damage mechanism for
17601771
players punching it by hand or a non-tool item, so that it can do something
17611772
else than take damage.

Diff for: ‎src/client/clientenvironment.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,16 @@ void ClientEnvironment::step(float dtime)
235235
&player_collisions);
236236
}
237237

238-
bool player_immortal = lplayer->getCAO() && lplayer->getCAO()->isImmortal();
238+
bool player_immortal = false;
239+
f32 player_fall_factor = 1.0f;
240+
GenericCAO *playercao = lplayer->getCAO();
241+
if (playercao) {
242+
player_immortal = playercao->isImmortal();
243+
int addp_p = itemgroup_get(playercao->getGroups(),
244+
"fall_damage_add_percent");
245+
// convert armor group into an usable fall damage factor
246+
player_fall_factor = 1.0f + (float)addp_p / 100.0f;
247+
}
239248

240249
for (const CollisionInfo &info : player_collisions) {
241250
v3f speed_diff = info.new_speed - info.old_speed;;
@@ -248,17 +257,20 @@ void ClientEnvironment::step(float dtime)
248257
speed_diff.Z = 0;
249258
f32 pre_factor = 1; // 1 hp per node/s
250259
f32 tolerance = BS*14; // 5 without damage
251-
f32 post_factor = 1; // 1 hp per node/s
252260
if (info.type == COLLISION_NODE) {
253261
const ContentFeatures &f = m_client->ndef()->
254262
get(m_map->getNode(info.node_p));
255-
// Determine fall damage multiplier
256-
int addp = itemgroup_get(f.groups, "fall_damage_add_percent");
257-
pre_factor = 1.0f + (float)addp / 100.0f;
263+
// Determine fall damage modifier
264+
int addp_n = itemgroup_get(f.groups, "fall_damage_add_percent");
265+
// convert node group to an usable fall damage factor
266+
f32 node_fall_factor = 1.0f + (float)addp_n / 100.0f;
267+
// combine both player fall damage modifiers
268+
pre_factor = node_fall_factor * player_fall_factor;
258269
}
259270
float speed = pre_factor * speed_diff.getLength();
260-
if (speed > tolerance && !player_immortal) {
261-
f32 damage_f = (speed - tolerance) / BS * post_factor;
271+
272+
if (speed > tolerance && !player_immortal && pre_factor > 0.0f) {
273+
f32 damage_f = (speed - tolerance) / BS;
262274
u16 damage = (u16)MYMIN(damage_f + 0.5, U16_MAX);
263275
if (damage != 0) {
264276
damageLocalPlayer(damage, true);

0 commit comments

Comments
 (0)
Please sign in to comment.