ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/shop.C
(Generate patch)

Comparing deliantra/server/server/shop.C (file contents):
Revision 1.5 by root, Tue Aug 29 07:34:00 2006 UTC vs.
Revision 1.7 by elmex, Tue Aug 29 10:51:43 2006 UTC

1/* 1/*
2 * static char *rcsid_shop_c = 2 * static char *rcsid_shop_c =
3 * "$Id: shop.C,v 1.5 2006/08/29 07:34:00 root Exp $"; 3 * "$Id: shop.C,v 1.7 2006/08/29 10:51:43 elmex Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
102 shop = flag & F_SHOP; 102 shop = flag & F_SHOP;
103 flag &= ~(F_NO_BARGAIN|F_IDENTIFIED|F_NOT_CURSED|F_APPROX|F_SHOP); 103 flag &= ~(F_NO_BARGAIN|F_IDENTIFIED|F_NOT_CURSED|F_APPROX|F_SHOP);
104 104
105 if (tmp->type==MONEY) return (tmp->nrof * tmp->value); 105 if (tmp->type==MONEY) return (tmp->nrof * tmp->value);
106 if (tmp->type==GEM) { 106 if (tmp->type==GEM) {
107 if (flag==F_TRUE) return (tmp->nrof * tmp->value); 107 if (flag==F_TRUE) return (tmp->nrof * tmp->value);
108 if (flag==F_BUY) return (uint64) (1.03 * tmp->nrof * tmp->value); 108 if (flag==F_BUY) return (uint64) (1.03 * tmp->nrof * tmp->value);
109 if (flag==F_SELL) return (uint64) (0.97 * tmp->nrof * tmp->value); 109 if (flag==F_SELL) return (uint64) (0.97 * tmp->nrof * tmp->value);
110 LOG(llevError,"Query_cost: Gem type with unknown flag : %d\n", flag); 110 LOG(llevError,"Query_cost: Gem type with unknown flag : %d\n", flag);
111 return 0; 111 return 0;
112 } 112 }
113 number = tmp->nrof; 113 number = tmp->nrof;
114 if (number==0) number=1; 114 if (number==0) number=1;
115 if (QUERY_FLAG(tmp, FLAG_IDENTIFIED) || !need_identify(tmp) || identified) { 115 if (QUERY_FLAG(tmp, FLAG_IDENTIFIED) || !need_identify(tmp) || identified) {
116 if (!not_cursed && (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED))) 116 if (!not_cursed && (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)))
117 return 0; 117 return 0;
118 else 118 else
119 val=tmp->value * number; 119 val=tmp->value * number;
120 } 120 }
121 /* This area deals with objects that are not identified, but can be */ 121 /* This area deals with objects that are not identified, but can be */
122 else { 122 else {
123 if (tmp->arch != NULL) { 123 if (tmp->arch != NULL) {
124 if (flag == F_BUY) { 124 if (flag == F_BUY) {
125 LOG(llevError, "Asking for buy-value of unidentified object.\n"); 125 LOG(llevError, "Asking for buy-value of unidentified object.\n");
126 val = tmp->arch->clone.value * 50 * number; 126 val = tmp->arch->clone.value * 50 * number;
127 } 127 }
128 else { /* Trying to sell something, or get true value */ 128 else { /* Trying to sell something, or get true value */
129 if (tmp->type == POTION) 129 if (tmp->type == POTION)
130 val = number * 40; /* Don't want to give anything away */ 130 val = number * 40; /* Don't want to give anything away */
131 else { 131 else {
132 /* Get 2/3'rd value for applied objects, 1/3'rd for totally 132 /* Get 2/3'rd value for applied objects, 1/3'rd for totally
133 * unknown objects 133 * unknown objects
134 */ 134 */
135 if (QUERY_FLAG(tmp, FLAG_BEEN_APPLIED)) 135 if (QUERY_FLAG(tmp, FLAG_BEEN_APPLIED))
136 val = number * tmp->arch->clone.value *2 / 3; 136 val = number * tmp->arch->clone.value *2 / 3;
137 else 137 else
138 val = number * tmp->arch->clone.value / 3; 138 val = number * tmp->arch->clone.value / 3;
139 } 139 }
140 } 140 }
141 } else { /* No archetype with this object */ 141 } else { /* No archetype with this object */
142 LOG(llevDebug,"In sell item: Have object with no archetype: %s\n", tmp->name); 142 LOG(llevDebug,"In sell item: Have object with no archetype: %s\n", tmp->name);
143 if (flag == F_BUY) { 143 if (flag == F_BUY) {
144 LOG(llevError, "Asking for buy-value of unidentified object without arch.\n"); 144 LOG(llevError, "Asking for buy-value of unidentified object without arch.\n");
145 val = number * tmp->value * 10; 145 val = number * tmp->value * 10;
146 } 146 }
147 else 147 else
148 val = number * tmp->value / 5; 148 val = number * tmp->value / 5;
149 } 149 }
150 } 150 }
151 151
152 /* If the item has been applied or identifed or does not need to be 152 /* If the item has been applied or identifed or does not need to be
153 * identified, AND the object is magical and the archetype is non 153 * identified, AND the object is magical and the archetype is non
154 * magical, then change values accordingly. The tmp->arch==NULL is 154 * magical, then change values accordingly. The tmp->arch==NULL is
157 * magic is to not give extra money for archetypes that are by 157 * magic is to not give extra money for archetypes that are by
158 * default magical. This is because the archetype value should have 158 * default magical. This is because the archetype value should have
159 * already figured in that value. 159 * already figured in that value.
160 */ 160 */
161 if((QUERY_FLAG(tmp, FLAG_IDENTIFIED)||!need_identify(tmp)||identified|| 161 if((QUERY_FLAG(tmp, FLAG_IDENTIFIED)||!need_identify(tmp)||identified||
162 QUERY_FLAG(tmp, FLAG_BEEN_APPLIED)) && 162 QUERY_FLAG(tmp, FLAG_BEEN_APPLIED)) &&
163 tmp->magic&&(tmp->arch==NULL||!tmp->arch->clone.magic)) { 163 tmp->magic&&(tmp->arch==NULL||!tmp->arch->clone.magic)) {
164 if(tmp->magic>0) 164 if(tmp->magic>0)
165 val*=(3*tmp->magic*tmp->magic*tmp->magic); 165 val*=(3*tmp->magic*tmp->magic*tmp->magic);
166 else 166 else
167 /* Note that tmp->magic is negative, so that this 167 /* Note that tmp->magic is negative, so that this
168 * will actually be something like val /=2, /=3, etc. 168 * will actually be something like val /=2, /=3, etc.
169 */ 169 */
170 val/=(1-tmp->magic); 170 val/=(1-tmp->magic);
171 } 171 }
172 172
173 if (tmp->type==WAND) { 173 if (tmp->type==WAND) {
174 /* Value of the wand is multiplied by the number of 174 /* Value of the wand is multiplied by the number of
175 * charges. the treasure code already sets up the value 175 * charges. the treasure code already sets up the value
176 * 50 charges is used as the baseline. 176 * 50 charges is used as the baseline.
177 */ 177 */
178 if (QUERY_FLAG(tmp, FLAG_IDENTIFIED) || !need_identify(tmp) || identified) 178 if (QUERY_FLAG(tmp, FLAG_IDENTIFIED) || !need_identify(tmp) || identified)
179 val=(val*tmp->stats.food) / 50; 179 val=(val*tmp->stats.food) / 50;
180 else /* if not identified, presume one charge */ 180 else /* if not identified, presume one charge */
181 val/=50; 181 val/=50;
182 } 182 }
183 183
184 /* Limit amount of money you can get for really great items. */ 184 /* Limit amount of money you can get for really great items. */
185 if (flag==F_SELL) 185 if (flag==F_SELL)
186 val=value_limit((uint64)val, number, who, shop); 186 val=value_limit((uint64)val, number, who, shop);
187 187
188 // use a nonlinear price adjustment. as my predecessor said, don't change 188 // use a nonlinear price adjustment. as my predecessor said, don't change
189 // the archetypes, its work required for balancing, and we don't care. 189 // the archetypes, its work required for balancing, and we don't care.
190 //val = pow (val, 1.05); 190 //val = pow (val, 1.05);
191 191
195 * Thus charisma will never get useless. 195 * Thus charisma will never get useless.
196 * -b.e. edler@heydernet.de 196 * -b.e. edler@heydernet.de
197 */ 197 */
198 198
199 if (who!=NULL && who->type==PLAYER) { 199 if (who!=NULL && who->type==PLAYER) {
200 int lev_bargain = 0; 200 int lev_bargain = 0;
201 int lev_identify = 0; 201 int lev_identify = 0;
202 int idskill1=0; 202 int idskill1=0;
203 int idskill2=0; 203 int idskill2=0;
204 const typedata *tmptype; 204 const typedata *tmptype;
205 205
206 tmptype=get_typedata(tmp->type); 206 tmptype=get_typedata(tmp->type);
207 207
208 if (find_skill_by_number(who,SK_BARGAINING)) { 208 if (find_skill_by_number(who,SK_BARGAINING)) {
209 lev_bargain = find_skill_by_number(who,SK_BARGAINING)->level; 209 lev_bargain = find_skill_by_number(who,SK_BARGAINING)->level;
210 } 210 }
211 if (tmptype) { 211 if (tmptype) {
212 idskill1=tmptype->identifyskill; 212 idskill1=tmptype->identifyskill;
213 if (idskill1) { 213 if (idskill1) {
214 idskill2=tmptype->identifyskill2; 214 idskill2=tmptype->identifyskill2;
215 if (find_skill_by_number(who,idskill1)) { 215 if (find_skill_by_number(who,idskill1)) {
216 lev_identify = find_skill_by_number(who,idskill1)->level; 216 lev_identify = find_skill_by_number(who,idskill1)->level;
217 } 217 }
218 if (idskill2 && find_skill_by_number(who,idskill2)) { 218 if (idskill2 && find_skill_by_number(who,idskill2)) {
219 lev_identify += find_skill_by_number(who,idskill2)->level; 219 lev_identify += find_skill_by_number(who,idskill2)->level;
220 } 220 }
221 } 221 }
222 } 222 }
223 else LOG(llevError, "Query_cost: item %s hasn't got a valid type\n", tmp->name); 223 else LOG(llevError, "Query_cost: item %s hasn't got a valid type\n", tmp->name);
224 224
225 /* ratio determines how much of the price modification 225 /* ratio determines how much of the price modification
226 * will come from the basic stat charisma 226 * will come from the basic stat charisma
227 * the rest will come from the level in bargaining skill 227 * the rest will come from the level in bargaining skill
228 */ 228 */
229 const double cha_ratio = 0.40; 229 const double cha_ratio = 0.40;
230 230
231 diff = no_bargain ? 1.0 : 1. - pow (lev_bargain / (double)settings.max_level, 0.25); 231 diff = no_bargain ? 1.0 : 1. - pow (lev_bargain / (double)settings.max_level, 0.25);
232 232
233 diff = (1. - cha_ratio) * diff 233 diff = (1. - cha_ratio) * diff
234 + cha_ratio * (cha_bonus[who->stats.Cha] - 1.) / (cha_bonus[who->stats.Cha] + 1.); 234 + cha_ratio * (cha_bonus[who->stats.Cha] - 1.) / (cha_bonus[who->stats.Cha] + 1.);
235 235
236 diff = .02 + (.80 - .02) * diff; 236 diff = .02 + (.80 - .02) * diff;
237 237
238 if (flag == F_BUY) val += (val * diff); 238 if (flag == F_BUY) val += (val * diff);
239 else if (flag == F_SELL) val -= (val * diff); 239 else if (flag == F_SELL) val -= (val * diff);
240 240
241 // now find a price range. the less good we can judge, the larger the range is 241 // now find a price range. the less good we can judge, the larger the range is
242 // then the range is adjusted randomly around the correct value 242 // then the range is adjusted randomly around the correct value
243 if (approximate) 243 if (approximate)
244 approx_range = uint64 (val / sqrt (lev_identify * 3 + 1)); 244 approx_range = uint64 (val / sqrt (lev_identify * 3 + 1));
245 } 245 }
246 246
247 /* I don't think this should really happen - if it does, it indicates and 247 /* I don't think this should really happen - if it does, it indicates and
248 * overflow of diff above. That shoudl only happen if 248 * overflow of diff above. That shoudl only happen if
249 * we are selling objects - in that case, the person just 249 * we are selling objects - in that case, the person just
250 * gets no money. 250 * gets no money.
251 */ 251 */
252 if((sint64)val<0) 252 if((sint64)val<0)
253 val=0; 253 val=0;
254 254
255 /* Unidentified stuff won't sell for more than 60gp */ 255 /* Unidentified stuff won't sell for more than 60gp */
256 if(flag==F_SELL && !QUERY_FLAG(tmp, FLAG_IDENTIFIED) && need_identify(tmp) && !identified) { 256 if(flag==F_SELL && !QUERY_FLAG(tmp, FLAG_IDENTIFIED) && need_identify(tmp) && !identified) {
257 val = (val > 600)? 600:val; 257 val = (val > 600)? 600:val;
258 } 258 }
259 259
260 /* if we are in a shop, check how the type of shop should affect the price */ 260 /* if we are in a shop, check how the type of shop should affect the price */
261 if (shop && who) { 261 if (shop && who) {
262 if (flag==F_SELL) 262 if (flag==F_SELL)
263 val= ( 263 val= (
264 val 264 val
265 * shop_specialisation_ratio(tmp, who->map) 265 * shop_specialisation_ratio(tmp, who->map)
266 * shopkeeper_approval(who->map, who) 266 * shopkeeper_approval(who->map, who)
267 / shop_greed(who->map) 267 / shop_greed(who->map)
268 ); 268 );
269 else if (flag==F_BUY) { 269 else if (flag==F_BUY) {
270 /* 270 /*
271 * when buying, if the item was sold by another player, it is ok to 271 * when buying, if the item was sold by another player, it is ok to
272 * let the item be sold cheaper, according to the specialisation of 272 * let the item be sold cheaper, according to the specialisation of
273 * the shop. If a player sold an item here, then his sale price was 273 * the shop. If a player sold an item here, then his sale price was
274 * multiplied by the specialisation ratio, to do the same to the buy 274 * multiplied by the specialisation ratio, to do the same to the buy
275 * price will not generate extra money. However, the 275 * price will not generate extra money. However, the
276 * same is not true of generated items, these have to /divide/ by the 276 * same is not true of generated items, these have to /divide/ by the
277 * specialisation, so that the price is never less than what they could 277 * specialisation, so that the price is never less than what they could
278 * be sold for (otherwise players could camp map resets to make money). 278 * be sold for (otherwise players could camp map resets to make money).
279 * In game terms, a non-specialist shop, might not recognise the true 279 * In game terms, a non-specialist shop, might not recognise the true
280 * value of the items they sell (much like how people sometimes find 280 * value of the items they sell (much like how people sometimes find
281 * antiques in a junk shop in real life). 281 * antiques in a junk shop in real life).
282 */ 282 */
283 if (QUERY_FLAG(tmp, FLAG_PLAYER_SOLD)) 283 if (QUERY_FLAG(tmp, FLAG_PLAYER_SOLD))
284 val= ( 284 val= (
285 val 285 val
286 * shop_greed(who->map) 286 * shop_greed(who->map)
287 * shop_specialisation_ratio(tmp, who->map) 287 * shop_specialisation_ratio(tmp, who->map)
288 / shopkeeper_approval(who->map, who) 288 / shopkeeper_approval(who->map, who)
289 ); 289 );
290 else 290 else
291 val= ( 291 val= (
292 val 292 val
293 * shop_greed(who->map) 293 * shop_greed(who->map)
294 / (shop_specialisation_ratio(tmp, who->map)*shopkeeper_approval(who->map, who)) 294 / (shop_specialisation_ratio(tmp, who->map)*shopkeeper_approval(who->map, who))
295 ); 295 );
296 } 296 }
297 /* we will also have an extra 0-5% variation between shops of the same type 297 /* we will also have an extra 0-5% variation between shops of the same type
298 * for valuable items (below a value of 50 this effect wouldn't be very 298 * for valuable items (below a value of 50 this effect wouldn't be very
299 * pointful, and could give fun with rounding. 299 * pointful, and could give fun with rounding.
300 */ 300 */
301 if(who->map->path!=NULL && val > 50) 301 if(who->map->path!=NULL && val > 50)
302 val= (val+0.05*(sint64)val*cos(tmp->count+strlen(who->map->path))); 302 val= (val+0.05*(sint64)val*cos(tmp->count+strlen(who->map->path)));
303 } 303 }
304 return (uint64)val; 304 return (uint64)val;
305} 305}
306 306
307/* Find the coin type that is worth more the 'c'. Starts at the 307/* Find the coin type that is worth more the 'c'. Starts at the
338 archetype *coin, *next_coin; 338 archetype *coin, *next_coin;
339 int num, cointype = 0; 339 int num, cointype = 0;
340 340
341 coin = find_next_coin(cost, &cointype); 341 coin = find_next_coin(cost, &cointype);
342 if (coin == NULL) 342 if (coin == NULL)
343 return "nothing"; 343 return "nothing";
344 344
345 num = cost / coin->clone.value; 345 num = cost / coin->clone.value;
346 /* so long as nrof is 32 bit, this is true. 346 /* so long as nrof is 32 bit, this is true.
347 * If it takes more coins than a person can possibly carry, this 347 * If it takes more coins than a person can possibly carry, this
348 * is basically true. 348 * is basically true.
349 */ 349 */
350 if ( (cost / coin->clone.value) > UINT32_MAX) { 350 if ( (cost / coin->clone.value) > UINT32_MAX) {
351 strcpy(buf,"an unimaginable sum of money"); 351 strcpy(buf,"an unimaginable sum of money");
352 return buf; 352 return buf;
353 } 353 }
354 354
355 cost -= (uint64)num * (uint64)coin->clone.value; 355 cost -= (uint64)num * (uint64)coin->clone.value;
356 sprintf(buf, "%d %s", num, num > 1 ? coin->clone.name_pl : coin->clone.name); 356 sprintf(buf, "%d %s", num, num > 1 ? coin->clone.name_pl : coin->clone.name);
357 357
358 next_coin = find_next_coin(cost, &cointype); 358 next_coin = find_next_coin(cost, &cointype);
359 if (next_coin == NULL || approx) 359 if (next_coin == NULL || approx)
360 return buf; 360 return buf;
361 361
362 coin = next_coin; 362 coin = next_coin;
363 num = cost / coin->clone.value; 363 num = cost / coin->clone.value;
364 cost -= (uint64)num * (uint64)coin->clone.value; 364 cost -= (uint64)num * (uint64)coin->clone.value;
365 365
374 int idskill2=0; 374 int idskill2=0;
375 const typedata *tmptype; 375 const typedata *tmptype;
376 376
377 tmptype=get_typedata(tmp->type); 377 tmptype=get_typedata(tmp->type);
378 if (tmptype) { 378 if (tmptype) {
379 idskill1=tmptype->identifyskill; 379 idskill1=tmptype->identifyskill;
380 idskill2=tmptype->identifyskill2; 380 idskill2=tmptype->identifyskill2;
381 } 381 }
382 382
383 /* we show an approximate price if 383 /* we show an approximate price if
384 * 1) we are approximating 384 * 1) we are approximating
385 * 2) there either is no id skill(s) for the item, or we don't have them 385 * 2) there either is no id skill(s) for the item, or we don't have them
386 * 3) we don't have bargaining skill either 386 * 3) we don't have bargaining skill either
387 */ 387 */
388 if (flag & F_APPROX) { 388 if (flag & F_APPROX) {
389 if (!idskill1 || !find_skill_by_number(who, idskill1)) { 389 if (!idskill1 || !find_skill_by_number(who, idskill1)) {
390 if (!idskill2 || !find_skill_by_number(who, idskill2)) { 390 if (!idskill2 || !find_skill_by_number(who, idskill2)) {
391 if (!find_skill_by_number(who,SK_BARGAINING)) { 391 if (!find_skill_by_number(who,SK_BARGAINING)) {
392 static char buf[MAX_BUF]; 392 static char buf[MAX_BUF];
393 int num, cointype = 0; 393 int num, cointype = 0;
394 archetype *coin = find_next_coin(real_value, &cointype); 394 archetype *coin = find_next_coin(real_value, &cointype);
395 395
396 if (coin == NULL) return "nothing"; 396 if (coin == NULL) return "nothing";
397 397
398 num = real_value / coin->clone.value; 398 num = real_value / coin->clone.value;
399 if (num == 1) 399 if (num == 1)
400 sprintf(buf, "about one %s", coin->clone.name); 400 sprintf(buf, "about one %s", coin->clone.name);
401 else if (num < 5) 401 else if (num < 5)
402 sprintf(buf, "a few %s", coin->clone.name_pl); 402 sprintf(buf, "a few %s", coin->clone.name_pl);
403 else if (num < 10) 403 else if (num < 10)
404 sprintf(buf, "several %s", coin->clone.name_pl); 404 sprintf(buf, "several %s", coin->clone.name_pl);
405 else if (num < 25) 405 else if (num < 25)
406 sprintf(buf, "a moderate amount of %s", coin->clone.name_pl); 406 sprintf(buf, "a moderate amount of %s", coin->clone.name_pl);
407 else if (num < 100) 407 else if (num < 100)
408 sprintf(buf, "lots of %s", coin->clone.name_pl); 408 sprintf(buf, "lots of %s", coin->clone.name_pl);
409 else if (num < 1000) 409 else if (num < 1000)
410 sprintf(buf, "a great many %s", coin->clone.name_pl); 410 sprintf(buf, "a great many %s", coin->clone.name_pl);
411 else 411 else
412 sprintf(buf, "a vast quantity of %s", coin->clone.name_pl); 412 sprintf(buf, "a vast quantity of %s", coin->clone.name_pl);
413 return buf; 413 return buf;
414 }
415 }
414 } 416 }
415 }
416 }
417 417
418 int hash = ((unsigned int)tmp->count * 174364621) & 1023; 418 int hash = ((unsigned int)tmp->count * 174364621) & 1023;
419 419
420 if (approx_range) 420 if (approx_range)
421 { 421 {
438uint64 query_money(const object *op) { 438uint64 query_money(const object *op) {
439 object *tmp; 439 object *tmp;
440 uint64 total=0; 440 uint64 total=0;
441 441
442 if (op->type!=PLAYER && op->type!=CONTAINER) { 442 if (op->type!=PLAYER && op->type!=CONTAINER) {
443 LOG(llevError, "Query money called with non player/container\n"); 443 LOG(llevError, "Query money called with non player/container\n");
444 return 0; 444 return 0;
445 } 445 }
446 for (tmp = op->inv; tmp; tmp= tmp->below) { 446 for (tmp = op->inv; tmp; tmp= tmp->below) {
447 if (tmp->type==MONEY) { 447 if (tmp->type==MONEY) {
448 total += (uint64)tmp->nrof * (uint64)tmp->value; 448 total += (uint64)tmp->nrof * (uint64)tmp->value;
449 } else if (tmp->type==CONTAINER && 449 } else if (tmp->type==CONTAINER &&
450 QUERY_FLAG(tmp,FLAG_APPLIED) && 450 QUERY_FLAG(tmp,FLAG_APPLIED) &&
451 (tmp->race==NULL || strstr(tmp->race,"gold"))) { 451 (tmp->race==NULL || strstr(tmp->race,"gold"))) {
452 total += query_money(tmp); 452 total += query_money(tmp);
453 } 453 }
454 } 454 }
455 return total; 455 return total;
456} 456}
457/* TCHIZE: This function takes the amount of money from the 457/* TCHIZE: This function takes the amount of money from the
458 * the player inventory and from it's various pouches using the 458 * the player inventory and from it's various pouches using the
466 if (to_pay > query_money(pl)) return 0; 466 if (to_pay > query_money(pl)) return 0;
467 467
468 to_pay = pay_from_container(pl, pl, to_pay); 468 to_pay = pay_from_container(pl, pl, to_pay);
469 469
470 for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) { 470 for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) {
471 if (pouch->type == CONTAINER 471 if (pouch->type == CONTAINER
472 && QUERY_FLAG(pouch, FLAG_APPLIED) 472 && QUERY_FLAG(pouch, FLAG_APPLIED)
473 && (pouch->race == NULL || strstr(pouch->race, "gold"))) { 473 && (pouch->race == NULL || strstr(pouch->race, "gold"))) {
474 to_pay = pay_from_container(pl, pouch, to_pay); 474 to_pay = pay_from_container(pl, pouch, to_pay);
475 } 475 }
476 } 476 }
477 fix_player(pl); 477 fix_player(pl);
478 return 1; 478 return 1;
479} 479}
480 480
501 change_exp(pl,saved_money,"bargaining",SK_EXP_NONE); 501 change_exp(pl,saved_money,"bargaining",SK_EXP_NONE);
502 502
503 to_pay = pay_from_container(pl, pl, to_pay); 503 to_pay = pay_from_container(pl, pl, to_pay);
504 504
505 for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) { 505 for (pouch=pl->inv; (pouch!=NULL) && (to_pay>0); pouch=pouch->below) {
506 if (pouch->type == CONTAINER 506 if (pouch->type == CONTAINER
507 && QUERY_FLAG(pouch, FLAG_APPLIED) 507 && QUERY_FLAG(pouch, FLAG_APPLIED)
508 && (pouch->race == NULL || strstr(pouch->race, "gold"))) { 508 && (pouch->race == NULL || strstr(pouch->race, "gold"))) {
509 to_pay = pay_from_container(pl, pouch, to_pay); 509 to_pay = pay_from_container(pl, pouch, to_pay);
510 } 510 }
511 } 511 }
512 if (settings.real_wiz == FALSE && QUERY_FLAG(pl, FLAG_WAS_WIZ)) 512 if (settings.real_wiz == FALSE && QUERY_FLAG(pl, FLAG_WAS_WIZ))
513 SET_FLAG(op, FLAG_WAS_WIZ); 513 SET_FLAG(op, FLAG_WAS_WIZ);
514 fix_player(pl); 514 fix_player(pl);
515 return 1; 515 return 1;
516} 516}
517 517
518/* This pays for the item, and takes the proper amount of money off 518/* This pays for the item, and takes the proper amount of money off
540 remain = to_pay; 540 remain = to_pay;
541 for (i=0; i<NUM_COINS; i++) coin_objs[i] = NULL; 541 for (i=0; i<NUM_COINS; i++) coin_objs[i] = NULL;
542 542
543 /* This hunk should remove all the money objects from the player/container */ 543 /* This hunk should remove all the money objects from the player/container */
544 for (tmp=pouch->inv; tmp; tmp=next) { 544 for (tmp=pouch->inv; tmp; tmp=next) {
545 next = tmp->below; 545 next = tmp->below;
546 546
547 if (tmp->type == MONEY) { 547 if (tmp->type == MONEY) {
548 for (i=0; i<NUM_COINS; i++) { 548 for (i=0; i<NUM_COINS; i++) {
549 if (!strcmp(coins[NUM_COINS-1-i], tmp->arch->name) && 549 if (!strcmp(coins[NUM_COINS-1-i], tmp->arch->name) &&
550 (tmp->value == tmp->arch->clone.value) ) { 550 (tmp->value == tmp->arch->clone.value) ) {
551 551
552 /* This should not happen, but if it does, just * 552 /* This should not happen, but if it does, just *
553 * merge the two. */ 553 * merge the two. */
554 if (coin_objs[i]!=NULL) { 554 if (coin_objs[i]!=NULL) {
555 LOG(llevError,"%s has two money entries of (%s)\n", 555 LOG(llevError,"%s has two money entries of (%s)\n",
556 pouch->name, coins[NUM_COINS-1-i]); 556 pouch->name, coins[NUM_COINS-1-i]);
557 remove_ob(tmp); 557 remove_ob(tmp);
558 coin_objs[i]->nrof += tmp->nrof; 558 coin_objs[i]->nrof += tmp->nrof;
559 esrv_del_item(pl->contr, tmp->count); 559 esrv_del_item(pl->contr, tmp->count);
560 free_object(tmp); 560 free_object(tmp);
561 } 561 }
562 else { 562 else {
563 remove_ob(tmp); 563 remove_ob(tmp);
564 if(pouch->type==PLAYER) esrv_del_item(pl->contr, tmp->count); 564 if(pouch->type==PLAYER) esrv_del_item(pl->contr, tmp->count);
565 coin_objs[i] = tmp; 565 coin_objs[i] = tmp;
566 } 566 }
567 break; 567 break;
568 } 568 }
569 } 569 }
570 if (i==NUM_COINS) 570 if (i==NUM_COINS)
571 LOG(llevError,"in pay_for_item: Did not find string match for %s\n", tmp->arch->name); 571 LOG(llevError,"in pay_for_item: Did not find string match for %s\n", tmp->arch->name);
572 } 572 }
573 } 573 }
574 574
575 /* Fill in any gaps in the coin_objs array - needed to make change. */ 575 /* Fill in any gaps in the coin_objs array - needed to make change. */
576 /* Note that the coin_objs array goes from least value to greatest value */ 576 /* Note that the coin_objs array goes from least value to greatest value */
577 for (i=0; i<NUM_COINS; i++) 577 for (i=0; i<NUM_COINS; i++)
578 if (coin_objs[i]==NULL) { 578 if (coin_objs[i]==NULL) {
579 at = find_archetype(coins[NUM_COINS-1-i]); 579 at = find_archetype(coins[NUM_COINS-1-i]);
580 if (at==NULL) LOG(llevError, "Could not find %s archetype\n", coins[NUM_COINS-1-i]); 580 if (at==NULL) LOG(llevError, "Could not find %s archetype\n", coins[NUM_COINS-1-i]);
581 coin_objs[i] = arch_to_object (at); 581 coin_objs[i] = arch_to_object (at);
582 coin_objs[i]->nrof = 0; 582 coin_objs[i]->nrof = 0;
583 } 583 }
584 584
585 for (i=0; i<NUM_COINS; i++) { 585 for (i=0; i<NUM_COINS; i++) {
586 int num_coins; 586 int num_coins;
587 587
588 if (coin_objs[i]->nrof*coin_objs[i]->value> remain) { 588 if (coin_objs[i]->nrof*coin_objs[i]->value> remain) {
589 num_coins = remain / coin_objs[i]->value; 589 num_coins = remain / coin_objs[i]->value;
590 if ((uint64)num_coins*(uint64)coin_objs[i]->value < remain) num_coins++; 590 if ((uint64)num_coins*(uint64)coin_objs[i]->value < remain) num_coins++;
591 } else { 591 } else {
592 num_coins = coin_objs[i]->nrof; 592 num_coins = coin_objs[i]->nrof;
593 } 593 }
594 remain -= (sint64) num_coins * (sint64)coin_objs[i]->value; 594 remain -= (sint64) num_coins * (sint64)coin_objs[i]->value;
595 coin_objs[i]->nrof -= num_coins; 595 coin_objs[i]->nrof -= num_coins;
596 /* Now start making change. Start at the coin value 596 /* Now start making change. Start at the coin value
597 * below the one we just did, and work down to 597 * below the one we just did, and work down to
598 * the lowest value. 598 * the lowest value.
599 */ 599 */
600 count=i-1; 600 count=i-1;
601 while (remain<0 && count>=0) { 601 while (remain<0 && count>=0) {
602 num_coins = -remain/ coin_objs[count]->value; 602 num_coins = -remain/ coin_objs[count]->value;
603 coin_objs[count]->nrof += num_coins; 603 coin_objs[count]->nrof += num_coins;
604 remain += num_coins * coin_objs[count]->value; 604 remain += num_coins * coin_objs[count]->value;
605 count--; 605 count--;
606 } 606 }
607 } 607 }
608 for (i=0; i<NUM_COINS; i++) { 608 for (i=0; i<NUM_COINS; i++) {
609 if (coin_objs[i]->nrof) { 609 if (coin_objs[i]->nrof) {
610 object *tmp = insert_ob_in_ob(coin_objs[i], pouch); 610 object *tmp = insert_ob_in_ob(coin_objs[i], pouch);
611 611
612 esrv_send_item(pl, tmp); 612 esrv_send_item(pl, tmp);
613 esrv_send_item (pl, pouch); 613 esrv_send_item (pl, pouch);
614 if (pl != pouch) esrv_update_item (UPD_WEIGHT, pl, pouch); 614 if (pl != pouch) esrv_update_item (UPD_WEIGHT, pl, pouch);
615 if (pl->type != PLAYER) { 615 if (pl->type != PLAYER) {
616 esrv_send_item (pl, pl); 616 esrv_send_item (pl, pl);
617 } 617 }
618 } else { 618 } else {
619 free_object(coin_objs[i]); 619 free_object(coin_objs[i]);
620 } 620 }
621 } 621 }
622 return(remain); 622 return(remain);
623} 623}
624 624
625/* Checks all unpaid items in op's inventory, adds up all the money they 625/* Checks all unpaid items in op's inventory, adds up all the money they
633 uint64 unpaid_price = 0; 633 uint64 unpaid_price = 0;
634 uint64 player_wealth = query_money(pl); 634 uint64 player_wealth = query_money(pl);
635 object *item; 635 object *item;
636 uint32 coincount[NUM_COINS]; 636 uint32 coincount[NUM_COINS];
637 if (!pl || pl->type != PLAYER) { 637 if (!pl || pl->type != PLAYER) {
638 LOG(llevError, "can_pay(): called against something that isn't a player\n"); 638 LOG(llevError, "can_pay(): called against something that isn't a player\n");
639 return 0; 639 return 0;
640 } 640 }
641 for (i=0; i< NUM_COINS; i++) coincount[i] = 0; 641 for (i=0; i< NUM_COINS; i++) coincount[i] = 0;
642 for (item = pl->inv;item;) { 642 for (item = pl->inv;item;) {
643 if QUERY_FLAG(item, FLAG_UNPAID) { 643 if QUERY_FLAG(item, FLAG_UNPAID) {
644 unpaid_count++; 644 unpaid_count++;
645 unpaid_price += query_cost(item, pl, F_BUY | F_SHOP); 645 unpaid_price += query_cost(item, pl, F_BUY | F_SHOP);
646 } 646 }
647 /* merely converting the player's monetary wealth won't do, if we did that, 647 /* merely converting the player's monetary wealth won't do, if we did that,
648 * we could print the wrong numbers for the coins, so we count the money instead 648 * we could print the wrong numbers for the coins, so we count the money instead
649 */ 649 */
650 for (i=0; i< NUM_COINS; i++) 650 for (i=0; i< NUM_COINS; i++)
651 if (!strcmp(coins[i], item->arch->name)) 651 if (!strcmp(coins[i], item->arch->name))
652 coincount[i] += item->nrof; 652 coincount[i] += item->nrof;
653 if (item->inv) item = item->inv; 653 if (item->inv) item = item->inv;
654 else if (item->below) item = item->below; 654 else if (item->below) item = item->below;
655 else if (item->env && item->env != pl && item->env->below) item = item->env->below; 655 else if (item->env && item->env != pl && item->env->below) item = item->env->below;
656 else item = NULL; 656 else item = NULL;
657 } 657 }
658 if (unpaid_price > player_wealth) { 658 if (unpaid_price > player_wealth) {
659 char buf[MAX_BUF], coinbuf[MAX_BUF]; 659 char buf[MAX_BUF], coinbuf[MAX_BUF];
660 int denominations = 0; 660 int denominations = 0;
661 int has_coins = NUM_COINS; 661 int has_coins = NUM_COINS;
662 char cost[MAX_BUF]; 662 char cost[MAX_BUF];
663 char missing[MAX_BUF]; 663 char missing[MAX_BUF];
664 664
665 sprintf(cost, "%s", cost_string_from_value (unpaid_price, 0)); 665 sprintf(cost, "%s", cost_string_from_value (unpaid_price, 0));
666 sprintf(missing, "%s", cost_string_from_value (unpaid_price - player_wealth, 0)); 666 sprintf(missing, "%s", cost_string_from_value (unpaid_price - player_wealth, 0));
667 667
668 sprintf(buf, "You have %d unpaid items that would cost you %s. You need another %s to be able to afford that.", 668 sprintf(buf, "You have %d unpaid items that would cost you %s. You need another %s to be able to afford that.",
669 unpaid_count, cost, missing); 669 unpaid_count, cost, missing);
670 new_draw_info(NDI_UNIQUE, 0, pl, buf); 670 new_draw_info(NDI_UNIQUE, 0, pl, buf);
671 return 0; 671 return 0;
672 } 672 }
673 else return 1; 673 else return 1;
674} 674}
675 675
676 676
702 if(op!=NULL&&QUERY_FLAG(op,FLAG_UNPAID)) { 702 if(op!=NULL&&QUERY_FLAG(op,FLAG_UNPAID)) {
703 strncpy(buf,query_cost_string(op,pl,F_BUY | F_SHOP),MAX_BUF); 703 strncpy(buf,query_cost_string(op,pl,F_BUY | F_SHOP),MAX_BUF);
704 buf[MAX_BUF-1] = '\0'; 704 buf[MAX_BUF-1] = '\0';
705 if(!pay_for_item(op,pl)) { 705 if(!pay_for_item(op,pl)) {
706 uint64 i=query_cost(op,pl,F_BUY | F_SHOP) - query_money(pl); 706 uint64 i=query_cost(op,pl,F_BUY | F_SHOP) - query_money(pl);
707 CLEAR_FLAG(op, FLAG_UNPAID); 707 CLEAR_FLAG(op, FLAG_UNPAID);
708 new_draw_info_format(NDI_UNIQUE, 0, pl, 708 new_draw_info_format(NDI_UNIQUE, 0, pl,
709 "You lack %s to buy %s.", cost_string_from_value (i, 0), 709 "You lack %s to buy %s.", cost_string_from_value (i, 0),
710 query_name(op)); 710 query_name(op));
711 SET_FLAG(op, FLAG_UNPAID); 711 SET_FLAG(op, FLAG_UNPAID);
712 return 0; 712 return 0;
713 } else { 713 } else {
714 object *tmp; 714 object *tmp;
715 tag_t c = op->count; 715 tag_t c = op->count;
716 716
717 CLEAR_FLAG(op, FLAG_UNPAID); 717 CLEAR_FLAG(op, FLAG_UNPAID);
718 CLEAR_FLAG(op, FLAG_PLAYER_SOLD); 718 CLEAR_FLAG(op, FLAG_PLAYER_SOLD);
719 new_draw_info_format(NDI_UNIQUE, 0, op, 719 new_draw_info_format(NDI_UNIQUE, 0, op,
720 "You paid %s for %s.",buf,query_name(op)); 720 "You paid %s for %s.",buf,query_name(op));
721 tmp=merge_ob(op,NULL); 721 tmp=merge_ob(op,NULL);
722 if (pl->type == PLAYER) { 722 if (pl->type == PLAYER) {
723 if (tmp) { /* it was merged */ 723 if (tmp) { /* it was merged */
724 esrv_del_item (pl->contr, c); 724 esrv_del_item (pl->contr, c);
725 op = tmp; 725 op = tmp;
726 } 726 }
727 esrv_send_item(pl, op); 727 esrv_send_item(pl, op);
728 } 728 }
729 } 729 }
730 } 730 }
731 return 1; 731 return 1;
732} 732}
733 733
734/* written by elmex: 734/* written by elmex:
892 shopitems *items=map->shopitems; 892 shopitems *items=map->shopitems;
893 double ratio = SPECIALISATION_EFFECT, likedness=0.001; 893 double ratio = SPECIALISATION_EFFECT, likedness=0.001;
894 int i; 894 int i;
895 895
896 if (item==NULL) { 896 if (item==NULL) {
897 LOG(llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", map->path); 897 LOG(llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", map->path);
898 return 0; 898 return 0;
899 } 899 }
900 if (!item->type) { 900 if (!item->type) {
901 LOG(llevError, "shop_specialisation_ratio: passed an item with an invalid type\n"); 901 LOG(llevError, "shop_specialisation_ratio: passed an item with an invalid type\n");
902 /* 902 /*
903 * I'm not really sure what the /right/ thing to do here is, these types of 903 * I'm not really sure what the /right/ thing to do here is, these types of
904 * item shouldn't exist anyway, but returning the ratio is probably the best bet.." 904 * item shouldn't exist anyway, but returning the ratio is probably the best bet.."
905 */ 905 */
906 return ratio; 906 return ratio;
907 } 907 }
908 if (map->shopitems) { 908 if (map->shopitems) {
909 for (i=0; i<items[0].index; i++) 909 for (i=0; i<items[0].index; i++)
910 if (items[i].typenum==item->type || (!items[i].typenum && likedness == 0.001)) 910 if (items[i].typenum==item->type || (!items[i].typenum && likedness == 0.001))
911 likedness = items[i].strength/100.0; 911 likedness = items[i].strength/100.0;
912 } 912 }
913 if (likedness > 1.0) { /* someone has been rather silly with the map headers. */ 913 if (likedness > 1.0) { /* someone has been rather silly with the map headers. */
914 LOG(llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", 914 LOG(llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n",
915 item->type, map->path); 915 item->type, map->path);
916 likedness = 1.0; 916 likedness = 1.0;
917 } 917 }
918 if (likedness < -1.0) { 918 if (likedness < -1.0) {
919 LOG(llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", 919 LOG(llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n",
920 item->type, map->path); 920 item->type, map->path);
921 likedness = -1.0; 921 likedness = -1.0;
922 } 922 }
923 ratio = ratio + (1.0-ratio) * likedness; 923 ratio = ratio + (1.0-ratio) * likedness;
924 if (ratio <= 0.1) ratio=0.1; /* if the ratio were much lower than this, we would get silly prices */ 924 if (ratio <= 0.1) ratio=0.1; /* if the ratio were much lower than this, we would get silly prices */
925 return ratio; 925 return ratio;
926} 926}
927 927
928/*returns the greed of the shop on map, or 1 if it isn't specified. */ 928/*returns the greed of the shop on map, or 1 if it isn't specified. */
929static double shop_greed(const mapstruct *map) { 929static double shop_greed(const mapstruct *map) {
930 double greed=1.0; 930 double greed=1.0;
931 if (map->shopgreed) 931 if (map->shopgreed)
932 return map->shopgreed; 932 return map->shopgreed;
933 return greed; 933 return greed;
934} 934}
935 935
936/* Returns a double based on how much the shopkeeper approves of the player. 936/* Returns a double based on how much the shopkeeper approves of the player.
937 * this is based on the race of the shopkeeper and that of the player. 937 * this is based on the race of the shopkeeper and that of the player.
938 */ 938 */
939double shopkeeper_approval(const mapstruct *map, const object *player) { 939double shopkeeper_approval(const mapstruct *map, const object *player) {
940 double approval=1.0; 940 double approval=1.0;
941 941
942 if (map->shoprace) { 942 if (map->shoprace) {
943 approval=NEUTRAL_RATIO; 943 approval=NEUTRAL_RATIO;
944 if (player->race && !strcmp(player->race, map->shoprace)) approval = 1.0; 944 if (player->race && !strcmp(player->race, map->shoprace)) approval = 1.0;
945 } 945 }
946 return approval; 946 return approval;
947} 947}
948 948
1000 char tmp[MAX_BUF]="\0"; 1000 char tmp[MAX_BUF]="\0";
1001 if (op->type != PLAYER) return 0; 1001 if (op->type != PLAYER) return 0;
1002 1002
1003 /*check if there is a shop specified for this map */ 1003 /*check if there is a shop specified for this map */
1004 if (map->shopitems || map->shopgreed || map->shoprace || map->shopmin || map->shopmax) { 1004 if (map->shopitems || map->shopgreed || map->shoprace || map->shopmin || map->shopmax) {
1005 new_draw_info(NDI_UNIQUE,0,op,"From looking at the nearby shop you determine that it trades in:"); 1005 new_draw_info(NDI_UNIQUE,0,op,"From looking at the nearby shop you determine that it trades in:");
1006 if (map->shopitems) { 1006 if (map->shopitems) {
1007 for (i=0; i < map->shopitems[0].index; i++) { 1007 for (i=0; i < map->shopitems[0].index; i++) {
1008 if (map->shopitems[i].name && map->shopitems[i].strength > 10) { 1008 if (map->shopitems[i].name && map->shopitems[i].strength > 10) {
1009 snprintf(tmp+pos, sizeof(tmp)-pos, "%s, ", map->shopitems[i].name_pl); 1009 snprintf(tmp+pos, sizeof(tmp)-pos, "%s, ", map->shopitems[i].name_pl);
1010 pos += strlen(tmp+pos); 1010 pos += strlen(tmp+pos);
1011 } 1011 }
1012 } 1012 }
1013 } 1013 }
1014 if (!pos) strcat(tmp, "a little of everything."); 1014 if (!pos) strcat(tmp, "a little of everything.");
1015 1015
1016 /* format the string into a list */ 1016 /* format the string into a list */
1017 make_list_like(tmp); 1017 make_list_like(tmp);
1018 new_draw_info_format(NDI_UNIQUE, 0, op, "%s", tmp); 1018 new_draw_info_format(NDI_UNIQUE, 0, op, "%s", tmp);
1019 1019
1020 if (map->shopmax) 1020 if (map->shopmax)
1021 new_draw_info_format(NDI_UNIQUE,0,op,"It won't trade for items above %s.", 1021 new_draw_info_format(NDI_UNIQUE,0,op,"It won't trade for items above %s.",
1022 cost_string_from_value(map->shopmax, 0)); 1022 cost_string_from_value(map->shopmax, 0));
1023 if (map->shopmin) 1023 if (map->shopmin)
1024 new_draw_info_format(NDI_UNIQUE,0,op,"It won't trade in items worth less than %s.", 1024 new_draw_info_format(NDI_UNIQUE,0,op,"It won't trade in items worth less than %s.",
1025 cost_string_from_value(map->shopmin, 0)); 1025 cost_string_from_value(map->shopmin, 0));
1026 if (map->shopgreed) { 1026 if (map->shopgreed) {
1027 if (map->shopgreed >2.0) 1027 if (map->shopgreed >2.0)
1028 new_draw_info(NDI_UNIQUE,0,op,"It tends to overcharge massively."); 1028 new_draw_info(NDI_UNIQUE,0,op,"It tends to overcharge massively.");
1029 else if (map->shopgreed >1.5) 1029 else if (map->shopgreed >1.5)
1030 new_draw_info(NDI_UNIQUE,0,op,"It tends to overcharge substantially."); 1030 new_draw_info(NDI_UNIQUE,0,op,"It tends to overcharge substantially.");
1031 else if (map->shopgreed >1.1) 1031 else if (map->shopgreed >1.1)
1032 new_draw_info(NDI_UNIQUE,0,op,"It tends to overcharge slightly."); 1032 new_draw_info(NDI_UNIQUE,0,op,"It tends to overcharge slightly.");
1033 else if (map->shopgreed <0.9) 1033 else if (map->shopgreed <0.9)
1034 new_draw_info(NDI_UNIQUE,0,op,"It tends to undercharge."); 1034 new_draw_info(NDI_UNIQUE,0,op,"It tends to undercharge.");
1035 } 1035 }
1036 if (map->shoprace) { 1036 if (map->shoprace) {
1037 opinion=shopkeeper_approval(map, op); 1037 opinion=shopkeeper_approval(map, op);
1038 if (opinion > 0.8) 1038 if (opinion > 0.8)
1039 new_draw_info(NDI_UNIQUE,0,op,"You think the shopkeeper likes you."); 1039 new_draw_info(NDI_UNIQUE,0,op,"You think the shopkeeper likes you.");
1040 else if (opinion > 0.5) 1040 else if (opinion > 0.5)
1041 new_draw_info(NDI_UNIQUE,0,op,"The shopkeeper seems unconcerned by you."); 1041 new_draw_info(NDI_UNIQUE,0,op,"The shopkeeper seems unconcerned by you.");
1042 else 1042 else
1043 new_draw_info(NDI_UNIQUE,0,op,"The shopkeeper seems to have taken a dislike to you."); 1043 new_draw_info(NDI_UNIQUE,0,op,"The shopkeeper seems to have taken a dislike to you.");
1044 } 1044 }
1045 } 1045 }
1046 else new_draw_info(NDI_UNIQUE,0,op,"There is no shop nearby."); 1046 else new_draw_info(NDI_UNIQUE,0,op,"There is no shop nearby.");
1047 1047
1048 return 1; 1048 return 1;
1049} 1049}
1089 if (tmp->nrof == 0) items[*numitems].nrof++; 1089 if (tmp->nrof == 0) items[*numitems].nrof++;
1090 items[*numitems].type=tmp->type; 1090 items[*numitems].type=tmp->type;
1091 1091
1092 switch (tmp->type) { 1092 switch (tmp->type) {
1093#if 0 1093#if 0
1094 case BOOTS: 1094 case BOOTS:
1095 case GLOVES: 1095 case GLOVES:
1096 case RING: 1096 case RING:
1097 case AMULET: 1097 case AMULET:
1098 case BRACERS: 1098 case BRACERS:
1099 case GIRDLE: 1099 case GIRDLE:
1100 sprintf(buf,"%s %s",query_base_name(tmp,0),describe_item(tmp, NULL)); 1100 sprintf(buf,"%s %s",query_base_name(tmp,0),describe_item(tmp, NULL));
1101 items[*numitems].item_sort = strdup_local(buf); 1101 items[*numitems].item_sort = strdup_local(buf);
1102 sprintf(buf,"%s %s",query_name(tmp),describe_item(tmp, NULL)); 1102 sprintf(buf,"%s %s",query_name(tmp),describe_item(tmp, NULL));
1103 items[*numitems].item_real = strdup_local(buf); 1103 items[*numitems].item_real = strdup_local(buf);
1104 (*numitems)++; 1104 (*numitems)++;
1105 break; 1105 break;
1106#endif 1106#endif
1107 1107
1108 default: 1108 default:
1109 items[*numitems].item_sort = strdup_local(query_base_name(tmp, 0)); 1109 items[*numitems].item_sort = strdup_local(query_base_name(tmp, 0));
1110 items[*numitems].item_real = strdup_local(query_base_name(tmp, 1)); 1110 items[*numitems].item_real = strdup_local(query_base_name(tmp, 1));
1111 (*numitems)++; 1111 (*numitems)++;
1112 break; 1112 break;
1113 } 1113 }
1114 SET_FLAG(tmp, FLAG_UNPAID); 1114 SET_FLAG(tmp, FLAG_UNPAID);
1115} 1115}
1116 1116
1117void shop_listing(object *op) 1117void shop_listing(object *op)
1130 items=(shopinv*)malloc(40*sizeof(shopinv)); 1130 items=(shopinv*)malloc(40*sizeof(shopinv));
1131 numallocated=40; 1131 numallocated=40;
1132 1132
1133 /* Find all the appropriate items */ 1133 /* Find all the appropriate items */
1134 for (i=0; i<MAP_WIDTH(op->map); i++) { 1134 for (i=0; i<MAP_WIDTH(op->map); i++) {
1135 for (j=0; j<MAP_HEIGHT(op->map); j++) { 1135 for (j=0; j<MAP_HEIGHT(op->map); j++) {
1136 /* magic map code now centers the map on the object at MAGIC_MAP_HALF. 1136 /* magic map code now centers the map on the object at MAGIC_MAP_HALF.
1137 * 1137 *
1138 */ 1138 */
1139 nx = i - op->x + MAGIC_MAP_HALF; 1139 nx = i - op->x + MAGIC_MAP_HALF;
1140 ny = j - op->y + MAGIC_MAP_HALF; 1140 ny = j - op->y + MAGIC_MAP_HALF;
1141 /* unlikely, but really big shops could run into this issue */ 1141 /* unlikely, but really big shops could run into this issue */
1142 if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE) continue; 1142 if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE) continue;
1143 1143
1144 if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR) { 1144 if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR) {
1145 stack =get_map_ob(op->map,i,j); 1145 stack =get_map_ob(op->map,i,j);
1146 1146
1147 while (stack) { 1147 while (stack) {
1148 if (QUERY_FLAG(stack, FLAG_UNPAID)) { 1148 if (QUERY_FLAG(stack, FLAG_UNPAID)) {
1149 if (numitems==numallocated) { 1149 if (numitems==numallocated) {
1150 items=(shopinv*)realloc(items, sizeof(shopinv)*(numallocated+10)); 1150 items=(shopinv*)realloc(items, sizeof(shopinv)*(numallocated+10));
1151 numallocated+=10; 1151 numallocated+=10;
1152 } 1152 }
1153 add_shop_item(stack, items, &numitems, &numallocated); 1153 add_shop_item(stack, items, &numitems, &numallocated);
1154 } 1154 }
1155 stack = stack->above; 1155 stack = stack->above;
1156 } 1156 }
1157 } 1157 }
1158 } 1158 }
1159 } 1159 }
1160 free(map_mark); 1160 free(map_mark);
1161 if (numitems == 0) { 1161 if (numitems == 0) {
1162 new_draw_info(NDI_UNIQUE, 0, op, "The shop is currently empty.\n"); 1162 new_draw_info(NDI_UNIQUE, 0, op, "The shop is currently empty.\n");
1163 free(items); 1163 free(items);
1164 return; 1164 return;
1165 } 1165 }
1166 qsort(items, numitems, sizeof(shopinv), (int (*)(const void*, const void*))shop_sort); 1166 qsort(items, numitems, sizeof(shopinv), (int (*)(const void*, const void*))shop_sort);
1167 1167
1168 for (i=0; i<numitems; i++) { 1168 for (i=0; i<numitems; i++) {
1169 /* Collapse items of the same name together */ 1169 /* Collapse items of the same name together */
1170 if ((i+1)<numitems && !strcmp(items[i].item_real, items[i+1].item_real)) { 1170 if ((i+1)<numitems && !strcmp(items[i].item_real, items[i+1].item_real)) {
1171 items[i+1].nrof += items[i].nrof; 1171 items[i+1].nrof += items[i].nrof;
1172 free(items[i].item_sort); 1172 free(items[i].item_sort);
1173 free(items[i].item_real); 1173 free(items[i].item_real);
1174 } else { 1174 } else {
1175 new_draw_info_format(NDI_UNIQUE, 0, op, "%d %s", 1175 new_draw_info_format(NDI_UNIQUE, 0, op, "%d %s",
1176 items[i].nrof? items[i].nrof:1, 1176 items[i].nrof? items[i].nrof:1,
1177 items[i].nrof==1?items[i].item_sort: items[i].item_real); 1177 items[i].nrof==1?items[i].item_sort: items[i].item_real);
1178 free(items[i].item_sort); 1178 free(items[i].item_sort);
1179 free(items[i].item_real); 1179 free(items[i].item_real);
1180 } 1180 }
1181 } 1181 }
1182 free(items); 1182 free(items);
1183} 1183}
1184
1185/* elmex: this function checks whether the object is in a shop */
1186bool is_in_shop (object *o)
1187{
1188 if (!o->map)
1189 return false;
1190
1191 return is_in_shop (o->map, o->x, o->y);
1192}
1193
1194/* elmex: this function checks whether we are in a shop or not */
1195bool is_in_shop (mapstruct *map, int x, int y)
1196{
1197 for (object *floor = get_map_ob (map, x, y); floor; floor = floor->above)
1198 if (floor->type == SHOP_FLOOR)
1199 return true;
1200
1201 return false;
1202}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines