Completely blocking off a room for specific people?


I’m working on something that requires characters to move around the map randomly. That’s simple enough by itself, by using “best route from X to Y”, but…

Some of those characters have wings. So they can obviously access locations and go through routes that other characters cannot. How would you figure out pathfinding in a scenario like that? As in, the characters should completely ignore routes that they can’t travel through.

See chapter 13.11. You might want to create a relation between rooms that describes flyability, completely separate from normal (walking) travel.

Oh, great. I didn’t realise that kind of a thing was possible too. That should be enough to handle this.

Also, another question: As per 7.15, I can define certain kinds of actions. The manual example uses “unmaidenly behaviour”, so… let’s say I wanted something to happen every time something NOT unmaidenly was done? Something like “Instead of doing something that is not unmaidenly behaviour” just makes the compiler angry at me.

I don’t have Inform 7 in front of me to test this, but perhaps “instead of doing something when the current action is not unmaidenly behavior” might work?

It should; “Instead of doing something when not unmaidenly behavior” will also work, oddly enough. (Discussed here; as I say there, it can be easier to envision the possible combinations if you give your kinds of actions names like “behaving unmaidenlily,” so “Instead of doing something when not behaving unmaidenlily” reads sort of like English. Except for the whole problem about turning “unmaidenly” into an adverb.)

Aw yeah, that worked perfectly. It was a bit counterintuitive and I didn’t find any mentions of it in the manual, but yeah, that solves it.

Might as well keep using this thread.

So my pathfinding is basically

let P be a random legal room which is adjacent to R;
let the way be the best route from R to P, using doors;

But I think that if two rooms are connected by a door, they don’t count as adjacent? 6.14 suggested “room-or-door” in another example but it doesn’t seem to function here. So how would I fix that?

Only rooms (not doors) can be adjacent to each other.

I think this is one way of doing what you want:

	let L be a list of rooms;
	repeat with away running through directions:
		let the target be the room-or-door away from R;
		if the target is a room, add the target to L;
		if the target is a door and the other side of the target is not nothing, add the other side of the target to L;
	sort L in random order;
	let the way be the best route from R to entry 1 of L, using doors;

Oh, that’s clever. Yup, that works perfectly, thanks a lot.

Felix’s solution works, but it does depend on a couple of things that can have some overhead (pathfinding, list operations). It looks like you don’t need a lot of the computation that’s done there – all you want to do is find out which directions you can go, and go those ways – so you can just define a relation between rooms and directions, and pick one of the directions:

[code]Chamber is a room. Yard is a room. The big door is a door. The big door is north of Chamber and south of yard. Parlor is west of Chamber. Kitchen is north of Parlor and northwest of Chamber.

Accessibility relates a direction (called the way) to a room (called the place) when the room-or-door the way from the place is not nothing. The verb to be accessible out of implies the accessibility relation.

Wandering Moe is an animal in Chamber.

Every turn:
if a direction is accessible out of the location of Moe:
try Moe going a random direction that is accessible out of the location of Moe.[/code]

I like that. I tend not to come think of defining relations.

Hm, alright. Relations still mystify me a bit, but that seems to work.

Let’s say I want to have an item that teleports the user to a random room that is exactly two moves away from the user’s location. What’s an easy way to figure out if a room is two moves away? By using the “number of moves”, I’d assume, but…

Additionally: I have a table of items I wish to randomly distribute through the map. The table basically contains a kind of an item, and a rarity of the item. It all works well, I can choose a random row from the table just fine, and while I know I can’t create objects dynamically, I’ve just prepared a dozen copies of everything off-stage.

This is using Victor Gijsbers’ example of weighed randomity he gave in another thread once upon a time:

[code]Table of Default Distribution
item rarity
thingamajing 6
foobar 5
health potion 9
potion of fun 8

Total rarity is a number that varies.

To calculate total rarity:
let m be 0;
repeat through the Table of Default Distribution:
increase m by rarity entry;
now total rarity is m.

