X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fserver%2Fthing_actions.c;h=2a682c277356f0e4deae6b8bef0ba08a5f936ab3;hb=109dc4e8a5d9f09541ef2dcb84bd6b6ac2e2fb00;hp=a5c78ba55027a10cb094bfaffebe43ffc8356a47;hpb=8d5a9e9d57cf004d04cb9916141797b9c3a6aae6;p=plomrogue diff --git a/src/server/thing_actions.c b/src/server/thing_actions.c index a5c78ba..2a682c2 100644 --- a/src/server/thing_actions.c +++ b/src/server/thing_actions.c @@ -7,11 +7,11 @@ #include "thing_actions.h" #include /* NULL */ -#include /* uint8_t, INT16_MIN */ +#include /* uint8_t, INT16_MIN, INT16_MAX */ #include /* sprintf() */ #include /* free() */ #include /* strlen() */ -#include "../common/rexit.h" /* exit_trouble() */ +#include "../common/rexit.h" /* exit_err(), exit_trouble() */ #include "../common/try_malloc.h" /* try_malloc() */ #include "../common/yx_uint8.h" /* yx_uint8 */ #include "field_of_view.h" /* build_fov_map() */ @@ -330,19 +330,44 @@ extern void actor_use(struct Thing * t) -extern void hunger(struct Thing * t) +extern void try_healing(struct Thing * t) { struct ThingType * tt = get_thing_type(t->type); - if (!(tt->stomach)) + if ( t->satiation > 0 && t->lifepoints < tt->lifepoints + && 0 == (rrand() % 31) + && get_thing_action_id_by_name(s[S_CMD_WAIT]) == t->command) { - return; + 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; - uint16_t endurance = tt->stomach; + 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)