diff --git a/tools/map/map2lnd.c b/tools/map/map2lnd.c index b78af1dc8..021c68c19 100644 --- a/tools/map/map2lnd.c +++ b/tools/map/map2lnd.c @@ -34,11 +34,6 @@ typedef enum _tileset_type static const char *tilesetDataSet[] = { "WarzoneDataC1.eds", "WarzoneDataC2.eds", "WarzoneDataC3.eds" }; static const char *tilesetTextures[] = { "texpages\\tertilesc1.pcx", "texpages\\tertilesc2.pcx", "texpages\\tertilesc3.pcx" }; -static MAPTILE *mapTile(GAMEMAP *map, int x, int y) -{ - return &map->psMapTiles[y * map->width + x]; -} - int main(int argc, char **argv) { char filename[PATH_MAX]; @@ -177,6 +172,9 @@ int main(int argc, char **argv) MADD(" FeatureSet %s", tilesetDataSet[tileset]); MADD(" NumObjects 0"); MADD(" Objects {"); + // %d UniqueID, %d TypeID, \"%s\" StructureName or description or \"NONAME\", %d PlayerID, \"%s\" ScriptName or \"NONAME\" MAY BE MISSING in v<3! + // fprintf(Stream, "%.2f %.2f %.2f ", Position.x, Position.y, Position.z); + // fprintf(Stream, "%.2f %.2f %.2f\n", curNode->Rotation.x, curNode->Rotation.y, curNode->Rotation.z); MADD(" }"); MADD("}"); MADD("ScrollLimits {"); @@ -188,8 +186,14 @@ int main(int argc, char **argv) MADD("}"); MADD("Gateways {"); MADD(" Version 1"); - MADD(" NumGateways 0"); // FIXME + MADD(" NumGateways %d", (int)map->numGateways); MADD(" Gates {"); + for (i = 0; i < map->numGateways; i++) + { + GATEWAY *psGate = mapGateway(map, i); + + MADD(" %llu %llu %llu %llu", psGate->x1, psGate->y1, psGate->x2, psGate->y2); + } MADD(" }"); MADD("}"); MADD("TileTypes {"); diff --git a/tools/map/mapload.c b/tools/map/mapload.c index 21c3407c0..c15a157aa 100644 --- a/tools/map/mapload.c +++ b/tools/map/mapload.c @@ -10,7 +10,8 @@ void mapFree(GAMEMAP *map) { - free(map->psMapTiles); + free(map->mGateways); + free(map->mMapTiles); free(map); } @@ -51,28 +52,28 @@ GAMEMAP *mapLoad(char *filename) || aFileType[1] != 'a' || aFileType[2] != 'p') { - debug(LOG_ERROR, "Bad header in %s", filename); + debug(LOG_ERROR, "Bad header in %s", path); return NULL; } else if (map->version <= 9) { - debug(LOG_ERROR, "%s: Unsupported save format version %u", filename, map->version); + debug(LOG_ERROR, "%s: Unsupported save format version %u", path, map->version); return NULL; } else if (map->version > 36) { - debug(LOG_ERROR, "%s: Undefined save format version %u", filename, map->version); + debug(LOG_ERROR, "%s: Undefined save format version %u", path, map->version); return NULL; } else if (map->width * map->height > MAP_MAXAREA) { - debug(LOG_ERROR, "Map %s too large : %d %d", filename, map->width, map->height); + debug(LOG_ERROR, "Map %s too large : %d %d", path, map->width, map->height); return NULL; } /* Allocate the memory for the map */ - map->psMapTiles = calloc(map->width * map->height, sizeof(*map->psMapTiles)); - if (!map->psMapTiles) + map->mMapTiles = calloc(map->width * map->height, sizeof(*map->mMapTiles)); + if (!map->mMapTiles) { debug(LOG_ERROR, "Out of memory"); return NULL; @@ -86,31 +87,31 @@ GAMEMAP *mapLoad(char *filename) if (!readU16(&texture) || !readU8(&height)) { - debug(LOG_ERROR, "%s: Error during savegame load", filename); + debug(LOG_ERROR, "%s: Error during savegame load", path); return NULL; } - map->psMapTiles[i].texture = texture; - map->psMapTiles[i].height = height; + map->mMapTiles[i].texture = texture; + map->mMapTiles[i].height = height; for (j = 0; j < MAX_PLAYERS; j++) { - map->psMapTiles[i].tileVisBits = (uint8_t)(map->psMapTiles[i].tileVisBits &~ (uint8_t)(1 << j)); + map->mMapTiles[i].tileVisBits = (uint8_t)(map->mMapTiles[i].tileVisBits &~ (uint8_t)(1 << j)); } } if (!readU32(&gwVersion) || !readU32(&map->numGateways) || gwVersion != 1) { - debug(LOG_ERROR, "Bad gateway in %s", filename); + debug(LOG_ERROR, "Bad gateway in %s", path); return NULL; } + map->mGateways = calloc(map->numGateways, sizeof(*map->mGateways)); for (i = 0; i < map->numGateways; i++) { - uint8_t x0, y0, x1, y1; - - if (!readU8(&x0) || !readU8(&y0) || !readU8(&x1) || !readU8(&y1)) + if (!readU8(&map->mGateways[i].x1) || !readU8(&map->mGateways[i].y1) + || !readU8(&map->mGateways[i].x2) || !readU8(&map->mGateways[i].y2)) { - debug(LOG_ERROR, "%s: Failed to read gateway info", filename); + debug(LOG_ERROR, "%s: Failed to read gateway info", path); return NULL; } } diff --git a/tools/map/mapload.h b/tools/map/mapload.h index a4470e7ae..1c645bb55 100644 --- a/tools/map/mapload.h +++ b/tools/map/mapload.h @@ -27,6 +27,11 @@ #define MAX_LEVEL_SIZE 20 +typedef struct _gateway +{ + uint8_t x1, y1, x2, y2; +} GATEWAY; + /* Information stored with each tile */ typedef struct _maptile_type { @@ -40,15 +45,28 @@ typedef struct _maptile_type typedef struct _mapfile_type { - MAPTILE *psMapTiles; uint32_t height, width, version, numGateways, numFeatures; int32_t scrollMinX; int32_t scrollMinY; uint32_t scrollMaxX; uint32_t scrollMaxY; char levelName[MAX_LEVEL_SIZE]; + + // private members - don't touch! :-) + GATEWAY *mGateways; + MAPTILE *mMapTiles; } GAMEMAP; +static inline MAPTILE *mapTile(GAMEMAP *map, int x, int y) +{ + return &map->mMapTiles[y * map->width + x]; +} + +static inline GATEWAY *mapGateway(GAMEMAP *map, int index) +{ + return &map->mGateways[index]; +} + /* Load the map data */ GAMEMAP *mapLoad(char *filename); void mapFree(GAMEMAP *map);