How do I model this?

Reading through the Writing Inform book, and I’m having some trouble modeling a concept. None of the examples seem to exactly fit, or if one does then I’m just not seeing it.

I’m very used to working in traditional programming languages, so Inform7 is a bit of a shift for me.

I want to model spaceships that might be in a docking port, planet, etc. Ships can be contained in other ships, so you might step on to the landing bay of a station and see a number of ships in the room. These can be boarded, looked at, you could attempt to pick their locks/shoot your way aboard, etc.

You can board a ship and enter a number of interconnected rooms, but certain rooms on the ship have various functions. The first room I want to code is a bridge. Bridges can have a standard description, but their description should be followed by that of the room which contains the ship to which the bridge is attached. So if you’re docked, you’d see something like:

A small, cramped room filled with consoles and control surfaces. Outside, the docking bay of Starbase Alpha swarms with activity as…

If you’ve launched, you may see:

A small, cramped room lined with consoles and active control surfaces. Outside, the blackness of space is speckled with many distant points of light. The warm, yellow glow of Sol is visible in the distance.

The latter would be the description of whatever solar system room/container the ship is in, and could easily change to display a number of circumstances.

How would I go about modeling this? A ship isn’t a vehicle in the sense of a train or bicycle in that it just indicates that you’re in a given room, but on a bicycle. Additionally, I want to associate a number of rooms with a single ship object for processing things like events (“The ship rumbles under the impact of a nearby explosion.”) etc. My initial thought was to create a non-portable container with rooms inside, but nothing I did made this work, and I’m not sure if that was due to me not writing good code or misunderstanding the object hierarchy.

Thanks.

Try something like…

The dock is a room.

The Millennium Falcon is a ship.
The Millennium Falcon Cockpit is a room. 
The description is "You are in the cockpit of the Millennium Falcon. Through the windows you can see [the location of the millennium falcon]".
The Millennium Falcon Lounge is a room.
It is aft of the millennium falcon cockpit.

The Millennium Falcon is in the dock.
Instead of entering the millennium falcon:
   Now the player is in the millennium falcon lounge.
Instead of exiting when the location of the player is the millennium falcon lounge:
   Now the player is in the location of the millennium falcon.

The idea is that the ship you see from the outside is a thing distinct from the rooms of the interior. Then we implement enter and exit by hand.

Here’s some fun trivia: the real Millennium Falcon is exactly like that, due to being smaller than the insides!

The TARDIS is the same, but that’s probably not a surprise.

OK, thanks, that helps some. I’m trying to make your code a bit more generic. At the moment I have:

Chapter World

Section - Space

A solar system is a kind of room. “The deep black of space with a giant nearby star, dotted by distant bits of color.”

Section Celestials

A celestial object is a kind of thing. It is fixed in place.

Section Ships

A bridge is a kind of room. It has a celestial object called the controlled object. The description is “A cramped room full of assorted control surfaces. Through the window you see [the location of the controlled object].”

A cargo bay is a kind of room.

A ship is a kind of celestial object. It has a bridge called the control center. It has a room called the airlock.

Chapter The Environment

Sol is a solar system.

The shuttle is a ship.
The shuttle is in the solar system.
The cockpit is a bridge.
The control center of the shuttle is the cockpit.

The player is in the cockpit.

Questions:

  1. How do I require a ship to have a bridge and an airlock? At the moment it seems like they aren’t.

  2. If I specify that a given object is a ship’s bridge, then I’d like that to imply that the ship is the bridge’s controlled object. How do I imply that?

How many ships do you anticipate having? If it’s just a small number then it will be easiest to hand code all the relations. If you want a large number then it might be better to procedurally link everything up. Or it may be better to still have a small number and “repaint” them when they are needed.

All of that seems fine. I’d suggest using a relation for the controlled object / cockpit relationship. You’re going to need a pile of code to handle moving ships around, docking, boarding and alighting, etc. You will also have to be careful with room names since all the names are global - there can be only one room named ‘cockpit’, and you will run into ambiguity issues if you have one room named ‘cockpit’ and then others named ‘ship x cockpit’, ‘ship y cockpit’, etc.