I’m not sure how much of this is a coding question and how much of this is a design question. Apologies if I wander a bit. I’ve posted a stripped-down version of the code I’m working with at the end of this post.
So I have a number of wandering, NPCs that track an object or location that they’re currently trying to reach, and each of which makes a move calculated using the best route from ... to ...
each turn that they’re currently seeking a goal.
I also have a set of windows that I want the PC to be able to climb through – there’s at least one “gain access to an area by managing to climb through a window” puzzle in the middle game, so I’ve declared a window is a kind of door
and written rules that check whether windows are physically accessible based on whether the PC has manipulated the physical environment appropriately to solve the puzzle.
The problem is that the best route
phrases will happily route the NPCs through windows even when there are non-window paths available, which I’d like to avoid. (It’s incongruous for an NPC to say “Welp, I’m going to bed now” and then to get to their bedroom by jumping out the bathroom window and climbing back in through their bedroom window instead of just walking down the hallway, even if it is the same number of moves.)
I guess I’m wondering what the best way to control this behavior is. Ideally, I’d like to be able to place conditions on the route found by the the best route
phrase. Writing with Inform 6.14 mentions a ...using [type of object]
qualifier, but is a little vague about the syntax. I’ve tried every variation in phrasing on using rooms and non-window doors
that I can think of, but nothing works. (I’d love a way to say “avoiding windows” or “avoiding windows if possible,” but I don’t see any indication that that’s a phrase that might work.)
Alternately, I suppose I could implement windows without making them a kind of door, but that also seems like a lot of work, because doors are special cases in a lot of ways: they appear in two rooms; there are a whole bunch of rules applying to them that I’d rather not rewrite; they already work with Locksmith; and so forth.
Does anyone have a suggestion on what they easiest way is to keep NPCs from jumping out windows?
Here’s a pared-down sample of what I’m currently doing. I’d love to be able to prevent the meter-reader from coming through windows.
"temp" by "Patrick Mooney"
The story headline is "A scratchpad".
Include Locksmith by Emily Short.
Section - Door stuff
A window is a kind of door. A window is usually locked.
A door is usually lockable. A door is usually closed.
A door is usually undescribed. The Can't Go Through Undescribed Doors rule is not listed in any rulebook.
Section - Game World
Living Room is a room. "Just an empty space with carpeting. The movers haven't delivered your stuff yet.[if someone is in Front Lawn][paragraph break]Outside the window, you can see [the list of people in Front Lawn].[end if][paragraph break]Your bedroom is north. Your bathroom is northeast. Your front lawn is to the southwest. You can head out to the garage to the east. You could in theory climb through your front window, to the south, and out onto the lawn, if you'd like.".
Front Lawn is a room. "A patch of grass. At least the previous owners bothered to mow out here shortly before selling the house.[paragraph break]Your living room is through your front door, to the northwest, or through your front window, to the north. The garage door leads northeast to your garage. The back lawn is through a gate to the west.".
the Living Room Window is a window. It is south of Living Room and north of Front Lawn.
Front Door is a locked door. It is northwest of Front Lawn and southwest of Living Room.
Bedroom is a room. "If your stuff ever arrives, this is going to be the coziest bedroom ever.[paragraph break]Your bathroom is east; the living room is to the south. Your back lawn is through the window to the west.".
the Bedroom door is a door. It is north of Living Room and south of Bedroom.
Bathroom is a room. "All the standard fixtures, plus some very stylish avocado-green linoleum peeling on the floor.[paragraph break]Your bedroom is west. Your living room is southwest.".
the First Bathroom Door is a door. It is east of Bedroom and west of Bathroom.
the Second Bathroom Door is a door. It is northeast of Living Room and southwest of Bathroom.
Garage is a room. "An empty space with an oil-stained concrete floor.[paragraph break]Your living room is back through the door to the west. Your front lawn is through the garage door to the southwest.".
the Interior Garage Door is a door. It is west of Garage and east of Living Room.
the Exterior Garage Door is a locked door. It is northeast of Front Lawn and southwest of Garage.
Back Lawn is a room. "The fence keeps the neighbors from seeing the yard, and the previous owners let the grass get pretty shaggy back here.[paragraph break]Your front lawn is through the gate to the south, or you could climb in through your bedroom window, to the west.".
The fence is scenery in Back Lawn. The water meter is scenery in Back Lawn.
the Gate is a locked door. It is west of Front Lawn and south of Back Lawn.
the Bedroom Window is a window. It is west of Bedroom and east of Back Lawn.
Street is a room. "Just an ordinary street in suburbia, just like jillions of other ordinary streets in suburbia.[paragraph break]Your new house is to the north." It is south of Front Lawn.
Section - People and Movement
A person can be awake or asleep. A person is usually awake.
A person has an object called the destination. The destination of a person is usually nothing.
Every turn (this is the People Seek Their Goals Rule):
let L be the list of awake people;
repeat with P running through L:
if the destination of P is not nothing:
let the destination sought be an object;
if the destination of P is not a room:
now the destination sought is the location of the destination of P;
otherwise:
now the destination sought is the destination of P;
if P is enclosed by the destination sought:
now the destination of P is nothing;
otherwise if P is awake and the destination sought is a room:
let the way be the best route from the location of P to the destination sought, using doors;
if the way is not a direction:
let the way be the best route from the location of P to the destination sought, using even locked doors;
if the way is a direction:
let old location be the location of P;
try P going the way.
Section - Characters
The player carries the master key. The master key unlocks Front Door. The master key unlocks Garage Door. The master key unlocks Bedroom Window. The Master Key unlocks Living Room Window. The master key unlocks Gate.
Your husband is a man in Bathroom.
Every turn:
if a random chance of one in four succeeds:
now the destination of husband is a random room.
Every turn when husband is visible, say "'Honey,' says your husband, 'have you seen [one of]the[or]my[purely at random] [one of]electric[or]cryogenic[or]8-bit[or]miniaturized[or]simplified[or]steam-powered[or]discount[or]hipster[or]enhanced[or]new[or]watermelon-flavored[or]damaged[or]chiptune-producing[at random] [one of]hedge clippers[or]razor[or]laptop[or]shirt press[or]skinny jeans[or]remote control[or]waffle iron[or]George Foreman grill[or]broom[or]foot locker[or]coffee pot[or]letter opener[or]screwdriver[or]reanimation kit[at random]?'[paragraph break]'Sorry, no,' you sigh."
Husband carries the garage-door opener. The opener unlocks Exterior Garage Door.
The Meter-Reader is a woman in Street. The description of the meter-reader is "A nondescript person in a nondescript uniform." The destination of the Meter-Reader is the water meter.
Every turn when the Meter-Reader can see the water meter:
If the player can see the water meter:
say "The meter-reader, glancing at the meter, looks very angry.";
now the destination of the Meter-Reader is the player.
Every turn when the Meter-Reader can see the player:
if the destination of the Meter-Reader is the water meter:
say "'Sir? Sir? I need to get access to your water meter to read it, please,' says the meter reader.";
else:
say "The meter-reader glowers at you. 'You've tricked out your water meter to underrepresent your usage,' he says. 'That's fraud.'[paragraph break]'No!' you yell. 'We just moved in this morning! That must have been done by the previous owners!'[paragraph break]'Tell it to the judge,' sneers the meter-reader, 'just like everyone else does. You're going away for a long, long time, bucko.'";
end the story saying "Jail is no fun.".