Index: client/agents/cma_core.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v retrieving revision 1.12 diff -u -r1.12 cma_core.c --- client/agents/cma_core.c 2002/02/19 20:03:03 1.12 +++ client/agents/cma_core.c 2002/02/23 08:53:29 @@ -96,7 +96,6 @@ #define DISABLE_CACHE3 FALSE #define ALWAYS_APPLY_AT_SERVER FALSE -#define MAX_CITY_SIZE 50 #define MAX_TRADE 200 #define MAX_LUXURY 150 #define NUM_SPECIALISTS_ROLLES 3 Index: common/city.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.h,v retrieving revision 1.101 diff -u -r1.101 city.h --- common/city.h 2002/02/21 08:56:21 1.101 +++ common/city.h 2002/02/23 08:53:30 @@ -71,6 +71,11 @@ */ #define NUM_TRADEROUTES 4 +/* + * Size of the biggest possible city + */ +#define MAX_CITY_SIZE 50 + /* Iterate a city map */ #define city_map_iterate(x, y) \ Index: server/citytools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v retrieving revision 1.165 diff -u -r1.165 citytools.c --- server/citytools.c 2002/02/21 09:44:52 1.165 +++ server/citytools.c 2002/02/23 08:53:37 @@ -193,15 +193,30 @@ **************************************************************************/ int food_weighting(int city_size) { - int food_weighting_is_for = 4; /* FOOD_WEIGHTING applies to city with - foodbox width of 4 */ - int weighting = (food_weighting_is_for * FOOD_WEIGHTING) - / (1+city_size); + static int cache[MAX_CITY_SIZE]; + static bool cache_valid = FALSE; - /* If the citysize is 1 we assume it will not be so for long, and - so adjust the value a little downwards. */ - if (city_size == 1) return ((weighting*3)/4); - else return weighting; + if (!cache_valid) { + int size = 0; + + for (size = 1; size < MAX_CITY_SIZE; size++) { + int food_weighting_is_for = 4; /* FOOD_WEIGHTING applies to city with + foodbox width of 4 */ + int weighting = (food_weighting_is_for * FOOD_WEIGHTING) / (1 + size); + + /* If the citysize is 1 we assume it will not be so for long, and + so adjust the value a little downwards. */ + if (size == 1) { + weighting = ((weighting * 3) / 4); + } + cache[size] = weighting; + } + cache_valid = TRUE; + } + + assert(city_size > 0 && city_size < MAX_CITY_SIZE); + + return cache[city_size]; } /**************************************************************************