3-way doors

In my very first game, more than 10 years ago, I had a few locations where 3-way doors were needed, because the door was in the corner of a walkway that ran around a central area in an open square. The 3-way doors were in the corners where the walkway turned from north to east and so on, so you could reach the northeast corner door from either the north side or the east side of the walkway. In Inform 6 this is not a problem.

Inform 7 doesn’t allow 3-way doors, of course … but just for fun, today I wrote an example of how to fake a 3-way door in Inform 7, using a backdrop. If anyone wants to see the code, let me know and I’ll post it here.

–JA

As someone who is learning Inform, work-arounds are of keen interest. It’d be very helpful to see how you programmed something that the game engine isn’t adept at accomplishing, so please do post it. Thanks!

Okay, here 'tis, complete with a few comments. I’ve tested it a bit, and it seems to be bug-free, but you never know.

"3-Way Doors" by Jim Aikin

Section 1 - Definition of doordrop object

[A doordrop is a backdrop that pretends to be a door. Because it's not a door, all of the handling (opening and closing, locking and unlocking, and travel through it) has to be handled manually.]

A doordrop is a kind of backdrop. A doordrop can be lockable. A doordrop is always lockable. A doordrop can be openable. A doordrop is always openable. A doordrop can be locked or unlocked. A doordrop can be open or closed. A doordrop is usually closed and locked. Understand "door" as a doordrop. The printed name of a doordrop is usually "door". The matching key of a doordrop is the master key.

Instead of locking a doordrop (called D) with the master key:
	if the player carries the master key:
		try locking keylessly D instead;
	otherwise:
		continue the action.
		
Instead of unlocking a doordrop (called D) with the master key:
	if the player carries the master key:
		try unlocking keylessly D instead;
	otherwise:
		continue the action.

Instead of opening a doordrop (called D):
	if D is locked:
		say "It seems to be locked.";
	otherwise if D is open:
		say "It's already open.";
	otherwise:
		now D is open;
		say "You open [the D]."
	
Section 2 - Locking & Unlocking with Implicit Key

[Inform's library doesn't understand "lock the door" or "unlock the door" without mention of a key, so we have to create two new actions to cover those commands:]

Unlocking keylessly is an action applying to one thing and requiring light. Understand "unlock [something]" as unlocking keylessly.
Check unlocking keylessly:
	say "That doesn't appear to be something that can be unlocked."

Instead of unlocking keylessly a doordrop (called D):
	if D is unlocked:
		say "It's not locked.";
	otherwise if the player does not carry the master key:
		say "You don't seem to have a key that fits the lock.";
	otherwise:
		now D is unlocked;
		say "You unlock [the D]."
		
Locking keylessly is an action applying to one thing and requiring light. Understand "lock [something]" as locking keylessly.
Check locking keylessly:
	say "That doesn't appear to be something that can be locked."
		
Instead of locking keylessly a doordrop (called D):
	if D is locked:
		say "It's already locked.";
	otherwise if the player does not carry the master key:
		say "You don't seem to have a key that fits the lock.";
	otherwise:
		now D is locked;
		now D is closed;
		say "You close and lock [the D]."
		
Section 3 - Rooms for Testing

The North Side of the Arcade is a room. "This covered walkway extends around all four sides of the arcade. From here you can proceed east, around a corner to the east side of the arcade. Above a door in the northeast corner is a sign that says 'TRAVEL AGENCY.'"

The East Side of the Arcade is east of the North Side of the Arcade. "This covered walkway extends around all four sides of the arcade. From here you can proceed north, around the corner to the north side of the arcade. Above a door in the northeast corner is a sign that says 'TRAVEL AGENCY.'" The North Side of the Arcade is north of the East Side of the Arcade.

[The Center of the Arcade is not part of the test, but we'll include it as its exits insure that going west from the East Side of the Arcade won't take you to the North Side of the Arcade, and so on. The Center of the Arcade overrides what Inform would normally do with these room exits.]

The Center of the Arcade is south of the North Side of the Arcade and west of the East Side of the Arcade. "You are standing in the center of the arcade."

The Travel Agency is a room. "Colorful posters showing vacation spots line the walls. The door is in the southwest corner."

The player carries the master key.

The Travel doordrop is a doordrop. The Travel doordrop is in the East Side of the Arcade, the North Side of the Arcade, and the Travel Agency. 

Section 4 - Travel Handling

[This section handles opening the door automatically if it's closed, and also handles unlocking it automatically if it's locked but you're holding the master key.]

Instead of going southwest in the Travel Agency:
	if the Travel doordrop is open:
		now the player is in the East Side of the Arcade;
	otherwise if the Travel doordrop is locked:
		if the player does not carry the master key:
			say "The door seems to be locked.";
		otherwise:
			now the Travel doordrop is open;
			now the Travel doordrop is unlocked;
			say "(first unlocking and opening the door)";
			now the player is in the East Side of the Arcade;
	otherwise:
		now the Travel doordrop is open;
		say "(first opening the door)";
		now the player is in the East Side of the Arcade.
		
Instead of exiting in the Travel Agency:
	try going southwest.
		
Instead of going northeast in the North Side of the Arcade:
	if the Travel doordrop is open:
		now the player is in the Travel Agency;
	otherwise if the Travel doordrop is locked:
		if the player does not carry the master key:
			say "The door seems to be locked.";
		otherwise:
			now the Travel doordrop is open;
			now the Travel doordrop is unlocked;
			say "(first unlocking and opening the door)";
			now the player is in the Travel Agency;
	otherwise:
		now the Travel doordrop is open;
		say "(first opening the door)";
		now the player is in the Travel Agency.
		
Instead of going inside in the North Side of the Arcade:
	try going northeast.
		
Instead of going northeast in the East Side of the Arcade:
	if the Travel doordrop is open:
		now the player is in the Travel Agency;
	otherwise if the Travel doordrop is locked:
		if the player does not carry the master key:
			say "The door seems to be locked.";
		otherwise:
			now the Travel doordrop is open;
			now the Travel doordrop is unlocked;
			say "(first unlocking and opening the door)";
			now the player is in the Travel Agency;
	otherwise:
		now the Travel doordrop is open;
		say "(first opening the door)";
		now the player is in the Travel Agency.
		
Instead of going inside in the East Side of the Arcade:
	try going northeast.
	
Test me with "drop key / ne / take key / ne / close door / sw / lock door / ne".