Mercurial > hg > early-roguelike
annotate xrogue/trader.c @ 133:e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
| author | John "Elwin" Edwards | 
|---|---|
| date | Tue, 21 Apr 2015 08:55:20 -0400 | 
| parents | |
| children | ce0cf824c192 | 
| rev | line source | 
|---|---|
| 133 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 1 /* | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 2 trader.c - Anything to do with trading posts | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 3 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 4 XRogue: Expeditions into the Dungeons of Doom | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 5 Copyright (C) 1991 Robert Pietkivitch | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 6 All rights reserved. | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 7 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 8 Based on "Advanced Rogue" | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 10 All rights reserved. | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 11 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 12 See the file LICENSE.TXT for full copyright and licensing information. | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 13 */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 14 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 15 #include <curses.h> | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 16 #include "rogue.h" | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 17 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 18 /* | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 19 * buy_it: | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 20 * Buy the item on which the hero stands | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 21 */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 22 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 23 buy_it() | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 24 { | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 25 reg int wh; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 26 struct linked_list *item = NULL; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 27 struct object *obj = NULL; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 28 int wasfood = FALSE; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 29 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 30 if (purse <= 0) { | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 31 msg("You have no money."); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 32 return; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 33 } | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 34 if (curprice < 0) { /* if not yet priced */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 35 wh = price_it(); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 36 if (!wh) /* nothing to price */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 37 return; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 38 msg("Do you want to buy it? "); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 39 do { | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 40 wh = wgetch(cw); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 41 if (wh == ESC || wh == 'n') { | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 42 msg(""); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 43 return; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 44 } | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 45 } until(wh == 'y'); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 46 } | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 47 mpos = 0; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 48 if (curprice > purse) { | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 49 msg("You can't afford it!"); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 50 return; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 51 } | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 52 /* | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 53 * See if the hero has done all his transacting | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 54 */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 55 if (!open_market()) | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 56 return; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 57 /* | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 58 * The hero bought the item here | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 59 */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 60 item = find_obj(hero.y, hero.x); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 61 obj = OBJPTR(item); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 62 mpos = 0; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 63 wasfood = ISMULT(obj->o_type); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 64 if (add_pack((struct linked_list *)NULL,TRUE)) {/* try to put it in his pack */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 65 purse -= curprice; /* take his money */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 66 ++trader; /* another transaction */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 67 trans_line(); /* show remaining deals */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 68 curprice = -1; /* reset stuff */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 69 curpurch[0] = 0; | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 70 if (!wasfood) /* if it was food then the object has been deleted */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 71 { | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 72 whatis (item); /* identify it */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 73 obj = OBJPTR(item); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 74 obj->o_flags &= ~ISPOST; /* turn off ISPOST */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 75 obj->o_flags |= ISKNOW; /* he knows the item */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 76 msg("%s", inv_name(obj, TRUE)); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 77 } | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 78 else | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 79 msg("a food ration."); | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 80 } | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 81 } | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 82 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 83 /* | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 84 * do_post: | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 85 * Put a trading post room and stuff on the screen | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 86 */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 87 | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 88 do_post(startup) | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 89 bool startup; /* True if equipping the player at the beginning of the game */ | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff
changeset | 90 { | 
| 
e6179860cb76
Import XRogue 8.0 from the Roguelike Restoration Project (r1490)
 John "Elwin" Edwards parents: diff | 
