Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2003:
[Freeciv-Dev] Re: Gold upkeep
Home

[Freeciv-Dev] Re: Gold upkeep

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Gold upkeep
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Mon, 16 Jun 2003 18:11:04 +0000 (GMT)

On Mon, 16 Jun 2003, Remi wrote:
> This patch fixes the gold upkeep for units.

Nice. See comments below.

> I don't know if the ai will cope with it and I don't know of to test that.

I am not sure what there is for the AI not to cope with.

+void pay_for_units(struct player *pplayer, struct city *pcity)
+{
+  struct government *pgov = get_gov_pplayer(pplayer);
+  int potential_gold = 0;
+  int free_pool, upkeep;
+
+  built_impr_iterate(pcity, pimpr) {
+    potential_gold += get_improvement_type(pimpr)->build_cost;
+  } built_impr_iterate_end;
+
+  free_pool = citygov_free_gold(pcity, pgov);

This is not correct. The number returned is not the number of shields
that are free, but the number of _units_ that we don't need to pay
upkeep for. This has already been calculated, see city.c:2058. So we
don't need this line. I think you can just remove free_pool altogether.

+  unit_list_iterate(pcity->units_supported, punit) {
+    upkeep = utype_gold_cost(unit_type(punit), pgov);

So here we should instead use

        upkeep = punit->upkeep_gold;

+    if (pplayer->economic.gold + potential_gold + free_pool < upkeep) {

And: if (pplayer->economic.gold < upkeep)

+      /* We have really no gold more, even with selling improvements
+       * But normally, if we sell evrithing and disband units, that
+       * should (must) be ok */

/* We cannot upkeep this unit any longer, and selling off city
 * improvements will not help, so we will have to disband. */

+      assert(pplayer->economic.gold + potential_gold + free_pool >= 0);
+

Remove this assert. It is perfectly possible that this happens, it is not
an error. We just have too many gold upkeeping units.

+    else {
+      /* Gold can be negative but improvement will be sell after
+       * That's better to sell improvements than units because impr gives
+       * gold whereas units give only shields. Or should units with gold
+       * upkeep give gold when disbanded? */

/* Gold can get negative here as city improvements will be sold afterwards
 * to balance our budget. We avoid selling improvements if possible
 * since they are often necessary for defense of the city. */

+      free_pool -= upkeep;

Instead: pplayer->economic.gold -= upkeep;

+  if (free_pool < 0) {
+    pplayer->economic.gold += free_pool;
+  }

Then you can remove this also.

-static int citygov_free_gold(struct city *pcity, struct government *gov)
+int citygov_free_gold(struct city *pcity, struct government *gov)
+int citygov_free_gold(struct city *pcity, struct government *gov);

No longer necessary.

+  int gold_cost;   /* gold upkeep (available now) */

Just /* gold upkeep */ please.

Otherwise it looks good.

  - Per



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