Mercurial > hg > early-roguelike
comparison urogue/trader.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 | 0250220d8cdd |
comparison
equal
deleted
inserted
replaced
253:d9badb9c0179 | 256:c495a4f288c6 |
---|---|
1 /* | |
2 trader.c - Anything to do with trading posts | |
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 <stdlib.h> | |
21 #include <ctype.h> | |
22 #include "rogue.h" | |
23 | |
24 #define EFFECTIVE_PURSE ((player.t_ctype==C_PALADIN)?(9 * purse / 10) : purse) | |
25 | |
26 /* | |
27 do_post() | |
28 Buy and sell things in a trading post | |
29 */ | |
30 | |
31 void | |
32 display_postinfo(void) | |
33 { | |
34 wclear(hw); | |
35 wstandout(hw); | |
36 mvwaddstr(hw, 0, COLS / 2 - 30, | |
37 "Welcome to Friendly Fiend's Flea Market" ); | |
38 wstandend(hw); | |
39 wclrtoeol(hw); | |
40 trans_line(); | |
41 } | |
42 | |
43 void | |
44 do_post(void) | |
45 { | |
46 int bad_letter = FALSE; | |
47 | |
48 player.t_trans = 0; | |
49 | |
50 for (;;) | |
51 { | |
52 if (!open_market()) | |
53 return; | |
54 | |
55 display_postinfo(); | |
56 | |
57 if (bad_letter) | |
58 { | |
59 bad_letter = FALSE; | |
60 wstandout(hw); | |
61 mvwaddstr(hw, 7, 0, "Type 'i' or 'I' to inventory, " | |
62 "'l' to leave, 'b' to buy, or 's' to sell"); | |
63 wstandend(hw); | |
64 } | |
65 | |
66 mvwaddstr(hw, 6, 0, "Do you wish to buy, sell, inventory, or leave?"); | |
67 wrefresh(hw); | |
68 | |
69 switch(readcharw(hw)) | |
70 { | |
71 case 'b': | |
72 mvwaddstr(hw, 7, 0, | |
73 "Lets go into the buying section of the store..."); | |
74 touchwin(hw); | |
75 wrefresh(hw); | |
76 buy_it('\0', ISNORMAL); | |
77 break; | |
78 | |
79 case 's': | |
80 mvwaddstr(hw, 7, 0, | |
81 "Lets go into the selling section of the store..."); | |
82 touchwin(hw); | |
83 wrefresh(hw); | |
84 sell_it(); | |
85 break; | |
86 | |
87 case 'i': | |
88 inventory(pack, '*'); | |
89 break; | |
90 | |
91 case 'I': | |
92 wclear(hw); | |
93 wrefresh(hw); | |
94 inventory(pack, 0); | |
95 msg(" "); | |
96 msg(""); | |
97 break; | |
98 | |
99 case 'l': | |
100 wclear(hw); | |
101 wrefresh(hw); | |
102 return; | |
103 | |
104 default: | |
105 bad_letter = TRUE; | |
106 break; | |
107 } | |
108 } | |
109 } | |
110 | |
111 void | |
112 buy_it(char itemtype, int flags) | |
113 { | |
114 int i; | |
115 int blessed = flags & ISBLESSED; | |
116 int cursed = flags & ISCURSED; | |
117 int is_spell = flags & SCR_MAGIC; | |
118 int array_size; /* # of items within type */ | |
119 int which_type = 0; /* Which type to buy */ | |
120 int which_one; /* Which one within type */ | |
121 int plus_or_minus = 0; /* for magic items */ | |
122 const struct magic_item *magic_array = NULL; | |
123 struct linked_list *item; | |
124 struct object *obj; | |
125 char buf[2 * LINELEN]; | |
126 | |
127 buy_more: | |
128 | |
129 display_postinfo(); | |
130 | |
131 do | |
132 { | |
133 array_size = 0; | |
134 | |
135 if (itemtype == '\0') | |
136 { | |
137 mpos = 0; | |
138 wmove(hw,10,0); | |
139 wclrtoeol(hw); | |
140 mvwaddstr(hw, 11, 0, "WHAT\tTYPE\n! Potion\n? Scroll\n" | |
141 "= Ring\n/ Stick\n] Armor\n) Weapon\n: Food"); | |
142 | |
143 if (wizard) | |
144 mvwaddstr(hw, 19, 0, ", Artifact"); | |
145 | |
146 mvwaddstr(hw, 9, 0, "What type of item do you want? "); | |
147 wclrtoeol(hw); | |
148 touchwin(hw); | |
149 wrefresh(hw); | |
150 itemtype = readcharw(hw); | |
151 } | |
152 | |
153 switch(itemtype) | |
154 { | |
155 case POTION: | |
156 which_type = TYP_POTION; | |
157 array_size = maxpotions; | |
158 magic_array = p_magic; | |
159 break; | |
160 | |
161 case SCROLL: | |
162 which_type = TYP_SCROLL; | |
163 array_size = maxscrolls; | |
164 magic_array = s_magic; | |
165 break; | |
166 | |
167 case FOOD: | |
168 which_type = TYP_FOOD; | |
169 array_size = maxfoods; | |
170 magic_array = fd_data; | |
171 break; | |
172 | |
173 case WEAPON: | |
174 which_type = TYP_WEAPON; | |
175 array_size = maxweapons; | |
176 break; | |
177 | |
178 case ARMOR: | |
179 which_type = TYP_ARMOR; | |
180 array_size = maxarmors; | |
181 break; | |
182 | |
183 case RING: | |
184 which_type = TYP_RING; | |
185 array_size = maxrings; | |
186 magic_array = r_magic; | |
187 break; | |
188 | |
189 case STICK: | |
190 which_type = TYP_STICK; | |
191 array_size = maxsticks; | |
192 magic_array = ws_magic; | |
193 break; | |
194 | |
195 case ARTIFACT: | |
196 if (!wizard) | |
197 { | |
198 itemtype = '\0'; | |
199 continue; | |
200 } | |
201 | |
202 which_type = TYP_ARTIFACT; | |
203 array_size = maxartifact; | |
204 break; | |
205 | |
206 case ESCAPE: | |
207 return; | |
208 | |
209 default: | |
210 wstandout(hw); | |
211 mvwaddstr(hw, 10, 0, "We don't stock any of those."); | |
212 wstandend(hw); | |
213 itemtype = '\0'; | |
214 continue; | |
215 } | |
216 } | |
217 while (array_size == 0); | |
218 | |
219 which_one = array_size; | |
220 | |
221 do | |
222 { | |
223 const struct magic_item *m_item; | |
224 | |
225 display_postinfo(); | |
226 | |
227 mpos = 0; | |
228 sprintf(buf, "Which kind of %s do you wish to have (* for list)? ", | |
229 things[which_type].mi_name); | |
230 | |
231 mvwaddstr(hw, 9, 0, buf); | |
232 | |
233 touchwin(hw); | |
234 wrefresh(hw); | |
235 buf[0] = '\0'; | |
236 | |
237 switch (get_string(buf, hw)) | |
238 { | |
239 case QUIT: | |
240 case ESCAPE: | |
241 itemtype = '\0'; | |
242 goto buy_more; | |
243 } | |
244 | |
245 if (buf[0] == '*') /* print list */ | |
246 { | |
247 add_line(" ID BASECOST NAME"); | |
248 | |
249 switch (which_type) | |
250 { | |
251 case TYP_RING: | |
252 case TYP_POTION: | |
253 case TYP_STICK: | |
254 case TYP_SCROLL: | |
255 case TYP_FOOD: | |
256 | |
257 for(i=0,m_item=magic_array; i < array_size; i++, m_item++) | |
258 if (!is_spell && m_item->mi_worth > 0) | |
259 { | |
260 sprintf(buf, "%3d) %8d %s", i, m_item->mi_worth, | |
261 m_item->mi_name); | |
262 add_line(buf); | |
263 } | |
264 break; | |
265 | |
266 case TYP_ARMOR: | |
267 for (i = 0; i < array_size; i++) | |
268 if (!is_spell && armors[i].a_worth > 0) | |
269 { | |
270 sprintf(buf, "%3d) %8d %s", i, armors[i].a_worth, | |
271 armors[i].a_name); | |
272 | |
273 add_line(buf); | |
274 } | |
275 break; | |
276 | |
277 case TYP_WEAPON: | |
278 for (i = 0; i < array_size; i++) | |
279 if (!is_spell && weaps[i].w_worth > 0) | |
280 { | |
281 sprintf(buf, "%3d) %8d %s", i, weaps[i].w_worth, | |
282 weaps[i].w_name); | |
283 add_line(buf); | |
284 } | |
285 break; | |
286 | |
287 case TYP_ARTIFACT: | |
288 for (i = 0; i < array_size; i++) | |
289 { | |
290 sprintf(buf, "%3d) %8d %s", i, arts[i].ar_worth, | |
291 arts[i].ar_name); | |
292 add_line(buf); | |
293 } | |
294 break; | |
295 | |
296 default: | |
297 add_line("What a strange type."); | |
298 } | |
299 | |
300 end_line(); | |
301 touchwin(hw); | |
302 wrefresh(hw); | |
303 continue; | |
304 } | |
305 | |
306 if (isdigit(buf[0])) | |
307 which_one = atoi(buf); | |
308 else | |
309 switch (which_type) | |
310 { | |
311 case TYP_RING: | |
312 case TYP_POTION: | |
313 case TYP_STICK: | |
314 case TYP_SCROLL: | |
315 case TYP_FOOD: | |
316 for (i=0,m_item=magic_array; i < array_size; i++, m_item++) | |
317 if (strcmp(buf, m_item->mi_name) == 0) | |
318 which_one = i; | |
319 break; | |
320 | |
321 case TYP_ARMOR: | |
322 for (i = 0; i < array_size; i++) | |
323 if (strcmp(buf, armors[i].a_name) == 0) | |
324 which_one = i; | |
325 break; | |
326 | |
327 case TYP_WEAPON: | |
328 for (i = 0; i < array_size; i++) | |
329 if (strcmp(buf, weaps[i].w_name) == 0) | |
330 which_one = i; | |
331 break; | |
332 | |
333 case TYP_ARTIFACT: | |
334 for (i = 0; i < array_size; i++) | |
335 if (strcmp(buf, arts[i].ar_name) == 0) | |
336 which_one = i; | |
337 break; | |
338 | |
339 default: | |
340 msg("What a strange type."); | |
341 } | |
342 | |
343 if (which_one < 0 || which_one >= array_size) | |
344 { | |
345 wstandout(hw); | |
346 mvwaddstr(hw, 10, 0, "Type the name or an ID number."); | |
347 wstandend(hw); | |
348 } | |
349 } | |
350 while (which_one < 0 || which_one >= array_size); | |
351 | |
352 item = new_item(sizeof *obj); | |
353 obj = OBJPTR(item); | |
354 | |
355 if (which_type == TYP_ARTIFACT) | |
356 { | |
357 new_artifact(which_one, obj); | |
358 add_pack(item, NOMESSAGE); | |
359 itemtype = '\0'; | |
360 goto buy_more; | |
361 } | |
362 | |
363 obj->o_type = itemtype; | |
364 obj->o_which = which_one; | |
365 obj->o_mark[0] = '\0'; | |
366 obj->o_group = 0; | |
367 obj->o_count = 1; | |
368 obj->o_weight = 0; | |
369 obj->o_dplus = obj->o_hplus = 0; | |
370 obj->o_worth = 0; | |
371 | |
372 if (!is_spell) | |