cleanup when exiting tutorial

When returning to play from within the tutorial, remove the level files
similar to how they're discarded for the rest of the dungeon when going
into the endgame.  It turned out to be a bit messier than anticipated.

The dungeon.c bit is sufficient for #overview, which now hides regular
level 1 while in the tutorial and hides all tutorial levels once exited.
Those will still appear in end-of-game disclosure.
This commit is contained in:
PatR
2023-07-17 14:27:28 -07:00
parent 536a4bd8b3
commit 8d60b92407
6 changed files with 39 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 extern.h $NHDT-Date: 1687343496 2023/06/21 10:31:36 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1276 $ */
/* NetHack 3.7 extern.h $NHDT-Date: 1689629242 2023/07/17 21:27:22 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1279 $ */
/* Copyright (c) Steve Creps, 1988. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1399,7 +1399,7 @@ extern void sort_rooms(void);
extern void add_room(int, int, int, int, boolean, schar, boolean);
extern void add_subroom(struct mkroom *, int, int, int, int, boolean, schar,
boolean);
extern void free_luathemes(boolean);
extern void free_luathemes(enum lua_theme_group);
extern void makecorridors(void);
extern void add_door(coordxy, coordxy, struct mkroom *);
extern void count_level_features(void);

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 hack.h $NHDT-Date: 1684374685 2023/05/18 01:51:25 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.218 $ */
/* NetHack 3.7 hack.h $NHDT-Date: 1689629241 2023/07/17 21:27:21 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.222 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Pasi Kallinen, 2017. */
/* NetHack may be freely redistributed. See license for details. */
@@ -400,6 +400,11 @@ struct dgn_topology { /* special dungeon levels for speed */
#define dunlev_reached(x) (gd.dungeons[(x)->dnum].dunlev_ureached)
#define MAXLINFO (MAXDUNGEON * MAXLEVEL)
enum lua_theme_group {
all_themes = 1, /* for end of game */
most_themes = 2, /* for entering endgame */
tut_themes = 3, /* for leaving tutorial */
};
enum earlyarg {
ARG_DEBUG, ARG_VERSION, ARG_SHOWPATHS

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 do.c $NHDT-Date: 1688415121 2023/07/03 20:12:01 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.357 $ */
/* NetHack 3.7 do.c $NHDT-Date: 1689629244 2023/07/17 21:27:24 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.358 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Derek S. Ray, 2015. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1413,6 +1413,7 @@ goto_level(
boolean cant_go_back, great_effort,
up = (depth(newlevel) < depth(&u.uz)),
newdungeon = (u.uz.dnum != newlevel->dnum),
leaving_tutorial = FALSE,
was_in_W_tower = In_W_tower(u.ux, u.uy, &u.uz),
familiar = FALSE,
new = FALSE; /* made a new level? */
@@ -1436,7 +1437,7 @@ goto_level(
} else if (In_tutorial(&u.uz)) {
tutorial(FALSE); /* leaving tutorial */
up = FALSE; /* re-enter level 1 as if starting new game */
/* TODO: remove tutorial level(s) from #overview data */
leaving_tutorial = TRUE;
}
}
new_ledger = ledger_no(newlevel);
@@ -1561,13 +1562,13 @@ goto_level(
* for the level being left, to recover dynamic memory in use and
* to avoid dangling timers and light sources.
*/
cant_go_back = (newdungeon && In_endgame(newlevel));
cant_go_back = ((newdungeon && In_endgame(newlevel)) || leaving_tutorial);
if (!cant_go_back) {
update_mlstmv(); /* current monsters are becoming inactive */
if (nhfp->structlevel)
bufon(nhfp->fd); /* use buffered output */
} else {
free_luathemes(TRUE);
free_luathemes(leaving_tutorial ? tut_themes : most_themes);
}
save_mode = nhfp->mode;
nhfp->mode = cant_go_back ? FREEING : (WRITING | FREEING);
@@ -1577,10 +1578,12 @@ goto_level(
if (cant_go_back) {
/* discard unreachable levels; keep #0 */
for (l_idx = maxledgerno(); l_idx > 0; --l_idx)
delete_levelfile(l_idx);
if (!leaving_tutorial || ledger_to_dnum(l_idx) == tutorial_dnum)
delete_levelfile(l_idx);
/* mark #overview data for all dungeon branches as uninteresting */
for (l_idx = 0; l_idx < gn.n_dgns; ++l_idx)
remdun_mapseen(l_idx);
if (!leaving_tutorial || l_idx == tutorial_dnum)
remdun_mapseen(l_idx);
/* get rid of mons & objs scheduled to migrate to discarded levels */
discard_migrations();
}

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 dungeon.c $NHDT-Date: 1685180838 2023/05/27 09:47:18 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.185 $ */
/* NetHack 3.7 dungeon.c $NHDT-Date: 1689629244 2023/07/17 21:27:24 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.188 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2012. */
/* NetHack may be freely redistributed. See license for details. */
@@ -2933,6 +2933,15 @@ interest_mapseen(mapseen *mptr)
return TRUE;
if (mptr->flags.unreachable || mptr->flags.forgot)
return FALSE;
/* when in tutorial, show all tutorial levels visited whether interesting
or not and don't show any other levels; when outside tutorial, don't
show any tutorial levels even if they're considered interesting */
if (In_tutorial(&u.uz)) {
return In_tutorial(&mptr->lev);
} else {
if (In_tutorial(&mptr->lev))
return FALSE;
}
/* level is of interest if it has an auto-generated annotation */
if (mptr->flags.oracle || mptr->flags.bigroom || mptr->flags.roguelevel
|| mptr->flags.castle || mptr->flags.valley

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 mklev.c $NHDT-Date: 1648066813 2022/03/23 20:20:13 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.121 $ */
/* NetHack 3.7 mklev.c $NHDT-Date: 1689629245 2023/07/17 21:27:25 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.154 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Alex Smith, 2017. */
/* NetHack may be freely redistributed. See license for details. */
@@ -241,12 +241,19 @@ add_subroom(struct mkroom *proom, int lowx, int lowy, int hix, int hiy,
}
void
free_luathemes(boolean keependgame) /* F: done, T: discarding main dungeon */
free_luathemes(enum lua_theme_group theme_group)
{
int i;
/*
* Release which group(s)?
* tut_themes => leaving tutorial, free tutorial themes only;
* most_themes => entering endgame, free non-endgame themes;
* all_themes => end of game, free all themes.
*/
for (i = 0; i < gn.n_dgns; ++i) {
if (keependgame && i == astral_level.dnum)
if ((theme_group == tut_themes && i != tutorial_dnum)
|| (theme_group == most_themes && i == astral_level.dnum))
continue;
if (gl.luathemes[i]) {
nhl_done((lua_State *) gl.luathemes[i]);

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 save.c $NHDT-Date: 1686726259 2023/06/14 07:04:19 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.206 $ */
/* NetHack 3.7 save.c $NHDT-Date: 1689629246 2023/07/17 21:27:26 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.207 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2009. */
/* NetHack may be freely redistributed. See license for details. */
@@ -1142,7 +1142,7 @@ free_dungeons(void)
tnhfp.mode = FREEING;
savelevchn(&tnhfp);
save_dungeon(&tnhfp, FALSE, TRUE);
free_luathemes(TRUE);
free_luathemes(all_themes);
#endif
return;
}