intfiction.org

The Interactive Fiction Community Forum
It is currently Thu Apr 27, 2017 11:48 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Apr 21, 2017 2:02 am 
Offline

Joined: Mon Apr 10, 2017 9:09 pm
Posts: 11
I'm learning Inform 7 by making a small game taking place on a pirate ship.

The current thing I'm tackling is trying to allow a light source to stretch through multiple rooms. Since on a pirate ship it's mostly open space rather than by doors. However I don't want the light source to travel vertically, just horizontally.

To simplify what I have:
Code:
room below decks is a kind of dark room.
ladder is a kind of open, unopenable door.

Storeroom is a room below decks. "This is the Storeroom".
Crew's Quarters is a room below decks. "This is the crew's quarters".
wooden ladder is a ladder. wooden ladder is above storeroom and below Crew's Quarters.

Capstan room is a room below decks. Capstan room is south of crew's quarters. "This is the capstan room".


Assuming the player drops their lantern in the crew's quarters, I'd like to be able to see in the capstan room but not in the storeroom.

Also, how hard would it be to specify that the light will only stretch the length of one room?
For example if I added another room south of the capstan room, with the lantern dropped in crew's quarters,
How difficult would it be to have the capstan room lit but the room further south dark?


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 6:13 am 
Offline
User avatar

Joined: Sun Nov 22, 2009 12:58 pm
Posts: 687
Location: Malmö, Sweden
Code:
A room below decks is a kind of dark room.
Before going from a room below decks, now every room below decks is dark.

Definition: a direction is horizontal if it is not up and it is not down.

Before going to a room below decks (called the place):
	repeat with d running through horizontal directions:
		let r be the room d from the place;
		if r is not nothing and r holds something which is lit, now place is lighted.



a ladder is a kind of open unopenable door.

Storeroom is a room below decks. "This is the Storeroom".
Crew's Quarters is a room below decks. "This is the crew's quarters".
Kitchen is south of the Capstan room. The kitchen is a room below decks.
the wooden ladder is a ladder. wooden ladder is above storeroom and below Crew's Quarters.

Capstan room is a room below decks. Capstan room is south of crew's quarters. "This is the capstan room".

The player is carrying a lantern. The lantern is lit.


This is not exactly idiomatic Inform 7, since it involves toggling values on and off rather than computing them. I'm not sure how to fix that issue. Any takers?

_________________
~Björn Paulsen


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 8:37 am 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 4775
Location: Burlington, VT
In a way, I think the idiomatic Inform 7 way of treating it would be to use visibility rules, as discussed in §12.19. But, as that section discusses, that doesn't help with looking--the looking action is defined so as not to require light, and instead runs through the activities for printing the name of a dark room and printing the description of a dark room.

So you'd have to modify those two activities as well. It wouldn't be too hard to modify the rule for printing the name of a dark room so as to print the room's printed name instead when there was a light in the next room, but modifying the rule for printing the description of a dark room to work correctly would be a humongous and unnecessary pain, since the behavior of the looking action is very complicated. As far as I know there's no bypass to make this activity go "Just print what you would print if the room were lighted."

So... the short version is that there's no idiomatic I7 way to handle this, because the calculation of lighting is handled at the I6 level and there's no handy way to jump in and tell it "Hey, the room should actually count as being in darkness if there's a light source in the next room." Which means your approach, which toggles the lighted/dark property as you need, is surely the best.

The thing I would say is that I'm pretty sure that your approach will leave a trail of light behind you, because you don't have a provision for making the room dark again when you take the light source away. I'd make a phrase to "update light belowdecks" or something like that, which could be triggered to calculate which rooms are supposed to be lighted and which dark, and which could be calculated whenever something happens that could change it (like going, or a light source failing, or something like that).


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 8:42 am 
Offline
User avatar

Joined: Sun Nov 22, 2009 12:58 pm
Posts: 687
Location: Malmö, Sweden
Well, there's a Before statement that darkens all belowdecks rooms. Is that what you mean?

Of course, one problem is that it triggers when going from a room below decks but not other rooms, which doesn't catch the case that you might be going from another kind of room with the lantern inside.

So that line would preferably read

Code:
Before going, now every room below decks is dark.


instead.

_________________
~Björn Paulsen


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 9:27 am 
Offline

Joined: Tue Mar 18, 2008 9:04 am
Posts: 1071
It's a bit old-school now (especially using all those begin;s) but here is how Bronze handles next-room light sources: http://inform7.com/learn/eg/bronze/source_17.html


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 10:02 am 
Offline

Joined: Fri Oct 18, 2013 10:13 am
Posts: 2324
Location: The Midwest
Alternate Lighting System allows this to be written using rules, though performance might take a hit.

_________________
Daniel Stelzer


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 10:30 am 
Offline

Joined: Tue Nov 08, 2011 8:11 am
Posts: 1793
Location: US - Central
Ooh, this is interesting. My solution is to create some scenery lights and move them around based on taking or dropping the lantern.

code : show
Code:
"Ambient Light Source"

A very bright lantern is carried by the player. It is lit. "This lantern casts extremely bright light in all directions."

ambient light is a kind of thing. It is scenery. It is lit."Light spills in here from [the best route from the location to the location of very bright lantern]."

There are 10 ambient lights.

Carry out dropping lantern:
	repeat with place running through adjacent rooms:
		now a random off-stage ambient light is in place.
		
Carry out taking lantern:
	repeat with snuffed running through on-stage ambient lights:
		now snuffed is off-stage.
		
after printing the name of a room:
	if the location is dark:
		if an ambient light is in the location:
			say " (lit by ambient light from the [best route from the location to the location of very bright lantern])"

Dark Dungeon is a room. It is dark. "You can go north and south here."

North Catacomb is north of Dark Dungeon. it is dark. "You can go south here."

South Chamber is south of Dark Dungeon. It is dark. "You can go north here."


transcript : show
Quote:
Dark Dungeon
You can go north and south here.

>i
You are carrying:
a very bright lantern (providing light)

>n

North Catacomb
You can go south here.

>s

Dark Dungeon
You can go north and south here.

>drop lantern
Dropped.

>n

North Catacomb (lit by ambient light from the south)
You can go south here.

>s

Dark Dungeon
You can go north and south here.

You can see a very bright lantern (providing light) here.

>s

South Chamber (lit by ambient light from the north)
You can go north here.

>n

Dark Dungeon
You can go north and south here.

You can see a very bright lantern (providing light) here.

>take lantern
Taken.

>s

South Chamber
You can go north here.

>drop lantern
Dropped.

>n

Dark Dungeon (lit by ambient light from the south)
You can go north and south here.

>n

Darkness
It is pitch dark, and you can't see a thing.




I just lit one room in each direction, but if you make the ambient light a lit backdrop and each deck of your ship a region, you can similarly move the ambient light backdrop into the appropriate region where the lamp is and it will fill the region.

_________________
http://hanonondricek.wix.com/pyramidif


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 1:17 pm 
Offline

Joined: Tue Mar 09, 2010 2:34 pm
Posts: 4775
Location: Burlington, VT
Eleas wrote:
Well, there's a Before statement that darkens all belowdecks rooms. Is that what you mean?

Of course, one problem is that it triggers when going from a room below decks but not other rooms, which doesn't catch the case that you might be going from another kind of room with the lantern inside.

So that line would preferably read

Code:
Before going, now every room below decks is dark.


instead.


Ooh, I missed that rule. Teach me to talk about code without running it!

Also, I didn't realize that your code works by only lighting up the room that you're going to, if appropriate. What I was thinking of is that there are some circumstances in which you might want to know the lighting status of every room, or adjust it another time than at the Before going stage. For instance, if a light source can spontaneously turn off, you might need to recalculate the lighting even without going. Or if you have a rule like this:
Code:
Instead of going from a dark room to a dark room: say "You can't see the way to the next room."

you need to recalculate lighting all at once instead of just lighting up the new room when you get there. If you add this line to your code, you can't get up the ladder, because the Storeroom gets darkened and the lantern in the Storeroom won't light the Capstan.

But yeah, I missed that in your code completely!


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 3:43 pm 
Offline
User avatar

Joined: Sun Nov 22, 2009 12:58 pm
Posts: 687
Location: Malmö, Sweden
Honestly, if I wrote this as a game, I'd probably end up doing a transcript first just to determine what issues I wanted the player to face. I know the OP just wants to play with it, but even if you're going big it's a nice scenario to ruminate on, you really could do a lot with it. Like, you could add Epistemology to make the player aware of something only if they've previously touched it, and then only if they're aware just what room they're in... you could add various light levels, even.

_________________
~Björn Paulsen


Top
 Profile Send private message  
 
PostPosted: Fri Apr 21, 2017 8:34 pm 
Offline

Joined: Mon Apr 10, 2017 9:09 pm
Posts: 11
Thanks a lot for all the help! Really appreciate the community.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group