/* ### 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 *);
* 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;
/*
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.
*
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 */