Source:NetHack 2.2a/mkobj.c

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

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

1.   /*	SCCS Id: @(#)mkobj.c	2.2	87/11/29 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.     4.    #include "hack.h"  5.    #ifdef SPELLS 6.   char mkobjstr[] = "))[[!!!!????+%%%%/=**))[[!!!!????+%%%%/=**(%";  7.    #else  8.    char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(%";  9.    #endif  10.    11.   struct obj *mkobj, *mksobj;  12.    13.   struct obj *  14.   mkobj_at(let,x,y)  15.   register int let,x,y;  16.   {  17.   	register struct obj *otmp = mkobj(let);  18.   	otmp->ox = x;  19.   	otmp->oy = y;  20.   	otmp->nobj = fobj;  21.   	fobj = otmp;  22.   	return(otmp);  23.   }  24.    25.   struct obj *  26.   mksobj_at(otyp,x,y)  27.   register int otyp,x,y;  28.   {  29.   	register struct obj *otmp = mksobj(otyp);  30.   	otmp->ox = x;  31.   	otmp->oy = y;  32.   	otmp->nobj = fobj;  33.   	return((fobj = otmp));  34.   }  35.    36.   #ifdef RPH  37.   struct obj *  38.   mk_named_obj_at (let, x, y, nm, lth)	/* used for named corpses */  39.   register let, x, y;  40.   char * nm;  41.   register int lth;  42.   {  43.   	register struct obj *otmp;  44.   	register struct obj *obj2;  45.    46.   	if (lth == 0)  return (mkobj_at (let,x,y));  47.    48.   	otmp =  mkobj(let);  49.   	obj2 = newobj(lth);  50.   	*obj2 = *otmp;  51.   	obj2->onamelth = lth;  52.   	(void) strcpy (ONAME(obj2), nm);  53.   	free( (char *)otmp);  54.   	obj2->ox = x;  55.   	obj2->oy = y;  56.   	obj2->nobj = fobj;  57.   	fobj = obj2;  58.   	return(obj2);  59.   }  60.   #endif  61.    62.   struct obj *  63.   mkobj(let) {  64.   int realtype;  65.   	switch (let) {  66.   		case RANDOM_SYM: {  67.   			realtype=probtype(mkobjstr[rn2(sizeof(mkobjstr)-1)]);  68.   			break;  69.   		}  70.   		case '3': { realtype = DEAD_SOLDIER; break; }  71.   		case '9': { realtype = DEAD_GIANT; break; }  72.   		case '&': { realtype = DEAD_DEMON; break; }  73.   		default: realtype = letter(let) ?  74.   				CORPSE + ((let>'Z') ? (let-'a'+'Z'-'@'+1) : (let-'@'))  75.   			:	probtype(let);  76.   	}  77.   	return(mksobj(realtype));  78.   }  79.   	  80.    81.   struct obj zeroobj;  82.    83.   struct obj *  84.   mksobj(otyp)  85.   register otyp;  86.   {  87.   	register struct obj *otmp;  88.   	char let = objects[otyp].oc_olet;  89.    90.   	otmp = newobj(0);  91.   	*otmp = zeroobj;  92.   	otmp->age = moves;  93.   	otmp->o_id = flags.ident++;  94.   	otmp->quan = 1;  95.   	otmp->olet = let;  96.   	otmp->otyp = otyp;  97.   	otmp->dknown = index(  98.   #ifdef KAA  99.   #ifdef SPELLS  100.  	"/=!?*+)",  101.  #else  102.  	"/=!?*)",  103.  #endif  104.  #else  105.  #ifdef SPELLS  106.  	"/=!?*+",  107.  #else  108.  	"/=!?*",  109.  #endif  110.  #endif  111.  		    let) ? 0 : 1;  112.  	switch(let) {  113.  	case WEAPON_SYM:  114.  		otmp->quan = (otmp->otyp <= ROCK) ? rn1(6,6) : 1;  115.  		if(!rn2(11)) otmp->spe = rne(2);  116.  		else if(!rn2(10)) {  117.  			otmp->cursed = 1;  118.  			otmp->spe = -rne(2);  119.  		}  120.  		break;  121.  	case FOOD_SYM:  122.  		if(otmp->otyp >= CORPSE) break;  123.  #ifdef NOT_YET_IMPLEMENTED  124.  		/* if tins are to be identified, need to adapt doname etc */  125.  		if(otmp->otyp == TIN)  126.  			otmp->spe = rnd(...);  127.  #endif  128.  		/* fall into next case */  129.  	case GEM_SYM:  130.  		otmp->quan = rn2(6) ? 1 : 2;  131.  	case TOOL_SYM:  132.  	case CHAIN_SYM:  133.  	case BALL_SYM:  134.  	case ROCK_SYM:  135.  	case POTION_SYM:  136.  	case SCROLL_SYM:  137.  	case AMULET_SYM:  138.  		break;  139.  #ifdef SPELLS  140.  	case SPBOOK_SYM:  141.  		if(!rn2(17)) otmp->cursed = 1;  142.  		break;  143.  #endif  144.  	case ARMOR_SYM:  145.  		if(!rn2(8)) otmp->cursed = 1;  146.  		if(!rn2(10)) otmp->spe = rne(2);  147.  		else if(!rn2(9)) {  148.  			otmp->spe = -rne(2);  149.  			otmp->cursed = 1;  150.  		}  151.  		break;  152.  	case WAND_SYM:  153.  #ifdef HARD  154.  		if(otmp->otyp == WAN_WISHING) otmp->spe = rnd(3); else  155.  #else		  156.  		if(otmp->otyp == WAN_WISHING) otmp->spe = 3; else  157.  #endif		  158.  		otmp->spe = rn1(5,  159.  			(objects[otmp->otyp].bits & NODIR) ? 11 : 4);  160.  		break;  161.  	case RING_SYM:  162.  		if(objects[otmp->otyp].bits & SPEC) {  163.  			if(!rn2(3)) {  164.  				otmp->cursed = 1;  165.  				otmp->spe = -rne(3);  166.  			} else otmp->spe = rne(3);  167.  		} else if(otmp->otyp == RIN_TELEPORTATION ||  168.  			  otmp->otyp == RIN_POLYMORPH ||  169.  			  otmp->otyp == RIN_AGGRAVATE_MONSTER ||  170.  			  otmp->otyp == RIN_HUNGER || !rn2(9))  171.  			otmp->cursed = 1;  172.  		break;  173.  	default:  174.  		panic("impossible mkobj %d, sym '%c'.", otmp->otyp, let);  175.  	}  176.  	otmp->owt = weight(otmp);  177.  	return(otmp);  178.  }  179.   180.  letter(c) {  181.  	return(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));  182.  }  183.   184.  weight(obj)  185.  register struct obj *obj;  186.  {  187.  register int wt = objects[obj->otyp].oc_weight;  188.  	return(wt ? wt*obj->quan : (obj->quan + 1)/2);  189.  }  190.   191.  mkgold(num,x,y)  192.  register long num;  193.  {  194.  	register struct gold *gold;  195.  	register long amount = (num ? num : 1 + (rnd(dlevel+2) * rnd(30)));  196.   197.  	if(gold = g_at(x,y))  198.  		gold->amount += amount;  199.  	else {  200.  		gold = newgold;  201.  		gold->ngold = fgold;  202.  		gold->gx = x;  203.  		gold->gy = y;  204.  		gold->amount = amount;  205.  		fgold = gold;  206.  		/* do sth with display? */  207.  	}  208.  }