From a7c45d31ad8e1613c533dd5b2098672a400bd060 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 25 Dec 2017 23:22:19 +0100 Subject: [PATCH] bug 2214: drifting ships in E3 should take no damage. --- conf/e3/config.json | 1 + src/move.c | 12 +++++++++--- src/move.test.c | 30 ++++++++++++++++-------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/conf/e3/config.json b/conf/e3/config.json index 7963f41b3..f3bddfdc0 100644 --- a/conf/e3/config.json +++ b/conf/e3/config.json @@ -65,6 +65,7 @@ "rules.stealth.anon_battle": false, "rules.check_overload": false, "rules.combat.goblinbonus": 3, + "rules.ship.damage_drift": 0.0, "rules.alliances": true, "rules.combat.herospeed": 3, "rules.combat.demon_vampire": 5, diff --git a/src/move.c b/src/move.c index a815c86a0..a36c13343 100644 --- a/src/move.c +++ b/src/move.c @@ -802,9 +802,14 @@ direction_t drift_target(ship *sh) { static void drifting_ships(region * r) { - bool drift = config_get_int("rules.ship.drifting", 1) != 0; - double damage_drift = config_get_flt("rules.ship.damage_drift", 0.02); + static int config; + static bool drift; + static double damage_drift; + if (config_changed(&config)) { + drift = config_get_int("rules.ship.drifting", 1) != 0; + damage_drift = config_get_flt("rules.ship.damage_drift", 0.02); + } if (fval(r->terrain, SEA_REGION)) { ship **shp = &r->ships; while (*shp) { @@ -872,8 +877,9 @@ static void drifting_ships(region * r) damage_ship(sh, damage_overload(ovl)); msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh)); } - else + else { damage_ship(sh, damage_drift); + } if (sh->damage >= sh->size * DAMAGE_SCALE) { msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("shipsink", "ship", sh)); remove_ship(&sh->region->ships, sh); diff --git a/src/move.test.c b/src/move.test.c index edb070bfb..54b8885d5 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -281,8 +281,6 @@ void setup_drift (struct drift_fixture *fix) { static void test_ship_no_overload(CuTest *tc) { struct drift_fixture fix; - test_cleanup(); - setup_drift(&fix); fix.u->number = 2; @@ -296,8 +294,6 @@ static void test_ship_no_overload(CuTest *tc) { static void test_ship_empty(CuTest *tc) { struct drift_fixture fix; - test_cleanup(); - setup_drift(&fix); fix.u->ship = NULL; ship_update_owner(fix.sh); @@ -310,10 +306,24 @@ static void test_ship_empty(CuTest *tc) { test_cleanup(); } -static void test_ship_normal_overload(CuTest *tc) { +static void test_no_drift_damage(CuTest *tc) { struct drift_fixture fix; + setup_drift(&fix); + fix.u->ship = NULL; + ship_update_owner(fix.sh); + + config_set("rules.ship.damage_drift", "0.0"); + movement(); + CuAssertPtrEquals(tc, fix.sh->region, findregion(0, 0)); + CuAssertIntEquals(tc, 0, ship_damage_percent(fix.sh)); + CuAssertPtrEquals(tc, 0, test_find_messagetype(fix.f->msgs, "ship_drift")); + test_cleanup(); +} + +static void test_ship_normal_overload(CuTest *tc) { + struct drift_fixture fix; setup_drift(&fix); @@ -329,8 +339,6 @@ static void test_ship_normal_overload(CuTest *tc) { static void test_ship_big_overload(CuTest *tc) { struct drift_fixture fix; - test_cleanup(); - setup_drift(&fix); fix.u->number = 22; @@ -345,8 +353,6 @@ static void test_ship_big_overload(CuTest *tc) { static void test_ship_no_real_overload(CuTest *tc) { struct drift_fixture fix; - test_cleanup(); - setup_drift(&fix); fix.u->number = 21; @@ -362,8 +368,6 @@ static void test_ship_no_real_overload(CuTest *tc) { static void test_ship_ridiculous_overload(CuTest *tc) { struct drift_fixture fix; - test_cleanup(); - setup_drift(&fix); fix.u->number = 500; @@ -377,8 +381,6 @@ static void test_ship_ridiculous_overload(CuTest *tc) { static void test_ship_ridiculous_overload_no_captain(CuTest *tc) { struct drift_fixture fix; - test_cleanup(); - setup_drift(&fix); set_level(fix.u, SK_SAILING, 0); @@ -393,7 +395,6 @@ static void test_ship_ridiculous_overload_no_captain(CuTest *tc) { static void test_ship_ridiculous_overload_bad(CuTest *tc) { struct drift_fixture fix; - test_cleanup(); setup_drift(&fix); fix.u->number = 500; @@ -607,6 +608,7 @@ 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_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_big_overload);