comparison arogue5/things.c @ 63:0ed67132cf10

Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 09 Aug 2012 22:58:48 +0000
parents
children c49f7927b0fa
comparison
equal deleted inserted replaced
62:0ef99244acb8 63:0ed67132cf10
1 /*
2 * Contains functions for dealing with things like
3 * potions and scrolls
4 *
5 * Advanced Rogue
6 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
7 * All rights reserved.
8 *
9 * Based on "Rogue: Exploring the Dungeons of Doom"
10 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
11 * All rights reserved.
12 *
13 * See the file LICENSE.TXT for full copyright and licensing information.
14 */
15
16 #include "curses.h"
17 #include <ctype.h>
18 #include "rogue.h"
19
20 /*
21 * print out the number of charges on a stick
22 */
23 char *
24 charge_str(obj)
25 register struct object *obj;
26 {
27 static char buf[20];
28
29 if (!(obj->o_flags & ISKNOW))
30 buf[0] = '\0';
31 else if (terse)
32 sprintf(buf, " [%d]", obj->o_charges);
33 else
34 sprintf(buf, " [%d charges]", obj->o_charges);
35 return buf;
36 }
37 /*
38 * inv_name:
39 * return the name of something as it would appear in an
40 * inventory.
41 */
42 char *
43 inv_name(obj, drop)
44 register struct object *obj;
45 bool drop;
46 {
47 register char *pb;
48
49 pb = prbuf;
50 pb[0] = '\0';
51 switch(obj->o_type) {
52 case SCROLL:
53 if (obj->o_count == 1)
54 sprintf(pb, "A %sscroll ", blesscurse(obj->o_flags));
55 else
56 sprintf(pb, "%d %sscrolls ",
57 obj->o_count, blesscurse(obj->o_flags));
58 pb = &pb[strlen(pb)];
59 if (s_know[obj->o_which] || (obj->o_flags & ISPOST))
60 sprintf(pb, "of %s", s_magic[obj->o_which].mi_name);
61 else if (s_guess[obj->o_which])
62 sprintf(pb, "called %s", s_guess[obj->o_which]);
63 else
64 sprintf(pb, "titled '%s'", s_names[obj->o_which]);
65 when POTION:
66 if (obj->o_count == 1)
67 sprintf(pb, "A %spotion ", blesscurse(obj->o_flags));
68 else
69 sprintf(pb, "%d %spotions ",
70 obj->o_count, blesscurse(obj->o_flags));
71 pb = &pb[strlen(pb)];
72 if (obj->o_flags & ISPOST)
73 sprintf(pb, "of %s", p_magic[obj->o_which].mi_name);
74 else if (p_know[obj->o_which])
75 sprintf(pb, "of %s (%s)", p_magic[obj->o_which].mi_name,
76 p_colors[obj->o_which]);
77 else if (p_guess[obj->o_which])
78 sprintf(pb, "called %s (%s)", p_guess[obj->o_which],
79 p_colors[obj->o_which]);
80 else {
81 pb = prbuf;
82 if (obj->o_count == 1)
83 sprintf(pb, "A%s %s potion",
84 vowelstr(p_colors[obj->o_which]),
85 p_colors[obj->o_which]);
86 else
87 sprintf(pb, "%d %s potions",
88 obj->o_count, p_colors[obj->o_which]);
89 }
90 when FOOD:
91 if (obj->o_which == 1)
92 if (obj->o_count == 1)
93 sprintf(pb, "A%s %s", vowelstr(fruit), fruit);
94 else
95 sprintf(pb, "%d %ss", obj->o_count, fruit);
96 else
97 if (obj->o_count == 1)
98 strcpy(pb, "Some food");
99 else
100 sprintf(pb, "%d rations of food", obj->o_count);
101 when WEAPON:
102 if (obj->o_count > 1)
103 sprintf(pb, "%d ", obj->o_count);
104 else
105 strcpy(pb, "A ");
106 pb = &pb[strlen(pb)];
107 if (obj->o_flags & ISKNOW) {
108 strcat(pb, num(obj->o_hplus, obj->o_dplus));
109 strcat (pb, " ");
110 }
111 strcat(pb, weaps[obj->o_which].w_name);
112 if (obj->o_count > 1)
113 strcat(pb, "s");
114 if (obj == cur_weapon)
115 strcat(pb, " (weapon in hand)");
116 when ARMOR:
117 if (obj->o_flags & ISKNOW) {
118 strcat(pb, num(armors[obj->o_which].a_class - obj->o_ac, 0));
119 strcat(pb, " ");
120 }
121 strcat(pb, armors[obj->o_which].a_name);
122 if (obj == cur_armor)
123 strcat(pb, " (being worn)");
124 when STICK:
125 sprintf(pb, "A %s%s ",
126 blesscurse(obj->o_flags), ws_type[obj->o_which]);
127 pb = &pb[strlen(pb)];
128 if (obj->o_flags & ISPOST)
129 sprintf(pb, "of %s", ws_magic[obj->o_which].mi_name);
130 else if (ws_know[obj->o_which])
131 sprintf(pb, "of %s%s (%s)", ws_magic[obj->o_which].mi_name,
132 charge_str(obj), ws_made[obj->o_which]);
133 else if (ws_guess[obj->o_which])
134 sprintf(pb, "called %s (%s)", ws_guess[obj->o_which],
135 ws_made[obj->o_which]);
136 else {
137 pb = prbuf;
138 sprintf(pb, "A %s %s", ws_made[obj->o_which],
139 ws_type[obj->o_which]);
140 }
141 if (obj == cur_weapon)
142 strcat(prbuf, " (weapon in hand)");
143 when RING:
144 if (obj->o_flags & ISPOST)
145 sprintf(pb, "A ring of %s", r_magic[obj->o_which].mi_name);
146 else if (r_know[obj->o_which])
147 sprintf(pb, "A%s ring of %s (%s)", ring_num(obj),
148 r_magic[obj->o_which].mi_name, r_stones[obj->o_which]);
149 else if (r_guess[obj->o_which])
150 sprintf(pb, "A ring called %s (%s)",
151 r_guess[obj->o_which], r_stones[obj->o_which]);
152 else
153 sprintf(pb, "A%s %s ring", vowelstr(r_stones[obj->o_which]),
154 r_stones[obj->o_which]);
155 if (obj == cur_ring[LEFT_1] || obj == cur_ring[LEFT_2] ||
156 obj == cur_ring[LEFT_3] || obj == cur_ring[LEFT_4])
157 strcat(pb, " (on left hand)");
158 if (obj == cur_ring[RIGHT_1] || obj == cur_ring[RIGHT_2] ||
159 obj == cur_ring[RIGHT_3] || obj == cur_ring[RIGHT_4])
160 strcat(pb, " (on right hand)");
161 when RELIC:
162 if (obj->o_flags & ISKNOW)
163 strcpy(pb, rel_magic[obj->o_which].mi_name);
164 else switch(obj->o_which) {
165 case MUSTY_DAGGER:
166 strcpy(pb, "Two very fine daggers marked MDDE");
167 when EMORI_CLOAK:
168 strcpy(pb, "A silk cloak");
169 when HEIL_ANKH:
170 strcpy(pb, "A golden ankh");
171 when MING_STAFF:
172 strcpy(pb, "A finely carved staff");
173 when ORCUS_WAND:
174 strcpy(pb, "A sparkling ivory wand");
175 when ASMO_ROD:
176 strcpy(pb, "A glistening ebony rod");
177 when YENDOR_AMULET:
178 strcpy(pb, "A silver amulet");
179 when BRIAN_MANDOLIN:
180 strcpy(pb, "A gleaming mandolin");
181 when HRUGGEK_MSTAR:
182 strcpy(pb, "A huge morning star");
183 when GERYON_HORN:
184 strcpy(pb, "A jet black horn");
185 when YEENOGHU_FLAIL:
186 strcpy(pb, "A shimmering flail");
187 otherwise:
188 strcpy(pb, "A magical item");
189 }
190
191 /* Take care of wielding and wearing */
192 switch (obj->o_which) {
193 case EMORI_CLOAK:
194 if (cur_armor == NULL && cur_misc[WEAR_CLOAK] == NULL)
195 strcat(pb, " (being worn)");
196 when HEIL_ANKH:
197 if (cur_relic[HEIL_ANKH]) strcat(pb, " (in hand)");
198 when YENDOR_AMULET:
199 if (cur_relic[YENDOR_AMULET] &&
200 cur_misc[WEAR_JEWEL] == NULL)
201 strcat(pb, " (in chest)");
202 when MUSTY_DAGGER:
203 case HRUGGEK_MSTAR:
204 case YEENOGHU_FLAIL:
205 case MING_STAFF:
206 case ASMO_ROD:
207 case ORCUS_WAND:
208 if (cur_weapon == obj) strcat(pb, " (weapon in hand)");
209 }
210 when MM:
211 if (m_know[obj->o_which])
212 strcpy(pb, misc_name(obj));
213 else {
214 switch (obj->o_which) {
215 case MM_JUG:
216 case MM_BEAKER:
217 strcpy(pb, "A bottle");
218 when MM_KEOGHTOM:
219 strcpy(pb, "A jar");
220 when MM_JEWEL:
221 strcpy(pb, "An amulet");
222 when MM_BOOK:
223 case MM_SKILLS:
224 strcpy(pb, "A book");
225 when MM_ELF_BOOTS:
226 case MM_DANCE:
227 strcpy(pb, "A pair of boots");
228 when MM_BRACERS:
229 strcpy(pb, "A pair of bracers");
230 when MM_OPEN:
231 case MM_HUNGER:
232 strcpy(pb, "A chime");
233 when MM_DISP:
234 case MM_R_POWERLESS:
235 case MM_PROTECT:
236 strcpy(pb, "A cloak");
237 when MM_DRUMS:
238 strcpy(pb, "A set of drums");
239 when MM_DISAPPEAR:
240 case MM_CHOKE:
241 strcpy(pb, "A pouch of dust");
242 when MM_G_DEXTERITY:
243 case MM_G_OGRE:
244 case MM_FUMBLE:
245 strcpy(pb, "A pair of gauntlets");
246 when MM_ADAPTION:
247 case MM_STRANGLE:
248 strcpy(pb, "A necklace");
249 otherwise:
250 strcpy(pb, "A magical item");
251 }
252 if (m_guess[obj->o_which]) {
253 strcat(pb, " called: ");
254 strcat(pb, m_guess[obj->o_which]);
255 }
256 }
257 if (obj == cur_misc[WEAR_BOOTS] ||
258 obj == cur_misc[WEAR_BRACERS] ||
259 obj == cur_misc[WEAR_CLOAK] ||
260 obj == cur_misc[WEAR_GAUNTLET] ||
261 obj == cur_misc[WEAR_NECKLACE] ||
262 obj == cur_misc[WEAR_JEWEL])
263 strcat(pb, " (being worn)");
264 when GOLD:
265 sprintf(pb, "%d Pieces of Gold", obj->o_count);
266 otherwise:
267 debug("Picked up something funny");
268 sprintf(pb, "Something bizarre %s", unctrl(obj->o_type));
269 }
270
271 /* Is it marked? */
272 if (obj->o_mark[0]) {
273 pb = &pb[strlen(pb)];
274 sprintf(pb, " <%s>", obj->o_mark);
275 }
276
277 if (obj->o_flags & ISPROT)
278 strcat(pb, " [protected]");
279 if (drop && isupper(prbuf[0]))
280 prbuf[0] = tolower(prbuf[0]);
281 else if (!drop && islower(*prbuf))
282 *prbuf = toupper(*prbuf);
283 if (!drop)
284 strcat(pb, ".");
285 /*
286 * Truncate if long. Use COLS-4 to offset the "pack letter" of a normal
287 * inventory listing.
288 */
289 prbuf[COLS-4] = '\0';
290 return prbuf;
291 }
292
293 /*
294 * weap_name:
295 * Return the name of a weapon.
296 */
297 char *
298 weap_name(obj)
299 register struct object *obj;
300 {
301 switch (obj->o_type) {
302 case WEAPON:
303 return(weaps[obj->o_which].w_name);
304 when RELIC:
305 switch (obj->o_which) {
306 case MUSTY_DAGGER:
307 return("daggers");
308 when YEENOGHU_FLAIL:
309 return("flail");
310 when HRUGGEK_MSTAR:
311 return("morning star");
312 when MING_STAFF:
313 return("staff");
314 when ORCUS_WAND:
315 return("wand");
316 when ASMO_ROD:
317 return("rod");
318 }
319 }
320 return("weapon");
321 }
322
323 /*
324 * drop:
325 * put something down
326 */
327 drop(item)
328 struct linked_list *item;
329 {
330 register char ch = 0;
331 register struct linked_list *obj, *nobj;
332 register struct object *op;
333
334 if (item == NULL) {
335 switch(ch = CCHAR( mvwinch(stdscr, hero.y, hero.x) )) {
336 case PASSAGE:
337 case SCROLL:
338 case POTION:
339 case WEAPON:
340 case FLOOR:
341 case STICK:
342 case ARMOR:
343 case POOL:
344 case RELIC:
345 case GOLD:
346 case FOOD:
347 case RING:
348 case MM:
349 break;
350 default:
351 msg("Can't leave it here");
352 return(FALSE);
353 }
354 if ((obj = get_item(pack, "drop", ALL)) == NULL)
355 return(FALSE);
356 }
357 else {
358 obj = item;
359 }
360 op = OBJPTR(obj);
361 if (!dropcheck(op))
362 return(FALSE);
363
364 /*
365 * If it is a scare monster scroll, curse it
366 */
367 if (op->o_type == SCROLL && op->o_which == S_SCARE) {
368 if (op->o_flags & ISBLESSED)