1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <spells.h> |
25 | #include <spells.h> |
26 | #include <skills.h> |
26 | #include <skills.h> |
… | |
… | |
42 | |
42 | |
43 | static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); |
43 | static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); |
44 | static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop); |
44 | static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop); |
45 | static double shop_specialisation_ratio (const object *item, const maptile *map); |
45 | static double shop_specialisation_ratio (const object *item, const maptile *map); |
46 | static double shop_greed (const maptile *map); |
46 | static double shop_greed (const maptile *map); |
47 | |
|
|
48 | #define NUM_COINS 4 /* number of coin types */ |
|
|
49 | static const char *const coins[] = { "royalty", "platinacoin", "goldcoin", "silvercoin", NULL }; |
|
|
50 | |
47 | |
51 | /* Added F_TRUE flag to define.h to mean that the price should not |
48 | /* Added F_TRUE flag to define.h to mean that the price should not |
52 | * be adjusted by players charisma. With F_TRUE, it returns the amount |
49 | * be adjusted by players charisma. With F_TRUE, it returns the amount |
53 | * that the item is worth, if it was sold, but unadjusted by charisma. |
50 | * that the item is worth, if it was sold, but unadjusted by charisma. |
54 | * This is needed for alchemy, to to determine what value of gold nuggets |
51 | * This is needed for alchemy, to to determine what value of gold nuggets |
… | |
… | |
586 | { |
583 | { |
587 | // This should not happen, but if it does, just merge the two. |
584 | // This should not happen, but if it does, just merge the two. |
588 | if (coin_objs [i]) |
585 | if (coin_objs [i]) |
589 | { |
586 | { |
590 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
587 | LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); |
591 | tmp->remove (); |
|
|
592 | coin_objs[i]->nrof += tmp->nrof; |
588 | coin_objs[i]->nrof += tmp->nrof; |
593 | esrv_del_item (pl->contr, tmp->count); |
|
|
594 | tmp->destroy (); |
589 | tmp->destroy (); |
595 | } |
590 | } |
596 | else |
591 | else |
597 | { |
592 | { |
598 | tmp->remove (); |
593 | tmp->remove (); |
599 | |
|
|
600 | if (pouch->type == PLAYER) |
|
|
601 | esrv_del_item (pl->contr, tmp->count); |
|
|
602 | |
|
|
603 | coin_objs[i] = tmp; |
594 | coin_objs[i] = tmp; |
604 | } |
595 | } |
605 | |
596 | |
606 | break; |
597 | break; |
607 | } |
598 | } |
… | |
… | |
786 | { |
777 | { |
787 | int count = 0; |
778 | int count = 0; |
788 | archetype *at = 0; |
779 | archetype *at = 0; |
789 | object *pouch = 0, *tmp = 0; |
780 | object *pouch = 0, *tmp = 0; |
790 | |
781 | |
791 | for (count = 0; coins[count] != NULL; count++) |
782 | for (count = 0; coins[count]; count++) |
792 | { |
783 | { |
793 | at = archetype::find (coins[count]); |
784 | at = archetype::find (coins[count]); |
794 | |
785 | |
795 | if (at == NULL) |
786 | if (at == NULL) |
796 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
787 | LOG (llevError, "Could not find %s archetype\n", coins[count]); |
… | |
… | |
842 | /* elmex: this is for the bank plugin :( */ |
833 | /* elmex: this is for the bank plugin :( */ |
843 | sint64 |
834 | sint64 |
844 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
835 | pay_player_arch (object *pl, const char *arch, sint64 amount) |
845 | { |
836 | { |
846 | archetype *at = archetype::find (arch); |
837 | archetype *at = archetype::find (arch); |
847 | object *tmp = NULL; |
|
|
848 | |
838 | |
849 | if (at == NULL) |
839 | if (!at) |
850 | return 0; |
840 | return 0; |
851 | |
841 | |
852 | if (amount > 0) |
842 | if (amount > 0) |
853 | { |
843 | { |
854 | tmp = arch_to_object (at); |
844 | object *tmp = arch_to_object (at); |
855 | tmp->nrof = amount; |
845 | tmp->nrof = amount; |
856 | tmp = insert_ob_in_ob (tmp, pl); |
846 | tmp = insert_ob_in_ob (tmp, pl); |
857 | esrv_send_item (pl, tmp); |
847 | esrv_send_item (pl, tmp); |
858 | esrv_send_item (pl, pl); |
848 | esrv_send_item (pl, pl); |
859 | } |
849 | } |
… | |
… | |
909 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
899 | change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); |
910 | |
900 | |
911 | pay_player (pl, amount); |
901 | pay_player (pl, amount); |
912 | |
902 | |
913 | 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)); |
903 | 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)); |
|
|
904 | pl->play_sound (sound_find ("shop_sell")); |
914 | |
905 | |
915 | SET_FLAG (op, FLAG_UNPAID); |
906 | SET_FLAG (op, FLAG_UNPAID); |
916 | identify (op); |
907 | identify (op); |
917 | } |
908 | } |
918 | |
|
|
919 | |
909 | |
920 | /* returns a double that is the ratio of the price that a shop will offer for |
910 | /* returns a double that is the ratio of the price that a shop will offer for |
921 | * item based on the shops specialisation. Does not take account of greed, |
911 | * item based on the shops specialisation. Does not take account of greed, |
922 | * returned value is between SPECIALISATION_EFFECT and 1. |
912 | * returned value is between SPECIALISATION_EFFECT and 1. |
923 | */ |
913 | */ |
… | |
… | |
1268 | return false; |
1258 | return false; |
1269 | |
1259 | |
1270 | return is_in_shop (o->map, o->x, o->y); |
1260 | return is_in_shop (o->map, o->x, o->y); |
1271 | } |
1261 | } |
1272 | |
1262 | |
1273 | /* elmex: this function checks whether we are in a shop or not */ |
1263 | /* elmex: this function checks whether we are in a shop or not |
|
|
1264 | - change 2007-11-26: enhanced the O(n) case by stopping at the first |
|
|
1265 | floor tile. this possibly will make map bugs where shopfloors are above |
|
|
1266 | floors more obvious. |
|
|
1267 | */ |
|
|
1268 | |
1274 | bool |
1269 | bool |
1275 | is_in_shop (maptile *map, int x, int y) |
1270 | is_in_shop (maptile *map, int x, int y) |
1276 | { |
1271 | { |
1277 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
1272 | for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) |
|
|
1273 | if (QUERY_FLAG (floor, FLAG_IS_FLOOR)) |
1278 | if (floor->type == SHOP_FLOOR) |
1274 | return floor->type == SHOP_FLOOR; |
1279 | return true; |
|
|
1280 | |
|
|
1281 | return false; |
1275 | return false; |
1282 | } |
1276 | } |
|
|
1277 | |