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.39 by root, Mon Jun 4 13:04:00 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * Crossfire TRT is free software; you can redistribute it and/or modify it
8 it under the terms of the GNU General Public License as published by 9 * under the terms of the GNU General Public License as published by the Free
9 the Free Software Foundation; either version 2 of the License, or 10 * Software Foundation; either version 2 of the License, or (at your option)
10 (at your option) any later version. 11 * 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, but
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 GNU General Public License for more details. 16 * 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 along
18 along with this program; if not, write to the Free Software 19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 to <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
133 if (tmp->arch != NULL) 131 if (tmp->arch != NULL)
134 { 132 {
135 if (flag == F_BUY) 133 if (flag == F_BUY)
136 { 134 {
137 LOG (llevError, "Asking for buy-value of unidentified object.\n"); 135 LOG (llevError, "Asking for buy-value of unidentified object.\n");
138 val = tmp->arch->clone.value * 50 * number; 136 val = tmp->arch->value * 50 * number;
139 } 137 }
140 else 138 else
141 { /* Trying to sell something, or get true value */ 139 { /* Trying to sell something, or get true value */
142 if (tmp->type == POTION) 140 if (tmp->type == POTION)
143 val = number * 40; /* Don't want to give anything away */ 141 val = number * 40; /* Don't want to give anything away */
145 { 143 {
146 /* Get 2/3'rd value for applied objects, 1/3'rd for totally 144 /* Get 2/3'rd value for applied objects, 1/3'rd for totally
147 * unknown objects 145 * unknown objects
148 */ 146 */
149 if (QUERY_FLAG (tmp, FLAG_BEEN_APPLIED)) 147 if (QUERY_FLAG (tmp, FLAG_BEEN_APPLIED))
150 val = number * tmp->arch->clone.value * 2 / 3; 148 val = number * tmp->arch->value * 2 / 3;
151 else 149 else
152 val = number * tmp->arch->clone.value / 3; 150 val = number * tmp->arch->value / 3;
153 } 151 }
154 } 152 }
155 } 153 }
156 else 154 else
157 { /* No archetype with this object */ 155 { /* No archetype with this object */
168 166
169 /* If the item has been applied or identifed or does not need to be 167 /* If the item has been applied or identifed or does not need to be
170 * identified, AND the object is magical and the archetype is non 168 * identified, AND the object is magical and the archetype is non
171 * magical, then change values accordingly. The tmp->arch==NULL is 169 * magical, then change values accordingly. The tmp->arch==NULL is
172 * really just a check to prevent core dumps for when it checks 170 * really just a check to prevent core dumps for when it checks
173 * tmp->arch->clone.magic for any magic. The check for archetype 171 * tmp->arch->magic for any magic. The check for archetype
174 * magic is to not give extra money for archetypes that are by 172 * magic is to not give extra money for archetypes that are by
175 * default magical. This is because the archetype value should have 173 * default magical. This is because the archetype value should have
176 * already figured in that value. 174 * already figured in that value.
177 */ 175 */
178 if ((QUERY_FLAG (tmp, FLAG_IDENTIFIED) || !need_identify (tmp) || identified || 176 if ((QUERY_FLAG (tmp, FLAG_IDENTIFIED) || !need_identify (tmp) || identified ||
179 QUERY_FLAG (tmp, FLAG_BEEN_APPLIED)) && tmp->magic && (tmp->arch == NULL || !tmp->arch->clone.magic)) 177 QUERY_FLAG (tmp, FLAG_BEEN_APPLIED)) && tmp->magic && (tmp->arch == NULL || !tmp->arch->magic))
180 { 178 {
181 if (tmp->magic > 0) 179 if (tmp->magic > 0)
182 val *= (3 * tmp->magic * tmp->magic * tmp->magic); 180 val *= (3 * tmp->magic * tmp->magic * tmp->magic);
183 else 181 else
184 /* Note that tmp->magic is negative, so that this 182 /* Note that tmp->magic is negative, so that this
250 * the rest will come from the level in bargaining skill 248 * the rest will come from the level in bargaining skill
251 */ 249 */
252 const double cha_ratio = 0.40; 250 const double cha_ratio = 0.40;
253 251
254 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);
255
256 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.);
257
258 diff = .02 + (.80 - .02) * diff; 254 diff = .02 + (.80 - .02) * diff;
259 255
260 if (flag == F_BUY) 256 if (flag == F_BUY)
261 val += (val * diff); 257 val += val * diff;
262 else if (flag == F_SELL) 258 else if (flag == F_SELL)
263 val -= (val * diff); 259 val -= val * diff;
264 260
265 // 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
266 // then the range is adjusted randomly around the correct value 262 // then the range is adjusted randomly around the correct value
267 if (approximate) 263 if (approximate)
268 approx_range = sint64 (val / sqrt (lev_identify * 3 + 1)); 264 approx_range = sint64 (val / sqrt (lev_identify * 3 + 1));
269 } 265 }
270 266
271 /* 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
272 * overflow of diff above. That shoudl only happen if 268 * overflow of diff above. That should only happen if
273 * we are selling objects - in that case, the person just 269 * we are selling objects - in that case, the person just
274 * gets no money. 270 * gets no money.
275 */ 271 */
276 if ((sint64) val < 0) 272 if ((sint64) val < 0)
277 val = 0; 273 val = 0;
305 if (QUERY_FLAG (tmp, FLAG_PLAYER_SOLD)) 301 if (QUERY_FLAG (tmp, FLAG_PLAYER_SOLD))
306 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));
307 else 303 else
308 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)));
309 } 305 }
306
310 /* 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
311 * 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
312 * pointful, and could give fun with rounding. 309 * pointful, and could give fun with rounding.
313 */ 310 */
314 if (who->map->path != NULL && val > 50) 311 //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))); 312 if (val > 50)
313 val += float (val) * .05f * cosf ((tmp->uuid.seq & 0xffff) * float (M_PI * 2. / 0x10000));
316 } 314 }
315
317 return (sint64) val; 316 return (sint64) val;
318} 317}
319 318
320/* 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
321 * cointype placement. 320 * cointype placement.
333 coin = archetype::find (coins[*cointype]); 332 coin = archetype::find (coins[*cointype]);
334 if (coin == NULL) 333 if (coin == NULL)
335 return NULL; 334 return NULL;
336 *cointype += 1; 335 *cointype += 1;
337 } 336 }
338 while (coin->clone.value > c); 337 while (coin->value > c);
339 338
340 return coin; 339 return coin;
341} 340}
342 341
343/* This returns a string of how much something is worth based on 342/* This returns a string of how much something is worth based on
359 358
360 coin = find_next_coin (cost, &cointype); 359 coin = find_next_coin (cost, &cointype);
361 if (coin == NULL) 360 if (coin == NULL)
362 return "nothing"; 361 return "nothing";
363 362
364 num = cost / coin->clone.value; 363 num = cost / coin->value;
365 /* so long as nrof is 32 bit, this is true. 364 /* so long as nrof is 32 bit, this is true.
366 * If it takes more coins than a person can possibly carry, this 365 * If it takes more coins than a person can possibly carry, this
367 * is basically true. 366 * is basically true.
368 */ 367 */
369 if ((cost / coin->clone.value) > UINT32_MAX) 368 if ((cost / coin->value) > UINT32_MAX)
370 { 369 {
371 strcpy (buf, "an unimaginable sum of money"); 370 strcpy (buf, "an unimaginable sum of money");
372 return buf; 371 return buf;
373 } 372 }
374 373
375 cost -= num * (sint64)coin->clone.value; 374 cost -= num * (sint64)coin->value;
376 375
377 sprintf (buf, "%d %s", num, num > 1 ? &coin->clone.name_pl : &coin->clone.name); 376 sprintf (buf, "%d %s", num, num > 1 ? &coin->object::name_pl : &coin->object::name);
378 377
379 next_coin = find_next_coin (cost, &cointype); 378 next_coin = find_next_coin (cost, &cointype);
380 if (next_coin == NULL || approx) 379 if (next_coin == NULL || approx)
381 return buf; 380 return buf;
382 381
383 coin = next_coin; 382 coin = next_coin;
384 num = cost / coin->clone.value; 383 num = cost / coin->value;
385 cost -= num * (sint64)coin->clone.value; 384 cost -= num * (sint64)coin->value;
386 385
387 sprintf (buf + strlen (buf), " and %d %s", num, num > 1 ? &coin->clone.name_pl : &coin->clone.name); 386 sprintf (buf + strlen (buf), " and %d %s", num, num > 1 ? &coin->object::name_pl : &coin->object::name);
388 387
389 return buf; 388 return buf;
390} 389}
391 390
392const char * 391const char *
422 archetype *coin = find_next_coin (real_value, &cointype); 421 archetype *coin = find_next_coin (real_value, &cointype);
423 422
424 if (coin == NULL) 423 if (coin == NULL)
425 return "nothing"; 424 return "nothing";
426 425
427 num = real_value / coin->clone.value; 426 num = real_value / coin->value;
428 if (num == 1) 427 if (num == 1)
429 sprintf (buf, "about one %s", &coin->clone.name); 428 sprintf (buf, "about one %s", &coin->object::name);
430 else if (num < 5) 429 else if (num < 5)
431 sprintf (buf, "a few %s", &coin->clone.name_pl); 430 sprintf (buf, "a few %s", &coin->object::name_pl);
432 else if (num < 10) 431 else if (num < 10)
433 sprintf (buf, "several %s", &coin->clone.name_pl); 432 sprintf (buf, "several %s", &coin->object::name_pl);
434 else if (num < 25) 433 else if (num < 25)
435 sprintf (buf, "a moderate amount of %s", &coin->clone.name_pl); 434 sprintf (buf, "a moderate amount of %s", &coin->object::name_pl);
436 else if (num < 100) 435 else if (num < 100)
437 sprintf (buf, "lots of %s", &coin->clone.name_pl); 436 sprintf (buf, "lots of %s", &coin->object::name_pl);
438 else if (num < 1000) 437 else if (num < 1000)
439 sprintf (buf, "a great many %s", &coin->clone.name_pl); 438 sprintf (buf, "a great many %s", &coin->object::name_pl);
440 else 439 else
441 sprintf (buf, "a vast quantity of %s", &coin->clone.name_pl); 440 sprintf (buf, "a vast quantity of %s", &coin->object::name_pl);
442 return buf; 441 return buf;
443 } 442 }
444 } 443 }
445 } 444 }
446 445
505 504
506 for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) 505 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"))) 506 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold")))
508 pay_from_container (pl, pouch, to_pay); 507 pay_from_container (pl, pouch, to_pay);
509 508
510 fix_player (pl); 509 pl->update_stats ();
511 return 1; 510 return 1;
512} 511}
513 512
514/* 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
515 * 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 541
543 for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below) 542 for (pouch = pl->inv; pouch && to_pay; pouch = pouch->below)
544 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold"))) 543 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && (pouch->race == NULL || strstr (pouch->race, "gold")))
545 pay_from_container (pl, pouch, to_pay); 544 pay_from_container (pl, pouch, to_pay);
546 545
547 if (settings.real_wiz == FALSE && QUERY_FLAG (pl, FLAG_WAS_WIZ)) 546 pl->update_stats ();
548 SET_FLAG (op, FLAG_WAS_WIZ);
549 547
550 fix_player (pl);
551 return 1; 548 return 1;
552} 549}
553 550
554/* This pays for the item, and takes the proper amount of money off 551/* This pays for the item, and takes the proper amount of money off
555 * the player. 552 * the player.
584 581
585 if (tmp->type == MONEY) 582 if (tmp->type == MONEY)
586 { 583 {
587 for (i = 0; i < NUM_COINS; i++) 584 for (i = 0; i < NUM_COINS; i++)
588 { 585 {
589 if (tmp->value == tmp->arch->clone.value && !strcmp (coins[NUM_COINS - 1 - i], tmp->arch->name)) 586 if (tmp->value == tmp->arch->value && !strcmp (coins[NUM_COINS - 1 - i], tmp->arch->archname))
590 { 587 {
591 // This should not happen, but if it does, just merge the two. 588 // This should not happen, but if it does, just merge the two.
592 if (coin_objs [i]) 589 if (coin_objs [i])
593 { 590 {
594 LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]); 591 LOG (llevError, "%s has two money entries of (%s)\n", &pouch->name, coins[NUM_COINS - 1 - i]);
610 break; 607 break;
611 } 608 }
612 } 609 }
613 610
614 if (i == NUM_COINS) 611 if (i == NUM_COINS)
615 LOG (llevError, "in pay_for_item: Did not find string match for %s\n", &tmp->arch->name); 612 LOG (llevError, "in pay_for_item: Did not find string match for %s\n", &tmp->arch->archname);
616 } 613 }
617 } 614 }
618 615
619 /* Fill in any gaps in the coin_objs array - needed to make change. */ 616 /* Fill in any gaps in the coin_objs array - needed to make change. */
620 /* Note that the coin_objs array goes from least value to greatest value */ 617 /* Note that the coin_objs array goes from least value to greatest value */
796 { 793 {
797 at = archetype::find (coins[count]); 794 at = archetype::find (coins[count]);
798 795
799 if (at == NULL) 796 if (at == NULL)
800 LOG (llevError, "Could not find %s archetype\n", coins[count]); 797 LOG (llevError, "Could not find %s archetype\n", coins[count]);
801 else if ((amount / at->clone.value) > 0) 798 else if ((amount / at->value) > 0)
802 { 799 {
803 for (pouch = pl->inv; pouch; pouch = pouch->below) 800 for (pouch = pl->inv; pouch; pouch = pouch->below)
804 { 801 {
805 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && pouch->race && strstr (pouch->race, "gold")) 802 if (pouch->type == CONTAINER && QUERY_FLAG (pouch, FLAG_APPLIED) && pouch->race && strstr (pouch->race, "gold"))
806 { 803 {
807 int w = at->clone.weight * (100 - pouch->stats.Str) / 100; 804 int w = at->weight * (100 - pouch->stats.Str) / 100;
808 int n = amount / at->clone.value; 805 int n = amount / at->value;
809 806
810 if (w == 0) 807 if (w == 0)
811 w = 1; /* Prevent divide by zero */ 808 w = 1; /* Prevent divide by zero */
812 809
813 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) 810 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit))
825 esrv_send_item (pl, pl); 822 esrv_send_item (pl, pl);
826 } 823 }
827 } 824 }
828 } 825 }
829 826
830 if (amount / at->clone.value > 0) 827 if (amount / at->value > 0)
831 { 828 {
832 tmp = arch_to_object (at); 829 tmp = arch_to_object (at);
833 tmp->nrof = amount / tmp->value; 830 tmp->nrof = amount / tmp->value;
834 amount -= tmp->nrof * tmp->value; 831 amount -= tmp->nrof * tmp->value;
835 tmp = insert_ob_in_ob (tmp, pl); 832 tmp = insert_ob_in_ob (tmp, pl);
933 double ratio = SPECIALISATION_EFFECT, likedness = 0.001; 930 double ratio = SPECIALISATION_EFFECT, likedness = 0.001;
934 int i; 931 int i;
935 932
936 if (item == NULL) 933 if (item == NULL)
937 { 934 {
938 LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", map->path); 935 LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", &map->path);
939 return 0; 936 return 0;
940 } 937 }
941 938
942 if (!item->type) 939 if (!item->type)
943 { 940 {
956 likedness = items[i].strength / 100.0; 953 likedness = items[i].strength / 100.0;
957 } 954 }
958 955
959 if (likedness > 1.0) 956 if (likedness > 1.0)
960 { /* someone has been rather silly with the map headers. */ 957 { /* 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); 958 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, &map->path);
962 likedness = 1.0; 959 likedness = 1.0;
963 } 960 }
964 961
965 if (likedness < -1.0) 962 if (likedness < -1.0)
966 { 963 {
967 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, map->path); 964 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, &map->path);
968 likedness = -1.0; 965 likedness = -1.0;
969 } 966 }
970 967
971 ratio = ratio + (1.0 - ratio) * likedness; 968 ratio = ratio + (1.0 - ratio) * likedness;
972 969
1195 } 1192 }
1196 SET_FLAG (tmp, FLAG_UNPAID); 1193 SET_FLAG (tmp, FLAG_UNPAID);
1197} 1194}
1198 1195
1199void 1196void
1200shop_listing (object *op) 1197shop_listing (object *sign, object *op)
1201{ 1198{
1202 int i, j, numitems = 0, numallocated = 0, nx, ny; 1199 int i, j, numitems = 0, numallocated = 0, x1, x2, y1, y2;
1203 char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); 1200 const char *shop_coords = get_ob_key_value (sign, "shop_coords");
1204 object *stack; 1201 object *stack;
1205 shopinv *items; 1202 shopinv *items;
1206 1203
1207 /* Should never happen, but just in case a monster does apply a sign */ 1204 /* Should never happen, but just in case a monster does apply a sign */
1208 if (op->type != PLAYER) 1205 if (op->type != PLAYER)
1209 return; 1206 return;
1210 1207
1211 new_draw_info (NDI_UNIQUE, 0, op, "\nThe shop contains:"); 1208 if (!(shop_coords && sscanf (shop_coords, "%d,%d,%d,%d", &x1, &y1, &x2, &y2)))
1209 {
1210 x1 = 0;
1211 y1 = 0;
1212 x2 = op->map->width - 1;
1213 y2 = op->map->height - 1;
1214 }
1212 1215
1213 magic_mapping_mark (op, map_mark, 3);
1214 items = (shopinv *) malloc (40 * sizeof (shopinv)); 1216 items = (shopinv *) malloc (40 * sizeof (shopinv));
1215 numallocated = 40; 1217 numallocated = 40;
1216 1218
1217 /* Find all the appropriate items */ 1219 /* Find all the appropriate items */
1218 for (i = 0; i < MAP_WIDTH (op->map); i++) 1220 for (i = x1; i <= x2; i++)
1219 { 1221 {
1220 for (j = 0; j < MAP_HEIGHT (op->map); j++) 1222 for (j = y1; j < y2; j++)
1221 {
1222 /* magic map code now centers the map on the object at MAGIC_MAP_HALF.
1223 * 1223 {
1224 */ 1224 if (is_in_shop (op->map, i, j))
1225 nx = i - op->x + MAGIC_MAP_HALF;
1226 ny = j - op->y + MAGIC_MAP_HALF;
1227 /* unlikely, but really big shops could run into this issue */
1228 if (nx < 0 || ny < 0 || nx > MAGIC_MAP_SIZE || ny > MAGIC_MAP_SIZE)
1229 continue;
1230
1231 if (map_mark[nx + MAGIC_MAP_SIZE * ny] & FACE_FLOOR)
1232 { 1225 {
1233 stack = get_map_ob (op->map, i, j); 1226 stack = GET_MAP_OB (op->map, i, j);
1234 1227
1235 while (stack) 1228 while (stack)
1236 { 1229 {
1237 if (QUERY_FLAG (stack, FLAG_UNPAID)) 1230 if (QUERY_FLAG (stack, FLAG_UNPAID))
1238 { 1231 {
1239 if (numitems == numallocated) 1232 if (numitems == numallocated)
1240 { 1233 {
1241 items = (shopinv *) realloc (items, sizeof (shopinv) * (numallocated + 10)); 1234 items = (shopinv *) realloc (items, sizeof (shopinv) * (numallocated + 10));
1242 numallocated += 10; 1235 numallocated += 10;
1243 } 1236 }
1237
1244 add_shop_item (stack, items, &numitems, &numallocated); 1238 add_shop_item (stack, items, &numitems, &numallocated);
1245 } 1239 }
1240
1246 stack = stack->above; 1241 stack = stack->above;
1247 } 1242 }
1248 } 1243 }
1249 } 1244 }
1250 } 1245 }
1251 1246
1252 free (map_mark);
1253
1254 if (numitems == 0) 1247 if (numitems == 0)
1255 { 1248 {
1256 new_draw_info (NDI_UNIQUE, 0, op, "The shop is currently empty.\n"); 1249 new_draw_info (NDI_UNIQUE, 0, op, "The shop is currently empty.\n");
1257 free (items); 1250 free (items);
1258 return; 1251 return;
1259 } 1252 }
1260 1253
1261 qsort (items, numitems, sizeof (shopinv), (int (*)(const void *, const void *)) shop_sort); 1254 qsort (items, numitems, sizeof (shopinv), (int (*)(const void *, const void *)) shop_sort);
1255
1256 new_draw_info (NDI_UNIQUE, 0, op, "\nThe shop contains:");
1262 1257
1263 for (i = 0; i < numitems; i++) 1258 for (i = 0; i < numitems; i++)
1264 { 1259 {
1265 /* Collapse items of the same name together */ 1260 /* Collapse items of the same name together */
1266 if ((i + 1) < numitems && !strcmp (items[i].item_real, items[i + 1].item_real)) 1261 if ((i + 1) < numitems && !strcmp (items[i].item_real, items[i + 1].item_real))
1275 items[i].nrof ? items[i].nrof : 1, items[i].nrof == 1 ? items[i].item_sort : items[i].item_real); 1270 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); 1271 free (items[i].item_sort);
1277 free (items[i].item_real); 1272 free (items[i].item_real);
1278 } 1273 }
1279 } 1274 }
1275
1280 free (items); 1276 free (items);
1281} 1277}
1282 1278
1283/* elmex: this function checks whether the object is in a shop */ 1279/* elmex: this function checks whether the object is in a shop */
1284bool 1280bool
1292 1288
1293/* elmex: this function checks whether we are in a shop or not */ 1289/* elmex: this function checks whether we are in a shop or not */
1294bool 1290bool
1295is_in_shop (maptile *map, int x, int y) 1291is_in_shop (maptile *map, int x, int y)
1296{ 1292{
1297 for (object *floor = get_map_ob (map, x, y); floor; floor = floor->above) 1293 for (object *floor = GET_MAP_OB (map, x, y); floor; floor = floor->above)
1298 if (floor->type == SHOP_FLOOR) 1294 if (floor->type == SHOP_FLOOR)
1299 return true; 1295 return true;
1300 1296
1301 return false; 1297 return false;
1302} 1298}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines