From b6f40148d7df89bdef5c9fe9e85983fb0bcaccf8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 16 Jul 2017 11:24:16 +0200 Subject: [PATCH 1/8] off-by-one in NMR count --- scripts/run-turn.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 4099c7976..83d4045ac 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -1,6 +1,6 @@ function nmr_check(maxnmrs) local nmrs = get_nmrs(1) - if nmrs >= maxnmrs then + if nmrs > maxnmrs then eressea.log.error("Shit. More than " .. maxnmrs .. " factions with 1 NMR (" .. nmrs .. ")") write_summary() return -1 From b79db40f4183c7aed08e7fe79b0daa42f49d8c48 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Jul 2017 13:59:30 +0200 Subject: [PATCH 2/8] retrofit a test for buildingcapacity. --- src/kernel/building.test.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 588ec2937..e19d074da 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -570,11 +570,32 @@ static void test_buildingtype(CuTest *tc) { test_cleanup(); } +static void test_buildingcapacity(CuTest *tc) { + building *b; + building_type *btype; + test_setup(); + btype = test_create_buildingtype("lighthouse"); + btype->capacity = 1; + btype->maxcapacity = 4; + b = test_create_building(test_create_region(0, 0, NULL), btype); + + b->size = 1; + CuAssertIntEquals(tc, b->size*btype->capacity, buildingcapacity(b)); + b->size = 5; + CuAssertIntEquals(tc, btype->maxcapacity, buildingcapacity(b)); + + btype->capacity = -1; + CuAssertTrue(tc, building_finished(b)); + CuAssertIntEquals(tc, btype->maxcapacity, buildingcapacity(b)); + test_cleanup(); +} + CuSuite *get_building_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_buildingtype); SUITE_ADD_TEST(suite, test_largestbuilding); + SUITE_ADD_TEST(suite, test_buildingcapacity); SUITE_ADD_TEST(suite, test_cmp_castle_size); SUITE_ADD_TEST(suite, test_cmp_taxes); SUITE_ADD_TEST(suite, test_cmp_wage); From 0bf003cdc49ad5d88c15d9b7a0670252c575a052 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Jul 2017 13:37:40 +0200 Subject: [PATCH 3/8] add a test for btype.maxsize --- scripts/tests/e2/buildings.lua | 20 ++++++++++++++++++++ src/kernel/building.c | 1 + 2 files changed, 21 insertions(+) diff --git a/scripts/tests/e2/buildings.lua b/scripts/tests/e2/buildings.lua index 4797643e1..07b774d9c 100644 --- a/scripts/tests/e2/buildings.lua +++ b/scripts/tests/e2/buildings.lua @@ -51,3 +51,23 @@ function test_build_castle_stages() process_orders() assert_equal(250, b.size) end + +function test_build_maxsize() + local r = region.create(0,0, "plain") + local f = faction.create("human") + local u = unit.create(f, r, 100) + local b = building.create(r, "harbour") + + b.size = 20 + u:add_item("stone", 1000) + u:add_item("log", 1000) + u:add_item("money", 10000) + + u:set_skill("building", 100) + u:clear_orders() + u:add_order("MACHE BURG " .. itoa36(b.id)) + process_orders() + assert_equal(25, b.size) -- build no more than max + process_orders() + assert_equal(25, b.size) -- stop at max +end diff --git a/src/kernel/building.c b/src/kernel/building.c index bcc914cca..14e4a3e07 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -310,6 +310,7 @@ static const int watch_bonus[3] = { 0, 1, 2 }; int building_protection(const building_type * btype, int stage) { + assert(btype->flags & BTF_FORTIFICATION); if (btype->maxsize < 0) { return castle_bonus[MIN(stage, 5)]; } From 3c2754071dfcc23cf9c7d9e6ff4a6213f3c69745 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Jul 2017 14:01:08 +0200 Subject: [PATCH 4/8] this test fails when btype->maxsize isn't used as a limit for building. --- res/core/common/buildings.xml | 2 +- scripts/tests/e2/buildings.lua | 34 ++++++++++++++++++--------------- scripts/tests/e2/e2features.lua | 23 ---------------------- src/kernel/build.c | 3 ++- 4 files changed, 22 insertions(+), 40 deletions(-) diff --git a/res/core/common/buildings.xml b/res/core/common/buildings.xml index a799ce309..b73ab01aa 100644 --- a/res/core/common/buildings.xml +++ b/res/core/common/buildings.xml @@ -129,7 +129,7 @@ - + diff --git a/scripts/tests/e2/buildings.lua b/scripts/tests/e2/buildings.lua index 07b774d9c..02298bd97 100644 --- a/scripts/tests/e2/buildings.lua +++ b/scripts/tests/e2/buildings.lua @@ -52,22 +52,26 @@ function test_build_castle_stages() assert_equal(250, b.size) end -function test_build_maxsize() - local r = region.create(0,0, "plain") - local f = faction.create("human") - local u = unit.create(f, r, 100) - local b = building.create(r, "harbour") - - b.size = 20 - u:add_item("stone", 1000) - u:add_item("log", 1000) - u:add_item("money", 10000) - - u:set_skill("building", 100) +function test_build_harbour() +-- try to reproduce mantis bug 2221 + local r = region.create(0, 0, "plain") + local f = faction.create("human", "harbour@eressea.de", "de") + local u = unit.create(f, r) + size = 30 + u.number = 20 + u:set_skill("building", 3) + u:add_item("money", size*250) + u:add_item("stone", size*5) + u:add_item("log", size*5) u:clear_orders() - u:add_order("MACHE BURG " .. itoa36(b.id)) + u:add_order("MACHE HAFEN") process_orders() - assert_equal(25, b.size) -- build no more than max + assert_not_nil(u.building) + assert_equal("harbour", u.building.type) + assert_equal(20, u.building.size) process_orders() - assert_equal(25, b.size) -- stop at max + assert_equal(25, u.building.size) + process_orders() + assert_equal(25, u.building.size) end + diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index ffe3266e3..7e143c0cc 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -62,29 +62,6 @@ function test_dwarf_bonus() assert_equal(70, r:get_resource("iron")) end -function test_build_harbour() --- try to reproduce mantis bug 2221 - local r = region.create(0, 0, "plain") - local f = faction.create("human", "harbour@eressea.de", "de") - local u = unit.create(f, r) - size = 30 - u.number = 20 - u:set_skill("building", 3) - u:add_item("money", size*250) - u:add_item("stone", size*5) - u:add_item("log", size*5) - u:clear_orders() - u:add_order("MACHE HAFEN") - process_orders() - assert_not_nil(u.building) - assert_equal("harbour", u.building.type) - assert_equal(20, u.building.size) - process_orders() - assert_equal(25, u.building.size) - process_orders() - assert_equal(25, u.building.size) -end - local function one_unit(r, f) local u = unit.create(f, r, 1) u:add_item("money", u.number * 100) diff --git a/src/kernel/build.c b/src/kernel/build.c index 57c172905..a6e8edc77 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -717,8 +717,9 @@ build_building(unit * u, const building_type * btype, int id, int want, order * b = u->building; } - if (b) + if (b) { btype = b->type; + } if (fval(btype, BTF_UNIQUE) && buildingtype_exists(r, btype, false)) { /* only one of these per region */ From 5f463fbc4c8feda1bef919b067fc2cd5d6b68e27 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Jul 2017 14:05:24 +0200 Subject: [PATCH 5/8] btype->cons->maxsize does not matter if it's not a multi-stage building (castle, watch). --- res/core/common/buildings.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/res/core/common/buildings.xml b/res/core/common/buildings.xml index b73ab01aa..64edc8a34 100644 --- a/res/core/common/buildings.xml +++ b/res/core/common/buildings.xml @@ -7,14 +7,14 @@ - + - + @@ -33,7 +33,7 @@ - + @@ -44,7 +44,7 @@ - + @@ -55,7 +55,7 @@ - + @@ -107,7 +107,7 @@ - + @@ -119,7 +119,7 @@ - + From f8de1bf29ec192282282f8acb35797c4bfd5ecd7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Jul 2017 16:11:00 +0200 Subject: [PATCH 6/8] remove default values from XML (capacity=1) --- res/buildings/castle-2.xml | 2 +- res/buildings/castle.xml | 2 +- res/core/common/buildings.xml | 28 ++++++++++++++-------------- res/e3a/buildings.xml | 4 ++-- res/eressea/buildings.xml | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/res/buildings/castle-2.xml b/res/buildings/castle-2.xml index 7e64f88af..accb92c08 100644 --- a/res/buildings/castle-2.xml +++ b/res/buildings/castle-2.xml @@ -1,5 +1,5 @@ - + diff --git a/res/buildings/castle.xml b/res/buildings/castle.xml index 78ce7066c..ce64e8030 100644 --- a/res/buildings/castle.xml +++ b/res/buildings/castle.xml @@ -1,5 +1,5 @@ - + diff --git a/res/core/common/buildings.xml b/res/core/common/buildings.xml index 64edc8a34..932326f1c 100644 --- a/res/core/common/buildings.xml +++ b/res/core/common/buildings.xml @@ -1,9 +1,9 @@ - + - + @@ -20,7 +20,7 @@ - + @@ -30,7 +30,7 @@ - + @@ -41,7 +41,7 @@ - + @@ -52,7 +52,7 @@ - + @@ -63,7 +63,7 @@ - + @@ -72,7 +72,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -92,7 +92,7 @@ - + @@ -127,7 +127,7 @@ - + @@ -136,7 +136,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -156,7 +156,7 @@ - + diff --git a/res/e3a/buildings.xml b/res/e3a/buildings.xml index 8641fd89e..069a24150 100644 --- a/res/e3a/buildings.xml +++ b/res/e3a/buildings.xml @@ -3,7 +3,7 @@ - + @@ -15,7 +15,7 @@ - + diff --git a/res/eressea/buildings.xml b/res/eressea/buildings.xml index 670ab484e..1559fd987 100644 --- a/res/eressea/buildings.xml +++ b/res/eressea/buildings.xml @@ -2,7 +2,7 @@ - - + + From 233ea9dce4e393e4a4b0ab68db0863e93f7b9fab Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Jul 2017 17:08:27 +0200 Subject: [PATCH 7/8] BUG 2337: lighthouse capacity is # of units, not people. --- conf/e2/config.json | 3 ++- conf/e3/config.json | 1 + src/reports.c | 9 ++++++++- src/reports.test.c | 9 +++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/conf/e2/config.json b/conf/e2/config.json index fb231e2eb..b8ca2f178 100644 --- a/conf/e2/config.json +++ b/conf/e2/config.json @@ -35,6 +35,7 @@ "rules.guard.guard_number_stop_prob": 0.001, "rules.guard.castle_stop_prob": 0.05, "rules.guard.region_type_stop_prob": 0.05, - "rules.economy.repopulate_maximum": 500 + "rules.economy.repopulate_maximum": 500, + "rules.lighthouse.unit_capacity": true } } diff --git a/conf/e3/config.json b/conf/e3/config.json index bfd1bd0fc..3305ce221 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -92,6 +92,7 @@ "rules.grow.formula": 1, "rules.tactics.formula": 1, "rules.help.mask": "fight guard money give", + "rules.lighthouse.unit_capacity": true, "movement.shipspeed.skillbonus": 6, "alliance.auto": "fight", "alliance.restricted": "fight" diff --git a/src/reports.c b/src/reports.c index 1a269caa5..e989aee40 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1405,10 +1405,12 @@ void prepare_report(report_context *ctx, faction *f) region *r; static int config; static bool rule_region_owners; + static bool rule_lighthouse_units; const struct building_type *bt_lighthouse = bt_find("lighthouse"); if (bt_lighthouse && config_changed(&config)) { rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name); + rule_lighthouse_units = config_get_int("rules.lighthouse.unit_capacity", 0) != 0; } if (f->age <= 2) { @@ -1471,7 +1473,12 @@ void prepare_report(report_context *ctx, faction *f) c = buildingcapacity(b); br = 0; } - c -= u->number; + if (rule_lighthouse_units) { + --c; + } + else { + c -= u->number; + } if (u->faction == f && c >= 0) { /* unit is one of ours, and inside the current lighthouse */ if (br == 0) { diff --git a/src/reports.test.c b/src/reports.test.c index 74750e9b5..1efd6369a 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -496,6 +496,15 @@ void test_prepare_lighthouse_capacity(CuTest *tc) { CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode); finish_reports(&ctx); + // lighthouse capacity is # of units, not people: + config_set_int("rules.lighthouse.unit_capacity", 1); + prepare_report(&ctx, u2->faction); + CuAssertPtrEquals(tc, r1, ctx.first); + CuAssertPtrEquals(tc, 0, ctx.last); + CuAssertIntEquals(tc, seen_unit, r1->seen.mode); + CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode); + finish_reports(&ctx); + test_cleanup(); } From aa2c13cffab2fc6cc6d7e11736bcee2e024e06de Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 17 Jul 2017 17:22:01 +0200 Subject: [PATCH 8/8] gcc ist pingelig --- src/reports.test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reports.test.c b/src/reports.test.c index 1efd6369a..891f7d4af 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -496,7 +496,7 @@ void test_prepare_lighthouse_capacity(CuTest *tc) { CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode); finish_reports(&ctx); - // lighthouse capacity is # of units, not people: + /* lighthouse capacity is # of units, not people: */ config_set_int("rules.lighthouse.unit_capacity", 1); prepare_report(&ctx, u2->faction); CuAssertPtrEquals(tc, r1, ctx.first);