Lemonade

Example 266
★★★

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.

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 ".
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".
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.

You can also see a pitcher of lemonade here.

>(Testing.)

>[1] x milk
The glass contains about one fluid ounce of milk.

>[2] x lemonade
The pitcher contains about twenty fluid ounces of lemonade.

>[3] drink lemonade
You take a sip of lemonade.

>[4] drink milk
You take a sip of milk.

>[5] pour lemonade into glass
Mixing lemonade with milk would give unsavory results.

>[6] drink milk
You take a sip of milk.

>[7] x milk
The glass contains a swallow or two of milk.

>[8] drink milk
You take a sip of milk.

>[9] g
You take a sip of milk, leaving the glass empty.

>[10] i
You are carrying:
an empty glass

>[11] fill glass with lemonade
The pitcher of lemonade now contains about eight fluid ounces of lemonade; the glass of lemonade contains about twelve fluid ounces of lemonade, and is now full.

>[12] drink lemonade
(the glass of lemonade)
You take a sip of lemonade.

>[13] drop glass
Dropped.

>[14] drink lemonade
Which do you mean, the glass of lemonade or the pitcher of lemonade?

>[15] pitcher
You take a sip of lemonade.