1 /* object.c Larn is copyrighted 1986 by Noah Morgan. */
2 /* $FreeBSD: src/games/larn/object.c,v 1.4 1999/11/16 02:57:23 billf Exp $ */
3 /* $DragonFly: src/games/larn/object.c,v 1.5 2006/08/26 17:05:05 pavalos Exp $ */
6 static void finditem(int);
7 static void ostairs(int);
8 static void opotion(int);
9 static void oscroll(int);
10 static void oorb(void);
11 static void opit(void);
12 static void obottomless(void);
13 static void oelevator(int);
14 static void ostatue(void);
15 static void omirror(void);
16 static void obook(void);
17 static void ocookie(void);
18 static void ogold(int);
19 static void ohome(void);
22 subroutine to look for an object and give the player his options
23 if an object was found.
29 if (c
[TIMESTOP
]) /* can't find objects is time is stopped */
31 i
= item
[playerx
][playery
];
34 showcell(playerx
, playery
);
42 lprcat("\n\nYou have found some gold!");
47 lprcat("\n\nYou have found a magic potion");
48 i
= iarg
[playerx
][playery
];
49 if (potionname
[i
][0] != 0)
50 lprintf(" of %s", potionname
[i
]);
55 lprcat("\n\nYou have found a magic scroll");
56 i
= iarg
[playerx
][playery
];
57 if (scrollname
[i
][0] != 0)
58 lprintf(" of %s", scrollname
[i
]);
65 lprcat("\n\nThere is a Holy Altar here!");
70 lprcat("\n\nYou have found a book.");
75 lprcat("\n\nYou have found a fortune cookie.");
82 lprintf("\n\nThere is %s here!", objectname
[i
]);
89 lprintf("\n\nThere is %s here!", objectname
[i
]);
94 lprintf("\n\nThere is %s here!", objectname
[i
]);
99 lprcat("\n\nYou have found the Orb!!!!!");
104 lprcat("\n\nYou're standing at the top of a pit.");
109 lprcat("\n\nThere is a circular staircase here");
114 lprcat("\n\nYou feel heavy for a moment, but the feeling disappears");
115 oelevator(1); /* up */
121 lprcat("\n\nThere is a fountain here");
128 lprcat("\n\nYou are standing in front of a statue");
133 lprcat("\n\nThere is a chest here");
140 item
[playerx
][playery
] = OTELEPORTER
;
141 know
[playerx
][playery
] = 1;
144 lprcat("\nZaaaappp! You've been teleported!\n");
153 lprcat("\n\nYou have found the College of Larn.");
154 lprcat("\nDo you (g) go inside, or (i) stay here? ");
156 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
159 oschool(); /* the college of larn */
161 lprcat(" stay here");
167 lprcat("\n\nThere is a mirror here");
176 lprcat("\n\nYou have found the bank of Larn.");
178 lprcat("\n\nYou have found a branch office of the bank of Larn.");
179 lprcat("\nDo you (g) go inside, or (i) stay here? ");
181 while ((j
!= 'g') && (j
!= 'i') && (j
!= '\33'))
187 obank2(); /* the bank of larn */
189 lprcat(" stay here");
195 lprcat("\n\nThere is a dead fountain here");
201 lprcat("\n\nThere is a DND store here.");
202 lprcat("\nDo you (g) go inside, or (i) stay here? ");
204 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
207 dndstore(); /* the dnd adventurers store */
209 lprcat(" stay here");
213 lprcat("\n\nThere is a circular staircase here");
214 ostairs(-1); /* down */
218 lprcat("\n\nYou feel light for a moment, but the feeling disappears");
219 oelevator(-1); /* down */
223 lprintf("\n\nYou have found %s", objectname
[i
]);
224 lprcat("\nDo you (c) close it");
227 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
229 if ((i
== '\33') || (i
== 'i')) {
235 item
[playerx
][playery
] = OCLOSEDDOOR
;
236 iarg
[playerx
][playery
] = 0;
242 lprintf("\n\nYou have found %s", objectname
[i
]);
243 lprcat("\nDo you (o) try to open it");
246 while ((i
!= 'o') && (i
!= 'i') && (i
!= '\33'))
248 if ((i
== '\33') || (i
== 'i')) {
256 switch (iarg
[playerx
][playery
]) {
258 c
[AGGRAVATE
] += rnd(400);
262 lprcat("\nYou are jolted by an electric shock ");
273 lprcat("\nYou suddenly feel weaker ");
286 item
[playerx
][playery
] = OOPENDOOR
;
292 lprcat("\nYou have found ");
293 lprcat(objectname
[OENTRANCE
]);
294 lprcat("\nDo you (g) go inside");
297 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
303 item
[33][MAXY
- 1] = know
[33][MAXY
- 1] = mitem
[33][MAXY
- 1] = 0;
304 draws(0, MAXX
, 0, MAXY
);
312 lprcat("\nYou have found ");
313 lprcat(objectname
[OVOLDOWN
]);
314 lprcat("\nDo you (c) climb down");
317 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
319 if ((i
== '\33') || (i
== 'i')) {
324 lprcat("\nThe shaft only extends 5 feet downward!");
327 if (packweight() > 45 + 3 * (c
[STRENGTH
] + c
[STREXTRA
])) {
328 lprcat("\nYou slip and fall down the shaft");
331 losehp(30 + rnd(20));
334 lprcat("climb down");
336 newcavelevel(MAXLEVEL
);
337 for (i
= 0; i
< MAXY
; i
++)
338 for (j
= 0; j
< MAXX
; j
++) /* put player near volcano shaft */
339 if (item
[j
][i
] == OVOLUP
) {
346 draws(0, MAXX
, 0, MAXY
);
351 lprcat("\nYou have found ");
352 lprcat(objectname
[OVOLUP
]);
353 lprcat("\nDo you (c) climb up");
356 while ((i
!= 'c') && (i
!= 'i') && (i
!= '\33'))
358 if ((i
== '\33') || (i
== 'i')) {
363 lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!");
366 if (packweight() > 45 + 5 * (c
[STRENGTH
] + c
[STREXTRA
])) {
367 lprcat("\nYou slip and fall down the shaft");
370 losehp(15 + rnd(20));
378 for (i
= 0; i
< MAXY
; i
++)
379 for (j
= 0; j
< MAXX
; j
++) /* put player near volcano shaft */
380 if (item
[j
][i
] == OVOLDOWN
) {
387 draws(0, MAXX
, 0, MAXY
);
392 if (rnd(17) < 13) /* for an arrow trap */
394 item
[playerx
][playery
] = OTRAPARROW
;
395 know
[playerx
][playery
] = 0;
398 lprcat("\nYou are hit by an arrow");
399 beep(); /* for an arrow trap */
401 losehp(rnd(10) + level
);
406 if (rnd(17) < 13) /* for a dart trap */
408 item
[playerx
][playery
] = ODARTRAP
;
409 know
[playerx
][playery
] = 0;
412 lprcat("\nYou are hit by a dart");
413 beep(); /* for a dart trap */
416 if ((--c
[STRENGTH
]) < 3)
422 if (rnd(17) < 13) /* for a trap door */
424 item
[playerx
][playery
] = OTRAPDOOR
;
425 know
[playerx
][playery
] = 1;
428 lastnum
= 272; /* a trap door */
429 if ((level
== MAXLEVEL
- 1) || (level
== MAXLEVEL
+ MAXVLEVEL
- 1)) {
430 lprcat("\nYou fell through a bottomless trap door!");
435 lprcat("\nYou fall through a trap door!");
436 beep(); /* for a trap door */
437 losehp(rnd(5 + level
));
439 newcavelevel(level
+ 1);
440 draws(0, MAXX
, 0, MAXY
);
448 lprcat("\nYou have found the Larn trading Post.");
449 lprcat("\nDo you (g) go inside, or (i) stay here? ");
451 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
462 lprcat("\nYou have found your way home.");
463 lprcat("\nDo you (g) go inside, or (i) stay here? ");
465 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
478 return; /* annihilated by sphere of annihilation */
483 lprcat("\n\nThere is an LRS office here.");
484 lprcat("\nDo you (g) go inside, or (i) stay here? ");
486 while ((i
!= 'g') && (i
!= 'i') && (i
!= '\33'))
489 olrs(); /* the larn revenue service */
491 lprcat(" stay here");
501 function to say what object we found and ask if player wants to take it
507 lprintf("\n\nYou have found %s ", objectname
[obj
]);
508 tmp
= iarg
[playerx
][playery
];
522 lprintf("+ %d", (long)tmp
);
524 lprintf(" %d", (long)tmp
);
526 lprcat("\nDo you want to (t) take it");
529 while (i
!= 't' && i
!= 'i' && i
!= '\33')
533 if (take(obj
, tmp
) == 0)
541 subroutine to process the stair cases
542 if dir > 0 the up else down
548 lprcat("\nDo you (s) stay here ");
550 lprcat("(u) go up ");
552 lprcat("(d) go down ");
553 lprcat("or (f) kick stairs? ");
564 lprcat("kick stairs");
566 lprcat("\nI hope you feel better. Showing anger rids you of frustration.");
568 k
= rnd((level
+ 1) << 1);
569 lprintf("\nYou hurt your foot dumb dumb! You suffer %d hit points", (long)k
);
579 lprcat("\nThe stairs don't go up!");
580 else if (level
>= 2 && level
!= 11) {
582 newcavelevel(level
- 1);
583 draws(0, MAXX
, 0, MAXY
);
586 lprcat("\nThe stairs lead to a dead end!");
592 lprcat("\nThe stairs don't go down!");
593 else if (level
!= 0 && level
!= 10 && level
!= 13) {
595 newcavelevel(level
+ 1);
596 draws(0, MAXX
, 0, MAXY
);
599 lprcat("\nThe stairs lead to a dead end!");
605 subroutine to handle a teleport trap +/- 1 level maximum
612 if (rnd(151) < 3) /* stuck in a rock */
614 c
[TELEFLAG
] = 1; /* show ?? on bottomline if been teleported */
617 else if (level
< MAXLEVEL
) {
618 tmp
= rnd(5) + level
- 3;
624 tmp
= rnd(3) + level
- 2;
625 if (tmp
>= MAXLEVEL
+ MAXVLEVEL
)
626 tmp
= MAXLEVEL
+ MAXVLEVEL
- 1;
630 playerx
= rnd(MAXX
- 2);
631 playery
= rnd(MAXY
- 2);
635 draws(0, MAXX
, 0, MAXY
);
640 function to process a potion
645 lprcat("\nDo you (d) drink it, (t) take it");
656 forget(); /* destroy potion */
662 if (take(OPOTION
, pot
) == 0)
669 function to drink a potion
675 if (pot
< 0 || pot
>= MAXPOTION
) /* check for within bounds */
677 potionname
[pot
] = potionhide
[pot
];
680 lprcat("\nYou feel greedy . . .");
682 for (i
= 0; i
< MAXY
; i
++)
683 for (j
= 0; j
< MAXX
; j
++)
684 if ((item
[j
][i
] == OGOLDPILE
) || (item
[j
][i
] == OMAXGOLD
)) {
692 lprcat("\nYou feel greedy . . .");
694 for (i
= 0; i
< MAXY
; i
++)
695 for (j
= 0; j
< MAXX
; j
++) {
697 if ((k
== ODIAMOND
) || (k
== ORUBY
) || (k
== OEMERALD
) || (k
== OMAXGOLD
)
698 || (k
== OSAPPHIRE
) || (k
== OLARNEYE
) || (k
== OGOLDPILE
)) {
708 break; /* instant healing */
711 lprcat("\nYou feel better");
712 if (c
[HP
] == c
[HPMAX
])
714 else if ((c
[HP
] += rnd(20) + 20 + c
[LEVEL
]) > c
[HPMAX
])
719 lprcat("\nSuddenly, you feel much more skillful!");
725 lprcat("\nYou feel strange for a moment");
730 lprcat("\nYou feel more self confident!");
735 lprcat("\nWow! You feel great!");
736 if (c
[STRENGTH
] < 12)
743 lprcat("\nYour charm went up by one!");
748 lprcat("\nYour intelligence went up by one!");
753 for (i
= 0; i
< MAXY
; i
++)
754 for (j
= 0; j
< MAXX
; j
++)
759 /* monster detection */
763 lprcat("\nThis potion has no taste to it");
767 lprcat("\nWOW!!! You feel Super-fantastic!!!");
769 for (i
= 0; i
< 6; i
++)
775 lprcat("\nYou have a greater intestinal constitude!");
780 lprcat("\nYou now have incredibly bulging muscles!!!");
781 if (c
[GIANTSTR
] == 0)
787 lprcat("\nYou feel a chill run up your spine!");
788 c
[FIRERESISTANCE
] += 1000;
792 lprcat("\nYou fall asleep. . .");
793 i
= rnd(11) - (c
[CONSTITUTION
] >> 2) + 2;
799 lprcat("\nYou woke up!");
803 lprcat("\nYou become dizzy!");
804 if (--c
[STRENGTH
] < 3)
809 lprcat("\nYou stagger for a moment . .");
810 for (i
= 0; i
< MAXY
; i
++)
811 for (j
= 0; j
< MAXX
; j
++)
814 draws(0, MAXX
, 0, MAXY
); /* potion of forgetfulness */
818 lprcat("\nYou can't see anything!"); /* blindness */
819 c
[BLINDCOUNT
] += 500;
823 lprcat("\nYou feel confused");
824 c
[CONFUSE
] += 20 + rnd(9);
828 lprcat("\nYou don't seem to be affected");
829 return; /* cure dianthroritis */
832 lprcat("\nYou feel a sickness engulf you"); /* poison */
833 c
[HALFDAM
] += 200 + rnd(200);
837 lprcat("\nYou feel your vision sharpen"); /* see invisible */
838 c
[SEEINVISIBLE
] += rnd(1000) + 400;
839 monstnamelist
[INVISIBLESTALKER
] = 'I';
842 bottomline(); /* show new stats */
847 function to process a magic scroll
853 if (c
[BLINDCOUNT
] == 0)
854 lprcat("(r) read it, ");
855 lprcat("(t) take it");
869 if (typ
== 2 || typ
== 15) {
870 show1cell(playerx
, playery
);
879 if (take(OSCROLL
, typ
) == 0)
880 forget(); /* destroy it */
886 data for the function to read a scroll
888 static int xh
, yh
, yl
, xl
;
889 static char curse
[] = { BLINDCOUNT
, CONFUSE
, AGGRAVATE
, HASTEMONST
, ITCHING
,
890 LAUGHING
, DRAINSTRENGTH
, CLUMSINESS
, INFEEBLEMENT
, HALFDAM
};
891 static char exten
[] = { PROTECTIONTIME
, DEXCOUNT
, STRCOUNT
, CHARMCOUNT
,
892 INVISIBILITY
, CANCELLATION
, HASTESELF
, GLOBE
, SCAREMONST
, HOLDMONST
, TIMESTOP
};
893 char time_change
[] = { HASTESELF
, HERO
, ALTPRO
, PROTECTIONTIME
, DEXCOUNT
,
894 STRCOUNT
, GIANTSTR
, CHARMCOUNT
, INVISIBILITY
, CANCELLATION
,
895 HASTESELF
, AGGRAVATE
, SCAREMONST
, STEALTH
, AWARENESS
, HOLDMONST
, HASTEMONST
,
896 FIRERESISTANCE
, GLOBE
, SPIRITPRO
, UNDEADPRO
, HALFDAM
, SEEINVISIBLE
,
897 ITCHING
, CLUMSINESS
, WTW
};
899 * function to adjust time when time warping and taking courses in school
902 larn_adjtime(long tim
)
905 for (j
= 0; j
< 26; j
++) /* adjust time related parameters */
906 if (c
[(int)time_change
[j
]])
907 if ((c
[(int)time_change
[j
]] -= tim
) < 1)
908 c
[(int)time_change
[j
]] = 1;
913 function to read a scroll
919 if (typ
< 0 || typ
>= MAXSCROLL
) /* be sure we are within bounds */
921 scrollname
[typ
] = scrollhide
[typ
];
924 lprcat("\nYour armor glows for a moment");
929 lprcat("\nYour weapon glows for a moment");
931 return; /* enchant weapon */
934 lprcat("\nYou have been granted enlightenment!");
935 yh
= min(playery
+ 7, MAXY
);
936 xh
= min(playerx
+ 25, MAXX
);
937 yl
= max(playery
- 7, 0);
938 xl
= max(playerx
- 25, 0);
939 for (i
= yl
; i
< yh
; i
++)
940 for (j
= xl
; j
< xh
; j
++)
943 draws(xl
, xh
, yl
, yh
);
947 lprcat("\nThis scroll seems to be blank");
951 createmonster(makemonst(level
+ 1));
952 return; /* this one creates a monster */
955 something(level
); /* create artifact */
960 return; /* aggravate monsters */
963 gtime
+= (i
= rnd(1000) - 850); /* time warp */
965 lprintf("\nYou went forward in time by %d mobuls", (long)((i
+ 99) / 100));
967 lprintf("\nYou went backward in time by %d mobuls", (long)(-(i
+ 99) / 100));
968 larn_adjtime((long)i
); /* adjust time for time warping */
973 return; /* teleportation */
976 c
[AWARENESS
] += 1800;
977 return; /* expanded awareness */
980 c
[HASTEMONST
] += rnd(55) + 12;
981 return; /* haste monster */
984 for (i
= 0; i
< MAXY
; i
++)
985 for (j
= 0; j
< MAXX
; j
++)
987 hitp
[j
][i
] = monster
[(int)mitem
[j
][i
]].hitpoints
;
988 return; /* monster healing */
990 c
[SPIRITPRO
] += 300 + rnd(200);
992 return; /* spirit protection */
995 c
[UNDEADPRO
] += 300 + rnd(200);
997 return; /* undead protection */
1000 c
[STEALTH
] += 250 + rnd(250);
1002 return; /* stealth */
1005 lprcat("\nYou have been granted enlightenment!"); /* magic mapping */
1006 for (i
= 0; i
< MAXY
; i
++)
1007 for (j
= 0; j
< MAXX
; j
++)
1010 draws(0, MAXX
, 0, MAXY
);
1016 return; /* hold monster */
1019 for (i
= 0; i
< 26; i
++) /* gem perfection */
1029 j
= 255; /* double value */
1036 for (i
= 0; i
< 11; i
++)
1037 c
[(int)exten
[i
]] <<= 1; /* spell extension */
1041 for (i
= 0; i
< 26; i
++) { /* identify */
1042 if (iven
[i
] == OPOTION
)
1043 potionname
[ivenarg
[i
]] = potionhide
[ivenarg
[i
]];
1044 if (iven
[i
] == OSCROLL
)
1045 scrollname
[ivenarg
[i
]] = scrollhide
[ivenarg
[i
]];
1050 for (i
= 0; i
< 10; i
++) /* remove curse */
1051 if (c
[(int)curse
[i
]])
1052 c
[(int)curse
[i
]] = 1;
1057 break; /* scroll of annihilation */
1060 godirect(22, 150, "The ray hits the %s", 0, ' '); /* pulverization */
1064 break; /* life protection */
1077 if (rnd(101) < 81) {
1078 if (rnd(70) > 9 * c
[DEXTERITY
] - packweight() || rnd(101) < 5) {
1079 if (level
== MAXLEVEL
- 1)
1081 else if (level
== MAXLEVEL
+ MAXVLEVEL
- 1)
1084 if (rnd(101) < 20) {
1086 lprcat("\nYou fell into a pit! Your fall is cushioned by an unknown force\n");
1088 i
= rnd(level
* 3 + 3);
1089 lprintf("\nYou fell into a pit! You suffer %d hit points damage", (long)i
);
1090 lastnum
= 261; /* if he dies scoreboard will say so */
1094 newcavelevel(level
+ 1);
1095 draws(0, MAXX
, 0, MAXY
);
1104 lprcat("\nYou fell into a bottomless pit!");
1111 oelevator(int dir __unused
)
1133 lprcat("\nDo you ");
1134 if (c
[BLINDCOUNT
] == 0)
1135 lprcat("(r) read it, ");
1136 lprcat("(t) take it");
1150 readbook(iarg
[playerx
][playery
]);
1156 if (take(OBOOK
, iarg
[playerx
][playery
]) == 0)
1157 forget(); /* no more book */
1163 function to read a book
1170 i
= rund((tmp
= splev
[lev
]) ? tmp
: 1);
1172 i
= rnd((tmp
= splev
[lev
] - 9) ? tmp
: 1) + 9;
1174 lprintf("\nSpell \"%s\": %s\n%s", spelcode
[i
], spelname
[i
], speldescript
[i
]);
1176 lprcat("\nYour int went up by one!");
1186 lprcat("\nDo you (e) eat it, (t) take it");
1196 lprcat("eat\nThe cookie tasted good.");
1197 forget(); /* no more cookie */
1200 if (!(p
= fortune()))
1202 lprcat(" A message inside the cookie reads:\n");
1208 if (take(OCOOKIE
, 0) == 0)
1209 forget(); /* no more book */
1215 /* routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth 100* the argument */
1220 i
= iarg
[playerx
][playery
];
1221 if (arg
== OMAXGOLD
)
1223 else if (arg
== OKGOLD
)
1225 else if (arg
== ODGOLD
)
1227 lprintf("\nIt is worth %d!", (long)i
);
1231 item
[playerx
][playery
] = know
[playerx
][playery
] = 0;
1238 nosignal
= 1; /* disable signals */
1239 for (i
= 0; i
< 26; i
++)
1240 if (iven
[i
] == OPOTION
)
1241 if (ivenarg
[i
] == 21) {
1242 iven
[i
] = 0; /* remove the potion of cure dianthroritis from inventory */
1244 lprcat("Congratulations. You found a potion of cure dianthroritis.\n");
1245 lprcat("\nFrankly, No one thought you could do it. Boy! Did you surprise them!\n");
1246 if (gtime
> TIMELIMIT
) {
1247 lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
1248 lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
1252 lprcat("\nThe doctor is now administering the potion, and in a few moments\n");
1253 lprcat("Your daughter should be well on her way to recovery.\n");
1255 lprcat("\nThe potion is");
1257 lprcat(" working! The doctor thinks that\n");
1258 lprcat("your daughter will recover in a few days. Congratulations!\n");
1267 lprintf("Welcome home %s. Latest word from the doctor is not good.\n", logname
);
1269 if (gtime
> TIMELIMIT
) {
1270 lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
1271 lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n");
1276 lprcat("\nThe diagnosis is confirmed as dianthroritis. He guesses that\n");
1277 lprintf("your daughter has only %d mobuls left in this world. It's up to you,\n", (long)((TIMELIMIT
- gtime
+ 99) / 100));
1278 lprintf("%s, to find the only hope for your daughter, the very rare\n", logname
);
1279 lprcat("potion of cure dianthroritis. It is rumored that only deep in the\n");
1280 lprcat("depths of the caves can this potion be found.\n\n\n");
1281 lprcat("\n ----- press ");
1283 lprcat(" to continue, ");
1285 lprcat(" to leave ----- ");
1287 while (i
!= '\33' && i
!= '\n')
1291 nosignal
= 0; /* enable signals */
1297 /* routine to save program space */
1301 lprcat(", or (i) ignore it? ");