Source:NetHack 1.4f/mkobj.c

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