hack.objnam.c revision 1.5 1 1.5 jsm /* $NetBSD: hack.objnam.c,v 1.5 2001/03/25 20:44:02 jsm Exp $ */
2 1.4 christos
3 1.2 mycroft /*
4 1.2 mycroft * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
5 1.2 mycroft */
6 1.2 mycroft
7 1.4 christos #include <sys/cdefs.h>
8 1.2 mycroft #ifndef lint
9 1.5 jsm __RCSID("$NetBSD: hack.objnam.c,v 1.5 2001/03/25 20:44:02 jsm Exp $");
10 1.4 christos #endif /* not lint */
11 1.1 cgd
12 1.4 christos #include <stdlib.h>
13 1.4 christos #include "hack.h"
14 1.4 christos #include "extern.h"
15 1.1 cgd #define Sprintf (void) sprintf
16 1.1 cgd #define Strcat (void) strcat
17 1.1 cgd #define Strcpy (void) strcpy
18 1.1 cgd #define PREFIX 15
19 1.1 cgd
20 1.4 christos char *
21 1.4 christos strprepend(s, pref)
22 1.4 christos char *s, *pref;
23 1.4 christos {
24 1.4 christos int i = strlen(pref);
25 1.4 christos if (i > PREFIX) {
26 1.1 cgd pline("WARNING: prefix too short.");
27 1.4 christos return (s);
28 1.1 cgd }
29 1.1 cgd s -= i;
30 1.1 cgd (void) strncpy(s, pref, i); /* do not copy trailing 0 */
31 1.4 christos return (s);
32 1.1 cgd }
33 1.1 cgd
34 1.4 christos char *
35 1.4 christos sitoa(a)
36 1.4 christos int a;
37 1.4 christos {
38 1.4 christos static char buf[13];
39 1.1 cgd Sprintf(buf, (a < 0) ? "%d" : "+%d", a);
40 1.4 christos return (buf);
41 1.1 cgd }
42 1.1 cgd
43 1.4 christos char *
44 1.1 cgd typename(otyp)
45 1.4 christos int otyp;
46 1.1 cgd {
47 1.4 christos static char buf[BUFSZ];
48 1.4 christos struct objclass *ocl = &objects[otyp];
49 1.5 jsm const char *an = ocl->oc_name;
50 1.5 jsm const char *dn = ocl->oc_descr;
51 1.4 christos char *un = ocl->oc_uname;
52 1.4 christos int nn = ocl->oc_name_known;
53 1.4 christos switch (ocl->oc_olet) {
54 1.1 cgd case POTION_SYM:
55 1.1 cgd Strcpy(buf, "potion");
56 1.1 cgd break;
57 1.1 cgd case SCROLL_SYM:
58 1.1 cgd Strcpy(buf, "scroll");
59 1.1 cgd break;
60 1.1 cgd case WAND_SYM:
61 1.1 cgd Strcpy(buf, "wand");
62 1.1 cgd break;
63 1.1 cgd case RING_SYM:
64 1.1 cgd Strcpy(buf, "ring");
65 1.1 cgd break;
66 1.1 cgd default:
67 1.4 christos if (nn) {
68 1.1 cgd Strcpy(buf, an);
69 1.4 christos if (otyp >= TURQUOISE && otyp <= JADE)
70 1.1 cgd Strcat(buf, " stone");
71 1.4 christos if (un)
72 1.1 cgd Sprintf(eos(buf), " called %s", un);
73 1.4 christos if (dn)
74 1.1 cgd Sprintf(eos(buf), " (%s)", dn);
75 1.1 cgd } else {
76 1.1 cgd Strcpy(buf, dn ? dn : an);
77 1.4 christos if (ocl->oc_olet == GEM_SYM)
78 1.1 cgd Strcat(buf, " gem");
79 1.4 christos if (un)
80 1.1 cgd Sprintf(eos(buf), " called %s", un);
81 1.1 cgd }
82 1.4 christos return (buf);
83 1.1 cgd }
84 1.1 cgd /* here for ring/scroll/potion/wand */
85 1.4 christos if (nn)
86 1.1 cgd Sprintf(eos(buf), " of %s", an);
87 1.4 christos if (un)
88 1.1 cgd Sprintf(eos(buf), " called %s", un);
89 1.4 christos if (dn)
90 1.1 cgd Sprintf(eos(buf), " (%s)", dn);
91 1.4 christos return (buf);
92 1.1 cgd }
93 1.1 cgd
94 1.4 christos char *
95 1.1 cgd xname(obj)
96 1.4 christos struct obj *obj;
97 1.1 cgd {
98 1.4 christos static char bufr[BUFSZ];
99 1.4 christos char *buf = &(bufr[PREFIX]); /* leave room for "17 -3 " */
100 1.4 christos int nn = objects[obj->otyp].oc_name_known;
101 1.5 jsm const char *an = objects[obj->otyp].oc_name;
102 1.5 jsm const char *dn = objects[obj->otyp].oc_descr;
103 1.4 christos char *un = objects[obj->otyp].oc_uname;
104 1.4 christos int pl = (obj->quan != 1);
105 1.4 christos if (!obj->dknown && !Blind)
106 1.4 christos obj->dknown = 1;/* %% doesnt belong here */
107 1.4 christos switch (obj->olet) {
108 1.1 cgd case AMULET_SYM:
109 1.1 cgd Strcpy(buf, (obj->spe < 0 && obj->known)
110 1.4 christos ? "cheap plastic imitation of the " : "");
111 1.4 christos Strcat(buf, "Amulet of Yendor");
112 1.1 cgd break;
113 1.1 cgd case TOOL_SYM:
114 1.4 christos if (!nn) {
115 1.1 cgd Strcpy(buf, dn);
116 1.1 cgd break;
117 1.1 cgd }
118 1.4 christos Strcpy(buf, an);
119 1.1 cgd break;
120 1.1 cgd case FOOD_SYM:
121 1.4 christos if (obj->otyp == DEAD_HOMUNCULUS && pl) {
122 1.1 cgd pl = 0;
123 1.1 cgd Strcpy(buf, "dead homunculi");
124 1.1 cgd break;
125 1.1 cgd }
126 1.1 cgd /* fungis ? */
127 1.1 cgd /* fall into next case */
128 1.1 cgd case WEAPON_SYM:
129 1.4 christos if (obj->otyp == WORM_TOOTH && pl) {
130 1.1 cgd pl = 0;
131 1.1 cgd Strcpy(buf, "worm teeth");
132 1.1 cgd break;
133 1.1 cgd }
134 1.4 christos if (obj->otyp == CRYSKNIFE && pl) {
135 1.1 cgd pl = 0;
136 1.1 cgd Strcpy(buf, "crysknives");
137 1.1 cgd break;
138 1.1 cgd }
139 1.1 cgd /* fall into next case */
140 1.1 cgd case ARMOR_SYM:
141 1.1 cgd case CHAIN_SYM:
142 1.1 cgd case ROCK_SYM:
143 1.4 christos Strcpy(buf, an);
144 1.1 cgd break;
145 1.1 cgd case BALL_SYM:
146 1.1 cgd Sprintf(buf, "%sheavy iron ball",
147 1.1 cgd (obj->owt > objects[obj->otyp].oc_weight) ? "very " : "");
148 1.1 cgd break;
149 1.1 cgd case POTION_SYM:
150 1.4 christos if (nn || un || !obj->dknown) {
151 1.1 cgd Strcpy(buf, "potion");
152 1.4 christos if (pl) {
153 1.1 cgd pl = 0;
154 1.1 cgd Strcat(buf, "s");
155 1.1 cgd }
156 1.4 christos if (!obj->dknown)
157 1.4 christos break;
158 1.4 christos if (un) {
159 1.1 cgd Strcat(buf, " called ");
160 1.1 cgd Strcat(buf, un);
161 1.1 cgd } else {
162 1.1 cgd Strcat(buf, " of ");
163 1.1 cgd Strcat(buf, an);
164 1.1 cgd }
165 1.1 cgd } else {
166 1.1 cgd Strcpy(buf, dn);
167 1.1 cgd Strcat(buf, " potion");
168 1.1 cgd }
169 1.1 cgd break;
170 1.1 cgd case SCROLL_SYM:
171 1.1 cgd Strcpy(buf, "scroll");
172 1.4 christos if (pl) {
173 1.1 cgd pl = 0;
174 1.1 cgd Strcat(buf, "s");
175 1.1 cgd }
176 1.4 christos if (!obj->dknown)
177 1.4 christos break;
178 1.4 christos if (nn) {
179 1.1 cgd Strcat(buf, " of ");
180 1.1 cgd Strcat(buf, an);
181 1.4 christos } else if (un) {
182 1.1 cgd Strcat(buf, " called ");
183 1.1 cgd Strcat(buf, un);
184 1.1 cgd } else {
185 1.1 cgd Strcat(buf, " labeled ");
186 1.1 cgd Strcat(buf, dn);
187 1.1 cgd }
188 1.1 cgd break;
189 1.1 cgd case WAND_SYM:
190 1.4 christos if (!obj->dknown)
191 1.1 cgd Sprintf(buf, "wand");
192 1.4 christos else if (nn)
193 1.1 cgd Sprintf(buf, "wand of %s", an);
194 1.4 christos else if (un)
195 1.1 cgd Sprintf(buf, "wand called %s", un);
196 1.1 cgd else
197 1.1 cgd Sprintf(buf, "%s wand", dn);
198 1.1 cgd break;
199 1.1 cgd case RING_SYM:
200 1.4 christos if (!obj->dknown)
201 1.1 cgd Sprintf(buf, "ring");
202 1.4 christos else if (nn)
203 1.1 cgd Sprintf(buf, "ring of %s", an);
204 1.4 christos else if (un)
205 1.1 cgd Sprintf(buf, "ring called %s", un);
206 1.1 cgd else
207 1.1 cgd Sprintf(buf, "%s ring", dn);
208 1.1 cgd break;
209 1.1 cgd case GEM_SYM:
210 1.4 christos if (!obj->dknown) {
211 1.1 cgd Strcpy(buf, "gem");
212 1.1 cgd break;
213 1.1 cgd }
214 1.4 christos if (!nn) {
215 1.1 cgd Sprintf(buf, "%s gem", dn);
216 1.1 cgd break;
217 1.1 cgd }
218 1.1 cgd Strcpy(buf, an);
219 1.4 christos if (obj->otyp >= TURQUOISE && obj->otyp <= JADE)
220 1.1 cgd Strcat(buf, " stone");
221 1.1 cgd break;
222 1.1 cgd default:
223 1.4 christos Sprintf(buf, "glorkum %c (0%o) %u %d",
224 1.4 christos obj->olet, obj->olet, obj->otyp, obj->spe);
225 1.1 cgd }
226 1.4 christos if (pl) {
227 1.4 christos char *p;
228 1.1 cgd
229 1.4 christos for (p = buf; *p; p++) {
230 1.4 christos if (!strncmp(" of ", p, 4)) {
231 1.1 cgd /* pieces of, cloves of, lumps of */
232 1.4 christos int c1, c2 = 's';
233 1.1 cgd
234 1.1 cgd do {
235 1.4 christos c1 = c2;
236 1.4 christos c2 = *p;
237 1.4 christos *p++ = c1;
238 1.4 christos } while (c1);
239 1.1 cgd goto nopl;
240 1.1 cgd }
241 1.1 cgd }
242 1.4 christos p = eos(buf) - 1;
243 1.4 christos if (*p == 's' || *p == 'z' || *p == 'x' ||
244 1.1 cgd (*p == 'h' && p[-1] == 's'))
245 1.1 cgd Strcat(buf, "es"); /* boxes */
246 1.4 christos else if (*p == 'y' && !strchr(vowels, p[-1]))
247 1.1 cgd Strcpy(p, "ies"); /* rubies, zruties */
248 1.1 cgd else
249 1.1 cgd Strcat(buf, "s");
250 1.1 cgd }
251 1.1 cgd nopl:
252 1.4 christos if (obj->onamelth) {
253 1.1 cgd Strcat(buf, " named ");
254 1.1 cgd Strcat(buf, ONAME(obj));
255 1.1 cgd }
256 1.4 christos return (buf);
257 1.1 cgd }
258 1.1 cgd
259 1.4 christos char *
260 1.1 cgd doname(obj)
261 1.4 christos struct obj *obj;
262 1.1 cgd {
263 1.4 christos char prefix[PREFIX];
264 1.4 christos char *bp = xname(obj);
265 1.4 christos if (obj->quan != 1)
266 1.1 cgd Sprintf(prefix, "%u ", obj->quan);
267 1.1 cgd else
268 1.1 cgd Strcpy(prefix, "a ");
269 1.4 christos switch (obj->olet) {
270 1.1 cgd case AMULET_SYM:
271 1.4 christos if (strncmp(bp, "cheap ", 6))
272 1.1 cgd Strcpy(prefix, "the ");
273 1.1 cgd break;
274 1.1 cgd case ARMOR_SYM:
275 1.4 christos if (obj->owornmask & W_ARMOR)
276 1.1 cgd Strcat(bp, " (being worn)");
277 1.1 cgd /* fall into next case */
278 1.1 cgd case WEAPON_SYM:
279 1.4 christos if (obj->known) {
280 1.1 cgd Strcat(prefix, sitoa(obj->spe));
281 1.1 cgd Strcat(prefix, " ");
282 1.1 cgd }
283 1.1 cgd break;
284 1.1 cgd case WAND_SYM:
285 1.4 christos if (obj->known)
286 1.1 cgd Sprintf(eos(bp), " (%d)", obj->spe);
287 1.1 cgd break;
288 1.1 cgd case RING_SYM:
289 1.4 christos if (obj->owornmask & W_RINGR)
290 1.4 christos Strcat(bp, " (on right hand)");
291 1.4 christos if (obj->owornmask & W_RINGL)
292 1.4 christos Strcat(bp, " (on left hand)");
293 1.4 christos if (obj->known && (objects[obj->otyp].bits & SPEC)) {
294 1.1 cgd Strcat(prefix, sitoa(obj->spe));
295 1.1 cgd Strcat(prefix, " ");
296 1.1 cgd }
297 1.1 cgd break;
298 1.1 cgd }
299 1.4 christos if (obj->owornmask & W_WEP)
300 1.1 cgd Strcat(bp, " (weapon in hand)");
301 1.4 christos if (obj->unpaid)
302 1.1 cgd Strcat(bp, " (unpaid)");
303 1.4 christos if (!strcmp(prefix, "a ") && strchr(vowels, *bp))
304 1.1 cgd Strcpy(prefix, "an ");
305 1.1 cgd bp = strprepend(bp, prefix);
306 1.4 christos return (bp);
307 1.1 cgd }
308 1.1 cgd
309 1.1 cgd /* used only in hack.fight.c (thitu) */
310 1.4 christos void
311 1.5 jsm setan(const char *str, char *buf)
312 1.1 cgd {
313 1.4 christos if (strchr(vowels, *str))
314 1.1 cgd Sprintf(buf, "an %s", str);
315 1.1 cgd else
316 1.1 cgd Sprintf(buf, "a %s", str);
317 1.1 cgd }
318 1.1 cgd
319 1.4 christos char *
320 1.4 christos aobjnam(otmp, verb)
321 1.4 christos struct obj *otmp;
322 1.5 jsm const char *verb;
323 1.4 christos {
324 1.4 christos char *bp = xname(otmp);
325 1.4 christos char prefix[PREFIX];
326 1.4 christos if (otmp->quan != 1) {
327 1.1 cgd Sprintf(prefix, "%u ", otmp->quan);
328 1.1 cgd bp = strprepend(bp, prefix);
329 1.1 cgd }
330 1.4 christos if (verb) {
331 1.1 cgd /* verb is given in plural (i.e., without trailing s) */
332 1.1 cgd Strcat(bp, " ");
333 1.4 christos if (otmp->quan != 1)
334 1.1 cgd Strcat(bp, verb);
335 1.4 christos else if (!strcmp(verb, "are"))
336 1.1 cgd Strcat(bp, "is");
337 1.1 cgd else {
338 1.1 cgd Strcat(bp, verb);
339 1.1 cgd Strcat(bp, "s");
340 1.1 cgd }
341 1.1 cgd }
342 1.4 christos return (bp);
343 1.1 cgd }
344 1.1 cgd
345 1.4 christos char *
346 1.1 cgd Doname(obj)
347 1.4 christos struct obj *obj;
348 1.1 cgd {
349 1.4 christos char *s = doname(obj);
350 1.1 cgd
351 1.4 christos if ('a' <= *s && *s <= 'z')
352 1.4 christos *s -= ('a' - 'A');
353 1.4 christos return (s);
354 1.1 cgd }
355 1.1 cgd
356 1.5 jsm const char *const wrp[] = {"wand", "ring", "potion", "scroll", "gem"};
357 1.5 jsm const char wrpsym[] = {WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM};
358 1.1 cgd
359 1.4 christos struct obj *
360 1.4 christos readobjnam(bp)
361 1.4 christos char *bp;
362 1.4 christos {
363 1.4 christos char *p;
364 1.4 christos int i;
365 1.4 christos int cnt, spe, spesgn, typ, heavy;
366 1.4 christos char let;
367 1.4 christos char *un, *dn, *an;
368 1.4 christos /* int the = 0; char *oname = 0; */
369 1.1 cgd cnt = spe = spesgn = typ = heavy = 0;
370 1.1 cgd let = 0;
371 1.1 cgd an = dn = un = 0;
372 1.4 christos for (p = bp; *p; p++)
373 1.4 christos if ('A' <= *p && *p <= 'Z')
374 1.4 christos *p += 'a' - 'A';
375 1.4 christos if (!strncmp(bp, "the ", 4)) {
376 1.4 christos /* the = 1; */
377 1.1 cgd bp += 4;
378 1.4 christos } else if (!strncmp(bp, "an ", 3)) {
379 1.1 cgd cnt = 1;
380 1.1 cgd bp += 3;
381 1.4 christos } else if (!strncmp(bp, "a ", 2)) {
382 1.1 cgd cnt = 1;
383 1.1 cgd bp += 2;
384 1.1 cgd }
385 1.4 christos if (!cnt && digit(*bp)) {
386 1.1 cgd cnt = atoi(bp);
387 1.4 christos while (digit(*bp))
388 1.4 christos bp++;
389 1.4 christos while (*bp == ' ')
390 1.4 christos bp++;
391 1.1 cgd }
392 1.4 christos if (!cnt)
393 1.4 christos cnt = 1; /* %% what with "gems" etc. ? */
394 1.1 cgd
395 1.4 christos if (*bp == '+' || *bp == '-') {
396 1.1 cgd spesgn = (*bp++ == '+') ? 1 : -1;
397 1.1 cgd spe = atoi(bp);
398 1.4 christos while (digit(*bp))
399 1.4 christos bp++;
400 1.4 christos while (*bp == ' ')
401 1.4 christos bp++;
402 1.1 cgd } else {
403 1.4 christos p = strrchr(bp, '(');
404 1.4 christos if (p) {
405 1.4 christos if (p > bp && p[-1] == ' ')
406 1.4 christos p[-1] = 0;
407 1.4 christos else
408 1.4 christos *p = 0;
409 1.1 cgd p++;
410 1.1 cgd spe = atoi(p);
411 1.4 christos while (digit(*p))
412 1.4 christos p++;
413 1.4 christos if (strcmp(p, ")"))
414 1.4 christos spe = 0;
415 1.4 christos else
416 1.4 christos spesgn = 1;
417 1.4 christos }
418 1.4 christos }
419 1.4 christos /*
420 1.4 christos * now we have the actual name, as delivered by xname, say green
421 1.4 christos * potions called whisky scrolls labeled "QWERTY" egg dead zruties
422 1.4 christos * fortune cookies very heavy iron ball named hoei wand of wishing
423 1.4 christos * elven cloak
424 1.4 christos */
425 1.4 christos for (p = bp; *p; p++)
426 1.4 christos if (!strncmp(p, " named ", 7)) {
427 1.4 christos *p = 0;
428 1.4 christos /* oname = p+7; */
429 1.4 christos }
430 1.4 christos for (p = bp; *p; p++)
431 1.4 christos if (!strncmp(p, " called ", 8)) {
432 1.4 christos *p = 0;
433 1.4 christos un = p + 8;
434 1.4 christos }
435 1.4 christos for (p = bp; *p; p++)
436 1.4 christos if (!strncmp(p, " labeled ", 9)) {
437 1.4 christos *p = 0;
438 1.4 christos dn = p + 9;
439 1.4 christos }
440 1.1 cgd /* first change to singular if necessary */
441 1.4 christos if (cnt != 1) {
442 1.1 cgd /* find "cloves of garlic", "worthless pieces of blue glass" */
443 1.4 christos for (p = bp; *p; p++)
444 1.4 christos if (!strncmp(p, "s of ", 5)) {
445 1.4 christos while ((*p = p[1]) != '\0')
446 1.4 christos p++;
447 1.4 christos goto sing;
448 1.4 christos }
449 1.1 cgd /* remove -s or -es (boxes) or -ies (rubies, zruties) */
450 1.1 cgd p = eos(bp);
451 1.4 christos if (p[-1] == 's') {
452 1.4 christos if (p[-2] == 'e') {
453 1.4 christos if (p[-3] == 'i') {
454 1.4 christos if (!strcmp(p - 7, "cookies"))
455 1.1 cgd goto mins;
456 1.4 christos Strcpy(p - 3, "y");
457 1.1 cgd goto sing;
458 1.1 cgd }
459 1.1 cgd /* note: cloves / knives from clove / knife */
460 1.4 christos if (!strcmp(p - 6, "knives")) {
461 1.4 christos Strcpy(p - 3, "fe");
462 1.1 cgd goto sing;
463 1.1 cgd }
464 1.1 cgd /* note: nurses, axes but boxes */
465 1.4 christos if (!strcmp(p - 5, "boxes")) {
466 1.1 cgd p[-2] = 0;
467 1.1 cgd goto sing;
468 1.1 cgd }
469 1.1 cgd }
470 1.4 christos mins:
471 1.1 cgd p[-1] = 0;
472 1.1 cgd } else {
473 1.4 christos if (!strcmp(p - 9, "homunculi")) {
474 1.4 christos Strcpy(p - 1, "us"); /* !! makes string
475 1.4 christos * longer */
476 1.1 cgd goto sing;
477 1.1 cgd }
478 1.4 christos if (!strcmp(p - 5, "teeth")) {
479 1.4 christos Strcpy(p - 5, "tooth");
480 1.1 cgd goto sing;
481 1.1 cgd }
482 1.1 cgd /* here we cannot find the plural suffix */
483 1.1 cgd }
484 1.1 cgd }
485 1.1 cgd sing:
486 1.4 christos if (!strcmp(bp, "amulet of yendor")) {
487 1.1 cgd typ = AMULET_OF_YENDOR;
488 1.1 cgd goto typfnd;
489 1.1 cgd }
490 1.1 cgd p = eos(bp);
491 1.4 christos if (!strcmp(p - 5, " mail")) { /* Note: ring mail is not a ring ! */
492 1.1 cgd let = ARMOR_SYM;
493 1.1 cgd an = bp;
494 1.1 cgd goto srch;
495 1.1 cgd }
496 1.4 christos for (i = 0; i < sizeof(wrpsym); i++) {
497 1.4 christos int j = strlen(wrp[i]);
498 1.4 christos if (!strncmp(bp, wrp[i], j)) {
499 1.1 cgd let = wrpsym[i];
500 1.1 cgd bp += j;
501 1.4 christos if (!strncmp(bp, " of ", 4))
502 1.4 christos an = bp + 4;
503 1.1 cgd /* else if(*bp) ?? */
504 1.1 cgd goto srch;
505 1.1 cgd }
506 1.4 christos if (!strcmp(p - j, wrp[i])) {
507 1.1 cgd let = wrpsym[i];
508 1.1 cgd p -= j;
509 1.1 cgd *p = 0;
510 1.4 christos if (p[-1] == ' ')
511 1.4 christos p[-1] = 0;
512 1.1 cgd dn = bp;
513 1.1 cgd goto srch;
514 1.1 cgd }
515 1.1 cgd }
516 1.4 christos if (!strcmp(p - 6, " stone")) {
517 1.1 cgd p[-6] = 0;
518 1.1 cgd let = GEM_SYM;
519 1.1 cgd an = bp;
520 1.1 cgd goto srch;
521 1.1 cgd }
522 1.4 christos if (!strcmp(bp, "very heavy iron ball")) {
523 1.1 cgd heavy = 1;
524 1.1 cgd typ = HEAVY_IRON_BALL;
525 1.1 cgd goto typfnd;
526 1.1 cgd }
527 1.1 cgd an = bp;
528 1.1 cgd srch:
529 1.4 christos if (!an && !dn && !un)
530 1.1 cgd goto any;
531 1.1 cgd i = 1;
532 1.4 christos if (let)
533 1.4 christos i = bases[letindex(let)];
534 1.4 christos while (i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)) {
535 1.5 jsm const char *zn = objects[i].oc_name;
536 1.1 cgd
537 1.4 christos if (!zn)
538 1.4 christos goto nxti;
539 1.4 christos if (an && strcmp(an, zn))
540 1.1 cgd goto nxti;
541 1.4 christos if (dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn)))
542 1.1 cgd goto nxti;
543 1.4 christos if (un && (!(zn = objects[i].oc_uname) || strcmp(un, zn)))
544 1.1 cgd goto nxti;
545 1.1 cgd typ = i;
546 1.1 cgd goto typfnd;
547 1.4 christos nxti:
548 1.1 cgd i++;
549 1.1 cgd }
550 1.1 cgd any:
551 1.4 christos if (!let)
552 1.4 christos let = wrpsym[rn2(sizeof(wrpsym))];
553 1.1 cgd typ = probtype(let);
554 1.1 cgd typfnd:
555 1.4 christos {
556 1.4 christos struct obj *otmp;
557 1.4 christos let = objects[typ].oc_olet;
558 1.4 christos otmp = mksobj(typ);
559 1.4 christos if (heavy)
560 1.4 christos otmp->owt += 15;
561 1.4 christos if (cnt > 0 && strchr("%?!*)", let) &&
562 1.1 cgd (cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20)))
563 1.4 christos otmp->quan = cnt;
564 1.1 cgd
565 1.4 christos if (spe > 3 && spe > otmp->spe)
566 1.4 christos spe = 0;
567 1.4 christos else if (let == WAND_SYM)
568 1.4 christos spe = otmp->spe;
569 1.4 christos if (spe == 3 && u.uluck < 0)
570 1.4 christos spesgn = -1;
571 1.4 christos if (let != WAND_SYM && spesgn == -1)
572 1.4 christos spe = -spe;
573 1.4 christos if (let == BALL_SYM)
574 1.4 christos spe = 0;
575 1.4 christos else if (let == AMULET_SYM)
576 1.4 christos spe = -1;
577 1.4 christos else if (typ == WAN_WISHING && rn2(10))
578 1.4 christos spe = (rn2(10) ? -1 : 0);
579 1.4 christos otmp->spe = spe;
580 1.1 cgd
581 1.4 christos if (spesgn == -1)
582 1.4 christos otmp->cursed = 1;
583 1.1 cgd
584 1.4 christos return (otmp);
585 1.4 christos }
586 1.1 cgd }
587