-/* NetHack 3.6 extern.h $NHDT-Date: 1581322657 2020/02/10 08:17:37 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.795 $ */
+/* NetHack 3.6 extern.h $NHDT-Date: 1581562570 2020/02/13 02:56:10 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.796 $ */
/* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */
E boolean FDECL(load_special, (const char *));
E xchar FDECL(selection_getpoint, (int, int, struct selectionvar *));
E struct selectionvar *NDECL(selection_new);
-E void FDECL(selection_free, (struct selectionvar *));
+E void FDECL(selection_free, (struct selectionvar *, BOOLEAN_P));
#if !defined(IN_SP_LEV_C)
E void FDECL(set_selection_floodfillchk, (int FDECL((*), (int,int))));
#endif
-/* NetHack 3.7 nhlua.c $NHDT-Date: 1581280068 2020/02/09 20:27:48 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.8 $ */
+/* NetHack 3.7 nhlua.c $NHDT-Date: 1581562591 2020/02/13 02:56:31 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.9 $ */
/* Copyright (c) 2018 by Pasi Kallinen */
/* NetHack may be freely redistributed. See license for details. */
struct selectionvar *sel;
luaL_checktype(L, index, LUA_TUSERDATA);
- sel = (struct selectionvar *)luaL_checkudata(L, index, "selection");
+ sel = (struct selectionvar *) luaL_checkudata(L, index, "selection");
if (!sel)
nhl_error(L, "Selection error");
return sel;
lua_State *L;
{
struct selectionvar *sel = l_selection_check(L, 1);
+
if (sel)
- selection_free(sel);
+ selection_free(sel, FALSE);
return 0;
}
lua_State *L;
{
struct selectionvar *tmp = selection_new();
- struct selectionvar *sel = (struct selectionvar *)lua_newuserdata(L, sizeof(struct selectionvar));
+ struct selectionvar
+ *sel = (struct selectionvar *) lua_newuserdata(L, sizeof sel);
+
luaL_getmetatable(L, "selection");
lua_setmetatable(L, -2);
sel->wid = tmp->wid;
sel->hei = tmp->hei;
sel->map = dupstr(tmp->map);
- selection_free(tmp);
- free(tmp);
+ selection_free(tmp, TRUE);
return sel;
}
-/* NetHack 3.6 sp_lev.c $NHDT-Date: 1580610435 2020/02/02 02:27:15 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.153 $ */
+/* NetHack 3.6 sp_lev.c $NHDT-Date: 1581562593 2020/02/13 02:56:33 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.157 $ */
/* Copyright (c) 1989 by Jean-Christophe Collet */
/* NetHack may be freely redistributed. See license for details. */
struct selectionvar *
selection_new()
{
- struct selectionvar *
- tmps = (struct selectionvar *) alloc(sizeof (struct selectionvar));
+ struct selectionvar *tmps = (struct selectionvar *) alloc(sizeof tmps);
tmps->wid = COLNO;
tmps->hei = ROWNO;
- tmps->map = (char *)alloc((COLNO * ROWNO) + 1);
+ tmps->map = (char *) alloc((COLNO * ROWNO) + 1);
(void) memset(tmps->map, 1, (COLNO * ROWNO));
tmps->map[(COLNO * ROWNO)] = '\0';
}
void
-selection_free(sel)
+selection_free(sel, freesel)
struct selectionvar *sel;
+boolean freesel;
{
- if (!sel)
- return;
- Free(sel->map);
- sel->map = NULL;
- sel->wid = sel->hei = 0;
+ if (sel) {
+ Free(sel->map);
+ sel->map = NULL;
+ if (freesel)
+ free((genericptr_t) sel);
+ else
+ sel->wid = sel->hei = 0;
+ }
}
struct selectionvar *
if (selection_getpoint(x, y, tmp))
selection_setpoint(x, y, ov, 1);
- selection_free(tmp);
- free(tmp);
+ selection_free(tmp, TRUE);
}
static int FDECL((*selection_flood_check_func), (int, int));
xchar dy[SEL_FLOOD_STACK];
if (selection_flood_check_func == (int FDECL((*), (int, int))) 0) {
- selection_free(tmp);
+ selection_free(tmp, TRUE);
return;
}
SEL_FLOOD(x, y);
#undef SEL_FLOOD
#undef SEL_FLOOD_STACK
#undef SEL_FLOOD_CHKDIR
- selection_free(tmp);
- free(tmp);
+ selection_free(tmp, TRUE);
}
/* McIlroy's Ellipse Algorithm */
/* try to make a hole or a trapdoor */
if (Can_fall_thru(&u.uz)) {
- selection_free(ov3);
+ selection_free(ov3, TRUE);
ov3 = selection_clone(ov2);
while (selection_rndcoord(ov3, &x, &y, TRUE)) {
if (maketrap(x,y, rn2(2) ? HOLE : TRAPDOOR))
res = FALSE;
gotitdone:
- selection_free(ov2);
- free(ov2);
- selection_free(ov3);
- free(ov3);
+ selection_free(ov2, TRUE);
+ selection_free(ov3, TRUE);
return res;
}
do {
ret = TRUE;
- for (x = 0; x < COLNO; x++)
+ for (x = 1; x < COLNO; x++)
for (y = 0; y < ROWNO; y++)
if (ACCESSIBLE(levl[x][y].typ)
&& !selection_getpoint(x, y, ov)) {
- if (generate_way_out_method(x,y, ov))
- selection_floodfill(ov, x,y, TRUE);
+ if (generate_way_out_method(x, y, ov))
+ selection_floodfill(ov, x, y, TRUE);
ret = FALSE;
goto outhere;
}
- outhere: ;
+ outhere:
+ ;
} while (!ret);
- selection_free(ov);
- free(ov);
+ selection_free(ov, TRUE);
}
int
create_des_coder();
- if (argc == 1)
+ if (argc == 1) {
sel = l_selection_check(L, -1);
- else if (argc == 0) {
+ } else if (argc == 0) {
freesel = TRUE;
sel = selection_new();
selection_not(sel);
if (sel) {
selection_iterate(sel, sel_set_wall_property, (genericptr_t) &prop);
- if (freesel) {
- selection_free(sel);
- free(sel);
- }
+ if (freesel)
+ selection_free(sel, TRUE);
}
}