Complete.Org: Mailing Lists: Archives: freeciv-ai: July 2003:
[freeciv-ai] AI Diplomacy v11 (PR#2413)
Home

[freeciv-ai] AI Diplomacy v11 (PR#2413)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [freeciv-ai] AI Diplomacy v11 (PR#2413)
From: "Per I. Mathisen" <per@xxxxxxxxxxx>
Date: Wed, 2 Jul 2003 13:16:32 -0700
Reply-to: rt@xxxxxxxxxxxxxx

CHANGES:
  - fixed bug where we thought no-contact meant active warfare, reported
by both Jordi and David M Stewart.
  - updated to current cvs

This only changes the patch against the cvs files. The extra files that
need to be added can be found in the v10 post.

  - Per

Index: ai/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/Makefile.am,v
retrieving revision 1.13
diff -u -r1.13 Makefile.am
--- ai/Makefile.am      2003/03/11 17:59:26     1.13
+++ ai/Makefile.am      2003/07/02 20:13:13
@@ -21,6 +21,8 @@
                advmilitary.h   \
                advscience.c    \
                advscience.h    \
+               advdiplomacy.c  \
+               advdiplomacy.h  \
                advspace.c      \
                advspace.h      \
                advtrade.c      \
Index: ai/advmilitary.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advmilitary.c,v
retrieving revision 1.147
diff -u -r1.147 advmilitary.c
--- ai/advmilitary.c    2003/06/19 17:44:21     1.147
+++ ai/advmilitary.c    2003/07/02 20:13:14
@@ -31,6 +31,7 @@
 
 #include "aiair.h"
 #include "aicity.h"
+#include "aidata.h"
 #include "aidiplomat.h"
 #include "aihand.h"
 #include "ailog.h"
@@ -913,6 +914,7 @@
 static void kill_something_with(struct player *pplayer, struct city *pcity, 
                                struct unit *myunit, struct ai_choice *choice)
 {
+  struct ai_data *ai = ai_data_get(pplayer);
   /* Our attack rating (with reinforcements) */
   int attack;
   /* Benefit from fighting the target */
@@ -999,7 +1001,7 @@
       move_rate *= 3;
     }
     
-    if (!pplayers_at_war(pplayer, city_owner(acity))) {
+    if (!HOSTILE_PLAYER(pplayer, ai, city_owner(acity))) {
       /* Not a valid target */
       return;
     }
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.16
diff -u -r1.16 aidata.c
--- ai/aidata.c 2003/05/29 13:44:38     1.16
+++ ai/aidata.c 2003/07/02 20:13:14
@@ -18,18 +18,22 @@
 #include <stdio.h>
 #include <string.h>
 
+#include "aisupport.h"
 #include "city.h"
 #include "game.h"
 #include "government.h"
 #include "map.h"
 #include "mem.h"
+#include "rand.h"
 #include "unit.h"
 
 #include "citytools.h"
+#include "diplhand.h"
 #include "maphand.h"
 #include "settlers.h"
 #include "unittools.h"
 
+#include "advdiplomacy.h"
 #include "advmilitary.h"
 #include "aicity.h"
 #include "aihand.h"
@@ -60,6 +64,8 @@
   bool can_build_antiair =  can_player_build_improvement(pplayer, B_SAM);
   bool can_build_antinuke = can_player_build_improvement(pplayer, B_SDI);
   bool can_build_antimissile = can_player_build_improvement(pplayer, B_SDI);
+  int ally_strength = -1;
+  struct player *ally_strongest = NULL;
 
   /*** Threats ***/
 
@@ -207,6 +213,10 @@
 
   /*** Diplomacy ***/
 
+  if (pplayer->ai.control && !is_barbarian(pplayer)) {
+    ai_diplomacy_calculate(pplayer, ai);
+  }
+
   /* Question: What can we accept as the reputation of a player before
    * we start taking action to prevent us from being suckered?
    * Answer: Very little. */
@@ -220,29 +230,42 @@
   for (i = 0; i < MAX_NUM_PLAYERS; i++) {
     struct player *aplayer = get_player(i);
 
-    ai->diplomacy.player_intel[i].is_allied_with_enemy = FALSE;
-    ai->diplomacy.player_intel[i].at_war_with_ally = FALSE;
-    ai->diplomacy.player_intel[i].is_allied_with_ally = FALSE;
+    ai->diplomacy.player_intel[i].is_allied_with_enemy = NULL;
+    ai->diplomacy.player_intel[i].at_war_with_ally = NULL;
+    ai->diplomacy.player_intel[i].is_allied_with_ally = NULL;
+
+    /* Determine who is the leader of our alliance. That is,
+     * whoever has the more cities. */
+    if (pplayers_allied(pplayer, aplayer)
+        && city_list_size(&aplayer->cities) > ally_strength) {
+      ally_strength = city_list_size(&aplayer->cities);
+      ally_strongest = aplayer;
+    }
 
     players_iterate(check_pl) {
-      if (check_pl == pplayer || check_pl == aplayer
+      if (check_pl == pplayer
+          || check_pl == aplayer
           || !check_pl->is_alive) {
         continue;
       }
       if (pplayers_allied(aplayer, check_pl)
-          && pplayers_at_war(pplayer, check_pl)) {
-       ai->diplomacy.player_intel[i].is_allied_with_enemy = TRUE;
+          && pplayer_get_diplstate(pplayer, check_pl)->type == DS_WAR) {
+       ai->diplomacy.player_intel[i].is_allied_with_enemy = check_pl;
       }
       if (pplayers_allied(pplayer, check_pl)
-          && pplayers_at_war(aplayer, check_pl)) {
-        ai->diplomacy.player_intel[i].at_war_with_ally = TRUE;
+          && pplayer_get_diplstate(aplayer, check_pl)->type == DS_WAR) {
+        ai->diplomacy.player_intel[i].at_war_with_ally = check_pl;
       }
       if (pplayers_allied(aplayer, check_pl)
           && pplayers_allied(pplayer, check_pl)) {
-        ai->diplomacy.player_intel[i].is_allied_with_ally = TRUE;
+        ai->diplomacy.player_intel[i].is_allied_with_ally = check_pl;
       }
     } players_iterate_end;
   }
+  if (ally_strongest != ai->diplomacy.alliance_leader) {
+    ai->diplomacy.alliance_leader = ally_strongest;
+  }
+  ai->diplomacy.spacerace_leader = aisupport_who_leads_spacerace();
 
   /*** Priorities ***/
 
@@ -278,29 +301,49 @@
 }
 
 /**************************************************************************
-  Return a pointer to our data
+  Initialize with sane values.
 **************************************************************************/
-struct ai_data *ai_data_get(struct player *pplayer)
+void ai_data_init(struct player *pplayer)
 {
   struct ai_data *ai = &aidata[pplayer->player_no];
+  int i;
 
-  if (ai->num_continents != map.num_continents) {
-    /* we discovered more continents, recalculate! */
-    ai_data_turn_done(pplayer);
-    ai_data_turn_init(pplayer);
+  ai->govt_reeval = 0;
+  ai->government_want = fc_calloc(game.government_count + 1, sizeof(int));
+
+  ai->diplomacy.target = NULL;
+  ai->diplomacy.strategy = WIN_OPEN;
+  ai->diplomacy.timer = 0;
+  ai->diplomacy.countdown = 0;
+  ai->diplomacy.love_coeff = 5; /* 5% */
+  ai->diplomacy.love_incr = 4;
+  ai->diplomacy.alliance_leader = pplayer;
+
+  for (i = 0; i < MAX_NUM_PLAYERS; i++) {
+    ai->diplomacy.player_intel[i].spam = i; /* pseudorandom */
+    ai->diplomacy.player_intel[i].distance = 1;
+    ai->diplomacy.player_intel[i].ally_patience = 0;
+    ai->diplomacy.player_intel[i].love = 1;
+    ai->diplomacy.player_intel[i].asked_about_peace = 0;
+    ai->diplomacy.player_intel[i].asked_about_alliance = 0;
+    ai->diplomacy.player_intel[i].asked_about_ceasefire = 0;
+    ai->diplomacy.player_intel[i].warned_about_space = 0;
   }
-  return ai;
 }
 
 /**************************************************************************
-  Initialize with sane values.
+  Return a pointer to our data
 **************************************************************************/
-void ai_data_init(struct player *pplayer)
+struct ai_data *ai_data_get(struct player *pplayer)
 {
   struct ai_data *ai = &aidata[pplayer->player_no];
 
-  ai->govt_reeval = 0;
-  ai->government_want = fc_calloc(game.government_count + 1, sizeof(int));
+  if (ai->num_continents != map.num_continents) {
+    /* we discovered more continents, recalculate! */
+    ai_data_turn_done(pplayer);
+    ai_data_turn_init(pplayer);
+  }
+  return ai;
 }
 
 /**************************************************************************
Index: ai/aidata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.h,v
retrieving revision 1.9
diff -u -r1.9 aidata.h
--- ai/aidata.h 2003/05/15 16:02:00     1.9
+++ ai/aidata.h 2003/07/02 20:13:14
@@ -27,10 +27,27 @@
  * start of every turn. 
  */
 
+enum winning_strategy {
+  WIN_OPEN,     /* still undetermined */
+  WIN_WAR,      /* we have no other choice than to crush all opposition */
+  WIN_SPACE,    /* we will race for space, peace very important */
+  WIN_CAPITAL   /* we cannot win unless we take war_target's capital */
+};
+
 struct ai_dip_intel {
-  bool is_allied_with_enemy;
-  bool at_war_with_ally;
-  bool is_allied_with_ally;
+  /* Remember one example of each for text spam purposes. */
+  struct player *is_allied_with_enemy;
+  struct player *at_war_with_ally;
+  struct player *is_allied_with_ally;
+
+  char spam;      /* timer to avoid spamming a player with chat */
+  int distance;   /* average distance to that player's cities */
+  char ally_patience; /* we EXPECT our allies to help us! */
+  int love;       /* basic player <-> player relation */
+  char asked_about_peace;     /* don't ask again */
+  char asked_about_alliance;  /* don't nag! */
+  char asked_about_ceasefire; /* don't ... you get the point */
+  char warned_about_space;
 };
 
 BV_DEFINE(bv_id, MAX_NUM_ID);
@@ -39,6 +56,14 @@
   struct {
     int acceptable_reputation;
     struct ai_dip_intel player_intel[MAX_NUM_PLAYERS];
+    enum winning_strategy strategy;
+    int timer; /* pursue our goals with some stubbornness, in turns */
+    int countdown;          /* countdown to we actually declare war */
+    struct player *target;    /* Concentrate on this player */
+    char love_coeff;          /* Reduce love with this % each turn */
+    char love_incr;           /* Modify love with this fixed amount */
+    struct player *alliance_leader; /* Who is leading our alliance */
+    struct player *spacerace_leader; /* who is leading the space pack */
   } diplomacy;
 
   /* Long-term threats, not to be confused with short-term danger */
@@ -95,6 +120,7 @@
   } goal;
 };
 
+void ai_data_init(struct player *pplayer);
 void ai_data_turn_init(struct player *pplayer);
 void ai_data_turn_done(struct player *pplayer);
 
Index: ai/aidiplomat.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidiplomat.c,v
retrieving revision 1.21
diff -u -r1.21 aidiplomat.c
--- ai/aidiplomat.c     2003/05/06 22:08:25     1.21
+++ ai/aidiplomat.c     2003/07/02 20:13:14
@@ -167,7 +167,7 @@
       return;
     }
     incite_cost = city_incite_cost(pplayer, acity);
-    if (pplayers_at_war(pplayer, city_owner(acity))
+    if (HOSTILE_PLAYER(pplayer, ai, city_owner(acity))
         && !city_got_building(acity, B_PALACE)
         && !government_has_flag(get_gov_pplayer(city_owner(acity)),
                                 G_UNBRIBABLE)
@@ -436,6 +436,7 @@
 {
   struct packet_diplomat_action packet;
   int gold_avail = pplayer->economic.gold - pplayer->ai.est_upkeep;
+  struct ai_data *ai = ai_data_get(pplayer);
 
   simple_unit_overlap_path_iterator(punit, pos) {
     struct tile *ptile = map_get_tile(pos.x, pos.y);
@@ -450,7 +451,7 @@
     }
 
     if (!pvictim
-        || !pplayers_at_war(pplayer, unit_owner(pvictim))
+        || !HOSTILE_PLAYER(pplayer, ai, unit_owner(pvictim))
         || unit_list_size(&ptile->units) > 1
         || map_get_city(pos.x, pos.y)
         || government_has_flag(get_gov_pplayer(unit_owner(pvictim)),
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.85
diff -u -r1.85 aitools.c
--- ai/aitools.c        2003/05/06 08:13:21     1.85
+++ ai/aitools.c        2003/07/02 20:13:14
@@ -74,8 +74,8 @@
 /**********************************************************************
   There are some signs that a player might be dangerous: We are at 
   war with him, he has lousy reputation, he has done lots of ignoble 
-  things to us, or he is an ally of one of our enemies (a ticking 
-  bomb to be sure).
+  things to us, he is an ally of one of our enemies (a ticking bomb
+  to be sure), or he is our war target.
 ***********************************************************************/
 bool is_player_dangerous(struct player *pplayer, struct player *aplayer)
 {
@@ -84,6 +84,7 @@
     = &ai->diplomacy.player_intel[aplayer->player_no];
 
   return (pplayers_at_war(pplayer, aplayer)
+          || ai->diplomacy.target == aplayer
           || pplayer->diplstates[aplayer->player_no].has_reason_to_cancel
           || ai->diplomacy.acceptable_reputation > aplayer->reputation
           || adip->is_allied_with_enemy);
Index: ai/aiunit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.c,v
retrieving revision 1.278
diff -u -r1.278 aiunit.c
--- ai/aiunit.c 2003/05/30 18:26:11     1.278
+++ ai/aiunit.c 2003/07/02 20:13:15
@@ -1876,6 +1876,8 @@
                           int which)
 {
   int x, y;
+  struct player *pplayer = unit_owner(punit);
+  struct ai_data *ai = ai_data_get(pplayer);
 
   CHECK_UNIT(punit);
 
@@ -1890,7 +1892,8 @@
   square_iterate(x, y, radius, x1, y1) {
     struct city *pcity = map_get_city(x1, y1);
 
-    if (pcity && pplayers_at_war(city_owner(pcity), unit_owner(punit))
+    if (pcity
+        && HOSTILE_PLAYER(pplayer, ai, city_owner(pcity))
        && (pcity->ai.invasion & which) != which
        && (dest || !has_defense(pcity))) {
       pcity->ai.invasion |= which;
@@ -1909,6 +1912,7 @@
 int find_something_to_kill(struct player *pplayer, struct unit *punit, 
                            int *x, int *y)
 {
+  struct ai_data *ai = ai_data_get(pplayer);
   /* basic attack */
   int attack_value = unit_att_rating(punit);
   /* Enemy defence rating */
@@ -1966,7 +1970,7 @@
 
   /* First calculate in nearby units */
   players_iterate(aplayer) {
-    if (!pplayers_at_war(pplayer, aplayer)) {
+    if (!HOSTILE_PLAYER(pplayer, ai, aplayer)) {
       continue;
     }
     city_list_iterate(aplayer->cities, acity) {
@@ -2055,7 +2059,7 @@
   }
 
   players_iterate(aplayer) {
-    if (!pplayers_at_war(pplayer, aplayer)) { 
+    if (!HOSTILE_PLAYER(pplayer, ai, aplayer)) {
       /* Not an enemy */
       continue;
     }
@@ -2448,6 +2456,7 @@
   struct city *pcity;
   struct packet_unit_request req;
   int tradeval, best_city = -1, best=0;
+  struct ai_data *ai = ai_data_get(pplayer);
 
   CHECK_UNIT(punit);
 
@@ -2475,7 +2484,9 @@
        /* A caravan without a home?  Kinda strange, but it might happen.  */
        pcity=player_find_city_by_id(pplayer, punit->homecity);
        players_iterate(aplayer) {
-         if (pplayers_at_war(pplayer, aplayer)) continue;
+         if (HOSTILE_PLAYER(pplayer, ai, aplayer)) {
+           continue;
+         }
          city_list_iterate(pplayer->cities,pdest) {
            if (pcity && can_establish_trade_route(pcity, pdest)
                && map_get_continent(pcity->x, pcity->y) 
Index: ai/aiunit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aiunit.h,v
retrieving revision 1.45
diff -u -r1.45 aiunit.h
--- ai/aiunit.h 2003/05/10 18:11:25     1.45
+++ ai/aiunit.h 2003/07/02 20:13:15
@@ -36,6 +36,9 @@
         > unit_type(punit)->transport_capacity)
 #define COULD_OCCUPY(punit) \
   (is_ground_unit(punit) || is_heli_unit(punit))
+#define HOSTILE_PLAYER(pplayer, ai, aplayer) \
+  (pplayers_at_war(pplayer, aplayer)         \
+   || ai->diplomacy.target == aplayer)
 
 struct player;
 struct city;
Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.81
diff -u -r1.81 options.c
--- client/options.c    2003/05/18 16:19:29     1.81
+++ client/options.c    2003/07/02 20:13:15
@@ -283,6 +283,7 @@
   GEN_EV(N_("Wonder: Started"),                       E_WONDER_STARTED),
   GEN_EV(N_("Wonder: Stopped"),                       E_WONDER_STOPPED),
   GEN_EV(N_("Wonder: Will Finish Next Turn"),         E_WONDER_WILL_BE_BUILT),
+  GEN_EV(N_("Diplomatic Message"),                    E_DIPLOMACY),
   GEN_EV_TERMINATOR
 };
 
Index: common/diptreaty.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/diptreaty.c,v
retrieving revision 1.16
diff -u -r1.16 diptreaty.c
--- common/diptreaty.c  2003/05/15 15:16:07     1.16
+++ common/diptreaty.c  2003/07/02 20:13:15
@@ -40,8 +40,8 @@
               || player_has_embassy(pplayer, aplayer)
               || pplayer->diplstates[aplayer->player_no].contact_turns_left > 0
               || aplayer->diplstates[pplayer->player_no].contact_turns_left > 
0)
-          && aplayer->is_connected
-          && pplayer->is_connected);
+          && (aplayer->is_connected || aplayer->ai.control)
+          && (pplayer->is_connected || pplayer->ai.control));
 }
 
 /**************************************************************************
Index: common/events.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/events.h,v
retrieving revision 1.22
diff -u -r1.22 events.h
--- common/events.h     2002/05/07 07:40:53     1.22
+++ common/events.h     2003/07/02 20:13:15
@@ -102,6 +102,7 @@
   E_WONDER_STARTED,
   E_WONDER_STOPPED,
   E_WONDER_WILL_BE_BUILT,
+  E_DIPLOMACY,
   /* 
    * Note: If you add a new event, make sure you make a similar change
    * to the events array in client/options.c using GEN_EV and to
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.119
diff -u -r1.119 player.c
--- common/player.c     2003/06/05 23:10:46     1.119
+++ common/player.c     2003/07/02 20:13:15
@@ -580,6 +580,23 @@
 }
 
 /***************************************************************
+  Returns true iff players are allied or at peace.
+***************************************************************/
+bool pplayers_in_peace(const struct player *pplayer,
+                       const struct player *pplayer2)
+{
+  enum diplstate_type ds = pplayer_get_diplstate(pplayer, pplayer2)->type;
+
+  if (pplayer == pplayer2) {
+    return TRUE;
+  }
+  if (is_barbarian(pplayer) || is_barbarian(pplayer2)) {
+    return FALSE;
+  }
+  return (ds == DS_PEACE || ds == DS_ALLIANCE);
+}
+
+/***************************************************************
   Returns true iff players have peace or cease-fire.
 ***************************************************************/
 bool pplayers_non_attack(const struct player *pplayer,
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.100
diff -u -r1.100 player.h
--- common/player.h     2003/05/31 16:22:15     1.100
+++ common/player.h     2003/07/02 20:13:16
@@ -263,6 +263,8 @@
                    const struct player *pplayer2);
 bool pplayers_allied(const struct player *pplayer,
                    const struct player *pplayer2);
+bool pplayers_in_peace(const struct player *pplayer,
+                    const struct player *pplayer2);
 bool pplayers_non_attack(const struct player *pplayer,
                        const struct player *pplayer2);
 
Index: common/aicore/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/Makefile.am,v
retrieving revision 1.4
diff -u -r1.4 Makefile.am
--- common/aicore/Makefile.am   2003/03/11 17:59:26     1.4
+++ common/aicore/Makefile.am   2003/07/02 20:13:16
@@ -5,6 +5,8 @@
 INCLUDES = -I.. -I$(top_srcdir)/common -I../../intl
 
 libaicore_a_SOURCES =          \
+       aisupport.c             \
+       aisupport.h             \
        path_finding.c          \
        path_finding.h          \
        pf_tools.c              \
Index: server/diplhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/diplhand.c,v
retrieving revision 1.71
diff -u -r1.71 diplhand.c
--- server/diplhand.c   2003/06/26 23:03:13     1.71
+++ server/diplhand.c   2003/07/02 20:13:16
@@ -37,6 +37,8 @@
 #include "settlers.h"
 #include "unittools.h"
 
+#include "advdiplomacy.h"
+
 #include "diplhand.h"
 
 #define SPECLIST_TAG treaty
@@ -325,6 +327,13 @@
       }
     } clause_list_iterate_end;
 
+    if (plr0->ai.control) {
+      ai_treaty_accepted(plr0, plr1, ptreaty);
+    }
+    if (plr1->ai.control) {
+      ai_treaty_accepted(plr1, plr0, ptreaty);
+    }
+
     clause_list_iterate(ptreaty->clauses, pclause) {
       pgiver = pclause->from;
       pdest = (plr0==pgiver) ? plr1 : plr0;
@@ -335,6 +344,11 @@
          * and try to give us the same tech at the same time. This
          * should be handled discreetly instead of giving a core dump. */
         if (get_invention(pdest, pclause->value) == TECH_KNOWN) {
+         freelog(LOG_VERBOSE,
+                  "The %s already know tech %s, that %s want to give them.",
+                 get_nation_name_plural(pdest->nation),
+                 advances[pclause->value].name,
+                 get_nation_name_plural(pgiver->nation));
           break;
         }
        notify_player_ex(pdest, -1, -1, E_TECH_GAIN,
@@ -446,7 +460,7 @@
       }
 
     } clause_list_iterate_end;
-  cleanup:      
+  cleanup:
     treaty_list_unlink(&treaties, ptreaty);
     free(ptreaty);
     send_player_info(plr0, NULL);
@@ -488,9 +502,14 @@
                                 PACKET_DIPLOMACY_REMOVE_CLAUSE, packet);
       lsend_packet_diplomacy_info(&plr1->connections, 
                                 PACKET_DIPLOMACY_REMOVE_CLAUSE, packet);
+      if (plr0->ai.control) {
+        ai_treaty_evaluate(plr0, plr1, ptreaty);
+      }
+      if (plr1->ai.control) {
+        ai_treaty_evaluate(plr1, plr0, ptreaty);
+      }
     }
   }
-
 }
 
 /**************************************************************************
@@ -531,6 +550,12 @@
       lsend_packet_diplomacy_info(&plr1->connections, 
                                 PACKET_DIPLOMACY_CREATE_CLAUSE, 
                                 packet);
+      if (plr0->ai.control) {
+        ai_treaty_evaluate(plr0, plr1, ptreaty);
+      }
+      if (plr1->ai.control) {
+        ai_treaty_evaluate(plr1, plr0, ptreaty);
+      }
     }
   }
 }
@@ -599,10 +624,11 @@
   plr0=&game.players[packet->plrno0];
   plr1=&game.players[packet->plrno1];
 
+  assert(plr0 != plr1);
+
   if (!find_treaty(plr0, plr1)) {
-    if (plr0->ai.control || plr1->ai.control) {
-      notify_player(plr0, _("AI controlled players cannot participate in "
-                           "diplomatic meetings."));
+    if (is_barbarian(plr0) || is_barbarian(plr1)) {
+      notify_player(plr0, _("Your diplomatic envoy was decapitated!"));
       return;
     }
 
@@ -644,6 +670,7 @@
     return;
   }
   players_iterate(other_player) {
+
     if ( (ptreaty=find_treaty(pplayer, other_player))) {
       struct packet_diplomacy_info packet;
       
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.279
diff -u -r1.279 plrhand.c
--- server/plrhand.c    2003/06/30 20:53:25     1.279
+++ server/plrhand.c    2003/07/02 20:13:16
@@ -1323,6 +1323,7 @@
     player_map_allocate(pplayer);
   }
   player_init(pplayer);
+  ai_data_init(pplayer);
 }
 
 /********************************************************************** 
@@ -1378,12 +1379,10 @@
   pplayer1->diplstates[player2].contact_turns_left = game.contactturns;
   pplayer2->diplstates[player1].contact_turns_left = game.contactturns;
 
-  /* FIXME: Always declaring war for the AI is a kludge until AI
-     diplomacy is implemented. */
   if (pplayer_get_diplstate(pplayer1, pplayer2)->type == DS_NO_CONTACT) {
     pplayer1->diplstates[player2].type
       = pplayer2->diplstates[player1].type
-      = pplayer1->ai.control || pplayer2->ai.control ? DS_WAR : DS_NEUTRAL;
+      = DS_NEUTRAL;
     notify_player_ex(pplayer1, x, y,
                     E_FIRST_CONTACT,
                     _("Game: You have made contact with the %s, ruled by %s."),
@@ -1541,10 +1540,10 @@
    * but for now AI players are always at war.
    */
   players_iterate(other_player) {
-    cplayer->diplstates[other_player->player_no].type = DS_WAR;
+    cplayer->diplstates[other_player->player_no].type = DS_NEUTRAL;
     cplayer->diplstates[other_player->player_no].has_reason_to_cancel = 0;
     cplayer->diplstates[other_player->player_no].turns_left = 0;
-    other_player->diplstates[cplayer->player_no].type = DS_WAR;
+    other_player->diplstates[cplayer->player_no].type = DS_NEUTRAL;
     other_player->diplstates[cplayer->player_no].has_reason_to_cancel = 0;
     other_player->diplstates[cplayer->player_no].turns_left = 0;
     
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.120
diff -u -r1.120 savegame.c
--- server/savegame.c   2003/06/26 23:09:23     1.120
+++ server/savegame.c   2003/07/02 20:13:17
@@ -49,6 +49,7 @@
 #include "unittools.h"
 
 #include "aicity.h"
+#include "aidata.h"
 #include "aiunit.h"
 
 #include "savegame.h"
@@ -695,7 +696,13 @@
 
   plr->reputation=secfile_lookup_int_default(file, GAME_DEFAULT_REPUTATION,
                                             "player%d.reputation", plrno);
-  for(i=0; i<game.nplayers; i++) {
+  for (i=0; i < game.nplayers; i++) {
+    struct ai_data *ai = ai_data_get(plr);
+
+    ai->diplomacy.player_intel[i].love =
+      secfile_lookup_int_default(file, 0,
+                                "player%d.ai_diplomacy%d.love", plrno, i);
+
     plr->diplstates[i].type = 
       secfile_lookup_int_default(file, DS_WAR,
                                 "player%d.diplstate%d.type", plrno, i);
@@ -1351,6 +1358,10 @@
 
   secfile_insert_int(file, plr->reputation, "player%d.reputation", plrno);
   for (i = 0; i < MAX_NUM_PLAYERS+MAX_NUM_BARBARIANS; i++) {
+    struct ai_data *ai = ai_data_get(plr);
+
+    secfile_insert_int(file, ai->diplomacy.player_intel[i].love,
+                       "player%d.ai_diplomacy%d.love", plrno, i);
     secfile_insert_int(file, plr->diplstates[i].type,
                       "player%d.diplstate%d.type", plrno, i);
     secfile_insert_int(file, plr->diplstates[i].turns_left,
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.127
diff -u -r1.127 srv_main.c
--- server/srv_main.c   2003/05/15 16:02:00     1.127
+++ server/srv_main.c   2003/07/02 20:13:17
@@ -91,6 +91,7 @@
 #include "unithand.h"
 #include "unittools.h"
 
+#include "advdiplomacy.h"
 #include "advmilitary.h"
 #include "aidata.h"
 #include "aihand.h"
@@ -467,9 +468,15 @@
     send_player_cities(pplayer);
   } players_iterate_end;
 
-  flush_packets();                     /* to curb major city spam */
-
+  flush_packets();  /* to curb major city spam */
   conn_list_do_unbuffer(&game.game_connections);
+
+  /* Try to avoid hiding events under a diplomacy dialog */
+  players_iterate(pplayer) {
+    if (pplayer->ai.control && !is_barbarian(pplayer)) {
+      ai_diplomacy_actions(pplayer);
+    }
+  } players_iterate_end;
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [freeciv-ai] AI Diplomacy v11 (PR#2413), Per I. Mathisen <=