diff --git a/include/extern.h b/include/extern.h index 7c6bac9c1..de0294635 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2171,6 +2171,7 @@ extern boolean create_particular(void); /* ### rect.c ### */ extern void init_rect(void); +extern void free_rect(void); extern NhRect *get_rect(NhRect *); extern NhRect *rnd_rect(void); extern void remove_rect(NhRect *); diff --git a/src/rect.c b/src/rect.c index 26d7a1167..5aaf4a688 100644 --- a/src/rect.c +++ b/src/rect.c @@ -13,11 +13,11 @@ static boolean intersect(NhRect *, NhRect *, NhRect *); * need for room generation. */ -#define MAXRECT 50 #define XLIM 4 #define YLIM 3 -static NhRect rect[MAXRECT + 1]; +static NhRect *rect = (NhRect *) 0; +static int n_rects = 0; static int rect_cnt; /* @@ -28,12 +28,28 @@ static int rect_cnt; void init_rect(void) { + if (!rect) { + n_rects = (COLNO * ROWNO) / 30; + rect = (NhRect *) alloc(sizeof(NhRect) * n_rects); + if (!rect) + panic("Could not alloc rect"); + } + rect_cnt = 1; rect[0].lx = rect[0].ly = 0; rect[0].hx = COLNO - 1; rect[0].hy = ROWNO - 1; } +void +free_rect(void) +{ + if (rect) + free(rect); + n_rects = rect_cnt = 0; +} + + /* * Search Index of one precise NhRect. * @@ -133,9 +149,8 @@ remove_rect(NhRect* r) void add_rect(NhRect* r) { - if (rect_cnt >= MAXRECT) { - if (wizard) - pline("MAXRECT may be too small."); + if (rect_cnt >= n_rects) { + impossible("n_rects may be too small."); return; } /* Check that this NhRect is not included in another one */ diff --git a/src/save.c b/src/save.c index 3fa32a431..27106c908 100644 --- a/src/save.c +++ b/src/save.c @@ -1082,6 +1082,7 @@ freedynamicdata(void) free_waterlevel(); free_dungeons(); free_CapMons(); + free_rect(); /* some pointers in iflags */ if (iflags.wc_font_map)