static void test_set_origin(CuTest *tc) { faction *f; int x = 0, y = 0; plane *pl; test_cleanup(); test_create_world(); pl = create_new_plane(0, "", 0, 19, 0, 19, 0); f = test_create_faction(0); CuAssertPtrEquals(tc, 0, f->ursprung); faction_setorigin(f, 0, 1, 1); CuAssertIntEquals(tc, 0, f->ursprung->id); CuAssertIntEquals(tc, 1, f->ursprung->x); CuAssertIntEquals(tc, 1, f->ursprung->y); faction_getorigin(f, 0, &x, &y); CuAssertIntEquals(tc, 1, x); CuAssertIntEquals(tc, 1, y); adjust_coordinates(f, &x, &y, pl); CuAssertIntEquals(tc, -9, x); CuAssertIntEquals(tc, -9, y); adjust_coordinates(f, &x, &y, 0); CuAssertIntEquals(tc, -10, x); CuAssertIntEquals(tc, -10, y); test_cleanup(); }
static void test_origin(CuTest *tc) { struct faction *f; int x, y; test_setup(); f = test_create_faction(NULL); x = 0; y = 0; adjust_coordinates(f, &x, &y, 0); CuAssertIntEquals(tc, 0, x); CuAssertIntEquals(tc, 0, y); faction_setorigin(f, 0, 10, 20); adjust_coordinates(f, &x, &y, 0); CuAssertIntEquals(tc, -10, x); CuAssertIntEquals(tc, -20, y); test_teardown(); }
static int tolua_faction_normalize(lua_State * L) { faction *f = (faction *)tolua_tousertype(L, 1, 0); region *r = (region *)tolua_tousertype(L, 2, 0); if (r) { plane *pl = rplane(r); int nx = r->x, ny = r->y; pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl, r); tolua_pushnumber(L, (lua_Number)nx); tolua_pushnumber(L, (lua_Number)ny); return 2; } return 0; }
const char *write_regionname(const region * r, const faction * f, char *buffer, size_t size) { char *buf = (char *)buffer; const struct locale *lang = f ? f->locale : 0; if (r == NULL) { strlcpy(buf, "(null)", size); } else { plane *pl = rplane(r); int nx = r->x, ny = r->y; pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl, r); slprintf(buf, size, "%s (%d,%d)", rname(r, lang), nx, ny); } return buffer; }
static void test_set_origin_bug(CuTest *tc) { faction *f; plane *pl; int x = 17, y = 10; test_cleanup(); test_create_world(); pl = create_new_plane(0, "", 0, 19, 0, 19, 0); f = test_create_faction(0); faction_setorigin(f, 0, -10, 3); faction_setorigin(f, 0, -13, -4); adjust_coordinates(f, &x, &y, pl); CuAssertIntEquals(tc, 0, f->ursprung->id); CuAssertIntEquals(tc, -9, x); CuAssertIntEquals(tc, 2, y); test_cleanup(); }