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

  1. /*    SCCS Id: @(#)mcastu.c    3.1    93/05/04    */
  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. #ifdef OVL0
  8. static void FDECL(cursetxt,(struct monst *));
  9.  
  10. extern const char *flash_types[];    /* from zap.c */
  11.  
  12. static
  13. void
  14. cursetxt(mtmp)
  15.     register struct monst *mtmp;
  16. {
  17.     if(canseemon(mtmp)) {
  18.         if ((Invis && !perceives(mtmp->data) &&
  19.                 (mtmp->mux != u.ux || mtmp->muy != u.uy))
  20. #ifdef POLYSELF
  21.             || u.usym == S_MIMIC_DEF || u.uundetected
  22. #endif
  23.                                     )
  24.         pline("%s points and curses in your general direction.",
  25.                 Monnam(mtmp));
  26.         else if (Displaced && (mtmp->mux != u.ux || mtmp->muy != u.uy))
  27.         pline("%s points and curses at your displaced image.",
  28.                 Monnam(mtmp));
  29.         else
  30.         pline("%s points at you, then curses.", Monnam(mtmp));
  31.     } else if((!(moves%4) || !rn2(4)) && flags.soundok) 
  32.         Norep("You hear a mumbled curse.");
  33. }
  34.  
  35. #endif /* OVL0 */
  36. #ifdef OVLB
  37.  
  38. int
  39. castmu(mtmp, mattk)    /* monster casts spell at you */
  40.     register struct monst *mtmp;
  41.     register struct attack *mattk;
  42. {
  43.     int    dmg, ml = mtmp->m_lev;
  44.  
  45.     if(mtmp->mcan || mtmp->mspec_used || !ml) {  /* could not attack */
  46.         cursetxt(mtmp);
  47.         return(0);
  48.     } else {
  49.         nomul(0);
  50.         if(rn2(ml*10) < (mtmp->mconf ? 100 : 20)) {    /* fumbled attack */
  51.         if(canseemon(mtmp)
  52. #ifdef SOUNDS
  53.                 && flags.soundok
  54. #endif
  55.                             )
  56.             pline("The air crackles around %s.", mon_nam(mtmp));
  57.         return(0);
  58.         }
  59.     }
  60. /*
  61.  *    As these are spells, the damage is related to the level
  62.  *    of the monster casting the spell.
  63.  */
  64.     if (mattk->damd)
  65.         dmg = d((int)((ml/3) + mattk->damn), (int)mattk->damd);
  66.     else dmg = d((int)((ml/3) + 1), 6);
  67.     if (Half_spell_damage) dmg = (dmg+1) / 2;
  68.  
  69.     switch(mattk->adtyp)   {
  70.  
  71.         case AD_FIRE:
  72.         pline("You're enveloped in flames.");
  73.         if(Fire_resistance) {
  74.             shieldeff(u.ux, u.uy);
  75.             pline("But you resist the effects.");
  76.             dmg = 0;
  77.         }
  78.         break;
  79.         case AD_COLD:
  80.         pline("You're covered in frost.");
  81.         if(Cold_resistance) {
  82.             shieldeff(u.ux, u.uy);
  83.             pline("But you resist the effects.");
  84.             dmg = 0;
  85.         }
  86.         break;
  87.         case AD_MAGM:
  88.         You("are hit by a shower of missiles!");
  89.         if(Antimagic) {
  90.             shieldeff(u.ux, u.uy);
  91.             pline("The missiles bounce off!");
  92.             dmg = 0;
  93.         } else dmg = d((int)mtmp->m_lev/2 + 1,6);
  94.         break;
  95.         case AD_SPEL:    /* random spell */
  96.  
  97.         mtmp->mspec_used = 10 - mtmp->m_lev;
  98.         if (mtmp->mspec_used < 2) mtmp->mspec_used = 2;
  99.         switch(rn2((int)mtmp->m_lev)) {
  100.             case 22:
  101.             case 21:
  102.             case 20:
  103.             pline("Oh no, %s's using the touch of death!",
  104.                   humanoid(mtmp->data)
  105.                   ? (mtmp->female ? "she" : "he")
  106.                   : "it"
  107.                  );
  108. #ifdef POLYSELF
  109.             if (is_undead(uasmon))
  110.                 You("seem no deader than before.");
  111.             else
  112. #endif
  113.             if (!Antimagic && rn2(ml) > 12) {
  114.  
  115.                 if(Hallucination)
  116.                 You("have an out of body experience.");
  117.                 else  {
  118.                 killer_format = KILLED_BY_AN;
  119.                 killer = "touch of death";
  120.                 done(DIED);
  121.                 }
  122.             } else {
  123.                 if(Antimagic) shieldeff(u.ux, u.uy);
  124.                 pline("Lucky for you, it didn't work!");
  125.             }
  126.             dmg = 0;
  127.             break;
  128.             case 19:
  129.             case 18:
  130.             if(mtmp->iswiz && flags.no_of_wizards == 1) {
  131.                 pline("Double Trouble...");
  132.                 clonewiz();
  133.                 dmg = 0;
  134.                 break;
  135.             } /* else fall into the next case */
  136.             case 17:
  137.             case 16:
  138.             case 15:
  139.             if(mtmp->iswiz)
  140.                 verbalize("Destroy the thief, my pets!");
  141.             nasty(mtmp);    /* summon something nasty */
  142.             /* fall into the next case */
  143.             case 14:        /* aggravate all monsters */
  144.             case 13:
  145.             aggravate();
  146.             dmg = 0;
  147.             break;
  148.             case 12:        /* curse random items */
  149.             case 11:
  150.             case 10:
  151.             rndcurse();
  152.             dmg = 0;
  153.             break;
  154.             case 9:
  155.             case 8:        /* destroy armor */
  156.             if (Antimagic) {
  157.                 shieldeff(u.ux, u.uy);
  158.                 pline("A field of force surrounds you!");
  159.             } else if(!destroy_arm(some_armor()))
  160.                 Your("skin itches.");
  161.             dmg = 0;
  162.             break;
  163.             case 7:
  164.             case 6:        /* drain strength */
  165.             if(Antimagic) {
  166.                 shieldeff(u.ux, u.uy);
  167.                 You("feel momentarily weakened.");
  168.             } else {
  169.                 You("suddenly feel weaker!");
  170.                 dmg = ml - 6;
  171.                 if(Half_spell_damage) dmg = (dmg+1) / 2;
  172.                 losestr(rnd(dmg));
  173.                 if(u.uhp < 1)
  174.                 done_in_by(mtmp);
  175.             }
  176.             dmg = 0;
  177.             break;
  178.             case 5:        /* make invisible if not */
  179.             case 4:
  180.             if(!mtmp->minvis) {
  181.                 if(canseemon(mtmp) && !See_invisible)
  182.                 pline("%s suddenly disappears!",
  183.                       Monnam(mtmp));
  184.                 mtmp->minvis = 1;
  185.                 newsym(mtmp->mx,mtmp->my);
  186.                 dmg = 0;
  187.                 break;
  188.             } /* else fall into the next case */
  189.             case 3:        /* stun */
  190.             if(Antimagic) {
  191.                 shieldeff(u.ux, u.uy);
  192.                 if(!Stunned)
  193.                 You("feel momentarily disoriented.");
  194.                 make_stunned(1L, FALSE);
  195.             } else {
  196.                 if (Stunned)
  197.                 You("struggle to keep your balance.");
  198.                 else
  199.                 You("reel...");
  200.                 dmg = d(ACURR(A_DEX) < 12 ? 6 : 4, 4);
  201.                 if(Half_spell_damage) dmg = (dmg+1) / 2;
  202.                 make_stunned(HStun + dmg, FALSE);
  203.             }
  204.             dmg = 0;
  205.             break;
  206.             case 2:        /* haste self */
  207.             if(mtmp->mspeed == MSLOW)    mtmp->mspeed = 0;
  208.             else                mtmp->mspeed = MFAST;
  209.             dmg = 0;
  210.             break;
  211.             case 1:        /* cure self */
  212.             if(mtmp->mhp < mtmp->mhpmax) {
  213.                 if((mtmp->mhp += rnd(8)) > mtmp->mhpmax)
  214.                 mtmp->mhp = mtmp->mhpmax;
  215.                 dmg = 0;
  216.                 break;
  217.             } /* else fall through to default case */
  218.             default:        /* psi bolt */
  219.             if(Antimagic) {
  220.                 shieldeff(u.ux, u.uy);
  221.                 You("get a slight %sache.",body_part(HEAD));
  222.                 dmg = 1;
  223.             } else {
  224.                 if (dmg <= 10)
  225.                 Your("brain is on fire!");
  226.                 else Your("%s suddenly aches!", body_part(HEAD));
  227.             }
  228.             break;
  229.         }
  230.         break;
  231.         
  232.         case AD_CLRC:    /* clerical spell */
  233.  
  234.         mtmp->mspec_used = 10 - mtmp->m_lev;
  235.         if (mtmp->mspec_used < 2) mtmp->mspec_used = 2;
  236.         switch(rn2((int)mtmp->m_lev)) {
  237.             /* Other ideas: lightning bolts, towers of flame,
  238.                     gush of water  -3. */
  239.  
  240.             default:        /* confuse */
  241.             if(Antimagic) {
  242.                 shieldeff(u.ux, u.uy);
  243.                 You("feel momentarily dizzy.");
  244.             } else {
  245.                 dmg = (int)mtmp->m_lev;
  246.                 if(Half_spell_damage) dmg = (dmg+1) / 2;
  247.                 make_confused(HConfusion + dmg, TRUE);
  248.             }
  249.             dmg = 0;
  250.             break;
  251.             case 12:        /* curse random items */
  252.             case 11:
  253.             case 10:
  254.             rndcurse();
  255.             dmg = 0;
  256.             break;
  257.             case 9:
  258.             case 8:        /* insects */
  259.             /* Try for insects, and if there are none
  260.                left, go for (sticks to) snakes.  -3. */
  261.             {
  262.             int i;
  263.             struct permonst *pm = mkclass(S_ANT,0);
  264.             struct monst *mtmp2;
  265.             char let = (pm ? S_ANT : S_SNAKE);
  266.   
  267.             for (i = 0; i <= (int) mtmp->m_lev; i++)
  268.                if ((pm = mkclass(let,0)) &&
  269.                     (mtmp2 = makemon(pm, u.ux, u.uy))) {
  270.                 mtmp2->msleep = mtmp2->mpeaceful =
  271.                     mtmp2->mtame = 0;
  272.                 set_malign(mtmp2);
  273.                 }
  274.             }            
  275.             dmg = 0;
  276.             break;
  277.             case 6:
  278.             case 7:        /* blindness */
  279.             if (!Blinded) {
  280.                 pline("Scales cover your eyes!");
  281.                 make_blinded(Half_spell_damage ? 100L:200L, FALSE);
  282.                 dmg = 0;
  283.                 break;
  284.             }
  285.             case 4:
  286.             case 5:        /* wound */
  287.             if(Antimagic) {
  288.                 shieldeff(u.ux, u.uy);
  289.                 Your("skin itches badly for a moment.");
  290.                 dmg = 0;
  291.             } else {
  292.                 pline("Wounds appear on your body!");
  293.                 dmg = d(2,8) + 1;
  294.                 if (Half_spell_damage) dmg = (dmg+1) / 2;
  295.             }
  296.             break;
  297.             case 3:        /* hold */
  298.             if(Antimagic) {
  299.                 shieldeff(u.ux, u.uy);
  300.                 if(multi >= 0)
  301.                 You("stiffen briefly.");
  302.                 nomul(-1);
  303.              } else {
  304.                 if (multi >= 0)    
  305.                     You("are frozen in place!");
  306.                 dmg = 4 + (int)mtmp->m_lev;
  307.                 if (Half_spell_damage) dmg = (dmg+1) / 2;
  308.                 nomul(-dmg);
  309.             }
  310.             dmg = 0;
  311.             break;
  312.             case 2:
  313.             case 1:        /* cure self */
  314.             if(mtmp->mhp < mtmp->mhpmax) {
  315.                 if((mtmp->mhp += rnd(8)) > mtmp->mhpmax)
  316.                 mtmp->mhp = mtmp->mhpmax;
  317.                 dmg = 0;
  318.                 break;
  319.             } /* else fall through to default case */
  320.         }
  321.     }
  322.     if(dmg) mdamageu(mtmp, dmg);
  323.     return(1);
  324. }
  325.  
  326. #endif /* OVLB */
  327. #ifdef OVL0
  328.  
  329. /* convert 1..10 to 0..9; add 10 for second group (spell casting) */
  330. #define ad_to_typ(k) (10 + (int)k - 1)
  331.  
  332. int
  333. buzzmu(mtmp, mattk)        /* monster uses spell (ranged) */
  334.     register struct monst *mtmp;
  335.     register struct attack  *mattk;
  336. {
  337.     if(mtmp->mcan || mattk->adtyp > AD_SPC2) {
  338.         cursetxt(mtmp);
  339.         return(0);
  340.     }
  341.     if(lined_up(mtmp) && rn2(3)) {
  342.         nomul(0);
  343.         if(mattk->adtyp && (mattk->adtyp < 11)) { /* no cf unsigned >0 */
  344.         if(canseemon(mtmp))
  345.             pline("%s zaps you with a %s!", Monnam(mtmp),
  346.               flash_types[ad_to_typ(mattk->adtyp)]);
  347.         buzz(-ad_to_typ(mattk->adtyp), (int)mattk->damn,
  348.              mtmp->mx, mtmp->my, sgn(tbx), sgn(tby));
  349.         } else impossible("Monster spell %d cast", mattk->adtyp-1);
  350.     }
  351.     return(1);
  352. }
  353.  
  354. #endif /* OVL0 */
  355.  
  356. /*mcastu.c*/
  357.