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