diff --git a/conf/e3/config.json b/conf/e3/config.json index 8d575340c..a1fc05b74 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -42,9 +42,9 @@ "nmr.removenewbie": 0, "GiveRestriction": 3, "hunger.long": false, - "hunger.demon.skill": true, "hunger.damage": "1d9+9", - "hunger.demons": true, + "hunger.demons.skill": true, + "hunger.demons.peasant_tolerance": true, "init_spells": 0, "recruit.allow_merge": true, "study.expensivemigrants": true, diff --git a/conf/e4/config.json b/conf/e4/config.json index e23eee261..12da61937 100644 --- a/conf/e4/config.json +++ b/conf/e4/config.json @@ -42,9 +42,9 @@ "nmr.removenewbie": 0, "GiveRestriction": 3, "hunger.long": false, - "hunger.demon.skill": true, "hunger.damage": "1d9+9", - "hunger.demons": true, + "hunger.demons.skill": true, + "hunger.demons.peasant_tolerance": true, "init_spells": 0, "recruit.allow_merge": true, "study.expensivemigrants": true, diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index 49c0416a8..446a7cf6d 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -674,7 +674,7 @@ function test_laen2() process_orders() init_reports() - write_report(u1.faction) +-- write_report(u1.faction) assert_equal(laen - 2, r:get_resource("laen")) assert_equal(2, u1:get_item("laen")) end @@ -985,13 +985,21 @@ local function find_in_report(f, pattern, extension) return start~=nil end +local function remove_report(faction) + local filetrunk = config.reportpath .. "/" .. get_turn() .. "-" .. itoa36(faction.id) + os.remove(filetrunk .. ".nr") + os.remove(filetrunk .. ".cr") + os.remove(filetrunk .. ".txt") +end + function test_coordinates_no_plane() local r = region.create(0, 0, "mountain") - local f = faction.create("noreply@eressea.de", "human", "de") + local f = faction.create("noplane@eressea.de", "human", "de") local u = unit.create(f, r, 1) init_reports() write_report(f) assert_true(find_in_report(f, r.name .. " %(0,0%), Berg")) + remove_report(f) end function test_show_shadowmaster_attacks() @@ -1005,6 +1013,7 @@ function test_show_shadowmaster_attacks() init_reports() write_report(f) assert_false(find_in_report(f, ", ,")) + remove_report(f) end function test_coordinates_named_plane() @@ -1015,6 +1024,7 @@ function test_coordinates_named_plane() init_reports() write_report(f) assert_true(find_in_report(f, r.name .. " %(0,0,Hell%), Berg")) + remove_report(f) end function test_coordinates_unnamed_plane() @@ -1025,6 +1035,7 @@ function test_coordinates_unnamed_plane() init_reports() write_report(f) assert_true(find_in_report(f, r.name .. " %(0,0%), Berg")) + remove_report(f) end function test_coordinates_noname_plane() @@ -1035,6 +1046,7 @@ function test_coordinates_noname_plane() init_reports() write_report(f) assert_true(find_in_report(f, r.name .. " %(0,0%), Berg")) + remove_report(f) end function test_lighthouse() @@ -1064,6 +1076,7 @@ function test_lighthouse() assert_false(find_in_report(f, " %(0,0%) %(vom Turm erblickt%)")) assert_false(find_in_report(f, " %(0,1%) %(vom Turm erblickt%)")) assert_false(find_in_report(f, " %(4,0%) %(vom Turm erblickt%)")) + remove_report(f) end module("tests.parser", package.seeall, lunit.testcase) diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index a4ee0ea3f..323103e73 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -965,3 +965,24 @@ function test_no_uruk() local f1 = faction.create("noreply@eressea.de", "uruk", "de") assert_equal(f1.race, "orc") end + +function test_bug2187() + set_rule("rules.food.flags", "0") + + local r = region.create(0,0,"plain") + local f = faction.create("2187@eressea.de", "goblin", "de") + local u = unit.create(f, r, 1) + u.race = "demon" + u.hp = u.hp_max * u.number + + r:set_resource("peasant", 0) + u:add_item("money", 500) + + hp = u.hp + process_orders() + assert_equal(hp, u.hp) +-- init_reports() +-- write_report(f) + + set_rule("rules.food.flags", "4") +end \ No newline at end of file diff --git a/src/laws.test.c b/src/laws.test.c index 5be4c7143..64f65663c 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1299,6 +1299,46 @@ static void test_immigration(CuTest * tc) test_cleanup(); } +static void test_demon_hunger(CuTest * tc) +{ + const resource_type *rtype; + region *r; + race *rc; + faction *f; + unit *u; + message* msg; + + test_cleanup(); + test_create_world(); + r = findregion(0, 0); + rc = test_create_race("demon"); + f = test_create_faction(rc); + u = test_create_unit(f, r); + u->hp = 999; + + config_set("hunger.demons.peasant_tolerance", "1"); + + rtype = get_resourcetype(R_SILVER); + i_change(&u->items, rtype->itype, 30); + scale_number(u, 1); + rsetpeasants(r, 0); + + get_food(r); + + CuAssertIntEquals(tc, 20, i_get(u->items, rtype->itype)); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "malnourish")); + + config_set("hunger.demons.peasant_tolerance", "0"); + + get_food(r); + + CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype)); + msg = test_get_last_message(u->faction->msgs); + CuAssertStrEquals(tc, "malnourish", test_get_messagetype(msg)); + + test_cleanup(); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -1358,6 +1398,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_name_ship); SUITE_ADD_TEST(suite, test_show_without_item); SUITE_ADD_TEST(suite, test_immigration); + SUITE_ADD_TEST(suite, test_demon_hunger); return suite; } diff --git a/src/randenc.c b/src/randenc.c index d948ea270..ae533f9ea 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -963,7 +963,7 @@ static void demon_skillchanges(void) if (fval(u, UFL_HUNGER)) { /* hungry demons only go down, never up in skill */ - int rule_hunger = config_get_int("hunger.demon.skill", 0) != 0; + int rule_hunger = config_get_int("hunger.demons.skill", 0) != 0; if (rule_hunger) { upchance = 0; downchance = 15; diff --git a/src/upkeep.c b/src/upkeep.c index 193c68480..5d114c74e 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -271,7 +271,7 @@ void get_food(region * r) peasantfood = 0; } if (hungry > 0) { - bool demon_hunger = config_get_int("hunger.demons", 0) != 0; + bool demon_hunger = config_get_int("hunger.demons.peasant_tolerance", 0) == 0; if (demon_hunger) { /* demons who don't feed are hungry */ if (hunger(hungry, u))