From 31feeecbd802aa8f8e82df8848f1b160d32d6870 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 30 Jul 2016 21:13:42 +0200 Subject: [PATCH] logging and fixing of live data for bug 2221 additional lua test that failed to find the issue https://bugs.eressea.de/view.php?id=2221 --- scripts/tests/e2/e2features.lua | 23 +++++++++++++++++++++++ src/kernel/build.c | 1 + src/kernel/save.c | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/scripts/tests/e2/e2features.lua b/scripts/tests/e2/e2features.lua index 24b6626e4..efed50ea1 100644 --- a/scripts/tests/e2/e2features.lua +++ b/scripts/tests/e2/e2features.lua @@ -2,6 +2,29 @@ require "lunit" module("tests.e2.e2features", package.seeall, lunit.testcase ) +function test_build_harbour() +-- try to reproduce mantis bug 2221 + local r = region.create(0, 0, "plain") + local f = faction.create("harbour@eressea.de", "human", "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 3d4fb6a17..1c284b3f9 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -848,6 +848,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order * } b->size += built; + assert(b->type->maxsize <= 0 || b->size <= b->type->maxsize); fset(b, BLD_EXPANDED); update_lighthouse(b); diff --git a/src/kernel/save.c b/src/kernel/save.c index 5c875702f..12afb6909 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1676,6 +1676,11 @@ int read_game(gamedata *data) { if (b->type == bt_lighthouse) { r->flags |= RF_LIGHTHOUSE; } + // repairs, bug 2221: + if (b->type->maxsize>0 && b->size>b->type->maxsize) { + log_error("building too big: %s (%s size %d of %d), fixing.", buildingname(b), b->type->_name, b->size, b->type->maxsize); + b->size = b->type->maxsize; + } } /* Schiffe */