+
+
+
+extern void try_healing(struct Thing * t)
+{
+ struct ThingType * tt = get_thing_type(t->type);
+ if ( t->satiation > 0 && t->lifepoints < tt->lifepoints
+ && 0 == (rrand() % 31)
+ && get_thing_action_id_by_name(s[S_CMD_WAIT]) == t->command)
+ {
+ t->lifepoints++;
+ t->satiation = t->satiation - 32;
+ if (get_player() == t)
+ {
+ update_log("You heal.");
+ }
+ else
+ {
+ char * msg_part = " heals.";
+ uint8_t len = strlen(tt->name) + strlen(msg_part) + 1;
+ char * msg = try_malloc(len, __func__);
+ int test = sprintf(msg, "%s%s", tt->name, msg_part);
+ exit_trouble(test < 0, __func__, s[S_FCN_SPRINTF]);
+ update_log(msg);
+ free(msg);
+ }
+ }
+}
+
+
+
+extern void hunger(struct Thing * t)
+{
+ if (t->satiation > INT16_MIN)
+ {
+ t->satiation--;
+ }
+ struct ThingType * tt = get_thing_type(t->type);
+ uint16_t testbase = t->satiation < 0 ? -(t->satiation) : t->satiation;
+ exit_err(!(tt->lifepoints), "A thing that should not hunger is hungering.");
+ uint16_t endurance = INT16_MAX / tt->lifepoints;
+ if ((testbase / endurance) / ((rrand() % endurance) + 1))
+ {
+ if (get_player() == t)
+ {
+ update_log("You suffer from hunger.");
+ }
+ else
+ {
+ char * msg_part = " suffers from hunger.";
+ uint8_t len = strlen(tt->name) + strlen(msg_part) + 1;
+ char * msg = try_malloc(len, __func__);
+ int test = sprintf(msg, "%s%s", tt->name, msg_part);
+ exit_trouble(test < 0, __func__, s[S_FCN_SPRINTF]);
+ update_log(msg);
+ free(msg);
+ }
+ decrement_lifepoints(t);
+ }
+}