Home | History | Annotate | Line # | Download | only in hack
      1  1.9  dholland /*	$NetBSD: hack.mkobj.c,v 1.9 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.9  dholland __RCSID("$NetBSD: hack.mkobj.c,v 1.9 2011/08/07 06:03:45 dholland Exp $");
     67  1.4  christos #endif				/* not lint */
     68  1.1       cgd 
     69  1.1       cgd #include "hack.h"
     70  1.4  christos #include "extern.h"
     71  1.1       cgd 
     72  1.8  dholland static const char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(%";
     73  1.1       cgd 
     74  1.4  christos struct obj     *
     75  1.7  dholland mkobj_at(int let, int x, int y)
     76  1.1       cgd {
     77  1.4  christos 	struct obj     *otmp = mkobj(let);
     78  1.1       cgd 	otmp->ox = x;
     79  1.1       cgd 	otmp->oy = y;
     80  1.1       cgd 	otmp->nobj = fobj;
     81  1.1       cgd 	fobj = otmp;
     82  1.4  christos 	return (otmp);
     83  1.1       cgd }
     84  1.1       cgd 
     85  1.4  christos void
     86  1.7  dholland mksobj_at(int otyp, int x, int y)
     87  1.1       cgd {
     88  1.4  christos 	struct obj     *otmp = mksobj(otyp);
     89  1.1       cgd 	otmp->ox = x;
     90  1.1       cgd 	otmp->oy = y;
     91  1.1       cgd 	otmp->nobj = fobj;
     92  1.1       cgd 	fobj = otmp;
     93  1.1       cgd }
     94  1.1       cgd 
     95  1.4  christos struct obj     *
     96  1.7  dholland mkobj(int let)
     97  1.4  christos {
     98  1.4  christos 	if (!let)
     99  1.1       cgd 		let = mkobjstr[rn2(sizeof(mkobjstr) - 1)];
    100  1.4  christos 	return (
    101  1.4  christos 		mksobj(
    102  1.4  christos 		       letter(let) ?
    103  1.4  christos 	  CORPSE + ((let > 'Z') ? (let - 'a' + 'Z' - '@' + 1) : (let - '@'))
    104  1.4  christos 		       : probtype(let)
    105  1.4  christos 		       )
    106  1.4  christos 		);
    107  1.1       cgd }
    108  1.1       cgd 
    109  1.1       cgd 
    110  1.4  christos struct obj      zeroobj;
    111  1.4  christos 
    112  1.4  christos struct obj     *
    113  1.7  dholland mksobj(int otyp)
    114  1.1       cgd {
    115  1.4  christos 	struct obj     *otmp;
    116  1.4  christos 	char            let = objects[otyp].oc_olet;
    117  1.1       cgd 
    118  1.1       cgd 	otmp = newobj(0);
    119  1.1       cgd 	*otmp = zeroobj;
    120  1.1       cgd 	otmp->age = moves;
    121  1.1       cgd 	otmp->o_id = flags.ident++;
    122  1.1       cgd 	otmp->quan = 1;
    123  1.1       cgd 	otmp->olet = let;
    124  1.1       cgd 	otmp->otyp = otyp;
    125  1.4  christos 	otmp->dknown = strchr("/=!?*", let) ? 0 : 1;
    126  1.4  christos 	switch (let) {
    127  1.1       cgd 	case WEAPON_SYM:
    128  1.4  christos 		otmp->quan = (otmp->otyp <= ROCK) ? rn1(6, 6) : 1;
    129  1.4  christos 		if (!rn2(11))
    130  1.4  christos 			otmp->spe = rnd(3);
    131  1.4  christos 		else if (!rn2(10)) {
    132  1.1       cgd 			otmp->cursed = 1;
    133  1.1       cgd 			otmp->spe = -rnd(3);
    134  1.1       cgd 		}
    135  1.1       cgd 		break;
    136  1.1       cgd 	case FOOD_SYM:
    137  1.4  christos 		if (otmp->otyp >= CORPSE)
    138  1.4  christos 			break;
    139  1.1       cgd #ifdef NOT_YET_IMPLEMENTED
    140  1.1       cgd 		/* if tins are to be identified, need to adapt doname() etc */
    141  1.4  christos 		if (otmp->otyp == TIN)
    142  1.1       cgd 			otmp->spe = rnd(...);
    143  1.4  christos #endif	/* NOT_YET_IMPLEMENTED */
    144  1.9  dholland 		/* FALLTHROUGH */
    145  1.1       cgd 	case GEM_SYM:
    146  1.1       cgd 		otmp->quan = rn2(6) ? 1 : 2;
    147  1.9  dholland 		break;
    148  1.1       cgd 	case TOOL_SYM:
    149  1.1       cgd 	case CHAIN_SYM:
    150  1.1       cgd 	case BALL_SYM:
    151  1.1       cgd 	case ROCK_SYM:
    152  1.1       cgd 	case POTION_SYM:
    153  1.1       cgd 	case SCROLL_SYM:
    154  1.1       cgd 	case AMULET_SYM:
    155  1.1       cgd 		break;
    156  1.1       cgd 	case ARMOR_SYM:
    157  1.4  christos 		if (!rn2(8))
    158  1.4  christos 			otmp->cursed = 1;
    159  1.4  christos 		if (!rn2(10))
    160  1.4  christos 			otmp->spe = rnd(3);
    161  1.4  christos 		else if (!rn2(9)) {
    162  1.1       cgd 			otmp->spe = -rnd(3);
    163  1.1       cgd 			otmp->cursed = 1;
    164  1.1       cgd 		}
    165  1.1       cgd 		break;
    166  1.1       cgd 	case WAND_SYM:
    167  1.4  christos 		if (otmp->otyp == WAN_WISHING)
    168  1.4  christos 			otmp->spe = 3;
    169  1.4  christos 		else
    170  1.4  christos 			otmp->spe = rn1(5,
    171  1.4  christos 			       (objects[otmp->otyp].bits & NODIR) ? 11 : 4);
    172  1.1       cgd 		break;
    173  1.1       cgd 	case RING_SYM:
    174  1.4  christos 		if (objects[otmp->otyp].bits & SPEC) {
    175  1.4  christos 			if (!rn2(3)) {
    176  1.1       cgd 				otmp->cursed = 1;
    177  1.1       cgd 				otmp->spe = -rnd(2);
    178  1.4  christos 			} else
    179  1.4  christos 				otmp->spe = rnd(2);
    180  1.4  christos 		} else if (otmp->otyp == RIN_TELEPORTATION ||
    181  1.4  christos 			   otmp->otyp == RIN_AGGRAVATE_MONSTER ||
    182  1.4  christos 			   otmp->otyp == RIN_HUNGER || !rn2(9))
    183  1.1       cgd 			otmp->cursed = 1;
    184  1.1       cgd 		break;
    185  1.1       cgd 	default:
    186  1.1       cgd 		panic("impossible mkobj");
    187  1.1       cgd 	}
    188  1.1       cgd 	otmp->owt = weight(otmp);
    189  1.4  christos 	return (otmp);
    190  1.1       cgd }
    191  1.1       cgd 
    192  1.4  christos int
    193  1.7  dholland letter(int c)
    194  1.4  christos {
    195  1.4  christos 	return (('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
    196  1.1       cgd }
    197  1.1       cgd 
    198  1.4  christos int
    199  1.7  dholland weight(struct obj *obj)
    200  1.1       cgd {
    201  1.4  christos 	int             wt = objects[obj->otyp].oc_weight;
    202  1.4  christos 	return (wt ? wt * obj->quan : (obj->quan + 1) / 2);
    203  1.1       cgd }
    204  1.1       cgd 
    205  1.4  christos void
    206  1.5       jsm mkgold(long num, int x, int y)
    207  1.1       cgd {
    208  1.4  christos 	struct gold    *gold;
    209  1.4  christos 	long            amount = (num ? num : 1 + (rnd(dlevel + 2) * rnd(30)));
    210  1.1       cgd 
    211  1.4  christos 	if ((gold = g_at(x, y)) != NULL)
    212  1.1       cgd 		gold->amount += amount;
    213  1.1       cgd 	else {
    214  1.1       cgd 		gold = newgold();
    215  1.1       cgd 		gold->ngold = fgold;
    216  1.1       cgd 		gold->gx = x;
    217  1.1       cgd 		gold->gy = y;
    218  1.1       cgd 		gold->amount = amount;
    219  1.1       cgd 		fgold = gold;
    220  1.1       cgd 		/* do sth with display? */
    221  1.1       cgd 	}
    222  1.1       cgd }
    223