From e2f954b7f6e17eb227ada0fbca3f7c751655f2c1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Dec 2017 10:16:56 +0100 Subject: [PATCH 1/5] BUG 2392: anyone can use weapons, as long as they have _some_ skill. --- src/battle.c | 2 -- src/battle.test.c | 4 ++-- src/economy.test.c | 2 +- src/guard.test.c | 27 ++++++++++++++------------- src/kernel/item.c | 4 +--- src/kernel/item.h | 3 +-- src/kernel/xmlreader.c | 4 +--- src/laws.c | 3 +-- src/laws.test.c | 17 ++++++----------- src/spy.test.c | 2 +- 10 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/battle.c b/src/battle.c index 823fd89f1..bb269d119 100644 --- a/src/battle.c +++ b/src/battle.c @@ -640,8 +640,6 @@ weapon_skill(const weapon_type * wtype, const unit * u, bool attacking) if (!i_canuse(u, wtype->itype)) return -1; skill = effskill(u, wtype->skill, 0); - if (skill < wtype->minskill) - skill = 0; if (skill > 0) { if (attacking) { skill += u_race(u)->at_bonus; diff --git a/src/battle.test.c b/src/battle.test.c index 3669f25d1..901c3e108 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -268,7 +268,7 @@ static void test_calculate_armor(CuTest * tc) ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD); ichain = it_get_or_create(rt_get_or_create("chainmail")); achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE); - wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE, 1); + wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE); rc = test_create_race("human"); du = test_create_unit(test_create_faction(rc), r); dt.index = 0; @@ -409,7 +409,7 @@ static void test_projectile_armor(CuTest * tc) ashield = new_armortype(ishield, 0.0, v50p, 1, ATF_SHIELD); ichain = it_get_or_create(rt_get_or_create("chainmail")); achain = new_armortype(ichain, 0.0, v50p, 3, ATF_NONE); - wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE, 1); + wtype = new_weapontype(it_get_or_create(rt_get_or_create("sword")), 0, v50p, 0, 0, 0, 0, SK_MELEE); rc = test_create_race("human"); rc->battle_flags |= BF_EQUIPMENT; du = test_create_unit(test_create_faction(rc), r); diff --git a/src/economy.test.c b/src/economy.test.c index 437f59d79..ddb715af8 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -326,7 +326,7 @@ static void test_tax_cmd(CuTest *tc) { silver = get_resourcetype(R_SILVER)->itype; sword = test_create_itemtype("sword"); - new_weapontype(sword, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 1); + new_weapontype(sword, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); i_change(&u->items, sword, 1); set_level(u, SK_MELEE, 1); diff --git a/src/guard.test.c b/src/guard.test.c index 8302bcc9a..b9bb69dcf 100644 --- a/src/guard.test.c +++ b/src/guard.test.c @@ -44,14 +44,19 @@ static void test_guard_unskilled(CuTest * tc) test_setup(); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); r = test_create_region(0, 0, 0); u = test_create_unit(test_create_faction(0), r); ug = test_create_unit(test_create_faction(0), r); i_change(&ug->items, itype, 1); + + setguard(ug, true); + CuAssertPtrEquals(tc, NULL, is_guarded(r, u)); + set_level(ug, SK_MELEE, 1); setguard(ug, true); - CuAssertPtrEquals(tc, 0, is_guarded(r, u)); + CuAssertPtrEquals(tc, ug, is_guarded(r, u)); + test_cleanup(); } @@ -63,7 +68,7 @@ static void test_guard_armed(CuTest * tc) test_setup(); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); r = test_create_region(0, 0, 0); u = test_create_unit(test_create_faction(0), r); ug = test_create_unit(test_create_faction(0), r); @@ -82,18 +87,14 @@ static void test_is_guard(CuTest * tc) test_setup(); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); r = test_create_region(0, 0, 0); ug = test_create_unit(test_create_faction(0), r); i_change(&ug->items, itype, 1); - set_level(ug, SK_MELEE, 2); setguard(ug, true); - CuAssertIntEquals(tc, 1, armedmen(ug, false)); - CuAssertTrue(tc, is_guard(ug)); - set_level(ug, SK_MELEE, 1); CuAssertIntEquals(tc, 0, armedmen(ug, false)); CuAssertTrue(tc, !is_guard(ug)); - set_level(ug, SK_MELEE, 2); + set_level(ug, SK_MELEE, 1); CuAssertIntEquals(tc, 1, armedmen(ug, false)); CuAssertTrue(tc, is_guard(ug)); test_cleanup(); @@ -142,11 +143,11 @@ static void test_update_guard(CuTest * tc) t_ocean = test_create_terrain("ocean", SEA_REGION); t_plain = test_create_terrain("packice", ARCTIC_REGION); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); r = test_create_region(0, 0, t_plain); ug = test_create_unit(test_create_faction(0), r); i_change(&ug->items, itype, 1); - set_level(ug, SK_MELEE, 2); + set_level(ug, SK_MELEE, 1); setguard(ug, true); CuAssertIntEquals(tc, 1, armedmen(ug, false)); CuAssertTrue(tc, is_guard(ug)); @@ -169,11 +170,11 @@ static void test_guard_on(CuTest * tc) t_ocean = test_create_terrain("ocean", SEA_REGION); t_plain = test_create_terrain("plain", LAND_REGION); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); r = test_create_region(0, 0, t_plain); ug = test_create_unit(test_create_faction(0), r); i_change(&ug->items, itype, 1); - set_level(ug, SK_MELEE, 2); + set_level(ug, SK_MELEE, 1); ug->thisorder = create_order(K_GUARD, ug->faction->locale, NULL); setguard(ug, false); diff --git a/src/kernel/item.c b/src/kernel/item.c index a633d5463..ef6b9d22c 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -271,11 +271,10 @@ luxury_type *new_luxurytype(item_type * itype, int price) weapon_type *new_weapontype(item_type * itype, int wflags, variant magres, const char *damage[], int offmod, int defmod, - int reload, skill_t sk, int minskill) + int reload, skill_t sk) { weapon_type *wtype; - assert(minskill > 0); assert(itype && (!itype->rtype || !resource2weapon(itype->rtype))); wtype = calloc(sizeof(weapon_type), 1); @@ -287,7 +286,6 @@ weapon_type *new_weapontype(item_type * itype, wtype->flags |= wflags; wtype->itype = itype; wtype->magres = magres; - wtype->minskill = minskill; wtype->offmod = offmod; wtype->reload = reload; wtype->skill = sk; diff --git a/src/kernel/item.h b/src/kernel/item.h index 6477a4923..cc5991ed6 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -187,7 +187,6 @@ extern "C" { char *damage[2]; unsigned int flags; skill_t skill; - int minskill; int offmod; int defmod; variant magres; @@ -232,7 +231,7 @@ extern "C" { luxury_type *new_luxurytype(item_type * itype, int price); weapon_type *new_weapontype(item_type * itype, int wflags, variant magres, const char *damage[], int offmod, int defmod, int reload, - skill_t sk, int minskill); + skill_t sk); armor_type *new_armortype(item_type * itype, double penalty, variant magres, int prot, unsigned int flags); potion_type *new_potiontype(item_type * itype, int level); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index ace0a4cc6..649b61135 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -523,7 +523,6 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) xmlChar *propValue; int k; skill_t sk; - int minskill = xml_ivalue(node, "minskill", 1); int offmod = xml_ivalue(node, "offmod", 0); int defmod = xml_ivalue(node, "defmod", 0); int reload = xml_ivalue(node, "reload", 0); @@ -555,8 +554,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) xmlFree(propValue); wtype = - new_weapontype(itype, flags, magres, NULL, offmod, defmod, reload, sk, - minskill); + new_weapontype(itype, flags, magres, NULL, offmod, defmod, reload, sk); /* reading weapon/damage */ xpath->node = node; diff --git a/src/laws.c b/src/laws.c index 873dc470f..d12406048 100644 --- a/src/laws.c +++ b/src/laws.c @@ -3904,9 +3904,8 @@ int armedmen(const unit * u, bool siege_weapons) const weapon_type *wtype = resource2weapon(itm->type->rtype); if (wtype == NULL || (!siege_weapons && (wtype->flags & WTF_SIEGE))) continue; - if (effskill(u, wtype->skill, 0) >= wtype->minskill) + if (effskill(u, wtype->skill, 0) >= 1) n += itm->number; - /* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */ if (n >= u->number) break; } diff --git a/src/laws.test.c b/src/laws.test.c index b00361dbe..898ae4627 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -720,9 +720,9 @@ void setup_guard(guard_fixture *fix, bool armed) { if (armed) { item_type *itype; itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); i_change(&u->items, itype, 1); - set_level(u, SK_MELEE, 2); + set_level(u, SK_MELEE, 1); } fix->u = u; } @@ -786,11 +786,11 @@ static void test_monsters_can_guard(CuTest *tc) { test_cleanup(); } -static void test_low_skill_cannot_guard(CuTest *tc) { +static void test_unskilled_cannot_guard(CuTest *tc) { guard_fixture fix; setup_guard(&fix, true); - set_level(fix.u, SK_MELEE, 1); + set_level(fix.u, SK_MELEE, 0); CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); @@ -1638,7 +1638,7 @@ static void test_armedmen(CuTest *tc) { test_setup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); it_sword = test_create_itemtype("sword"); - wtype = new_weapontype(it_sword, 0, frac_make(1, 2), 0, 0, 0, 0, SK_MELEE, 1); + wtype = new_weapontype(it_sword, 0, frac_make(1, 2), 0, 0, 0, 0, SK_MELEE); CuAssertIntEquals(tc, 0, armedmen(u, false)); CuAssertIntEquals(tc, 0, armedmen(u, true)); set_level(u, SK_MELEE, 1); @@ -1655,11 +1655,6 @@ static void test_armedmen(CuTest *tc) { set_level(u, SK_MELEE, 1); i_change(&u->items, it_sword, -1); CuAssertIntEquals(tc, 1, armedmen(u, false)); - wtype->minskill = 2; - CuAssertIntEquals(tc, 0, armedmen(u, false)); - set_level(u, SK_MELEE, 2); - CuAssertIntEquals(tc, 1, armedmen(u, false)); - CuAssertIntEquals(tc, 1, armedmen(u, true)); wtype->flags |= WTF_SIEGE; CuAssertIntEquals(tc, 0, armedmen(u, false)); CuAssertIntEquals(tc, 1, armedmen(u, true)); @@ -1806,7 +1801,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_unarmed_races_can_guard); SUITE_ADD_TEST(suite, test_monsters_can_guard); SUITE_ADD_TEST(suite, test_fleeing_cannot_guard); - SUITE_ADD_TEST(suite, test_low_skill_cannot_guard); + SUITE_ADD_TEST(suite, test_unskilled_cannot_guard); SUITE_ADD_TEST(suite, test_reserve_self); SUITE_ADD_TEST(suite, test_reserve_cmd); SUITE_ADD_TEST(suite, test_pay_cmd); diff --git a/src/spy.test.c b/src/spy.test.c index 11c8c1ff1..64ca60541 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -64,7 +64,7 @@ static void test_all_spy_message(CuTest *tc) { set_factionstealth(fix.victim, fix.spy->faction); itype = it_get_or_create(rt_get_or_create("sword")); - new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); + new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE); i_change(&fix.victim->items, itype, 1); spy_message(99, fix.spy, fix.victim); From 714e44cd71ad6e7d15e8046e2d85a99ff1fd67f5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Dec 2017 10:19:07 +0100 Subject: [PATCH 2/5] BUG 2392: remove minskill attribute from any weapons. --- res/core/weapons/firesword.xml | 2 +- res/core/weapons/mallornlance.xml | 2 +- res/core/weapons/mallornspear.xml | 2 +- res/core/weapons/runesword.xml | 2 +- res/e3a/weapons/mallornlance.xml | 2 +- scripts/tests/e3/rules.lua | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/res/core/weapons/firesword.xml b/res/core/weapons/firesword.xml index 9e8284fe6..d716e6013 100644 --- a/res/core/weapons/firesword.xml +++ b/res/core/weapons/firesword.xml @@ -1,7 +1,7 @@ - + diff --git a/res/core/weapons/mallornlance.xml b/res/core/weapons/mallornlance.xml index c67390d52..4024d4578 100644 --- a/res/core/weapons/mallornlance.xml +++ b/res/core/weapons/mallornlance.xml @@ -4,7 +4,7 @@ - + diff --git a/res/core/weapons/mallornspear.xml b/res/core/weapons/mallornspear.xml index 66d41a943..516f59540 100644 --- a/res/core/weapons/mallornspear.xml +++ b/res/core/weapons/mallornspear.xml @@ -4,7 +4,7 @@ - + diff --git a/res/core/weapons/runesword.xml b/res/core/weapons/runesword.xml index 566fe1589..1bfae2544 100644 --- a/res/core/weapons/runesword.xml +++ b/res/core/weapons/runesword.xml @@ -1,7 +1,7 @@ - + diff --git a/res/e3a/weapons/mallornlance.xml b/res/e3a/weapons/mallornlance.xml index 8eb25ceb4..0c50d125a 100644 --- a/res/e3a/weapons/mallornlance.xml +++ b/res/e3a/weapons/mallornlance.xml @@ -4,7 +4,7 @@ - + diff --git a/scripts/tests/e3/rules.lua b/scripts/tests/e3/rules.lua index 8669dc465..8d599462d 100644 --- a/scripts/tests/e3/rules.lua +++ b/scripts/tests/e3/rules.lua @@ -1015,7 +1015,7 @@ function test_demons_using_mallornlance() local f = faction.create('goblin') local u = unit.create(f, r, 1, 'demon') u:set_skill('taxation', 1) - u:set_skill('polearm', 4) -- demon has +1 + u:set_skill('polearm', 1) u:add_item('mallornlance', 1) u:add_order('BEWACHE') process_orders() From 3685bcabfb8c6fa9a4b296bf6b015eee590fc688 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Dec 2017 14:06:40 +0100 Subject: [PATCH 3/5] BUG 2389: insects starve in glaciers. add feature tests for hunger. --- conf/e3/config.json | 3 +- scripts/tests/e2/insects.lua | 10 ---- scripts/tests/hunger.lua | 108 +++++++++++++++++++++++++++++++++++ scripts/tests/init.lua | 1 + src/bind_region.c | 23 ++++++++ src/laws.test.c | 4 +- src/upkeep.c | 29 ++++++++-- 7 files changed, 158 insertions(+), 20 deletions(-) create mode 100644 scripts/tests/hunger.lua diff --git a/conf/e3/config.json b/conf/e3/config.json index 780dc216d..7cbf30f3d 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -48,8 +48,7 @@ "healing.forest": 2.0, "hunger.long": false, "hunger.damage": "1d9+9", - "hunger.demons.skill": true, - "hunger.demons.peasant_tolerance": true, + "hunger.demon.peasant_tolerance": true, "init_spells": 0, "recruit.allow_merge": true, "study.expensivemigrants": true, diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua index 374bedff8..4dcc2898b 100644 --- a/scripts/tests/e2/insects.lua +++ b/scripts/tests/e2/insects.lua @@ -71,13 +71,3 @@ function test_recruit_in_desert() assert_equal('winter', get_season(get_turn())) assert_equal(2, u.number) end - -function bug_1841_test_hunger_in_glacier() - local r = region.create(0, 0, "glacier") - local f = faction.create("insect", "insect@eressea.de", "de") - local u = unit.create(f, r, 1) - - local flags = u.flags - process_orders() - assert_equal(flags+2048, u.flags) -end diff --git a/scripts/tests/hunger.lua b/scripts/tests/hunger.lua new file mode 100644 index 000000000..a33c2208b --- /dev/null +++ b/scripts/tests/hunger.lua @@ -0,0 +1,108 @@ +require "lunit" + +module("tests.hunger", package.seeall, lunit.testcase) + +function setup() + eressea.free_game() + conf = [[{ + "races": { + "demon": { + "maintenance": 10, + "hp" : 50 + }, + "insect": { + "maintenance": 10, + "hp" : 50 + } + }, + "terrains" : { + "plain": { "flags" : [ "land", "walk" ] }, + "glacier": { "flags" : [ "arctic", "land", "walk" ] } + } + }]] + + eressea.config.reset() + eressea.config.parse(conf) + + eressea.settings.set("rules.peasants.growth.factor", "0") + eressea.settings.set("rules.peasantluck.growth.factor", "0") + eressea.settings.set("hunger.damage", "10") +end + +function test_maintenance() + local r = region.create(0, 0, "plain") + local f = faction.create("insect") + local u = unit.create(f, r, 2) + local flags = u.flags + u:add_item('money', 100) + + process_orders() + assert_equal(flags, u.flags, "should not be hungry") + assert_equal(80, u:get_item('money'), "should pay maintenance") + assert_equal(100, u.hp, "should not take damage") +end + +function test_demons_eat_peasants() + local r = region.create(0, 0, "plain") + local f = faction.create("demon") + local u = unit.create(f, r, 10) + local flags = u.flags + u:add_item('money', 120) + + r.peasants = 3 + process_orders() + assert_equal(20, u:get_item('money')) + assert_equal(2, r.peasants) + assert_equal(flags, u.flags) + assert_equal(500, u.hp) +end + +function test_demons_need_peasants() + local r = region.create(0, 0, "plain") + local f = faction.create("demon") + local u = unit.create(f, r, 1) + local flags = u.flags + u:add_item('money', 100) + + eressea.settings.set("hunger.demon.peasant_tolerance", "0") + r.peasants = 0 + process_orders() + assert_equal(90, u:get_item('money')) -- use money even if no peasants + assert_equal(flags+2048, u.flags) + assert_equal(40, u.hp) + + eressea.settings.set("hunger.demon.peasant_tolerance", "1") + u.flags = flags + u.hp = 50 + process_orders() + assert_equal(80, u:get_item('money')) -- use money even if no peasants + assert_equal(flags+2048, u.flags) + assert_equal(50, u.hp) + assert_equal(0, r.peasants) +end + +function test_insects_hunger_in_glacier() + -- bug 2389 + local r = region.create(0, 0, "plain") + local f = faction.create("insect") + local u = unit.create(f, r, 1) + local flags = u.flags + u:add_item('money', 1000) + + -- eressea.settings.set("hunger.insect.cold", "1") -- default + process_orders() + assert_equal(flags, u.flags) + assert_equal(50, u.hp) + + r.terrain = 'glacier' + process_orders() + assert_equal(flags+2048, u.flags) + assert_equal(40, u.hp) + + u.flags = u.flags-2048 + u.hp = 50 + eressea.settings.set("hunger.insect.cold", "0") + process_orders() + assert_equal(flags, u.flags) + assert_equal(50, u.hp) +end diff --git a/scripts/tests/init.lua b/scripts/tests/init.lua index baa8dbef4..c933d4e69 100644 --- a/scripts/tests/init.lua +++ b/scripts/tests/init.lua @@ -9,3 +9,4 @@ require 'tests.settings' require 'tests.study' require 'tests.laws' require 'tests.bindings' +require 'tests.hunger' diff --git a/src/bind_region.c b/src/bind_region.c index 2f9309549..c749baff8 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -536,6 +536,27 @@ static int tolua_region_get_age(lua_State * L) return 0; } +static int tolua_region_get_peasants(lua_State * L) +{ + region *self = (region *)tolua_tousertype(L, 1, 0); + + if (self) { + lua_pushinteger(L, self->land ? self->land->peasants : 0); + return 1; + } + return 0; +} + +static int tolua_region_set_peasants(lua_State * L) +{ + region *self = (region *)tolua_tousertype(L, 1, 0); + + if (self && self->land) { + self->land->peasants = lua_tointeger(L, 2); + } + return 0; +} + static int tolua_region_getkey(lua_State * L) { region *self = (region *)tolua_tousertype(L, 1, 0); @@ -734,6 +755,8 @@ void tolua_region_open(lua_State * L) tolua_variable(L, TOLUA_CAST "age", tolua_region_get_age, NULL); tolua_variable(L, TOLUA_CAST "buildings", tolua_region_get_buildings, NULL); + tolua_variable(L, TOLUA_CAST "peasants", tolua_region_get_peasants, + tolua_region_set_peasants); tolua_variable(L, TOLUA_CAST "terrain", tolua_region_get_terrain, tolua_region_set_terrain); tolua_function(L, TOLUA_CAST "get_resourcelevel", diff --git a/src/laws.test.c b/src/laws.test.c index 898ae4627..a57b93b9e 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1607,7 +1607,7 @@ static void test_demon_hunger(CuTest * tc) u = test_create_unit(f, r); u->hp = 999; - config_set("hunger.demons.peasant_tolerance", "1"); + config_set("hunger.demon.peasant_tolerance", "1"); rtype = get_resourcetype(R_SILVER); i_change(&u->items, rtype->itype, 30); @@ -1619,7 +1619,7 @@ static void test_demon_hunger(CuTest * tc) 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"); + config_set("hunger.demon.peasant_tolerance", "0"); get_food(r); diff --git a/src/upkeep.c b/src/upkeep.c index d7626084d..f94804633 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -109,16 +109,27 @@ void get_food(region * r) plane *pl = rplane(r); unit *u; int peasantfood = rpeasants(r) * 10; - int food_rules = config_get_int("rules.food.flags", 0); - static const race *rc_demon; - static int rc_cache; - + static const race *rc_demon, *rc_insect; + static int rc_cache, config_cache; + static int food_rules; + static bool insect_hunger; + static bool demon_hunger; + bool is_cold; + if (rc_changed(&rc_cache)) { rc_demon = get_race(RC_DAEMON); + rc_insect = get_race(RC_INSECT); + } + if (config_changed(&config_cache)) { + food_rules = config_get_int("rules.food.flags", 0); + insect_hunger = config_get_int("hunger.insect.cold", 1) != 0; + demon_hunger = config_get_int("hunger.demon.peasant_tolerance", 0) == 0; } if (food_rules & FOOD_IS_FREE) { return; } + is_cold = insect_hunger && r_insectstalled(r); + /* 1. Versorgung von eigenen Einheiten. Das vorhandene Silber * wird zun�chst so auf die Einheiten aufgeteilt, dass idealerweise * jede Einheit genug Silber f�r ihren Unterhalt hat. */ @@ -227,7 +238,8 @@ void get_food(region * r) * bei fehlenden Bauern den D�mon hungern lassen */ for (u = r->units; u; u = u->next) { - if (u_race(u) == rc_demon) { + const race * rc = u_race(u); + if (rc == rc_demon) { int hungry = u->number; /* use peasantblood before eating the peasants themselves */ @@ -271,7 +283,6 @@ void get_food(region * r) peasantfood = 0; } if (hungry > 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)) @@ -284,6 +295,12 @@ void get_food(region * r) } } } + else if (is_cold && rc == rc_insect) { + /* insects in glaciers get hunger damage */ + if (hunger(u->number, u)) { + fset(u, UFL_HUNGER); + } + } } rsetpeasants(r, peasantfood / 10); From ed75f4d21a6b1bedc0e5d530abc1fc38bbc8150b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Dec 2017 14:28:15 +0100 Subject: [PATCH 4/5] fix bug 2389 (sailing into glaciers). reduce verbosity. --- scripts/tests/e2/insects.lua | 2 +- src/kernel/save.c | 2 +- src/move.c | 15 --------------- 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/scripts/tests/e2/insects.lua b/scripts/tests/e2/insects.lua index 4dcc2898b..bfd0a2065 100644 --- a/scripts/tests/e2/insects.lua +++ b/scripts/tests/e2/insects.lua @@ -34,7 +34,7 @@ function test_sail_into_glacier() u1:add_order("NACH OST") u2.ship = u1.ship process_orders() - assert_equal(r, u2.region) + assert_equal(r2, u2.region) end function test_recruit_in_winter() diff --git a/src/kernel/save.c b/src/kernel/save.c index fe83f943a..2a5740312 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1429,7 +1429,7 @@ int read_game(gamedata *data) /* Burgen */ READ_INT(store, &p); if (p > 0 && !r->land) { - log_error("%s, uid=%d has %d %s", regionname(r, NULL), r->uid, p, (p==1) ? "building" : "buildings"); + log_debug("%s, uid=%d has %d %s", regionname(r, NULL), r->uid, p, (p==1) ? "building" : "buildings"); } bp = &r->buildings; diff --git a/src/move.c b/src/move.c index 69a84c2cd..4cc15c9bf 100644 --- a/src/move.c +++ b/src/move.c @@ -677,21 +677,6 @@ int check_ship_allowed(struct ship *sh, const region * r) int c = 0; const building_type *bt_harbour = bt_find("harbour"); - if (sh->region && r_insectstalled(r)) { - /* insekten dürfen nicht hier rein. haben wir welche? */ - unit *u; - - for (u = sh->region->units; u != NULL; u = u->next) { - if (u->ship != sh) { - continue; - } - - if (is_freezing(u)) { - return SA_NO_INSECT; - } - } - } - if (bt_harbour && buildingtype_exists(r, bt_harbour, true)) { unit* harbourmaster = NULL; harbourmaster = owner_buildingtyp(r, bt_harbour); From 404691c5dbbe7b8715e71c5a473c56e35ab8aeda Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Dec 2017 14:33:18 +0100 Subject: [PATCH 5/5] delete unused define and code for insects. --- src/move.c | 5 +---- src/move.h | 3 +-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/move.c b/src/move.c index 4cc15c9bf..1502f6243 100644 --- a/src/move.c +++ b/src/move.c @@ -1837,10 +1837,7 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting) reason = check_ship_allowed(sh, next_point); if (reason < 0) { /* for some reason or another, we aren't allowed in there.. */ - if (reason == SA_NO_INSECT) { - ADDMSG(&f->msgs, msg_message("detectforbidden", "unit region", u, sh->region)); - } - else if (check_leuchtturm(current_point, NULL)) { + if (check_leuchtturm(current_point, NULL)) { ADDMSG(&f->msgs, msg_message("sailnolandingstorm", "ship region", sh, next_point)); } else { diff --git a/src/move.h b/src/move.h index 535c76bb2..d3a5d1e0d 100644 --- a/src/move.h +++ b/src/move.h @@ -90,8 +90,7 @@ extern "C" { #define SA_HARBOUR 1 #define SA_COAST 0 -#define SA_NO_INSECT -1 -#define SA_NO_COAST -2 +#define SA_NO_COAST -1 int check_ship_allowed(struct ship *sh, const struct region * r); direction_t drift_target(struct ship *sh);