home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / NetHack 3.1.3 / source / src / timeout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  11.7 KB  |  472 lines  |  [TEXT/R*ch]

  1. /*    SCCS Id: @(#)timeout.c    3.1    93/07/07    */
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6.  
  7. STATIC_DCL void NDECL(stoned_dialogue);
  8. STATIC_DCL void NDECL(vomiting_dialogue);
  9. STATIC_DCL void NDECL(choke_dialogue);
  10. STATIC_DCL void FDECL(hatch_it, (struct obj *));
  11.  
  12. static void FDECL(age_candle, (struct obj *));
  13.  
  14. #ifdef OVLB
  15.  
  16. /* He is being petrified - dialogue by inmet!tower */
  17. static NEARDATA const char *stoned_texts[] = {
  18.     "You are slowing down.",        /* 5 */
  19.     "Your limbs are stiffening.",        /* 4 */
  20.     "Your limbs have turned to stone.",    /* 3 */
  21.     "You have turned to stone.",        /* 2 */
  22.     "You are a statue."            /* 1 */
  23. };
  24.  
  25. STATIC_OVL void
  26. stoned_dialogue() {
  27.     register long i = (Stoned & TIMEOUT);
  28.  
  29.     if(i > 0 && i <= SIZE(stoned_texts))
  30.         pline(stoned_texts[SIZE(stoned_texts) - i]);
  31.     if(i == 5)
  32.         Fast &= ~(TIMEOUT|INTRINSIC);
  33.     if(i == 3)
  34.         nomul(-3);
  35.     exercise(A_DEX, FALSE);
  36. }
  37.  
  38. /* He is getting sicker and sicker prior to vomiting */
  39. static NEARDATA const char *vomiting_texts[] = {
  40.     "You are feeling mildly nauseous.",    /* 14 */
  41.     "You feel slightly confused.",        /* 11 */
  42.     "You can't seem to think straight.",    /* 8 */
  43.     "You feel incredibly sick.",        /* 5 */
  44.     "You suddenly vomit!"            /* 2 */
  45. };
  46.  
  47. STATIC_OVL void
  48. vomiting_dialogue() {
  49.     register long i = (Vomiting & TIMEOUT) / 3L;
  50.  
  51.     if ((((Vomiting & TIMEOUT) % 3L) == 2) && (i >= 0)
  52.         && (i < SIZE(vomiting_texts)))
  53.         pline(vomiting_texts[SIZE(vomiting_texts) - i - 1]);
  54.  
  55.     switch ((int) i) {
  56.     case 0:
  57.         vomit();
  58.         morehungry(20);
  59.         break;
  60.     case 2:
  61.         make_stunned(HStun + d(2,4), FALSE);
  62.         /* fall through */
  63.     case 3:
  64.         make_confused(HConfusion + d(2,4), FALSE);
  65.         break;
  66.     }
  67.     exercise(A_CON, FALSE);
  68. }
  69.  
  70. static NEARDATA const char *choke_texts[] = {
  71.     "You find it hard to breathe.",
  72.     "You're gasping for air.",
  73.     "You can no longer breathe.",
  74.     "You're turning %s.",
  75.     "You suffocate."
  76. };
  77.  
  78. STATIC_OVL void
  79. choke_dialogue()
  80. {
  81.     register long i = (Strangled & TIMEOUT);
  82.  
  83.     if(i > 0 && i <= SIZE(choke_texts))
  84.         pline(choke_texts[SIZE(choke_texts) - i], Hallucination ?
  85.             hcolor() : blue);
  86.     exercise(A_STR, FALSE);
  87. }
  88.  
  89. #endif /* OVLB */
  90. #ifdef OVL0
  91.  
  92. void
  93. nh_timeout()
  94. {
  95.     register struct prop *upp;
  96.     int sleeptime;
  97.  
  98.     if(u.uluck && moves % (u.uhave.amulet || u.ugangr ? 300 : 600) == 0) {
  99.     /* Cursed luckstones stop bad luck from timing out; blessed luckstones
  100.      * stop good luck from timing out; normal luckstones stop both;
  101.      * neither is stopped if you don't have a luckstone.
  102.      * Luck is based at 0 usually, +1 if a full moon and -1 on Friday 13th
  103.      */
  104.         register int time_luck = stone_luck(FALSE);
  105.         boolean nostone = !carrying(LUCKSTONE) && !stone_luck(TRUE);
  106.         int baseluck = (flags.moonphase == FULL_MOON) ? 1 : 0;
  107.  
  108.         baseluck -= (flags.friday13 ? 1 : 0);
  109.  
  110.         if(u.uluck > baseluck && (nostone || time_luck < 0))
  111.         u.uluck--;
  112.         else if(u.uluck < baseluck && (nostone || time_luck > 0))
  113.         u.uluck++;
  114.     }
  115.     if(u.uinvulnerable) return; /* things past this point could kill you */
  116.     if(Stoned) stoned_dialogue();
  117.     if(Vomiting) vomiting_dialogue();
  118.     if(Strangled) choke_dialogue();
  119. #ifdef POLYSELF
  120.     if(u.mtimedone) if(!--u.mtimedone) rehumanize();
  121. #endif
  122.     if(u.ucreamed) u.ucreamed--;
  123.  
  124.     for(upp = u.uprops; upp < u.uprops+SIZE(u.uprops); upp++)
  125.         if((upp->p_flgs & TIMEOUT) && !(--upp->p_flgs & TIMEOUT)) {
  126.         switch(upp - u.uprops){
  127.         case STONED:
  128.             if (!killer) {
  129.                 killer_format = KILLED_BY_AN;
  130.                 killer = "cockatrice";
  131.             } done(STONING);
  132.             break;
  133.         case VOMITING:
  134.             make_vomiting(0L, TRUE);
  135.             break;
  136.         case SICK:
  137.             You("die from your illness.");
  138.             killer_format = KILLED_BY_AN;
  139.             killer = u.usick_cause;
  140.             done(POISONING);
  141.             break;
  142.         case FAST:
  143.             if (Fast & ~INTRINSIC) /* boot speed */
  144.                 ;
  145.             else
  146.                 You("feel yourself slowing down%s.",
  147.                             Fast ? " a bit" : "");
  148.             break;
  149.         case CONFUSION:
  150.             HConfusion = 1; /* So make_confused works properly */
  151.             make_confused(0L, TRUE);
  152.             stop_occupation();
  153.             break;
  154.         case STUNNED:
  155.             HStun = 1;
  156.             make_stunned(0L, TRUE);
  157.             stop_occupation();
  158.             break;
  159.         case BLINDED:
  160.             Blinded = 1;
  161.             make_blinded(0L, TRUE);
  162.             stop_occupation();
  163.             break;
  164.         case INVIS:
  165.             newsym(u.ux,u.uy);
  166.             if (!Invis && !See_invisible && !Blind) {
  167.                 You("are no longer invisible.");
  168.                 stop_occupation();
  169.             }
  170.             break;
  171.         case SEE_INVIS:
  172.             set_mimic_blocking(); /* do special mimic handling */
  173.             see_monsters();        /* make invis mons appear */
  174.             newsym(u.ux,u.uy);    /* make self appear */
  175.             stop_occupation();
  176.             break;
  177.         case WOUNDED_LEGS:
  178.             heal_legs();
  179.             stop_occupation();
  180.             break;
  181.         case HALLUC:
  182.             HHallucination = 1;
  183.             make_hallucinated(0L, TRUE, 0L);
  184.             stop_occupation();
  185.             break;
  186.         case SLEEPING:
  187.             if (unconscious() || Sleep_resistance)
  188.                 Sleeping += rnd(100);
  189.             else {
  190.                 You("fall asleep.");
  191.                 sleeptime = rnd(20);
  192.                 nomul(-sleeptime);
  193.                 u.usleep = 1;
  194.                 nomovemsg = "You wake up.";
  195.                 Sleeping = sleeptime + rnd(100);
  196.             }
  197.             break;
  198.         case LEVITATION:
  199.             (void) float_down();
  200.             break;
  201.         case STRANGLED:
  202.             killer_format = KILLED_BY;
  203.             killer = "strangulation";
  204.             done(DIED);
  205.             break;
  206.         case FUMBLING:
  207.             /* call this only when a move took place.  */
  208.             /* otherwise handle fumbling msgs locally. */
  209.             if (!Levitation && u.umoved) {
  210.                 if (OBJ_AT(u.ux, u.uy))
  211.                 You("trip over something.");
  212.                 else if (rn2(3) && is_ice(u.ux, u.uy))
  213.                 You("%s on the ice.",
  214.                     rn2(2) ? "slip" : "slide");
  215.                 else
  216.                 switch (rn2(4)) {
  217.                     case 1:
  218.                     if (ACCESSIBLE(levl[u.ux][u.uy].typ)) { /* not POOL or STONE */
  219.                         if (Hallucination) pline("A rock bites your %s.", body_part(FOOT));
  220.                         else You("trip over a rock.");
  221.                         break;
  222.                     }
  223.                     case 2:
  224.                     if (ACCESSIBLE(levl[u.ux][u.uy].typ)) { /* not POOL or STONE */
  225.                         if (Hallucination) You("slip on a banana peel.");
  226.                         else You("slip and nearly fall.");
  227.                         break;
  228.                     }
  229.                     case 3:
  230.                     You("flounder.");
  231.                     break;
  232.                     default:
  233.                     You("stumble.");
  234.                 }
  235.                 nomul(-2);
  236.                 nomovemsg = "";
  237.                 /* Fumbling can be noisy */
  238.                 if ((inv_weight() > -500)) {
  239.                     You("make a lot of noise!");
  240.                     wake_nearby();
  241.                 }
  242.             }
  243.             Fumbling += rnd(20);
  244.             break;
  245.         }
  246.     }
  247. }
  248.  
  249. #endif /* OVL0 */
  250. #ifdef OVLB
  251.  
  252. STATIC_OVL void
  253. hatch_it(otmp)        /* hatch the egg "otmp" if possible */
  254. register struct obj *otmp;
  255. {
  256.     register struct monst *mtmp;
  257. #ifdef POLYSELF
  258.     int yours = otmp->spe;
  259. #endif
  260.     long egg_age = monstermoves - otmp->age;
  261.  
  262.     if (egg_age > 200L) {        /* very old egg - it's dead */
  263.         otmp->corpsenm = -1;
  264.         return;
  265.     } else if (egg_age <= 150L) {    /* too young to hatch */
  266.         return;
  267.     } else if (rnd((int)egg_age) > 150) {
  268.         mtmp = makemon(&mons[big_to_little(otmp->corpsenm)], u.ux, u.uy);
  269.         useup(otmp);
  270.         if(mtmp) {
  271.  
  272.         if(Blind)
  273.             You("feel something %s from your pack!",
  274.             locomotion(mtmp->data, "drop"));
  275.         else
  276.             You("see %s %s out of your pack!",
  277.             a_monnam(mtmp),
  278.             locomotion(mtmp->data, "drop"));
  279.  
  280. #ifdef POLYSELF
  281.         if (yours) {
  282.             struct monst *mtmp2;
  283.  
  284.             pline("Its cries sound like \"%s.\"",
  285.             flags.female ? "mommy" : "daddy");
  286.             if ((mtmp2 = tamedog(mtmp, (struct obj *)0)) != 0)
  287.             mtmp = mtmp2;
  288.             mtmp->mtame = 20;
  289.             while ((otmp = (mtmp->minvent)) != 0) {
  290.             mtmp->minvent = otmp->nobj;
  291.             dealloc_obj(otmp);
  292.             }
  293.             return;
  294.         }
  295. #endif
  296.         if(mtmp->data->mlet == S_DRAGON) {
  297.             struct monst *mtmp2;
  298.  
  299.             verbalize("Gleep!");        /* Mything eggs :-) */
  300.             if ((mtmp2 = tamedog(mtmp, (struct obj *)0)) != 0)
  301.             mtmp = mtmp2;
  302.             while ((otmp = (mtmp->minvent)) != 0) {
  303.             mtmp->minvent = otmp->nobj;
  304.             dealloc_obj(otmp);
  305.             }
  306.         }
  307.         }
  308.     }
  309. }
  310.  
  311. #endif /* OVLB */
  312. #ifdef OVL1
  313.  
  314. void
  315. hatch_eggs()        /* hatch any eggs that have been too long in pack */
  316. {
  317.     register struct obj *otmp, *otmp2;
  318.  
  319.     for(otmp = invent; otmp; otmp = otmp2) {
  320.         otmp2 = otmp->nobj;        /* otmp may hatch */
  321.         if(otmp->otyp == EGG && otmp->corpsenm >= 0) hatch_it(otmp);
  322.         /* else if (Has_contents(otmp)) ...                */
  323.         /*                                */
  324.         /* Check for container here and hatch with the container.    */
  325.         /* One of these days...                    */
  326.         /* Maybe call hatch_eggs() with invent as a parameter so    */
  327.         /* that we can call it recursively.                */
  328.     }
  329. }
  330.  
  331. /* Burn up lit lamps.  Only applies to non-magic lamps; magic lamps stay
  332.  * lit as long as there's a genie inside.  We use obj->age to see how long
  333.  * there is left for the lamp to burn, but this differs from the use of
  334.  * age for corpses and eggs: for the latter items it's when the object was
  335.  * created, but for lamps it's the number of moves remaining.
  336.  */
  337. void
  338. burn_lamps()
  339. {
  340.     register struct obj *obj, *obj2;
  341.  
  342.     /* Note: magic lamps never go out as long as the genie's inside */
  343.     for (obj=invent; obj; obj=obj2) {
  344.         obj2 = obj->nobj;
  345.         if ((obj->otyp == OIL_LAMP || obj->otyp == BRASS_LANTERN)
  346.                             && obj->lamplit) {
  347.         obj->age--;
  348.         switch((int)obj->age) {
  349.             case 150:
  350.             case 100:
  351.             if (obj->otyp == BRASS_LANTERN) goto advmsg;
  352.             if (!Blind)
  353.                 Your("%s flickers.", xname(obj));
  354.             break;
  355.             case 50:
  356.             if (obj->otyp == BRASS_LANTERN) goto advmsg;
  357.             if (!Blind)
  358.                 Your("%s flickers considerably.", xname(obj));
  359.             break;
  360.             case 25:
  361.     advmsg:        if (!Blind) {
  362.                 if (obj->otyp == BRASS_LANTERN) {
  363.                 Your("lamp is getting dim.");
  364.                 if (Hallucination)
  365.                     pline("Batteries have not been invented yet.");
  366.                 } else
  367.                 Your("%s seems about to go out.", xname(obj));
  368.             }
  369.             break;
  370.             case 0: /* even if blind you'll know */
  371.             if (obj->otyp == BRASS_LANTERN)
  372.                 Your("lamp has run out of power.");
  373.             else Your("%s goes out.", xname(obj));
  374.             obj->lamplit = 0;
  375.             obj->spe = 0;
  376.             check_lamps();
  377.             break;
  378.             default: break;
  379.         }
  380.         }
  381.         if ((obj->otyp == CANDELABRUM_OF_INVOCATION || Is_candle(obj)) &&
  382.             obj->lamplit)
  383.         age_candle(obj);    /* candles may vanish */
  384.     }
  385. }
  386.  
  387. static void
  388. age_candle(otmp)
  389. register struct obj *otmp;
  390. {
  391.     register boolean many, 
  392.                      menorah = otmp->otyp == CANDELABRUM_OF_INVOCATION;
  393.  
  394.     otmp->age--;
  395.  
  396.     if (otmp->age == 0L) {
  397.         otmp->lamplit = 0;
  398.         many = menorah ? otmp->spe > 1 : otmp->quan > 1L;
  399.         if (menorah) {
  400.         pline("%s's flame%s.", 
  401.             The(xname(otmp)), (many ? "s die" : " dies"));
  402.         otmp->spe = 0;
  403.         } else {
  404.         Your("%s %s consumed!  %s",
  405.             xname(otmp), (many ? "are" : "is"),
  406.             (Hallucination ?
  407.                 (many ? "They shriek!" : "It shrieks!") :
  408.              Blind ? "" :
  409.                 (many ? "Their flames die." : "Its flame dies.")));
  410.         freeinv(otmp);
  411.         obfree(otmp, (struct obj *)0);
  412.         }
  413.         check_lamps();
  414.     } else if (Blind) {
  415.         return;
  416.     } else if (otmp->age == 15L) {
  417.         many = menorah ? otmp->spe > 1 : otmp->quan > 1L;
  418.         Norep("The %scandle%s flame%s flicker%s low!",
  419.             (menorah ? "candelabrum's " : ""),
  420.             (many ? "s'" : "'s"),
  421.             (many ? "s" : ""),
  422.             (many ? "" : "s"));
  423.     } else if (otmp->age == 75L) {
  424.         many = menorah ? otmp->spe > 1 : otmp->quan > 1L;
  425.         Norep("The %scandle%s getting short.",
  426.             menorah ? "candelabrum's " : "",
  427.             (many ? "s are" : " is"));
  428.     }
  429. }
  430. void
  431. do_storms()
  432. {
  433.     int nstrike;
  434.     register int x, y;
  435.     int dirx, diry;
  436.     int count;
  437.  
  438.     /* no lightning if not the air level or too often, even then */
  439.     if(!Is_airlevel(&u.uz) || rn2(8))
  440.     return;
  441.  
  442.     /* the number of strikes is 8-log2(nstrike) */
  443.     for(nstrike = rnd(64); nstrike <= 64; nstrike *= 2) {
  444.     count = 0;
  445.     do {
  446.         x = rnd(COLNO-1);
  447.         y = rn2(ROWNO);
  448.     } while (++count < 100 && levl[x][y].typ != CLOUD);
  449.  
  450.     if(count < 100) {
  451.         dirx = rn2(3) - 1;
  452.         diry = rn2(3) - 1;
  453.         if(dirx != 0 || diry != 0)
  454.         buzz(-15, /* "monster" LIGHTNING spell */
  455.              8, x, y, dirx, diry);
  456.     }
  457.     }
  458.  
  459.     if(levl[u.ux][u.uy].typ == CLOUD) {
  460.     /* inside a cloud during a thunder storm is deafening */
  461.     pline("Kaboom!!!  Boom!!  Boom!!");
  462.     if(!u.uinvulnerable) {
  463.         stop_occupation();
  464.         nomul(-3);
  465.     }
  466.     } else
  467.     You("hear a rumbling noise.");
  468. }
  469. #endif /* OVL1 */
  470.  
  471. /*timeout.c*/
  472.