static void setup_piracy(void) { struct locale *lang; ship_type *st_boat; config_set("rules.ship.storms", "0"); lang = get_or_create_locale("de"); locale_setstring(lang, directions[D_EAST], "OSTEN"); init_directions(lang); test_create_terrain("ocean", SEA_REGION); st_boat = test_create_shiptype("boat"); st_boat->cargo = 1000; mt_create_error(144); mt_create_error(146); mt_create_va(mt_new("piratenovictim", NULL), "ship:ship", "unit:unit", "region:region", MT_NEW_END); mt_create_va(mt_new("piratesawvictim", NULL), "ship:ship", "unit:unit", "region:region", "dir:int", MT_NEW_END); mt_create_va(mt_new("shipsail", NULL), "ship:ship", "from:region", "to:region", MT_NEW_END); mt_create_va(mt_new("shipfly", NULL), "ship:ship", "from:region", "to:region", MT_NEW_END); mt_create_va(mt_new("shipnoshore", NULL), "ship:ship", "region:region", MT_NEW_END); mt_create_va(mt_new("travel", NULL), "unit:unit", "start:region", "end:region", "mode:int", "regions:regions", MT_NEW_END); }
static void test_shipspeed_speedy(CuTest *tc) { ship_type *stype; ship *sh; unit *cap, *crw; test_setup(); stype = test_create_shiptype("dragonship"); stype->range = 5; stype->range_max = -1; stype->flags |= SFL_SPEEDY; cap = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); crw = test_create_unit(cap->faction, cap->region); sh = test_create_ship(cap->region, stype); cap->ship = sh; crw->ship = sh; set_level(cap, SK_SAILING, stype->cptskill); set_level(crw, SK_SAILING, stype->sumskill - stype->cptskill); CuAssertPtrEquals(tc, cap, ship_owner(sh)); 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(); }
static void test_piracy_cmd_land_to_land(CuTest * tc) { unit *u; region *r; faction *f; int target; const terrain_type *t_plain; const ship_type *stype; test_setup(); setup_piracy(); t_plain = get_or_create_terrain("plain"); stype = test_create_shiptype("boat"); /* create a target: */ r = test_create_region(0, 0, t_plain); f = test_create_faction(NULL); u = test_create_unit(f, r); u->ship = test_create_ship(r, stype); target = f->no; /* create a pirate: */ r = test_create_region(1, 0, t_plain); f = test_create_faction(NULL); u = test_create_unit(f, r); u->ship = test_create_ship(r, stype); set_level(u, SK_SAILING, u->ship->type->sumskill); u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(target)); piracy_cmd(u); CuAssertPtrEquals(tc, NULL, u->thisorder); CuAssertPtrEquals(tc, r, u->region); test_teardown(); }
static void test_sabotage_other_fail(CuTest *tc) { unit *u, *u2; region *r; order *ord; message *msg; setup_sabotage(); r = test_create_region(0, 0, 0); assert(r); u = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(test_create_faction(NULL), r); assert(u && u2); u2->ship = test_create_ship(r, test_create_shiptype("boat")); assert(u2->ship); u->ship = u2->ship; ship_update_owner(u->ship); assert(ship_owner(u->ship) == u); ord = create_order(K_SABOTAGE, u->faction->locale, "SCHIFF"); assert(ord); CuAssertIntEquals(tc, 0, sabotage_cmd(u2, ord)); msg = test_get_last_message(u2->faction->msgs); CuAssertStrEquals(tc, "destroy_ship_1", test_get_messagetype(msg)); msg = test_get_last_message(u->faction->msgs); CuAssertStrEquals(tc, "destroy_ship_3", test_get_messagetype(msg)); CuAssertPtrNotNull(tc, r->ships); free_order(ord); test_cleanup(); }
static ship *setup_ship(void) { region *r; ship_type *stype; config_set("movement.shipspeed.skillbonus", "0"); r = test_create_ocean(0, 0); stype = test_create_shiptype("longboat"); stype->cptskill = 1; stype->sumskill = 10; stype->minskill = 1; stype->range = 2; stype->range_max = 4; return test_create_ship(r, stype); }
static ship *setup_ship(void) { region *r; ship_type *stype; set_param(&global.parameters, "movement.shipspeed.skillbonus", "0"); r = test_create_region(0, 0, test_create_terrain("ocean", 0)); stype = test_create_shiptype("longboat"); stype->cptskill = 1; stype->sumskill = 10; stype->minskill = 1; stype->range = 2; stype->range_max = 4; return test_create_ship(r, stype); }
static void test_sabotage_self(CuTest *tc) { unit *u; region *r; order *ord; setup_sabotage(); r = test_create_region(0, 0, 0); assert(r); u = test_create_unit(test_create_faction(NULL), r); assert(u && u->faction && u->region == r); u->ship = test_create_ship(r, test_create_shiptype("boat")); assert(u->ship); ord = create_order(K_SABOTAGE, u->faction->locale, "SCHIFF"); assert(ord); CuAssertIntEquals(tc, 0, sabotage_cmd(u, ord)); CuAssertPtrEquals(tc, 0, r->ships); free_order(ord); test_cleanup(); }
/** creates a small world and some stuff in it. * two terrains: 'plain' and 'ocean' * one race: 'human' * one ship_type: 'boat' * one building_type: 'castle' * in 0.0 and 1.0 is an island of two plains, around it is ocean. */ void test_create_world(void) { terrain_type *t_plain, *t_ocean; region *island[2]; int i; const char * names[] = { "horse", "horse_p", "boat", "boat_p", "iron", "iron_p", "stone", "stone_p" }; make_locale("de"); init_resources(); assert(!olditemtype[I_HORSE]); olditemtype[I_HORSE] = test_create_itemtype(names+0); olditemtype[I_IRON] = test_create_itemtype(names+4); olditemtype[I_STONE] = test_create_itemtype(names+6); t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION); t_plain->size = 1000; t_ocean = test_create_terrain("ocean", SEA_REGION | SAIL_INTO | SWIM_INTO); t_ocean->size = 0; island[0] = test_create_region(0, 0, t_plain); island[1] = test_create_region(1, 0, t_plain); for (i = 0; i != 2; ++i) { int j; region *r = island[i]; for (j = 0; j != MAXDIRECTIONS; ++j) { region *rn = r_connect(r, (direction_t)j); if (!rn) { rn = test_create_region(r->x + delta_x[j], r->y + delta_y[j], t_ocean); } } } test_create_race("human"); test_create_buildingtype("castle"); test_create_shiptype(names+2); }
static void test_sabotage_other_success(CuTest *tc) { unit *u, *u2; region *r; order *ord; setup_sabotage(); r = test_create_region(0, 0, 0); assert(r); u = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(test_create_faction(NULL), r); assert(u && u2); u2->ship = test_create_ship(r, test_create_shiptype("boat")); assert(u2->ship); u->ship = u2->ship; ship_update_owner(u->ship); assert(ship_owner(u->ship) == u); ord = create_order(K_SABOTAGE, u->faction->locale, "SCHIFF"); assert(ord); set_level(u2, SK_SPY, 1); CuAssertIntEquals(tc, 0, sabotage_cmd(u2, ord)); CuAssertPtrEquals(tc, 0, r->ships); free_order(ord); test_cleanup(); }