eric (02/12/83)
#N:whuxlb:1100002:000:5664 whuxlb!eric Feb 11 18:59:00 1983 Ok, here is my map combiner program. It takes radar from ships and maps, and outputs an empire compatible map of the combined terrain. Therefore, this map could be saved, and used again with new data to build a map of the world. Files for the program are created with "radar # >file, radar # >>file, or map ##:##,##:## > [>>] file". Note that for maps, you must specify the sectors, the prgram will barf on "# or #1 or such". Enjoy, and of course, report any bugs or improvments you make. Eric Holtman harpo!whuxlb!eric ----- start combrad.c ----- /****************************************************************************** * * * Copyright by Eric Holtman Feburary, 1983 * * * * * * Combine empire radar and maps into big maps (which can be saved and * * sent through this program again to build even bigger maps. * * * * syntax: * * combrad [ ##:##,##:## | - | ##,##] file [more files] * * * * where ##:##,##:## would be an empire-type range of area to map, * * ##,## is a sector around which a whole 24x80 map will be drawn * * - means spit out the smallest map that contains all information * * like "realm #0" in empire * * * * any number of files may be specified (1 is nessecary). Files should be * * output of "radar/map 10 >file" or "radar/map 10 >>file" type. Doctoring * * may lead to strange results. Maps must supply coordinates (##:##,##:##), * * not just a realm number. * ******************************************************************************/ #include "stdio.h" #define YLEN 256 #define XLEN 256 #define NEXTLINE fgets(curlin,XLEN+2,rads) char tab[YLEN][XLEN+2]; char lines[80][80]; char curlin[XLEN+2]; int i,j,k,l; int x,y,hx,lx,hy,ly; int eof = 0; FILE *rads; int highx = -2000; int highy = -2000; int lowx = 2000; int lowy = 2000; main(argc,argv) int argc; char **argv; { if (argc < 3) { printf("Usage: %s [ ##:##,##:## | - | ##,##] file [more files]\n",argv[0]); exit(0); } for (i=0;i<YLEN;i++) { for (j=0;j<XLEN;j++) { tab[i][j] = ' '; } } argc--; while (argc > 1) { if ( (rads = fopen(argv[argc],"r")) == NULL) { printf("%s: cannot open",argv[argc]); exit(0); } NEXTLINE; NEXTLINE; while (rads != NULL) { if (index(curlin,"rad") == 0) { if (radar() == 0) break; } if (index(curlin,"map") == 0) { if (map() == 0) break; } } fclose(rads); argc--; } eof = 0; if (argv[1][0] == '-' && argv[1][1] == 0) { hx = highx; lx = lowx; hy = highy; ly = lowy; } else if (strchr(argv[1],':') == NULL) { if (sscanf(argv[1],"%d,%d",&x,&y) != 2) eof = 1; lx = x - 35; hx = x + 35; ly = y - 9; hy = y + 9; } else { if (sscanf(argv[1],"%d:%d,%d:%d",&lx,&hx,&ly,&hy) != 4) eof = 1; } if (eof) { printf("Illegal specification: %s\n",argv[1]); printf("Usage: %s [ ##:##,##:## | - | ##,##] file [more files]\n",argv[0]); exit(0); } printf("\nmap %d:%d,%d:%d\n",lx,hx,ly,hy); doheader(); for (i = ly;i<=hy;i++) { printf("%3d ",i); for (j=lx;j<=hx;j++) { putchar(tab[i+(YLEN/2)][j+(XLEN/2)]); } printf(" %-d\n",i); } doheader(); } index(s,t) char s[],t[]; { int i,j,k; for (i=0;s[i] != '\0'; i++) { for (j=i,k=0;t[k] != 0 && s[j] == t[k];j++,k++); if (t[k] == 0) return(i); } return(-1); } map() { sscanf(curlin,"%*s %d:%d,%d:%d",&lx,&hx,&ly,&hy); NEXTLINE; NEXTLINE; for (i=ly;i<=hy;i++) { NEXTLINE; for (j=lx;j<=hx;j++) { if (curlin[(j-lx) + 4] != ' ') { intab(i,j,curlin[(j-lx) + 4]); } } } NEXTLINE; NEXTLINE; if (NEXTLINE == NULL) { return(0); } NEXTLINE; return(1); } radar() { NEXTLINE; while ((rads != NULL)) { if (strlen(curlin) == 1) { NEXTLINE; return(1); } i = index(curlin," at "); sscanf(&curlin[i+4],"%d, %d",&x,&y); NEXTLINE; for (i=0;i<80;i++) { for (j=0;j<80;j++) lines[i][j] = ' '; if (fgets(lines[i],80,rads) == NULL) { eof = 1; break; } if (lines[i][0] != ' ') break; for (j=0;j<strlen(lines[i]);j++) { if (lines[i][j] != '\n' && lines[i][j] != ' ') break; } if (j == strlen(lines[i])) { i--; } } strcpy(curlin,lines[i]); lines[i][0] = 0; ly = (y - (i-2)/2) - 1; hy = (y + (i-2)/2) + 1; lx = (x - (i-2)) - 1; hx = (x + (i-2)) + 1; for (i=0,j=ly;j<=hy;i++,j++) { for (k=1,l=lx;l<=hx;k++,l++) { if (lines[i][k] == 0) break; if (lines[i][k] != ' ') { intab(j,l,lines[i][k]); } } } if (eof == 1) return(0); } } intab(qi,qj,qc) int qi,qj; char qc; { if (qc == ' ') return; if (qj < lowx) lowx = qj; if (qj > highx) highx = qj; if (qi < lowy) lowy = qi; if (qi > highy) highy = qi; tab[qi+YLEN/2][qj+XLEN/2] = qc; return; } doheader() { printf(" "); for (i = lx;i<=hx;i++) { j = i / 10; if (i >= -9 && i < 0) printf("-"); else printf("%d",(j<0) ? (-j) : j); } printf("\n "); for (i = lx;i<=hx;i++) { j = i % 10; printf("%d",(j<0) ? (-j) : j); } putchar('\n'); } ----- end combrad.c -----
jfw (02/14/83)
I also wrote a mapmaker program while I was involved with empire. I also wrote a program (called FEEDME) which would analyze status reports and tell which sectors should have food shipped to them (which I always did by hand, to avoid plague). It did other interesting things related to that idea. If there is any interest, I will send out the source, if I can dig it up again. John Woods, ...!decvax!genradbo!mitccc!jfw