comparison srogue/trader.c @ 36:2128c7dc8a40

Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author elwin
date Thu, 25 Nov 2010 12:21:41 +0000
parents
children 94a0d9dd5ce1
comparison
equal deleted inserted replaced
35:05018c63a721 36:2128c7dc8a40
1 /*
2 * Anything to do with trading posts & mazes
3 *
4 * @(#)trader.c 9.0 (rdk) 7/17/84
5 *
6 * Super-Rogue
7 * Copyright (C) 1984 Robert D. Kindelberger
8 * All rights reserved.
9 *
10 * See the file LICENSE.TXT for full copyright and licensing information.
11 */
12
13 #include <stdlib.h>
14 #include "rogue.h"
15 #include "rogue.ext"
16
17 #define NOTPRICED -1
18
19 /*
20 * do_post:
21 * Put a trading post room and stuff on the screen
22 */
23 do_post()
24 {
25 struct coord tp;
26 reg int i;
27 reg struct room *rp;
28 reg struct object *op;
29 reg struct linked_list *ll;
30
31 free_list(lvl_obj); /* throw old items away */
32
33 for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
34 rp->r_goldval = 0; /* no gold */
35 rp->r_nexits = 0; /* no exits */
36 rp->r_flags = ISGONE; /* kill all rooms */
37 }
38 rp = &rooms[0]; /* point to only room */
39 rp->r_flags = 0; /* this room NOT gone */
40 rp->r_max.x = 40;
41 rp->r_max.y = 10; /* 10 * 40 room */
42 rp->r_pos.x = (COLS - rp->r_max.x) / 2; /* center horizontal */
43 rp->r_pos.y = 1; /* 2nd line */
44 draw_room(rp); /* draw the only room */
45 i = roll(4,10); /* 10 to 40 items */
46 for (; i > 0 ; i--) { /* place all the items */
47 ll = new_thing(FALSE, ANYTHING); /* get something */
48 attach(lvl_obj, ll);
49 op = OBJPTR(ll);
50 setoflg(op, ISPOST); /* object in trading post */
51 tp = *rnd_pos(rp);
52 op->o_pos = tp;
53 mvaddch(tp.y,tp.x,op->o_type);
54 }
55 trader = 0;
56 wmove(cw,12,0);
57 waddstr(cw,"Welcome to Friendly Fiend's Flea Market\n\r");
58 waddstr(cw,"=======================================\n\r");
59 waddstr(cw,"$: Prices object that you stand upon.\n\r");
60 waddstr(cw,"#: Buys the object that you stand upon.\n\r");
61 waddstr(cw,"%: Trades in something in your pack for gold.\n\r");
62 trans_line();
63 }
64
65 /*
66 * price_it:
67 * Price the object that the hero stands on
68 */
69 price_it()
70 {
71 static char *bargain[] = {
72 "great bargain",
73 "quality product",
74 "exceptional find",
75 };
76 reg struct linked_list *item;
77 reg struct object *obj;
78 reg int worth;
79
80 if (!open_market()) /* after buying hours */
81 return FALSE;
82 if ((item = find_obj(hero.y,hero.x)) == NULL)
83 return FALSE;
84 obj = OBJPTR(item);
85 if (curprice == NOTPRICED) {
86 worth = get_worth(obj);
87 worth += 50 - rnd(100);
88 if (worth < 25)
89 worth = 25;
90 worth *= 3; /* slightly expensive */
91 curprice = worth; /* save price */
92 strcpy(curpurch, obj->o_typname); /* save item */
93 }
94 msg("That %s is a %s for only %d pieces of gold", curpurch,
95 bargain[rnd(3)], curprice);
96 return TRUE;
97 }
98
99 /*
100 * buy_it:
101 * Buy the item on which the hero stands
102 */
103 buy_it()
104 {
105 reg int wh;
106
107 if (purse <= 0) {
108 msg("You have no money.");
109 return;
110 }
111 if (curprice < 0) { /* if not yet priced */
112 wh = price_it();
113 if (!wh) /* nothing to price */
114 return;
115 msg("Do you want to buy it? ");
116 do {
117 wh = readchar();
118 if (isupper(wh))
119 wh = tolower(wh);
120 if (wh == ESCAPE || wh == 'n') {
121 msg("");
122 return;
123 }
124 } until(wh == 'y');
125 }
126 mpos = 0;
127 if (curprice > purse) {
128 msg("You can't afford to buy that %s !",curpurch);
129 return;
130 }
131 /*
132 * See if the hero has done all his transacting
133 */
134 if (!open_market())
135 return;
136 /*
137 * The hero bought the item here
138 */
139 mpos = 0;
140 wh = add_pack(NULL,FALSE); /* try to put it in his pack */
141 if (wh) { /* he could get it */
142 purse -= curprice; /* take his money */
143 ++trader; /* another transaction */
144 trans_line(); /* show remaining deals */
145 curprice = NOTPRICED;
146 curpurch[0] = '\0';
147 }
148 }
149
150 /*
151 * sell_it:
152 * Sell an item to the trading post
153 */
154 sell_it()
155 {
156 reg struct linked_list *item;
157 reg struct object *obj;
158 reg int wo, ch;
159
160 if (!open_market()) /* after selling hours */
161 return;
162
163 if ((item = get_item("sell",0)) == NULL)
164 return;
165 obj = OBJPTR(item);
166 wo = get_worth(obj);
167 if (wo <= 0) {
168 mpos = 0;
169 msg("We don't buy those.");
170 return;
171 }
172 if (wo < 25)
173 wo = 25;
174 msg("Your %s is worth %d pieces of gold.", obj->o_typname, wo);
175 msg("Do you want to sell it? ");
176 do {
177 ch = readchar();
178 if (isupper(ch))