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.
+ /* 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.
+ 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.