forked from github/server
must have one captain per ship.
This commit is contained in:
parent
178f7c2e19
commit
5cf417d16d
|
@ -100,7 +100,6 @@ function test_ship_convoy_capacity()
|
|||
|
||||
u:add_order('NACH W')
|
||||
u:add_item('jewel', 39)
|
||||
u.name = 'Xolgrim'
|
||||
u.ship.number = 2
|
||||
u.number = 2
|
||||
u:set_skill('sailing', 2, true)
|
||||
|
@ -155,9 +154,9 @@ function test_ship_convoy_skill()
|
|||
assert_equal(r2, u.region)
|
||||
|
||||
u.ship.number = 2
|
||||
u:set_skill('sailing', 2, true)
|
||||
u:set_skill('sailing', 4, true)
|
||||
process_orders()
|
||||
assert_equal(r2, u.region)
|
||||
assert_equal(r2, u.region) -- not enough captains
|
||||
|
||||
u.number = 2
|
||||
u:set_skill('sailing', 2, true)
|
||||
|
|
|
@ -332,7 +332,7 @@ int shipspeed(const ship * sh, const unit * u)
|
|||
|
||||
bonus = ShipSpeedBonus(u);
|
||||
if (bonus > 0 && sh->type->range_max > sh->type->range) {
|
||||
int crew = crew_skill(sh, NULL);
|
||||
int crew = crew_skill(sh);
|
||||
int crew_bonus = (crew / sh->type->sumskill / 2) - 1;
|
||||
if (crew_bonus > 0) {
|
||||
int sbonus = sh->type->range_max - sh->type->range;
|
||||
|
@ -387,31 +387,41 @@ int enoughsailors(const ship * sh, int crew_skill)
|
|||
return crew_skill >= sh->type->sumskill * sh->number;
|
||||
}
|
||||
|
||||
int crew_skill(const ship *sh, int *o_captains) {
|
||||
int n = 0, captains = 0;
|
||||
int crew_skill(const ship *sh) {
|
||||
int n = 0;
|
||||
unit *u;
|
||||
|
||||
for (u = sh->region->units; u; u = u->next) {
|
||||
if (u->ship == sh) {
|
||||
int es = effskill(u, SK_SAILING, NULL);
|
||||
if (es >= sh->type->cptskill) {
|
||||
captains += u->number;
|
||||
}
|
||||
if (es >= sh->type->minskill) {
|
||||
n += es * u->number;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (o_captains) {
|
||||
*o_captains = captains;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
bool ship_crewed(const ship *sh)
|
||||
{
|
||||
int num_caps, crew = crew_skill(sh, &num_caps);
|
||||
return num_caps >= sh->number && enoughsailors(sh, crew);
|
||||
bool ship_crewed(const ship *sh) {
|
||||
unit *u;
|
||||
int capskill = -1, sumskill = 0;
|
||||
for (u = sh->region->units; u; u = u->next) {
|
||||
if (u->ship == sh) {
|
||||
int es = effskill(u, SK_SAILING, NULL);
|
||||
if (capskill < 0) {
|
||||
if (u->number >= sh->number) {
|
||||
capskill = es;
|
||||
}
|
||||
else {
|
||||
capskill = 0;
|
||||
}
|
||||
}
|
||||
if (es >= sh->type->minskill) {
|
||||
sumskill += es * u->number;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (capskill >= ship_captain_minskill(sh)) && (sumskill >= sh->type->sumskill * sh->number);
|
||||
}
|
||||
|
||||
int ship_capacity(const ship * sh)
|
||||
|
|
|
@ -118,7 +118,7 @@ extern "C" {
|
|||
int shipspeed(const struct ship *sh, const struct unit *u);
|
||||
|
||||
bool ship_crewed(const struct ship *sh);
|
||||
int crew_skill(const struct ship *sh, int *num_captains);
|
||||
int crew_skill(const struct ship *sh);
|
||||
int ship_captain_minskill(const struct ship *sh);
|
||||
|
||||
int ship_damage_percent(const struct ship *sh);
|
||||
|
|
|
@ -641,21 +641,21 @@ static void test_crew_skill(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, 1, stype->minskill);
|
||||
r = test_create_ocean(0, 0);
|
||||
sh = test_create_ship(r, stype);
|
||||
CuAssertIntEquals(tc, 0, crew_skill(sh, NULL));
|
||||
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, NULL));
|
||||
CuAssertIntEquals(tc, 0, crew_skill(sh));
|
||||
u_set_ship(u, sh);
|
||||
set_level(u, SK_SAILING, 1);
|
||||
CuAssertIntEquals(tc, 1, crew_skill(sh, NULL));
|
||||
CuAssertIntEquals(tc, 1, crew_skill(sh));
|
||||
set_number(u, 10);
|
||||
CuAssertIntEquals(tc, 10, crew_skill(sh, NULL));
|
||||
CuAssertIntEquals(tc, 10, crew_skill(sh));
|
||||
stype->minskill = 2;
|
||||
CuAssertIntEquals(tc, 0, crew_skill(sh, NULL));
|
||||
CuAssertIntEquals(tc, 0, crew_skill(sh));
|
||||
set_level(u, SK_SAILING, 2);
|
||||
CuAssertIntEquals(tc, 20, crew_skill(sh, NULL));
|
||||
CuAssertIntEquals(tc, 20, crew_skill(sh));
|
||||
set_level(u, SK_SAILING, 3);
|
||||
CuAssertIntEquals(tc, 30, crew_skill(sh, NULL));
|
||||
CuAssertIntEquals(tc, 30, crew_skill(sh));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue