Fix compilation of map tools. Add support for version 10 game files with power information.

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@7905 4a71c877-e1ca-e34f-864e-861f7616d084
master
Per Inge Mathisen 2009-07-27 16:01:56 +00:00 committed by Git SVN Gateway
parent 2f92b730ad
commit 4ff191aeea
4 changed files with 47 additions and 27 deletions

View File

@ -69,6 +69,8 @@ int main(int argc, char **argv)
mkdir(filename, 0777);
strcpy(base, filename);
strcat(filename, "/map-001");
mkdir(filename, 0777);
/*** Map configuration ***/
strcat(filename, "/map.ini");
@ -93,7 +95,7 @@ int main(int argc, char **argv)
MADD("TileHeight = %d", TILE_WIDTH);
MADD("SeaLevel = %d", SEALEVEL);
MADD("Tileset = %s", tilesetTextures[map->tileset]);
MADD("NumTiles = %d", map->width * map->height);
MADD("\n[scroll_limits]");
MADD("x1 = %d", map->scrollMinX);
MADD("y1 = %d", map->scrollMinY);

View File

@ -46,7 +46,8 @@ int main(int argc, char **argv)
else { strcpy(tilesetName, "(unknown)"); }
printf("Loaded map: %s\n", filename);
printf("\tMap version: %d\n", (int)map->version);
printf("\tMap version: %d\n", (int)map->mapVersion);
printf("\tGame version: %d\n", (int)map->gameVersion);
printf("\tWidth: %d\n", (int)map->width);
printf("\tHeight: %d\n", (int)map->height);
printf("\tGateways: %d\n", (int)map->numGateways);

View File

@ -31,8 +31,7 @@ GAMEMAP *mapLoad(char *filename)
{
char path[PATH_MAX];
GAMEMAP *map = malloc(sizeof(*map));
uint32_t i, j, gameTime, gameType, droidVersion, structVersion;
uint32_t gwVersion, gameVersion, featVersion, terrainVersion;
uint32_t i, j, gameTime, gameType, gwVersion;
char aFileType[4];
bool littleEndian = true;
PHYSFS_file *fp = NULL;
@ -65,7 +64,7 @@ GAMEMAP *mapLoad(char *filename)
goto failure;
}
else if (PHYSFS_read(fp, aFileType, 4, 1) != 1
|| !readU32(&map->version)
|| !readU32(&map->mapVersion)
|| !readU32(&map->width)
|| !readU32(&map->height)
|| aFileType[0] != 'm'
@ -75,14 +74,14 @@ GAMEMAP *mapLoad(char *filename)
debug(LOG_ERROR, "Bad header in %s", path);
goto failure;
}
else if (map->version <= 9)
else if (map->mapVersion <= 9)
{
debug(LOG_ERROR, "%s: Unsupported save format version %u", path, map->version);
debug(LOG_ERROR, "%s: Unsupported save format version %u", path, map->mapVersion);
goto failure;
}
else if (map->version > 36)
else if (map->mapVersion > 36)
{
debug(LOG_ERROR, "%s: Undefined save format version %u", path, map->version);
debug(LOG_ERROR, "%s: Undefined save format version %u", path, map->mapVersion);
goto failure;
}
else if (map->width * map->height > MAP_MAXAREA)
@ -153,12 +152,12 @@ GAMEMAP *mapLoad(char *filename)
|| aFileType[1] != 'a'
|| aFileType[2] != 'm'
|| aFileType[3] != 'e'
|| !readU32(&gameVersion))
|| !readU32(&map->gameVersion))
{
debug(LOG_ERROR, "Bad header in %s", path);
goto failure;
}
if (gameVersion > 35) // big-endian
if (map->gameVersion > 35) // big-endian
{
littleEndian = false;
}
@ -173,6 +172,23 @@ GAMEMAP *mapLoad(char *filename)
debug(LOG_ERROR, "Bad data in %s", filename);
goto failure;
}
for (i = 0; i < 8; i++)
{
if (map->gameVersion >= 10)
{
uint32_t dummy; // extracted power, not used
if (!readU32(&map->power[i]) || !readU32(&dummy))
{
debug(LOG_ERROR, "Bad power data in %s", filename);
goto failure;
}
}
else
{
map->power[i] = 0; // TODO... is there a default?
}
}
PHYSFS_close(fp);
@ -192,7 +208,7 @@ GAMEMAP *mapLoad(char *filename)
|| aFileType[1] != 'e'
|| aFileType[2] != 'a'
|| aFileType[3] != 't'
|| !readU32(&featVersion)
|| !readU32(&map->featVersion)
|| !readU32(&map->numFeatures))
{
debug(LOG_ERROR, "Bad features header in %s", path);
@ -206,7 +222,7 @@ GAMEMAP *mapLoad(char *filename)
uint32_t dummy;
uint8_t visibility[8];
if (featVersion <= 19)
if (map->featVersion <= 19)
{
nameLength = 40;
}
@ -223,7 +239,7 @@ GAMEMAP *mapLoad(char *filename)
goto failure;
}
psObj->player = 0; // work around invalid feature owner
if (featVersion >= 14 && PHYSFS_read(fp, &visibility, 1, 8) != 8)
if (map->featVersion >= 14 && PHYSFS_read(fp, &visibility, 1, 8) != 8)
{
debug(LOG_ERROR, "Failed to read feature visibility from %s", path);
goto failure;
@ -255,7 +271,7 @@ GAMEMAP *mapLoad(char *filename)
|| aFileType[1] != 't'
|| aFileType[2] != 'y'
|| aFileType[3] != 'p'
|| !readU32(&terrainVersion)
|| !readU32(&map->terrainVersion)
|| !readU32(&map->numTerrainTypes))
{
debug(LOG_ERROR, "Bad features header in %s", path);
@ -302,7 +318,7 @@ GAMEMAP *mapLoad(char *filename)
|| aFileType[1] != 't'
|| aFileType[2] != 'r'
|| aFileType[3] != 'u'
|| !readU32(&structVersion)
|| !readU32(&map->structVersion)
|| !readU32(&map->numStructures))
{
debug(LOG_ERROR, "Bad structure header in %s", path);
@ -319,7 +335,7 @@ GAMEMAP *mapLoad(char *filename)
int32_t dummyS32;
char researchName[60];
if (structVersion <= 19)
if (map->structVersion <= 19)
{
nameLength = 40;
}
@ -349,7 +365,7 @@ GAMEMAP *mapLoad(char *filename)
debug(LOG_ERROR, "Failed to read structure from %s", path);
goto failure;
}
if (structVersion >= 12
if (map->structVersion >= 12
&& (!readU32(&dummy) // factoryInc
|| !readU8(&dummy8) // loopsPerformed - causes structure padding
|| !readU8(&dummy8) // structure padding
@ -364,12 +380,12 @@ GAMEMAP *mapLoad(char *filename)
debug(LOG_ERROR, "Failed to read structure v12 part from %s", path);
goto failure;
}
if (structVersion >= 14 && PHYSFS_read(fp, &visibility, 1, 8) != 8)
if (map->structVersion >= 14 && PHYSFS_read(fp, &visibility, 1, 8) != 8)
{
debug(LOG_ERROR, "Failed to read structure visibility from %s", path);
goto failure;
}
if (structVersion >= 15 && PHYSFS_read(fp, researchName, nameLength, 1) != 1)
if (map->structVersion >= 15 && PHYSFS_read(fp, researchName, nameLength, 1) != 1)
{
// If version < 20, then this causes no padding, but the short below
// will still cause two bytes padding; however, if version >= 20, we
@ -378,17 +394,17 @@ GAMEMAP *mapLoad(char *filename)
debug(LOG_ERROR, "Failed to read structure v15 part from %s", path);
goto failure;
}
if (structVersion >= 17 && !readS16(&dummyS16))
if (map->structVersion >= 17 && !readS16(&dummyS16))
{
debug(LOG_ERROR, "Failed to read structure v17 part from %s", path);
goto failure;
}
if (structVersion >= 15 && !readS16(&dummyS16)) // structure padding
if (map->structVersion >= 15 && !readS16(&dummyS16)) // structure padding
{
debug(LOG_ERROR, "Failed to read 16 bits of structure padding from %s", path);
goto failure;
}
if (structVersion >= 21 && !readU32(&dummy))
if (map->structVersion >= 21 && !readU32(&dummy))
{
debug(LOG_ERROR, "Failed to read structure v21 part from %s", path);
goto failure;
@ -425,7 +441,7 @@ GAMEMAP *mapLoad(char *filename)
|| aFileType[1] != 'i'
|| aFileType[2] != 'n'
|| aFileType[3] != 't'
|| !readU32(&droidVersion)
|| !readU32(&map->droidVersion)
|| !readU32(&map->numDroids))
{
debug(LOG_ERROR, "Bad droid header in %s", path);
@ -438,7 +454,7 @@ GAMEMAP *mapLoad(char *filename)
int nameLength = 60;
uint32_t dummy;
if (droidVersion <= 19)
if (map->droidVersion <= 19)
{
nameLength = 40;
}

View File

@ -23,6 +23,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "wzglobal.h"
#include "physfs_ext.h"
#define MAX_LEVEL_SIZE 20
@ -72,8 +73,8 @@ typedef struct _maptile_type
typedef struct _mapfile_type
{
uint32_t height, width, version, numGateways, numFeatures, numTerrainTypes;
uint32_t numPlayers, numDroids, numStructures;
uint32_t height, width, mapVersion, gameVersion, numGateways, numFeatures, numTerrainTypes, power[8];
uint32_t numPlayers, numDroids, numStructures, droidVersion, structVersion, featVersion, terrainVersion;
int32_t scrollMinX;
int32_t scrollMinY;
uint32_t scrollMaxX;