itverb.c

Go to the documentation of this file.
00001 /*      program ITVERB.C                                        */
00002 
00003 
00004 #include        <stdio.h>
00005 #include        "advent.h"
00006 #include        "advdec.h"
00007 
00008 _PROTOTYPE(void needobj, (void));
00009 _PROTOTYPE(void ivtake, (void));
00010 _PROTOTYPE(void ivopen, (void));
00011 _PROTOTYPE(void ivkill, (void));
00012 _PROTOTYPE(void ivdrink, (void));
00013 _PROTOTYPE(void ivquit, (void));
00014 _PROTOTYPE(void ivfoo, (void));
00015 _PROTOTYPE(void inventory, (void));
00016 _PROTOTYPE(void addobj, (int obj));
00017 _PROTOTYPE(void ivpour, (void));
00018 _PROTOTYPE(void ivfill, (void));
00019 _PROTOTYPE(void ivbrief, (void));
00020 _PROTOTYPE(void ivread, (void));
00021 _PROTOTYPE(void ivcombo, (void));
00022 _PROTOTYPE(void iveat, (void));
00023 /*
00024   Routines to process intransitive verbs
00025 */
00026 void itverb()
00027 {
00028     int i;
00029 
00030     newtravel = FALSE;
00031     switch (verb) {
00032     case DROP:
00033     case SAY:
00034     case WAVE:
00035     case CALM:
00036     case RUB:
00037     case THROW:
00038     case FIND:
00039     case FEED:
00040     case BREAK:
00041     case WAKE:
00042     case WEAR:
00043     case HIT:
00044     case DIAL:
00045     case PLAY:
00046     case PICK:
00047     case PUT:
00048     case TURN:          needobj();      break;
00049     case TAKE:
00050     case YANK:
00051     case GET:
00052     case INSRT:
00053     case REMOVE:
00054     case BURN:          ivtake();       break;
00055     case OPEN:
00056     case CLOSE:
00057     case LOCK:
00058     case UNLOCK:        ivopen();       break;
00059     case NOTHING:       rspeak(54);     break;
00060     case ON:
00061     case OFF:           trverb();       break;
00062     case WALK:          actspk(verb);   break;
00063     case KILL:          ivkill();       break;
00064     case POUR:          ivpour();       break;
00065     case EAT:           iveat();        break;
00066     case DRINK:         ivdrink();      break;
00067     case QUIT:          ivquit();       break;
00068     case INVENTORY:     inventory();    break;
00069     case FILL:          ivfill();       break;
00070     case BLAST:         ivblast();      break;
00071     case SCORE:         score(TRUE);    break;
00072     case FOO:           ivfoo();        break;
00073     case BRIEF:         ivbrief();      break;
00074     case READ:          ivread();       break;
00075     case SUSPEND:
00076         if (g.closing)
00077             rspeak(378);
00078         else
00079             saveadv("advent.sav");
00080         break;
00081     case RESTORE:       restore("advent.sav");  break;
00082     case ANSWER:
00083         if ((g.loc != 189) || (g.prop[PHONE] != 0))
00084             needobj();
00085         else {
00086             object = PHONE;
00087             itverb();
00088         }
00089         break;
00090     case BLOW:          rspeak(268);    break;
00091         /* Action verb 'LEAVE' has no object */
00092     case LEAVE:         bug(29);        break;
00093         /* Call if no phone is handy, yell. */
00094     case YELL:
00095         if (!here(PHONE))
00096             needobj();
00097         else if (!g.closed)
00098             rspeak(271);
00099         else {
00100             rspeak(283);
00101             normend();
00102         }
00103         break;
00104         /* Health. give him a diagnosis. */
00105     case HEALTH:
00106         if (g.numdie)
00107             fprintf(stdout, "You have been killed %d times otherwise\n",
00108                     g.numdie);
00109         if (g.health >= 95) {
00110             if (pct(50))
00111                 rspeak(348);
00112             else
00113                 rspeak(349);
00114         } else {
00115             fprintf(stdout,
00116                "Your health rating is %2d out of a possible 100.\n",
00117                     g.health);
00118             rspeak(381 + (100 - g.health) / 20);
00119         }
00120         break;
00121     case LOOK:          ivlook();       break;
00122     case COMBO:
00123         if (at(SAFE))
00124             ivcombo();
00125         break;
00126     case SWEEP:
00127         /* Dust/sweep */
00128         if (!at(CARVNG) || !athand(BRUSH) || (g.prop[CARVNG] == 1))
00129             rspeak(342);
00130         else {
00131             g.prop[CARVNG] = 1;
00132             rspeak(363);
00133             rspeak(372);
00134         }
00135         break;
00136     case TERSE:
00137         /* Terse/unterse. supress all long_form descriptions. */
00138         g.terse = !g.terse;
00139         g.detail = 3;
00140         rspeak(54);
00141         break;
00142     case WIZ:
00143         is_wiz = !is_wiz;
00144     case MAP:
00145         rspeak(54);
00146         break;
00147     case GATE:
00148         if (is_wiz) {
00149             static char buf[INPUTBUFLEN];
00150             sscanf(ask("Location ? ", buf, sizeof(buf)), "%d", &g.loc);
00151         }
00152         rspeak(54);
00153         break;
00154     case PIRLOC:
00155         if (is_wiz) {
00156             fprintf(stdout, "The dwarfs are at locations:\n");
00157             for (i = 1; i < DWARFMAX; i++)
00158                 fprintf(stdout, "  %4d", g.dloc[i]);
00159             fprintf(stdout, "\nThe pirate is at location %4d\n",
00160                     g.dloc[DWARFMAX]);
00161         }
00162         rspeak(54);
00163         break;
00164     default:
00165         printf("This intransitive not implemented yet\n");
00166     }
00167     return;
00168 }
00169 
00170 /*
00171   Routine to indicate no reasonable
00172   object for verb found.  Used mostly by
00173   intransitive verbs.
00174 */
00175 void needobj()
00176 {
00177     printf("%s what?\n", vtxt[vrbx]);
00178     return;
00179 }
00180 
00181 /*
00182   CARRY, TAKE etc.
00183 */
00184 void ivtake()
00185 {
00186     int anobj, item;
00187 
00188     anobj = 0;
00189     for (item = 1; item < MAXOBJ; ++item)
00190         if (g.place[item] == g.loc)
00191             if (anobj == 0)
00192                 anobj = item;
00193             else {
00194                 needobj();
00195                 return;
00196             }
00197 
00198     if (anobj == 0 || (dcheck() && g.dflag >= 2) || blind())
00199         needobj();
00200     else {
00201         object = anobj;
00202         if (verb == YANK)
00203             vyank();
00204         else if (verb == WEAR)
00205             vwear();
00206         else
00207             vtake();
00208     }
00209     return;
00210 }
00211 
00212 /*
00213   OPEN, LOCK, UNLOCK
00214 */
00215 void ivopen()
00216 {
00217     int obj_cnt, item;
00218 
00219     for (item = 1, obj_cnt = 0; item < MAXOBJ; item++) {
00220         if ((g.place[item] == g.loc) && (hinged(item))) {
00221             object = item;
00222             obj_cnt++;
00223         }
00224     }
00225     if (obj_cnt != 1)
00226         needobj();
00227     else if (verb == LOCK)
00228         vlock();
00229     else if (verb == UNLOCK)
00230         vunlock();
00231     else if (verb == SHUT)
00232         vclose();
00233     else
00234         vopen();
00235 }
00236 
00237 /*
00238   ATTACK, KILL etc
00239 */
00240 boolean previous_obj;
00241 
00242 void ivkill()
00243 {
00244     previous_obj = FALSE;
00245     if (dcheck() && g.dflag >= 2)
00246         object = DWARF;
00247     if (here(SNAKE))
00248         addobj(SNAKE);
00249     if (at(DRAGON) && g.prop[DRAGON] == 0)
00250         addobj(DRAGON);
00251     if (at(TROLL))
00252         addobj(TROLL);
00253     if (here(GNOME))
00254         addobj(GNOME);
00255     if (here(BEAR) && g.prop[BEAR] == 0)
00256         addobj(BEAR);
00257     if (here(WUMPUS) && g.prop[WUMPUS] == 0)
00258         addobj(WUMPUS);
00259     /* Can't attack bird by throwing axe */
00260     if (here(BIRD) && verb != THROW)
00261         addobj(BIRD);
00262     /* Clam and oyster both treated as clam for intransitive case; no
00263        harm done. */
00264     if (here(CLAM) || here(OYSTER))
00265         addobj(CLAM);
00266 
00267     if ((previous_obj) || (object == 0))
00268         rspeak(44);
00269     else
00270         vkill();
00271     return;
00272 }
00273 
00274 /*
00275   POUR if no object, assume liq in container, if holding one.
00276 */
00277 void ivpour()
00278 {
00279     if ((holding(BOTTLE)) && (liq(BOTTLE) != 0) && !holding(CASK))
00280         object = BOTTLE;
00281     if ((holding(CASK)) && (liq(CASK) != 0) && !holding(BOTTLE))
00282         object = CASK;
00283 
00284     if (object == 0)
00285         needobj();
00286     else
00287         trverb();
00288 }
00289 
00290 /*
00291   EAT. intransitive: assume edible if present, else ask what.
00292   If he as more than one edible, or none, 'EAT' is ambiguous
00293   without an explicit object.
00294 */
00295 void iveat()
00296 {
00297     int i;
00298 
00299     previous_obj = FALSE;
00300     for (i = 1; i < MAXOBJ; i++) {
00301         if ((here(i)) && (edible(i)))
00302             addobj(i);
00303     }
00304     if ((previous_obj) || (object == 0))
00305         needobj();
00306     else
00307         trverb();
00308 }
00309 
00310 /*
00311   DRINK.  If no object, assume water or wine and look for them here.
00312   If potable is in bottle or cask, drink that.  If not, see if there
00313   is something drinkable nearby (stream, lake, wine fountain, etc.),
00314   and drink that.  If he has stuff in both containers, ask which.
00315 */
00316 void ivdrink()
00317 {
00318     int ll;
00319 
00320     previous_obj = FALSE;
00321     ll = liqloc(g.loc);
00322     if ((ll == WATER) || (ll == WINE)) {
00323         object = ll;
00324         iobj = -1;
00325     }
00326     ll = liq(BOTTLE);
00327     if ((athand(BOTTLE)) && ((ll == WATER) || (ll == WINE))) {
00328         object = ll;
00329         iobj = BOTTLE;
00330     }
00331     ll = liq(CASK);
00332     if ((athand(CASK)) && ((ll == WATER) || (ll == WINE))
00333         && iobj != BOTTLE) {
00334         object = ll;
00335         iobj = CASK;
00336     } else
00337         object = 0;
00338 
00339     if (object == 0)
00340         needobj();
00341     else
00342         trverb();
00343 }
00344 
00345 /*
00346   QUIT intransitive only. Verify intent and exit if that's what he wants
00347 */
00348 void ivquit()
00349 {
00350     gaveup = yes(22, 54, 54);
00351     if (gaveup)
00352         normend();
00353     return;
00354 }
00355 
00356 /*
00357   INVENTORY
00358 */
00359 void inventory()
00360 {
00361     int i, msg;
00362     boolean init_msg;
00363 
00364     init_msg = TRUE;
00365     msg = 98;
00366     for (i = 1; i < MAXOBJ; i++) {
00367         if (!holding(i) || wearng(i) || i == BEAR || i == BOAT)
00368             continue;
00369         if (init_msg)
00370             rspeak(99);
00371         pspeak(i, -1);
00372         init_msg = FALSE;
00373         msg = 0;
00374         lookin(i);
00375     }
00376 
00377     /* Tell him what he is wearing */
00378     init_msg = TRUE;
00379     for (i = 1; i < MAXOBJ; i++) {
00380         if (wearng(i)) {
00381             if (init_msg)
00382                 fprintf(stdout, "\nYou are wearing:\n");
00383             fprintf(stdout, "     ");
00384             pspeak(i, -1);
00385             msg = 0;
00386             init_msg = FALSE;
00387         }
00388     }
00389 
00390     if (holding(BOAT)) {
00391         rspeak(221);
00392         lookin(BOAT);
00393     }
00394     if (holding(BEAR))
00395         msg = 141;
00396 
00397     if (msg)
00398         rspeak(msg);
00399     return;
00400 }
00401 
00402 /*
00403   FILL bottle or cask must be empty, and some liquid avaible
00404 */
00405 void ivfill()
00406 {
00407     if ((g.prop[CASK] == 1) && !here(CASK))
00408         object = CASK;
00409     if ((g.prop[BOTTLE] == 1) && !here(BOTTLE))
00410         object = BOTTLE;
00411 
00412     if ((here(BOTTLE) && here(CASK)) || (object == 0))
00413         needobj();
00414     else
00415         trverb();
00416 }
00417 
00418 /*
00419   BLAST etc.
00420 */
00421 void ivblast()
00422 {
00423     if (!g.closed)
00424         actspk(verb);
00425     else {
00426         g.bonus = 135;
00427         if (g.place[ROD2] == 212 && g.loc == 116)
00428             g.bonus = 133;
00429         if (g.place[ROD2] == 116 && g.loc != 116)
00430             g.bonus = 134;
00431         rspeak(g.bonus);
00432         normend();
00433     }
00434     return;
00435 }
00436 
00437 /*
00438   Handle fee fie foe foo...
00439 */
00440 void ivfoo()
00441 {
00442     int k;
00443     int msg;
00444 
00445     k = VAL(vocab(vtxt[vrbx], MISC));
00446     if (g.foobar != 1 - k) {
00447         if (g.foobar == 0)
00448             msg = 42;
00449         else
00450             msg = 151;
00451         rspeak(msg);
00452         return;
00453     }
00454     g.foobar = k;
00455     if (k != 4)
00456         return;
00457     g.foobar = 0;
00458     if (g.place[EGGS] == plac[EGGS] ||
00459         (toting(EGGS) && g.loc == plac[EGGS])) {
00460         rspeak(42);
00461         return;
00462     }
00463     /* Bring back troll if we steal the eggs back from him before
00464        crossing */
00465     if (g.place[EGGS] == 0 && g.place[TROLL] == 0 && g.prop[TROLL] == 0)
00466         g.prop[TROLL] = 1;
00467 
00468     if (here(EGGS))
00469         k = 1;
00470     else if (g.loc == plac[EGGS])
00471         k = 0;
00472     else
00473         k = 2;
00474     move(EGGS, plac[EGGS]);
00475     pspeak(EGGS, k);
00476     return;
00477 }
00478 
00479 /*
00480   brief/unbrief. intransitive only.
00481   suppress long descriptions after first time.
00482 */
00483 void ivbrief()
00484 {
00485     int msg;
00486 
00487     g.detail = 3;
00488     g.terse = FALSE;
00489     if (g.abbnum != 10000) {
00490         msg = 156;
00491         g.abbnum = 10000;
00492     } else {
00493         msg = 374;
00494         g.abbnum = 5;
00495     }
00496     rspeak(msg);
00497 }
00498 
00499 /*
00500   read etc...
00501 */
00502 void ivread()
00503 {
00504     previous_obj = FALSE;
00505     if (here(BOOK))
00506         object = BOOK;
00507     if (here(BOOK2))
00508         addobj(BOOK2);
00509     if (here(BILLBD))
00510         addobj(BILLBD);
00511     if (here(CARVNG))
00512         addobj(CARVNG);
00513     if (here(MAGAZINE))
00514         addobj(MAGAZINE);
00515     if (here(MESSAGE))
00516         addobj(MESSAGE);
00517     if (here(OYSTER))
00518         addobj(OYSTER);
00519     if (here(POSTER))
00520         addobj(POSTER);
00521     if (here(TABLET))
00522         addobj(TABLET);
00523 
00524     if (previous_obj || object == 0 || dark())
00525         needobj();
00526     else
00527         vread();
00528     return;
00529 }
00530 
00531 /*
00532    LOOK. can't give more detail. Pretend it wasn't dark (though it may "now"
00533    be dark) so he won't fall into a pit staring into the gloom.
00534 */
00535 void ivlook()
00536 {
00537     if (g.detail++ < 3)
00538         rspeak(15);
00539     g.wzdark = FALSE;
00540     g.visited[g.loc] = 0;
00541     g.newloc = g.loc;
00542     newtravel = TRUE;
00543     return;
00544 }
00545 
00546 /*
00547   COMBO: trying to open safe. (see comments for fee fie foe foo)
00548 */
00549 void ivcombo()
00550 {
00551     int k, msg;
00552 
00553     k = VAL(vocab(vtxt[vrbx], MISC)) - 10;
00554     msg = 42;
00555     if (g.combo != 1 - k) {
00556         if (g.combo != 0)
00557             msg = 366;
00558         rspeak(msg);
00559         return;
00560     }
00561     g.combo = k;
00562     if (k != 3)
00563         rspeak(371);
00564     else {
00565         g.combo = 0;
00566         bitoff(SAFE, LOCKBT);
00567         biton(SAFE, OPENBT);
00568         g.prop[SAFE] = 1;
00569         if (g.prop[BOOK] < 0) {
00570             g.tally--;
00571             g.prop[BOOK] = 0;
00572             /* If remaining treasures too elusive, zap his lamp. this
00573                duplicates some code, must be done here since book is
00574                contained ins safe & tally stuff only works for thing
00575                deposited at a location. */
00576             if ((g.tally == g.tally2) && (g.tally != 0))
00577                 g.limit = (g.limit < 35) ? g.limit : 35;
00578         }
00579         rspeak(365);
00580     }
00581 }
00582 
00583 /*
00584   ensure uniqueness as objects are searched
00585   out for an intransitive verb
00586 */
00587 void addobj(obj)
00588 int obj;
00589 {
00590     if (!previous_obj) {
00591         if (object != 0)
00592             previous_obj = TRUE;
00593         else
00594             object = obj;
00595     }
00596     return;
00597 }

Generated on Fri Apr 14 22:56:39 2006 for minix by  doxygen 1.4.6