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 $ */
10 getpos(force,goal) int force; char *goal; {
12 extern char sdir[]; /* defined in hack.c */
13 extern schar xdir[], ydir[]; /* idem */
14 extern char *visctrl(); /* see below */
16 pline("(For instructions type a ?)");
20 while((c = readchar()) != '.'){
21 for(i=0; i<8; i++) if(sdir[i] == c){
22 if(1 <= cx + xdir[i] && cx + xdir[i] <= COLNO)
24 if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1)
29 pline("Use [hjkl] to move the cursor to %s.", goal);
30 pline("Type a . when you are at the right place.");
32 pline("Unknown direction: '%s' (%s).",
34 force ? "use hjkl or ." : "aborted");
52 struct monst *mtmp, *mtmp2;
53 extern char *lmonnam();
54 cc = getpos(0, "the monster you want to name");
60 if(cx == u.ux && cy == u.uy)
61 pline("This ugly monster is called %s and cannot be renamed.",
64 pline("There is no monster there.");
68 pline("I see no monster there.");
72 pline("I cannot see a monster there.");
75 pline("What do you want to call %s? ", lmonnam(mtmp));
78 if(!*buf || *buf == '\033')
85 mtmp2 = newmonst(mtmp->mxlth + lth);
87 for(i=0; i<mtmp->mxlth; i++)
88 ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i];
89 mtmp2->mnamelth = lth;
90 (void) strcpy(NAME(mtmp2), buf);
96 * This routine changes the address of obj . Be careful not to call it
97 * when there might be pointers around in unknown places. For now: only
98 * when obj is in the inventory.
100 do_oname(obj) struct obj *obj; {
101 struct obj *otmp, *otmp2;
104 pline("What do you want to name %s? ", doname(obj));
107 if(!*buf || *buf == '\033')
116 otmp2->onamelth = lth;
117 (void) strcpy(ONAME(otmp2), buf);
119 setworn((struct obj *) 0, obj->owornmask);
120 setworn(otmp2, otmp2->owornmask);
122 /* do freeinv(obj); etc. by hand in order to preserve
123 the position of this object in the inventory */
124 if(obj == invent) invent = otmp2;
125 else for(otmp = invent; ; otmp = otmp->nobj){
127 panic("Do_oname: cannot find obj.");
128 if(otmp->nobj == obj){
133 /*obfree(obj, otmp2);*/ /* now unnecessary: no pointers on bill */
134 free((char *) obj); /* let us hope nobody else saved a pointer */
141 pline("Do you want to name an individual object? [ny] ");
146 obj = getobj("#", "name");
147 if(obj) do_oname(obj);
150 obj = getobj("?!=/", "call");
162 extern char *xname();
169 pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str);
172 if(!*buf || *buf == '\033')
174 str = newstring(strlen(buf)+1);
175 (void) strcpy(str,buf);
176 str1 = &(objects[obj->otyp].oc_uname);
177 if(*str1) free(*str1);
181 char *ghostnames[] = { /* these names should have length < PL_NSIZ */
182 "adri", "andries", "andreas", "bert", "david", "dirk", "emile",
183 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
184 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
189 xmonnam(mtmp, vb) struct monst *mtmp; int vb; {
190 static char buf[BUFSZ]; /* %% */
191 extern char *shkname();
192 if(mtmp->mnamelth && !vb) {
193 (void) strcpy(buf, NAME(mtmp));
196 switch(mtmp->data->mlet) {
198 { char *gn = (char *) mtmp->mextra;
199 if(!*gn) { /* might also look in scorefile */
200 gn = ghostnames[rn2(SIZE(ghostnames))];
202 strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn);
204 (void) sprintf(buf, "%s's ghost", gn);
209 (void) strcpy(buf, shkname(mtmp));
212 /* fall into next case */
214 (void) sprintf(buf, "the %s%s",
215 mtmp->minvis ? "invisible " : "",
218 if(vb && mtmp->mnamelth) {
219 (void) strcat(buf, " called ");
220 (void) strcat(buf, NAME(mtmp));
226 lmonnam(mtmp) struct monst *mtmp; {
227 return(xmonnam(mtmp, 1));
231 monnam(mtmp) struct monst *mtmp; {
232 return(xmonnam(mtmp, 0));
236 Monnam(mtmp) struct monst *mtmp; {
237 char *bp = monnam(mtmp);
238 if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a');
247 char *bp = monnam(mtmp);
248 static char buf[BUFSZ]; /* %% */
250 if(!strncmp(bp, "the ", 4)) bp += 4;
251 (void) sprintf(buf, "the %s %s", adj, bp);
260 char *bp = amonnam(mtmp,adj);
267 Xmonnam(mtmp) struct monst *mtmp; {
268 char *bp = Monnam(mtmp);
269 if(!strncmp(bp, "The ", 4)) {