Source:NetHack 2.3e/mkobj.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to mkobj.c from the source code of NetHack 2.3e.

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

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

1.    /*	SCCS Id: @(#)mkobj.c	2.3	88/02/11
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.  		if(otmp->otyp == LAMP) otmp->spe = rnd(10);
133.  		else if(otmp->otyp == MAGIC_LAMP) otmp->spe = 1;
134.  		else if(otmp->otyp == MAGIC_MARKER) otmp->spe = rnd(100);
135.  	case CHAIN_SYM:
136.  	case BALL_SYM:
137.  	case ROCK_SYM:
138.  	case POTION_SYM:
139.  	case SCROLL_SYM:
140.  	case AMULET_SYM:
141.  		break;
142.  #ifdef SPELLS
143.  	case SPBOOK_SYM:
144.  		if(!rn2(17)) otmp->cursed = 1;
145.  		break;
146.  #endif
147.  	case ARMOR_SYM:
148.  		if(!rn2(8)) otmp->cursed = 1;
149.  		if(!rn2(10)) otmp->spe = rne(2);
150.  		else if(!rn2(9)) {
151.  			otmp->spe = -rne(2);
152.  			otmp->cursed = 1;
153.  		}
154.  		break;
155.  	case WAND_SYM:
156.  #ifdef HARD
157.  		if(otmp->otyp == WAN_WISHING) otmp->spe = rnd(3); else
158.  #else		
159.  		if(otmp->otyp == WAN_WISHING) otmp->spe = 3; else
160.  #endif		
161.  		otmp->spe = rn1(5,
162.  			(objects[otmp->otyp].bits & NODIR) ? 11 : 4);
163.  		break;
164.  	case RING_SYM:
165.  		if(objects[otmp->otyp].bits & SPEC) {
166.  			if(!rn2(3)) {
167.  				otmp->cursed = 1;
168.  				otmp->spe = -rne(3);
169.  			} else otmp->spe = rne(3);
170.  		} else if(otmp->otyp == RIN_TELEPORTATION ||
171.  			  otmp->otyp == RIN_POLYMORPH ||
172.  			  otmp->otyp == RIN_AGGRAVATE_MONSTER ||
173.  			  otmp->otyp == RIN_HUNGER || !rn2(9))
174.  			otmp->cursed = 1;
175.  		break;
176.  	default:
177.  		panic("impossible mkobj %d, sym '%c'.", otmp->otyp, let);
178.  	}
179.  	otmp->owt = weight(otmp);
180.  	return(otmp);
181.  }
182.  
183.  letter(c) {
184.  	return(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
185.  }
186.  
187.  weight(obj)
188.  register struct obj *obj;
189.  {
190.  register int wt = objects[obj->otyp].oc_weight;
191.  	return(wt ? wt*obj->quan : (obj->quan + 1)/2);
192.  }
193.  
194.  mkgold(num,x,y)
195.  register long num;
196.  {
197.  	register struct gold *gold;
198.  	register long amount = (num ? num : 1 + (rnd(dlevel+2) * rnd(30)));
199.  
200.  	if(gold = g_at(x,y))
201.  		gold->amount += amount;
202.  	else {
203.  		gold = newgold();
204.  		gold->ngold = fgold;
205.  		gold->gx = x;
206.  		gold->gy = y;
207.  		gold->amount = amount;
208.  		fgold = gold;
209.  		/* do sth with display? */
210.  	}
211.  }