From a7a82662b7598099097ba3fe14e83f60f7170ed3 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Tue, 17 Nov 2015 15:47:43 +0100 Subject: [PATCH] reduce maximum overload damage to 38% --- src/kernel/ship.c | 4 ++++ src/kernel/ship.h | 2 ++ src/move.c | 18 +++++++++--------- src/move.h | 2 ++ src/move.test.c | 35 +++++++++++++++++++++++------------ src/report.c | 3 +-- 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/kernel/ship.c b/src/kernel/ship.c index b1c0e1725..40198068a 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -469,3 +469,7 @@ const char *ship_getname(const ship * self) { return self->name; } + +int ship_damage_percent(const ship *ship) { + return (ship->damage * 100 + DAMAGE_SCALE - 1) / (ship->size * DAMAGE_SCALE); +} diff --git a/src/kernel/ship.h b/src/kernel/ship.h index 6ba2de75d..73b8a9718 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -126,6 +126,8 @@ extern "C" { void ship_setname(struct ship *self, const char *name); int shipspeed(const struct ship *sh, const struct unit *u); int crew_skill(const struct ship *sh); + + int ship_damage_percent(const struct ship *ship); #ifdef __cplusplus } #endif diff --git a/src/move.c b/src/move.c index ccb58ac9a..26b536aed 100644 --- a/src/move.c +++ b/src/move.c @@ -721,13 +721,13 @@ static float damage_drift(void) return value; } -static float damage_overload(void) +static double damage_overload(double overload) { - static float value = -1.0F; - if (value < 0) { - value = (float)get_param_flt(global.parameters, "rules.ship.damage_overload", 0.3F); - } - return value; + static double damage; + damage = get_param_flt(global.parameters, "rules.ship.damage_overload_min", 0.2); + damage *= overload - OVERLOAD_THRESHOLD + 1; + damage = _min(damage, get_param_flt(global.parameters, "rules.ship.damage_overload_max", 0.37)); + return damage; } /* message to all factions in ship, start from firstu, end before lastu (may be NULL) */ @@ -794,7 +794,7 @@ static void drifting_ships(region * r) } ovl = overload(r, sh); - if (ovl >= 2) { + if (ovl >= OVERLOAD_THRESHOLD) { rnext = NULL; } else { /* Auswahl einer Richtung: Zuerst auf Land, dann @@ -830,8 +830,8 @@ static void drifting_ships(region * r) if (sh != NULL) { fset(sh, SF_DRIFTED); - if (ovl >= 2) { - damage_ship(sh, (ovl - 1) * damage_overload()); + if (ovl >= OVERLOAD_THRESHOLD) { + damage_ship(sh, damage_overload(ovl)); msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh)); } else damage_ship(sh, damage_drift()); diff --git a/src/move.h b/src/move.h index c0b92d071..2f93bcd0a 100644 --- a/src/move.h +++ b/src/move.h @@ -42,6 +42,8 @@ extern "C" { #define HORSESNEEDED 2 #define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */ +#define OVERLOAD_THRESHOLD 1.5 + /* ein mensch wiegt 10, traegt also 5, ein pferd wiegt 50, traegt also 20. ein ** wagen wird von zwei pferden gezogen und traegt total 140, davon 40 die ** pferde, macht nur noch 100, aber samt eigenem gewicht (40) macht also 140. */ diff --git a/src/move.test.c b/src/move.test.c index d0a91b9b9..f1aefa34b 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -314,7 +314,7 @@ void setup_drift (struct drift_fixture *fix) { test_create_world(); fix->st_boat = st_get_or_create("boat"); - fix->st_boat->cabins = 2000; + fix->st_boat->cabins = 10000; fix->u = test_create_unit(fix->f = test_create_faction(0), fix->r=findregion(-1,0)); assert(fix->r && fix->r->terrain->flags & SAIL_INTO); set_level(fix->u, SK_SAILING, fix->st_boat->sumskill); @@ -338,10 +338,10 @@ static void test_ship_normal_overload(CuTest *tc) { struct drift_fixture fix; setup_drift(&fix); - fix.u->number = 3; + fix.u->number = 12; movement(); CuAssertPtrEquals(tc, fix.u->region, findregion(0, 0)); - CuAssertDblEquals(tc, (double) (fix.sh->size * DAMAGE_SCALE * .02), (double ) fix.sh->damage, ASSERT_DBL_DELTA); + CuAssertIntEquals(tc, 2, ship_damage_percent(fix.sh)); CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "ship_drift")); } @@ -349,10 +349,10 @@ static void test_ship_big_overload(CuTest *tc) { struct drift_fixture fix; setup_drift(&fix); - fix.u->number = 4; + fix.u->number = 15; movement(); CuAssertPtrEquals(tc, fix.u->region, findregion(-1, 0)); - CuAssertDblEquals(tc, (double) (fix.sh->size * DAMAGE_SCALE * .3), (double ) fix.sh->damage, ASSERT_DBL_DELTA); + CuAssertIntEquals(tc, 20, ship_damage_percent(fix.sh)); CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload")); } @@ -360,11 +360,11 @@ static void test_ship_no_real_overload(CuTest *tc) { struct drift_fixture fix; setup_drift(&fix); - fix.u->number = 3; + fix.u->number = 12; damage_ship(fix.sh, .80); movement(); CuAssertPtrEquals(tc, fix.u->region, findregion(0, 0)); - CuAssertDblEquals(tc, (double) (fix.sh->size * DAMAGE_SCALE * .82), (double ) fix.sh->damage, ASSERT_DBL_DELTA); + CuAssertIntEquals(tc, 82, ship_damage_percent(fix.sh)); CuAssertPtrEquals(tc, 0, test_find_messagetype(fix.f->msgs, "massive_overload")); } @@ -374,10 +374,8 @@ static void test_ship_ridiculous_overload(CuTest *tc) { fix.u->number = 100; movement(); - CuAssertTrue(tc, fix.sh->size * DAMAGE_SCALE * .2 < fix.sh->damage); - CuAssertPtrEquals(tc, 0, fix.sh->region); + CuAssertIntEquals(tc, 37, ship_damage_percent(fix.sh)); CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload")); - CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "shipsink")); } static void test_ship_ridiculous_overload_no_captain(CuTest *tc) { @@ -387,12 +385,24 @@ static void test_ship_ridiculous_overload_no_captain(CuTest *tc) { fix.u->number = 100; movement(); - CuAssertTrue(tc, fix.sh->size * DAMAGE_SCALE * .2 < fix.sh->damage); - CuAssertPtrEquals(tc, 0, fix.sh->region); + CuAssertIntEquals(tc, 37, ship_damage_percent(fix.sh)); CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload")); +} + +static void test_ship_ridiculous_overload_bad(CuTest *tc) { + struct drift_fixture fix; + setup_drift(&fix); + + fix.u->number = 200; + set_param(&global.parameters, "rules.ship.damage_overload_max", "1"); + movement(); + CuAssertTrue(tc, ship_damage_percent(fix.sh) > 99); + CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload")); + CuAssertPtrEquals(tc, 0, fix.sh->region); CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "shipsink")); } + CuSuite *get_move_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -412,6 +422,7 @@ CuSuite *get_move_suite(void) SUITE_ADD_TEST(suite, test_ship_no_real_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); SUITE_ADD_TEST(suite, test_ship_ridiculous_overload_no_captain); return suite; } diff --git a/src/report.c b/src/report.c index f157a75f4..291356b40 100644 --- a/src/report.c +++ b/src/report.c @@ -1804,8 +1804,7 @@ const unit * captain) WARN_STATIC_BUFFER(); } if (sh->damage) { - int percent = - (sh->damage * 100 + DAMAGE_SCALE - 1) / (sh->size * DAMAGE_SCALE); + int percent = ship_damage_percent(sh); bytes = _snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); if (wrptr(&bufp, &size, bytes) != 0)