Source:NetHack 3.4.3/src/do name.c

From NetHackWiki
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)do_name.c	3.4	2003/01/14	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

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. #include "hack.h"
  2.  
  3. #ifdef OVLB
  4.  
  5. STATIC_DCL void FDECL(do_oname, (struct obj *));
  6. static void FDECL(getpos_help, (BOOLEAN_P,const char *));
  7.  
  8. extern const char what_is_an_unknown_object[];		/* from pager.c */

getpos_help[edit]

  1. /* the response for '?' help request in getpos() */
  2. static void
  3. getpos_help(force, goal)
  4. boolean force;
  5. const char *goal;
  6. {
  7. char sbuf[BUFSZ];
  8. boolean doing_what_is;
  9. winid tmpwin = create_nhwindow(NHW_MENU);
  10.  
  11. Sprintf(sbuf, "Use [%s] to move the cursor to %s.",
  12. 	    iflags.num_pad ? "2468" : "hjkl", goal);
  13. putstr(tmpwin, 0, sbuf);
  14. putstr(tmpwin, 0, "Use [HJKL] to move the cursor 8 units at a time.");
  15. putstr(tmpwin, 0, "Or enter a background symbol (ex. <).");
  16. /* disgusting hack; the alternate selection characters work for any
  17. getpos call, but they only matter for dowhatis (and doquickwhatis) */
  18. doing_what_is = (goal == what_is_an_unknown_object);
  19. Sprintf(sbuf, "Type a .%s when you are at the right place.",
  20. doing_what_is ? " or , or ; or :" : "");
  21. putstr(tmpwin, 0, sbuf);
  22. if (!force)
  23. 	putstr(tmpwin, 0, "Type Space or Escape when you're done.");
  24. putstr(tmpwin, 0, "");
  25. display_nhwindow(tmpwin, TRUE);
  26. destroy_nhwindow(tmpwin);
  27. }

getpos[edit]

  1. int
  2. getpos(cc, force, goal)
  3. coord *cc;
  4. boolean force;
  5. const char *goal;
  6. {
  7. int result = 0;
  8. int cx, cy, i, c;
  9. int sidx, tx, ty;
  10. boolean msg_given = TRUE;	/* clear message window by default */
  11. static const char pick_chars[] = ".,;:";
  12. const char *cp;
  13. const char *sdp;
  14. if(iflags.num_pad) sdp = ndir; else sdp = sdir;	/* DICE workaround */
  15.  
  16. if (flags.verbose) {
  17. 	pline("(For instructions type a ?)");
  18. 	msg_given = TRUE;
  19. }
  20. cx = cc->x;
  21. cy = cc->y;
  22. #ifdef CLIPPING
  23. cliparound(cx, cy);
  24. #endif
  25. curs(WIN_MAP, cx,cy);
  26. flush_screen(0);
  27. #ifdef MAC
  28. lock_mouse_cursor(TRUE);
  29. #endif
  30. for (;;) {
  31. 	c = nh_poskey(&tx, &ty, &sidx);
  32. 	if (c == '\033') {
  33. 	    cx = cy = -10;
  34. 	    msg_given = TRUE;	/* force clear */
  35. 	    result = -1;
  36. 	    break;
  37. 	}
  38. 	if(c == 0) {
  39. 	    if (!isok(tx, ty)) continue;
  40. 	    /* a mouse click event, just assign and return */
  41. 	    cx = tx;
  42. 	    cy = ty;
  43. 	    break;
  44. 	}
  45. 	if ((cp = index(pick_chars, c)) != 0) {
  46. 	    /* '.' => 0, ',' => 1, ';' => 2, ':' => 3 */
  47. 	    result = cp - pick_chars;
  48. 	    break;
  49. 	}
  50. 	for (i = 0; i < 8; i++) {
  51. 	    int dx, dy;
  52.  
  53. 	    if (sdp[i] == c) {
  54. 		/* a normal movement letter or digit */
  55. 		dx = xdir[i];
  56. 		dy = ydir[i];
  57. 	    } else if (sdir[i] == lowc((char)c)) {
  58. 		/* a shifted movement letter */
  59. 		dx = 8 * xdir[i];
  60. 		dy = 8 * ydir[i];
  61. 	    } else
  62. 		continue;
  63.  
  64. 	    /* truncate at map edge; diagonal moves complicate this... */
  65. 	    if (cx + dx < 1) {
  66. 		dy -= sgn(dy) * (1 - (cx + dx));
  67. 		dx = 1 - cx;		/* so that (cx+dx == 1) */
  68. 	    } else if (cx + dx > COLNO-1) {
  69. 		dy += sgn(dy) * ((COLNO-1) - (cx + dx));
  70. 		dx = (COLNO-1) - cx;
  71. 	    }
  72. 	    if (cy + dy < 0) {
  73. 		dx -= sgn(dx) * (0 - (cy + dy));
  74. 		dy = 0 - cy;		/* so that (cy+dy == 0) */
  75. 	    } else if (cy + dy > ROWNO-1) {
  76. 		dx += sgn(dx) * ((ROWNO-1) - (cy + dy));
  77. 		dy = (ROWNO-1) - cy;
  78. 	    }
  79. 	    cx += dx;
  80. 	    cy += dy;
  81. 	    goto nxtc;
  82. 	}
  83.  
  84. 	if(c == '?'){
  85. 	    getpos_help(force, goal);
  86. 	} else {
  87. 	    if (!index(quitchars, c)) {
  88. 		char matching[MAXPCHARS];
  89. 		int pass, lo_x, lo_y, hi_x, hi_y, k = 0;
  90. 		(void)memset((genericptr_t)matching, 0, sizeof matching);
  91. 		for (sidx = 1; sidx < MAXPCHARS; sidx++)
  92. 		    if (c == defsyms[sidx].sym || c == (int)showsyms[sidx])
  93. 			matching[sidx] = (char) ++k;
  94. 		if (k) {
  95. 		    for (pass = 0; pass <= 1; pass++) {
  96. 			/* pass 0: just past current pos to lower right;
  97. 			   pass 1: upper left corner to current pos */
  98. 			lo_y = (pass == 0) ? cy : 0;
  99. 			hi_y = (pass == 0) ? ROWNO - 1 : cy;
  100. 			for (ty = lo_y; ty <= hi_y; ty++) {
  101. 			    lo_x = (pass == 0 && ty == lo_y) ? cx + 1 : 1;
  102. 			    hi_x = (pass == 1 && ty == hi_y) ? cx : COLNO - 1;
  103. 			    for (tx = lo_x; tx <= hi_x; tx++) {
  104. 				k = levl[tx][ty].glyph;
  105. 				if (glyph_is_cmap(k) &&
  106. 					matching[glyph_to_cmap(k)]) {
  107. 				    cx = tx,  cy = ty;
  108. 				    if (msg_given) {
  109. 					clear_nhwindow(WIN_MESSAGE);
  110. 					msg_given = FALSE;
  111. 				    }
  112. 				    goto nxtc;
  113. 				}
  114. 			    }	/* column */
  115. 			}	/* row */
  116. 		    }		/* pass */
  117. 		    pline("Can't find dungeon feature '%c'.", c);
  118. 		    msg_given = TRUE;
  119. 		    goto nxtc;
  120. 		} else {
  121. 		    pline("Unknown direction: '%s' (%s).",
  122. 			  visctrl((char)c),
  123. 			  !force ? "aborted" :
  124. 			  iflags.num_pad ? "use 2468 or ." : "use hjkl or .");
  125. 		    msg_given = TRUE;
  126. 		} /* k => matching */
  127. 	    } /* !quitchars */
  128. 	    if (force) goto nxtc;
  129. 	    pline("Done.");
  130. 	    msg_given = FALSE;	/* suppress clear */
  131. 	    cx = -1;
  132. 	    cy = 0;
  133. 	    result = 0;	/* not -1 */
  134. 	    break;
  135. 	}
  136. nxtc:	;
  137. #ifdef CLIPPING
  138. 	cliparound(cx, cy);
  139. #endif
  140. 	curs(WIN_MAP,cx,cy);
  141. 	flush_screen(0);
  142. }
  143. #ifdef MAC
  144. lock_mouse_cursor(FALSE);
  145. #endif
  146. if (msg_given) clear_nhwindow(WIN_MESSAGE);
  147. cc->x = cx;
  148. cc->y = cy;
  149. return result;
  150. }

christen_monst[edit]

  1. struct monst *
  2. christen_monst(mtmp, name)
  3. struct monst *mtmp;
  4. const char *name;
  5. {
  6. 	int lth;
  7. 	struct monst *mtmp2;
  8. 	char buf[PL_PSIZ];
  9.  
  10. 	/* dogname & catname are PL_PSIZ arrays; object names have same limit */
  11. 	lth = *name ? (int)(strlen(name) + 1) : 0;
  12. 	if(lth > PL_PSIZ){
  13. 		lth = PL_PSIZ;
  14. 		name = strncpy(buf, name, PL_PSIZ - 1);
  15. 		buf[PL_PSIZ - 1] = '\0';
  16. 	}
  17. 	if (lth == mtmp->mnamelth) {
  18. 		/* don't need to allocate a new monst struct */
  19. 		if (lth) Strcpy(NAME(mtmp), name);
  20. 		return mtmp;
  21. 	}
  22. 	mtmp2 = newmonst(mtmp->mxlth + lth);
  23. 	*mtmp2 = *mtmp;
  24. 	(void) memcpy((genericptr_t)mtmp2->mextra,
  25. 		      (genericptr_t)mtmp->mextra, mtmp->mxlth);
  26. 	mtmp2->mnamelth = lth;
  27. 	if (lth) Strcpy(NAME(mtmp2), name);
  28. 	replmon(mtmp,mtmp2);
  29. 	return(mtmp2);
  30. }

do_mname[edit]

  1. int
  2. do_mname()
  3. {
  4. 	char buf[BUFSZ];
  5. 	coord cc;
  6. 	register int cx,cy;
  7. 	register struct monst *mtmp;
  8. 	char qbuf[QBUFSZ];
  9.  
  10. 	if (Hallucination) {
  11. 		You("would never recognize it anyway.");
  12. 		return 0;
  13. 	}
  14. 	cc.x = u.ux;
  15. 	cc.y = u.uy;
  16. 	if (getpos(&cc, FALSE, "the monster you want to name") < 0 ||
  17. 			(cx = cc.x) < 0)
  18. 		return 0;
  19. 	cy = cc.y;
  20.  
  21. 	if (cx == u.ux && cy == u.uy) {
  22. #ifdef STEED
  23. 	    if (u.usteed && canspotmon(u.usteed))
  24. 		mtmp = u.usteed;
  25. 	    else {
  26. #endif
  27. 		pline("This %s creature is called %s and cannot be renamed.",
  28. 		ACURR(A_CHA) > 14 ?
  29. 		(flags.female ? "beautiful" : "handsome") :
  30. 		"ugly",
  31. 		plname);
  32. 		return(0);
  33. #ifdef STEED
  34. 	    }
  35. #endif
  36. 	} else
  37. 	    mtmp = m_at(cx, cy);
  38.  
  39. 	if (!mtmp || (!sensemon(mtmp) &&
  40. 			(!(cansee(cx,cy) || see_with_infrared(mtmp)) || mtmp->mundetected
  41. 			|| mtmp->m_ap_type == M_AP_FURNITURE
  42. 			|| mtmp->m_ap_type == M_AP_OBJECT
  43. 			|| (mtmp->minvis && !See_invisible)))) {
  44. 		pline("I see no monster there.");
  45. 		return(0);
  46. 	}
  47. 	/* special case similar to the one in lookat() */
  48. 	(void) distant_monnam(mtmp, ARTICLE_THE, buf);
  49. 	Sprintf(qbuf, "What do you want to call %s?", buf);
  50. 	getlin(qbuf,buf);
  51. 	if(!*buf || *buf == '\033') return(0);
  52. 	/* strip leading and trailing spaces; unnames monster if all spaces */
  53. 	(void)mungspaces(buf);
  54.  
  55. 	if (mtmp->data->geno & G_UNIQ)
  56. 	    pline("%s doesn't like being called names!", Monnam(mtmp));
  57. 	else
  58. 	    (void) christen_monst(mtmp, buf);
  59. 	return(0);
  60. }

do_oname[edit]

  1. /*
  2. * This routine changes the address of obj. Be careful not to call it
  3. * when there might be pointers around in unknown places. For now: only
  4. * when obj is in the inventory.
  5. */
  6. STATIC_OVL
  7. void
  8. do_oname(obj)
  9. register struct obj *obj;
  10. {
  11. 	char buf[BUFSZ], qbuf[QBUFSZ];
  12. 	const char *aname;
  13. 	short objtyp;
  14.  
  15. 	Sprintf(qbuf, "What do you want to name %s %s?",
  16. 		is_plural(obj) ? "these" : "this", xname(obj));
  17. 	getlin(qbuf, buf);
  18. 	if(!*buf || *buf == '\033')	return;
  19. 	/* strip leading and trailing spaces; unnames item if all spaces */
  20. 	(void)mungspaces(buf);
  21.  
  22. 	/* relax restrictions over proper capitalization for artifacts */
  23. 	if ((aname = artifact_name(buf, &objtyp)) != 0 && objtyp == obj->otyp)
  24. 		Strcpy(buf, aname);
  25.  
  26. 	if (obj->oartifact) {
  27. 		pline_The("artifact seems to resist the attempt.");
  28. 		return;
  29. 	} else if (restrict_name(obj, buf) || exist_artifact(obj->otyp, buf)) {

The above test is the source of the artifact name bug. restrict_name will return TRUE if the basetype+name match an artifact. (exist_artifact is used to prevent the player from generating Sting multiple times.)

  1. 		int n = rn2((int)strlen(buf));
  2. 		register char c1, c2;
  3.  
  4. 		c1 = lowc(buf[n]);
  5. 		do c2 = 'a' + rn2('z'-'a'); while (c1 == c2);
  6. 		buf[n] = (buf[n] == c1) ? c2 : highc(c2);  /* keep same case */
  7. 		pline("While engraving your %s slips.", body_part(HAND));
  8. 		display_nhwindow(WIN_MESSAGE, FALSE);
  9. 		You("engrave: \"%s\".",buf);
  10. 	}
  11. 	obj = oname(obj, buf);
  12. }

realloc_obj[edit]

  1. /*
  2. * Allocate a new and possibly larger storage space for an obj.
  3. */
  4. struct obj *
  5. realloc_obj(obj, oextra_size, oextra_src, oname_size, name)
  6. struct obj *obj;
  7. int oextra_size;		/* storage to allocate for oextra            */
  8. genericptr_t oextra_src;
  9. int oname_size;			/* size of name string + 1 (null terminator) */
  10. const char *name;
  11. {
  12. 	struct obj *otmp;
  13.  
  14. 	otmp = newobj(oextra_size + oname_size);
  15. 	*otmp = *obj;	/* the cobj pointer is copied to otmp */
  16. 	if (oextra_size) {
  17. 	    if (oextra_src)
  18. 		(void) memcpy((genericptr_t)otmp->oextra, oextra_src,
  19. 							oextra_size);
  20. 	} else {
  21. 	    otmp->oattached = OATTACHED_NOTHING;
  22. 	}
  23. 	otmp->oxlth = oextra_size;
  24.  
  25. 	otmp->onamelth = oname_size;
  26. 	otmp->timed = 0;	/* not timed, yet */
  27. 	otmp->lamplit = 0;	/* ditto */
  28. 	/* __GNUC__ note:  if the assignment of otmp->onamelth immediately
  29. 	   precedes this `if' statement, a gcc bug will miscompile the
  30. 	   test on vax (`insv' instruction used to store bitfield does
  31. 	   not set condition codes, but optimizer behaves as if it did).
  32. 	   gcc-2.7.2.1 finally fixed this. */
  33. 	if (oname_size) {
  34. 	    if (name)
  35. 		Strcpy(ONAME(otmp), name);
  36. 	}
  37.  
  38. 	if (obj->owornmask) {
  39. 		boolean save_twoweap = u.twoweap;
  40. 		/* unwearing the old instance will clear dual-wield mode
  41. 		   if this object is either of the two weapons */
  42. 		setworn((struct obj *)0, obj->owornmask);
  43. 		setworn(otmp, otmp->owornmask);
  44. 		u.twoweap = save_twoweap;
  45. 	}
  46.  
  47. 	/* replace obj with otmp */
  48. 	replace_object(obj, otmp);
  49.  
  50. 	/* fix ocontainer pointers */
  51. 	if (Has_contents(obj)) {
  52. 		struct obj *inside;
  53.  
  54. 		for(inside = obj->cobj; inside; inside = inside->nobj)
  55. 			inside->ocontainer = otmp;
  56. 	}
  57.  
  58. 	/* move timers and light sources from obj to otmp */
  59. 	if (obj->timed) obj_move_timers(obj, otmp);
  60. 	if (obj->lamplit) obj_move_light_source(obj, otmp);
  61.  
  62. 	/* objects possibly being manipulated by multi-turn occupations
  63. 	   which have been interrupted but might be subsequently resumed */
  64. 	if (obj->oclass == FOOD_CLASS)
  65. 	    food_substitution(obj, otmp);	/* eat food or open tin */
  66. 	else if (obj->oclass == SPBOOK_CLASS)
  67. 	    book_substitution(obj, otmp);	/* read spellbook */
  68.  
  69. 	/* obfree(obj, otmp);	now unnecessary: no pointers on bill */
  70. 	dealloc_obj(obj);	/* let us hope nobody else saved a pointer */
  71. 	return otmp;
  72. }

oname[edit]

  1. struct obj *
  2. oname(obj, name)
  3. struct obj *obj;
  4. const char *name;
  5. {
  6. 	int lth;
  7. 	char buf[PL_PSIZ];
  8.  
  9. 	lth = *name ? (int)(strlen(name) + 1) : 0;
  10. 	if (lth > PL_PSIZ) {
  11. 		lth = PL_PSIZ;
  12. 		name = strncpy(buf, name, PL_PSIZ - 1);
  13. 		buf[PL_PSIZ - 1] = '\0';
  14. 	}
  15. 	/* If named artifact exists in the game, do not create another.
  16. 	 * Also trying to create an artifact shouldn't de-artifact
  17. 	 * it (e.g. Excalibur from prayer). In this case the object
  18. 	 * will retain its current name. */
  19. 	if (obj->oartifact || (lth && exist_artifact(obj->otyp, name)))
  20. 		return obj;
  21.  
  22. 	if (lth == obj->onamelth) {
  23. 		/* no need to replace entire object */
  24. 		if (lth) Strcpy(ONAME(obj), name);
  25. 	} else {
  26. 		obj = realloc_obj(obj, obj->oxlth,
  27. 			      (genericptr_t)obj->oextra, lth, name);
  28. 	}
  29. 	if (lth) artifact_exists(obj, name, TRUE);
  30. 	if (obj->oartifact) {
  31. 	    /* can't dual-wield with artifact as secondary weapon */
  32. 	    if (obj == uswapwep) untwoweapon();
  33. 	    /* activate warning if you've just named your weapon "Sting" */
  34. 	    if (obj == uwep) set_artifact_intrinsic(obj, TRUE, W_WEP);
  35. 	}
  36. 	if (carried(obj)) update_inventory();
  37. 	return obj;
  38. }

ddocall[edit]

  1. static NEARDATA const char callable[] = {
  2. 	SCROLL_CLASS, POTION_CLASS, WAND_CLASS, RING_CLASS, AMULET_CLASS,
  3. 	GEM_CLASS, SPBOOK_CLASS, ARMOR_CLASS, TOOL_CLASS, 0 };
  4.  
  5. int
  6. ddocall()
  7. {
  8. 	register struct obj *obj;
  9. #ifdef REDO
  10. 	char	ch;
  11. #endif
  12. 	char allowall[2];
  13.  
  14. 	switch(
  15. #ifdef REDO
  16. 		ch =
  17. #endif
  18. 		ynq("Name an individual object?")) {
  19. 	case 'q':
  20. 		break;
  21. 	case 'y':
  22. #ifdef REDO
  23. 		savech(ch);
  24. #endif
  25. 		allowall[0] = ALL_CLASSES; allowall[1] = '\0';
  26. 		obj = getobj(allowall, "name");
  27. 		if(obj) do_oname(obj);
  28. 		break;
  29. 	default :
  30. #ifdef REDO
  31. 		savech(ch);
  32. #endif
  33. 		obj = getobj(callable, "call");
  34. 		if (obj) {
  35. 			/* behave as if examining it in inventory;
  36. 			   this might set dknown if it was picked up
  37. 			   while blind and the hero can now see */
  38. 			(void) xname(obj);
  39.  
  40. 			if (!obj->dknown) {
  41. 				You("would never recognize another one.");
  42. 				return 0;
  43. 			}
  44. 			docall(obj);
  45. 		}
  46. 		break;
  47. 	}
  48. 	return 0;
  49. }

docall[edit]

  1. void
  2. docall(obj)
  3. register struct obj *obj;
  4. {
  5. 	char buf[BUFSZ], qbuf[QBUFSZ];
  6. 	struct obj otemp;
  7. 	register char **str1;
  8.  
  9. 	if (!obj->dknown) return; /* probably blind */
  10. 	otemp = *obj;
  11. 	otemp.quan = 1L;
  12. 	otemp.onamelth = 0;
  13. 	otemp.oxlth = 0;
  14. 	if (objects[otemp.otyp].oc_class == POTION_CLASS && otemp.fromsink)
  15. 	    /* kludge, meaning it's sink water */
  16. 	    Sprintf(qbuf,"Call a stream of %s fluid:",
  17. 		    OBJ_DESCR(objects[otemp.otyp]));
  18. 	else
  19. 	    Sprintf(qbuf, "Call %s:", an(xname(&otemp)));
  20. 	getlin(qbuf, buf);
  21. 	if(!*buf || *buf == '\033')
  22. 		return;
  23.  
  24. 	/* clear old name */
  25. 	str1 = &(objects[obj->otyp].oc_uname);
  26. 	if(*str1) free((genericptr_t)*str1);
  27.  
  28. 	/* strip leading and trailing spaces; uncalls item if all spaces */
  29. 	(void)mungspaces(buf);
  30. 	if (!*buf) {
  31. 	    if (*str1) {	/* had name, so possibly remove from disco[] */
  32. 		/* strip name first, for the update_inventory() call
  33. 		   from undiscover_object() */
  34. 		*str1 = (char *)0;
  35. 		undiscover_object(obj->otyp);
  36. 	    }
  37. 	} else {
  38. 	    *str1 = strcpy((char *) alloc((unsigned)strlen(buf)+1), buf);
  39. 	    discover_object(obj->otyp, FALSE, TRUE); /* possibly add to disco[] */
  40. 	}
  41. }
  42.  
  43. #endif /*OVLB*/

rndghostname[edit]

  1. #ifdef OVL0
  2.  
  3. static const char * const ghostnames[] = {
  4. 	/* these names should have length < PL_NSIZ */
  5. 	/* Capitalize the names for aesthetics -dgk */
  6. 	"Adri", "Andries", "Andreas", "Bert", "David", "Dirk", "Emile",
  7. 	"Frans", "Fred", "Greg", "Hether", "Jay", "John", "Jon", "Karnov",
  8. 	"Kay", "Kenny", "Kevin", "Maud", "Michiel", "Mike", "Peter", "Robert",
  9. 	"Ron", "Tom", "Wilmar", "Nick Danger", "Phoenix", "Jiro", "Mizue",
  10. 	"Stephan", "Lance Braccus", "Shadowhawk"
  11. };
  12.  
  13. /* ghost names formerly set by x_monnam(), now by makemon() instead */
  14. const char *
  15. rndghostname()
  16. {
  17. return rn2(7) ? ghostnames[rn2(SIZE(ghostnames))] : (const char *)plname;
  18. }

Monster naming functions[edit]

  1. /* Monster naming functions:
  2. * x_monnam is the generic monster-naming function.
  3. *		  seen	      unseen	   detected		  named
  4. * mon_nam:	the newt	it	the invisible orc	Fido
  5. * noit_mon_nam:the newt (as if detected) the invisible orc	Fido
  6. * l_monnam:	newt		it	invisible orc		dog called fido
  7. * Monnam:	The newt	It	The invisible orc	Fido
  8. * noit_Monnam: The newt (as if detected) The invisible orc	Fido
  9. * Adjmonnam:	The poor newt	It	The poor invisible orc	The poor Fido
  10. * Amonnam:	A newt		It	An invisible orc	Fido
  11. * a_monnam:	a newt		it	an invisible orc	Fido
  12. * m_monnam:	newt		xan	orc			Fido
  13. * y_monnam:	your newt     your xan	your invisible orc	Fido
  14. */
  15.  
  16. /* Bug: if the monster is a priest or shopkeeper, not every one of these
  17. * options works, since those are special cases.
  18. */

