| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "global.h" |
| 22 |
|
| 23 |
#include <assert.h> |
| 24 |
#include <math.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <string.h> |
| 27 |
|
| 28 |
#include "shop.h" |
| 29 |
#include "sproto.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#define SPECIALISATION_EFFECT 0.5 |
| 40 |
|
| 41 |
|
| 42 |
#define DISAPPROVAL_RATIO 0.2 |
| 43 |
|
| 44 |
|
| 45 |
#define NEUTRAL_RATIO 0.8 |
| 46 |
|
| 47 |
static uint64_t pay_from_container(object *pl, object *pouch, uint64_t to_pay); |
| 48 |
static uint64_t value_limit(uint64_t val, int quantity, const object *who, int isshop); |
| 49 |
static double shop_specialisation_ratio(const object *item, const mapstruct *map); |
| 50 |
static double shop_greed(const mapstruct *map); |
| 51 |
|
| 52 |
#define NUM_COINS 5 |
| 53 |
|
| 54 |
#define LARGEST_COIN_GIVEN 2 |
| 55 |
|
| 56 |
|
| 57 |
static const char *const coins[] = { |
| 58 |
"ambercoin", |
| 59 |
"jadecoin", |
| 60 |
"platinacoin", |
| 61 |
"goldcoin", |
| 62 |
"silvercoin", |
| 63 |
NULL |
| 64 |
}; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
uint64_t price_base(const object *obj) { |
| 71 |
|
| 72 |
const int number = NROF(obj); |
| 73 |
const bool identified = is_identified(obj); |
| 74 |
uint64_t val = (uint64_t)obj->value * number; |
| 75 |
|
| 76 |
|
| 77 |
const char *key = object_get_value(obj, "price_adjustment"); |
| 78 |
if (key != NULL) { |
| 79 |
float ratio = atof(key); |
| 80 |
return val * ratio; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
if (obj->type == MONEY || obj->type == GEM) { |
| 85 |
return val; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
if (!identified && obj->arch) { |
| 90 |
val = obj->arch->clone.value * number; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
if (QUERY_FLAG(obj, FLAG_BLESSED)){ |
| 99 |
val *= 1.15; |
| 100 |
} else if (QUERY_FLAG(obj, FLAG_CURSED)) { |
| 101 |
val *= 0.8; |
| 102 |
} else if (QUERY_FLAG(obj, FLAG_DAMNED)) { |
| 103 |
val *= 0.6; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
if (obj->arch != NULL && identified) { |
| 109 |
int diff = obj->magic - obj->arch->clone.magic; |
| 110 |
val *= pow(1.15, diff); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
if (obj->type == WAND) { |
| 115 |
val *= obj->stats.food / 50.0; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
val *= 4; |
| 124 |
|
| 125 |
return val; |
| 126 |
} |
| 127 |
|
| 128 |
uint64_t price_approx(const object *tmp, object *who) { |
| 129 |
uint64_t val = price_base(tmp); |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
const typedata *tmptype = get_typedata(tmp->type); |
| 142 |
int lev_identify = 0; |
| 143 |
|
| 144 |
if (tmptype) { |
| 145 |
int idskill1 = tmptype->identifyskill; |
| 146 |
if (idskill1) { |
| 147 |
int idskill2 = tmptype->identifyskill2; |
| 148 |
if (find_skill_by_number(who, idskill1)) { |
| 149 |
lev_identify = find_skill_by_number(who, idskill1)->level; |
| 150 |
} |
| 151 |
if (idskill2 && find_skill_by_number(who, idskill2)) { |
| 152 |
lev_identify += find_skill_by_number(who, idskill2)->level; |
| 153 |
} |
| 154 |
} |
| 155 |
} else { |
| 156 |
LOG(llevError, "Query_cost: item %s hasn't got a valid type\n", tmp->name); |
| 157 |
} |
| 158 |
val += val * (sin(tmp->count) / sqrt(lev_identify * 3 + 1.0)); |
| 159 |
|
| 160 |
return val; |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
static float shop_buy_multiplier(int charisma) { |
| 170 |
float multiplier = 1 / (0.38 * pow(1.06, charisma)); |
| 171 |
|
| 172 |
if (multiplier > 2) { |
| 173 |
return 2; |
| 174 |
} else if (multiplier < 0.5) { |
| 175 |
return 0.5; |
| 176 |
} else { |
| 177 |
return multiplier; |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
static float shop_bargain_multiplier(int lev_bargain) { |
| 189 |
return 1 - 0.5 * lev_bargain / settings.max_level; |
| 190 |
} |
| 191 |
|
| 192 |
uint64_t shop_price_buy(const object *tmp, object *who) { |
| 193 |
assert(who != NULL && who->type == PLAYER); |
| 194 |
uint64_t val = price_base(tmp); |
| 195 |
|
| 196 |
const char *key = object_get_value(tmp, "price_adjustment_buy"); |
| 197 |
if (key != NULL) { |
| 198 |
float ratio = atof(key); |
| 199 |
return val * ratio; |
| 200 |
} |
| 201 |
|
| 202 |
if (tmp->type == GEM) { |
| 203 |
return 1.03 * val; |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) { |
| 208 |
val *= 0.8; |
| 209 |
} |
| 210 |
|
| 211 |
int bargain_level = 0; |
| 212 |
if (find_skill_by_number(who, SK_BARGAINING)) { |
| 213 |
bargain_level = find_skill_by_number(who, SK_BARGAINING)->level; |
| 214 |
} |
| 215 |
|
| 216 |
float multiplier = shop_bargain_multiplier(bargain_level); |
| 217 |
multiplier *= shop_buy_multiplier(who->stats.Cha); |
| 218 |
|
| 219 |
|
| 220 |
val *= multiplier > 0.5 ? multiplier : 0.5; |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
if (QUERY_FLAG(tmp, FLAG_PLAYER_SOLD)) { |
| 238 |
val = (int64_t)val*shop_greed(who->map) |
| 239 |
*shop_specialisation_ratio(tmp, who->map) |
| 240 |
/shop_approval(who->map, who); |
| 241 |
} else { |
| 242 |
val = (int64_t)val*shop_greed(who->map) |
| 243 |
/(shop_specialisation_ratio(tmp, who->map) |
| 244 |
*shop_approval(who->map, who)); |
| 245 |
} |
| 246 |
|
| 247 |
return val; |
| 248 |
} |
| 249 |
|
| 250 |
uint64_t shop_price_sell(const object *tmp, object *who) { |
| 251 |
assert(who != NULL && who->type == PLAYER); |
| 252 |
uint64_t val = price_base(tmp); |
| 253 |
|
| 254 |
const char *key = object_get_value(tmp, "price_adjustment_sell"); |
| 255 |
if (key != NULL) { |
| 256 |
float ratio = atof(key); |
| 257 |
return val * ratio; |
| 258 |
} |
| 259 |
|
| 260 |
if (tmp->type == GEM) { |
| 261 |
return 0.97 * val; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
if (!is_identified(tmp)) { |
| 266 |
if (tmp->arch != NULL) { |
| 267 |
|
| 268 |
if (QUERY_FLAG(tmp, FLAG_BEEN_APPLIED)) { |
| 269 |
val *= 0.85; |
| 270 |
} else { |
| 271 |
val *= 0.70; |
| 272 |
} |
| 273 |
} else { |
| 274 |
|
| 275 |
val /= 2; |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
val /= 2; |
| 281 |
|
| 282 |
|
| 283 |
int number = NROF(tmp); |
| 284 |
val = value_limit(val, number, who, 1); |
| 285 |
|
| 286 |
val = (int64_t)val*shop_specialisation_ratio(tmp, who->map)* |
| 287 |
shop_approval(who->map, who)/shop_greed(who->map); |
| 288 |
return val; |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
static archetype *find_next_coin(uint64_t c, int *cointype) { |
| 303 |
archetype *coin; |
| 304 |
|
| 305 |
do { |
| 306 |
if (coins[*cointype] == NULL) |
| 307 |
return NULL; |
| 308 |
coin = find_archetype(coins[*cointype]); |
| 309 |
if (coin == NULL) |
| 310 |
return NULL; |
| 311 |
*cointype += 1; |
| 312 |
} while (coin->clone.value > (int64_t) c); |
| 313 |
|
| 314 |
return coin; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
char* cost_string_from_value(uint64_t cost, int largest_coin) { |
| 335 |
archetype *coin, *next_coin; |
| 336 |
uint32_t num; |
| 337 |
int cointype = largest_coin; |
| 338 |
|
| 339 |
if (cointype < 0) |
| 340 |
cointype = 0; |
| 341 |
else if (cointype >= NUM_COINS) |
| 342 |
cointype = NUM_COINS - 1; |
| 343 |
|
| 344 |
StringBuffer* buf = stringbuffer_new(); |
| 345 |
coin = find_next_coin(cost, &cointype); |
| 346 |
if (coin == NULL) { |
| 347 |
stringbuffer_append_string(buf, "nothing"); |
| 348 |
goto done; |
| 349 |
} |
| 350 |
|
| 351 |
num = cost/coin->clone.value; |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
if ((cost/coin->clone.value) > UINT32_MAX) { |
| 357 |
stringbuffer_append_string(buf, "an unimaginable sum of money."); |
| 358 |
goto done; |
| 359 |
} |
| 360 |
|
| 361 |
cost -= (uint64_t)num*(uint64_t)coin->clone.value; |
| 362 |
if (num == 1) |
| 363 |
stringbuffer_append_printf(buf, "1 %s", coin->clone.name); |
| 364 |
else |
| 365 |
stringbuffer_append_printf(buf, "%u %ss", num, coin->clone.name); |
| 366 |
|
| 367 |
next_coin = find_next_coin(cost, &cointype); |
| 368 |
if (next_coin == NULL) |
| 369 |
goto done; |
| 370 |
|
| 371 |
do { |
| 372 |
coin = next_coin; |
| 373 |
num = cost/coin->clone.value; |
| 374 |
cost -= (uint64_t)num*(uint64_t)coin->clone.value; |
| 375 |
|
| 376 |
if (cost == 0) |
| 377 |
next_coin = NULL; |
| 378 |
else |
| 379 |
next_coin = find_next_coin(cost, &cointype); |
| 380 |
|
| 381 |
if (next_coin) { |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
stringbuffer_append_string(buf, ", "); |
| 386 |
} else { |
| 387 |
stringbuffer_append_string(buf, " and "); |
| 388 |
} |
| 389 |
if (num == 1) |
| 390 |
stringbuffer_append_printf(buf, "1 %s", coin->clone.name); |
| 391 |
else |
| 392 |
stringbuffer_append_printf(buf, "%u %ss", num, coin->clone.name); |
| 393 |
} while (next_coin); |
| 394 |
|
| 395 |
done: |
| 396 |
return stringbuffer_finish(buf); |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
static StringBuffer *real_money_value(const object *coin, StringBuffer *buf) { |
| 410 |
assert(coin->type == MONEY); |
| 411 |
assert(buf); |
| 412 |
|
| 413 |
stringbuffer_append_printf(buf, "%ld %s", (long)coin->nrof, coin->nrof == 1 ? coin->name : coin->name_pl); |
| 414 |
return buf; |
| 415 |
} |
| 416 |
|
| 417 |
char *cost_str(uint64_t cost) { |
| 418 |
return cost_string_from_value(cost, LARGEST_COIN_GIVEN); |
| 419 |
} |
| 420 |
|
| 421 |
char *cost_approx_str(const object *tmp, object *who) { |
| 422 |
uint64_t approx_val = price_approx(tmp, who); |
| 423 |
int idskill1 = 0; |
| 424 |
int idskill2 = 0; |
| 425 |
const typedata *tmptype; |
| 426 |
|
| 427 |
StringBuffer *buf = stringbuffer_new(); |
| 428 |
|
| 429 |
|
| 430 |
if (tmp->type == MONEY) { |
| 431 |
return stringbuffer_finish(real_money_value(tmp, buf)); |
| 432 |
} |
| 433 |
|
| 434 |
tmptype = get_typedata(tmp->type); |
| 435 |
if (tmptype) { |
| 436 |
idskill1 = tmptype->identifyskill; |
| 437 |
idskill2 = tmptype->identifyskill2; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
if (!idskill1 || !find_skill_by_number(who, idskill1)) { |
| 446 |
if (!idskill2 || !find_skill_by_number(who, idskill2)) { |
| 447 |
if (!find_skill_by_number(who, SK_BARGAINING)) { |
| 448 |
int num; |
| 449 |
int cointype = LARGEST_COIN_GIVEN; |
| 450 |
archetype *coin = find_next_coin(approx_val, &cointype); |
| 451 |
|
| 452 |
if (coin == NULL) { |
| 453 |
stringbuffer_append_string(buf, "nothing"); |
| 454 |
return stringbuffer_finish(buf); |
| 455 |
} |
| 456 |
|
| 457 |
num = approx_val/coin->clone.value; |
| 458 |
if (num == 1) |
| 459 |
stringbuffer_append_printf(buf, "about one %s", coin->clone.name); |
| 460 |
else if (num < 5) |
| 461 |
stringbuffer_append_printf(buf, "a few %s", coin->clone.name_pl); |
| 462 |
else if (num < 10) |
| 463 |
stringbuffer_append_printf(buf, "several %s", coin->clone.name_pl); |
| 464 |
else if (num < 25) |
| 465 |
stringbuffer_append_printf(buf, "a moderate amount of %s", coin->clone.name_pl); |
| 466 |
else if (num < 100) |
| 467 |
stringbuffer_append_printf(buf, "lots of %s", coin->clone.name_pl); |
| 468 |
else if (num < 1000) |
| 469 |
stringbuffer_append_printf(buf, "a great many %s", coin->clone.name_pl); |
| 470 |
else |
| 471 |
stringbuffer_append_printf(buf, "a vast quantity of %s", coin->clone.name_pl); |
| 472 |
return stringbuffer_finish(buf); |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
stringbuffer_delete(buf); |
| 479 |
return cost_str(approx_val); |
| 480 |
} |
| 481 |
|
| 482 |
uint64_t query_money(const object *op) { |
| 483 |
uint64_t total = 0; |
| 484 |
|
| 485 |
if (op->type != PLAYER && op->type != CONTAINER) { |
| 486 |
LOG(llevError, "Query money called with non player/container\n"); |
| 487 |
return 0; |
| 488 |
} |
| 489 |
FOR_INV_PREPARE(op, tmp) { |
| 490 |
if (tmp->type == MONEY) { |
| 491 |
total += (uint64_t)tmp->nrof*(uint64_t)tmp->value; |
| 492 |
} else if (tmp->type == CONTAINER |
| 493 |
&& QUERY_FLAG(tmp, FLAG_APPLIED) |
| 494 |
&& (tmp->race == NULL || strstr(tmp->race, "gold"))) { |
| 495 |
total += query_money(tmp); |
| 496 |
} |
| 497 |
} FOR_INV_FINISH(); |
| 498 |
return total; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
int pay_for_amount(uint64_t to_pay, object *pl) { |
| 514 |
if (to_pay == 0) |
| 515 |
return 1; |
| 516 |
if (to_pay > query_money(pl)) |
| 517 |
return 0; |
| 518 |
|
| 519 |
to_pay = pay_from_container(pl, pl, to_pay); |
| 520 |
|
| 521 |
FOR_INV_PREPARE(pl, pouch) { |
| 522 |
if (to_pay <= 0) |
| 523 |
break; |
| 524 |
if (pouch->type == CONTAINER |
| 525 |
&& QUERY_FLAG(pouch, FLAG_APPLIED) |
| 526 |
&& (pouch->race == NULL || strstr(pouch->race, "gold"))) { |
| 527 |
to_pay = pay_from_container(pl, pouch, to_pay); |
| 528 |
} |
| 529 |
} FOR_INV_FINISH(); |
| 530 |
if (to_pay > 0) { |
| 531 |
LOG(llevError, "pay_for_amount: Cannot remove enough money -- %"FMT64U" remains\n", to_pay); |
| 532 |
} |
| 533 |
|
| 534 |
fix_object(pl); |
| 535 |
return 1; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
int pay_for_item(object *op, object *pl) { |
| 552 |
uint64_t to_pay = shop_price_buy(op, pl); |
| 553 |
|
| 554 |
if (to_pay == 0) |
| 555 |
return 1; |
| 556 |
if (to_pay > query_money(pl)) |
| 557 |
return 0; |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
int64_t saved_money = price_base(op) - to_pay; |
| 564 |
if (saved_money > 0) |
| 565 |
change_exp(pl, saved_money, "bargaining", SK_EXP_NONE); |
| 566 |
|
| 567 |
to_pay = pay_from_container(pl, pl, to_pay); |
| 568 |
|
| 569 |
FOR_INV_PREPARE(pl, pouch) { |
| 570 |
if (to_pay <= 0) |
| 571 |
break; |
| 572 |
if (pouch->type == CONTAINER |
| 573 |
&& QUERY_FLAG(pouch, FLAG_APPLIED) |
| 574 |
&& (pouch->race == NULL || strstr(pouch->race, "gold"))) { |
| 575 |
to_pay = pay_from_container(pl, pouch, to_pay); |
| 576 |
} |
| 577 |
} FOR_INV_FINISH(); |
| 578 |
if (to_pay > 0) { |
| 579 |
LOG(llevError, "pay_for_item: Cannot remove enough money -- %"FMT64U" remains\n", to_pay); |
| 580 |
} |
| 581 |
if (settings.real_wiz == FALSE && QUERY_FLAG(pl, FLAG_WAS_WIZ)) |
| 582 |
SET_FLAG(op, FLAG_WAS_WIZ); |
| 583 |
fix_object(pl); |
| 584 |
return 1; |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
static int64_t remove_value(object *coin_objs[], int64_t remain) { |
| 599 |
int i; |
| 600 |
|
| 601 |
for (i = 0; i < NUM_COINS; i++) { |
| 602 |
int count; |
| 603 |
int64_t num_coins; |
| 604 |
|
| 605 |
if ((int64_t)coin_objs[i]->nrof * coin_objs[i]->value > remain) { |
| 606 |
num_coins = remain/coin_objs[i]->value; |
| 607 |
if ((uint64_t)num_coins*(uint64_t)coin_objs[i]->value < (uint64_t) remain) { |
| 608 |
num_coins++; |
| 609 |
} |
| 610 |
} else { |
| 611 |
num_coins = coin_objs[i]->nrof; |
| 612 |
} |
| 613 |
remain -= (int64_t)num_coins*(int64_t)coin_objs[i]->value; |
| 614 |
coin_objs[i]->nrof -= num_coins; |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
count = i-1; |
| 620 |
while (remain < 0 && count >= 0) { |
| 621 |
num_coins = -remain/coin_objs[count]->value; |
| 622 |
coin_objs[count]->nrof += num_coins; |
| 623 |
remain += num_coins*coin_objs[count]->value; |
| 624 |
count--; |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
return remain; |
| 629 |
} |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
static void add_value(object *coin_objs[], int64_t value) { |
| 640 |
int i; |
| 641 |
|
| 642 |
for (i = NUM_COINS-LARGEST_COIN_GIVEN-1; i >= 0; i--) { |
| 643 |
uint32_t nrof; |
| 644 |
|
| 645 |
nrof = (uint32_t)(value/coin_objs[i]->value); |
| 646 |
value -= nrof*coin_objs[i]->value; |
| 647 |
coin_objs[i]->nrof += nrof; |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
static void insert_objects(object *pl, object *container, object *objects[], int objects_len) { |
| 664 |
int i, one = 0; |
| 665 |
|
| 666 |
for (i = 0; i < objects_len; i++) { |
| 667 |
if (objects[i]->nrof > 0) { |
| 668 |
object_insert_in_ob(objects[i], container); |
| 669 |
one = 1; |
| 670 |
} else { |
| 671 |
object_free_drop_inventory(objects[i]); |
| 672 |
} |
| 673 |
} |
| 674 |
if (one) |
| 675 |
esrv_update_item(UPD_WEIGHT, pl, container); |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
static uint64_t pay_from_container(object *pl, object *pouch, uint64_t to_pay) { |
| 692 |
size_t i; |
| 693 |
int64_t remain; |
| 694 |
object *coin_objs[NUM_COINS]; |
| 695 |
object *other_money[16]; |
| 696 |
size_t other_money_len; |
| 697 |
archetype *at; |
| 698 |
|
| 699 |
if (pouch->type != PLAYER && pouch->type != CONTAINER) |
| 700 |
return to_pay; |
| 701 |
|
| 702 |
remain = to_pay; |
| 703 |
for (i = 0; i < NUM_COINS; i++) |
| 704 |
coin_objs[i] = NULL; |
| 705 |
|
| 706 |
|
| 707 |
other_money_len = 0; |
| 708 |
FOR_INV_PREPARE(pouch, tmp) { |
| 709 |
if (tmp->type == MONEY) { |
| 710 |
for (i = 0; i < NUM_COINS; i++) { |
| 711 |
if (!strcmp(coins[NUM_COINS-1-i], tmp->arch->name) |
| 712 |
&& (tmp->value == tmp->arch->clone.value)) { |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
if (coin_objs[i] != NULL) { |
| 717 |
LOG(llevError, "%s has two money entries of (%s)\n", pouch->name, coins[NUM_COINS-1-i]); |
| 718 |
object_remove(tmp); |
| 719 |
coin_objs[i]->nrof += tmp->nrof; |
| 720 |
object_free_drop_inventory(tmp); |
| 721 |
} else { |
| 722 |
object_remove(tmp); |
| 723 |
coin_objs[i] = tmp; |
| 724 |
} |
| 725 |
break; |
| 726 |
} |
| 727 |
} |
| 728 |
if (i == NUM_COINS) { |
| 729 |
if (other_money_len >= sizeof(other_money)/sizeof(*other_money)) { |
| 730 |
LOG(llevError, "pay_for_item: Cannot store non-standard money object %s\n", tmp->arch->name); |
| 731 |
} else { |
| 732 |
object_remove(tmp); |
| 733 |
other_money[other_money_len++] = tmp; |
| 734 |
} |
| 735 |
} |
| 736 |
} |
| 737 |
} FOR_INV_FINISH(); |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
for (i = 0; i < NUM_COINS; i++) |
| 742 |
if (coin_objs[i] == NULL) { |
| 743 |
at = find_archetype(coins[NUM_COINS-1-i]); |
| 744 |
if (at == NULL) { |
| 745 |
continue; |
| 746 |
} |
| 747 |
coin_objs[i] = object_new(); |
| 748 |
object_copy(&at->clone, coin_objs[i]); |
| 749 |
coin_objs[i]->nrof = 0; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
remain = remove_value(coin_objs, remain); |
| 754 |
|
| 755 |
|
| 756 |
for (i = 0; i < other_money_len && remain > 0; i++) { |
| 757 |
uint32_t nrof; |
| 758 |
object *coin; |
| 759 |
|
| 760 |
coin = other_money[i]; |
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
nrof = (remain+coin->value-1)/coin->value; |
| 766 |
if (nrof > coin->nrof) { |
| 767 |
nrof = coin->nrof; |
| 768 |
} |
| 769 |
coin->nrof -= nrof; |
| 770 |
add_value(coin_objs, nrof*coin->value); |
| 771 |
|
| 772 |
remain = remove_value(coin_objs, remain); |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
insert_objects(pl, pouch, coin_objs, NUM_COINS); |
| 777 |
insert_objects(pl, pouch, other_money, other_money_len); |
| 778 |
|
| 779 |
return(remain); |
| 780 |
} |
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
static void count_unpaid(object *pl, object *item, int *unpaid_count, uint64_t *unpaid_price, uint32_t *coincount) { |
| 797 |
int i; |
| 798 |
|
| 799 |
FOR_OB_AND_BELOW_PREPARE(item) { |
| 800 |
if (QUERY_FLAG(item, FLAG_UNPAID)) { |
| 801 |
(*unpaid_count)++; |
| 802 |
(*unpaid_price) += shop_price_buy(item, pl); |
| 803 |
} |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
for (i = 0; i < NUM_COINS; i++) |
| 809 |
if (!strcmp(coins[i], item->arch->name)) { |
| 810 |
coincount[i] += item->nrof; |
| 811 |
break; |
| 812 |
} |
| 813 |
if (item->inv) |
| 814 |
count_unpaid(pl, item->inv, unpaid_count, unpaid_price, coincount); |
| 815 |
} FOR_OB_AND_BELOW_FINISH(); |
| 816 |
} |
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
int can_pay(object *pl) { |
| 831 |
int unpaid_count = 0, i; |
| 832 |
uint64_t unpaid_price = 0; |
| 833 |
uint64_t player_wealth = query_money(pl); |
| 834 |
uint32_t coincount[NUM_COINS]; |
| 835 |
|
| 836 |
if (!pl || pl->type != PLAYER) { |
| 837 |
LOG(llevError, "can_pay(): called against something that isn't a player\n"); |
| 838 |
return 0; |
| 839 |
} |
| 840 |
|
| 841 |
for (i = 0; i < NUM_COINS; i++) |
| 842 |
coincount[i] = 0; |
| 843 |
|
| 844 |
count_unpaid(pl, pl->inv, &unpaid_count, &unpaid_price, coincount); |
| 845 |
|
| 846 |
if (unpaid_price > player_wealth) { |
| 847 |
char buf[MAX_BUF], coinbuf[MAX_BUF]; |
| 848 |
int denominations = 0; |
| 849 |
char *value = cost_str(unpaid_price); |
| 850 |
|
| 851 |
snprintf(buf, sizeof(buf), "You have %d unpaid items that would cost you %s, ", unpaid_count, value); |
| 852 |
free(value); |
| 853 |
for (i = 0; i < NUM_COINS; i++) { |
| 854 |
if (coincount[i] > 0 && coins[i]) { |
| 855 |
if (denominations == 0) |
| 856 |
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "but you only have"); |
| 857 |
denominations++; |
| 858 |
archetype *arch = find_archetype(coins[i]); |
| 859 |
if (arch != NULL) |
| 860 |
{ |
| 861 |
snprintf(coinbuf, sizeof(coinbuf), " %u %s,", coincount[i], arch->clone.name_pl); |
| 862 |
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "%s", coinbuf); |
| 863 |
} |
| 864 |
} |
| 865 |
} |
| 866 |
if (denominations == 0) |
| 867 |
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf), "but you don't have any money."); |
| 868 |
else if (denominations > 1) |
| 869 |
make_list_like(buf); |
| 870 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SHOP, |
| 871 |
MSG_TYPE_SHOP_PAYMENT, buf); |
| 872 |
return 0; |
| 873 |
} else |
| 874 |
return 1; |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
int shop_pay_unpaid(object *pl, object *op) { |
| 884 |
char name_op[MAX_BUF]; |
| 885 |
int ret = 1; |
| 886 |
|
| 887 |
if (op != NULL && op->inv) |
| 888 |
ret = shop_pay_unpaid(pl, op->inv); |
| 889 |
|
| 890 |
if (!ret) |
| 891 |
return 0; |
| 892 |
|
| 893 |
if (op != NULL && op->below) |
| 894 |
ret = shop_pay_unpaid(pl, op->below); |
| 895 |
|
| 896 |
if (!ret) |
| 897 |
return 0; |
| 898 |
|
| 899 |
if (op != NULL && QUERY_FLAG(op, FLAG_UNPAID)) { |
| 900 |
uint64_t price = shop_price_buy(op, pl); |
| 901 |
if (!pay_for_item(op, pl)) { |
| 902 |
uint64_t i = price - query_money(pl); |
| 903 |
char *missing = cost_str(i); |
| 904 |
|
| 905 |
CLEAR_FLAG(op, FLAG_UNPAID); |
| 906 |
query_name(op, name_op, MAX_BUF); |
| 907 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, |
| 908 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_PAYMENT, |
| 909 |
"You lack %s to buy %s.", |
| 910 |
missing, name_op); |
| 911 |
free(missing); |
| 912 |
SET_FLAG(op, FLAG_UNPAID); |
| 913 |
return 0; |
| 914 |
} else { |
| 915 |
|
| 916 |
|
| 917 |
if (execute_event(op, EVENT_BOUGHT, pl, NULL, NULL, SCRIPT_FIX_ALL) != 0) |
| 918 |
return 0; |
| 919 |
object *tmp; |
| 920 |
char *value = cost_str(price); |
| 921 |
|
| 922 |
CLEAR_FLAG(op, FLAG_UNPAID); |
| 923 |
CLEAR_FLAG(op, FLAG_PLAYER_SOLD); |
| 924 |
query_name(op, name_op, MAX_BUF); |
| 925 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, |
| 926 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_PAYMENT, |
| 927 |
"You paid %s for %s.", |
| 928 |
value, name_op); |
| 929 |
free(value); |
| 930 |
tmp = object_merge(op, NULL); |
| 931 |
if (pl->type == PLAYER && !tmp) { |
| 932 |
|
| 933 |
esrv_update_item(UPD_FLAGS|UPD_NAME, pl, op); |
| 934 |
} |
| 935 |
} |
| 936 |
} |
| 937 |
return 1; |
| 938 |
} |
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
void sell_item(object *op, object *pl) { |
| 952 |
object *tmp; |
| 953 |
archetype *at; |
| 954 |
char obj_name[MAX_BUF]; |
| 955 |
|
| 956 |
query_name(op, obj_name, MAX_BUF); |
| 957 |
|
| 958 |
if (pl == NULL || pl->type != PLAYER) { |
| 959 |
LOG(llevDebug, "Object other than player tried to sell something.\n"); |
| 960 |
return; |
| 961 |
} |
| 962 |
|
| 963 |
if (execute_event(op, EVENT_SELLING, pl, NULL, NULL, SCRIPT_FIX_ALL) != 0) |
| 964 |
return; |
| 965 |
|
| 966 |
if (op->custom_name) |
| 967 |
FREE_AND_CLEAR_STR(op->custom_name); |
| 968 |
|
| 969 |
uint64_t price = shop_price_sell(op, pl); |
| 970 |
if (price == 0) { |
| 971 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, |
| 972 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_SELL, |
| 973 |
"We're not interested in %s.", |
| 974 |
obj_name); |
| 975 |
return; |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
int64_t extra_gain = price - price_base(op); |
| 984 |
if (extra_gain > 0) { |
| 985 |
change_exp(pl, extra_gain/10, "bargaining", SK_EXP_NONE); |
| 986 |
} |
| 987 |
|
| 988 |
char *value_str = cost_str(price); |
| 989 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SHOP, MSG_TYPE_SHOP_SELL, |
| 990 |
"You receive %s for %s.", value_str, obj_name); |
| 991 |
free(value_str); |
| 992 |
|
| 993 |
for (int count = LARGEST_COIN_GIVEN; coins[count] != NULL; count++) { |
| 994 |
at = find_archetype(coins[count]); |
| 995 |
if (at == NULL) |
| 996 |
LOG(llevError, "Could not find %s archetype\n", coins[count]); |
| 997 |
else if ((price/at->clone.value) > 0) { |
| 998 |
FOR_INV_PREPARE(pl, pouch) { |
| 999 |
if (pouch->type == CONTAINER |
| 1000 |
&& QUERY_FLAG(pouch, FLAG_APPLIED) |
| 1001 |
&& pouch->race |
| 1002 |
&& strstr(pouch->race, "gold")) { |
| 1003 |
int w = at->clone.weight*(100-pouch->stats.Str)/100; |
| 1004 |
int n = price/at->clone.value; |
| 1005 |
|
| 1006 |
if (w == 0) |
| 1007 |
w = 1; |
| 1008 |
if (n > 0 |
| 1009 |
&& (!pouch->weight_limit || pouch->carrying+w <= pouch->weight_limit)) { |
| 1010 |
if (pouch->weight_limit |
| 1011 |
&& (pouch->weight_limit-pouch->carrying)/w < n) |
| 1012 |
n = (pouch->weight_limit-pouch->carrying)/w; |
| 1013 |
|
| 1014 |
tmp = object_new(); |
| 1015 |
object_copy(&at->clone, tmp); |
| 1016 |
tmp->nrof = n; |
| 1017 |
price -= (uint64_t)tmp->nrof*(uint64_t)tmp->value; |
| 1018 |
tmp = object_insert_in_ob(tmp, pouch); |
| 1019 |
esrv_update_item(UPD_WEIGHT, pl, pl); |
| 1020 |
} |
| 1021 |
} |
| 1022 |
} FOR_INV_FINISH(); |
| 1023 |
if (price/at->clone.value > 0) { |
| 1024 |
tmp = object_new(); |
| 1025 |
object_copy(&at->clone, tmp); |
| 1026 |
tmp->nrof = price/tmp->value; |
| 1027 |
price -= (uint64_t)tmp->nrof*(uint64_t)tmp->value; |
| 1028 |
tmp = object_insert_in_ob(tmp, pl); |
| 1029 |
esrv_update_item(UPD_WEIGHT, pl, pl); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
if (price != 0) { |
| 1035 |
LOG(llevError, "Warning - payment not zero: %" PRIo64 "\n", price); |
| 1036 |
} |
| 1037 |
|
| 1038 |
SET_FLAG(op, FLAG_UNPAID); |
| 1039 |
identify(op); |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
static double shop_specialisation_ratio(const object *item, const mapstruct *map) { |
| 1056 |
shopitems *items = map->shopitems; |
| 1057 |
double ratio = SPECIALISATION_EFFECT, likedness = 0.001; |
| 1058 |
int i; |
| 1059 |
|
| 1060 |
if (item == NULL) { |
| 1061 |
LOG(llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", map->path); |
| 1062 |
return 0; |
| 1063 |
} |
| 1064 |
if (item->type == (uint8_t)-1) { |
| 1065 |
LOG(llevError, "shop_specialisation_ratio: passed an item with an invalid type\n"); |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
return ratio; |
| 1072 |
} |
| 1073 |
if (map->shopitems) { |
| 1074 |
for (i = 0; i < items[0].index; i++) |
| 1075 |
if (items[i].typenum == item->type || (items[i].typenum == -1 && likedness == 0.001)) |
| 1076 |
likedness = items[i].strength/100.0; |
| 1077 |
} |
| 1078 |
if (likedness > 1.0) { |
| 1079 |
LOG(llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, map->path); |
| 1080 |
likedness = 1.0; |
| 1081 |
} |
| 1082 |
if (likedness < -1.0) { |
| 1083 |
LOG(llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, map->path); |
| 1084 |
likedness = -1.0; |
| 1085 |
} |
| 1086 |
ratio = ratio+(1.0-ratio)*likedness; |
| 1087 |
if (ratio <= 0.1) |
| 1088 |
ratio = 0.1; |
| 1089 |
return ratio; |
| 1090 |
} |
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
static double shop_greed(const mapstruct *map) { |
| 1101 |
double greed = 1.0; |
| 1102 |
|
| 1103 |
if (map->shopgreed) |
| 1104 |
return map->shopgreed; |
| 1105 |
return greed; |
| 1106 |
} |
| 1107 |
|
| 1108 |
double shop_approval(const mapstruct *map, const object *player) { |
| 1109 |
double approval = 1.0; |
| 1110 |
|
| 1111 |
if (map->shoprace) { |
| 1112 |
approval = NEUTRAL_RATIO; |
| 1113 |
if (player->race && !strcmp(player->race, map->shoprace)) |
| 1114 |
approval = 1.0; |
| 1115 |
} |
| 1116 |
return approval; |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
static uint64_t value_limit(uint64_t val, int quantity, const object *who, int isshop) { |
| 1139 |
uint64_t newval, unit_price; |
| 1140 |
mapstruct *map; |
| 1141 |
|
| 1142 |
unit_price = val/quantity; |
| 1143 |
if (!isshop || !who) { |
| 1144 |
if (unit_price > 10000) |
| 1145 |
newval = 8000+isqrt(unit_price)*20; |
| 1146 |
else |
| 1147 |
newval = unit_price; |
| 1148 |
} else { |
| 1149 |
if (!who->map) { |
| 1150 |
LOG(llevError, "value_limit: asked shop price for ob %s on NULL map\n", who->name); |
| 1151 |
return val; |
| 1152 |
} |
| 1153 |
map = who->map; |
| 1154 |
if (map->shopmin && unit_price < map->shopmin) |
| 1155 |
return 0; |
| 1156 |
else if (map->shopmax && unit_price > map->shopmax/2) |
| 1157 |
newval = MIN((map->shopmax/2)+isqrt(unit_price-map->shopmax/2), map->shopmax); |
| 1158 |
else if (unit_price > 10000) |
| 1159 |
newval = 8000+isqrt(unit_price)*20; |
| 1160 |
else |
| 1161 |
newval = unit_price; |
| 1162 |
} |
| 1163 |
newval *= quantity; |
| 1164 |
return newval; |
| 1165 |
} |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
int shop_describe(const object *op) { |
| 1173 |
mapstruct *map = op->map; |
| 1174 |
|
| 1175 |
int pos = 0, i; |
| 1176 |
double opinion = 0; |
| 1177 |
char tmp[MAX_BUF] = "\0", *value; |
| 1178 |
|
| 1179 |
if (op->type != PLAYER) |
| 1180 |
return 0; |
| 1181 |
|
| 1182 |
|
| 1183 |
if (map->shopitems |
| 1184 |
|| map->shopgreed |
| 1185 |
|| map->shoprace |
| 1186 |
|| map->shopmin |
| 1187 |
|| map->shopmax) { |
| 1188 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SHOP, MSG_TYPE_SHOP_LISTING, |
| 1189 |
"From looking at the nearby shop you determine that it trades in:"); |
| 1190 |
|
| 1191 |
if (map->shopitems) { |
| 1192 |
for (i = 0; i < map->shopitems[0].index; i++) { |
| 1193 |
if (map->shopitems[i].name && map->shopitems[i].strength > 10) { |
| 1194 |
snprintf(tmp+pos, sizeof(tmp)-pos, "%s, ", map->shopitems[i].name_pl); |
| 1195 |
pos += strlen(tmp+pos); |
| 1196 |
} |
| 1197 |
} |
| 1198 |
} |
| 1199 |
if (!pos) |
| 1200 |
strcpy(tmp, "a little of everything."); |
| 1201 |
|
| 1202 |
|
| 1203 |
make_list_like(tmp); |
| 1204 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1205 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_LISTING, tmp); |
| 1206 |
|
| 1207 |
if (map->shopmax) { |
| 1208 |
value = cost_str(map->shopmax); |
| 1209 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1210 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1211 |
"It won't trade for items above %s.", |
| 1212 |
value); |
| 1213 |
free(value); |
| 1214 |
} |
| 1215 |
|
| 1216 |
if (map->shopmin) { |
| 1217 |
value = cost_str(map->shopmin); |
| 1218 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1219 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1220 |
"It won't trade in items worth less than %s.", |
| 1221 |
value); |
| 1222 |
free(value); |
| 1223 |
} |
| 1224 |
|
| 1225 |
if (map->shopgreed) { |
| 1226 |
if (map->shopgreed > 2.0) |
| 1227 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1228 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1229 |
"It tends to overcharge massively."); |
| 1230 |
else if (map->shopgreed > 1.5) |
| 1231 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1232 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1233 |
"It tends to overcharge substantially."); |
| 1234 |
else if (map->shopgreed > 1.1) |
| 1235 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1236 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1237 |
"It tends to overcharge slightly."); |
| 1238 |
else if (map->shopgreed < 0.9) |
| 1239 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1240 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1241 |
"It tends to undercharge."); |
| 1242 |
} |
| 1243 |
if (map->shoprace) { |
| 1244 |
opinion = shop_approval(map, op); |
| 1245 |
if (opinion > 0.8) |
| 1246 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1247 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1248 |
"You think the shopkeeper likes you."); |
| 1249 |
else if (opinion > 0.5) |
| 1250 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1251 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1252 |
"The shopkeeper seems unconcerned by you."); |
| 1253 |
else |
| 1254 |
draw_ext_info(NDI_UNIQUE, 0, op, |
| 1255 |
MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1256 |
"The shopkeeper seems to have taken a dislike to you."); |
| 1257 |
} |
| 1258 |
} else draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SHOP, MSG_TYPE_SHOP_MISC, |
| 1259 |
"There is no shop nearby."); |
| 1260 |
|
| 1261 |
return 1; |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
static bool coords_in_shop(mapstruct *map, int x, int y) { |
| 1268 |
FOR_MAP_PREPARE(map, x, y, floor) |
| 1269 |
if (floor->type == SHOP_FLOOR) return true; |
| 1270 |
FOR_MAP_FINISH(); |
| 1271 |
return false; |
| 1272 |
} |
| 1273 |
|
| 1274 |
bool shop_contains(object *ob) { |
| 1275 |
if (!ob->map) return 0; |
| 1276 |
return coords_in_shop(ob->map, ob->x, ob->y); |
| 1277 |
} |