System for handling plugs and sockets.
This extension provides a mechanism to add plugs and sockets of various kinds to things to allow objects to attach to one another. For example, one could create a TV with a (male) plug attached. Additionally a wall point with a (female) socket could be created thereby allowing the TV to be plugged into it. This could be coded like so: Test Lab is a room. A wall point is here. It is fixed in place. Incorporated by it is a PS-socket. A TV is here. It is fixed in place. Incorporated by it is a PS-plug. This allows the TV to be plugged into the wall point. Naturally, the TV can be unplugged from the wall point. The additional grammar "PLUG something into something" and "UNPLUG something FROM something" have been provided for this. Things can have both plugs and sockets. For example: A power board is here. Incorporated by it is a PS-plug and four PS-sockets. This allows up to four things that have plugs to be plugged into the power board, whilst it itself can be plugged into something with a socket, such as the wall point. Note that when plugging, a specific plug and/or socket can be nominated. This is not permitted when unplugging, but more on this later. One point about multiple plugging: a thing cannot be plugged into something more than once. So, for example, if we have a cable defined thusly: A cable is here. Incorporated by it are two PS-plugs. we cannot "PLUG CABLE INTO THE POWER BOARD" twice. The first time is okay but the second will be rejected, even though we could, in the real world, plug a both ends of male-male power cable into a power board. Plugs and sockets have a text property called "PS-type". By default, the PS-type of sockets and plugs provided - PS-socket and PS-plug - is "standard". If you use these kinds only, then everything will work nicely as expected. However we may want to create plugs and sockets of different kinds. For example: An S-Video plug is a kind of PS-plug. The PS-type of an S-Video Plug is "S-Video". An S-Video socket is a kind of PS-socket. The PS-type of an S-Video Socket is "S-Video". An S-Video cable is here. Incorporated by it are two S-Video plugs. An amplifier is here. Incorporated by it is an S-Video socket. A DVD player is here. Incorporated by it is an S-Video socket. creates an S-Video cable that can connect between an amplifier and a DVD player. Plugs and sockets of differing types cannot be plugged into each other. It becomes more complex when considering some things may contain several different types of sockets. For example: An HDMI socket is a kind of PS-socket. The PS-type of an HDMI socket is "HDMI". An HDMI plug is a kind of PS-plug. The PS-type of an HDMI plug is "HDMI". An HMDI cable is here. Incorporated by it are two HDMI plugs. The amplifier incorporates an HDMI socket. The amplifier now has two different types of socket. This isn't so bad because if we try "PLUG HDMI CABLE INTO AMPLIFIER" the game will know, without ambiguity, which socket to use. Similarly, we could define an adapter cable that has a 3.5mm audio plug at one end and a pair of RC audio connectors at the other. If we attempted to plug this into something with only one type of socket (say an iPhone), it would automatically plug in the correct matching plug. Things can have any number of plugs and sockets of any type attached. It can become too complicated to figure out which cable end to plug into which socket. For example, if we had an adapter cable with an HDMI plug at one end and an S-Video plug at the other, we would have trouble with "PLUG CABLE INTO THE AMPLIFIER" (assuming the sockets of the amplifier were all free). This is because the code doesn't know which end to plug in - either would be valid. In this case, the solution is to name the plugs and/or the sockets. Then the player can specify which end is to be plugged into the amplifier. A complex cable is here. The description is "An HDMI to S-Video adapter cable (which is probably not possible!)". The HDMI end of the cable is an HDMI plug. It is part of the complex cable. The S-Video end of the cable is an S-Video plug. It is part of the complex cable. Now the player can type "PLUG THE HDMI END OF THE CABLE INTO THE AMPLIFIER" which will work as expected. Or even "PLUG THE HDMI END OF THE CABLE INTO THE HDMI-IN SOCKET" (if the sockets were appropriately named) would work if you wanted to be more specific still. Similarly, "UNPLUG CABLE FROM THE AMPLIFIER" performs as expected. If the cable is only plugged into the amplifier, just "UNPLUG CABLE" would be sufficient. The synonyms "INSERT" and "ATTACH" work for "PLUG", likewise "DETACH" and "REMOVE" work for "UNPLUG". Note these synonyms work when the attempt is made for plugs or sockets or things containing plugs or sockets. Otherwise the existing behaviour for the synonym (if it exists) will take place. For example, if "ATTACH" is attempted for a non-plug or something not containing a plug, the command will revert to being understood as "TIE". All of this behaviour can be changed with appropriate manipulation of the listed rules. The extension does support plural items with appropriate messages. So "PLUG TV INTO SOME BANANAS" will give the message "The bananas have no socket" rather than "The bananas has no socket". The extension also supports actors other than the player. For example, "GEORGE, PLUG THE CORD INTO THE POWER POINT" will work correctly (as long as George is willing). There are currently three major limitations to the extension: 1) You cannot plug an item into another item multiple times. There is a rule which explicitly forbids it (although it could be delisted). It creates problems with listing attachments and ambiguity and wasn't really necessary. 2) You cannot name a plug or socket when unplugging. Once again, it would have added complexity and I didn't believe it is needed. 3) Plugs and sockets has not been tested for multi-layered situations. That is, a plug or socket must be a part of a parent object, not a part of a part. For example, lets say we have an "entertainment system" which has a "DVD player" as a part. The "DVD player" could then have a plug as a part of it. However this may cause problems when trying to "PLUG" it into things. One final point: a value called PS-leaving can be either PS-denied or PS-allowed. It is PS-denied by default. When it is PS-denied and the player attempts to leave a location whilst carrying something attached to something not carried, a message will be displayed and the action prevented. If this variable is set to PS-allowed, the action will be okay but all the relevant connections for those things carried will be broken. Example: ** Home Theatre - Plugging a variety of components with different connections together to watch a DVD. *: "Home Theatre" by Sean Turner Include Plugs and Sockets by Sean Turner Section 1 - New plug and socket kinds An HDMI-plug is a kind of PS-plug. The PS-type of an HDMI-plug is "HDMI". An HDMI-socket is a kind of PS-socket. The PS-type of an HDMI-socket is "HDMI". A DVI-plug is a kind of PS-plug. The PS-type of a DVI-plug is "DVI". A DVI-socket is a kind of PS-socket. The PS-type of a DVI-socket is "DVI". A power-plug is a kind of PS-plug. The PS-type of a power-plug is "power". A power-plug has a truth state called searched state. The searched state of a power-plug is usually false. A power-socket is a kind of PS-socket. The PS-type of a power-socket is "power". A double-adapter is a kind of thing. Every double-adapter incorporates a power-plug and two power-sockets. A hifi-gadget is a kind of thing. Every hifi-gadget incorporates a power-plug. Section 2 - A few decisions To decide if the (test-item - a thing) is powered: repeat with item running through the power-plugs: now the searched state of the item is false; let forever be true; while forever is true: if the test-item is the power point: decide yes; let test-plug be a random power-plug which is part of the test-item; if the test-plug is nothing, or the attachment of the test-plug is nothing: decide no; else: if the searched state of the test-plug is true: decide no; now the searched state of the test-plug is true; now the test-item is the holder of the attachment of the test-plug. To decide if the audio is connected: if the HDMI cable is inserted into the receiver, and the HDMI cable is inserted into the DVD player, and the holder of the attachment of the HDMI-IN socket is HDMI cable: decide on true; decide on false. To decide if the video is connected: if the video converter is inserted into the TV, and the video converter is inserted into the receiver, and the attachment of the HDMI-OUT socket is the green plug: decide on true; decide on false. Section 3 - Scenario The Home Theatre is a room. "This softly lit and richly carpeted homage to 1970's decor is the perfect place to relax and watch a movie. A store room is to the south." A big screen TV is a hifi-gadget. It is here. "A huge 150cm Plasma TV dominates the north wall.". It is fixed in place. The description is "Tastelessly huge. The TV is [if the TV is powered]on although nothing is showing.[else]off.". Incorporated by it is a DVI-socket. A power point is here. It is fixed in place. "Unfortunately the room has only one single power point tucked away in the corner farthest from the TV." Incorporated by it is a power-socket. Check plugging a PS-inserter into the power point (this is the power-point-too-far rule): if the noun is fixed in place, say "The plug of [the noun] will not reach to [the power point]." instead; if the noun is not the extension cord, say "It would be useless to plug [the noun] into [the power point] when it is so far from the TV." instead. The power-point-too-far rule is listed last in the check plugging it into rulebook. A Blu-ray DVD player is a hifi-gadget. It is here. The description is "A state of the art DVD player. In the player is a movie waiting to be watched. The DVD player is [if the DVD is powered]on and the movie is playing.[else]off." Incorporated by it is an HDMI-socket. A digital receiver is a hifi-gadget. It is here. It is fixed in place. The description is "A complex switching mechanism routing various audio visual inputs to the TV and speakers. The speakers are hard-wired into the back of the receiver. On the back of the receiver are two HDMI sockets labeled HDMI-IN and HDMI-OUT. The receiver is [if the receiver is powered]on and hums slightly.[else]off.". Incorporated by the receiver is an HDMI-socket called the HDMI-OUT socket. Incorporated by the receiver is an HDMI-socket called the HDMI-IN socket. Some speakers are scenery. They are here. The Store room is south of the Home Theatre. An extension cord is here. The description is "5 metres of sturdy electrical cord.". The indefinite article is "an". Incorporated by it is a power-plug and a power-socket. A video converter cable is here. The description is "It converts from an HDMI source to a DVI destination - useful when only the video component of the signal is required. The male DVI plug is red and the male HDMI plug is green.". Incorporated by the cable is a DVI-plug called the red plug. Incorporated by the cable is an HDMI-plug called the green plug. An HDMI cable is here. Incorporated by it are two HDMI-plugs. The indefinite article is "an". The description is "Connects two HDMI devices for video and sound. The two male connectors are indistinguishable.". A cream double adapter is a double-adapter. It is here. A white double adapter is a double-adapter. It is here. Section 4 - Victory condition Every turn: let power flowing be true; repeat with item running through hifi-gadgets: unless the item is powered: now power flowing is false; if power flowing is true, and the audio is connected, and the video is connected: say "Ahh. Now you can relax and watch the movie."; end the story saying "You have won."; else: if the receiver is powered, and the DVD is powered, and the audio is connected: say "You can hear the movie but you can't see any picture!". Section 5 - Testing test me with "s/get all/n/plug tv into white/plug dvd into white/plug white into cream/plug receiver into cream/plug cream into cord/plug cord into point/plug hdmi into receiver/plug hdmi into dvd/plug video into receiver/x green/x red/plug video into tv/unplug video from receiver/unplug hdmi from receiver/plug hdmi into hdmi-in/plug video into hdmi-out". test errors with "plug tv into point/plug tv into receiver/s/get all/n/plug cord into point/s/plug hdmi into cream/unplug cord from point/plug cord into cord/unplug cord/plug tv into white/plug receiver into white/ plug cream into white/unplug tv/plug red plug into receiver/plug green plug into receiver/plug video cable into tv".