diff --git a/src/attributes/targetregion.c b/src/attributes/targetregion.c index 600d2e184..4f5a2101a 100644 --- a/src/attributes/targetregion.c +++ b/src/attributes/targetregion.c @@ -36,7 +36,7 @@ write_targetregion(const variant *var, const void *owner, struct storage *store) static int read_targetregion(variant *var, void *owner, gamedata *data) { - if (read_region_reference(data, (region **)&var->v, NULL) <= 0) { + if (read_region_reference(data, (region **)&var->v) <= 0) { return AT_READ_FAIL; } return AT_READ_OK; diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 62e7ab9b2..bf3c8fef0 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -229,7 +229,7 @@ int curse_read(variant *var, void *owner, gamedata *data) READ_INT(store, &c->data.i); } if (c->type->typ == CURSETYP_REGION) { - int rr = read_region_reference(data, (region **)&c->data.v, NULL); + int rr = read_region_reference(data, (region **)&c->data.v); if (ur == 0 && rr == 0 && !c->data.v) { return AT_READ_FAIL; } diff --git a/src/kernel/region.c b/src/kernel/region.c index fee51d13c..192469b8e 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -242,7 +242,7 @@ static void unhash_uid(region * r) uidhash[key].r = NULL; } -static void hash_uid(region * r) +static void rhash_uid(region * r) { int uid = r->uid; for (;;) { @@ -761,32 +761,35 @@ static region *last; static unsigned int max_index = 0; +region *region_create(int uid) +{ + region *r = (region *)calloc(1, sizeof(region)); + assert_alloc(r); + r->uid = uid; + rhash_uid(r); + return r; +} + region *new_region(int x, int y, struct plane *pl, int uid) { region *r; pnormalize(&x, &y, pl); r = rfindhash(x, y); - - if (r) { - log_error("duplicate region discovered: %s(%d,%d)\n", regionname(r, NULL), x, y); - if (r->units) - log_error("duplicate region contains units\n"); - return r; + if (!r) { + r = region_create(uid); } - r = (region *)calloc(sizeof(region), 1); - assert_alloc(r); r->x = x; r->y = y; - r->uid = uid; r->age = 1; r->_plane = pl; rhash(r); - hash_uid(r); - if (last) + if (last) { addlist(&last, r); - else + } + else { addlist(®ions, r); + } last = r; assert(r->next == NULL); r->index = ++max_index; @@ -1263,7 +1266,7 @@ void resolve_region(region *r) resolve(RESOLVE_REGION | r->uid, r); } -int read_region_reference(gamedata * data, region **rp, resolve_fun fun) +int read_region_reference(gamedata * data, region **rp) { struct storage * store = data->store; int id = 0; @@ -1271,7 +1274,7 @@ int read_region_reference(gamedata * data, region **rp, resolve_fun fun) READ_INT(store, &id); *rp = findregionbyid(id); if (*rp == NULL) { - ur_add(RESOLVE_REGION | id, (void **)rp, fun); + ur_add(RESOLVE_REGION | id, (void **)rp, NULL); } return id; } diff --git a/src/kernel/region.h b/src/kernel/region.h index bf932e9c3..436434024 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -225,6 +225,7 @@ extern "C" { const char *write_regionname(const struct region *r, const struct faction *f, char *buffer, size_t size); + struct region *region_create(int uid); 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); @@ -252,7 +253,7 @@ extern "C" { #define RESOLVE_REGION (TYP_REGION << 24) void resolve_region(region *r); void write_region_reference(const struct region *r, struct storage *store); - int read_region_reference(struct gamedata *data, region **rp, resolve_fun fun); + int read_region_reference(struct gamedata *data, region **rp); const char *regionname(const struct region *r, const struct faction *f); diff --git a/src/triggers/createunit.c b/src/triggers/createunit.c index 5adabc7ea..82155de55 100644 --- a/src/triggers/createunit.c +++ b/src/triggers/createunit.c @@ -99,7 +99,7 @@ static int createunit_read(trigger * t, gamedata *data) result = AT_READ_FAIL; } - read_region_reference(data, &td->r, NULL); + read_region_reference(data, &td->r); td->race = read_race_reference(data->store); if (!td->race) { result = AT_READ_FAIL; diff --git a/src/triggers/gate.c b/src/triggers/gate.c index 065be8cf8..bd67e56f4 100644 --- a/src/triggers/gate.c +++ b/src/triggers/gate.c @@ -76,7 +76,7 @@ static int gate_read(trigger * t, gamedata *data) { gate_data *gd = (gate_data *)t->data.v; int bc = read_building_reference(data, &gd->gate, NULL); - int rc = read_region_reference(data, &gd->target, NULL); + int rc = read_region_reference(data, &gd->target); if (bc <= 0 && rc <= 0) { return AT_READ_FAIL; diff --git a/src/wormhole.c b/src/wormhole.c index 382e64d16..1ce6686c9 100644 --- a/src/wormhole.c +++ b/src/wormhole.c @@ -103,7 +103,7 @@ static int wormhole_read(variant *var, void *owner, struct gamedata *data) if (data->version < ATTRIBOWNER_VERSION) { READ_INT(data->store, NULL); } - id = read_region_reference(data, (region **)&var->v, NULL); + id = read_region_reference(data, (region **)&var->v); return (id <= 0) ? AT_READ_FAIL : AT_READ_OK; }