Chapter 14: Units
14.13. Multiplication of units

Similarly, it is forbidden to multiply 122kg and 10kg, not because it could never make sense (a physicist will occasionally multiply two weights) but because the result is - what? Not a number, and not a weight any more. But we are allowed to tell Inform what the result ought to be, and once we have done so, the multiplication will be allowed:

A length is a kind of value. 10m specifies a length. An area is a kind of value. 10 sq m specifies an area.

A length times a length specifies an area.

The balance platform is in the Weighbridge. "The balance platform is 10m by 8m, giving it an area of [10m multiplied by 8m]."

which will turn up as:

The balance platform is 10m by 8m, giving it an area of 80 sq m.

And having told Inform that lengths multiply to area, we could also divide an area by a length to get a length: no further instructions would be needed.

Note that we are only allowed to make such a rule about multiplication, and only between units, and the result has to be a unit. So this system cannot be used to make Inform multiply, say, a time by a piece of text, nor to contradict any of the standard "dimensional rules" outlined above.


204
* Example  Depth
Receptacles that calculate internal volume and the amount of room available, and cannot be overfilled.

Now we are free to design a system that is much more rigorous about a system of capacity:

"Depth"

A length is a kind of value. 10 cm specifies a length. An area is a kind of value. 10 sq cm specifies an area. A length times a length specifies an area. A volume is a kind of value. 10 cu cm specifies a volume. A length times an area specifies a volume.

A thing has a length called height. A thing has a length called width. A thing has a length called depth. The height of a thing is usually 10 cm. The width of a thing is usually 10 cm. The depth of a thing is usually 10 cm.

A measured container is a kind of container. A measured container has a length called interior height. A measured container has a length called interior width. A measured container has a length called interior depth.

To decide what volume is the interior volume of (item - a measured container):
    let base area be the interior height of the item multiplied by the interior width of the item;
    let base volume be the base area multiplied by the interior depth of the item;
    decide on the base volume.

To decide what volume is the exterior volume of (item - a thing):
    let base area be the height of the item multiplied by the width of the item;
    let base volume be the base area multiplied by the depth of the item;
    decide on the base volume.

We're going to assume that everything is effectively cubical, in order to avoid packing problems. In practice, this is probably close enough to be adequate for the purposes of interactive fiction.

To decide what volume is the available volume of (item - a measured container):
    let starting size be the interior volume of the item;
    repeat with second item running through things in the item
    begin;
        decrease starting size by the exterior volume of the second item;
        if starting size is less than 0 cu cm, change starting size to 0 cu cm;
    end repeat;
    decide on starting size.

To decide what length is the largest dimension of (item - a thing):
    let long side be the height of item;
    if the width of the item is greater than the long side, change the long side to the width of the item;
    if the depth of the item is greater than the long side,
        change the long side to the depth of the item;
    decide on the long side.

Check inserting something into a measured container:
    if the exterior volume of the noun is greater than the interior volume of the second noun, say "[The noun] will never fit inside [the second noun]." instead;
    if the exterior volume of the noun is greater than the available volume of the second noun, say "[The noun] will not fit into [the second noun] with [the list of things in the second noun]." instead;
    if the height of the noun is greater than the largest dimension of the second noun, say "[The noun] is the wrong shape to fit into [the second noun]." instead;
    if the width of the noun is greater than the largest dimension of the second noun, say "[The noun] is the wrong shape to fit into [the second noun]." instead;
    if the depth of the noun is greater than the largest dimension of the second noun, say "[The noun] is the wrong shape to fit into [the second noun]." instead.

The player carries a measured container called a can. The interior height of the can is 10 cm. The interior depth of the can is 5 cm. The interior width of the can is 5 cm.

A pebble is a kind of thing. The height of a pebble is usually 2 cm. The depth of a pebble is usually 2 cm. The width of a pebble is usually 2 cm.

The player carries 25 pebbles. The player carries a red rubber ball. The depth of the ball is 5 cm. The width of the ball is 5 cm. The height of the ball is 5 cm.

The player carries an arrow. The height of the arrow is 40 cm. The width of the arrow is 1 cm. The depth of the arrow is 1 cm.

The player carries a baguette. The height of the baguette is 80 cm. The depth of the baguette is 5 cm. The width of the baguette is 4 cm.

The Lab is a room.

Test me with "put ball in can / put baguette in can / put arrow in can / put pebbles in can".

Several warnings about this. One is that the numbers can't go very high: while the volume can in theory go to 32,767, in practice this equates to an object 32 cm on a side, which is not very large. It will therefore be a good idea to choose dimensions that fit the needs of the game: in some circumstances a decimeter might be a better basic unit of measurement, for instance.

The other is that the system will require a height, width, and depth for every portable object in the game, which is a large commitment of data entry; it may be kind of tiresome. So it is probably not worth bothering with this kind of simulation unless it is going to be genuinely significant.


PreviousContentsNext