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/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 a799ce309..932326f1c 100644 --- a/res/core/common/buildings.xml +++ b/res/core/common/buildings.xml @@ -1,26 +1,26 @@ - + - + - + - + - + @@ -30,10 +30,10 @@ - + - + @@ -41,10 +41,10 @@ - + - + @@ -52,10 +52,10 @@ - + - + @@ -63,7 +63,7 @@ - + @@ -72,7 +72,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -92,7 +92,7 @@ - + @@ -107,7 +107,7 @@ - + @@ -119,7 +119,7 @@ - + @@ -127,16 +127,16 @@ - + - + - + @@ -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 @@ - - + + diff --git a/scripts/tests/e2/buildings.lua b/scripts/tests/e2/buildings.lua index 4797643e1..02298bd97 100644 --- a/scripts/tests/e2/buildings.lua +++ b/scripts/tests/e2/buildings.lua @@ -51,3 +51,27 @@ function test_build_castle_stages() process_orders() assert_equal(250, b.size) 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 + 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 */ 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)]; } 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); 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..891f7d4af 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(); }