Source:NetHack 3.3.0/do name.c

From NetHackWiki
Jump to navigation Jump to search

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

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

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1.    /*	SCCS Id: @(#)do_name.c	3.3	1999/10/10	*/
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.   	    /* a mouse click event, just assign and return */
81.   	    cx = tx;
82.   	    cy = ty;
83.   	    break;
84.   	}
85.   	if ((cp = index(pick_chars, c)) != 0) {
86.   	    /* '.' => 0, ',' => 1, ';' => 2, ':' => 3 */
87.   	    result = cp - pick_chars;
88.   	    break;
89.   	}
90.   	for (i = 0; i < 8; i++) {
91.   	    int dx, dy;
92.   
93.   	    if (sdp[i] == c) {
94.   		/* a normal movement letter or digit */
95.   		dx = xdir[i];
96.   		dy = ydir[i];
97.   	    } else if (sdir[i] == lowc((char)c)) {
98.   		/* a shifted movement letter */
99.   		dx = 8 * xdir[i];
100.  		dy = 8 * ydir[i];
101.  	    } else
102.  		continue;
103.  
104.  	    /* truncate at map edge; diagonal moves complicate this... */
105.  	    if (cx + dx < 1) {
106.  		dy -= sgn(dy) * (1 - (cx + dx));
107.  		dx = 1 - cx;		/* so that (cx+dx == 1) */
108.  	    } else if (cx + dx > COLNO-1) {
109.  		dy += sgn(dy) * ((COLNO-1) - (cx + dx));
110.  		dx = (COLNO-1) - cx;
111.  	    }
112.  	    if (cy + dy < 0) {
113.  		dx -= sgn(dx) * (0 - (cy + dy));
114.  		dy = 0 - cy;		/* so that (cy+dy == 0) */
115.  	    } else if (cy + dy > ROWNO-1) {
116.  		dx += sgn(dx) * ((ROWNO-1) - (cy + dy));
117.  		dy = (ROWNO-1) - cy;
118.  	    }
119.  	    cx += dx;
120.  	    cy += dy;
121.  	    goto nxtc;
122.  	}
123.  
124.  	if(c == '?'){
125.  	    getpos_help(force, goal);
126.  	} else {
127.  	    if (!index(quitchars, c)) {
128.  		char matching[MAXPCHARS];
129.  		int pass, lo_x, lo_y, hi_x, hi_y, k = 0;
130.  		(void)memset((genericptr_t)matching, 0, sizeof matching);
131.  		for (sidx = 1; sidx < MAXPCHARS; sidx++)
132.  		    if (c == defsyms[sidx].sym || c == (int)showsyms[sidx])
133.  			matching[sidx] = (char) ++k;
134.  		if (k) {
135.  		    for (pass = 0; pass <= 1; pass++) {
136.  			/* pass 0: just past current pos to lower right;
137.  			   pass 1: upper left corner to current pos */
138.  			lo_y = (pass == 0) ? cy : 0;
139.  			hi_y = (pass == 0) ? ROWNO - 1 : cy;
140.  			for (ty = lo_y; ty <= hi_y; ty++) {
141.  			    lo_x = (pass == 0 && ty == lo_y) ? cx + 1 : 1;
142.  			    hi_x = (pass == 1 && ty == hi_y) ? cx : COLNO - 1;
143.  			    for (tx = lo_x; tx <= hi_x; tx++) {
144.  				k = levl[tx][ty].glyph;
145.  				if (glyph_is_cmap(k) &&
146.  					matching[glyph_to_cmap(k)]) {
147.  				    cx = tx,  cy = ty;
148.  				    if (msg_given) {
149.  					clear_nhwindow(WIN_MESSAGE);
150.  					msg_given = FALSE;
151.  				    }
152.  				    goto nxtc;
153.  				}
154.  			    }	/* column */
155.  			}	/* row */
156.  		    }		/* pass */
157.  		    pline("Can't find dungeon feature '%c'", c);
158.  		    msg_given = TRUE;
159.  		    goto nxtc;
160.  		} else {
161.  		    pline("Unknown direction: '%s' (%s).",
162.  			  visctrl((char)c),
163.  			  !force ? "aborted" :
164.  			  iflags.num_pad ? "use 2468 or ." : "use hjkl or .");
165.  		    msg_given = TRUE;
166.  		} /* k => matching */
167.  	    } /* !quitchars */
168.  	    if (force) goto nxtc;
169.  	    pline("Done.");
170.  	    msg_given = FALSE;	/* suppress clear */
171.  	    cx = -1;
172.  	    cy = 0;
173.  	    result = 0;	/* not -1 */
174.  	    break;
175.  	}
176.      nxtc:	;
177.  #ifdef CLIPPING
178.  	cliparound(cx, cy);
179.  #endif
180.  	curs(WIN_MAP,cx,cy);
181.  	flush_screen(0);
182.      }
183.  #ifdef MAC
184.      lock_mouse_cursor(FALSE);
185.  #endif
186.      if (msg_given) clear_nhwindow(WIN_MESSAGE);
187.      cc->x = cx;
188.      cc->y = cy;
189.      return result;
190.  }
191.  
192.  struct monst *
193.  christen_monst(mtmp, name)
194.  struct monst *mtmp;
195.  const char *name;
196.  {
197.  	int lth;
198.  	struct monst *mtmp2;
199.  	char buf[PL_PSIZ];
200.  
201.  	/* dogname & catname are PL_PSIZ arrays; object names have same limit */
202.  	lth = *name ? (int)(strlen(name) + 1) : 0;
203.  	if(lth > PL_PSIZ){
204.  		lth = PL_PSIZ;
205.  		name = strncpy(buf, name, PL_PSIZ - 1);
206.  		buf[PL_PSIZ - 1] = '\0';
207.  	}
208.  	if (lth == mtmp->mnamelth) {
209.  		/* don't need to allocate a new monst struct */
210.  		if (lth) Strcpy(NAME(mtmp), name);
211.  		return mtmp;
212.  	}
213.  	mtmp2 = newmonst(mtmp->mxlth + lth);
214.  	*mtmp2 = *mtmp;
215.  	(void) memcpy((genericptr_t)mtmp2->mextra,
216.  		      (genericptr_t)mtmp->mextra, mtmp->mxlth);
217.  	mtmp2->mnamelth = lth;
218.  	if (lth) Strcpy(NAME(mtmp2), name);
219.  	replmon(mtmp,mtmp2);
220.  	return(mtmp2);
221.  }
222.  
223.  int
224.  do_mname()
225.  {
226.  	char buf[BUFSZ];
227.  	coord cc;
228.  	register int cx,cy;
229.  	register struct monst *mtmp;
230.  	char qbuf[QBUFSZ];
231.  
232.  	if (Hallucination) {
233.  		You("would never recognize it anyway.");
234.  		return 0;
235.  	}
236.  	cc.x = u.ux;
237.  	cc.y = u.uy;
238.  	if (getpos(&cc, FALSE, "the monster you want to name") < 0 ||
239.  			(cx = cc.x) < 0)
240.  		return 0;
241.  	cy = cc.y;
242.  
243.  	if (cx == u.ux && cy == u.uy) {
244.  #ifdef STEED
245.  	    if (u.usteed && canspotmon(u.usteed))
246.  		mtmp = u.usteed;
247.  	    else {
248.  #endif
249.  		pline("This %s creature is called %s and cannot be renamed.",
250.  		ACURR(A_CHA) > 14 ?
251.  		(flags.female ? "beautiful" : "handsome") :
252.  		"ugly",
253.  		plname);
254.  		return(0);
255.  #ifdef STEED
256.  	    }
257.  #endif
258.  	} else
259.  	    mtmp = m_at(cx, cy);
260.  
261.  	if (!mtmp || (!sensemon(mtmp) &&
262.  			(!(cansee(cx,cy) || see_with_infrared(mtmp)) || mtmp->mundetected
263.  			|| mtmp->m_ap_type == M_AP_FURNITURE
264.  			|| mtmp->m_ap_type == M_AP_OBJECT
265.  			|| (mtmp->minvis && !See_invisible)))) {
266.  		pline("I see no monster there.");
267.  		return(0);
268.  	}
269.  	/* special case similar to the one in lookat() */
270.  	if (mtmp->data != &mons[PM_HIGH_PRIEST])
271.  	    Strcpy(buf, x_monnam(mtmp, 0, (char *)0, 1));
272.  	else
273.  	    Sprintf(buf, "the high priest%s", mtmp->female ? "ess" : "");
274.  	Sprintf(qbuf, "What do you want to call %s?", buf);
275.  	getlin(qbuf,buf);
276.  	if(!*buf || *buf == '\033') return(0);
277.  	/* strip leading and trailing spaces; unnames monster if all spaces */
278.  	(void)mungspaces(buf);
279.  
280.  	if (mtmp->iswiz || type_is_pname(mtmp->data))
281.  	    pline("%s doesn't like being called names!", Monnam(mtmp));
282.  	else (void) christen_monst(mtmp, buf);
283.  	return(0);
284.  }
285.  
286.  /*
287.   * This routine changes the address of obj. Be careful not to call it
288.   * when there might be pointers around in unknown places. For now: only
289.   * when obj is in the inventory.
290.   */
291.  STATIC_OVL
292.  void
293.  do_oname(obj)
294.  register struct obj *obj;
295.  {
296.  	char buf[BUFSZ], qbuf[QBUFSZ];
297.  	const char *aname;
298.  	short objtyp;
299.  
300.  	Sprintf(qbuf, "What do you want to name %s?", doname(obj));
301.  	getlin(qbuf, buf);
302.  	if(!*buf || *buf == '\033')	return;
303.  	/* strip leading and trailing spaces; unnames item if all spaces */
304.  	(void)mungspaces(buf);
305.  
306.  	/* relax restrictions over proper capitalization for artifacts */
307.  	if ((aname = artifact_name(buf, &objtyp)) != 0 && objtyp == obj->otyp)
308.  		Strcpy(buf, aname);
309.  
310.  	if (obj->oartifact) {
311.  		pline_The("artifact seems to resist the attempt.");
312.  		return;
313.  	} else if (restrict_name(obj, buf) || exist_artifact(obj->otyp, buf)) {
314.  		int n = rn2((int)strlen(buf));
315.  		register char c1, c2;
316.  
317.  		c1 = lowc(buf[n]);
318.  		do c2 = 'a' + rn2('z'-'a'); while (c1 == c2);
319.  		buf[n] = (buf[n] == c1) ? c2 : highc(c2);  /* keep same case */
320.  		pline("While engraving your %s slips.", body_part(HAND));
321.  		display_nhwindow(WIN_MESSAGE, FALSE);
322.  		You("engrave: \"%s\".",buf);
323.  	}
324.  	obj = oname(obj, buf);
325.  	if (obj->where == OBJ_INVENT)
326.  		update_inventory();
327.  }
328.  
329.  /*
330.   * Allocate a new and possibly larger storage space for an obj.
331.   */
332.  struct obj *
333.  realloc_obj(obj, oextra_size, oextra_src, oname_size, name)
334.  struct obj *obj;
335.  int oextra_size;		/* storage to allocate for oextra            */
336.  genericptr_t oextra_src;
337.  int oname_size;			/* size of name string + 1 (null terminator) */
338.  const char *name;
339.  {
340.  	struct obj *otmp;
341.  
342.  	otmp = newobj(oextra_size + oname_size);
343.  	*otmp = *obj;	/* the cobj pointer is copied to otmp */
344.  	if (oextra_size) {
345.  	    if (oextra_src)
346.  		(void) memcpy((genericptr_t)otmp->oextra, oextra_src,
347.  							oextra_size);
348.  	} else {
349.  	    otmp->oattached = OATTACHED_NOTHING;
350.  	}
351.  	otmp->oxlth = oextra_size;
352.  
353.  	otmp->onamelth = oname_size;
354.  	otmp->timed = 0;	/* not timed, yet */
355.  	otmp->lamplit = 0;	/* ditto */
356.  	/* __GNUC__ note:  if the assignment of otmp->onamelth immediately
357.  	   precedes this `if' statement, a gcc bug will miscompile the
358.  	   test on vax (`insv' instruction used to store bitfield does
359.  	   not set condition codes, but optimizer behaves as if it did).
360.  	   gcc-2.7.2.1 finally fixed this. */
361.  	if (oname_size) {
362.  	    if (name)
363.  		Strcpy(ONAME(otmp), name);
364.  	}
365.  
366.  	if (obj->owornmask) {
367.  		setworn((struct obj *)0, obj->owornmask);
368.  		setworn(otmp, otmp->owornmask);
369.  	}
370.  
371.  	/* replace obj with otmp */
372.  	replace_object(obj, otmp);
373.  
374.  	/* fix ocontainer pointers */
375.  	if (Has_contents(obj)) {
376.  		struct obj *inside;
377.  
378.  		for(inside = obj->cobj; inside; inside = inside->nobj)
379.  			inside->ocontainer = otmp;
380.  	}
381.  
382.  	/* move timers and light sources from obj to otmp */
383.  	if (obj->timed) obj_move_timers(obj, otmp);
384.  	if (obj->lamplit) obj_move_light_source(obj, otmp);
385.  
386.  	/* objects possibly being manipulated by multi-turn occupations
387.  	   which have been interrupted but might be subsequently resumed */
388.  	if (obj->oclass == FOOD_CLASS)
389.  	    food_substitution(obj, otmp);	/* eat food or open tin */
390.  	else if (obj->oclass == SPBOOK_CLASS)
391.  	    book_substitution(obj, otmp);	/* read spellbook */
392.  
393.  	/* obfree(obj, otmp);	now unnecessary: no pointers on bill */
394.  	dealloc_obj(obj);	/* let us hope nobody else saved a pointer */
395.  	return otmp;
396.  }
397.  
398.  struct obj *
399.  oname(obj, name)
400.  struct obj *obj;
401.  const char *name;
402.  {
403.  	int lth;
404.  	char buf[PL_PSIZ];
405.  
406.  	lth = *name ? (int)(strlen(name) + 1) : 0;
407.  	if (lth > PL_PSIZ) {
408.  		lth = PL_PSIZ;
409.  		name = strncpy(buf, name, PL_PSIZ - 1);
410.  		buf[PL_PSIZ - 1] = '\0';
411.  	}
412.  	/* If named artifact exists in the game, do not create another.
413.  	 * Also trying to create an artifact shouldn't de-artifact
414.  	 * it (e.g. Excalibur from prayer). In this case the object
415.  	 * will retain its current name. */
416.  	if (obj->oartifact || (lth && exist_artifact(obj->otyp, name)))
417.  		return obj;
418.  
419.  	if (lth == obj->onamelth) {
420.  		/* no need to replace entire object */
421.  		if (lth) Strcpy(ONAME(obj), name);
422.  	} else {
423.  		obj = realloc_obj(obj, obj->oxlth,
424.  			      (genericptr_t)obj->oextra, lth, name);
425.  	}
426.  	if (lth) artifact_exists(obj, name, TRUE);
427.  	return obj;
428.  }
429.  
430.  static NEARDATA const char callable[] = {
431.  	SCROLL_CLASS, POTION_CLASS, WAND_CLASS, RING_CLASS, AMULET_CLASS,
432.  	GEM_CLASS, SPBOOK_CLASS, ARMOR_CLASS, TOOL_CLASS, 0 };
433.  
434.  int
435.  ddocall()
436.  {
437.  	register struct obj *obj;
438.  #ifdef REDO
439.  	char	ch;
440.  #endif
441.  	char allowall[2];
442.  
443.  	switch(
444.  #ifdef REDO
445.  		ch =
446.  #endif
447.  		ynq("Name an individual object?")) {
448.  	case 'q':
449.  		break;
450.  	case 'y':
451.  #ifdef REDO
452.  		savech(ch);
453.  #endif
454.  		allowall[0] = ALL_CLASSES; allowall[1] = '\0';
455.  		obj = getobj(allowall, "name");
456.  		if(obj) do_oname(obj);
457.  		break;
458.  	default :
459.  #ifdef REDO
460.  		savech(ch);
461.  #endif
462.  		obj = getobj(callable, "call");
463.  		if (obj) {
464.  			if (!obj->dknown) {
465.  				You("would never recognize another one.");
466.  				return 0;
467.  			}
468.  			docall(obj);
469.  		}
470.  		break;
471.  	}
472.  	return 0;
473.  }
474.  
475.  void
476.  docall(obj)
477.  register struct obj *obj;
478.  {
479.  	char buf[BUFSZ], qbuf[QBUFSZ];
480.  	struct obj otemp;
481.  	register char **str1;
482.  
483.  	if (!obj->dknown) return; /* probably blind */
484.  	otemp = *obj;
485.  	otemp.quan = 1L;
486.  	otemp.onamelth = 0;
487.  	otemp.oxlth = 0;
488.  	if (objects[otemp.otyp].oc_class == POTION_CLASS && otemp.corpsenm)
489.  	    /* kludge, meaning it's sink water */
490.  	    Sprintf(qbuf,"Call a stream of %s fluid:",
491.  		    OBJ_DESCR(objects[otemp.otyp]));
492.  	else
493.  	    Sprintf(qbuf, "Call %s:", an(xname(&otemp)));
494.  	getlin(qbuf, buf);
495.  	if(!*buf || *buf == '\033')
496.  		return;
497.  
498.  	/* clear old name */
499.  	str1 = &(objects[obj->otyp].oc_uname);
500.  	if(*str1) free((genericptr_t)*str1);
501.  
502.  	/* strip leading and trailing spaces; uncalls item if all spaces */
503.  	(void)mungspaces(buf);
504.  	if (!*buf) {
505.  	    if (*str1) {	/* had name, so possibly remove from disco[] */
506.  		/* strip name first, for the update_inventory() call
507.  		   from undiscover_object() */
508.  		*str1 = (char *)0;
509.  		undiscover_object(obj->otyp);
510.  	    }
511.  	} else {
512.  	    *str1 = strcpy((char *) alloc((unsigned)strlen(buf)+1), buf);
513.  	    discover_object(obj->otyp, FALSE, TRUE); /* possibly add to disco[] */
514.  	}
515.  }
516.  
517.  #endif /*OVLB*/
518.  #ifdef OVL0
519.  
520.  static const char *ghostnames[] = {
521.  	/* these names should have length < PL_NSIZ */
522.  	/* Capitalize the names for aesthetics -dgk */
523.  	"Adri", "Andries", "Andreas", "Bert", "David", "Dirk", "Emile",
524.  	"Frans", "Fred", "Greg", "Hether", "Jay", "John", "Jon", "Karnov",
525.  	"Kay", "Kenny", "Kevin", "Maud", "Michiel", "Mike", "Peter", "Robert",
526.  	"Ron", "Tom", "Wilmar", "Nick Danger", "Phoenix", "Jiro", "Mizue",
527.  	"Stephan", "Lance Braccus", "Shadowhawk"
528.  };
529.  
530.  /* ghost names formerly set by x_monnam(), now by makemon() instead */
531.  const char *
532.  rndghostname()
533.  {
534.      return rn2(7) ? ghostnames[rn2(SIZE(ghostnames))] : (const char *)plname;
535.  }
536.  
537.  /* Monster naming functions:
538.   * x_monnam is the generic monster-naming function.
539.   *		  seen	      unseen	   detected		  named
540.   * mon_nam:	the newt	it	the invisible orc	Fido
541.   * l_monnam:	newt		it	invisible orc		dog called fido
542.   * Monnam:	The newt	It	The invisible orc	Fido
543.   * Adjmonnam:	The poor newt	It	The poor invisible orc	The poor Fido
544.   * Amonnam:	A newt		It	An invisible orc	Fido
545.   * a_monnam:	a newt		it	an invisible orc	Fido
546.   * m_monnam:	newt		xan	orc			Fido
547.   * y_monnam:	your newt     your xan	your invisible orc	Fido
548.   */
549.  
550.  char *
551.  x_monnam(mtmp, article, adjective, called)
552.  register struct monst *mtmp;
553.  /* Articles:
554.   * 0: "the" in front of everything except names and "it"
555.   * 1: "the" in front of everything except "it"; looks bad for names unless you
556.   *    are also using an adjective.
557.   * 2: "a" in front of everything except "it".
558.   * 3: no article at all.
559.   * 4: no article; "it" and invisible suppressed.
560.   * 5: "your" instead of an article; include "invisible" even when unseen
561.   */
562.  int article, called;
563.  const char *adjective;
564.  {
565.  #ifdef LINT	/* static char buf[BUFSZ]; */
566.  	char buf[BUFSZ];
567.  #else
568.  	static char buf[BUFSZ];
569.  #endif
570.  	struct permonst *mdat = mtmp->data;
571.  	char *name = 0;
572.  	int force_the = 0, trunam = (article == 4), use_your = (article == 5);
573.  
574.  	buf[0] = '\0';
575.  	if (use_your && !mtmp->mtame)
576.  	    use_your = 0,  article = 0;
577.  	if (mtmp->ispriest || mtmp->isminion) {
578.  	    char priestnambuf[BUFSZ];
579.  	    long save_prop = EHalluc_resistance;
580.  
581.  	    /* when true name is wanted, explicitly block Hallucination */
582.  	    if (trunam) EHalluc_resistance = 1L;
583.  	    name = priestname(mtmp, priestnambuf);
584.  	    EHalluc_resistance = save_prop;
585.  	    if ((trunam || article == 3) && !strncmp(name, "the ", 4))
586.  		name += 4;
587.  	    return strcpy(buf, name);
588.  	}
589.  	if (!trunam && !use_your && !canspotmon(mtmp) &&
590.  #ifdef STEED
591.  		(mtmp != u.usteed) &&
592.  #endif
593.  		!(u.uswallow && mtmp == u.ustuck) && !killer) {
594.  	    if (!mon_visible(mtmp) || (!cansee(bhitpos.x,bhitpos.y) &&
595.  !see_with_infrared(mtmp))) {
596.  		Strcpy(buf, "it");
597.  		return  buf;
598.  	    }
599.  	}
600.  	if (trunam || !Hallucination) {
601.  	    if (mtmp->isshk) {
602.  		Strcpy(buf, shkname(mtmp));
603.  		if ((mdat == &mons[PM_SHOPKEEPER] && !mtmp->minvis) || trunam)
604.  		    return buf;
605.  		/* For normal shopkeepers, just 'Asidonhopo'.
606.  		 * For unusual ones, 'Asidonhopo the invisible shopkeeper'
607.  		 * or 'Asidonhopo the blue dragon'.
608.  		 */
609.  		Strcat(buf, " ");
610.  	    } else if (mtmp->mnamelth) {
611.  		name = NAME(mtmp);
612.  		if (mdat == &mons[PM_GHOST]) {
613.  		    called = 0;
614.  		    Sprintf(buf, "%s ghost", s_suffix(name));
615.  		    goto bot_nam;
616.  		}
617.  	    }
618.  	}
619.  
620.  	if (!trunam) {
621.  	    force_the = (!Hallucination &&
622.  			 (mdat == &mons[PM_WIZARD_OF_YENDOR] || mtmp->isshk));
623.  	    if (force_the ||
624.  		    ((article == 1 || ((!name || called) && article == 0)) &&
625.  			(Hallucination || !type_is_pname(mdat))))
626.  		Strcat(buf, "the ");
627.  	    else if (use_your && !name)
628.  		Strcat(buf, "your ");
629.  	    if (adjective)
630.  		Strcat(strcat(buf, adjective), " ");
631.  	    if (mtmp->minvis && !Blind)
632.  		Strcat(buf, "invisible ");
633.  #ifdef STEED
634.  	    if ((mtmp->misc_worn_check & W_SADDLE) &&
635.  			!Blind && (!name || called) && mtmp != u.usteed)
636.  		Strcat(buf, "saddled ");
637.  #endif
638.  	}
639.  
640.  	if (name && !called) {
641.  	    Strcat(buf, name);
642.  	    goto bot_nam;
643.  	}
644.  
645.  	if (Hallucination && !trunam) {
646.  	    Strcat(buf, rndmonnam());
647.  	} else if (is_mplayer(mdat) && !In_endgame(&u.uz)) {
648.  	    char pbuf[BUFSZ];
649.  	    Strcpy(pbuf, rank_of((int)mtmp->m_lev,
650.  				 monsndx(mdat),
651.  				 (boolean)mtmp->female));
652.  	    Strcat(buf, lcase(pbuf));
653.  	} else {
654.  	    Strcat(buf, mdat->mname);
655.  	}
656.  
657.  	if (name) {	/* if we reach here, `name' implies `called' */
658.  	    Strcat(buf, " called ");
659.  	    Strcat(buf, NAME(mtmp));
660.  	}
661.   bot_nam:
662.  	if (article == 2 && !force_the && (!name || called) &&
663.  		(Hallucination || !type_is_pname(mdat)))
664.  	    return an(buf);
665.  	else
666.  	    return buf;
667.  }
668.  
669.  #endif /* OVL0 */
670.  #ifdef OVLB
671.  
672.  char *
673.  l_monnam(mtmp)
674.  register struct monst *mtmp;
675.  {
676.  	return(x_monnam(mtmp, 3, (char *)0, 1));
677.  }
678.  
679.  #endif /* OVLB */
680.  #ifdef OVL0
681.  
682.  char *
683.  mon_nam(mtmp)
684.  register struct monst *mtmp;
685.  {
686.  	return(x_monnam(mtmp, 0, (char *)0, 0));
687.  }
688.  
689.  char *
690.  Monnam(mtmp)
691.  register struct monst *mtmp;
692.  {
693.  	register char *bp = mon_nam(mtmp);
694.  
695.  	*bp = highc(*bp);
696.  	return(bp);
697.  }
698.  
699.  /* monster's own name */
700.  char *
701.  m_monnam(mtmp)
702.  struct monst *mtmp;
703.  {
704.  	char *result;
705.  	unsigned save_invis = mtmp->minvis;
706.  
707.  	mtmp->minvis = 0;  /* affects priestname() as well as x_monnam() */
708.  	result = x_monnam(mtmp, 4, (char *)0, 0);
709.  	mtmp->minvis = save_invis;
710.  	return result;
711.  }
712.  
713.  /* pet name: "your little dog" */
714.  char *
715.  y_monnam(mtmp)
716.  struct monst *mtmp;
717.  {
718.  	return x_monnam(mtmp, 5, (char *)0, 0);
719.  }
720.  
721.  #endif /* OVL0 */
722.  #ifdef OVLB
723.  
724.  char *
725.  Adjmonnam(mtmp, adj)
726.  register struct monst *mtmp;
727.  register const char *adj;
728.  {
729.  	register char *bp = x_monnam(mtmp,1,adj,0);
730.  
731.  	*bp = highc(*bp);
732.  	return(bp);
733.  }
734.  
735.  char *
736.  a_monnam(mtmp)
737.  register struct monst *mtmp;
738.  {
739.  	return x_monnam(mtmp, 2, (char *)0, 0);
740.  }
741.  
742.  char *
743.  Amonnam(mtmp)
744.  register struct monst *mtmp;
745.  {
746.  	register char *bp = a_monnam(mtmp);
747.  
748.  	*bp = highc(*bp);
749.  	return(bp);
750.  }
751.  
752.  static const char *bogusmons[] = {
753.  	"jumbo shrimp", "giant pigmy", "gnu", "killer penguin",
754.  	"giant cockroach", "giant slug", "maggot", "pterodactyl",
755.  	"tyrannosaurus rex", "basilisk", "beholder", "nightmare",
756.  	"efreeti", "marid", "rot grub", "bookworm", "master lichen",
757.  	"shadow", "hologram", "jester", "attorney", "sleazoid",
758.  	"killer tomato", "amazon", "robot", "battlemech",
759.  	"rhinovirus", "harpy", "lion-dog", "rat-ant",
760.  						/* misc. */
761.  	"grue", "Christmas-tree monster", "luck sucker", "paskald",
762.  	"brogmoid", "dornbeast",		/* Quendor (Zork, &c.) */
763.  	"Ancient Multi-Hued Dragon", "Evil Iggy",
764.  						/* Moria */
765.  	"emu", "kestrel", "xeroc", "venus flytrap",
766.  						/* Rogue */
767.  	"creeping coins",			/* Wizardry */
768.  	"hydra", "siren",			/* Greek legend */
769.  	"killer bunny",				/* Monty Python */
770.  	"rodent of unusual size",		/* The Princess Bride */
771.  	"Smokey the bear",	/* "Only you can prevent forest fires!" */
772.  	"Luggage",				/* Discworld */
773.  	"Ent",					/* Lord of the Rings */
774.  	"tangle tree", "nickelpede", "wiggle",	/* Xanth */
775.  	"white rabbit", "snark",		/* Lewis Carroll */
776.  	"pushmi-pullyu",			/* Dr. Doolittle */
777.  	"smurf",				/* The Smurfs */
778.  	"tribble", "Klingon", "Borg",		/* Star Trek */
779.  	"Ewok",					/* Star Wars */
780.  	"Totoro",				/* Tonari no Totoro */
781.  	"ohmu",					/* Nausicaa */
782.  	"youma",				/* Sailor Moon */
783.  	"nyaasu",				/* Pokemon (Meowth) */
784.  	"Godzilla", "King Kong",		/* monster movies */
785.  	"earthquake beast",			/* old L of SH */
786.  	"Invid",				/* Robotech */
787.  	"Terminator",				/* The Terminator */
788.  	"boomer",				/* Bubblegum Crisis */
789.  	"Dalek",				/* Dr. Who ("Exterminate!") */
790.  	"microscopic space fleet", "Ravenous Bugblatter Beast of Traal",
791.  						/* HGttG */
792.  	"teenage mutant ninja turtle",		/* TMNT */
793.  	"samurai rabbit",			/* Usagi Yojimbo */
794.  	"aardvark",				/* Cerebus */
795.  	"Audrey II",				/* Little Shop of Horrors */
796.  	"witch doctor", "one-eyed one-horned flying purple people eater",
797.  						/* 50's rock 'n' roll */
798.  	"Barney the dinosaur",			/* saccharine kiddy TV */
799.  	"Morgoth",				/* Angband */
800.  	"Vorlon",				/* Babylon 5 */
801.  	"questing beast",		/* King Arthur */
802.  	"Predator",				/* Movie */
803.  	"mother-in-law"				/* common pest */
804.  };
805.  
806.  const char *
807.  rndmonnam()	/* Random name of monster type, if hallucinating */
808.  {
809.  	int name;
810.  
811.  	do {
812.  	    name = rn1(SPECIAL_PM + SIZE(bogusmons) - LOW_PM, LOW_PM);
813.  	} while (name < SPECIAL_PM &&
814.  	    (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN)));
815.  
816.  	if (name >= SPECIAL_PM) return bogusmons[name - SPECIAL_PM];
817.  	return mons[name].mname;
818.  }
819.  
820.  const char *pronoun_pairs[][2] = {
821.  	{"him", "her"}, {"Him", "Her"}, {"his", "her"}, {"His", "Her"},
822.  	{"he", "she"}, {"He", "She"},
823.  	{0, 0}
824.  };
825.  
826.  char *
827.  self_pronoun(str, pronoun)
828.  const char *str;
829.  const char *pronoun;
830.  {
831.  	static NEARDATA char buf[BUFSZ];
832.  	register int i;
833.  
834.  	for(i=0; pronoun_pairs[i][0]; i++) {
835.  		if(!strncmp(pronoun, pronoun_pairs[i][0], 3)) {
836.  			Sprintf(buf, str, pronoun_pairs[i][flags.female]);
837.  			return buf;
838.  		}
839.  	}
840.  	impossible("never heard of pronoun %s?", pronoun);
841.  	Sprintf(buf, str, pronoun_pairs[i][0]);
842.  	return buf;
843.  }
844.  
845.  #ifdef REINCARNATION
846.  const char *
847.  roguename() /* Name of a Rogue player */
848.  {
849.  	char *i, *opts;
850.  
851.  	if ((opts = getenv("ROGUEOPTS")) != 0) {
852.  		for (i = opts; *i; i++)
853.  			if (!strncmp("name=",i,5)) {
854.  				char *j;
855.  				if ((j = index(i+5,',')) != 0)
856.  					*j = (char)0;
857.  				return i+5;
858.  			}
859.  	}
860.  	return rn2(3) ? (rn2(2) ? "Michael Toy" : "Kenneth Arnold")
861.  		: "Glenn Wichman";
862.  }
863.  #endif /* REINCARNATION */
864.  #endif /* OVLB */
865.  
866.  #ifdef OVL2
867.  
868.  static NEARDATA const char *hcolors[] = {
869.  	"ultraviolet", "infrared", "bluish-orange",
870.  	"reddish-green", "dark white", "light black", "sky blue-pink",
871.  	"salty", "sweet", "sour", "bitter",
872.  	"striped", "spiral", "swirly", "plaid", "checkered", "argyle",
873.  	"paisley", "blotchy", "guernsey-spotted", "polka-dotted",
874.  	"square", "round", "triangular",
875.  	"cabernet", "sangria", "fuchsia", "wisteria",
876.  	"lemon-lime", "strawberry-banana", "peppermint",
877.  	"romantic", "incandescent"
878.  };
879.  
880.  const char *
881.  hcolor(colorpref)
882.  const char *colorpref;
883.  {
884.  	return (Hallucination || !colorpref) ?
885.  		hcolors[rn2(SIZE(hcolors))] : colorpref;
886.  }
887.  
888.  /* Aliases for road-runner nemesis
889.   * See also http://www.geocities.com/EnchantedForest/1141/latin.html
890.   */

The link above doesn't work anymore, and was removed in 3.4.1. The Wayback Machine has a copy here.

891.  static const char *coynames[] = {
892.  	"Carnivorous Vulgaris","Road-Runnerus Digestus",
893.  	"Eatibus Anythingus"  ,"Famishus-Famishus",
894.  	"Eatibus Almost Anythingus","Eatius Birdius",
895.  	"Famishius Fantasticus","Eternalii Famishiis",
896.  	"Famishus Vulgarus","Famishius Vulgaris Ingeniusi",
897.  	"Eatius-Slobbius","Hardheadipus Oedipus",
898.  	"Carnivorous Slobbius","Hard-Headipus Ravenus",
899.  	"Evereadii Eatibus","Apetitius Giganticus",
900.  	"Hungrii Flea-Bagius","Overconfidentii Vulgaris",
901.  	"Caninus Nervous Rex","Grotesques Appetitus",
902.  	"Nemesis Riduclii","Canis latrans"
903.  };
904.  	
905.  char *coyotename(buf)
906.  char *buf;
907.  {
908.  	if (buf)
909.  		Sprintf(buf,
910.  			"coyote - %s",
911.  			coynames[rn2(SIZE(coynames)-1)]);
912.  	return buf;
913.  }
914.  #endif /* OVL2 */
915.  
916.  /*do_name.c*/