164 lines
3.7 KiB
C
164 lines
3.7 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdarg.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <time.h>
|
||
|
#include <sys/time.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
#include <SDL/SDL.h>
|
||
|
#include <SDL/SDL_keysym.h>
|
||
|
#include "convert.h"
|
||
|
#include "constants.h"
|
||
|
|
||
|
char text[BUFLEN];
|
||
|
|
||
|
int nummaps;
|
||
|
int curmap;
|
||
|
int modified;
|
||
|
|
||
|
int main (int argc, char **argv) {
|
||
|
if (argc != 3) {
|
||
|
printf("convert - converts old netmapr 0.98 maps to new format.\n",argv[0]);
|
||
|
printf("usage: %s source dest\n",argv[0]);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
strcpy(text, argv[1]);
|
||
|
loadmap();
|
||
|
|
||
|
strcpy(text, argv[2]);
|
||
|
savemap();
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int loadmap(void) {
|
||
|
char filename[BUFLEN];
|
||
|
FILE *f;
|
||
|
int namelen;
|
||
|
int i;
|
||
|
/* TODO: validate */
|
||
|
strcpy(filename, text);
|
||
|
|
||
|
|
||
|
f = fopen(filename, "rb");
|
||
|
if (!f) {
|
||
|
printf("ERROR: Cannot open '%s'.\n",filename);
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
/* TODO: free() variables! */
|
||
|
|
||
|
|
||
|
/* read in number maps */
|
||
|
fread(&nummaps, sizeof(int), 1, f);
|
||
|
|
||
|
for (i = 0; i < nummaps; i++) {
|
||
|
fread(&map[i].width, sizeof(int), 1, f);
|
||
|
fread(&map[i].height, sizeof(int), 1, f);
|
||
|
fread(&map[i].bpp, sizeof(int), 1, f);
|
||
|
fread(&map[i].bgcol, sizeof(SDL_Color), 1, f);
|
||
|
fread(&map[i].boxcol, sizeof(SDL_Color), 1, f);
|
||
|
fread(&map[i].numthings, sizeof(int), 1, f);
|
||
|
fread(&map[i].numobjects, sizeof(int), 1, f);
|
||
|
fread(&map[i].numlinks, sizeof(int), 1, f);
|
||
|
fread(&map[i].numtext, sizeof(int), 1, f);
|
||
|
map[i].selecteditem = -1;
|
||
|
map[i].selecteditemtype = -1;
|
||
|
map[i].selectedlinkpoint = -1;
|
||
|
map[i].selectedtype = 0;
|
||
|
map[i].curobj = -1;
|
||
|
map[i].curlink = -1;
|
||
|
map[i].curlinkpoint = -1;
|
||
|
map[i].curtext = -1;
|
||
|
map[i].startx = -1;
|
||
|
map[i].starty = -1;
|
||
|
map[i].textanchor = -1;
|
||
|
strcpy(map[i].text, "");
|
||
|
|
||
|
fread(&namelen, sizeof(int), 1, f);
|
||
|
fread(&map[i].name, (namelen+1) * sizeof(char), 1, f);
|
||
|
|
||
|
/* read objects */
|
||
|
fread(&map[i].thing, sizeof(thing_t), map[i].numthings, f);
|
||
|
fread(&map[i].olink, sizeof(link_t), map[i].numlinks, f);
|
||
|
fread(&map[i].obj, sizeof(object_t), map[i].numobjects, f);
|
||
|
fread(&map[i].textob, sizeof(text_t), map[i].numtext, f);
|
||
|
}
|
||
|
|
||
|
fclose(f);
|
||
|
|
||
|
curmap = 0;
|
||
|
|
||
|
modified = FALSE;
|
||
|
printf("Successfully loaded map from '%s' (%d maps).\n",filename,nummaps); fflush(stdout);
|
||
|
|
||
|
return FALSE;
|
||
|
}
|
||
|
|
||
|
|
||
|
int savemap(void) {
|
||
|
char filename[BUFLEN];
|
||
|
FILE *f;
|
||
|
int namelen;
|
||
|
int i;
|
||
|
|
||
|
/* TODO: validate */
|
||
|
strcpy(filename, text);
|
||
|
|
||
|
|
||
|
printf("Saving map...\n");
|
||
|
|
||
|
|
||
|
if ((f = fopen(filename, "wb")) == NULL) {
|
||
|
printf("ERROR: Could not open '%s'.\n",filename);
|
||
|
return TRUE;
|
||
|
}
|
||
|
|
||
|
/* dump out numbers of map[curmap].objects */
|
||
|
fwrite(&nummaps, sizeof(int), 1, f);
|
||
|
|
||
|
for (i = 0; i < nummaps; i++) {
|
||
|
fwrite(&map[i].width, sizeof(int), 1, f);
|
||
|
fwrite(&map[i].height, sizeof(int), 1, f);
|
||
|
fwrite(&map[i].bpp, sizeof(int), 1, f);
|
||
|
fwrite(&map[i].bgcol, sizeof(SDL_Color), 1, f);
|
||
|
fwrite(&map[i].boxcol, sizeof(SDL_Color), 1, f);
|
||
|
fwrite(&map[i].numthings, sizeof(int), 1, f);
|
||
|
fwrite(&map[i].numobjects, sizeof(int), 1, f);
|
||
|
fwrite(&map[i].numlinks, sizeof(int), 1, f);
|
||
|
fwrite(&map[i].numtext, sizeof(int), 1, f);
|
||
|
/* selecteditem*/
|
||
|
/* selecteditemtype*/
|
||
|
/* selectedlinkpoint*/
|
||
|
/* selectedtype*/
|
||
|
/* curobj*/
|
||
|
/* curlink*/
|
||
|
/* curlinkpoint*/
|
||
|
/* curtext*/
|
||
|
/* startx,starty */
|
||
|
/* textanchor */
|
||
|
/* text*/
|
||
|
namelen = strlen(map[i].name);
|
||
|
fwrite(&namelen, sizeof(int), 1, f);
|
||
|
fwrite(&map[i].name, (namelen+1) * sizeof(char), 1, f);
|
||
|
|
||
|
/* write objects */
|
||
|
fwrite(&map[i].thing, sizeof(thing_t), map[i].numthings, f);
|
||
|
fwrite(&map[i].olink, sizeof(link_t), map[i].numlinks, f);
|
||
|
fwrite(&map[i].obj, sizeof(mapobject_t), map[i].numobjects, f);
|
||
|
fwrite(&map[i].textob, sizeof(text_t), map[i].numtext, f);
|
||
|
}
|
||
|
|
||
|
fclose(f);
|
||
|
|
||
|
|
||
|
modified = FALSE;
|
||
|
printf("Successfully saved map to '%s'.\n",filename);
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
}
|