home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume4 / xconq5 / part17 / hexify.c < prev    next >
C/C++ Source or Header  |  1988-07-01  |  2KB  |  89 lines

  1. /* Quicky hack to convert old-style maps into new-style.  R/W to stdin/out. */
  2. /* Unit side names evaporate entirely, sigh, and no run-length encoding. */
  3.  
  4. #include <stdio.h>
  5. #include "misc.h"
  6.  
  7. #define SEPCHAR '*'
  8.  
  9. char citybuf[8000];
  10. char *uname[1000], *usname[1000];
  11. /* have to do something about this! */
  12. char terrchars[] = ".,=+%~(^_:";
  13. char terrain[400][400];
  14. int ux[1000], uy[1000], utype[1000];
  15.  
  16. main()
  17. {
  18.     char ch, *name, *sname, *next;
  19.     int worldwidth, worldheight, worldscale, greenwich, equator;
  20.     int i, j, x, y, terr, x1, numcities = 0;
  21.     
  22.     scanf("M %d %d %d %d %d\n",
  23.       &worldwidth, &worldheight, &greenwich, &equator, &worldscale);
  24.     for (y = worldheight-1; y >= 0; --y) {
  25.     for (x = 0; x < worldwidth; ++x) {
  26.         x1 = x - y / 2;          /* New x coordinate */
  27.         if (x1 < 0) x1 += worldwidth;
  28.         scanf("%c", &ch);
  29.         terr = iindex(ch, terrchars);
  30.         if (terr < 0) {
  31.         terr = '+';
  32.         ux[numcities] = x1;  uy[numcities] = y;
  33.         utype[numcities] = ch;
  34.         numcities++;
  35.         }
  36.         terrain[x1][y] = terr;
  37.     }
  38.     scanf("\n");
  39.     }
  40.     i = 0;
  41.     while ((ch = getc(stdin)) != EOF) {
  42.     if (ch == ' ' || ch == '\n' || ch == '\t') ch = '\0';
  43.     if (ch == '\\') ch = getc(stdin);
  44.     citybuf[i++] = ch;
  45.     }
  46.     citybuf[i++] = '\0';  /* in case somebody forgot a newline at EOF */
  47.     name = citybuf;
  48.     for (i = 0; i < numcities; ++i) {
  49.     next = (char *) index(name,'\0');
  50.     sname = (char *) index(name, SEPCHAR);
  51.     if (sname != NULL) *sname++ = '\0';
  52.     uname[i] = name;
  53.     usname[i] = sname;
  54.     while (*next++ == '\0');
  55.     name = next-1;
  56.     }
  57.     printf("Xconq 0 -+---+\n");
  58.     printf("Map %d %d %d 1 0\n", worldwidth, worldheight, worldscale);
  59.     for (y = worldheight-1; y >= 0; --y) {
  60.     for (x = 0; x < worldwidth; ++x) {
  61.         putc(terrchars[(int) terrain[x][y]], stdout);
  62.     }
  63.     printf("\n");
  64.     }
  65.     printf("Units %d 1 0\n", numcities);
  66.     for (i = 0; i < numcities; ++i) {
  67.     if (usname[i] == NULL || strlen(usname[i]) == 1) usname[i] = "*";
  68.     for (j = 0; j < strlen(uname[i]); ++j) {
  69.         if ((uname[i])[j] == ' ') (uname[i])[j] = '*';
  70.     }
  71.     printf("%c %s %d,%d\n", utype[i], uname[i], ux[i], uy[i]);
  72.     }
  73. }
  74.  
  75. /* Get a *numeric* index into a string (infinitely more useful than ptr!). */
  76. /* Return -1 on failed search. */
  77.  
  78. iindex(ch, str)
  79. char ch, *str;
  80. {
  81.     int i;
  82.  
  83.     if (str == NULL) return (-1);
  84.     for (i = 0; str[i] != '\0'; ++i) {
  85.     if (ch == str[i]) return i;
  86.     }
  87.     return (-1);
  88. }
  89.