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.92 by root, Mon Oct 29 23:55:55 2012 UTC vs.
Revision 1.94 by root, Sun Jan 29 02:47:06 2017 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
29#include <sproto.h> 29#include <sproto.h>
30 30
31/* this is a measure of how effective store specialisation is. A general store 31/* this is a measure of how effective store specialisation is. A general store
32 * will offer this proportion of the 'maximum' price, a specialised store will 32 * will offer this proportion of the 'maximum' price, a specialised store will
33 * offer a range of prices around it such that the maximum price is always one 33 * offer a range of prices around it such that the maximum price is always one
34 * therefore making this number higher, makes specialisation less effective. 34 * therefore making this number higher, makes specialisation less effective.
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
55 * would not be done. 55 * would not be done.
56 * 56 *
57 * Added F_APPROX flag, which means that the price returned should be wrong by 57 * Added F_APPROX flag, which means that the price returned should be wrong by
58 * an amount related to the player's bargaining skill. 58 * an amount related to the player's bargaining skill.
59 * 59 *
60 * Added F_SHOP flag to mean that the specialisation of the shop on the player's 60 * Added F_SHOP flag to mean that the specialisation of the shop on the player's
61 * current map should be taken into account when determining the price. Shops that 61 * current map should be taken into account when determining the price. Shops that
62 * specialise in what is being traded will give better prices than those that do not. 62 * specialise in what is being traded will give better prices than those that do not.
63 * 63 *
64 * CF 0.91.4 - This function got changed around a bit. Now the 64 * CF 0.91.4 - This function got changed around a bit. Now the
65 * number of object is multiplied by the value early on. This fixes problems 65 * number of object is multiplied by the value early on. This fixes problems
66 * with items worth very little. What happened before is that various 66 * with items worth very little. What happened before is that various
67 * divisions took place, the value got rounded to 0 (Being an int), and 67 * divisions took place, the value got rounded to 0 (Being an int), and
255 { 255 {
256 if (flag == F_SELL) 256 if (flag == F_SELL)
257 val *= shop_specialisation_ratio (tmp, who->map) * shopkeeper_approval (who->map, who) / shop_greed (who->map); 257 val *= shop_specialisation_ratio (tmp, who->map) * shopkeeper_approval (who->map, who) / shop_greed (who->map);
258 else if (flag == F_BUY) 258 else if (flag == F_BUY)
259 { 259 {
260 /* 260 /*
261 * when buying, if the item was sold by another player, it is ok to 261 * when buying, if the item was sold by another player, it is ok to
262 * let the item be sold cheaper, according to the specialisation of 262 * let the item be sold cheaper, according to the specialisation of
263 * the shop. If a player sold an item here, then his sale price was 263 * the shop. If a player sold an item here, then his sale price was
264 * multiplied by the specialisation ratio, to do the same to the buy 264 * multiplied by the specialisation ratio, to do the same to the buy
265 * price will not generate extra money. However, the 265 * price will not generate extra money. However, the
266 * same is not true of generated items, these have to /divide/ by the 266 * same is not true of generated items, these have to /divide/ by the
267 * specialisation, so that the price is never less than what they could 267 * specialisation, so that the price is never less than what they could
268 * be sold for (otherwise players could camp map resets to make money). 268 * be sold for (otherwise players could camp map resets to make money).
269 * In game terms, a non-specialist shop, might not recognise the true 269 * In game terms, a non-specialist shop, might not recognise the true
270 * value of the items they sell (much like how people sometimes find 270 * value of the items they sell (much like how people sometimes find
271 * antiques in a junk shop in real life). 271 * antiques in a junk shop in real life).
272 */ 272 */
273 if (tmp->flag [FLAG_PLAYER_SOLD]) 273 if (tmp->flag [FLAG_PLAYER_SOLD])
274 val *= shop_specialisation_ratio (tmp, who->map); 274 val *= shop_specialisation_ratio (tmp, who->map);
275 else 275 else
276 val /= shop_specialisation_ratio (tmp, who->map); 276 val /= shop_specialisation_ratio (tmp, who->map);
277 277
278 val *= shop_greed (who->map) / shopkeeper_approval (who->map, who); 278 val *= shop_greed (who->map) / shopkeeper_approval (who->map, who);
279 } 279 }
280 280
281 /* we will also have an extra 0-5% variation between shops of the same type 281 /* we will also have an extra 0-5% variation between shops of the same type
282 * for valuable items (below a value of 50 this effect wouldn't be very 282 * for valuable items (below a value of 50 this effect wouldn't be very
283 * pointful, and could give fun with rounding. 283 * pointful, and could give fun with rounding.
284 */ 284 */
285 //TODO: why use cosf at all, just % and scale linearly, gives more even distribution 285 //TODO: why use cosf at all, just % and scale linearly, gives more even distribution
286 if (val > 50) 286 if (val > 50)
287 val *= 1 + .05f * cosf ((tmp->uuid.seq & 0xffff) * M_PI * 2. / 0x10000); 287 val *= 1 + .05f * cosf ((tmp->uuid.seq & 0xffff) * M_PI * 2. / 0x10000);
617 coin_objs[i]->destroy (); 617 coin_objs[i]->destroy ();
618} 618}
619 619
620/* Checks all unpaid items in op's inventory, adds up all the money they 620/* Checks all unpaid items in op's inventory, adds up all the money they
621 * have, and checks that they can actually afford what they want to buy. 621 * have, and checks that they can actually afford what they want to buy.
622 * Returns 1 if they can, and 0 if they can't. also prints an appropriate message 622 * Returns 1 if they can, and 0 if they can't. also prints an appropriate message
623 * to the player 623 * to the player
624 */ 624 */
625int 625int
626can_pay (object *pl) 626can_pay (object *pl)
627{ 627{
837 837
838 return true; 838 return true;
839} 839}
840 840
841/* returns a double that is the ratio of the price that a shop will offer for 841/* returns a double that is the ratio of the price that a shop will offer for
842 * item based on the shops specialisation. Does not take account of greed, 842 * item based on the shops specialisation. Does not take account of greed,
843 * returned value is between SPECIALISATION_EFFECT and 1. 843 * returned value is between SPECIALISATION_EFFECT and 1.
844 */ 844 */
845static double 845static double
846shop_specialisation_ratio (const object *item, const maptile *map) 846shop_specialisation_ratio (const object *item, const maptile *map)
847{ 847{
856 } 856 }
857 857
858 if (!item->type) 858 if (!item->type)
859 { 859 {
860 LOG (llevError, "shop_specialisation_ratio: passed an item with an invalid type: %s\n", item->debug_desc ()); 860 LOG (llevError, "shop_specialisation_ratio: passed an item with an invalid type: %s\n", item->debug_desc ());
861 /* 861 /*
862 * I'm not really sure what the /right/ thing to do here is, these types of 862 * I'm not really sure what the /right/ thing to do here is, these types of
863 * item shouldn't exist anyway, but returning the ratio is probably the best bet.." 863 * item shouldn't exist anyway, but returning the ratio is probably the best bet.."
864 */ 864 */
865 return SPECIALISATION_EFFECT; 865 return SPECIALISATION_EFFECT;
866 } 866 }
867 867
868 if (map->shopitems) 868 if (map->shopitems)
904 ? DISLIKE_RATIO 904 ? DISLIKE_RATIO
905 : 1.; 905 : 1.;
906} 906}
907 907
908/* limit the value of items based on the wealth of the shop. If the item is close 908/* limit the value of items based on the wealth of the shop. If the item is close
909 * to the maximum value a shop will offer, we start to reduce it, if the item is 909 * to the maximum value a shop will offer, we start to reduce it, if the item is
910 * below the minimum value the shop is prepared to trade in, then we don't 910 * below the minimum value the shop is prepared to trade in, then we don't
911 * want it and offer nothing. If it isn't a shop, check whether we should do generic 911 * want it and offer nothing. If it isn't a shop, check whether we should do generic
912 * value reduction. 912 * value reduction.
913 * 913 *
914 */ 914 */
915static sint64 915static sint64

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines