]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.do_name.c
1 /* $NetBSD: hack.do_name.c,v 1.13 2011/08/07 06:03:45 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.do_name.c,v 1.13 2011/08/07 06:03:45 dholland Exp $");
73 static void do_oname(struct obj
*);
74 static char *xmonnam(struct monst
*, int);
75 static char *lmonnam(struct monst
*);
76 static char *visctrl(int);
79 getpos(int force
, const char *goal
)
83 pline("(For instructions type a ?)");
87 while ((c
= readchar()) != '.') {
88 for (i
= 0; i
< 8; i
++)
90 if (1 <= cx
+ xdir
[i
] && cx
+ xdir
[i
] <= COLNO
)
92 if (0 <= cy
+ ydir
[i
] && cy
+ ydir
[i
] <= ROWNO
- 1)
97 pline("Use [hjkl] to move the cursor to %s.", goal
);
98 pline("Type a . when you are at the right place.");
100 pline("Unknown direction: '%s' (%s).",
102 force
? "use hjkl or ." : "aborted");
125 struct monst
*mtmp
, *mtmp2
;
126 cc
= getpos(0, "the monster you want to name");
133 if (cx
== u
.ux
&& cy
== u
.uy
)
134 pline("This ugly monster is called %s and cannot be renamed.",
137 pline("There is no monster there.");
141 pline("I see no monster there.");
144 if (!cansee(cx
, cy
)) {
145 pline("I cannot see a monster there.");
148 pline("What do you want to call %s? ", lmonnam(mtmp
));
151 if (!*buf
|| *buf
== '\033')
153 lth
= strlen(buf
) + 1;
158 mtmp2
= newmonst(mtmp
->mxlth
+ lth
);
160 for (i
= 0; i
< mtmp
->mxlth
; i
++)
161 ((char *) mtmp2
->mextra
)[i
] = ((char *) mtmp
->mextra
)[i
];
162 mtmp2
->mnamelth
= lth
;
163 (void) strcpy(NAME(mtmp2
), buf
);
164 replmon(mtmp
, mtmp2
);
169 * This routine changes the address of obj . Be careful not to call it
170 * when there might be pointers around in unknown places. For now: only
171 * when obj is in the inventory.
174 do_oname(struct obj
*obj
)
176 struct obj
*otmp
, *otmp2
;
179 pline("What do you want to name %s? ", doname(obj
));
182 if (!*buf
|| *buf
== '\033')
184 lth
= strlen(buf
) + 1;
191 otmp2
->onamelth
= lth
;
192 (void) strcpy(ONAME(otmp2
), buf
);
194 setworn((struct obj
*) 0, obj
->owornmask
);
195 setworn(otmp2
, otmp2
->owornmask
);
198 * do freeinv(obj); etc. by hand in order to preserve the position of
199 * this object in the inventory
204 for (otmp
= invent
;; otmp
= otmp
->nobj
) {
206 panic("Do_oname: cannot find obj.");
207 if (otmp
->nobj
== obj
) {
213 obfree(obj
, otmp2
); /* now unnecessary: no pointers on bill */
215 free(obj
); /* let us hope nobody else saved a pointer */
223 pline("Do you want to name an individual object? [ny] ");
224 switch (readchar()) {
228 obj
= getobj("#", "name");
233 obj
= getobj("?!=/", "call");
241 docall(struct obj
*obj
)
252 pline("Call %s %s: ", strchr(vowels
, *str
) ? "an" : "a", str
);
255 if (!*buf
|| *buf
== '\033')
257 str
= newstring(strlen(buf
) + 1);
258 (void) strcpy(str
, buf
);
259 str1
= &(objects
[obj
->otyp
].oc_uname
);
265 static const char *const ghostnames
[] = {
266 /* these names should have length < PL_NSIZ */
267 "adri", "andries", "andreas", "bert", "david", "dirk", "emile",
268 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
269 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
274 xmonnam(struct monst
*mtmp
, int vb
)
276 static char buf
[BUFSZ
]; /* %% */
277 if (mtmp
->mnamelth
&& !vb
) {
278 (void) strlcpy(buf
, NAME(mtmp
), sizeof(buf
));
281 switch (mtmp
->data
->mlet
) {
284 const char *gn
= (char *) mtmp
->mextra
;
285 if (!*gn
) { /* might also look in scorefile */
286 gn
= ghostnames
[rn2(SIZE(ghostnames
))];
289 strlcpy((char *) mtmp
->mextra
, !rn2(5) ? plname
: gn
, mtmp
->mxlth
);
291 (void) snprintf(buf
, sizeof(buf
), "%s's ghost", gn
);
296 (void) strlcpy(buf
, shkname(mtmp
), sizeof(buf
));
301 (void) snprintf(buf
, sizeof(buf
), "the %s%s",
302 mtmp
->minvis
? "invisible " : "",
305 if (vb
&& mtmp
->mnamelth
) {
306 (void) strlcat(buf
, " called ", sizeof(buf
));
307 (void) strlcat(buf
, NAME(mtmp
), sizeof(buf
));
313 lmonnam(struct monst
*mtmp
)
315 return (xmonnam(mtmp
, 1));
319 monnam(struct monst
*mtmp
)
321 return (xmonnam(mtmp
, 0));
325 Monnam(struct monst
*mtmp
)
327 char *bp
= monnam(mtmp
);
328 if ('a' <= *bp
&& *bp
<= 'z')
334 amonnam(struct monst
*mtmp
, const char *adj
)
336 char *bp
= monnam(mtmp
);
337 static char buf
[BUFSZ
]; /* %% */
339 if (!strncmp(bp
, "the ", 4))
341 (void) snprintf(buf
, sizeof(buf
), "the %s %s", adj
, bp
);
346 Amonnam(struct monst
*mtmp
, const char *adj
)
348 char *bp
= amonnam(mtmp
, adj
);
355 Xmonnam(struct monst
*mtmp
)
357 char *bp
= Monnam(mtmp
);
358 if (!strncmp(bp
, "The ", 4)) {