Mercurial > hg > early-roguelike
comparison arogue5/trader.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 * Anything to do with trading posts | |
| 3 * | |
| 4 * Advanced Rogue | |
| 5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | |
| 6 * All rights reserved. | |
| 7 * | |
| 8 * Based on "Super-Rogue" | |
| 9 * Copyright (C) 1984 Robert D. Kindelberger | |
| 10 * All rights reserved. | |
| 11 * | |
| 12 * See the file LICENSE.TXT for full copyright and licensing information. | |
| 13 */ | |
| 14 | |
| 15 #include "curses.h" | |
| 16 #include "rogue.h" | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 /* | |
| 23 * buy_it: | |
| 24 * Buy the item on which the hero stands | |
| 25 */ | |
| 26 buy_it() | |
| 27 { | |
| 28 reg int wh; | |
| 29 struct linked_list *item; | |
| 30 | |
| 31 if (purse <= 0) { | |
| 32 msg("You have no money."); | |
| 33 return; | |
| 34 } | |
| 35 if (curprice < 0) { /* if not yet priced */ | |
| 36 wh = price_it(); | |
| 37 if (!wh) /* nothing to price */ | |
| 38 return; | |
| 39 msg("Do you want to buy it? "); | |
| 40 do { | |
| 41 wh = tolower(readchar()); | |
| 42 if (wh == ESCAPE || wh == 'n') { | |
| 43 msg(""); | |
| 44 return; | |
| 45 } | |
| 46 } until(wh == 'y'); | |
| 47 } | |
| 48 mpos = 0; | |
| 49 if (curprice > purse) { | |
| 50 msg("You can't afford to buy that %s !",curpurch); | |
| 51 return; | |
| 52 } | |
| 53 /* | |
| 54 * See if the hero has done all his transacting | |
| 55 */ | |
| 56 if (!open_market()) | |
| 57 return; | |
| 58 /* | |
| 59 * The hero bought the item here | |
| 60 */ | |
| 61 item = find_obj(hero.y, hero.x); | |
| 62 mpos = 0; | |
| 63 if (add_pack(NULL,TRUE,&item)) { /* try to put it in his pack */ | |
| 64 purse -= curprice; /* take his money */ | |
| 65 ++trader; /* another transaction */ | |
| 66 trans_line(); /* show remaining deals */ | |
| 67 curprice = -1; /* reset stuff */ | |
| 68 curpurch[0] = 0; | |
| 69 whatis (item); /* identify it after purchase */ | |
| 70 (OBJPTR(item))->o_flags &= ~ISPOST; /* turn off ISPOST */ | |
| 71 msg("%s", inv_name(OBJPTR(item), TRUE)); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 /* | |
| 76 * do_post: | |
| 77 * Put a trading post room and stuff on the screen | |
| 78 */ | |
| 79 do_post() | |
| 80 { | |
| 81 coord tp; | |
| 82 reg int i; | |
| 83 reg struct room *rp; | |
| 84 reg struct object *op; | |
| 85 reg struct linked_list *ll; | |
| 86 | |
| 87 o_free_list(lvl_obj); /* throw old items away */ | |
| 88 | |
| 89 for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) | |
| 90 rp->r_flags = ISGONE; /* kill all rooms */ | |
| 91 | |
| 92 rp = &rooms[0]; /* point to only room */ | |
| 93 rp->r_flags = 0; /* this room NOT gone */ | |
| 94 rp->r_max.x = 40; | |
| 95 rp->r_max.y = 10; /* 10 * 40 room */ | |
| 96 rp->r_pos.x = (COLS - rp->r_max.x) / 2; /* center horizontal */ | |
| 97 rp->r_pos.y = 1; /* 2nd line */ | |
| 98 draw_room(rp); /* draw the only room */ | |
| 99 i = roll(4,10); /* 10 to 40 items */ | |
| 100 for (; i > 0 ; i--) { /* place all the items */ | |
| 101 ll = new_thing(ALL); /* get something */ | |
| 102 attach(lvl_obj, ll); | |
| 103 op = OBJPTR(ll); | |
| 104 op->o_flags |= ISPOST; /* object in trading post */ | |
| 105 do { | |
| 106 rnd_pos(rp,&tp); | |
| 107 } until (mvinch(tp.y, tp.x) == FLOOR); | |
| 108 op->o_pos = tp; | |
| 109 mvaddch(tp.y,tp.x,op->o_type); | |
| 110 } | |
| 111 trader = 0; | |
| 112 wmove(cw,12,0); | |
| 113 waddstr(cw,"Welcome to Friendly Fiend's Flea Market\n\r"); | |
| 114 waddstr(cw,"=======================================\n\r"); | |
| 115 waddstr(cw,"$: Prices object that you stand upon.\n\r"); | |
| 116 waddstr(cw,"#: Buys the object that you stand upon.\n\r"); | |
| 117 waddstr(cw,"%: Trades in something in your pack for gold.\n\r"); | |
| 118 trans_line(); | |
| 119 } | |
| 120 | |
| 121 | |
| 122 /* | |
| 123 * get_worth: | |
| 124 * Calculate an objects worth in gold | |
| 125 */ | |
| 126 get_worth(obj) | |
| 127 reg struct object *obj; | |
| 128 { | |
| 129 reg int worth, wh; | |
| 130 | |
| 131 worth = 0; | |
| 132 wh = obj->o_which; | |
| 133 switch (obj->o_type) { | |
| 134 case FOOD: | |
| 135 worth = 2; | |
| 136 when WEAPON: | |
| 137 if (wh < MAXWEAPONS) { | |
| 138 worth = weaps[wh].w_worth; | |
| 139 worth += s_magic[S_ALLENCH].mi_worth * | |
| 140 (obj->o_hplus + obj->o_dplus); | |
| 141 } | |
| 142 when ARMOR: | |
| 143 if (wh < MAXARMORS) { | |
| 144 worth = armors[wh].a_worth; | |
| 145 worth += s_magic[S_ALLENCH].mi_worth * | |
| 146 (armors[wh].a_class - obj->o_ac); | |
| 147 } | |
| 148 when SCROLL: | |
| 149 if (wh < MAXSCROLLS) | |
| 150 worth = s_magic[wh].mi_worth; | |
| 151 when POTION: | |
| 152 if (wh < MAXPOTIONS) | |
| 153 worth = p_magic[wh].mi_worth; | |
| 154 when RING: | |
| 155 if (wh < MAXRINGS) { | |
| 156 worth = r_magic[wh].mi_worth; | |
| 157 worth += obj->o_ac * 40; | |
| 158 } | |
| 159 when STICK: | |
| 160 if (wh < MAXSTICKS) { | |
| 161 worth = ws_magic[wh].mi_worth; | |
| 162 worth += 20 * obj->o_charges; | |
| 163 } | |
| 164 when MM: | |
| 165 if (wh < MAXMM) { | |
| 166 worth = m_magic[wh].mi_worth; | |
| 167 switch (wh) { | |
| 168 case MM_BRACERS: worth += 40 * obj->o_ac; | |
| 169 when MM_PROTECT: worth += 60 * obj->o_ac; | |
| 170 when MM_DISP: /* ac already figured in price*/ | |
| 171 otherwise: worth += 20 * obj->o_ac; | |
| 172 } | |
| 173 } | |
| 174 when RELIC: | |
| 175 if (wh < MAXRELIC) { | |
| 176 worth = rel_magic[wh].mi_worth; | |
| 177 if (wh == quest_item) worth *= 10; | |
| 178 } | |
| 179 otherwise: | |
| 180 worth = 0; | |
| 181 } | |
| 182 if (obj->o_flags & ISPROT) /* 300% more for protected */ | |
| 183 worth *= 3; | |
| 184 if (obj->o_flags & ISBLESSED) /* 50% more for blessed */ | |
| 185 worth = worth * 3 / 2; | |
| 186 if (obj->o_flags & ISCURSED) /* half for cursed */ | |
| 187 worth /= 2; | |
| 188 if (worth < 0) | |
| 189 worth = 0; | |
| 190 return worth; | |
| 191 } | |
| 192 | |
| 193 /* | |
| 194 * open_market: | |
| 195 * Retruns TRUE when ok do to transacting | |
| 196 */ | |
| 197 open_market() | |
| 198 { | |
| 199 if (trader >= MAXPURCH && !wizard) { | |
| 200 msg("The market is closed. The stairs are that-a-way."); | |
| 201 return FALSE; | |
| 202 } | |
| 203 else { | |
| 204 return TRUE; | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 /* | |
| 209 * price_it: | |
| 210 * Price the object that the hero stands on | |
| 211 */ | |
| 212 price_it() | |
| 213 { | |
| 214 reg struct linked_list *item; | |
| 215 reg struct object *obj; | |
| 216 reg int worth; | |
| 217 reg char *str; | |
| 218 | |
| 219 if (!open_market()) /* after buying hours */ | |
| 220 return FALSE; | |
| 221 if ((item = find_obj(hero.y,hero.x)) == NULL) | |
| 222 return FALSE; | |
| 223 obj = OBJPTR(item); | |
| 224 worth = get_worth(obj); | |
| 225 if (worth < 0) { | |
| 226 msg("That's not for sale."); | |
| 227 return FALSE; | |
| 228 } | |
| 229 if (worth < 25) | |
| 230 worth = 25; | |
| 231 worth *= 3; /* slightly expensive */ | |
| 232 str = inv_name(obj, TRUE); | |
| 233 sprintf(outstring,"%s for only %d pieces of gold", str, worth); | |
| 234 msg(outstring); | |
| 235 curprice = worth; /* save price */ | |
| 236 strcpy(curpurch,str); /* save item */ | |
| 237 return TRUE; | |
| 238 } | |
| 239 | |
| 240 | |
| 241 | |
| 242 /* | |
| 243 * sell_it: | |
| 244 * Sell an item to the trading post | |
| 245 */ | |
| 246 sell_it() | |
| 247 { | |
| 248 reg struct linked_list *item; | |
| 249 reg struct object *obj; | |
| 250 reg int wo, ch; | |
| 251 | |
| 252 if (!open_market()) /* after selling hours */ | |
| 253 return; | |
| 254 | |
| 255 if ((item = get_item(pack, "sell", ALL)) == NULL) | |
| 256 return; | |
| 257 obj = OBJPTR(item); | |
| 258 wo = get_worth(obj); | |
| 259 if (wo <= 0) { | |
| 260 mpos = 0; | |
| 261 msg("We don't buy those."); | |
| 262 return; | |
| 263 } | |
| 264 if (wo < 25) | |
| 265 wo = 25; | |
| 266 sprintf(outstring,"Your %s is worth %d pieces of gold.",typ_name(obj),wo); | |
| 267 msg(outstring); | |
| 268 msg("Do you want to sell it? "); | |
| 269 do { | |
| 270 ch = tolower(readchar()); | |
| 271 if (ch == ESCAPE || ch == 'n') { | |
| 272 msg(""); | |
| 273 return; | |
| 274 } | |
| 275 } until (ch == 'y'); | |
| 276 mpos = 0; | |
| 277 if (drop(item) == TRUE) { /* drop this item */ | |
| 278 purse += wo; /* give him his money */ | |
| 279 ++trader; /* another transaction */ | |
| 280 wo = obj->o_count; | |
| 281 if (obj->o_group == 0) /* dropped one at a time */ | |
| 282 obj->o_count = 1; | |
| 283 msg("Sold %s",inv_name(obj,TRUE)); | |
| 284 obj->o_count = wo; | |
| 285 trans_line(); /* show remaining deals */ | |
| 286 } | |
| 287 } | |
| 288 | |
| 289 /* | |
| 290 * trans_line: | |
| 291 * Show how many transactions the hero has left | |
| 292 */ | |
| 293 trans_line() | |
| 294 { | |
| 295 if (!wizard) | |
| 296 sprintf(prbuf,"You have %d transactions remaining.", | |
| 297 MAXPURCH - trader); | |
| 298 else | |
| 299 sprintf(prbuf, | |
| 300 "You have infinite transactions remaining oh great wizard"); | |
| 301 mvwaddstr(cw,LINES - 3,0,prbuf); | |
| 302 } | |
| 303 | |
| 304 | |
| 305 | |
| 306 /* | |
| 307 * typ_name: | |
| 308 * Return the name for this type of object | |
| 309 */ | |
| 310 char * | |
| 311 typ_name(obj) | |
| 312 reg struct object *obj; | |
| 313 { | |
| 314 static char buff[20]; | |
| 315 reg int wh; | |
| 316 | |
| 317 switch (obj->o_type) { | |
| 318 case POTION: wh = TYP_POTION; | |
| 319 when SCROLL: wh = TYP_SCROLL; | |
| 320 when STICK: wh = TYP_STICK; | |
| 321 when RING: wh = TYP_RING; | |
| 322 when ARMOR: wh = TYP_ARMOR; | |
| 323 when WEAPON: wh = TYP_WEAPON; | |
| 324 when MM: wh = TYP_MM; | |
| 325 when FOOD: wh = TYP_FOOD; | |
| 326 when RELIC: wh = TYP_RELIC; | |
| 327 otherwise: wh = -1; | |
| 328 } | |
| 329 if (wh < 0) | |
| 330 strcpy(buff,"unknown"); | |
| 331 else | |
| 332 strcpy(buff,things[wh].mi_name); | |
| 333 return (buff); | |
| 334 } | |
| 335 | |
| 336 |
