§7.4. Barter and Exchange

By default, Inform characters are a bit grudging about giving and sharing objects: they react with disinterest when they're shown things and refuse everything they're offered.

If we'd like to change this, we can simply remove the default "block giving" rule, as in

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

If we do this, giving items to characters will have the result of moving our possessions to the other person's inventory. Of course, without more customization, the player may not ever be able to persuade the other character to return his possessions. Bribery demonstrates a scenario in which a character will accept gifts if they are interesting to him, and respond with a changed attitude to the player.

Barter Barter expands further on this by allowing other characters to trade things with one another.

* See Modifying Existing Commands for ways to allow the player to give or show things that he isn't currently holding

* See Actions on Multiple Objects for an implementation of giving that allows the player to offer multiple objects at once, where their combined value determines whether they are accepted

* See Money for ways to keep track of cash flow, physical money objects, and price negotiations


arrow-up.pngStart of Chapter 7: Other Characters
arrow-left.pngBack to §7.3. Reactive Characters
arrow-right.pngOnward to §7.5. Combat and Death

If we want to rewrite the functionality of a command that usually ends with a "block..." rule, we will have to begin by turning the blocking off.

paste.png "Bribery"

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

As it happens, correct behavior is built into the GIVE command once "block giving" is turned off, so we do not have to write a replacement report or carry-out rule; the object will be transferred to the possession of the caterpillar. But we do want to adjust the action just a little so that our gift cheers up the recipient:

Carry out giving (this is the gratitude for gifts rule): improve the mood of the second noun.

Mood is a kind of value. The moods are hostile, suspicious, indifferent, friendly, and adoring. An animal has a mood. An animal is usually indifferent.

To improve the mood of (character - an animal):
    if the mood of character is less than friendly, now the mood of the character is the mood after the mood of the character.

Now whenever we give something to an animal, the animal will be pleased about the present. Of course, we might also want to add a check rule to giving, to see whether the offering is something the recipient really wants:

Check giving (this is the polite refusal of unwanted objects rule):
    unless the noun interests the second noun:
        say "[The second noun] disdainfully refuses [the noun]." instead.

To decide whether (item - a thing) interests (character - a person):
    if the character has the item, no;
    if the item is edible, yes;
    no.

Instead of showing something to someone:
try giving the noun to the second noun.

There is already a perfectly workable report rule that will describe what happens when we give something to someone, but let's say we want to report on the recipient's changed mood, too:

After giving something to someone:
    say "You give [the noun] to [the second noun], who appears mollified and is now merely [mood of the second noun]."

And the rest is all scenario:

The Leafy Branch is a room. "You stand on smooth bark dappled by sunlight. The scent-trail runs forward to home.

The branch continues forward and backward from here, and a stem extends forward-up."

Instead of going south in Leafy Branch, say "You must not back down! The scent trail leads onward!"

The Very Hungry Caterpillar is a hostile animal in the Leafy Branch. "[The Caterpillar] looks [mood]." Instead of examining the Caterpillar, say "[The caterpillar] appears [mood]."

The player carries an edible thing called a peanut crumb. The carrying capacity of the player is 1. After taking something, say "You lift [the noun], though it is nearly your own size."

Instead of going north in the presence of a hostile caterpillar:
    say "[The Caterpillar] moves to block your exit, glaring down at you with all the bristles on its skin extended to full size."

Instead of going north in the presence of a suspicious caterpillar:
    say "[The Caterpillar] moves to block your exit, though it might allow you past if you offered further tribute."

The Leaf Face is above the branch. "The smooth and shiny surface of the leaf extends forward from here, but you have lost the scent-trail. This is not the way home." The pear fragment is an edible thing in Leaf Face. The dead aphid is a thing in Leaf Face.

The Twig is north of Leafy Branch. "The scent-trail is weak but not entirely gone, and you pursue it faithfully..."

