Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2003:
[Freeciv-Dev] Re: (PR#4349) New tax code
Home

[Freeciv-Dev] Re: (PR#4349) New tax code

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#4349) New tax code
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 2 Jun 2003 14:15:52 -0700
Reply-to: rt@xxxxxxxxxxxxxx

On Mon, 2 Jun 2003, Per I. Mathisen wrote:
> I have not tested longer games, I predict it might find it hard to keep
> Republic or Democracy alive for long, since current AI city management
> routines are very poor at keeping dissent at bay at any cost.

Well, I tested a few longer games, and the AI does not seem to have more
than the usual problem keeping a Republic/Democracy on its feet. Once
things become problematic (as in having produced a total overkill number
of units) it switches over to Communism anyway.

> Some ideas on how the AI should be thinking about luxury tax settings
> appreciated (and I am not thinking about rapture here, we'll get to that
> later).

Is it even necessary? I am not sure. I could add some code that increased
luxuries until all cities were happy, but should we really allow a single
city let every other city suffer because it can't keep its citizens in
line? Better wait for the CM patch and let that city starve a bit. (*civ
is a bit cruel that way - it seems quite a successful tactic to starve
city populations into contentment.)

I had a look at maxbuycost, and found that the new code already figured
that one in. Cool. But I audited its use anyway, and the attached patch is
the result. Basically I make sure that we don't increase maxbuycost
unnecessarily, and remove the silly increase-maxbuycost-for-caravans
(caravans!). Also fixed bug that didn't let us upgrade units in cities in
anarchy. Finally simplified the disband-explorer code a bit.

I actually think the new tax code patch is ready now. Greg?

  - Per

Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.140
diff -u -r1.140 aicity.c
--- ai/aicity.c 30 May 2003 18:50:59 -0000      1.140
+++ ai/aicity.c 2 Jun 2003 21:03:58 -0000
@@ -55,6 +55,9 @@
 
 #include "aicity.h"
 
+#define LOG_BUY LOG_DEBUG
+
+static void resolve_city_emergency(struct player *pplayer, struct city *pcity);
 static void ai_manage_city(struct player *pplayer, struct city *pcity);
 
 /**************************************************************************
@@ -297,7 +300,17 @@
   } impr_type_iterate_end;
 }
 
-#define LOG_BUY LOG_DEBUG
+/************************************************************************** 
+  Increase maxbuycost. This is used in ai_gold_reserve().
+**************************************************************************/
+static void adjust_buylimit(struct player *pplayer, int by_how_much)
+{
+  if (pplayer->economic.gold - pplayer->ai.est_upkeep
+      < pplayer->ai.maxbuycost) {
+    pplayer->ai.maxbuycost = MAX(pplayer->ai.maxbuycost, by_how_much);
+  }
+}
+
 /************************************************************************** 
   Try to upgrade a city's units. limit is the last amount of gold we can
   end up with after the upgrade. military is if we want to upgrade non-
@@ -332,7 +345,7 @@
                  military ? "military" : "civilian");
         handle_unit_upgrade_request(city_owner(pcity), &packet);
       } else {
-        pplayer->ai.maxbuycost = MAX(pplayer->ai.maxbuycost, cost);
+        adjust_buylimit(pplayer, cost);
       }
     }
   } unit_list_iterate_end;
@@ -346,16 +359,15 @@
   struct ai_choice bestchoice;
   int cached_limit = ai_gold_reserve(pplayer);
 
-  /* Disband troops that are at home but don't serve a purpose. */
+  /* Disband explorers that are at home but don't serve a purpose. 
+   * FIXME: This is a clever hack, but should be removed once we
+   * learn how to ferry explorers to new land. */
   city_list_iterate(pplayer->cities, pcity) {
     struct tile *ptile = map_get_tile(pcity->x, pcity->y);
     unit_list_iterate(ptile->units, punit) {
-      if (((unit_types[punit->type].shield_cost > 0
-            && pcity->shield_prod == 0)
-           || unit_has_role(punit->type, L_EXPLORER))
+      if (unit_has_role(punit->type, L_EXPLORER)
           && pcity->id == punit->homecity
-          && pcity->ai.urgency == 0
-          && is_ground_unit(punit)) {
+          && pcity->ai.urgency == 0) {
         struct packet_unit_request packet;
         packet.unit_id = punit->id;
         CITY_LOG(LOG_BUY, pcity, "disbanding %s to increase production",
@@ -374,8 +386,8 @@
     /* Find highest wanted item on the buy list */
     init_choice(&bestchoice);
     city_list_iterate(pplayer->cities, acity) {
-      if (acity->anarchy != 0) continue;
-      if (acity->ai.choice.want > bestchoice.want && ai_fuzzy(pplayer, TRUE)) {
+      if (acity->ai.choice.want > bestchoice.want 
+          && ai_fuzzy(pplayer, TRUE)) {
         bestchoice.choice = acity->ai.choice.choice;
         bestchoice.want = acity->ai.choice.want;
         bestchoice.type = acity->ai.choice.type;
@@ -384,7 +396,9 @@
     } city_list_iterate_end;
 
     /* We found nothing, so we're done */
-    if (bestchoice.want == 0) break;
+    if (bestchoice.want == 0) {
+      break;
+    }
 
     /* Not dealing with this city a second time */
     pcity->ai.choice.want = 0;
@@ -392,9 +406,9 @@
     ASSERT_REAL_CHOICE_TYPE(bestchoice.type);
 
     /* Try upgrade units at danger location (high want is usually danger) */
-    if (pcity->ai.danger > 1) {
+    if (pcity->ai.urgency > 1) {
       if (bestchoice.type == CT_BUILDING && is_wonder(bestchoice.choice)) {
-        CITY_LOG(LOG_BUY, pcity, "Wonder being built in dangerous position!");
+        CITY_LOG(LOG_ERROR, pcity, "Wonder being built in dangerous 
position!");
       } else {
         /* If we have urgent want, spend more */
         int upgrade_limit = limit;
@@ -406,6 +420,10 @@
       }
     }
 
+    if (pcity->anarchy != 0 && bestchoice.type != CT_BUILDING) {
+      continue; /* Nothing we can do */
+    }
+
     /* Cost to complete production */
     buycost = city_buy_cost(pcity);
 
@@ -444,15 +462,6 @@
        continue;
     }
 
-    if (!expensive && bestchoice.type != CT_BUILDING
-        && (unit_type_flag(bestchoice.choice, F_TRADE_ROUTE) 
-            || unit_type_flag(bestchoice.choice, F_HELP_WONDER))
-        && buycost < unit_types[bestchoice.choice].build_cost * 2) {
-      /* We need more money for buying caravans. Increasing
-         maxbuycost will increase taxes */
-      pplayer->ai.maxbuycost = MAX(pplayer->ai.maxbuycost, buycost);
-    }
-
     /* FIXME: Here Syela wanted some code to check if
      * pcity was doomed, and we should therefore attempt
      * to sell everything in it of non-military value */
@@ -478,10 +487,7 @@
         CITY_LOG(LOG_BUY, pcity, "now we can afford it (sold something)");
         really_handle_city_buy(pplayer, pcity);
       }
-      if (buycost > pplayer->ai.maxbuycost) {
-        /* Consequently we need to raise more money through taxes */
-        pplayer->ai.maxbuycost = MAX(pplayer->ai.maxbuycost, buycost);
-      }
+      adjust_buylimit(pplayer, buycost); /* May need to raise taxes */
     }
   } while (TRUE);
 
@@ -490,15 +496,9 @@
     ai_upgrade_units(pcity, cached_limit, FALSE);
   } city_list_iterate_end;
 
-  if (pplayer->economic.gold + cached_limit < pplayer->ai.maxbuycost) {
-    /* We have too much gold! Don't raise taxes */
-    pplayer->ai.maxbuycost = 0;
-  }
-
   freelog(LOG_BUY, "%s wants to keep %d in reserve (tax factor %d)", 
           pplayer->name, cached_limit, pplayer->ai.maxbuycost);
 }
-#undef LOG_BUY
 
 /**************************************************************************
  cities, build order and worker allocation stuff here..

[Prev in Thread] Current Thread [Next in Thread]