The g? structs had a mix of variables that were written to
the savefile, and those that were not.
For better clarity and to distinguish those that end up in
the savefile, relocate some g? variables that get written
directly to the savefile into different structs.
This updates EDITLEVEL, although technically it probably
didn't need to, since savefile contents are not changing.
Details:
gb.bases -> svb.bases
gb.bbubbles -> svb.bbubbles
gb.branches -> svb.branches
gc.context -> svc.context
gd.disco -> svd.disco
gd.dndest -> svd.dndest
gd.doors -> svd.doors
gd.doors_alloc -> svd.doors_alloc
gd.dungeon_topology -> svd.dungeon_topology
gd.dungeons -> svd.dungeons
ge.exclusion_zones -> sve.exclusion_zones
gh.hackpid -> svh.hackpid
gi.inv_pos -> svi.inv_pos
gk.killer -> svk.killer
gl.lastseentyp -> svl.lastseentyp
gl.level -> svl.level
gl.level_info -> svl.level_info
gm.mapseenchn -> svm.mapseenchn
gm.moves -> svm.moves
gm.mvitals -> svm.mvitals
gn.n_dgns -> svn.n_dgns
gn.n_regions -> svn.n_regions
gn.nroom -> svn.nroom
go.oracle_cnt -> svo.oracle_cnt
gp.pl_character -> svp.pl_character
gp.pl_fruit -> svp.pl_fruit
gp.plname -> svp.plname
gp.program_state -> svp.program_state
gq.quest_status -> svq.quest_status
gr.rooms -> svr.rooms
gs.sp_levchn -> svs.sp_levchn
gs.spl_book -> svs.spl_book
gt.timer_id -> svt.timer_id
gt.tune -> svt.tune
gu.updest -> svu.updest
gx.xmax -> svx.xmax
gx.xmin -> svx.xmin
gy.ymax -> svy.ymax
gy.ymin -> svy.ymin
Related note:
There are some pointer variables that are heads of chains that were not
moved from 'g?' to 'sv?', because they are not actually written to the
savefile directly, but the objects/monst/trap/lightsource/timer in the
chains they point to are. That can be changed, if desired.
Examples: gi.invent, gm.migrating_objs, gb.billobjs, gm.migrating_mons,
gf.ftrap, gl.light_base, gt.timer_base
238 lines
5.9 KiB
C
238 lines
5.9 KiB
C
/* NetHack 3.7 stairs.c $NHDT-Date: 1704043695 2023/12/31 17:28:15 $ $NHDT-Branch: keni-luabits2 $:$NHDT-Revision: 1.207 $ */
|
|
/* Copyright (c) 2024 by Pasi Kallinen */
|
|
/* NetHack may be freely redistributed. See license for details. */
|
|
|
|
#include "hack.h"
|
|
|
|
void
|
|
stairway_add(
|
|
coordxy x, coordxy y,
|
|
boolean up, boolean isladder,
|
|
d_level *dest)
|
|
{
|
|
stairway *tmp = (stairway *) alloc(sizeof (stairway));
|
|
|
|
(void) memset((genericptr_t) tmp, 0, sizeof (stairway));
|
|
tmp->sx = x;
|
|
tmp->sy = y;
|
|
tmp->up = up;
|
|
tmp->isladder = isladder;
|
|
tmp->u_traversed = FALSE;
|
|
assign_level(&(tmp->tolev), dest);
|
|
tmp->next = gs.stairs;
|
|
gs.stairs = tmp;
|
|
}
|
|
|
|
void
|
|
stairway_free_all(void)
|
|
{
|
|
stairway *tmp = gs.stairs;
|
|
|
|
while (tmp) {
|
|
stairway *tmp2 = tmp->next;
|
|
free(tmp);
|
|
tmp = tmp2;
|
|
}
|
|
gs.stairs = NULL;
|
|
}
|
|
|
|
stairway *
|
|
stairway_at(coordxy x, coordxy y)
|
|
{
|
|
stairway *tmp = gs.stairs;
|
|
|
|
while (tmp && !(tmp->sx == x && tmp->sy == y))
|
|
tmp = tmp->next;
|
|
return tmp;
|
|
}
|
|
|
|
stairway *
|
|
stairway_find(d_level *fromdlev)
|
|
{
|
|
stairway *tmp = gs.stairs;
|
|
|
|
while (tmp) {
|
|
if (tmp->tolev.dnum == fromdlev->dnum
|
|
&& tmp->tolev.dlevel == fromdlev->dlevel)
|
|
break; /* return */
|
|
tmp = tmp->next;
|
|
}
|
|
return tmp;
|
|
}
|
|
|
|
stairway *
|
|
stairway_find_from(d_level *fromdlev, boolean isladder)
|
|
{
|
|
stairway *tmp = gs.stairs;
|
|
|
|
while (tmp) {
|
|
if (tmp->tolev.dnum == fromdlev->dnum
|
|
&& tmp->tolev.dlevel == fromdlev->dlevel
|
|
&& tmp->isladder == isladder)
|
|
break; /* return */
|
|
tmp = tmp->next;
|
|
}
|
|
return tmp;
|
|
}
|
|
|
|
stairway *
|
|
stairway_find_dir(boolean up)
|
|
{
|
|
stairway *tmp = gs.stairs;
|
|
|
|
while (tmp && !(tmp->up == up))
|
|
tmp = tmp->next;
|
|
return tmp;
|
|
}
|
|
|
|
stairway *
|
|
stairway_find_type_dir(boolean isladder, boolean up)
|
|
{
|
|
stairway *tmp = gs.stairs;
|
|
|
|
while (tmp && !(tmp->isladder == isladder && tmp->up == up))
|
|
tmp = tmp->next;
|
|
return tmp;
|
|
}
|
|
|
|
stairway *
|
|
stairway_find_special_dir(boolean up)
|
|
{
|
|
stairway *tmp = gs.stairs;
|
|
|
|
while (tmp) {
|
|
if (tmp->tolev.dnum != u.uz.dnum && tmp->up != up)
|
|
return tmp;
|
|
tmp = tmp->next;
|
|
}
|
|
return tmp;
|
|
}
|
|
|
|
/* place you on the special staircase */
|
|
void
|
|
u_on_sstairs(int upflag)
|
|
{
|
|
stairway *stway = stairway_find_special_dir(upflag);
|
|
|
|
if (stway)
|
|
u_on_newpos(stway->sx, stway->sy);
|
|
else
|
|
u_on_rndspot(upflag);
|
|
}
|
|
|
|
/* place you on upstairs (or special equivalent) */
|
|
void
|
|
u_on_upstairs(void)
|
|
{
|
|
stairway *stway = stairway_find_dir(TRUE);
|
|
|
|
if (stway)
|
|
u_on_newpos(stway->sx, stway->sy);
|
|
else
|
|
u_on_sstairs(0); /* destination upstairs implies moving down */
|
|
}
|
|
|
|
/* place you on dnstairs (or special equivalent) */
|
|
void
|
|
u_on_dnstairs(void)
|
|
{
|
|
stairway *stway = stairway_find_dir(FALSE);
|
|
|
|
if (stway)
|
|
u_on_newpos(stway->sx, stway->sy);
|
|
else
|
|
u_on_sstairs(1); /* destination dnstairs implies moving up */
|
|
}
|
|
|
|
boolean
|
|
On_stairs(coordxy x, coordxy y)
|
|
{
|
|
return (stairway_at(x, y) != NULL);
|
|
}
|
|
|
|
boolean
|
|
On_ladder(coordxy x, coordxy y)
|
|
{
|
|
stairway *stway = stairway_at(x, y);
|
|
|
|
return (boolean) (stway && stway->isladder);
|
|
}
|
|
|
|
boolean
|
|
On_stairs_up(coordxy x, coordxy y)
|
|
{
|
|
stairway *stway = stairway_at(x, y);
|
|
|
|
return (boolean) (stway && stway->up);
|
|
}
|
|
|
|
boolean
|
|
On_stairs_dn(coordxy x, coordxy y)
|
|
{
|
|
stairway *stway = stairway_at(x, y);
|
|
|
|
return (boolean) (stway && !stway->up);
|
|
}
|
|
|
|
/* return True if 'sway' is a branch staircase and hero has used these stairs
|
|
to visit the branch */
|
|
boolean
|
|
known_branch_stairs(stairway *sway)
|
|
{
|
|
return (sway && sway->tolev.dnum != u.uz.dnum && sway->u_traversed);
|
|
}
|
|
|
|
/* describe staircase 'sway' based on whether hero knows the destination */
|
|
char *
|
|
stairs_description(
|
|
stairway *sway, /* stairs/ladder to describe */
|
|
char *outbuf, /* result buffer */
|
|
boolean stcase) /* True: "staircase" or "ladder", always singular;
|
|
* False: "stairs" or "ladder"; caller needs to deal
|
|
* with singular vs plural when forming a sentence */
|
|
{
|
|
d_level tolev;
|
|
const char *stairs, *updown;
|
|
|
|
tolev = sway->tolev;
|
|
stairs = sway->isladder ? "ladder" : stcase ? "staircase" : "stairs";
|
|
updown = sway->up ? "up" : "down";
|
|
|
|
if (!known_branch_stairs(sway)) {
|
|
/* ordinary stairs or branch stairs to not-yet-visited branch */
|
|
Sprintf(outbuf, "%s %s", stairs, updown);
|
|
if (sway->u_traversed) {
|
|
boolean specialdepth = (tolev.dnum == quest_dnum
|
|
|| single_level_branch(&tolev)); /* knox */
|
|
int to_dlev = specialdepth ? dunlev(&tolev) : depth(&tolev);
|
|
|
|
Sprintf(eos(outbuf), " to level %d", to_dlev);
|
|
}
|
|
} else if (u.uz.dnum == 0 && u.uz.dlevel == 1 && sway->up) {
|
|
/* stairs up from level one are a special case; they are marked
|
|
as having been traversed because the hero obviously started
|
|
the game by coming down them, but the remote side varies
|
|
depending on whether the Amulet is being carried */
|
|
Sprintf(outbuf, "%s%s %s %s",
|
|
!u.uhave.amulet ? "" : "branch ",
|
|
stairs, updown,
|
|
!u.uhave.amulet ? "out of the dungeon"
|
|
/* minimize our expectations about what comes next */
|
|
: (on_level(&tolev, &earth_level)
|
|
|| on_level(&tolev, &air_level)
|
|
|| on_level(&tolev, &fire_level)
|
|
|| on_level(&tolev, &water_level))
|
|
? "to the Elemental Planes"
|
|
: "to the end game");
|
|
} else {
|
|
/* known branch stairs; tacking on destination level is too verbose */
|
|
Sprintf(outbuf, "branch %s %s to %s",
|
|
stairs, updown, svd.dungeons[tolev.dnum].dname);
|
|
/* dungeons[].dname is capitalized; undo that for "The <Branch>" */
|
|
(void) strsubst(outbuf, "The ", "the ");
|
|
}
|
|
return outbuf;
|
|
}
|
|
|
|
/*stairs.c*/
|