… | |
… | |
126 | { |
126 | { |
127 | if (tmp->arch != NULL) |
127 | if (tmp->arch != NULL) |
128 | { |
128 | { |
129 | if (flag == F_BUY) |
129 | if (flag == F_BUY) |
130 | { |
130 | { |
131 | LOG (llevError, "Asking for buy-value of unidentified object.\n"); |
131 | LOG (llevError | logBacktrace, "Asking for buy-value of unidentified object.\n"); |
132 | val = tmp->arch->value * 50 * number; |
132 | val = tmp->arch->value * 50 * number; |
133 | } |
133 | } |
134 | else |
134 | else |
135 | { /* Trying to sell something, or get true value */ |
135 | { /* Trying to sell something, or get true value */ |
136 | if (tmp->type == POTION) |
136 | if (tmp->type == POTION) |
… | |
… | |
150 | else |
150 | else |
151 | { /* No archetype with this object */ |
151 | { /* No archetype with this object */ |
152 | LOG (llevDebug, "In sell item: Have object with no archetype: %s\n", &tmp->name); |
152 | LOG (llevDebug, "In sell item: Have object with no archetype: %s\n", &tmp->name); |
153 | if (flag == F_BUY) |
153 | if (flag == F_BUY) |
154 | { |
154 | { |
155 | LOG (llevError, "Asking for buy-value of unidentified object without arch.\n"); |
155 | LOG (llevError | logBacktrace, "Asking for buy-value of unidentified object without arch.\n"); |
156 | val = number * tmp->value * 10; |
156 | val = number * tmp->value * 10; |
157 | } |
157 | } |
158 | else |
158 | else |
159 | val = number * tmp->value / 5; |
159 | val = number * tmp->value / 5; |
160 | } |
160 | } |
… | |
… | |
577 | // This should not happen, but if it does, just merge the two. |
577 | // This should not happen, but if it does, just merge the two. |
578 | if (coin_objs [i]) |
578 | if (coin_objs [i]) |
579 | { |
579 | { |
580 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
580 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
581 | coin_objs[i]->nrof += tmp->nrof; |
581 | coin_objs[i]->nrof += tmp->nrof; |
582 | tmp->destroy (); |
582 | tmp->destroy (true); |
583 | } |
583 | } |
584 | else |
584 | else |
585 | { |
585 | { |
586 | tmp->remove (); |
586 | tmp->remove (); |
587 | coin_objs[i] = tmp; |
587 | coin_objs[i] = tmp; |
… | |
… | |
631 | count--; |
631 | count--; |
632 | } |
632 | } |
633 | } |
633 | } |
634 | |
634 | |
635 | for (i = 0; i < NUM_COINS; i++) |
635 | for (i = 0; i < NUM_COINS; i++) |
636 | { |
|
|
637 | if (coin_objs[i]->nrof) |
636 | if (coin_objs[i]->nrof) |
638 | insert_ob_in_ob (coin_objs [i], pouch); |
637 | insert_ob_in_ob (coin_objs [i], pouch); |
639 | else |
638 | else |
640 | coin_objs[i]->destroy (); |
639 | coin_objs[i]->destroy (true); |
641 | } |
|
|
642 | } |
640 | } |
643 | |
641 | |
644 | /* Checks all unpaid items in op's inventory, adds up all the money they |
642 | /* Checks all unpaid items in op's inventory, adds up all the money they |
645 | * have, and checks that they can actually afford what they want to buy. |
643 | * have, and checks that they can actually afford what they want to buy. |
646 | * Returns 1 if they can, and 0 if they can't. also prints an appropriate message |
644 | * Returns 1 if they can, and 0 if they can't. also prints an appropriate message |
… | |
… | |
666 | unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); |
664 | unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); |
667 | } |
665 | } |
668 | |
666 | |
669 | if (unpaid_price > player_wealth) |
667 | if (unpaid_price > player_wealth) |
670 | { |
668 | { |
671 | char buf[MAX_BUF]; |
669 | dynbuf_text buf; |
672 | char cost[MAX_BUF]; |
|
|
673 | char missing[MAX_BUF]; |
|
|
674 | |
670 | |
675 | snprintf (cost, MAX_BUF, "%s", cost_string_from_value (unpaid_price, 0)); |
671 | buf << "You have " << unpaid_count |
676 | snprintf (missing, MAX_BUF, "%s", cost_string_from_value (unpaid_price - player_wealth, 0)); |
672 | << " unpaid item(s) that would cost you " << cost_string_from_value (unpaid_price, 0) |
|
|
673 | << ". You need another " << cost_string_from_value (unpaid_price - player_wealth, 0) |
|
|
674 | << " to be able to afford that."; |
677 | |
675 | |
678 | snprintf (buf, MAX_BUF, "You have %d unpaid items that would cost you %s. You need another %s to be able to afford that.", |
676 | pl->failmsg (buf); |
679 | unpaid_count, cost, missing); |
|
|
680 | new_draw_info (NDI_UNIQUE, 0, pl, buf); |
|
|
681 | |
677 | |
682 | return 0; |
678 | return 0; |
683 | } |
679 | } |
684 | else |
680 | else |
685 | return 1; |
681 | return 1; |
… | |
… | |
797 | |
793 | |
798 | /* elmex: this is for the bank plugin :( */ |
794 | /* elmex: this is for the bank plugin :( */ |
799 | sint64 |
795 | sint64 |
800 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
796 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
801 | { |
797 | { |
802 | archetype *at = archetype::find (arch); |
|
|
803 | |
|
|
804 | if (!at) |
|
|
805 | return 0; |
|
|
806 | |
|
|
807 | if (amount > 0) |
798 | if (amount) |
808 | { |
799 | { |
809 | object *tmp = arch_to_object (at); |
800 | object *ob = archetype::get (arch); |
|
|
801 | |
|
|
802 | if (!ob) |
|
|
803 | return 0; |
|
|
804 | |
810 | tmp->nrof = amount; |
805 | ob->nrof = amount; |
811 | insert_ob_in_ob (tmp, pl); |
806 | pl->insert (ob); |
812 | } |
807 | } |
813 | |
808 | |
814 | return 1; |
809 | return 1; |
815 | } |
810 | } |
816 | |
811 | |
… | |
… | |
1068 | { |
1063 | { |
1069 | shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; |
1064 | shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; |
1070 | |
1065 | |
1071 | if (s1->type < s2->type) |
1066 | if (s1->type < s2->type) |
1072 | return -1; |
1067 | return -1; |
|
|
1068 | |
1073 | if (s1->type > s2->type) |
1069 | if (s1->type > s2->type) |
1074 | return 1; |
1070 | return 1; |
1075 | |
1071 | |
1076 | /* the type is the same (what atoi gets), so do a strcasecmp to sort |
1072 | /* the type is the same (what atoi gets), so do a strcasecmp to sort |
1077 | * via alphabetical order |
1073 | * via alphabetical order |
… | |
… | |
1127 | |
1123 | |
1128 | void |
1124 | void |
1129 | shop_listing (object *sign, object *op) |
1125 | shop_listing (object *sign, object *op) |
1130 | { |
1126 | { |
1131 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1127 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1132 | const char *shop_coords = get_ob_key_value (sign, "shop_coords"); |
1128 | const char *shop_coords = sign->kv (shstr_shop_coords); |
1133 | object *stack; |
1129 | object *stack; |
1134 | shopinv *items; |
1130 | shopinv *items; |
1135 | |
1131 | |
1136 | /* Should never happen, but just in case a monster does apply a sign */ |
1132 | /* Should never happen, but just in case a monster does apply a sign */ |
1137 | if (op->type != PLAYER) |
1133 | if (op->type != PLAYER) |
… | |
… | |
1210 | |
1206 | |
1211 | /* elmex: this function checks whether the object is in a shop */ |
1207 | /* elmex: this function checks whether the object is in a shop */ |
1212 | bool |
1208 | bool |
1213 | is_in_shop (object *o) |
1209 | is_in_shop (object *o) |
1214 | { |
1210 | { |
1215 | if (!o->map) |
1211 | if (!o->is_on_map ()) |
1216 | return false; |
1212 | return false; |
1217 | |
1213 | |
1218 | return is_in_shop (o->map, o->x, o->y); |
1214 | return is_in_shop (o->map, o->x, o->y); |
1219 | } |
1215 | } |
1220 | |
1216 | |
… | |
… | |
1228 | is_in_shop (maptile *map, int x, int y) |
1224 | is_in_shop (maptile *map, int x, int y) |
1229 | { |
1225 | { |
1230 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1226 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1231 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1227 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1232 | return floor->type == SHOP_FLOOR; |
1228 | return floor->type == SHOP_FLOOR; |
|
|
1229 | |
1233 | return false; |
1230 | return false; |
1234 | } |
1231 | } |
1235 | |
1232 | |