Mercurial > hg > early-roguelike
comparison rogue4/things.c @ 12:9535a08ddc39
Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
author | edwarj4 |
---|---|
date | Sat, 24 Oct 2009 16:52:52 +0000 |
parents | |
children | 1b73a8641b37 |
comparison
equal
deleted
inserted
replaced
11:949d558c2162 | 12:9535a08ddc39 |
---|---|
1 /* | |
2 * Contains functions for dealing with things like potions, scrolls, | |
3 * and other items. | |
4 * | |
5 * @(#)things.c 4.26 (Berkeley) 5/18/82 | |
6 * | |
7 * Rogue: Exploring the Dungeons of Doom | |
8 * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman | |
9 * All rights reserved. | |
10 * | |
11 * See the file LICENSE.TXT for full copyright and licensing information. | |
12 */ | |
13 | |
14 #include <curses.h> | |
15 #include <ctype.h> | |
16 #include <string.h> | |
17 #include "rogue.h" | |
18 | |
19 bool got_genocide = FALSE; | |
20 | |
21 /* | |
22 * inv_name: | |
23 * Return the name of something as it would appear in an | |
24 * inventory. | |
25 */ | |
26 char * | |
27 inv_name(obj, drop) | |
28 register THING *obj; | |
29 register bool drop; | |
30 { | |
31 register char *pb; | |
32 | |
33 pb = prbuf; | |
34 switch (obj->o_type) | |
35 { | |
36 case SCROLL: | |
37 if (obj->o_count == 1) | |
38 { | |
39 strcpy(pb, "A scroll "); | |
40 pb = &prbuf[9]; | |
41 } | |
42 else | |
43 { | |
44 sprintf(pb, "%d scrolls ", obj->o_count); | |
45 pb = &prbuf[strlen(prbuf)]; | |
46 } | |
47 if (s_know[obj->o_which]) | |
48 sprintf(pb, "of %s", s_magic[obj->o_which].mi_name); | |
49 else if (s_guess[obj->o_which]) | |
50 sprintf(pb, "called %s", s_guess[obj->o_which]); | |
51 else | |
52 sprintf(pb, "titled '%s'", s_names[obj->o_which]); | |
53 when POTION: | |
54 if (obj->o_count == 1) | |
55 { | |
56 strcpy(pb, "A potion "); | |
57 pb = &prbuf[9]; | |
58 } | |
59 else | |
60 { | |
61 sprintf(pb, "%d potions ", obj->o_count); | |
62 pb = &pb[strlen(prbuf)]; | |
63 } | |
64 if (p_know[obj->o_which]) | |
65 sprintf(pb, "of %s(%s)", p_magic[obj->o_which].mi_name, | |
66 p_colors[obj->o_which]); | |
67 else if (p_guess[obj->o_which]) | |
68 sprintf(pb, "called %s(%s)", p_guess[obj->o_which], | |
69 p_colors[obj->o_which]); | |
70 else if (obj->o_count == 1) | |
71 sprintf(prbuf, "A%s %s potion", vowelstr(p_colors[obj->o_which]), | |
72 p_colors[obj->o_which]); | |
73 else | |
74 sprintf(prbuf, "%d %s potions", obj->o_count, | |
75 p_colors[obj->o_which]); | |
76 when FOOD: | |
77 if (obj->o_which == 1) | |
78 if (obj->o_count == 1) | |
79 sprintf(pb, "A%s %s", vowelstr(fruit), fruit); | |
80 else | |
81 sprintf(pb, "%d %ss", obj->o_count, fruit); | |
82 else | |
83 if (obj->o_count == 1) | |
84 strcpy(pb, "Some food"); | |
85 else | |
86 sprintf(pb, "%d rations of food", obj->o_count); | |
87 when WEAPON: | |
88 if (obj->o_count > 1) | |
89 sprintf(pb, "%d ", obj->o_count); | |
90 else | |
91 sprintf(pb, "A%s ", vowelstr(w_names[obj->o_which])); | |
92 pb = &prbuf[strlen(prbuf)]; | |
93 if (obj->o_flags & ISKNOW) | |
94 sprintf(pb, "%s %s", num(obj->o_hplus, obj->o_dplus, WEAPON), | |
95 w_names[obj->o_which]); | |
96 else | |
97 sprintf(pb, "%s", w_names[obj->o_which]); | |
98 if (obj->o_count > 1) | |
99 strcat(pb, "s"); | |
100 when ARMOR: | |
101 if (obj->o_flags & ISKNOW) | |
102 { | |
103 sprintf(pb, "%s %s [", | |
104 num(a_class[obj->o_which] - obj->o_ac, 0, ARMOR), | |
105 a_names[obj->o_which]); | |
106 if (!terse) | |
107 strcat(pb, "armor class "); | |
108 pb = &prbuf[strlen(prbuf)]; | |
109 sprintf(pb, "%d]", obj->o_ac); | |
110 } | |
111 else | |
112 sprintf(pb, "%s", a_names[obj->o_which]); | |
113 when AMULET: | |
114 strcpy(pb, "The Amulet of Yendor"); | |
115 when STICK: | |
116 sprintf(pb, "A%s %s ", vowelstr(ws_type[obj->o_which]), | |
117 ws_type[obj->o_which]); | |
118 pb = &prbuf[strlen(prbuf)]; | |
119 if (ws_know[obj->o_which]) | |
120 sprintf(pb, "of %s%s(%s)", ws_magic[obj->o_which].mi_name, | |
121 charge_str(obj), ws_made[obj->o_which]); | |
122 else if (ws_guess[obj->o_which]) | |
123 sprintf(pb, "called %s(%s)", ws_guess[obj->o_which], | |
124 ws_made[obj->o_which]); | |
125 else | |
126 sprintf(pb = &prbuf[1], "%s %s %s", | |
127 vowelstr(ws_made[obj->o_which]), ws_made[obj->o_which], | |
128 ws_type[obj->o_which]); | |
129 when RING: | |
130 if (r_know[obj->o_which]) | |
131 sprintf(pb, "A%s ring of %s(%s)", ring_num(obj), | |
132 r_magic[obj->o_which].mi_name, r_stones[obj->o_which]); | |
133 else if (r_guess[obj->o_which]) | |
134 sprintf(pb, "A ring called %s(%s)", | |
135 r_guess[obj->o_which], r_stones[obj->o_which]); | |
136 else | |
137 sprintf(pb, "A%s %s ring", vowelstr(r_stones[obj->o_which]), | |
138 r_stones[obj->o_which]); | |
139 when GOLD: | |
140 sprintf(pb, "%d pieces of gold", obj->o_goldval); | |
141 #ifdef WIZARD | |
142 otherwise: | |
143 debug("Picked up something funny %s", unctrol(obj->o_type)); | |
144 sprintf(pb, "Something bizarre %s", unctrol(obj->o_type)); | |
145 #endif | |
146 } | |
147 if (obj == cur_armor) | |
148 strcat(pb, " (being worn)"); | |
149 if (obj == cur_weapon) | |
150 strcat(pb, " (weapon in hand)"); | |
151 if (obj == cur_ring[LEFT]) | |
152 strcat(pb, " (on left hand)"); | |
153 else if (obj == cur_ring[RIGHT]) | |
154 strcat(pb, " (on right hand)"); | |
155 if (drop && isupper(prbuf[0])) | |
156 prbuf[0] = tolower(prbuf[0]); | |
157 else if (!drop && islower(*prbuf)) | |
158 *prbuf = toupper(*prbuf); | |
159 return prbuf; | |
160 } | |
161 | |
162 /* | |
163 * drop: | |
164 * Put something down | |
165 */ | |
166 drop() | |
167 { | |
168 register char ch; | |
169 register THING *nobj, *op; | |
170 | |
171 ch = chat(hero.y, hero.x); | |
172 if (ch != FLOOR && ch != PASSAGE) | |
173 { | |
174 after = FALSE; | |
175 msg("there is something there already"); | |
176 return; | |
177 } | |
178 if ((op = get_item("drop", 0)) == NULL) | |
179 return; | |
180 if (!dropcheck(op)) | |
181 return; | |
182 /* | |
183 * Take it out of the pack | |
184 */ | |
185 if (op->o_count >= 2 && op->o_type != WEAPON) | |
186 { | |
187 op->o_count--; | |
188 nobj = new_item(); | |
189 *nobj = *op; | |
190 nobj->o_count = 1; | |
191 op = nobj; | |
192 if (op->o_group != 0) | |
193 inpack++; | |
194 } | |
195 else | |
196 detach(pack, op); | |
197 inpack--; | |
198 /* | |
199 * Link it into the level object list | |
200 */ | |
201 attach(lvl_obj, op); | |
202 chat(hero.y, hero.x) = op->o_type; | |
203 flat(hero.y, hero.x) |= F_DROPPED; | |
204 op->o_pos = hero; | |
205 if (op->o_type == AMULET) | |
206 amulet = FALSE; | |
207 msg("dropped %s", inv_name(op, TRUE)); | |
208 } | |
209 | |
210 /* | |
211 * dropcheck: | |
212 * Do special checks for dropping or unweilding|unwearing|unringing | |
213 */ | |
214 dropcheck(op) | |
215 register THING *op; | |
216 { | |
217 if (op == NULL) | |
218 return TRUE; | |
219 if (op != cur_armor && op != cur_weapon | |
220 && op != cur_ring[LEFT] && op != cur_ring[RIGHT]) | |
221 return TRUE; | |
222 if (op->o_flags & ISCURSED) | |
223 { | |
224 msg("you can't. It appears to be cursed"); | |
225 return FALSE; | |
226 } | |
227 if (op == cur_weapon) | |
228 cur_weapon = NULL; | |
229 else if (op == cur_armor) | |
230 { | |
231 waste_time(); | |
232 cur_armor = NULL; | |
233 } | |
234 else | |
235 { | |
236 cur_ring[op == cur_ring[LEFT] ? LEFT : RIGHT] = NULL; | |
237 switch (op->o_which) | |
238 { | |
239 case R_ADDSTR: | |
240 chg_str(-op->o_ac); | |
241 break; | |
242 case R_SEEINVIS: | |
243 unsee(); | |
244 extinguish(unsee); | |
245 break; | |
246 } | |
247 } | |
248 return TRUE; | |
249 } | |
250 | |
251 /* | |
252 * new_thing: | |
253 * Return a new thing | |
254 */ | |
255 THING * | |
256 new_thing() | |
257 { | |
258 register THING *cur; | |
259 register int j, k; | |
260 | |
261 cur = new_item(); | |
262 cur->o_hplus = cur->o_dplus = 0; | |
263 strcpy(cur->o_damage,"0d0"); | |
264 strcpy(cur->o_hurldmg,"0d0"); | |
265 cur->o_ac = 11; | |
266 cur->o_count = 1; | |
267 cur->o_group = 0; | |
268 cur->o_flags = 0; | |
269 /* | |
270 * Decide what kind of object it will be | |
271 * If we haven't had food for a while, let it be food. | |
272 */ | |
273 switch (no_food > 3 ? 2 : pick_one(things, NUMTHINGS)) | |
274 { | |
275 case 0: | |
276 cur->o_type = POTION; | |
277 cur->o_which = pick_one(p_magic, MAXPOTIONS); | |
278 when 1: | |
279 cur->o_type = SCROLL; | |
280 cur->o_which = pick_one(s_magic, MAXSCROLLS); | |
281 /* | |
282 * Only one genocide scroll allowed per game, so if it's | |
283 * the second one, then turn it into a identify scroll | |
284 */ | |
285 if (cur->o_which == S_GENOCIDE) | |
286 if (got_genocide) | |
287 cur->o_which = S_IDENT; | |
288 else | |
289 got_genocide = TRUE; | |
290 when 2: | |
291 no_food = 0; | |
292 cur->o_type = FOOD; | |
293 if (rnd(10) != 0) | |
294 cur->o_which = 0; | |
295 else | |
296 cur->o_which = 1; | |
297 when 3: | |
298 cur->o_type = WEAPON; | |
299 cur->o_which = rnd(MAXWEAPONS); | |
300 init_weapon(cur, cur->o_which); | |
301 if ((k = rnd(100)) < 10) | |
302 { | |
303 cur->o_flags |= ISCURSED; | |
304 cur->o_hplus -= rnd(3) + 1; | |
305 } | |
306 else if (k < 15) | |
307 cur->o_hplus += rnd(3) + 1; | |
308 when 4: | |
309 cur->o_type = ARMOR; | |
310 for (j = 0, k = rnd(100); j < MAXARMORS; j++) | |
311 if (k < a_chances[j]) | |
312 break; | |
313 #ifdef WIZARD | |
314 if (j == MAXARMORS) | |
315 { | |
316 debug("Picked a bad armor %d", k); | |
317 j = 0; | |
318 } | |
319 #endif | |
320 cur->o_which = j; | |
321 cur->o_ac = a_class[j]; | |
322 if ((k = rnd(100)) < 20) | |
323 { | |
324 cur->o_flags |= ISCURSED; | |
325 cur->o_ac += rnd(3) + 1; | |
326 } | |
327 else if (k < 28) | |
328 cur->o_ac -= rnd(3) + 1; | |
329 when 5: | |
330 cur->o_type = RING; | |
331 cur->o_which = pick_one(r_magic, MAXRINGS); | |
332 switch (cur->o_which) | |
333 { | |
334 case R_ADDSTR: | |
335 case R_PROTECT: | |
336 case R_ADDHIT: | |
337 case R_ADDDAM: | |
338 if ((cur->o_ac = rnd(3)) == 0) | |
339 { | |
340 cur->o_ac = -1; | |
341 cur->o_flags |= ISCURSED; | |
342 } | |
343 when R_AGGR: | |
344 case R_TELEPORT: | |
345 cur->o_flags |= ISCURSED; | |
346 } | |
347 when 6: | |
348 cur->o_type = STICK; | |
349 cur->o_which = pick_one(ws_magic, MAXSTICKS); | |
350 fix_stick(cur); | |
351 #ifdef WIZARD | |
352 otherwise: | |
353 debug("Picked a bad kind of object"); | |
354 wait_for(' '); | |
355 #endif | |
356 } | |
357 return cur; | |
358 } | |
359 | |
360 /* | |
361 * pick_one: | |
362 * Pick an item out of a list of nitems possible magic items | |
363 */ | |
364 pick_one(magic, nitems) | |
365 register struct magic_item *magic; | |
366 int nitems; | |
367 { | |
368 register struct magic_item *end; | |
369 register int i; | |
370 register struct magic_item *start; | |
371 | |
372 start = magic; | |
373 for (end = &magic[nitems], i = rnd(100); magic < end; magic++) | |
374 if (i < magic->mi_prob) | |
375 break; | |
376 if (magic == end) |