From c8769a4412782d45e2de8550f598386acc313f0b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 27 Oct 2019 10:56:16 +0100 Subject: [PATCH] Fehler in ship_crewed Berechnung --- src/kernel/ship.c | 13 ++++------- src/kernel/ship.test.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 56551e0f2..87194834b 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -407,22 +407,19 @@ int crew_skill(const ship *sh) { } bool ship_crewed(const ship *sh) { - unit *u; + unit *u, *cap = ship_owner(sh); int capskill = -1, sumskill = 0; for (u = sh->region->units; u; u = u->next) { if (u->ship == sh) { int es = effskill(u, SK_SAILING, NULL); - if (capskill < 0) { - if (u->number >= sh->number) { + if (es > 0) { + if (u == cap && u->number >= sh->number) { capskill = es; } - else { - capskill = 0; + if (es >= sh->type->minskill) { + sumskill += es * u->number; } } - if (es >= sh->type->minskill) { - sumskill += es * u->number; - } } } return (capskill >= ship_captain_minskill(sh)) && (sumskill >= sh->type->sumskill * sh->number); diff --git a/src/kernel/ship.test.c b/src/kernel/ship.test.c index 062e7cd20..ddc0d7795 100644 --- a/src/kernel/ship.test.c +++ b/src/kernel/ship.test.c @@ -30,6 +30,58 @@ static void test_register_ship(CuTest * tc) test_teardown(); } +static void test_ship_crewed(CuTest * tc) +{ + struct region *r; + struct faction *f; + struct ship *sh; + struct unit *u1, *u2; + struct ship_type *stype; + + test_setup(); + f = test_create_faction(NULL); + r = test_create_ocean(0, 0); + stype = test_create_shiptype("longboat"); + stype->cptskill = 2; + stype->sumskill = 4; + sh = test_create_ship(r, stype); + CuAssertTrue(tc, !ship_crewed(sh)); + u1 = test_create_unit(f, r); + set_level(u1, SK_SAILING, 4); + u_set_ship(u1, sh); + CuAssertTrue(tc, ship_crewed(sh)); + u2 = test_create_unit(f, r); + set_level(u1, SK_SAILING, 2); + set_level(u1, SK_SAILING, 2); + u_set_ship(u2, sh); + CuAssertTrue(tc, ship_crewed(sh)); + set_level(u1, SK_SAILING, 1); + set_level(u2, SK_SAILING, 2); + CuAssertTrue(tc, !ship_crewed(sh)); + set_level(u1, SK_SAILING, 2); + set_level(u2, SK_SAILING, 1); + CuAssertTrue(tc, !ship_crewed(sh)); + set_level(u1, SK_SAILING, 3); + set_level(u2, SK_SAILING, 1); + CuAssertTrue(tc, ship_crewed(sh)); + stype->minskill = 2; + CuAssertTrue(tc, !ship_crewed(sh)); + set_level(u1, SK_SAILING, 2); + set_level(u2, SK_SAILING, 2); + CuAssertTrue(tc, ship_crewed(sh)); + sh->number = 2; + CuAssertTrue(tc, !ship_crewed(sh)); + set_level(u1, SK_SAILING, 4); + set_level(u2, SK_SAILING, 4); + CuAssertTrue(tc, !ship_crewed(sh)); + u1->number = 2; + set_level(u1, SK_SAILING, 2); + set_level(u2, SK_SAILING, 4); + CuAssertTrue(tc, ship_crewed(sh)); + + test_teardown(); +} + static void test_ship_set_owner(CuTest * tc) { struct region *r; @@ -665,6 +717,7 @@ CuSuite *get_ship_suite(void) SUITE_ADD_TEST(suite, test_register_ship); SUITE_ADD_TEST(suite, test_stype_defaults); SUITE_ADD_TEST(suite, test_ship_set_owner); + SUITE_ADD_TEST(suite, test_ship_crewed); SUITE_ADD_TEST(suite, test_shipowner_resets_when_empty); SUITE_ADD_TEST(suite, test_shipowner_goes_to_next_when_empty); SUITE_ADD_TEST(suite, test_shipowner_goes_to_other_when_empty);