… | |
… | |
324 | * 10,000 silver or something) |
324 | * 10,000 silver or something) |
325 | */ |
325 | */ |
326 | const char * |
326 | const char * |
327 | cost_string_from_value (sint64 cost, int approx) |
327 | cost_string_from_value (sint64 cost, int approx) |
328 | { |
328 | { |
329 | static char buf[MAX_BUF]; |
|
|
330 | archetype *coin, *next_coin; |
329 | archetype *coin, *next_coin; |
331 | int num, cointype = 0; |
330 | int num, cointype = 0; |
332 | |
331 | |
333 | coin = find_next_coin (cost, &cointype); |
332 | coin = find_next_coin (cost, &cointype); |
334 | if (coin == NULL) |
333 | if (!coin) |
335 | return "nothing"; |
334 | return "nothing"; |
336 | |
335 | |
337 | num = cost / coin->value; |
336 | num = cost / coin->value; |
338 | /* so long as nrof is 32 bit, this is true. |
337 | /* so long as nrof is 32 bit, this is true. |
339 | * If it takes more coins than a person can possibly carry, this |
338 | * If it takes more coins than a person can possibly carry, this |
340 | * is basically true. |
339 | * is basically true. |
341 | */ |
340 | */ |
342 | if ((cost / coin->value) > UINT32_MAX) |
341 | if (cost / coin->value > UINT32_MAX) |
343 | { |
|
|
344 | strcpy (buf, "an unimaginable sum of money"); |
342 | return "an unimaginable sum of money"; |
345 | return buf; |
|
|
346 | } |
|
|
347 | |
343 | |
348 | cost -= num * (sint64)coin->value; |
344 | cost -= num * (sint64)coin->value; |
349 | |
345 | |
350 | sprintf (buf, "%d %s", num, num > 1 ? &coin->object::name_pl : &coin->object::name); |
346 | char *buf = format ("%d %s", num, num > 1 ? &coin->object::name_pl : &coin->object::name); |
351 | |
347 | |
352 | next_coin = find_next_coin (cost, &cointype); |
348 | next_coin = find_next_coin (cost, &cointype); |
353 | if (next_coin == NULL || approx) |
349 | if (!next_coin || approx) |
354 | return buf; |
350 | return buf; |
355 | |
351 | |
356 | coin = next_coin; |
352 | coin = next_coin; |
357 | num = cost / coin->value; |
353 | num = cost / coin->value; |
358 | cost -= num * (sint64)coin->value; |
354 | cost -= num * (sint64)coin->value; |
359 | |
355 | |
360 | sprintf (buf + strlen (buf), " and %d %s", num, num > 1 ? &coin->object::name_pl : &coin->object::name); |
356 | return format ("%s and %d %s", buf, num, num > 1 ? &coin->object::name_pl : &coin->object::name); |
361 | |
|
|
362 | return buf; |
|
|
363 | } |
357 | } |
364 | |
358 | |
365 | const char * |
359 | const char * |
366 | query_cost_string (const object *tmp, object *who, int flag) |
360 | query_cost_string (const object *tmp, object *who, int flag) |
367 | { |
361 | { |
… | |
… | |
388 | { |
382 | { |
389 | if (!idskill2 || !find_skill_by_number (who, idskill2)) |
383 | if (!idskill2 || !find_skill_by_number (who, idskill2)) |
390 | { |
384 | { |
391 | if (!find_skill_by_number (who, SK_BARGAINING)) |
385 | if (!find_skill_by_number (who, SK_BARGAINING)) |
392 | { |
386 | { |
393 | static char buf[MAX_BUF]; |
|
|
394 | int num, cointype = 0; |
387 | int num, cointype = 0; |
395 | archetype *coin = find_next_coin (real_value, &cointype); |
388 | archetype *coin = find_next_coin (real_value, &cointype); |
396 | |
389 | |
397 | if (coin == NULL) |
390 | if (!coin) |
398 | return "nothing"; |
391 | return "nothing"; |
399 | |
392 | |
400 | num = real_value / coin->value; |
393 | num = real_value / coin->value; |
401 | |
394 | |
402 | if (num == 1) |
395 | if (num == 1) |
403 | sprintf (buf, "about one %s", &coin->object::name); |
396 | return format ("about one %s", &coin->object::name); |
404 | else if (num < 5) |
397 | else if (num < 5) |
405 | sprintf (buf, "a few %s", &coin->object::name_pl); |
398 | return format ("a few %s", &coin->object::name_pl); |
406 | else if (num < 10) |
399 | else if (num < 10) |
407 | sprintf (buf, "several %s", &coin->object::name_pl); |
400 | return format ("several %s", &coin->object::name_pl); |
408 | else if (num < 25) |
401 | else if (num < 25) |
409 | sprintf (buf, "a moderate amount of %s", &coin->object::name_pl); |
402 | return format ("a moderate amount of %s", &coin->object::name_pl); |
410 | else if (num < 100) |
403 | else if (num < 100) |
411 | sprintf (buf, "lots of %s", &coin->object::name_pl); |
404 | return format ("lots of %s", &coin->object::name_pl); |
412 | else if (num < 1000) |
405 | else if (num < 1000) |
413 | sprintf (buf, "a great many %s", &coin->object::name_pl); |
406 | return format ("a great many %s", &coin->object::name_pl); |
414 | else |
407 | else |
415 | sprintf (buf, "a vast quantity of %s", &coin->object::name_pl); |
408 | return format ("a vast quantity of %s", &coin->object::name_pl); |
416 | |
|
|
417 | return buf; |
|
|
418 | } |
409 | } |
419 | } |
410 | } |
420 | } |
411 | } |
421 | |
412 | |
422 | int hash = ((unsigned int) tmp->count * 174364621) & 1023; |
|
|
423 | |
|
|
424 | if (approx_range) |
413 | if (approx_range) |
425 | { |
414 | { |
|
|
415 | int hash = tmp->random_seed () & 1023; |
426 | sint64 lo = (sint64) real_value - (approx_range * hash >> 10); |
416 | sint64 lo = real_value - (approx_range * hash >> 10); |
427 | static char buf[MAX_BUF]; |
|
|
428 | |
417 | |
429 | sprintf (buf, "between %s", cost_string_from_value (lo, 1)); |
418 | return format ("between %s and %s", |
430 | sprintf (buf + strlen (buf), " and %s", cost_string_from_value (lo + approx_range, 1)); |
419 | cost_string_from_value (lo, 1), |
431 | |
420 | cost_string_from_value (lo + approx_range, 1)); |
432 | return buf; |
|
|
433 | } |
421 | } |
434 | } |
422 | } |
435 | |
423 | |
436 | return cost_string_from_value (real_value, 0); |
424 | return cost_string_from_value (real_value, 0); |
437 | } |
425 | } |
… | |
… | |
684 | |
672 | |
685 | for (object::depth_iterator op = pl->begin (); op != pl->end (); ++op) |
673 | for (object::depth_iterator op = pl->begin (); op != pl->end (); ++op) |
686 | { |
674 | { |
687 | if (op->flag [FLAG_UNPAID]) |
675 | if (op->flag [FLAG_UNPAID]) |
688 | { |
676 | { |
689 | char buf[MAX_BUF]; |
|
|
690 | snprintf (buf, MAX_BUF, "%s", query_cost_string (op, pl, F_BUY | F_SHOP)); |
677 | const char *buf = query_cost_string (op, pl, F_BUY | F_SHOP); |
691 | |
678 | |
692 | if (!pay_for_item (op, pl)) |
679 | if (!pay_for_item (op, pl)) |
693 | { |
680 | { |
694 | sint64 i = query_cost (op, pl, F_BUY | F_SHOP) - query_money (pl); |
681 | sint64 i = query_cost (op, pl, F_BUY | F_SHOP) - query_money (pl); |
695 | |
682 | |
… | |
… | |
700 | } |
687 | } |
701 | else |
688 | else |
702 | { |
689 | { |
703 | op->clr_flag (FLAG_UNPAID); |
690 | op->clr_flag (FLAG_UNPAID); |
704 | op->clr_flag (FLAG_PLAYER_SOLD); |
691 | op->clr_flag (FLAG_PLAYER_SOLD); |
705 | new_draw_info_format (NDI_UNIQUE, 0, op, "You paid %s for %s.", buf, query_name (op)); |
692 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You paid %s for %s.", buf, query_name (op)); |
706 | |
693 | |
707 | if (!merge_ob (op, op->env->inv)) |
694 | if (!merge_ob (op, op->env->inv)) |
708 | esrv_update_item (UPD_FLAGS, pl, op); |
695 | esrv_update_item (UPD_FLAGS, pl, op); |
709 | |
696 | |
710 | goto next_item; |
697 | goto next_item; |
… | |
… | |
1073 | } |
1060 | } |
1074 | |
1061 | |
1075 | static void |
1062 | static void |
1076 | add_shop_item (object *tmp, shopinv * items, int *numitems, int *numallocated) |
1063 | add_shop_item (object *tmp, shopinv * items, int *numitems, int *numallocated) |
1077 | { |
1064 | { |
1078 | #if 0 |
|
|
1079 | char buf[MAX_BUF]; |
|
|
1080 | #endif |
|
|
1081 | /* clear unpaid flag so that doesn't come up in query |
1065 | /* clear unpaid flag so that doesn't come up in query |
1082 | * string. We clear nrof so that we can better sort |
1066 | * string. We clear nrof so that we can better sort |
1083 | * the object names. |
1067 | * the object names. |
1084 | */ |
1068 | */ |
1085 | |
1069 | |