1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.do_name.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.do_name.c,v 1.5 1999/11/16 10:26:36 marcel Exp $ */
4 /* $DragonFly: src/games/hack/hack.do_name.c,v 1.4 2006/08/21 19:45:32 pavalos Exp $ */
8 static void do_oname(struct obj
*);
9 static char *xmonnam(struct monst
*, int);
10 static char *lmonnam(struct monst
*);
11 static char *visctrl(char);
14 getpos(int force
, const char *goal
)
19 pline("(For instructions type a ?)");
23 while ((c
= readchar()) != '.') {
24 for (i
= 0; i
< 8; i
++)
26 if (1 <= cx
+ xdir
[i
] && cx
+ xdir
[i
] <= COLNO
)
28 if (0 <= cy
+ ydir
[i
] && cy
+ ydir
[i
] <= ROWNO
- 1)
33 pline("Use [hjkl] to move the cursor to %s.", goal
);
34 pline("Type a . when you are at the right place.");
36 pline("Unknown direction: '%s' (%s).",
38 force
? "use hjkl or ." : "aborted");
59 struct monst
*mtmp
, *mtmp2
;
61 cc
= getpos(0, "the monster you want to name");
68 if (cx
== u
.ux
&& cy
== u
.uy
)
69 pline("This ugly monster is called %s and cannot be renamed.",
72 pline("There is no monster there.");
76 pline("I see no monster there.");
79 if (!cansee(cx
, cy
)) {
80 pline("I cannot see a monster there.");
83 pline("What do you want to call %s? ", lmonnam(mtmp
));
86 if (!*buf
|| *buf
== '\033')
88 lth
= strlen(buf
) + 1;
93 mtmp2
= newmonst(mtmp
->mxlth
+ lth
);
95 for (i
= 0; (unsigned)i
< mtmp
->mxlth
; i
++)
96 ((char *)mtmp2
->mextra
)[i
] = ((char *)mtmp
->mextra
)[i
];
97 mtmp2
->mnamelth
= lth
;
98 strcpy(NAME(mtmp2
), buf
);
104 * This routine changes the address of obj . Be careful not to call it
105 * when there might be pointers around in unknown places. For now: only
106 * when obj is in the inventory.
109 do_oname(struct obj
*obj
)
111 struct obj
*otmp
, *otmp2
;
115 pline("What do you want to name %s? ", doname(obj
));
118 if (!*buf
|| *buf
== '\033')
120 lth
= strlen(buf
) + 1;
127 otmp2
->onamelth
= lth
;
128 strcpy(ONAME(otmp2
), buf
);
130 setworn(NULL
, obj
->owornmask
);
131 setworn(otmp2
, otmp2
->owornmask
);
134 * do freeinv(obj); etc. by hand in order to preserve the position of
135 * this object in the inventory
140 for (otmp
= invent
;; otmp
= otmp
->nobj
) {
142 panic("Do_oname: cannot find obj.");
143 if (otmp
->nobj
== obj
) {
148 /*obfree(obj, otmp2);*/ /* now unnecessary: no pointers on bill */
149 free(obj
); /* let us hope nobody else saved a pointer */
157 pline("Do you want to name an individual object? [ny] ");
158 switch (readchar()) {
162 obj
= getobj("#", "name");
167 obj
= getobj("?!=/", "call");
175 docall(struct obj
*obj
)
186 pline("Call %s %s: ", strchr(vowels
, *str
) ? "an" : "a", str
);
189 if (!*buf
|| *buf
== '\033')
191 str
= newstring(strlen(buf
) + 1);
193 str1
= &(objects
[obj
->otyp
].oc_uname
);
199 /* these names should have length < PL_NSIZ */
200 const char *ghostnames
[] = {
201 "adri", "andries", "andreas", "bert", "david", "dirk", "emile",
202 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
203 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
208 xmonnam(struct monst
*mtmp
, int vb
)
210 static char buf
[BUFSZ
]; /* %% */
212 if (mtmp
->mnamelth
&& !vb
) {
213 strcpy(buf
, NAME(mtmp
));
216 switch (mtmp
->data
->mlet
) {
219 const char *gn
= (const char *)mtmp
->mextra
;
220 if (!*gn
) { /* might also look in scorefile */
221 gn
= ghostnames
[rn2(SIZE(ghostnames
))];
223 strcpy((char *)mtmp
->mextra
,
224 !rn2(5) ? plname
: gn
);
226 sprintf(buf
, "%s's ghost", gn
);
231 strcpy(buf
, shkname(mtmp
));
234 /* fall into next case */
236 sprintf(buf
, "the %s%s",
237 mtmp
->minvis
? "invisible " : "",
240 if (vb
&& mtmp
->mnamelth
) {
241 strcat(buf
, " called ");
242 strcat(buf
, NAME(mtmp
));
248 lmonnam(struct monst
*mtmp
)
250 return (xmonnam(mtmp
, 1));
254 monnam(struct monst
*mtmp
)
256 return (xmonnam(mtmp
, 0));
260 Monnam(struct monst
*mtmp
)
262 char *bp
= monnam(mtmp
);
264 if ('a' <= *bp
&& *bp
<= 'z')
270 amonnam(struct monst
*mtmp
, const char *adj
)
272 char *bp
= monnam(mtmp
);
273 static char buf
[BUFSZ
]; /* %% */
275 if (!strncmp(bp
, "the ", 4))
277 sprintf(buf
, "the %s %s", adj
, bp
);
282 Amonnam(struct monst
*mtmp
, const char *adj
)
284 char *bp
= amonnam(mtmp
, adj
);
291 Xmonnam(struct monst
*mtmp
)
293 char *bp
= Monnam(mtmp
);
295 if (!strncmp(bp
, "The ", 4)) {