From 59bfee991090658d963e9b75e5184f97f407b395 Mon Sep 17 00:00:00 2001 From: walter253 <130906143+walt253@users.noreply.github.com> Date: Wed, 28 Feb 2024 23:44:10 +0100 Subject: [PATCH] Disable HungerHealthLoss if rule is set to 0, instead of crashing (#3018) --- src/creature_states.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/creature_states.c b/src/creature_states.c index cef956f43e..6061369167 100644 --- a/src/creature_states.c +++ b/src/creature_states.c @@ -4071,11 +4071,15 @@ TbBool process_creature_hunger(struct Thing *thing) cctrl->hunger_level++; if (!hunger_is_creature_hungry(thing)) return false; - // Make sure every creature loses health on different turn - if (((game.play_gameturn + thing->index) % game.conf.rules.health.turns_per_hunger_health_loss) == 0) { - SYNCDBG(9,"The %s index %d lost %d health due to hunger",thing_model_name(thing), (int)thing->index, (int)game.conf.rules.health.hunger_health_loss); - remove_health_from_thing_and_display_health(thing, game.conf.rules.health.hunger_health_loss); - return true; + // HungerHealthLoss is disabled if set to 0 on rules.cfg. + if (game.conf.rules.health.turns_per_hunger_health_loss > 0) + { + // Make sure every creature loses health on different turn. + if (((game.play_gameturn + thing->index) % game.conf.rules.health.turns_per_hunger_health_loss) == 0) { + SYNCDBG(9,"The %s index %d lost %d health due to hunger",thing_model_name(thing), (int)thing->index, (int)game.conf.rules.health.hunger_health_loss); + remove_health_from_thing_and_display_health(thing, game.conf.rules.health.hunger_health_loss); + return true; + } } return false; }