do_name.c (6840B)
1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 2 /* do_name.c - version 1.0.3 */ 3 4 #include <stdio.h> 5 #include "hack.h" 6 extern char plname[]; 7 8 coord 9 getpos(force,goal) int force; char *goal; { 10 register cx,cy,i,c; 11 extern char sdir[]; /* defined in hack.c */ 12 extern schar xdir[], ydir[]; /* idem */ 13 extern char *visctrl(); /* see below */ 14 coord cc; 15 pline("(For instructions type a ?)"); 16 cx = u.ux; 17 cy = u.uy; 18 curs(cx,cy+2); 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) 22 cx += xdir[i]; 23 if(0 <= cy + ydir[i] && cy + ydir[i] <= ROWNO-1) 24 cy += ydir[i]; 25 goto nxtc; 26 } 27 if(c == '?'){ 28 pline("Use [hjkl] to move the cursor to %s.", goal); 29 pline("Type a . when you are at the right place."); 30 } else { 31 pline("Unknown direction: '%s' (%s).", 32 visctrl(c), 33 force ? "use hjkl or ." : "aborted"); 34 if(force) goto nxtc; 35 cc.x = -1; 36 cc.y = 0; 37 return(cc); 38 } 39 nxtc: ; 40 curs(cx,cy+2); 41 } 42 cc.x = cx; 43 cc.y = cy; 44 return(cc); 45 } 46 47 do_mname(){ 48 char buf[BUFSZ]; 49 coord cc; 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"); 54 cx = cc.x; 55 cy = cc.y; 56 if(cx < 0) return(0); 57 #ifdef DGK 58 if (cx == u.ux && cy == u.uy) { 59 pline("This ugly monster is called %s and cannot be renamed.", 60 plname); 61 return 1; 62 } 63 if (!cansee(cx, cy) || !(mtmp = m_at(cx, cy)) || mtmp->mimic) { 64 pline("I see no monster there."); 65 return 1; 66 } 67 #else 68 mtmp = m_at(cx,cy); 69 if(!mtmp){ 70 if(cx == u.ux && cy == u.uy) 71 pline("This ugly monster is called %s and cannot be renamed.", 72 plname); 73 else 74 pline("There is no monster there."); 75 return(1); 76 } 77 if(mtmp->mimic){ 78 pline("I see no monster there."); 79 return(1); 80 } 81 if(!cansee(cx,cy)) { 82 pline("I cannot see a monster there."); 83 return(1); 84 } 85 #endif 86 pline("What do you want to call %s? ", lmonnam(mtmp)); 87 getlin(buf); 88 clrlin(); 89 if(!*buf || *buf == '\033') 90 return(1); 91 lth = strlen(buf)+1; 92 if(lth > 63){ 93 buf[62] = 0; 94 lth = 63; 95 } 96 mtmp2 = newmonst(mtmp->mxlth + lth); 97 *mtmp2 = *mtmp; 98 for(i=0; i<mtmp->mxlth; i++) 99 ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i]; 100 mtmp2->mnamelth = lth; 101 (void) strcpy(NAME(mtmp2), buf); 102 replmon(mtmp,mtmp2); 103 return(0); 104 } 105 106 /* 107 * This routine changes the address of obj . Be careful not to call it 108 * when there might be pointers around in unknown places. For now: only 109 * when obj is in the inventory. 110 */ 111 do_oname(obj) register struct obj *obj; { 112 register struct obj *otmp, *otmp2; 113 register lth; 114 char buf[BUFSZ]; 115 pline("What do you want to name %s? ", doname(obj)); 116 getlin(buf); 117 clrlin(); 118 if(!*buf || *buf == '\033') 119 return; 120 lth = strlen(buf)+1; 121 if(lth > 63){ 122 buf[62] = 0; 123 lth = 63; 124 } 125 otmp2 = newobj(lth); 126 *otmp2 = *obj; 127 otmp2->onamelth = lth; 128 (void) strcpy(ONAME(otmp2), buf); 129 130 setworn((struct obj *) 0, obj->owornmask); 131 setworn(otmp2, otmp2->owornmask); 132 133 /* do freeinv(obj); etc. by hand in order to preserve 134 the position of this object in the inventory */ 135 if(obj == invent) invent = otmp2; 136 else for(otmp = invent; ; otmp = otmp->nobj){ 137 if(!otmp) 138 panic("Do_oname: cannot find obj."); 139 if(otmp->nobj == obj){ 140 otmp->nobj = otmp2; 141 break; 142 } 143 } 144 /* obfree(obj, otmp2); /* now unnecessary: no pointers on bill */ 145 free((char *) obj); /* let us hope nobody else saved a pointer */ 146 } 147 148 ddocall() 149 { 150 register struct obj *obj; 151 char ch; 152 153 #ifdef REDO 154 if (!in_doagain) 155 #endif 156 pline("Do you want to name an individual object? [ny] "); 157 switch(ch = readchar()) { 158 case '\033': 159 break; 160 case 'y': 161 #ifdef REDO 162 savech(ch); 163 #endif 164 obj = getobj("#", "name"); 165 if(obj) do_oname(obj); 166 break; 167 default: 168 #ifdef REDO 169 savech(ch); 170 #endif 171 obj = getobj("?!=/", "call"); 172 if(obj) docall(obj); 173 } 174 return(0); 175 } 176 177 docall(obj) 178 register struct obj *obj; 179 { 180 char buf[BUFSZ]; 181 struct obj otemp; 182 register char **str1; 183 extern char *xname(); 184 register char *str; 185 186 otemp = *obj; 187 otemp.quan = 1; 188 otemp.onamelth = 0; 189 str = xname(&otemp); 190 pline("Call %s %s: ", index(vowels,*str) ? "an" : "a", str); 191 getlin(buf); 192 clrlin(); 193 if(!*buf || *buf == '\033') 194 return; 195 str = newstring(strlen(buf)+1); 196 (void) strcpy(str,buf); 197 str1 = &(objects[obj->otyp].oc_uname); 198 if(*str1) free(*str1); 199 *str1 = str; 200 } 201 202 char *ghostnames[] = { /* these names should have length < PL_NSIZ */ 203 #ifdef DGK 204 /* Capitalize the names for asthetics -dgk 205 */ 206 "Adri", "Andries", "Andreas", "Bert", "David", "Dirk", "Emile", 207 "Frans", "Fred", "Greg", "Hether", "Jay", "John", "Jon", "Kay", 208 "Kenny", "Maud", "Michiel", "Mike", "Peter", "Robert", "Ron", 209 "Tom", "Wilmar", "Nick Danger" 210 #else 211 "adri", "andries", "andreas", "bert", "david", "dirk", "emile", 212 "frans", "fred", "greg", "hether", "jay", "john", "jon", "kay", 213 "kenny", "maud", "michiel", "mike", "peter", "robert", "ron", 214 "tom", "wilmar" 215 #endif 216 }; 217 218 char * 219 xmonnam(mtmp, vb) register struct monst *mtmp; int vb; { 220 static char buf[BUFSZ]; /* %% */ 221 extern char *shkname(); 222 if(mtmp->mnamelth && !vb) { 223 (void) strcpy(buf, NAME(mtmp)); 224 return(buf); 225 } 226 switch(mtmp->data->mlet) { 227 case ' ': 228 { register char *gn = (char *) mtmp->mextra; 229 if(!*gn) { /* might also look in scorefile */ 230 gn = ghostnames[rn2(SIZE(ghostnames))]; 231 if(!rn2(2)) (void) 232 strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn); 233 } 234 (void) sprintf(buf, "%s's ghost", gn); 235 } 236 break; 237 case '@': 238 if(mtmp->isshk) { 239 (void) strcpy(buf, shkname(mtmp)); 240 break; 241 } 242 /* fall into next case */ 243 default: 244 (void) sprintf(buf, "the %s%s", 245 mtmp->minvis ? "invisible " : "", 246 mtmp->data->mname); 247 } 248 if(vb && mtmp->mnamelth) { 249 (void) strcat(buf, " called "); 250 (void) strcat(buf, NAME(mtmp)); 251 } 252 return(buf); 253 } 254 255 char * 256 lmonnam(mtmp) register struct monst *mtmp; { 257 return(xmonnam(mtmp, 1)); 258 } 259 260 char * 261 monnam(mtmp) register struct monst *mtmp; { 262 return(xmonnam(mtmp, 0)); 263 } 264 265 char * 266 Monnam(mtmp) register struct monst *mtmp; { 267 register char *bp = monnam(mtmp); 268 if('a' <= *bp && *bp <= 'z') *bp += ('A' - 'a'); 269 return(bp); 270 } 271 272 char * 273 amonnam(mtmp,adj) 274 register struct monst *mtmp; 275 register char *adj; 276 { 277 register char *bp = monnam(mtmp); 278 static char buf[BUFSZ]; /* %% */ 279 280 if(!strncmp(bp, "the ", 4)) bp += 4; 281 (void) sprintf(buf, "the %s %s", adj, bp); 282 return(buf); 283 } 284 285 char * 286 Amonnam(mtmp, adj) 287 register struct monst *mtmp; 288 register char *adj; 289 { 290 register char *bp = amonnam(mtmp,adj); 291 292 *bp = 'T'; 293 return(bp); 294 } 295 296 char * 297 Xmonnam(mtmp) register struct monst *mtmp; { 298 register char *bp = Monnam(mtmp); 299 if(!strncmp(bp, "The ", 4)) { 300 bp += 2; 301 *bp = 'A'; 302 } 303 return(bp); 304 } 305 306 char * 307 visctrl(c) 308 char c; 309 { 310 static char ccc[3]; 311 if(c < 040) { 312 ccc[0] = '^'; 313 ccc[1] = c + 0100; 314 ccc[2] = 0; 315 } else { 316 ccc[0] = c; 317 ccc[1] = 0; 318 } 319 return(ccc); 320 }