comparison urogue/things.c @ 256:c495a4f288c6

Import UltraRogue from the Roguelike Restoration Project (r1490)
author John "Elwin" Edwards
date Tue, 31 Jan 2017 19:56:04 -0500
parents
children 5a94c9b3181e
comparison
equal deleted inserted replaced
253:d9badb9c0179 256:c495a4f288c6
1 /*
2 things.c - functions for dealing with things like potions and scrolls
3
4 UltraRogue: The Ultimate Adventure in the Dungeons of Doom
5 Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong
6 All rights reserved.
7
8 Based on "Advanced Rogue"
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka
10 All rights reserved.
11
12 Based on "Rogue: Exploring the Dungeons of Doom"
13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
14 All rights reserved.
15
16 See the file LICENSE.TXT for full copyright and licensing information.
17 */
18
19 #include <string.h>
20 #include <ctype.h>
21 #include "rogue.h"
22
23 /*
24 inv_name()
25 return the name of something as it would appear in an inventory.
26 */
27
28 char *
29 inv_name(struct object *obj, int lowercase)
30 {
31 char *pb;
32 char buf[1024];
33
34 switch(obj->o_type)
35 {
36 case SCROLL:
37 if (obj->o_count == 1)
38 sprintf(prbuf, "A %s%sscroll ",
39 obj->o_flags & CANRETURN ? "claimed " : "",
40 blesscurse(obj->o_flags));
41 else
42 sprintf(prbuf, "%d %s%sscrolls ",
43 obj->o_count,
44 obj->o_flags & CANRETURN ? "claimed " : "",
45 blesscurse(obj->o_flags));
46
47 pb = &prbuf[strlen(prbuf)];
48
49 if (know_items[TYP_SCROLL][obj->o_which])
50 sprintf(pb, "of %s", s_magic[obj->o_which].mi_name);
51 else if (guess_items[TYP_SCROLL][obj->o_which])
52 sprintf(pb, "called %s", guess_items[TYP_SCROLL][obj->o_which]);
53 else
54 sprintf(pb, "titled '%s'", s_names[obj->o_which]);
55 break;
56
57 case POTION:
58 if (obj->o_count == 1)
59 sprintf(prbuf, "A %s%spotion ",
60 obj->o_flags & CANRETURN ? "claimed " : "",
61 blesscurse(obj->o_flags));
62 else
63 sprintf(prbuf, "%d %s%spotions ",
64 obj->o_count,
65 obj->o_flags & CANRETURN ? "claimed " : "",
66 blesscurse(obj->o_flags));
67
68 pb = &prbuf[strlen(prbuf)];
69
70 if (know_items[TYP_POTION][obj->o_which])
71 sprintf(pb, "of %s(%s)", p_magic[obj->o_which].mi_name,
72 p_colors[obj->o_which]);
73 else if (guess_items[TYP_POTION][obj->o_which])
74 sprintf(pb, "called %s(%s)", guess_items[TYP_POTION][obj->o_which],
75 p_colors[obj->o_which]);
76 else
77 {
78 if (obj->o_count == 1)
79 sprintf(prbuf, "A%s %s potion",
80 obj->o_flags & CANRETURN ? " claimed" :
81 (char *) vowelstr(p_colors[obj->o_which]),
82 p_colors[obj->o_which]);
83 else
84 sprintf(prbuf, "%d %s%s potions",
85 obj->o_count,
86 obj->o_flags & CANRETURN ? "claimed " : "",
87 (char *) p_colors[obj->o_which]);
88 }
89 break;
90
91 case FOOD:
92 if (obj->o_count == 1)
93 sprintf(prbuf, "A%s %s",
94 obj->o_flags & CANRETURN ? " claimed" :
95 (char *) vowelstr(fd_data[obj->o_which].mi_name),
96 fd_data[obj->o_which].mi_name);
97 else
98 sprintf(prbuf, "%d %s%ss", obj->o_count,
99 obj->o_flags & CANRETURN ? "claimed " : "",
100 fd_data[obj->o_which].mi_name);
101 break;
102
103 case WEAPON:
104 if (obj->o_count > 1)
105 sprintf(prbuf, "%d ", obj->o_count);
106 else if ((obj->o_flags & (ISZAPPED | CANRETURN | ISPOISON | ISSILVER | ISTWOH)) ||
107 ((obj->o_flags & (ISKNOW | ISZAPPED)) == (ISKNOW | ISZAPPED)))
108 strcpy(prbuf, "A ");
109 else
110 sprintf(prbuf, "A%s ", vowelstr(weaps[obj->o_which].w_name));
111
112 pb = &prbuf[strlen(prbuf)];
113
114 if ((obj->o_flags & ISKNOW) && (obj->o_flags & ISZAPPED))
115 sprintf(pb, "charged%s ", charge_str(obj,buf));
116
117 pb = &prbuf[strlen(prbuf)];
118
119 if (obj->o_flags & CANRETURN)
120 sprintf(pb, "claimed ");
121
122 pb = &prbuf[strlen(prbuf)];
123
124 if (obj->o_flags & ISPOISON)
125 sprintf(pb, "poisoned ");
126
127 pb = &prbuf[strlen(prbuf)];
128
129 if (obj->o_flags & ISSILVER)
130 sprintf(pb, "silver ");
131
132 if (obj->o_flags & ISTWOH)
133 sprintf(pb, "two-handed ");
134
135 pb = &prbuf[strlen(prbuf)];
136
137 if (obj->o_flags & ISKNOW)
138 sprintf(pb, "%s %s", num(obj->o_hplus, obj->o_dplus, buf),
139 weaps[obj->o_which].w_name);
140 else
141 sprintf(pb, "%s", weaps[obj->o_which].w_name);
142
143 if (obj->o_count > 1)
144 strcat(prbuf, "s");
145
146 break;
147
148 case ARMOR:
149 if (obj->o_flags & ISKNOW)
150 sprintf(prbuf, "%s%s %s",
151 obj->o_flags & CANRETURN ? "claimed " : "",
152 num(armors[obj->o_which].a_class - obj->o_ac, 0, buf),
153 armors[obj->o_which].a_name);
154 else
155 sprintf(prbuf, "%s%s",
156 obj->o_flags & CANRETURN ? "claimed " : "",
157 armors[obj->o_which].a_name);
158
159 break;
160
161 case ARTIFACT:
162 sprintf(prbuf, "the %s", arts[obj->o_which].ar_name);
163
164 if (obj->o_flags & CANRETURN)
165 strcat(prbuf, " (claimed)");
166
167 break;
168
169 case STICK:
170 sprintf(prbuf, "A %s%s%s ",
171 obj->o_flags & CANRETURN ? "claimed " : "",
172 blesscurse(obj->o_flags), ws_type[obj->o_which]);
173
174 pb = &prbuf[strlen(prbuf)];
175
176 if (know_items[TYP_STICK][obj->o_which])
177 sprintf(pb, "of %s%s(%s)", ws_magic[obj->o_which].mi_name,
178 charge_str(obj,buf), ws_made[obj->o_which]);
179 else if (guess_items[TYP_STICK][obj->o_which])
180 sprintf(pb, "called %s(%s)", guess_items[TYP_STICK][obj->o_which],
181 ws_made[obj->o_which]);
182 else
183 sprintf(&prbuf[2], "%s%s %s",
184 obj->o_flags & CANRETURN ? "claimed " : "",
185 ws_made[obj->o_which],
186 ws_type[obj->o_which]);
187
188 break;
189
190 case RING:
191 if (know_items[TYP_RING][obj->o_which])
192 sprintf(prbuf, "A%s%s ring of %s(%s)",
193 obj->o_flags & CANRETURN ? " claimed" : "", ring_num(obj,buf),
194 r_magic[obj->o_which].mi_name, r_stones[obj->o_which]);
195 else if (guess_items[TYP_RING][obj->o_which])
196 sprintf(prbuf, "A %sring called %s(%s)",
197 obj->o_flags & CANRETURN ? "claimed " : "",
198 guess_items[TYP_RING][obj->o_which], r_stones[obj->o_which]);
199 else
200 sprintf(prbuf, "A%s %s ring",
201 obj->o_flags & CANRETURN ? "claimed " :
202 (char *)vowelstr(r_stones[obj->o_which]),
203 r_stones[obj->o_which]);
204 break;
205
206 case GOLD:
207 sprintf(prbuf, "%d gold pieces", obj->o_count);
208 break;
209
210 default:
211 debug("Picked up something funny.");
212 sprintf(prbuf, "Something bizarre %s", unctrl(obj->o_type));
213 break;
214 }
215
216 /* Is it marked? */
217
218 if (obj->o_mark[0])
219 {
220 pb = &prbuf[strlen(prbuf)];
221 sprintf(pb, " <%s>", obj->o_mark);
222 }
223
224 if (obj == cur_armor)
225 strcat(prbuf, " (being worn)");
226
227 if (obj == cur_weapon)
228 strcat(prbuf, " (weapon in hand)");
229
230 if (obj == cur_ring[LEFT_1])
231 strcat(prbuf, " (on left hand)");
232 else if (obj == cur_ring[LEFT_2])
233 strcat(prbuf, " (on left hand)");
234 else if (obj == cur_ring[LEFT_3])
235 strcat(prbuf, " (on left hand)");
236 else if (obj == cur_ring[LEFT_4])
237 strcat(prbuf, " (on left hand)");
238 else if (obj == cur_ring[LEFT_5])
239 strcat(prbuf, " (on left hand)");
240 else if (obj == cur_ring[RIGHT_1])
241 strcat(prbuf, " (on right hand)");
242 else if (obj == cur_ring[RIGHT_2])
243 strcat(prbuf, " (on right hand)");
244 else if (obj == cur_ring[RIGHT_3])
245 strcat(prbuf, " (on right hand)");
246 else if (obj == cur_ring[RIGHT_4])
247 strcat(prbuf, " (on right hand)");
248 else if (obj == cur_ring[RIGHT_5])
249 strcat(prbuf, " (on right hand)");
250
251 if (obj->o_flags & ISPROT)
252 strcat(prbuf, " [protected]");
253
254 if (lowercase && isupper(prbuf[0]))
255 prbuf[0] = (char) tolower(prbuf[0]);
256 else if (!lowercase && islower(*prbuf))
257 *prbuf = (char) toupper(*prbuf);
258
259 if (!lowercase)
260 strcat(prbuf, ".");
261
262 return(prbuf);
263 }
264
265 /*
266 rem_obj()
267 Remove an object from the level.
268 */
269
270 void
271 rem_obj(struct linked_list *item, int dis)
272 {
273 struct linked_list *llptr;
274 struct object *objptr, *op;
275 int x, y;
276
277 if (item == NULL)
278 return;
279
280 detach(lvl_obj, item);
281 objptr = OBJPTR(item);
282
283 if ( (llptr = objptr->next_obj) != NULL )
284 {
285 detach((objptr->next_obj), llptr);
286 attach(lvl_obj, llptr);
287
288 op = OBJPTR(llptr);
289
290 op->next_obj = objptr->next_obj;
291
292 if (op->next_obj)
293 objptr->next_obj->l_prev = NULL;
294
295 y = op->o_pos.y;
296 x = op->o_pos.x;
297
298 if (cansee(y, x))
299 mvwaddch(cw, y, x, op->o_type);
300
301 mvaddch(y, x, op->o_type);
302 }
303 else
304 {
305 y = objptr->o_pos.y;
306 x = objptr->o_pos.x;
307
308 /* problems if dropped in rock */
309
310 mvaddch(y,x,(roomin((objptr->o_pos)) == NULL ? PASSAGE : FLOOR));
311 }
312
313 if (dis)
314 discard(item);
315 }
316
317 /*
318 add_obj()
319 adds an object to the level
320 */
321
322 void
323 add_obj(struct linked_list *item, int y, int x)
324 {
325 struct linked_list *llptr;
326 struct object*objptr;
327
328 llptr = find_obj(y, x);
329
330 if (llptr)
331 {
332 objptr = OBJPTR(llptr);
333 attach((objptr->next_obj), item);
334 }
335 else
336 {
337 attach(lvl_obj, item);
338 objptr = OBJPTR(item);
339 objptr->next_obj = NULL;
340 objptr->o_pos.y = y;
341 objptr->o_pos.x = x;
342 mvaddch(y, x, objptr->o_type);
343 }
344 }
345
346 /*
347 drop()
348 put something down
349 */
350
351 int
352 drop(struct linked_list *item)
353 {
354 char ch = CCHAR( mvwinch(stdscr, hero.y, hero.x) );
355 struct object *obj;
356
357 switch (ch)
358 {
359 case GOLD:
360