Complete.Org: Mailing Lists: Archives: freeciv-ai: March 2005:
[freeciv-ai] (PR#10997) AI can sell his last cities
Home

[freeciv-ai] (PR#10997) AI can sell his last cities

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [freeciv-ai] (PR#10997) AI can sell his last cities
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Mon, 7 Mar 2005 11:27:50 -0800
Reply-to: bugs@xxxxxxxxxxx

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

I've just boght _all_ cities from AI. :)
This was because the AI didn't have any capital.

Here are patches which make AI reject such treaties.
AI won't sell his last two cities.
--
mateusz
Index: ai/advdiplomacy.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdiplomacy.c,v
retrieving revision 1.47.2.11
diff -u -r1.47.2.11 advdiplomacy.c
--- ai/advdiplomacy.c   19 Feb 2005 23:21:37 -0000      1.47.2.11
+++ ai/advdiplomacy.c   7 Mar 2005 19:20:17 -0000
@@ -476,6 +476,7 @@
   bool has_treaty = FALSE;
   bool only_gifts = TRUE;
   struct ai_data *ai = ai_data_get(pplayer);
+  int given_cities = 0;
 
   assert(!is_barbarian(pplayer));
 
@@ -485,6 +486,9 @@
     if (is_pact_clause(pclause->type)) {
       has_treaty = TRUE;
     }
+    if (pclause->type == CLAUSE_CITY && pclause->from == pplayer) {
+       given_cities++;
+    }
     if (pclause->type != CLAUSE_GOLD && pclause->type != CLAUSE_MAP
         && pclause->type != CLAUSE_SEAMAP && pclause->type != CLAUSE_VISION
         && (pclause->type != CLAUSE_ADVANCE 
@@ -505,6 +509,13 @@
     return;
   }
 
+  if (given_cities > 0) {
+    /* alway keep at least two cities */
+    if (city_list_size(&pplayer->cities) - given_cities <= 2) {
+      return;
+    }
+  }
+
   /* Accept if balance is good */
   if (total_balance >= 0) {
     handle_diplomacy_accept_treaty_req(pplayer, aplayer->player_no);
@@ -562,7 +573,6 @@
   /* Evaluate clauses */
   clause_list_iterate(ptreaty->clauses, pclause) {
     int balance = ai_goldequiv_clause(pplayer, aplayer, pclause, ai, TRUE);
-
     total_balance += balance;
     gift = (gift && (balance >= 0));
     ai_treaty_react(pplayer, aplayer, pclause);
Index: ai/advdiplomacy.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdiplomacy.c,v
retrieving revision 1.67
diff -u -r1.67 advdiplomacy.c
--- ai/advdiplomacy.c   19 Feb 2005 23:26:25 -0000      1.67
+++ ai/advdiplomacy.c   7 Mar 2005 19:24:43 -0000
@@ -531,6 +531,7 @@
   struct ai_data *ai = ai_data_get(pplayer);
   enum diplstate_type ds_after =
     pplayer_get_diplstate(pplayer, aplayer)->type;
+  int given_cities = 0;
 
   assert(!is_barbarian(pplayer));
   
@@ -538,6 +539,9 @@
     if (is_pact_clause(pclause->type)) {
       ds_after = pact_clause_to_diplstate_type(pclause->type);
     }
+    if (pclause->type == CLAUSE_CITY && pclause->from == pplayer) {
+       given_cities++;
+    }    
   } clause_list_iterate_end;
   
   /* Evaluate clauses */
@@ -565,6 +569,13 @@
     return;
   }
 
+  if (given_cities > 0) {
+    /* alway keep at least two cities */
+    if (city_list_size(&pplayer->cities) - given_cities <= 2) {
+      return;
+    }
+  }
+
   /* Accept if balance is good */
   if (total_balance >= 0) {
     handle_diplomacy_accept_treaty_req(pplayer, aplayer->player_no);

[Prev in Thread] Current Thread [Next in Thread]
  • [freeciv-ai] (PR#10997) AI can sell his last cities, Mateusz Stefek <=