set_origin: renaming German function name to English, add a simple test for it.

This commit is contained in:
Enno Rehling 2015-05-05 09:33:59 -07:00
parent 42783ff02c
commit 03084a7ee7
7 changed files with 24 additions and 8 deletions

View File

@ -297,7 +297,7 @@ static int tolua_faction_set_origin(lua_State * L)
plane *pl = rplane(r);
int id = pl ? pl->id : 0;
set_ursprung(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
set_origin(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
return 0;
}

View File

@ -257,7 +257,7 @@ unit *addplayer(region * r, faction * f)
char buffer[32];
assert(f->units == NULL);
set_ursprung(f, 0, r->x, r->y);
set_origin(f, 0, r->x, r->y);
u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
equip_items(&u->faction->items, get_equipment("new_faction"));
equip_unit(u, get_equipment("first_unit"));

View File

@ -4,6 +4,7 @@
#include <kernel/faction.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/plane.h>
#include <kernel/config.h>
#include <util/language.h>
@ -109,6 +110,20 @@ static void test_get_monsters(CuTest *tc) {
test_cleanup();
}
static void test_set_origin(CuTest *tc) {
faction *f;
test_cleanup();
test_create_world();
f = test_create_faction(0);
CuAssertPtrEquals(tc, 0, f->ursprung);
set_origin(f, 0, 1, 1);
CuAssertIntEquals(tc, 0, f->ursprung->id);
CuAssertIntEquals(tc, 1, f->ursprung->x);
CuAssertIntEquals(tc, 1, f->ursprung->y);
test_cleanup();
}
CuSuite *get_faction_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -117,5 +132,6 @@ CuSuite *get_faction_suite(void)
SUITE_ADD_TEST(suite, test_remove_empty_factions_allies);
SUITE_ADD_TEST(suite, test_remove_dead_factions);
SUITE_ADD_TEST(suite, test_get_monsters);
SUITE_ADD_TEST(suite, test_set_origin);
return suite;
}

View File

@ -136,7 +136,7 @@ ursprung_x(const faction * f, const plane * pl, const region * rdefault)
}
if (!rdefault)
return 0;
set_ursprung((faction *)f, id, rdefault->x - plane_center_x(pl),
set_origin((faction *)f, id, rdefault->x - plane_center_x(pl),
rdefault->y - plane_center_y(pl));
return rdefault->x - plane_center_x(pl);
}
@ -159,7 +159,7 @@ ursprung_y(const faction * f, const plane * pl, const region * rdefault)
}
if (!rdefault)
return 0;
set_ursprung((faction *)f, id, rdefault->x - plane_center_x(pl),
set_origin((faction *)f, id, rdefault->x - plane_center_x(pl),
rdefault->y - plane_center_y(pl));
return rdefault->y - plane_center_y(pl);
}
@ -221,7 +221,7 @@ const region * r)
*y = ny;
}
void set_ursprung(faction * f, int id, int x, int y)
void set_origin(faction * f, int id, int x, int y)
{
ursprung *ur;
assert(f != NULL);

View File

@ -70,7 +70,7 @@ extern "C" {
struct plane *getplanebyid(int id);
int plane_center_x(const struct plane *pl);
int plane_center_y(const struct plane *pl);
void set_ursprung(struct faction *f, int id, int x, int y);
void set_origin(struct faction *f, int id, int x, int y);
struct plane *create_new_plane(int id, const char *name, int minx, int maxx,
int miny, int maxy, int flags);
struct plane *getplanebyname(const char *);

View File

@ -1250,7 +1250,7 @@ faction *readfaction(struct gamedata * data)
READ_INT(data->store, &id);
READ_INT(data->store, &ux);
READ_INT(data->store, &uy);
set_ursprung(f, id, ux, uy);
set_origin(f, id, ux, uy);
}
f->newbies = 0;

View File

@ -2544,7 +2544,7 @@ int origin_cmd(unit * u, struct order *ord)
px = (short)getint();
py = (short)getint();
set_ursprung(u->faction, getplaneid(u->region), px, py);
set_origin(u->faction, getplaneid(u->region), px, py);
return 0;
}