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(); }
void leave_ship(unit * u) { struct ship *sh = u->ship; u->ship = 0; if (sh->_owner==u) { ship_update_owner(sh); sh->_owner = ship_owner(sh); } set_leftship(u, sh); }
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(); }