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