X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=map.c;h=4c548e6fab02aacea66ed51fff6fdc228d490f14;hb=HEAD;hp=4b948ff699e6329e6ece47827f88c184bbcdf587;hpb=36829587f6a6c375aa2912d955f84871a098c254;p=dungeon1 diff --git a/map.c b/map.c index 4b948ff..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,18 +29,166 @@ 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) +{ + struct map *map; + + map = calloc(1, sizeof(struct map)); + map->name = strdup("(BLACK)"); + memset(map->map, BLANKCHAR, sizeof(map->map)); + return map; +} + +void +see(struct map *map, int ypos, int xpos) +{ + int y, x; + + for (y=ypos-SEEDIST; y <= ypos+SEEDIST; y++) { + if (y<0 || y>=MAPH) { + continue; + } + for (x=xpos-SEEDIST; x <= xpos+SEEDIST; x++) { + if (x<0 || x>=MAPW) { + continue; + } + mvwaddch(w_map, y, x, map->map[y][x]); + } + } + wmove(w_map, ypos, xpos); +} + +void +freemap(struct map *map) +{ + if (!map) { + return; + } + free(map->name); + free(map); +} + +void +findchar(struct map *map, char c, int *yret, int *xret) +{ + int y, x; + + for (y=0; ymap[y][x] == c) { + *yret = y; + *xret = x; + return; + } + } + } +} + void -showmap(struct map* map) +showmap(struct map *map) { int x, y; - mvprintw(0, 50, "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]); } } }