Home | History | Annotate | Line # | Download | only in hack
hack.wizard.c revision 1.3
      1  1.2  mycroft /*
      2  1.2  mycroft  * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
      3  1.2  mycroft  */
      4  1.2  mycroft 
      5  1.2  mycroft #ifndef lint
      6  1.3      cgd static char rcsid[] = "$NetBSD: hack.wizard.c,v 1.3 1995/03/23 08:32:09 cgd Exp $";
      7  1.2  mycroft #endif /* not lint */
      8  1.1      cgd 
      9  1.1      cgd /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
     10  1.1      cgd 
     11  1.1      cgd #include "hack.h"
     12  1.1      cgd extern struct permonst pm_wizard;
     13  1.1      cgd extern struct monst *makemon();
     14  1.1      cgd 
     15  1.1      cgd #define	WIZSHOT	    6	/* one chance in WIZSHOT that wizard will try magic */
     16  1.1      cgd #define	BOLT_LIM    8	/* from this distance D and 1 will try to hit you */
     17  1.1      cgd 
     18  1.1      cgd char wizapp[] = "@DNPTUVXcemntx";
     19  1.1      cgd 
     20  1.1      cgd /* If he has found the Amulet, make the wizard appear after some time */
     21  1.1      cgd amulet(){
     22  1.1      cgd 	register struct obj *otmp;
     23  1.1      cgd 	register struct monst *mtmp;
     24  1.1      cgd 
     25  1.1      cgd 	if(!flags.made_amulet || !flags.no_of_wizards)
     26  1.1      cgd 		return;
     27  1.1      cgd 	/* find wizard, and wake him if necessary */
     28  1.1      cgd 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
     29  1.1      cgd 	    if(mtmp->data->mlet == '1' && mtmp->msleep && !rn2(40))
     30  1.1      cgd 		for(otmp = invent; otmp; otmp = otmp->nobj)
     31  1.1      cgd 		    if(otmp->olet == AMULET_SYM && !otmp->spe) {
     32  1.1      cgd 			mtmp->msleep = 0;
     33  1.1      cgd 			if(dist(mtmp->mx,mtmp->my) > 2)
     34  1.1      cgd 			    pline(
     35  1.1      cgd     "You get the creepy feeling that somebody noticed your taking the Amulet."
     36  1.1      cgd 			    );
     37  1.1      cgd 			return;
     38  1.1      cgd 		    }
     39  1.1      cgd }
     40  1.1      cgd 
     41  1.1      cgd wiz_hit(mtmp)
     42  1.1      cgd register struct monst *mtmp;
     43  1.1      cgd {
     44  1.1      cgd 	/* if we have stolen or found the amulet, we disappear */
     45  1.1      cgd 	if(mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
     46  1.1      cgd 	    mtmp->minvent->spe == 0) {
     47  1.1      cgd 		/* vanish -- very primitive */
     48  1.1      cgd 		fall_down(mtmp);
     49  1.1      cgd 		return(1);
     50  1.1      cgd 	}
     51  1.1      cgd 
     52  1.1      cgd 	/* if it is lying around someplace, we teleport to it */
     53  1.1      cgd 	if(!carrying(AMULET_OF_YENDOR)) {
     54  1.1      cgd 	    register struct obj *otmp;
     55  1.1      cgd 
     56  1.1      cgd 	    for(otmp = fobj; otmp; otmp = otmp->nobj)
     57  1.1      cgd 		if(otmp->olet == AMULET_SYM && !otmp->spe) {
     58  1.1      cgd 		    if((u.ux != otmp->ox || u.uy != otmp->oy) &&
     59  1.1      cgd 		       !m_at(otmp->ox, otmp->oy)) {
     60  1.1      cgd 
     61  1.1      cgd 			/* teleport to it and pick it up */
     62  1.1      cgd 			mtmp->mx = otmp->ox;
     63  1.1      cgd 			mtmp->my = otmp->oy;
     64  1.1      cgd 			freeobj(otmp);
     65  1.1      cgd 			mpickobj(mtmp, otmp);
     66  1.1      cgd 			pmon(mtmp);
     67  1.1      cgd 			return(0);
     68  1.1      cgd 		    }
     69  1.1      cgd 		    goto hithim;
     70  1.1      cgd 		}
     71  1.1      cgd 	    return(0);				/* we don't know where it is */
     72  1.1      cgd 	}
     73  1.1      cgd hithim:
     74  1.1      cgd 	if(rn2(2)) {				/* hit - perhaps steal */
     75  1.1      cgd 
     76  1.1      cgd 	    /* if hit 1/20 chance of stealing amulet & vanish
     77  1.1      cgd 		- amulet is on level 26 again. */
     78  1.1      cgd 	    if(hitu(mtmp, d(mtmp->data->damn,mtmp->data->damd))
     79  1.1      cgd 		&& !rn2(20) && stealamulet(mtmp))
     80  1.1      cgd 		;
     81  1.1      cgd 	}
     82  1.1      cgd 	else
     83  1.1      cgd 	    inrange(mtmp);			/* try magic */
     84  1.1      cgd 	return(0);
     85  1.1      cgd }
     86  1.1      cgd 
     87  1.1      cgd inrange(mtmp)
     88  1.1      cgd register struct monst *mtmp;
     89  1.1      cgd {
     90  1.1      cgd 	register schar tx,ty;
     91  1.1      cgd 
     92  1.1      cgd 	/* do nothing if cancelled (but make '1' say something) */
     93  1.1      cgd 	if(mtmp->data->mlet != '1' && mtmp->mcan)
     94  1.1      cgd 		return;
     95  1.1      cgd 
     96  1.1      cgd 	/* spit fire only when both in a room or both in a corridor */
     97  1.1      cgd 	if(inroom(u.ux,u.uy) != inroom(mtmp->mx,mtmp->my)) return;
     98  1.1      cgd 	tx = u.ux - mtmp->mx;
     99  1.1      cgd 	ty = u.uy - mtmp->my;
    100  1.1      cgd 	if((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
    101  1.1      cgd 	    || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)){
    102  1.1      cgd 	    switch(mtmp->data->mlet) {
    103  1.1      cgd 	    case 'D':
    104  1.1      cgd 		/* spit fire in the direction of @ (not nec. hitting) */
    105  1.1      cgd 		buzz(-1,mtmp->mx,mtmp->my,sgn(tx),sgn(ty));
    106  1.1      cgd 		break;
    107  1.1      cgd 	    case '1':
    108  1.1      cgd 		if(rn2(WIZSHOT)) break;
    109  1.1      cgd 		/* if you zapped wizard with wand of cancellation,
    110  1.1      cgd 		he has to shake off the effects before he can throw
    111  1.1      cgd 		spells successfully.  1/2 the time they fail anyway */
    112  1.1      cgd 		if(mtmp->mcan || rn2(2)) {
    113  1.1      cgd 		    if(canseemon(mtmp))
    114  1.1      cgd 			pline("%s makes a gesture, then curses.",
    115  1.1      cgd 			    Monnam(mtmp));
    116  1.1      cgd 		    else
    117  1.1      cgd 			pline("You hear mumbled cursing.");
    118  1.1      cgd 		    if(!rn2(3)) {
    119  1.1      cgd 			mtmp->mspeed = 0;
    120  1.1      cgd 			mtmp->minvis = 0;
    121  1.1      cgd 		    }
    122  1.1      cgd 		    if(!rn2(3))
    123  1.1      cgd 			mtmp->mcan = 0;
    124  1.1      cgd 		} else {
    125  1.1      cgd 		    if(canseemon(mtmp)){
    126  1.1      cgd 			if(!rn2(6) && !Invis) {
    127  1.1      cgd 			    pline("%s hypnotizes you.", Monnam(mtmp));
    128  1.1      cgd 			    nomul(rn2(3) + 3);
    129  1.1      cgd 			    break;
    130  1.1      cgd 			} else
    131  1.1      cgd 			    pline("%s chants an incantation.",
    132  1.1      cgd 				Monnam(mtmp));
    133  1.1      cgd 		    } else
    134  1.1      cgd 			    pline("You hear a mumbled incantation.");
    135  1.1      cgd 		    switch(rn2(Invis ? 5 : 6)) {
    136  1.1      cgd 		    case 0:
    137  1.1      cgd 			/* create a nasty monster from a deep level */
    138  1.1      cgd 			/* (for the moment, 'nasty' is not implemented) */
    139  1.1      cgd 			(void) makemon((struct permonst *)0, u.ux, u.uy);
    140  1.1      cgd 			break;
    141  1.1      cgd 		    case 1:
    142  1.1      cgd 			pline("\"Destroy the thief, my pets!\"");
    143  1.1      cgd 			aggravate();	/* aggravate all the monsters */
    144  1.1      cgd 			/* fall into next case */
    145  1.1      cgd 		    case 2:
    146  1.1      cgd 			if (flags.no_of_wizards == 1 && rnd(5) == 0)
    147  1.1      cgd 			    /* if only 1 wizard, clone himself */
    148  1.1      cgd 			    clonewiz(mtmp);
    149  1.1      cgd 			break;
    150  1.1      cgd 		    case 3:
    151  1.1      cgd 			if(mtmp->mspeed == MSLOW)
    152  1.1      cgd 				mtmp->mspeed = 0;
    153  1.1      cgd 			else
    154  1.1      cgd 				mtmp->mspeed = MFAST;
    155  1.1      cgd 			break;
    156  1.1      cgd 		    case 4:
    157  1.1      cgd 			mtmp->minvis = 1;
    158  1.1      cgd 			break;
    159  1.1      cgd 		    case 5:
    160  1.1      cgd 			/* Only if not Invisible */
    161  1.1      cgd 			pline("You hear a clap of thunder!");
    162  1.1      cgd 			/* shoot a bolt of fire or cold, or a sleep ray */
    163  1.1      cgd 			buzz(-rnd(3),mtmp->mx,mtmp->my,sgn(tx),sgn(ty));
    164  1.1      cgd 			break;
    165  1.1      cgd 		    }
    166  1.1      cgd 		}
    167  1.1      cgd 	    }
    168  1.1      cgd 	    if(u.uhp < 1) done_in_by(mtmp);
    169  1.1      cgd 	}
    170  1.1      cgd }
    171  1.1      cgd 
    172  1.1      cgd aggravate()
    173  1.1      cgd {
    174  1.1      cgd 	register struct monst *mtmp;
    175  1.1      cgd 
    176  1.1      cgd 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
    177  1.1      cgd 		mtmp->msleep = 0;
    178  1.1      cgd 		if(mtmp->mfroz && !rn2(5))
    179  1.1      cgd 			mtmp->mfroz = 0;
    180  1.1      cgd 	}
    181  1.1      cgd }
    182  1.1      cgd 
    183  1.1      cgd clonewiz(mtmp)
    184  1.1      cgd register struct monst *mtmp;
    185  1.1      cgd {
    186  1.1      cgd 	register struct monst *mtmp2;
    187  1.1      cgd 
    188  1.1      cgd 	if(mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my)) {
    189  1.1      cgd 		flags.no_of_wizards = 2;
    190  1.1      cgd 		unpmon(mtmp2);
    191  1.1      cgd 		mtmp2->mappearance = wizapp[rn2(sizeof(wizapp)-1)];
    192  1.1      cgd 		pmon(mtmp);
    193  1.1      cgd 	}
    194  1.1      cgd }
    195