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 $ */
7 static void do_oname(struct obj
*);
8 static char *xmonnam(struct monst
*, int);
9 static char *lmonnam(struct monst
*);
10 static char *visctrl(char);
13 getpos(int force
, const char *goal
)
18 pline("(For instructions type a ?)");
22 while ((c
= readchar()) != '.') {
23 for (i
= 0; i
< 8; i
++)
25 if (1 <= cx
+ xdir
[i
] && cx
+ xdir
[i
] <= COLNO
)
27 if (0 <= cy
+ ydir
[i
] && cy
+ ydir
[i
] <= ROWNO
- 1)
32 pline("Use [hjkl] to move the cursor to %s.", goal
);
33 pline("Type a . when you are at the right place.");
35 pline("Unknown direction: '%s' (%s).",
37 force
? "use hjkl or ." : "aborted");
58 struct monst
*mtmp
, *mtmp2
;
60 cc
= getpos(0, "the monster you want to name");
67 if (cx
== u
.ux
&& cy
== u
.uy
)
68 pline("This ugly monster is called %s and cannot be renamed.",
71 pline("There is no monster there.");
75 pline("I see no monster there.");
78 if (!cansee(cx
, cy
)) {
79 pline("I cannot see a monster there.");
82 pline("What do you want to call %s? ", lmonnam(mtmp
));
85 if (!*buf
|| *buf
== '\033')
87 lth
= strlen(buf
) + 1;
92 mtmp2
= newmonst(mtmp
->mxlth
+ lth
);
94 for (i
= 0; (unsigned)i
< mtmp
->mxlth
; i
++)
95 ((char *)mtmp2
->mextra
)[i
] = ((char *)mtmp
->mextra
)[i
];
96 mtmp2
->mnamelth
= lth
;
97 strcpy(NAME(mtmp2
), buf
);
103 * This routine changes the address of obj . Be careful not to call it
104 * when there might be pointers around in unknown places. For now: only
105 * when obj is in the inventory.
108 do_oname(struct obj
*obj
)
110 struct obj
*otmp
, *otmp2
;
114 pline("What do you want to name %s? ", doname(obj
));
117 if (!*buf
|| *buf
== '\033')
119 lth
= strlen(buf
) + 1;
126 otmp2
->onamelth
= lth
;
127 strcpy(ONAME(otmp2
), buf
);
129 setworn(NULL
, obj
->owornmask
);
130 setworn(otmp2
, otmp2
->owornmask
);
133 * do freeinv(obj); etc. by hand in order to preserve the position of
134 * this object in the inventory
139 for (otmp
= invent
;; otmp
= otmp
->nobj
) {
141 panic("Do_oname: cannot find obj.");
142 if (otmp
->nobj
== obj
) {
147 /*obfree(obj, otmp2);*/ /* now unnecessary: no pointers on bill */
148 free(obj
); /* let us hope nobody else saved a pointer */
156 pline("Do you want to name an individual object? [ny] ");
157 switch (readchar()) {
161 obj
= getobj("#", "name");
166 obj
= getobj("?!=/", "call");
174 docall(struct obj
*obj
)
185 pline("Call %s %s: ", strchr(vowels
, *str
) ? "an" : "a", str
);
188 if (!*buf
|| *buf
== '\033')
190 str
= newstring(strlen(buf
) + 1);
192 str1
= &(objects
[obj
->otyp
].oc_uname
);
198 /* these names should have length < PL_NSIZ */
199 const char *ghostnames
[] = {
200 "adri", "andries", "andreas", "bert", "david", "dirk", "emile",
201 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
202 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
207 xmonnam(struct monst
*mtmp
, int vb
)
209 static char buf
[BUFSZ
]; /* %% */
211 if (mtmp
->mnamelth
&& !vb
) {
212 strcpy(buf
, NAME(mtmp
));
215 switch (mtmp
->data
->mlet
) {
218 const char *gn
= (const char *)mtmp
->mextra
;
219 if (!*gn
) { /* might also look in scorefile */
220 gn
= ghostnames
[rn2(SIZE(ghostnames
))];
222 strcpy((char *)mtmp
->mextra
,
223 !rn2(5) ? plname
: gn
);
225 sprintf(buf
, "%s's ghost", gn
);
230 strcpy(buf
, shkname(mtmp
));
235 sprintf(buf
, "the %s%s",
236 mtmp
->minvis
? "invisible " : "",
239 if (vb
&& mtmp
->mnamelth
) {
240 strcat(buf
, " called ");
241 strcat(buf
, NAME(mtmp
));
247 lmonnam(struct monst
*mtmp
)
249 return (xmonnam(mtmp
, 1));
253 monnam(struct monst
*mtmp
)
255 return (xmonnam(mtmp
, 0));
259 Monnam(struct monst
*mtmp
)
261 char *bp
= monnam(mtmp
);
263 if ('a' <= *bp
&& *bp
<= 'z')
269 amonnam(struct monst
*mtmp
, const char *adj
)
271 char *bp
= monnam(mtmp
);
272 static char buf
[BUFSZ
]; /* %% */
274 if (!strncmp(bp
, "the ", 4))
276 sprintf(buf
, "the %s %s", adj
, bp
);
281 Amonnam(struct monst
*mtmp
, const char *adj
)
283 char *bp
= amonnam(mtmp
, adj
);
290 Xmonnam(struct monst
*mtmp
)
292 char *bp
= Monnam(mtmp
);
294 if (!strncmp(bp
, "The ", 4)) {