forked from github/server
implement speedy ships, with unit tests and edge testing.
This commit is contained in:
parent
c2167c963e
commit
198f084f5d
3 changed files with 35 additions and 13 deletions
|
@ -58,25 +58,20 @@ function test_speedy_ship_slow()
|
||||||
u2:set_skill("sailing", 24) -- sumskill = 50
|
u2:set_skill("sailing", 24) -- sumskill = 50
|
||||||
u1.name = "XXX"
|
u1.name = "XXX"
|
||||||
u1:add_order("NACH O O O O O O O O O O")
|
u1:add_order("NACH O O O O O O O O O O")
|
||||||
print(u1.region)
|
|
||||||
process_orders()
|
process_orders()
|
||||||
print(u1.region)
|
|
||||||
assert_equal(5, u1.region.x)
|
assert_equal(5, u1.region.x)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test_speedy_ship_fast()
|
function test_speedy_ship_fast()
|
||||||
local r1 = region.create(0, 0, 'ocean')
|
local r1 = region.create(0, 0, 'ocean')
|
||||||
local f = faction.create("human")
|
local f = faction.create("human")
|
||||||
f.name="Vikings"
|
|
||||||
local u1 = unit.create(f, r1, 1)
|
local u1 = unit.create(f, r1, 1)
|
||||||
u1.name = "Hagar"
|
|
||||||
for x = 1, 10 do
|
for x = 1, 10 do
|
||||||
region.create(x, 0, 'ocean')
|
region.create(x, 0, 'ocean')
|
||||||
end
|
end
|
||||||
u1.ship = ship.create(r1, "dragonship")
|
u1.ship = ship.create(r1, "dragonship")
|
||||||
u1:set_skill("sailing", 64) -- cptskill = 2^6
|
u1:set_skill("sailing", 54) -- cptskill = 2*3^3
|
||||||
u1:add_order("NACH O O O O O O O O O O")
|
u1:add_order("NACH O O O O O O O O O O")
|
||||||
process_orders()
|
process_orders()
|
||||||
print(f, get_turn())
|
assert_equal(8, u1.region.x)
|
||||||
assert_equal(10, u1.region.x)
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -288,12 +288,28 @@ const char *write_shipname(const ship * sh, char *ibuf, size_t size)
|
||||||
|
|
||||||
static int ShipSpeedBonus(const unit * u)
|
static int ShipSpeedBonus(const unit * u)
|
||||||
{
|
{
|
||||||
int level = config_get_int("movement.shipspeed.skillbonus", 0);
|
const ship * sh = u->ship;
|
||||||
if (level > 0) {
|
static int config;
|
||||||
ship *sh = u->ship;
|
static int bonus;
|
||||||
|
|
||||||
|
if (config_changed(&config)) {
|
||||||
|
bonus = config_get_int("movement.shipspeed.skillbonus", 0);
|
||||||
|
}
|
||||||
|
if (bonus > 0) {
|
||||||
int skl = effskill(u, SK_SAILING, 0);
|
int skl = effskill(u, SK_SAILING, 0);
|
||||||
int minsk = (sh->type->cptskill + 1) / 2;
|
int minsk = (sh->type->cptskill + 1) / 2;
|
||||||
return (skl - minsk) / level;
|
return (skl - minsk) / bonus;
|
||||||
|
}
|
||||||
|
else if (sh->type->flags & SFL_SPEEDY) {
|
||||||
|
int base = 3;
|
||||||
|
int speed = 0;
|
||||||
|
int minsk = sh->type->cptskill * base;
|
||||||
|
int skl = effskill(u, SK_SAILING, 0);
|
||||||
|
while (skl >= minsk) {
|
||||||
|
++speed;
|
||||||
|
minsk *= base;
|
||||||
|
}
|
||||||
|
return speed;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -438,7 +438,7 @@ static void test_shipspeed_speedy(CuTest *tc) {
|
||||||
unit *cap, *crw;
|
unit *cap, *crw;
|
||||||
test_setup();
|
test_setup();
|
||||||
stype = test_create_shiptype("dragonship");
|
stype = test_create_shiptype("dragonship");
|
||||||
stype->range = 2;
|
stype->range = 5;
|
||||||
stype->range_max = -1;
|
stype->range_max = -1;
|
||||||
stype->flags |= SFL_SPEEDY;
|
stype->flags |= SFL_SPEEDY;
|
||||||
cap = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
cap = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
|
@ -449,7 +449,18 @@ static void test_shipspeed_speedy(CuTest *tc) {
|
||||||
set_level(cap, SK_SAILING, stype->cptskill);
|
set_level(cap, SK_SAILING, stype->cptskill);
|
||||||
set_level(crw, SK_SAILING, stype->sumskill - stype->cptskill);
|
set_level(crw, SK_SAILING, stype->sumskill - stype->cptskill);
|
||||||
CuAssertPtrEquals(tc, cap, ship_owner(sh));
|
CuAssertPtrEquals(tc, cap, ship_owner(sh));
|
||||||
CuAssertIntEquals(tc, 2, shipspeed(sh, cap));
|
CuAssertIntEquals(tc, 5, shipspeed(sh, cap));
|
||||||
|
|
||||||
|
set_level(cap, SK_SAILING, stype->cptskill * 3 - 1);
|
||||||
|
CuAssertIntEquals(tc, 5, shipspeed(sh, cap));
|
||||||
|
set_level(cap, SK_SAILING, stype->cptskill * 3);
|
||||||
|
CuAssertIntEquals(tc, 6, shipspeed(sh, cap));
|
||||||
|
|
||||||
|
set_level(cap, SK_SAILING, stype->cptskill * 3 * 3 - 1);
|
||||||
|
CuAssertIntEquals(tc, 6, shipspeed(sh, cap));
|
||||||
|
set_level(cap, SK_SAILING, stype->cptskill * 3 * 3);
|
||||||
|
CuAssertIntEquals(tc, 7, shipspeed(sh, cap));
|
||||||
|
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue