Source:NetHack 3.4.0/do name.c

Below is the full text to do_name.c from the source code of NetHack 3.4.0. To link to a particular line, write [[NetHack 3.4.0/do_name.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)do_name.c	3.4	2002/01/17	*/ 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6. 7.   #ifdef OVLB 8.    9.    STATIC_DCL void FDECL(do_oname, (struct obj *)); 10.  static void FDECL(getpos_help, (BOOLEAN_P,const char *)); 11.   12.   extern const char what_is_an_unknown_object[];		/* from pager.c */ 13.   14.   /* the response for '?' help request in getpos */ 15.  static void 16.  getpos_help(force, goal) 17.  boolean force; 18.  const char *goal; 19.  {  20.       char sbuf[BUFSZ]; 21.      boolean doing_what_is; 22.      winid tmpwin = create_nhwindow(NHW_MENU); 23.   24.       Sprintf(sbuf, "Use [%s] to move the cursor to %s.",  25.   	    iflags.num_pad ? "2468" : "hjkl", goal); 26.      putstr(tmpwin, 0, sbuf); 27.      putstr(tmpwin, 0, "Use [HJKL] to move the cursor 8 units at a time."); 28.      putstr(tmpwin, 0, "Or enter a background symbol (ex. <)."); 29.      /* disgusting hack; the alternate selection characters work for any 30.         getpos call, but they only matter for dowhatis (and doquickwhatis) */ 31.      doing_what_is = (goal == what_is_an_unknown_object); 32.      Sprintf(sbuf, "Type a .%s when you are at the right place.",  33.               doing_what_is ? " or, or ; or :" : ""); 34.      putstr(tmpwin, 0, sbuf); 35.      if (!force) 36.  	putstr(tmpwin, 0, "Type Space or Escape when you're done."); 37.      putstr(tmpwin, 0, ""); 38.      display_nhwindow(tmpwin, TRUE); 39.      destroy_nhwindow(tmpwin); 40.  }  41.    42.   int 43.  getpos(cc, force, goal) 44.  coord *cc; 45.  boolean force; 46.  const char *goal; 47.  {  48.       int result = 0; 49.      int cx, cy, i, c;  50. int sidx, tx, ty; 51.      boolean msg_given = TRUE;	/* clear message window by default */ 52.      static const char *pick_chars = ".,;:"; 53.      const char *cp; 54.      const char *sdp; 55.      if(iflags.num_pad) sdp = ndir; else sdp = sdir;	/* DICE workaround */ 56.   57.       if (flags.verbose) { 58.  	pline("(For instructions type a ?)"); 59.  	msg_given = TRUE; 60.      }  61.       cx = cc->x; 62.      cy = cc->y; 63.  #ifdef CLIPPING 64.      cliparound(cx, cy); 65.  #endif 66.      curs(WIN_MAP, cx,cy); 67.      flush_screen(0); 68.  #ifdef MAC 69.      lock_mouse_cursor(TRUE); 70.  #endif 71.      for  { 72.  	c = nh_poskey(&tx, &ty, &sidx); 73.  	if (c == '\033') { 74.  	    cx = cy = -10; 75.  	    msg_given = TRUE;	/* force clear */ 76.  	    result = -1; 77.  	    break; 78.  	}  79.   	if(c == 0) { 80.  	    if (!isok(tx, ty)) continue; 81.  	    /* a mouse click event, just assign and return */ 82.  	    cx = tx; 83.  	    cy = ty; 84.  	    break; 85.  	}  86.   	if ((cp = index(pick_chars, c)) != 0) { 87.  	    /* '.' => 0, ',' => 1, ';' => 2, ':' => 3 */  88.   	    result = cp - pick_chars; 89.  	    break; 90.  	}  91.   	for (i = 0; i < 8; i++) { 92.  	    int dx, dy; 93.   94.   	    if (sdp[i] == c) { 95.  		/* a normal movement letter or digit */ 96.  		dx = xdir[i]; 97.  		dy = ydir[i]; 98.  	    } else if (sdir[i] == lowc((char)c)) { 99.  		/* a shifted movement letter */ 100. 		dx = 8 * xdir[i]; 101. 		dy = 8 * ydir[i]; 102. 	    } else 103. 		continue; 104.  105.  	    /* truncate at map edge; diagonal moves complicate this... */ 106.  	    if (cx + dx < 1) { 107. 		dy -= sgn(dy) * (1 - (cx + dx)); 108. 		dx = 1 - cx;		/* so that (cx+dx == 1) */ 109. 	    } else if (cx + dx > COLNO-1) { 110. 		dy += sgn(dy) * ((COLNO-1) - (cx + dx)); 111. 		dx = (COLNO-1) - cx; 112. 	    }  113.  	    if (cy + dy < 0) { 114. 		dx -= sgn(dx) * (0 - (cy + dy)); 115. 		dy = 0 - cy;		/* so that (cy+dy == 0) */ 116. 	    } else if (cy + dy > ROWNO-1) { 117. 		dx += sgn(dx) * ((ROWNO-1) - (cy + dy)); 118. 		dy = (ROWNO-1) - cy; 119. 	    }  120.  	    cx += dx; 121. 	    cy += dy; 122. 	    goto nxtc; 123. 	}  124.   125.  	if(c == '?'){ 126. 	    getpos_help(force, goal); 127. 	} else { 128. 	    if (!index(quitchars, c)) { 129. 		char matching[MAXPCHARS]; 130. 		int pass, lo_x, lo_y, hi_x, hi_y, k = 0; 131. 		(void)memset((genericptr_t)matching, 0, sizeof matching); 132. 		for (sidx = 1; sidx < MAXPCHARS; sidx++) 133. 		    if (c == defsyms[sidx].sym || c == (int)showsyms[sidx]) 134. 			matching[sidx] = (char) ++k; 135. 		if (k) { 136. 		    for (pass = 0; pass <= 1; pass++) { 137. 			/* pass 0: just past current pos to lower right; 138. 			   pass 1: upper left corner to current pos */ 139. 			lo_y = (pass == 0) ? cy : 0; 140. 			hi_y = (pass == 0) ? ROWNO - 1 : cy; 141. 			for (ty = lo_y; ty <= hi_y; ty++) { 142. 			    lo_x = (pass == 0 && ty == lo_y) ? cx + 1 : 1; 143. 			    hi_x = (pass == 1 && ty == hi_y) ? cx : COLNO - 1; 144. 			    for (tx = lo_x; tx <= hi_x; tx++) { 145. 				k = levl[tx][ty].glyph; 146. 				if (glyph_is_cmap(k) &&  147.  					matching[glyph_to_cmap(k)]) { 148. 				    cx = tx,  cy = ty; 149. 				    if (msg_given) { 150. 					clear_nhwindow(WIN_MESSAGE); 151. 					msg_given = FALSE; 152. 				    }  153.  				    goto nxtc; 154. 				}  155.  			    }	/* column */ 156. 			}	/* row */ 157. 		    }		/* pass */ 158. 		    pline("Can't find dungeon feature '%c'.", c); 159. 		    msg_given = TRUE; 160. 		    goto nxtc; 161. 		} else { 162. 		    pline("Unknown direction: '%s' (%s).",  163.  			  visctrl((char)c),  164.  			  !force ? "aborted" :  165.  			  iflags.num_pad ? "use 2468 or ." : "use hjkl or ."); 166. 		    msg_given = TRUE; 167. 		} /* k => matching */ 168. 	    } /* !quitchars */ 169. 	    if (force) goto nxtc; 170. 	    pline("Done."); 171. 	    msg_given = FALSE;	/* suppress clear */ 172. 	    cx = -1; 173. 	    cy = 0; 174. 	    result = 0;	/* not -1 */ 175. 	    break; 176. 	}  177.      nxtc:	; 178. #ifdef CLIPPING 179. 	cliparound(cx, cy); 180. #endif 181. 	curs(WIN_MAP,cx,cy); 182. 	flush_screen(0); 183.     }  184.  #ifdef MAC 185.     lock_mouse_cursor(FALSE); 186. #endif 187.     if (msg_given) clear_nhwindow(WIN_MESSAGE); 188.     cc->x = cx; 189.     cc->y = cy; 190.     return result; 191. }  192.   193.  struct monst * 194. christen_monst(mtmp, name) 195. struct monst *mtmp; 196. const char *name; 197. {  198.  	int lth; 199. 	struct monst *mtmp2; 200. 	char buf[PL_PSIZ]; 201.  202.  	/* dogname & catname are PL_PSIZ arrays; object names have same limit */ 203. 	lth = *name ? (int)(strlen(name) + 1) : 0; 204. 	if(lth > PL_PSIZ){ 205. 		lth = PL_PSIZ; 206. 		name = strncpy(buf, name, PL_PSIZ - 1); 207. 		buf[PL_PSIZ - 1] = '\0'; 208. 	}  209.  	if (lth == mtmp->mnamelth) { 210. 		/* don't need to allocate a new monst struct */ 211. 		if (lth) Strcpy(NAME(mtmp), name); 212. 		return mtmp; 213. 	}  214.  	mtmp2 = newmonst(mtmp->mxlth + lth); 215. 	*mtmp2 = *mtmp; 216. 	(void) memcpy((genericptr_t)mtmp2->mextra,  217.  		      (genericptr_t)mtmp->mextra, mtmp->mxlth); 218. 	mtmp2->mnamelth = lth; 219. 	if (lth) Strcpy(NAME(mtmp2), name); 220. 	replmon(mtmp,mtmp2); 221. 	return(mtmp2); 222. }  223.   224.  int 225. do_mname 226. {  227.  	char buf[BUFSZ]; 228. 	coord cc; 229. 	register int cx,cy; 230. 	register struct monst *mtmp; 231. 	char qbuf[QBUFSZ]; 232.  233.  	if (Hallucination) { 234. 		You("would never recognize it anyway."); 235. 		return 0; 236. 	}  237.  	cc.x = u.ux; 238. 	cc.y = u.uy; 239. 	if (getpos(&cc, FALSE, "the monster you want to name") < 0 ||  240.  			(cx = cc.x) < 0) 241. 		return 0; 242. 	cy = cc.y;  243. 244. 	if (cx == u.ux && cy == u.uy) { 245. #ifdef STEED 246. 	    if (u.usteed && canspotmon(u.usteed)) 247. 		mtmp = u.usteed; 248. 	    else { 249. #endif 250. 		pline("This %s creature is called %s and cannot be renamed.",  251.  		ACURR(A_CHA) > 14 ?  252.  		(flags.female ? "beautiful" : "handsome") : 253.  		"ugly",  254.  		plname); 255. 		return(0); 256. #ifdef STEED 257. 	    }  258.  #endif 259. 	} else 260. 	    mtmp = m_at(cx, cy); 261.  262.  	if (!mtmp || (!sensemon(mtmp) && 263. 			(!(cansee(cx,cy) || see_with_infrared(mtmp)) || mtmp->mundetected  264.  			|| mtmp->m_ap_type == M_AP_FURNITURE  265.  			|| mtmp->m_ap_type == M_AP_OBJECT  266.  			|| (mtmp->minvis && !See_invisible)))) { 267. 		pline("I see no monster there."); 268. 		return(0); 269. 	}  270.  	/* special case similar to the one in lookat */ 271. 	(void) distant_monnam(mtmp, ARTICLE_THE, buf); 272. 	Sprintf(qbuf, "What do you want to call %s?", buf); 273. 	getlin(qbuf,buf); 274. 	if(!*buf || *buf == '\033') return(0); 275. 	/* strip leading and trailing spaces; unnames monster if all spaces */ 276. 	(void)mungspaces(buf); 277.  278.  	if (mtmp->iswiz || type_is_pname(mtmp->data)) 279. 	    pline("%s doesn't like being called names!", Monnam(mtmp)); 280. 	else (void) christen_monst(mtmp, buf); 281. 	return(0); 282. }  283.   284.  /*  285.   * This routine changes the address of obj. Be careful not to call it 286. * when there might be pointers around in unknown places. For now: only 287.  * when obj is in the inventory. 288.  */  289.  STATIC_OVL 290. void 291. do_oname(obj) 292. register struct obj *obj; 293. {  294.  	char buf[BUFSZ], qbuf[QBUFSZ]; 295. 	const char *aname; 296. 	short objtyp; 297.  298.  	Sprintf(qbuf, "What do you want to name %s %s?",  299.  		is_plural(obj) ? "these" : "this", xname(obj)); 300. 	getlin(qbuf, buf); 301. 	if(!*buf || *buf == '\033')	return; 302. 	/* strip leading and trailing spaces; unnames item if all spaces */ 303. 	(void)mungspaces(buf); 304.  305.  	/* relax restrictions over proper capitalization for artifacts */ 306. 	if ((aname = artifact_name(buf, &objtyp)) != 0 && objtyp == obj->otyp) 307. 		Strcpy(buf, aname); 308.  309.  	if (obj->oartifact) { 310. 		pline_The("artifact seems to resist the attempt."); 311. 		return; 312. 	} else if (restrict_name(obj, buf) || exist_artifact(obj->otyp, buf)) { 313. 		int n = rn2((int)strlen(buf)); 314. 		register char c1, c2; 315.  316.  		c1 = lowc(buf[n]); 317. 		do c2 = 'a' + rn2('z'-'a'); while (c1 == c2); 318. 		buf[n] = (buf[n] == c1) ? c2 : highc(c2); /* keep same case */ 319. 		pline("While engraving your %s slips.", body_part(HAND)); 320. 		display_nhwindow(WIN_MESSAGE, FALSE); 321. 		You("engrave: \"%s\".",buf); 322. 	}  323.  	obj = oname(obj, buf); 324. }  325.   326.  /*  327.   * Allocate a new and possibly larger storage space for an obj. 328.  */  329.  struct obj * 330. realloc_obj(obj, oextra_size, oextra_src, oname_size, name) 331. struct obj *obj; 332. int oextra_size;		/* storage to allocate for oextra            */ 333. genericptr_t oextra_src; 334. int oname_size;			/* size of name string + 1 (null terminator) */ 335. const char *name; 336. {  337.  	struct obj *otmp; 338.  339.  	otmp = newobj(oextra_size + oname_size); 340. 	*otmp = *obj;	/* the cobj pointer is copied to otmp */ 341. 	if (oextra_size) { 342. 	    if (oextra_src) 343. 		(void) memcpy((genericptr_t)otmp->oextra, oextra_src,  344.  							oextra_size); 345. 	} else { 346. 	    otmp->oattached = OATTACHED_NOTHING; 347. 	}  348.  	otmp->oxlth = oextra_size; 349.  350.  	otmp->onamelth = oname_size; 351. 	otmp->timed = 0;	/* not timed, yet */ 352. 	otmp->lamplit = 0;	/* ditto */ 353. 	/* __GNUC__ note:  if the assignment of otmp->onamelth immediately 354. 	   precedes this `if' statement, a gcc bug will miscompile the 355. 	   test on vax (`insv' instruction used to store bitfield does  356.  	   not set condition codes, but optimizer behaves as if it did). 357. 	   gcc-2.7.2.1 finally fixed this. */ 358.  	if (oname_size) { 359. 	    if (name) 360. 		Strcpy(ONAME(otmp), name); 361. 	}  362.   363.  	if (obj->owornmask) { 364. 		setworn((struct obj *)0, obj->owornmask); 365. 		setworn(otmp, otmp->owornmask); 366. 	}  367.   368.  	/* replace obj with otmp */ 369. 	replace_object(obj, otmp); 370.  371.  	/* fix ocontainer pointers */ 372. 	if (Has_contents(obj)) { 373. 		struct obj *inside; 374.  375.  		for(inside = obj->cobj; inside; inside = inside->nobj) 376. 			inside->ocontainer = otmp; 377. 	}  378.   379.  	/* move timers and light sources from obj to otmp */ 380. 	if (obj->timed) obj_move_timers(obj, otmp); 381. 	if (obj->lamplit) obj_move_light_source(obj, otmp); 382.  383.  	/* objects possibly being manipulated by multi-turn occupations 384. 	   which have been interrupted but might be subsequently resumed */ 385. 	if (obj->oclass == FOOD_CLASS) 386. 	    food_substitution(obj, otmp);	/* eat food or open tin */ 387. 	else if (obj->oclass == SPBOOK_CLASS) 388. 	    book_substitution(obj, otmp);	/* read spellbook */ 389.  390.  	/* obfree(obj, otmp);	now unnecessary: no pointers on bill */ 391. 	dealloc_obj(obj);	/* let us hope nobody else saved a pointer */ 392. 	return otmp; 393. }  394.   395.  struct obj * 396. oname(obj, name) 397. struct obj *obj; 398. const char *name; 399. {  400.  	int lth; 401. 	char buf[PL_PSIZ]; 402.  403.  	lth = *name ? (int)(strlen(name) + 1) : 0; 404. 	if (lth > PL_PSIZ) { 405. 		lth = PL_PSIZ; 406. 		name = strncpy(buf, name, PL_PSIZ - 1); 407. 		buf[PL_PSIZ - 1] = '\0'; 408. 	}  409.  	/* If named artifact exists in the game, do not create another. 410. 	 * Also trying to create an artifact shouldn't de-artifact 411. 	 * it (e.g. Excalibur from prayer). In this case the object 412. 	 * will retain its current name. */ 413.  	if (obj->oartifact || (lth && exist_artifact(obj->otyp, name))) 414. 		return obj; 415.  416.  	if (lth == obj->onamelth) { 417. 		/* no need to replace entire object */ 418. 		if (lth) Strcpy(ONAME(obj), name); 419. 	} else { 420. 		obj = realloc_obj(obj, obj->oxlth,  421.  			      (genericptr_t)obj->oextra, lth, name); 422. 	}  423.  	if (lth) artifact_exists(obj, name, TRUE); 424. 	if (obj->oartifact && obj == uswapwep) untwoweapon; 425. 	if (carried(obj)) update_inventory; 426. 	return obj; 427. }  428.   429.  static NEARDATA const char callable[] = { 430. 	SCROLL_CLASS, POTION_CLASS, WAND_CLASS, RING_CLASS, AMULET_CLASS, 431. 	GEM_CLASS, SPBOOK_CLASS, ARMOR_CLASS, TOOL_CLASS, 0 }; 432.  433.  int 434. ddocall 435. {  436.  	register struct obj *obj; 437. #ifdef REDO 438. 	char	ch; 439. #endif 440. 	char allowall[2]; 441.  442.  	switch(  443.  #ifdef REDO  444.  		ch =  445.  #endif  446.  		ynq("Name an individual object?")) { 447. 	case 'q': 448. 		break; 449. 	case 'y': 450. #ifdef REDO 451. 		savech(ch); 452. #endif 453. 		allowall[0] = ALL_CLASSES; allowall[1] = '\0'; 454. 		obj = getobj(allowall, "name"); 455. 		if(obj) do_oname(obj); 456. 		break; 457. 	default : 458. #ifdef REDO 459. 		savech(ch); 460. #endif 461. 		obj = getobj(callable, "call"); 462. 		if (obj) { 463. 			if (!obj->dknown) { 464. 				You("would never recognize another one."); 465. 				return 0; 466. 			}  467.  			docall(obj); 468. 		}  469.  		break; 470. 	}  471.  	return 0; 472. }  473.   474.  void 475. docall(obj) 476. register struct obj *obj; 477. {  478.  	char buf[BUFSZ], qbuf[QBUFSZ]; 479. 	struct obj otemp; 480. 	register char **str1; 481.  482.  	if (!obj->dknown) return; /* probably blind */ 483. 	otemp = *obj; 484. 	otemp.quan = 1L; 485. 	otemp.onamelth = 0; 486. 	otemp.oxlth = 0; 487. 	if (objects[otemp.otyp].oc_class == POTION_CLASS && otemp.corpsenm) 488. 	    /* kludge, meaning it's sink water */ 489. 	    Sprintf(qbuf,"Call a stream of %s fluid:",  490.  		    OBJ_DESCR(objects[otemp.otyp])); 491. 	else 492. 	    Sprintf(qbuf, "Call %s:", an(xname(&otemp))); 493. 	getlin(qbuf, buf); 494. 	if(!*buf || *buf == '\033') 495. 		return; 496.  497.  	/* clear old name */ 498. 	str1 = &(objects[obj->otyp].oc_uname); 499. 	if(*str1) free((genericptr_t)*str1); 500.  501.  	/* strip leading and trailing spaces; uncalls item if all spaces */ 502. 	(void)mungspaces(buf); 503. 	if (!*buf) { 504. 	    if (*str1) {	/* had name, so possibly remove from disco[] */ 505. 		/* strip name first, for the update_inventory call 506. 		   from undiscover_object */ 507. 		*str1 = (char *)0; 508. 		undiscover_object(obj->otyp); 509. 	    }  510.  	} else { 511. 	    *str1 = strcpy((char *) alloc((unsigned)strlen(buf)+1), buf); 512. 	    discover_object(obj->otyp, FALSE, TRUE); /* possibly add to disco[] */ 513. 	}  514.  }  515.   516.  #endif /*OVLB*/ 517. #ifdef OVL0 518.  519.  static const char *ghostnames[] = { 520. 	/* these names should have length < PL_NSIZ */ 521. 	/* Capitalize the names for aesthetics -dgk */ 522. 	"Adri", "Andries", "Andreas", "Bert", "David", "Dirk", "Emile", 523. 	"Frans", "Fred", "Greg", "Hether", "Jay", "John", "Jon", "Karnov", 524. 	"Kay", "Kenny", "Kevin", "Maud", "Michiel", "Mike", "Peter", "Robert", 525. 	"Ron", "Tom", "Wilmar", "Nick Danger", "Phoenix", "Jiro", "Mizue", 526. 	"Stephan", "Lance Braccus", "Shadowhawk" 527. };  528.   529.  /* ghost names formerly set by x_monnam, now by makemon instead */ 530. const char * 531. rndghostname 532. {  533.      return rn2(7) ? ghostnames[rn2(SIZE(ghostnames))] : (const char *)plname; 534. }  535.   536.  /* Monster naming functions: 537.  * x_monnam is the generic monster-naming function. 538.  *		  seen	      unseen	   detected		  named 539.  * mon_nam:	the newt	it	the invisible orc	Fido 540.  * noit_mon_nam:the newt (as if detected) the invisible orc	Fido 541.  * l_monnam:	newt		it	invisible orc		dog called fido 542.  * Monnam:	The newt	It	The invisible orc	Fido 543.  * noit_Monnam: The newt (as if detected) The invisible orc	Fido 544.  * Adjmonnam:	The poor newt	It	The poor invisible orc	The poor Fido 545.  * Amonnam:	A newt		It	An invisible orc	Fido 546.  * a_monnam:	a newt		it	an invisible orc	Fido 547.  * m_monnam:	newt		xan	orc			Fido 548.  * y_monnam:	your newt     your xan	your invisible orc	Fido 549.  */  550.   551.  /* Bug: if the monster is a priest or shopkeeper, not every one of these 552.  * options works, since those are special cases. 553.  */  554.  char * 555. x_monnam(mtmp, article, adjective, suppress, called) 556. register struct monst *mtmp; 557. int article; 558. /* ARTICLE_NONE, ARTICLE_THE, ARTICLE_A: obvious 559.  * ARTICLE_YOUR: "your" on pets, "the" on everything else 560.  *  561.   * If the monster would be referred to as "it" or if the monster has a name 562.  * _and_ there is no adjective, "invisible", "saddled", etc., override this 563.  * and always use no article. 564.  */  565.  const char *adjective; 566. int suppress; 567. /* SUPPRESS_IT, SUPPRESS_INVISIBLE, SUPPRESS_HALLUCINATION, SUPPRESS_SADDLE. 568.  * EXACT_NAME: combination of all the above 569.  */  570.  boolean called; 571. {  572.  #ifdef LINT	/* static char buf[BUFSZ]; */ 573. 	char buf[BUFSZ]; 574. #else 575. 	static char buf[BUFSZ]; 576. #endif 577. 	struct permonst *mdat = mtmp->data; 578. 	boolean do_hallu, do_invis, do_it, do_saddle; 579. 	boolean name_at_start, has_adjectives; 580. 	char *bp; 581.  582.  	if (program_state.gameover) 583. 	    suppress |= SUPPRESS_HALLUCINATION; 584. 	if (article == ARTICLE_YOUR && !mtmp->mtame) 585. 	    article = ARTICLE_THE; 586.  587.  	do_hallu = Hallucination && !(suppress & SUPPRESS_HALLUCINATION); 588. 	do_invis = mtmp->minvis && !(suppress & SUPPRESS_INVISIBLE); 589. 	do_it = !canspotmon(mtmp) && 590. 	    article != ARTICLE_YOUR && 591. 	    !program_state.gameover && 592. #ifdef STEED 593. 	    mtmp != u.usteed && 594. #endif 595. 	    !(u.uswallow && mtmp == u.ustuck) && 596. 	    !(suppress & SUPPRESS_IT); 597. 	do_saddle = !(suppress & SUPPRESS_SADDLE); 598.  599.  	buf[0] = 0; 600.  601.  	/* unseen monsters, etc.  Use "it" */ 602. 	if (do_it) { 603. 	    Strcpy(buf, "it"); 604. 	    return buf; 605. 	}  606.   607.  	/* priests and minions: don't even use this function */ 608. 	if (mtmp->ispriest || mtmp->isminion) { 609. 	    char priestnambuf[BUFSZ]; 610. 	    char *name; 611. 	    long save_prop = EHalluc_resistance; 612. 	    unsigned save_invis = mtmp->minvis; 613.  614.  	    /* when true name is wanted, explicitly block Hallucination */ 615. 	    if (!do_hallu) EHalluc_resistance = 1L; 616. 	    if (!do_invis) mtmp->minvis = 0; 617. 	    name = priestname(mtmp, priestnambuf); 618. 	    EHalluc_resistance = save_prop; 619. 	    mtmp->minvis = save_invis; 620. 	    if (article == ARTICLE_NONE && !strncmp(name, "the ", 4)) 621. 		name += 4; 622. 	    return strcpy(buf, name); 623. 	}  624.   625.  	/* Shopkeepers: use shopkeeper name. For normal shopkeepers, just 626. 	 * "Asidonhopo"; for unusual ones, "Asidonhopo the invisible  627.  	 * shopkeeper" or "Asidonhopo the blue dragon". If hallucinating, 628. 	 * none of this applies. 629. 	 */  630.  	if (mtmp->isshk && !do_hallu) { 631. 	    if (adjective && article == ARTICLE_THE) { 632. 		/* pathological case: "the angry Asidonhopo the blue dragon" 633. 		   sounds silly */ 634. 		Strcpy(buf, "the "); 635. 		Strcat(strcat(buf, adjective), " "); 636. 		Strcat(buf, shkname(mtmp)); 637. 		return buf; 638. 	    }  639.  	    Strcat(buf, shkname(mtmp)); 640. 	    if (mdat == &mons[PM_SHOPKEEPER] && !do_invis) 641. 		return buf; 642. 	    Strcat(buf, " the "); 643. 	    if (do_invis) 644. 		Strcat(buf, "invisible "); 645. 	    Strcat(buf, mdat->mname); 646. 	    return buf; 647. 	}  648.   649.  	/* Put the adjectives in the buffer */ 650. 	if (adjective) 651. 	    Strcat(strcat(buf, adjective), " "); 652. 	if (do_invis) 653. 	    Strcat(buf, "invisible "); 654. #ifdef STEED 655. 	if (do_saddle && (mtmp->misc_worn_check & W_SADDLE) &&  656.  	    !Blind && !Hallucination) 657. 	    Strcat(buf, "saddled "); 658. #endif 659. 	if (buf[0] != 0) 660. 	    has_adjectives = TRUE; 661. 	else 662. 	    has_adjectives = FALSE; 663.  664.  	/* Put the actual monster name or type into the buffer now */ 665. 	/* Be sure to remember whether the buffer starts with a name */ 666. 	if (do_hallu) { 667. 	    Strcat(buf, rndmonnam); 668. 	    name_at_start = FALSE; 669. 	} else if (mtmp->mnamelth) { 670. 	    char *name = NAME(mtmp); 671.  672.  	    if (mdat == &mons[PM_GHOST]) { 673. 		Sprintf(eos(buf), "%s ghost", s_suffix(name)); 674. 		name_at_start = TRUE; 675. 	    } else if (called) { 676. 		Sprintf(eos(buf), "%s called %s", mdat->mname, name); 677. 		name_at_start = (boolean)type_is_pname(mdat); 678. 	    } else if (is_mplayer(mdat) && (bp = strstri(name, " the ")) != 0) { 679. 		/* the    */ 680. 		char pbuf[BUFSZ]; 681.  682.  		Strcpy(pbuf, name); 683. 		pbuf[bp - name + 5] = '\0'; /* adjectives right after " the " */ 684. 		if (has_adjectives) 685. 		    Strcat(pbuf, buf); 686. 		Strcat(pbuf, bp + 5);	/* append the rest of the name */ 687. 		Strcpy(buf, pbuf); 688. 		article = ARTICLE_NONE; 689. 		name_at_start = TRUE; 690. 	    } else { 691. 		Strcat(buf, name); 692. 		name_at_start = TRUE; 693. 	    }  694.  	} else if (is_mplayer(mdat) && !In_endgame(&u.uz)) { 695. 	    char pbuf[BUFSZ]; 696. 	    Strcpy(pbuf, rank_of((int)mtmp->m_lev, 697. 				 monsndx(mdat), 698. 				 (boolean)mtmp->female)); 699. 	    Strcat(buf, lcase(pbuf)); 700. 	    name_at_start = FALSE; 701. 	} else { 702. 	    Strcat(buf, mdat->mname); 703. 	    name_at_start = (boolean)type_is_pname(mdat); 704. 	}  705.   706.  	if (name_at_start && !has_adjectives) { 707. 	    if (mdat == &mons[PM_WIZARD_OF_YENDOR]) 708. 		article = ARTICLE_THE; 709. 	    else 710. 		article = ARTICLE_NONE; 711. 	} else if (mons[monsndx(mdat)].geno & G_UNIQ &&  712.  		   article == ARTICLE_A) { 713. 	    article = ARTICLE_THE; 714. 	}  715.   716.  	{  717.  	    char buf2[BUFSZ]; 718.  719.  	    switch(article) { 720. 		case ARTICLE_YOUR: 721. 		    Strcpy(buf2, "your "); 722. 		    Strcat(buf2, buf); 723. 		    Strcpy(buf, buf2); 724. 		    return buf; 725. 		case ARTICLE_THE: 726. 		    Strcpy(buf2, "the "); 727. 		    Strcat(buf2, buf); 728. 		    Strcpy(buf, buf2); 729. 		    return buf; 730. 		case ARTICLE_A: 731. 		    return(an(buf)); 732. 		case ARTICLE_NONE: 733. 		default: 734. 		    return buf; 735. 	    }  736.  	}  737.  }  738.   739.  #endif /* OVL0 */ 740. #ifdef OVLB 741.  742.  char * 743. l_monnam(mtmp) 744. register struct monst *mtmp; 745. {  746.  	return(x_monnam(mtmp, ARTICLE_NONE, (char *)0, 747. 		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, TRUE)); 748. }  749.   750.  #endif /* OVLB */ 751. #ifdef OVL0 752.  753.  char * 754. mon_nam(mtmp) 755. register struct monst *mtmp; 756. {  757.  	return(x_monnam(mtmp, ARTICLE_THE, (char *)0, 758. 		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, FALSE)); 759. }  760.   761.  /* print the name as if mon_nam was called, but assume that the player 762.  * can always see the monster--used for probing and for monsters aggravating 763.  * the player with a cursed potion of invisibility 764.  */  765.  char * 766. noit_mon_nam(mtmp) 767. register struct monst *mtmp; 768. {  769.  	return(x_monnam(mtmp, ARTICLE_THE, (char *)0, 770. 		mtmp->mnamelth ? (SUPPRESS_SADDLE|SUPPRESS_IT) : 771. 		    SUPPRESS_IT, FALSE)); 772. }  773.   774.  char * 775. Monnam(mtmp) 776. register struct monst *mtmp; 777. {  778.  	register char *bp = mon_nam(mtmp); 779.  780.  	*bp = highc(*bp); 781. 	return(bp); 782. }  783.   784.  char * 785. noit_Monnam(mtmp) 786. register struct monst *mtmp; 787. {  788.  	register char *bp = noit_mon_nam(mtmp); 789.  790.  	*bp = highc(*bp); 791. 	return(bp); 792. }  793.   794.  /* monster's own name */ 795. char * 796. m_monnam(mtmp) 797. struct monst *mtmp; 798. {  799.  	return x_monnam(mtmp, ARTICLE_NONE, (char *)0, EXACT_NAME, FALSE); 800. }  801.   802.  /* pet name: "your little dog" */ 803. char * 804. y_monnam(mtmp) 805. struct monst *mtmp; 806. {  807.  	return x_monnam(mtmp, ARTICLE_YOUR, (char *)0,  808.  		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, FALSE); 809. }  810.   811.  #endif /* OVL0 */ 812. #ifdef OVLB 813.  814.  char * 815. Adjmonnam(mtmp, adj) 816. register struct monst *mtmp; 817. register const char *adj; 818. {  819.  	register char *bp = x_monnam(mtmp, ARTICLE_THE, adj,  820.  		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, FALSE); 821.  822.  	*bp = highc(*bp); 823. 	return(bp); 824. }  825.   826.  char * 827. a_monnam(mtmp) 828. register struct monst *mtmp; 829. {  830.  	return x_monnam(mtmp, ARTICLE_A, (char *)0,  831.  		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, FALSE); 832. }  833.   834.  char * 835. Amonnam(mtmp) 836. register struct monst *mtmp; 837. {  838.  	register char *bp = a_monnam(mtmp); 839.  840.  	*bp = highc(*bp); 841. 	return(bp); 842. }  843.   844.  /* used for monster ID by the '/', ';', and 'C' commands to block remote 845.    identification of the endgame altars via their attending priests */ 846. char * 847. distant_monnam(mon, article, outbuf) 848. struct monst *mon; 849. int article;	/* only ARTICLE_NONE and ARTICLE_THE are handled here */ 850. char *outbuf; 851. {  852.      /* high priest(ess)'s identity is concealed on the Astral Plane, 853.        unless you're adjacent (overridden for hallucination which does  854.         its own obfuscation) */ 855.     if (mon->data == &mons[PM_HIGH_PRIEST] && !Hallucination &&  856.  	    Is_astralevel(&u.uz) && distu(mon->mx, mon->my) > 2) { 857. 	Strcpy(outbuf, article == ARTICLE_THE ? "the " : ""); 858. 	Strcat(outbuf, mon->female ? "high priestess" : "high priest"); 859.     } else { 860. 	Strcpy(outbuf, x_monnam(mon, article, (char *)0, 0, TRUE)); 861.     }  862.      return outbuf; 863. }  864.   865.  static const char *bogusmons[] = { 866. 	"jumbo shrimp", "giant pigmy", "gnu", "killer penguin", 867. 	"giant cockroach", "giant slug", "maggot", "pterodactyl", 868. 	"tyrannosaurus rex", "basilisk", "beholder", "nightmare", 869. 	"efreeti", "marid", "rot grub", "bookworm", "master lichen", 870. 	"shadow", "hologram", "jester", "attorney", "sleazoid", 871. 	"killer tomato", "amazon", "robot", "battlemech", 872. 	"rhinovirus", "harpy", "lion-dog", "rat-ant", "Y2K bug", 873. 						/* misc. */ 874. 	"grue", "Christmas-tree monster", "luck sucker", "paskald", 875. 	"brogmoid", "dornbeast",		/* Quendor (Zork, &c.) */ 876. 	"Ancient Multi-Hued Dragon", "Evil Iggy", 877. 						/* Moria */ 878. 	"emu", "kestrel", "xeroc", "venus flytrap", 879. 						/* Rogue */ 880. 	"creeping coins",			/* Wizardry */ 881. 	"hydra", "siren",			/* Greek legend */ 882. 	"killer bunny",				/* Monty Python */ 883. 	"rodent of unusual size",		/* The Princess Bride */ 884. 	"Smokey the bear",	/* "Only you can prevent forest fires!" */ 885.  	"Luggage",				/* Discworld */ 886. 	"Ent",					/* Lord of the Rings */ 887. 	"tangle tree", "nickelpede", "wiggle",	/* Xanth */ 888. 	"white rabbit", "snark",		/* Lewis Carroll */ 889. 	"pushmi-pullyu",			/* Dr. Doolittle */ 890. 	"smurf",				/* The Smurfs */ 891. 	"tribble", "Klingon", "Borg",		/* Star Trek */ 892. 	"Ewok",					/* Star Wars */ 893. 	"Totoro",				/* Tonari no Totoro */ 894. 	"ohmu",					/* Nausicaa */ 895. 	"youma",				/* Sailor Moon */ 896. 	"nyaasu",				/* Pokemon (Meowth) */ 897. 	"Godzilla", "King Kong",		/* monster movies */ 898. 	"earthquake beast",			/* old L of SH */ 899. 	"Invid",				/* Robotech */ 900. 	"Terminator",				/* The Terminator */ 901. 	"boomer",				/* Bubblegum Crisis */ 902. 	"Dalek",				/* Dr. Who ("Exterminate!") */ 903. 	"microscopic space fleet", "Ravenous Bugblatter Beast of Traal", 904. 						/* HGttG */ 905. 	"teenage mutant ninja turtle",		/* TMNT */ 906. 	"samurai rabbit",			/* Usagi Yojimbo */ 907. 	"aardvark",				/* Cerebus */ 908. 	"Audrey II",				/* Little Shop of Horrors */ 909. 	"witch doctor", "one-eyed one-horned flying purple people eater", 910. 						/* 50's rock 'n' roll */ 911. 	"Barney the dinosaur",			/* saccharine kiddy TV */ 912. 	"Morgoth",				/* Angband */ 913. 	"Vorlon",				/* Babylon 5 */ 914. 	"questing beast",		/* King Arthur */ 915. 	"Predator",				/* Movie */ 916. 	"mother-in-law"				/* common pest */ 917. };  918.   919.   920.  /* Return a random monster name, for hallucination. 921.  * KNOWN BUG: May be a proper name (Godzilla, Barney), may not 922.  * (the Terminator, a Dalek). There's no elegant way to deal 923.  * with this without radically modifying the calling functions. 924.  */  925.  const char * 926. rndmonnam 927. {  928.  	int name; 929.  930.  	do { 931. 	    name = rn1(SPECIAL_PM + SIZE(bogusmons) - LOW_PM, LOW_PM); 932. 	} while (name < SPECIAL_PM &&  933.  	    (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN))); 934.  935.  	if (name >= SPECIAL_PM) return bogusmons[name - SPECIAL_PM]; 936. 	return mons[name].mname; 937. }  938.   939.  #ifdef REINCARNATION 940. const char * 941. roguename /* Name of a Rogue player */ 942. {  943.  	char *i, *opts; 944.  945.  	if ((opts = nh_getenv("ROGUEOPTS")) != 0) { 946. 		for (i = opts; *i; i++) 947. 			if (!strncmp("name=",i,5)) { 948. 				char *j; 949. 				if ((j = index(i+5,',')) != 0) 950. 					*j = (char)0; 951. 				return i+5; 952. 			}  953.  	}  954.  	return rn2(3) ? (rn2(2) ? "Michael Toy" : "Kenneth Arnold") 955. 		: "Glenn Wichman"; 956. }  957.  #endif /* REINCARNATION */ 958. #endif /* OVLB */ 959.  960.  #ifdef OVL2 961.  962.  static NEARDATA const char *hcolors[] = { 963. 	"ultraviolet", "infrared", "bluish-orange", 964. 	"reddish-green", "dark white", "light black", "sky blue-pink", 965. 	"salty", "sweet", "sour", "bitter", 966. 	"striped", "spiral", "swirly", "plaid", "checkered", "argyle", 967. 	"paisley", "blotchy", "guernsey-spotted", "polka-dotted", 968. 	"square", "round", "triangular", 969. 	"cabernet", "sangria", "fuchsia", "wisteria", 970. 	"lemon-lime", "strawberry-banana", "peppermint", 971. 	"romantic", "incandescent" 972. };  973.   974.  const char * 975. hcolor(colorpref) 976. const char *colorpref; 977. {  978.  	return (Hallucination || !colorpref) ? 979. 		hcolors[rn2(SIZE(hcolors))] : colorpref; 980. }  981.   982.  /* Aliases for road-runner nemesis 983.  * See also http://www.geocities.com/EnchantedForest/1141/latin.html 984.  */  985.  static const char *coynames[] = { 986. 	"Carnivorous Vulgaris","Road-Runnerus Digestus", 987. 	"Eatibus Anythingus"  ,"Famishus-Famishus", 988. 	"Eatibus Almost Anythingus","Eatius Birdius", 989. 	"Famishius Fantasticus","Eternalii Famishiis", 990. 	"Famishus Vulgarus","Famishius Vulgaris Ingeniusi", 991. 	"Eatius-Slobbius","Hardheadipus Oedipus", 992. 	"Carnivorous Slobbius","Hard-Headipus Ravenus", 993. 	"Evereadii Eatibus","Apetitius Giganticus", 994. 	"Hungrii Flea-Bagius","Overconfidentii Vulgaris", 995. 	"Caninus Nervous Rex","Grotesques Appetitus", 996. 	"Nemesis Riduclii","Canis latrans" 997. };  998.  	  999.  char *coyotename(mtmp, buf) 1000. struct monst *mtmp; 1001. char *buf; 1002. { 1003.     if (mtmp && buf) { 1004. 	Sprintf(buf, "%s - %s", 1005. 	    x_monnam(mtmp, ARTICLE_NONE, (char *)0, 0, TRUE),  1006. 	    mtmp->mcan ? coynames[SIZE(coynames)-1] : coynames[rn2(SIZE(coynames)-1)]); 1007.    }  1008.     return buf; 1009. } 1010. #endif /* OVL2 */ 1011. 1012. /*do_name.c*/