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.2 2003/06/17 04:25:24 dillon Exp $ */
11 getpos(force,goal) int force; char *goal; {
13 extern char sdir[]; /* defined in hack.c */
14 extern schar xdir[], ydir[]; /* idem */
15 extern char *visctrl(); /* see below */
17 pline("(For instructions type a ?)");
21 while((c = readchar()) != '.'){
22 for(i=0; i<8; i++) if(sdir[i] == c){
23 if(1 <= cx + xdir[i] && cx + xdir[i] <= COLNO)
25 if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1)
30 pline("Use [hjkl] to move the cursor to %s.", goal);
31 pline("Type a . when you are at the right place.");
33 pline("Unknown direction: '%s' (%s).",
35 force ? "use hjkl or ." : "aborted");
53 struct monst *mtmp, *mtmp2;
54 extern char *lmonnam();
55 cc = getpos(0, "the monster you want to name");
61 if(cx == u.ux && cy == u.uy)
62 pline("This ugly monster is called %s and cannot be renamed.",
65 pline("There is no monster there.");
69 pline("I see no monster there.");
73 pline("I cannot see a monster there.");
76 pline("What do you want to call %s? ", lmonnam(mtmp));
79 if(!*buf || *buf == '\033')
86 mtmp2 = newmonst(mtmp->mxlth + lth);
88 for(i=0; i<mtmp->mxlth; i++)
89 ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i];
90 mtmp2->mnamelth = lth;
91 (void) strcpy(NAME(mtmp2), buf);
97 * This routine changes the address of obj . Be careful not to call it
98 * when there might be pointers around in unknown places. For now: only
99 * when obj is in the inventory.
101 do_oname(obj) struct obj *obj; {
102 struct obj *otmp, *otmp2;
105 pline("What do you want to name %s? ", doname(obj));
108 if(!*buf || *buf == '\033')
117 otmp2->onamelth = lth;
118 (void) strcpy(ONAME(otmp2), buf);
120 setworn((struct obj *) 0, obj->owornmask);
121 setworn(otmp2, otmp2->owornmask);
123 /* do freeinv(obj); etc. by hand in order to preserve
124 the position of this object in the inventory */
125 if(obj == invent) invent = otmp2;
126 else for(otmp = invent; ; otmp = otmp->nobj){
128 panic("Do_oname: cannot find obj.");
129 if(otmp->nobj == obj){
134 /*obfree(obj, otmp2);*/ /* now unnecessary: no pointers on bill */
135 free((char *) obj); /* let us hope nobody else saved a pointer */
142 pline("Do you want to name an individual object? [ny] ");
147 obj = getobj("#", "name");
148 if(obj) do_oname(obj);
151 obj = getobj("?!=/", "call");
163 extern char *xname();
170 pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str);
173 if(!*buf || *buf == '\033')
175 str = newstring(strlen(buf)+1);
176 (void) strcpy(str,buf);
177 str1 = &(objects[obj->otyp].oc_uname);
178 if(*str1) free(*str1);
182 char *ghostnames[] = { /* these names should have length < PL_NSIZ */
183 "adri", "andries", "andreas", "bert", "david", "dirk", "emile",
184 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
185 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
190 xmonnam(mtmp, vb) struct monst *mtmp; int vb; {
191 static char buf[BUFSZ]; /* %% */
192 extern char *shkname();
193 if(mtmp->mnamelth && !vb) {
194 (void) strcpy(buf, NAME(mtmp));
197 switch(mtmp->data->mlet) {
199 { char *gn = (char *) mtmp->mextra;
200 if(!*gn) { /* might also look in scorefile */
201 gn = ghostnames[rn2(SIZE(ghostnames))];
203 strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn);
205 (void) sprintf(buf, "%s's ghost", gn);
210 (void) strcpy(buf, shkname(mtmp));
213 /* fall into next case */
215 (void) sprintf(buf, "the %s%s",
216 mtmp->minvis ? "invisible " : "",
219 if(vb && mtmp->mnamelth) {
220 (void) strcat(buf, " called ");
221 (void) strcat(buf, NAME(mtmp));
227 lmonnam(mtmp) struct monst *mtmp; {
228 return(xmonnam(mtmp, 1));
232 monnam(mtmp) struct monst *mtmp; {
233 return(xmonnam(mtmp, 0));
237 Monnam(mtmp) struct monst *mtmp; {
238 char *bp = monnam(mtmp);
239 if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a');
248 char *bp = monnam(mtmp);
249 static char buf[BUFSZ]; /* %% */
251 if(!strncmp(bp, "the ", 4)) bp += 4;
252 (void) sprintf(buf, "the %s %s", adj, bp);
261 char *bp = amonnam(mtmp,adj);
268 Xmonnam(mtmp) struct monst *mtmp; {
269 char *bp = Monnam(mtmp);
270 if(!strncmp(bp, "The ", 4)) {