279 lines
9.8 KiB
C
279 lines
9.8 KiB
C
// Converter from Warzone (savegame) map format to Editworld LND format.
|
|
// Note that we are missing some information, most notably the height for
|
|
// the rightmost and bottom most vertices, which in Warzone is snapped to
|
|
// sea level, while it can be freely manipulated in Editworld.
|
|
|
|
// gcc -o ~/bin/map2lnd map2lnd.c mapload.c -I. -lphysfs -g -I../../lib/framework
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
#include "mapload.h"
|
|
|
|
#define GRDLANDVERSION 4
|
|
#define ELEVATION_SCALE 2
|
|
#define GRAVITY 1
|
|
#define SEALEVEL 0
|
|
#define TILE_HEIGHT 128
|
|
#define TILE_WIDTH 128
|
|
#define TILE_NUMMASK 0x01ff
|
|
#define TILE_XFLIP 0x8000
|
|
#define TILE_YFLIP 0x4000
|
|
#define TILE_ROTMASK 0x3000
|
|
#define TILE_ROTSHIFT 12
|
|
#define TILE_TRIFLIP 0x0800
|
|
#define TRI_FLIPPED(x) ((x)->texture & TILE_TRIFLIP)
|
|
#define SNAP_MODE 0
|
|
|
|
typedef enum _tileset_type
|
|
{
|
|
TILESET_ARIZONA = 0, TILESET_URBAN, TILESET_ROCKIES
|
|
} TILESET;
|
|
|
|
static const char *tilesetDataSet[] = { "WarzoneDataC1.eds", "WarzoneDataC2.eds", "WarzoneDataC3.eds" };
|
|
static const char *tilesetTextures[] = { "texpages\\tertilesc1.pcx", "texpages\\tertilesc2.pcx", "texpages\\tertilesc3.pcx" };
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
char filename[PATH_MAX];
|
|
char path[PATH_MAX], *delim;
|
|
GAMEMAP *map;
|
|
FILE *fp;
|
|
int i, x, y;
|
|
TILESET tileset = TILESET_ARIZONA; // FIXME, hack for now
|
|
|
|
if (argc != 2)
|
|
{
|
|
printf("Usage: %s <map>\n", argv[0]);
|
|
return -1;
|
|
}
|
|
strcpy(path, argv[1]);
|
|
delim = strrchr(path, '/');
|
|
if (delim)
|
|
{
|
|
*delim = '\0';
|
|
delim++;
|
|
strcpy(filename, delim);
|
|
}
|
|
else
|
|
{
|
|
path[1] = '.';
|
|
path[1] = '\0';
|
|
strcpy(filename, argv[1]);
|
|
}
|
|
PHYSFS_init(argv[0]);
|
|
PHYSFS_addToSearchPath(path, 1);
|
|
|
|
map = mapLoad(filename);
|
|
if (!map)
|
|
{
|
|
fprintf(stderr, "Failed to load map\n");
|
|
return -1;
|
|
}
|
|
|
|
strcat(filename, ".lnd");
|
|
fp = fopen(filename, "w");
|
|
if (!fp)
|
|
{
|
|
fprintf(stderr, "Could not open target: %s", filename);
|
|
return -1;
|
|
}
|
|
#define MADD(...) fprintf(fp, __VA_ARGS__); fprintf(fp, "\n");
|
|
MADD("DataSet %s", tilesetDataSet[tileset]);
|
|
MADD("GrdLand {");
|
|
MADD(" Version %d", GRDLANDVERSION);
|
|
MADD(" 3DPosition %f %f %f", 0.0, 0.0, 0.0); // FIXME
|
|
MADD(" 3DRotation %f %f %f", 0.0, 0.0, 0.0); // FIXME
|
|
MADD(" 2DPosition %d %d", 0, 0); // FIXME
|
|
MADD(" CustomSnap %d %d", 0, 0); // FIXME
|
|
MADD(" SnapMode %d", SNAP_MODE);
|
|
MADD(" Gravity %d", GRAVITY);
|
|
MADD(" HeightScale %d", ELEVATION_SCALE);
|
|
MADD(" MapWidth %d", map->width);
|
|
MADD(" MapHeight %d", map->height);
|
|
MADD(" TileWidth %d", TILE_HEIGHT);
|
|
MADD(" TileHeight %d", TILE_WIDTH);
|
|
MADD(" SeaLevel %d", SEALEVEL);
|
|
MADD(" TextureWidth %d", 64); // Hack for editworld
|
|
MADD(" TextureHeight %d", 64);
|
|
MADD(" NumTextures %d", 1);
|
|
MADD(" Textures {");
|
|
MADD(" %s", tilesetTextures[tileset]);
|
|
MADD(" }");
|
|
MADD(" NumTiles %d", map->width * map->height);
|
|
MADD(" Tiles {");
|
|
for (i = 0, x = 0, y = 0; i < map->width * map->height; i++)
|
|
{
|
|
MAPTILE *psTile = mapTile(map, x, y);
|
|
|
|
// Example: TID 1 VF 0 TF 0 F 0 VH 128 128 128 128
|
|
// TID is texture identification
|
|
// VF is triangle (vertex) flip. If value of one, it is flipped.
|
|
// TF is tile or texture flip. If value of one, it is flipped in the X direction. Otherwise Y direction.
|
|
// F are bitflags, with these values:
|
|
// 2 : Triangle flip
|
|
// 4 : Texture flip X (yes, duplicate info)
|
|
// 8 : Texture flip Y (ditto)
|
|
// 16 : Rotate 90 degrees
|
|
// 32 : Rotate 180 degrees (yes, a 270 degree is possible)
|
|
// 64 : Gateway?
|
|
// 128: TF_TEXTURESPARE0, whatever that was, unused even in Editworld
|
|
// VH is vertex height, and gives height of all the four vertices that make up our tile
|
|
int tid = psTile->texture & TILE_NUMMASK;
|
|
int vf = TRI_FLIPPED(psTile);
|
|
int tf = (psTile->texture & TILE_XFLIP) > 0 ? 1 : 0;
|
|
int f = 0;
|
|
int vh[4];
|
|
|
|
// Compose flag
|
|
if (TRI_FLIPPED(psTile)) f += 2;
|
|
if (psTile->texture & TILE_XFLIP) f += 4;
|
|
if (psTile->texture & TILE_YFLIP) f += 8;
|
|
switch ((psTile->texture & TILE_ROTMASK) >> TILE_ROTSHIFT)
|
|
{
|
|
case 0: break;
|
|
case 1: f += 16; break;
|
|
case 2: f += 32; break;
|
|
case 3: f += 48; break;
|
|
default: fprintf(stderr, "Bad rotation value: %d\n", (psTile->texture & TILE_ROTMASK) >> TILE_ROTSHIFT); return -1;
|
|
}
|
|
|
|
// Vertex positions set in clockwise order
|
|
vh[0] = psTile->height;
|
|
vh[1] = vh[2] = vh[3] = 0;
|
|
if (x + 1 < map->width)
|
|
{
|
|
vh[1] = mapTile(map, x + 1, y)->height;
|
|
}
|
|
if (x + 1 < map->width && y + 1 < map->height)
|
|
{
|
|
vh[2] = mapTile(map, x + 1, y + 1)->height;
|
|
}
|
|
if (y + 1 < map->height)
|
|
{
|
|
vh[3] = mapTile(map, x, y + 1)->height;
|
|
}
|
|
|
|
// No idea why +1 to TID. In EditWorld source, it is a "hide" flag.
|
|
MADD(" TID %d VF %d TF %d F %d VH %d %d %d %d",
|
|
tid + 1, vf, tf, f, vh[0], vh[1], vh[2], vh[3]);
|
|
x++;
|
|
if (x == map->width)
|
|
{
|
|
x = 0;
|
|
y++;
|
|
}
|
|
}
|
|
MADD(" }");
|
|
MADD("}");
|
|
MADD("ObjectList {");
|
|
MADD(" Version 3");
|
|
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 {");
|
|
MADD(" Version 1");
|
|
MADD(" NumLimits 1"); // FIXME: do scroll limits go here?
|
|
MADD(" Limits {");
|
|
MADD(" \"Entire Map\" 0 0 0 %d %d", map->width, map->height);
|
|
MADD(" }");
|
|
MADD("}");
|
|
MADD("Gateways {");
|
|
MADD(" Version 1");
|
|
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 {");
|
|
MADD(" NumTiles 128"); // ??? FIXME - read from ttypes file
|
|
MADD(" Tiles {");
|
|
switch (tileset)
|
|
{
|
|
case TILESET_ARIZONA:
|
|
MADD(" 2 1 0 2 2 0 2 2 2 2 1 1 1 0 7 7\n"
|
|
" 7 7 7 8 6 4 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{"); // ??
|
|
MADD(" NumTiles 128");
|
|
MADD(" Flags {");
|
|
MADD(" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
MADD(" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
MADD(" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
MADD(" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
MADD(" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
MADD(" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
MADD(" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
MADD(" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0");
|
|
MADD(" }");
|
|
MADD("}");
|
|
MADD("Brushes {");
|
|
MADD(" Version 2");
|
|
MADD(" NumEdgeBrushes 16");
|
|
MADD(" NumUserBrushes 0");
|
|
MADD(" EdgeBrushes {");
|
|
MADD(" 0 128 0 -1 0 46 16 46 32 30 32 46 0 30 16 47 0 64 0 46 48 47 0 30 48 64 16 30 0 64 48 64 32 65 16");
|
|
MADD(" 0 128 0 -1 0 43 16 43 32 30 32 43 0 30 16 47 0 10 0 43 48 47 0 30 48 10 16 30 0 10 48 10 32 42 0");
|
|
MADD(" 0 128 0 -1 0 10 32 10 48 45 32 10 16 45 16 47 0 64 0 10 0 47 0 45 48 64 16 45 0 64 48 64 32 65 128");
|
|
MADD(" 0 128 0 -1 0 34 0 34 16 32 0 34 48 32 48 -1 0 33 0 34 32 -1 0 32 16 33 16 32 32 33 48 33 32 18 0");
|
|
MADD(" 0 128 0 -1 0 4 32 4 48 3 48 4 16 3 32 -1 0 5 32 4 0 -1 0 3 0 5 48 3 16 5 16 5 0 6 0");
|
|
MADD(" 0 128 0 -1 0 46 16 46 32 47 0 46 0 47 16 -1 0 19 0 46 48 -1 0 47 48 19 16 47 32 19 48 19 32 6 128");
|
|
MADD(" 0 128 0 -1 0 5 0 5 16 3 16 5 48 3 0 -1 0 4 0 5 32 -1 0 3 32 4 16 3 48 4 48 4 32 1 128");
|
|
MADD(" 0 128 0 -1 0 11 0 11 16 13 0 11 48 13 48 6 128 12 0 11 32 6 128 13 16 12 16 13 32 12 48 12 32 6 128");
|
|
MADD(" 0 128 0 -1 0 41 32 41 48 39 48 41 16 39 32 -1 0 40 32 41 0 -1 0 39 0 40 48 39 16 40 16 40 0 54 128");
|
|
MADD(" 0 128 0 -1 0 36 0 36 16 35 16 36 48 35 0 -1 0 37 0 36 32 -1 0 35 32 37 16 35 48 37 48 37 32 54 0");
|
|
MADD(" 0 128 0 -1 0 66 0 66 16 68 0 66 48 68 48 -1 0 67 0 66 32 -1 0 68 16 67 16 68 32 67 48 67 32 42 128");
|
|
MADD(" 0 128 0 -1 0 78 32 78 48 77 32 78 16 77 16 -1 0 55 32 78 0 -1 0 77 48 55 48 77 0 55 16 55 0 65 128");
|
|
MADD(" 0 128 0 -1 0 21 32 21 48 22 48 21 16 22 32 -1 0 20 32 21 0 -1 0 22 0 20 48 22 16 20 16 20 0 23 128");
|
|
MADD(" 0 128 0 -1 0 67 32 67 48 68 32 67 16 68 16 -1 0 66 32 67 0 -1 0 68 48 66 48 68 0 66 16 66 0 65 128");
|
|
MADD(" 0 128 0 -1 0 12 32 12 48 49 32 12 16 49 16 -1 0 11 32 12 0 -1 0 49 48 11 48 49 0 11 16 11 0 42 0");
|
|
MADD(" 0 128 0 -1 0 16 16 16 32 15 32 16 0 15 16 15 16 17 16 16 48 15 16 15 48 17 32 15 0 17 0 17 48 18 0");
|
|
MADD(" }");
|
|
MADD("}");
|
|
|
|
fclose(fp);
|
|
mapFree(map);
|
|
|
|
return 0;
|
|
}
|