Author: sveinung
Date: Tue Oct 27 16:55:25 2015
New Revision: 30240

URL: http://svn.gna.org/viewcvs/freeciv?rev=30240&view=rev
Log:
Peace and Alliance is closer than "Never met"

The closest diplomatic relationship two players have had is recorded.
(Currently only Peace and Alliance is seen as a significant enough change to
be worth recording) Fix the recording so it stops considering "Never met" as
closer than everything except team.

See bug #23973

Modified:
    branches/S2_5/server/diplhand.c
    branches/S2_5/server/savegame.c
    branches/S2_5/server/savegame2.c

Modified: branches/S2_5/server/diplhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/diplhand.c?rev=30240&r1=30239&r2=30240&view=diff
==============================================================================
--- branches/S2_5/server/diplhand.c     (original)
+++ branches/S2_5/server/diplhand.c     Tue Oct 27 16:55:25 2015
@@ -135,6 +135,29 @@
   } treaty_list_iterate_end;
 
   return NULL;
+}
+
+/**************************************************************************
+  Return the closest of the two diplstate types.
+**************************************************************************/
+static enum diplstate_type dst_closest(enum diplstate_type a,
+                                       enum diplstate_type b)
+{
+  static const int how_close[DS_LAST] = {
+    [DS_NO_CONTACT] = 0,
+    [DS_WAR] = 1,
+    [DS_CEASEFIRE] = 2,
+    [DS_ARMISTICE] = 3,
+    [DS_PEACE] = 4,
+    [DS_ALLIANCE] = 5,
+    [DS_TEAM] = 6,
+  };
+
+  if (how_close[a] < how_close[b]) {
+    return b;
+  } else {
+    return a;
+  }
 }
 
 /**************************************************************************
@@ -523,8 +546,10 @@
         ds_destgiver->type = DS_ARMISTICE;
         ds_giverdest->turns_left = TURNS_LEFT;
         ds_destgiver->turns_left = TURNS_LEFT;
-        ds_giverdest->max_state = MAX(DS_PEACE, ds_giverdest->max_state);
-        ds_destgiver->max_state = MAX(DS_PEACE, ds_destgiver->max_state);
+        ds_giverdest->max_state = dst_closest(DS_PEACE,
+                                              ds_giverdest->max_state);
+        ds_destgiver->max_state = dst_closest(DS_PEACE,
+                                              ds_destgiver->max_state);
         notify_player(pgiver, NULL, E_TREATY_PEACE, ftc_server,
                       /* TRANS: ... the Poles ... Polish territory. */
                       PL_("You agree on an armistice with the %s. In %d turn, "
@@ -562,8 +587,10 @@
       case CLAUSE_ALLIANCE:
         ds_giverdest->type = DS_ALLIANCE;
         ds_destgiver->type = DS_ALLIANCE;
-        ds_giverdest->max_state = MAX(DS_ALLIANCE, ds_giverdest->max_state);
-        ds_destgiver->max_state = MAX(DS_ALLIANCE, ds_destgiver->max_state);
+        ds_giverdest->max_state = dst_closest(DS_ALLIANCE,
+                                              ds_giverdest->max_state);
+        ds_destgiver->max_state = dst_closest(DS_ALLIANCE,
+                                              ds_destgiver->max_state);
         notify_player(pgiver, NULL, E_TREATY_ALLIANCE, ftc_server,
                       _("You agree on an alliance with %s."),
                       player_name(pdest));

Modified: branches/S2_5/server/savegame.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/savegame.c?rev=30240&r1=30239&r2=30240&view=diff
==============================================================================
--- branches/S2_5/server/savegame.c     (original)
+++ branches/S2_5/server/savegame.c     Tue Oct 27 16:55:25 2015
@@ -4490,6 +4490,27 @@
     assign_player_colors();
   }
 
+  /* Fix save games from Freeciv versions with a bug that make it view
+   * "Never met" as closer than "Peace" or "Alliance". */
+  players_iterate(pplayer) {
+    players_iterate(aplayer) {
+      struct player_diplstate *ds = player_diplstate_get(pplayer, aplayer);
+
+      if (ds->max_state == DS_NO_CONTACT
+          && (ds->type == DS_PEACE
+              || ds->type == DS_ALLIANCE)) {
+        /* The current relationship is closer than what the save game
+         * claims is the closes relationship ever. */
+
+        log_error(_("The save game is wrong about what the closes "
+                    "relationship %s and %s have had is. Fixing."),
+                  player_name(pplayer), player_name(aplayer));
+
+        ds->max_state = ds->type;
+      }
+    } players_iterate_end;
+  } players_iterate_end;
+
   /* Restore game random state, just in case various initialization code
    * inexplicably altered the previously existing state. */
   if (!game.info.is_new_game) {

Modified: branches/S2_5/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/savegame2.c?rev=30240&r1=30239&r2=30240&view=diff
==============================================================================
--- branches/S2_5/server/savegame2.c    (original)
+++ branches/S2_5/server/savegame2.c    Tue Oct 27 16:55:25 2015
@@ -6309,6 +6309,27 @@
     randomize_base64url_string(server.game_identifier,
                                sizeof(server.game_identifier));
   }
+
+  /* Fix save games from Freeciv versions with a bug that make it view
+   * "Never met" as closer than "Peace" or "Alliance". */
+  players_iterate(pplayer) {
+    players_iterate(aplayer) {
+      struct player_diplstate *ds = player_diplstate_get(pplayer, aplayer);
+
+      if (ds->max_state == DS_NO_CONTACT
+          && (ds->type == DS_PEACE
+              || ds->type == DS_ALLIANCE)) {
+        /* The current relationship is closer than what the save game
+         * claims is the closes relationship ever. */
+
+        log_sg(_("The save game is wrong about what the closes "
+                 "relationship %s and %s have had is. Fixing."),
+               player_name(pplayer), player_name(aplayer));
+
+        ds->max_state = ds->type;
+      }
+    } players_iterate_end;
+  } players_iterate_end;
 
   /* Restore game random state, just in case various initialization code
    * inexplicably altered the previously existing state. */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to