After going to the Twig:
    say "The scent-trail is weak but not entirely gone, and you pursue it faithfully...";
    end the story finally.

Understand "forward-up" as up. Understand "forward" as north. Understand "backward" as south. Understand "backward-down" as down.

Test me with "forward / give crumb to caterpillar / forward / forward-up / get aphid / get fragment / down / give aphid to caterpillar / drop aphid / forward-up / get fragment / down / give fragment / forward".

**ExampleBribery
A GIVE command that gets rid of Inform's default refusal message in favor of something a bit more sophisticated.

If we want to rewrite the functionality of a command that usually ends with a "block..." rule, we will have to begin by turning the blocking off.

paste.png "Bribery"

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

As it happens, correct behavior is built into the GIVE command once "block giving" is turned off, so we do not have to write a replacement report or carry-out rule; the object will be transferred to the possession of the caterpillar. But we do want to adjust the action just a little so that our gift cheers up the recipient:

Carry out giving (this is the gratitude for gifts rule): improve the mood of the second noun.

Mood is a kind of value. The moods are hostile, suspicious, indifferent, friendly, and adoring. An animal has a mood. An animal is usually indifferent.

To improve the mood of (character - an animal):
    if the mood of character is less than friendly, now the mood of the character is the mood after the mood of the character.

Now whenever we give something to an animal, the animal will be pleased about the present. Of course, we might also want to add a check rule to giving, to see whether the offering is something the recipient really wants:

Check giving (this is the polite refusal of unwanted objects rule):
    unless the noun interests the second noun:
        say "[The second noun] disdainfully refuses [the noun]." instead.

To decide whether (item - a thing) interests (character - a person):
    if the character has the item, no;
    if the item is edible, yes;
    no.

Instead of showing something to someone:
try giving the noun to the second noun.

There is already a perfectly workable report rule that will describe what happens when we give something to someone, but let's say we want to report on the recipient's changed mood, too:

After giving something to someone:
    say "You give [the noun] to [the second noun], who appears mollified and is now merely [mood of the second noun]."

And the rest is all scenario:

The Leafy Branch is a room. "You stand on smooth bark dappled by sunlight. The scent-trail runs forward to home.

The branch continues forward and backward from here, and a stem extends forward-up."

Instead of going south in Leafy Branch, say "You must not back down! The scent trail leads onward!"

The Very Hungry Caterpillar is a hostile animal in the Leafy Branch. "[The Caterpillar] looks [mood]." Instead of examining the Caterpillar, say "[The caterpillar] appears [mood]."

The player carries an edible thing called a peanut crumb. The carrying capacity of the player is 1. After taking something, say "You lift [the noun], though it is nearly your own size."

Instead of going north in the presence of a hostile caterpillar:
    say "[The Caterpillar] moves to block your exit, glaring down at you with all the bristles on its skin extended to full size."

Instead of going north in the presence of a suspicious caterpillar:
    say "[The Caterpillar] moves to block your exit, though it might allow you past if you offered further tribute."

The Leaf Face is above the branch. "The smooth and shiny surface of the leaf extends forward from here, but you have lost the scent-trail. This is not the way home." The pear fragment is an edible thing in Leaf Face. The dead aphid is a thing in Leaf Face.

The Twig is north of Leafy Branch. "The scent-trail is weak but not entirely gone, and you pursue it faithfully..."

After going to the Twig:
    say "The scent-trail is weak but not entirely gone, and you pursue it faithfully...";
    end the story finally.

Understand "forward-up" as up. Understand "forward" as north. Understand "backward" as south. Understand "backward-down" as down.

Test me with "forward / give crumb to caterpillar / forward / forward-up / get aphid / get fragment / down / give aphid to caterpillar / drop aphid / forward-up / get fragment / down / give fragment / forward".

***ExampleBarter Barter
Allowing characters other than the player to give objects to one another, accounting for the possibility that some items may not be desired by the intended recipients.