forked from github/server
Bug 2509 contd: new_region still creating duplicates
This commit is contained in:
parent
6c11e740ff
commit
8bcdb5c381
5 changed files with 28 additions and 32 deletions
|
@ -448,7 +448,7 @@ static int tolua_region_create(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
assert(!pnormalize(&x, &y, pl));
|
||||
pnormalize(&x, &y, pl);
|
||||
r = result = findregion(x, y);
|
||||
|
||||
if (r != NULL && r->units != NULL) {
|
||||
|
|
|
@ -481,7 +481,7 @@ static int tolua_get_region(lua_State * L)
|
|||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
region *r;
|
||||
assert(!pnormalize(&x, &y, findplane(x, y)));
|
||||
pnormalize(&x, &y, findplane(x, y));
|
||||
r = findregion(x, y);
|
||||
tolua_pushusertype(L, r, TOLUA_CAST "region");
|
||||
return 1;
|
||||
|
|
|
@ -268,7 +268,7 @@ static int hash_requests;
|
|||
static int hash_misses;
|
||||
#endif
|
||||
|
||||
bool pnormalize(int *x, int *y, const plane * pl)
|
||||
void pnormalize(int *x, int *y, const plane * pl)
|
||||
{
|
||||
if (pl) {
|
||||
if (x) {
|
||||
|
@ -284,7 +284,6 @@ bool pnormalize(int *x, int *y, const plane * pl)
|
|||
*y = ny % height + pl->miny;
|
||||
}
|
||||
}
|
||||
return false; /* TBD */
|
||||
}
|
||||
|
||||
static region *rfindhash(int x, int y)
|
||||
|
@ -343,8 +342,9 @@ region *r_connect(const region * r, direction_t dir)
|
|||
int x, y;
|
||||
region *rmodify = (region *)r;
|
||||
assert(dir >= 0 && dir < MAXDIRECTIONS);
|
||||
if (r->connect[dir])
|
||||
if (r->connect[dir]) {
|
||||
return r->connect[dir];
|
||||
}
|
||||
assert(dir < MAXDIRECTIONS);
|
||||
x = r->x + delta_x[dir];
|
||||
y = r->y + delta_y[dir];
|
||||
|
@ -757,10 +757,6 @@ int rsettrees(const region * r, int ageclass, int value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static region *last;
|
||||
|
||||
static unsigned int max_index = 0;
|
||||
|
||||
region *region_create(int uid)
|
||||
{
|
||||
region *r = (region *)calloc(1, sizeof(region));
|
||||
|
@ -770,16 +766,13 @@ region *region_create(int uid)
|
|||
return r;
|
||||
}
|
||||
|
||||
region *new_region(int x, int y, struct plane *pl, int uid)
|
||||
{
|
||||
region *r;
|
||||
static region *last;
|
||||
static unsigned int max_index;
|
||||
|
||||
pnormalize(&x, &y, pl);
|
||||
r = region_create(uid);
|
||||
void add_region(region *r, int x, int y) {
|
||||
r->x = x;
|
||||
r->y = y;
|
||||
r->age = 1;
|
||||
r->_plane = pl;
|
||||
r->_plane = findplane(x, y);
|
||||
rhash(r);
|
||||
if (last) {
|
||||
addlist(&last, r);
|
||||
|
@ -790,6 +783,15 @@ region *new_region(int x, int y, struct plane *pl, int uid)
|
|||
last = r;
|
||||
assert(r->next == NULL);
|
||||
r->index = ++max_index;
|
||||
}
|
||||
|
||||
region *new_region(int x, int y, struct plane *pl, int uid)
|
||||
{
|
||||
region *r;
|
||||
r = region_create(uid);
|
||||
r->age = 1;
|
||||
add_region(r, x, y);
|
||||
assert(pl == r->_plane);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -226,11 +226,12 @@ extern "C" {
|
|||
char *buffer, size_t size);
|
||||
|
||||
struct region *region_create(int uid);
|
||||
void add_region(region *r, int x, int y);
|
||||
struct region *new_region(int x, int y, struct plane *pl, int uid);
|
||||
void remove_region(region ** rlist, region * r);
|
||||
void terraform_region(struct region *r, const struct terrain_type *terrain);
|
||||
void init_region(struct region *r);
|
||||
bool pnormalize(int *x, int *y, const struct plane *pl);
|
||||
void pnormalize(int *x, int *y, const struct plane *pl);
|
||||
|
||||
extern const int delta_x[MAXDIRECTIONS];
|
||||
extern const int delta_y[MAXDIRECTIONS];
|
||||
|
|
|
@ -624,24 +624,17 @@ static region *readregion(gamedata *data, int x, int y)
|
|||
READ_INT(data->store, &uid);
|
||||
r = findregionbyid(uid);
|
||||
if (r == NULL) {
|
||||
plane *pl = findplane(x, y);
|
||||
r = new_region(x, y, pl, uid);
|
||||
r = region_create(uid);
|
||||
}
|
||||
else {
|
||||
assert(uid == 0 || r->uid == uid);
|
||||
while (r->attribs)
|
||||
a_remove(&r->attribs, r->attribs);
|
||||
if (r->land) {
|
||||
free_land(r->land);
|
||||
r->land = 0;
|
||||
}
|
||||
while (r->resources) {
|
||||
rawmaterial *rm = r->resources;
|
||||
r->resources = rm->next;
|
||||
free(rm);
|
||||
}
|
||||
r->land = 0;
|
||||
/* make sure this was not read earlier */
|
||||
assert(r->next == NULL);
|
||||
assert(r->attribs == NULL);
|
||||
assert(r->land == NULL);
|
||||
assert(r->resources == NULL);
|
||||
}
|
||||
/* add region to the global list: */
|
||||
add_region(r, x, y);
|
||||
if (data->version < LANDDISPLAY_VERSION) {
|
||||
read_regioninfo(data, r, info, sizeof(info));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue