Chapter 10: Physics: Substances, Ropes, Energy and Weight
10.2. Liquids

Liquids are notoriously difficult to simulate well. A fully thorough approach consumes endless storage and can be very finicky to write and keep realistic. It is essential to decide what aspect of a liquid's behaviour is actually needed in a given story, and to simulate only that. For instance, if we only need a little chemistry, where a player can add (say) water to salt and make a solution, we do not want to fool around with calculating quantities or concentrations: what's important is that "some water" (amount unspecified) combines with "some salt" to produce "some salty water". We should no more calculate precisely here than we would work out where all the furniture is to the nearest inch. Good advice for handling liquids is to simulate the least amount of realism possible, but no less.

Sometimes all we want is a down-in-one drink: we needn't simulate the actual liquid, just the bottle it comes in, and all we need is to handle the "drinking" action. See Beverage Service, and also 3 AM, where carbonated drinks can be shaken - again simulating the vessel, not the liquid.

Some elementary biochemistry in Xylan is done simply by... well, the point is that two different liquids are represented by single things each, and a chemical reaction simply switches one for the other.

In Frizz, we allow any container to be filled (only) with water (only) and we simulate what happens to any solid objects also inside: some waterproof, some not. Flotation provides a well (always full of water), with rules to determine whether things dropped into it should sink or float.

Next we move up to quantitative approaches, where we remember not just whether a liquid is present, but how much of it. In its simplest form, we could have a drinking vessel from which we draw in sips, so that it can be full, half-empty or empty: see Thirst.

The example with the best compromise between simulation quality and complexity is Lemonade. Here we provide a kind of container called a "fluid container", not just a single cup, and each such vessel has a given "fluid capacity". Each holds only a single liquid at a time (so no mixtures) and can be empty or full to any level (rounded off to the nearest 0.1 fl oz). We can fill one vessel from another (unless it would make a mixture). But liquids leaving these vessels must be consumed - drunk or poured away without trace: we cannot make pools on the floor, or carry liquids in our cupped hands. There is no object representing "lemonade": there are only fluid containers, but which can be called LEMONADE if that is what they now contain.

Savannah is a light elaboration of Lemonade, showing how liquids might be poured on other objects, as for instance to extinguish a fire.

Noisy Cricket extends Lemonade to allow for mixing, though then the number of different possible mixtures is so large that complexity increases greatly. Lakeside Living extends Lemonade differently to add a "liquid source" kind, a form of fluid container which has infinite fluid capacity and is scenery - ideal for a lake, river or spring.

* See Bags, Bottles, Boxes and Safes for stoppered bottles which could also be used for carrying liquids around in

* See Heat for keeping liquids warm in insulated containers


123
* Example  Beverage Service
A potion that the player can drink.

WI
193
*** Example  3 AM
A shake command which agitates soda and makes items thump around in boxes.

WI
192
*** Example  Frizz
Liquid flows within containers and soaks objects that are not waterproof; any contact with a wet object can dampen our gloves.

WI
385
* Example  Flotation
Objects that can sink or float in a well, depending on their own properties and the state of the surrounding environment.

WI
277
** Example  Xylan
Creating a new command that does require an object to be named; and some comments about the choice of vocabulary, in general.

WI
117
* Example  Thirst
A waterskin that is depleted as the player drinks from it.

WI
256
*** Example  Lemonade
Containers for liquid which keep track of how much liquid they are holding and of what kind, and allow quantities to be moved from one container to another.

WI

Liquids, and all substances that can be mixed or broken off in partial amounts, pose a challenge to model in interactive fiction. The following example is a simple one, but adequate for many scenarios.

We start by assuming that all liquids in the game will always appear in containers. The player can pour liquids from one container to another, and the containers keep track of how full they are and describe themselves appropriately. The player can also refer to containers by content.

Mixture, however, is not allowed, nor is it possible to put liquids on other objects, pour them out on the ground, etc. These ideas would require a more complicated set-up.

"Lemonade"

A volume is a kind of value. 15.9 fl oz specifies a volume with parts ounces and tenths (optional, preamble optional).

A fluid container is a kind of container. A fluid container has a volume called a fluid capacity. A fluid container has a volume called current volume.

The fluid capacity of a fluid container is usually 12.0 fl oz. The current volume of a fluid container is usually 0.0 fl oz.

Liquid is a kind of value. The liquids are water, milk, lemonade, and iced tea. A fluid container has a liquid.

Instead of examining a fluid container:
    if the noun is empty,
        say "You catch just a hint of [the liquid of the noun] at the bottom.";
    otherwise
        say "[The noun] contains [current volume of the noun in rough terms] of [liquid of the noun]."

To say (amount - a volume) in rough terms:
    if the amount is less than 0.5 fl oz:
        say "a swallow or two";
    otherwise if tenths part of amount is greater than 3 and tenths part of amount is less than 7:
        let estimate be ounces part of amount;
        say "[estimate in words] or [estimate plus 1 in words] fluid ounces";
    otherwise:
        if tenths part of amount is greater than 6, increase amount by 1.0 fl oz;
        say "about [ounces part of amount in words] fluid ounce[s]".

Before printing the name of a fluid container (called the target) while not drinking:
    if the target is empty:
        say "empty ";
    otherwise:
        do nothing.

After printing the name of a fluid container (called the target) while not examining:
    unless the target is empty:
        say " of [liquid of the target]";
        omit contents in listing.

Instead of inserting something into a fluid container:
    say "[The second noun] has too narrow a mouth to accept anything but liquids."

Definition: a fluid container is empty if the current volume of it is 0.0 fl oz. Definition: a fluid container is full if the current volume of it is the fluid capacity of it.

Understand "drink from [fluid container]" as drinking.

