Source:Hack 1.0/hack.mkobj.c

From NetHackWiki
Jump to: navigation, search

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

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

Screenshots and source code from Hack are used under the CWI license.

1.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
2.    
3.    #ifdef MKLEV
4.    #include "mklev.h"
5.    #else
6.    #include "hack.h"
7.    #endif MKLEV
8.    
9.    #include "hack.onames.h"
10.   
11.   char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(";
12.   struct obj *mkobj(), *mksobj();
13.   
14.   mkobj_at(let,x,y)
15.   register 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.   }
23.   
24.   #ifndef MKLEV
25.   mksobj_at(let,otyp,x,y)
26.   register let,otyp,x,y;
27.   {
28.   	register struct obj *otmp = mksobj(let, otyp);
29.   	otmp->ox = x;
30.   	otmp->oy = y;
31.   	otmp->nobj = fobj;
32.   	fobj = otmp;
33.   }
34.   #endif MKLEV
35.   
36.   struct obj *
37.   mkobj(let) {
38.   	if(!let) let = mkobjstr[rn2(sizeof(mkobjstr) - 1)];
39.   	return(mksobj(let, letter(let) ? CORPSE : probtype(let)));
40.   }
41.   	
42.   
43.   struct obj zeroobj;
44.   
45.   struct obj *
46.   mksobj(let, otyp) {
47.   	register struct obj *otmp;
48.   
49.   	otmp = newobj(0);
50.   	*otmp = zeroobj;
51.   #ifdef MKLEV
52.   	otmp->age = 0;
53.   	otmp->o_id = 0;
54.   #else
55.   	otmp->age = moves;
56.   	otmp->o_id = flags.ident++;
57.   #endif MKLEV
58.   	otmp->quan = 1;
59.   	if(letter(let)){
60.   		otmp->olet = FOOD_SYM;
61.   		otmp->otyp = CORPSE + ((let > 'Z') ? (let-'a'+'Z'-'@'+1) :
62.   				(let-'@'));
63.   		otmp->spe = let;
64.   		otmp->known = 1;
65.   		otmp->owt = weight(otmp);
66.   		return(otmp);
67.   	}
68.   	otmp->olet = let;
69.   	otmp->otyp = otyp;
70.   	otmp->dknown = index("/=!?*", let) ? 0 : 1;
71.   	switch(let) {
72.   	case WEAPON_SYM:
73.   		otmp->quan = (otmp->otyp <= ROCK) ? rn1(6,6) : 1;
74.   		if(!rn2(11)) otmp->spe = rnd(3);
75.   		else if(!rn2(10)) {
76.   			otmp->cursed = 1;
77.   			otmp->spe = -rnd(3);
78.   		}
79.   		break;
80.   	case FOOD_SYM:
81.   	case GEM_SYM:
82.   		otmp->quan = rn2(6) ? 1 : 2;
83.   	case TOOL_SYM:
84.   	case CHAIN_SYM:
85.   	case BALL_SYM:
86.   	case ROCK_SYM:
87.   	case POTION_SYM:
88.   	case SCROLL_SYM:
89.   	case AMULET_SYM:
90.   		break;
91.   	case ARMOR_SYM:
92.   		if(!rn2(8)) otmp->cursed = 1;
93.   		if(!rn2(10)) otmp->spe = rnd(3);
94.   		else if(!rn2(9)) {
95.   			otmp->spe = -rnd(3);
96.   			otmp->cursed = 1;
97.   		}
98.   		otmp->spe += 10 - objects[otmp->otyp].a_ac;
99.   		break;
100.  	case WAND_SYM:
101.  		if(otmp->otyp == WAN_WISHING) otmp->spe = 3; else
102.  		otmp->spe = rn1(5,
103.  			(objects[otmp->otyp].bits & NODIR) ? 11 : 4);
104.  		break;
105.  	case RING_SYM:
106.  		if(objects[otmp->otyp].bits & SPEC) {
107.  			if(!rn2(3)) {
108.  				otmp->cursed = 1;
109.  				otmp->spe = -rnd(2);
110.  			} else otmp->spe = rnd(2);
111.  		} else if(otmp->otyp == RIN_TELEPORTATION ||
112.  			  otmp->otyp == RIN_AGGRAVATE_MONSTER ||
113.  			  otmp->otyp == RIN_HUNGER || !rn2(9))
114.  			otmp->cursed = 1;
115.  		break;
116.  	default:
117.  		panic("impossible mkobj");
118.  	}
119.  	otmp->owt = weight(otmp);
120.  	return(otmp);
121.  }
122.  
123.  letter(c) {
124.  	return(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
125.  }
126.  
127.  weight(obj)
128.  register struct obj *obj;
129.  {
130.  register int wt = objects[obj->otyp].oc_weight;
131.  	return(wt ? wt*obj->quan : (obj->quan + 1)/2);
132.  }
133.  
134.  mkgold(num,x,y)
135.  register num;
136.  {
137.  	register struct gen *gtmp;
138.  	register int amount = num ? num : 1 + (rnd(dlevel+2) * rnd(30));
139.  
140.  	if(gtmp = g_at(x,y,fgold))
141.  		gtmp->gflag += amount;
142.  	else {
143.  		gtmp = newgen();
144.  		gtmp->ngen = fgold;
145.  		gtmp->gx = x;
146.  		gtmp->gy = y;
147.  		gtmp->gflag = amount;
148.  		fgold = gtmp;
149.  #ifdef MKLEV
150.  		levl[x][y].scrsym = '$';
151.  #endif MKLEV
152.  	}
153.  }