Inform’s built-in pathfinding is both a wonderful thing and (occasionally) just a little more limiting than I want, and I’ve found myself banging my head against best route
calculations a fair number of times in the thing I’m working on right now, thinking “if I could only …”.
In any case, there are a couple of things that suggest themselves to me as possible responses to the situation your characters are in. One, perhaps the simplest, would be to have the NPC slavishly follow the PC wherever s/he goes instead of independently seeking the same goal. You can use phrases like the best route from the location of Carlos to the player
(if your NPC is named Carlos, of course) to calculate what the NPC’s route should be. This might solve the larger problem in a way that makes your specific concern unnecessary to deal with.
On the other hand, it may be narratively unsatisfying, too, and you really might want to have an NPC chomping at the bit but who will wait if s/he is ahead of you. The problem here is that Inform doesn’t give you an easy way to see the entire list of moves that would be needed to get from A to B. (And there are reasons why this is a good choice in many circumstances: after all, the best route might change if the map is rearranged or if doors in between get locked or for any number of reasons.) But if I were solving this problem in, say, Python, that’s what I’d want to do: cobble together the whole list of moves and then see whether the PC’s current location appears in that list. This would be a more difficult task in Inform, though not impossible. (The code I’m sketching out in my head seems like it would be prohibitively slow, though.)
What might be easier, though, is just to see whether the PC is closer to the goal, in the sense of fewer moves being required, than the relevant NPC is. This assumes that they’re moving toward the same goal, but it sounds like that’s what’s going on in your particular situation. You can find the number of moves between two locations using, appropropriately enough, Inform’s the number of moves from ... to ...
phrase.
So you might try something like this:
Reactor Core is a room. Core Entrance Chamber is south of Reactor Core. Decontamination is south of Core Entrance Chamber. Suit Storage is south of Decontamination. Control Booth is south of Suit Storage. Visitor's Gift Shop is south of Control Booth.
The player is in Decontamination. Useless Fred is a man in Control Booth.
Reactor Meltdown is a scene. Reactor Meltdown begins when the player is in Suit Storage.
When Reactor Meltdown begins, say "A loud alarm goes off! The reactor is overheating!".
Every turn during Reactor Meltdown:
say "Oh no! The reactor is overheating!";
let f be the number of moves from the location of Useless Fred to Reactor Core;
let p be the number of moves from the location of the player to Reactor Core;
if p is less than f:
let the way be the best route from the location of Useless Fred to Reactor Core;
if the way is a direction:
try Useless Fred going the way;
otherwise if Useless Fred can see the player:
say "'Hurry the aitch ee double-hockey-sticks up!' yells Fred. 'That reactor ain't waitin' on no one nohow!'".
(You can also shorten the location of the player
to just the location
, but I think it’s easier to leave the expanded form in for demonstration purposes.) This would of course require plenty of cleanup, but kind of illustrates what you might theoretically do.
Notice that checking the number of moves required is really just a heuristic for whether the paths intersect, which you’re definitely not checking here. However, if the PC and NPC are likely to be close together anyway, and the paths overlap substantially, then this may be good enough.