Instead of drinking a fluid container:
    if the noun is empty:
        say "There is no more [liquid of the noun] within." instead;
    otherwise:
        decrease the current volume of the noun by 0.2 fl oz;
        if the current volume of the noun is less than 0.0 fl oz, now the current volume of the noun is 0.0 fl oz;
        say "You take a sip of [the liquid of the noun][if the noun is empty], leaving [the noun] empty[end if]."

We have allowed all liquids to be drunk, but it would be possible also to add checking, if we had a game where some liquids were beverages and others were, say, motor oil.

Understand the command "fill" as something new.

Understand "pour [fluid container] in/into/on/onto [fluid container]" as pouring it into. Understand "empty [fluid container] into [fluid container]" as pouring it into. Understand "fill [fluid container] with/from [fluid container]" as pouring it into (with nouns reversed).

Understand "pour [something] in/into/on/onto [something]" as pouring it into. Understand "empty [something] into [something]" as pouring it into. Understand "fill [something] with/from [something]" as pouring it into (with nouns reversed).

Pouring it into is an action applying to two things.

Check pouring it into:
    if the noun is not a fluid container, say "You can't pour [the noun]." instead;
    if the second noun is not a fluid container, say "You can't pour liquids into [the second noun]." instead;
    if the noun is the second noun, say "You can hardly pour [the noun] into itself." instead;
    if the liquid of the noun is not the liquid of the second noun:
        if the second noun is empty, now the liquid of the second noun is the liquid of the noun;
        otherwise say "Mixing [the liquid of the noun] with [the liquid of the second noun] would give unsavory results." instead;
    if the noun is empty, say "No more [liquid of the noun] remains in [the noun]." instead;
    if the second noun is full, say "[The second noun] cannot contain any more than it already holds." instead.

Carry out pouring it into:
    let available capacity be the fluid capacity of the second noun minus the current volume of the second noun;
    if the available capacity is greater than the current volume of the noun, now the available capacity is the current volume of the noun;
    increase the current volume of the second noun by available capacity;
    decrease the current volume of the noun by available capacity.

Report pouring it into:
    say "[if the noun is empty][The noun] is now empty;[otherwise][The noun] now contains [current volume of the noun in rough terms] of [liquid of the noun]; [end if]";
    say "[the second noun] contains [current volume of the second noun in rough terms] of [liquid of the second noun][if the second noun is full], and is now full[end if]."

This is probably a drier description than we would actually want in our story, but it does allow us to see that the mechanics of the system are working, so we'll stick with this for the example.

Now we need a trick from a later chapter, which allows something to be described in terms of a property it has. This way, the story will understand not only "pitcher" and "glass" but also "pitcher of lemonade" and "glass of milk" -- and, indeed, "glass of lemonade", if we empty the glass and refill it with another substance:

Understand the liquid property as describing a fluid container. Understand "of" as a fluid container.

And now the scenario itself:

The Porch is a room. The porch swing is an enterable supporter in the Porch. "An inviting swing hangs here at the end of the porch, allowing you to enjoy the summer with a cool beverage, and watch your neighbor Ted mowing his lawn with the very last manual powerless lawnmower on the block."

The glass is a fluid container carried by the player. The liquid of the glass is milk. The current volume of the glass is 0.8 fl oz.

The pitcher is a fluid container in the Porch. The fluid capacity of the pitcher is 32.0 fl oz. The current volume of the pitcher is 20.0 fl oz. The liquid of the pitcher is lemonade.

Ted's Lawn is outside from the Porch. Ted is a man in Ted's Lawn. "Ted has taken off his shirt, but still seems a bit oppressed by the sun." The description of Ted is "He looks hot. In all senses."

After deciding the scope of the player: place Ted in scope.

Instead of doing something to Ted when the player is in the Porch: say "You can't really interact with Ted from this distance, except in the sense of eyeing him surreptitiously."

Instead of giving an empty fluid container to Ted: say "Yes, taunt the poor man, why don't you?"

Instead of giving a fluid container to Ted when the liquid of the noun is milk: say "Ted looks ruefully at the milk. 'Thanks, but I'm lactose-intolerant,' he says."

The block giving rule is not listed in the check giving it to rules.

Every turn:
    if Ted is in the location:
        if Ted carries a fluid container (called refreshment):
            try Ted drinking the refreshment;
        otherwise if a random chance of 1 in 3 succeeds:
            say "Ted pushes the ineffective mower over some dandelions."

Instead of someone drinking a fluid container:
    if the noun is empty:
        try the person asked giving the noun to the player;
    otherwise:
        decrease the current volume of the noun by 2.0 fl oz;
        if the current volume of the noun is less than 0.0 fl oz, now the current volume of the noun is 0.0 fl oz;
        say "[The person asked] gulps down some [liquid of the noun]."

After someone giving something to the player:
    say "'Here,' says [the person asked], handing [the noun] back to you. 'Thanks, I owe you one.'";
    end the story finally.

Test me with "x milk / x lemonade / drink lemonade / drink milk / pour lemonade into glass / drink milk / x milk / drink milk / g / i / fill glass with lemonade / drink lemonade / drop glass / drink lemonade / pitcher".

Test Ted with "out / give milk to ted / drink milk / g / g / g / give glass to ted / in / fill glass with lemonade / out / give lemonade to ted / wait / z / z / z ".

255
*** Example  Savannah
Using the liquid implementation demonstrated in Lemonade for putting out fires.

WI
265
*** Example  Noisy Cricket
Implementing liquids that can be mixed, and the components automatically recognized as matching one recipe or another.

WI
320
*** Example  Lakeside Living
Similar to "Lemonade", but with bodies of liquid that can never be depleted, and some adjustments to the "fill" command so that it will automatically attempt to fill from a large liquid source if possible.

WI


PreviousContentsNext