]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.mkobj.c
Clean this up, and be more consistent:
[bsdgames-darwin.git] / hack / hack.mkobj.c
1 /*
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
3 */
4
5 #ifndef lint
6 static char rcsid[] = "$NetBSD: hack.mkobj.c,v 1.3 1995/03/23 08:30:47 cgd Exp $";
7 #endif /* not lint */
8
9 #include "hack.h"
10
11 char mkobjstr[] = "))[[!!!!????%%%%/=**))[[!!!!????%%%%/=**(%";
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 if(!let)
39 let = mkobjstr[rn2(sizeof(mkobjstr) - 1)];
40 return(
41 mksobj(
42 letter(let) ?
43 CORPSE + ((let > 'Z') ? (let-'a'+'Z'-'@'+1) : (let-'@'))
44 : probtype(let)
45 )
46 );
47 }
48
49
50 struct obj zeroobj;
51
52 struct obj *
53 mksobj(otyp)
54 register otyp;
55 {
56 register struct obj *otmp;
57 char let = objects[otyp].oc_olet;
58
59 otmp = newobj(0);
60 *otmp = zeroobj;
61 otmp->age = moves;
62 otmp->o_id = flags.ident++;
63 otmp->quan = 1;
64 otmp->olet = let;
65 otmp->otyp = otyp;
66 otmp->dknown = index("/=!?*", let) ? 0 : 1;
67 switch(let) {
68 case WEAPON_SYM:
69 otmp->quan = (otmp->otyp <= ROCK) ? rn1(6,6) : 1;
70 if(!rn2(11)) otmp->spe = rnd(3);
71 else if(!rn2(10)) {
72 otmp->cursed = 1;
73 otmp->spe = -rnd(3);
74 }
75 break;
76 case FOOD_SYM:
77 if(otmp->otyp >= CORPSE) break;
78 #ifdef NOT_YET_IMPLEMENTED
79 /* if tins are to be identified, need to adapt doname() etc */
80 if(otmp->otyp == TIN)
81 otmp->spe = rnd(...);
82 #endif NOT_YET_IMPLEMENTED
83 /* fall into next case */
84 case GEM_SYM:
85 otmp->quan = rn2(6) ? 1 : 2;
86 case TOOL_SYM:
87 case CHAIN_SYM:
88 case BALL_SYM:
89 case ROCK_SYM:
90 case POTION_SYM:
91 case SCROLL_SYM:
92 case AMULET_SYM:
93 break;
94 case ARMOR_SYM:
95 if(!rn2(8)) otmp->cursed = 1;
96 if(!rn2(10)) otmp->spe = rnd(3);
97 else if(!rn2(9)) {
98 otmp->spe = -rnd(3);
99 otmp->cursed = 1;
100 }
101 break;
102 case WAND_SYM:
103 if(otmp->otyp == WAN_WISHING) otmp->spe = 3; else
104 otmp->spe = rn1(5,
105 (objects[otmp->otyp].bits & NODIR) ? 11 : 4);
106 break;
107 case RING_SYM:
108 if(objects[otmp->otyp].bits & SPEC) {
109 if(!rn2(3)) {
110 otmp->cursed = 1;
111 otmp->spe = -rnd(2);
112 } else otmp->spe = rnd(2);
113 } else if(otmp->otyp == RIN_TELEPORTATION ||
114 otmp->otyp == RIN_AGGRAVATE_MONSTER ||
115 otmp->otyp == RIN_HUNGER || !rn2(9))
116 otmp->cursed = 1;
117 break;
118 default:
119 panic("impossible mkobj");
120 }
121 otmp->owt = weight(otmp);
122 return(otmp);
123 }
124
125 letter(c) {
126 return(('@' <= c && c <= 'Z') || ('a' <= c && c <= 'z'));
127 }
128
129 weight(obj)
130 register struct obj *obj;
131 {
132 register int wt = objects[obj->otyp].oc_weight;
133 return(wt ? wt*obj->quan : (obj->quan + 1)/2);
134 }
135
136 mkgold(num,x,y)
137 register long num;
138 {
139 register struct gold *gold;
140 register long amount = (num ? num : 1 + (rnd(dlevel+2) * rnd(30)));
141
142 if(gold = g_at(x,y))
143 gold->amount += amount;
144 else {
145 gold = newgold();
146 gold->ngold = fgold;
147 gold->gx = x;
148 gold->gy = y;
149 gold->amount = amount;
150 fgold = gold;
151 /* do sth with display? */
152 }
153 }