Making use of the regional-containment relation

Hey! I’m banging my head against the wall trying to get Inform 7 to understand that I want to use the R-C relation in my game. The idea is that I’d have a region “Home” with a Bathroom, a KItchen, a Bedroom, an Office, etc. and I want the player to be able to move to any of them from wherever they are by cheating and teleporting them where they say they want to go. I also want them to be able to leave the house, but I don’t want them to be able to teleport from the Supermarket’s Meat Section to the Home’s Bathroom. I’ve scoured the documentation and the index for anything to help but nothing works. If anyone has any advice it would be greatly appreciated, thank you.

This does what you describe:

The House-region is a region.
The Supermarket-region is a region.

The Kitchen is a room in the House-region.
The Front Yard is a room in the House-region.

The Supermarket Entrance is a room in the Supermarket-region.
The Meat Section is a room in the Supermarket-region.

The Front Yard is east of the Kitchen.
The Road is east of the Front Yard.
The Supermarket Entrance is east of the Road.
The Meat section is east of the Entrance.

Teleporting is an action applying to a thing.
Understand "teleport to/-- [a room]" as teleporting.

After deciding the scope of the player when teleporting:
    repeat with visited-room running through visited rooms begin;
      place visited-room in scope;
    end repeat.

Check teleporting:
    if the noun is not in the map region of the location, say "There are limits to even your power." instead.

Carry out teleporting:
    move the player to the noun.

But you’d probably want a better error than “You can’t see any such thing.” when the player tries teleporting to a place they haven’t been.

The map region of syntax is buried in Example 114 and easy to miss.

Yes. The built-in map region property of a room defines the complicated relations between regions and rooms.

The map region of a room is the region that directly contains and directly regionally contains that room but yet it does not hold or enclose that room (this is the only circumstance where an object contains but does not hold another object).

See here for more (exhaustive) detail on the complex relations of regions.

1 Like

by the way, welcome to IntFiction, @SarahTomb !

Last night, after posting, I thought I’d take a whack at a solution that was sensitive to rooms being within the same region hierarchy instead of just immediately within the same map region. And after a bunch of effort to get a really ugly solution down to just a moderately ugly solution, I reread Dr. Bates’ post and was reminded of the common ancestor which facilitates a not ugly solution.

To decide whether (r - a room) and (s - a room) are co-regional:
  let rm be the map region of r;
  let sm be the map region of s;
  if rm is nothing or sm is nothing, decide no;
  if rm is sm, decide yes;
  if the common ancestor of rm with sm is nothing, decide no;
  decide yes.

Check teleporting:
  if the noun is the location, say "Incredibly, you appear in the exact place you are!" instead;
  if the noun and the location are co-regional, continue the action;
  say "There are limits to even your power." instead.

(I also added a test for teleporting to the same room you’re in, which is what you get if you omit the noun.)

1 Like

PS
I think these 2 lines are redundant because the common ancestor of something with nothing is nothing and the common ancestor of something with itself is itself (I’ve updated the ‘relations’ post to make this clearer)

So the rule can be simply reduced to:

To decide whether (r - a room) and (s - a room) are co-regional:
  if the common ancestor of the map region of r with the map region of s is nothing, decide no;
  decide yes.
1 Like