| 1 |
/* Copyright 2000, 2002 Michael J. Roberts */ |
| 2 |
/* |
| 3 |
* TADS 3 library - English language module |
| 4 |
* |
| 5 |
* The library attempts to isolate everything related to producing |
| 6 |
* messages in English to this module. When translating the library to |
| 7 |
* a non-English language, this module must be replaced with an |
| 8 |
* appropriate implementation for the alternative language. It is the |
| 9 |
* intention of the library's designers that the library can be |
| 10 |
* translated by replacing this module, without changing any of the |
| 11 |
* other portions of the library. |
| 12 |
*/ |
| 13 |
|
| 14 |
#include "adv3.h" |
| 15 |
|
| 16 |
|
| 17 |
/* ------------------------------------------------------------------------ */ |
| 18 |
/* |
| 19 |
* Language-specific globals |
| 20 |
*/ |
| 21 |
languageGlobals: object |
| 22 |
/* |
| 23 |
* The character to use to separate groups of digits in large |
| 24 |
* numbers. US English uses commas; most Europeans use periods. |
| 25 |
* |
| 26 |
* Note that this setting does not affect system-level BigNumber |
| 27 |
* formatting, but this information can be passed when calling |
| 28 |
* BigNumber formatting routines. |
| 29 |
*/ |
| 30 |
digitGroupSeparator = ',' |
| 31 |
|
| 32 |
/* |
| 33 |
* The decimal point to display in floating-point numbers. US |
| 34 |
* English uses a period; most Europeans use a comma. |
| 35 |
* |
| 36 |
* Note that this setting doesn't affect system-level BigNumber |
| 37 |
* formatting, but this information can be passed when calling |
| 38 |
* BigNumber formatting routines. |
| 39 |
*/ |
| 40 |
decimalPointCharacter = '.' |
| 41 |
; |
| 42 |
|
| 43 |
|
| 44 |
/* ------------------------------------------------------------------------ */ |
| 45 |
/* |
| 46 |
* Language-specific base class for Thing. This class contains the |
| 47 |
* methods and properties of Thing that need to be replaced when the |
| 48 |
* library is translated to another language. |
| 49 |
* |
| 50 |
* The properties and methods defined here should generally never be |
| 51 |
* used by language-independent library code, because everything defined |
| 52 |
* here is specific to English. Translators are thus free to change the |
| 53 |
* entire scheme defined here. |
| 54 |
*/ |
| 55 |
class LangThing: object |
| 56 |
/* |
| 57 |
* Flag that this object's name is rendered as a plural (this |
| 58 |
* applies to both a singular noun with plural usage, such as |
| 59 |
* "pants," and an object used to represent a collection of physical |
| 60 |
* objects, such as "shrubs"). |
| 61 |
*/ |
| 62 |
isPlural = nil |
| 63 |
|
| 64 |
/* |
| 65 |
* The short description string. Each instance should override this |
| 66 |
* to define the name of the object. This string should not contain |
| 67 |
* any articles; we use this string as the root to generate various |
| 68 |
* forms of the object's name for use in different places in |
| 69 |
* sentences. |
| 70 |
*/ |
| 71 |
sDescStr = '' |
| 72 |
|
| 73 |
/* |
| 74 |
* Display the short description. By default, we'll simply display |
| 75 |
* the short-description-string property, sDescStr. |
| 76 |
*/ |
| 77 |
sDesc { "<<sDescStr>>"; } |
| 78 |
|
| 79 |
/* |
| 80 |
* Display a count of the object ("five coins"). 'info' is a |
| 81 |
* SenseInfoListEntry giving the sense conditions under which the |
| 82 |
* object is being described. |
| 83 |
*/ |
| 84 |
countDesc(count) |
| 85 |
{ |
| 86 |
/* |
| 87 |
* display the number followed by a space - spell out numbers |
| 88 |
* below 100, but use numerals to denote larger numbers |
| 89 |
*/ |
| 90 |
"<<spellIntBelowExt(count, 100, 0, INTDEC_GROUP_SEP)>> "; |
| 91 |
|
| 92 |
/* add the plural name */ |
| 93 |
pluralDesc; |
| 94 |
} |
| 95 |
|
| 96 |
/* display a pronoun for the object in the nominitive/object case */ |
| 97 |
itDescNom { if (isPlural) "they"; else "it"; } |
| 98 |
itDescObj { if (isPlural) "them"; else "it"; } |
| 99 |
|
| 100 |
/* display the name with a definite article ("the box") */ |
| 101 |
theDesc { "the <<sDescStr>>"; } |
| 102 |
|
| 103 |
/* display my name and a being verb ("the box is") */ |
| 104 |
nameIsDesc { "<<theDesc>> <<isPlural ? 'are' : 'is'>>"; } |
| 105 |
|
| 106 |
/* |
| 107 |
* the indefinite article to use; if this is nil, we'll try to |
| 108 |
* figure it out by looking at the sDescStr |
| 109 |
*/ |
| 110 |
articleIndef = nil |
| 111 |
|
| 112 |
/* |
| 113 |
* Display the name with an indefinite article ("a box"). If an |
| 114 |
* 'articleIndef' property is defined to non-nil, we'll display that |
| 115 |
* article; otherwise, we'll try to figure it out by looking at the |
| 116 |
* sDescStr property. |
| 117 |
* |
| 118 |
* By default, we'll use the article "a" if the sDescStr starts with |
| 119 |
* a consonant, or "an" if it starts with a vowel. |
| 120 |
* |
| 121 |
* If the sDescStr starts with a "y", we'll look at the second |
| 122 |
* letter; if it's a consonant, we'll use "an", otherwise "a" (hence |
| 123 |
* "an yttrium block" but "a yellow brick"). |
| 124 |
* |
| 125 |
* If the object is marked as having plural usage, we will use |
| 126 |
* "some" as the article ("some pants" or "some shrubs"). |
| 127 |
* |
| 128 |
* Some objects will want to override the default behavior, because |
| 129 |
* the lexical rules about when to use "a" and "an" are not without |
| 130 |
* exception. For example, silent-"h" words ("honor") are written |
| 131 |
* with "an", and "h" words with a pronounced but weakly stressed |
| 132 |
* initial "h" are sometimes used with "an" ("an historian"). Also, |
| 133 |
* some 'y' words might not follow the generic 'y' rule. |
| 134 |
* |
| 135 |
* 'U' words are especially likely not to follow any lexical rule - |
| 136 |
* any 'u' word that sounds like it starts with 'y' should use 'a' |
| 137 |
* rather than 'an', but there's no good way to figure that out just |
| 138 |
* looking at the spelling (consider "a universal symbol" and "an |
| 139 |
* unimportant word", or "a unanimous decision" and "an unassuming |
| 140 |
* man"). We simply always use 'an' for a word starting with 'u', |
| 141 |
* but this will have to be overridden when the 'u' sounds like 'y'. |
| 142 |
* |
| 143 |
* Note that this routine can be overridden entirely, but in most |
| 144 |
* cases, an object can simply override the 'article' property to |
| 145 |
* specify the article to use. |
| 146 |
*/ |
| 147 |
aDesc |
| 148 |
{ |
| 149 |
/* |
| 150 |
* The complete list of unaccented, accented, and ligaturized |
| 151 |
* Latin vowels from the Unicode character set. (The Unicode |
| 152 |
* database doesn't classify characters as vowels or the like, |
| 153 |
* so it seems the only way we can come up with this list is |
| 154 |
* simply to enumerate the vowels.) |
| 155 |
* |
| 156 |
* These are all lower-case letters; all of these are either |
| 157 |
* exclusively lower-case or have upper-case equivalents that |
| 158 |
* map to these lower-case letters. |
| 159 |
* |
| 160 |
* (Note an implementation detail: the compiler will append all |
| 161 |
* of these strings together at compile time, so we don't have |
| 162 |
* to perform all of this concatenation work each time we |
| 163 |
* execute this method.) |
| 164 |
*/ |
| 165 |
local vowels = 'aeiou\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6' |
| 166 |
+ '\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF' |
| 167 |
+ '\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8\u00F9\u00FA' |
| 168 |
+ '\u00FB\u00FC\u0101\u0103\u0105\u0113\u0115\u0117' |
| 169 |
+ '\u0119\u011B\u0129\u012B\u012D\u012F\u014D\u014F' |
| 170 |
+ '\u0151\u0169\u016B\u016D\u016F\u0171\u0173\u01A1' |
| 171 |
+ '\u01A3\u01B0\u01CE\u01D0\u01D2\u01D4\u01D6\u01D8' |
| 172 |
+ '\u01DA\u01DC\u01DF\u01E1\u01E3\u01EB\u01ED\u01FB' |
| 173 |
+ '\u01FD\u01FF\u0201\u0203\u0205\u0207\u0209\u020B' |
| 174 |
+ '\u020D\u020F\u0215\u0217\u0254\u025B\u0268\u0289' |
| 175 |
+ '\u1E01\u1E15\u1E17\u1E19\u1E1B\u1E1D\u1E2D\u1E2F' |
| 176 |
+ '\u1E4D\u1E4F\u1E51\u1E53\u1E73\u1E75\u1E77\u1E79' |
| 177 |
+ '\u1E7B\u1E9A\u1EA1\u1EA3\u1EA5\u1EA7\u1EA9\u1EAB' |
| 178 |
+ '\u1EAD\u1EAF\u1EB1\u1EB3\u1EB5\u1EB7\u1EB9\u1EBB' |
| 179 |
+ '\u1EBD\u1EBF\u1EC1\u1EC3\u1EC5\u1EC7\u1EC9\u1ECB' |
| 180 |
+ '\u1ECD\u1ECF\u1ED1\u1ED3\u1ED5\u1ED7\u1ED9\u1EDB' |
| 181 |
+ '\u1EDD\u1EDF\u1EE1\u1EE3\u1EE5\u1EE7\u1EE9\u1EEB' |
| 182 |
+ '\u1EED\u1EEF\u1EF1\uFF41\uFF4F\uFF55'; |
| 183 |
|
| 184 |
/* |
| 185 |
* A few upper-case vowels in unicode don't have lower-case |
| 186 |
* mappings - consider them separately. |
| 187 |
*/ |
| 188 |
local vowelsUpperOnly = '\u0130\u019f'; |
| 189 |
|
| 190 |
/* |
| 191 |
* the various accented forms of the letter 'y' - these are all |
| 192 |
* lower-case versions; the upper-case versions all map to these |
| 193 |
*/ |
| 194 |
local ys = 'y\u00FD\u00FF\u0177\u01B4\u1E8F\u1E99\u1EF3' |
| 195 |
+ '\u1EF5\u1EF7\u1EF9\u24B4\uFF59'; |
| 196 |
|
| 197 |
/* if there's an explicit indefinite article, use it */ |
| 198 |
if (articleIndef != nil) |
| 199 |
{ |
| 200 |
"<<articleIndef>> <<sDescStr>>"; |
| 201 |
return; |
| 202 |
} |
| 203 |
|
| 204 |
/* check for the plural */ |
| 205 |
if (isPlural) |
| 206 |
{ |
| 207 |
/* it's a plural - always use 'some' as the article */ |
| 208 |
"some <<sDescStr>>"; |
| 209 |
} |
| 210 |
else |
| 211 |
{ |
| 212 |
local firstChar; |
| 213 |
local firstCharLower; |
| 214 |
|
| 215 |
/* if it's empty, just display "a" */ |
| 216 |
if (sDescStr == '') |
| 217 |
{ |
| 218 |
"a"; |
| 219 |
return; |
| 220 |
} |
| 221 |
|
| 222 |
/* get the first character of the name */ |
| 223 |
firstChar = sDescStr.substr(1, 1); |
| 224 |
firstCharLower = firstChar.toLower(); |
| 225 |
|
| 226 |
/* |
| 227 |
* look for it in the lower-case and upper-case-only vowel |
| 228 |
* lists |
| 229 |
*/ |
| 230 |
if (vowels.find(firstCharLower) != nil |
| 231 |
|| vowelsUpperOnly.find(firstChar) != nil) |
| 232 |
{ |
| 233 |
/* it starts with a vowel */ |
| 234 |
"an <<sDescStr>>"; |
| 235 |
} |
| 236 |
else if (ys.find(firstCharLower) != nil) |
| 237 |
{ |
| 238 |
local secondChar; |
| 239 |
|
| 240 |
/* get the second character, if there is one */ |
| 241 |
secondChar = sDescStr.substr(2, 1); |
| 242 |
|
| 243 |
/* |
| 244 |
* It starts with 'y' - if the second letter is a |
| 245 |
* consonant, assume the 'y' is a vowel sound, hence we |
| 246 |
* should use 'an'; otherwise assume the 'y' is a |
| 247 |
* dipthong 'ei' sound, which means we should use 'a'. |
| 248 |
* If there's no second character at all, or the second |
| 249 |
* character isn't alphabetic, use 'a' - "a Y" or "a |
| 250 |
* Y-connector". |
| 251 |
*/ |
| 252 |
if (secondChar == '' |
| 253 |
|| rexMatch('<alpha>', secondChar) == nil |
| 254 |
|| vowels.find(secondChar.toLower()) != nil |
| 255 |
|| vowelsUpperOnly.find(secondChar) != nil) |
| 256 |
{ |
| 257 |
/* |
| 258 |
* it's just one character, or the second character |
| 259 |
* is non-alphabetic, or the second character is a |
| 260 |
* vowel - in any of these cases, use 'a' |
| 261 |
*/ |
| 262 |
"a <<sDescStr>>"; |
| 263 |
} |
| 264 |
else |
| 265 |
{ |
| 266 |
/* the second character is a consonant - use 'an' */ |
| 267 |
"an <<sDescStr>>"; |
| 268 |
} |
| 269 |
} |
| 270 |
else |
| 271 |
{ |
| 272 |
/* it starts with a consonant */ |
| 273 |
"a <<sDescStr>>"; |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
/* |
| 279 |
* Display a default plural description. If the short description |
| 280 |
* name ends in anything other than 'y', we'll add an 's'; otherwise |
| 281 |
* we'll replace the 'y' with 'ies'. Some objects will have to |
| 282 |
* override this to deal with irregular plurals ('child' -> |
| 283 |
* 'children' and the like). |
| 284 |
*/ |
| 285 |
pluralDesc |
| 286 |
{ |
| 287 |
local len; |
| 288 |
local lastChar; |
| 289 |
|
| 290 |
/* if there's no short description, display nothing */ |
| 291 |
len = sDescStr.length(); |
| 292 |
if (len == 0) |
| 293 |
return; |
| 294 |
|
| 295 |
/* if it's only one letter long, add an apostrophe-s */ |
| 296 |
if (len == 1) |
| 297 |
{ |
| 298 |
"<<sDescStr>>'s"; |
| 299 |
return; |
| 300 |
} |
| 301 |
|
| 302 |
/* get the last character of the name */ |
| 303 |
lastChar = sDescStr.substr(len, 1); |
| 304 |
|
| 305 |
/* |
| 306 |
* if the last letter is a capital letter, it must be an |
| 307 |
* abbreviation of some kind; add an apostrophe-s |
| 308 |
*/ |
| 309 |
if (rexMatch('<upper>', lastChar) != nil) |
| 310 |
{ |
| 311 |
"<<sDescStr>>'s"; |
| 312 |
return; |
| 313 |
} |
| 314 |
|
| 315 |
/* if it ends with 'y', the plural is made with '-ies' */ |
| 316 |
if (lastChar == 'y') |
| 317 |
{ |
| 318 |
"<<sDescStr.substr(1, len - 1)>>ies"; |
| 319 |
return; |
| 320 |
} |
| 321 |
|
| 322 |
/* for anything else, just add 's' */ |
| 323 |
"<<sDescStr>>s"; |
| 324 |
} |
| 325 |
|
| 326 |
/* |
| 327 |
* Show this item as part of a list. 'options' is a combination of |
| 328 |
* LIST_xxx flags indicating the type of listing. 'senseInfo' is a |
| 329 |
* SenseInfoListEntry object giving the sense information applying |
| 330 |
* to this object for the purposes of the listing. |
| 331 |
*/ |
| 332 |
showListItem(options, pov, senseInfo) |
| 333 |
{ |
| 334 |
/* use the appropriate display function, based on the options */ |
| 335 |
if ((options & LIST_GROUP) != 0) |
| 336 |
groupListDesc(options, pov, senseInfo); |
| 337 |
else |
| 338 |
listDesc(options, pov, senseInfo); |
| 339 |
} |
| 340 |
|
| 341 |
/* |
| 342 |
* Show this item as part of a list, grouped with a count of |
| 343 |
* list-equivalent items. |
| 344 |
*/ |
| 345 |
showListItemCounted(equivCount, options, pov, senseInfo) |
| 346 |
{ |
| 347 |
/* use the appropriate display function, based on the options */ |
| 348 |
if ((options & LIST_GROUP) != 0) |
| 349 |
groupCountListDesc(equivCount, options, pov, senseInfo); |
| 350 |
else |
| 351 |
countListDesc(equivCount, options, pov, senseInfo); |
| 352 |
} |
| 353 |
|
| 354 |
/* |
| 355 |
* Single-item listing description. This is used to display the |
| 356 |
* item when it appears as a single (non-grouped) item in a list. |
| 357 |
* By default, we just show the indefinite article description. |
| 358 |
*/ |
| 359 |
listDesc(options, pov, senseInfo) |
| 360 |
{ |
| 361 |
withVisualSenseInfo(pov, senseInfo, &aDesc); |
| 362 |
} |
| 363 |
|
| 364 |
/* |
| 365 |
* Single-item counted listing description. This is used to display |
| 366 |
* an item with a count of equivalent items ("four gold coins"). |
| 367 |
*/ |
| 368 |
countListDesc(equivCount, options, pov, senseInfo) |
| 369 |
{ |
| 370 |
withVisualSenseInfo(pov, senseInfo, &countDesc, equivCount); |
| 371 |
} |
| 372 |
|
| 373 |
/* |
| 374 |
* Group listing description. This is used to list an item as part |
| 375 |
* of its listing group. By default, we just show the indefinite |
| 376 |
* article description. |
| 377 |
*/ |
| 378 |
groupListDesc(options, pov, senseInfo) |
| 379 |
{ |
| 380 |
withVisualSenseInfo(pov, senseInfo, &aDesc); |
| 381 |
} |
| 382 |
|
| 383 |
/* |
| 384 |
* Group counted description. This is used to display the item in a |
| 385 |
* list when it's grouped and a number of equivalent items appear in |
| 386 |
* the group. |
| 387 |
* |
| 388 |
* For example: in "$1.53 in coins (six quarters and three |
| 389 |
* pennies)", this routine is used to display the "six quarters" |
| 390 |
* part. |
| 391 |
*/ |
| 392 |
groupCountListDesc(equivCount, options, pov, senseInfo) |
| 393 |
{ |
| 394 |
countListDesc(equivCount, options, pov, senseInfo); |
| 395 |
} |
| 396 |
; |
| 397 |
|
| 398 |
|
| 399 |
/* ------------------------------------------------------------------------ */ |
| 400 |
/* |
| 401 |
* Library Messages |
| 402 |
*/ |
| 403 |
libMessages: object |
| 404 |
/* generic short description of a dark room */ |
| 405 |
roomDarkSDesc = "In the dark" |
| 406 |
|
| 407 |
/* generic long description of a dark room */ |
| 408 |
roomDarkLDesc = "It's pitch black. " |
| 409 |
|
| 410 |
/* generic long description of a Thing */ |
| 411 |
thingLDesc(obj) { "You see nothing unusual about <<obj.itDescObj>>. "; } |
| 412 |
|
| 413 |
/* |
| 414 |
* the object used to construct the sentence desribing the listing |
| 415 |
* of a room's contents |
| 416 |
*/ |
| 417 |
roomLister = libRoomLister |
| 418 |
|
| 419 |
/* |
| 420 |
* the object used to construct the sentence describing a dark |
| 421 |
* room's contents |
| 422 |
*/ |
| 423 |
darkRoomLister = libDarkRoomLister |
| 424 |
|
| 425 |
/* the object used to list the inventory for the player charater */ |
| 426 |
playerInventoryLister = stdPlayerInventoryLister |
| 427 |
|
| 428 |
/* the object used to list items being worn by the player character */ |
| 429 |
playerWearingLister = stdPlayerWearingLister |
| 430 |
|
| 431 |
/* the list separator character in the middle of a list */ |
| 432 |
listSepMiddle = ", " |
| 433 |
|
| 434 |
/* the list separator character for a two-element list */ |
| 435 |
listSepTwo = " and " |
| 436 |
|
| 437 |
/* the list separator for the end of a list of at least three elements */ |
| 438 |
listSepEnd = ", and " |
| 439 |
|
| 440 |
/* |
| 441 |
* the list separator for the middle of a long list (a list with |
| 442 |
* embedded lists not otherwise set off, such as by parentheses) |
| 443 |
*/ |
| 444 |
longListSepMiddle = "; " |
| 445 |
|
| 446 |
/* the list separator for a two-element list of sublists */ |
| 447 |
longListSepTwo = ", and " |
| 448 |
|
| 449 |
/* the list separator for the end of a long list */ |
| 450 |
longListSepEnd = "; and " |
| 451 |
|
| 452 |
/* the status message for a LightSource that's currently turned on */ |
| 453 |
providingLightDesc = " (providing light)" |
| 454 |
|
| 455 |
/* the status message for a Wearable that's currently being worn */ |
| 456 |
wornDesc = " (being worn)" |
| 457 |
|
| 458 |
/* |
| 459 |
* the status message for an object that's both providing light and |
| 460 |
* being worn |
| 461 |
*/ |
| 462 |
providingLightWornDesc = " (providing light and being worn)" |
| 463 |
|
| 464 |
/* |
| 465 |
* Score ranking list. Games will almost always want to override |
| 466 |
* this with a customized list. For each entry in the list, the |
| 467 |
* first element is the minimum score for the rank, and the second |
| 468 |
* is a string describing the rank. The ranks should be given in |
| 469 |
* ascending order, since we simply search the list for the first |
| 470 |
* item whose minimum score is greater than our score, and use the |
| 471 |
* preceding item. |
| 472 |
* |
| 473 |
* If this is set to nil, which it is by default, we'll simply skip |
| 474 |
* score ranks entirely. |
| 475 |
*/ |
| 476 |
scoreRankTable = nil |
| 477 |
|
| 478 |
/* show the full message for a given score rank string */ |
| 479 |
showScoreRankMessage(msg) |
| 480 |
{ |
| 481 |
"This makes you <<msg>>. "; |
| 482 |
} |
| 483 |
|
| 484 |
/* show the basic score message */ |
| 485 |
showScoreMessage(points, maxPoints, turns) |
| 486 |
{ |
| 487 |
"Your score is <<points>> of a possible <<maxPoints>>, |
| 488 |
in <<libGlobal.totalTurns>> moves. "; |
| 489 |
} |
| 490 |
|
| 491 |
/* |
| 492 |
* show the list prefix for the full score listing; this is shown on |
| 493 |
* a line by itself before the list of full score items, shown |
| 494 |
* indented and one item per line |
| 495 |
*/ |
| 496 |
showFullScorePrefix = "You scored:" |
| 497 |
|
| 498 |
/* |
| 499 |
* show the item prefix, with the number of points, for a full score |
| 500 |
* item - immediately after this is displayed, we'll display the |
| 501 |
* description message for the achievement |
| 502 |
*/ |
| 503 |
fullScoreItemPoints(points) |
| 504 |
{ |
| 505 |
"\t<<points>> point<<points == 1 ? '' : 's'>> for "; |
| 506 |
} |
| 507 |
|
| 508 |
/* show the response to an empty command line */ |
| 509 |
emptyCommandResponse() { "I beg your pardon?"; } |
| 510 |
; |
| 511 |
|
| 512 |
/* |
| 513 |
* Plain lister - this lister doesn't show anything for an empty list, |
| 514 |
* and doesn't show a list suffix or prefix. |
| 515 |
*/ |
| 516 |
plainLister: ShowListInterface |
| 517 |
/* show the prefix/suffix in wide mode */ |
| 518 |
showListPrefixWide(itemCount, pov, parent) { } |
| 519 |
showListSuffixWide(itemCount, pov, parent) { } |
| 520 |
|
| 521 |
/* show the tall prefix */ |
| 522 |
showListPrefixTall(itemCount, pov, parent) { } |
| 523 |
|
| 524 |
/* show an empty list */ |
| 525 |
showListEmpty(pov, parent) { } |
| 526 |
; |
| 527 |
|
| 528 |
/* |
| 529 |
* The "room lister" object - this is the object that we use by default |
| 530 |
* with showList() to construct the listing of the portable items in a |
| 531 |
* room when displaying the room's description. |
| 532 |
*/ |
| 533 |
libRoomLister: ShowListInterface |
| 534 |
/* show the prefix/suffix in wide mode */ |
| 535 |
showListPrefixWide(itemCount, pov, parent) { "You see "; } |
| 536 |
showListSuffixWide(itemCount, pov, parent) { " here. "; } |
| 537 |
|
| 538 |
/* show the tall prefix */ |
| 539 |
showListPrefixTall(itemCount, pov, parent) { "You see:"; } |
| 540 |
|
| 541 |
/* show an empty list */ |
| 542 |
showListEmpty(pov, parent) { } |
| 543 |
; |
| 544 |
|
| 545 |
/* |
| 546 |
* The room lister for dark rooms |
| 547 |
*/ |
| 548 |
libDarkRoomLister: ShowListInterface |
| 549 |
showListPrefixWide(itemCount, pov, parent) |
| 550 |
{ "In the darkness you can see "; } |
| 551 |
showListSuffixWide(itemCount, pov, parent) { ". "; } |
| 552 |
|
| 553 |
showListPrefixTall(itemCount, pov, parent) |
| 554 |
{ "In the darkness you see:"; } |
| 555 |
|
| 556 |
showListEmpty(pov, parent) { } |
| 557 |
; |
| 558 |
|
| 559 |
/* |
| 560 |
* Base class for inventory listers |
| 561 |
*/ |
| 562 |
class InventoryLister: ShowListInterface |
| 563 |
; |
| 564 |
|
| 565 |
/* |
| 566 |
* standard inventory lister for the player character |
| 567 |
*/ |
| 568 |
stdPlayerInventoryLister: InventoryLister |
| 569 |
showListPrefixWide(itemCount, pov, parent) { "You are carrying "; } |
| 570 |
showListSuffixWide(itemCount, pov, parent) { ". "; } |
| 571 |
|
| 572 |
showListPrefixTall(itemCount, pov, parent) { "You are carrying:"; } |
| 573 |
|
| 574 |
showListEmpty(pov, parent) { "You are empty-handed."; } |
| 575 |
; |
| 576 |
|
| 577 |
/* |
| 578 |
* Base class for non-player character listers |
| 579 |
*/ |
| 580 |
class NonPlayerInventoryLister: InventoryLister |
| 581 |
showListPrefixWide(itemCount, pov, parent) |
| 582 |
{ "\^<<parent.nameIsDesc>> carrying "; } |
| 583 |
showListSuffixWide(itemCount, parent) { ". "; } |
| 584 |
|
| 585 |
showListPrefixTall(itemCount, pov, parent) |
| 586 |
{ "\^<<parent.nameIsDesc>> carrying:"; } |
| 587 |
|
| 588 |
showListEmpty(pov, parent) |
| 589 |
{ "\^<<parent.nameIsDesc>> empty-handed. "; } |
| 590 |
; |
| 591 |
|
| 592 |
/* |
| 593 |
* Base class for inventory lister for items being worn |
| 594 |
*/ |
| 595 |
class WearingLister: ShowListInterface |
| 596 |
; |
| 597 |
|
| 598 |
/* |
| 599 |
* standard inventory lister for items being worn by the player |
| 600 |
* character |
| 601 |
*/ |
| 602 |
stdPlayerWearingLister: WearingLister |
| 603 |
showListPrefixWide(itemCount, pov, parent) { "You are wearing "; } |
| 604 |
showListSuffixWide(itemCount, pov, parent) { ". "; } |
| 605 |
|
| 606 |
showListPrefixTall(itemCount, pov, parent) { "You are wearing:"; } |
| 607 |
|
| 608 |
showListEmpty(pov, parent) { } |
| 609 |
; |
| 610 |
|
| 611 |
/* |
| 612 |
* Base class for non-player character inventory listers for items being |
| 613 |
* worn by NPC's |
| 614 |
*/ |
| 615 |
class NonPlayerWearingLister: WearingLister |
| 616 |
showListPrefixWide(itemCount, pov, parent) |
| 617 |
{ |
| 618 |
"\^<<parent.nameIsDesc>> wearing "; |
| 619 |
} |
| 620 |
showListSuffixWide(itemCount, pov, parent) { ". "; } |
| 621 |
|
| 622 |
showListPrefixTall(itemCount, pov, parent) |
| 623 |
{ |
| 624 |
"\^<<parent.nameIsDesc>> wearing:"; |
| 625 |
} |
| 626 |
|
| 627 |
showListEmpty(pov, parent) { } |
| 628 |
; |
| 629 |
|
| 630 |
/* |
| 631 |
* Base class for contents listers |
| 632 |
*/ |
| 633 |
class ContentsLister: ShowListInterface |
| 634 |
showListEmpty(pov, parent) { } |
| 635 |
showListSuffixWide(itemCount, pov, parent) { ". "; } |
| 636 |
; |
| 637 |
|
| 638 |
/* |
| 639 |
* Contents lister for things |
| 640 |
*/ |
| 641 |
thingContentsLister: ContentsLister |
| 642 |
showListPrefixWide(itemCount, pov, parent) |
| 643 |
{ |
| 644 |
"\^<<parent.theDesc>> contain<<parent.isPlural ? '' : 's'>> "; |
| 645 |
} |
| 646 |
showListPrefixTall(itemCount, pov, parent) |
| 647 |
{ |
| 648 |
"\^<<parent.theDesc>> contain<<parent.isPlural ? '' : 's'>>:"; |
| 649 |
} |
| 650 |
; |
| 651 |
|
| 652 |
/* |
| 653 |
* Contents lister for a surface |
| 654 |
*/ |
| 655 |
surfaceContentsLister: ContentsLister |
| 656 |
showListPrefixWide(itemCount, pov, parent) |
| 657 |
{ |
| 658 |
"On <<parent.theDesc>> you see "; |
| 659 |
} |
| 660 |
showListPrefixTall(itemCount, pov, parent) |
| 661 |
{ |
| 662 |
"On <<parent.theDesc>>:"; |
| 663 |
} |
| 664 |
; |
| 665 |
|
| 666 |
|
| 667 |
/* ------------------------------------------------------------------------ */ |
| 668 |
/* |
| 669 |
* Spell out an integer number. |
| 670 |
* |
| 671 |
* This entire function is language-specific. We have not attempted to |
| 672 |
* break down the numeric conversion into smaller language-specific |
| 673 |
* primitives, because we assume that the spelled-out form of numbers |
| 674 |
* varies considerably from language to language and that it would be |
| 675 |
* difficult to cover the full range of possibilities without simply |
| 676 |
* making the entire function language-specific. |
| 677 |
* |
| 678 |
* Note that some of the SPELLINT_xxx flags might not be meaningful in |
| 679 |
* all languages, because most of the flags are by their very nature |
| 680 |
* associated with language-specific idioms. Translations are free to |
| 681 |
* ignore flags that indicate variations with no local equivalent. |
| 682 |
*/ |
| 683 |
spellIntExt(val, flags) |
| 684 |
{ |
| 685 |
local str; |
| 686 |
local trailingSpace; |
| 687 |
local needAnd; |
| 688 |
local powers = [1000000000, ' billion ', |
| 689 |
1000000, ' million ', |
| 690 |
1000, ' thousand ', |
| 691 |
100, ' hundred ']; |
| 692 |
|
| 693 |
/* start with an empty string */ |
| 694 |
str = ''; |
| 695 |
trailingSpace = nil; |
| 696 |
needAnd = nil; |
| 697 |
|
| 698 |
/* if it's zero, it's a special case */ |
| 699 |
if (val == 0) |
| 700 |
return 'zero'; |
| 701 |
|
| 702 |
/* |
| 703 |
* if the number is negative, note it in the string, and use the |
| 704 |
* absolute value |
| 705 |
*/ |
| 706 |
if (val < 0) |
| 707 |
{ |
| 708 |
str = 'minus '; |
| 709 |
val = -val; |
| 710 |
} |
| 711 |
|
| 712 |
/* do each named power of ten */ |
| 713 |
for (local i = 1 ; val >= 100 && i <= powers.length() ; i += 2) |
| 714 |
{ |
| 715 |
/* |
| 716 |
* if we're in teen-hundreds mode, do the teen-hundreds - this only |
| 717 |
* works for values from 1,100 to 9,999, since a number like 12,000 |
| 718 |
* doesn't work this way - 'one hundred twenty hundred' is no good |
| 719 |
*/ |
| 720 |
if ((flags & SPELLINT_TEEN_HUNDREDS) != 0 |
| 721 |
&& val >= 1100 && val < 10000) |
| 722 |
{ |
| 723 |
/* if desired, add a comma if there was a prior power group */ |
| 724 |
if (needAnd && (flags & SPELLINT_COMMAS) != 0) |
| 725 |
str = str.substr(1, str.length() - 1) + ', '; |
| 726 |
|
| 727 |
/* spell it out as a number of hundreds */ |
| 728 |
str += spellIntExt(val / 100, flags) + ' hundred '; |
| 729 |
|
| 730 |
/* take off the hundreds */ |
| 731 |
val %= 100; |
| 732 |
|
| 733 |
/* note the trailing space */ |
| 734 |
trailingSpace = true; |
| 735 |
|
| 736 |
/* we have something to put an 'and' after, if desired */ |
| 737 |
needAnd = true; |
| 738 |
|
| 739 |
/* |
| 740 |
* whatever's left is below 100 now, so there's no need to |
| 741 |
* keep scanning the big powers of ten |
| 742 |
*/ |
| 743 |
break; |
| 744 |
} |
| 745 |
|
| 746 |
/* if we have something in this power range, apply it */ |
| 747 |
if (val >= powers[i]) |
| 748 |
{ |
| 749 |
/* if desired, add a comma if there was a prior power group */ |
| 750 |
if (needAnd && (flags & SPELLINT_COMMAS) != 0) |
| 751 |
str = str.substr(1, str.length() - 1) + ', '; |
| 752 |
|
| 753 |
/* add the number of multiples of this power and the power name */ |
| 754 |
str += spellIntExt(val / powers[i], flags) + powers[i+1]; |
| 755 |
|
| 756 |
/* take it out of the remaining value */ |
| 757 |
val %= powers[i]; |
| 758 |
|
| 759 |
/* |
| 760 |
* note that we have a trailing space in the string (all of |
| 761 |
* the power-of-ten names have a trailing space, to make it |
| 762 |
* easy to tack on the remainder of the value) |
| 763 |
*/ |
| 764 |
trailingSpace = true; |
| 765 |
|
| 766 |
/* we have something to put an 'and' after, if one is desired */ |
| 767 |
needAnd = true; |
| 768 |
} |
| 769 |
} |
| 770 |
|
| 771 |
/* |
| 772 |
* if we have anything left, and we have written something so far, |
| 773 |
* and the caller wanted an 'and' before the tens part, add the |
| 774 |
* 'and' |
| 775 |
*/ |
| 776 |
if ((flags & SPELLINT_AND_TENS) != 0 |
| 777 |
&& needAnd |
| 778 |
&& val != 0) |
| 779 |
{ |
| 780 |
/* add the 'and' */ |
| 781 |
str += 'and '; |
| 782 |
trailingSpace = true; |
| 783 |
} |
| 784 |
|
| 785 |
/* do the tens */ |
| 786 |
if (val >= 20) |
| 787 |
{ |
| 788 |
/* anything above the teens is nice and regular */ |
| 789 |
str += ['twenty', 'thirty', 'forty', 'fifty', 'sixty', |
| 790 |
'seventy', 'eighty', 'ninety'][val/10 - 1]; |
| 791 |
val %= 10; |
| 792 |
|
| 793 |
/* if it's non-zero, we'll add the units, so add a hyphen */ |
| 794 |
if (val != 0) |
| 795 |
str += '-'; |
| 796 |
|
| 797 |
/* we no longer have a trailing space in the string */ |
| 798 |
trailingSpace = nil; |
| 799 |
} |
| 800 |
else if (val >= 10) |
| 801 |
{ |
| 802 |
/* we have a teen */ |
| 803 |
str += ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', |
| 804 |
'fifteen', 'sixteen', 'seventeen', 'eighteen', |
| 805 |
'nineteen'][val - 9]; |
| 806 |
|
| 807 |
/* we've finished with the number */ |
| 808 |
val = 0; |
| 809 |
|
| 810 |
/* there's no trailing space */ |
| 811 |
trailingSpace = nil; |
| 812 |
} |
| 813 |
|
| 814 |
/* if we have a units value, add it */ |
| 815 |
if (val != 0) |
| 816 |
{ |
| 817 |
/* add the units name */ |
| 818 |
str += ['one', 'two', 'three', 'four', 'five', |
| 819 |
'six', 'seven', 'eight', 'nine'][val]; |
| 820 |
|
| 821 |
/* we have no trailing space now */ |
| 822 |
trailingSpace = nil; |
| 823 |
} |
| 824 |
|
| 825 |
/* if there's a trailing space, remove it */ |
| 826 |
if (trailingSpace) |
| 827 |
str = str.substr(1, str.length() - 1); |
| 828 |
|
| 829 |
/* return the string */ |
| 830 |
return str; |
| 831 |
} |
| 832 |
|