x_monnam[edit]

  1. char *
  2. x_monnam(mtmp, article, adjective, suppress, called)
  3. register struct monst *mtmp;
  4. int article;
  5. /* ARTICLE_NONE, ARTICLE_THE, ARTICLE_A: obvious
  6. * ARTICLE_YOUR: "your" on pets, "the" on everything else
  7. *
  8. * If the monster would be referred to as "it" or if the monster has a name
  9. * _and_ there is no adjective, "invisible", "saddled", etc., override this
  10. * and always use no article.
  11. */
  12. const char *adjective;
  13. int suppress;
  14. /* SUPPRESS_IT, SUPPRESS_INVISIBLE, SUPPRESS_HALLUCINATION, SUPPRESS_SADDLE.
  15. * EXACT_NAME: combination of all the above
  16. */
  17. boolean called;
  18. {
  19. #ifdef LINT	/* static char buf[BUFSZ]; */
  20. 	char buf[BUFSZ];
  21. #else
  22. 	static char buf[BUFSZ];
  23. #endif
  24. 	struct permonst *mdat = mtmp->data;
  25. 	boolean do_hallu, do_invis, do_it, do_saddle;
  26. 	boolean name_at_start, has_adjectives;
  27. 	char *bp;
  28.  
  29. 	if (program_state.gameover)
  30. 	    suppress |= SUPPRESS_HALLUCINATION;
  31. 	if (article == ARTICLE_YOUR && !mtmp->mtame)
  32. 	    article = ARTICLE_THE;
  33.  
  34. 	do_hallu = Hallucination && !(suppress & SUPPRESS_HALLUCINATION);
  35. 	do_invis = mtmp->minvis && !(suppress & SUPPRESS_INVISIBLE);
  36. 	do_it = !canspotmon(mtmp) && 
  37. 	    article != ARTICLE_YOUR &&
  38. 	    !program_state.gameover &&
  39. #ifdef STEED
  40. 	    mtmp != u.usteed &&
  41. #endif
  42. 	    !(u.uswallow && mtmp == u.ustuck) &&
  43. 	    !(suppress & SUPPRESS_IT);
  44. 	do_saddle = !(suppress & SUPPRESS_SADDLE);
  45.  
  46. 	buf[0] = 0;
  47.  
  48. 	/* unseen monsters, etc.  Use "it" */
  49. 	if (do_it) {
  50. 	    Strcpy(buf, "it");
  51. 	    return buf;
  52. 	}
  53.  
  54. 	/* priests and minions: don't even use this function */
  55. 	if (mtmp->ispriest || mtmp->isminion) {
  56. 	    char priestnambuf[BUFSZ];
  57. 	    char *name;
  58. 	    long save_prop = EHalluc_resistance;
  59. 	    unsigned save_invis = mtmp->minvis;
  60.  
  61. 	    /* when true name is wanted, explicitly block Hallucination */
  62. 	    if (!do_hallu) EHalluc_resistance = 1L;
  63. 	    if (!do_invis) mtmp->minvis = 0;
  64. 	    name = priestname(mtmp, priestnambuf);
  65. 	    EHalluc_resistance = save_prop;
  66. 	    mtmp->minvis = save_invis;
  67. 	    if (article == ARTICLE_NONE && !strncmp(name, "the ", 4))
  68. 		name += 4;
  69. 	    return strcpy(buf, name);
  70. 	}
  71.  
  72. 	/* Shopkeepers: use shopkeeper name.  For normal shopkeepers, just
  73. 	 * "Asidonhopo"; for unusual ones, "Asidonhopo the invisible
  74. 	 * shopkeeper" or "Asidonhopo the blue dragon".  If hallucinating,
  75. 	 * none of this applies.
  76. 	 */
  77. 	if (mtmp->isshk && !do_hallu) {
  78. 	    if (adjective && article == ARTICLE_THE) {
  79. 		/* pathological case: "the angry Asidonhopo the blue dragon"
  80. 		   sounds silly */
  81. 		Strcpy(buf, "the ");
  82. 		Strcat(strcat(buf, adjective), " ");
  83. 		Strcat(buf, shkname(mtmp));
  84. 		return buf;
  85. 	    }
  86. 	    Strcat(buf, shkname(mtmp));
  87. 	    if (mdat == &mons[PM_SHOPKEEPER] && !do_invis)
  88. 		return buf;
  89. 	    Strcat(buf, " the ");
  90. 	    if (do_invis)
  91. 		Strcat(buf, "invisible ");
  92. 	    Strcat(buf, mdat->mname);
  93. 	    return buf;
  94. 	}
  95.  
  96. 	/* Put the adjectives in the buffer */
  97. 	if (adjective)
  98. 	    Strcat(strcat(buf, adjective), " ");
  99. 	if (do_invis)
  100. 	    Strcat(buf, "invisible ");
  101. #ifdef STEED
  102. 	if (do_saddle && (mtmp->misc_worn_check & W_SADDLE) &&
  103. 	    !Blind && !Hallucination)
  104. 	    Strcat(buf, "saddled ");
  105. #endif
  106. 	if (buf[0] != 0)
  107. 	    has_adjectives = TRUE;
  108. 	else
  109. 	    has_adjectives = FALSE;
  110.  
  111. 	/* Put the actual monster name or type into the buffer now */
  112. 	/* Be sure to remember whether the buffer starts with a name */
  113. 	if (do_hallu) {
  114. 	    Strcat(buf, rndmonnam());
  115. 	    name_at_start = FALSE;
  116. 	} else if (mtmp->mnamelth) {
  117. 	    char *name = NAME(mtmp);
  118.  
  119. 	    if (mdat == &mons[PM_GHOST]) {
  120. 		Sprintf(eos(buf), "%s ghost", s_suffix(name));
  121. 		name_at_start = TRUE;
  122. 	    } else if (called) {
  123. 		Sprintf(eos(buf), "%s called %s", mdat->mname, name);
  124. 		name_at_start = (boolean)type_is_pname(mdat);
  125. 	    } else if (is_mplayer(mdat) && (bp = strstri(name, " the ")) != 0) {
  126. 		/* <name> the <adjective> <invisible> <saddled> <rank> */
  127. 		char pbuf[BUFSZ];
  128.  
  129. 		Strcpy(pbuf, name);
  130. 		pbuf[bp - name + 5] = '\0'; /* adjectives right after " the " */
  131. 		if (has_adjectives)
  132. 		    Strcat(pbuf, buf);
  133. 		Strcat(pbuf, bp + 5);	/* append the rest of the name */
  134. 		Strcpy(buf, pbuf);
  135. 		article = ARTICLE_NONE;
  136. 		name_at_start = TRUE;
  137. 	    } else {
  138. 		Strcat(buf, name);
  139. 		name_at_start = TRUE;
  140. 	    }
  141. 	} else if (is_mplayer(mdat) && !In_endgame(&u.uz)) {
  142. 	    char pbuf[BUFSZ];
  143. 	    Strcpy(pbuf, rank_of((int)mtmp->m_lev,
  144. 				 monsndx(mdat),
  145. 				 (boolean)mtmp->female));
  146. 	    Strcat(buf, lcase(pbuf));
  147. 	    name_at_start = FALSE;
  148. 	} else {
  149. 	    Strcat(buf, mdat->mname);
  150. 	    name_at_start = (boolean)type_is_pname(mdat);
  151. 	}
  152.  
  153. 	if (name_at_start && (article == ARTICLE_YOUR || !has_adjectives)) {
  154. 	    if (mdat == &mons[PM_WIZARD_OF_YENDOR])
  155. 		article = ARTICLE_THE;
  156. 	    else
  157. 		article = ARTICLE_NONE;
  158. 	} else if ((mdat->geno & G_UNIQ) && article == ARTICLE_A) {
  159. 	    article = ARTICLE_THE;
  160. 	}
  161.  
  162. 	{
  163. 	    char buf2[BUFSZ];
  164.  
  165. 	    switch(article) {
  166. 		case ARTICLE_YOUR:
  167. 		    Strcpy(buf2, "your ");
  168. 		    Strcat(buf2, buf);
  169. 		    Strcpy(buf, buf2);
  170. 		    return buf;
  171. 		case ARTICLE_THE:
  172. 		    Strcpy(buf2, "the ");
  173. 		    Strcat(buf2, buf);
  174. 		    Strcpy(buf, buf2);
  175. 		    return buf;
  176. 		case ARTICLE_A:
  177. 		    return(an(buf));
  178. 		case ARTICLE_NONE:
  179. 		default:
  180. 		    return buf;
  181. 	    }
  182. 	}
  183. }
  184.  
  185. #endif /* OVL0 */

l_monnam[edit]

  1. #ifdef OVLB
  2.  
  3. char *
  4. l_monnam(mtmp)
  5. register struct monst *mtmp;
  6. {
  7. 	return(x_monnam(mtmp, ARTICLE_NONE, (char *)0, 
  8. 		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, TRUE));
  9. }
  10.  
  11. #endif /* OVLB */

mon_nam[edit]

  1. #ifdef OVL0
  2.  
  3. char *
  4. mon_nam(mtmp)
  5. register struct monst *mtmp;
  6. {
  7. 	return(x_monnam(mtmp, ARTICLE_THE, (char *)0,
  8. 		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, FALSE));
  9. }

noit_mon_nam[edit]

  1. /* print the name as if mon_nam() was called, but assume that the player
  2. * can always see the monster--used for probing and for monsters aggravating
  3. * the player with a cursed potion of invisibility
  4. */
  5. char *
  6. noit_mon_nam(mtmp)
  7. register struct monst *mtmp;
  8. {
  9. 	return(x_monnam(mtmp, ARTICLE_THE, (char *)0,
  10. 		mtmp->mnamelth ? (SUPPRESS_SADDLE|SUPPRESS_IT) :
  11. 		    SUPPRESS_IT, FALSE));
  12. }

Monnam[edit]

  1. char *
  2. Monnam(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	register char *bp = mon_nam(mtmp);
  6.  
  7. 	*bp = highc(*bp);
  8. 	return(bp);
  9. }

