1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-18 03:04:48 +00:00

vernum uniformization

This commit is contained in:
Zeno Rogue 2019-05-22 00:19:03 +02:00
parent a6dd48cec0
commit 1b93ecd5a3
3 changed files with 33 additions and 34 deletions

View File

@ -3,7 +3,6 @@
// version numbers // version numbers
#define VER "11.0y" #define VER "11.0y"
#define VERNUM 11025
#define VERNUM_HEX 0xA619 #define VERNUM_HEX 0xA619
#include <stdarg.h> #include <stdarg.h>
@ -4628,13 +4627,14 @@ template<class C, class C1, class... CS> void hread(hstream& hs, C& c, C1& c1, C
struct hstream_exception : hr_exception { hstream_exception() {} }; struct hstream_exception : hr_exception { hstream_exception() {} };
struct fhstream : hstream { struct fhstream : hstream {
color_t vernum;
FILE *f; FILE *f;
virtual void write_char(char c) { write_chars(&c, 1); } virtual void write_char(char c) { write_chars(&c, 1); }
virtual void write_chars(const char* c, size_t i) { if(fwrite(c, i, 1, f) != 1) throw hstream_exception(); } virtual void write_chars(const char* c, size_t i) { if(fwrite(c, i, 1, f) != 1) throw hstream_exception(); }
virtual void read_chars(char* c, size_t i) { if(fread(c, i, 1, f) != 1) throw hstream_exception(); } virtual void read_chars(char* c, size_t i) { if(fread(c, i, 1, f) != 1) throw hstream_exception(); }
virtual char read_char() { char c; read_chars(&c, 1); return c; } virtual char read_char() { char c; read_chars(&c, 1); return c; }
fhstream() { f = NULL; } fhstream() { f = NULL; vernum = VERNUM_HEX; }
fhstream(const string pathname, const char *mode) { f = fopen(pathname.c_str(), mode); } fhstream(const string pathname, const char *mode) { f = fopen(pathname.c_str(), mode); vernum = VERNUM_HEX; }
~fhstream() { if(f) fclose(f); } ~fhstream() { if(f) fclose(f); }
}; };

View File

@ -99,7 +99,7 @@ namespace mapstream {
bool saveMap(const char *fname) { bool saveMap(const char *fname) {
fhstream f(fname, "wb"); fhstream f(fname, "wb");
if(!f.f) return false; if(!f.f) return false;
int32_t i = VERNUM; f.write(i); f.write(f.vernum);
f.write(patterns::whichPattern); f.write(patterns::whichPattern);
f.write(geometry); f.write(geometry);
char nbtype = char(variation); char nbtype = char(variation);
@ -249,17 +249,17 @@ namespace mapstream {
fhstream f(fname, "rb"); fhstream f(fname, "rb");
if(!f.f) return false; if(!f.f) return false;
clearMemory(); clearMemory();
int vernum = f.get<int>(); f.read(f.vernum);
if(vernum > 10505 && vernum < 11000) if(f.vernum > 10505 && f.vernum < 11000)
vernum = 11005; f.vernum = 11005;
if(vernum >= 10420 && vernum < 10503) { if(f.vernum >= 10420 && f.vernum < 10503) {
int i; int i;
f.read(i); f.read(i);
patterns::whichPattern = patterns::ePattern(i); patterns::whichPattern = patterns::ePattern(i);
} }
else if(vernum >= 7400) f.read(patterns::whichPattern); else if(f.vernum >= 7400) f.read(patterns::whichPattern);
if(vernum >= 10203) { if(f.vernum >= 10203) {
f.read(geometry); f.read(geometry);
char nbtype; char nbtype;
f.read(nbtype); f.read(nbtype);
@ -274,7 +274,7 @@ namespace mapstream {
f.read(torusconfig::qty); f.read(torusconfig::qty);
f.read(torusconfig::dx); f.read(torusconfig::dx);
f.read(torusconfig::dy); f.read(torusconfig::dy);
if(vernum >= 10504) { if(f.vernum >= 10504) {
f.read(torusconfig::sdx); f.read(torusconfig::sdx);
f.read(torusconfig::sdy); f.read(torusconfig::sdy);
f.read(torusconfig::torus_mode); f.read(torusconfig::torus_mode);
@ -282,7 +282,7 @@ namespace mapstream {
torusconfig::activate(); torusconfig::activate();
} }
#if CAP_CRYSTAL #if CAP_CRYSTAL
if(geometry == gCrystal && vernum >= 10504) { if(geometry == gCrystal && f.vernum >= 10504) {
int sides; int sides;
f.read(sides); f.read(sides);
#if CAP_CRYSTAL #if CAP_CRYSTAL
@ -327,7 +327,7 @@ namespace mapstream {
initcells(); initcells();
if(shmup::on) shmup::init(); if(shmup::on) shmup::init();
if(vernum >= 10505) { if(f.vernum >= 10505) {
// game settings // game settings
f.read(safety); f.read(safety);
bool b; bool b;
@ -364,7 +364,7 @@ namespace mapstream {
if(parent<0 || parent >= isize(cellbyid)) break; if(parent<0 || parent >= isize(cellbyid)) break;
int dir = f.read_char(); int dir = f.read_char();
cell *c2 = cellbyid[parent]; cell *c2 = cellbyid[parent];
dir = fixspin(dir, relspin[parent], c2->type, vernum); dir = fixspin(dir, relspin[parent], c2->type, f.vernum);
c = createMov(c2, dir); c = createMov(c2, dir);
// printf("%p:%d,%d -> %p\n", c2, relspin[parent], dir, c); // printf("%p:%d,%d -> %p\n", c2, relspin[parent], dir, c);
@ -379,20 +379,20 @@ namespace mapstream {
cellbyid.push_back(c); cellbyid.push_back(c);
relspin.push_back(rspin); relspin.push_back(rspin);
c->land = (eLand) f.read_char(); c->land = (eLand) f.read_char();
c->mondir = fixspin(rspin, f.read_char(), c->type, vernum); c->mondir = fixspin(rspin, f.read_char(), c->type, f.vernum);
c->monst = (eMonster) f.read_char(); c->monst = (eMonster) f.read_char();
if(c->monst == moTortoise && vernum >= 11001) if(c->monst == moTortoise && f.vernum >= 11001)
f.read(tortoise::emap[c]); f.read(tortoise::emap[c]);
c->wall = (eWall) f.read_char(); c->wall = (eWall) f.read_char();
// c->barleft = (eLand) f.read_char(); // c->barleft = (eLand) f.read_char();
// c->barright = (eLand) f.read_char(); // c->barright = (eLand) f.read_char();
c->item = (eItem) f.read_char(); c->item = (eItem) f.read_char();
if(c->item == itBabyTortoise && vernum >= 11001) if(c->item == itBabyTortoise && f.vernum >= 11001)
f.read(tortoise::babymap[c]); f.read(tortoise::babymap[c]);
c->mpdist = f.read_char(); c->mpdist = f.read_char();
c->bardir = NOBARRIERS; c->bardir = NOBARRIERS;
// fixspin(rspin, f.read_char(), c->type); // fixspin(rspin, f.read_char(), c->type);
if(vernum < 7400) { if(f.vernum < 7400) {
short z; short z;
f.read(z); f.read(z);
c->wparam = z; c->wparam = z;
@ -400,7 +400,7 @@ namespace mapstream {
else f.read(c->wparam); else f.read(c->wparam);
f.read(c->landparam); f.read(c->landparam);
// backward compatibility // backward compatibility
if(vernum < 7400 && !isIcyLand(c->land)) c->landparam = HEAT(c); if(f.vernum < 7400 && !isIcyLand(c->land)) c->landparam = HEAT(c);
c->stuntime = f.read_char(); c->stuntime = f.read_char();
c->hitpoints = f.read_char(); c->hitpoints = f.read_char();
@ -440,9 +440,9 @@ namespace mapstream {
cheater = 1; cheater = 1;
dynamicval<bool> a3(geom3::always3, geom3::always3); dynamicval<bool> a3(geom3::always3, geom3::always3);
if(vernum >= 0xA616) f.read(geom3::always3); if(f.vernum >= 0xA616) f.read(geom3::always3);
if(vernum >= 7400) while(true) { if(f.vernum >= 7400) while(true) {
int i = f.get<int>(); int i = f.get<int>();
if(i == -1) break; if(i == -1) break;
#if CAP_POLY #if CAP_POLY
@ -454,7 +454,7 @@ namespace mapstream {
initShape(i, j); initShape(i, j);
usershapelayer& ds(usershapes[i][j]->d[l]); usershapelayer& ds(usershapes[i][j]->d[l]);
if(vernum >= 11008) f.read(ds.zlevel); if(f.vernum >= 11008) f.read(ds.zlevel);
f.read(ds.sym); f.read(ds.rots); f.read(ds.color); f.read(ds.sym); f.read(ds.rots); f.read(ds.color);
ds.list.clear(); ds.list.clear();
@ -470,7 +470,7 @@ namespace mapstream {
#endif #endif
} }
if(vernum >= 11005) { if(f.vernum >= 11005) {
f.read(mutantphase); f.read(mutantphase);
f.read(rosewave); f.read(rosewave);
f.read(rosephase); f.read(rosephase);
@ -1645,15 +1645,14 @@ namespace mapeditor {
return false; return false;
} }
scanline(f); scanline(f);
color_t vernum; scan(f, f.vernum);
scan(f, vernum); printf("vernum = %x\n", f.vernum);
printf("vernum = %x\n", vernum); if(f.vernum == 0) {
if(vernum == 0) {
addMessage(XLAT("Failed to load pictures from %1", picfile)); addMessage(XLAT("Failed to load pictures from %1", picfile));
return false; return false;
} }
if(vernum >= 0xA0A0) { if(f.vernum >= 0xA0A0) {
int tg, wp; int tg, wp;
int nt; int nt;
scan(f, tg, nt, wp, patterns::subpattern_flags); scan(f, tg, nt, wp, patterns::subpattern_flags);
@ -1678,7 +1677,7 @@ namespace mapeditor {
initShape(i, j); initShape(i, j);
usershapelayer& ds(usershapes[i][j]->d[l]); usershapelayer& ds(usershapes[i][j]->d[l]);
if(vernum >= 0xA608) scan(f, ds.zlevel); if(f.vernum >= 0xA608) scan(f, ds.zlevel);
ds.shift = readHyperpoint(f); ds.shift = readHyperpoint(f);
ds.spin = readHyperpoint(f); ds.spin = readHyperpoint(f);
ds.list.clear(); ds.list.clear();
@ -1703,8 +1702,8 @@ namespace mapeditor {
return false; return false;
} }
println(f, "HyperRogue saved picture"); println(f, "HyperRogue saved picture");
println(f, format("%x\n", VERNUM_HEX)); println(f, f.vernum);
if(VERNUM_HEX >= 0xA0A0) if(f.vernum >= 0xA0A0)
println(f, spaced(geometry, int(variation), patterns::whichPattern, patterns::subpattern_flags)); println(f, spaced(geometry, int(variation), patterns::whichPattern, patterns::subpattern_flags));
for(int i=0; i<USERSHAPEGROUPS; i++) for(auto usp: usershapes[i]) { for(int i=0; i<USERSHAPEGROUPS; i++) for(auto usp: usershapes[i]) {
usershape *us = usp.second; usershape *us = usp.second;

View File

@ -150,8 +150,8 @@ bool read_ghosts(string seed, int mcode) {
println(hlog, "trying to read ghosts from: ", fname); println(hlog, "trying to read ghosts from: ", fname);
fhstream f(fname, "rb"); fhstream f(fname, "rb");
if(!f.f) return false; if(!f.f) return false;
int vernum = f.get<int> (); f.vernum = f.get<int> ();
if(vernum <= 0xA600) return true; // scores removed due to the possibility of cheating if(f.vernum <= 0xA600) return true; // scores removed due to the possibility of cheating
hread(f, ghostset()); hread(f, ghostset());
return true; return true;
} }
@ -160,7 +160,7 @@ void write_ghosts(string seed, int mcode) {
fhstream f; fhstream f;
f.f = fopen(ghost_filename(seed, mcode).c_str(), "wb"); f.f = fopen(ghost_filename(seed, mcode).c_str(), "wb");
if(!f.f) throw hstream_exception(); // ("failed to write the ghost file"); if(!f.f) throw hstream_exception(); // ("failed to write the ghost file");
hwrite(f, (const int&) VERNUM_HEX); hwrite(f, f.vernum);
hwrite(f, ghostset()); hwrite(f, ghostset());
} }
#endif #endif