Ignore invalid walls in some old saves, so that they load correctly

E.g. save 10631 from old server
This commit is contained in:
jacksonmj 2013-10-17 15:14:14 +01:00
parent 132755525c
commit 02a4c17d72

View File

@ -1187,7 +1187,7 @@ void GameSave::readPSv(char * data, int dataLength)
{ {
//In old saves, ignore walls created by sign tool bug //In old saves, ignore walls created by sign tool bug
//Not ignoring other invalid walls or invalid walls in new saves, so that any other bugs causing them are easier to notice, find and fix //Not ignoring other invalid walls or invalid walls in new saves, so that any other bugs causing them are easier to notice, find and fix
if (ver<71 && d[p]==O_WL_SIGN) if (ver>=44 && ver<71 && d[p]==O_WL_SIGN)
{ {
p++; p++;
continue; continue;
@ -1220,38 +1220,44 @@ void GameSave::readPSv(char * data, int dataLength)
else if (blockMap[y][x]==13) else if (blockMap[y][x]==13)
blockMap[y][x]=WL_ALLOWGAS; blockMap[y][x]=WL_ALLOWGAS;
if (blockMap[y][x]==O_WL_WALLELEC) if (ver>=44)
blockMap[y][x]=WL_WALLELEC; {
else if (blockMap[y][x]==O_WL_EWALL) /* The numbers used to save walls were changed, starting in v44.
blockMap[y][x]=WL_EWALL; * The new numbers are ignored for older versions due to some corruption of bmap in saves from older versions.
else if (blockMap[y][x]==O_WL_DETECT) */
blockMap[y][x]=WL_DETECT; if (blockMap[y][x]==O_WL_WALLELEC)
else if (blockMap[y][x]==O_WL_STREAM) blockMap[y][x]=WL_WALLELEC;
blockMap[y][x]=WL_STREAM; else if (blockMap[y][x]==O_WL_EWALL)
else if (blockMap[y][x]==O_WL_FAN||blockMap[y][x]==O_WL_FANHELPER) blockMap[y][x]=WL_EWALL;
blockMap[y][x]=WL_FAN; else if (blockMap[y][x]==O_WL_DETECT)
else if (blockMap[y][x]==O_WL_ALLOWLIQUID) blockMap[y][x]=WL_DETECT;
blockMap[y][x]=WL_ALLOWLIQUID; else if (blockMap[y][x]==O_WL_STREAM)
else if (blockMap[y][x]==O_WL_DESTROYALL) blockMap[y][x]=WL_STREAM;
blockMap[y][x]=WL_DESTROYALL; else if (blockMap[y][x]==O_WL_FAN||blockMap[y][x]==O_WL_FANHELPER)
else if (blockMap[y][x]==O_WL_ERASE) blockMap[y][x]=WL_FAN;
blockMap[y][x]=WL_ERASE; else if (blockMap[y][x]==O_WL_ALLOWLIQUID)
else if (blockMap[y][x]==O_WL_WALL) blockMap[y][x]=WL_ALLOWLIQUID;
blockMap[y][x]=WL_WALL; else if (blockMap[y][x]==O_WL_DESTROYALL)
else if (blockMap[y][x]==O_WL_ALLOWAIR) blockMap[y][x]=WL_DESTROYALL;
blockMap[y][x]=WL_ALLOWAIR; else if (blockMap[y][x]==O_WL_ERASE)
else if (blockMap[y][x]==O_WL_ALLOWSOLID) blockMap[y][x]=WL_ERASE;
blockMap[y][x]=WL_ALLOWSOLID; else if (blockMap[y][x]==O_WL_WALL)
else if (blockMap[y][x]==O_WL_ALLOWALLELEC) blockMap[y][x]=WL_WALL;
blockMap[y][x]=WL_ALLOWALLELEC; else if (blockMap[y][x]==O_WL_ALLOWAIR)
else if (blockMap[y][x]==O_WL_EHOLE) blockMap[y][x]=WL_ALLOWAIR;
blockMap[y][x]=WL_EHOLE; else if (blockMap[y][x]==O_WL_ALLOWSOLID)
else if (blockMap[y][x]==O_WL_ALLOWGAS) blockMap[y][x]=WL_ALLOWSOLID;
blockMap[y][x]=WL_ALLOWGAS; else if (blockMap[y][x]==O_WL_ALLOWALLELEC)
else if (blockMap[y][x]==O_WL_GRAV) blockMap[y][x]=WL_ALLOWALLELEC;
blockMap[y][x]=WL_GRAV; else if (blockMap[y][x]==O_WL_EHOLE)
else if (blockMap[y][x]==O_WL_ALLOWENERGY) blockMap[y][x]=WL_EHOLE;
blockMap[y][x]=WL_ALLOWENERGY; else if (blockMap[y][x]==O_WL_ALLOWGAS)
blockMap[y][x]=WL_ALLOWGAS;
else if (blockMap[y][x]==O_WL_GRAV)
blockMap[y][x]=WL_GRAV;
else if (blockMap[y][x]==O_WL_ALLOWENERGY)
blockMap[y][x]=WL_ALLOWENERGY;
}
if (blockMap[y][x] < 0 || blockMap[y][x] >= UI_WALLCOUNT) if (blockMap[y][x] < 0 || blockMap[y][x] >= UI_WALLCOUNT)
blockMap[y][x] = 0; blockMap[y][x] = 0;
@ -1261,7 +1267,7 @@ void GameSave::readPSv(char * data, int dataLength)
} }
for (y=by0; y<by0+bh; y++) for (y=by0; y<by0+bh; y++)
for (x=bx0; x<bx0+bw; x++) for (x=bx0; x<bx0+bw; x++)
if (d[(y-by0)*bw+(x-bx0)]==4||d[(y-by0)*bw+(x-bx0)]==O_WL_FAN) if (d[(y-by0)*bw+(x-bx0)]==4||(ver>=44 && d[(y-by0)*bw+(x-bx0)]==O_WL_FAN))
{ {
if (p >= dataLength) if (p >= dataLength)
throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
@ -1269,7 +1275,7 @@ void GameSave::readPSv(char * data, int dataLength)
} }
for (y=by0; y<by0+bh; y++) for (y=by0; y<by0+bh; y++)
for (x=bx0; x<bx0+bw; x++) for (x=bx0; x<bx0+bw; x++)
if (d[(y-by0)*bw+(x-bx0)]==4||d[(y-by0)*bw+(x-bx0)]==O_WL_FAN) if (d[(y-by0)*bw+(x-bx0)]==4||(ver>=44 && d[(y-by0)*bw+(x-bx0)]==O_WL_FAN))
{ {
if (p >= dataLength) if (p >= dataLength)
throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));