X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=map.c;h=4c548e6fab02aacea66ed51fff6fdc228d490f14;hb=HEAD;hp=2dedb2dcd757efea1e43443d0b5e33dc4fec556a;hpb=cccecbe0c0861ecef1cb511378132f9e981056e6;p=dungeon1 diff --git a/map.c b/map.c index 2dedb2d..4c548e6 100644 --- a/map.c +++ b/map.c @@ -1,5 +1,7 @@ #include "main.h" +static void beautifymap(struct map *); +static char getnewchar(struct map *, int, int); struct map * readmap(char *fname) @@ -18,9 +20,8 @@ readmap(char *fname) return NULL; } - x = y = 0; - for (y=0; ymap[y][x] = fgetc(fp); } if (fgetc(fp) != '\n') { @@ -28,9 +29,101 @@ readmap(char *fname) return NULL; } } + beautifymap(map); return map; } +static void +beautifymap(struct map *map) +{ + int x, y; + char c; + + for (y=0; ymap[y][x]; + if (c != '#') { + continue; + } + map->map[y][x] = getnewchar(map, y, x); + } + } + for (y=0; ymap[y][x]; + if (c == '#') { + map->map[y][x] = ' '; + } + } + } +} + +static char +getnewchar(struct map *map, int y, int x) +{ + char l, r, a, b; + char la, lb, ra, rb; + enum { + L, R, A, B, + }; + static struct nbors { + char n[5]; + char newc; + } nborstable[] = { + { "####", '#' }, + { " ", '+' }, + { "# ", '+' }, + { "## ", '-' }, + { "### ", '-' }, + { "## #", '-' }, + { " # ", '+' }, + { " ##", '|' }, + { " ###", '|' }, + { "# ##", '|' }, + { "# # ", '\'' }, + { " ## ", '\'' }, + { " # ", '\'' }, + { "# #", '.' }, + { " # #", '.' }, + { " #", '.' }, + { "", '\0' }, + }; + struct nbors *p; + + l = x-1 < 0 ? '#' : map->map[y][x-1]; + l = strchr(WALLCHARS, l) ? '#' : ' '; + r = x+1 > W ? '#' : map->map[y][x+1]; + r = strchr(WALLCHARS, r) ? '#' : ' '; + a = y-1 < 0 ? '#' : map->map[y-1][x]; + a = strchr(WALLCHARS, a) ? '#' : ' '; + b = y+1 > H ? '#' : map->map[y+1][x]; + b = strchr(WALLCHARS, b) ? '#' : ' '; + + la = x-1 < 0 || y-1 < 0 ? '#' : map->map[y-1][x-1]; + la = strchr(WALLCHARS, la) ? '#' : ' '; + ra = x+1 > W || y-1 < 0 ? '#' : map->map[y-1][x+1]; + ra = strchr(WALLCHARS, ra) ? '#' : ' '; + lb = x-1 < 0 || y+1 > H ? '#' : map->map[y+1][x-1]; + lb = strchr(WALLCHARS, lb) ? '#' : ' '; + rb = x+1 > W || y+1 > H ? '#' : map->map[y+1][x+1]; + rb = strchr(WALLCHARS, rb) ? '#' : ' '; + + for (p=nborstable; *p->n; p++) { + if (p->n[L] == l && p->n[R] == r && p->n[A] == a && p->n[B] == b) { + if (strcmp(p->n, "####")==0) { + if (la==' ' || ra==' ') { + return '\''; + } + if (lb==' ' || rb==' ') { + return '.'; + } + } + return p->newc; + } + } + return map->map[y][x]; +} + struct map * getblackmap(void) { @@ -48,17 +141,17 @@ see(struct map *map, int ypos, int xpos) int y, x; for (y=ypos-SEEDIST; y <= ypos+SEEDIST; y++) { - if (yH) { + if (y<0 || y>=MAPH) { continue; } for (x=xpos-SEEDIST; x <= xpos+SEEDIST; x++) { - if (x<0 || x>W) { + if (x<0 || x>=MAPW) { continue; } - mvaddch(y, x, map->map[y][x]); + mvwaddch(w_map, y, x, map->map[y][x]); } } - move(ypos, xpos); + wmove(w_map, ypos, xpos); } void @@ -76,8 +169,8 @@ findchar(struct map *map, char c, int *yret, int *xret) { int y, x; - for (y=0; ymap[y][x] == c) { *yret = y; *xret = x; @@ -92,10 +185,10 @@ showmap(struct map *map) { int x, y; - mvprintw(0, 60, "map: %s", map->name); - for (y=T; ymap[y][x]); + mvwprintw(w_info, 1, 20, "map: %s", map->name); + for (y=0; ymap[y][x]); } } }