# Re: [Freeciv-Dev] (PR#34725) [Patch] AI accepts slightly negative balance if it has a lot of gold

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=34725 >

On 1/28/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
> AI accepts slightly
> negative balance if it has gold reserves for that. More precisely:
> negative balance is acceptable if AI could with its current gold
> reserves live up to 50 turns with such a balance.

- This version does not accept negative balance if there is need to
refill coffers.

- ML

diff -Nurd -X.diff_ignore freeciv/ai/aihand.c freeciv/ai/aihand.c
--- freeciv/ai/aihand.c	2006-07-17 23:56:47.000000000 +0300
+++ freeciv/ai/aihand.c	2007-02-01 21:30:09.000000000 +0200
@@ -66,6 +66,10 @@

#define LOGLEVEL_TAX LOG_DEBUG

+/* When setting rates, we accept negative balance if we have a lot of
+ * gold reserves. This is how long time gold reserves should last */
+#define AI_GOLD_RESERVE_MIN_TURNS 50
+
/**************************************************************************
handle spaceship related stuff
**************************************************************************/
@@ -102,6 +106,7 @@
int can_celebrate = 0, total_cities = 0;
int expenses = 0; /* total amount of gold upkeep */
+  bool refill_coffers = pplayer->economic.gold < ai_gold_reserve(pplayer);

if (!game.info.changable_tax) {
return; /* This ruleset does not support changing tax rates. */
@@ -127,7 +132,8 @@
pplayer->economic.luxury = (100 - pplayer->economic.science
- pplayer->economic.tax); /* Spillover */

-  /* Now find the minimum tax with positive balance */
+  /* Now find the minimum tax with positive balance
+   * Negative balance is acceptable if we have a lot of gold. */
while(pplayer->economic.tax < maxrate
&& (pplayer->economic.science > 0
|| pplayer->economic.luxury > 0)) {
@@ -142,7 +148,11 @@
rates[TAX] = 100 - rates[SCIENCE] - rates[LUXURY];

-    if (expenses - result[TAX] > 0) {
+    if (expenses - result[TAX] > 0
+        || (!refill_coffers
+            && expenses - result[TAX] >
+               pplayer->economic.gold / AI_GOLD_RESERVE_MIN_TURNS)) {
+      /* Clearly negative balance. Unacceptable */
pplayer->economic.tax += 10;
if (pplayer->economic.luxury > 0) {
pplayer->economic.luxury -= 10;
@@ -150,8 +160,9 @@
pplayer->economic.science -= 10;
}
} else {
-      /* Ok, got positive balance */
-      if (pplayer->economic.gold < ai_gold_reserve(pplayer)) {
+      /* Ok, got positive balance
+       * Or just slightly negative, if we can afford that for a while */
+      if (refill_coffers) {
/* Need to refill coffers, increase tax a bit */
pplayer->economic.tax += 10;
if (pplayer->economic.luxury > 0) {
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev