Check Room Path is safe

Hey everyone.

So I have a part of my Inform 7 code that sends People to a particular room, using ‘Move [person] to [Start Room]’

What I would like to add is a means to check if any of the rooms between the room currently in, and the room they were sent to, has any threats (enemies, traps) in them, and if so, report they did not make it.

Any thoughts on how this might be achieved?

2 Likes

Look over §6.14. Adjacent rooms and routes through the map, specifically best route from (object) to (object) - It’s possible to write a rule that moves the player or an NPC that includes checking things each step of the way like if a monster is in the location of (object): ...

http://inform7.com/book/WI_6_14.html

Or, if you just want to check whether a safe route is possible rather than to walk through it step by step to identify the blocking threat, define rooms as safe or unsafe and try to find a route via safe rooms only:

Definition: a room is safe if: .....

If the best route from Room A to Room B through safe rooms is a direction....

The ‘best route’ is nothing (rather than a direction) if there is no safe route from A to B.

2 Likes

Can anyone offer any assistance with how ‘best route’ works?

I have the following code:

While NPC1 is not in Outside Cave:
let the way be the best route from the location of NPC1 to Outside Cave;
if the way is a direction:
let next place be the room the way from the location;
say “[Bold type][NPC1] moves [way] to [the printed name of next place]”;
move NPC1 to next place;
pause the game;
clear the screen;

I am trying to make it so that it loops through all rooms leading from the current one to the destination (outside), printing the next direction and room the NPC walks through to get there.

It works if Outside Cave is the adjacent room, but if it’s mutliple rooms away, it just keeps looping the first direction and room.

For example:

“Bob moves West to Dark Tunnel”
“Bob moves West to Dark Tunnel”
“Bob moves West to Dark Tunnel”
“Bob moves West to Dark Tunnel”
“Bob moves West to Dark Tunnel”
“Bob moves West to Dark Tunnel”
“Bob moves West to Dark Tunnel”
etc.

Any idea how to achieve a NPC walkthrough of rooms?

Oops, never mind…worked it out.
This was the offending line…

let next place be the room the way from the location;

Location will always be the current room.

I needed to make it ‘location of NPC1’ so it’s always referring to the new location.

1 Like