From: nethack.rankin Date: Wed, 30 Nov 2011 18:52:28 +0000 (+0000) Subject: hangup vs u.uinwater again (trunk only) X-Git-Tag: MOVE2GIT~148 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e055b2820e62574b0a971eb31f393b334d504fd1;p=nethack hangup vs u.uinwater again (trunk only) Redo the fix that prevents hangup from putting hero on top of water if it occurs during magic mapping or object/gold/trap detection. Instead of copying u.uinwater into another field in struct u so that it can be reset during restore, copy it into a new field in struct iflags and reset it during save so that no fixup upon restore is needed. --- diff --git a/include/flag.h b/include/flag.h index 25e2bac84..a4e53408d 100644 --- a/include/flag.h +++ b/include/flag.h @@ -306,6 +306,11 @@ struct instance_flags { #define MAX_ALTKEYHANDLER 25 char altkeyhandler[MAX_ALTKEYHANDLER]; #endif + /* copies of values in struct u, used during detection when the + originals are temporarily cleared; kept here rather than + locally so that they can be restored during a hangup save */ + Bitfield(save_uinwater,1); + Bitfield(save_uburied,1); }; /* diff --git a/include/you.h b/include/you.h index 9b3e0743d..55f0864a6 100644 --- a/include/you.h +++ b/include/you.h @@ -227,14 +227,6 @@ struct Align { extern const struct Align aligns[]; /* table of available alignments */ -/* hangup handling; sometimes u.uinwater is overridden, and we need to - be able to reset it in the event of restoring from a hangup save; - save/override/restore takes place during normal execution, so this - isn't dependent upon current port's signal handling capability */ -struct huphack { - Bitfield(hup_uinwater,1); - Bitfield(hup_uburied,1); -}; /*** Information about the player ***/ struct you { @@ -368,7 +360,6 @@ struct you { xchar skill_record[P_SKILL_LIMIT]; /* skill advancements */ struct skills weapon_skills[P_NUM_SKILLS]; boolean twoweap; /* KMH -- Using two-weapon combat */ - struct huphack save; /* hup_{uinwater,uburied} */ }; /* end of `struct you' */ diff --git a/src/detect.c b/src/detect.c index a06a62e7e..824105207 100644 --- a/src/detect.c +++ b/src/detect.c @@ -233,7 +233,7 @@ register struct obj *sobj; outgoldmap: cls(); - u.save.hup_uinwater = u.uinwater, u.save.hup_uburied = u.uburied; + iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; u.uinwater = u.uburied = 0; /* Discover gold locations. */ for (obj = fobj; obj; obj = obj->nobj) { @@ -278,7 +278,7 @@ outgoldmap: } } newsym(u.ux,u.uy); - u.uinwater = u.save.hup_uinwater, u.uburied = u.save.hup_uburied; + u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; You_feel("very greedy, and sense gold!"); exercise(A_WIS, TRUE); display_nhwindow(WIN_MAP, TRUE); @@ -351,7 +351,7 @@ register struct obj *sobj; struct obj *temp; known = TRUE; cls(); - u.save.hup_uinwater = u.uinwater, u.save.hup_uburied = u.uburied; + iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; u.uinwater = u.uburied = 0; for (obj = fobj; obj; obj = obj->nobj) if ((temp = o_in(obj, oclass)) != 0) { @@ -371,7 +371,7 @@ register struct obj *sobj; break; /* skip rest of this monster's inventory */ } newsym(u.ux,u.uy); - u.uinwater = u.save.hup_uinwater, u.uburied = u.save.hup_uburied; + u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; if (sobj) { if (sobj->blessed) { Your("%s %s to tingle and you smell %s.", body_part(NOSE), @@ -482,7 +482,7 @@ int class; /* an object class, 0 for all */ cls(); - u.save.hup_uinwater = u.uinwater, u.save.hup_uburied = u.uburied; + iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; u.uinwater = u.uburied = 0; /* * Map all buried objects first. @@ -560,7 +560,7 @@ int class; /* an object class, 0 for all */ } newsym(u.ux,u.uy); - u.uinwater = u.save.hup_uinwater, u.uburied = u.save.hup_uburied; + u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; You("detect the %s of %s.", ct ? "presence" : "absence", stuff); display_nhwindow(WIN_MAP, TRUE); /* @@ -766,7 +766,7 @@ register struct obj *sobj; outtrapmap: cls(); - u.save.hup_uinwater = u.uinwater, u.save.hup_uburied = u.uburied; + iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; u.uinwater = u.uburied = 0; /* show chest traps first, so that subsequent floor trap display @@ -792,7 +792,7 @@ outtrapmap: glyph = glyph_at(u.ux, u.uy); if (!(glyph_is_trap(glyph) || glyph_is_object(glyph))) newsym(u.ux, u.uy); - u.uinwater = u.save.hup_uinwater, u.uburied = u.save.hup_uburied; + u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; You_feel("%s.", cursed_src ? "very greedy" : "entrapped"); /* wait for user to respond, then reset map display to normal */ @@ -1005,12 +1005,12 @@ do_mapping() { register int zx, zy; - u.save.hup_uinwater = u.uinwater, u.save.hup_uburied = u.uburied; + iflags.save_uinwater = u.uinwater, iflags.save_uburied = u.uburied; u.uinwater = u.uburied = 0; for (zx = 1; zx < COLNO; zx++) for (zy = 0; zy < ROWNO; zy++) show_map_spot(zx, zy); - u.uinwater = u.save.hup_uinwater, u.uburied = u.save.hup_uburied; + u.uinwater = iflags.save_uinwater, u.uburied = iflags.save_uburied; if (!level.flags.hero_memory || Underwater) { flush_screen(1); /* flush temp screen */ display_nhwindow(WIN_MAP, TRUE); /* wait */ diff --git a/src/restore.c b/src/restore.c index 9e2def56d..4d5136f7a 100644 --- a/src/restore.c +++ b/src/restore.c @@ -857,11 +857,6 @@ register int fd; */ reset_restpref(); - /* some fixups in case this was a hangup save */ - u.uinvulnerable = 0; - if (u.save.hup_uinwater) u.uinwater = 1, u.save.hup_uinwater = 0; - if (u.save.hup_uburied) u.uburied = 1, u.save.hup_uburied = 0; - restlevelstate(stuckid, steedid); program_state.something_worth_saving = 1; /* useful data now exists */ diff --git a/src/save.c b/src/save.c index ecf8d305f..2e743037f 100644 --- a/src/save.c +++ b/src/save.c @@ -139,6 +139,13 @@ dosave0() d_level uz_save; char whynot[BUFSZ]; + /* we may get here via hangup signal, in which case we want to fix up + a few of things before saving so that they won't be restored in + an improper state; these will be no-ops for normal save sequence */ + u.uinvulnerable = 0; + if (iflags.save_uinwater) u.uinwater = 1, iflags.save_uinwater = 0; + if (iflags.save_uburied) u.uburied = 1, iflags.save_uburied = 0; + if (!program_state.something_worth_saving || !SAVEF[0]) return 0; fq_save = fqname(SAVEF, SAVEPREFIX, 1); /* level files take 0 */