Add fog of war
[dungeon1] / map.c
diff --git a/map.c b/map.c
index 4b948ff..2dedb2d 100644 (file)
--- a/map.c
+++ b/map.c
@@ -31,12 +31,68 @@ readmap(char *fname)
        return map;
 }
 
+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<T || y>H) {
+                       continue;
+               }
+               for (x=xpos-SEEDIST; x <= xpos+SEEDIST; x++) {
+                       if (x<0 || x>W) {
+                               continue;
+                       }
+                       mvaddch(y, x, map->map[y][x]);
+               }
+       }
+       move(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; y<H; y++) {
+               for (x=0; x<W; x++) {
+                       if (map->map[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);
+       mvprintw(0, 60, "map: %s", map->name);
        for (y=T; y<H; y++) {
                for (x=0; x<W; x++) {
                        mvaddch(y, x, map->map[y][x]);