-
Notifications
You must be signed in to change notification settings - Fork 10
/
almazar.c
1833 lines (1754 loc) · 67.9 KB
/
almazar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <assert.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef Z_MACHINE
#ifdef SAVE_AND_RESTORE
extern int attempt_save(void);
extern int attempt_restore(void);
#endif /* SAVE_AND_RESTORE */
/* The Z-machine's "@random 42" instruction returns a value in the range 1..42. */
int ran(int range) =
"\t@random r0 -> r0;\n"
"\t@sub r0 0+1 -> r0;\n";
#else
int ran(int range) { return rand() % range; }
#endif /* Z_MACHINE */
#define SOFT_NL "\n"
#define SOFT_HYPHEN "-\n"
#define apport(obj, loc) object_position[obj] = loc
#define toting(obj) (object_position[obj] == -1)
#define there(obj, loc) (object_position[obj] == loc)
#define putsn(s) do { puts(s); extra_newline(); } while (0)
enum {
R_LIMBO=0, R_START, R_SHACK, R_STREWN, R_FOREST1, R_FOREST2, R_FOREST3,
R_ROAD, R_OIL, R_JUNC, R_CAVE, R_FILTER, R_BROKEN, R_REMAINS, R_HALL1,
R_LIGHTED, R_TOOL, R_CORR, R_MAZE18, R_MAZE19, R_MAZE20, R_MAZE21,
R_MAZE22, R_MAZE23, R_TALL, R_HALL2, R_MEET, R_CHASM, R_LEDGE, R_NARROW,
R_TEE, R_MINE, R_TREE, R_MINE33, R_MINE34, R_MINE35, R_MINE36, R_MINE37,
R_MINE38, R_WINDS, R_ROAD2, R_HILL, R_ROCK, R_RIVER, R_WELCOME,
R_CROSSROADS, R_HOLEY, R_STABLE, R_END, R_RIVERFRONT, R_GARGOYLE,
R_OUTOUT, R_IDOL, R_GARDEN, R_ORCHARD, R_HOUSE, R_FOYER, R_DINING,
R_KITCHEN, R_LIVING, R_HIDDEN, R_BASEMENT, R_OUTSIDE, R_RECEPTION,
R_MIDDLE, R_LIBRARY, R_BEDROOM, R_CLOSET, R_TOP, R_ATTIC, R_OUTHOUSE,
R_LIFT, R_VAULT
};
typedef int Location;
typedef enum {
NO_VERB,
NORTH, EAST, SOUTH, WEST, UP, DOWN, LOOK, HINT, INVENTORY,
JUMP, SCORE, QUIT, SAVE, RESTORE, ENTER, LEAVE,
GET, DROP, WAVE, SHOW, READ, FILL, LIGHT, KILL, KICK,
BREAK, TOSS, EAT, DRINK, FEED, TURN, UNLOCK, CROSS, SWIM,
OPEN, CLOSE, OFF, PULL, EMPTY
} Verb;
typedef enum {
NO_OBJECT,
// These nouns denote portable objects.
// - SPICES means the spices in the bottle.
// - BOTTLE means the empty bottle.
DIAMOND, EYE, CHAIN, APPLE, PEARLS, SPICES, DAGGER, FIGURINE,
LAMP, KEY, RING, ROD, STAFF, INCENSE, HAY, CHEESE, MOUSE,
MATCHES, BOTTLE, WATER_BOTTLE,
// These nouns denote non-portable objects with location.
// Their order matters to describe_room().
EYE_IN_PLACE, GNOME, SPICES_IN_PLACE, WIZARD, SNAKE, BALL,
FIGURINE_IN_PLACE, OPEN_WINDOW, CLOSED_WINDOW, OPEN_PANEL,
// These nouns are used by the parser, but have no location.
// Their order doesn't matter.
IDOL, CHASM, RIVER, HEAD,
BOOK, MESSAGE, OIL, WATER, VAULT, CHEST, DRAWER, WINDOW,
ROPE, SIGN
} Object;
typedef enum {
STATUS_LOCKED, STATUS_UNLOCKED, STATUS_OPEN
} Status;
struct Place {
const char *long_desc;
const char *short_desc;
Location neighbors[6];
bool visited;
};
struct Place places[R_VAULT+1];
Location object_position[OPEN_PANEL + 1]; // OP in the original program
int lamp_counter = 0; // SP1 in the original program
bool lamp_is_on = false; // SP2 in the original program
bool mouse_is_fed = false; // SP3 in the original program
// SP4 in the original program was never used
bool wizard_is_dead = false; // SP5 in the original program
int wizard_counter = 0; // SP6 in the original program
Status vault_status = STATUS_LOCKED; // SP7 in the original program
bool river_is_open = false; // SP8 in the original program
bool chasm_is_bridged = false; // SP9 in the original program
// SP10 in the original program was window_is_open, but we don't need it
Status drawer_status = STATUS_LOCKED; // SP11 in the original program
Status chest_status = STATUS_LOCKED; // SP12 in the original program
int darkness_counter = 0; // SP13 in the original program
int river_counter = 0; // SP14 in the original program
bool chased_by_gnome = false; // SC in the original program
bool heard_voiceover = false; // VO in the original program
bool lamp_has_dimmed = false; // W1 in the original program
bool better_hurry = false; // W2 in the original program
int hint_penalties = 0; // PR in the original program
int turn_counter = 0; // TU in the original program
int death_counter = 0; // DI in the original program
Verb lookup_verb(const char *word)
{
#define V(e, w) if (strncmp(word, w, 4) == 0) return e
V(NORTH, "nort"); V(NORTH, "n");
V(EAST, "east"); V(EAST, "e");
V(SOUTH, "sout"); V(SOUTH, "s");
V(WEST, "west"); V(WEST, "w");
V(UP, "up"); V(UP, "u");
V(DOWN, "down"); V(DOWN, "d");
V(LOOK, "look");
V(HINT, "hint"); V(HINT, "help");
V(INVENTORY, "inve");
V(JUMP, "jump");
V(SCORE, "scor");
V(QUIT, "quit");
V(SAVE, "save");
V(RESTORE, "rest");
V(ENTER, "ente");
V(LEAVE, "leav");
V(GET, "get"); V(GET, "take"); V(GET, "t"); V(GET, "obta");
V(DROP, "drop"); V(DROP, "dr");
V(WAVE, "wave");
V(SHOW, "show");
V(READ, "read");
V(FILL, "fill");
V(LIGHT, "ligh"); V(LIGHT, "burn");
V(KILL, "kill"); V(KILL, "atta");
V(KICK, "kick");
V(BREAK, "brea"); V(BREAK, "smas");
V(TOSS, "toss"); V(TOSS, "thro");
V(EAT, "eat");
V(DRINK, "drink");
V(FEED, "feed");
V(TURN, "turn");
V(UNLOCK, "unlo");
V(CROSS, "cros");
V(SWIM, "swim");
V(OPEN, "open");
V(CLOSE, "clos");
V(OFF, "off");
V(PULL, "pull");
V(EMPTY, "empt");
#undef V
return NO_VERB;
}
Object lookup_noun(const char *word)
{
#define N(e, w) if (strncmp(word, w, 4) == 0) return e
N(DIAMOND, "diam");
N(EYE, "emer"); N(EYE, "eye");
N(CHAIN, "chai"); N(CHAIN, "plat");
N(APPLE, "appl"); N(APPLE, "gold");
N(PEARLS, "pear");
N(SPICES, "spic");
N(DAGGER, "dagg"); N(DAGGER, "knif");
N(FIGURINE, "figu");
N(LAMP, "lamp");
N(KEY, "key");
N(RING, "ring");
N(ROD, "rod");
N(STAFF, "staff");
N(INCENSE, "ince");
N(HAY, "hay"); N(HAY, "stra");
N(CHEESE, "chee");
N(MOUSE, "mous");
N(MATCHES, "matc");
N(BOTTLE, "bott");
N(IDOL, "idol");
N(SNAKE, "snak");
N(CHASM, "chas"); N(CHASM, "abys");
N(WIZARD, "wiza");
N(RIVER, "rive");
N(HEAD, "head");
N(BOOK, "book");
N(MESSAGE, "mess");
N(BALL, "ball"); N(BALL, "crys");
N(OIL, "oil");
N(WATER, "wate");
N(VAULT, "vaul");
N(CHEST, "ches");
N(DRAWER, "draw");
N(WINDOW, "wind");
N(ROPE, "rope");
N(SIGN, "sign");
N(GNOME, "gnom");
#undef N
return NO_OBJECT;
}
bool is_transitive(Verb v)
{
return (GET <= v && v <= EMPTY);
}
void listen(Verb *iverb, Object *iobj)
{
char buffer[72];
printf("? "); fflush(stdout);
fgets(buffer, sizeof(buffer), stdin);
for (char *p = buffer; *p != '\0'; ++p) {
*p = (*p == '\n') ? '\0' : tolower(*p);
}
const char *first_word = buffer;
char *second_word = strchr(buffer, ' ');
if (second_word != NULL) {
*second_word++ = '\0';
} else {
second_word = "";
}
*iverb = lookup_verb(first_word);
if (is_transitive(*iverb)) {
*iobj = lookup_noun(second_word);
}
}
void extra_newline()
{
puts("");
}
bool yes(const char *q)
{
char buffer[72];
while (true) {
printf("%s ", q); fflush(stdout);
fgets(buffer, sizeof(buffer), stdin);
extra_newline();
if (tolower(*buffer) == 'y') {
return true;
} else if (tolower(*buffer) == 'n') {
return false;
} else {
putsn(" Please answer Yes or No.");
}
}
}
// Line 2530 in the original program
bool vault_challenge()
{
char buffer[72];
printf("Left? "); fflush(stdout);
fgets(buffer, sizeof(buffer), stdin);
int first = atoi(buffer);
printf("Right? "); fflush(stdout);
fgets(buffer, sizeof(buffer), stdin);
int second = atoi(buffer);
printf("Left? "); fflush(stdout);
fgets(buffer, sizeof(buffer), stdin);
int third = atoi(buffer);
return (first == 3 && second == 7 && third == 21);
}
void describe_object(Object obj)
{
switch (obj) {
case DIAMOND: putsn("A large diamond is lying here!"); break;
case EYE: putsn("There's an emerald eye here!"); break;
case CHAIN: putsn("A platinum chain is lying here!"); break;
case APPLE: putsn("There is a golden apple here!"); break;
case PEARLS: putsn("A string of pearls is lying here!"); break;
case SPICES: putsn("There's a bottle of rare spices lying here!"); break;
case DAGGER: putsn("There is a jewel-encrusted dagger here!"); break;
case FIGURINE: putsn("A priceless figurine is sitting on some hay!"); break;
case LAMP: putsn("There is an old oil lamp here."); break;
case KEY: putsn("An old brass key is sitting here."); break;
case RING: putsn("There is a worthless-looking ring here."); break;
case ROD: putsn("An old black rod is sitting here."); break;
case STAFF: putsn("There's an ancient-looking staff lying here."); break;
case INCENSE: putsn("There's a package of incense lying here."); break;
case HAY: putsn("There's a bale of hay here."); break;
case CHEESE: putsn("A package of Kraft cheese is lying here."); break;
case MOUSE: putsn("There is a noisy little mouse here."); break;
case MATCHES: putsn("There's a box of matches lying here."); break;
case BOTTLE: putsn("There's an empty bottle here."); break;
case WATER_BOTTLE: putsn("There's a brownish bottle of water here."); break;
case EYE_IN_PLACE: putsn("An emerald eye sits on top of the idol."); break;
case GNOME: putsn("There is a knife-wielding gnome in the room with you!"); break;
case SPICES_IN_PLACE: putsn("There are rare spices sitting on the ground."); break;
case WIZARD: putsn("An angry wizard wearing a platinum chain is in the room with you!"); break;
case SNAKE: putsn("A giant snake is jealously guarding a golden apple."); break;
case BALL: putsn("There is a large crystal ball on the ground."); break;
case FIGURINE_IN_PLACE: putsn("A priceless figurine stands on the table."); break;
case OPEN_WINDOW: putsn("The window is open."); break;
case CLOSED_WINDOW: putsn("The window is closed."); break;
case OPEN_PANEL: putsn("There is a panel open to the north."); break;
default: assert(false);
}
}
bool has_darkness(int loc)
{
switch (loc) {
case R_BROKEN: case R_REMAINS: case R_HALL1:
case R_TOOL: case R_CORR: case R_MAZE18: case R_MAZE19:
case R_MAZE20: case R_MAZE21: case R_MAZE22: case R_MAZE23:
case R_TALL: case R_HALL2: case R_MEET: case R_CHASM:
case R_LEDGE: case R_NARROW: case R_MINE33: case R_MINE34:
case R_MINE35: case R_MINE36: case R_MINE37: case R_MINE38:
return true;
default:
return false;
}
}
bool has_river(Location loc)
{
return (loc == R_RIVER || loc == R_WELCOME || loc == R_RIVERFRONT);
}
void describe_room(Location loc)
{
bool has_light = (toting(LAMP) || there(LAMP, loc)) && lamp_is_on;
if (has_darkness(loc) && !has_light) {
putsn("There is insufficient light to see by.");
if (darkness_counter == 0) {
darkness_counter = 1;
}
} else {
darkness_counter = 0;
if (places[loc].visited || places[loc].long_desc == NULL) {
putsn(places[loc].short_desc);
} else {
putsn(places[loc].long_desc);
places[loc].visited = true;
}
for (int i = DIAMOND; i <= OPEN_PANEL; ++i) {
if (there(i, loc) && i != GNOME) {
describe_object(i);
}
}
}
if (loc == R_HILL && !heard_voiceover) {
putsn("A loud voice emanates from beyond, saying: \"Time grows short," SOFT_NL
"mortal, before we feast again.\"");
heard_voiceover = true;
}
}
// Line 7000 in the original program
Location attempt_move_to_room(Location loc, Location nextloc)
{
if (!river_is_open && ((loc == R_RIVER && nextloc == R_WELCOME) ||
(loc == R_WELCOME && nextloc == R_RIVER))) {
putsn("You cannot cross the river.");
return loc;
} else if (!chasm_is_bridged && ((loc == R_CHASM && nextloc == R_LEDGE) ||
(loc == R_LEDGE && nextloc == R_CHASM))) {
putsn("The abyss is too wide to cross.");
return loc;
} else if (loc == R_BASEMENT && nextloc != R_BASEMENT && !wizard_is_dead) {
putsn("The wizard blocks your way.");
return loc;
} else if (loc == R_CLOSET && nextloc == R_LIFT && !wizard_is_dead) {
putsn("There is no way to go in that direction.");
return loc;
}
loc = nextloc;
describe_room(loc);
return loc;
}
void offer_hint(const char *hint)
{
if (yes("The hint will cost you 3 points. Do you still want it?")) {
putsn(hint);
} else {
putsn("OK.");
}
}
// Line 300 in the original program
void attempt_hint(Location loc)
{
switch (loc) {
case R_STABLE: offer_hint("Hay is soft."); break;
case R_RECEPTION: offer_hint("The figurine is extremely delicate."); break;
case R_ORCHARD: offer_hint("Snakes love rodents."); break;
case R_BASEMENT: offer_hint("Only a power stronger than the wizard's own can defeat him."); break;
case R_OUTHOUSE: offer_hint("Complete your task, and return here, and..."); break;
case R_ATTIC: offer_hint("The hungry are always restless."); break;
case R_IDOL: offer_hint("Gods are unhappy creatures with many needs."); break;
case R_RIVER: offer_hint("The river flows toward the Red Sea."); break;
default: putsn("There is no help to be obtained."); break;
}
}
int burden() {
int count = 0;
for (int x = DIAMOND; x <= WATER_BOTTLE; ++x) {
if (toting(x)) count += 1;
}
return count;
}
void describe_inventory_object(Object x)
{
switch (x) {
case DIAMOND: puts(" Large diamond"); break;
case EYE: puts(" Emerald eye"); break;
case CHAIN: puts(" Platinum chain"); break;
case APPLE: puts(" Golden apple"); break;
case PEARLS: puts(" String of pearls"); break;
case SPICES: puts(" Bottle of spices"); break;
case DAGGER: puts(" Jeweled dagger"); break;
case FIGURINE: puts(" Priceless figurine"); break;
case LAMP: puts(" Oil lamp"); break;
case KEY: puts(" Brass key"); break;
case RING: puts(" Ring"); break;
case ROD: puts(" Black rod"); break;
case STAFF: puts(" Wooden staff"); break;
case INCENSE: puts(" Incense"); break;
case HAY: puts(" Hay"); break;
case CHEESE: puts(" Kraft cheese"); break;
case MOUSE: puts(" Noisy mouse"); break;
case MATCHES: puts(" Matches"); break;
case BOTTLE: puts(" Empty bottle"); break;
case WATER_BOTTLE: puts(" Bottle of water"); break;
default: assert(false);
}
}
// Line 400 in the original program
void attempt_inventory()
{
puts("You are carrying:");
for (int x = DIAMOND; x <= WATER_BOTTLE; ++x) {
if (toting(x)) {
describe_inventory_object(x);
}
}
if (burden() == 0) {
puts(" Nothing");
}
extra_newline();
}
// Line 600 in the original program
int attempt_score(bool winning)
{
int pt = 0;
for (int x = DIAMOND; x <= FIGURINE; ++x) {
if (toting(x)) pt += 7;
else if (there(x, R_VAULT)) pt += 10;
}
pt -= 10 * death_counter;
pt -= hint_penalties;
if (winning) pt += 10;
printf("You have scored %d points.\n", pt);
extra_newline();
return pt;
}
// Line 7300 in the original program
void final_score_and_exit(bool winning)
{
int pt = attempt_score(winning);
if (pt == 90) putsn("All honor thee, Grandmaster Adventurer!");
else if (pt >= 80) putsn("You are now an advanced adventurer.");
else if (pt >= 36) putsn("You may now consider yourself an intermediate in this game.");
else if (pt >= 8) putsn("You are obviously a rank novice in this game.");
else putsn("You obviously have no idea what's happening in this game.");
#ifdef Z_MACHINE
puts("\n\n");
#endif /* Z_MACHINE */
exit(0);
}
// Line 7210 in the original program
Location random_death_drop_room()
{
// In the original program, R_LIMBO was a possible outcome here.
return R_START + ran(R_LIGHTED - R_START + 1);
}
// Line 7200 in the original program
Location death()
{
death_counter += 1;
if (death_counter == 3) {
putsn("You have died three times. The game is therefore suspended.");
final_score_and_exit(false);
}
if (!yes("Do you want another chance?")) {
final_score_and_exit(false);
}
// Reincarnate the player.
if (death_counter == 1) {
putsn("Everything spins around you as a wall of fire encircles you." SOFT_NL
"When you wake up you find that...");
} else {
putsn("A small wall of fire barely surrounds you. You regain" SOFT_NL
"consciousness and find that...");
}
for (int x = DIAMOND; x <= WATER_BOTTLE; ++x) {
// In the original program, this loop didn't include WATER_BOTTLE.
if (toting(x)) apport(x, random_death_drop_room());
}
apport(LAMP, R_SHACK);
apport(MATCHES, R_FOREST3);
apport(STAFF, R_ROCK);
lamp_is_on = false;
river_is_open = false;
river_counter = 0;
chased_by_gnome = false;
return attempt_move_to_room(R_LIMBO, R_START);
}
// Line 700 in the original program
void attempt_quit()
{
if (yes("Are you sure you want to quit?")) {
final_score_and_exit(false);
} else {
putsn("OK.");
}
}
bool is_portable(Object obj)
{
return (DIAMOND <= obj && obj <= BOTTLE);
}
// Line 1000 in the original program
Location attempt_get(Object iobj, Location loc)
{
if (iobj == EYE && there(EYE_IN_PLACE, loc)) {
putsn("The god is incensed by your audacity. With a blink of an eye" SOFT_NL
"you fall dead to the ground.");
return death();
} else if (iobj == IDOL && loc == R_IDOL) {
putsn("It's too heavy for you to take.");
} else if (iobj == CHEST && loc == R_ATTIC) {
putsn("It's too heavy for you to take.");
} else if (iobj == BALL && loc == R_TREE) {
putsn("It's too heavy for you to take.");
} else if (iobj == BOOK && loc == R_LIBRARY) {
putsn("It's too heavy for you to take.");
} else if (iobj == APPLE && there(SNAKE, loc)) {
putsn("The snake blocks your way.");
} else if (iobj == CHAIN && there(WIZARD, loc)) {
putsn("The wizard won't let you.");
} else if (iobj == MOUSE && there(MOUSE, loc) && !mouse_is_fed) {
putsn("The mouse is frightened by you.");
} else if (iobj == SPICES && there(SPICES_IN_PLACE, loc)) {
if (toting(WATER_BOTTLE)) {
putsn("Your container is full.");
} else if (!toting(BOTTLE)) {
putsn("You have no container to put it in.");
} else {
putsn("OK.");
apport(SPICES_IN_PLACE, R_LIMBO);
apport(BOTTLE, R_LIMBO);
apport(SPICES, -1);
}
} else if (iobj == WATER && has_river(loc) && !there(WATER_BOTTLE, loc)) {
if (toting(WATER_BOTTLE) || toting(SPICES)) {
putsn("Your container is full.");
} else if (!toting(BOTTLE)) {
putsn("You have no container to put it in.");
} else {
putsn("OK.");
apport(BOTTLE, R_LIMBO);
apport(WATER_BOTTLE, -1);
}
} else if (iobj == OIL) {
if (loc != R_OIL) {
putsn("There is no sign of any oil here.");
} else if (!toting(LAMP)) {
putsn("You don't have a lamp.");
} else {
putsn("OK.");
lamp_counter = 100;
}
} else if (iobj == FIGURINE && there(FIGURINE_IN_PLACE, loc)) {
if (burden() >= 7) {
putsn("You've got too much to carry.");
} else {
putsn("OK.");
apport(FIGURINE_IN_PLACE, R_LIMBO);
apport(FIGURINE, -1);
}
} else {
if (iobj == BOTTLE && (there(SPICES, loc) || toting(SPICES))) {
iobj = SPICES;
} else if (iobj == BOTTLE && (there(WATER_BOTTLE, loc) || toting(WATER_BOTTLE))) {
iobj = WATER_BOTTLE;
} else if (iobj == WATER && (there(WATER_BOTTLE, loc) || toting(WATER_BOTTLE))) {
iobj = WATER_BOTTLE;
}
if (!is_portable(iobj)) {
putsn("I don't understand.");
} else if (toting(iobj)) {
putsn("You're already carrying it.");
} else if (!there(iobj, loc)) {
putsn("I don't see it here.");
} else if (burden() >= 7) {
putsn("You've got too much to carry.");
} else {
putsn("OK.");
apport(iobj, -1);
}
}
return loc;
}
// Line 1100 in the original program
void attempt_drop(Object iobj, Location loc)
{
if ((iobj == BOTTLE || iobj == WATER) && toting(WATER_BOTTLE)) {
putsn("OK.");
apport(WATER_BOTTLE, loc);
} else if ((iobj == BOTTLE || iobj == SPICES) && toting(SPICES)) {
putsn("OK.");
apport(SPICES, loc);
} else if (!is_portable(iobj)) {
putsn("I don't understand.");
} else if (!toting(iobj)) {
putsn("You're not carrying it.");
} else if (iobj == FIGURINE) {
if (there(HAY, loc)) {
putsn("OK.");
apport(FIGURINE, loc);
} else {
putsn("The delicate figurine breaks upon hitting the ground.");
apport(FIGURINE, R_LIMBO);
}
} else if (iobj == MOUSE) {
putsn("The mouse runs away.");
apport(MOUSE, R_LIMBO);
mouse_is_fed = false;
} else {
putsn("OK.");
apport(iobj, loc);
}
}
void print_default_message(Object iobj)
{
if (toting(iobj)) {
putsn("Nothing happens.");
} else if (is_portable(iobj)) {
putsn("You're not carrying it.");
} else {
putsn("I don't understand.");
}
}
// Line 1200 in the original program
void attempt_wave(Object iobj, Location loc)
{
if (iobj == STAFF && toting(STAFF) && (loc == R_RIVER || loc == R_WELCOME)) {
if (river_is_open) {
putsn("A loud noise surrounds you as the river closes.");
river_is_open = false;
} else {
putsn("Holy Moses! The river just split in two! A dry path leads to" SOFT_NL
"the other side.");
river_is_open = true;
}
} else if (iobj == ROD && toting(ROD) && (loc == R_CHASM || loc == R_LEDGE)) {
if (chasm_is_bridged) {
putsn("The bridge has just as suddenly disappeared.");
chasm_is_bridged = false;
} else {
putsn("A crystal bridge now spans the chasm.");
chasm_is_bridged = true;
}
} else {
print_default_message(iobj);
}
}
// Line 1300 in the original program
void attempt_show(Object iobj, Location loc)
{
if (iobj == RING && toting(RING) && loc == R_BASEMENT && !wizard_is_dead) {
putsn("The ring glows brightly. A lightning bolt strikes the wizard!");
putsn("A platinum chain lies before you.");
wizard_is_dead = true;
apport(CHAIN, loc);
apport(WIZARD, R_LIMBO);
} else {
print_default_message(iobj);
}
}
// Line 1400 in the original program
Location attempt_read(Object iobj, Location loc)
{
if (iobj != MESSAGE && iobj != SIGN && iobj != BOOK) {
putsn("I don't understand.");
} else if (loc == R_HALL2 && iobj == MESSAGE) {
putsn("\"Merlin was here.\"");
} else if (loc == R_TREE && iobj == MESSAGE) {
putsn("\"The great Almazar bids you well. Though you will encounter many" SOFT_NL
"trials, he shall provide for you. He that is both water and flame" SOFT_NL
"shall send you a gift to aid you in your quest. Thus saith" SOFT_NL
"Almazar: 'Live, and you shall live.'\"");
} else if (loc == R_RIVER && iobj == SIGN) {
putsn("\"Fish from the Amazon.\"");
} else if (loc == R_WELCOME && (iobj == MESSAGE || iobj == SIGN)) {
// The original game didn't accept "READ SIGN" here, only "READ MESSAGE".
putsn("\"Discretion will prevent transgression.\"");
} else if (loc == R_LIBRARY && iobj == BOOK) {
if (there(OPEN_WINDOW, loc)) {
putsn("A small axe flies through the window and strikes you dead.");
return death();
} else {
putsn("\"And so it came to pass that in the third day of the seventh" SOFT_NL
"month of the twenty-first year a great event happened. The earth" SOFT_NL
"opened and took within it the fruits of the people's labor and" SOFT_NL
"gave upon them a greater glory.\"");
}
} else if (loc == R_OUTHOUSE && iobj == MESSAGE) {
bool collected_all_the_treasures = true;
for (Object x = DIAMOND; x <= FIGURINE; ++x) {
if (!there(x, R_VAULT)) collected_all_the_treasures = false;
}
if (collected_all_the_treasures && toting(RING)) {
putsn("In a blaze of glory you find yourself in a land far away!");
final_score_and_exit(true);
} else {
putsn("\"Frodo lives!\"");
}
} else {
putsn("I don't see it here.");
}
return loc;
}
// Line 1500 in the original program
void attempt_fill(Object iobj, Location loc)
{
if (iobj == LAMP) {
if (!toting(LAMP)) {
putsn("You don't have a lamp.");
} else if (loc != R_OIL) {
putsn("There is nothing to fill it with.");
} else {
attempt_get(OIL, loc);
}
} else if (iobj == BOTTLE) {
if (!toting(SPICES) && !toting(BOTTLE) && !toting(WATER_BOTTLE)) {
putsn("You're not carrying a bottle.");
} else if (!has_river(loc)) {
putsn("There is nothing to fill it with.");
} else {
attempt_get(WATER, loc);
}
} else {
putsn("I don't understand.");
}
}
// Line 1600 in the original program
void attempt_light(Object iobj, Location loc)
{
if (iobj == LAMP) {
if (!toting(LAMP)) {
putsn("You're not carrying it.");
} else if (lamp_is_on) {
putsn("The lamp is already lit.");
} else if (lamp_counter <= 0) {
putsn("You cannot light an empty oil lamp.");
} else if (!toting(MATCHES)) {
putsn("You don't have any matches.");
} else {
putsn("OK.");
lamp_is_on = true;
darkness_counter = 0;
}
} else if (iobj == INCENSE) {
if (!toting(INCENSE)) {
putsn("You're not carrying it.");
} else if (!toting(MATCHES)) {
putsn("You don't have any matches.");
} else {
apport(INCENSE, R_LIMBO);
if (loc == R_IDOL) {
putsn("An emerald eye falls to the ground.");
apport(EYE_IN_PLACE, R_LIMBO);
apport(EYE, loc);
} else {
putsn("OK.");
}
}
} else {
putsn("I don't understand.");
}
}
// Line 1700 in the original program
Location attempt_kill(Object iobj, Location loc)
{
if (iobj == SNAKE || iobj == WIZARD || iobj == GNOME || iobj == BALL) {
if (!there(iobj, loc)) {
putsn("I don't see it here.");
} else if (!yes("With what, your bare hands?")) {
putsn("Nothing happens.");
} else if (iobj == SNAKE) {
putsn("The snake severs your hand. You have been poisoned.");
return death();
} else if (iobj == WIZARD) {
putsn("The wizard raises his hand and in an instant you find yourself" SOFT_NL
"uncomfortably hot. As you look up into the sky you see a large" SOFT_NL
"stone idol. You are being offered as a sacrifice.");
return death();
} else if (iobj == GNOME) {
putsn("The gnome is too fast for you.");
} else {
assert(iobj == BALL);
putsn("Eech! Your hands just turned into a bloody mess.");
}
} else {
putsn("I don't understand.");
}
return loc;
}
// Line 1800 in the original program
Location attempt_kick(Object iobj, Location loc)
{
if (iobj == BALL) {
if (there(BALL, loc)) {
putsn("Ouch! Every bone in your foot just broke.");
} else {
putsn("I don't see it here.");
}
} else if (iobj == WIZARD) {
putsn("The wizard raises his hand and in an instant you find yourself" SOFT_NL
"uncomfortably hot. As you look up into the sky you see a large" SOFT_NL
"stone idol. You are being offered as a sacrifice.");
wizard_counter = 0;
return death();
} else if (!is_portable(iobj)) {
putsn("I don't understand.");
} else if (iobj == FIGURINE && toting(FIGURINE)) {
// The original game allowed KICK FIGURINE to safely drop the figurine sans hay.
putsn("The delicate figurine breaks upon hitting the ground.");
apport(FIGURINE, R_LIMBO);
} else {
if (toting(iobj)) {
apport(iobj, loc);
putsn("OK.");
} else if (there(iobj, loc)) {
putsn("You're not carrying it.");
} else {
putsn("I don't see it here.");
}
}
return loc;
}
// Line 1900 in the original program
void attempt_break(Object iobj, Location loc)
{
if (iobj == BALL) {
if (there(BALL, loc)) {
attempt_kill(BALL, loc);
} else {
putsn("I don't see it here.");
}
} else if (iobj == FIGURINE && toting(FIGURINE)) {
putsn("The delicate figurine breaks upon hitting the ground.");
apport(FIGURINE, R_LIMBO);
} else if (iobj == BOTTLE && toting(BOTTLE)) {
putsn("The bottle breaks on impact.");
apport(BOTTLE, R_LIMBO);
} else if (iobj == BOTTLE && toting(WATER_BOTTLE)) {
putsn("The bottle breaks on impact.");
apport(WATER_BOTTLE, R_LIMBO);
} else if ((iobj == BOTTLE || iobj == SPICES) && toting(SPICES)) {
putsn("The bottle breaks on impact.");
putsn("A sudden wind blows from behind and scatters the spices to the" SOFT_NL
"four corners of the earth.");
apport(SPICES, R_LIMBO);
} else {
print_default_message(iobj);
}
}
// Line 2000 in the original program
void attempt_toss(Object iobj, Location loc)
{
if (iobj == BOTTLE || iobj == SPICES) {
attempt_break(iobj, loc);
} else if (iobj == DAGGER && toting(DAGGER) && there(GNOME, loc)) {
int p = ran(100) - burden();
if (p > 40) {
putsn("You killed a nasty knife-throwing gnome!");
apport(GNOME, R_LIMBO);
} else {
putsn("You missed! You ought to get your eyes examined.");
}
apport(DAGGER, loc);
} else {
attempt_drop(iobj, loc);
}
}
// Line 2100 in the original program
Location attempt_eat(Object iobj, Location loc)
{
if (iobj == MOUSE && toting(MOUSE)) {
putsn("Yuck! The mouse was used for carcinogenic testing. You're dead.");
apport(MOUSE, R_LIMBO);
return death();
}
if (iobj == SPICES && (there(SPICES, loc) || toting(SPICES))) {
putsn("Whew! That's strong stuff!");
apport(BOTTLE, object_position[SPICES]);
apport(SPICES, R_LIMBO);
} else if (iobj == SPICES && there(SPICES_IN_PLACE, loc)) {
putsn("Whew! That's strong stuff!");
apport(SPICES_IN_PLACE, R_LIMBO);
} else if (iobj == CHEESE && (there(CHEESE, loc) || toting(CHEESE))) {
putsn("The cheese was stale, but you managed to consume the entire box.");
apport(CHEESE, R_LIMBO);
} else if (iobj == MOUSE && there(MOUSE, loc)) {
putsn("The mouse runs away.");
apport(MOUSE, R_LIMBO);
} else {
putsn("The only thing edible here is you!");
}
return loc;
}
// Line 2200 in the original program
void attempt_drink(Object iobj, Location loc)
{
if (iobj == WATER) {
if (toting(WATER_BOTTLE)) {
putsn("Eech! What lousy-tasting water.");
apport(WATER_BOTTLE, R_LIMBO);
apport(BOTTLE, -1);
} else if (has_river(loc)) {
putsn("Eech! What lousy-tasting water.");
} else {
putsn("There's no water within reach.");
}
} else {
putsn("I don't understand.");
}
}
// Line 2300 in the original program
void attempt_feed(Object iobj, Location loc)
{
if (iobj == MOUSE) {
if (!there(MOUSE, loc)) {
putsn("I don't see it here.");
} else if (!toting(CHEESE)) {
putsn("The only thing edible here is you!");
} else {
putsn("OK.");
mouse_is_fed = true;
}
} else if (iobj == SNAKE) {
if (!there(SNAKE, loc)) {
puts("I don't see it here.");
} else if (!toting(MOUSE)) {
puts("The only thing edible here is you!");
} else {
putsn("The mouse was used for carcinogenic testing. The snake is dead.");
putsn("A golden apple hangs by an apple tree.");
apport(MOUSE, R_LIMBO);
apport(SNAKE, R_LIMBO);
apport(APPLE, loc);
}
} else {
putsn("I don't understand.");
}
}
// Line 2400 in the original program
void attempt_turn(Object iobj, Location loc)
{
if (iobj == HEAD && loc == R_LIVING) {
if (there(OPEN_PANEL, loc)) {
putsn("The panel closes and seals the passage.");
apport(OPEN_PANEL, R_LIMBO);
} else {
putsn("A panel slides open, revealing a passage to the north.");
apport(OPEN_PANEL, loc);
}