Reported by paxed. A potion of oil, that was already in the midst of exploding,
got picked up through spot_effects(), which led to it merging with
another potion of oil and the freeing of the original obj.
The original obj pointer was still held by breakobj(), and breakobj()
proceeded to delete the obj (again).
Function nesting:
1 spelleffects()
2 -> weffects()
3 -> bhit()
4 -> bhitpile()
5 -> bhito(obj ...)
6 -> hero_breaks(obj ...)
7 -> breakobj(obj ...)
8 -> explode_oil(obj ...)
9 -> splatter_burning_oil()
10 -> explode()
11 -> zap_over_floor()
12 -> melt_ice()
13 -> spot_effects()
14 -> pickup()
15 -> pickup_object(obj ...)
16 -> pick_obj(obj ...)
17 -> addinv(obj ...)
18 -> addinv_core0(obj ...)
19 -> merged(obj ...)
20 -> obfree(obj ...)
21 -> dealloc_obj(obj ...)
8 -> delobj(obj ...)
9 -> delobj_core(obj ...)
10 -> obfree(obj ...)
11 -> dealloc_obj(obj ...)
12 -> impossible("obj already deleted)
This marks the exploding potion with LOST_EXPLODING, so that it won't
get picked up, or merged with another object during the long
sequence of functions, and that should take care of 15-21 above.
The ones below marked "left,revisit" might be worthy of code changes
explode.c:removed: arg sx,sy passed to breaks() are coordxy and so are the parameters
invent.c: removed: discover_artifact() parameter is xint16, so change cast to match
mail.c: removed: gv.viz_rmin[] contains coordxy's, and enexto() 2nd param is too
mkmaze.c: removed: x, y are coordxy and so are cc->x, cc->y
mkroom.c: removed: tx, ty are coordxy and so are parameters to occupied()
mplayer.c: left,revisit: x,y declared int, but mk_mplayer() params are coordxy
sp_lev.c 2890: left alone: x,y declared int, but is_ok_location() params coordxy
sp_lev.c 4114: left alone: cast from lua_Integer
sp_lev.c 4123: left alone: cast from lua_Integer
sp_lev.c 4650: left alone: cast from lua_Integer returned from lua_tointeger
sp_lev.c 4765: left alone: cast from int_Integer returned from lua_tointeger
sp_lev.c 4772: left alone: cast from int_Integer returned from get_table_int
teleport.c 366: left alone: cast from int returned from rn2()
timeout.c 2171: left alone: cast from long
vault.c: left,revisit: guardx,guardy declared int, but bestcc fields are coordxy
worm.c 791: left,revisit: wseg.wx, wseg.wy are coordxy, so are nx, ny, but not
ox, oy; why are ox, oy needed at all?
worm.c 955: left alone: wx, wy are coordxy, wseg_at() params are int x, int y
zap.c 5061: left alone: cast from long
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
Note: Original change is from xNetHack by copperwater <aosdict@gmail.com>,
but this commit comes from HACKEM-MUCHE by Erik Lunna, with
some minor code formatting.
From xNetHack commit a0a6103bea:
'The original goal: nerf item destruction using a method I initially
proposed for SpliceHack, in which the number of items subject to
damage from any single source is limited by the amount of damage the
effect caused. The intent was to be more fair all around and prevent
aggravating situations where, for instance, a chest shock trap zaps
you for 4 damage and immediately ten of your rings and wands blow up.
Problem 1: no easy way to limit the items destroyed without biasing
heavily towards the start of the invent chain. The old code was able
to get away without bias by just indiscriminately destroying
everything eligible with a 1/3 chance. Here, I had to introduce
reservoir sampling in a somewhat more complex form than I've applied
it elsewhere, since there are a pool of potential items.
Problem 2: destroy_item no longer worked remotely like destroy_mitem,
which still destroyed 1/3 of items indiscriminately. Commence the
process of squishing them into one function that handles both the
player and monsters. (Which required making a lot of adjustments to
destroy_one_item, now named maybe_destroy_item, on nits such as
messaging and when to negate damage. An annoying consequence of the
merge is that in the player case, their HP is deducted and they can
be killed directly, but for monsters they need to add up the
destruction damage and return it.)
Unifying destroy_item and destroy_mitem has some advantages: in
addition to the obvious code duplication removal, it ensures monsters
now take the same damage as players for destruction (previously they
took a piddly 1 damage per destroyed item). Now when you hit
something with Mjollnir and their coveted wand of death breaks apart
and explodes, you at least get the satisfaction of knowing they took
the standard amount of damage from it. Monsters also now get
symmetry with players in having extrinsic elemental resistance
protect them from item destruction, and damage negation from item
destruction if they were appropriately resistant.
Problem 3: a lot of callers didn't preserve the "amount of incoming
damage" that this refactor relies on. E.g. if the defender resisted
that element, the local dmg variable would be set to 0. So I had to
do some wrangling with callers to save that original damage
value. The rule of thumb is: all *incoming* damage counts. So that
includes the player's spellcasting bonus if applicable, but not
things like half damage, negation due to resistance, or extra damage
due to being vulnerable to cold/fire.
Then I figured, while I'm here let's get rid of all those silly cases
where destroy_items is called multiple times for various different
object classes, and cut the object class parameter out of it. This
has a few minor effects:
- Places where different object classes previously rolled
independently for destruction to happen at all now roll
once. (Which, by my calculation, generally means less incidences of
destruction - a fire attack now won't have three separate chances
to hit your scrolls, potions, and spellbooks. On the flip side, a
lucky roll will no longer save an entire object class in your
inventory.)
- Callers can no longer specify different probabilities for
destroying different object classes. The only place this was really
used was to call destroy_item with a slightly lower probability on
SPBOOK_CLASS. With the nerf in this commit, less of them ought to
be destroyed anyway.
- A very edge case of where explosion-vs-monster damage was totted up
differently for golems, which could result in differences of a hit
point here or there.
- All object classes being processed in one go means that less items
are destroyed than would be if they were still processed
independently. This is not really visible compared to the old
baseline of just destroying 33% of everything, but would be a
marked difference versus a copy of the game that still called
destroy_items separately for different object classes. To
compensate, I adjusted my planned damage-to-destruction-limit
scaling factor down from 8 to 5.
Not done: merging in ignite_items(), though that would probably be
really easy now.'
Notes from porting from xNetHack:
- It might be necessary to reexamine at all the conditional checks for
calling destroy_items. Because item destruction is much more
restrained and uses the actual damage from an effect, we might now
need to check 'if (!rn2(3))' and similar in all the places item
destruction occurs.
The exploding magical trap did not cause problems before just by
being a magical explosion by accident; adding an object caused
the cancellation wand ID to change, and the explosion now had
an impossible explosion type.
Hardcode trap explosions to generic magical blasts.
Unless you kill the monster with one hit, it'll wake up
cranky and make noise - waking up other sleeping monsters.
This was a bit tricky with all the message sequencing; I tested
all the hit/throw/fire/zap combos I could think of, and it took
a while to get things looking right.
Insert the calls to trigger a number of potential soundeffects
into the core.
If no additional soundlib support is integrated into the
build, then the Soundeffect macro (sndprocs.h) expands to nothing:
[#define Soundeffect(seid, vol)
]
If, however, at least one additional soundlib support is integrated
into the build, then the Soundeffect macro gets defined as this
in sndprocs.h:
[#define Soundeffect(seid, vol) \
do { \
if (!Deaf && soundprocs.sound_soundeffect \
&& ((soundprocs.sndcap & SNDCAP_SOUNDEFFECTS) != 0)) \
(*soundprocs.sound_soundeffect)(emptystr, (seid), (vol)); \
} while(0)
]
That macro definition checks for the hero not being Deaf; it checks
to ensure that the active soundlib interface has a non-null
sound_soundeffect() function pointer; and it checks to ensure
that the active soundlib interface has declared that it supports
soundeffects by setting the SNDCAP_SOUNDEFFECTS bit in its sndcap
entry. That just means that the interface routines are prepared to
accept and deal with the calls from the core, whether or not it
actually produces the desired soundeffect.
The consolidation of global variables from scattered source
files into decl.c and declared in decl.h was begun in 3.7.0.
Their placement in common files was done for centralized
initialization and potential re-initialization during a
"play again" scenario.
It wasn't really necessary for all of them to be housed in a
single huge structure to meet the "play again" requirement,
and the single huge structure has been a little unwieldy when
it comes to maintenance.
Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.
To make things easy for the developer, each variable is placed
into the struct corresponding to the starting letter of the variable.
That way, no lookup is required in order to know which struct houses
a particular variable, it is a simple match to the starting letter
for all the centralized global variables.
A global variable named 'amulets', would be found in ga.
ga.amulets
^ ^
A global varable named 'move', would be found in gm.
gm.moves
^ ^
A global variable named 'val_for_n_or_more' would be found in gv.
gv.val_for_n_or_more
^ ^
A global variable named 'youmonst' would be found in gy.
gy.youmonst
^ ^
Instead of using index() macro defined to strchr, use C99 strchr.
Instead of using rindex() macro defined to strrchr, use C99 strrchr.
If you want to try building on a platform that doesn't offer those
two functions, these are available:
define NOT_C99 /* to make some non-C99 code available */
define NEED_INDEX /* to define a macro for index() */
define NEED_RINDX /* to define a macro for rindex() */
When breaking a wand of sleep, don't print the message "the sleep ray
hits you!" since it produces an area effect/explosion rather than a ray.
For a couple other wands, !ordinary (wand breakage) effects don't
produce a message (I assume because the do_break_wand feedback is
considered sufficient), but I put in an alternative message for the
explosion since I think it's important to inform the player the hero has
fallen asleep.
Change trappers and lurkers above to remove digestion damage. They
fold themselves around rather than swallow the victim. There were
are lot of places that assumed that an engulfer which is an animal
would swallow and digest the victim. In hindsight, it might have
been simpler to take the M1_ANIMAL flag off of trappers and lurkers
above.
This adds a new digests() predicate for creatures with AT_ENGL+AD_DGST
(purple worm) and also enfolds() for AT_ENGL+AD_WRAP (both 't'-class
critters).
There are several minor fixes mixed in with this. I didn't record
them as I went along but the two I remember are
1) if poly'd into a holder and holding on to a monster, the '<' and
'>' commands refursed to work; release the held creature first
and then treat those commands as normal;
2) throwing a non-weapon while engulfed by an ochre jelly reported
"the <item> vanishes into the ochre jelly's /currents/".
This needs a lot more testing. I found and fixed multiple minor
details before my own testing burned out.
One of the drivers of this change was that screen coordinates require a
type that can hold values greater than 127. Parameters to the window
port routines require a large type in order to be able to have values
a fair bit larger than COLNO and ROWNO passed to them, particularly for
their use to the right of the map window.
This splits the uses of xchar into 3 different situations, and adjusts
their type and size:
xchar
|
-----------------------
| | |
coordxy xint16 xint8
coordxy: Actual x or y coordinates for various things (moved to 16-bits).
xint16: Same data size as coordxy, but for non-coordinate use (16-bits).
xint8: There are only a few use cases initially, where it was very
plain to see that the variable could remain as 8-bits, rather
than be bumped to 16-bits. There are probably more such cases
that could be changed after additional review.
Note: This first changed all xchar variables to coordxy. Some were
reviewed and got changed to xint16 or xint8 when it became apparent that
their usage was not for coordinates.
This increments EDITLEVEL in patchlevel.h
Switch to using a macro invocation Verbos(n, s) in place of the
flags.verbose checks.
Provide the mechanics for individual suppression of any of the
existing messages that were considered verbose.
Mechanics only - this code update does not provide any means of
setting the suppression bits.
iflags.verbose = 0
is still a master suppression of all the verbose messages.
iflags.verbose = 1
turns on the verbose messages only for those whose suppression
bit is 0 (not set).
Add the patch from entrez to describe the tower of flame effect from
a scroll of fire as "the blast" rather than "your spell" if it reveals
a secret door.
explosion that reveals a secret door
Make the fix to feedback when an exploding potion of oil reveals a
door and then destroys it not affect other zap_over_floor feedback.
This incorporates the followup comment from entrez.
Monster hiding under an item on a location with a land mine,
a rolling boulder trap launches a boulder which blows up the mine,
and all the items scatter away. If the hider survived that, it
was still hiding.
Reported by entrez: if a monster or explosion kills the hero with an
object that has timers or is a light source, it could trigger a panic
when end of game cleanup can't find it because it has been removed
from the map or monster's inventory and not placed back on the map
yet. This isn't much different from something thrown by hero which
had a similar situation dealt with a long time ago. Fix by setting
'thrownobj' for monster-launched and explosion-launched missiles.
That way done_object_cleanup() called from really_done() will place the
missile on the map where saving bones or general cleanup can find it.
It doesn't bother dealing with exploding a lit potion of oil that
kills the hero by missile damage before the potion explodes. If that
ends up in bones, it should still be lit and might blow up before the
new character reaches it. (Not verified.)
The code for a hero polymorphed into a unicorn and catching a thrown
gem has been moved into its own routine. No change in behavior, just
less clutter in the thrown-object-hits-hero section of the monster
throwing routine.
Use a slightly more meaningful name for each one rather than
a sequential numerical name.
S_explode1 to S_expl_tl
S_explode2 to S_expl_tc
S_explode3 to S_expl_tr
S_explode4 to S_expl_ml
S_explode5 to S_expl_mc
S_explode6 to S_expl_mr
S_explode7 to S_expl_bl
S_explode8 to S_expl_bc
S_explode9 to S_expl_br
Despite active explosion attacks being called explosions in-game,
they only affected a single target, and were handled differently
from actual explosions. Make them do an actual explosion instead.
This should make spheres more interesting and inspire different
tactics handling them.
Because spheres deal more damage on average and can destroy items
in their explosions, their difficulty has been increased slightly.
Polyselfed hero exploding won't cause elemental damage to their
own gear.
Originally from xNetHack by copperwater <aosdict@gmail.com>.
If monsters see you resist something, generally elemental or magical
attack, or if they see you reflect an attack, they learn that and
will adjust their attack accordingly.
Originally from SporkHack, but this version comes via EvilHack with
some minor changes.
Objects shot, thrown, or kicked by the hero or by monsters stop
short if they try to pass over a sink; make objects launched by
an explosion behave similarly.
clear some -Wformat-overflow warnings being experienced with
i586-pc-msdosdjgpp-gcc (GCC) 10.2.0 cross-compiler
--
Warnings log:
botl.c: In function 'status_hilite_menu_add':
botl.c:3661:38: warning: ' or ' directive writing 4 bytes into a region of size between 1 and 80 [-Wformat-overflow=]
3661 | Sprintf(obuf, "%s or %s",
| ^~~~
In file included from ../include/config.h:631,
from ../include/hack.h:10,
from botl.c:6:
../include/global.h:274:24: note: 'sprintf' output between 5 and 163 bytes into a destination of size 80
274 | #define Sprintf (void) sprintf
botl.c:3661:21: note: in expansion of macro 'Sprintf'
3661 | Sprintf(obuf, "%s or %s",
| ^~~~~~~
do_name.c: In function 'getpos_menu':
do_name.c:594:37: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
594 | Sprintf(fullbuf, "%s%s%s", firstmatch,
| ^
In file included from ../include/config.h:631,
from ../include/hack.h:10,
from do_name.c:6:
../include/global.h:274:24: note: 'sprintf' output 1 or more bytes (assuming 257) into a destination of size 256
274 | #define Sprintf (void) sprintf
do_name.c:594:13: note: in expansion of macro 'Sprintf'
594 | Sprintf(fullbuf, "%s%s%s", firstmatch,
| ^~~~~~~
dungeon.c: In function 'print_dungeon':
dungeon.c:2172:27: warning: '%s' directive writing up to 1407 bytes into a region of size 256 [-Wformat-overflow=]
2172 | Sprintf(buf, "%s: %s %d", dptr->dname, descr, dptr->depth_start);
| ^~
In file included from ../include/config.h:631,
from ../include/hack.h:10,
from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 10 and 1427 bytes into a destination of size 256
274 | #define Sprintf (void) sprintf
dungeon.c:2172:13: note: in expansion of macro 'Sprintf'
2172 | Sprintf(buf, "%s: %s %d", dptr->dname, descr, dptr->depth_start);
| ^~~~~~~
dungeon.c:2169:27: warning: '%s' directive writing up to 1407 bytes into a region of size 256 [-Wformat-overflow=]
2169 | Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
| ^~
dungeon.c:2169:26: note: directive argument in the range [-2147483647, 2147483646]
2169 | Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
| ^~~~~~~~~~~~~~~~~
In file included from ../include/config.h:631,
from ../include/hack.h:10,
from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output 10 or more bytes (assuming 1427) into a destination of size 256
274 | #define Sprintf (void) sprintf
dungeon.c:2169:13: note: in expansion of macro 'Sprintf'
2169 | Sprintf(buf, "%s: %s %d to %d", dptr->dname, makeplural(descr),
| ^~~~~~~
dungeon.c: In function 'print_mapseen':
dungeon.c:3185:33: warning: '%s' directive writing up to 255 bytes into a region of size 249 [-Wformat-overflow=]
3185 | Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp);
| ^~ ~~~
In file included from ../include/config.h:631,
from ../include/hack.h:10,
from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 37 and 292 bytes into a destination of size 256
274 | #define Sprintf (void) sprintf
dungeon.c:3185:9: note: in expansion of macro 'Sprintf'
3185 | Sprintf(outbuf, " (play %s to open or close drawbridge)", tmp);
| ^~~~~~~
dungeon.c:3350:35: warning: '%s' directive writing up to 255 bytes into a region of size 240 [-Wformat-overflow=]
3350 | Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf));
| ^~
In file included from ../include/config.h:631,
from ../include/hack.h:10,
from dungeon.c:6:
../include/global.h:274:24: note: 'sprintf' output between 18 and 273 bytes into a destination of size 256
274 | #define Sprintf (void) sprintf
dungeon.c:3350:9: note: in expansion of macro 'Sprintf'
3350 | Sprintf(buf, "%sThe castle%s.", PREFIX, tunesuffix(mptr, tmpbuf));
| ^~~~~~~
explode.c:541:69: warning: '%s' directive writing up to 255 bytes into a region of size 236 [-Wformat-overflow=]
541 | Sprintf(g.killer.name, "caught %sself in %s own %s", uhim(),
| ^~
In file included from ../include/config.h:631,
from ../include/hack.h:10,
from explode.c:5:
../include/global.h:274:24: note: 'sprintf' output 21 or more bytes (assuming 276) into a destination of size 256
274 | #define Sprintf (void) sprintf
explode.c:541:21: note: in expansion of macro 'Sprintf'
541 | Sprintf(g.killer.name, "caught %sself in %s own %s", uhim(),
| ^~~~~~~
hacklib.c: In function 'yyyymmddhhmmss':
hacklib.c:1034:28: warning: '%02d' directive writing between 2 and 11 bytes into a region of size between 4 and 11 [-Wformat-overflow=]
1034 | Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
| ^~~~
hacklib.c:1034:22: note: directive argument in the range [-2147483647, 2147483647]
1034 | Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/config.h:631,
from ../include/hack.h:10,
from hacklib.c:7:
../include/global.h:274:24: note: 'sprintf' output between 15 and 67 bytes into a destination of size 15
274 | #define Sprintf (void) sprintf
hacklib.c:1034:5: note: in expansion of macro 'Sprintf'
1034 | Sprintf(datestr, "%04ld%02d%02d%02d%02d%02d", datenum, lt->tm_mon + 1,
| ^~~~~~~