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.71 by root, Fri Oct 16 01:56:42 2009 UTC vs.
Revision 1.76 by root, Fri Mar 26 01:04:45 2010 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 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
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
25#include <global.h> 25#include <global.h>
26#include <spells.h> 26#include <spells.h>
27#include <skills.h> 27#include <skills.h>
28#include <living.h> 28#include <living.h>
29#include <sproto.h> 29#include <sproto.h>
30#include <math.h>
31 30
32/* 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
33 * 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
34 * 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
35 * therefore making this number higher, makes specialisation less effective. 34 * therefore making this number higher, makes specialisation less effective.
589 at = archetype::find (coins[NUM_COINS - 1 - i]); 588 at = archetype::find (coins[NUM_COINS - 1 - i]);
590 589
591 if (at == NULL) 590 if (at == NULL)
592 LOG (llevError, "Could not find %s archetype\n", coins[NUM_COINS - 1 - i]); 591 LOG (llevError, "Could not find %s archetype\n", coins[NUM_COINS - 1 - i]);
593 592
594 coin_objs[i] = arch_to_object (at); 593 coin_objs[i] = at->instance ();
595 coin_objs[i]->nrof = 0; 594 coin_objs[i]->nrof = 0;
596 } 595 }
597 596
598 for (i = 0; i < NUM_COINS; i++) 597 for (i = 0; i < NUM_COINS; i++)
599 { 598 {
753 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit)) 752 if (n > 0 && (!pouch->weight_limit || pouch->carrying + w <= pouch->weight_limit))
754 { 753 {
755 if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n) 754 if (pouch->weight_limit && (pouch->weight_limit - pouch->carrying) / w < n)
756 n = (pouch->weight_limit - pouch->carrying) / w; 755 n = (pouch->weight_limit - pouch->carrying) / w;
757 756
758 object *tmp = arch_to_object (at); 757 object *tmp = at->instance ();
759 tmp->nrof = n; 758 tmp->nrof = n;
760 amount -= tmp->nrof * tmp->value; 759 amount -= tmp->nrof * tmp->value;
761 pouch->insert (tmp); 760 pouch->insert (tmp);
762 } 761 }
763 } 762 }
764 } 763 }
765 764
766 if (amount / at->value > 0) 765 if (amount / at->value > 0)
767 { 766 {
768 object *tmp = arch_to_object (at); 767 object *tmp = at->instance ();
769 tmp->nrof = amount / tmp->value; 768 tmp->nrof = amount / tmp->value;
770 amount -= tmp->nrof * tmp->value; 769 amount -= tmp->nrof * tmp->value;
771 pl->insert (tmp); 770 pl->insert (tmp);
772 } 771 }
773 } 772 }
852 */ 851 */
853static double 852static double
854shop_specialisation_ratio (const object *item, const maptile *map) 853shop_specialisation_ratio (const object *item, const maptile *map)
855{ 854{
856 shopitems *items = map->shopitems; 855 shopitems *items = map->shopitems;
857 double likedness = 0.; 856 int likedness = 0;
858 int i; 857 int i;
859 858
860 if (item == NULL) 859 if (item == NULL)
861 { 860 {
862 LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", &map->path); 861 LOG (llevError, "shop_specialisation_ratio: passed a NULL item for map %s\n", &map->path);
872 */ 871 */
873 return SPECIALISATION_EFFECT; 872 return SPECIALISATION_EFFECT;
874 } 873 }
875 874
876 if (map->shopitems) 875 if (map->shopitems)
877 {
878 for (i = 0; i < items[0].index; i++) 876 for (i = 0; i < items[0].index; i++)
879 if (items[i].typenum == item->type || (!items[i].typenum && likedness == 0.001)) 877 if (items[i].typenum == item->type || (!items[i].typenum && !likedness))
880 likedness = items[i].strength / 100.0; 878 likedness = items[i].strength;
881 }
882 879
883 if (likedness > 1.0) 880 if (likedness > 100)
884 { /* someone has been rather silly with the map headers. */ 881 { /* someone has been rather silly with the map headers. */
885 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, &map->path); 882 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is above 100%%\n", item->type, &map->path);
886 likedness = 1.0; 883 likedness = 100;
887 } 884 }
888 885
889 if (likedness < -1.0) 886 if (likedness < -100)
890 { 887 {
891 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, &map->path); 888 LOG (llevDebug, "shop_specialisation ratio: item type %d on map %s is below -100%%\n", item->type, &map->path);
892 likedness = -1.0; 889 likedness = -100;
893 } 890 }
894 891
895 return lerp (likedness, -1., 1., SPECIALISATION_EFFECT, 1.); 892 return lerp (double (likedness), -100., 100., SPECIALISATION_EFFECT, 1.);
896} 893}
897 894
898/*returns the greed of the shop on map, or 1 if it isn't specified. */ 895/*returns the greed of the shop on map, or 1 if it isn't specified. */
899static double 896static double
900shop_greed (const maptile *map) 897shop_greed (const maptile *map)
950 tmpshopmax = map->shopmax ? map->shopmax : 100000; // 20 royalties default 947 tmpshopmax = map->shopmax ? map->shopmax : 100000; // 20 royalties default
951 948
952 if (map->shopmin && unit_price < map->shopmin) 949 if (map->shopmin && unit_price < map->shopmin)
953 return 0; 950 return 0;
954 else if (unit_price > tmpshopmax / 2) 951 else if (unit_price > tmpshopmax / 2)
955 newval = MIN ((tmpshopmax / 2) + isqrt (unit_price - tmpshopmax / 2), tmpshopmax); 952 newval = min ((tmpshopmax / 2) + isqrt (unit_price - tmpshopmax / 2), tmpshopmax);
956 else 953 else
957 newval = unit_price; 954 newval = unit_price;
958 } 955 }
959 956
960 newval *= quantity; 957 newval *= quantity;
978 975
979 /*check if there is a shop specified for this map */ 976 /*check if there is a shop specified for this map */
980 if (map->shopitems || map->shopgreed || map->shoprace || map->shopmin || map->shopmax) 977 if (map->shopitems || map->shopgreed || map->shoprace || map->shopmin || map->shopmax)
981 { 978 {
982 buf << "From looking at the nearby shop you determine that it trades in "; 979 buf << "From looking at the nearby shop you determine that it trades in ";
983 980 int lastcomma = 0, prevcomma = 0;
984 char tmp[MAX_BUF];
985 981
986 if (map->shopitems) 982 if (map->shopitems)
987 for (i = 0; i < map->shopitems[0].index; i++) 983 for (i = 0; i < map->shopitems[0].index; i++)
988 if (map->shopitems[i].name && map->shopitems[i].strength > 10) 984 if (map->shopitems[i].name && map->shopitems[i].strength > 10)
989 { 985 {
990 snprintf (tmp + pos, sizeof (tmp) - pos, "%s, ", map->shopitems[i].name_pl); 986 buf << map->shopitems[i].name_pl;
991 pos += strlen (tmp + pos); 987 prevcomma = lastcomma;
988 lastcomma = buf.size (); // remember offset
989 buf << ", ";
992 } 990 }
993 991
994 if (pos) 992 if (lastcomma)
995 make_list_like (tmp); 993 {
994 buf.splice (lastcomma, 2);
995
996 if (prevcomma)
997 buf.splice (prevcomma, 2, " and ");
998 }
996 else 999 else
997 strcat (tmp, "a little of everything."); 1000 buf << "a little of everything.";
998 1001
999 /* format the string into a list */
1000 buf << tmp << "\n\n"; 1002 buf << ".\n\n";
1001 1003
1002 if (map->shopmax) 1004 if (map->shopmax)
1003 buf << "It won't trade for items above " << cost_string_from_value (map->shopmax, 0) << ".\n\n"; 1005 buf << "It won't trade for items above " << cost_string_from_value (map->shopmax, 0) << ".\n\n";
1004 1006
1005 if (map->shopmin) 1007 if (map->shopmin)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines