1 #include "std.h"
2 
3 #undef EXTRA_INIT
4 #define EXTRA_INIT\
5     add_action("sell", "sell");\
6     add_action("value", "value");\
7     add_action("buy", "buy");\
8     add_action("north", "north");\
9     add_action("list", "list");
10 
11 TWO_EXIT("room/vill_road2", "south",
12 	"room/storage", "west",
13 	 "The shop",
14 "You are in a shop. You can buy or sell things here.\n" +
15 "Commands are: 'buy item', 'sell item', 'sell all', 'list', 'list weapons'\n"+
16 "'list armours' and 'value item'.\n" +
17 "There is an opening to the north, and some shimmering\n" +
18 "blue light in the doorway.\nTo the west you see a small room.\n", 1)
19 
20 
find_item_in_player(string i)21 object find_item_in_player(string i)
22 {
23     object ob;
24 
25     ob = first_inventory(this_player());
26     while(ob) {
27         if (ob->id(i))
28 	    return ob;
29 	ob = next_inventory(ob);
30     }
31     return 0;
32 }
33 
do_sell(object ob)34 int do_sell(object ob) {
35     int value, do_destroy;
36     value = ob->query_value();
37     if (!value) {
38 	write(ob->short() + " has no value.\n");
39 	return 1;
40     }
41     if (environment(ob) == this_player()) {
42         int weight;
43 	if (ob->drop()) {
44 	    write("I can't take it from you!\n");
45 	    return 1;
46 	}
47         weight = ob->query_weight();
48 	this_player()->add_weight(- weight);
49     }
50     if (value > 2000)
51 	do_destroy = 1;
52     if (value > 1000) {
53 	write("The shop is low on money...\n");
54 	value = 1000;
55     }
56     write("You get "); write(value); write(" gold coins.\n");
57     say(this_player()->query_name() + " sells " + ob->short() + ".\n");
58     this_player()->add_money(value);
59     add_worth(value, ob);
60     if (do_destroy) {
61 	write("The valuable item is hidden away.\n");
62 	destruct(ob);
63 	return 1;
64     }
65     "room/store"->store(ob);
66     return 1;
67 }
68 
sell(string item)69 int sell(string item) {
70     object ob;
71 
72     if (!item)
73 	return 0;
74     if (item == "all") {
75 	object next;
76 	ob = first_inventory(this_player());
77 	while(ob) {
78 	    next = next_inventory(ob);
79 	    if (!ob->drop() && ob->query_value()) {
80 		write(ob->short() + ":\t");
81 		do_sell(ob);
82 	    }
83 	    ob = next;
84 	}
85 	write("Ok.\n");
86 	return 1;
87     }
88     ob = present(item, this_player());
89     if (!ob)
90 	ob = present(item, this_object());
91     if (!ob) {
92 	write("No such item ("); write(item); write(") here.\n");
93 	return 1;
94     }
95     do_sell(ob);
96     return 1;
97 }
98 
value(string item)99 int value(string item) {
100     int value;
101     object name_of_item;
102 
103     if (!item)
104 	return 0;
105     name_of_item = present(item);
106     if (!name_of_item)
107       name_of_item = find_item_in_player(item);
108     if (!name_of_item) {
109 	if ("room/store"->value(item))
110 	    return 1;
111 	write("No such item ("); write(item); write(") here\n");
112 	write("or in the store.\n");
113 	return 1;
114     }
115     value = name_of_item->query_value();
116     if (!value) {
117 	write(item); write(" has no value.\n");
118 	return 1;
119     }
120     write("You would get "); write(value); write(" gold coins.\n");
121     return 1;
122 }
123 
buy(string item)124 int buy(string item) {
125     if (!item)
126 	return 0;
127     "room/store"->buy(item);
128     return 1;
129 }
130 
north()131 int north() {
132     if (this_player()->query_level() < 20) {
133 	write("A strong magic force stops you.\n");
134 	say(this_player()->query_name() +
135 	    " tries to go through the field, but fails.\n");
136 	return 1;
137     }
138     write("You wriggle through the force field...\n");
139     this_player()->move_player("north#room/store");
140     return 1;
141 }
142 
list(string obj)143 int list(string obj) {
144     "room/store"->inventory(obj);
145     return 1;
146 }
147 
query_drop_castle()148 int query_drop_castle() {
149     return 1;
150 }
151