hack.objnam.c revision 1.4 1 1.4 christos /* $NetBSD: hack.objnam.c,v 1.4 1997/10/19 16:58:39 christos 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.4 christos __RCSID("$NetBSD: hack.objnam.c,v 1.4 1997/10/19 16:58:39 christos 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.4 christos char *an = ocl->oc_name;
50 1.4 christos 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.4 christos char *an = objects[obj->otyp].oc_name;
102 1.4 christos 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.4 christos setan(str, buf)
312 1.4 christos char *str, *buf;
313 1.1 cgd {
314 1.4 christos if (strchr(vowels, *str))
315 1.1 cgd Sprintf(buf, "an %s", str);
316 1.1 cgd else
317 1.1 cgd Sprintf(buf, "a %s", str);
318 1.1 cgd }
319 1.1 cgd
320 1.4 christos char *
321 1.4 christos aobjnam(otmp, verb)
322 1.4 christos struct obj *otmp;
323 1.4 christos char *verb;
324 1.4 christos {
325 1.4 christos char *bp = xname(otmp);
326 1.4 christos char prefix[PREFIX];
327 1.4 christos if (otmp->quan != 1) {
328 1.1 cgd Sprintf(prefix, "%u ", otmp->quan);
329 1.1 cgd bp = strprepend(bp, prefix);
330 1.1 cgd }
331 1.4 christos if (verb) {
332 1.1 cgd /* verb is given in plural (i.e., without trailing s) */
333 1.1 cgd Strcat(bp, " ");
334 1.4 christos if (otmp->quan != 1)
335 1.1 cgd Strcat(bp, verb);
336 1.4 christos else if (!strcmp(verb, "are"))
337 1.1 cgd Strcat(bp, "is");
338 1.1 cgd else {
339 1.1 cgd Strcat(bp, verb);
340 1.1 cgd Strcat(bp, "s");
341 1.1 cgd }
342 1.1 cgd }
343 1.4 christos return (bp);
344 1.1 cgd }
345 1.1 cgd
346 1.4 christos char *
347 1.1 cgd Doname(obj)
348 1.4 christos struct obj *obj;
349 1.1 cgd {
350 1.4 christos char *s = doname(obj);
351 1.1 cgd
352 1.4 christos if ('a' <= *s && *s <= 'z')
353 1.4 christos *s -= ('a' - 'A');
354 1.4 christos return (s);
355 1.1 cgd }
356 1.1 cgd
357 1.4 christos char *wrp[] = {"wand", "ring", "potion", "scroll", "gem"};
358 1.4 christos char wrpsym[] = {WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM};
359 1.1 cgd
360 1.4 christos struct obj *
361 1.4 christos readobjnam(bp)
362 1.4 christos char *bp;
363 1.4 christos {
364 1.4 christos char *p;
365 1.4 christos int i;
366 1.4 christos int cnt, spe, spesgn, typ, heavy;
367 1.4 christos char let;
368 1.4 christos char *un, *dn, *an;
369 1.4 christos /* int the = 0; char *oname = 0; */
370 1.1 cgd cnt = spe = spesgn = typ = heavy = 0;
371 1.1 cgd let = 0;
372 1.1 cgd an = dn = un = 0;
373 1.4 christos for (p = bp; *p; p++)
374 1.4 christos if ('A' <= *p && *p <= 'Z')
375 1.4 christos *p += 'a' - 'A';
376 1.4 christos if (!strncmp(bp, "the ", 4)) {
377 1.4 christos /* the = 1; */
378 1.1 cgd bp += 4;
379 1.4 christos } else if (!strncmp(bp, "an ", 3)) {
380 1.1 cgd cnt = 1;
381 1.1 cgd bp += 3;
382 1.4 christos } else if (!strncmp(bp, "a ", 2)) {
383 1.1 cgd cnt = 1;
384 1.1 cgd bp += 2;
385 1.1 cgd }
386 1.4 christos if (!cnt && digit(*bp)) {
387 1.1 cgd cnt = atoi(bp);
388 1.4 christos while (digit(*bp))
389 1.4 christos bp++;
390 1.4 christos while (*bp == ' ')
391 1.4 christos bp++;
392 1.1 cgd }
393 1.4 christos if (!cnt)
394 1.4 christos cnt = 1; /* %% what with "gems" etc. ? */
395 1.1 cgd
396 1.4 christos if (*bp == '+' || *bp == '-') {
397 1.1 cgd spesgn = (*bp++ == '+') ? 1 : -1;
398 1.1 cgd spe = atoi(bp);
399 1.4 christos while (digit(*bp))
400 1.4 christos bp++;
401 1.4 christos while (*bp == ' ')
402 1.4 christos bp++;
403 1.1 cgd } else {
404 1.4 christos p = strrchr(bp, '(');
405 1.4 christos if (p) {
406 1.4 christos if (p > bp && p[-1] == ' ')
407 1.4 christos p[-1] = 0;
408 1.4 christos else
409 1.4 christos *p = 0;
410 1.1 cgd p++;
411 1.1 cgd spe = atoi(p);
412 1.4 christos while (digit(*p))
413 1.4 christos p++;
414 1.4 christos if (strcmp(p, ")"))
415 1.4 christos spe = 0;
416 1.4 christos else
417 1.4 christos spesgn = 1;
418 1.4 christos }
419 1.4 christos }
420 1.4 christos /*
421 1.4 christos * now we have the actual name, as delivered by xname, say green
422 1.4 christos * potions called whisky scrolls labeled "QWERTY" egg dead zruties
423 1.4 christos * fortune cookies very heavy iron ball named hoei wand of wishing
424 1.4 christos * elven cloak
425 1.4 christos */
426 1.4 christos for (p = bp; *p; p++)
427 1.4 christos if (!strncmp(p, " named ", 7)) {
428 1.4 christos *p = 0;
429 1.4 christos /* oname = p+7; */
430 1.4 christos }
431 1.4 christos for (p = bp; *p; p++)
432 1.4 christos if (!strncmp(p, " called ", 8)) {
433 1.4 christos *p = 0;
434 1.4 christos un = p + 8;
435 1.4 christos }
436 1.4 christos for (p = bp; *p; p++)
437 1.4 christos if (!strncmp(p, " labeled ", 9)) {
438 1.4 christos *p = 0;
439 1.4 christos dn = p + 9;
440 1.4 christos }
441 1.1 cgd /* first change to singular if necessary */
442 1.4 christos if (cnt != 1) {
443 1.1 cgd /* find "cloves of garlic", "worthless pieces of blue glass" */
444 1.4 christos for (p = bp; *p; p++)
445 1.4 christos if (!strncmp(p, "s of ", 5)) {
446 1.4 christos while ((*p = p[1]) != '\0')
447 1.4 christos p++;
448 1.4 christos goto sing;
449 1.4 christos }
450 1.1 cgd /* remove -s or -es (boxes) or -ies (rubies, zruties) */
451 1.1 cgd p = eos(bp);
452 1.4 christos if (p[-1] == 's') {
453 1.4 christos if (p[-2] == 'e') {
454 1.4 christos if (p[-3] == 'i') {
455 1.4 christos if (!strcmp(p - 7, "cookies"))
456 1.1 cgd goto mins;
457 1.4 christos Strcpy(p - 3, "y");
458 1.1 cgd goto sing;
459 1.1 cgd }
460 1.1 cgd /* note: cloves / knives from clove / knife */
461 1.4 christos if (!strcmp(p - 6, "knives")) {
462 1.4 christos Strcpy(p - 3, "fe");
463 1.1 cgd goto sing;
464 1.1 cgd }
465 1.1 cgd /* note: nurses, axes but boxes */
466 1.4 christos if (!strcmp(p - 5, "boxes")) {
467 1.1 cgd p[-2] = 0;
468 1.1 cgd goto sing;
469 1.1 cgd }
470 1.1 cgd }
471 1.4 christos mins:
472 1.1 cgd p[-1] = 0;
473 1.1 cgd } else {
474 1.4 christos if (!strcmp(p - 9, "homunculi")) {
475 1.4 christos Strcpy(p - 1, "us"); /* !! makes string
476 1.4 christos * longer */
477 1.1 cgd goto sing;
478 1.1 cgd }
479 1.4 christos if (!strcmp(p - 5, "teeth")) {
480 1.4 christos Strcpy(p - 5, "tooth");
481 1.1 cgd goto sing;
482 1.1 cgd }
483 1.1 cgd /* here we cannot find the plural suffix */
484 1.1 cgd }
485 1.1 cgd }
486 1.1 cgd sing:
487 1.4 christos if (!strcmp(bp, "amulet of yendor")) {
488 1.1 cgd typ = AMULET_OF_YENDOR;
489 1.1 cgd goto typfnd;
490 1.1 cgd }
491 1.1 cgd p = eos(bp);
492 1.4 christos if (!strcmp(p - 5, " mail")) { /* Note: ring mail is not a ring ! */
493 1.1 cgd let = ARMOR_SYM;
494 1.1 cgd an = bp;
495 1.1 cgd goto srch;
496 1.1 cgd }
497 1.4 christos for (i = 0; i < sizeof(wrpsym); i++) {
498 1.4 christos int j = strlen(wrp[i]);
499 1.4 christos if (!strncmp(bp, wrp[i], j)) {
500 1.1 cgd let = wrpsym[i];
501 1.1 cgd bp += j;
502 1.4 christos if (!strncmp(bp, " of ", 4))
503 1.4 christos an = bp + 4;
504 1.1 cgd /* else if(*bp) ?? */
505 1.1 cgd goto srch;
506 1.1 cgd }
507 1.4 christos if (!strcmp(p - j, wrp[i])) {
508 1.1 cgd let = wrpsym[i];
509 1.1 cgd p -= j;
510 1.1 cgd *p = 0;
511 1.4 christos if (p[-1] == ' ')
512 1.4 christos p[-1] = 0;
513 1.1 cgd dn = bp;
514 1.1 cgd goto srch;
515 1.1 cgd }
516 1.1 cgd }
517 1.4 christos if (!strcmp(p - 6, " stone")) {
518 1.1 cgd p[-6] = 0;
519 1.1 cgd let = GEM_SYM;
520 1.1 cgd an = bp;
521 1.1 cgd goto srch;
522 1.1 cgd }
523 1.4 christos if (!strcmp(bp, "very heavy iron ball")) {
524 1.1 cgd heavy = 1;
525 1.1 cgd typ = HEAVY_IRON_BALL;
526 1.1 cgd goto typfnd;
527 1.1 cgd }
528 1.1 cgd an = bp;
529 1.1 cgd srch:
530 1.4 christos if (!an && !dn && !un)
531 1.1 cgd goto any;
532 1.1 cgd i = 1;
533 1.4 christos if (let)
534 1.4 christos i = bases[letindex(let)];
535 1.4 christos while (i <= NROFOBJECTS && (!let || objects[i].oc_olet == let)) {
536 1.4 christos char *zn = objects[i].oc_name;
537 1.1 cgd
538 1.4 christos if (!zn)
539 1.4 christos goto nxti;
540 1.4 christos if (an && strcmp(an, zn))
541 1.1 cgd goto nxti;
542 1.4 christos if (dn && (!(zn = objects[i].oc_descr) || strcmp(dn, zn)))
543 1.1 cgd goto nxti;
544 1.4 christos if (un && (!(zn = objects[i].oc_uname) || strcmp(un, zn)))
545 1.1 cgd goto nxti;
546 1.1 cgd typ = i;
547 1.1 cgd goto typfnd;
548 1.4 christos nxti:
549 1.1 cgd i++;
550 1.1 cgd }
551 1.1 cgd any:
552 1.4 christos if (!let)
553 1.4 christos let = wrpsym[rn2(sizeof(wrpsym))];
554 1.1 cgd typ = probtype(let);
555 1.1 cgd typfnd:
556 1.4 christos {
557 1.4 christos struct obj *otmp;
558 1.4 christos let = objects[typ].oc_olet;
559 1.4 christos otmp = mksobj(typ);
560 1.4 christos if (heavy)
561 1.4 christos otmp->owt += 15;
562 1.4 christos if (cnt > 0 && strchr("%?!*)", let) &&
563 1.1 cgd (cnt < 4 || (let == WEAPON_SYM && typ <= ROCK && cnt < 20)))
564 1.4 christos otmp->quan = cnt;
565 1.1 cgd
566 1.4 christos if (spe > 3 && spe > otmp->spe)
567 1.4 christos spe = 0;
568 1.4 christos else if (let == WAND_SYM)
569 1.4 christos spe = otmp->spe;
570 1.4 christos if (spe == 3 && u.uluck < 0)
571 1.4 christos spesgn = -1;
572 1.4 christos if (let != WAND_SYM && spesgn == -1)
573 1.4 christos spe = -spe;
574 1.4 christos if (let == BALL_SYM)
575 1.4 christos spe = 0;
576 1.4 christos else if (let == AMULET_SYM)
577 1.4 christos spe = -1;
578 1.4 christos else if (typ == WAN_WISHING && rn2(10))
579 1.4 christos spe = (rn2(10) ? -1 : 0);
580 1.4 christos otmp->spe = spe;
581 1.1 cgd
582 1.4 christos if (spesgn == -1)
583 1.4 christos otmp->cursed = 1;
584 1.1 cgd
585 1.4 christos return (otmp);
586 1.4 christos }
587 1.1 cgd }
588