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)
18 pline("(For instructions type a ?)");
22 while((c = readchar()) != '.'){
23 for(i=0; i<8; i++) if(sdir[i] == c){
24 if(1 <= cx + xdir[i] && cx + xdir[i] <= COLNO)
26 if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1)
31 pline("Use [hjkl] to move the cursor to %s.", goal);
32 pline("Type a . when you are at the right place.");
34 pline("Unknown direction: '%s' (%s).",
36 force ? "use hjkl or ." : "aborted");
56 struct monst *mtmp, *mtmp2;
57 cc = getpos(0, "the monster you want to name");
63 if(cx == u.ux && cy == u.uy)
64 pline("This ugly monster is called %s and cannot be renamed.",
67 pline("There is no monster there.");
71 pline("I see no monster there.");
75 pline("I cannot see a monster there.");
78 pline("What do you want to call %s? ", lmonnam(mtmp));
81 if(!*buf || *buf == '\033')
88 mtmp2 = newmonst(mtmp->mxlth + lth);
90 for(i=0; (unsigned)i<mtmp->mxlth; i++)
91 ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i];
92 mtmp2->mnamelth = lth;
93 strcpy(NAME(mtmp2), buf);
99 * This routine changes the address of obj . Be careful not to call it
100 * when there might be pointers around in unknown places. For now: only
101 * when obj is in the inventory.
104 do_oname(struct obj *obj)
106 struct obj *otmp, *otmp2;
109 pline("What do you want to name %s? ", doname(obj));
112 if(!*buf || *buf == '\033')
121 otmp2->onamelth = lth;
122 strcpy(ONAME(otmp2), buf);
124 setworn((struct obj *) 0, obj->owornmask);
125 setworn(otmp2, otmp2->owornmask);
127 /* do freeinv(obj); etc. by hand in order to preserve
128 the position of this object in the inventory */
129 if(obj == invent) invent = otmp2;
130 else for(otmp = invent; ; otmp = otmp->nobj){
132 panic("Do_oname: cannot find obj.");
133 if(otmp->nobj == obj){
138 /*obfree(obj, otmp2);*/ /* now unnecessary: no pointers on bill */
139 free((char *) obj); /* let us hope nobody else saved a pointer */
147 pline("Do you want to name an individual object? [ny] ");
152 obj = getobj("#", "name");
153 if(obj) do_oname(obj);
156 obj = getobj("?!=/", "call");
163 docall(struct obj *obj)
174 pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str);
177 if(!*buf || *buf == '\033')
179 str = newstring(strlen(buf)+1);
181 str1 = &(objects[obj->otyp].oc_uname);
182 if(*str1) free(*str1);
186 /* these names should have length < PL_NSIZ */
187 const char *ghostnames[] = {
188 "adri", "andries", "andreas", "bert", "david", "dirk", "emile",
189 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
190 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
195 xmonnam(struct monst *mtmp, int vb)
197 static char buf[BUFSZ]; /* %% */
198 if(mtmp->mnamelth && !vb) {
199 strcpy(buf, NAME(mtmp));
202 switch(mtmp->data->mlet) {
204 { const char *gn = (const char *)mtmp->mextra;
205 if(!*gn) { /* might also look in scorefile */
206 gn = ghostnames[rn2(SIZE(ghostnames))];
208 strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn);
210 sprintf(buf, "%s's ghost", gn);
215 strcpy(buf, shkname(mtmp));
218 /* fall into next case */
220 sprintf(buf, "the %s%s",
221 mtmp->minvis ? "invisible " : "",
224 if(vb && mtmp->mnamelth) {
225 strcat(buf, " called ");
226 strcat(buf, NAME(mtmp));
232 lmonnam(struct monst *mtmp)
234 return(xmonnam(mtmp, 1));
238 monnam(struct monst *mtmp)
240 return(xmonnam(mtmp, 0));
244 Monnam(struct monst *mtmp)
246 char *bp = monnam(mtmp);
247 if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a');
252 amonnam(struct monst *mtmp, const char *adj)
254 char *bp = monnam(mtmp);
255 static char buf[BUFSZ]; /* %% */
257 if(!strncmp(bp, "the ", 4)) bp += 4;
258 sprintf(buf, "the %s %s", adj, bp);
263 Amonnam(struct monst *mtmp, const char *adj)
265 char *bp = amonnam(mtmp,adj);
272 Xmonnam(struct monst *mtmp)
274 char *bp = Monnam(mtmp);
275 if(!strncmp(bp, "The ", 4)) {