diff --git a/res/translations/messages.de.po b/res/translations/messages.de.po index 0ac3c477a..537454fef 100644 --- a/res/translations/messages.de.po +++ b/res/translations/messages.de.po @@ -1161,6 +1161,12 @@ msgid "spyreport_faction" msgstr "\"$unit($target) gehört der Partei $faction($faction) an.\"" msgid "ship_drift" +msgstr "\"Die $ship($ship) treibt nach $direction($dir).\"" + +msgid "ship_drift_overload" +msgstr "\"Die $ship($ship) ist überladen und treibt nach $direction($dir).\"" + +msgid "ship_drift_nocrew" msgstr "\"Die $ship($ship) hat zu wenig Segler und treibt nach $direction($dir).\"" msgid "error_max_magicians" diff --git a/res/translations/messages.en.po b/res/translations/messages.en.po index 61f5a6010..8da97fba2 100644 --- a/res/translations/messages.en.po +++ b/res/translations/messages.en.po @@ -1161,6 +1161,12 @@ msgid "spyreport_faction" msgstr "\"$unit($target) belongs to $faction($faction).\"" msgid "ship_drift" +msgstr "\"The ship $ship($ship) drifts to the $direction($dir).\"" + +msgid "ship_drift_overload" +msgstr "\"The ship $ship($ship) is too heavily loaded and drifts to the $direction($dir).\"" + +msgid "ship_drift_nocrew" msgstr "\"The ship $ship($ship) needs more sailors and drifts to the $direction($dir).\"" msgid "error_max_magicians" diff --git a/src/move.c b/src/move.c index a847e293d..9480e3463 100644 --- a/src/move.c +++ b/src/move.c @@ -813,12 +813,13 @@ static void drifting_ships(region * r) if (fval(r->terrain, SEA_REGION)) { ship **shp = &r->ships; while (*shp) { - ship *sh = *shp; - region *rnext = NULL; - region_list *route = NULL; - unit *firstu = r->units, *lastu = NULL; + ship* sh = *shp; + region* rnext = NULL; + region_list* route = NULL; + unit* firstu = r->units, * lastu = NULL; direction_t dir = NODIRECTION; double ovl; + const char* reason = "ship_drift"; if (sh->type->fishing > 0) { sh->flags |= SF_FISHING; @@ -833,11 +834,21 @@ static void drifting_ships(region * r) /* Kapitaen da? Beschaedigt? Genuegend Matrosen? * Genuegend leicht? Dann ist alles OK. */ - if (ship_finished(sh) && ship_crewed(sh, ship_owner(sh)) && cansail(r, sh)) { - shp = &sh->next; - continue; + if (ship_finished(sh)) { + if (!ship_crewed(sh, ship_owner(sh))) { + reason = "ship_drift_nocrew"; + } + else if (!cansail(r, sh)) { + reason = "ship_drift_overload"; + } + else { + /* no problems, don't drift */ + shp = &sh->next; + continue; + } } + fset(sh, SF_DRIFTED); ovl = overload(r, sh); if (ovl < overload_start()) { /* Auswahl einer Richtung: Zuerst auf Land, dann @@ -849,11 +860,10 @@ static void drifting_ships(region * r) } if (rnext && firstu) { - message *msg = msg_message("ship_drift", "ship dir", sh, dir); + message *msg = msg_message(reason, "ship dir", sh, dir); msg_to_passengers(sh, &firstu, &lastu, msg); } - fset(sh, SF_DRIFTED); if (ovl >= overload_start()) { damage_ship(sh, damage_overload(ovl)); msg_to_passengers(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh)); diff --git a/src/move.test.c b/src/move.test.c index cc0cafc1f..8309a8154 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -293,6 +293,10 @@ void setup_drift (struct drift_fixture *fix) { mt_create_va(mt_new("ship_drift", NULL), "ship:ship", "dir:int", MT_NEW_END); + mt_create_va(mt_new("ship_drift_nocrew", NULL), + "ship:ship", "dir:int", MT_NEW_END); + mt_create_va(mt_new("ship_drift_overload", NULL), + "ship:ship", "dir:int", MT_NEW_END); mt_create_va(mt_new("shipsink", NULL), "ship:ship", MT_NEW_END); mt_create_va(mt_new("massive_overload", NULL), @@ -323,8 +327,24 @@ static void test_ship_empty(CuTest *tc) { movement(); CuAssertPtrEquals(tc, fix.sh->region, findregion(0, 0)); + CuAssertIntEquals(tc, SF_DRIFTED, fix.sh->flags & SF_DRIFTED); CuAssertIntEquals(tc, 2, ship_damage_percent(fix.sh)); - CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "ship_drift")); + + test_teardown(); +} + +static void test_ship_no_crew(CuTest *tc) { + struct drift_fixture fix; + + test_setup(); + setup_drift(&fix); + set_level(fix.u, SK_SAILING, 0); + + movement(); + CuAssertPtrEquals(tc, fix.sh->region, findregion(0, 0)); + CuAssertIntEquals(tc, SF_DRIFTED, fix.sh->flags & SF_DRIFTED); + CuAssertIntEquals(tc, 2, ship_damage_percent(fix.sh)); + CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "ship_drift_nocrew")); test_teardown(); } @@ -340,6 +360,7 @@ static void test_no_drift_damage(CuTest *tc) { config_set("rules.ship.damage_drift", "0.0"); movement(); CuAssertPtrEquals(tc, fix.sh->region, findregion(0, 0)); + CuAssertIntEquals(tc, SF_DRIFTED, fix.sh->flags & SF_DRIFTED); CuAssertIntEquals(tc, 0, ship_damage_percent(fix.sh)); CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "ship_drift")); @@ -355,8 +376,9 @@ static void test_ship_normal_overload(CuTest *tc) { fix.u->number = 21; movement(); CuAssertPtrEquals(tc, fix.u->region, findregion(0, 0)); + CuAssertIntEquals(tc, SF_DRIFTED, fix.sh->flags & SF_DRIFTED); CuAssertIntEquals(tc, 2, ship_damage_percent(fix.sh)); - CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "ship_drift")); + CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "ship_drift_overload")); test_teardown(); } @@ -370,13 +392,16 @@ static void test_ship_big_overload(CuTest *tc) { fix.u->number = 22; movement(); CuAssertPtrEquals(tc, fix.u->region, findregion(-1, 0)); + CuAssertIntEquals(tc, SF_DRIFTED, fix.sh->flags & SF_DRIFTED); CuAssertIntEquals(tc, 5, ship_damage_percent(fix.sh)); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "ship_drift_overload")); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "ship_drift")); CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload")); test_teardown(); } -static void test_ship_no_real_overload(CuTest *tc) { +static void test_ship_small_overload(CuTest *tc) { struct drift_fixture fix; test_setup(); @@ -386,7 +411,9 @@ static void test_ship_no_real_overload(CuTest *tc) { damage_ship(fix.sh, .80); movement(); CuAssertPtrEquals(tc, fix.u->region, findregion(0, 0)); + CuAssertIntEquals(tc, SF_DRIFTED, fix.sh->flags & SF_DRIFTED); CuAssertIntEquals(tc, 82, ship_damage_percent(fix.sh)); + CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "ship_drift_overload")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "massive_overload")); test_teardown(); @@ -400,7 +427,11 @@ static void test_ship_ridiculous_overload(CuTest *tc) { fix.u->number = 500; movement(); + CuAssertPtrEquals(tc, fix.u->region, findregion(-1, 0)); + CuAssertIntEquals(tc, SF_DRIFTED, fix.sh->flags & SF_DRIFTED); CuAssertIntEquals(tc, 37, ship_damage_percent(fix.sh)); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "ship_drift_overload")); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "ship_drift")); CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload")); test_teardown(); @@ -755,9 +786,10 @@ CuSuite *get_move_suite(void) SUITE_ADD_TEST(suite, test_age_trails); SUITE_ADD_TEST(suite, test_ship_no_overload); SUITE_ADD_TEST(suite, test_ship_empty); + SUITE_ADD_TEST(suite, test_ship_no_crew); SUITE_ADD_TEST(suite, test_no_drift_damage); SUITE_ADD_TEST(suite, test_ship_normal_overload); - SUITE_ADD_TEST(suite, test_ship_no_real_overload); + SUITE_ADD_TEST(suite, test_ship_small_overload); SUITE_ADD_TEST(suite, test_ship_big_overload); SUITE_ADD_TEST(suite, test_ship_ridiculous_overload); SUITE_ADD_TEST(suite, test_ship_ridiculous_overload_bad);