3 static void beautifymap(struct map *);
4 static char getnewchar(struct map *, int, int);
14 map = calloc(1, sizeof(struct map));
15 map->name = strdup(fname);
17 snprintf(buf, sizeof(buf), "%s/%s", MAPDIR, fname);
18 if (!(fp = fopen(buf, "r"))) {
19 fprintf(stderr, "error fopen() %s\n", buf);
23 for (y=0; y<MAPH; y++) {
24 for (x=0; x<MAPW; x++) {
25 map->map[y][x] = fgetc(fp);
27 if (fgetc(fp) != '\n') {
28 fprintf(stderr, "error file format: no NL at y=%d x=%d\n", y, x);
37 beautifymap(struct map *map)
42 for (y=0; y<MAPH; y++) {
43 for (x=0; x<MAPW; x++) {
48 map->map[y][x] = getnewchar(map, y, x);
51 for (y=0; y<MAPH; y++) {
52 for (x=0; x<MAPW; x++) {
62 getnewchar(struct map *map, int y, int x)
93 l = x-1 < 0 ? '#' : map->map[y][x-1];
94 l = strchr(WALLCHARS, l) ? '#' : ' ';
95 r = x+1 > W ? '#' : map->map[y][x+1];
96 r = strchr(WALLCHARS, r) ? '#' : ' ';
97 a = y-1 < 0 ? '#' : map->map[y-1][x];
98 a = strchr(WALLCHARS, a) ? '#' : ' ';
99 b = y+1 > H ? '#' : map->map[y+1][x];
100 b = strchr(WALLCHARS, b) ? '#' : ' ';
102 la = x-1 < 0 || y-1 < 0 ? '#' : map->map[y-1][x-1];
103 la = strchr(WALLCHARS, la) ? '#' : ' ';
104 ra = x+1 > W || y-1 < 0 ? '#' : map->map[y-1][x+1];
105 ra = strchr(WALLCHARS, ra) ? '#' : ' ';
106 lb = x-1 < 0 || y+1 > H ? '#' : map->map[y+1][x-1];
107 lb = strchr(WALLCHARS, lb) ? '#' : ' ';
108 rb = x+1 > W || y+1 > H ? '#' : map->map[y+1][x+1];
109 rb = strchr(WALLCHARS, rb) ? '#' : ' ';
111 for (p=nborstable; *p->n; p++) {
112 if (p->n[L] == l && p->n[R] == r && p->n[A] == a && p->n[B] == b) {
113 if (strcmp(p->n, "####")==0) {
114 if (la==' ' || ra==' ') {
117 if (lb==' ' || rb==' ') {
124 return map->map[y][x];
132 map = calloc(1, sizeof(struct map));
133 map->name = strdup("(BLACK)");
134 memset(map->map, BLANKCHAR, sizeof(map->map));
139 see(struct map *map, int ypos, int xpos)
143 for (y=ypos-SEEDIST; y <= ypos+SEEDIST; y++) {
144 if (y<0 || y>=MAPH) {
147 for (x=xpos-SEEDIST; x <= xpos+SEEDIST; x++) {
148 if (x<0 || x>=MAPW) {
151 mvwaddch(w_map, y, x, map->map[y][x]);
154 wmove(w_map, ypos, xpos);
158 freemap(struct map *map)
168 findchar(struct map *map, char c, int *yret, int *xret)
172 for (y=0; y<MAPH; y++) {
173 for (x=0; x<MAPW; x++) {
174 if (map->map[y][x] == c) {
184 showmap(struct map *map)
188 mvwprintw(w_info, 1, 20, "map: %s", map->name);
189 for (y=0; y<MAPH; y++) {
190 for (x=0; x<MAPW; x++) {
191 mvwaddch(w_map, y, x, map->map[y][x]);