static int createunit_read(trigger * t, gamedata *data) { createunit_data *td = (createunit_data *)t->data.v; variant var; int result = AT_READ_OK; var = read_faction_reference(data); if (var.i > 0) { td->f = findfaction(var.i); if (!td->f) { ur_add(var, &td->f, resolve_faction); } } else { result = AT_READ_FAIL; } // read_reference(&td->f, store, read_faction_reference, resolve_faction); read_reference(&td->r, data, read_region_reference, RESOLVE_REGION(data->version)); td->race = (const struct race *)read_race_reference(data->store).v; if (!td->race) { result = AT_READ_FAIL; } READ_INT(data->store, &td->number); return result; }
static int gate_read(trigger * t, struct storage *store) { gate_data *gd = (gate_data *) t->data.v; int bc = read_reference(&gd->gate, store, read_building_reference, resolve_building); int rc = read_reference(&gd->target, store, read_region_reference, RESOLVE_REGION(global.data_version)); if (bc == 0 && rc == 0) { if (!gd->gate || !gd->target) return AT_READ_FAIL; } return AT_READ_OK; }
static int createunit_read(trigger * t, struct storage *store) { createunit_data *td = (createunit_data *)t->data.v; int uc = read_reference(&td->f, store, read_faction_reference, resolve_faction); int rc = read_reference(&td->r, store, read_region_reference, RESOLVE_REGION(global.data_version)); td->race = (const struct race *)read_race_reference(store).v; if (uc == 0 && rc == 0) { if (!td->f || !td->r) return AT_READ_FAIL; } READ_INT(store, &td->number); return AT_READ_OK; }
static int object_read(attrib * a, void *owner, struct storage *store) { char name[NAMESIZE]; object_data *data = (object_data *) a->data.v; int result, n; float flt; READ_STR(store, name, sizeof(name)); data->name = _strdup(name); READ_INT(store, &n); data->type = (object_type)n; switch (data->type) { case TINTEGER: READ_INT(store, &data->data.i); break; case TREAL: READ_FLT(store, &flt); data->data.real = flt; break; case TSTRING: READ_STR(store, name, sizeof(name)); data->data.str = _strdup(name); break; case TBUILDING: result = read_reference(&data->data.b, store, read_building_reference, resolve_building); if (result == 0 && !data->data.b) { return AT_READ_FAIL; } break; case TUNIT: result = read_reference(&data->data.u, store, read_unit_reference, resolve_unit); if (result == 0 && !data->data.u) { return AT_READ_FAIL; } break; case TFACTION: result = read_reference(&data->data.f, store, read_faction_reference, resolve_faction); if (result == 0 && !data->data.f) { return AT_READ_FAIL; } break; case TREGION: result = read_reference(&data->data.r, store, read_region_reference, RESOLVE_REGION(global.data_version)); if (result == 0 && !data->data.r) { return AT_READ_FAIL; } break; case TSHIP: /* return read_ship_reference(&data->data.sh, store); */ assert(!"not implemented"); break; case TNONE: break; default: return AT_READ_FAIL; } return AT_READ_OK; }
int curse_read(attrib * a, void *owner, struct storage *store) { curse *c = (curse *) a->data.v; int ur; char cursename[64]; int n; int flags; float flt; READ_INT(store, &c->no); chash(c); READ_TOK(store, cursename, sizeof(cursename)); READ_INT(store, &flags); READ_INT(store, &c->duration); if (global.data_version >= CURSEVIGOURISFLOAT_VERSION) { READ_FLT(store, &flt); c->vigour = flt; } else { READ_INT(store, &n); c->vigour = (float)n; } if (global.data_version < INTPAK_VERSION) { ur = read_reference(&c->magician, store, read_int, resolve_unit); } else { ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit); } if (global.data_version < CURSEFLOAT_VERSION) { READ_INT(store, &n); c->effect = (float)n; } else { READ_FLT(store, &flt); c->effect = flt; } c->type = ct_find(cursename); if (c->type == NULL) { int result = read_ccompat(cursename, store); if (result != 0) { log_error("missing curse %s, no compatibility code either.\n", cursename); } assert(result == 0); return AT_READ_FAIL; } if (global.data_version < CURSEFLAGS_VERSION) { c_setflag(c, flags); } else { c->flags = flags; } c_clearflag(c, CURSE_ISNEW); if (c->type->read) c->type->read(store, c, owner); else if (c->type->typ == CURSETYP_UNIT) { READ_INT(store, &c->data.i); } if (c->type->typ == CURSETYP_REGION) { int rr = read_reference(&c->data.v, store, read_region_reference, RESOLVE_REGION(global.data_version)); if (ur == 0 && rr == 0 && !c->data.v) { return AT_READ_FAIL; } } return AT_READ_OK; }