hack.mkobj.c revision 1.7 1 1.7 dholland /* $NetBSD: hack.mkobj.c,v 1.7 2009/06/07 18:30:39 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.7 dholland __RCSID("$NetBSD: hack.mkobj.c,v 1.7 2009/06/07 18:30:39 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.4 christos 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.1 cgd /* fall into next case */
145 1.1 cgd case GEM_SYM:
146 1.1 cgd otmp->quan = rn2(6) ? 1 : 2;
147 1.1 cgd case TOOL_SYM:
148 1.1 cgd case CHAIN_SYM:
149 1.1 cgd case BALL_SYM:
150 1.1 cgd case ROCK_SYM:
151 1.1 cgd case POTION_SYM:
152 1.1 cgd case SCROLL_SYM:
153 1.1 cgd case AMULET_SYM:
154 1.1 cgd break;
155 1.1 cgd case ARMOR_SYM:
156 1.4 christos if (!rn2(8))
157 1.4 christos otmp->cursed = 1;
158 1.4 christos if (!rn2(10))
159 1.4 christos otmp->spe = rnd(3);
160 1.4 christos else if (!rn2(9)) {
161 1.1 cgd otmp->spe = -rnd(3);
162 1.1 cgd otmp->cursed = 1;
163 1.1 cgd }
164 1.1 cgd break;
165 1.1 cgd case WAND_SYM:
166 1.4 christos if (otmp->otyp == WAN_WISHING)
167 1.4 christos otmp->spe = 3;
168 1.4 christos else
169 1.4 christos otmp->spe = rn1(5,
170 1.4 christos (objects[otmp->otyp].bits & NODIR) ? 11 : 4);
171 1.1 cgd break;
172 1.1 cgd case RING_SYM:
173 1.4 christos if (objects[otmp->otyp].bits & SPEC) {
174 1.4 christos if (!rn2(3)) {
175 1.1 cgd otmp->cursed = 1;
176 1.1 cgd otmp->spe = -rnd(2);
177 1.4 christos } else
178 1.4 christos otmp->spe = rnd(2);
179 1.4 christos } else if (otmp->otyp == RIN_TELEPORTATION ||
180 1.4 christos otmp->otyp == RIN_AGGRAVATE_MONSTER ||
181 1.4 christos otmp->otyp == RIN_HUNGER || !rn2(9))
182 1.1 cgd otmp->cursed = 1;
183 1.1 cgd break;
184 1.1 cgd default:
185 1.1 cgd panic("impossible mkobj");
186 1.1 cgd }
187 1.1 cgd otmp->owt = weight(otmp);
188 1.4 christos return (otmp);
189 1.1 cgd }
190 1.1 cgd
191 1.4 christos int
192 1.7 dholland letter(int c)
193 1.4 christos {
194 1.4 christos return (('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
195 1.1 cgd }
196 1.1 cgd
197 1.4 christos int
198 1.7 dholland weight(struct obj *obj)
199 1.1 cgd {
200 1.4 christos int wt = objects[obj->otyp].oc_weight;
201 1.4 christos return (wt ? wt * obj->quan : (obj->quan + 1) / 2);
202 1.1 cgd }
203 1.1 cgd
204 1.4 christos void
205 1.5 jsm mkgold(long num, int x, int y)
206 1.1 cgd {
207 1.4 christos struct gold *gold;
208 1.4 christos long amount = (num ? num : 1 + (rnd(dlevel + 2) * rnd(30)));
209 1.1 cgd
210 1.4 christos if ((gold = g_at(x, y)) != NULL)
211 1.1 cgd gold->amount += amount;
212 1.1 cgd else {
213 1.1 cgd gold = newgold();
214 1.1 cgd gold->ngold = fgold;
215 1.1 cgd gold->gx = x;
216 1.1 cgd gold->gy = y;
217 1.1 cgd gold->amount = amount;
218 1.1 cgd fgold = gold;
219 1.1 cgd /* do sth with display? */
220 1.1 cgd }
221 1.1 cgd }
222