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: "Per I. Mathisen" <per@xxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: Gold upkeep
From: Remi <remi.bonnet@xxxxxxxxxxx>
Date: Tue, 17 Jun 2003 18:45:54 +0200

Per I. Mathisen a écrit :

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.
But some units needs gold and not shield. Free units are also differents. However I will change the code to make this correctly work, even if I think that free upkeep is more logical than free units.

+  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;

This fonction is needed! utype_gold_cost returns upkeep * gold_factor (field in government.ruleset)

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

And: if (pplayer->economic.gold < upkeep)
Do you mean that you prefer disbanding units than selling? If you remove potential_gold, you will disband units even if there is building to sell.

+      /* 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.
No! It can't happen! If we have too many units, they will be disbanded in previous loops before this happen. If this assert is false, that means that after selling all improvements in this city and even if next units are disbanded, gold will be negative!

+    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. */
If we remove potential_gold, gold will never be negative. (I think that I need to learn english before my tomorrow exam :-( )

+      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.
ok

Otherwise it looks good.

 - Per




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