]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - larn/object.c
1 /* $NetBSD: object.c,v 1.17 2019/02/03 03:19:25 mrg Exp $ */
3 /* object.c Larn is copyrighted 1986 by Noah Morgan. */
7 __RCSID("$NetBSD: object.c,v 1.17 2019/02/03 03:19:25 mrg 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;
153 lprcat("\nZaaaappp! You've been teleported!\n");
162 lprcat("\n\nYou have found the College of Larn.");
163 lprcat("\nDo you (g) go inside, or (i) stay here? ");
165 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
168 oschool(); /* the college of larn */
170 lprcat(" stay here");
176 lprcat("\n\nThere is a mirror here");
185 lprcat("\n\nYou have found the bank of Larn.");
187 lprcat("\n\nYou have found a branch office of the bank of Larn.");
188 lprcat("\nDo you (g) go inside, or (i) stay here? ");
190 while ((j
!= 'g') && (j
!= 'i') && (j
!= '\33'))
196 obank2(); /* the bank of larn */
198 lprcat(" stay here");
204 lprcat("\n\nThere is a dead fountain here");
210 lprcat("\n\nThere is a DND store here.");
211 lprcat("\nDo you (g) go inside, or (i) stay here? ");
213 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
216 dndstore(); /* the dnd adventurers store */
218 lprcat(" stay here");
222 lprcat("\n\nThere is a circular staircase here");
223 ostairs(-1); /* down */
227 lprcat("\n\nYou feel light for a moment, but the feeling disappears");
228 oelevator(-1); /* down */
232 lprintf("\n\nYou have found %s", objectname
[i
]);
233 lprcat("\nDo you (c) close it");
236 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
238 if ((i
== '\33') || (i
== 'i')) {
244 item
[playerx
][playery
] = OCLOSEDDOOR
;
245 iarg
[playerx
][playery
] = 0;
251 lprintf("\n\nYou have found %s", objectname
[i
]);
252 lprcat("\nDo you (o) try to open it");
255 while ((i
!= 'o') && (i
!= 'i') && (i
!= '\33'))
257 if ((i
== '\33') || (i
== 'i')) {
265 switch (iarg
[playerx
][playery
]) {
267 c
[AGGRAVATE
] += rnd(400);
271 lprcat("\nYou are jolted by an electric shock ");
282 lprcat("\nYou suddenly feel weaker ");
295 item
[playerx
][playery
] = OOPENDOOR
;
301 lprcat("\nYou have found ");
302 lprcat(objectname
[OENTRANCE
]);
303 lprcat("\nDo you (g) go inside");
306 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
312 item
[33][MAXY
- 1] = know
[33][MAXY
- 1] = mitem
[33][MAXY
- 1] = 0;
313 draws(0, MAXX
, 0, MAXY
);
321 lprcat("\nYou have found ");
322 lprcat(objectname
[OVOLDOWN
]);
323 lprcat("\nDo you (c) climb down");
326 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
328 if ((i
== '\33') || (i
== 'i')) {
333 lprcat("\nThe shaft only extends 5 feet downward!");
336 if (packweight() > 45 + 3 * (c
[STRENGTH
] + c
[STREXTRA
])) {
337 lprcat("\nYou slip and fall down the shaft");
340 losehp(30 + rnd(20));
343 lprcat("climb down");
345 newcavelevel(MAXLEVEL
);
346 for (i
= 0; i
< MAXY
; i
++)
347 for (j
= 0; j
< MAXX
; j
++) /* put player near
349 if (item
[j
][i
] == OVOLUP
) {
356 draws(0, MAXX
, 0, MAXY
);
361 lprcat("\nYou have found ");
362 lprcat(objectname
[OVOLUP
]);
363 lprcat("\nDo you (c) climb up");
366 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
368 if ((i
== '\33') || (i
== 'i')) {
373 lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!");
376 if (packweight() > 45 + 5 * (c
[STRENGTH
] + c
[STREXTRA
])) {
377 lprcat("\nYou slip and fall down the shaft");
380 losehp(15 + rnd(20));
388 for (i
= 0; i
< MAXY
; i
++)
389 for (j
= 0; j
< MAXX
; j
++) /* put player near
391 if (item
[j
][i
] == OVOLDOWN
) {
398 draws(0, MAXX
, 0, MAXY
);
404 return; /* for an arrow trap */
405 item
[playerx
][playery
] = OTRAPARROW
;
406 know
[playerx
][playery
] = 0;
410 lprcat("\nYou are hit by an arrow");
411 beep(); /* for an arrow trap */
413 losehp(rnd(10) + level
);
419 return; /* for a dart trap */
420 item
[playerx
][playery
] = ODARTRAP
;
421 know
[playerx
][playery
] = 0;
425 lprcat("\nYou are hit by a dart");
426 beep(); /* for a dart trap */
429 if ((--c
[STRENGTH
]) < 3)
436 return; /* for a trap door */
437 item
[playerx
][playery
] = OTRAPDOOR
;
438 know
[playerx
][playery
] = 1;
442 lastnum
= 272; /* a trap door */
443 if ((level
== MAXLEVEL
- 1) || (level
== MAXLEVEL
+ MAXVLEVEL
- 1)) {
444 lprcat("\nYou fell through a bottomless trap door!");
449 lprcat("\nYou fall through a trap door!");
450 beep(); /* for a trap door */
451 losehp(rnd(5 + level
));
453 newcavelevel(level
+ 1);
454 draws(0, MAXX
, 0, MAXY
);
462 lprcat("\nYou have found the Larn trading Post.");
463 lprcat("\nDo you (g) go inside, or (i) stay here? ");
465 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
476 lprcat("\nYou have found your way home.");
477 lprcat("\nDo you (g) go inside, or (i) stay here? ");
479 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
492 return; /* annihilated by sphere of annihilation */
497 lprcat("\n\nThere is an LRS office here.");
498 lprcat("\nDo you (g) go inside, or (i) stay here? ");
500 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
503 olrs(); /* the larn revenue service */
505 lprcat(" stay here");
515 function to say what object we found and ask if player wants to take it
518 finditem(int theitem
)
521 lprintf("\n\nYou have found %s ", objectname
[theitem
]);
522 tmp
= iarg
[playerx
][playery
];
536 lprintf("+ %ld", (long) tmp
);
538 lprintf(" %ld", (long) tmp
);
540 lprcat("\nDo you want to (t) take it");
543 while (i
!= 't' && i
!= 'i' && i
!= '\33')
547 if (take(theitem
, tmp
) == 0)
557 subroutine to process the stair cases
558 if dir > 0 the up else down
564 lprcat("\nDo you (s) stay here ");
566 lprcat("(u) go up ");
568 lprcat("(d) go down ");
569 lprcat("or (f) kick stairs? ");
580 lprcat("kick stairs");
582 lprcat("\nI hope you feel better. Showing anger rids you of frustration.");
584 k
= rnd((level
+ 1) << 1);
585 lprintf("\nYou hurt your foot dumb dumb! You suffer %ld hit points", (long) k
);
595 lprcat("\nThe stairs don't go up!");
596 else if (level
>= 2 && level
!= 11) {
598 newcavelevel(level
- 1);
599 draws(0, MAXX
, 0, MAXY
);
602 lprcat("\nThe stairs lead to a dead end!");
608 lprcat("\nThe stairs don't go down!");
609 else if (level
!= 0 && level
!= 10 && level
!= 13) {
611 newcavelevel(level
+ 1);
612 draws(0, MAXX
, 0, MAXY
);
615 lprcat("\nThe stairs lead to a dead end!");
623 subroutine to handle a teleport trap +/- 1 level maximum
631 died(264); /* stuck in a rock */
632 c
[TELEFLAG
] = 1; /* show ?? on bottomline if been teleported */
635 else if (level
< MAXLEVEL
) {
636 tmp
= rnd(5) + level
- 3;
642 tmp
= rnd(3) + level
- 2;
643 if (tmp
>= MAXLEVEL
+ MAXVLEVEL
)
644 tmp
= MAXLEVEL
+ MAXVLEVEL
- 1;
648 playerx
= rnd(MAXX
- 2);
649 playery
= rnd(MAXY
- 2);
653 draws(0, MAXX
, 0, MAXY
);
659 function to process a potion
664 lprcat("\nDo you (d) drink it, (t) take it");
675 forget(); /* destroy potion */
681 if (take(OPOTION
, pot
) == 0)
688 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
872 if (c
[BLINDCOUNT
] == 0)
873 lprcat("(r) read it, ");
874 lprcat("(t) take it");
888 if (typ
== 2 || typ
== 15) {
889 show1cell(playerx
, playery
);
892 /* destroy it */ read_scroll(typ
);
897 if (take(OSCROLL
, typ
) == 0)
898 forget(); /* destroy it */
904 data for the function to read a scroll
906 static int xh
, yh
, yl
, xl
;
907 static u_char curse
[] = {
908 BLINDCOUNT
, CONFUSE
, AGGRAVATE
, HASTEMONST
, ITCHING
,
909 LAUGHING
, DRAINSTRENGTH
, CLUMSINESS
, INFEEBLEMENT
, HALFDAM
912 static u_char exten
[] = {
913 PROTECTIONTIME
, DEXCOUNT
, STRCOUNT
, CHARMCOUNT
, INVISIBILITY
,
914 CANCELLATION
, HASTESELF
, GLOBE
, SCAREMONST
, HOLDMONST
, TIMESTOP
917 static u_char time_change
[] = {
918 HASTESELF
, HERO
, ALTPRO
, PROTECTIONTIME
, DEXCOUNT
, STRCOUNT
,
919 GIANTSTR
, CHARMCOUNT
, INVISIBILITY
, CANCELLATION
, HASTESELF
,
920 AGGRAVATE
, SCAREMONST
, STEALTH
, AWARENESS
, HOLDMONST
,
921 HASTEMONST
, FIRERESISTANCE
, GLOBE
, SPIRITPRO
, UNDEADPRO
,
922 HALFDAM
, SEEINVISIBLE
, ITCHING
, CLUMSINESS
, WTW
926 * function to adjust time when time warping and taking courses in school
932 for (j
= 0; j
< 26; j
++)/* adjust time related parameters */
933 if (c
[time_change
[j
]])
934 if ((c
[time_change
[j
]] -= tim
) < 1)
935 c
[time_change
[j
]] = 1;
940 function to read a scroll
946 if (typ
< 0 || typ
>= MAXSCROLL
)
947 return; /* be sure we are within bounds */
948 scrollname
[typ
] = scrollhide
[typ
];
951 lprcat("\nYour armor glows for a moment");
956 lprcat("\nYour weapon glows for a moment");
958 return; /* enchant weapon */
961 lprcat("\nYou have been granted enlightenment!");
962 yh
= min(playery
+ 7, MAXY
);
963 xh
= min(playerx
+ 25, MAXX
);
964 yl
= max(playery
- 7, 0);
965 xl
= max(playerx
- 25, 0);
966 for (i
= yl
; i
< yh
; i
++)
967 for (j
= xl
; j
< xh
; j
++)
970 draws(xl
, xh
, yl
, yh
);
974 lprcat("\nThis scroll seems to be blank");
978 createmonster(makemonst(level
+ 1));
979 return; /* this one creates a monster */
982 something(level
); /* create artifact */
987 return; /* aggravate monsters */
990 gltime
+= (i
= rnd(1000) - 850); /* time warp */
992 lprintf("\nYou went forward in time by %ld mobuls", (long) ((i
+ 99) / 100));
994 lprintf("\nYou went backward in time by %ld mobuls", (long) (-(i
+ 99) / 100));
995 adjusttime((long) i
); /* adjust time for time warping */
1000 return; /* teleportation */
1003 c
[AWARENESS
] += 1800;
1004 return; /* expanded awareness */
1007 c
[HASTEMONST
] += rnd(55) + 12;
1008 return; /* haste monster */
1011 for (i
= 0; i
< MAXY
; i
++)
1012 for (j
= 0; j
< MAXX
; j
++)
1014 hitp
[j
][i
] = monster
[mitem
[j
][i
]].hitpoints
;
1015 return; /* monster healing */
1017 c
[SPIRITPRO
] += 300 + rnd(200);
1019 return; /* spirit protection */
1022 c
[UNDEADPRO
] += 300 + rnd(200);
1024 return; /* undead protection */
1027 c
[STEALTH
] += 250 + rnd(250);
1029 return; /* stealth */
1032 lprcat("\nYou have been granted enlightenment!"); /* magic mapping */
1033 for (i
= 0; i
< MAXY
; i
++)
1034 for (j
= 0; j
< MAXX
; j
++)
1037 draws(0, MAXX
, 0, MAXY
);
1043 return; /* hold monster */
1046 for (i
= 0; i
< 26; i
++) /* gem perfection */
1056 j
= 255; /* double value */
1063 for (i
= 0; i
< 11; i
++)
1064 c
[exten
[i
]] <<= 1; /* spell extension */
1068 for (i
= 0; i
< 26; i
++) { /* identify */
1069 if (iven
[i
] == OPOTION
)
1070 potionname
[ivenarg
[i
]] = potionhide
[ivenarg
[i
]];
1071 if (iven
[i
] == OSCROLL
)
1072 scrollname
[ivenarg
[i
]] = scrollhide
[ivenarg
[i
]];
1077 for (i
= 0; i
< 10; i
++) /* remove curse */
1084 break; /* scroll of annihilation */
1087 godirect(22, 150, "The ray hits the %s", 0, ' '); /* pulverization */
1091 break; /* life protection */
1106 if (rnd(101) < 81) {
1107 if (rnd(70) > 9 * c
[DEXTERITY
] - packweight() || rnd(101) < 5) {
1108 if (level
== MAXLEVEL
- 1)
1110 else if (level
== MAXLEVEL
+ MAXVLEVEL
- 1)
1113 if (rnd(101) < 20) {
1115 lprcat("\nYou fell into a pit! Your fall is cushioned by an unknown force\n");
1117 i
= rnd(level
* 3 + 3);
1118 lprintf("\nYou fell into a pit! You suffer %ld hit points damage", (long) i
);
1119 lastnum
= 261; /* if he dies scoreboard
1124 newcavelevel(level
+ 1);
1125 draws(0, MAXX
, 0, MAXY
);
1134 lprcat("\nYou fell into a bottomless pit!");
1163 lprcat("\nDo you ");
1164 if (c
[BLINDCOUNT
] == 0)
1165 lprcat("(r) read it, ");
1166 lprcat("(t) take it");
1169 switch (ttgetch()) {
1179 /* no more book */ readbook(iarg
[playerx
][playery
]);
1185 if (take(OBOOK
, iarg
[playerx
][playery
]) == 0)
1186 forget(); /* no more book */
1192 function to read a book
1199 i
= rund((tmp
= splev
[lev
]) ? tmp
: 1);
1201 i
= rnd((tmp
= splev
[lev
] - 9) ? tmp
: 1) + 9;
1203 lprintf("\nSpell \"%s\": %s\n%s", spelcode
[i
], spelname
[i
], speldescript
[i
]);
1205 lprcat("\nYour int went up by one!");
1216 lprcat("\nDo you (e) eat it, (t) take it");
1219 switch (ttgetch()) {
1226 lprcat("eat\nThe cookie tasted good.");
1227 forget(); /* no more cookie */
1230 if (!(p
= fortune()))
1232 lprcat(" A message inside the cookie reads:\n");
1238 if (take(OCOOKIE
, 0) == 0)
1239 forget(); /* no more book */
1246 * routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth
1253 i
= iarg
[playerx
][playery
];
1254 if (arg
== OMAXGOLD
)
1256 else if (arg
== OKGOLD
)
1258 else if (arg
== ODGOLD
)
1260 lprintf("\nIt is worth %ld!", (long) i
);
1263 item
[playerx
][playery
] = know
[playerx
][playery
] = 0; /* destroy gold */
1270 nosignal
= 1; /* disable signals */
1271 for (i
= 0; i
< 26; i
++)
1272 if (iven
[i
] == OPOTION
)
1273 if (ivenarg
[i
] == 21) {
1274 iven
[i
] = 0; /* remove the potion of cure
1275 * dianthroritis from
1278 lprcat("Congratulations. You found a potion of cure dianthroritis.\n");
1279 lprcat("\nFrankly, No one thought you could do it. Boy! Did you surprise them!\n");
1280 if (gltime
> TIMELIMIT
) {
1281 lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
1282 lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
1286 lprcat("\nThe doctor is now administering the potion, and in a few moments\n");
1287 lprcat("Your daughter should be well on her way to recovery.\n");
1289 lprcat("\nThe potion is");
1291 lprcat(" working! The doctor thinks that\n");
1292 lprcat("your daughter will recover in a few days. Congratulations!\n");
1300 lprintf("Welcome home %s. Latest word from the doctor is not good.\n", logname
);
1302 if (gltime
> TIMELIMIT
) {
1303 lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
1304 lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
1308 lprcat("\nThe diagnosis is confirmed as dianthroritis. He guesses that\n");
1309 lprintf("your daughter has only %ld mobuls left in this world. It's up to you,\n", (long) ((TIMELIMIT
- gltime
+ 99) / 100));
1310 lprintf("%s, to find the only hope for your daughter, the very rare\n", logname
);
1311 lprcat("potion of cure dianthroritis. It is rumored that only deep in the\n");
1312 lprcat("depths of the caves can this potion be found.\n\n\n");
1313 lprcat("\n ----- press ");
1315 lprcat(" to continue, ");
1317 lprcat(" to leave ----- ");
1319 while (i
!= '\33' && i
!= '\n')
1323 nosignal
= 0; /* enable signals */
1329 /* routine to save program space */
1333 lprcat(", or (i) ignore it? ");