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 | */ |
853 | static double |
852 | static double |
854 | shop_specialisation_ratio (const object *item, const maptile *map) |
853 | shop_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. */ |
899 | static double |
896 | static double |
900 | shop_greed (const maptile *map) |
897 | shop_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; |