[Freeciv-Dev] (PR#8877) patch: design for generalized specialists
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] (PR#8877) patch: design for generalized specialists |
From: |
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> |
Date: |
Sun, 5 Sep 2004 20:41:27 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8877 >
Here's an updated patch.
jason
Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.118
diff -u -r1.118 advdomestic.c
--- ai/advdomestic.c 31 Aug 2004 15:52:46 -0000 1.118
+++ ai/advdomestic.c 6 Sep 2004 03:40:39 -0000
@@ -178,6 +178,42 @@
}
/**************************************************************************
+ Return the number of "entertainers".
+
+ The AI assumes that for any specialist that provides 2 luxury, if we
+ can get 2 luxury from some other source it allows the specialist to
+ become a worker. The benefits from an extra worker are weighed against
+ the losses from acquiring the two extra luxury.
+
+ This is a very bad model if the abilities of specialists are changed.
+ But as long as the civ2 model of specialists is used it will continue
+ to work okay.
+**************************************************************************/
+static int get_num_entertainers(struct city *pcity)
+{
+ int elvis = 0;
+
+ /* Count all luxury-producing specialists. We "estimate" that for every
+ * extra citizen made content one of these can be put to work elsewhere.
+ * This calculation should be improved. */
+ specialist_type_iterate(i) {
+ if (game.rgame.specialists[i].bonus_lux >= 2) {
+ elvis += pcity->specialists[i];
+ }
+ } specialist_type_iterate_end;
+
+ return elvis;
+}
+
+/**************************************************************************
+ Return the number of "non-entertainiers". See get_num_entertainers().
+**************************************************************************/
+static int get_num_nonentertainers(struct city *pcity)
+{
+ return city_specialists(pcity) - get_num_entertainers(pcity);
+}
+
+/**************************************************************************
Returns the value (desire to build it) of the improvement for keeping
of order in the city.
@@ -198,8 +234,7 @@
{
/* How much one rebeling citizen counts - 16 is debatable value */
#define SADVAL 16
- /* Number of elvises in the city */
- int elvis = pcity->specialists[SP_ELVIS];
+ int elvis = get_num_entertainers(pcity);
/* Raw number of unhappy people */
int sad = pcity->ppl_unhappy[0];
/* Final number of content people */
@@ -234,7 +269,7 @@
while (happy > 0) { happy--; value += SADVAL; }
freelog(LOG_DEBUG, "%s: %d elvis %d sad %d content %d size %d val",
- pcity->name, pcity->specialists[SP_ELVIS], pcity->ppl_unhappy[4],
+ pcity->name, elvis, pcity->ppl_unhappy[4],
pcity->ppl_content[4], pcity->size, value);
return value;
@@ -496,9 +531,7 @@
sci = 0;
}
- est_food = (2 * pcity->specialists[SP_SCIENTIST]
- + 2 * pcity->specialists[SP_TAXMAN]
- + pcity->food_surplus);
+ est_food = (2 * get_num_nonentertainers(pcity) + pcity->food_surplus);
prod =
(pcity->shield_prod * SHIELD_WEIGHTING * 100) / city_shield_bonus(pcity);
needpower = (city_got_building(pcity, B_MFG) ? 2 :
@@ -515,9 +548,7 @@
grana = food_weighting(grana + 1);
hunger = 1;
j = (pcity->size * 2) + settler_eats(pcity) - pcity->food_prod;
- if (j >= 0
- && pcity->specialists[SP_SCIENTIST] <= 0
- && pcity->specialists[SP_TAXMAN] <= 0) {
+ if (j >= 0 && get_num_nonentertainers(pcity) == 0) {
hunger += j + 1;
}
@@ -603,8 +634,24 @@
case B_MARKETPLACE:
case B_BANK:
case B_STOCK:
- values[id] = (tax + 3 * pcity->specialists[SP_TAXMAN]
- + pcity->specialists[SP_ELVIS] * wwtv) / 2;
+ values[id] = tax; /* +50% to taxes */
+
+ specialist_type_iterate(sp) {
+ /* +50% to taxmen. */
+ values[id] += (pcity->specialists[sp]
+ * game.rgame.specialists[sp].bonus_tax);
+
+ /* +50% to luxuries => converted to workers. That's 1 more
+ * worker per 4 luxuries. Note this assumes that an
+ * entertainer specialist exists that can be put to work when
+ * we get more luxuries. */
+ values[id] += (pcity->specialists[sp]
+ * game.rgame.specialists[sp].bonus_lux
+ * wwtv) / 2;
+ } specialist_type_iterate_end;
+
+ /* Bonus is 50% */
+ values[id] /= 2;
break;
case B_SUPERHIGHWAYS:
values[id] = road_trade(pcity) * t;
@@ -1026,9 +1073,7 @@
Unit_Type_id unit_type;
/* Food surplus assuming that workers and elvii are already accounted for
* and properly balanced. */
- int est_food = pcity->food_surplus
- + 2 * pcity->specialists[SP_SCIENTIST]
- + 2 * pcity->specialists[SP_TAXMAN];
+ int est_food = pcity->food_surplus + 2 * get_num_nonentertainers(pcity);
init_choice(choice);
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.162
diff -u -r1.162 aicity.c
--- ai/aicity.c 4 Sep 2004 19:28:18 -0000 1.162
+++ ai/aicity.c 6 Sep 2004 03:40:40 -0000
@@ -678,7 +678,7 @@
is_valid = map_to_city_map(&city_map_x, &city_map_y, acity, x, y);
assert(is_valid);
server_remove_worker_city(acity, city_map_x, city_map_y);
- acity->specialists[SP_ELVIS]++;
+ acity->specialists[DEFAULT_SPECIALIST]++;
if (!city_list_find_id(&minilist, acity->id)) {
city_list_insert(&minilist, acity);
}
Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.36
diff -u -r1.36 cityrepdata.c
--- client/cityrepdata.c 6 Sep 2004 02:13:16 -0000 1.36
+++ client/cityrepdata.c 6 Sep 2004 03:40:40 -0000
@@ -117,6 +117,7 @@
return specialists_string(pcity->specialists);
}
+#if 0
static const char *cr_entry_entertainers(const struct city *pcity)
{
static char buf[8];
@@ -137,6 +138,7 @@
my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[SP_TAXMAN]);
return buf;
}
+#endif
static const char *cr_entry_attack(const struct city *pcity)
{
@@ -437,12 +439,14 @@
N_("?entertainers/scientists/taxmen:E/S/T"),
N_("Entertainers, Scientists, Taxmen"),
FUNC_TAG(specialists) },
+#if 0
{ FALSE, 2, 1, NULL, N_("?Entertainers:E"), N_("Entertainers"),
FUNC_TAG(entertainers) },
{ FALSE, 2, 1, NULL, N_("?Scientists:S"), N_("Scientists"),
FUNC_TAG(scientists) },
{ FALSE, 2, 1, NULL, N_("?Taxmen:T"), N_("Taxmen"),
FUNC_TAG(taxmen) },
+#endif
{ FALSE, 8, 1, N_("Best"), N_("attack"),
N_("Best attacking units"), FUNC_TAG(attack)},
{ FALSE, 8, 1, N_("Best"), N_("defense"),
Index: client/cityrepdata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.h,v
retrieving revision 1.11
diff -u -r1.11 cityrepdata.h
--- client/cityrepdata.h 4 Sep 2004 18:39:38 -0000 1.11
+++ client/cityrepdata.h 6 Sep 2004 03:40:40 -0000
@@ -21,7 +21,7 @@
#define REPORT_CITYNAME_ABBREV 15
/* Number of city report columns: have to set this manually now... */
-#define NUM_CREPORT_COLS 33
+#define NUM_CREPORT_COLS 30
struct city_report_spec {
bool show; /* modify this to customize */
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.401
diff -u -r1.401 packhand.c
--- client/packhand.c 6 Sep 2004 02:58:11 -0000 1.401
+++ client/packhand.c 6 Sep 2004 03:40:41 -0000
@@ -2711,10 +2711,15 @@
{
int i;
+ /* Must set num_specialist_types before iterating over them. */
+ game.rgame.num_specialist_types = packet->num_specialist_types;
+ game.rgame.default_specialist = packet->default_specialist;
specialist_type_iterate(sp) {
sz_strlcpy(game.rgame.specialists[sp].name, packet->specialist_name[sp]);
game.rgame.specialists[sp].min_size = packet->specialist_min_size[sp];
- game.rgame.specialists[sp].bonus = packet->specialist_bonus[sp];
+ game.rgame.specialists[sp].bonus_sci = packet->specialist_bonus_sci[sp];
+ game.rgame.specialists[sp].bonus_tax = packet->specialist_bonus_tax[sp];
+ game.rgame.specialists[sp].bonus_lux = packet->specialist_bonus_lux[sp];
} specialist_type_iterate_end;
tilespec_setup_specialist_types();
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.85
diff -u -r1.85 tilespec.h
--- client/tilespec.h 3 Sep 2004 04:22:36 -0000 1.85
+++ client/tilespec.h 6 Sep 2004 03:40:41 -0000
@@ -151,7 +151,7 @@
* sprites, as defined by the tileset. */
int count;
struct Sprite *sprite[MAX_NUM_CITIZEN_SPRITES];
- } citizen[NUM_TILES_CITIZEN], specialist[SP_COUNT];
+ } citizen[NUM_TILES_CITIZEN], specialist[MAX_NUM_SPECIALISTS];
struct {
struct Sprite
*solar_panels,
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.62
diff -u -r1.62 cma_core.c
--- client/agents/cma_core.c 4 Sep 2004 18:39:38 -0000 1.62
+++ client/agents/cma_core.c 6 Sep 2004 03:40:41 -0000
@@ -104,9 +104,10 @@
T(disorder);
T(happy);
- T(specialists[SP_ELVIS]);
- T(specialists[SP_SCIENTIST]);
- T(specialists[SP_TAXMAN]);
+
+ specialist_type_iterate(sp) {
+ T(specialists[sp]);
+ } specialist_type_iterate_end;
for (stat = 0; stat < NUM_STATS; stat++) {
T(surplus[stat]);
@@ -194,7 +195,7 @@
static bool apply_result_on_server(struct city *pcity,
const struct cm_result *const result)
{
- int first_request_id = 0, last_request_id = 0, i, sp;
+ int first_request_id = 0, last_request_id = 0, i;
struct cm_result current_state;
bool success;
@@ -232,22 +233,24 @@
}
} my_city_map_iterate_end;
- /* Change the excess non-elvis specialists to elvises. */
- assert(SP_ELVIS == 0);
- for (sp = 1; sp < SP_COUNT; sp++) {
+ /* Change the excess non-(default) specialists to (default). */
+ specialist_type_iterate(sp) {
+ if (sp == DEFAULT_SPECIALIST) {
+ continue;
+ }
for (i = 0; i < pcity->specialists[sp] - result->specialists[sp]; i++) {
- last_request_id = city_change_specialist(pcity, sp, SP_ELVIS);
+ last_request_id = city_change_specialist(pcity, sp, DEFAULT_SPECIALIST);
if (first_request_id == 0) {
first_request_id = last_request_id;
}
}
- }
+ } specialist_type_iterate_end;
/* now all surplus people are enterainers */
/* Set workers */
- /* FIXME: This code assumes that any toggled worker will turn into an
- * elvis! */
+ /* FIXME: This code assumes that any toggled worker will turn into a
+ * DEFAULT_SPECIALIST! */
my_city_map_iterate(pcity, x, y) {
if (result->worker_positions_used[x][y] &&
pcity->city_map[x][y] != C_TILE_WORKER) {
@@ -259,17 +262,19 @@
}
} my_city_map_iterate_end;
- /* Set all specialists except SP_ELVIS (all the unchanged ones remain
- * as elvises). */
- assert(SP_ELVIS == 0);
- for (sp = 1; sp < SP_COUNT; sp++) {
+ /* Set all specialists except DEFAULT_SPECIALIST (all the unchanged ones
+ * remain as DEFAULT_SPECIALIST). */
+ specialist_type_iterate(sp) {
+ if (sp == DEFAULT_SPECIALIST) {
+ continue;
+ }
for (i = 0; i < result->specialists[sp] - pcity->specialists[sp]; i++) {
- last_request_id = city_change_specialist(pcity, SP_ELVIS, sp);
+ last_request_id = city_change_specialist(pcity, DEFAULT_SPECIALIST, sp);
if (first_request_id == 0) {
first_request_id = last_request_id;
}
}
- }
+ } specialist_type_iterate_end;
if (last_request_id == 0 || ALWAYS_APPLY_AT_SERVER) {
/*
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.184
diff -u -r1.184 capstr.c
--- common/capstr.c 6 Sep 2004 02:58:11 -0000 1.184
+++ common/capstr.c 6 Sep 2004 03:40:41 -0000
@@ -73,7 +73,7 @@
* are not directly related to the capability strings discussed here.)
*/
-#define CAPABILITY "+Freeciv.Devel.2004.Sep.5"
+#define CAPABILITY "+Freeciv.Devel.2004.Sep.5b"
void init_our_capability(void)
{
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.243
diff -u -r1.243 city.c
--- common/city.c 6 Sep 2004 02:13:16 -0000 1.243
+++ common/city.c 6 Sep 2004 03:40:41 -0000
@@ -1850,12 +1850,15 @@
get_tax_income(city_owner(pcity), pcity->trade_prod, &pcity->science_total,
&pcity->luxury_total, &pcity->tax_total);
- pcity->luxury_total += (pcity->specialists[SP_ELVIS]
- * game.rgame.specialists[SP_ELVIS].bonus);
- pcity->science_total += (pcity->specialists[SP_SCIENTIST]
- * game.rgame.specialists[SP_SCIENTIST].bonus);
- pcity->tax_total += (pcity->specialists[SP_TAXMAN]
- * game.rgame.specialists[SP_TAXMAN].bonus);
+ specialist_type_iterate(sp) {
+ pcity->luxury_total
+ += pcity->specialists[sp] * game.rgame.specialists[sp].bonus_lux;
+ pcity->science_total
+ += pcity->specialists[sp] * game.rgame.specialists[sp].bonus_sci;
+ pcity->tax_total
+ += pcity->specialists[sp] * game.rgame.specialists[sp].bonus_tax;
+ } specialist_type_iterate_end;
+
pcity->tax_total += get_city_tithes_bonus(pcity);
}
@@ -2464,6 +2467,57 @@
}
/**************************************************************************
+ Return the best science specialist available in the game.
+**************************************************************************/
+Specialist_type_id best_science_specialist(void)
+{
+ int best = DEFAULT_SPECIALIST, val = -1;
+
+ specialist_type_iterate(i) {
+ if (game.rgame.specialists[i].bonus_sci > val) {
+ best = i;
+ val = game.rgame.specialists[i].bonus_sci;
+ }
+ } specialist_type_iterate_end;
+
+ return best;
+}
+
+/**************************************************************************
+ Return the best tax specialist available in the game.
+**************************************************************************/
+Specialist_type_id best_tax_specialist(void)
+{
+ int best = DEFAULT_SPECIALIST, val = -1;
+
+ specialist_type_iterate(i) {
+ if (game.rgame.specialists[i].bonus_tax > val) {
+ best = i;
+ val = game.rgame.specialists[i].bonus_tax;
+ }
+ } specialist_type_iterate_end;
+
+ return best;
+}
+
+/**************************************************************************
+ Return the best luxury specialist available in the game.
+**************************************************************************/
+Specialist_type_id best_luxury_specialist(void)
+{
+ int best = DEFAULT_SPECIALIST, val = -1;
+
+ specialist_type_iterate(i) {
+ if (game.rgame.specialists[i].bonus_lux > val) {
+ best = i;
+ val = game.rgame.specialists[i].bonus_lux;
+ }
+ } specialist_type_iterate_end;
+
+ return best;
+}
+
+/**************************************************************************
Return a string showing the number of specialists in the array.
For instance with a city with (0,3,1) specialists call
@@ -2475,7 +2529,7 @@
const char *specialists_string(const int *specialists)
{
size_t len = 0;
- static char buf[5 * SP_COUNT];
+ static char buf[5 * MAX_NUM_SPECIALISTS];
specialist_type_iterate(sp) {
char *separator = (len == 0) ? "" : "/";
@@ -2638,7 +2692,7 @@
specialist_type_iterate(sp) {
pcity->specialists[sp] = 0;
} specialist_type_iterate_end;
- pcity->specialists[SP_ELVIS] = 1;
+ pcity->specialists[DEFAULT_SPECIALIST] = 1;
pcity->ppl_happy[4] = 0;
pcity->ppl_content[4] = 1;
pcity->ppl_unhappy[4] = 0;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.161
diff -u -r1.161 city.h
--- common/city.h 6 Sep 2004 02:13:16 -0000 1.161
+++ common/city.h 6 Sep 2004 03:40:41 -0000
@@ -22,10 +22,6 @@
TYPE_UNIT, TYPE_NORMAL_IMPROVEMENT, TYPE_WONDER
};
-enum specialist_type {
- SP_ELVIS, SP_SCIENTIST, SP_TAXMAN, SP_COUNT
-};
-
enum city_tile_type {
C_TILE_EMPTY, C_TILE_WORKER, C_TILE_UNAVAILABLE
};
@@ -79,6 +75,9 @@
*/
#define MAX_CITY_SIZE 100
+/* Maximum number of specialist types. */
+#define MAX_NUM_SPECIALISTS 20
+
/*
* Iterate a city map. This iterates over all city positions in the
* city map (i.e., positions that are workable by the city) in unspecified
@@ -226,7 +225,7 @@
int ppl_happy[5], ppl_content[5], ppl_unhappy[5], ppl_angry[5];
/* Specialists */
- int specialists[SP_COUNT];
+ int specialists[MAX_NUM_SPECIALISTS];
/* trade routes */
int trade[NUM_TRADEROUTES], trade_value[NUM_TRADEROUTES];
@@ -484,6 +483,9 @@
int city_corruption(const struct city *pcity, int trade);
int city_waste(const struct city *pcity, int shields);
int city_specialists(const struct city *pcity); /*
elv+tax+scie */
+Specialist_type_id best_science_specialist(void);
+Specialist_type_id best_tax_specialist(void);
+Specialist_type_id best_luxury_specialist(void);
const char *specialists_string(const int *specialists);
int get_temple_power(const struct city *pcity);
int get_cathedral_power(const struct city *pcity);
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.6
diff -u -r1.6 fc_types.h
--- common/fc_types.h 6 Sep 2004 02:05:31 -0000 1.6
+++ common/fc_types.h 6 Sep 2004 03:40:41 -0000
@@ -20,7 +20,7 @@
typedef signed short Continent_id;
typedef enum tile_terrain_type Terrain_type_id;
-typedef enum specialist_type Specialist_type_id;
+typedef int Specialist_type_id;
/* TODO: Remove this enum and make this an integer when gen-eff is done. */
typedef enum {
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.184
diff -u -r1.184 game.c
--- common/game.c 4 Sep 2004 20:19:51 -0000 1.184
+++ common/game.c 6 Sep 2004 03:40:42 -0000
@@ -70,13 +70,16 @@
**************************************************************************/
int total_player_citizens(struct player *pplayer)
{
- return (pplayer->score.happy
- +pplayer->score.content
- +pplayer->score.unhappy
- +pplayer->score.angry
- +pplayer->score.scientists
- +pplayer->score.elvis
- +pplayer->score.taxmen);
+ int count = (pplayer->score.happy
+ +pplayer->score.content
+ +pplayer->score.unhappy
+ +pplayer->score.angry), sp;
+
+ for (sp = 0; sp < SP_COUNT; sp++) {
+ count += pplayer->score.specialists[sp];
+ }
+
+ return count;
}
/**************************************************************************
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.150
diff -u -r1.150 game.h
--- common/game.h 6 Sep 2004 02:58:11 -0000 1.150
+++ common/game.h 6 Sep 2004 03:40:42 -0000
@@ -189,10 +189,15 @@
/* values from game.ruleset */
struct {
- struct {
+ struct specialist_type {
char name[MAX_LEN_NAME];
- int min_size, bonus;
- } specialists[SP_COUNT];
+ int min_size;
+ int bonus_sci, bonus_tax, bonus_lux;
+ } specialists[MAX_NUM_SPECIALISTS];
+#define DEFAULT_SPECIALIST game.rgame.default_specialist
+#define SP_COUNT game.rgame.num_specialist_types
+ int default_specialist, num_specialist_types;
+
bool changable_tax;
int forced_science; /* only relevant if !changable_tax */
int forced_luxury;
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.47
diff -u -r1.47 packets.def
--- common/packets.def 6 Sep 2004 02:58:11 -0000 1.47
+++ common/packets.def 6 Sep 2004 03:40:42 -0000
@@ -391,7 +391,7 @@
UINT8 ppl_happy[5], ppl_content[5], ppl_unhappy[5], ppl_angry[5];
- UINT8 specialists[SP_COUNT];
+ UINT8 specialists[MAX_NUM_SPECIALISTS];
UINT16 food_prod, shield_prod, trade_prod;
SINT16 food_surplus, shield_surplus, tile_trade;
@@ -967,9 +967,12 @@
end
PACKET_RULESET_GAME=97;sc,lsend
- STRING specialist_name[SP_COUNT][MAX_LEN_NAME];
- UINT8 specialist_min_size[SP_COUNT];
- UINT8 specialist_bonus[SP_COUNT];
+ UINT8 default_specialist, num_specialist_types;
+ STRING
specialist_name[MAX_NUM_SPECIALISTS:num_specialist_types][MAX_LEN_NAME];
+ UINT8 specialist_min_size[MAX_NUM_SPECIALISTS:num_specialist_types];
+ UINT8 specialist_bonus_sci[MAX_NUM_SPECIALISTS:num_specialist_types];
+ UINT8 specialist_bonus_tax[MAX_NUM_SPECIALISTS:num_specialist_types];
+ UINT8 specialist_bonus_lux[MAX_NUM_SPECIALISTS:num_specialist_types];
BOOL changable_tax;
UINT8 forced_science;
UINT8 forced_luxury;
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.150
diff -u -r1.150 player.c
--- common/player.c 29 Aug 2004 19:03:31 -0000 1.150
+++ common/player.c 6 Sep 2004 03:40:42 -0000
@@ -419,8 +419,10 @@
get_tax_income(pplayer, trade, &sci, &lux, &tax);
income += tax;
- income += pcity->specialists[SP_TAXMAN]
- * game.rgame.specialists[SP_TAXMAN].bonus;
+ specialist_type_iterate(sp) {
+ income
+ += pcity->specialists[sp] * game.rgame.specialists[sp].bonus_tax;
+ } specialist_type_iterate_end;
income += get_city_tithes_bonus(pcity);
/* Improvement upkeep. */
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.122
diff -u -r1.122 player.h
--- common/player.h 3 Sep 2004 04:22:37 -0000 1.122
+++ common/player.h 6 Sep 2004 03:40:42 -0000
@@ -103,9 +103,7 @@
int content;
int unhappy;
int angry;
- int taxmen;
- int scientists;
- int elvis;
+ int specialists[MAX_NUM_SPECIALISTS];
int wonders;
int techs;
int techout;
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.41
diff -u -r1.41 cm.c
--- common/aicore/cm.c 6 Sep 2004 02:13:16 -0000 1.41
+++ common/aicore/cm.c 6 Sep 2004 03:40:43 -0000
@@ -149,27 +149,8 @@
#define SHOW_CM_STORAGE_USED FALSE
#define DISABLE_CACHE3 FALSE
-#define NUM_SPECIALISTS_ROLES 3
#define MAX_FIELDS_USED (CITY_TILES - 1)
-/*
- * Maps (trade, taxmen) -> (gold_production, gold_surplus)
- * Maps (trade, entertainers) -> (luxury_production, luxury_surplus)
- * Maps (trade, scientists) -> (science_production, science_surplus)
- * Maps (luxury, workers) -> (city_is_in_disorder, city_is_happy)
- */
-static struct {
- int allocated_trade, allocated_size, allocated_luxury;
-
- struct secondary_stat {
- bool is_valid;
- short int surplus;
- } *secondary_stats;
- struct city_status {
- bool is_valid, disorder, happy;
- } *city_status;
-} cache2;
-
/*
* Contains all combinations. Caches all the data about a city across
* multiple cm_query_result calls about the same city.
@@ -187,7 +168,9 @@
struct results_set {
struct combination {
- int max_scientists, max_taxmen, worker;
+ int worker;
+ int max_specialists[MAX_NUM_SPECIALISTS];
+ int cache1_size;
int production2[NUM_PRIMARY_STATS];
enum city_tile_type worker_positions[CITY_MAP_SIZE][CITY_MAP_SIZE];
@@ -213,7 +196,7 @@
int queries;
struct cache_stats {
int hits, misses;
- } cache1, cache2, cache3;
+ } cache1, cache3;
} stats;
/*
@@ -236,6 +219,9 @@
} city_map_checked_iterate_end; \
}
+/* The specialist with best luxury production. */
+static int best_entertainer;
+
/****************************************************************************
* implementation of utility functions (these are relatively independent
* of the algorithms used)
@@ -383,10 +369,8 @@
freelog(LOG_NORMAL, "print_city(city='%s'(id=%d))",
pcity->name, pcity->id);
freelog(LOG_NORMAL,
- " size=%d, entertainers=%d, scientists=%d, taxmen=%d",
- pcity->size, pcity->specialists[SP_ELVIS],
- pcity->specialists[SP_SCIENTIST],
- pcity->specialists[SP_TAXMAN]);
+ " size=%d, specialists=%s",
+ pcity->size, specialists_string(pcity->specialists));
freelog(LOG_NORMAL, " workers at:");
my_city_map_iterate(pcity, x, y) {
if (pcity->city_map[x][y] == C_TILE_WORKER) {
@@ -508,105 +492,9 @@
}
/****************************************************************************
- Wraps the array access to cache2.secondary_stats.
-*****************************************************************************/
-static struct secondary_stat *get_secondary_stat(int trade, int specialists,
- Specialist_type_id
- specialist_type)
-{
- freelog(LOG_DEBUG, "second: trade=%d spec=%d type=%d", trade, specialists,
- specialist_type);
-
- assert(trade >= 0 && trade < cache2.allocated_trade);
- assert(specialists >= 0 && specialists < cache2.allocated_size);
-
- return &cache2.secondary_stats[NUM_SPECIALISTS_ROLES *
- (cache2.allocated_size * trade +
- specialists) + specialist_type];
-}
-
-/****************************************************************************
- Wraps the array access to cache2.city_status.
-*****************************************************************************/
-static struct city_status *get_city_status(int luxury, int workers)
-{
- freelog(LOG_DEBUG, "status: lux=%d worker=%d", luxury, workers);
-
- assert(luxury >=0 && luxury < cache2.allocated_luxury);
- assert(workers >= 0 && workers < cache2.allocated_size);
-
- return &cache2.city_status[cache2.allocated_size * luxury + workers];
-}
-
-/****************************************************************************
- Update the cache2 according to the filled out result. If the info is
- already in the cache check that the two match.
-*****************************************************************************/
-static void update_cache2(struct city *pcity,
- const struct cm_result *const result)
-{
- struct secondary_stat *p;
- struct city_status *q;
-
- /*
- * Science is set to 0 if the city is unhappy/in disorder. See
- * unhappy_city_check.
- */
- if (!result->disorder) {
- p = get_secondary_stat(result->surplus[TRADE],
- result->specialists[SP_SCIENTIST],
- SP_SCIENTIST);
- if (!p->is_valid) {
- p->surplus = result->surplus[SCIENCE];
- p->is_valid = TRUE;
- } else {
- assert(p->surplus == result->surplus[SCIENCE]);
- }
- }
-
- /*
- * Gold is set to 0 if the city is unhappy/in disorder. See
- * unhappy_city_check.
- */
- if (!result->disorder) {
- p = get_secondary_stat(result->surplus[TRADE],
- result->specialists[SP_TAXMAN],
- SP_TAXMAN);
- if (!p->is_valid && !result->disorder) {
- p->surplus = result->surplus[GOLD];
- p->is_valid = TRUE;
- } else {
- assert(p->surplus == result->surplus[GOLD]);
- }
- }
-
- p = get_secondary_stat(result->surplus[TRADE],
- result->specialists[SP_ELVIS],
- SP_ELVIS);
- if (!p->is_valid) {
- p->surplus = result->surplus[LUXURY];
- p->is_valid = TRUE;
- } else {
- if (!result->disorder) {
- assert(p->surplus == result->surplus[LUXURY]);
- }
- }
-
- q = get_city_status(result->surplus[LUXURY],
- cm_count_worker(pcity, result));
- if (!q->is_valid) {
- q->disorder = result->disorder;
- q->happy = result->happy;
- q->is_valid = TRUE;
- } else {
- assert(q->disorder == result->disorder && q->happy == result->happy);
- }
-}
-
-/****************************************************************************
Clear the results of the cache. Does NOT free all storage; arrays stay
allocated so we don't thrash memory.
-****************************************************************************/
+*****************************************************************************/
static void clear_cache(void)
{
int i, j;
@@ -659,9 +547,9 @@
}
} my_city_map_iterate_end;
- pcity->specialists[SP_ELVIS] = result->specialists[SP_ELVIS];
- pcity->specialists[SP_SCIENTIST] = result->specialists[SP_SCIENTIST];
- pcity->specialists[SP_TAXMAN] = result->specialists[SP_TAXMAN];
+ specialist_type_iterate(sp) {
+ pcity->specialists[sp] = result->specialists[sp];
+ } specialist_type_iterate_end;
/* Do a local recalculation of the city */
generic_city_refresh(pcity, FALSE, NULL);
@@ -680,7 +568,6 @@
result->surplus[LUXURY],
result->surplus[GOLD],
result->disorder ? "yes" : "no", result->happy ? "yes" : "no");
- update_cache2(pcity, result);
}
/****************************************************************************
@@ -791,7 +678,6 @@
#if SHOW_CACHE_STATS
report_one_cache_stat(&stats.cache1, "CACHE1");
- report_one_cache_stat(&stats.cache2, "CACHE2");
report_one_cache_stat(&stats.cache3, "CACHE3");
#endif
@@ -804,38 +690,74 @@
algorithmic functions
*****************************************************************************/
+static int combination_spec_index(struct combination *combination,
+ int *specialists)
+{
+ int sp, index = 0;
+
+ for (sp = 0; sp < SP_COUNT; sp++) {
+ if (sp == best_entertainer) {
+ continue;
+ }
+
+ index *= combination->max_specialists[sp] + 1;
+ index += specialists[sp];
+ }
+
+ return index;
+}
+
/****************************************************************************
Frontend cache for real_fill_out_result. This method tries to avoid
calling real_fill_out_result by all means.
*****************************************************************************/
static void fill_out_result(struct city *pcity, struct cm_result *result,
struct combination *base_combination,
- int scientists, int taxmen)
+ int *specialists)
{
struct cm_result *slot;
- bool got_all;
+ int sp;
+ bool all_zero = TRUE;
/*
* First try to get a filled out result from cache1 or from the
* all_entertainer result.
*/
- if (scientists == 0 && taxmen == 0) {
+ for (sp = 0; sp < SP_COUNT; sp++) {
+ if (sp != best_entertainer
+ && specialists[sp] != 0) {
+ /* I used to call combination_spec_index up above. Then if all
+ * the specialists were zero the index would be zero. Duh. But
+ * in some cases (with all 0's) the max_specialists fields are not
+ * filled out. This
+ * causes valgrind to give a spurious error. Of course 0 times and
+ * unknown value is 0, but valgrind thinks it is unknown.
+ *
+ * So, to make debugging easier I just do the check manually. */
+ all_zero = FALSE;
+ break;
+ }
+ }
+ if (all_zero) {
slot = &base_combination->all_entertainer;
} else {
- assert(scientists <= base_combination->max_scientists);
- assert(taxmen <= base_combination->max_taxmen);
+ int index = combination_spec_index(base_combination, specialists);
+
+ for (sp = 0; sp < SP_COUNT; sp++) {
+ if (sp == best_entertainer) continue;
+ assert(specialists[sp] <= base_combination->max_specialists[sp]);
+ }
assert(base_combination->cache1 != NULL);
assert(base_combination->all_entertainer.found_a_valid);
- slot = &base_combination->cache1[scientists *
- (base_combination->max_taxmen + 1) +
- taxmen];
+ slot = &base_combination->cache1[index];
}
freelog(LOG_DEBUG,
- "fill_out_result(base_comb=%p (w=%d), scientists=%d, taxmen=%d) %s",
- base_combination, base_combination->worker, scientists,
- taxmen, slot->found_a_valid ? "CACHED" : "unknown");
+ "fill_out_result(base_comb=%p (w=%d) (s=%s) %s",
+ base_combination, base_combination->worker,
+ specialists_string(specialists),
+ slot->found_a_valid ? "CACHED" : "unknown");
if (slot->found_a_valid) {
/* Cache1 contains the result */
@@ -850,84 +772,19 @@
(base_combination->worker_positions[x][y] == C_TILE_WORKER);
} my_city_map_iterate_end;
- result->specialists[SP_SCIENTIST] = scientists;
- result->specialists[SP_TAXMAN] = taxmen;
- result->specialists[SP_ELVIS] =
- pcity->size - (base_combination->worker + scientists + taxmen);
+ result->specialists[best_entertainer]
+ = pcity->size - base_combination->worker;
+ specialist_type_iterate(sp) {
+ if (sp != best_entertainer) {
+ result->specialists[sp] = specialists[sp];
+ result->specialists[best_entertainer] -= specialists[sp];
+ }
+ } specialist_type_iterate_end;
freelog(LOG_DEBUG,
"fill_out_result(city='%s'(%d), specialists=%s)",
pcity->name, pcity->id, specialists_string(result->specialists));
- /* try to fill result from cache2 */
- if (!base_combination->all_entertainer.found_a_valid) {
- got_all = FALSE;
- } else {
- struct secondary_stat *p;
- struct city_status *q;
- int i;
-
- got_all = TRUE;
-
- /*
- * fill out the primary stats that are known from the
- * all_entertainer result
- */
- for (i = 0; i < NUM_PRIMARY_STATS; i++) {
- result->surplus[i] = base_combination->all_entertainer.surplus[i];
- }
-
- p = get_secondary_stat(result->surplus[TRADE],
- result->specialists[SP_SCIENTIST],
- SP_SCIENTIST);
- if (!p->is_valid) {
- got_all = FALSE;
- } else {
- result->surplus[SCIENCE] = p->surplus;
- }
-
- p = get_secondary_stat(result->surplus[TRADE],
- result->specialists[SP_TAXMAN],
- SP_TAXMAN);
- if (!p->is_valid) {
- got_all = FALSE;
- } else {
- result->surplus[GOLD] = p->surplus;
- }
-
- p = get_secondary_stat(result->surplus[TRADE],
- result->specialists[SP_ELVIS],
- SP_ELVIS);
- if (!p->is_valid) {
- got_all = FALSE;
- } else {
- result->surplus[LUXURY] = p->surplus;
- }
-
- q = get_city_status(result->surplus[LUXURY],
- base_combination->worker);
- if (!q->is_valid) {
- got_all = FALSE;
- } else {
- result->disorder = q->disorder;
- result->happy = q->happy;
- }
- }
-
- if (got_all) {
- /*
- * All secondary stats and the city status have been filled from
- * cache2.
- */
-
- stats.cache2.hits++;
- memcpy(slot, result, sizeof(struct cm_result));
- slot->found_a_valid = TRUE;
- return;
- }
-
- stats.cache2.misses++;
-
/*
* Result can't be constructed from caches. Do the slow
* re-calculation.
@@ -1078,86 +935,6 @@
}
/****************************************************************************
- Expand the secondary_stats and city_status fields of cache2 if this
- is necessary. For this the function tries to estimate the upper limit
- of trade and luxury. It will also invalidate cache2.
-*****************************************************************************/
-static void ensure_invalid_cache2(struct city *pcity, int total_tile_trade)
-{
- bool change_size = FALSE;
- int backup,i, luxury, total_trade = total_tile_trade;
-
- /* Hack since trade_between_cities accesses pcity->tile_trade */
- backup = pcity->tile_trade;
- pcity->tile_trade = total_tile_trade;
- for (i = 0; i < NUM_TRADEROUTES; i++) {
- struct city *pc2 = find_city_by_id(pcity->trade[i]);
-
- total_trade += trade_between_cities(pcity, pc2);
- }
- pcity->tile_trade = backup;
-
- /*
- * Estimate an upper limit for the luxury. We assume that the player
- * has set the luxury rate to 100%. There are two extremal cases: all
- * citizen are entertainers (yielding a luxury of "(pcity->size * 2
- * * get_city_luxury_bonus(pcity))/100" = A) or all citizen are
- * working on tiles and the resulting trade is converted to luxury
- * (yielding a luxury of "(total_trade * get_city_luxury_bonus(pcity))
- * / 100" = B) . We can't use MAX(A, B) since there may be cases in
- * between them which are better than these two exremal cases. So we
- * use A+B as upper limit.
- */
- luxury
- = ((pcity->size * 2 + total_trade) * get_city_luxury_bonus(pcity)) / 100;
-
- /* +1 because we want to index from 0 to pcity->size inclusive */
- if (pcity->size + 1 > cache2.allocated_size) {
- cache2.allocated_size = pcity->size + 1;
- change_size = TRUE;
- }
-
- if (total_trade + 1 > cache2.allocated_trade) {
- cache2.allocated_trade = total_trade + 1;
- change_size = TRUE;
- }
-
- if (luxury + 1 > cache2.allocated_luxury) {
- cache2.allocated_luxury = luxury + 1;
- change_size = TRUE;
- }
-
- if (change_size) {
- freelog(LOG_DEBUG,
- "CM: expanding cache2 to size=%d, trade=%d, luxury=%d",
- cache2.allocated_size, cache2.allocated_trade,
- cache2.allocated_luxury);
- if (cache2.secondary_stats) {
- free(cache2.secondary_stats);
- cache2.secondary_stats = NULL;
- }
- cache2.secondary_stats =
- fc_malloc(cache2.allocated_trade * cache2.allocated_size *
- NUM_SPECIALISTS_ROLES * sizeof(struct secondary_stat));
-
- if (cache2.city_status) {
- free(cache2.city_status);
- cache2.city_status = NULL;
- }
- cache2.city_status =
- fc_malloc(cache2.allocated_luxury * cache2.allocated_size *
- sizeof(struct city_status));
- }
-
- /* Make cache2 invalid */
- memset(cache2.secondary_stats, 0,
- cache2.allocated_trade * cache2.allocated_size *
- NUM_SPECIALISTS_ROLES * sizeof(struct secondary_stat));
- memset(cache2.city_status, 0,
- cache2.allocated_luxury * cache2.allocated_size *
- sizeof(struct city_status));
-}
-/****************************************************************************
Setup. Adds the root combination (the combination which doesn't use
any worker but the production of the city center). Incrementaly calls
expand_cache3.
@@ -1234,8 +1011,6 @@
for (i = 1; i <= MIN(cache3.fields_available_total, pcity->size); i++) {
expand_cache3(pcity, i, &tile_stats);
}
-
- ensure_invalid_cache2(pcity, total_tile_trade);
}
/****************************************************************************
@@ -1249,28 +1024,35 @@
int *best_minor_fitness)
{
int worker = base_combination->worker;
- int specialists = pcity->size - worker;
- int scientists, taxmen;
+ int num_specialists = pcity->size - worker;
+ int index;
if (!base_combination->cache1) {
/* setup cache1 */
- int i, items;
+ int i, items = 1, sp;
- if (city_can_use_specialist(pcity, SP_SCIENTIST)) {
- base_combination->max_scientists = specialists;
- } else {
- base_combination->max_scientists = 0;
- }
+ for (sp = 0; sp < SP_COUNT; sp++) {
+ int max;
- if (city_can_use_specialist(pcity, SP_TAXMAN)) {
- base_combination->max_taxmen = specialists;
- } else {
- base_combination->max_taxmen = 0;
+ if (sp == best_entertainer) {
+ base_combination->max_specialists[sp] = num_specialists;
+ assert(city_can_use_specialist(pcity, sp));
+ continue;
+ }
+
+ if (city_can_use_specialist(pcity, sp)) {
+ max = num_specialists;
+ } else {
+ max = 0;
+ }
+
+ base_combination->max_specialists[sp] = max;
+ items *= (max + 1);
}
- items = (base_combination->max_scientists + 1) *
- (base_combination->max_taxmen + 1);
+
+ base_combination->cache1_size = items;
base_combination->cache1 =
fc_malloc(sizeof(struct cm_result) * items);
for (i = 0; i < items; i++) {
@@ -1280,54 +1062,72 @@
best_result->found_a_valid = FALSE;
- for (scientists = 0;
- scientists <= base_combination->max_scientists; scientists++) {
- for (taxmen = 0;
- taxmen <= base_combination->max_taxmen - scientists; taxmen++) {
- int major_fitness, minor_fitness;
- struct cm_result result;
+ for (index = 0; index < base_combination->cache1_size; index++) {
+ int specialists[SP_COUNT], sp, count = 0, myindex = index;
+ int major_fitness, minor_fitness;
+ struct cm_result result;
+
+ for (sp = SP_COUNT - 1; sp >= 0; sp--) {
+ /* This loop is the inverse of combination_spec_index(). */
+ int max = base_combination->max_specialists[sp] + 1;
- freelog(FIND_BEST_SPECIALIST_ARRANGEMENT_LOG_LEVEL,
- " optimize_people: using (W/E/S/T) %d/%d/%d/%d",
- worker, pcity->size - (worker + scientists + taxmen),
- scientists, taxmen);
+ if (sp == best_entertainer) {
+ continue;
+ }
+ if (max == 0) {
+ specialists[sp] = 0;
+ continue;
+ }
- fill_out_result(pcity, &result, base_combination, scientists,
- taxmen);
+ specialists[sp] = myindex % max;
+ myindex /= max;
- freelog(FIND_BEST_SPECIALIST_ARRANGEMENT_LOG_LEVEL,
- " optimize_people: got extra=(tax=%d, luxury=%d, "
- "science=%d)",
- result.surplus[GOLD] - parameter->minimal_surplus[GOLD],
- result.surplus[LUXURY] -
- parameter->minimal_surplus[LUXURY],
- result.surplus[SCIENCE] -
- parameter->minimal_surplus[SCIENCE]);
+ count += specialists[sp];
+ }
+ if (count > num_specialists) {
+ /* FIXME: cache1 is much bigger than it needs to be! */
+ continue;
+ }
+ specialists[best_entertainer] = num_specialists - count;
- if (!is_valid_result(parameter, &result)) {
- freelog(FIND_BEST_SPECIALIST_ARRANGEMENT_LOG_LEVEL,
- " optimize_people: doesn't have enough surplus or disorder");
- continue;
- }
+ freelog(FIND_BEST_SPECIALIST_ARRANGEMENT_LOG_LEVEL,
+ " optimize_people: using (W/E/S/T) %d/%s",
+ worker, specialists_string(specialists));
- calc_fitness(pcity, parameter, &result, &major_fitness,
- &minor_fitness);
+ fill_out_result(pcity, &result, base_combination, specialists);
+ freelog(FIND_BEST_SPECIALIST_ARRANGEMENT_LOG_LEVEL,
+ " optimize_people: got extra=(tax=%d, luxury=%d, "
+ "science=%d)",
+ result.surplus[GOLD] - parameter->minimal_surplus[GOLD],
+ result.surplus[LUXURY] -
+ parameter->minimal_surplus[LUXURY],
+ result.surplus[SCIENCE] -
+ parameter->minimal_surplus[SCIENCE]);
+
+ if (!is_valid_result(parameter, &result)) {
freelog(FIND_BEST_SPECIALIST_ARRANGEMENT_LOG_LEVEL,
- " optimize_people: fitness=(%d,%d)", major_fitness,
- minor_fitness);
+ " optimize_people: doesn't have enough surplus or disorder");
+ continue;
+ }
- result.found_a_valid = TRUE;
- if (!best_result->found_a_valid
- || ((major_fitness > *best_major_fitness)
- || (major_fitness == *best_major_fitness
- && minor_fitness > *best_minor_fitness))) {
- memcpy(best_result, &result, sizeof(struct cm_result));
- *best_major_fitness = major_fitness;
- *best_minor_fitness = minor_fitness;
- }
- } /* for taxmen */
- } /* for scientists */
+ calc_fitness(pcity, parameter, &result, &major_fitness,
+ &minor_fitness);
+
+ freelog(FIND_BEST_SPECIALIST_ARRANGEMENT_LOG_LEVEL,
+ " optimize_people: fitness=(%d,%d)", major_fitness,
+ minor_fitness);
+
+ result.found_a_valid = TRUE;
+ if (!best_result->found_a_valid
+ || ((major_fitness > *best_major_fitness)
+ || (major_fitness == *best_major_fitness
+ && minor_fitness > *best_minor_fitness))) {
+ memcpy(best_result, &result, sizeof(struct cm_result));
+ *best_major_fitness = major_fitness;
+ *best_minor_fitness = minor_fitness;
+ }
+ }
}
/****************************************************************************
@@ -1359,11 +1159,18 @@
struct combination *current = results->combinations[i];
int major_fitness, minor_fitness;
struct cm_result result;
+ int specialists[SP_COUNT], sp;
freelog(OPTIMIZE_FINAL_LOG_LEVEL2, " trying combination %d", i);
/* this will set the all_entertainer result */
- fill_out_result(pcity, &result, current, 0, 0);
+ // memset(specialists, 0, sizeof(specialists));
+ for (sp = 0; sp < SP_COUNT; sp++) {
+ specialists[sp] = 0;
+ }
+ /* FIXME: although specialists[i] == 0 max_specialists[i] has not
+ * been filled out. Is this a bug? At the least it's risky... */
+ fill_out_result(pcity, &result, current, specialists);
/*
@@ -1462,16 +1269,6 @@
free_timer(stats.wall_timer);
stats.wall_timer = NULL;
- free(cache2.secondary_stats);
- cache2.secondary_stats = NULL;
-
- free(cache2.city_status);
- cache2.city_status = NULL;
-
- cache2.allocated_size = 0;
- cache2.allocated_trade = 0;
- cache2.allocated_luxury = 0;
-
clear_cache();
for (i = 0; i <= MAX_FIELDS_USED; i++) {
free(cache3.results[i].combinations);
Index: common/aicore/cm.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.h,v
retrieving revision 1.10
diff -u -r1.10 cm.h
--- common/aicore/cm.h 22 Jul 2004 15:20:47 -0000 1.10
+++ common/aicore/cm.h 6 Sep 2004 03:40:43 -0000
@@ -49,7 +49,7 @@
int surplus[NUM_STATS];
bool worker_positions_used[CITY_MAP_SIZE][CITY_MAP_SIZE];
- int specialists[SP_COUNT];
+ int specialists[MAX_NUM_SPECIALISTS];
};
void cm_init(void);
Index: data/default/cities.ruleset
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/default/cities.ruleset,v
retrieving revision 1.11
diff -u -r1.11 cities.ruleset
--- data/default/cities.ruleset 9 Jun 2004 04:39:13 -0000 1.11
+++ data/default/cities.ruleset 6 Sep 2004 03:40:43 -0000
@@ -21,14 +21,13 @@
; the city is of a certain size.
[specialist]
-; Changing the order or names of specialists will break things
types = "elvis", "scientist", "taxman"
elvis_min_size = 0
-elvis_base_bonus = 2
+elvis_bonus_lux = 2
scientist_min_size = 5
-scientist_base_bonus = 3
+scientist_bonus_sci = 3
taxman_min_size = 5
-taxman_base_bonus = 3
+taxman_bonus_tax = 3
changable_tax = 1
;forced_science = 0
Index: server/cityhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v
retrieving revision 1.135
diff -u -r1.135 cityhand.c
--- server/cityhand.c 6 Sep 2004 02:05:31 -0000 1.135
+++ server/cityhand.c 6 Sep 2004 03:40:43 -0000
@@ -106,7 +106,7 @@
}
if (is_worker_here(pcity, worker_x, worker_y)) {
server_remove_worker_city(pcity, worker_x, worker_y);
- pcity->specialists[SP_ELVIS]++;
+ pcity->specialists[DEFAULT_SPECIALIST]++;
city_refresh(pcity);
sync_cities();
} else {
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.271
diff -u -r1.271 citytools.c
--- server/citytools.c 31 Aug 2004 04:40:50 -0000 1.271
+++ server/citytools.c 6 Sep 2004 03:40:44 -0000
@@ -1525,9 +1525,9 @@
packet->ppl_unhappy[i]=pcity->ppl_unhappy[i];
packet->ppl_angry[i]=pcity->ppl_angry[i];
}
- packet->specialists[SP_ELVIS] = pcity->specialists[SP_ELVIS];
- packet->specialists[SP_SCIENTIST] = pcity->specialists[SP_SCIENTIST];
- packet->specialists[SP_TAXMAN] = pcity->specialists[SP_TAXMAN];
+ specialist_type_iterate(sp) {
+ packet->specialists[sp] = pcity->specialists[sp];
+ } specialist_type_iterate_end;
for (i = 0; i < NUM_TRADEROUTES; i++) {
packet->trade[i]=pcity->trade[i];
packet->trade_value[i]=pcity->trade_value[i];
@@ -1989,7 +1989,7 @@
case C_TILE_WORKER:
if (!is_available) {
server_set_tile_city(pcity, city_x, city_y, C_TILE_UNAVAILABLE);
- pcity->specialists[SP_ELVIS]++; /* keep city sanity */
+ pcity->specialists[DEFAULT_SPECIALIST]++; /* keep city sanity */
auto_arrange_workers(pcity); /* will place the displaced */
city_refresh(pcity);
send_city_info(NULL, pcity);
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.259
diff -u -r1.259 cityturn.c
--- server/cityturn.c 4 Sep 2004 20:19:51 -0000 1.259
+++ server/cityturn.c 6 Sep 2004 03:40:44 -0000
@@ -374,6 +374,8 @@
**************************************************************************/
bool city_reduce_size(struct city *pcity, int pop_loss)
{
+ int i;
+
if (pop_loss == 0) {
return TRUE;
}
@@ -391,16 +393,15 @@
/* First try to kill off the specialists */
while (pop_loss > 0 && city_specialists(pcity) > 0) {
- if (pcity->specialists[SP_TAXMAN] > 0) {
- pcity->specialists[SP_TAXMAN]--;
- } else if (pcity->specialists[SP_SCIENTIST] > 0) {
- pcity->specialists[SP_SCIENTIST]--;
- } else {
- assert(pcity->specialists[SP_ELVIS] > 0);
- pcity->specialists[SP_ELVIS]--;
+ for (i = SP_COUNT - 1; i >= 0; i--) {
+ if (pcity->specialists[i] > 0) {
+ pcity->specialists[i]--;
+ pop_loss--;
+ break;
+ }
}
- pop_loss--;
}
+ assert(pop_loss == 0 || city_specialists(pcity) == 0);
/* we consumed all the pop_loss in specialists */
if (pop_loss == 0) {
@@ -434,6 +435,7 @@
bool has_granary = city_got_effect(pcity, B_GRANARY);
bool rapture_grow = city_rapture_grow(pcity); /* check before size increase!
*/
int new_food;
+ int best_sci = best_science_specialist(), best_tax = best_tax_specialist();
if (!city_got_building(pcity, B_AQUEDUCT)
&& pcity->size>=game.aqueduct_size) {/* need aqueduct */
@@ -494,18 +496,17 @@
have_square = TRUE;
}
} city_map_iterate_end;
- if (((pcity->food_surplus >= 2) || !have_square) && pcity->size >= 5 &&
- (is_city_option_set(pcity, CITYO_NEW_EINSTEIN) ||
- is_city_option_set(pcity, CITYO_NEW_TAXMAN))) {
-
- if (is_city_option_set(pcity, CITYO_NEW_EINSTEIN)) {
- pcity->specialists[SP_SCIENTIST]++;
- } else { /* now pcity->city_options & (1<<CITYO_NEW_TAXMAN) is true */
- pcity->specialists[SP_TAXMAN]++;
- }
+ if ((pcity->food_surplus >= 2 || !have_square)
+ && is_city_option_set(pcity, CITYO_NEW_EINSTEIN)
+ && pcity->size >= game.rgame.specialists[best_sci].min_size) {
+ pcity->specialists[best_sci]++;
+ } else if ((pcity->food_surplus >= 2 || !have_square)
+ && is_city_option_set(pcity, CITYO_NEW_TAXMAN)
+ && pcity->size >= game.rgame.specialists[best_tax].min_size) {
+ pcity->specialists[best_tax]++;
} else {
- pcity->specialists[SP_TAXMAN]++; /* or else city is !sane */
+ pcity->specialists[DEFAULT_SPECIALIST]++; /* or else city is !sane */
auto_arrange_workers(pcity);
}
Index: server/report.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/report.c,v
retrieving revision 1.54
diff -u -r1.54 report.c
--- server/report.c 4 Sep 2004 20:36:10 -0000 1.54
+++ server/report.c 6 Sep 2004 03:40:44 -0000
@@ -492,19 +492,15 @@
return pplayer->score.unhappy;
}
-static int get_taxmen(struct player *pplayer)
+static int get_specialists(struct player *pplayer)
{
- return pplayer->score.taxmen;
-}
+ int i, count = 0;
-static int get_scientists(struct player *pplayer)
-{
- return pplayer->score.scientists;
-}
+ for (i = 0; i < SP_COUNT; i++) {
+ count += pplayer->score.specialists[i];
+ }
-static int get_elvis(struct player *pplayer)
-{
- return pplayer->score.elvis;
+ return count;
}
static int get_gov(struct player *pplayer)
@@ -901,9 +897,7 @@
{"happypop", get_happypop},
{"contentpop", get_contentpop},
{"unhappypop", get_unhappypop},
- {"taxmen", get_taxmen},
- {"scientists", get_scientists},
- {"elvis", get_elvis},
+ {"specialists", get_specialists},
{"gov", get_gov},
{"corruption", get_corruption} /* new 1.11.5 tags end here */
};
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.193
diff -u -r1.193 ruleset.c
--- server/ruleset.c 6 Sep 2004 02:58:12 -0000 1.193
+++ server/ruleset.c 6 Sep 2004 03:40:45 -0000
@@ -2541,11 +2541,6 @@
/* Specialist options */
specialist_names = secfile_lookup_str_vec(file, &nval, "specialist.types");
- if (nval != SP_COUNT) {
- freelog(LOG_FATAL, "There must be exactly %d types of specialist.",
- SP_COUNT);
- exit(EXIT_FAILURE);
- }
for (i = 0; i < nval; i++) {
const char *name = specialist_names[i];
@@ -2553,10 +2548,20 @@
sz_strlcpy(game.rgame.specialists[i].name, name);
game.rgame.specialists[i].min_size
= secfile_lookup_int(file, "specialist.%s_min_size", name);
- game.rgame.specialists[i].bonus
- = secfile_lookup_int(file, "specialist.%s_base_bonus", name);
-
+ game.rgame.specialists[i].bonus_sci
+ = secfile_lookup_int_default(file, 0, "specialist.%s_bonus_sci", name);
+ game.rgame.specialists[i].bonus_tax
+ = secfile_lookup_int_default(file, 0, "specialist.%s_bonus_tax", name);
+ game.rgame.specialists[i].bonus_lux
+ = secfile_lookup_int_default(file, 0, "specialist.%s_bonus_lux", name);
+
+ if (game.rgame.specialists[i].min_size == 0
+ && game.rgame.default_specialist == -1) {
+ game.rgame.default_specialist = i;
+ }
}
+ assert(game.rgame.default_specialist != -1);
+ game.rgame.num_specialist_types = nval;
game.rgame.changable_tax =
secfile_lookup_bool_default(file, TRUE, "specialist.changable_tax");
@@ -2571,11 +2576,6 @@
freelog(LOG_FATAL, "Forced taxes do not add up in ruleset!");
exit(EXIT_FAILURE);
}
- if (game.rgame.specialists[SP_ELVIS].min_size > 0) {
- freelog(LOG_FATAL, "Elvises must be available without a "
- "city size restriction!");
- exit(EXIT_FAILURE);
- }
/* City Parameters */
@@ -3149,10 +3149,14 @@
int i;
struct packet_ruleset_game misc_p;
+ misc_p.num_specialist_types = game.rgame.num_specialist_types;
+ misc_p.default_specialist = game.rgame.default_specialist;
specialist_type_iterate(sp) {
sz_strlcpy(misc_p.specialist_name[sp], game.rgame.specialists[sp].name);
misc_p.specialist_min_size[sp] = game.rgame.specialists[sp].min_size;
- misc_p.specialist_bonus[sp] = game.rgame.specialists[sp].bonus;
+ misc_p.specialist_bonus_sci[sp] = game.rgame.specialists[sp].bonus_sci;
+ misc_p.specialist_bonus_tax[sp] = game.rgame.specialists[sp].bonus_tax;
+ misc_p.specialist_bonus_lux[sp] = game.rgame.specialists[sp].bonus_lux;
} specialist_type_iterate_end;
misc_p.changable_tax = game.rgame.changable_tax;
misc_p.forced_science = game.rgame.forced_science;
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.50
diff -u -r1.50 sanitycheck.c
--- server/sanitycheck.c 29 Aug 2004 19:38:07 -0000 1.50
+++ server/sanitycheck.c 6 Sep 2004 03:40:45 -0000
@@ -235,9 +235,9 @@
}
} city_map_iterate_end;
if (workers + city_specialists(pcity) != pcity->size + 1) {
- die("%s is illegal (size%d w%d e%d t%d s%d) in %s line %d",
- pcity->name, pcity->size, workers, pcity->specialists[SP_ELVIS],
- pcity->specialists[SP_TAXMAN], pcity->specialists[SP_SCIENTIST], file,
line);
+ die("%s is illegal (size%d w%d s%s) in %s line %d",
+ pcity->name, pcity->size, workers,
+ specialists_string(pcity->specialists), file, line);
}
}
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.184
diff -u -r1.184 savegame.c
--- server/savegame.c 4 Sep 2004 21:25:57 -0000 1.184
+++ server/savegame.c 6 Sep 2004 03:40:46 -0000
@@ -1912,7 +1912,7 @@
/* oops, inconsistent savegame; minimal fix: */
freelog(LOG_VERBOSE, "Inconsistent worked for %s (%d,%d), "
"converting to elvis", pcity->name, x, y);
- pcity->specialists[SP_ELVIS]++;
+ pcity->specialists[DEFAULT_SPECIALIST]++;
set_worker_city(pcity, x, y, C_TILE_UNAVAILABLE);
} else {
set_worker_city(pcity, x, y, C_TILE_WORKER);
@@ -2781,7 +2781,7 @@
int map_x, map_y;
bool is_real;
- pcity->specialists[SP_ELVIS]++;
+ pcity->specialists[DEFAULT_SPECIALIST]++;
set_worker_city(pcity, x, y, C_TILE_UNAVAILABLE);
freelog(LOG_DEBUG, "Worked tile was unavailable!");
Index: server/score.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/score.c,v
retrieving revision 1.6
diff -u -r1.6 score.c
--- server/score.c 3 Sep 2004 01:21:03 -0000 1.6
+++ server/score.c 6 Sep 2004 03:40:46 -0000
@@ -383,9 +383,9 @@
pplayer->score.content = 0;
pplayer->score.unhappy = 0;
pplayer->score.angry = 0;
- pplayer->score.taxmen = 0;
- pplayer->score.scientists = 0;
- pplayer->score.elvis = 0;
+ specialist_type_iterate(sp) {
+ pplayer->score.specialists[sp] = 0;
+ } specialist_type_iterate_end;
pplayer->score.wonders = 0;
pplayer->score.techs = 0;
pplayer->score.techout = 0;
@@ -412,9 +412,9 @@
pplayer->score.content += pcity->ppl_content[4];
pplayer->score.unhappy += pcity->ppl_unhappy[4];
pplayer->score.angry += pcity->ppl_angry[4];
- pplayer->score.taxmen += pcity->specialists[SP_TAXMAN];
- pplayer->score.scientists += pcity->specialists[SP_SCIENTIST];
- pplayer->score.elvis += pcity->specialists[SP_ELVIS];
+ specialist_type_iterate(sp) {
+ pplayer->score.specialists[sp] += pcity->specialists[sp];
+ } specialist_type_iterate_end;
pplayer->score.population += city_population(pcity);
pplayer->score.cities++;
pplayer->score.pollution += pcity->pollution;
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.303
diff -u -r1.303 unithand.c
--- server/unithand.c 26 Aug 2004 18:37:52 -0000 1.303
+++ server/unithand.c 6 Sep 2004 03:40:46 -0000
@@ -479,7 +479,7 @@
assert(unit_pop_value(punit->type) > 0);
pcity->size += unit_pop_value(punit->type);
/* Make the new people something, otherwise city fails the checks */
- pcity->specialists[SP_TAXMAN] += unit_pop_value(punit->type);
+ pcity->specialists[DEFAULT_SPECIALIST] += unit_pop_value(punit->type);
auto_arrange_workers(pcity);
wipe_unit(punit);
send_city_info(NULL, pcity);
|
|