MESSAGE management
==================

BabbleMUD server.

Author:  Nick Gammon 
          http://www.gammon.com.au/ 

Written: 18th August 2004.

(C) Copyright Nick Gammon 2004. Permission to copy, use, modify, sell and
distribute this document is granted provided this copyright notice appears
in all copies. 


Introduction
------------

In any non-trivial MUD server you will confront the problems of sending messages to players. These problem have four main parts:

1. Putting them into a file for easy modification

2. Substituting words

3. Supporting different languages (eg. English, French, Italian)

4. Grammar issues


(Plus, colour replacement which is covered in a separate document).


Putting messages into files
---------------------------

There is a lot to be said for maintaining messages in separate files (rather than the C++ source code of the server). It seems ridiculous to have to recompile the server just to fix a spelling mistake, and not every MUD administrator is familiar with C++ coding.


Substituting words
------------------

Once you put messages into a file, the issue arises about "variable" words, for example:

  "Nick gives his sword to David."

Now as any player might type that, the message in the file really needs to be something like:

  "[player] gives his [what] to [target]."

Then, the program will set up list of substitution words, and pass the whole thing to a substitution routine. eg.

player = Nick
what = sword
target = David


Supporting different languages
------------------------------

It would be nice to be able to either simply translate the whole MUD into a different language (eg. Italian) or, more complexly, support multiple languages.

The BabbleMUD server asks new players which language they wish to use, and then chooses the appropriate message from language-dependent sets of messages. eg.

  English: "Nick gives his sword to David."
  French: "Nick donne son pe  David."
  Italian: "Nick d la sua spada a David."


Grammar issues
--------------

Finally even a simple sentence like the above will vary even more depending on the gender of the enactor and target. For example:

  "Margaret gives her sword to David."

Then there are other issues like "a bucket" "an apple", "some apples", and so on.


BabbleMUD implementation
------------------------

When sending text to a player you have various ways of doing it:

1. Straight send: eg. player.send ("Hi there");

This should be used sparingly as the message is hard-coded, and will not be translated into different languages.
It is really provided for use in case you had already looked up a message in the messagemap, and didn't need to lookup it up again.

2. Send a message code: eg. player.send ("no_inventory", messagemap ());

This form looks up "no_inventory" in "messagemap ()" and finds the matching message. It also prepends the player's language code to find the correct transation (eg. it actually would look for "en_no_inventory" [English], "fr_no_inventory" [French], "it_no_inventory" [Italian] and so on).

This is the preferred way of sending messages. For one thing, they are looked up in an external file, and for another thing, the support different languages.

3. Send a message with substitutions, eg.

  ThingMap subs;
  subs ["player"].sets ("short", "Nick");
  subs ["direction"].sets ("short", "South");
  
  player.send ("%<player> goes %<direction>", subs);
  
This uses the "map of things" [subs], to replace each special word in the message. It can also consult the map to find out the gender of each item if required for the message grammar.

This should also be used sparingly as the message is hard-coded, and will not be translated into different languages.
It is really provided for use in case you had already looked up a message in the messagemap, and didn't need to lookup it up again.

4. Send a message code with substitutions, eg.

  ThingMap subs;
  subs ["player"].sets ("short", "Nick");
  subs ["direction"].sets ("short", "South");
  
  player.send ("player_moves", messagemap (), subs);
  
First, this looks up the message "player_moves" in messagemap (), and then uses the "map of things" [subs], to replace each special word in the message. It can also consult the map to find out the gender of each item if required for the message grammar.

