]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/object.c
1 /* $NetBSD: object.c,v 1.16 2012/06/19 05:30:43 dholland Exp $ */
3 /* object.c Larn is copyrighted 1986 by Noah Morgan. */
7 __RCSID("$NetBSD: object.c,v 1.16 2012/06/19 05:30:43 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
560 lprcat("\nDo you (s) stay here ");
562 lprcat("(u) go up ");
564 lprcat("(d) go down ");
565 lprcat("or (f) kick stairs? ");
576 lprcat("kick stairs");
578 lprcat("\nI hope you feel better. Showing anger rids you of frustration.");
580 k
= rnd((level
+ 1) << 1);
581 lprintf("\nYou hurt your foot dumb dumb! You suffer %ld hit points", (long) k
);
591 lprcat("\nThe stairs don't go up!");
592 else if (level
>= 2 && level
!= 11) {
594 newcavelevel(level
- 1);
595 draws(0, MAXX
, 0, MAXY
);
598 lprcat("\nThe stairs lead to a dead end!");
604 lprcat("\nThe stairs don't go down!");
605 else if (level
!= 0 && level
!= 10 && level
!= 13) {
607 newcavelevel(level
+ 1);
608 draws(0, MAXX
, 0, MAXY
);
611 lprcat("\nThe stairs lead to a dead end!");
619 subroutine to handle a teleport trap +/- 1 level maximum
627 died(264); /* stuck in a rock */
628 c
[TELEFLAG
] = 1; /* show ?? on bottomline if been teleported */
631 else if (level
< MAXLEVEL
) {
632 tmp
= rnd(5) + level
- 3;
638 tmp
= rnd(3) + level
- 2;
639 if (tmp
>= MAXLEVEL
+ MAXVLEVEL
)
640 tmp
= MAXLEVEL
+ MAXVLEVEL
- 1;
644 playerx
= rnd(MAXX
- 2);
645 playery
= rnd(MAXY
- 2);
649 draws(0, MAXX
, 0, MAXY
);
655 function to process a potion
660 lprcat("\nDo you (d) drink it, (t) take it");
671 forget(); /* destroy potion */
677 if (take(OPOTION
, pot
) == 0)
684 function to drink a potion
690 if (pot
< 0 || pot
>= MAXPOTION
)
691 return; /* check for within bounds */
692 potionname
[pot
] = potionhide
[pot
];
695 lprcat("\nYou feel greedy . . .");
697 for (i
= 0; i
< MAXY
; i
++)
698 for (j
= 0; j
< MAXX
; j
++)
699 if ((item
[j
][i
] == OGOLDPILE
) || (item
[j
][i
] == OMAXGOLD
)) {
707 lprcat("\nYou feel greedy . . .");
709 for (i
= 0; i
< MAXY
; i
++)
710 for (j
= 0; j
< MAXX
; j
++) {
712 if ((k
== ODIAMOND
) || (k
== ORUBY
) || (k
== OEMERALD
) || (k
== OMAXGOLD
)
713 || (k
== OSAPPHIRE
) || (k
== OLARNEYE
) || (k
== OGOLDPILE
)) {
723 break; /* instant healing */
726 lprcat("\nYou feel better");
727 if (c
[HP
] == c
[HPMAX
])
729 else if ((c
[HP
] += rnd(20) + 20 + c
[LEVEL
]) > c
[HPMAX
])
734 lprcat("\nSuddenly, you feel much more skillful!");
740 lprcat("\nYou feel strange for a moment");
745 lprcat("\nYou feel more self confident!");
750 lprcat("\nWow! You feel great!");
751 if (c
[STRENGTH
] < 12)
758 lprcat("\nYour charm went up by one!");
763 lprcat("\nYour intelligence went up by one!");
768 for (i
= 0; i
< MAXY
; i
++)
769 for (j
= 0; j
< MAXX
; j
++)
774 /* monster detection */ return;
777 lprcat("\nThis potion has no taste to it");
781 lprcat("\nWOW!!! You feel Super-fantastic!!!");
783 for (i
= 0; i
< 6; i
++)
789 lprcat("\nYou have a greater intestinal constitude!");
794 lprcat("\nYou now have incredibly bulging muscles!!!");
795 if (c
[GIANTSTR
] == 0)
801 lprcat("\nYou feel a chill run up your spine!");
802 c
[FIRERESISTANCE
] += 1000;
806 lprcat("\nYou fall asleep. . .");
807 i
= rnd(11) - (c
[CONSTITUTION
] >> 2) + 2;
813 lprcat("\nYou woke up!");
817 lprcat("\nYou become dizzy!");
818 if (--c
[STRENGTH
] < 3)
823 lprcat("\nYou stagger for a moment . .");
824 for (i
= 0; i
< MAXY
; i
++)
825 for (j
= 0; j
< MAXX
; j
++)
828 draws(0, MAXX
, 0, MAXY
); /* potion of forgetfulness */
832 lprcat("\nYou can't see anything!"); /* blindness */
833 c
[BLINDCOUNT
] += 500;
837 lprcat("\nYou feel confused");
838 c
[CONFUSE
] += 20 + rnd(9);
842 lprcat("\nYou don't seem to be affected");
843 return; /* cure dianthroritis */
846 lprcat("\nYou feel a sickness engulf you"); /* poison */
847 c
[HALFDAM
] += 200 + rnd(200);
851 lprcat("\nYou feel your vision sharpen"); /* see invisible */
852 c
[SEEINVISIBLE
] += rnd(1000) + 400;
853 monstnamelist
[INVISIBLESTALKER
] = 'I';
856 bottomline(); /* show new stats */
862 function to process a magic scroll
868 if (c
[BLINDCOUNT
] == 0)
869 lprcat("(r) read it, ");
870 lprcat("(t) take it");
884 if (typ
== 2 || typ
== 15) {
885 show1cell(playerx
, playery
);
888 /* destroy it */ read_scroll(typ
);
893 if (take(OSCROLL
, typ
) == 0)
894 forget(); /* destroy it */
900 data for the function to read a scroll
902 static int xh
, yh
, yl
, xl
;
903 static u_char curse
[] = {
904 BLINDCOUNT
, CONFUSE
, AGGRAVATE
, HASTEMONST
, ITCHING
,
905 LAUGHING
, DRAINSTRENGTH
, CLUMSINESS
, INFEEBLEMENT
, HALFDAM
908 static u_char exten
[] = {
909 PROTECTIONTIME
, DEXCOUNT
, STRCOUNT
, CHARMCOUNT
, INVISIBILITY
,
910 CANCELLATION
, HASTESELF
, GLOBE
, SCAREMONST
, HOLDMONST
, TIMESTOP
913 static u_char time_change
[] = {
914 HASTESELF
, HERO
, ALTPRO
, PROTECTIONTIME
, DEXCOUNT
, STRCOUNT
,
915 GIANTSTR
, CHARMCOUNT
, INVISIBILITY
, CANCELLATION
, HASTESELF
,
916 AGGRAVATE
, SCAREMONST
, STEALTH
, AWARENESS
, HOLDMONST
,
917 HASTEMONST
, FIRERESISTANCE
, GLOBE
, SPIRITPRO
, UNDEADPRO
,
918 HALFDAM
, SEEINVISIBLE
, ITCHING
, CLUMSINESS
, WTW
922 * function to adjust time when time warping and taking courses in school
928 for (j
= 0; j
< 26; j
++)/* adjust time related parameters */
929 if (c
[time_change
[j
]])
930 if ((c
[time_change
[j
]] -= tim
) < 1)
931 c
[time_change
[j
]] = 1;
936 function to read a scroll
942 if (typ
< 0 || typ
>= MAXSCROLL
)
943 return; /* be sure we are within bounds */
944 scrollname
[typ
] = scrollhide
[typ
];
947 lprcat("\nYour armor glows for a moment");
952 lprcat("\nYour weapon glows for a moment");
954 return; /* enchant weapon */
957 lprcat("\nYou have been granted enlightenment!");
958 yh
= min(playery
+ 7, MAXY
);
959 xh
= min(playerx
+ 25, MAXX
);
960 yl
= max(playery
- 7, 0);
961 xl
= max(playerx
- 25, 0);
962 for (i
= yl
; i
< yh
; i
++)
963 for (j
= xl
; j
< xh
; j
++)
966 draws(xl
, xh
, yl
, yh
);
970 lprcat("\nThis scroll seems to be blank");
974 createmonster(makemonst(level
+ 1));
975 return; /* this one creates a monster */
978 something(level
); /* create artifact */
983 return; /* aggravate monsters */
986 gltime
+= (i
= rnd(1000) - 850); /* time warp */
988 lprintf("\nYou went forward in time by %ld mobuls", (long) ((i
+ 99) / 100));
990 lprintf("\nYou went backward in time by %ld mobuls", (long) (-(i
+ 99) / 100));
991 adjusttime((long) i
); /* adjust time for time warping */
996 return; /* teleportation */
999 c
[AWARENESS
] += 1800;
1000 return; /* expanded awareness */
1003 c
[HASTEMONST
] += rnd(55) + 12;
1004 return; /* haste monster */
1007 for (i
= 0; i
< MAXY
; i
++)
1008 for (j
= 0; j
< MAXX
; j
++)
1010 hitp
[j
][i
] = monster
[mitem
[j
][i
]].hitpoints
;
1011 return; /* monster healing */
1013 c
[SPIRITPRO
] += 300 + rnd(200);
1015 return; /* spirit protection */
1018 c
[UNDEADPRO
] += 300 + rnd(200);
1020 return; /* undead protection */
1023 c
[STEALTH
] += 250 + rnd(250);
1025 return; /* stealth */
1028 lprcat("\nYou have been granted enlightenment!"); /* magic mapping */
1029 for (i
= 0; i
< MAXY
; i
++)
1030 for (j
= 0; j
< MAXX
; j
++)
1033 draws(0, MAXX
, 0, MAXY
);
1039 return; /* hold monster */
1042 for (i
= 0; i
< 26; i
++) /* gem perfection */
1052 j
= 255; /* double value */
1059 for (i
= 0; i
< 11; i
++)
1060 c
[exten
[i
]] <<= 1; /* spell extension */
1064 for (i
= 0; i
< 26; i
++) { /* identify */
1065 if (iven
[i
] == OPOTION
)
1066 potionname
[ivenarg
[i
]] = potionhide
[ivenarg
[i
]];
1067 if (iven
[i
] == OSCROLL
)
1068 scrollname
[ivenarg
[i
]] = scrollhide
[ivenarg
[i
]];
1073 for (i
= 0; i
< 10; i
++) /* remove curse */
1080 break; /* scroll of annihilation */
1083 godirect(22, 150, "The ray hits the %s", 0, ' '); /* pulverization */
1087 break; /* life protection */
1102 if (rnd(101) < 81) {
1103 if (rnd(70) > 9 * c
[DEXTERITY
] - packweight() || rnd(101) < 5) {
1104 if (level
== MAXLEVEL
- 1)
1106 else if (level
== MAXLEVEL
+ MAXVLEVEL
- 1)
1109 if (rnd(101) < 20) {
1111 lprcat("\nYou fell into a pit! Your fall is cushioned by an unknown force\n");
1113 i
= rnd(level
* 3 + 3);
1114 lprintf("\nYou fell into a pit! You suffer %ld hit points damage", (long) i
);
1115 lastnum
= 261; /* if he dies scoreboard
1120 newcavelevel(level
+ 1);
1121 draws(0, MAXX
, 0, MAXY
);
1130 lprcat("\nYou fell into a bottomless pit!");
1159 lprcat("\nDo you ");
1160 if (c
[BLINDCOUNT
] == 0)
1161 lprcat("(r) read it, ");
1162 lprcat("(t) take it");
1165 switch (ttgetch()) {
1175 /* no more book */ readbook(iarg
[playerx
][playery
]);
1181 if (take(OBOOK
, iarg
[playerx
][playery
]) == 0)
1182 forget(); /* no more book */
1188 function to read a book
1195 i
= rund((tmp
= splev
[lev
]) ? tmp
: 1);
1197 i
= rnd((tmp
= splev
[lev
] - 9) ? tmp
: 1) + 9;
1199 lprintf("\nSpell \"%s\": %s\n%s", spelcode
[i
], spelname
[i
], speldescript
[i
]);
1201 lprcat("\nYour int went up by one!");
1212 lprcat("\nDo you (e) eat it, (t) take it");
1215 switch (ttgetch()) {
1222 lprcat("eat\nThe cookie tasted good.");
1223 forget(); /* no more cookie */
1226 if (!(p
= fortune()))
1228 lprcat(" A message inside the cookie reads:\n");
1234 if (take(OCOOKIE
, 0) == 0)
1235 forget(); /* no more book */
1242 * routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth
1249 i
= iarg
[playerx
][playery
];
1250 if (arg
== OMAXGOLD
)
1252 else if (arg
== OKGOLD
)
1254 else if (arg
== ODGOLD
)
1256 lprintf("\nIt is worth %ld!", (long) i
);
1259 item
[playerx
][playery
] = know
[playerx
][playery
] = 0; /* destroy gold */
1266 nosignal
= 1; /* disable signals */
1267 for (i
= 0; i
< 26; i
++)
1268 if (iven
[i
] == OPOTION
)
1269 if (ivenarg
[i
] == 21) {
1270 iven
[i
] = 0; /* remove the potion of cure
1271 * dianthroritis from
1274 lprcat("Congratulations. You found a potion of cure dianthroritis.\n");
1275 lprcat("\nFrankly, No one thought you could do it. Boy! Did you surprise them!\n");
1276 if (gltime
> TIMELIMIT
) {
1277 lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
1278 lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
1282 lprcat("\nThe doctor is now administering the potion, and in a few moments\n");
1283 lprcat("Your daughter should be well on her way to recovery.\n");
1285 lprcat("\nThe potion is");
1287 lprcat(" working! The doctor thinks that\n");
1288 lprcat("your daughter will recover in a few days. Congratulations!\n");
1296 lprintf("Welcome home %s. Latest word from the doctor is not good.\n", logname
);
1298 if (gltime
> TIMELIMIT
) {
1299 lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
1300 lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
1304 lprcat("\nThe diagnosis is confirmed as dianthroritis. He guesses that\n");
1305 lprintf("your daughter has only %ld mobuls left in this world. It's up to you,\n", (long) ((TIMELIMIT
- gltime
+ 99) / 100));
1306 lprintf("%s, to find the only hope for your daughter, the very rare\n", logname
);
1307 lprcat("potion of cure dianthroritis. It is rumored that only deep in the\n");
1308 lprcat("depths of the caves can this potion be found.\n\n\n");
1309 lprcat("\n ----- press ");
1311 lprcat(" to continue, ");
1313 lprcat(" to leave ----- ");
1315 while (i
!= '\33' && i
!= '\n')
1319 nosignal
= 0; /* enable signals */
1325 /* routine to save program space */
1329 lprcat(", or (i) ignore it? ");