Home | History | Annotate | Line # | Download | only in hack
      1  1.10  dholland /*	$NetBSD: hack.wizard.c,v 1.10 2011/08/07 06:03:45 dholland 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.10  dholland __RCSID("$NetBSD: hack.wizard.c,v 1.10 2011/08/07 06:03:45 dholland 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.9  dholland static const char wizapp[] = "@DNPTUVXcemntx";
     80   1.9  dholland 
     81   1.9  dholland static void aggravate(void);
     82   1.9  dholland static void clonewiz(struct monst *);
     83   1.9  dholland 
     84   1.1       cgd 
     85   1.1       cgd /* If he has found the Amulet, make the wizard appear after some time */
     86   1.4  christos void
     87   1.8  dholland amulet(void)
     88   1.4  christos {
     89   1.4  christos 	struct obj     *otmp;
     90   1.4  christos 	struct monst   *mtmp;
     91   1.1       cgd 
     92   1.4  christos 	if (!flags.made_amulet || !flags.no_of_wizards)
     93   1.1       cgd 		return;
     94   1.1       cgd 	/* find wizard, and wake him if necessary */
     95   1.4  christos 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
     96   1.4  christos 		if (mtmp->data->mlet == '1' && mtmp->msleep && !rn2(40))
     97   1.4  christos 			for (otmp = invent; otmp; otmp = otmp->nobj)
     98   1.4  christos 				if (otmp->olet == AMULET_SYM && !otmp->spe) {
     99   1.4  christos 					mtmp->msleep = 0;
    100   1.4  christos 					if (dist(mtmp->mx, mtmp->my) > 2)
    101   1.4  christos 						pline(
    102   1.4  christos 						      "You get the creepy feeling that somebody noticed your taking the Amulet."
    103   1.4  christos 							);
    104   1.4  christos 					return;
    105   1.4  christos 				}
    106   1.1       cgd }
    107   1.1       cgd 
    108   1.4  christos int
    109   1.8  dholland wiz_hit(struct monst *mtmp)
    110   1.1       cgd {
    111   1.1       cgd 	/* if we have stolen or found the amulet, we disappear */
    112   1.4  christos 	if (mtmp->minvent && mtmp->minvent->olet == AMULET_SYM &&
    113   1.1       cgd 	    mtmp->minvent->spe == 0) {
    114   1.1       cgd 		/* vanish -- very primitive */
    115   1.1       cgd 		fall_down(mtmp);
    116   1.4  christos 		return (1);
    117   1.1       cgd 	}
    118   1.1       cgd 	/* if it is lying around someplace, we teleport to it */
    119   1.4  christos 	if (!carrying(AMULET_OF_YENDOR)) {
    120   1.4  christos 		struct obj     *otmp;
    121   1.1       cgd 
    122   1.4  christos 		for (otmp = fobj; otmp; otmp = otmp->nobj)
    123   1.4  christos 			if (otmp->olet == AMULET_SYM && !otmp->spe) {
    124   1.4  christos 				if ((u.ux != otmp->ox || u.uy != otmp->oy) &&
    125   1.4  christos 				    !m_at(otmp->ox, otmp->oy)) {
    126   1.4  christos 
    127   1.4  christos 					/* teleport to it and pick it up */
    128   1.4  christos 					mtmp->mx = otmp->ox;
    129   1.4  christos 					mtmp->my = otmp->oy;
    130   1.4  christos 					freeobj(otmp);
    131   1.4  christos 					mpickobj(mtmp, otmp);
    132   1.4  christos 					pmon(mtmp);
    133   1.4  christos 					return (0);
    134   1.4  christos 				}
    135   1.4  christos 				goto hithim;
    136   1.4  christos 			}
    137   1.4  christos 		return (0);	/* we don't know where it is */
    138   1.1       cgd 	}
    139   1.1       cgd hithim:
    140   1.4  christos 	if (rn2(2)) {		/* hit - perhaps steal */
    141   1.1       cgd 
    142   1.4  christos 		/*
    143   1.4  christos 		 * if hit 1/20 chance of stealing amulet & vanish - amulet is
    144   1.4  christos 		 * on level 26 again.
    145   1.4  christos 		 */
    146   1.4  christos 		if (hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd))
    147   1.7  dholland 		    && !rn2(20) && stealamulet(mtmp)) {
    148   1.7  dholland 			/* nothing */
    149   1.7  dholland 		}
    150   1.4  christos 	} else
    151   1.4  christos 		inrange(mtmp);	/* try magic */
    152   1.4  christos 	return (0);
    153   1.1       cgd }
    154   1.1       cgd 
    155   1.4  christos void
    156   1.8  dholland inrange(struct monst *mtmp)
    157   1.1       cgd {
    158   1.4  christos 	schar           tx, ty;
    159   1.1       cgd 
    160   1.1       cgd 	/* do nothing if cancelled (but make '1' say something) */
    161   1.4  christos 	if (mtmp->data->mlet != '1' && mtmp->mcan)
    162   1.1       cgd 		return;
    163   1.1       cgd 
    164   1.1       cgd 	/* spit fire only when both in a room or both in a corridor */
    165   1.4  christos 	if (inroom(u.ux, u.uy) != inroom(mtmp->mx, mtmp->my))
    166   1.4  christos 		return;
    167   1.1       cgd 	tx = u.ux - mtmp->mx;
    168   1.1       cgd 	ty = u.uy - mtmp->my;
    169   1.4  christos 	if ((!tx && abs(ty) < BOLT_LIM) || (!ty && abs(tx) < BOLT_LIM)
    170   1.4  christos 	    || (abs(tx) == abs(ty) && abs(tx) < BOLT_LIM)) {
    171   1.4  christos 		switch (mtmp->data->mlet) {
    172   1.4  christos 		case 'D':
    173   1.4  christos 			/* spit fire in the direction of @ (not nec. hitting) */
    174   1.4  christos 			buzz(-1, mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
    175   1.1       cgd 			break;
    176   1.4  christos 		case '1':
    177   1.4  christos 			if (rn2(WIZSHOT))
    178   1.4  christos 				break;
    179   1.4  christos 			/*
    180   1.4  christos 			 * if you zapped wizard with wand of cancellation, he
    181   1.4  christos 			 * has to shake off the effects before he can throw
    182   1.4  christos 			 * spells successfully.  1/2 the time they fail
    183   1.4  christos 			 * anyway
    184   1.4  christos 			 */
    185   1.4  christos 			if (mtmp->mcan || rn2(2)) {
    186   1.4  christos 				if (canseemon(mtmp))
    187   1.4  christos 					pline("%s makes a gesture, then curses.",
    188   1.4  christos 					      Monnam(mtmp));
    189   1.4  christos 				else
    190   1.4  christos 					pline("You hear mumbled cursing.");
    191   1.4  christos 				if (!rn2(3)) {
    192   1.4  christos 					mtmp->mspeed = 0;
    193   1.4  christos 					mtmp->minvis = 0;
    194   1.4  christos 				}
    195   1.4  christos 				if (!rn2(3))
    196   1.4  christos 					mtmp->mcan = 0;
    197   1.4  christos 			} else {
    198   1.4  christos 				if (canseemon(mtmp)) {
    199   1.4  christos 					if (!rn2(6) && !Invis) {
    200   1.4  christos 						pline("%s hypnotizes you.", Monnam(mtmp));
    201   1.4  christos 						nomul(rn2(3) + 3);
    202   1.4  christos 						break;
    203   1.4  christos 					} else
    204   1.4  christos 						pline("%s chants an incantation.",
    205   1.4  christos 						      Monnam(mtmp));
    206   1.4  christos 				} else
    207   1.4  christos 					pline("You hear a mumbled incantation.");
    208   1.4  christos 				switch (rn2(Invis ? 5 : 6)) {
    209   1.4  christos 				case 0:
    210   1.4  christos 					/*
    211   1.4  christos 					 * create a nasty monster from a deep
    212   1.4  christos 					 * level
    213   1.4  christos 					 */
    214   1.4  christos 					/*
    215   1.4  christos 					 * (for the moment, 'nasty' is not
    216   1.4  christos 					 * implemented)
    217   1.4  christos 					 */
    218   1.4  christos 					(void) makemon((struct permonst *) 0, u.ux, u.uy);
    219   1.4  christos 					break;
    220   1.4  christos 				case 1:
    221   1.4  christos 					pline("\"Destroy the thief, my pets!\"");
    222   1.4  christos 					aggravate();	/* aggravate all the
    223   1.4  christos 							 * monsters */
    224  1.10  dholland 					/* FALLTHROUGH */
    225   1.4  christos 				case 2:
    226   1.4  christos 					if (flags.no_of_wizards == 1 && rnd(5) == 0)
    227   1.4  christos 						/*
    228   1.4  christos 						 * if only 1 wizard, clone
    229   1.4  christos 						 * himself
    230   1.4  christos 						 */
    231   1.4  christos 						clonewiz(mtmp);
    232   1.4  christos 					break;
    233   1.4  christos 				case 3:
    234   1.4  christos 					if (mtmp->mspeed == MSLOW)
    235   1.4  christos 						mtmp->mspeed = 0;
    236   1.4  christos 					else
    237   1.4  christos 						mtmp->mspeed = MFAST;
    238   1.4  christos 					break;
    239   1.4  christos 				case 4:
    240   1.4  christos 					mtmp->minvis = 1;
    241   1.4  christos 					break;
    242   1.4  christos 				case 5:
    243   1.4  christos 					/* Only if not Invisible */
    244   1.4  christos 					pline("You hear a clap of thunder!");
    245   1.4  christos 					/*
    246   1.4  christos 					 * shoot a bolt of fire or cold, or a
    247   1.4  christos 					 * sleep ray
    248   1.4  christos 					 */
    249   1.4  christos 					buzz(-rnd(3), mtmp->mx, mtmp->my, sgn(tx), sgn(ty));
    250   1.4  christos 					break;
    251   1.4  christos 				}
    252   1.4  christos 			}
    253   1.1       cgd 		}
    254   1.4  christos 		if (u.uhp < 1)
    255   1.4  christos 			done_in_by(mtmp);
    256   1.1       cgd 	}
    257   1.1       cgd }
    258   1.1       cgd 
    259   1.4  christos void
    260   1.8  dholland aggravate(void)
    261   1.1       cgd {
    262   1.4  christos 	struct monst   *mtmp;
    263   1.1       cgd 
    264   1.4  christos 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
    265   1.1       cgd 		mtmp->msleep = 0;
    266   1.4  christos 		if (mtmp->mfroz && !rn2(5))
    267   1.1       cgd 			mtmp->mfroz = 0;
    268   1.1       cgd 	}
    269   1.1       cgd }
    270   1.1       cgd 
    271   1.4  christos void
    272   1.8  dholland clonewiz(struct monst *mtmp)
    273   1.1       cgd {
    274   1.4  christos 	struct monst   *mtmp2;
    275   1.1       cgd 
    276   1.4  christos 	if ((mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my)) != NULL) {
    277   1.1       cgd 		flags.no_of_wizards = 2;
    278   1.1       cgd 		unpmon(mtmp2);
    279   1.4  christos 		mtmp2->mappearance = wizapp[rn2(sizeof(wizapp) - 1)];
    280   1.1       cgd 		pmon(mtmp);
    281   1.1       cgd 	}
    282   1.1       cgd }
    283