fix and test implementation of ship_type.minskill

This commit is contained in:
Enno Rehling 2019-08-18 12:13:51 +02:00
parent e616449fd0
commit 5264b6e4f5
2 changed files with 33 additions and 22 deletions

View File

@ -318,7 +318,10 @@ int crew_skill(const ship *sh) {
for (u = sh->region->units; u; u = u->next) {
if (u->ship == sh) {
n += effskill(u, SK_SAILING, NULL) * u->number;
int es = effskill(u, SK_SAILING, NULL);
if (es >= sh->type->minskill) {
n += es * u->number;
}
}
}
return n;

View File

@ -384,27 +384,6 @@ static void test_stype_defaults(CuTest *tc) {
test_teardown();
}
static void test_crew_skill(CuTest *tc) {
ship *sh;
region *r;
struct faction *f;
int i;
test_setup();
test_create_world();
r = test_create_region(0, 0, NULL);
f = test_create_faction(NULL);
assert(r && f);
sh = test_create_ship(r, st_find("boat"));
for (i = 0; i != 4; ++i) {
unit * u = test_create_unit(f, r);
set_level(u, SK_SAILING, 5);
u->ship = sh;
}
CuAssertIntEquals(tc, 20, crew_skill(sh));
test_teardown();
}
static ship *setup_ship(void) {
region *r;
ship_type *stype;
@ -651,6 +630,35 @@ static void test_shipspeed_max_range(CuTest *tc) {
test_teardown();
}
static void test_crew_skill(CuTest *tc) {
ship_type *stype;
ship * sh;
unit *u;
region *r;
test_setup();
stype = test_create_shiptype("kayak");
CuAssertIntEquals(tc, 1, stype->minskill);
r = test_create_ocean(0, 0);
sh = test_create_ship(r, stype);
CuAssertIntEquals(tc, 0, crew_skill(sh));
u = test_create_unit(test_create_faction(NULL), r);
set_level(u, SK_SAILING, 1);
CuAssertIntEquals(tc, 0, crew_skill(sh));
u_set_ship(u, sh);
set_level(u, SK_SAILING, 1);
CuAssertIntEquals(tc, 1, crew_skill(sh));
set_number(u, 10);
CuAssertIntEquals(tc, 10, crew_skill(sh));
stype->minskill = 2;
CuAssertIntEquals(tc, 0, crew_skill(sh));
set_level(u, SK_SAILING, 2);
CuAssertIntEquals(tc, 20, crew_skill(sh));
set_level(u, SK_SAILING, 3);
CuAssertIntEquals(tc, 30, crew_skill(sh));
test_teardown();
}
CuSuite *get_ship_suite(void)
{
CuSuite *suite = CuSuiteNew();