Skip to content

Commit

Permalink
better hunger messages for insects and demons
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Jan 18, 2025
1 parent 18a1e19 commit 9f4ee6e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
12 changes: 12 additions & 0 deletions res/core/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,18 @@
<arg name="region" type="region"/>
</type>
</message>
<message name="malnourish_insect" section="events">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
</type>
</message>
<message name="malnourish_demon" section="events">
<type>
<arg name="unit" type="unit"/>
<arg name="region" type="region"/>
</type>
</message>
<message name="starvation" section="events">
<type>
<arg name="unit" type="unit"/>
Expand Down
6 changes: 6 additions & 0 deletions res/translations/messages.de.po
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,12 @@ msgstr "\"$unit($unit) in $region($region) bläst das Horn des Tanzes, doch niem
msgid "malnourish"
msgstr "\"$unit($unit) in $region($region) wird durch unzureichende Nahrung geschwächt.\""

msgid "malnourish_demon"
msgstr "\"$unit($unit) in $region($region) wird durch unzureichende Opfer geschwächt.\""

msgid "malnourish_insect"
msgstr "\"$unit($unit) wird durch die extreme Kälte in $region($region) geschwächt.\""

msgid "iceberg_land"
msgstr "\"Der Eisberg $region($region) treibt an eine Küste.\""

Expand Down
8 changes: 7 additions & 1 deletion res/translations/messages.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,13 @@ msgid "hornofpeace_r_nosuccess"
msgstr "\"$unit($unit) in $region($region) blows the Horn of Dancing, but nobody here gets into the mood.\""

msgid "malnourish"
msgstr "\"$unit($unit) is weakened due to malnourishment.\""
msgstr "\"$unit($unit) in $region($region) is weakened due to malnourishment.\""

msgid "malnourish_demon"
msgstr "\"$unit($unit) is weakened due to lack of victims in $region($region).\""

msgid "malnourish_insect"
msgstr "\"$unit($unit) is weakened due to the cold in $region($region).\""

msgid "iceberg_land"
msgstr "\"The iceberg $region($region) drifts onto a coast.\""
Expand Down
31 changes: 30 additions & 1 deletion src/laws.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,35 @@ static void test_demon_hunger(CuTest * tc)
get_food(r);

CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "malnourish"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "malnourish_demon"));

test_teardown();
}

static void test_insect_hunger(CuTest * tc)
{
const resource_type *rtype;
region *r;
race *rc;
faction *f;
unit *u;

test_setup();
config_set("hunger.damage", NULL);
init_resources();
r = test_create_region(0, 0, test_create_terrain("glacier", LAND_REGION | ARCTIC_REGION));
rc = test_create_race("insect");
f = test_create_faction_ex(rc, NULL);
u = test_create_unit(f, r);
u->hp = 999;

rtype = get_resourcetype(R_SILVER);
i_change(&u->items, rtype->itype, 20);

get_food(r);

CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "malnourish_insect"));

test_teardown();
}
Expand Down Expand Up @@ -3016,6 +3044,7 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_repopulate_income_based);
SUITE_ADD_TEST(suite, test_repopulate_blocked);
SUITE_ADD_TEST(suite, test_demon_hunger);
SUITE_ADD_TEST(suite, test_insect_hunger);
SUITE_ADD_TEST(suite, test_armedmen);
SUITE_ADD_TEST(suite, test_cansee);
SUITE_ADD_TEST(suite, test_cansee_ring);
Expand Down
10 changes: 5 additions & 5 deletions src/upkeep.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static const char *hunger_damage(const race *rc) {
return damage;
}

static bool hunger(int number, unit * u)
static bool hunger(int number, unit * u, const char *reason)
{
region *r = u->region;
int dead = 0, hpsub = 0;
Expand Down Expand Up @@ -105,7 +105,7 @@ static bool hunger(int number, unit * u)
/* Meldung nur, wenn noch keine fuer Tote generiert. */
if (dead == 0) {
/* Durch unzureichende Ernaehrung wird %s geschwaecht */
ADDMSG(&u->faction->msgs, msg_message("malnourish", "unit region", u, r));
ADDMSG(&u->faction->msgs, msg_message(reason, "unit region", u, r));
}
}
return (dead || hpsub);
Expand Down Expand Up @@ -234,7 +234,7 @@ void get_food(region * r)
int lspp = lifestyle(u) / u->number;
if (lspp > 0) {
int number = (need + lspp - 1) / lspp;
if (hunger(number, u))
if (hunger(number, u, "malnourish"))
fset(u, UFL_HUNGER);
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ void get_food(region * r)
if (hungry > 0) {
if (demon_hunger) {
/* demons who don't feed are hungry */
if (hunger(hungry, u))
if (hunger(hungry, u, "malnourish_demon"))
fset(u, UFL_HUNGER);
}
else {
Expand All @@ -301,7 +301,7 @@ void get_food(region * r)
else if (is_cold && rc == rc_insect) {
/* insects in glaciers get hunger damage */
if (!is_cursed(u->attribs, &ct_insectfur)) {
if (hunger(u->number, u)) {
if (hunger(u->number, u, "malnourish_insect")) {
fset(u, UFL_HUNGER);
}
}
Expand Down

0 comments on commit 9f4ee6e

Please sign in to comment.