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.23 by root, Thu Dec 14 22:45:41 2006 UTC vs.
Revision 1.33 by root, Thu Feb 8 13:47:18 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>
28#include <newclient.h>
29#ifndef __CEXTRACT__
30# include <sproto.h> 29#include <sproto.h>
31#endif
32#include <math.h> 30#include <math.h>
33 31
34/* this is a measure of how effective store specialisation is. A general store 32/* this is a measure of how effective store specialisation is. A general store
35 * will offer this proportion of the 'maximum' price, a specialised store will 33 * will offer this proportion of the 'maximum' price, a specialised store will
36 * offer a range of prices around it such that the maximum price is always one 34 * offer a range of prices around it such that the maximum price is always one
309 } 307 }
310 /* we will also have an extra 0-5% variation between shops of the same type 308 /* we will also have an extra 0-5% variation between shops of the same type
311 * for valuable items (below a value of 50 this effect wouldn't be very 309 * for valuable items (below a value of 50 this effect wouldn't be very
312 * pointful, and could give fun with rounding. 310 * pointful, and could give fun with rounding.
313 */ 311 */
314 if (who->map->path != NULL && val > 50) 312 //TODO: why use cosf at all, just % and scale linearly, gives more even distribution
315 val = (val + 0.05 * (sint64) val * cos (tmp->count + strlen (who->map->path))); 313 if (val > 50)
314 val += float (val) * .05f * cosf ((tmp->uuid.seq & 0xffff) * float (M_PI * 2. / 0x10000));
316 } 315 }
316
317 return (sint64) val; 317 return (sint64) val;
318} 318}
319 319
320/* Find the coin type that is worth more the 'c'. Starts at the 320/* Find the coin type that is worth more the 'c'. Starts at the
321 * cointype placement. 321 * cointype placement.
505 505
506 for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) 506 for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below)
507 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold"))) 507 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold")))
508 pay_from_container (pl, pouch, to_pay); 508 pay_from_container (pl, pouch, to_pay);
509 509
510 fix_player (pl); 510 pl->update_stats ();
511 return 1; 511 return 1;
512} 512}
513 513
514/* DAMN: This is now a wrapper for pay_from_container, which is 514/* DAMN: This is now a wrapper for pay_from_container, which is
515 * called for the player, then for each active container that can hold 515 * called for the player, then for each active container that can hold
545 pay_from_container (pl, pouch, to_pay); 545 pay_from_container (pl, pouch, to_pay);
546 546
547 if (settings.real_wiz == FALSE && QUERY_FLAG (pl, FLAG_WAS_WIZ)) 547 if (settings.real_wiz == FALSE && QUERY_FLAG (pl, FLAG_WAS_WIZ))
548 SET_FLAG (op, FLAG_WAS_WIZ); 548 SET_FLAG (op, FLAG_WAS_WIZ);
549 549
550 fix_player (pl); 550 pl->update_stats ();
551 return 1; 551 return 1;
552} 552}
553 553
554/* This pays for the item, and takes the proper amount of money off 554/* This pays for the item, and takes the proper amount of money off
555 * the player. 555 * the player.
933 double ratio = SPECIALISATION_EFFECT, likedness = 0.001; 933 double ratio = SPECIALISATION_EFFECT, likedness = 0.001;
934 int i; 934 int i;
935 935
936 if (item == NULL) 936 if (item == NULL)
937 { 937 {
938 LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", map->path); 938 LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", &map->path);
939 return 0; 939 return 0;
940 } 940 }
941 941
942 if (!item->type) 942 if (!item->type)
943 { 943 {
956 likedness = items[i].strength / 100.0; 956 likedness = items[i].strength / 100.0;
957 } 957 }
958 958
959 if (likedness > 1.0) 959 if (likedness > 1.0)
960 { /* someone has been rather silly with the map headers. */ 960 { /* someone has been rather silly with the map headers. */
961 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, map->path); 961 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, &map->path);
962 likedness = 1.0; 962 likedness = 1.0;
963 } 963 }
964 964
965 if (likedness < -1.0) 965 if (likedness < -1.0)
966 { 966 {
967 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, map->path); 967 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, &map->path);
968 likedness = -1.0; 968 likedness = -1.0;
969 } 969 }
970 970
971 ratio = ratio + (1.0 - ratio) * likedness; 971 ratio = ratio + (1.0 - ratio) * likedness;
972 972
1213 magic_mapping_mark (op, map_mark, 3); 1213 magic_mapping_mark (op, map_mark, 3);
1214 items = (shopinv *) malloc (40 * sizeof (shopinv)); 1214 items = (shopinv *) malloc (40 * sizeof (shopinv));
1215 numallocated = 40; 1215 numallocated = 40;
1216 1216
1217 /* Find all the appropriate items */ 1217 /* Find all the appropriate items */
1218 for (i = 0; i < MAP_WIDTH (op->map); i++) 1218 for (i = 0; i < op->map->width; i++)
1219 { 1219 {
1220 for (j = 0; j < MAP_HEIGHT (op->map); j++) 1220 for (j = 0; j < op->map->height; j++)
1221 { 1221 {
1222 /* magic map code now centers the map on the object at MAGIC_MAP_HALF. 1222 // magic map code now centers the map on the object at MAGIC_MAP_HALF.
1223 *
1224 */
1225 nx = i - op->x + MAGIC_MAP_HALF; 1223 nx = i - op->x + MAGIC_MAP_HALF;
1226 ny = j - op->y + MAGIC_MAP_HALF; 1224 ny = j - op->y + MAGIC_MAP_HALF;
1227 /* unlikely, but really big shops could run into this issue */ 1225 /* unlikely, but really big shops could run into this issue */
1228 if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE) 1226 if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE)
1229 continue; 1227 continue;
1230 1228
1231 if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR) 1229 if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR)
1232 { 1230 {
1233 stack = get_map_ob (op->map, i, j); 1231 stack = GET_MAP_OB (op->map, i, j);
1234 1232
1235 while (stack) 1233 while (stack)
1236 { 1234 {
1237 if (QUERY_FLAG (stack, FLAG_UNPAID)) 1235 if (QUERY_FLAG (stack, FLAG_UNPAID))
1238 { 1236 {
1239 if (numitems == numallocated) 1237 if (numitems == numallocated)
1240 { 1238 {
1241 items = (shopinv *) realloc (items, sizeof (shopinv) * (numallocated + 10)); 1239 items = (shopinv *) realloc (items, sizeof (shopinv) * (numallocated + 10));
1242 numallocated += 10; 1240 numallocated += 10;
1243 } 1241 }
1242
1244 add_shop_item (stack, items, &numitems, &numallocated); 1243 add_shop_item (stack, items, &numitems, &numallocated);
1245 } 1244 }
1245
1246 stack = stack->above; 1246 stack = stack->above;
1247 } 1247 }
1248 } 1248 }
1249 } 1249 }
1250 } 1250 }
1275 items[i].nrof ? items[i].nrof : 1, items[i].nrof == 1 ? items[i].item_sort : items[i].item_real); 1275 items[i].nrof ? items[i].nrof : 1, items[i].nrof == 1 ? items[i].item_sort : items[i].item_real);
1276 free (items[i].item_sort); 1276 free (items[i].item_sort);
1277 free (items[i].item_real); 1277 free (items[i].item_real);
1278 } 1278 }
1279 } 1279 }
1280
1280 free (items); 1281 free (items);
1281} 1282}
1282 1283
1283/* elmex: this function checks whether the object is in a shop */ 1284/* elmex: this function checks whether the object is in a shop */
1284bool 1285bool
1292 1293
1293/* elmex: this function checks whether we are in a shop or not */ 1294/* elmex: this function checks whether we are in a shop or not */
1294bool 1295bool
1295is_in_shop (maptile *map, int x, int y) 1296is_in_shop (maptile *map, int x, int y)
1296{ 1297{
1297 for (object *floor = get_map_ob (map, x, y); floor; floor = floor->above) 1298 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above)
1298 if (floor->type == SHOP_FLOOR) 1299 if (floor->type == SHOP_FLOOR)
1299 return true; 1300 return true;
1300 1301
1301 return false; 1302 return false;
1302} 1303}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines