1 /* $NetBSD: object.c,v 1.14 2008/02/04 01:07:01 dholland Exp $ */
3 /* object.c Larn is copyrighted 1986 by Noah Morgan. */
7 __RCSID("$NetBSD: object.c,v 1.14 2008/02/04 01:07:01 dholland Exp $");
12 static void finditem(int);
13 static void ostairs(int);
14 static void opotion(int);
15 static void oscroll(int);
16 static void oorb(void);
17 static void opit(void);
18 static void obottomless(void);
19 static void oelevator(int);
20 static void ostatue(void);
21 static void omirror(void);
22 static void obook(void);
23 static void ocookie(void);
24 static void ogold(int);
25 static void ohome(void);
30 subroutine to look for an object and give the player his options
31 if an object was found.
38 return; /* can't find objects if time is stopped */
39 i
= item
[playerx
][playery
];
42 showcell(playerx
, playery
);
50 lprcat("\n\nYou have found some gold!");
55 lprcat("\n\nYou have found a magic potion");
56 i
= iarg
[playerx
][playery
];
57 if (potionname
[i
][0] != 0)
58 lprintf(" of%s", potionname
[i
]);
63 lprcat("\n\nYou have found a magic scroll");
64 i
= iarg
[playerx
][playery
];
65 if (scrollname
[i
][0] != 0)
66 lprintf(" of%s", scrollname
[i
]);
73 lprcat("\n\nThere is a Holy Altar here!");
78 lprcat("\n\nYou have found a book.");
83 lprcat("\n\nYou have found a fortune cookie.");
90 lprintf("\n\nThere is %s here!", objectname
[i
]);
97 lprintf("\n\nThere is %s here!", objectname
[i
]);
102 lprintf("\n\nThere is %s here!", objectname
[i
]);
107 lprcat("\n\nYou have found the Orb!!!!!");
112 lprcat("\n\nYou're standing at the top of a pit.");
117 lprcat("\n\nThere is a circular staircase here");
122 lprcat("\n\nYou feel heavy for a moment, but the feeling disappears");
123 oelevator(1); /* up */
129 lprcat("\n\nThere is a fountain here");
136 lprcat("\n\nYou are standing in front of a statue");
141 lprcat("\n\nThere is a chest here");
148 item
[playerx
][playery
] = OTELEPORTER
;
149 know
[playerx
][playery
] = 1;
152 lprcat("\nZaaaappp! You've been teleported!\n");
161 lprcat("\n\nYou have found the College of Larn.");
162 lprcat("\nDo you (g) go inside, or (i) stay here? ");
164 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
167 oschool(); /* the college of larn */
169 lprcat(" stay here");
175 lprcat("\n\nThere is a mirror here");
184 lprcat("\n\nYou have found the bank of Larn.");
186 lprcat("\n\nYou have found a branch office of the bank of Larn.");
187 lprcat("\nDo you (g) go inside, or (i) stay here? ");
189 while ((j
!= 'g') && (j
!= 'i') && (j
!= '\33'))
195 obank2(); /* the bank of larn */
197 lprcat(" stay here");
203 lprcat("\n\nThere is a dead fountain here");
209 lprcat("\n\nThere is a DND store here.");
210 lprcat("\nDo you (g) go inside, or (i) stay here? ");
212 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
215 dndstore(); /* the dnd adventurers store */
217 lprcat(" stay here");
221 lprcat("\n\nThere is a circular staircase here");
222 ostairs(-1); /* down */
226 lprcat("\n\nYou feel light for a moment, but the feeling disappears");
227 oelevator(-1); /* down */
231 lprintf("\n\nYou have found %s", objectname
[i
]);
232 lprcat("\nDo you (c) close it");
235 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
237 if ((i
== '\33') || (i
== 'i')) {
243 item
[playerx
][playery
] = OCLOSEDDOOR
;
244 iarg
[playerx
][playery
] = 0;
250 lprintf("\n\nYou have found %s", objectname
[i
]);
251 lprcat("\nDo you (o) try to open it");
254 while ((i
!= 'o') && (i
!= 'i') && (i
!= '\33'))
256 if ((i
== '\33') || (i
== 'i')) {
264 switch (iarg
[playerx
][playery
]) {
266 c
[AGGRAVATE
] += rnd(400);
270 lprcat("\nYou are jolted by an electric shock ");
281 lprcat("\nYou suddenly feel weaker ");
294 item
[playerx
][playery
] = OOPENDOOR
;
300 lprcat("\nYou have found ");
301 lprcat(objectname
[OENTRANCE
]);
302 lprcat("\nDo you (g) go inside");
305 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
311 item
[33][MAXY
- 1] = know
[33][MAXY
- 1] = mitem
[33][MAXY
- 1] = 0;
312 draws(0, MAXX
, 0, MAXY
);
320 lprcat("\nYou have found ");
321 lprcat(objectname
[OVOLDOWN
]);
322 lprcat("\nDo you (c) climb down");
325 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
327 if ((i
== '\33') || (i
== 'i')) {
332 lprcat("\nThe shaft only extends 5 feet downward!");
335 if (packweight() > 45 + 3 * (c
[STRENGTH
] + c
[STREXTRA
])) {
336 lprcat("\nYou slip and fall down the shaft");
339 losehp(30 + rnd(20));
342 lprcat("climb down");
344 newcavelevel(MAXLEVEL
);
345 for (i
= 0; i
< MAXY
; i
++)
346 for (j
= 0; j
< MAXX
; j
++) /* put player near
348 if (item
[j
][i
] == OVOLUP
) {
355 draws(0, MAXX
, 0, MAXY
);
360 lprcat("\nYou have found ");
361 lprcat(objectname
[OVOLUP
]);
362 lprcat("\nDo you (c) climb up");
365 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
367 if ((i
== '\33') || (i
== 'i')) {
372 lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!");
375 if (packweight() > 45 + 5 * (c
[STRENGTH
] + c
[STREXTRA
])) {
376 lprcat("\nYou slip and fall down the shaft");
379 losehp(15 + rnd(20));
387 for (i
= 0; i
< MAXY
; i
++)
388 for (j
= 0; j
< MAXX
; j
++) /* put player near
390 if (item
[j
][i
] == OVOLDOWN
) {
397 draws(0, MAXX
, 0, MAXY
);
403 return; /* for an arrow trap */
404 item
[playerx
][playery
] = OTRAPARROW
;
405 know
[playerx
][playery
] = 0;
408 lprcat("\nYou are hit by an arrow");
409 beep(); /* for an arrow trap */
411 losehp(rnd(10) + level
);
417 return; /* for a dart trap */
418 item
[playerx
][playery
] = ODARTRAP
;
419 know
[playerx
][playery
] = 0;
422 lprcat("\nYou are hit by a dart");
423 beep(); /* for a dart trap */
426 if ((--c
[STRENGTH
]) < 3)
433 return; /* for a trap door */
434 item
[playerx
][playery
] = OTRAPDOOR
;
435 know
[playerx
][playery
] = 1;
438 lastnum
= 272; /* a trap door */
439 if ((level
== MAXLEVEL
- 1) || (level
== MAXLEVEL
+ MAXVLEVEL
- 1)) {
440 lprcat("\nYou fell through a bottomless trap door!");
445 lprcat("\nYou fall through a trap door!");
446 beep(); /* for a trap door */
447 losehp(rnd(5 + level
));
449 newcavelevel(level
+ 1);
450 draws(0, MAXX
, 0, MAXY
);
458 lprcat("\nYou have found the Larn trading Post.");
459 lprcat("\nDo you (g) go inside, or (i) stay here? ");
461 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
472 lprcat("\nYou have found your way home.");
473 lprcat("\nDo you (g) go inside, or (i) stay here? ");
475 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
488 return; /* annihilated by sphere of annihilation */
493 lprcat("\n\nThere is an LRS office here.");
494 lprcat("\nDo you (g) go inside, or (i) stay here? ");
496 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
499 olrs(); /* the larn revenue service */
501 lprcat(" stay here");
511 function to say what object we found and ask if player wants to take it
514 finditem(int theitem
)
517 lprintf("\n\nYou have found %s ", objectname
[theitem
]);
518 tmp
= iarg
[playerx
][playery
];
532 lprintf("+ %ld", (long) tmp
);
534 lprintf(" %ld", (long) tmp
);
536 lprcat("\nDo you want to (t) take it");
539 while (i
!= 't' && i
!= 'i' && i
!= '\33')
543 if (take(theitem
, tmp
) == 0)
553 subroutine to process the stair cases
554 if dir > 0 the up else down
561 lprcat("\nDo you (s) stay here ");
563 lprcat("(u) go up ");
565 lprcat("(d) go down ");
566 lprcat("or (f) kick stairs? ");
577 lprcat("kick stairs");
579 lprcat("\nI hope you feel better. Showing anger rids you of frustration.");
581 k
= rnd((level
+ 1) << 1);
582 lprintf("\nYou hurt your foot dumb dumb! You suffer %ld hit points", (long) k
);
592 lprcat("\nThe stairs don't go up!");
593 else if (level
>= 2 && level
!= 11) {
595 newcavelevel(level
- 1);
596 draws(0, MAXX
, 0, MAXY
);
599 lprcat("\nThe stairs lead to a dead end!");
605 lprcat("\nThe stairs don't go down!");
606 else if (level
!= 0 && level
!= 10 && level
!= 13) {
608 newcavelevel(level
+ 1);
609 draws(0, MAXX
, 0, MAXY
);
612 lprcat("\nThe stairs lead to a dead end!");
620 subroutine to handle a teleport trap +/- 1 level maximum
629 died(264); /* stuck in a rock */
630 c
[TELEFLAG
] = 1; /* show ?? on bottomline if been teleported */
633 else if (level
< MAXLEVEL
) {
634 tmp
= rnd(5) + level
- 3;
640 tmp
= rnd(3) + level
- 2;
641 if (tmp
>= MAXLEVEL
+ MAXVLEVEL
)
642 tmp
= MAXLEVEL
+ MAXVLEVEL
- 1;
646 playerx
= rnd(MAXX
- 2);
647 playery
= rnd(MAXY
- 2);
651 draws(0, MAXX
, 0, MAXY
);
657 function to process a potion
663 lprcat("\nDo you (d) drink it, (t) take it");
674 forget(); /* destroy potion */
680 if (take(OPOTION
, pot
) == 0)
687 function to drink a potion
694 if (pot
< 0 || pot
>= MAXPOTION
)
695 return; /* check for within bounds */
696 potionname
[pot
] = potionhide
[pot
];
699 lprcat("\nYou feel greedy . . .");
701 for (i
= 0; i
< MAXY
; i
++)
702 for (j
= 0; j
< MAXX
; j
++)
703 if ((item
[j
][i
] == OGOLDPILE
) || (item
[j
][i
] == OMAXGOLD
)) {
711 lprcat("\nYou feel greedy . . .");
713 for (i
= 0; i
< MAXY
; i
++)
714 for (j
= 0; j
< MAXX
; j
++) {
716 if ((k
== ODIAMOND
) || (k
== ORUBY
) || (k
== OEMERALD
) || (k
== OMAXGOLD
)
717 || (k
== OSAPPHIRE
) || (k
== OLARNEYE
) || (k
== OGOLDPILE
)) {
727 break; /* instant healing */
730 lprcat("\nYou feel better");
731 if (c
[HP
] == c
[HPMAX
])
733 else if ((c
[HP
] += rnd(20) + 20 + c
[LEVEL
]) > c
[HPMAX
])
738 lprcat("\nSuddenly, you feel much more skillful!");
744 lprcat("\nYou feel strange for a moment");
749 lprcat("\nYou feel more self confident!");
754 lprcat("\nWow! You feel great!");
755 if (c
[STRENGTH
] < 12)
762 lprcat("\nYour charm went up by one!");
767 lprcat("\nYour intelligence went up by one!");
772 for (i
= 0; i
< MAXY
; i
++)
773 for (j
= 0; j
< MAXX
; j
++)
778 /* monster detection */ return;
781 lprcat("\nThis potion has no taste to it");
785 lprcat("\nWOW!!! You feel Super-fantastic!!!");
787 for (i
= 0; i
< 6; i
++)
793 lprcat("\nYou have a greater intestinal constitude!");
798 lprcat("\nYou now have incredibly bulging muscles!!!");
799 if (c
[GIANTSTR
] == 0)
805 lprcat("\nYou feel a chill run up your spine!");
806 c
[FIRERESISTANCE
] += 1000;
810 lprcat("\nYou fall asleep. . .");
811 i
= rnd(11) - (c
[CONSTITUTION
] >> 2) + 2;
817 lprcat("\nYou woke up!");
821 lprcat("\nYou become dizzy!");
822 if (--c
[STRENGTH
] < 3)
827 lprcat("\nYou stagger for a moment . .");
828 for (i
= 0; i
< MAXY
; i
++)
829 for (j
= 0; j
< MAXX
; j
++)
832 draws(0, MAXX
, 0, MAXY
); /* potion of forgetfulness */
836 lprcat("\nYou can't see anything!"); /* blindness */
837 c
[BLINDCOUNT
] += 500;
841 lprcat("\nYou feel confused");
842 c
[CONFUSE
] += 20 + rnd(9);
846 lprcat("\nYou don't seem to be affected");
847 return; /* cure dianthroritis */
850 lprcat("\nYou feel a sickness engulf you"); /* poison */
851 c
[HALFDAM
] += 200 + rnd(200);
855 lprcat("\nYou feel your vision sharpen"); /* see invisible */
856 c
[SEEINVISIBLE
] += rnd(1000) + 400;
857 monstnamelist
[INVISIBLESTALKER
] = 'I';
860 bottomline(); /* show new stats */
866 function to process a magic scroll
873 if (c
[BLINDCOUNT
] == 0)
874 lprcat("(r) read it, ");
875 lprcat("(t) take it");
889 if (typ
== 2 || typ
== 15) {
890 show1cell(playerx
, playery
);
893 /* destroy it */ read_scroll(typ
);
898 if (take(OSCROLL
, typ
) == 0)
899 forget(); /* destroy it */
905 data for the function to read a scroll
907 static int xh
, yh
, yl
, xl
;
908 static u_char curse
[] = {
909 BLINDCOUNT
, CONFUSE
, AGGRAVATE
, HASTEMONST
, ITCHING
,
910 LAUGHING
, DRAINSTRENGTH
, CLUMSINESS
, INFEEBLEMENT
, HALFDAM
913 static u_char exten
[] = {
914 PROTECTIONTIME
, DEXCOUNT
, STRCOUNT
, CHARMCOUNT
, INVISIBILITY
,
915 CANCELLATION
, HASTESELF
, GLOBE
, SCAREMONST
, HOLDMONST
, TIMESTOP
918 static u_char time_change
[] = {
919 HASTESELF
, HERO
, ALTPRO
, PROTECTIONTIME
, DEXCOUNT
, STRCOUNT
,
920 GIANTSTR
, CHARMCOUNT
, INVISIBILITY
, CANCELLATION
, HASTESELF
,
921 AGGRAVATE
, SCAREMONST
, STEALTH
, AWARENESS
, HOLDMONST
,
922 HASTEMONST
, FIRERESISTANCE
, GLOBE
, SPIRITPRO
, UNDEADPRO
,
923 HALFDAM
, SEEINVISIBLE
, ITCHING
, CLUMSINESS
, WTW
927 * function to adjust time when time warping and taking courses in school
934 for (j
= 0; j
< 26; j
++)/* adjust time related parameters */
935 if (c
[time_change
[j
]])
936 if ((c
[time_change
[j
]] -= tim
) < 1)
937 c
[time_change
[j
]] = 1;
942 function to read a scroll
949 if (typ
< 0 || typ
>= MAXSCROLL
)
950 return; /* be sure we are within bounds */
951 scrollname
[typ
] = scrollhide
[typ
];
954 lprcat("\nYour armor glows for a moment");
959 lprcat("\nYour weapon glows for a moment");
961 return; /* enchant weapon */
964 lprcat("\nYou have been granted enlightenment!");
965 yh
= min(playery
+ 7, MAXY
);
966 xh
= min(playerx
+ 25, MAXX
);
967 yl
= max(playery
- 7, 0);
968 xl
= max(playerx
- 25, 0);
969 for (i
= yl
; i
< yh
; i
++)
970 for (j
= xl
; j
< xh
; j
++)
973 draws(xl
, xh
, yl
, yh
);
977 lprcat("\nThis scroll seems to be blank");
981 createmonster(makemonst(level
+ 1));
982 return; /* this one creates a monster */
985 something(level
); /* create artifact */
990 return; /* aggravate monsters */
993 gltime
+= (i
= rnd(1000) - 850); /* time warp */
995 lprintf("\nYou went forward in time by %ld mobuls", (long) ((i
+ 99) / 100));
997 lprintf("\nYou went backward in time by %ld mobuls", (long) (-(i
+ 99) / 100));
998 adjusttime((long) i
); /* adjust time for time warping */
1003 return; /* teleportation */
1006 c
[AWARENESS
] += 1800;
1007 return; /* expanded awareness */
1010 c
[HASTEMONST
] += rnd(55) + 12;
1011 return; /* haste monster */
1014 for (i
= 0; i
< MAXY
; i
++)
1015 for (j
= 0; j
< MAXX
; j
++)
1017 hitp
[j
][i
] = monster
[mitem
[j
][i
]].hitpoints
;
1018 return; /* monster healing */
1020 c
[SPIRITPRO
] += 300 + rnd(200);
1022 return; /* spirit protection */
1025 c
[UNDEADPRO
] += 300 + rnd(200);
1027 return; /* undead protection */
1030 c
[STEALTH
] += 250 + rnd(250);
1032 return; /* stealth */
1035 lprcat("\nYou have been granted enlightenment!"); /* magic mapping */
1036 for (i
= 0; i
< MAXY
; i
++)
1037 for (j
= 0; j
< MAXX
; j
++)
1040 draws(0, MAXX
, 0, MAXY
);
1046 return; /* hold monster */
1049 for (i
= 0; i
< 26; i
++) /* gem perfection */
1059 j
= 255; /* double value */
1066 for (i
= 0; i
< 11; i
++)
1067 c
[exten
[i
]] <<= 1; /* spell extension */
1071 for (i
= 0; i
< 26; i
++) { /* identify */
1072 if (iven
[i
] == OPOTION
)
1073 potionname
[ivenarg
[i
]] = potionhide
[ivenarg
[i
]];
1074 if (iven
[i
] == OSCROLL
)
1075 scrollname
[ivenarg
[i
]] = scrollhide
[ivenarg
[i
]];
1080 for (i
= 0; i
< 10; i
++) /* remove curse */
1087 break; /* scroll of annihilation */
1090 godirect(22, 150, "The ray hits the %s", 0, ' '); /* pulverization */
1094 break; /* life protection */
1109 if (rnd(101) < 81) {
1110 if (rnd(70) > 9 * c
[DEXTERITY
] - packweight() || rnd(101) < 5) {
1111 if (level
== MAXLEVEL
- 1)
1113 else if (level
== MAXLEVEL
+ MAXVLEVEL
- 1)
1116 if (rnd(101) < 20) {
1118 lprcat("\nYou fell into a pit! Your fall is cushioned by an unknown force\n");
1120 i
= rnd(level
* 3 + 3);
1121 lprintf("\nYou fell into a pit! You suffer %ld hit points damage", (long) i
);
1122 lastnum
= 261; /* if he dies scoreboard
1127 newcavelevel(level
+ 1);
1128 draws(0, MAXX
, 0, MAXY
);
1137 lprcat("\nYou fell into a bottomless pit!");
1167 lprcat("\nDo you ");
1168 if (c
[BLINDCOUNT
] == 0)
1169 lprcat("(r) read it, ");
1170 lprcat("(t) take it");
1173 switch (ttgetch()) {
1183 /* no more book */ readbook(iarg
[playerx
][playery
]);
1189 if (take(OBOOK
, iarg
[playerx
][playery
]) == 0)
1190 forget(); /* no more book */
1196 function to read a book
1204 i
= rund((tmp
= splev
[lev
]) ? tmp
: 1);
1206 i
= rnd((tmp
= splev
[lev
] - 9) ? tmp
: 1) + 9;
1208 lprintf("\nSpell \"%s\": %s\n%s", spelcode
[i
], spelname
[i
], speldescript
[i
]);
1210 lprcat("\nYour int went up by one!");
1221 lprcat("\nDo you (e) eat it, (t) take it");
1224 switch (ttgetch()) {
1231 lprcat("eat\nThe cookie tasted good.");
1232 forget(); /* no more cookie */
1235 if (!(p
= fortune()))
1237 lprcat(" A message inside the cookie reads:\n");
1243 if (take(OCOOKIE
, 0) == 0)
1244 forget(); /* no more book */
1251 * routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth
1259 i
= iarg
[playerx
][playery
];
1260 if (arg
== OMAXGOLD
)
1262 else if (arg
== OKGOLD
)
1264 else if (arg
== ODGOLD
)
1266 lprintf("\nIt is worth %ld!", (long) i
);
1269 item
[playerx
][playery
] = know
[playerx
][playery
] = 0; /* destroy gold */
1276 nosignal
= 1; /* disable signals */
1277 for (i
= 0; i
< 26; i
++)
1278 if (iven
[i
] == OPOTION
)
1279 if (ivenarg
[i
] == 21) {
1280 iven
[i
] = 0; /* remove the potion of cure
1281 * dianthroritis from
1284 lprcat("Congratulations. You found a potion of cure dianthroritis.\n");
1285 lprcat("\nFrankly, No one thought you could do it. Boy! Did you surprise them!\n");
1286 if (gltime
> TIMELIMIT
) {
1287 lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
1288 lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
1292 lprcat("\nThe doctor is now administering the potion, and in a few moments\n");
1293 lprcat("Your daughter should be well on her way to recovery.\n");
1295 lprcat("\nThe potion is");
1297 lprcat(" working! The doctor thinks that\n");
1298 lprcat("your daughter will recover in a few days. Congratulations!\n");
1306 lprintf("Welcome home %s. Latest word from the doctor is not good.\n", logname
);
1308 if (gltime
> TIMELIMIT
) {
1309 lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
1310 lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
1314 lprcat("\nThe diagnosis is confirmed as dianthroritis. He guesses that\n");
1315 lprintf("your daughter has only %ld mobuls left in this world. It's up to you,\n", (long) ((TIMELIMIT
- gltime
+ 99) / 100));
1316 lprintf("%s, to find the only hope for your daughter, the very rare\n", logname
);
1317 lprcat("potion of cure dianthroritis. It is rumored that only deep in the\n");
1318 lprcat("depths of the caves can this potion be found.\n\n\n");
1319 lprcat("\n ----- press ");
1321 lprcat(" to continue, ");
1323 lprcat(" to leave ----- ");
1325 while (i
!= '\33' && i
!= '\n')
1329 nosignal
= 0; /* enable signals */
1335 /* routine to save program space */
1339 lprcat(", or (i) ignore it? ");