static void test_shipspeed(CuTest *tc) { ship *sh; const ship_type *stype; unit *cap, *crew; test_setup(); sh = setup_ship(); stype = sh->type; CuAssertIntEquals_Msg(tc, "ship without a captain cannot move", 0, shipspeed(sh, NULL)); setup_crew(sh, 0, &cap, &crew); CuAssertPtrEquals(tc, cap, ship_owner(sh)); CuAssertIntEquals_Msg(tc, "ship with fully skilled crew can sail at max speed", 2, shipspeed(sh, cap)); CuAssertIntEquals_Msg(tc, "shipspeed without a hint defaults to captain", 2, shipspeed(sh, NULL)); set_level(cap, SK_SAILING, stype->cptskill + 5); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 10); CuAssertIntEquals_Msg(tc, "higher skills should not affect top speed", 2, shipspeed(sh, cap)); set_level(cap, SK_SAILING, stype->cptskill); set_level(crew, SK_SAILING, stype->sumskill - stype->cptskill); CuAssertIntEquals(tc, 2, shipspeed(sh, cap)); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 11); set_level(cap, SK_SAILING, stype->cptskill + 10); CuAssertIntEquals_Msg(tc, "regular skills should not exceed sh.range", 2, shipspeed(sh, cap)); test_teardown(); }
static void test_shipspeed_max_range(CuTest *tc) { ship *sh; ship_type *stype; region *r; struct faction *f; unit *cap, *crew; test_setup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); config_set("movement.shipspeed.skillbonus", "5"); r = sh->region; f = test_create_faction(NULL); assert(r && f); stype = st_get_or_create(sh->type->_name); set_level(cap, SK_SAILING, stype->cptskill + 4); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 4); CuAssertIntEquals_Msg(tc, "skill bonus requires at least movement.shipspeed.skillbonus points", 2, shipspeed(sh, cap)); set_level(cap, SK_SAILING, stype->cptskill + 5); set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 5); CuAssertIntEquals_Msg(tc, "skill bonus from movement.shipspeed.skillbonus", 3, shipspeed(sh, cap)); set_level(cap, SK_SAILING, stype->cptskill + 15); scale_number(crew, 15); set_level(crew, SK_SAILING, stype->sumskill - stype->cptskill); CuAssertIntEquals_Msg(tc, "skill-bonus cannot exceed max_range", 4, shipspeed(sh, cap)); test_teardown(); }
static void test_shipspeed_shipspeedup(CuTest *tc) { ship *sh; unit *cap, *crew; test_setup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); register_shipcurse(); assert(sh && cap && crew); create_curse(0, &sh->attribs, &ct_shipspeedup, 1, 1, 3, 0); CuAssertIntEquals_Msg(tc, "shipspeedup adds effect to range", sh->type->range + 3, shipspeed(sh, cap)); test_teardown(); }
static void test_shipspeed_nodrift(CuTest *tc) { ship *sh; unit *cap, *crew; test_cleanup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); register_shipcurse(); assert(sh && cap && crew); create_curse(0, &sh->attribs, ct_find("nodrift"), 1, 1, 1, 0); CuAssertIntEquals_Msg(tc, "nodrift adds +1 to range", sh->type->range + 1, shipspeed(sh, cap)); test_cleanup(); }
static void test_shipspeed_stormwind(CuTest *tc) { ship *sh; unit *cap, *crew; test_cleanup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); register_shipcurse(); assert(sh && cap && crew); create_curse(0, &sh->attribs, ct_find("stormwind"), 1, 1, 1, 0); CuAssertIntEquals_Msg(tc, "stormwind doubles ship range", sh->type->range * 2, shipspeed(sh, cap)); test_cleanup(); }
static void test_shipspeed_race_bonus(CuTest *tc) { ship *sh; unit *cap, *crew; race *rc; test_setup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); assert(sh && cap && crew); rc = rc_get_or_create(cap->_race->_name); rc->flags |= RCF_SHIPSPEED; CuAssertIntEquals_Msg(tc, "captain with RCF_SHIPSPEED adds +1 to range", sh->type->range + 1, shipspeed(sh, cap)); test_teardown(); }
static void test_shipspeed_at_speedup(CuTest *tc) { ship *sh; unit *cap, *crew; attrib *a; test_setup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); assert(sh && cap && crew); a = a_new(&at_speedup); a->data.i = 3; a_add(&sh->attribs, a); CuAssertIntEquals_Msg(tc, "at_speedup adds value to range", sh->type->range + 3, shipspeed(sh, cap)); test_teardown(); }
static void test_shipspeed_damage(CuTest *tc) { ship *sh; unit *cap, *crew; test_setup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); assert(sh && cap && crew); sh->damage = 1; CuAssertIntEquals_Msg(tc, "minimally damaged ships lose no range", 2, shipspeed(sh, cap)); sh->damage = sh->size * DAMAGE_SCALE / 2; CuAssertIntEquals_Msg(tc, "damaged ships lose range", 1, shipspeed(sh, cap)); sh->damage = sh->size * DAMAGE_SCALE; CuAssertIntEquals_Msg(tc, "fully damaged ships have no range", 0, shipspeed(sh, cap)); test_teardown(); }
static void test_shipspeed_stormwind(CuTest *tc) { ship *sh; unit *cap, *crew; test_setup(); sh = setup_ship(); setup_crew(sh, 0, &cap, &crew); register_shipcurse(); assert(sh && cap && crew); create_curse(0, &sh->attribs, &ct_stormwind, 1, 1, 1, 0); CuAssertPtrNotNull(tc, sh->attribs); CuAssertIntEquals_Msg(tc, "stormwind doubles ship range", sh->type->range * 2, shipspeed(sh, cap)); a_age(&sh->attribs, sh); CuAssertPtrEquals(tc, NULL, sh->attribs); test_teardown(); }