… | |
… | |
206 | * AND Cha = 30 will get optimal price. |
206 | * AND Cha = 30 will get optimal price. |
207 | * Thus charisma will never get useless. |
207 | * Thus charisma will never get useless. |
208 | * -b.e. edler@heydernet.de |
208 | * -b.e. edler@heydernet.de |
209 | */ |
209 | */ |
210 | |
210 | |
211 | if (who != NULL && who->type == PLAYER) |
211 | if (who && who->type == PLAYER) |
212 | { |
212 | { |
213 | int lev_bargain = 0; |
213 | int lev_bargain = 0; |
214 | int lev_identify = 0; |
214 | int lev_identify = 0; |
215 | int idskill1 = 0; |
|
|
216 | int idskill2 = 0; |
|
|
217 | const typedata *tmptype; |
|
|
218 | |
|
|
219 | tmptype = get_typedata (tmp->type); |
|
|
220 | |
215 | |
221 | if (find_skill_by_number (who, SK_BARGAINING)) |
216 | if (find_skill_by_number (who, SK_BARGAINING)) |
222 | lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level; |
217 | lev_bargain = find_skill_by_number (who, SK_BARGAINING)->level; |
223 | |
218 | |
224 | if (tmptype) |
219 | if (const typedata *tmptype = get_typedata (tmp->type)) |
225 | { |
220 | { |
226 | idskill1 = tmptype->identifyskill; |
221 | if (int idskill1 = tmptype->identifyskill) |
227 | |
|
|
228 | if (idskill1) |
|
|
229 | { |
222 | { |
230 | idskill2 = tmptype->identifyskill2; |
223 | int idskill2 = tmptype->identifyskill2; |
231 | |
224 | |
232 | if (find_skill_by_number (who, idskill1)) |
225 | if (find_skill_by_number (who, idskill1)) |
233 | lev_identify = find_skill_by_number (who, idskill1)->level; |
226 | lev_identify = find_skill_by_number (who, idskill1)->level; |
234 | |
227 | |
235 | if (idskill2 && find_skill_by_number (who, idskill2)) |
228 | if (idskill2 && find_skill_by_number (who, idskill2)) |
236 | lev_identify += find_skill_by_number (who, idskill2)->level; |
229 | lev_identify += find_skill_by_number (who, idskill2)->level; |
237 | } |
230 | } |
238 | } |
231 | } |
239 | else |
|
|
240 | LOG (llevError, "Query_cost: item %s hasn't got a valid type\n", tmp->debug_desc ()); |
|
|
241 | |
232 | |
242 | /* ratio determines how much of the price modification |
233 | /* ratio determines how much of the price modification |
243 | * will come from the basic stat charisma |
234 | * will come from the basic stat charisma |
244 | * the rest will come from the level in bargaining skill |
235 | * the rest will come from the level in bargaining skill |
245 | */ |
236 | */ |
… | |
… | |
418 | |
409 | |
419 | if (coin == NULL) |
410 | if (coin == NULL) |
420 | return "nothing"; |
411 | return "nothing"; |
421 | |
412 | |
422 | num = real_value / coin->value; |
413 | num = real_value / coin->value; |
|
|
414 | |
423 | if (num == 1) |
415 | if (num == 1) |
424 | sprintf (buf, "about one %s", &coin->object::name); |
416 | sprintf (buf, "about one %s", &coin->object::name); |
425 | else if (num < 5) |
417 | else if (num < 5) |
426 | sprintf (buf, "a few %s", &coin->object::name_pl); |
418 | sprintf (buf, "a few %s", &coin->object::name_pl); |
427 | else if (num < 10) |
419 | else if (num < 10) |
… | |
… | |
432 | sprintf (buf, "lots of %s", &coin->object::name_pl); |
424 | sprintf (buf, "lots of %s", &coin->object::name_pl); |
433 | else if (num < 1000) |
425 | else if (num < 1000) |
434 | sprintf (buf, "a great many %s", &coin->object::name_pl); |
426 | sprintf (buf, "a great many %s", &coin->object::name_pl); |
435 | else |
427 | else |
436 | sprintf (buf, "a vast quantity of %s", &coin->object::name_pl); |
428 | sprintf (buf, "a vast quantity of %s", &coin->object::name_pl); |
|
|
429 | |
437 | return buf; |
430 | return buf; |
438 | } |
431 | } |
439 | } |
432 | } |
440 | } |
433 | } |
441 | |
434 | |
… | |
… | |
673 | unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); |
666 | unpaid_price += query_cost (item, pl, F_BUY | F_SHOP); |
674 | } |
667 | } |
675 | |
668 | |
676 | if (unpaid_price > player_wealth) |
669 | if (unpaid_price > player_wealth) |
677 | { |
670 | { |
678 | char buf[MAX_BUF]; |
671 | dynbuf_text buf; |
679 | char cost[MAX_BUF]; |
|
|
680 | char missing[MAX_BUF]; |
|
|
681 | |
672 | |
682 | snprintf (cost, MAX_BUF, "%s", cost_string_from_value (unpaid_price, 0)); |
673 | buf << "You have " << unpaid_count |
683 | snprintf (missing, MAX_BUF, "%s", cost_string_from_value (unpaid_price - player_wealth, 0)); |
674 | << " unpaid item(s) that would cost you " << cost_string_from_value (unpaid_price, 0) |
|
|
675 | << ". You need another " << cost_string_from_value (unpaid_price - player_wealth, 0) |
|
|
676 | << " to be able to afford that."; |
684 | |
677 | |
685 | snprintf (buf, MAX_BUF, "You have %d unpaid items that would cost you %s. You need another %s to be able to afford that.", |
678 | pl->failmsg (buf); |
686 | unpaid_count, cost, missing); |
|
|
687 | new_draw_info (NDI_UNIQUE, 0, pl, buf); |
|
|
688 | |
679 | |
689 | return 0; |
680 | return 0; |
690 | } |
681 | } |
691 | else |
682 | else |
692 | return 1; |
683 | return 1; |
… | |
… | |
804 | |
795 | |
805 | /* elmex: this is for the bank plugin :( */ |
796 | /* elmex: this is for the bank plugin :( */ |
806 | sint64 |
797 | sint64 |
807 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
798 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
808 | { |
799 | { |
809 | archetype *at = archetype::find (arch); |
|
|
810 | |
|
|
811 | if (!at) |
|
|
812 | return 0; |
|
|
813 | |
|
|
814 | if (amount > 0) |
800 | if (amount) |
815 | { |
801 | { |
816 | object *tmp = arch_to_object (at); |
802 | object *ob = archetype::get (arch); |
|
|
803 | |
|
|
804 | if (!ob) |
|
|
805 | return 0; |
|
|
806 | |
817 | tmp->nrof = amount; |
807 | ob->nrof = amount; |
818 | insert_ob_in_ob (tmp, pl); |
808 | pl->insert (ob); |
819 | } |
809 | } |
820 | |
810 | |
821 | return 1; |
811 | return 1; |
822 | } |
812 | } |
823 | |
813 | |
… | |
… | |
826 | * buy item. |
816 | * buy item. |
827 | * |
817 | * |
828 | * Modified to fill available race: gold containers before dumping |
818 | * Modified to fill available race: gold containers before dumping |
829 | * remaining coins in character's inventory. |
819 | * remaining coins in character's inventory. |
830 | */ |
820 | */ |
831 | void |
821 | bool |
832 | sell_item (object *op, object *pl) |
822 | sell_item (object *op, object *pl) |
833 | { |
823 | { |
834 | sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; |
824 | sint64 amount = query_cost (op, pl, F_SELL | F_SHOP), extra_gain; |
835 | |
825 | |
836 | if (pl == NULL || pl->type != PLAYER) |
826 | if (pl == NULL || pl->type != PLAYER) |
837 | { |
827 | { |
838 | LOG (llevDebug, "Object other than player tried to sell something.\n"); |
828 | LOG (llevDebug, "Object other than player tried to sell something.\n"); |
839 | return; |
829 | return false; |
840 | } |
830 | } |
841 | |
831 | |
842 | op->custom_name = 0; |
832 | op->custom_name = 0; |
843 | |
833 | |
844 | if (!amount) |
834 | if (!amount) |
845 | { |
835 | { |
846 | new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", query_name (op)); |
836 | new_draw_info_format (NDI_UNIQUE, 0, pl, "We're not interested in %s.", |
847 | |
837 | query_name (op)); |
848 | /* Even if the character doesn't get anything for it, it may still be |
838 | // elmex: change: the player now gets the item back if the shop is not |
849 | * worth something. If so, make it unpaid |
839 | // interested in it. |
850 | */ |
|
|
851 | if (op->value) |
|
|
852 | { |
|
|
853 | SET_FLAG (op, FLAG_UNPAID); |
|
|
854 | SET_FLAG (op, FLAG_PLAYER_SOLD); |
|
|
855 | } |
|
|
856 | |
|
|
857 | identify (op); |
|
|
858 | return; |
840 | return false; |
859 | } |
841 | } |
860 | |
842 | |
861 | /* We compare the price with the one for a player |
843 | /* We compare the price with the one for a player |
862 | * without bargaining skill. |
844 | * without bargaining skill. |
863 | * This determins the amount of exp (if any) gained for bargaining. |
845 | * This determins the amount of exp (if any) gained for bargaining. |
… | |
… | |
868 | if (extra_gain > 0) |
850 | if (extra_gain > 0) |
869 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
851 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
870 | |
852 | |
871 | pay_player (pl, amount); |
853 | pay_player (pl, amount); |
872 | |
854 | |
873 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |
855 | new_draw_info_format (NDI_UNIQUE, 0, pl, "You receive %s for %s.", |
|
|
856 | query_cost_string (op, pl, F_SELL | F_SHOP), query_name (op)); |
874 | pl->play_sound (sound_find ("shop_sell")); |
857 | pl->play_sound (sound_find ("shop_sell")); |
875 | |
858 | |
876 | SET_FLAG (op, FLAG_UNPAID); |
859 | SET_FLAG (op, FLAG_UNPAID); |
877 | identify (op); |
860 | identify (op); |
|
|
861 | |
|
|
862 | return true; |
878 | } |
863 | } |
879 | |
864 | |
880 | /* returns a double that is the ratio of the price that a shop will offer for |
865 | /* returns a double that is the ratio of the price that a shop will offer for |
881 | * item based on the shops specialisation. Does not take account of greed, |
866 | * item based on the shops specialisation. Does not take account of greed, |
882 | * returned value is between SPECIALISATION_EFFECT and 1. |
867 | * returned value is between SPECIALISATION_EFFECT and 1. |
… | |
… | |
1080 | { |
1065 | { |
1081 | shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; |
1066 | shopinv *s1 = (shopinv *) a1, *s2 = (shopinv *) a2; |
1082 | |
1067 | |
1083 | if (s1->type < s2->type) |
1068 | if (s1->type < s2->type) |
1084 | return -1; |
1069 | return -1; |
|
|
1070 | |
1085 | if (s1->type > s2->type) |
1071 | if (s1->type > s2->type) |
1086 | return 1; |
1072 | return 1; |
1087 | |
1073 | |
1088 | /* the type is the same (what atoi gets), so do a strcasecmp to sort |
1074 | /* the type is the same (what atoi gets), so do a strcasecmp to sort |
1089 | * via alphabetical order |
1075 | * via alphabetical order |
… | |
… | |
1139 | |
1125 | |
1140 | void |
1126 | void |
1141 | shop_listing (object *sign, object *op) |
1127 | shop_listing (object *sign, object *op) |
1142 | { |
1128 | { |
1143 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1129 | int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2; |
1144 | const char *shop_coords = get_ob_key_value (sign, "shop_coords"); |
1130 | const char *shop_coords = sign->kv (shstr_shop_coords); |
1145 | object *stack; |
1131 | object *stack; |
1146 | shopinv *items; |
1132 | shopinv *items; |
1147 | |
1133 | |
1148 | /* Should never happen, but just in case a monster does apply a sign */ |
1134 | /* Should never happen, but just in case a monster does apply a sign */ |
1149 | if (op->type != PLAYER) |
1135 | if (op->type != PLAYER) |
… | |
… | |
1222 | |
1208 | |
1223 | /* elmex: this function checks whether the object is in a shop */ |
1209 | /* elmex: this function checks whether the object is in a shop */ |
1224 | bool |
1210 | bool |
1225 | is_in_shop (object *o) |
1211 | is_in_shop (object *o) |
1226 | { |
1212 | { |
1227 | if (!o->map) |
1213 | if (!o->is_on_map ()) |
1228 | return false; |
1214 | return false; |
1229 | |
1215 | |
1230 | return is_in_shop (o->map, o->x, o->y); |
1216 | return is_in_shop (o->map, o->x, o->y); |
1231 | } |
1217 | } |
1232 | |
1218 | |
… | |
… | |
1240 | is_in_shop (maptile *map, int x, int y) |
1226 | is_in_shop (maptile *map, int x, int y) |
1241 | { |
1227 | { |
1242 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1228 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1243 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1229 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1244 | return floor->type == SHOP_FLOOR; |
1230 | return floor->type == SHOP_FLOOR; |
|
|
1231 | |
1245 | return false; |
1232 | return false; |
1246 | } |
1233 | } |
1247 | |
1234 | |