forked from github/server
reduce maximum overload damage to 38%
This commit is contained in:
parent
3a18384ddb
commit
a7a82662b7
6 changed files with 41 additions and 23 deletions
|
@ -469,3 +469,7 @@ const char *ship_getname(const ship * self)
|
||||||
{
|
{
|
||||||
return self->name;
|
return self->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ship_damage_percent(const ship *ship) {
|
||||||
|
return (ship->damage * 100 + DAMAGE_SCALE - 1) / (ship->size * DAMAGE_SCALE);
|
||||||
|
}
|
||||||
|
|
|
@ -126,6 +126,8 @@ extern "C" {
|
||||||
void ship_setname(struct ship *self, const char *name);
|
void ship_setname(struct ship *self, const char *name);
|
||||||
int shipspeed(const struct ship *sh, const struct unit *u);
|
int shipspeed(const struct ship *sh, const struct unit *u);
|
||||||
int crew_skill(const struct ship *sh);
|
int crew_skill(const struct ship *sh);
|
||||||
|
|
||||||
|
int ship_damage_percent(const struct ship *ship);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
18
src/move.c
18
src/move.c
|
@ -721,13 +721,13 @@ static float damage_drift(void)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float damage_overload(void)
|
static double damage_overload(double overload)
|
||||||
{
|
{
|
||||||
static float value = -1.0F;
|
static double damage;
|
||||||
if (value < 0) {
|
damage = get_param_flt(global.parameters, "rules.ship.damage_overload_min", 0.2);
|
||||||
value = (float)get_param_flt(global.parameters, "rules.ship.damage_overload", 0.3F);
|
damage *= overload - OVERLOAD_THRESHOLD + 1;
|
||||||
}
|
damage = _min(damage, get_param_flt(global.parameters, "rules.ship.damage_overload_max", 0.37));
|
||||||
return value;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* message to all factions in ship, start from firstu, end before lastu (may be NULL) */
|
/* 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);
|
ovl = overload(r, sh);
|
||||||
if (ovl >= 2) {
|
if (ovl >= OVERLOAD_THRESHOLD) {
|
||||||
rnext = NULL;
|
rnext = NULL;
|
||||||
} else {
|
} else {
|
||||||
/* Auswahl einer Richtung: Zuerst auf Land, dann
|
/* Auswahl einer Richtung: Zuerst auf Land, dann
|
||||||
|
@ -830,8 +830,8 @@ static void drifting_ships(region * r)
|
||||||
|
|
||||||
if (sh != NULL) {
|
if (sh != NULL) {
|
||||||
fset(sh, SF_DRIFTED);
|
fset(sh, SF_DRIFTED);
|
||||||
if (ovl >= 2) {
|
if (ovl >= OVERLOAD_THRESHOLD) {
|
||||||
damage_ship(sh, (ovl - 1) * damage_overload());
|
damage_ship(sh, damage_overload(ovl));
|
||||||
msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh));
|
msg_to_ship_inmates(sh, &firstu, &lastu, msg_message("massive_overload", "ship", sh));
|
||||||
} else
|
} else
|
||||||
damage_ship(sh, damage_drift());
|
damage_ship(sh, damage_drift());
|
||||||
|
|
|
@ -42,6 +42,8 @@ extern "C" {
|
||||||
#define HORSESNEEDED 2
|
#define HORSESNEEDED 2
|
||||||
#define STRENGTHMULTIPLIER 50 /* multiplier for trollbelt */
|
#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
|
/* 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
|
** 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. */
|
** pferde, macht nur noch 100, aber samt eigenem gewicht (40) macht also 140. */
|
||||||
|
|
|
@ -314,7 +314,7 @@ void setup_drift (struct drift_fixture *fix) {
|
||||||
test_create_world();
|
test_create_world();
|
||||||
|
|
||||||
fix->st_boat = st_get_or_create("boat");
|
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));
|
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);
|
assert(fix->r && fix->r->terrain->flags & SAIL_INTO);
|
||||||
set_level(fix->u, SK_SAILING, fix->st_boat->sumskill);
|
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;
|
struct drift_fixture fix;
|
||||||
setup_drift(&fix);
|
setup_drift(&fix);
|
||||||
|
|
||||||
fix.u->number = 3;
|
fix.u->number = 12;
|
||||||
movement();
|
movement();
|
||||||
CuAssertPtrEquals(tc, fix.u->region, findregion(0, 0));
|
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"));
|
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;
|
struct drift_fixture fix;
|
||||||
setup_drift(&fix);
|
setup_drift(&fix);
|
||||||
|
|
||||||
fix.u->number = 4;
|
fix.u->number = 15;
|
||||||
movement();
|
movement();
|
||||||
CuAssertPtrEquals(tc, fix.u->region, findregion(-1, 0));
|
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"));
|
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;
|
struct drift_fixture fix;
|
||||||
setup_drift(&fix);
|
setup_drift(&fix);
|
||||||
|
|
||||||
fix.u->number = 3;
|
fix.u->number = 12;
|
||||||
damage_ship(fix.sh, .80);
|
damage_ship(fix.sh, .80);
|
||||||
movement();
|
movement();
|
||||||
CuAssertPtrEquals(tc, fix.u->region, findregion(0, 0));
|
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"));
|
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;
|
fix.u->number = 100;
|
||||||
movement();
|
movement();
|
||||||
CuAssertTrue(tc, fix.sh->size * DAMAGE_SCALE * .2 < fix.sh->damage);
|
CuAssertIntEquals(tc, 37, ship_damage_percent(fix.sh));
|
||||||
CuAssertPtrEquals(tc, 0, fix.sh->region);
|
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload"));
|
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) {
|
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;
|
fix.u->number = 100;
|
||||||
movement();
|
movement();
|
||||||
CuAssertTrue(tc, fix.sh->size * DAMAGE_SCALE * .2 < fix.sh->damage);
|
CuAssertIntEquals(tc, 37, ship_damage_percent(fix.sh));
|
||||||
CuAssertPtrEquals(tc, 0, fix.sh->region);
|
|
||||||
CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload"));
|
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"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "shipsink"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CuSuite *get_move_suite(void)
|
CuSuite *get_move_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
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_no_real_overload);
|
||||||
SUITE_ADD_TEST(suite, test_ship_big_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);
|
||||||
|
SUITE_ADD_TEST(suite, test_ship_ridiculous_overload_bad);
|
||||||
SUITE_ADD_TEST(suite, test_ship_ridiculous_overload_no_captain);
|
SUITE_ADD_TEST(suite, test_ship_ridiculous_overload_no_captain);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1804,8 +1804,7 @@ const unit * captain)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
if (sh->damage) {
|
if (sh->damage) {
|
||||||
int percent =
|
int percent = ship_damage_percent(sh);
|
||||||
(sh->damage * 100 + DAMAGE_SCALE - 1) / (sh->size * DAMAGE_SCALE);
|
|
||||||
bytes =
|
bytes =
|
||||||
_snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged"));
|
_snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged"));
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
|
|
Loading…
Reference in a new issue