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