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.24 by root, Fri Dec 15 19:59:20 2006 UTC vs.
Revision 1.34 by root, Sun Feb 25 19:13:25 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <spells.h> 26#include <spells.h>
26#include <skills.h> 27#include <skills.h>
27#include <living.h> 28#include <living.h>
247 * the rest will come from the level in bargaining skill 248 * the rest will come from the level in bargaining skill
248 */ 249 */
249 const double cha_ratio = 0.40; 250 const double cha_ratio = 0.40;
250 251
251 diff = no_bargain ? 1.0 : 1. - pow (lev_bargain / (double) settings.max_level, 0.25); 252 diff = no_bargain ? 1.0 : 1. - pow (lev_bargain / (double) settings.max_level, 0.25);
252
253 diff = (1. - cha_ratio) * diff + cha_ratio * (cha_bonus[who->stats.Cha] - 1.) / (cha_bonus[who->stats.Cha] + 1.); 253 diff = (1. - cha_ratio) * diff + cha_ratio * (cha_bonus[who->stats.Cha] - 1.) / (cha_bonus[who->stats.Cha] + 1.);
254
255 diff = .02 + (.80 - .02) * diff; 254 diff = .02 + (.80 - .02) * diff;
256 255
257 if (flag == F_BUY) 256 if (flag == F_BUY)
258 val += (val * diff); 257 val += val * diff;
259 else if (flag == F_SELL) 258 else if (flag == F_SELL)
260 val -= (val * diff); 259 val -= val * diff;
261 260
262 // now find a price range. the less good we can judge, the larger the range is 261 // now find a price range. the less good we can judge, the larger the range is
263 // then the range is adjusted randomly around the correct value 262 // then the range is adjusted randomly around the correct value
264 if (approximate) 263 if (approximate)
265 approx_range = sint64 (val / sqrt (lev_identify * 3 + 1)); 264 approx_range = sint64 (val / sqrt (lev_identify * 3 + 1));
266 } 265 }
267 266
268 /* I don't think this should really happen - if it does, it indicates and 267 /* I don't think this should really happen - if it does, it indicates and
269 * overflow of diff above. That shoudl only happen if 268 * overflow of diff above. That should only happen if
270 * we are selling objects - in that case, the person just 269 * we are selling objects - in that case, the person just
271 * gets no money. 270 * gets no money.
272 */ 271 */
273 if ((sint64) val < 0) 272 if ((sint64) val < 0)
274 val = 0; 273 val = 0;
302 if (QUERY_FLAG (tmp, FLAG_PLAYER_SOLD)) 301 if (QUERY_FLAG (tmp, FLAG_PLAYER_SOLD))
303 val = (val * shop_greed (who->map) * shop_specialisation_ratio (tmp, who->map) / shopkeeper_approval (who->map, who)); 302 val = (val * shop_greed (who->map) * shop_specialisation_ratio (tmp, who->map) / shopkeeper_approval (who->map, who));
304 else 303 else
305 val = (val * shop_greed (who->map) / (shop_specialisation_ratio (tmp, who->map) * shopkeeper_approval (who->map, who))); 304 val = (val * shop_greed (who->map) / (shop_specialisation_ratio (tmp, who->map) * shopkeeper_approval (who->map, who)));
306 } 305 }
306
307 /* we will also have an extra 0-5% variation between shops of the same type 307 /* we will also have an extra 0-5% variation between shops of the same type
308 * for valuable items (below a value of 50 this effect wouldn't be very 308 * for valuable items (below a value of 50 this effect wouldn't be very
309 * pointful, and could give fun with rounding. 309 * pointful, and could give fun with rounding.
310 */ 310 */
311 if (who->map->path != NULL && val > 50) 311 //TODO: why use cosf at all, just % and scale linearly, gives more even distribution
312 val = (val + 0.05 * (sint64) val * cos (tmp->count + strlen (who->map->path))); 312 if (val > 50)
313 val += float (val) * .05f * cosf ((tmp->uuid.seq & 0xffff) * float (M_PI * 2. / 0x10000));
313 } 314 }
315
314 return (sint64) val; 316 return (sint64) val;
315} 317}
316 318
317/* Find the coin type that is worth more the 'c'. Starts at the 319/* Find the coin type that is worth more the 'c'. Starts at the
318 * cointype placement. 320 * cointype placement.
502 504
503 for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) 505 for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below)
504 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold"))) 506 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold")))
505 pay_from_container (pl, pouch, to_pay); 507 pay_from_container (pl, pouch, to_pay);
506 508
507 fix_player (pl); 509 pl->update_stats ();
508 return 1; 510 return 1;
509} 511}
510 512
511/* DAMN: This is now a wrapper for pay_from_container, which is 513/* DAMN: This is now a wrapper for pay_from_container, which is
512 * called for the player, then for each active container that can hold 514 * called for the player, then for each active container that can hold
542 pay_from_container (pl, pouch, to_pay); 544 pay_from_container (pl, pouch, to_pay);
543 545
544 if (settings.real_wiz == FALSE && QUERY_FLAG (pl, FLAG_WAS_WIZ)) 546 if (settings.real_wiz == FALSE && QUERY_FLAG (pl, FLAG_WAS_WIZ))
545 SET_FLAG (op, FLAG_WAS_WIZ); 547 SET_FLAG (op, FLAG_WAS_WIZ);
546 548
547 fix_player (pl); 549 pl->update_stats ();
548 return 1; 550 return 1;
549} 551}
550 552
551/* This pays for the item, and takes the proper amount of money off 553/* This pays for the item, and takes the proper amount of money off
552 * the player. 554 * the player.
930 double ratio = SPECIALISATION_EFFECT, likedness = 0.001; 932 double ratio = SPECIALISATION_EFFECT, likedness = 0.001;
931 int i; 933 int i;
932 934
933 if (item == NULL) 935 if (item == NULL)
934 { 936 {
935 LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", map->path); 937 LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", &map->path);
936 return 0; 938 return 0;
937 } 939 }
938 940
939 if (!item->type) 941 if (!item->type)
940 { 942 {
953 likedness = items[i].strength / 100.0; 955 likedness = items[i].strength / 100.0;
954 } 956 }
955 957
956 if (likedness > 1.0) 958 if (likedness > 1.0)
957 { /* someone has been rather silly with the map headers. */ 959 { /* someone has been rather silly with the map headers. */
958 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, map->path); 960 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, &map->path);
959 likedness = 1.0; 961 likedness = 1.0;
960 } 962 }
961 963
962 if (likedness < -1.0) 964 if (likedness < -1.0)
963 { 965 {
964 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, map->path); 966 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, &map->path);
965 likedness = -1.0; 967 likedness = -1.0;
966 } 968 }
967 969
968 ratio = ratio + (1.0 - ratio) * likedness; 970 ratio = ratio + (1.0 - ratio) * likedness;
969 971
1210 magic_mapping_mark (op, map_mark, 3); 1212 magic_mapping_mark (op, map_mark, 3);
1211 items = (shopinv *) malloc (40 * sizeof (shopinv)); 1213 items = (shopinv *) malloc (40 * sizeof (shopinv));
1212 numallocated = 40; 1214 numallocated = 40;
1213 1215
1214 /* Find all the appropriate items */ 1216 /* Find all the appropriate items */
1215 for (i = 0; i < MAP_WIDTH (op->map); i++) 1217 for (i = 0; i < op->map->width; i++)
1216 { 1218 {
1217 for (j = 0; j < MAP_HEIGHT (op->map); j++) 1219 for (j = 0; j < op->map->height; j++)
1218 { 1220 {
1219 /* magic map code now centers the map on the object at MAGIC_MAP_HALF. 1221 // magic map code now centers the map on the object at MAGIC_MAP_HALF.
1220 *
1221 */
1222 nx = i - op->x + MAGIC_MAP_HALF; 1222 nx = i - op->x + MAGIC_MAP_HALF;
1223 ny = j - op->y + MAGIC_MAP_HALF; 1223 ny = j - op->y + MAGIC_MAP_HALF;
1224 /* unlikely, but really big shops could run into this issue */ 1224 /* unlikely, but really big shops could run into this issue */
1225 if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE) 1225 if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE)
1226 continue; 1226 continue;
1227 1227
1228 if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR) 1228 if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR)
1229 { 1229 {
1230 stack = get_map_ob (op->map, i, j); 1230 stack = GET_MAP_OB (op->map, i, j);
1231 1231
1232 while (stack) 1232 while (stack)
1233 { 1233 {
1234 if (QUERY_FLAG (stack, FLAG_UNPAID)) 1234 if (QUERY_FLAG (stack, FLAG_UNPAID))
1235 { 1235 {
1236 if (numitems == numallocated) 1236 if (numitems == numallocated)
1237 { 1237 {
1238 items = (shopinv *) realloc (items, sizeof (shopinv) * (numallocated + 10)); 1238 items = (shopinv *) realloc (items, sizeof (shopinv) * (numallocated + 10));
1239 numallocated += 10; 1239 numallocated += 10;
1240 } 1240 }
1241
1241 add_shop_item (stack, items, &numitems, &numallocated); 1242 add_shop_item (stack, items, &numitems, &numallocated);
1242 } 1243 }
1244
1243 stack = stack->above; 1245 stack = stack->above;
1244 } 1246 }
1245 } 1247 }
1246 } 1248 }
1247 } 1249 }
1272 items[i].nrof ? items[i].nrof : 1, items[i].nrof == 1 ? items[i].item_sort : items[i].item_real); 1274 items[i].nrof ? items[i].nrof : 1, items[i].nrof == 1 ? items[i].item_sort : items[i].item_real);
1273 free (items[i].item_sort); 1275 free (items[i].item_sort);
1274 free (items[i].item_real); 1276 free (items[i].item_real);
1275 } 1277 }
1276 } 1278 }
1279
1277 free (items); 1280 free (items);
1278} 1281}
1279 1282
1280/* elmex: this function checks whether the object is in a shop */ 1283/* elmex: this function checks whether the object is in a shop */
1281bool 1284bool
1289 1292
1290/* elmex: this function checks whether we are in a shop or not */ 1293/* elmex: this function checks whether we are in a shop or not */
1291bool 1294bool
1292is_in_shop (maptile *map, int x, int y) 1295is_in_shop (maptile *map, int x, int y)
1293{ 1296{
1294 for (object *floor = get_map_ob (map, x, y); floor; floor = floor->above) 1297 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above)
1295 if (floor->type == SHOP_FLOOR) 1298 if (floor->type == SHOP_FLOOR)
1296 return true; 1299 return true;
1297 1300
1298 return false; 1301 return false;
1299} 1302}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines