From cb16315e7cf69bef4e3553c686d66e11145e9135 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Fri, 6 Nov 2015 13:14:19 +0100 Subject: [PATCH 1/6] new test Added test for the handling of castles' buildstages and their individual skillcaps. --- src/kernel/build.test.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index b879295e1..bda6475a3 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -261,6 +261,34 @@ static void test_build_building_success(CuTest *tc) { teardown_build(&bf); } +static void test_build_castle_skillcap(CuTest *tc) { + const building_type *btype; + build_fixture bf = { 0 }; + unit *u; + const resource_type *rtype; + + u = setup_build(&bf); + btype = bt_find("castle"); + assert(btype); + + set_number(u, 1000); + set_level(u, SK_BUILDING, 1); + rtype = get_resourcetype(R_STONE); + i_change(&bf.u->items, rtype->itype, 1000); + + u->orders = create_order(K_MAKE, u->faction->locale, 0); + + CuAssertIntEquals(tc, 10, build_building(u, btype, 0, 100, u->orders)); + CuAssertIntEquals(tc, 10, u->building->size); + + set_level(u, SK_BUILDING, 3); + + CuAssertIntEquals(tc, 240, build_building(u, btype, 0, 200, u->orders)); + CuAssertIntEquals(tc, 250, u->building->size); + + teardown_build(&bf); +} + CuSuite *get_build_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -275,6 +303,7 @@ CuSuite *get_build_suite(void) SUITE_ADD_TEST(suite, test_build_building_success); SUITE_ADD_TEST(suite, test_build_building_with_golem); SUITE_ADD_TEST(suite, test_build_building_no_materials); + SUITE_ADD_TEST(suite, test_build_castle_skillcap); return suite; } From be5d81acd1bb914187d352d76aeeedc3f81c06b2 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Fri, 6 Nov 2015 20:51:38 +0100 Subject: [PATCH 2/6] Revert "new test" This reverts commit cb16315e7cf69bef4e3553c686d66e11145e9135. --- src/kernel/build.test.c | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index bda6475a3..b879295e1 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -261,34 +261,6 @@ static void test_build_building_success(CuTest *tc) { teardown_build(&bf); } -static void test_build_castle_skillcap(CuTest *tc) { - const building_type *btype; - build_fixture bf = { 0 }; - unit *u; - const resource_type *rtype; - - u = setup_build(&bf); - btype = bt_find("castle"); - assert(btype); - - set_number(u, 1000); - set_level(u, SK_BUILDING, 1); - rtype = get_resourcetype(R_STONE); - i_change(&bf.u->items, rtype->itype, 1000); - - u->orders = create_order(K_MAKE, u->faction->locale, 0); - - CuAssertIntEquals(tc, 10, build_building(u, btype, 0, 100, u->orders)); - CuAssertIntEquals(tc, 10, u->building->size); - - set_level(u, SK_BUILDING, 3); - - CuAssertIntEquals(tc, 240, build_building(u, btype, 0, 200, u->orders)); - CuAssertIntEquals(tc, 250, u->building->size); - - teardown_build(&bf); -} - CuSuite *get_build_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -303,7 +275,6 @@ CuSuite *get_build_suite(void) SUITE_ADD_TEST(suite, test_build_building_success); SUITE_ADD_TEST(suite, test_build_building_with_golem); SUITE_ADD_TEST(suite, test_build_building_no_materials); - SUITE_ADD_TEST(suite, test_build_castle_skillcap); return suite; } From a452ad1517ebe5b2eb05c665ca858a0ca8115c48 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Fri, 6 Nov 2015 20:53:10 +0100 Subject: [PATCH 3/6] added a lua-test New lua-test for the bug concerning the minskill for castle-stages. (#1859) --- scripts/tests/e3/castles.lua | 23 +++++++++++++++++++++++ src/kernel/build.c | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua index b9cbabe0b..b32f80f5d 100644 --- a/scripts/tests/e3/castles.lua +++ b/scripts/tests/e3/castles.lua @@ -50,3 +50,26 @@ function test_build_packice() process_orders() assert_equal(nil, u.building) end + +function test_build_castle_stages() + local r = region.create(0,0, "plain") + local f = faction.create("castle@eressea.de", "human", "de") + local u = unit.create(f, r, 1000) + local b = building.create(r, "castle") + + u:add_item("stone", 1000) + + u:set_skill("building", 1) + u:clear_orders() + + u:add_order("MACHE BURG " .. itoa36(b.id)) + process_orders() + assert_equal(10, b.size) + + u:set_skill("building", 3) + u:clear_orders() + + u:add_order("MACHE BURG " .. itoa36(b.id)) + process_orders() + assert_equal(250, b.size) +end diff --git a/src/kernel/build.c b/src/kernel/build.c index e38d76641..3952c732a 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -522,7 +522,9 @@ int build(unit * u, const construction * ctype, int completed, int want) if (basesk < type->minskill) { if (made == 0) - return ELOWSKILL; /* not good enough to go on */ + return ELOWSKILL; + else + return made; /* not good enough to go on */ } /* n = maximum buildable size */ From b0a986e1555784a1e95d30d847a484679d24af49 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Fri, 6 Nov 2015 20:57:19 +0100 Subject: [PATCH 4/6] Revert "added a lua-test" This reverts commit a452ad1517ebe5b2eb05c665ca858a0ca8115c48. --- scripts/tests/e3/castles.lua | 23 ----------------------- src/kernel/build.c | 4 +--- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua index b32f80f5d..b9cbabe0b 100644 --- a/scripts/tests/e3/castles.lua +++ b/scripts/tests/e3/castles.lua @@ -50,26 +50,3 @@ function test_build_packice() process_orders() assert_equal(nil, u.building) end - -function test_build_castle_stages() - local r = region.create(0,0, "plain") - local f = faction.create("castle@eressea.de", "human", "de") - local u = unit.create(f, r, 1000) - local b = building.create(r, "castle") - - u:add_item("stone", 1000) - - u:set_skill("building", 1) - u:clear_orders() - - u:add_order("MACHE BURG " .. itoa36(b.id)) - process_orders() - assert_equal(10, b.size) - - u:set_skill("building", 3) - u:clear_orders() - - u:add_order("MACHE BURG " .. itoa36(b.id)) - process_orders() - assert_equal(250, b.size) -end diff --git a/src/kernel/build.c b/src/kernel/build.c index 3952c732a..e38d76641 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -522,9 +522,7 @@ int build(unit * u, const construction * ctype, int completed, int want) if (basesk < type->minskill) { if (made == 0) - return ELOWSKILL; - else - return made; /* not good enough to go on */ + return ELOWSKILL; /* not good enough to go on */ } /* n = maximum buildable size */ From 4f5a02a1a394771e4132e58a0f3b364c7b4c9918 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Fri, 6 Nov 2015 20:59:45 +0100 Subject: [PATCH 5/6] new lua-test for castle-stages (Messed up the previous commit) New lua-test for the behaviour concerning the castle-stages and their min-skills. (Bug 1859) --- scripts/tests/e3/castles.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/tests/e3/castles.lua b/scripts/tests/e3/castles.lua index b9cbabe0b..b32f80f5d 100644 --- a/scripts/tests/e3/castles.lua +++ b/scripts/tests/e3/castles.lua @@ -50,3 +50,26 @@ function test_build_packice() process_orders() assert_equal(nil, u.building) end + +function test_build_castle_stages() + local r = region.create(0,0, "plain") + local f = faction.create("castle@eressea.de", "human", "de") + local u = unit.create(f, r, 1000) + local b = building.create(r, "castle") + + u:add_item("stone", 1000) + + u:set_skill("building", 1) + u:clear_orders() + + u:add_order("MACHE BURG " .. itoa36(b.id)) + process_orders() + assert_equal(10, b.size) + + u:set_skill("building", 3) + u:clear_orders() + + u:add_order("MACHE BURG " .. itoa36(b.id)) + process_orders() + assert_equal(250, b.size) +end From 663d947b2aed2648d8c866b0482009b607387e08 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Fri, 6 Nov 2015 21:04:35 +0100 Subject: [PATCH 6/6] New behaviour in case of low skill during building Insufficient skill after hitting the next improvement stage is now handled by leaving the for-loop and skipping to after-build-processing. --- src/kernel/build.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index e38d76641..c81e610d7 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -522,7 +522,9 @@ int build(unit * u, const construction * ctype, int completed, int want) if (basesk < type->minskill) { if (made == 0) - return ELOWSKILL; /* not good enough to go on */ + return ELOWSKILL; + else + break; /* not good enough to go on */ } /* n = maximum buildable size */