Home | History | Annotate | Line # | Download | only in hack
hack.wizard.c revision 1.6.22.1
      1  1.6.22.1      matt /*	hack.wizard.c,v 1.6 2003/04/02 18:36:41 jsm Exp	*/
      2       1.4  christos 
      3       1.2   mycroft /*
      4       1.6       jsm  * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
      5       1.6       jsm  * Amsterdam
      6       1.6       jsm  * All rights reserved.
      7       1.6       jsm  *
      8       1.6       jsm  * Redistribution and use in source and binary forms, with or without
      9       1.6       jsm  * modification, are permitted provided that the following conditions are
     10       1.6       jsm  * met:
     11       1.6       jsm  *
     12       1.6       jsm  * - Redistributions of source code must retain the above copyright notice,
     13       1.6       jsm  * this list of conditions and the following disclaimer.
     14       1.6       jsm  *
     15       1.6       jsm  * - Redistributions in binary form must reproduce the above copyright
     16       1.6       jsm  * notice, this list of conditions and the following disclaimer in the
     17       1.6       jsm  * documentation and/or other materials provided with the distribution.
     18       1.6       jsm  *
     19       1.6       jsm  * - Neither the name of the Stichting Centrum voor Wiskunde en
     20       1.6       jsm  * Informatica, nor the names of its contributors may be used to endorse or
     21       1.6       jsm  * promote products derived from this software without specific prior
     22       1.6       jsm  * written permission.
     23       1.6       jsm  *
     24       1.6       jsm  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     25       1.6       jsm  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26       1.6       jsm  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     27       1.6       jsm  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
     28       1.6       jsm  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     29       1.6       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     30       1.6       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     31       1.6       jsm  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     32       1.6       jsm  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     33       1.6       jsm  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     34       1.6       jsm  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35       1.6       jsm  */
     36       1.6       jsm 
     37       1.6       jsm /*
     38       1.6       jsm  * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org>
     39       1.6       jsm  * All rights reserved.
     40       1.6       jsm  *
     41       1.6       jsm  * Redistribution and use in source and binary forms, with or without
     42       1.6       jsm  * modification, are permitted provided that the following conditions
     43       1.6       jsm  * are met:
     44       1.6       jsm  * 1. Redistributions of source code must retain the above copyright
     45       1.6       jsm  *    notice, this list of conditions and the following disclaimer.
     46       1.6       jsm  * 2. Redistributions in binary form must reproduce the above copyright
     47       1.6       jsm  *    notice, this list of conditions and the following disclaimer in the
     48       1.6       jsm  *    documentation and/or other materials provided with the distribution.
     49       1.6       jsm  * 3. The name of the author may not be used to endorse or promote products
     50       1.6       jsm  *    derived from this software without specific prior written permission.
     51       1.6       jsm  *
     52       1.6       jsm  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     53       1.6       jsm  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
     54       1.6       jsm  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
     55       1.6       jsm  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     56       1.6       jsm  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     57       1.6       jsm  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     58       1.6       jsm  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     59       1.6       jsm  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     60       1.6       jsm  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     61       1.6       jsm  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     62       1.2   mycroft  */
     63       1.2   mycroft 
     64       1.4  christos #include <sys/cdefs.h>
     65       1.2   mycroft #ifndef lint
     66  1.6.22.1      matt __RCSID("hack.wizard.c,v 1.6 2003/04/02 18:36:41 jsm Exp");
     67       1.4  christos #endif				/* not lint */
     68       1.1       cgd 
     69       1.1       cgd /* wizard code - inspired by rogue code from Merlyn Leroy (digi-g!brian) */
     70       1.1       cgd 
     71       1.1       cgd #include "hack.h"
     72       1.4  christos #include "extern.h"
     73       1.1       cgd 
     74       1.4  christos #define	WIZSHOT	    6		/* one chance in WIZSHOT that wizard will try
     75       1.4  christos 				 * magic */
     76       1.4  christos #define	BOLT_LIM    8		/* from this distance D and 1 will try to hit
     77       1.4  christos 				 * you */
     78       1.1       cgd 
     79       1.5       jsm const char            wizapp[] = "@DNPTUVXcemntx";
     80       1.1       cgd 
     81       1.1       cgd /* If he has found the Amulet, make the wizard appear after some time */
     82       1.4  christos void
     83       1.4  christos amulet()
     84       1.4  christos {
     85       1.4  christos 	struct obj     *otmp;
     86       1.4  christos 	struct monst   *mtmp;
     87       1.1       cgd 
     88       1.4  christos 	if (!flags.made_amulet || !flags.no_of_wizards)
     89       1.1       cgd 		return;
     90       1.1       cgd 	/* find wizard, and wake him if necessary */
     91       1.4  christos 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
     92       1.4  christos 		if (mtmp->data->mlet == '1' && mtmp->msleep && !rn2(40))
     93       1.4  christos 			for (otmp = invent; otmp; otmp = otmp->nobj)
     94       1.4  christos 				if (otmp->olet == AMULET_SYM && !otmp->spe) {
     95       1.4  christos 					mtmp->msleep = 0;
     96       1.4  christos 					if (dist(mtmp->mx, mtmp->my) > 2)
     97       1.4  christos 						pline(
     98       1.4  christos 						      "You get the creepy feeling that somebody noticed your taking the Amulet."
     99       1.4  christos 							);
    100       1.4  christos 					return;
    101       1.4  christos 				}
    102       1.1       cgd }
    103       1.1       cgd 
    104       1.4  christos int
    105       1.1       cgd wiz_hit(mtmp)
    106       1.4  christos 	struct monst   *mtmp;
    107       1.1       cgd {
    108       1.1       cgd 	/* if we have stolen or found the amulet, we disappear */
    109       1.4  christos 	if (mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
    110       1.1       cgd 	    mtmp->minvent->spe == 0) {
    111       1.1       cgd 		/* vanish -- very primitive */
    112       1.1       cgd 		fall_down(mtmp);
    113       1.4  christos 		return (1);
    114       1.1       cgd 	}
    115       1.1       cgd 	/* if it is lying around someplace, we teleport to it */
    116       1.4  christos 	if (!carrying(AMULET_OF_YENDOR)) {
    117       1.4  christos 		struct obj     *otmp;
    118       1.1       cgd 
    119       1.4  christos 		for (otmp = fobj; otmp; otmp = otmp->nobj)
    120       1.4  christos 			if (otmp->olet == AMULET_SYM && !otmp->spe) {
    121       1.4  christos 				if ((u.ux != otmp->ox || u.uy != otmp->oy) &&
    122       1.4  christos 				    !m_at(otmp->ox, otmp->oy)) {
    123       1.4  christos 
    124       1.4  christos 					/* teleport to it and pick it up */
    125       1.4  christos 					mtmp->mx = otmp->ox;
    126       1.4  christos 					mtmp->my = otmp->oy;
    127       1.4  christos 					freeobj(otmp);
    128       1.4  christos 					mpickobj(mtmp, otmp);
    129       1.4  christos 					pmon(mtmp);
    130       1.4  christos 					return (0);
    131       1.4  christos 				}
    132       1.4  christos 				goto hithim;
    133       1.4  christos 			}
    134       1.4  christos 		return (0);	/* we don't know where it is */
    135       1.1       cgd 	}
    136       1.1       cgd hithim:
    137       1.4  christos 	if (rn2(2)) {		/* hit - perhaps steal */
    138       1.1       cgd 
    139       1.4  christos 		/*
    140       1.4  christos 		 * if hit 1/20 chance of stealing amulet & vanish - amulet is
    141       1.4  christos 		 * on level 26 again.
    142       1.4  christos 		 */
    143       1.4  christos 		if (hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd))
    144  1.6.22.1      matt 		    && !rn2(20) && stealamulet(mtmp)) {
    145  1.6.22.1      matt 			/* nothing */
    146  1.6.22.1      matt 		}
    147       1.4  christos 	} else
    148       1.4  christos 		inrange(mtmp);	/* try magic */
    149       1.4  christos 	return (0);
    150       1.1       cgd }
    151       1.1       cgd 
    152       1.4  christos void
    153       1.1       cgd inrange(mtmp)
    154       1.4  christos 	struct monst   *mtmp;
    155       1.1       cgd {
    156       1.4  christos 	schar           tx, ty;
    157       1.1       cgd 
    158       1.1       cgd 	/* do nothing if cancelled (but make '1' say something) */
    159       1.4  christos 	if (mtmp->data->mlet != '1' && mtmp->mcan)
    160       1.1       cgd 		return;
    161       1.1       cgd 
    162       1.1       cgd 	/* spit fire only when both in a room or both in a corridor */
    163       1.4  christos 	if (inroom(u.ux, u.uy) != inroom(mtmp->mx, mtmp->my))
    164       1.4  christos 		return;
    165       1.1       cgd 	tx = u.ux - mtmp->mx;
    166       1.1       cgd 	ty = u.uy - mtmp->my;
    167       1.4  christos 	if ((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
    168       1.4  christos 	    || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)) {
    169       1.4  christos 		switch (mtmp->data->mlet) {
    170       1.4  christos 		case 'D':
    171       1.4  christos 			/* spit fire in the direction of @ (not nec. hitting) */
    172       1.4  christos 			buzz(-1, mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
    173       1.1       cgd 			break;
    174       1.4  christos 		case '1':
    175       1.4  christos 			if (rn2(WIZSHOT))
    176       1.4  christos 				break;
    177       1.4  christos 			/*
    178       1.4  christos 			 * if you zapped wizard with wand of cancellation, he
    179       1.4  christos 			 * has to shake off the effects before he can throw
    180       1.4  christos 			 * spells successfully.  1/2 the time they fail
    181       1.4  christos 			 * anyway
    182       1.4  christos 			 */
    183       1.4  christos 			if (mtmp->mcan || rn2(2)) {
    184       1.4  christos 				if (canseemon(mtmp))
    185       1.4  christos 					pline("%s makes a gesture, then curses.",
    186       1.4  christos 					      Monnam(mtmp));
    187       1.4  christos 				else
    188       1.4  christos 					pline("You hear mumbled cursing.");
    189       1.4  christos 				if (!rn2(3)) {
    190       1.4  christos 					mtmp->mspeed = 0;
    191       1.4  christos 					mtmp->minvis = 0;
    192       1.4  christos 				}
    193       1.4  christos 				if (!rn2(3))
    194       1.4  christos 					mtmp->mcan = 0;
    195       1.4  christos 			} else {
    196       1.4  christos 				if (canseemon(mtmp)) {
    197       1.4  christos 					if (!rn2(6) && !Invis) {
    198       1.4  christos 						pline("%s hypnotizes you.", Monnam(mtmp));
    199       1.4  christos 						nomul(rn2(3) + 3);
    200       1.4  christos 						break;
    201       1.4  christos 					} else
    202       1.4  christos 						pline("%s chants an incantation.",
    203       1.4  christos 						      Monnam(mtmp));
    204       1.4  christos 				} else
    205       1.4  christos 					pline("You hear a mumbled incantation.");
    206       1.4  christos 				switch (rn2(Invis ? 5 : 6)) {
    207       1.4  christos 				case 0:
    208       1.4  christos 					/*
    209       1.4  christos 					 * create a nasty monster from a deep
    210       1.4  christos 					 * level
    211       1.4  christos 					 */
    212       1.4  christos 					/*
    213       1.4  christos 					 * (for the moment, 'nasty' is not
    214       1.4  christos 					 * implemented)
    215       1.4  christos 					 */
    216       1.4  christos 					(void) makemon((struct permonst *) 0, u.ux, u.uy);
    217       1.4  christos 					break;
    218       1.4  christos 				case 1:
    219       1.4  christos 					pline("\"Destroy the thief, my pets!\"");
    220       1.4  christos 					aggravate();	/* aggravate all the
    221       1.4  christos 							 * monsters */
    222       1.4  christos 					/* fall into next case */
    223       1.4  christos 				case 2:
    224       1.4  christos 					if (flags.no_of_wizards == 1 && rnd(5) == 0)
    225       1.4  christos 						/*
    226       1.4  christos 						 * if only 1 wizard, clone
    227       1.4  christos 						 * himself
    228       1.4  christos 						 */
    229       1.4  christos 						clonewiz(mtmp);
    230       1.4  christos 					break;
    231       1.4  christos 				case 3:
    232       1.4  christos 					if (mtmp->mspeed == MSLOW)
    233       1.4  christos 						mtmp->mspeed = 0;
    234       1.4  christos 					else
    235       1.4  christos 						mtmp->mspeed = MFAST;
    236       1.4  christos 					break;
    237       1.4  christos 				case 4:
    238       1.4  christos 					mtmp->minvis = 1;
    239       1.4  christos 					break;
    240       1.4  christos 				case 5:
    241       1.4  christos 					/* Only if not Invisible */
    242       1.4  christos 					pline("You hear a clap of thunder!");
    243       1.4  christos 					/*
    244       1.4  christos 					 * shoot a bolt of fire or cold, or a
    245       1.4  christos 					 * sleep ray
    246       1.4  christos 					 */
    247       1.4  christos 					buzz(-rnd(3), mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
    248       1.4  christos 					break;
    249       1.4  christos 				}
    250       1.4  christos 			}
    251       1.1       cgd 		}
    252       1.4  christos 		if (u.uhp < 1)
    253       1.4  christos 			done_in_by(mtmp);
    254       1.1       cgd 	}
    255       1.1       cgd }
    256       1.1       cgd 
    257       1.4  christos void
    258       1.1       cgd aggravate()
    259       1.1       cgd {
    260       1.4  christos 	struct monst   *mtmp;
    261       1.1       cgd 
    262       1.4  christos 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
    263       1.1       cgd 		mtmp->msleep = 0;
    264       1.4  christos 		if (mtmp->mfroz && !rn2(5))
    265       1.1       cgd 			mtmp->mfroz = 0;
    266       1.1       cgd 	}
    267       1.1       cgd }
    268       1.1       cgd 
    269       1.4  christos void
    270       1.1       cgd clonewiz(mtmp)
    271       1.4  christos 	struct monst   *mtmp;
    272       1.1       cgd {
    273       1.4  christos 	struct monst   *mtmp2;
    274       1.1       cgd 
    275       1.4  christos 	if ((mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my)) != NULL) {
    276       1.1       cgd 		flags.no_of_wizards = 2;
    277       1.1       cgd 		unpmon(mtmp2);
    278       1.4  christos 		mtmp2->mappearance = wizapp[rn2(sizeof(wizapp) - 1)];
    279       1.1       cgd 		pmon(mtmp);
    280       1.1       cgd 	}
    281       1.1       cgd }
    282