Example: Dynamically Describing Exits

While scrounging through old extensions for ECTOCOMP purposes, I came across this bit of code, which I don’t think I ever released. It seems like it might be useful for others, so I’m putting it here.

The purpose of this is to describe rooms in useful and vaguely memorable ways, when the map can vary in play. (Imagine a procedurally-generated cave, for example, or a puzzle where the maze changes while you go through it.)

To describe the/-- dynamic exits of (place - a room):
	let the ways be a list of directions;
	let the name text be "";
	let the description text be "";
	[First, construct a list of viable directions.]
	repeat with the way running through directions:
		if the room way from the place is not nothing, add the way to the ways;
	[Now look for correspondences.]
	if the number of entries in the ways is 0: [No exits: bubble.]
		now the name text is "Bubble";
		now the description text is "This is a small spherical chamber, cut off from all other passages.";
	else if the number of entries in the ways is 1: [Only 1 exit: hole, dome, or dead end.]
		let the way be entry 1 in the ways;
		if the way is up:
			now the name text is "Hole";
			now the description text is "This is the bottom of the vertical shaft.";
		else if the way is down:
			now the name text is "Dome";
			now the description text is "This is the top of the vertical shaft.";
		otherwise:
			now the name text is "Dead End";
			now the description text is "The tunnel stops here. The only way out is to the [way].";
	else if the number of entries in the ways is 2: [Only 2 exits: shaft, corridor, or bend.]
		let the primary be entry 1 in the ways;
		let the secondary be entry 2 in the ways;
		if the primary is the opposite of the secondary:
			if the primary is up or the primary is down:
				now the name text is "Shaft";
				now the description text is "This is a straight vertical shaft, with enough handholds in the wall to allow climbing up and down.";
			otherwise:
				now the name text is "[Primary in title case]-[Secondary in title case] Corridor";
				now the description text is "This is a narrow tunnel going straight from the [primary] to the [secondary].";
		otherwise:
			if the secondary is up or the secondary is down: [Swap the variables so the vertical direction is primary.]
				let the temporary be the primary;
				now the primary is the secondary;
				now the secondary is the temporary;
			if the primary is up:
				now the name text is "Bottom of Shaft";
				now the description text is "A steep shaft ends here, curving into a flat corridor to the [secondary].";
			otherwise if the primary is down:
				now the name text is "Top of Shaft";
				now the description text is "A flat tunnel leading off to the [secondary] ends here at a wide hole in the floor.";
			otherwise:
				now the name text is "[Primary in title case]-[Secondary in title case] Bend";
				now the description text is "The tunnel bends here, leading off to the [primary] and [secondary].";
	otherwise: [3+ exits: opening in shaft, crossing, T-intersection, complex junction, complex intersection]
		if up is listed in the ways and down is listed in the ways:
			remove up from the ways;
			remove down from the ways;
			now the name text is "[if the number of entries in the ways is one][entry one in the ways in title case] [end if]Opening in Shaft";
			now the description is "[if the number of entries in the ways is greater than one]Passages lead[else]A passage leads[end if] off to the [ways] from the middle of a vertical shaft.";
		otherwise:
			let the count be the number of entries in the ways;
			let the pairs be a list of directions;
			let L be the ways;
			repeat with the way running through L:
				let the reverse be the opposite of the way;
				if the reverse is listed in the ways:
					add the way to the pairs;
					remove the way from the ways;
					remove the reverse from the ways;
			let the passages be a list of text;
			repeat with the way running through the pairs:
				add the substituted form of "[way]-[opposite of the way]" to the passages;
			if the number of entries in the ways is zero:
				now the name text is "Crossing";
				now the description text is "This is a wide intersection of passages running [passages].";
			otherwise if the number of entries in the pairs is one:
				now the name text is "T-Intersection";
				now the description text is "[if the number of entries in the ways is 1]A passage [entry 1 in the ways] splits[else]Passages [ways] separate[end if] off a longer [entry 1 in the passages] tunnel here.";
			otherwise if the number of entries in the pairs is zero:
				now the name text is "Complex Junction";
				now the description text is "Passages from the [ways] all come together here in a wide junction.";
			otherwise:
				now the name text is "Complex Intersection";
				now the description text is "[if the number of entries in the ways is 1]A single passage [entry 1 in the ways] separates[else]Single passages [ways] split[end if] off from the intersection of the [passages] tunnels.";
	now the printed name of the place is the substituted form of "[Name Text]";
	now the description of the place is the substituted form of "[description text]".

For example, a room with exits north, south, east, west, and southeast would be a “Complex Intersection”: “A single passage southeast separates off from the intersection of the north-south and east-west tunnels.”

A room with exits northwest and down, on the other hand, would be a “Top of Shaft”: “A flat tunnel leading off to the northwest ends here at a wide hole in the floor.”

I’m not making this an extension, because I think most authors using it would want to customize it for their own purposes instead of using my exact descriptions. But that’s still a lot easier than doing all of this from scratch!

4 Likes