static int tolua_storage_read_unit(lua_State * L) { gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); struct unit *u = read_unit(data); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); return 1; }
void read(Archive & ar, Env & env) { auto verbose = env.verbose; auto ver = current_version; // version read(ar, ver); // factions read_mark(ar, "FACS"); { if (verbose) print("load factions\n"); auto& ps = env.get_cont<Faction>(); auto num = read<size_t>(ar); for (size_t i=0; i<num; ++i) { auto id = read<Faction::Id>(ar); read(ar, env, ps[id]); } } // terrain read_mark(ar, "TERS"); { if (verbose) print("load terrain\n"); print("offset = %||\n", ar.tellg()); read(ar, env.dim); print("map dim = %||, %||\n", env.dim[0], env.dim[1]); env.resize(env.dim); for(Coord j = 0; j < env.dim[1]; ++j) { for(Coord i = 0; i < env.dim[0]; ++i) { auto& x = env.get_terr(Coords(i,j)); // terr value read(ar, env, x); } } } // colonies read_mark(ar, "COLS"); { // section mark /*if (read_byte(ar) != 'C') { fail('invalid section mark: expected C (Colonies)'); }*/ if (verbose) print("load colonies\n"); auto& ps = env.get_cont<Colony>(); auto tmp = read<decltype(ps.size())>(ar); for (decltype(ps.size()) i=0; i<tmp; ++i) { Colony x; read(ar, x.id); read(ar, x.name); read_reg(ar, x.store); auto key = x.id; auto p = ps.emplace(key, std::move(x)).first; auto& col = (*p).second; print("loaded colony name = %||\n", col.name); // buildings for (auto& b: col.builds) { auto build_type_id = read<BuildType::Id>(ar); //cerr << "load building type id = " << build_type_id << endl; b.type = & env.get_buildtype( build_type_id ); read(ar, b.free_slots); // task read(ar, env, b.task); } // fields auto nfields = read<Colony::Fields::size_type>(ar); for (Colony::Fields::size_type i = 0; i < nfields; ++i) { // field col.add_field( Field(env.get_terr(read<Coords>(ar))) ); col.fields[i].set_proditem(read<Item>(ar)); } // location env.put(env.get_terr(read<Coords>(ar)), (*p).second); } } // units read_mark(ar, "UNIS"); { if (verbose) print("load units\n"); auto& units = env.get_cont<Unit>(); size_t tmp; read(ar, tmp); for (size_t i = 0; i < tmp; ++i) { auto unit_id = read<Unit::Id>(ar); read_unit(ar, env, units[unit_id]); } } if (verbose) print("load misc\n"); read_mark(ar, "MISC"); // turn info read(ar, env.turn_no); // next id read(ar, env.next_id); // state read(ar, env.state); // current control env.set_current_control(read<Control>(ar)); // current nation //l += write(f, env.current_nation_id); }