The %attacker% approach can be extended to include some information other than just the names of the objects:
- The verb may be singular or plural. This depends on the subject. "You attack X" (singular 2nd person subject) vs. "Extrakun attacks X" (singular 3rd person subject) vs. "The goblins attack X" (plural 3rd person subject). Most verbs just need an
-s
added but there are a few exceptions.
- The noun may be a proper noun ("Goblin attacks X") or a common noun ("A goblin attacks X"). Common nouns starting with a vowel sound should use "an" instead of "a". It may be a common noun but having only one instance in the current context ("The goblin attacks X").
- The noun may vary in number, from zero ("You hit no goblins") to one ("You hit one goblin") to many ("You hit three goblins"). Many nouns just need an
-s
or -es
added but there are many exceptions.
- Subjects and objects may be simple ("A goblin") or compound ("A goblin and her brother").
- Common nouns at the beginning of the sentence need to be capitalized, but if the noun has an article or if it's compound you want to only capitalize the first word. Proper nouns are always capitalized.
- The subject position ("She hit the goblin") and object position ("The goblin hit her") use different pronouns.
- Possessives can be generated by adding
's
if singular ("A goblin's axe"), '
if plural ("Two goblins' axes"), but pronouns have their own rules ("Your axe").
For English, I wrote Python a text generation library derived from a MUD called JaysHouseMOO. Feel free to study or copy the code. It doesn't have a good library of exceptional cases; you'll have to add that with the words used in your game. I'm afraid my ported code isn't extensively tested. It might also need more cases added for games (it was designed for a social MUD, not a gaming MUD).
Your example would be written as "%1I %1:(inflicts) a serious wound (%2n damage) on %3i"
. The numbers %1
, %2
, %3
tell it which object is to be substituted; I
/i
tell it to add an indirect article ("a", "an") if needed; n
tells it to display the noun without articles; :(inflicts)
tells it to conjugate the verb for that object.
Here's the output to show to the attacker, the defender, and to everyone else:
$ python
>>> import msg
>>> m = "%1I %1:(inflicts) a serious wound (%2n damage) on %3i."
>>> attacker = msg.GenderedObject('Amit', 'm', 'proper')
>>> defender = msg.GenderedObject('goblin', 'm', 'unique')
>>> points = (12, 'point')
>>> msg.Msg().sub_parties({1: attacker, 2: points, 3: defender},
m, [attacker, defender])
(['You inflict a serious wound (12 points damage) on the goblin.',
'Amit inflicts a serious wound (12 points damage) on you.'],
'Amit inflicts a serious wound (12 points damage) on the goblin.')
Note if you had given it (1, 'point')
it would have printed "1 point" instead of "1 points". That's something that bugs me in game text, so I made sure to include a feature to make it easy to print that properly.
Here's another example, with compound nouns, and "a" vs. "an":
>>> m = "%1I %1:(hits) %2'n %2'(head)."
>>> a1 = msg.GenderedObject('goblin', 'm', 'normal')
>>> a2 = msg.GenderedObject('orc', 'm', 'normal')
>>> d1 = msg.GenderedObject('Amit', 'm', 'proper')
>>> d2 = msg.GenderedObject('Extrakun', 'm', 'proper')
>>> msg.Msg().sub_parties({1: [a1, a2], 2: [d1, d2]}, m, [d1, d2])
(["A goblin and an orc hit your and Extrakun's heads.",
"A goblin and an orc hit Amit's and your heads."],
"A goblin and an orc hit Amit's and Extrakun's heads.")
These examples are in English, and only track male/female, pronouns, singular/plural verbs/nouns, and proper/common nouns. What you need to track will vary across languages and the type of text in your game. In Spanish there are formal and informal pronouns. Several languages have masculine and feminine forms of verbs. Japanese pronouns depend on the status of the subject relative to the object. In some languages the verb conjugation can implicitly include the subject. Determine all the kinds of text you want to generate and the languages you want to translate to, and that'll tell you what you need to track in your game objects. When you're creating the content, you can include the necessary annotations and exceptional cases.