1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-09-10 14:26:01 +00:00

text files are now read with scan(fhstream&...) functions and written with print(...) functions

This commit is contained in:
Zeno Rogue
2019-05-21 23:59:07 +02:00
parent ae100b1e72
commit 8518f97ded
5 changed files with 87 additions and 85 deletions

View File

@@ -812,36 +812,35 @@ void start_game_on_created_map() {
}
bool save_map(const string& fname) {
FILE *f = fopen(fname.c_str(), "wt");
if(!f) return false;
fhstream f(fname, "wt");
if(!f.f) return false;
auto& all = base->allcells();
int origcells = 0;
for(cellinfo& ci: cells)
if(ci.generation == 0)
origcells++;
fprintf(f, "%d %d %d\n", geometry, isize(all), origcells);
println(f, spaced(int(geometry), isize(all), origcells));
for(auto h: all) {
origcells = 0;
for(auto i: cells_of_heptagon[h->master])
if(cells[i].generation == 0)
origcells++;
fprintf(f, "%d\n", origcells);
println(f, origcells);
for(auto i: cells_of_heptagon[h->master]) if(cells[i].generation == 0) {
auto &ci = cells[i];
fprintf(f, "%lf %lf %lf\n", double(ci.p[0]), double(ci.p[1]), double(ci.p[GDIM]));
println(f, spaced(ci.p[0], ci.p[1], ci.p[GDIM]));
}
}
fclose(f);
return true;
}
bool load_map(const string &fname) {
FILE *f = fopen(fname.c_str(), "rt");
if(!f) return false;
fhstream f(fname, "rt");
if(!f.f) return false;
auto& all = base->allcells();
int g, sa;
ignore(fscanf(f, "%d %d %d\n", &g, &sa, &cellcount));
scan(f, g, sa, cellcount);
if(sa != isize(all) || g != geometry) { printf("bad parameters\n"); addMessage(XLAT("bad format or bad map geometry")); return false; }
density = cellcount * 1. / isize(all);
@@ -849,20 +848,19 @@ bool load_map(const string &fname) {
for(auto h: all) {
int q = 0;
ignore(fscanf(f, "%d\n", &q));
scan(f, q);
if(q < 0 || q > cellcount) { runlevel = 0; return false; }
while(q--) {
cells.emplace_back();
cellinfo& s = cells.back();
s.patterndir = -1;
double a, b, c;
ignore(fscanf(f, "%lf%lf%lf", &a, &b, &c));
scan(f, a, b, c);
s.p = hpxyz(a, b, c);
for(auto c0: all) s.relmatrices[c0] = calc_relative_matrix(c0, h, s.p);
s.owner = h;
}
}
fclose(f);
make_cells_of_heptagon();
runlevel = 2;