From 77e3814f0c0e3dea4d0032e25666f77e6f83bfff Mon Sep 17 00:00:00 2001 From: cgd Date: Sun, 21 Mar 1993 09:45:37 +0000 Subject: initial import of 386bsd-0.1 sources --- larn/object.c | 807 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 807 insertions(+) create mode 100644 larn/object.c (limited to 'larn/object.c') diff --git a/larn/object.c b/larn/object.c new file mode 100644 index 00000000..9bf7c3c5 --- /dev/null +++ b/larn/object.c @@ -0,0 +1,807 @@ +/* object.c Larn is copyrighted 1986 by Noah Morgan. */ +#include "header.h" + +/* + *************** + LOOK_FOR_OBJECT + *************** + + subroutine to look for an object and give the player his options + if an object was found. + */ +lookforobject() +{ +register int i,j; +if (c[TIMESTOP]) return; /* can't find objects is time is stopped */ +i=item[playerx][playery]; if (i==0) return; +showcell(playerx,playery); cursors(); yrepcount=0; +switch(i) + { + case OGOLDPILE: case OMAXGOLD: + case OKGOLD: case ODGOLD: lprcat("\n\nYou have found some gold!"); ogold(i); break; + + case OPOTION: lprcat("\n\nYou have found a magic potion"); + i = iarg[playerx][playery]; + if (potionname[i][0]) lprintf(" of %s",&potionname[i][1]); opotion(i); break; + + case OSCROLL: lprcat("\n\nYou have found a magic scroll"); + i = iarg[playerx][playery]; + if (scrollname[i][0]) lprintf(" of %s",&scrollname[i][1]); + oscroll(i); break; + + case OALTAR: if (nearbymonst()) return; + lprcat("\n\nThere is a Holy Altar here!"); oaltar(); break; + + case OBOOK: lprcat("\n\nYou have found a book."); obook(); break; + + case OCOOKIE: lprcat("\n\nYou have found a fortune cookie."); ocookie(); break; + + case OTHRONE: if (nearbymonst()) return; + lprintf("\n\nThere is %s here!",objectname[i]); othrone(0); break; + + case OTHRONE2: if (nearbymonst()) return; + lprintf("\n\nThere is %s here!",objectname[i]); othrone(1); break; + + case ODEADTHRONE: lprintf("\n\nThere is %s here!",objectname[i]); odeadthrone(); break; + + case OORB: lprcat("\n\nYou have found the Orb!!!!!"); oorb(); break; + + case OPIT: lprcat("\n\nYou're standing at the top of a pit."); opit(); break; + + case OSTAIRSUP: lprcat("\n\nThere is a circular staircase here"); ostairs(1); /* up */ break; + + case OELEVATORUP: lprcat("\n\nYou feel heavy for a moment, but the feeling disappears"); + oelevator(1); /* up */ break; + + case OFOUNTAIN: if (nearbymonst()) return; + lprcat("\n\nThere is a fountain here"); ofountain(); break; + + case OSTATUE: if (nearbymonst()) return; + lprcat("\n\nYou are standing in front of a statue"); ostatue(); break; + + case OCHEST: lprcat("\n\nThere is a chest here"); ochest(); break; + + case OIVTELETRAP: if (rnd(11)<6) return; + item[playerx][playery] = OTELEPORTER; + know[playerx][playery] = 1; + + case OTELEPORTER: lprcat("\nZaaaappp! You've been teleported!\n"); + beep(); nap(3000); oteleport(0); + break; + + case OSCHOOL: if (nearbymonst()) return; + lprcat("\n\nYou have found the College of Larn."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); + if (i == 'g') { oschool(); /* the college of larn */ } + else lprcat(" stay here"); + break; + + case OMIRROR: if (nearbymonst()) return; + lprcat("\n\nThere is a mirror here"); omirror(); break; + + case OBANK2: + case OBANK: if (nearbymonst()) return; + if (i==OBANK) lprcat("\n\nYou have found the bank of Larn."); + else lprcat("\n\nYou have found a branch office of the bank of Larn."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + j=0; while ((j!='g') && (j!='i') && (j!='\33')) j=getchar(); + if (j == 'g') { if (i==OBANK) obank(); else obank2(); /* the bank of larn */ } + else lprcat(" stay here"); + break; + + case ODEADFOUNTAIN: if (nearbymonst()) return; + lprcat("\n\nThere is a dead fountain here"); break; + + case ODNDSTORE: if (nearbymonst()) return; + lprcat("\n\nThere is a DND store here."); + lprcat("\nDo you (g) go inside, or (i) stay here? "); + i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); + if (i == 'g') + dndstore(); /* the dnd adventurers store */ + else lprcat(" stay here"); + break; + + case OSTAIRSDOWN: lprcat("\n\nThere is a circular staircase here"); ostairs(-1); /* down */ break; + + case OELEVATORDOWN: lprcat("\n\nYou feel light for a moment, but the feeling disappears"); + oelevator(-1); /* down */ + break; + + case OOPENDOOR: lprintf("\n\nYou have found %s",objectname[i]); + lprcat("\nDo you (c) close it"); iopts(); + i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar(); + if ((i=='\33') || (i=='i')) { ignore(); break; } + lprcat("close"); forget(); + item[playerx][playery]=OCLOSEDDOOR; + iarg[playerx][playery]=0; + playerx = lastpx; playery = lastpy; + break; + + case OCLOSEDDOOR: lprintf("\n\nYou have found %s",objectname[i]); + lprcat("\nDo you (o) try to open it"); iopts(); + i=0; while ((i!='o') && (i!='i') && (i!='\33')) i=getchar(); + if ((i=='\33') || (i=='i')) + { ignore(); playerx = lastpx; + playery = lastpy; break; } + else + { + lprcat("open"); + if (rnd(11)<7) + { + switch(iarg[playerx][playery]) + { + case 6: c[AGGRAVATE] += rnd(400); break; + + case 7: lprcat("\nYou are jolted by an electric shock "); + lastnum=274; losehp(rnd(20)); bottomline(); break; + + case 8: loselevel(); break; + + case 9: lprcat("\nYou suddenly feel weaker "); + if (c[STRENGTH]>3) c[STRENGTH]--; + bottomline(); break; + + default: break; + } + playerx = lastpx; playery = lastpy; + } + else + { + forget(); item[playerx][playery]=OOPENDOOR; + } + } + break; + + case OENTRANCE: lprcat("\nYou have found "); lprcat(objectname[OENTRANCE]); + lprcat("\nDo you (g) go inside"); iopts(); + i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar(); + if (i == 'g') + { + newcavelevel(1); playerx=33; playery=MAXY-2; + item[33][MAXY-1]=know[33][MAXY-1]=mitem[33][MAXY-1]=0; + draws(0,MAXX,0,MAXY); bot_linex(); return; + } + else ignore(); + break; + + case OVOLDOWN: lprcat("\nYou have found "); lprcat(objectname[OVOLDOWN]); + lprcat("\nDo you (c) climb down"); iopts(); + i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar(); + if ((i=='\33') || (i=='i')) { ignore(); break; } + if (level!=0) { lprcat("\nThe shaft only extends 5 feet downward!"); return; } + if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); beep(); + lastnum=275; losehp(30+rnd(20)); bottomhp(); } + + else lprcat("climb down"); nap(3000); newcavelevel(MAXLEVEL); + for (i=0; i 45+5*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); beep(); + lastnum=275; losehp(15+rnd(20)); bottomhp(); return; } + lprcat("climb up"); lflush(); nap(3000); newcavelevel(0); + for (i=0; i0) lprintf("+ %d",(long)tmp); else if (tmp<0) lprintf(" %d",(long)tmp); + } + lprcat("\nDo you want to (t) take it"); iopts(); + i=0; while (i!='t' && i!='i' && i!='\33') i=getchar(); + if (i == 't') + { lprcat("take"); if (take(itm,tmp)==0) forget(); return; } + ignore(); + } + + +/* + ******* + OSTAIRS + ******* + + subroutine to process the stair cases + if dir > 0 the up else down + */ +ostairs(dir) + int dir; + { + register int k; + lprcat("\nDo you (s) stay here "); + if (dir > 0) lprcat("(u) go up "); else lprcat("(d) go down "); + lprcat("or (f) kick stairs? "); + + while (1) switch(getchar()) + { + case '\33': + case 's': case 'i': lprcat("stay here"); return; + + case 'f': lprcat("kick stairs"); + if (rnd(2) == 1) + lprcat("\nI hope you feel better. Showing anger rids you of frustration."); + else + { + k=rnd((level+1)<<1); + lprintf("\nYou hurt your foot dumb dumb! You suffer %d hit points",(long)k); + lastnum=276; losehp(k); bottomline(); + } + return; + + case 'u': lprcat("go up"); + if (dir < 0) lprcat("\nThe stairs don't go up!"); + else + if (level>=2 && level!=11) + { + k = level; newcavelevel(level-1); + draws(0,MAXX,0,MAXY); bot_linex(); + } + else lprcat("\nThe stairs lead to a dead end!"); + return; + + case 'd': lprcat("go down"); + if (dir > 0) lprcat("\nThe stairs don't go down!"); + else + if (level!=0 && level!=10 && level!=13) + { + k = level; newcavelevel(level+1); + draws(0,MAXX,0,MAXY); bot_linex(); + } + else lprcat("\nThe stairs lead to a dead end!"); + return; + }; + } + + +/* + ********* + OTELEPORTER + ********* + + subroutine to handle a teleport trap +/- 1 level maximum + */ +oteleport(err) + int err; + { + register int tmp; + if (err) if (rnd(151)<3) died(264); /* stuck in a rock */ + c[TELEFLAG]=1; /* show ?? on bottomline if been teleported */ + if (level==0) tmp=0; + else if (level < MAXLEVEL) + { tmp=rnd(5)+level-3; if (tmp>=MAXLEVEL) tmp=MAXLEVEL-1; + if (tmp<1) tmp=1; } + else + { tmp=rnd(3)+level-2; if (tmp>=MAXLEVEL+MAXVLEVEL) tmp=MAXLEVEL+MAXVLEVEL-1; + if (tmp=MAXPOTION) return; /* check for within bounds */ + potionname[pot][0] = ' '; + switch(pot) + { + case 9: lprcat("\nYou feel greedy . . ."); nap(2000); + for (i=0; i c[HPMAX]) c[HP]=c[HPMAX]; break; + + case 2: lprcat("\nSuddenly, you feel much more skillful!"); + raiselevel(); raisemhp(1); return; + + case 3: lprcat("\nYou feel strange for a moment"); + c[rund(6)]++; break; + + case 4: lprcat("\nYou feel more self confident!"); + c[WISDOM] += rnd(2); break; + + case 5: lprcat("\nWow! You feel great!"); + if (c[STRENGTH]<12) c[STRENGTH]=12; else c[STRENGTH]++; break; + + case 6: lprcat("\nYour charm went up by one!"); c[CHARISMA]++; break; + + case 8: lprcat("\nYour intelligence went up by one!"); + c[INTELLIGENCE]++; break; + + case 10: for (i=0; i>2)+2; while(--i>0) { parse2(); nap(1000); } + cursors(); lprcat("\nYou woke up!"); return; + + case 7: lprcat("\nYou become dizzy!"); + if (--c[STRENGTH] < 3) c[STRENGTH]=3; break; + + case 11: lprcat("\nYou stagger for a moment . ."); + for (i=0; i=MAXSCROLL) return; /* be sure we are within bounds */ + scrollname[typ][0] = ' '; + switch(typ) + { + case 0: lprcat("\nYour armor glows for a moment"); enchantarmor(); return; + + case 1: lprcat("\nYour weapon glows for a moment"); enchweapon(); return; /* enchant weapon */ + + case 2: lprcat("\nYou have been granted enlightenment!"); + yh = min(playery+7,MAXY); xh = min(playerx+25,MAXX); + yl = max(playery-7,0); xl = max(playerx-25,0); + for (i=yl; i=0) lprintf("\nYou went forward in time by %d mobuls",(long)((i+99)/100)); + else lprintf("\nYou went backward in time by %d mobuls",(long)(-(i+99)/100)); + adjtime((long)i); /* adjust time for time warping */ + return; + + case 8: oteleport(0); return; /* teleportation */ + + case 9: c[AWARENESS] += 1800; return; /* expanded awareness */ + + case 10: c[HASTEMONST] += rnd(55)+12; return; /* haste monster */ + + case 11: for (i=0; i 255) j=255; /* double value */ + ivenarg[i] = j; break; + } + break; + + case 18: for (i=0; i<11; i++) c[exten[i]] <<= 1; /* spell extension */ + break; + + case 19: for (i=0; i<26; i++) /* identify */ + { + if (iven[i]==OPOTION) potionname[ivenarg[i]][0] = ' '; + if (iven[i]==OSCROLL) scrollname[ivenarg[i]][0] = ' '; + } + break; + + case 20: for (i=0; i<10; i++) /* remove curse */ + if (c[curse[i]]) c[curse[i]] = 1; + break; + + case 21: annihilate(); break; /* scroll of annihilation */ + + case 22: godirect(22,150,"The ray hits the %s",0,' '); /* pulverization */ + break; + case 23: c[LIFEPROT]++; break; /* life protection */ + }; + } + + +oorb() + { + } + +opit() + { + register int i; + if (rnd(101)<81) + if (rnd(70) > 9*c[DEXTERITY]-packweight() || rnd(101)<5) + if (level==MAXLEVEL-1) obottomless(); else + if (level==MAXLEVEL+MAXVLEVEL-1) obottomless(); else + { + if (rnd(101)<20) + { + i=0; lprcat("\nYou fell into a pit! Your fall is cushioned by an unknown force\n"); + } + else + { + i = rnd(level*3+3); + lprintf("\nYou fell into a pit! You suffer %d hit points damage",(long)i); + lastnum=261; /* if he dies scoreboard will say so */ + } + losehp(i); nap(2000); newcavelevel(level+1); draws(0,MAXX,0,MAXY); + } + } + +obottomless() + { + lprcat("\nYou fell into a bottomless pit!"); beep(); nap(3000); died(262); + } +oelevator(dir) + int dir; + { +#ifdef lint + int x; + x=dir; + dir=x; +#endif lint + } + +ostatue() + { + } + +omirror() + { + } + +obook() + { + lprcat("\nDo you "); + if (c[BLINDCOUNT]==0) lprcat("(r) read it, "); lprcat("(t) take it"); iopts(); + while (1) switch(getchar()) + { + case '\33': + case 'i': ignore(); return; + + case 'r': if (c[BLINDCOUNT]) break; + lprcat("read"); + /* no more book */ readbook(iarg[playerx][playery]); forget(); return; + + case 't': lprcat("take"); if (take(OBOOK,iarg[playerx][playery])==0) forget(); /* no more book */ + return; + }; + } + +/* + function to read a book + */ +readbook(lev) + register int lev; + { + register int i,tmp; + if (lev<=3) i = rund((tmp=splev[lev])?tmp:1); else + i = rnd((tmp=splev[lev]-9)?tmp:1) + 9; + spelknow[i]=1; + lprintf("\nSpell \"%s\": %s\n%s",spelcode[i],spelname[i],speldescript[i]); + if (rnd(10)==4) + { lprcat("\nYour int went up by one!"); c[INTELLIGENCE]++; bottomline(); } + } + +ocookie() + { + char *p; + lprcat("\nDo you (e) eat it, (t) take it"); iopts(); + while (1) switch(getchar()) + { + case '\33': + case 'i': ignore(); return; + + case 'e': lprcat("eat\nThe cookie tasted good."); + forget(); /* no more cookie */ + if (c[BLINDCOUNT]) return; + if (!(p=fortune(fortfile))) return; + lprcat(" A message inside the cookie reads:\n"); lprcat(p); + return; + + case 't': lprcat("take"); if (take(OCOOKIE,0)==0) forget(); /* no more book */ + return; + }; + } + + +/* routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth 100* the argument */ +ogold(arg) + int arg; + { + register long i; + i = iarg[playerx][playery]; + if (arg==OMAXGOLD) i *= 100; + else if (arg==OKGOLD) i *= 1000; + else if (arg==ODGOLD) i *= 10; + lprintf("\nIt is worth %d!",(long)i); c[GOLD] += i; bottomgold(); + item[playerx][playery] = know[playerx][playery] = 0; /* destroy gold */ + } + +ohome() + { + register int i; + nosignal = 1; /* disable signals */ + for (i=0; i<26; i++) if (iven[i]==OPOTION) if (ivenarg[i]==21) + { + iven[i]=0; /* remove the potion of cure dianthroritis from inventory */ + clear(); lprcat("Congratulations. You found a potion of cure dianthroritis.\n"); + lprcat("\nFrankly, No one thought you could do it. Boy! Did you surprise them!\n"); + if (gtime>TIMELIMIT) + { + lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n"); + lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n"); + nap(5000); died(269); + } + else + { + lprcat("\nThe doctor is now administering the potion, and in a few moments\n"); + lprcat("Your daughter should be well on her way to recovery.\n"); + nap(6000); + lprcat("\nThe potion is"); nap(3000); lprcat(" working! The doctor thinks that\n"); + lprcat("your daughter will recover in a few days. Congratulations!\n"); + beep(); nap(5000); died(263); + } + } + + while (1) + { + clear(); lprintf("Welcome home %s. Latest word from the doctor is not good.\n",logname); + + if (gtime>TIMELIMIT) + { + lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n"); + lprcat("You didn't make it in time. In your agony, you kill the doctor,\nyour wife, and yourself! Too bad!\n"); + nap(5000); died(269); + } + + lprcat("\nThe diagnosis is confirmed as dianthroritis. He guesses that\n"); + lprintf("your daughter has only %d mobuls left in this world. It's up to you,\n",(long)((TIMELIMIT-gtime+99)/100)); + lprintf("%s, to find the only hope for your daughter, the very rare\n",logname); + lprcat("potion of cure dianthroritis. It is rumored that only deep in the\n"); + lprcat("depths of the caves can this potion be found.\n\n\n"); + lprcat("\n ----- press "); standout("return"); + lprcat(" to continue, "); standout("escape"); + lprcat(" to leave ----- "); + i=getchar(); while (i!='\33' && i!='\n') i=getchar(); + if (i=='\33') { drawscreen(); nosignal = 0; /* enable signals */ return; } + } + } + +/* routine to save program space */ +iopts() + { lprcat(", or (i) ignore it? "); } +ignore() + { lprcat("ignore\n"); } + -- cgit v1.2.3-56-ge451