ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/shop.C
(Generate patch)

Comparing deliantra/server/server/shop.C (file contents):
Revision 1.41 by root, Sat Jul 21 19:04:45 2007 UTC vs.
Revision 1.46 by root, Wed Apr 9 14:36:47 2008 UTC

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 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>
35 * setting this value above 1 or to a negative value would have interesting, 35 * setting this value above 1 or to a negative value would have interesting,
36 * (though not useful) effects. 36 * (though not useful) effects.
37 */ 37 */
38#define SPECIALISATION_EFFECT .5 38#define SPECIALISATION_EFFECT .5
39 39
40/* price a shopkeeper will give someone they neither like nor dislike */ 40// price a shopkeeper will give someone that is not of their race
41#define NEUTRAL_RATIO 0.8 41#define DISLIKE_RATIO 0.8
42 42
43static void pay_from_container (object *pl, object *pouch, sint64 &to_pay); 43static void pay_from_container (object *pl, object *pouch, sint64 &to_pay);
44static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop); 44static sint64 value_limit (sint64 val, int quantity, const object *who, int isshop);
45static double shop_specialisation_ratio (const object *item, const maptile *map); 45static double shop_specialisation_ratio (const object *item, const maptile *map);
46static double shop_greed (const maptile *map); 46static double shop_greed (const maptile *map);
47
48#define NUM_COINS 4 /* number of coin types */
49static 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
786{ 783{
787 int count = 0; 784 int count = 0;
788 archetype *at = 0; 785 archetype *at = 0;
789 object *pouch = 0, *tmp = 0; 786 object *pouch = 0, *tmp = 0;
790 787
791 for (count = 0; coins[count] != NULL; count++) 788 for (count = 0; coins[count]; count++)
792 { 789 {
793 at = archetype::find (coins[count]); 790 at = archetype::find (coins[count]);
794 791
795 if (at == NULL) 792 if (at == NULL)
796 LOG (llevError, "Could not find %s archetype\n", coins[count]); 793 LOG (llevError, "Could not find %s archetype\n", coins[count]);
909 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE); 906 change_exp (pl, extra_gain / 10, "bargaining", SK_EXP_NONE);
910 907
911 pay_player (pl, amount); 908 pay_player (pl, amount);
912 909
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)); 910 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));
911 pl->play_sound (sound_find ("shop_sell"));
914 912
915 SET_FLAG (op, FLAG_UNPAID); 913 SET_FLAG (op, FLAG_UNPAID);
916 identify (op); 914 identify (op);
917} 915}
918
919 916
920/* returns a double that is the ratio of the price that a shop will offer for 917/* 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, 918 * item based on the shops specialisation. Does not take account of greed,
922 * returned value is between SPECIALISATION_EFFECT and 1. 919 * returned value is between SPECIALISATION_EFFECT and 1.
923 */ 920 */
968 965
969/*returns the greed of the shop on map, or 1 if it isn't specified. */ 966/*returns the greed of the shop on map, or 1 if it isn't specified. */
970static double 967static double
971shop_greed (const maptile *map) 968shop_greed (const maptile *map)
972{ 969{
973 double greed = 1.0;
974
975 if (map->shopgreed)
976 return map->shopgreed; 970 return map->shopgreed
977 return greed; 971 ? map->shopgreed
972 : 1.;
978} 973}
979 974
980/* Returns a double based on how much the shopkeeper approves of the player. 975/* Returns a double based on how much the shopkeeper approves of the player.
981 * this is based on the race of the shopkeeper and that of the player. 976 * this is based on the race of the shopkeeper and that of the player.
982 */ 977 */
983double 978double
984shopkeeper_approval (const maptile *map, const object *player) 979shopkeeper_approval (const maptile *map, const object *player)
985{ 980{
986 double approval = 1.0; 981 return map->shoprace && player->race != map->shoprace
987 982 ? DISLIKE_RATIO
988 if (map->shoprace) 983 : 1.;
989 {
990 approval = NEUTRAL_RATIO;
991 if (player->race && !strcmp (player->race, map->shoprace))
992 approval = 1.0;
993 }
994
995 return approval;
996} 984}
997 985
998/* limit the value of items based on the wealth of the shop. If the item is close 986/* limit the value of items based on the wealth of the shop. If the item is close
999 * to the maximum value a shop will offer, we start to reduce it, if the item is 987 * to the maximum value a shop will offer, we start to reduce it, if the item is
1000 * below the minimum value the shop is prepared to trade in, then we don't 988 * below the minimum value the shop is prepared to trade in, then we don't
1277 return false; 1265 return false;
1278 1266
1279 return is_in_shop (o->map, o->x, o->y); 1267 return is_in_shop (o->map, o->x, o->y);
1280} 1268}
1281 1269
1282/* elmex: this function checks whether we are in a shop or not */ 1270/* elmex: this function checks whether we are in a shop or not
1271 - change 2007-11-26: enhanced the O(n) case by stopping at the first
1272 floor tile. this possibly will make map bugs where shopfloors are above
1273 floors more obvious.
1274*/
1275
1283bool 1276bool
1284is_in_shop (maptile *map, int x, int y) 1277is_in_shop (maptile *map, int x, int y)
1285{ 1278{
1286 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above) 1279 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above)
1280 if (QUERY_FLAG (floor, FLAG_IS_FLOOR))
1287 if (floor->type == SHOP_FLOOR) 1281 return floor->type == SHOP_FLOOR;
1288 return true;
1289
1290 return false; 1282 return false;
1291} 1283}
1284

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines