Source:NetHack 3.4.3/src/objnam.c

From NetHackWiki
(Redirected from Source:Ref/mimic obj name)
Jump to: navigation, search

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

The job of this particular source code file is to give the name of an object as a string. A read will reveal much about how NetHack discloses the identity of objects and how it uses the fields from the struct defined in obj.h. This file also handles putting articles (a, an, the) in front of names, making names plural, and interpreting wishes.

Top of file[edit]

  1. /*	SCCS Id: @(#)objnam.c	3.4	2003/12/04	*/
  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. /* "an uncursed greased partly eaten guardian naga hatchling [corpse]" */
  4. #define PREFIX	80	/* (56) */
  5. #define SCHAR_LIM 127
  6. #define NUMOBUF 12

NetHack employs two unusual ways to manipulate strings in C. It will put some object names (like "corpse") PREFIX characters into a buffer so that it can add prefixes (like "an uncursed greased partly eaten guardian naga hatchling") with the strprepend function. Meanwhile, it statically allocates NUMOBUF buffers of SCHAR_LIM characters each and makes those buffers available to the nextobuf function.

  1. STATIC_DCL char *FDECL([[#strprepend|strprepend]],(char *,const char *));
  2. #ifdef OVLB
  3. static boolean FDECL([[#wishymatch|wishymatch]], (const char *,const char *,BOOLEAN_P));
  4. #endif
  5. static char *NDECL([[#nextobuf|nextobuf]]);
  6. static void FDECL([[#add_erosion_words|add_erosion_words]], (struct obj *, char *));

struct Jitem[edit]

  1. struct Jitem {
  2. 	int item;
  3. 	const char *name;
  4. };

This struct is used for the #Japanese_items array; it associates an object (as identified in onames.h with its Japanese name. For some reason, 3.4.3 has the GemStone macro definition between this struct Jitem definition and the Japanese_items array.

GemStone[edit]

  1. /* true for gems/rocks that should have " stone" appended to their names */
  2. #define GemStone(typ)	(typ == FLINT ||				\
  3. 			 (objects[typ].oc_material == GEMSTONE &&	\
  4. 			  (typ != DILITHIUM_CRYSTAL && typ != RUBY &&	\
  5. 			   typ != DIAMOND && typ != SAPPHIRE &&		\
  6. 			   typ != BLACK_OPAL && 	\
  7. 			   typ != EMERALD && typ != OPAL)))

The gems as defined at objects.c#line887 do not contain the word "stone" in their names. The GemStone macro takes an object type arguement and returns true for the flint stone and all valuable gems except dilithium crystals, diamonds, black opals, and emeralds, thus indicating that NetHack should add the word stone to make phrases like garnet stone. NetHack also adds the word to the unidentified gray stone.

Japanese_items[edit]

  1. #ifndef OVLB
  2.  
  3. STATIC_DCL struct Jitem Japanese_items[];
  4.  
  5. #else /* OVLB */
  6.  
  7. STATIC_OVL struct Jitem Japanese_items[] = {
  8. 	{ SHORT_SWORD, "wakizashi" },
  9. 	{ BROADSWORD, "ninja-to" },
  10. 	{ FLAIL, "nunchaku" },
  11. 	{ GLAIVE, "naginata" },
  12. 	{ LOCK_PICK, "osaku" },
  13. 	{ WOODEN_HARP, "koto" },
  14. 	{ KNIFE, "shito" },
  15. 	{ PLATE_MAIL, "tanko" },
  16. 	{ HELMET, "kabuto" },
  17. 	{ LEATHER_GLOVES, "yugake" },
  18. 	{ FOOD_RATION, "gunyoki" },
  19. 	{ POT_BOOZE, "sake" },
  20. 	{0, "" }
  21. };
  22.  
  23. #endif /* OVLB */

The array Japanese_items (of #struct Jitem) that maps certain objects to their Japanese names. Samurai see these names instead of the usual names ("short sword", "broadsword", ... "booze").

  1. STATIC_DCL const char *FDECL(Japanese_item_name,(int i));

The declaration for the Japanese_item_name function is not with the other functions but instead below the declaration of the Japanese_items array.

strprepend[edit]

  1. #ifdef OVL1
  2.  
  3. STATIC_OVL char *
  4. strprepend(s,pref)
  5. register char *s;
  6. register const char *pref;
  7. {

This function strprepend does prepend a prefix (such as "3 cursed") to a string (such as "potions of blindness"), then returns a pointer to the new string. It must be only used if there are PREFIX bytes available in memory before the start of the string. So you cannot use this to prepend to any string, but only to strings allocated with that extra space. Any attempt to prepend more than one prefix might cause this function to crash.

  1. 	register int i = (int)strlen(pref);

The function first uses strlen to get the length of the prefix, and stores this as int i.

  1. 	if(i > PREFIX) {
  2. 		impossible("PREFIX too short (for %d).", i);
  3. 		return(s);
  4. 	}

Then it does check to make sure that the prefix is not larger than PREFIX. This catches when a programmer needs to increase PREFIX.

  1. 	s -= i;

The pointer s now moves backward to the beginning of where the prefix would be prepended.

  1. 	(void) strncpy(s, pref, i);	/* do not copy trailing 0 */

Exactly i characters are copied from the prefix to where the pointer s is; this correctly prepends the prefix to the string. Note that strncpy terminates s with the trailing 0 if and only if pref has less than i characters; this is often the source of bugs (and is why *BSD has strlcpy). The call for strprepend is a rare case of strncpy is used correctly but does not terminate the string. The comment "/* do not copy trailing 0 */" is a reminder that this use of strncpy is correct.

  1. 	return(s);
  2. }
  3.  
  4. #endif /* OVL1 */

At the end, strprepend returns the new pointer to the string including its prefix. The original string pointer passed to strprepend is no longer correct if you want to use the prefix.

nextobuf[edit]

  1. #ifdef OVLB
  2.  
  3. /* manage a pool of BUFSZ buffers, so callers don't have to */
  4. static char *
  5. nextobuf()
  6. {

The nextobuf function is another unusual tactic in managing memory for strings. Instead of dynamically allocating and freeing buffers, the nextobuf ("next open buffer") function instead returns the next buffer in a group of statically allocated buffers.

  1. 	static char NEARDATA bufs[NUMOBUF][BUFSZ];

The bufs array contains the buffers (allocated adjacent to themselves in a two dimensional array). Notice how the buffers are "static", which means that they are stored between calls to nextobuf. (Otherwise each call to nextobuf would create its own buffers on the stack, and deallocate them when nextobuf returned, thus making the buffers useless.)

  1. 	static int bufidx = 0;

The int bufidx is also static, and used so that nextobuf remembers which buffer is next. Initially, when the operating system loads NetHack, this value is 0, referring to the very first buffer in the bufs array.

  1. 	bufidx = (bufidx + 1) % NUMOBUF;

Each call to the function increments bufidx. The effect of "% NUMOBUF" is to begin recycling buffers after we have used them all. Because bufidx started at 0, the very first call to nextobuf after NetHack starts will return the buffer at index 1. The next calls use buffers 2, 3, ..., NUMOBUF - 1. The buffer at index 0 is the last buffer used before we begin recycling.

  1. 	return bufs[bufidx];
  2. }

The function returns a pointer to the bufidx buffer.

Compared to dynamic allocation, these few lines of C have some advantages:

  • You do not have to worry about freeing each buffer after you use it. You can just forget about the buffers and wait for them to be recycled.
  • There is a slight decrease in running time. Recycling buffers is slightly faster than freeing them and allocating new ones later. Also, with all buffers allocated together in memory (at program startup, before anyone worries about fragmentation), you are guaranteed to have some locality if you write code that uses multiple buffers.

There are enough disadvantages that nextobuf is not a universal replacement for dynamic allocation:

  • You have to be careful in objnam.c not to call nextobuf too many times and use too many buffers, because it will start recycling buffers before you finish using them. You can only use the NUMOBUF newest buffers.
  • This does not work if you need a buffer larger than BUFSZ.
  • If you increase NUMOBUF and BUFSZ to very large then you start wasting space. (So use nextobuf for NetHack object naming, not for large databases.)

This nextobuf function works well because objects in NetHack can only have names that are so long (for they should fit in the inventory screen on an 80x24 terminal), and the code is relatively linear and does not loop through the creation of many buffers.

Yet many programmers would have just dynamically allocated buffers instead of using a solution such as this.

obj_typename[edit]

  1. char *
  2. obj_typename(otyp)
  3. register int otyp;
  4. {

The goal of the obj_typename function is to return type names such as "amethyst stone (violet)", "wand called cancellation (balsa)", "ring of warning (topaz)". The name does not include information not known to the player; an unidentified scroll or spellbook could be "scroll (THARR)" or "spellbook (wrinkled)". The information is only about a particular type of object, and never includes details about a particular object such as counts, BUC statuses, enchantments, or charges. Thus the type is singular, never plural.

For example, a call to otyp(SILVER_DAGGER) returns only "silver dagger". A call to otyp(ELVEN_DAGGER) apparently returns either "elven dagger" or "runed dagger", but not "elven dagger (runed dagger)", because descriptions are only appended for certain classes of objects.

The parameter otyp must be an array index into the global "objects" array. (One can find such indices in the generated file onames.h.) The result is returned in a temporary "nextobuf" buffer, so if you are not using it quickly, then you should copy it to another buffer.

  1. 	char *buf = nextobuf();
  2. 	register struct objclass *ocl = &objects[otyp];
  3. 	register const char *actualn = OBJ_NAME(*ocl);
  4. 	register const char *dn = OBJ_DESCR(*ocl);
  5. 	register const char *un = ocl->oc_uname;
  6. 	register int nn = ocl->oc_name_known;

The code declares several local variables:

char *buf This is a buffer in which the result will appear.
struct objclass *ocl This is &objects[otyp], a pointer into the data structure that describes this type of object. It contains the info from objects.c and some other information, like whether or not the player has identified this type of object.
const char *actualn This is a buffer containing the actual name of the object, as defined in objects.c. Note that this does not include wording such as "spellbook of" or "wand of". Examples of actual names are "orcish arrow", "levitation boots", "adornment" (for the ring), "protection" (for the ring, and also for the spellbook), "extra healing" (for the potion or the spellbook), "undead turning" (for the wand). However, amulets do include the word amulet in the actual name, for example: "amulet of ESP", "amulet versus poison" and "Amulet of Yendor".
const char *dn This buffer contains the object description, such as "crude arrow", "snow boots", or for magic items, adjectives such as "wooden", "jade", "shiny" for rings, "milky", "bubbly", "clear" for potions. For scrolls, this is a label like "DAIYEN FOOELS" or "GARVEN DEH" (or "stamped" or "unlabeled"). This obj_typename function will sometimes use these descriptions, but it will not prefix any adjectives. So it might return "crude arrow" or "scroll labeled GARVEN DEH", but it returns "ring", not "shiny ring".
const char *un This is a name set with the #name command when you use it to name types of objects. For example, if you have a "scroll called identify named cursed", then this is "identify".
int nn This acts as a flag to determine whether the player has identified this type of item, that is, whether the player knows the actual name instead of the description. Does the player yet know that crude arrows are orcish arrows, that certain conical hats are dunce caps, that in the current game scrolls labeled READ ME are stinking cloud?
  1. 	if (Role_if(PM_SAMURAI) && Japanese_item_name(otyp))
  2. 		actualn = Japanese_item_name(otyp);

If you are a Samurai and a Japanese item name exists for the item (as determined by the Japanese_item_name function at #line2740), then the code replaces the actual name with the Japanese version.

  1. 	switch(ocl->oc_class) {

After the declarations, the code switches on the class of item. Each case copies something appropriate into the buffer at buf. Some of these cases break to some final code at #line151, while others immediately return the contents of the buffer. The cases are:

case COIN_CLASS for coins $ #line104
case POTION_CLASS for potions ! #line107
case SCROLL_CLASS for scrolls ? #line110
case WAND_CLASS for wands / #line113
case SPBOOK_CLASS for spellbooks + #line116
case RING_CLASS for rings = #line119
case AMULET_CLASS for amulets " #line122
default for all other items #line132
  1. 	case COIN_CLASS:
  2. 		Strcpy(buf, "coin");
  3. 		break;

The file objects.c defines only one type of coin, so case COIN_CLASS only runs for gold coins. The code copies the word "coin" into the buffer; it does not include the "gold" adjective. It then breaks to #line151.

  1. 	case POTION_CLASS:
  2. 		Strcpy(buf, "potion");
  3. 		break;
  4. 	case SCROLL_CLASS:
  5. 		Strcpy(buf, "scroll");
  6. 		break;
  7. 	case WAND_CLASS:
  8. 		Strcpy(buf, "wand");
  9. 		break;
  10. 	case SPBOOK_CLASS:
  11. 		Strcpy(buf, "spellbook");
  12. 		break;
  13. 	case RING_CLASS:
  14. 		Strcpy(buf, "ring");
  15. 		break;

The cases for potions, scrolls, wands, spellbooks, and ring exactly identical to the case for coins, except that the word copied into the buffer is "potion", "scroll", "wand", "spellbook", "ring". The code breaks to #line151 so that it can later append type information to make strings like "potion of enlightenment", "wand called stop bugs".

  1. 	case AMULET_CLASS:
  2. 		if(nn)
  3. 			Strcpy(buf,actualn);

In case AMULET_CLASS, if this type of amulet is known (flag nn is true), then the code copies the actual string such as "amulet of strangulation" or "amulet versus poison" into the buffer. Remember, unlike with the previous cases (ranging from coins to rings), the actual names of amulets include the word "amulet" where appropriate.

  1. 		else
  2. 			Strcpy(buf,"amulet");

If the amulet is unknown, the code just uses the string "amulet" without the descriptive prefix.

  1. 		if(un)
  2. 			Sprintf(eos(buf)," called %s",un);

If the amulet has a #name un, then code appends "called %s" where %s is the name, for example "amulet called unknown" or "amulet of strangulation called harmful".

  1. 		if(dn)
  2. 			Sprintf(eos(buf)," (%s)",dn);

If the amulet has a description dn, it is appended in parenthesees, as in "amulet called unknown (triangular)" or "amulet of ESP (concave)".

For both #names and descriptions, the code does nothing if the pointer is null. (At present, all of the amulets in objects.c do have descriptions, so the second check is strictly unnecessary.) The same four lines appending #names and descriptions appear many more times in this obj_typename function, and used to append #names and descriptions to all types of objects. (Some of those objects do lack descriptions.)

  1. 		return(buf);

For amulets, the name is returned immediately; the code does not break to #line151.

  1. 	default:

The default case handles all other types of objects, such as armor, tools, and gems. Gems and amulets must be handled specially, because unidentified amulets must be called "amulet", and most gems must be called "stone" or "gem" as appropriate. However, while amulets have their own separate case above, gems are handled with if statements in the default case.

  1. 		if(nn) {
  2. 			Strcpy(buf, actualn);
  3. 			if (GemStone(otyp))
  4. 				Strcat(buf, " stone");
  5. 			if(un)
  6. 				Sprintf(eos(buf), " called %s", un);
  7. 			if(dn)
  8. 				Sprintf(eos(buf), " (%s)", dn);

The default case opens with an if block for items identified by the player. For these items, the actual name is known to the player, so the code copies actualn into buf. Line 135 calls the GemStone macro of #line24 to test if line 136 should append the word "stone". The four lines from 137 to 140 append the #name and description, as lines 127 to 130 did for amulets.

  1. 		} else {
  2. 			Strcpy(buf, dn ? dn : actualn);

The default case has an interesting else block. For an unidentified object, if it has a description (such as "crude arrow") then the code uses the description, otherwise it uses the actual name. Thus obvious objects (ranging from the "dart" to "dwarvish mithril-coat", from the "tinning kit" to the "pancake" without a description use their actual name without requiring the player to identify them somehow.

Examples of descriptions include "lamp" (which might be a oil lamp or magic lamp), "conical hat" (which might be a cornuthaum or dunce cap), "riding boots" (which is a random type of boots), and many others.

  1. 			if(ocl->oc_class == GEM_CLASS)
  2. 				Strcat(buf, (ocl->oc_material == MINERAL) ?
  3. 						" stone" : " gem");

The code appends the word "stone" or "gem" to all unidentified gems (belonging to GEM_CLASS). The effect here is that obvious minerals obtain the word "stone", yielding a "gray stone", while all other objects obtain the word "gem" (for example, "violet gem"), thus making it ambiguous whether the unidentified thing is a valuable stone or a worthless piece of glass.

  1. 			if(un)
  2. 				Sprintf(eos(buf), " called %s", un);

Interestingly, lines 146 and 147 append the #name un, but nothing tries to append the description dn. Thus, identifying an object (that is not a coin, potion, scroll, wand, spellbook, ring, or amulet) causes the actual name to completely mask the description for the purposes of the obj_typename function.

  1. 		}
  2. 		return(buf);
  3. 	}

Line 149 closes the default case by returning buf immediately and not continuing to line 151.

  1. 	/* here for ring/scroll/potion/wand */

The cases that break from the switch statement (instead of returning) cause the code starting at line 151 to run. This code runs for coins, potions, scrolls, wands, spellbooks, and rings only. By now, buf includes a lone word like "potion", regardless of what the player knows about this potion.

  1. 	if(nn) {
  2. 	    if (ocl->oc_unique)
  3. 		Strcpy(buf, actualn); /* avoid spellbook of Book of the Dead */
  4. 	    else
  5. 		Sprintf(eos(buf), " of %s", actualn);
  6. 	}

The if block on lines 152 to 157 intervene if the player has identified this type of item. For a unique item, the name is completely replaced with the actual name. (In all these classes, the Book of the Dead is the only unique item.) Otherwise, code appends the actual name in an "of" clause. This produces strings like "potion of restore ability", "spellbook of identify", in effect "type of actual name". Interestingly, for coins this produces the string "coin of gold piece".

  1. 	if(un)
  2. 		Sprintf(eos(buf), " called %s", un);
  3. 	if(dn)
  4. 		Sprintf(eos(buf), " (%s)", dn);
  5. 	return(buf);
  6. }

Lines 158 to 161 then append the #name and description, if any, and line 162 finally returns the string.

simple_typename[edit]

  1. /* less verbose result than obj_typename(); either the actual name
  2. or the description (but not both); user-assigned name is ignored */
  3. char *
  4. simple_typename(otyp)
  5. int otyp;
  6. {
  7. char *bufp, *pp, *save_uname = objects[otyp].oc_uname;
  8.  
  9. objects[otyp].oc_uname = 0;		/* suppress any name given by user */
  10. bufp = obj_typename(otyp);
  11. objects[otyp].oc_uname = save_uname;
  12. if ((pp = strstri(bufp, " (")) != 0)
  13. 	*pp = '\0';		/* strip the appended description */
  14. return bufp;
  15. }

The simple_typename function calls obj_typename and removes any "called" clause (from the #name) command and removes any appended description, so "wand called cancellation (balsa)" becomes "wand". Actually, it temporarily sets objects[otyp].oc_uname, pretending that the user never used #name to call that type of object.

There must be a simpler way of coding obj_typename and simple_typename than this! No one has any incentive to code it, but one could cause that "called" clauses and appended descriptions are appended when wanted, not stripped when unwanted.

obj_is_pname[edit]

  1. boolean
  2. obj_is_pname(obj)
  3. register struct obj *obj;
  4. {
  5. return((boolean)(obj->dknown && obj->known && obj->onamelth &&
  6. 		     /* Since there aren't any objects which are both
  7. 		        artifacts and unique, the last check is redundant. */
  8. 		     obj->oartifact && !objects[obj->otyp].oc_unique));
  9. }

In NetHack, an artifact is simply an object bearing a certain #name, for example that elven dagger named Sting or that luckstone named Heart of Ahriman. This gives rise to quirks such as the naming artifacts bug. Now there are situations in which the game refers to Ogresmasher as "Ogremasher", not "war hammer named Ogresmasher", because Ogresmasher does something extra that other war hammers do not do.

The obj_is_pname tests if NetHack can refer to an object by just its #name. This function should return TRUE for Ogresmasher, but FALSE for typical objects such as the red potion named cursed, long sword named Newtbane, or mace named Ogresmasher. It also returns FALSE if the player has not yet identified the object. This is why you find or receive a "war hammer named Ogresmasher"; it only becomes the "the blessed +0 rustproof Ogremasher" after you identify it. Unless you unfamiliar with artifacts in general, the fact that the war hammer named Ogresmasher already has a #name, unless you found it on a bones level, reveals plainly that the object is an artifact, as does being blasted (if you happen to discover it while polymorphed into an ogre), so in practice the obj_is_pname function only has a cosmetic effect in inventory screens and messages.

Now consider what happens if while exploring the dungeon, Random Number God favors you that you encounter the Eye of the Aethiopica sits on a floor a few squares away from you. (The Eye is a quest artifact, so this could only happen on a bones level.) In order for obj_is_pname to return TRUE, you must know the object's description in addition to its identity. Normally, you can know the description simply by moving onto the square with the amulet; thus it might be an "oval amulet" or a "triangular amulet" (or an "amulet of ESP" if you know that type). However, if you were blind, then obj->dknown will never be set and obj_is_pname will return FALSE; thus NetHack does not mention that it is the Eye. (Being blasted, then noticing the energy regeneration might give a hint!) Having seen the amulet, but having not identified it, obj_is_pname returns FALSE. You want to identify it (directly or indirectly, assuming you ignore the naming artifacts bug), thus causing obj_is_pname to return TRUE; imagine being tricked by someone who left an "amulet of strangulation named Eye of the Aethiopica" in a bones pile!

distant_name[edit]

  1. /* Give the name of an object seen at a distance.  Unlike xname/doname,
  2. * we don't want to set dknown if it's not set already.  The kludge used is
  3. * to temporarily set Blind so that xname() skips the dknown setting.  This
  4. * assumes that we don't want to do this too often; if this function becomes
  5. * frequently used, it'd probably be better to pass a parameter to xname()
  6. * or doname() instead.
  7. */
  8. char *
  9. distant_name(obj, func)
  10. register struct obj *obj;
  11. char *FDECL((*func), (OBJ_P));
  12. {
  13. 	char *str;
  14.  
  15. 	long save_Blinded = Blinded;
  16. 	Blinded = 1;
  17. 	str = (*func)(obj);
  18. 	Blinded = save_Blinded;
  19. 	return str;
  20. }

fruitname[edit]

  1. /* convert player specified fruit name into corresponding fruit juice name
  2. ("slice of pizza" -> "pizza juice" rather than "slice of pizza juice") */
  3. char *
  4. fruitname(juice)
  5. boolean juice;	/* whether or not to append " juice" to the name */
  6. {
  7. char *buf = nextobuf();
  8. const char *fruit_nam = strstri(pl_fruit, " of ");
  9.  
  10. if (fruit_nam)
  11. 	fruit_nam += 4;		/* skip past " of " */
  12. else
  13. 	fruit_nam = pl_fruit;	/* use it as is */
  14.  
  15. Sprintf(buf, "%s%s", makesingular(fruit_nam), juice ? " juice" : "");
  16. return buf;
  17. }
  18.  
  19. #endif /* OVLB */

xname[edit]

  1. #ifdef OVL1
  2.  
  3. char *
  4. xname(obj)
  5. register struct obj *obj;
  6. {
  7. 	register char *buf;
  8. 	register int typ = obj->otyp;
  9. 	register struct objclass *ocl = &objects[typ];
  10. 	register int nn = ocl->oc_name_known;
  11. 	register const char *actualn = OBJ_NAME(*ocl);
  12. 	register const char *dn = OBJ_DESCR(*ocl);
  13. 	register const char *un = ocl->oc_uname;
  14.  
  15. 	buf = nextobuf() + PREFIX;	/* leave room for "17 -3 " */
  16. 	if (Role_if(PM_SAMURAI) && Japanese_item_name(typ))
  17. 		actualn = Japanese_item_name(typ);
  18.  
  19. 	buf[0] = '\0';
  20. 	/*
  21. 	 * clean up known when it's tied to oc_name_known, eg after AD_DRIN
  22. 	 * This is only required for unique objects since the article
  23. 	 * printed for the object is tied to the combination of the two
  24. 	 * and printing the wrong article gives away information.
  25. 	 */
  26. 	if (!nn && ocl->oc_uses_known && ocl->oc_unique) obj->known = 0;
  27. 	if (!Blind) obj->dknown = TRUE;
  28. 	if (Role_if(PM_PRIEST)) obj->bknown = TRUE;
  29. 	if (obj_is_pname(obj))
  30. 	    goto nameit;
  31. 	switch (obj->oclass) {
  32. 	    case AMULET_CLASS:
  33. 		if (!obj->dknown)
  34. 			Strcpy(buf, "amulet");
  35. 		else if (typ == AMULET_OF_YENDOR ||
  36. 			 typ == FAKE_AMULET_OF_YENDOR)
  37. 			/* each must be identified individually */
  38. 			Strcpy(buf, obj->known ? actualn : dn);
  39. 		else if (nn)
  40. 			Strcpy(buf, actualn);
  41. 		else if (un)
  42. 			Sprintf(buf,"amulet called %s", un);
  43. 		else
  44. 			Sprintf(buf,"%s amulet", dn);
  45. 		break;
  46. 	    case WEAPON_CLASS:
  47. 		if (is_poisonable(obj) && obj->opoisoned)
  48. 			Strcpy(buf, "poisoned ");
  49. 	    case VENOM_CLASS:
  50. 	    case TOOL_CLASS:
  51. 		if (typ == LENSES)
  52. 			Strcpy(buf, "pair of ");
  53.  
  54. 		if (!obj->dknown)
  55. 			Strcat(buf, dn ? dn : actualn);
  56. 		else if (nn)
  57. 			Strcat(buf, actualn);
  58. 		else if (un) {
  59. 			Strcat(buf, dn ? dn : actualn);
  60. 			Strcat(buf, " called ");
  61. 			Strcat(buf, un);
  62. 		} else
  63. 			Strcat(buf, dn ? dn : actualn);
  64. 		/* If we use an() here we'd have to remember never to use */
  65. 		/* it whenever calling doname() or xname(). */
  66. 		if (typ == FIGURINE)
  67. 		    Sprintf(eos(buf), " of a%s %s",
  68. 			index(vowels,*(mons[obj->corpsenm].mname)) ? "n" : "",
  69. 			mons[obj->corpsenm].mname);
  70. 		break;
  71. 	    case ARMOR_CLASS:
  72. 		/* depends on order of the dragon scales objects */
  73. 		if (typ >= GRAY_DRAGON_SCALES && typ <= YELLOW_DRAGON_SCALES) {
  74. 			Sprintf(buf, "set of %s", actualn);
  75. 			break;
  76. 		}
  77. 		if(is_boots(obj) || is_gloves(obj)) Strcpy(buf,"pair of ");
  78.  
  79. 		if(obj->otyp >= ELVEN_SHIELD && obj->otyp <= ORCISH_SHIELD
  80. 				&& !obj->dknown) {
  81. 			Strcpy(buf, "shield");
  82. 			break;
  83. 		}
  84. 		if(obj->otyp == SHIELD_OF_REFLECTION && !obj->dknown) {
  85. 			Strcpy(buf, "smooth shield");
  86. 			break;
  87. 		}
  88.  
  89. 		if(nn)	Strcat(buf, actualn);
  90. 		else if(un) {
  91. 			if(is_boots(obj))
  92. 				Strcat(buf,"boots");
  93. 			else if(is_gloves(obj))
  94. 				Strcat(buf,"gloves");
  95. 			else if(is_cloak(obj))
  96. 				Strcpy(buf,"cloak");
  97. 			else if(is_helmet(obj))
  98. 				Strcpy(buf,"helmet");
  99. 			else if(is_shield(obj))
  100. 				Strcpy(buf,"shield");
  101. 			else
  102. 				Strcpy(buf,"armor");
  103. 			Strcat(buf, " called ");
  104. 			Strcat(buf, un);
  105. 		} else	Strcat(buf, dn);
  106. 		break;
  107. 	    case FOOD_CLASS:
  108. 		if (typ == SLIME_MOLD) {
  109. 			register struct fruit *f;
  110.  
  111. 			for(f=ffruit; f; f = f->nextf) {
  112. 				if(f->fid == obj->spe) {
  113. 					Strcpy(buf, f->fname);
  114. 					break;
  115. 				}
  116. 			}
  117. 			if (!f) impossible("Bad fruit #%d?", obj->spe);
  118. 			break;
  119. 		}
  120.  
  121. 		Strcpy(buf, actualn);
  122. 		if (typ == TIN && obj->known) {
  123. 		    if(obj->spe > 0)
  124. 			Strcat(buf, " of spinach");
  125. 		    else if (obj->corpsenm == NON_PM)
  126. 		        Strcpy(buf, "empty tin");
  127. 		    else if (vegetarian(&mons[obj->corpsenm]))
  128. 			Sprintf(eos(buf), " of %s", mons[obj->corpsenm].mname);
  129. 		    else
  130. 			Sprintf(eos(buf), " of %s meat", mons[obj->corpsenm].mname);
  131. 		}
  132. 		break;
  133. 	    case COIN_CLASS:
  134. 	    case CHAIN_CLASS:
  135. 		Strcpy(buf, actualn);
  136. 		break;
  137. 	    case ROCK_CLASS:
  138. 		if (typ == STATUE)
  139. 		    Sprintf(buf, "%s%s of %s%s",
  140. 			(Role_if(PM_ARCHEOLOGIST) && (obj->spe & STATUE_HISTORIC)) ? "historic " : "" ,
  141. 			actualn,
  142. 			type_is_pname(&mons[obj->corpsenm]) ? "" :
  143. 			  (mons[obj->corpsenm].geno & G_UNIQ) ? "the " :
  144. 			    (index(vowels,*(mons[obj->corpsenm].mname)) ?
  145. 								"an " : "a "),
  146. 			mons[obj->corpsenm].mname);
  147. 		else Strcpy(buf, actualn);
  148. 		break;
  149. 	    case BALL_CLASS:
  150. 		Sprintf(buf, "%sheavy iron ball",
  151. 			(obj->owt > ocl->oc_weight) ? "very " : "");
  152. 		break;
  153. 	    case POTION_CLASS:
  154. 		if (obj->dknown && obj->odiluted)
  155. 			Strcpy(buf, "diluted ");
  156. 		if(nn || un || !obj->dknown) {
  157. 			Strcat(buf, "potion");
  158. 			if(!obj->dknown) break;
  159. 			if(nn) {
  160. 			    Strcat(buf, " of ");
  161. 			    if (typ == POT_WATER &&
  162. 				obj->bknown && (obj->blessed || obj->cursed)) {
  163. 				Strcat(buf, obj->blessed ? "holy " : "unholy ");
  164. 			    }
  165. 			    Strcat(buf, actualn);
  166. 			} else {
  167. 				Strcat(buf, " called ");
  168. 				Strcat(buf, un);
  169. 			}
  170. 		} else {
  171. 			Strcat(buf, dn);
  172. 			Strcat(buf, " potion");
  173. 		}
  174. 		break;
  175. 	case SCROLL_CLASS:
  176. 		Strcpy(buf, "scroll");
  177. 		if(!obj->dknown) break;
  178. 		if(nn) {
  179. 			Strcat(buf, " of ");
  180. 			Strcat(buf, actualn);
  181. 		} else if(un) {
  182. 			Strcat(buf, " called ");
  183. 			Strcat(buf, un);
  184. 		} else if (ocl->oc_magic) {
  185. 			Strcat(buf, " labeled ");
  186. 			Strcat(buf, dn);
  187. 		} else {
  188. 			Strcpy(buf, dn);
  189. 			Strcat(buf, " scroll");
  190. 		}
  191. 		break;
  192. 	case WAND_CLASS:
  193. 		if(!obj->dknown)
  194. 			Strcpy(buf, "wand");
  195. 		else if(nn)
  196. 			Sprintf(buf, "wand of %s", actualn);
  197. 		else if(un)
  198. 			Sprintf(buf, "wand called %s", un);
  199. 		else
  200. 			Sprintf(buf, "%s wand", dn);
  201. 		break;
  202. 	case SPBOOK_CLASS:
  203. 		if (!obj->dknown) {
  204. 			Strcpy(buf, "spellbook");
  205. 		} else if (nn) {
  206. 			if (typ != SPE_BOOK_OF_THE_DEAD)
  207. 			    Strcpy(buf, "spellbook of ");
  208. 			Strcat(buf, actualn);
  209. 		} else if (un) {
  210. 			Sprintf(buf, "spellbook called %s", un);
  211. 		} else
  212. 			Sprintf(buf, "%s spellbook", dn);
  213. 		break;
  214. 	case RING_CLASS:
  215. 		if(!obj->dknown)
  216. 			Strcpy(buf, "ring");
  217. 		else if(nn)
  218. 			Sprintf(buf, "ring of %s", actualn);
  219. 		else if(un)
  220. 			Sprintf(buf, "ring called %s", un);
  221. 		else
  222. 			Sprintf(buf, "%s ring", dn);
  223. 		break;
  224. 	case GEM_CLASS:
  225. 	    {
  226. 		const char *rock =
  227. 			    (ocl->oc_material == MINERAL) ? "stone" : "gem";
  228. 		if (!obj->dknown) {
  229. 		    Strcpy(buf, rock);
  230. 		} else if (!nn) {
  231. 		    if (un) Sprintf(buf,"%s called %s", rock, un);
  232. 		    else Sprintf(buf, "%s %s", dn, rock);
  233. 		} else {
  234. 		    Strcpy(buf, actualn);
  235. 		    if (GemStone(typ)) Strcat(buf, " stone");
  236. 		}
  237. 		break;
  238. 	    }
  239. 	default:
  240. 		Sprintf(buf,"glorkum %d %d %d", obj->oclass, typ, obj->spe);
  241. 	}
  242. 	if (obj->quan != 1L) Strcpy(buf, makeplural(buf));
  243.  
  244. 	if (obj->onamelth && obj->dknown) {
  245. 		Strcat(buf, " named ");
  246. nameit:
  247. 		Strcat(buf, ONAME(obj));
  248. 	}
  249.  
  250. 	if (!strncmpi(buf, "the ", 4)) buf += 4;
  251. 	return(buf);
  252. }

xname() returns the full name of object obj, considering whether hero has identified or named it, or whether hero is Samurai, etc.

mshot_xname[edit]

  1. /* xname() output augmented for multishot missile feedback */
  2. char *
  3. mshot_xname(obj)
  4. struct obj *obj;
  5. {
  6. char tmpbuf[BUFSZ];
  7. char *onm = xname(obj);
  8.  
  9. if (m_shot.n > 1 && m_shot.o == obj->otyp) {
  10. 	/* copy xname's result so that we can reuse its return buffer */
  11. 	Strcpy(tmpbuf, onm);
  12. 	/* "the Nth arrow"; value will eventually be passed to an() or
  13. 	   The(), both of which correctly handle this "the " prefix */
  14. 	Sprintf(onm, "the %d%s %s", m_shot.i, ordin(m_shot.i), tmpbuf);
  15. }
  16.  
  17. return onm;
  18. }
  19.  
  20. #endif /* OVL1 */
  21. #ifdef OVL0
  22.  
  23. /* used for naming "the unique_item" instead of "a unique_item" */
  24. boolean
  25. the_unique_obj(obj)
  26. register struct obj *obj;
  27. {
  28. if (!obj->dknown)
  29. 	return FALSE;
  30. else if (obj->otyp == FAKE_AMULET_OF_YENDOR && !obj->known)
  31. 	return TRUE;		/* lie */
  32. else
  33. 	return (boolean)(objects[obj->otyp].oc_unique &&
  34. 			 (obj->known || obj->otyp == AMULET_OF_YENDOR));
  35. }

add_erosion_words[edit]

  1. static void
  2. add_erosion_words(obj,prefix)
  3. struct obj *obj;
  4. char *prefix;
  5. {
  6. 	boolean iscrys = (obj->otyp == CRYSKNIFE);
  7.  
  8.  
  9. 	if (!is_damageable(obj) && !iscrys) return;
  10.  
  11. 	/* The only cases where any of these bits do double duty are for
  12. 	 * rotted food and diluted potions, which are all not is_damageable().
  13. 	 */
  14. 	if (obj->oeroded && !iscrys) {
  15. 		switch (obj->oeroded) {
  16. 			case 2:	Strcat(prefix, "very "); break;
  17. 			case 3:	Strcat(prefix, "thoroughly "); break;
  18. 		}			
  19. 		Strcat(prefix, is_rustprone(obj) ? "rusty " : "burnt ");
  20. 	}
  21. 	if (obj->oeroded2 && !iscrys) {
  22. 		switch (obj->oeroded2) {
  23. 			case 2:	Strcat(prefix, "very "); break;
  24. 			case 3:	Strcat(prefix, "thoroughly "); break;
  25. 		}			
  26. 		Strcat(prefix, is_corrodeable(obj) ? "corroded " :
  27. 			"rotted ");
  28. 	}
  29. 	if (obj->rknown && obj->oerodeproof)
  30. 		Strcat(prefix,
  31. 		       iscrys ? "fixed " :
  32. 		       is_rustprone(obj) ? "rustproof " :
  33. 		       is_corrodeable(obj) ? "corrodeproof " :	/* "stainless"? */
  34. 		       is_flammable(obj) ? "fireproof " : "");
  35. }

add_erosion_words() adds erosion-related words like "rusty thoroughly corroded " or "fireproof " to the prefix.

doname[edit]

  1. char *
  2. doname(obj)
  3. register struct obj *obj;
  4. {
  5. 	boolean ispoisoned = FALSE;
  6. 	char prefix[PREFIX];
  7. 	char tmpbuf[PREFIX+1];
  8. 	/* when we have to add something at the start of prefix instead of the
  9. 	 * end (Strcat is used on the end)
  10. 	 */
  11. 	register char *bp = xname(obj);
  12.  
  13. 	/* When using xname, we want "poisoned arrow", and when using
  14. 	 * doname, we want "poisoned +0 arrow".  This kludge is about the only
  15. 	 * way to do it, at least until someone overhauls xname() and doname(),
  16. 	 * combining both into one function taking a parameter.
  17. 	 */
  18. 	/* must check opoisoned--someone can have a weirdly-named fruit */
  19. 	if (!strncmp(bp, "poisoned ", 9) && obj->opoisoned) {
  20. 		bp += 9;
  21. 		ispoisoned = TRUE;
  22. 	}
  23.  
  24. 	if(obj->quan != 1L)
  25. 		Sprintf(prefix, "%ld ", obj->quan);
  26. 	else if (obj_is_pname(obj) || the_unique_obj(obj)) {
  27. 		if (!strncmpi(bp, "the ", 4))
  28. 		    bp += 4;
  29. 		Strcpy(prefix, "the ");
  30. 	} else
  31. 		Strcpy(prefix, "a ");
  32.  
  33. #ifdef INVISIBLE_OBJECTS
  34. 	if (obj->oinvis) Strcat(prefix,"invisible ");
  35. #endif
  36.  
  37. 	if (obj->bknown &&
  38. 	    obj->oclass != COIN_CLASS &&
  39. 	    (obj->otyp != POT_WATER || !objects[POT_WATER].oc_name_known
  40. 		|| (!obj->cursed && !obj->blessed))) {
  41. 	    /* allow 'blessed clear potion' if we don't know it's holy water;
  42. 	     * always allow "uncursed potion of water"
  43. 	     */
  44. 	    if (obj->cursed)
  45. 		Strcat(prefix, "cursed ");
  46. 	    else if (obj->blessed)
  47. 		Strcat(prefix, "blessed ");
  48. 	    else if ((!obj->known || !objects[obj->otyp].oc_charged ||
  49. 		      (obj->oclass == ARMOR_CLASS ||
  50. 		       obj->oclass == RING_CLASS))
  51. 		/* For most items with charges or +/-, if you know how many
  52. 		 * charges are left or what the +/- is, then you must have
  53. 		 * totally identified the item, so "uncursed" is unneccesary,
  54. 		 * because an identified object not described as "blessed" or
  55. 		 * "cursed" must be uncursed.
  56. 		 *
  57. 		 * If the charges or +/- is not known, "uncursed" must be
  58. 		 * printed to avoid ambiguity between an item whose curse
  59. 		 * status is unknown, and an item known to be uncursed.
  60. 		 */
  61. #ifdef MAIL
  62. 			&& obj->otyp != SCR_MAIL
  63. #endif
  64. 			&& obj->otyp != FAKE_AMULET_OF_YENDOR
  65. 			&& obj->otyp != AMULET_OF_YENDOR
  66. 			&& !Role_if(PM_PRIEST))
  67. 		Strcat(prefix, "uncursed ");
  68. 	}
  69.  
  70. 	if (obj->greased) Strcat(prefix, "greased ");
  71.  
  72. 	switch(obj->oclass) {
  73. 	case AMULET_CLASS:
  74. 		if(obj->owornmask & W_AMUL)
  75. 			Strcat(bp, " (being worn)");
  76. 		break;
  77. 	case WEAPON_CLASS:
  78. 		if(ispoisoned)
  79. 			Strcat(prefix, "poisoned ");
  80. plus:
  81. 		add_erosion_words(obj, prefix);
  82. 		if(obj->known) {
  83. 			Strcat(prefix, sitoa(obj->spe));
  84. 			Strcat(prefix, " ");
  85. 		}
  86. 		break;
  87. 	case ARMOR_CLASS:
  88. 		if(obj->owornmask & W_ARMOR)
  89. 			Strcat(bp, (obj == uskin) ? " (embedded in your skin)" :
  90. 				" (being worn)");
  91. 		goto plus;
  92. 	case TOOL_CLASS:
  93. 		/* weptools already get this done when we go to the +n code */
  94. 		if (!is_weptool(obj))
  95. 		    add_erosion_words(obj, prefix);
  96. 		if(obj->owornmask & (W_TOOL /* blindfold */
  97. #ifdef STEED
  98. 				| W_SADDLE
  99. #endif
  100. 				)) {
  101. 			Strcat(bp, " (being worn)");
  102. 			break;
  103. 		}
  104. 		if (obj->otyp == LEASH && obj->leashmon != 0) {
  105. 			Strcat(bp, " (in use)");
  106. 			break;
  107. 		}
  108. 		if (is_weptool(obj))
  109. 			goto plus;
  110. 		if (obj->otyp == CANDELABRUM_OF_INVOCATION) {
  111. 			if (!obj->spe)
  112. 			    Strcpy(tmpbuf, "no");
  113. 			else
  114. 			    Sprintf(tmpbuf, "%d", obj->spe);
  115. 			Sprintf(eos(bp), " (%s candle%s%s)",
  116. 				tmpbuf, plur(obj->spe),
  117. 				!obj->lamplit ? " attached" : ", lit");
  118. 			break;
  119. 		} else if (obj->otyp == OIL_LAMP || obj->otyp == MAGIC_LAMP ||
  120. 			obj->otyp == BRASS_LANTERN || Is_candle(obj)) {
  121. 			if (Is_candle(obj) &&
  122. 			    obj->age < 20L * (long)objects[obj->otyp].oc_cost)
  123. 				Strcat(prefix, "partly used ");
  124. 			if(obj->lamplit)
  125. 				Strcat(bp, " (lit)");
  126. 			break;
  127. 		}
  128. 		if(objects[obj->otyp].oc_charged)
  129. 		    goto charges;
  130. 		break;
  131. 	case WAND_CLASS:
  132. 		add_erosion_words(obj, prefix);
  133. charges:
  134. 		if(obj->known)
  135. 		    Sprintf(eos(bp), " (%d:%d)", (int)obj->recharged, obj->spe);
  136. 		break;
  137. 	case POTION_CLASS:
  138. 		if (obj->otyp == POT_OIL && obj->lamplit)
  139. 		    Strcat(bp, " (lit)");
  140. 		break;
  141. 	case RING_CLASS:
  142. 		add_erosion_words(obj, prefix);
  143. ring:
  144. 		if(obj->owornmask & W_RINGR) Strcat(bp, " (on right ");
  145. 		if(obj->owornmask & W_RINGL) Strcat(bp, " (on left ");
  146. 		if(obj->owornmask & W_RING) {
  147. 		    Strcat(bp, body_part(HAND));
  148. 		    Strcat(bp, ")");
  149. 		}
  150. 		if(obj->known && objects[obj->otyp].oc_charged) {
  151. 			Strcat(prefix, sitoa(obj->spe));
  152. 			Strcat(prefix, " ");
  153. 		}
  154. 		break;
  155. 	case FOOD_CLASS:
  156. 		if (obj->oeaten)
  157. 		    Strcat(prefix, "partly eaten ");
  158. 		if (obj->otyp == CORPSE) {
  159. 		    if (mons[obj->corpsenm].geno & G_UNIQ) {
  160. 			Sprintf(prefix, "%s%s ",
  161. 				(type_is_pname(&mons[obj->corpsenm]) ?
  162. 					"" : "the "),
  163. 				s_suffix(mons[obj->corpsenm].mname));
  164. 			if (obj->oeaten) Strcat(prefix, "partly eaten ");
  165. 		    } else {
  166. 			Strcat(prefix, mons[obj->corpsenm].mname);
  167. 			Strcat(prefix, " ");
  168. 		    }
  169. 		} else if (obj->otyp == EGG) {
  170. #if 0	/* corpses don't tell if they're stale either */
  171. 		    if (obj->known && stale_egg(obj))
  172. 			Strcat(prefix, "stale ");
  173. #endif
  174. 		    if (obj->corpsenm >= LOW_PM &&
  175. 			    (obj->known ||
  176. 			    mvitals[obj->corpsenm].mvflags & MV_KNOWS_EGG)) {
  177. 			Strcat(prefix, mons[obj->corpsenm].mname);
  178. 			Strcat(prefix, " ");
  179. 			if (obj->spe)
  180. 			    Strcat(bp, " (laid by you)");
  181. 		    }
  182. 		}
  183. 		if (obj->otyp == MEAT_RING) goto ring;
  184. 		break;
  185. 	case BALL_CLASS:
  186. 	case CHAIN_CLASS:
  187. 		add_erosion_words(obj, prefix);
  188. 		if(obj->owornmask & W_BALL)
  189. 			Strcat(bp, " (chained to you)");
  190. 			break;
  191. 	}
  192.  
  193. 	if((obj->owornmask & W_WEP) && !mrg_to_wielded) {
  194. 		if (obj->quan != 1L) {
  195. 			Strcat(bp, " (wielded)");
  196. 		} else {
  197. 			const char *hand_s = body_part(HAND);
  198.  
  199. 			if (bimanual(obj)) hand_s = makeplural(hand_s);
  200. 			Sprintf(eos(bp), " (weapon in %s)", hand_s);
  201. 		}
  202. 	}
  203. 	if(obj->owornmask & W_SWAPWEP) {
  204. 		if (u.twoweap)
  205. 			Sprintf(eos(bp), " (wielded in other %s)",
  206. 				body_part(HAND));
  207. 		else
  208. 			Strcat(bp, " (alternate weapon; not wielded)");
  209. 	}
  210. 	if(obj->owornmask & W_QUIVER) Strcat(bp, " (in quiver)");
  211. 	if(obj->unpaid) {
  212. 		xchar ox, oy; 
  213. 		long quotedprice = unpaid_cost(obj);
  214. 		struct monst *shkp = (struct monst *)0;
  215.  
  216. 		if (Has_contents(obj) &&
  217. 		    get_obj_location(obj, &ox, &oy, BURIED_TOO|CONTAINED_TOO) &&
  218. 		    costly_spot(ox, oy) &&
  219. 		    (shkp = shop_keeper(*in_rooms(ox, oy, SHOPBASE))))
  220. 			quotedprice += contained_cost(obj, shkp, 0L, FALSE, TRUE);
  221. 		Sprintf(eos(bp), " (unpaid, %ld %s)",
  222. 			quotedprice, currency(quotedprice));
  223. 	}
  224. 	if (!strncmp(prefix, "a ", 2) &&
  225. 			index(vowels, *(prefix+2) ? *(prefix+2) : *bp)
  226. 			&& (*(prefix+2) || (strncmp(bp, "uranium", 7)
  227. 				&& strncmp(bp, "unicorn", 7)
  228. 				&& strncmp(bp, "eucalyptus", 10)))) {
  229. 		Strcpy(tmpbuf, prefix);
  230. 		Strcpy(prefix, "an ");
  231. 		Strcpy(prefix+3, tmpbuf+2);
  232. 	}
  233. 	bp = strprepend(bp, prefix);
  234. 	return(bp);
  235. }
  236.  
  237. #endif /* OVL0 */

not_fully_identified[edit]

  1. #ifdef OVLB
  2.  
  3. /* used from invent.c */
  4. boolean
  5. not_fully_identified(otmp)
  6. register struct obj *otmp;
  7. {
  8. #ifdef GOLDOBJ
  9. /* gold doesn't have any interesting attributes [yet?] */
  10. if (otmp->oclass == COIN_CLASS) return FALSE;	/* always fully ID'd */
  11. #endif
  12. /* check fundamental ID hallmarks first */
  13. if (!otmp->known || !otmp->dknown ||
  14. #ifdef MAIL
  15. 	    (!otmp->bknown && otmp->otyp != SCR_MAIL) ||
  16. #else
  17. 	    !otmp->bknown ||
  18. #endif
  19. 	    !objects[otmp->otyp].oc_name_known)	/* ?redundant? */
  20. 	return TRUE;
  21. if (otmp->oartifact && undiscovered_artifact(otmp->oartifact))
  22. 	return TRUE;
  23. /* otmp->rknown is the only item of interest if we reach here */
  24. /*
  25. 	*  Note:  if a revision ever allows scrolls to become fireproof or
  26. 	*  rings to become shockproof, this checking will need to be revised.
  27. 	*  `rknown' ID only matters if xname() will provide the info about it.
  28. 	*/
  29. if (otmp->rknown || (otmp->oclass != ARMOR_CLASS &&
  30. 			 otmp->oclass != WEAPON_CLASS &&
  31. 			 !is_weptool(otmp) &&		    /* (redunant) */
  32. 			 otmp->oclass != BALL_CLASS))	    /* (useless) */
  33. 	return FALSE;
  34. else	/* lack of `rknown' only matters for vulnerable objects */
  35. 	return (boolean)(is_rustprone(otmp) ||
  36. 			 is_corrodeable(otmp) ||
  37. 			 is_flammable(otmp));
  38. }

corpse_xname[edit]

  1. char *
  2. corpse_xname(otmp, ignore_oquan)
  3. struct obj *otmp;
  4. boolean ignore_oquan;	/* to force singular */
  5. {
  6. 	char *nambuf = nextobuf();
  7.  
  8. 	Sprintf(nambuf, "%s corpse", mons[otmp->corpsenm].mname);
  9.  
  10. 	if (ignore_oquan || otmp->quan < 2)
  11. 	    return nambuf;
  12. 	else
  13. 	    return makeplural(nambuf);
  14. }

cxname[edit]

  1. /* xname, unless it's a corpse, then corpse_xname(obj, FALSE) */
  2. char *
  3. cxname(obj)
  4. struct obj *obj;
  5. {
  6. 	if (obj->otyp == CORPSE)
  7. 	    return corpse_xname(obj, FALSE);
  8. 	return xname(obj);
  9. }

killer_xname[edit]

  1. /* treat an object as fully ID'd when it might be used as reason for death */
  2. char *
  3. killer_xname(obj)
  4. struct obj *obj;
  5. {
  6. struct obj save_obj;
  7. unsigned save_ocknown;
  8. char *buf, *save_ocuname;
  9.  
  10. /* remember original settings for core of the object;
  11. oname and oattached extensions don't matter here--since they
  12. aren't modified they don't need to be saved and restored */
  13. save_obj = *obj;
  14. /* killer name should be more specific than general xname; however, exact
  15. info like blessed/cursed and rustproof makes things be too verbose */
  16. obj->known = obj->dknown = 1;
  17. obj->bknown = obj->rknown = obj->greased = 0;
  18. /* if character is a priest[ess], bknown will get toggled back on */
  19. obj->blessed = obj->cursed = 0;
  20. /* "killed by poisoned <obj>" would be misleading when poison is
  21. not the cause of death and "poisoned by poisoned <obj>" would
  22. be redundant when it is, so suppress "poisoned" prefix */
  23. obj->opoisoned = 0;
  24. /* strip user-supplied name; artifacts keep theirs */
  25. if (!obj->oartifact) obj->onamelth = 0;
  26. /* temporarily identify the type of object */
  27. save_ocknown = objects[obj->otyp].oc_name_known;
  28. objects[obj->otyp].oc_name_known = 1;
  29. save_ocuname = objects[obj->otyp].oc_uname;
  30. objects[obj->otyp].oc_uname = 0;	/* avoid "foo called bar" */
  31.  
  32. buf = xname(obj);
  33. if (obj->quan == 1L) buf = obj_is_pname(obj) ? the(buf) : an(buf);
  34.  
  35. objects[obj->otyp].oc_name_known = save_ocknown;
  36. objects[obj->otyp].oc_uname = save_ocuname;
  37. *obj = save_obj;	/* restore object's core settings */
  38.  
  39. return buf;
  40. }

singular[edit]

  1. /*
  2. * Used if only one of a collection of objects is named (e.g. in eat.c).
  3. */
  4. const char *
  5. singular(otmp, func)
  6. register struct obj *otmp;
  7. char *FDECL((*func), (OBJ_P));
  8. {
  9. 	long savequan;
  10. 	char *nam;
  11.  
  12. 	/* Note: using xname for corpses will not give the monster type */
  13. 	if (otmp->otyp == CORPSE && func == xname)
  14. 		return corpse_xname(otmp, TRUE);
  15.  
  16. 	savequan = otmp->quan;
  17. 	otmp->quan = 1L;
  18. 	nam = (*func)(otmp);
  19. 	otmp->quan = savequan;
  20. 	return nam;
  21. }

an[edit]

an() takes a string and returns it prefixed with either "an " or "a ".

  1. char *
  2. an(str)
  3. register const char *str;
  4. {
  5. 	char *buf = nextobuf();
  6.  
  7. 	buf[0] = '\0';
  8.  
  9. 	if (strncmpi(str, "the ", 4) &&
  10. 	    strcmp(str, "molten lava") &&
  11. 	    strcmp(str, "iron bars") &&
  12. 	    strcmp(str, "ice")) {
  13. 		if (index(vowels, *str) &&
  14. 		    strncmp(str, "one-", 4) &&
  15. 		    strncmp(str, "useful", 6) &&
  16. 		    strncmp(str, "unicorn", 7) &&
  17. 		    strncmp(str, "uranium", 7) &&
  18. 		    strncmp(str, "eucalyptus", 10))
  19. 			Strcpy(buf, "an ");
  20. 		else
  21. 			Strcpy(buf, "a ");
  22. 	}
  23.  
  24. 	Strcat(buf, str);
  25. 	return buf;
  26. }

An[edit]

  1. char *
  2. An(str)
  3. const char *str;
  4. {
  5. 	register char *tmp = an(str);
  6. 	*tmp = highc(*tmp);
  7. 	return tmp;
  8. }

the[edit]

  1. /*
  2. * Prepend "the" if necessary; assumes str is a subject derived from xname.
  3. * Use type_is_pname() for monster names, not the().  the() is idempotent.
  4. */
  5. char *
  6. the(str)
  7. const char *str;
  8. {
  9. 	char *buf = nextobuf();
  10. 	boolean insert_the = FALSE;
  11.  
  12. 	if (!strncmpi(str, "the ", 4)) {
  13. 	    buf[0] = lowc(*str);
  14. 	    Strcpy(&buf[1], str+1);
  15. 	    return buf;
  16. 	} else if (*str < 'A' || *str > 'Z') {
  17. 	    /* not a proper name, needs an article */
  18. 	    insert_the = TRUE;
  19. 	} else {
  20. 	    /* Probably a proper name, might not need an article */
  21. 	    register char *tmp, *named, *called;
  22. 	    int l;
  23.  
  24. 	    /* some objects have capitalized adjectives in their names */
  25. 	    if(((tmp = rindex(str, ' ')) || (tmp = rindex(str, '-'))) &&
  26. 	       (tmp[1] < 'A' || tmp[1] > 'Z'))
  27. 		insert_the = TRUE;
  28. 	    else if (tmp && index(str, ' ') < tmp) {	/* has spaces */
  29. 		/* it needs an article if the name contains "of" */
  30. 		tmp = strstri(str, " of ");
  31. 		named = strstri(str, " named ");
  32. 		called = strstri(str, " called ");
  33. 		if (called && (!named || called < named)) named = called;
  34.  
  35. 		if (tmp && (!named || tmp < named))	/* found an "of" */
  36. 		    insert_the = TRUE;
  37. 		/* stupid special case: lacks "of" but needs "the" */
  38. 		else if (!named && (l = strlen(str)) >= 31 &&
  39. 		      !strcmp(&str[l - 31], "Platinum Yendorian Express Card"))
  40. 		    insert_the = TRUE;
  41. 	    }
  42. 	}
  43. 	if (insert_the)
  44. 	    Strcpy(buf, "the ");
  45. 	else
  46. 	    buf[0] = '\0';
  47. 	Strcat(buf, str);
  48.  
  49. 	return buf;
  50. }

The[edit]

  1. char *
  2. The(str)
  3. const char *str;
  4. {
  5. register char *tmp = the(str);
  6. *tmp = highc(*tmp);
  7. return tmp;
  8. }

The() returns the string str prepended with "The ".

aobjname[edit]

  1. /* returns "count cxname(otmp)" or just cxname(otmp) if count == 1 */
  2. char *
  3. aobjnam(otmp,verb)
  4. register struct obj *otmp;
  5. register const char *verb;
  6. {
  7. 	register char *bp = cxname(otmp);
  8. 	char prefix[PREFIX];
  9.  
  10. 	if(otmp->quan != 1L) {
  11. 		Sprintf(prefix, "%ld ", otmp->quan);
  12. 		bp = strprepend(bp, prefix);
  13. 	}
  14.  
  15. 	if(verb) {
  16. 	    Strcat(bp, " ");
  17. 	    Strcat(bp, otense(otmp, verb));
  18. 	}
  19. 	return(bp);
  20. }

Tobjnam[edit]

  1. /* like aobjnam, but prepend "The", not count, and use xname */
  2. char *
  3. Tobjnam(otmp, verb)
  4. register struct obj *otmp;
  5. register const char *verb;
  6. {
  7. 	char *bp = The(xname(otmp));
  8.  
  9. 	if(verb) {
  10. 	    Strcat(bp, " ");
  11. 	    Strcat(bp, otense(otmp, verb));
  12. 	}
  13. 	return(bp);
  14. }

otense[edit]

  1. /* return form of the verb (input plural) if xname(otmp) were the subject */
  2. char *
  3. otense(otmp, verb)
  4. register struct obj *otmp;
  5. register const char *verb;
  6. {
  7. 	char *buf;
  8.  
  9. 	/*
  10. 	 * verb is given in plural (without trailing s).  Return as input
  11. 	 * if the result of xname(otmp) would be plural.  Don't bother
  12. 	 * recomputing xname(otmp) at this time.
  13. 	 */
  14. 	if (!is_plural(otmp))
  15. 	    return vtense((char *)0, verb);
  16.  
  17. 	buf = nextobuf();
  18. 	Strcpy(buf, verb);
  19. 	return buf;
  20. }


  1. /* various singular words that vtense would otherwise categorize as plural */
  2. static const char * const special_subjs[] = {
  3. 	"erinys",
  4. 	"manes",		/* this one is ambiguous */
  5. 	"Cyclops",
  6. 	"Hippocrates",
  7. 	"Pelias",
  8. 	"aklys",
  9. 	"amnesia",
  10. 	"paralysis",
  11. 	0
  12. };

vtense[edit]

  1. /* return form of the verb (input plural) for present tense 3rd person subj */
  2. char *
  3. vtense(subj, verb)
  4. register const char *subj;
  5. register const char *verb;
  6. {
  7. 	char *buf = nextobuf();
  8. 	int len, ltmp;
  9. 	const char *sp, *spot;
  10. 	const char * const *spec;
  11.  
  12. 	/*
  13. 	 * verb is given in plural (without trailing s).  Return as input
  14. 	 * if subj appears to be plural.  Add special cases as necessary.
  15. 	 * Many hard cases can already be handled by using otense() instead.
  16. 	 * If this gets much bigger, consider decomposing makeplural.
  17. 	 * Note: monster names are not expected here (except before corpse).
  18. 	 *
  19. 	 * special case: allow null sobj to get the singular 3rd person
  20. 	 * present tense form so we don't duplicate this code elsewhere.
  21. 	 */
  22. 	if (subj) {
  23. 	    if (!strncmpi(subj, "a ", 2) || !strncmpi(subj, "an ", 3))
  24. 		goto sing;
  25. 	    spot = (const char *)0;
  26. 	    for (sp = subj; (sp = index(sp, ' ')) != 0; ++sp) {
  27. 		if (!strncmp(sp, " of ", 4) ||
  28. 		    !strncmp(sp, " from ", 6) ||
  29. 		    !strncmp(sp, " called ", 8) ||
  30. 		    !strncmp(sp, " named ", 7) ||
  31. 		    !strncmp(sp, " labeled ", 9)) {
  32. 		    if (sp != subj) spot = sp - 1;
  33. 		    break;
  34. 		}
  35. 	    }
  36. 	    len = (int) strlen(subj);
  37. 	    if (!spot) spot = subj + len - 1;
  38.  
  39. 	    /*
  40. 	     * plural: anything that ends in 's', but not '*us' or '*ss'.
  41. 	     * Guess at a few other special cases that makeplural creates.
  42. 	     */
  43. 	    if ((*spot == 's' && spot != subj &&
  44. 			(*(spot-1) != 'u' && *(spot-1) != 's')) ||
  45. 		((spot - subj) >= 4 && !strncmp(spot-3, "eeth", 4)) ||
  46. 		((spot - subj) >= 3 && !strncmp(spot-3, "feet", 4)) ||
  47. 		((spot - subj) >= 2 && !strncmp(spot-1, "ia", 2)) ||
  48. 		((spot - subj) >= 2 && !strncmp(spot-1, "ae", 2))) {
  49. 		/* check for special cases to avoid false matches */
  50. 		len = (int)(spot - subj) + 1;
  51. 		for (spec = special_subjs; *spec; spec++) {
  52. 		    ltmp = strlen(*spec);
  53. 		    if (len == ltmp && !strncmpi(*spec, subj, len)) goto sing;
  54. 		    /* also check for <prefix><space><special_subj>
  55. 		       to catch things like "the invisible erinys" */
  56. 		    if (len > ltmp && *(spot - ltmp) == ' ' &&
  57. 			   !strncmpi(*spec, spot - ltmp + 1, ltmp)) goto sing;
  58. 		}
  59.  
  60. 		return strcpy(buf, verb);
  61. 	    }
  62. 	    /*
  63. 	     * 3rd person plural doesn't end in telltale 's';
  64. 	     * 2nd person singular behaves as if plural.
  65. 	     */
  66. 	    if (!strcmpi(subj, "they") || !strcmpi(subj, "you"))
  67. 		return strcpy(buf, verb);
  68. 	}
  69.  
  70. sing:
  71. 	len = strlen(verb);
  72. 	spot = verb + len - 1;
  73.  
  74. 	if (!strcmp(verb, "are"))
  75. 	    Strcpy(buf, "is");
  76. 	else if (!strcmp(verb, "have"))
  77. 	    Strcpy(buf, "has");
  78. 	else if (index("zxs", *spot) ||
  79. 		 (len >= 2 && *spot=='h' && index("cs", *(spot-1))) ||
  80. 		 (len == 2 && *spot == 'o')) {
  81. 	    /* Ends in z, x, s, ch, sh; add an "es" */
  82. 	    Strcpy(buf, verb);
  83. 	    Strcat(buf, "es");
  84. 	} else if (*spot == 'y' && (!index(vowels, *(spot-1)))) {
  85. 	    /* like "y" case in makeplural */
  86. 	    Strcpy(buf, verb);
  87. 	    Strcpy(buf + len - 1, "ies");
  88. 	} else {
  89. 	    Strcpy(buf, verb);
  90. 	    Strcat(buf, "s");
  91. 	}
  92.  
  93. 	return buf;
  94. }

Doname2[edit]

  1. /* capitalized variant of doname() */
  2. char *
  3. Doname2(obj)
  4. register struct obj *obj;
  5. {
  6. 	register char *s = doname(obj);
  7.  
  8. 	*s = highc(*s);
  9. 	return(s);
  10. }

yname[edit]

  1. /* returns "your xname(obj)" or "Foobar's xname(obj)" or "the xname(obj)" */
  2. char *
  3. yname(obj)
  4. struct obj *obj;
  5. {
  6. 	char *outbuf = nextobuf();
  7. 	char *s = shk_your(outbuf, obj);	/* assert( s == outbuf ); */
  8. 	int space_left = BUFSZ - strlen(s) - sizeof " ";
  9.  
  10. 	return strncat(strcat(s, " "), cxname(obj), space_left);
  11. }

Yname2[edit]

  1. /* capitalized variant of yname() */
  2. char *
  3. Yname2(obj)
  4. struct obj *obj;
  5. {
  6. 	char *s = yname(obj);
  7.  
  8. 	*s = highc(*s);
  9. 	return s;
  10. }

ysimple_name[edit]

  1. /* returns "your simple_typename(obj->otyp)"
  2. * or "Foobar's simple_typename(obj->otyp)"
  3. * or "the simple_typename(obj-otyp)"
  4. */
  5. char *
  6. ysimple_name(obj)
  7. struct obj *obj;
  8. {
  9. 	char *outbuf = nextobuf();
  10. 	char *s = shk_your(outbuf, obj);	/* assert( s == outbuf ); */
  11. 	int space_left = BUFSZ - strlen(s) - sizeof " ";
  12.  
  13. 	return strncat(strcat(s, " "), simple_typename(obj->otyp), space_left);
  14. }
  15.  
  16. /* capitalized variant of ysimple_name() */
  17. char *
  18. Ysimple_name2(obj)
  19. struct obj *obj;
  20. {
  21. 	char *s = ysimple_name(obj);
  22.  
  23. 	*s = highc(*s);
  24. 	return s;
  25. }
  26.  
  27. static const char *wrp[] = {
  28. 	"wand", "ring", "potion", "scroll", "gem", "amulet",
  29. 	"spellbook", "spell book",
  30. 	/* for non-specific wishes */
  31. 	"weapon", "armor", "armour", "tool", "food", "comestible",
  32. };
  33. static const char wrpsym[] = {
  34. 	WAND_CLASS, RING_CLASS, POTION_CLASS, SCROLL_CLASS, GEM_CLASS,
  35. 	AMULET_CLASS, SPBOOK_CLASS, SPBOOK_CLASS,
  36. 	WEAPON_CLASS, ARMOR_CLASS, ARMOR_CLASS, TOOL_CLASS, FOOD_CLASS,
  37. 	FOOD_CLASS
  38. };
  39.  
  40. #endif /* OVLB */
  41. #ifdef OVL0
  42.  
  43. /* Plural routine; chiefly used for user-defined fruits.  We have to try to
  44. * account for everything reasonable the player has; something unreasonable
  45. * can still break the code.  However, it's still a lot more accurate than
  46. * "just add an s at the end", which Rogue uses...
  47. *
  48. * Also used for plural monster names ("Wiped out all homunculi.")
  49. * and body parts.
  50. *
  51. * Also misused by muse.c to convert 1st person present verbs to 2nd person.
  52. */

makeplural[edit]

makeplural() takes one string parameter and returns a plural of that string. This should be able to handle every string given to it.

  1. char *
  2. makeplural(oldstr)
  3. const char *oldstr;
  4. {
  5. 	/* Note: cannot use strcmpi here -- it'd give MATZot, CAVEMeN,... */
  6. 	register char *spot;
  7. 	char *str = nextobuf();
  8. 	const char *excess = (char *)0;
  9. 	int len;
  10.  
  11. 	while (*oldstr==' ') oldstr++;
  12. 	if (!oldstr || !*oldstr) {
  13. 		impossible("plural of null?");
  14. 		Strcpy(str, "s");
  15. 		return str;
  16. 	}
  17. 	Strcpy(str, oldstr);
  18.  
  19. 	/*
  20. 	 * Skip changing "pair of" to "pairs of".  According to Webster, usual
  21. 	 * English usage is use pairs for humans, e.g. 3 pairs of dancers,
  22. 	 * and pair for objects and non-humans, e.g. 3 pair of boots.  We don't
  23. 	 * refer to pairs of humans in this game so just skip to the bottom.
  24. 	 */
  25. 	if (!strncmp(str, "pair of ", 8))
  26. 		goto bottom;
  27.  
  28. 	/* Search for common compounds, ex. lump of royal jelly */
  29. 	for(spot=str; *spot; spot++) {
  30. 		if (!strncmp(spot, " of ", 4)
  31. 				|| !strncmp(spot, " labeled ", 9)
  32. 				|| !strncmp(spot, " called ", 8)
  33. 				|| !strncmp(spot, " named ", 7)
  34. 				|| !strcmp(spot, " above") /* lurkers above */
  35. 				|| !strncmp(spot, " versus ", 8)
  36. 				|| !strncmp(spot, " from ", 6)
  37. 				|| !strncmp(spot, " in ", 4)
  38. 				|| !strncmp(spot, " on ", 4)
  39. 				|| !strncmp(spot, " a la ", 6)
  40. 				|| !strncmp(spot, " with", 5)	/* " with "? */
  41. 				|| !strncmp(spot, " de ", 4)
  42. 				|| !strncmp(spot, " d'", 3)
  43. 				|| !strncmp(spot, " du ", 4)) {
  44. 			excess = oldstr + (int) (spot - str);
  45. 			*spot = 0;
  46. 			break;
  47. 		}
  48. 	}
  49. 	spot--;
  50. 	while (*spot==' ') spot--; /* Strip blanks from end */
  51. 	*(spot+1) = 0;
  52. 	/* Now spot is the last character of the string */
  53.  
  54. 	len = strlen(str);
  55.  
  56. 	/* Single letters */
  57. 	if (len==1 || !letter(*spot)) {
  58. 		Strcpy(spot+1, "'s");
  59. 		goto bottom;
  60. 	}
  61.  
  62. 	/* Same singular and plural; mostly Japanese words except for "manes" */
  63. 	if ((len == 2 && !strcmp(str, "ya")) ||
  64. 	    (len >= 2 && !strcmp(spot-1, "ai")) || /* samurai, Uruk-hai */
  65. 	    (len >= 3 && !strcmp(spot-2, " ya")) ||
  66. 	    (len >= 4 &&
  67. 	     (!strcmp(spot-3, "fish") || !strcmp(spot-3, "tuna") ||
  68. 	      !strcmp(spot-3, "deer") || !strcmp(spot-3, "yaki"))) ||
  69. 	    (len >= 5 && (!strcmp(spot-4, "sheep") ||
  70. 			!strcmp(spot-4, "ninja") ||
  71. 			!strcmp(spot-4, "ronin") ||
  72. 			!strcmp(spot-4, "shito") ||
  73. 			!strcmp(spot-7, "shuriken") ||
  74. 			!strcmp(spot-4, "tengu") ||
  75. 			!strcmp(spot-4, "manes"))) ||
  76. 	    (len >= 6 && !strcmp(spot-5, "ki-rin")) ||
  77. 	    (len >= 7 && !strcmp(spot-6, "gunyoki")))
  78. 		goto bottom;
  79.  
  80. 	/* man/men ("Wiped out all cavemen.") */
  81. 	if (len >= 3 && !strcmp(spot-2, "man") &&
  82. 			(len<6 || strcmp(spot-5, "shaman")) &&
  83. 			(len<5 || strcmp(spot-4, "human"))) {
  84. 		*(spot-1) = 'e';
  85. 		goto bottom;
  86. 	}
  87.  
  88. 	/* tooth/teeth */
  89. 	if (len >= 5 && !strcmp(spot-4, "tooth")) {
  90. 		Strcpy(spot-3, "eeth");
  91. 		goto bottom;
  92. 	}
  93.  
  94. 	/* knife/knives, etc... */
  95. 	if (!strcmp(spot-1, "fe")) {
  96. 		Strcpy(spot-1, "ves");
  97. 		goto bottom;
  98. 	} else if (*spot == 'f') {
  99. 		if (index("lr", *(spot-1)) || index(vowels, *(spot-1))) {
  100. 			Strcpy(spot, "ves");
  101. 			goto bottom;
  102. 		} else if (len >= 5 && !strncmp(spot-4, "staf", 4)) {
  103. 			Strcpy(spot-1, "ves");
  104. 			goto bottom;
  105. 		}
  106. 	}
  107.  
  108. 	/* foot/feet (body part) */
  109. 	if (len >= 4 && !strcmp(spot-3, "foot")) {
  110. 		Strcpy(spot-2, "eet");
  111. 		goto bottom;
  112. 	}
  113.  
  114. 	/* ium/ia (mycelia, baluchitheria) */
  115. 	if (len >= 3 && !strcmp(spot-2, "ium")) {
  116. 		*(spot--) = (char)0;
  117. 		*spot = 'a';
  118. 		goto bottom;
  119. 	}
  120.  
  121. 	/* algae, larvae, hyphae (another fungus part) */
  122. 	if ((len >= 4 && !strcmp(spot-3, "alga")) ||
  123. 	    (len >= 5 &&
  124. 	     (!strcmp(spot-4, "hypha") || !strcmp(spot-4, "larva")))) {
  125. 		Strcpy(spot, "ae");
  126. 		goto bottom;
  127. 	}
  128.  
  129. 	/* fungus/fungi, homunculus/homunculi, but buses, lotuses, wumpuses */
  130. 	if (len > 3 && !strcmp(spot-1, "us") &&
  131. 	    (len < 5 || (strcmp(spot-4, "lotus") &&
  132. 			 (len < 6 || strcmp(spot-5, "wumpus"))))) {
  133. 		*(spot--) = (char)0;
  134. 		*spot = 'i';
  135. 		goto bottom;
  136. 	}
  137.  
  138. 	/* vortex/vortices */
  139. 	if (len >= 6 && !strcmp(spot-3, "rtex")) {
  140. 		Strcpy(spot-1, "ices");
  141. 		goto bottom;
  142. 	}
  143.  
  144. 	/* djinni/djinn (note: also efreeti/efreet) */
  145. 	if (len >= 6 && !strcmp(spot-5, "djinni")) {
  146. 		*spot = (char)0;
  147. 		goto bottom;
  148. 	}
  149.  
  150. 	/* mumak/mumakil */
  151. 	if (len >= 5 && !strcmp(spot-4, "mumak")) {
  152. 		Strcpy(spot+1, "il");
  153. 		goto bottom;
  154. 	}
  155.  
  156. 	/* sis/ses (nemesis) */
  157. 	if (len >= 3 && !strcmp(spot-2, "sis")) {
  158. 		*(spot-1) = 'e';
  159. 		goto bottom;
  160. 	}
  161.  
  162. 	/* erinys/erinyes */
  163. 	if (len >= 6 && !strcmp(spot-5, "erinys")) {
  164. 		Strcpy(spot, "es");
  165. 		goto bottom;
  166. 	}
  167.  
  168. 	/* mouse/mice,louse/lice (not a monster, but possible in food names) */
  169. 	if (len >= 5 && !strcmp(spot-3, "ouse") && index("MmLl", *(spot-4))) {
  170. 		Strcpy(spot-3, "ice");
  171. 		goto bottom;
  172. 	}
  173.  
  174. 	/* matzoh/matzot, possible food name */
  175. 	if (len >= 6 && (!strcmp(spot-5, "matzoh")
  176. 					|| !strcmp(spot-5, "matzah"))) {
  177. 		Strcpy(spot-1, "ot");
  178. 		goto bottom;
  179. 	}
  180. 	if (len >= 5 && (!strcmp(spot-4, "matzo")
  181. 					|| !strcmp(spot-5, "matza"))) {
  182. 		Strcpy(spot, "ot");
  183. 		goto bottom;
  184. 	}
  185.  
  186. 	/* child/children (for wise guys who give their food funny names) */
  187. 	if (len >= 5 && !strcmp(spot-4, "child")) {
  188. 		Strcpy(spot, "dren");
  189. 		goto bottom;
  190. 	}
  191.  
  192. 	/* note: -eau/-eaux (gateau, bordeau...) */
  193. 	/* note: ox/oxen, VAX/VAXen, goose/geese */
  194.  
  195. 	/* Ends in z, x, s, ch, sh; add an "es" */
  196. 	if (index("zxs", *spot)
  197. 			|| (len >= 2 && *spot=='h' && index("cs", *(spot-1)))
  198. 	/* Kludge to get "tomatoes" and "potatoes" right */
  199. 			|| (len >= 4 && !strcmp(spot-2, "ato"))) {
  200. 		Strcpy(spot+1, "es");
  201. 		goto bottom;
  202. 	}
  203.  
  204. 	/* Ends in y preceded by consonant (note: also "qu") change to "ies" */
  205. 	if (*spot == 'y' &&
  206. 	    (!index(vowels, *(spot-1)))) {
  207. 		Strcpy(spot, "ies");
  208. 		goto bottom;
  209. 	}
  210.  
  211. 	/* Default: append an 's' */
  212. 	Strcpy(spot+1, "s");
  213.  
  214. bottom:	if (excess) Strcpy(eos(str), excess);
  215. 	return str;
  216. }
  217.  
  218. #endif /* OVL0 */

struct o_range[edit]

  1. struct o_range {
  2. 	const char *name, oclass;
  3. 	int  f_o_range, l_o_range;
  4. };
  5.  
  6. #ifndef OVLB
  7.  
  8. STATIC_DCL const struct o_range o_ranges[];
  9.  
  10. #else /* OVLB */
  11.  
  12. /* wishable subranges of objects */
  13. STATIC_OVL NEARDATA const struct o_range o_ranges[] = {
  14. 	{ "bag",	TOOL_CLASS,   SACK,	      BAG_OF_TRICKS },
  15. 	{ "lamp",	TOOL_CLASS,   OIL_LAMP,	      MAGIC_LAMP },
  16. 	{ "candle",	TOOL_CLASS,   TALLOW_CANDLE,  WAX_CANDLE },
  17. 	{ "horn",	TOOL_CLASS,   TOOLED_HORN,    HORN_OF_PLENTY },
  18. 	{ "shield",	ARMOR_CLASS,  SMALL_SHIELD,   SHIELD_OF_REFLECTION },
  19. 	{ "helm",	ARMOR_CLASS,  ELVEN_LEATHER_HELM, HELM_OF_TELEPATHY },
  20. 	{ "gloves",	ARMOR_CLASS,  LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY },
  21. 	{ "gauntlets",	ARMOR_CLASS,  LEATHER_GLOVES, GAUNTLETS_OF_DEXTERITY },
  22. 	{ "boots",	ARMOR_CLASS,  LOW_BOOTS,      LEVITATION_BOOTS },
  23. 	{ "shoes",	ARMOR_CLASS,  LOW_BOOTS,      IRON_SHOES },
  24. 	{ "cloak",	ARMOR_CLASS,  MUMMY_WRAPPING, CLOAK_OF_DISPLACEMENT },
  25. #ifdef TOURIST
  26. 	{ "shirt",	ARMOR_CLASS,  HAWAIIAN_SHIRT, T_SHIRT },
  27. #endif
  28. 	{ "dragon scales",
  29. 			ARMOR_CLASS,  GRAY_DRAGON_SCALES, YELLOW_DRAGON_SCALES },
  30. 	{ "dragon scale mail",
  31. 			ARMOR_CLASS,  GRAY_DRAGON_SCALE_MAIL, YELLOW_DRAGON_SCALE_MAIL },
  32. 	{ "sword",	WEAPON_CLASS, SHORT_SWORD,    KATANA },
  33. #ifdef WIZARD
  34. 	{ "venom",	VENOM_CLASS,  BLINDING_VENOM, ACID_VENOM },
  35. #endif
  36. 	{ "gray stone",	GEM_CLASS,    LUCKSTONE,      FLINT },
  37. 	{ "grey stone",	GEM_CLASS,    LUCKSTONE,      FLINT },
  38. };
  39.  
  40. #define BSTRCMP(base,ptr,string) ((ptr) < base || strcmp((ptr),string))
  41. #define BSTRCMPI(base,ptr,string) ((ptr) < base || strcmpi((ptr),string))
  42. #define BSTRNCMP(base,ptr,string,num) ((ptr)<base || strncmp((ptr),string,num))
  43. #define BSTRNCMPI(base,ptr,string,num) ((ptr)<base||strncmpi((ptr),string,num))

makesingular[edit]

  1. /*
  2. * Singularize a string the user typed in; this helps reduce the complexity
  3. * of readobjnam, and is also used in pager.c to singularize the string
  4. * for which help is sought.
  5. */
  6. char *
  7. makesingular(oldstr)
  8. const char *oldstr;
  9. {
  10. 	register char *p, *bp;
  11. 	char *str = nextobuf();
  12.  
  13. 	if (!oldstr || !*oldstr) {
  14. 		impossible("singular of null?");
  15. 		str[0] = 0;
  16. 		return str;
  17. 	}
  18. 	Strcpy(str, oldstr);
  19. 	bp = str;
  20.  
  21. 	while (*bp == ' ') bp++;
  22. 	/* find "cloves of garlic", "worthless pieces of blue glass" */
  23. 	if ((p = strstri(bp, "s of ")) != 0) {
  24. 	    /* but don't singularize "gauntlets", "boots", "Eyes of the.." */
  25. 	    if (BSTRNCMPI(bp, p-3, "Eye", 3) &&
  26. 		BSTRNCMP(bp, p-4, "boot", 4) &&
  27. 		BSTRNCMP(bp, p-8, "gauntlet", 8))
  28. 		while ((*p = *(p+1)) != 0) p++;
  29. 	    return bp;
  30. 	}
  31.  
  32. 	/* remove -s or -es (boxes) or -ies (rubies) */
  33. 	p = eos(bp);
  34. 	if (p >= bp+1 && p[-1] == 's') {
  35. 		if (p >= bp+2 && p[-2] == 'e') {
  36. 			if (p >= bp+3 && p[-3] == 'i') {
  37. 				if(!BSTRCMP(bp, p-7, "cookies") ||
  38. 				   !BSTRCMP(bp, p-4, "pies"))
  39. 					goto mins;
  40. 				Strcpy(p-3, "y");
  41. 				return bp;
  42. 			}
  43.  
  44. 			/* note: cloves / knives from clove / knife */
  45. 			if(!BSTRCMP(bp, p-6, "knives")) {
  46. 				Strcpy(p-3, "fe");
  47. 				return bp;
  48. 			}
  49. 			if(!BSTRCMP(bp, p-6, "staves")) {
  50. 				Strcpy(p-3, "ff");
  51. 				return bp;
  52. 			}
  53. 			if (!BSTRCMPI(bp, p-6, "leaves")) {
  54. 				Strcpy(p-3, "f");
  55. 				return bp;
  56. 			}
  57. 			if (!BSTRCMP(bp, p-8, "vortices")) {
  58. 				Strcpy(p-4, "ex");
  59. 				return bp;
  60. 			}
  61.  
  62. 			/* note: nurses, axes but boxes */
  63. 			if (!BSTRCMP(bp, p-5, "boxes") ||
  64. 			    !BSTRCMP(bp, p-4, "ches")) {
  65. 				p[-2] = '\0';
  66. 				return bp;
  67. 			}
  68.  
  69. 			if (!BSTRCMP(bp, p-6, "gloves") ||
  70. 			    !BSTRCMP(bp, p-6, "lenses") ||
  71. 			    !BSTRCMP(bp, p-5, "shoes") ||
  72. 			    !BSTRCMP(bp, p-6, "scales"))
  73. 				return bp;
  74.  
  75. 		} else if (!BSTRCMP(bp, p-5, "boots") ||
  76. 			   !BSTRCMP(bp, p-9, "gauntlets") ||
  77. 			   !BSTRCMP(bp, p-6, "tricks") ||
  78. 			   !BSTRCMP(bp, p-9, "paralysis") ||
  79. 			   !BSTRCMP(bp, p-5, "glass") ||
  80. 			   !BSTRCMP(bp, p-4, "ness") ||
  81. 			   !BSTRCMP(bp, p-14, "shape changers") ||
  82. 			   !BSTRCMP(bp, p-15, "detect monsters") ||
  83. 			   !BSTRCMPI(bp, p-11, "Aesculapius") || /* staff */
  84. 			   !BSTRCMP(bp, p-10, "eucalyptus") ||
  85. #ifdef WIZARD
  86. 			   !BSTRCMP(bp, p-9, "iron bars") ||
  87. #endif
  88. 			   !BSTRCMP(bp, p-5, "aklys") ||
  89. 			   !BSTRCMP(bp, p-6, "fungus"))
  90. 				return bp;
  91. 	mins:
  92. 		p[-1] = '\0';
  93.  
  94. 	} else {
  95.  
  96. 		if(!BSTRCMP(bp, p-5, "teeth")) {
  97. 			Strcpy(p-5, "tooth");
  98. 			return bp;
  99. 		}
  100.  
  101. 		if (!BSTRCMP(bp, p-5, "fungi")) {
  102. 			Strcpy(p-5, "fungus");
  103. 			return bp;
  104. 		}
  105.  
  106. 		/* here we cannot find the plural suffix */
  107. 	}
  108. 	return bp;
  109. }

wishymatch[edit]

  1. /* compare user string against object name string using fuzzy matching */
  2. static boolean
  3. wishymatch(u_str, o_str, retry_inverted)
  4. const char *u_str;	/* from user, so might be variant spelling */
  5. const char *o_str;	/* from objects[], so is in canonical form */
  6. boolean retry_inverted;	/* optional extra "of" handling */
  7. {
  8. 	/* special case: wizards can wish for traps.  The object is "beartrap"
  9. 	 * and the trap is "bear trap", so to let wizards wish for both we
  10. 	 * must not fuzzymatch.
  11. 	 */
  12. #ifdef WIZARD
  13. 	if (wizard && !strcmp(o_str, "beartrap"))
  14. 	    return !strncmpi(o_str, u_str, 8);
  15. #endif
  16.  
  17. 	/* ignore spaces & hyphens and upper/lower case when comparing */
  18. 	if (fuzzymatch(u_str, o_str, " -", TRUE)) return TRUE;
  19.  
  20. 	if (retry_inverted) {
  21. 	    const char *u_of, *o_of;
  22. 	    char *p, buf[BUFSZ];
  23.  
  24. 	    /* when just one of the strings is in the form "foo of bar",
  25. 	       convert it into "bar foo" and perform another comparison */
  26. 	    u_of = strstri(u_str, " of ");
  27. 	    o_of = strstri(o_str, " of ");
  28. 	    if (u_of && !o_of) {
  29. 		Strcpy(buf, u_of + 4);
  30. 		p = eos(strcat(buf, " "));
  31. 		while (u_str < u_of) *p++ = *u_str++;
  32. 		*p = '\0';
  33. 		return fuzzymatch(buf, o_str, " -", TRUE);
  34. 	    } else if (o_of && !u_of) {
  35. 		Strcpy(buf, o_of + 4);
  36. 		p = eos(strcat(buf, " "));
  37. 		while (o_str < o_of) *p++ = *o_str++;
  38. 		*p = '\0';
  39. 		return fuzzymatch(u_str, buf, " -", TRUE);
  40. 	    }
  41. 	}
  42.  
  43. 	/* [note: if something like "elven speed boots" ever gets added, these
  44. 	   special cases should be changed to call wishymatch() recursively in
  45. 	   order to get the "of" inversion handling] */
  46. 	if (!strncmp(o_str, "dwarvish ", 9)) {
  47. 	    if (!strncmpi(u_str, "dwarven ", 8))
  48. 		return fuzzymatch(u_str + 8, o_str + 9, " -", TRUE);
  49. 	} else if (!strncmp(o_str, "elven ", 6)) {
  50. 	    if (!strncmpi(u_str, "elvish ", 7))
  51. 		return fuzzymatch(u_str + 7, o_str + 6, " -", TRUE);
  52. 	    else if (!strncmpi(u_str, "elfin ", 6))
  53. 		return fuzzymatch(u_str + 6, o_str + 6, " -", TRUE);
  54. 	} else if (!strcmp(o_str, "aluminum")) {
  55. 		/* this special case doesn't really fit anywhere else... */
  56. 		/* (note that " wand" will have been stripped off by now) */
  57. 	    if (!strcmpi(u_str, "aluminium"))
  58. 		return fuzzymatch(u_str + 9, o_str + 8, " -", TRUE);
  59. 	}
  60.  
  61. 	return FALSE;
  62. }

struct alt_spellings[edit]

  1. /* alternate spellings; if the difference is only the presence or
  2. absence of spaces and/or hyphens (such as "pickaxe" vs "pick axe"
  3. vs "pick-axe") then there is no need for inclusion in this list;
  4. likewise for ``"of" inversions'' ("boots of speed" vs "speed boots") */
  5. struct alt_spellings {
  6. 	const char *sp;
  7. 	int ob;
  8. } spellings[] = {
  9. 	{ "pickax", PICK_AXE },
  10. 	{ "whip", BULLWHIP },
  11. 	{ "saber", SILVER_SABER },
  12. 	{ "silver sabre", SILVER_SABER },
  13. 	{ "smooth shield", SHIELD_OF_REFLECTION },
  14. 	{ "grey dragon scale mail", GRAY_DRAGON_SCALE_MAIL },
  15. 	{ "grey dragon scales", GRAY_DRAGON_SCALES },
  16. 	{ "enchant armour", SCR_ENCHANT_ARMOR },
  17. 	{ "destroy armour", SCR_DESTROY_ARMOR },
  18. 	{ "scroll of enchant armour", SCR_ENCHANT_ARMOR },
  19. 	{ "scroll of destroy armour", SCR_DESTROY_ARMOR },
  20. 	{ "leather armour", LEATHER_ARMOR },
  21. 	{ "studded leather armour", STUDDED_LEATHER_ARMOR },
  22. 	{ "iron ball", HEAVY_IRON_BALL },
  23. 	{ "lantern", BRASS_LANTERN },
  24. 	{ "mattock", DWARVISH_MATTOCK },
  25. 	{ "amulet of poison resistance", AMULET_VERSUS_POISON },
  26. 	{ "stone", ROCK },
  27. #ifdef TOURIST
  28. 	{ "camera", EXPENSIVE_CAMERA },
  29. 	{ "tee shirt", T_SHIRT },
  30. #endif
  31. 	{ "can", TIN },
  32. 	{ "can opener", TIN_OPENER },
  33. 	{ "kelp", KELP_FROND },
  34. 	{ "eucalyptus", EUCALYPTUS_LEAF },
  35. 	{ "grapple", GRAPPLING_HOOK },
  36. 	{ (const char *)0, 0 },
  37. };

readobjnam[edit]

  1. /*
  2. * Return something wished for.  Specifying a null pointer for
  3. * the user request string results in a random object.  Otherwise,
  4. * if asking explicitly for "nothing" (or "nil") return no_wish;
  5. * if not an object return &zeroobj; if an error (no matching object),
  6. * return null.
  7. * If from_user is false, we're reading from the wizkit, nothing was typed in.
  8. */
  9. struct obj *
  10. readobjnam(bp, no_wish, from_user)
  11. register char *bp;
  12. struct obj *no_wish;
  13. boolean from_user;
  14. {
  15. 	register char *p;
  16. 	register int i;
  17. 	register struct obj *otmp;
  18. 	int cnt, spe, spesgn, typ, very, rechrg;
  19. 	int blessed, uncursed, iscursed, ispoisoned, isgreased;
  20. 	int eroded, eroded2, erodeproof;
  21. #ifdef INVISIBLE_OBJECTS
  22. 	int isinvisible;
  23. #endif
  24. 	int halfeaten, mntmp, contents;
  25. 	int islit, unlabeled, ishistoric, isdiluted;
  26. 	struct fruit *f;
  27. 	int ftype = current_fruit;
  28. 	char fruitbuf[BUFSZ];
  29. 	/* Fruits may not mess up the ability to wish for real objects (since
  30. 	 * you can leave a fruit in a bones file and it will be added to
  31. 	 * another person's game), so they must be checked for last, after
  32. 	 * stripping all the possible prefixes and seeing if there's a real
  33. 	 * name in there.  So we have to save the full original name.  However,
  34. 	 * it's still possible to do things like "uncursed burnt Alaska",
  35. 	 * or worse yet, "2 burned 5 course meals", so we need to loop to
  36. 	 * strip off the prefixes again, this time stripping only the ones
  37. 	 * possible on food.
  38. 	 * We could get even more detailed so as to allow food names with
  39. 	 * prefixes that _are_ possible on food, so you could wish for
  40. 	 * "2 3 alarm chilis".  Currently this isn't allowed; [[options.c]]
  41. 	 * automatically sticks 'candied' in front of such names.
  42. 	 */
  43.  
  44. 	char oclass;
  45. 	char *un, *dn, *actualn;
  46. 	const char *name=0;
  47.  
  48. 	cnt = spe = spesgn = typ = very = rechrg =
  49. 		blessed = uncursed = iscursed =
  50. #ifdef INVISIBLE_OBJECTS
  51. 		isinvisible =
  52. #endif
  53. 		ispoisoned = isgreased = eroded = eroded2 = erodeproof =
  54. 		halfeaten = islit = unlabeled = ishistoric = isdiluted = 0;
  55. 	mntmp = NON_PM;
  56. #define UNDEFINED 0
  57. #define EMPTY 1
  58. #define SPINACH 2
  59. 	contents = UNDEFINED;
  60. 	oclass = 0;
  61. 	actualn = dn = un = 0;
  62.  
  63. 	if (!bp) goto any;
  64. 	/* first, remove extra whitespace they may have typed */
  65. 	(void)mungspaces(bp);
  66. 	/* allow wishing for "nothing" to preserve wishless conduct...
  67. 	   [now requires "wand of nothing" if that's what was really wanted] */
  68. 	if (!strcmpi(bp, "nothing") || !strcmpi(bp, "nil") ||
  69. 	    !strcmpi(bp, "none")) return no_wish;
  70. 	/* save the [nearly] unmodified choice string */
  71. 	Strcpy(fruitbuf, bp);
  72.  
  73. 	for(;;) {
  74. 		register int l;
  75.  
  76. 		if (!bp || !*bp) goto any;
  77. 		if (!strncmpi(bp, "an ", l=3) ||
  78. 		    !strncmpi(bp, "a ", l=2)) {
  79. 			cnt = 1;
  80. 		} else if (!strncmpi(bp, "the ", l=4)) {
  81. 			;	/* just increment `bp' by `l' below */
  82. 		} else if (!cnt && digit(*bp) && strcmp(bp, "0")) {
  83. 			cnt = atoi(bp);
  84. 			while(digit(*bp)) bp++;
  85. 			while(*bp == ' ') bp++;
  86. 			l = 0;
  87. 		} else if (*bp == '+' || *bp == '-') {
  88. 			spesgn = (*bp++ == '+') ? 1 : -1;
  89. 			spe = atoi(bp);
  90. 			while(digit(*bp)) bp++;
  91. 			while(*bp == ' ') bp++;
  92. 			l = 0;
  93. 		} else if (!strncmpi(bp, "blessed ", l=8) ||
  94. 			   !strncmpi(bp, "holy ", l=5)) {
  95. 			blessed = 1;
  96. 		} else if (!strncmpi(bp, "cursed ", l=7) ||
  97. 			   !strncmpi(bp, "unholy ", l=7)) {
  98. 			iscursed = 1;
  99. 		} else if (!strncmpi(bp, "uncursed ", l=9)) {
  100. 			uncursed = 1;
  101. #ifdef INVISIBLE_OBJECTS
  102. 		} else if (!strncmpi(bp, "invisible ", l=10)) {
  103. 			isinvisible = 1;
  104. #endif
  105. 		} else if (!strncmpi(bp, "rustproof ", l=10) ||
  106. 			   !strncmpi(bp, "erodeproof ", l=11) ||
  107. 			   !strncmpi(bp, "corrodeproof ", l=13) ||
  108. 			   !strncmpi(bp, "fixed ", l=6) ||
  109. 			   !strncmpi(bp, "fireproof ", l=10) ||
  110. 			   !strncmpi(bp, "rotproof ", l=9)) {
  111. 			erodeproof = 1;
  112. 		} else if (!strncmpi(bp,"lit ", l=4) ||
  113. 			   !strncmpi(bp,"burning ", l=8)) {
  114. 			islit = 1;
  115. 		} else if (!strncmpi(bp,"unlit ", l=6) ||
  116. 			   !strncmpi(bp,"extinguished ", l=13)) {
  117. 			islit = 0;
  118. 		/* "unlabeled" and "blank" are synonymous */
  119. 		} else if (!strncmpi(bp,"unlabeled ", l=10) ||
  120. 			   !strncmpi(bp,"unlabelled ", l=11) ||
  121. 			   !strncmpi(bp,"blank ", l=6)) {
  122. 			unlabeled = 1;
  123. 		} else if(!strncmpi(bp, "poisoned ",l=9)
  124. #ifdef WIZARD
  125. 			  || (wizard && !strncmpi(bp, "trapped ",l=8))
  126. #endif
  127. 			  ) {
  128. 			ispoisoned=1;
  129. 		} else if(!strncmpi(bp, "greased ",l=8)) {
  130. 			isgreased=1;
  131. 		} else if (!strncmpi(bp, "very ", l=5)) {
  132. 			/* very rusted very heavy iron ball */
  133. 			very = 1;
  134. 		} else if (!strncmpi(bp, "thoroughly ", l=11)) {
  135. 			very = 2;
  136. 		} else if (!strncmpi(bp, "rusty ", l=6) ||
  137. 			   !strncmpi(bp, "rusted ", l=7) ||
  138. 			   !strncmpi(bp, "burnt ", l=6) ||
  139. 			   !strncmpi(bp, "burned ", l=7)) {
  140. 			eroded = 1 + very;
  141. 			very = 0;
  142. 		} else if (!strncmpi(bp, "corroded ", l=9) ||
  143. 			   !strncmpi(bp, "rotted ", l=7)) {
  144. 			eroded2 = 1 + very;
  145. 			very = 0;
  146. 		} else if (!strncmpi(bp, "partly eaten ", l=13)) {
  147. 			halfeaten = 1;
  148. 		} else if (!strncmpi(bp, "historic ", l=9)) {
  149. 			ishistoric = 1;
  150. 		} else if (!strncmpi(bp, "diluted ", l=8)) {
  151. 			isdiluted = 1;
  152. 		} else if(!strncmpi(bp, "empty ", l=6)) {
  153. 			contents = EMPTY;
  154. 		} else break;
  155. 		bp += l;
  156. 	}
  157. 	if(!cnt) cnt = 1;		/* %% what with "gems" etc. ? */
  158. 	if (strlen(bp) > 1) {
  159. 	    if ((p = rindex(bp, '(')) != 0) {
  160. 		if (p > bp && p[-1] == ' ') p[-1] = 0;
  161. 		else *p = 0;
  162. 		p++;
  163. 		if (!strcmpi(p, "lit)")) {
  164. 		    islit = 1;
  165. 		} else {
  166. 		    spe = atoi(p);
  167. 		    while (digit(*p)) p++;
  168. 		    if (*p == ':') {
  169. 			p++;
  170. 			rechrg = spe;
  171. 			spe = atoi(p);
  172. 			while (digit(*p)) p++;
  173. 		    }
  174. 		    if (*p != ')') {
  175. 			spe = rechrg = 0;
  176. 		    } else {
  177. 			spesgn = 1;
  178. 			p++;
  179. 			if (*p) Strcat(bp, p);
  180. 		    }
  181. 		}
  182. 	    }
  183. 	}
  184. /*
  185. otmp->spe is type schar; so we don't want spe to be any bigger or smaller.
  186. also, spe should always be positive  -- some cheaters may try to confuse
  187. atoi()
  188. */
  189. 	if (spe < 0) {
  190. 		spesgn = -1;	/* cheaters get what they deserve */
  191. 		spe = abs(spe);
  192. 	}
  193. 	if (spe > SCHAR_LIM)
  194. 		spe = SCHAR_LIM;
  195. 	if (rechrg < 0 || rechrg > 7) rechrg = 7;	/* recharge_limit */
  196.  
  197. 	/* now we have the actual name, as delivered by xname, say
  198. 		green potions called whisky
  199. 		scrolls labeled "QWERTY"
  200. 		egg
  201. 		fortune cookies
  202. 		very heavy iron ball named hoei
  203. 		wand of wishing
  204. 		elven cloak
  205. 	*/
  206. 	if ((p = strstri(bp, " named ")) != 0) {
  207. 		*p = 0;
  208. 		name = p+7;
  209. 	}
  210. 	if ((p = strstri(bp, " called ")) != 0) {
  211. 		*p = 0;
  212. 		un = p+8;
  213. 		/* "helmet called telepathy" is not "helmet" (a specific type)
  214. 		 * "shield called reflection" is not "shield" (a general type)
  215. 		 */
  216. 		for(i = 0; i < SIZE(o_ranges); i++)
  217. 		    if(!strcmpi(bp, o_ranges[i].name)) {
  218. 			oclass = o_ranges[i].oclass;
  219. 			goto srch;
  220. 		    }
  221. 	}
  222. 	if ((p = strstri(bp, " labeled ")) != 0) {
  223. 		*p = 0;
  224. 		dn = p+9;
  225. 	} else if ((p = strstri(bp, " labelled ")) != 0) {
  226. 		*p = 0;
  227. 		dn = p+10;
  228. 	}
  229. 	if ((p = strstri(bp, " of spinach")) != 0) {
  230. 		*p = 0;
  231. 		contents = SPINACH;
  232. 	}
  233.  
  234. 	/*
  235. 	Skip over "pair of ", "pairs of", "set of" and "sets of".
  236.  
  237. 	Accept "3 pair of boots" as well as "3 pairs of boots". It is valid
  238. 	English either way.  See makeplural() for more on pair/pairs.
  239.  
  240. 	We should only double count if the object in question is not
  241. 	refered to as a "pair of".  E.g. We should double if the player
  242. 	types "pair of spears", but not if the player types "pair of
  243. 	lenses".  Luckily (?) all objects that are refered to as pairs
  244. 	-- boots, gloves, and lenses -- are also not mergable, so cnt is
  245. 	ignored anyway.
  246. 	*/
  247. 	if(!strncmpi(bp, "pair of ",8)) {
  248. 		bp += 8;
  249. 		cnt *= 2;
  250. 	} else if(cnt > 1 && !strncmpi(bp, "pairs of ",9)) {
  251. 		bp += 9;
  252. 		cnt *= 2;
  253. 	} else if (!strncmpi(bp, "set of ",7)) {
  254. 		bp += 7;
  255. 	} else if (!strncmpi(bp, "sets of ",8)) {
  256. 		bp += 8;
  257. 	}
  258.  
  259. 	/*
  260. 	 * Find corpse type using "of" (figurine of an orc, tin of orc meat)
  261. 	 * Don't check if it's a wand or spellbook.
  262. 	 * (avoid "wand/finger of death" confusion).
  263. 	 */
  264. 	if (!strstri(bp, "wand ")
  265. 	 && !strstri(bp, "spellbook ")
  266. 	 && !strstri(bp, "finger ")) {
  267. 	    if ((p = strstri(bp, " of ")) != 0
  268. 		&& (mntmp = name_to_mon(p+4)) >= LOW_PM)
  269. 		*p = 0;
  270. 	}
  271. 	/* Find corpse type w/o "of" (red dragon scale mail, yeti corpse) */
  272. 	if (strncmpi(bp, "samurai sword", 13)) /* not the "samurai" monster! */
  273. 	if (strncmpi(bp, "wizard lock", 11)) /* not the "wizard" monster! */
  274. 	if (strncmpi(bp, "ninja-to", 8)) /* not the "ninja" rank */
  275. 	if (strncmpi(bp, "master key", 10)) /* not the "master" rank */
  276. 	if (strncmpi(bp, "magenta", 7)) /* not the "mage" rank */
  277. 	if (mntmp < LOW_PM && strlen(bp) > 2 &&
  278. 	    (mntmp = name_to_mon(bp)) >= LOW_PM) {
  279. 		int mntmptoo, mntmplen;	/* double check for rank title */
  280. 		char *obp = bp;
  281. 		mntmptoo = title_to_mon(bp, (int *)0, &mntmplen);
  282. 		bp += mntmp != mntmptoo ? (int)strlen(mons[mntmp].mname) : mntmplen;
  283. 		if (*bp == ' ') bp++;
  284. 		else if (!strncmpi(bp, "s ", 2)) bp += 2;
  285. 		else if (!strncmpi(bp, "es ", 3)) bp += 3;
  286. 		else if (!*bp && !actualn && !dn && !un && !oclass) {
  287. 		    /* no referent; they don't really mean a monster type */
  288. 		    bp = obp;
  289. 		    mntmp = NON_PM;
  290. 		}
  291. 	}
  292.  
  293. 	/* first change to singular if necessary */
  294. 	if (*bp) {
  295. 		char *sng = makesingular(bp);
  296. 		if (strcmp(bp, sng)) {
  297. 			if (cnt == 1) cnt = 2;
  298. 			Strcpy(bp, sng);
  299. 		}
  300. 	}
  301.  
  302. 	/* Alternate spellings (pick-ax, silver sabre, &c) */
  303. {
  304. 	struct alt_spellings *as = spellings;
  305.  
  306. 	while (as->sp) {
  307. 		if (fuzzymatch(bp, as->sp, " -", TRUE)) {
  308. 			typ = as->ob;
  309. 			goto typfnd;
  310. 		}
  311. 		as++;
  312. 	}
  313. 	/* can't use spellings list for this one due to shuffling */
  314. 	if (!strncmpi(bp, "grey spell", 10))
  315. 		*(bp + 2) = 'a';
  316. }
  317.  
  318. 	/* dragon scales - assumes order of dragons */
  319. 	if(!strcmpi(bp, "scales") &&
  320. 			mntmp >= PM_GRAY_DRAGON && mntmp <= PM_YELLOW_DRAGON) {
  321. 		typ = GRAY_DRAGON_SCALES + mntmp - PM_GRAY_DRAGON;
  322. 		mntmp = NON_PM;	/* no monster */
  323. 		goto typfnd;
  324. 	}
  325.  
  326. 	p = eos(bp);
  327. 	if(!BSTRCMPI(bp, p-10, "holy water")) {
  328. 		typ = POT_WATER;
  329. 		if ((p-bp) >= 12 && *(p-12) == 'u')
  330. 			iscursed = 1; /* unholy water */
  331. 		else blessed = 1;
  332. 		goto typfnd;
  333. 	}
  334. 	if(unlabeled && !BSTRCMPI(bp, p-6, "scroll")) {
  335. 		typ = SCR_BLANK_PAPER;
  336. 		goto typfnd;
  337. 	}
  338. 	if(unlabeled && !BSTRCMPI(bp, p-9, "spellbook")) {
  339. 		typ = SPE_BLANK_PAPER;
  340. 		goto typfnd;
  341. 	}
  342. 	/*
  343. 	 * NOTE: Gold pieces are handled as objects nowadays, and therefore
  344. 	 * this section should probably be reconsidered as well as the entire
  345. 	 * gold/money concept.  Maybe we want to add other monetary units as
  346. 	 * well in the future. (TH)
  347. 	 */
  348. 	if(!BSTRCMPI(bp, p-10, "gold piece") || !BSTRCMPI(bp, p-7, "zorkmid") ||
  349. 	   !strcmpi(bp, "gold") || !strcmpi(bp, "money") ||
  350. 	   !strcmpi(bp, "coin") || *bp == GOLD_SYM) {
  351. 			if (cnt > 5000
  352. #ifdef WIZARD
  353. 					&& !wizard
  354. #endif
  355. 						) cnt=5000;
  356. 		if (cnt < 1) cnt=1;
  357. #ifndef GOLDOBJ
  358. 		if (from_user)
  359. 		    pline("%d gold piece%s.", cnt, plur(cnt));
  360. 		u.ugold += cnt;
  361. 		flags.botl=1;
  362. 		return (&zeroobj);
  363. #else
  364. otmp = mksobj(GOLD_PIECE, FALSE, FALSE);
  365. 		otmp->quan = cnt;
  366. otmp->owt = weight(otmp);
  367. 		flags.botl=1;
  368. 		return (otmp);
  369. #endif
  370. 	}
  371. 	if (strlen(bp) == 1 &&
  372. 	   (i = def_char_to_objclass(*bp)) < MAXOCLASSES && i > ILLOBJ_CLASS
  373. #ifdef WIZARD
  374. 	    && (wizard || i != VENOM_CLASS)
  375. #else
  376. 	    && i != VENOM_CLASS
  377. #endif
  378. 	    ) {
  379. 		oclass = i;
  380. 		goto any;
  381. 	}
  382.  
  383. 	/* Search for class names: XXXXX potion, scroll of XXXXX.  Avoid */
  384. 	/* false hits on, e.g., rings for "ring mail". */
  385. 	if(strncmpi(bp, "enchant ", 8) &&
  386. 	   strncmpi(bp, "destroy ", 8) &&
  387. 	   strncmpi(bp, "food detection", 14) &&
  388. 	   strncmpi(bp, "ring mail", 9) &&
  389. 	   strncmpi(bp, "studded leather arm", 19) &&
  390. 	   strncmpi(bp, "leather arm", 11) &&
  391. 	   strncmpi(bp, "tooled horn", 11) &&
  392. 	   strncmpi(bp, "food ration", 11) &&
  393. 	   strncmpi(bp, "meat ring", 9)
  394. 	)
  395. 	for (i = 0; i < (int)(sizeof wrpsym); i++) {
  396. 		register int j = strlen(wrp[i]);
  397. 		if(!strncmpi(bp, wrp[i], j)){
  398. 			oclass = wrpsym[i];
  399. 			if(oclass != AMULET_CLASS) {
  400. 			    bp += j;
  401. 			    if(!strncmpi(bp, " of ", 4)) actualn = bp+4;
  402. 			    /* else if(*bp) ?? */
  403. 			} else
  404. 			    actualn = bp;
  405. 			goto srch;
  406. 		}
  407. 		if(!BSTRCMPI(bp, p-j, wrp[i])){
  408. 			oclass = wrpsym[i];
  409. 			p -= j;
  410. 			*p = 0;
  411. 			if(p > bp && p[-1] == ' ') p[-1] = 0;
  412. 			actualn = dn = bp;
  413. 			goto srch;
  414. 		}
  415. 	}
  416.  
  417. 	/* "grey stone" check must be before general "stone" */
  418. 	for (i = 0; i < SIZE(o_ranges); i++)
  419. 	    if(!strcmpi(bp, o_ranges[i].name)) {
  420. 		typ = rnd_class(o_ranges[i].f_o_range, o_ranges[i].l_o_range);
  421. 		goto typfnd;
  422. 	    }
  423.  
  424. 	if (!BSTRCMPI(bp, p-6, " stone")) {
  425. 		p[-6] = 0;
  426. 		oclass = GEM_CLASS;
  427. 		dn = actualn = bp;
  428. 		goto srch;
  429. 	} else if (!strcmpi(bp, "looking glass")) {
  430. 		;	/* avoid false hit on "* glass" */
  431. 	} else if (!BSTRCMPI(bp, p-6, " glass") || !strcmpi(bp, "glass")) {
  432. 		register char *g = bp;
  433. 		if (strstri(g, "broken")) return (struct obj *)0;
  434. 		if (!strncmpi(g, "worthless ", 10)) g += 10;
  435. 		if (!strncmpi(g, "piece of ", 9)) g += 9;
  436. 		if (!strncmpi(g, "colored ", 8)) g += 8;
  437. 		else if (!strncmpi(g, "coloured ", 9)) g += 9;
  438. 		if (!strcmpi(g, "glass")) {	/* choose random color */
  439. 			/* 9 different kinds */
  440. 			typ = LAST_GEM + rnd(9);
  441. 			if (objects[typ].oc_class == GEM_CLASS) goto typfnd;
  442. 			else typ = 0;	/* somebody changed objects[]? punt */
  443. 		} else {		/* try to construct canonical form */
  444. 			char tbuf[BUFSZ];
  445. 			Strcpy(tbuf, "worthless piece of ");
  446. 			Strcat(tbuf, g);  /* assume it starts with the color */
  447. 			Strcpy(bp, tbuf);
  448. 		}
  449. 	}
  450.  
  451. 	actualn = bp;
  452. 	if (!dn) dn = actualn; /* ex. "skull cap" */
  453. srch:
  454. 	/* check real names of gems first */
  455. 	if(!oclass && actualn) {
  456. 	    for(i = bases[GEM_CLASS]; i <= LAST_GEM; i++) {
  457. 		register const char *zn;
  458.  
  459. 		if((zn = OBJ_NAME(objects[i])) && !strcmpi(actualn, zn)) {
  460. 		    typ = i;
  461. 		    goto typfnd;
  462. 		}
  463. 	    }
  464. 	}
  465. 	i = oclass ? bases[(int)oclass] : 1;
  466. 	while(i < NUM_OBJECTS && (!oclass || objects[i].oc_class == oclass)){
  467. 		register const char *zn;
  468.  
  469. 		if (actualn && (zn = OBJ_NAME(objects[i])) != 0 &&
  470. 			    wishymatch(actualn, zn, TRUE)) {
  471. 			typ = i;
  472. 			goto typfnd;
  473. 		}
  474. 		if (dn && (zn = OBJ_DESCR(objects[i])) != 0 &&
  475. 			    wishymatch(dn, zn, FALSE)) {
  476. 			/* don't match extra descriptions (w/o real name) */
  477. 			if (!OBJ_NAME(objects[i])) return (struct obj *)0;
  478. 			typ = i;
  479. 			goto typfnd;
  480. 		}
  481. 		if (un && (zn = objects[i].oc_uname) != 0 &&
  482. 			    wishymatch(un, zn, FALSE)) {
  483. 			typ = i;
  484. 			goto typfnd;
  485. 		}
  486. 		i++;
  487. 	}
  488. 	if (actualn) {
  489. 		struct Jitem *j = Japanese_items;
  490. 		while(j->item) {
  491. 			if (actualn && !strcmpi(actualn, j->name)) {
  492. 				typ = j->item;
  493. 				goto typfnd;
  494. 			}
  495. 			j++;
  496. 		}
  497. 	}
  498. 	if (!strcmpi(bp, "spinach")) {
  499. 		contents = SPINACH;
  500. 		typ = TIN;
  501. 		goto typfnd;
  502. 	}
  503. 	/* Note: not strncmpi.  2 fruits, one capital, one not, are possible. */
  504. 	{
  505. 	    char *fp;
  506. 	    int l, cntf;
  507. 	    int blessedf, iscursedf, uncursedf, halfeatenf;
  508.  
  509. 	    blessedf = iscursedf = uncursedf = halfeatenf = 0;
  510. 	    cntf = 0;
  511.  
  512. 	    fp = fruitbuf;
  513. 	    for(;;) {
  514. 		if (!fp || !*fp) break;
  515. 		if (!strncmpi(fp, "an ", l=3) ||
  516. 		    !strncmpi(fp, "a ", l=2)) {
  517. 			cntf = 1;
  518. 		} else if (!cntf && digit(*fp)) {
  519. 			cntf = atoi(fp);
  520. 			while(digit(*fp)) fp++;
  521. 			while(*fp == ' ') fp++;
  522. 			l = 0;
  523. 		} else if (!strncmpi(fp, "blessed ", l=8)) {
  524. 			blessedf = 1;
  525. 		} else if (!strncmpi(fp, "cursed ", l=7)) {
  526. 			iscursedf = 1;
  527. 		} else if (!strncmpi(fp, "uncursed ", l=9)) {
  528. 			uncursedf = 1;
  529. 		} else if (!strncmpi(fp, "partly eaten ", l=13)) {
  530. 			halfeatenf = 1;
  531. 		} else break;
  532. 		fp += l;
  533. 	    }
  534.  
  535. 	    for(f=ffruit; f; f = f->nextf) {
  536. 		char *f1 = f->fname, *f2 = makeplural(f->fname);
  537.  
  538. 		if(!strncmp(fp, f1, strlen(f1)) ||
  539. 					!strncmp(fp, f2, strlen(f2))) {
  540. 			typ = SLIME_MOLD;
  541. 			blessed = blessedf;
  542. 			iscursed = iscursedf;
  543. 			uncursed = uncursedf;
  544. 			halfeaten = halfeatenf;
  545. 			cnt = cntf;
  546. 			ftype = f->fid;
  547. 			goto typfnd;
  548. 		}
  549. 	    }
  550. 	}
  551.  
  552. 	if(!oclass && actualn) {
  553. 	    short objtyp;
  554.  
  555. 	    /* Perhaps it's an artifact specified by name, not type */
  556. 	    name = artifact_name(actualn, &objtyp);
  557. 	    if(name) {
  558. 		typ = objtyp;
  559. 		goto typfnd;
  560. 	    }
  561. 	}
  562. #ifdef WIZARD
  563. 	/* Let wizards wish for traps --KAA */
  564. 	/* must come after objects check so wizards can still wish for
  565. 	 * trap objects like beartraps
  566. 	 */
  567. 	if (wizard && from_user) {
  568. 		int trap;
  569.  
  570. 		for (trap = NO_TRAP+1; trap < TRAPNUM; trap++) {
  571. 			const char *tname;
  572.  
  573. 			tname = defsyms[trap_to_defsym(trap)].explanation;
  574. 			if (!strncmpi(tname, bp, strlen(tname))) {
  575. 				/* avoid stupid mistakes */
  576. 				if((trap == TRAPDOOR || trap == HOLE)
  577. 				      && !Can_fall_thru(&u.uz)) trap = ROCKTRAP;
  578. 				(void) maketrap(u.ux, u.uy, trap);
  579. 				pline("%s.", An(tname));
  580. 				return(&zeroobj);
  581. 			}
  582. 		}
  583. 		/* or some other dungeon features -dlc */
  584. 		p = eos(bp);
  585. 		if(!BSTRCMP(bp, p-8, "fountain")) {
  586. 			levl[u.ux][u.uy].typ = FOUNTAIN;
  587. 			level.flags.nfountains++;
  588. 			if(!strncmpi(bp, "magic ", 6))
  589. 				levl[u.ux][u.uy].blessedftn = 1;
  590. 			pline("A %sfountain.",
  591. 			      levl[u.ux][u.uy].blessedftn ? "magic " : "");
  592. 			newsym(u.ux, u.uy);
  593. 			return(&zeroobj);
  594. 		}
  595. 		if(!BSTRCMP(bp, p-6, "throne")) {
  596. 			levl[u.ux][u.uy].typ = THRONE;
  597. 			pline("A throne.");
  598. 			newsym(u.ux, u.uy);
  599. 			return(&zeroobj);
  600. 		}
  601. # ifdef SINKS
  602. 		if(!BSTRCMP(bp, p-4, "sink")) {
  603. 			levl[u.ux][u.uy].typ = SINK;
  604. 			level.flags.nsinks++;
  605. 			pline("A sink.");
  606. 			newsym(u.ux, u.uy);
  607. 			return &zeroobj;
  608. 		}
  609. # endif
  610. 		if(!BSTRCMP(bp, p-4, "pool")) {
  611. 			levl[u.ux][u.uy].typ = POOL;
  612. 			del_engr_at(u.ux, u.uy);
  613. 			pline("A pool.");
  614. 			/* Must manually make kelp! */
  615. 			water_damage(level.objects[u.ux][u.uy], FALSE, TRUE);
  616. 			newsym(u.ux, u.uy);
  617. 			return &zeroobj;
  618. 		}
  619. 		if (!BSTRCMP(bp, p-4, "lava")) {  /* also matches "molten lava" */
  620. 			levl[u.ux][u.uy].typ = LAVAPOOL;
  621. 			del_engr_at(u.ux, u.uy);
  622. 			pline("A pool of molten lava.");
  623. 			if (!(Levitation || Flying)) (void) lava_effects();
  624. 			newsym(u.ux, u.uy);
  625. 			return &zeroobj;
  626. 		}
  627.  
  628. 		if(!BSTRCMP(bp, p-5, "altar")) {
  629. 		    aligntyp al;
  630.  
  631. 		    levl[u.ux][u.uy].typ = ALTAR;
  632. 		    if(!strncmpi(bp, "chaotic ", 8))
  633. 			al = A_CHAOTIC;
  634. 		    else if(!strncmpi(bp, "neutral ", 8))
  635. 			al = A_NEUTRAL;
  636. 		    else if(!strncmpi(bp, "lawful ", 7))
  637. 			al = A_LAWFUL;
  638. 		    else if(!strncmpi(bp, "unaligned ", 10))
  639. 			al = A_NONE;
  640. 		    else /* -1 - A_CHAOTIC, 0 - A_NEUTRAL, 1 - A_LAWFUL */
  641. 			al = (!rn2(6)) ? A_NONE : rn2((int)A_LAWFUL+2) - 1;
  642. 		    levl[u.ux][u.uy].altarmask = Align2amask( al );
  643. 		    pline("%s altar.", An(align_str(al)));
  644. 		    newsym(u.ux, u.uy);
  645. 		    return(&zeroobj);
  646. 		}
  647.  
  648. 		if(!BSTRCMP(bp, p-5, "grave") || !BSTRCMP(bp, p-9, "headstone")) {
  649. 		    make_grave(u.ux, u.uy, (char *) 0);
  650. 		    pline("A grave.");
  651. 		    newsym(u.ux, u.uy);
  652. 		    return(&zeroobj);
  653. 		}
  654.  
  655. 		if(!BSTRCMP(bp, p-4, "tree")) {
  656. 		    levl[u.ux][u.uy].typ = TREE;
  657. 		    pline("A tree.");
  658. 		    newsym(u.ux, u.uy);
  659. 		    block_point(u.ux, u.uy);
  660. 		    return &zeroobj;
  661. 		}
  662.  
  663. 		if(!BSTRCMP(bp, p-4, "bars")) {
  664. 		    levl[u.ux][u.uy].typ = IRONBARS;
  665. 		    pline("Iron bars.");
  666. 		    newsym(u.ux, u.uy);
  667. 		    return &zeroobj;
  668. 		}
  669. 	}
  670. #endif
  671. 	if(!oclass) return((struct obj *)0);
  672. any:
  673. 	if(!oclass) oclass = wrpsym[rn2((int)sizeof(wrpsym))];
  674. typfnd:
  675. 	if (typ) oclass = objects[typ].oc_class;
  676.  
  677. 	/* check for some objects that are not allowed */
  678. 	if (typ && objects[typ].oc_unique) {
  679. #ifdef WIZARD
  680. 	    if (wizard)
  681. 		;	/* allow unique objects */
  682. 	    else
  683. #endif
  684. 	    switch (typ) {
  685. 		case AMULET_OF_YENDOR:
  686. 		    typ = FAKE_AMULET_OF_YENDOR;
  687. 		    break;
  688. 		case CANDELABRUM_OF_INVOCATION:
  689. 		    typ = rnd_class(TALLOW_CANDLE, WAX_CANDLE);
  690. 		    break;
  691. 		case BELL_OF_OPENING:
  692. 		    typ = BELL;
  693. 		    break;
  694. 		case SPE_BOOK_OF_THE_DEAD:
  695. 		    typ = SPE_BLANK_PAPER;
  696. 		    break;
  697. 	    }
  698. 	}
  699.  
  700. 	/* catch any other non-wishable objects */
  701. 	if (objects[typ].oc_nowish
  702. #ifdef WIZARD
  703. 	    && !wizard
  704. #endif
  705. 	    )
  706. 	    return((struct obj *)0);
  707.  
  708. 	/* convert magic lamps to regular lamps before lighting them or setting
  709. 	   the charges */
  710. 	if (typ == MAGIC_LAMP
  711. #ifdef WIZARD
  712. 				&& !wizard
  713. #endif
  714. 						)
  715. 	    typ = OIL_LAMP;
  716.  
  717. 	if(typ) {
  718. 		otmp = mksobj(typ, TRUE, FALSE);
  719. 	} else {
  720. 		otmp = mkobj(oclass, FALSE);
  721. 		if (otmp) typ = otmp->otyp;
  722. 	}
  723.  
  724. 	if (islit &&
  725. 		(typ == OIL_LAMP || typ == MAGIC_LAMP || typ == BRASS_LANTERN ||
  726. 		 Is_candle(otmp) || typ == POT_OIL)) {
  727. 	    place_object(otmp, u.ux, u.uy);  /* make it viable light source */
  728. 	    begin_burn(otmp, FALSE);
  729. 	    obj_extract_self(otmp);	 /* now release it for caller's use */
  730. 	}
  731.  
  732. 	if(cnt > 0 && objects[typ].oc_merge && oclass != SPBOOK_CLASS &&
  733. 		(cnt < rnd(6) ||
  734. #ifdef WIZARD
  735. 		wizard ||
  736. #endif
  737. 		 (cnt <= 7 && Is_candle(otmp)) ||
  738. 		 (cnt <= 20 &&
  739. 		  ((oclass == WEAPON_CLASS && is_ammo(otmp))
  740. 				|| typ == ROCK || is_missile(otmp)))))
  741. 			otmp->quan = (long) cnt;
  742.  
  743. #ifdef WIZARD
  744. 	if (oclass == VENOM_CLASS) otmp->spe = 1;
  745. #endif
  746.  
  747. 	if (spesgn == 0) spe = otmp->spe;
  748. #ifdef WIZARD
  749. 	else if (wizard) /* no alteration to spe */ ;
  750. #endif
  751. 	else if (oclass == ARMOR_CLASS || oclass == WEAPON_CLASS ||
  752. 		 is_weptool(otmp) ||
  753. 			(oclass==RING_CLASS && objects[typ].oc_charged)) {
  754. 		if(spe > rnd(5) && spe > otmp->spe) spe = 0;
  755. 		if(spe > 2 && Luck < 0) spesgn = -1;
  756. 	} else {
  757. 		if (oclass == WAND_CLASS) {
  758. 			if (spe > 1 && spesgn == -1) spe = 1;
  759. 		} else {
  760. 			if (spe > 0 && spesgn == -1) spe = 0;
  761. 		}
  762. 		if (spe > otmp->spe) spe = otmp->spe;
  763. 	}
  764.  
  765. 	if (spesgn == -1) spe = -spe;
  766.  
  767. 	/* set otmp->spe.  This may, or may not, use spe... */
  768. 	switch (typ) {
  769. 		case TIN: if (contents==EMPTY) {
  770. 				otmp->corpsenm = NON_PM;
  771. 				otmp->spe = 0;
  772. 			} else if (contents==SPINACH) {
  773. 				otmp->corpsenm = NON_PM;
  774. 				otmp->spe = 1;
  775. 			}
  776. 			break;
  777. 		case SLIME_MOLD: otmp->spe = ftype;
  778. 			/* Fall through */
  779. 		case SKELETON_KEY: case CHEST: case LARGE_BOX:
  780. 		case HEAVY_IRON_BALL: case IRON_CHAIN: case STATUE:
  781. 			/* otmp->cobj already done in mksobj() */
  782. 				break;
  783. #ifdef MAIL
  784. 		case SCR_MAIL: otmp->spe = 1; break;
  785. #endif
  786. 		case WAN_WISHING:
  787. #ifdef WIZARD
  788. 			if (!wizard) {
  789. #endif
  790. 				otmp->spe = (rn2(10) ? -1 : 0);
  791. 				break;
  792. #ifdef WIZARD
  793. 			}
  794. 			/* fall through, if wizard */
  795. #endif
  796. 		default: otmp->spe = spe;
  797. 	}
  798.  
  799. 	/* set otmp->corpsenm or dragon scale [mail] */
  800. 	if (mntmp >= LOW_PM) {
  801. 		if (mntmp == PM_LONG_WORM_TAIL) mntmp = PM_LONG_WORM;
  802.  
  803. 		switch (typ) {
  804. 		case TIN:
  805. 			otmp->spe = 0; /* No spinach */
  806. 			if (dead_species(mntmp, FALSE)) {
  807. 			    otmp->corpsenm = NON_PM;	/* it's empty */
  808. 			} else if (!(mons[mntmp].geno & G_UNIQ) &&
  809. 				   !(mvitals[mntmp].mvflags & G_NOCORPSE) &&
  810. 				   mons[mntmp].cnutrit != 0) {
  811. 			    otmp->corpsenm = mntmp;
  812. 			}
  813. 			break;
  814. 		case CORPSE:
  815. 			if (!(mons[mntmp].geno & G_UNIQ) &&
  816. 				   !(mvitals[mntmp].mvflags & G_NOCORPSE)) {
  817. 			    /* beware of random troll or lizard corpse,
  818. 			       or of ordinary one being forced to such */
  819. 			    if (otmp->timed) obj_stop_timers(otmp);
  820. 			    if (mons[mntmp].msound == MS_GUARDIAN)
  821. 			    	otmp->corpsenm = genus(mntmp,1);
  822. 			    else
  823. 				otmp->corpsenm = mntmp;
  824. 			    start_corpse_timeout(otmp);
  825. 			}
  826. 			break;
  827. 		case FIGURINE:
  828. 			if (!(mons[mntmp].geno & G_UNIQ)
  829. 			    && !is_human(&mons[mntmp])
  830. #ifdef MAIL
  831. 			    && mntmp != PM_MAIL_DAEMON
  832. #endif
  833. 							)
  834. 				otmp->corpsenm = mntmp;
  835. 			break;
  836. 		case EGG:
  837. 			mntmp = can_be_hatched(mntmp);
  838. 			if (mntmp != NON_PM) {
  839. 			    otmp->corpsenm = mntmp;
  840. 			    if (!dead_species(mntmp, TRUE))
  841. 				attach_egg_hatch_timeout(otmp);
  842. 			    else
  843. 				kill_egg(otmp);
  844. 			}
  845. 			break;
  846. 		case STATUE: otmp->corpsenm = mntmp;
  847. 			if (Has_contents(otmp) && verysmall(&mons[mntmp]))
  848. 			    delete_contents(otmp);	/* no spellbook */
  849. 			otmp->spe = ishistoric ? STATUE_HISTORIC : 0;
  850. 			break;
  851. 		case SCALE_MAIL:
  852. 			/* Dragon mail - depends on the order of objects */
  853. 			/*		 & dragons.			 */
  854. 			if (mntmp >= PM_GRAY_DRAGON &&
  855. 						mntmp <= PM_YELLOW_DRAGON)
  856. 			    otmp->otyp = GRAY_DRAGON_SCALE_MAIL +
  857. 						    mntmp - PM_GRAY_DRAGON;
  858. 			break;
  859. 		}
  860. 	}
  861.  
  862. 	/* set blessed/cursed -- setting the fields directly is safe
  863. 	 * since weight() is called below and addinv() will take care
  864. 	 * of luck */
  865. 	if (iscursed) {
  866. 		curse(otmp);
  867. 	} else if (uncursed) {
  868. 		otmp->blessed = 0;
  869. 		otmp->cursed = (Luck < 0
  870. #ifdef WIZARD
  871. 					 && !wizard
  872. #endif
  873. 							);
  874. 	} else if (blessed) {
  875. 		otmp->blessed = (Luck >= 0
  876. #ifdef WIZARD
  877. 					 || wizard
  878. #endif
  879. 							);
  880. 		otmp->cursed = (Luck < 0
  881. #ifdef WIZARD
  882. 					 && !wizard
  883. #endif
  884. 							);
  885. 	} else if (spesgn < 0) {
  886. 		curse(otmp);
  887. 	}
  888.  
  889. #ifdef INVISIBLE_OBJECTS
  890. 	if (isinvisible) otmp->oinvis = 1;
  891. #endif
  892.  
  893. 	/* set eroded */
  894. 	if (is_damageable(otmp) || otmp->otyp == CRYSKNIFE) {
  895. 	    if (eroded && (is_flammable(otmp) || is_rustprone(otmp)))
  896. 		    otmp->oeroded = eroded;
  897. 	    if (eroded2 && (is_corrodeable(otmp) || is_rottable(otmp)))
  898. 		    otmp->oeroded2 = eroded2;
  899.  
  900. 	    /* set erodeproof */
  901. 	    if (erodeproof && !eroded && !eroded2)
  902. 		    otmp->oerodeproof = (Luck >= 0
  903. #ifdef WIZARD
  904. 					     || wizard
  905. #endif
  906. 					);
  907. 	}
  908.  
  909. 	/* set otmp->recharged */
  910. 	if (oclass == WAND_CLASS) {
  911. 	    /* prevent wishing abuse */
  912. 	    if (otmp->otyp == WAN_WISHING
  913. #ifdef WIZARD
  914. 		    && !wizard
  915. #endif
  916. 		) rechrg = 1;
  917. 	    otmp->recharged = (unsigned)rechrg;
  918. 	}
  919.  
  920. 	/* set poisoned */
  921. 	if (ispoisoned) {
  922. 	    if (is_poisonable(otmp))
  923. 		otmp->opoisoned = (Luck >= 0);
  924. 	    else if (Is_box(otmp) || typ == TIN)
  925. 		otmp->otrapped = 1;
  926. 	    else if (oclass == FOOD_CLASS)
  927. 		/* try to taint by making it as old as possible */
  928. 		otmp->age = 1L;
  929. 	}
  930.  
  931. 	if (isgreased) otmp->greased = 1;
  932.  
  933. 	if (isdiluted && otmp->oclass == POTION_CLASS &&
  934. 			otmp->otyp != POT_WATER)
  935. 		otmp->odiluted = 1;
  936.  
  937. 	if (name) {
  938. 		const char *aname;
  939. 		short objtyp;
  940.  
  941. 		/* an artifact name might need capitalization fixing */
  942. 		aname = artifact_name(name, &objtyp);
  943. 		if (aname && objtyp == otmp->otyp) name = aname;
  944.  
  945. 		otmp = oname(otmp, name);
  946. 		if (otmp->oartifact) {
  947. 			otmp->quan = 1L;
  948. 			u.uconduct.wisharti++;	/* KMH, conduct */
  949. 		}
  950. 	}
  951.  
  952. 	/* more wishing abuse: don't allow wishing for certain artifacts */
  953. 	/* and make them pay; charge them for the wish anyway! */
  954. 	if ((is_quest_artifact(otmp) ||
  955. 	     (otmp->oartifact && rn2(nartifact_exist()) > 1))
  956. #ifdef WIZARD
  957. 	    && !wizard
  958. #endif
  959. 	    ) {
  960. 	    artifact_exists(otmp, ONAME(otmp), FALSE);
  961. 	    obfree(otmp, (struct obj *) 0);
  962. 	    otmp = &zeroobj;
  963. 	    pline("For a moment, you feel %s in your %s, but it disappears!",
  964. 		  something,
  965. 		  makeplural(body_part(HAND)));
  966. 	}
  967.  
  968. 	if (halfeaten && otmp->oclass == FOOD_CLASS) {
  969. 		if (otmp->otyp == CORPSE)
  970. 			otmp->oeaten = mons[otmp->corpsenm].cnutrit;
  971. 		else otmp->oeaten = objects[otmp->otyp].oc_nutrition;
  972. 		/* (do this adjustment before setting up object's weight) */
  973. 		consume_oeaten(otmp, 1);
  974. 	}
  975. 	otmp->owt = weight(otmp);
  976. 	if (very && otmp->otyp == HEAVY_IRON_BALL) otmp->owt += 160;
  977.  
  978. 	return(otmp);
  979. }

rnd_class[edit]

  1. int
  2. rnd_class(first,last)
  3. int first,last;
  4. {
  5. 	int i, x, sum=0;
  6.  
  7. 	if (first == last)
  8. 	    return (first);
  9. 	for(i=first; i<=last; i++)
  10. 		sum += objects[i].oc_prob;
  11. 	if (!sum) /* all zero */
  12. 		return first + rn2(last-first+1);
  13. 	x = rnd(sum);
  14. 	for(i=first; i<=last; i++)
  15. 		if (objects[i].oc_prob && (x -= objects[i].oc_prob) <= 0)
  16. 			return i;
  17. 	return 0;
  18. }

Japanese_item_name[edit]

  1. STATIC_OVL const char *
  2. Japanese_item_name(i)
  3. int i;
  4. {
  5. 	struct Jitem *j = Japanese_items;
  6.  
  7. 	while(j->item) {
  8. 		if (i == j->item)
  9. 			return j->name;
  10. 		j++;
  11. 	}
  12. 	return (const char *)0;
  13. }

cloak_simple_name[edit]

  1. const char *
  2. cloak_simple_name(cloak)
  3. struct obj *cloak;
  4. {
  5. if (cloak) {
  6. 	switch (cloak->otyp) {
  7. 	case ROBE:
  8. 	    return "robe";
  9. 	case MUMMY_WRAPPING:
  10. 	    return "wrapping";
  11. 	case ALCHEMY_SMOCK:
  12. 	    return (objects[cloak->otyp].oc_name_known &&
  13. 			cloak->dknown) ? "smock" : "apron";
  14. 	default:
  15. 	    break;
  16. 	}
  17. }
  18. return "cloak";
  19. }

mimic_obj_name[edit]

  1. const char *
  2. mimic_obj_name(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	if (mtmp->m_ap_type == M_AP_OBJECT && mtmp->mappearance != STRANGE_OBJECT) {
  6. 		int idx = objects[mtmp->mappearance].oc_descr_idx;
  7. 		if (mtmp->mappearance == GOLD_PIECE) return "gold";
  8. 		return obj_descr[idx].oc_name;
  9. 	}
  10. 	return "whatcha-may-callit";
  11. }
  12. #endif /* OVLB */
  13.  
  14. /*objnam.c*/