[freeciv-ai] (PR#11399) another AI providers patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11399 >
I simplified this patch a bit. Jason, have a look.
- Per
Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.123
diff -u -r1.123 advdomestic.c
--- ai/advdomestic.c 8 Dec 2004 04:18:09 -0000 1.123
+++ ai/advdomestic.c 10 Dec 2004 17:44:29 -0000
@@ -147,11 +147,6 @@
struct government *gov = get_gov_pplayer(pplayer);
/* Unit type with certain role */
Unit_Type_id unit_type;
- /* Food surplus assuming that workers and elvii are already accounted for
- * and properly balanced. */
- int est_food = pcity->surplus[O_FOOD]
- + 2 * pcity->specialists[SP_SCIENTIST]
- + 2 * pcity->specialists[SP_TAXMAN];
init_choice(choice);
@@ -159,8 +154,8 @@
unit_type = best_role_unit(pcity, F_SETTLERS);
if (unit_type != U_LAST
- && est_food > utype_upkeep_cost(get_unit_type(unit_type),
- gov, O_FOOD)) {
+ && pcity->surplus[O_FOOD] > utype_upkeep_cost(get_unit_type(unit_type),
+ gov, O_FOOD)) {
/* settler_want calculated in settlers.c called from ai_manage_cities() */
int want = pcity->ai.settler_want;
@@ -182,8 +177,8 @@
unit_type = best_role_unit(pcity, F_CITIES);
if (unit_type != U_LAST
- && est_food >= utype_upkeep_cost(get_unit_type(unit_type),
- gov, O_FOOD)) {
+ && pcity->surplus[O_FOOD] >= utype_upkeep_cost(get_unit_type(unit_type),
+ gov, O_FOOD)) {
/* founder_want calculated in settlers.c, called from ai_manage_cities().
*/
int want = pcity->ai.founder_want;
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.181
diff -u -r1.181 aicity.c
--- ai/aicity.c 9 Dec 2004 20:17:46 -0000 1.181
+++ ai/aicity.c 10 Dec 2004 17:44:29 -0000
@@ -76,6 +76,33 @@
static void ai_sell_obsolete_buildings(struct city *pcity);
/**************************************************************************
+ Return the number of "luxury specialists". This is the number of
+ specialists who provide at least HAPPY_COST luxury, being the number of
+ luxuries needed to make one citizen content or happy.
+
+ The AI assumes that for any specialist that provides HAPPY_COST luxury,
+ if we can get that 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_entertainers(const struct city *pcity)
+{
+ int providers = 0;
+
+ specialist_type_iterate(i) {
+ if (game.rgame.specialists[i].bonus[O_LUXURY] >= HAPPY_COST) {
+ providers += pcity->specialists[i];
+ }
+ } specialist_type_iterate_end;
+
+ return providers;
+}
+
+/**************************************************************************
This calculates the usefulness of pcity to us. Note that you can pass
another player's ai_data structure here for evaluation by different
priorities.
@@ -275,18 +302,21 @@
/* TODO */
break;
case EFT_NO_UNHAPPY:
- v += (pcity->specialists[SP_ELVIS] + pcity->ppl_unhappy[4]) * 20;
+ v += (get_entertainers(pcity)
+ + pcity->ppl_unhappy[4]) * 20;
break;
case EFT_FORCE_CONTENT:
if (!government_has_flag(gov, G_NO_UNHAPPY_CITIZENS)) {
- v += (pcity->ppl_unhappy[4] + pcity->specialists[SP_ELVIS]) * 20;
+ v += (pcity->ppl_unhappy[4]
+ + get_entertainers(pcity)) * 20;
v += 5 * c;
}
break;
case EFT_MAKE_CONTENT_MIL_PER:
case EFT_MAKE_CONTENT:
if (!government_has_flag(gov, G_NO_UNHAPPY_CITIZENS)) {
- v += MIN(pcity->ppl_unhappy[4] + pcity->specialists[SP_ELVIS],
+ v += MIN(pcity->ppl_unhappy[4]
+ + get_entertainers(pcity),
amount) * 20;
v += MIN(amount, 5) * c;
}
@@ -1065,7 +1095,7 @@
is_valid = map_to_city_map(&city_map_x, &city_map_y, acity, ptile);
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);
}
- [freeciv-ai] (PR#11399) another AI providers patch,
Per I. Mathisen <=
|
|