Monnam() returns a capitalized monster name for monster mtmp:

  • The newt - seen monster
  • It - unseen monster
  • The invisible orc - detected monster
  • Fido - called monster

noit_Monnam[edit]

  1. char *
  2. noit_Monnam(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	register char *bp = noit_mon_nam(mtmp);
  6.  
  7. 	*bp = highc(*bp);
  8. 	return(bp);
  9. }

m_monnam[edit]

  1. /* monster's own name */
  2. char *
  3. m_monnam(mtmp)
  4. struct monst *mtmp;
  5. {
  6. 	return x_monnam(mtmp, ARTICLE_NONE, (char *)0, EXACT_NAME, FALSE);
  7. }

y_monnam[edit]

  1. /* pet name: "your little dog" */
  2. char *
  3. y_monnam(mtmp)
  4. struct monst *mtmp;
  5. {
  6. 	int prefix, suppression_flag;
  7.  
  8. 	prefix = mtmp->mtame ? ARTICLE_YOUR : ARTICLE_THE;
  9. 	suppression_flag = (mtmp->mnamelth
  10. #ifdef STEED
  11. 			    /* "saddled" is redundant when mounted */
  12. 			    || mtmp == u.usteed
  13. #endif
  14. 			    ) ? SUPPRESS_SADDLE : 0;
  15.  
  16. 	return x_monnam(mtmp, prefix, (char *)0, suppression_flag, FALSE);
  17. }
  18.  
  19. #endif /* OVL0 */

Adjmonnam[edit]

  1. #ifdef OVLB
  2.  
  3. char *
  4. Adjmonnam(mtmp, adj)
  5. register struct monst *mtmp;
  6. register const char *adj;
  7. {
  8. 	register char *bp = x_monnam(mtmp, ARTICLE_THE, adj,
  9. 		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, FALSE);
  10.  
  11. 	*bp = highc(*bp);
  12. 	return(bp);
  13. }

a_monnam[edit]

  1. char *
  2. a_monnam(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	return x_monnam(mtmp, ARTICLE_A, (char *)0,
  6. 		mtmp->mnamelth ? SUPPRESS_SADDLE : 0, FALSE);
  7. }

Amonnam[edit]

  1. char *
  2. Amonnam(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	register char *bp = a_monnam(mtmp);
  6.  
  7. 	*bp = highc(*bp);
  8. 	return(bp);
  9. }

distant_monnam[edit]

  1. /* used for monster ID by the '/', ';', and 'C' commands to block remote
  2. identification of the endgame altars via their attending priests */
  3. char *
  4. distant_monnam(mon, article, outbuf)
  5. struct monst *mon;
  6. int article;	/* only ARTICLE_NONE and ARTICLE_THE are handled here */
  7. char *outbuf;
  8. {
  9. /* high priest(ess)'s identity is concealed on the Astral Plane,
  10. unless you're adjacent (overridden for hallucination which does
  11. its own obfuscation) */
  12. if (mon->data == &mons[PM_HIGH_PRIEST] && !Hallucination &&
  13. 	    Is_astralevel(&u.uz) && distu(mon->mx, mon->my) > 2) {
  14. 	Strcpy(outbuf, article == ARTICLE_THE ? "the " : "");
  15. 	Strcat(outbuf, mon->female ? "high priestess" : "high priest");
  16. } else {
  17. 	Strcpy(outbuf, x_monnam(mon, article, (char *)0, 0, TRUE));
  18. }
  19. return outbuf;
  20. }

Hallucinatory monster names[edit]

  1. static const char * const bogusmons[] = {
  2. 	"jumbo shrimp", "giant pigmy", "gnu", "killer penguin",
  3. 	"giant cockroach", "giant slug", "maggot", "pterodactyl",
  4. 	"tyrannosaurus rex", "basilisk", "beholder", "nightmare",
  5. 	"efreeti", "marid", "rot grub", "bookworm", "master lichen",
  6. 	"shadow", "hologram", "jester", "attorney", "sleazoid",
  7. 	"killer tomato", "amazon", "robot", "battlemech",
  8. 	"rhinovirus", "harpy", "lion-dog", "rat-ant", "Y2K bug",
  9. 						/* misc. */
  10. 	"grue", "Christmas-tree monster", "luck sucker", "paskald",
  11. 	"brogmoid", "dornbeast",		/* Quendor (Zork, &c.) */
  12. 	"Ancient Multi-Hued Dragon", "Evil Iggy",
  13. 						/* Moria */
  14. 	"emu", "kestrel", "xeroc", "venus flytrap",
  15. 						/* Rogue */
  16. 	"creeping coins",			/* Wizardry */
  17. 	"hydra", "siren",			/* Greek legend */
  18. 	"killer bunny",				/* Monty Python */
  19. 	"rodent of unusual size",		/* The Princess Bride */
  20. 	"Smokey the bear",	/* "Only you can prevent forest fires!" */
  21. 	"Luggage",				/* Discworld */
  22. 	"Ent",					/* Lord of the Rings */
  23. 	"tangle tree", "nickelpede", "wiggle",	/* Xanth */
  24. 	"white rabbit", "snark",		/* Lewis Carroll */
  25. 	"pushmi-pullyu",			/* Dr. Doolittle */
  26. 	"smurf",				/* The Smurfs */
  27. 	"tribble", "Klingon", "Borg",		/* Star Trek */
  28. 	"Ewok",					/* Star Wars */
  29. 	"Totoro",				/* Tonari no Totoro */
  30. 	"ohmu",					/* Nausicaa */
  31. 	"youma",				/* Sailor Moon */
  32. 	"nyaasu",				/* Pokemon (Meowth) */
  33. 	"Godzilla", "King Kong",		/* monster movies */
  34. 	"earthquake beast",			/* old L of SH */
  35. 	"Invid",				/* Robotech */
  36. 	"Terminator",				/* The Terminator */
  37. 	"boomer",				/* Bubblegum Crisis */
  38. 	"Dalek",				/* Dr. Who ("Exterminate!") */
  39. 	"microscopic space fleet", "Ravenous Bugblatter Beast of Traal",
  40. 						/* HGttG */
  41. 	"teenage mutant ninja turtle",		/* TMNT */
  42. 	"samurai rabbit",			/* Usagi Yojimbo */
  43. 	"aardvark",				/* Cerebus */
  44. 	"Audrey II",				/* Little Shop of Horrors */
  45. 	"witch doctor", "one-eyed one-horned flying purple people eater",
  46. 						/* 50's rock 'n' roll */
  47. 	"Barney the dinosaur",			/* saccharine kiddy TV */
  48. 	"Morgoth",				/* Angband */
  49. 	"Vorlon",				/* Babylon 5 */
  50. 	"questing beast",		/* King Arthur */
  51. 	"Predator",				/* Movie */
  52. 	"mother-in-law"				/* common pest */
  53. };

