Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] Re: (PR#10211) AI love is adjusted on save game load
Home

[Freeciv-Dev] Re: (PR#10211) AI love is adjusted on save game load

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#10211) AI love is adjusted on save game load
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sat, 4 Dec 2004 16:35:17 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10211 >

Jason Short wrote:
>>[cazfi - Mon Sep 20 19:54:18 2004]:
>>
>>  See #436, date "Sun, 29 Aug 2004 20:36:11 +0300". This is more than 
>>matter of extra rand(), but things like 
>>"pplayer->ai.love[aplayer->player_no] += ai->diplomacy.love_incr;" 
>>happen too (They are actually reson to that rand(), since they may cause 
>>target to change which in turn triggers rand() ).
>>  If AI hates you, simply save+load often enough :-)
> 
> So what is the fix?

  This maybe.

  Should fix problems with AI love increasing multiple times / turn, 
#436 is still very much alive.


  - Cazfi

diff -Nurd -X.diff_ignore freeciv/ai/advdiplomacy.c freeciv/ai/advdiplomacy.c
--- freeciv/ai/advdiplomacy.c   2004-12-04 11:49:57.687500000 +0200
+++ freeciv/ai/advdiplomacy.c   2004-12-05 02:10:19.140625000 +0200
@@ -700,7 +700,7 @@
 
   Only ever called for AI players and never for barbarians.
 ***********************************************************************/
-void ai_diplomacy_calculate(struct player *pplayer, struct ai_data *ai)
+void ai_diplomacy_begin_turn(struct player *pplayer, struct ai_data *ai)
 {
   int war_desire[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
   int best_desire = 0;
diff -Nurd -X.diff_ignore freeciv/ai/advdiplomacy.h freeciv/ai/advdiplomacy.h
--- freeciv/ai/advdiplomacy.h   2004-12-04 11:49:57.687500000 +0200
+++ freeciv/ai/advdiplomacy.h   2004-12-05 01:44:39.781250000 +0200
@@ -20,7 +20,7 @@
 struct Clause;
 struct ai_data;
 
-void ai_diplomacy_calculate(struct player *pplayer, struct ai_data *ai);
+void ai_diplomacy_begin_turn(struct player *pplayer, struct ai_data *ai);
 void ai_diplomacy_actions(struct player *pplayer);
 
 void ai_treaty_evaluate(struct player *pplayer, struct player *aplayer,
diff -Nurd -X.diff_ignore freeciv/ai/aidata.c freeciv/ai/aidata.c
--- freeciv/ai/aidata.c 2004-12-05 01:18:09.593750000 +0200
+++ freeciv/ai/aidata.c 2004-12-05 01:45:47.078125000 +0200
@@ -131,7 +131,7 @@
   defending units, and ignore enemy units that are incapable of harming 
   us, instead of just checking attack strength > 1.
 **************************************************************************/
-void ai_data_turn_init(struct player *pplayer) 
+void ai_data_turn_init(struct player *pplayer, bool is_new_turn)
 {
   struct ai_data *ai = &aidata[pplayer->player_no];
   int i, nuke_units = num_role_units(F_NUCLEAR);
@@ -292,8 +292,8 @@
 
   /*** Diplomacy ***/
 
-  if (pplayer->ai.control && !is_barbarian(pplayer)) {
-    ai_diplomacy_calculate(pplayer, ai);
+  if (pplayer->ai.control && !is_barbarian(pplayer) && is_new_turn) {
+    ai_diplomacy_begin_turn(pplayer, ai);
   }
 
   /* Question: What can we accept as the reputation of a player before
@@ -439,7 +439,7 @@
       || ai->num_oceans != map.num_oceans) {
     /* we discovered more continents, recalculate! */
     ai_data_turn_done(pplayer);
-    ai_data_turn_init(pplayer);
+    ai_data_turn_init(pplayer, FALSE);
   }
   return ai;
 }
diff -Nurd -X.diff_ignore freeciv/ai/aidata.h freeciv/ai/aidata.h
--- freeciv/ai/aidata.h 2004-12-04 11:49:57.890625000 +0200
+++ freeciv/ai/aidata.h 2004-12-05 01:31:18.156250000 +0200
@@ -141,7 +141,7 @@
 };
 
 void ai_data_init(struct player *pplayer);
-void ai_data_turn_init(struct player *pplayer);
+void ai_data_turn_init(struct player *pplayer, bool is_new_phase);
 void ai_data_turn_done(struct player *pplayer);
 
 void ai_data_init(struct player *pplayer);
diff -Nurd -X.diff_ignore freeciv/server/plrhand.c freeciv/server/plrhand.c
--- freeciv/server/plrhand.c    2004-12-05 01:18:09.984375000 +0200
+++ freeciv/server/plrhand.c    2004-12-05 02:10:24.921875000 +0200
@@ -2033,9 +2033,9 @@
   give_map_from_player_to_player(pplayer, cplayer);
 
   /* Not sure if this is necessary, but might be a good idea
-     to avoid doing some ai calculations with bogus data:
+     to avoid doing some ai calculations with bogus data.
   */
-  ai_data_turn_init(cplayer);
+  ai_data_turn_init(cplayer, TRUE);
   assess_danger_player(cplayer);
   if (pplayer->ai.control) {
     assess_danger_player(pplayer);
diff -Nurd -X.diff_ignore freeciv/server/srv_main.c freeciv/server/srv_main.c
--- freeciv/server/srv_main.c   2004-12-04 11:51:21.312500000 +0200
+++ freeciv/server/srv_main.c   2004-12-05 01:29:47.375000000 +0200
@@ -522,7 +522,7 @@
     freelog(LOG_DEBUG, "beginning player turn for #%d (%s)",
            pplayer->player_no, pplayer->name);
     /* human players also need this for building advice */
-    ai_data_turn_init(pplayer);
+    ai_data_turn_init(pplayer, is_new_phase);
     ai_manage_buildings(pplayer);
   } players_iterate_end;
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#10211) AI love is adjusted on save game load, Marko Lindqvist <=