To decide which number is chosen row:
calculate total rarity;
let x be a random number between 1 and total rarity;
repeat with n running from 1 to the number of rows in the Table of Default Distribution:
choose row n in the Table of Default Distribution;
if x is not greater than rarity entry:
decide on n;
decrease x by rarity entry;
decide on 1. [This should never happen.]

To distribute items randomly:
choose row chosen row in the Table of Default Distribution;
now player is carrying a random off-stage item entry;

When play begins:
distribute items randomly;[/code]

This should give the player a random item from the table, but it returns an error saying it doesn’t understand what a “random off-stage item entry” is. However, if I say “now player is carrying a random off-stage thingamajing;” it works just fine, with the player starting with a thingamajing in his pocket.

I don’t think “random off-stage item entry” is valid Inform terminology. You might want something like this (assuming it works).

To distribute items randomly: choose a random row in the Table of Default Distribution; move the item entry to the player.

Hope this helps.

I think you have defined “thingamajing”, “foobar” and so on as kinds of things, rather than things?

You are running into a situation where I7 interprets these as blank table entries, rather than entries containing kinds. (See 15.8; a kind at the top of a column is interpreted to mean “blank column with this type”. The fact that the rest of the column isn’t blank should tip off the compiler that something’s wrong, but it currently just ignores it. Bug 690, if you’re interested.)

I am not sure of the right way to make a column of kinds. Anyone here spend more time on tables than me? :confused:

Beginning my new and better life centred on relations (and what day could be better?), I suggest this work-around:

Association relates various things to one thing. The verb to be associated with implies the association relation.

Every thingamajing is associated with the thingamajing item.
Every foobar is associated with the foobar item.
Every health potion is associated with the health potion item.
Every potion of fun is associated with the potion of fun item.

Table of Default Distribution
item rarity
thingamajing item 6
foobar item 5
health potion item 9
potion of fun item 8


To distribute items randomly:
choose row chosen row in the Table of Default Distribution;
now player is carrying a random off-stage thing that is associated with the item entry.[/code]

Well, damn, that just worked perfectly. Very nice. Thanks for your continued help.

Still wondering about the two-room warp thing, if anyone’s got some ultra clever solution to that as well.

Perhaps you could define some new directions (e.g., ‘teleport-one’, ‘teleport-two’, etc., however many you think you’ll need) and then just declare that ‘Planet Surface is teleport-one from Transporter Room’?

(This idea arises from the ‘shipboard directions’ (fore/aft/port/starboard) examples/extensions/discussions.)

That’s pretty interesting. But it’s a pretty big map and manually declaring every room that’s two steps away from every other room would be a nightmare.

The problem seems to be that the number of moves phrase ignores rooms the other side of a door, right?

I think this is a way to do it (I don’t know if it’s the best way—but I’m beginning to get fond of relations and defining adjectives):

Neighbouring relates a room (called X) to a room (called Y) when X is adjacent to Y or Y is adjacent to X or (there is a door (called Z) in X and Y is the other side of Z from X) or (there is a door (called Z) in Y and X is the other side of Z from Y).
The verb to be nextdoors to implies the neighbouring relation.

Definition: A room is nextdoors if it is nextdoors to the location.

Definition: A room is nearby if it is nextdoors to a nextdoors room and it is not the location.

Definition: A room is twice removed if it is nearby and it is not nextdoors.

A room is nearby if there is some two move way to get to it (i.e. you can reach it by passing through one other room, though there may be a way to reach it in one move as well—or in more than two moves).
A room is twice removed if there shortest way to it is in two moves (i.e. to reach a twice removed room, the shortest way is to pass through one other room—there may be longer ways but no shorter ones).
Or so was my intention.
(Note also that simply ‘nextdoors’ always means ‘nextdoors to the location of the player’ not nextdoors to any other room.)

That works perfectly. Thanks a ton, once again!