1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.do_name.c - version 1.0.3 */
9 getpos(force,goal) int force; char *goal; {
11 extern char sdir[]; /* defined in hack.c */
12 extern schar xdir[], ydir[]; /* idem */
13 extern char *visctrl(); /* see below */
15 pline("(For instructions type a ?)");
19 while((c = readchar()) != '.'){
20 for(i=0; i<8; i++) if(sdir[i] == c){
21 if(1 <= cx + xdir[i] && cx + xdir[i] <= COLNO)
23 if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1)
28 pline("Use [hjkl] to move the cursor to %s.", goal);
29 pline("Type a . when you are at the right place.");
31 pline("Unknown direction: '%s' (%s).",
33 force ? "use hjkl or ." : "aborted");
50 register int cx,cy,lth,i;
51 register struct monst *mtmp, *mtmp2;
52 extern char *lmonnam();
53 cc = getpos(0, "the monster you want to name");
59 if(cx == u.ux && cy == u.uy)
60 pline("This ugly monster is called %s and cannot be renamed.",
63 pline("There is no monster there.");
67 pline("I see no monster there.");
71 pline("I cannot see a monster there.");
74 pline("What do you want to call %s? ", lmonnam(mtmp));
77 if(!*buf || *buf == '\033')
84 mtmp2 = newmonst(mtmp->mxlth + lth);
86 for(i=0; i<mtmp->mxlth; i++)
87 ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i];
88 mtmp2->mnamelth = lth;
89 (void) strcpy(NAME(mtmp2), buf);
95 * This routine changes the address of obj . Be careful not to call it
96 * when there might be pointers around in unknown places. For now: only
97 * when obj is in the inventory.
99 do_oname(obj) register struct obj *obj; {
100 register struct obj *otmp, *otmp2;
103 pline("What do you want to name %s? ", doname(obj));
106 if(!*buf || *buf == '\033')
115 otmp2->onamelth = lth;
116 (void) strcpy(ONAME(otmp2), buf);
118 setworn((struct obj *) 0, obj->owornmask);
119 setworn(otmp2, otmp2->owornmask);
121 /* do freeinv(obj); etc. by hand in order to preserve
122 the position of this object in the inventory */
123 if(obj == invent) invent = otmp2;
124 else for(otmp = invent; ; otmp = otmp->nobj){
126 panic("Do_oname: cannot find obj.");
127 if(otmp->nobj == obj){
132 /*obfree(obj, otmp2);*/ /* now unnecessary: no pointers on bill */
133 free((char *) obj); /* let us hope nobody else saved a pointer */
138 register struct obj *obj;
140 pline("Do you want to name an individual object? [ny] ");
145 obj = getobj("#", "name");
146 if(obj) do_oname(obj);
149 obj = getobj("?!=/", "call");
156 register struct obj *obj;
160 register char **str1;
161 extern char *xname();
168 pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str);
171 if(!*buf || *buf == '\033')
173 str = newstring(strlen(buf)+1);
174 (void) strcpy(str,buf);
175 str1 = &(objects[obj->otyp].oc_uname);
176 if(*str1) free(*str1);
180 char *ghostnames[] = { /* these names should have length < PL_NSIZ */
181 "adri", "andries", "andreas", "bert", "david", "dirk", "emile",
182 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay",
183 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron",
188 xmonnam(mtmp, vb) register struct monst *mtmp; int vb; {
189 static char buf[BUFSZ]; /* %% */
190 extern char *shkname();
191 if(mtmp->mnamelth && !vb) {
192 (void) strcpy(buf, NAME(mtmp));
195 switch(mtmp->data->mlet) {
197 { register char *gn = (char *) mtmp->mextra;
198 if(!*gn) { /* might also look in scorefile */
199 gn = ghostnames[rn2(SIZE(ghostnames))];
201 strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn);
203 (void) sprintf(buf, "%s's ghost", gn);
208 (void) strcpy(buf, shkname(mtmp));
211 /* fall into next case */
213 (void) sprintf(buf, "the %s%s",
214 mtmp->minvis ? "invisible " : "",
217 if(vb && mtmp->mnamelth) {
218 (void) strcat(buf, " called ");
219 (void) strcat(buf, NAME(mtmp));
225 lmonnam(mtmp) register struct monst *mtmp; {
226 return(xmonnam(mtmp, 1));
230 monnam(mtmp) register struct monst *mtmp; {
231 return(xmonnam(mtmp, 0));
235 Monnam(mtmp) register struct monst *mtmp; {
236 register char *bp = monnam(mtmp);
237 if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a');
243 register struct monst *mtmp;
246 register char *bp = monnam(mtmp);
247 static char buf[BUFSZ]; /* %% */
249 if(!strncmp(bp, "the ", 4)) bp += 4;
250 (void) sprintf(buf, "the %s %s", adj, bp);
256 register struct monst *mtmp;
259 register char *bp = amonnam(mtmp,adj);
266 Xmonnam(mtmp) register struct monst *mtmp; {
267 register char *bp = Monnam(mtmp);
268 if(!strncmp(bp, "The ", 4)) {