int resolve_region_id(variant id, void *address) { region *r = NULL; if (id.i != 0) { r = findregionbyid(id.i); if (r == NULL) { *(region **)address = NULL; return -1; } } *(region **)address = r; return 0; }
int read_borders(gamedata *data) { struct storage *store = data->store; for (;;) { int bid = 0; char zText[32]; region *from, *to; border_type *type; READ_TOK(store, zText, sizeof(zText)); if (!strcmp(zText, "end")) break; READ_INT(store, &bid); if (data->version < UIDHASH_VERSION) { int fx, fy, tx, ty; READ_INT(store, &fx); READ_INT(store, &fy); READ_INT(store, &tx); READ_INT(store, &ty); from = findregion(fx, fy); to = findregion(tx, ty); } else { int fid, tid; READ_INT(store, &fid); READ_INT(store, &tid); from = findregionbyid(fid); to = findregionbyid(tid); if (!to || !from) { log_warning("%s connection between incomplete regions %d and %d", zText, fid, tid); continue; } } type = find_bordertype(zText); if (type == NULL) { log_error("[read_borders] unknown connection type '%s' in %s\n", zText, regionname(from, NULL)); assert(type || !"connection type not registered"); } if (to == from && type && from) { direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); region *r = rconnect(from, dir); log_error("[read_borders] invalid %s in %s\n", type->__name, regionname(from, NULL)); if (r != NULL) to = r; } if ((type->read && !type->write)) { log_warning("ignore invalid border '%s' between '%s' and '%s'\n", zText, regionname(from, 0), regionname(to, 0)); } else { connection *b = new_border(type, from, to); nextborder--; /* new_border erhöht den Wert */ b->id = bid; assert(bid <= nextborder); if (type->read) { type->read(b, data); } if (data->version < NOBORDERATTRIBS_VERSION) { attrib *a = NULL; int result = read_attribs(data, &a, b); if (border_convert_cb) { border_convert_cb(b, a); } while (a) { a_remove(&a, a); } if (result < 0) { return result; } } } } return 0; }