rndmonnam[edit]

  1. /* Return a random monster name, for hallucination.
  2. * KNOWN BUG: May be a proper name (Godzilla, Barney), may not
  3. * (the Terminator, a Dalek).  There's no elegant way to deal
  4. * with this without radically modifying the calling functions.
  5. */
  6. const char *
  7. rndmonnam()
  8. {
  9. 	int name;
  10.  
  11. 	do {
  12. 	    name = rn1(SPECIAL_PM + SIZE(bogusmons) - LOW_PM, LOW_PM);
  13. 	} while (name < SPECIAL_PM &&
  14. 	    (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN)));
  15.  
  16. 	if (name >= SPECIAL_PM) return bogusmons[name - SPECIAL_PM];
  17. 	return mons[name].mname;
  18. }

roguename[edit]

  1. #ifdef REINCARNATION
  2. const char *
  3. roguename() /* Name of a Rogue player */
  4. {
  5. 	char *i, *opts;
  6.  
  7. 	if ((opts = nh_getenv("ROGUEOPTS")) != 0) {
  8. 		for (i = opts; *i; i++)
  9. 			if (!strncmp("name=",i,5)) {
  10. 				char *j;
  11. 				if ((j = index(i+5,',')) != 0)
  12. 					*j = (char)0;
  13. 				return i+5;
  14. 			}
  15. 	}
  16. 	return rn2(3) ? (rn2(2) ? "Michael Toy" : "Kenneth Arnold")
  17. 		: "Glenn Wichman";
  18. }
  19. #endif /* REINCARNATION */
  20. #endif /* OVLB */

hcolor[edit]

If not hallucinating and a color is specified this function is identity. Otherwise it picks a random hallucination color. This function is called, for instance, by doaltarobj in do.c when a player is hallucinating.

  1. #ifdef OVL2
  2.  
  3. static NEARDATA const char * const hcolors[] = {
  4. 	"ultraviolet", "infrared", "bluish-orange",
  5. 	"reddish-green", "dark white", "light black", "sky blue-pink",
  6. 	"salty", "sweet", "sour", "bitter",
  7. 	"striped", "spiral", "swirly", "plaid", "checkered", "argyle",
  8. 	"paisley", "blotchy", "guernsey-spotted", "polka-dotted",
  9. 	"square", "round", "triangular",
  10. 	"cabernet", "sangria", "fuchsia", "wisteria",
  11. 	"lemon-lime", "strawberry-banana", "peppermint",
  12. 	"romantic", "incandescent"
  13. };
  14.  
  15. const char *
  16. hcolor(colorpref)
  17. const char *colorpref;
  18. {
  19. 	return (Hallucination || !colorpref) ?
  20. 		hcolors[rn2(SIZE(hcolors))] : colorpref;
  21. }

rndcolor[edit]

  1. /* return a random real color unless hallucinating */
  2. const char *
  3. rndcolor()
  4. {
  5. 	int k = rn2(CLR_MAX);
  6. 	return Hallucination ? hcolor((char *)0) : (k == NO_COLOR) ?
  7. 		"colorless" : c_obj_colors[k];
  8. }

coyotename[edit]

  1. /* Aliases for road-runner nemesis
  2. */
  3. static const char * const coynames[] = {
  4. 	"Carnivorous Vulgaris","Road-Runnerus Digestus",
  5. 	"Eatibus Anythingus"  ,"Famishus-Famishus",
  6. 	"Eatibus Almost Anythingus","Eatius Birdius",
  7. 	"Famishius Fantasticus","Eternalii Famishiis",
  8. 	"Famishus Vulgarus","Famishius Vulgaris Ingeniusi",
  9. 	"Eatius-Slobbius","Hardheadipus Oedipus",
  10. 	"Carnivorous Slobbius","Hard-Headipus Ravenus",
  11. 	"Evereadii Eatibus","Apetitius Giganticus",
  12. 	"Hungrii Flea-Bagius","Overconfidentii Vulgaris",
  13. 	"Caninus Nervous Rex","Grotesques Appetitus",
  14. 	"Nemesis Riduclii","Canis latrans"
  15. };

The Wayback Machine has a copy of a web page that was used to obtain this list; the page is referenced in versions 3.3.0 through 3.4.0, but is no longer available. At least one of the names (faithfully copied from the Geocities list) is misspelled: the actual species name used in the cartoon "Soup or Sonic" is "Nemesis Ridiculii", not "Riduclii".

  1. char *
  2. coyotename(mtmp, buf)
  3. struct monst *mtmp;
  4. char *buf;
  5. {
  6. if (mtmp && buf) {
  7. 	Sprintf(buf, "%s - %s",
  8. 	    x_monnam(mtmp, ARTICLE_NONE, (char *)0, 0, TRUE),
  9. 	    mtmp->mcan ? coynames[SIZE(coynames)-1] : coynames[rn2(SIZE(coynames)-1)]);
  10. }
  11. return buf;
  12. }
  13. #endif /* OVL2 */
  14.  
  15. /*do_name.c*/