rewrite safe_teleds()
The teleport to safety routine would try to find a viable spot 400 times, the first 200 rejecting trap locations and the last 200 accepting such. While testing various escape from lava variations recently, I noticed that I could fail to reach safety even when there was an open spot immediately adjacent to me. I added a BandAid(tm) to make another 400 tries if the first attempt failed, but that was clumsy and still didn't guarantee picking a viable spot. This adds a new routine, collect_coords(), which will gather a list of coordinates for the entire map. safe_teleds() goes through them one by one until either finding a spot or exhausting the possibilies, without randomly trying and retrying the same spot multiple times and without missing other potential spots, also without just scanning the map from left to right and top to bottom or similar. Various other things which retry over and over, and especially the ones which make a bunch of random attempts and then fallback to trying every spot on the map, could be switched over to this, at least for the falling back phase. Right now collect_coords() is local to teleport.c but that could be easily changed. The try-at-random method is much quicker when there are lots of available spots but the gather-shuffled-candidates method is guaranteed to succeed if success is possible. The way safe_teleds() is presently using it collects the list with all locations within 2 steps first, then those within 3 to 4, then 5 to 6, and so on out, randomized within each block of ranges. So the destination will be within one step of being as close to the starting spot as possible but not always immediately adjacent when that happens to be available.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.7 trap.c $NHDT-Date: 1684138083 2023/05/15 08:08:03 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.535 $ */
|
||||
/* NetHack 3.7 trap.c $NHDT-Date: 1684140131 2023/05/15 08:42:11 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.536 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/*-Copyright (c) Robert Patrick Rankin, 2013. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -6278,11 +6278,7 @@ lava_effects(void)
|
||||
urgent_pline("You %s...", boil_away ? "boil away"
|
||||
: "burn to a crisp");
|
||||
done(BURNING);
|
||||
if (safe_teleds(TELEDS_ALLOW_DRAG | TELEDS_TELEPORT)
|
||||
/* if the level is completely full then this second attempt
|
||||
won't accomplish anything, but if it is only mostly full
|
||||
then hero still might manage to escape the lava */
|
||||
|| safe_teleds(TELEDS_ALLOW_DRAG | TELEDS_TELEPORT))
|
||||
if (safe_teleds(TELEDS_ALLOW_DRAG | TELEDS_TELEPORT))
|
||||
break; /* successful life-save */
|
||||
/* nowhere safe to land; repeat burning loop */
|
||||
pline("You're still burning.");
|
||||
|
||||
Reference in New Issue
Block a user