| 1 |
#include "adv3.h" |
| 2 |
|
| 3 |
object template "sDesc"; |
| 4 |
object template 'sDescStr'; |
| 5 |
object template 'sDescStr' "lDesc"; |
| 6 |
object template "sDesc" "lDesc"; |
| 7 |
|
| 8 |
/* |
| 9 |
* List group for encyclopedia volumes. We want the listing to come out |
| 10 |
* like this: volumes I, III, and VII of the Encyclopedia Tadsica. Note |
| 11 |
* that we want the volumes in ascending order of volume number. |
| 12 |
*/ |
| 13 |
EncycListGroup: ListGroup |
| 14 |
showGroupList(pov, lister, lst, options, indent, infoList) |
| 15 |
{ |
| 16 |
/* put the list in sorted order of volume */ |
| 17 |
lst = lst.sort(nil, {a, b: a.volumeNum - b.volumeNum}); |
| 18 |
|
| 19 |
/* check for wide/tall mode */ |
| 20 |
if ((options & LIST_TALL) != 0) |
| 21 |
{ |
| 22 |
"<<spellInt(lst.length())>> volumes of the Encyclopedia |
| 23 |
Tadsica\n"; |
| 24 |
showListSimple(pov, lister, lst, options | LIST_GROUP, |
| 25 |
indent + 1, 0, infoList); |
| 26 |
} |
| 27 |
else |
| 28 |
{ |
| 29 |
"volumes "; |
| 30 |
showListSimple(pov, lister, lst, options | LIST_GROUP, |
| 31 |
indent + 1, 0, infoList); |
| 32 |
" of the Encyclopedia Tadsica"; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
/* |
| 37 |
* because of our phrasing, we don't need to set off our group |
| 38 |
* sublist from items in the enclosing list |
| 39 |
*/ |
| 40 |
groupDisplaysSublist = nil |
| 41 |
; |
| 42 |
|
| 43 |
class EncycVolume: Thing |
| 44 |
/* my volume number, as an integer */ |
| 45 |
volumeNum = 0 |
| 46 |
|
| 47 |
/* list with other volumes */ |
| 48 |
listWith = EncycListGroup |
| 49 |
|
| 50 |
/* use a roman numeral to display my volume number */ |
| 51 |
sDescStr |
| 52 |
{ |
| 53 |
return 'Encyclopedia Tadsica volume ' |
| 54 |
+ intToRoman(volumeNum).toUpper(); |
| 55 |
} |
| 56 |
|
| 57 |
/* don't display any articles */ |
| 58 |
aDesc { sDesc; } |
| 59 |
theDesc { sDesc; } |
| 60 |
|
| 61 |
/* when I'm listed in a group, just show my volume number */ |
| 62 |
groupListDesc(options, pov, senseInfo) |
| 63 |
{ |
| 64 |
say(intToRoman(volumeNum).toUpper()); |
| 65 |
} |
| 66 |
; |
| 67 |
|
| 68 |
/* |
| 69 |
* Define a group lister for coins. This one's a bit complicated: when |
| 70 |
* we list the group, we want to add up the dollars-and-cents value of |
| 71 |
* the coins, and then we want to sort the coins in descending order of |
| 72 |
* value (more valuable coins first). |
| 73 |
*/ |
| 74 |
CoinListGroup: ListGroup |
| 75 |
showGroupList(pov, lister, lst, options, indent, infoList) |
| 76 |
{ |
| 77 |
local total; |
| 78 |
|
| 79 |
/* count up the amount of money we have */ |
| 80 |
total = 0; |
| 81 |
foreach (local cur in lst) |
| 82 |
total += cur.value; |
| 83 |
|
| 84 |
/* show the monetary value */ |
| 85 |
if (total < 100) |
| 86 |
{ |
| 87 |
/* it's less than a dollar - spell out the number of cents */ |
| 88 |
"<<spellInt(total)>> cents in coins"; |
| 89 |
} |
| 90 |
else |
| 91 |
{ |
| 92 |
local cents; |
| 93 |
|
| 94 |
/* it's over a dollar - show like $1.25 */ |
| 95 |
"$<<total/100>>."; |
| 96 |
|
| 97 |
/* get the cents */ |
| 98 |
cents = toString(total % 100); |
| 99 |
|
| 100 |
/* make sure we show a leading zero if it's only one digit */ |
| 101 |
if (cents.length() == 1) |
| 102 |
cents = '0' + cents; |
| 103 |
|
| 104 |
/* show it */ |
| 105 |
"<<cents>> in change"; |
| 106 |
} |
| 107 |
|
| 108 |
/* sort the list by descending monetary value */ |
| 109 |
lst = lst.sort(true, {coin1, coin2: coin1.value - coin2.value}); |
| 110 |
|
| 111 |
/* show the appropriate wide/tall separator */ |
| 112 |
if ((options & LIST_TALL) != 0) "\n"; else " ("; |
| 113 |
|
| 114 |
/* show the sublist */ |
| 115 |
showListSimple(pov, lister, lst, options | LIST_GROUP, indent + 1, |
| 116 |
0, infoList); |
| 117 |
|
| 118 |
/* end the sublist */ |
| 119 |
if ((options & LIST_TALL) == 0) ")"; |
| 120 |
} |
| 121 |
|
| 122 |
/* we parenthesize our list, so we don't introduce a sublist */ |
| 123 |
groupDisplaysSublist = nil |
| 124 |
; |
| 125 |
|
| 126 |
class Coin: Thing |
| 127 |
isEquivalent = true |
| 128 |
sDescStr = 'coin' |
| 129 |
listWith = CoinListGroup |
| 130 |
|
| 131 |
/* the monetary value of the coin, in cents */ |
| 132 |
value = 0 |
| 133 |
; |
| 134 |
|
| 135 |
class DollarCoin: Coin |
| 136 |
sDescStr = 'dollar coin' |
| 137 |
value = 100 |
| 138 |
; |
| 139 |
|
| 140 |
class QuarterCoin: Coin |
| 141 |
sDescStr = 'quarter' |
| 142 |
value = 25 |
| 143 |
; |
| 144 |
|
| 145 |
class DimeCoin: Coin |
| 146 |
sDescStr = 'dime' |
| 147 |
value = 10 |
| 148 |
; |
| 149 |
|
| 150 |
class NickelCoin: Coin |
| 151 |
sDescStr = 'nickel' |
| 152 |
value = 5 |
| 153 |
; |
| 154 |
|
| 155 |
class PennyCoin: Coin |
| 156 |
sDescStr = 'penny' |
| 157 |
value = 1 |
| 158 |
; |
| 159 |
|
| 160 |
dirtyGlass: Material |
| 161 |
seeThru = obscured |
| 162 |
hearThru = opaque |
| 163 |
smellThru = opaque |
| 164 |
touchThru = opaque |
| 165 |
; |
| 166 |
|
| 167 |
window: Connector, Thing 'window' |
| 168 |
locationList = [room1, myCar] |
| 169 |
connectorMaterial = glass |
| 170 |
initDesc = "A window lets you see into a nearby car. " |
| 171 |
; |
| 172 |
|
| 173 |
dirtyWindow: Connector, Thing 'dirty window' |
| 174 |
locationList = [room1, room3] |
| 175 |
connectorMaterial = dirtyGlass |
| 176 |
; |
| 177 |
|
| 178 |
room1: DarkRoom "Room A" |
| 179 |
"This room was obviously constructed in a hurry and without much |
| 180 |
forethought: the walls are at odd angles and don't quite meet at |
| 181 |
the seams; pieces of debris are scattered all about; many of the |
| 182 |
nails haven't been pounded down all the way. " |
| 183 |
; |
| 184 |
|
| 185 |
+ Container 'dark glass sphere' |
| 186 |
isOpen = nil |
| 187 |
material = dirtyGlass |
| 188 |
; |
| 189 |
|
| 190 |
++ Thing |
| 191 |
sDescStr |
| 192 |
{ |
| 193 |
local info; |
| 194 |
|
| 195 |
/* get my visual sense information */ |
| 196 |
info = getVisualSenseInfo(); |
| 197 |
|
| 198 |
/* change the name depending on how well lit we are */ |
| 199 |
if (info == nil || info.ambient < 3) |
| 200 |
return 'shiny object'; |
| 201 |
else |
| 202 |
return 'silver key'; |
| 203 |
} |
| 204 |
; |
| 205 |
|
| 206 |
+ chair: Thing 'chair'; |
| 207 |
|
| 208 |
++ me: Actor 'me'; |
| 209 |
|
| 210 |
+++ torch: LightSource 'torch' |
| 211 |
isLit = nil |
| 212 |
brightnessOn = 4 |
| 213 |
; |
| 214 |
|
| 215 |
+++ QuarterCoin; |
| 216 |
+++ quarter3: QuarterCoin; |
| 217 |
+++ quarter4: QuarterCoin; |
| 218 |
+++ QuarterCoin; |
| 219 |
+++ QuarterCoin; |
| 220 |
+++ DimeCoin; |
| 221 |
+++ NickelCoin; |
| 222 |
+++ NickelCoin; |
| 223 |
+++ penny1: PennyCoin; |
| 224 |
+++ penny2: PennyCoin; |
| 225 |
+++ PennyCoin; |
| 226 |
|
| 227 |
+++ candle: LightSource 'candle' |
| 228 |
isLit = nil |
| 229 |
brightnessOn = 2 |
| 230 |
; |
| 231 |
|
| 232 |
+++ EncycVolume volumeNum = 4; |
| 233 |
|
| 234 |
+ quarter1: QuarterCoin; |
| 235 |
+ PennyCoin; |
| 236 |
+ quarter2: QuarterCoin; |
| 237 |
|
| 238 |
+ Surface 'desk'; |
| 239 |
|
| 240 |
++ EncycVolume volumeNum = 3; |
| 241 |
++ EncycVolume volumeNum = 7; |
| 242 |
++ EncycVolume volumeNum = 2; |
| 243 |
++ EncycVolume volumeNum = 6; |
| 244 |
++ EncycVolume volumeNum = 5; |
| 245 |
|
| 246 |
+ PennyCoin; |
| 247 |
+ PennyCoin; |
| 248 |
|
| 249 |
room2: DarkRoom "Room B"; |
| 250 |
|
| 251 |
+ myCar: Container 'car' |
| 252 |
isOpen = nil |
| 253 |
; |
| 254 |
|
| 255 |
++ seatbelt: Thing 'seatbelt'; |
| 256 |
|
| 257 |
++ clock: Thing 'LED clock' aDesc = "an LED clock" brightness=1; |
| 258 |
|
| 259 |
+ box: OpenableContainer 'box' |
| 260 |
isOpen = true |
| 261 |
; |
| 262 |
|
| 263 |
++ book: Thing 'book'; |
| 264 |
|
| 265 |
room3: DarkRoom "Room C"; |
| 266 |
|
| 267 |
+ abacus: Thing 'abacus' brightness=1; |
| 268 |
|
| 269 |
+ flashlight: LightSource 'flashlight' |
| 270 |
isLit = nil |
| 271 |
; |
| 272 |
|
| 273 |
+ cabinet: Container 'cabinet' |
| 274 |
isOpen = nil |
| 275 |
material = dirtyGlass |
| 276 |
; |
| 277 |
|
| 278 |
++ calculator: Thing 'calculator'; |
| 279 |
|
| 280 |
++ dime: Thing 'dime' seeSize = small; |
| 281 |
|
| 282 |
/* |
| 283 |
* An Achievement object for earning money |
| 284 |
*/ |
| 285 |
moneyAchievement: Achievement |
| 286 |
achieve(points, item) |
| 287 |
{ |
| 288 |
/* add the item to our money list */ |
| 289 |
moneyList += item; |
| 290 |
|
| 291 |
/* add myself to the score */ |
| 292 |
addToScore(points, self); |
| 293 |
} |
| 294 |
|
| 295 |
lDesc |
| 296 |
{ |
| 297 |
"finding "; |
| 298 |
showListAll(plainLister, moneyList, 0, 0); |
| 299 |
} |
| 300 |
|
| 301 |
/* the list of items for which I've been achieved */ |
| 302 |
moneyList = [] |
| 303 |
; |
| 304 |
|
| 305 |
main(args) |
| 306 |
{ |
| 307 |
/* set the player character */ |
| 308 |
setPlayer(me); |
| 309 |
|
| 310 |
"<.roomname>Room Name Test<./roomname>\b"; |
| 311 |
|
| 312 |
/* look around in the dark */ |
| 313 |
room1.lookAround(me, true); |
| 314 |
"\b"; |
| 315 |
|
| 316 |
/* do some point-to-point tests */ |
| 317 |
"me->chair: <<sayTrans(me.senseObj(sight, chair))>>\n"; |
| 318 |
"me->box: <<sayTrans(me.senseObj(sight, box))>>\n"; |
| 319 |
"me->book: <<sayTrans(me.senseObj(sight, book))>>\n"; |
| 320 |
"me->car: <<sayTrans(me.senseObj(sight, myCar))>>\n"; |
| 321 |
"me->seatbelt: <<sayTrans(me.senseObj(sight, seatbelt))>>\n"; |
| 322 |
"me->clock: <<sayTrans(me.senseObj(sight, clock))>>\n"; |
| 323 |
"me->abacus: <<sayTrans(me.senseObj(sight, abacus))>>\n"; |
| 324 |
"me->calculator: <<sayTrans(me.senseObj(sight, calculator))>>\n"; |
| 325 |
"me->dime: <<sayTrans(me.senseObj(sight, dime))>>\n"; |
| 326 |
"abacus->calculator: <<sayTrans(abacus.senseObj(sight, calculator))>>\n"; |
| 327 |
|
| 328 |
"\b"; |
| 329 |
|
| 330 |
/* construct some lists of everything visible from a given point */ |
| 331 |
"visible from me: <<sayList(me.senseList(sight))>>\n"; |
| 332 |
"visible from Room C: <<sayList(room3.senseList(sight))>>\n"; |
| 333 |
"visible from calculator: <<sayList(calculator.senseList(sight))>>\n"; |
| 334 |
|
| 335 |
/* construct a list of everything in scope for me */ |
| 336 |
"in scope for me: <<sayList(me.scopeList())>>\n"; |
| 337 |
|
| 338 |
"\b"; |
| 339 |
|
| 340 |
/* turn on the flashlight and see what we can see */ |
| 341 |
flashlight.isLit = true; |
| 342 |
"After lighting the flashlight:\n |
| 343 |
visible from me: <<sayList(me.senseList(sight))>>\n"; |
| 344 |
|
| 345 |
"\b"; |
| 346 |
|
| 347 |
/* turn on the candle and see what we can see */ |
| 348 |
candle.isLit = true; |
| 349 |
"After lighting the candle:\n |
| 350 |
visible from me: <<sayList(me.senseList(sight))>>\n"; |
| 351 |
|
| 352 |
"\b"; |
| 353 |
|
| 354 |
/* turn off the flashlight and see what we can see */ |
| 355 |
flashlight.isLit = nil; |
| 356 |
"After turning the flashlight off again:\n |
| 357 |
visible from me: <<sayList(me.senseList(sight))>>\n"; |
| 358 |
|
| 359 |
"\b"; |
| 360 |
|
| 361 |
/* show the room description */ |
| 362 |
room1.lookAround(me, true); |
| 363 |
"\b"; |
| 364 |
|
| 365 |
/* show the player character inventory */ |
| 366 |
me.showInventory(nil); |
| 367 |
"\b"; |
| 368 |
|
| 369 |
/* show a tall inventory */ |
| 370 |
me.showInventory(true); |
| 371 |
"\b"; |
| 372 |
|
| 373 |
/* turn on the torch */ |
| 374 |
torch.isLit = true; |
| 375 |
"After lighting the torch:\n"; |
| 376 |
|
| 377 |
/* show the room description */ |
| 378 |
room1.lookAround(me, true); |
| 379 |
"\b"; |
| 380 |
|
| 381 |
/* make the torch brighter */ |
| 382 |
torch.brightnessOn++; |
| 383 |
"After increasing the torch's brightness:\n"; |
| 384 |
|
| 385 |
/* show the room description */ |
| 386 |
room1.lookAround(me, true); |
| 387 |
"\b"; |
| 388 |
|
| 389 |
/* show the score */ |
| 390 |
showFullScore(); |
| 391 |
"\b"; |
| 392 |
|
| 393 |
/* add some points, then show the score again */ |
| 394 |
moneyAchievement.achieve(2, quarter1); |
| 395 |
addToScore(10, 'turning on the flashlight'); |
| 396 |
addToScore(3, 'finding various treasures'); |
| 397 |
addToScore(5, 'climbing the ladder'); |
| 398 |
addToScore(1, 'lighting the torch'); |
| 399 |
addToScore(9, 'finding various treasures'); |
| 400 |
moneyAchievement.achieve(2, quarter2); |
| 401 |
moneyAchievement.achieve(1, penny2); |
| 402 |
|
| 403 |
/* while we're at it, set up a ranking table */ |
| 404 |
libMessages.scoreRankTable = |
| 405 |
[ |
| 406 |
[0, 'a novice adventurer'], |
| 407 |
[30, 'an intermediate adventurer'], |
| 408 |
[70, 'an advanced adventurer'], |
| 409 |
[100, 'a master adventurer'] |
| 410 |
]; |
| 411 |
|
| 412 |
/* show the full score */ |
| 413 |
showFullScore(); |
| 414 |
"\b"; |
| 415 |
} |
| 416 |
|
| 417 |
sayTrans(trans) |
| 418 |
{ |
| 419 |
/* note the transparency level */ |
| 420 |
switch(trans[1]) |
| 421 |
{ |
| 422 |
case opaque: |
| 423 |
"opaque"; |
| 424 |
break; |
| 425 |
|
| 426 |
case transparent: |
| 427 |
"transparent"; |
| 428 |
break; |
| 429 |
|
| 430 |
case obscured: |
| 431 |
"obscured"; |
| 432 |
break; |
| 433 |
|
| 434 |
case distant: |
| 435 |
"distant"; |
| 436 |
break; |
| 437 |
|
| 438 |
default: |
| 439 |
"???"; |
| 440 |
break; |
| 441 |
} |
| 442 |
|
| 443 |
/* note the obstructor */ |
| 444 |
if (trans[2] != nil) |
| 445 |
" - obstructed by <<trans[2].sDesc>>"; |
| 446 |
|
| 447 |
if (trans[3] != nil) |
| 448 |
" (light level <<trans[3]>>)"; |
| 449 |
} |
| 450 |
|
| 451 |
sayList(lst) |
| 452 |
{ |
| 453 |
local i; |
| 454 |
|
| 455 |
"["; |
| 456 |
i = 0; |
| 457 |
foreach (local cur in lst) |
| 458 |
{ |
| 459 |
if (i++ != 0) |
| 460 |
", "; |
| 461 |
cur.sDesc; |
| 462 |
} |
| 463 |
"]"; |
| 464 |
} |
| 465 |
|