Author: sveinung
Date: Tue Oct 27 16:54:17 2015
New Revision: 30236

URL: http://svn.gna.org/viewcvs/freeciv?rev=30236&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_6/server/diplhand.c
    branches/S2_6/server/savecompat.c

Modified: branches/S2_6/server/diplhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/diplhand.c?rev=30236&r1=30235&r2=30236&view=diff
==============================================================================
--- branches/S2_6/server/diplhand.c     (original)
+++ branches/S2_6/server/diplhand.c     Tue Oct 27 16:54:17 2015
@@ -128,6 +128,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;
+  }
 }
 
 /**************************************************************************
@@ -541,8 +564,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, "
@@ -580,8 +605,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_6/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savecompat.c?rev=30236&r1=30235&r2=30236&view=diff
==============================================================================
--- branches/S2_6/server/savecompat.c   (original)
+++ branches/S2_6/server/savecompat.c   Tue Oct 27 16:54:17 2015
@@ -1014,6 +1014,44 @@
                            "savefile.diplstate_type_vector");
     free(modname);
   }
+
+  /* Fix save games from Freeciv versions with a bug that made it view
+   * "Never met" as closer than "Peace" or "Alliance". */
+  for (plrno = 0; plrno < nplayers; plrno++) {
+    int i;
+
+    for (i = 0; i < nplayers; i++) {
+      char buf[32];
+      int current;
+      int closest;
+
+      fc_snprintf(buf, sizeof(buf), "player%d.diplstate%d", plrno, i);
+
+      /* Read the current diplomatic state. */
+      current = secfile_lookup_int_default(loading->file, DS_NO_CONTACT,
+                                           "%s.type",
+                                           buf);
+
+      /* Read the closest diplomatic state. */
+      closest = secfile_lookup_int_default(loading->file, DS_NO_CONTACT,
+                                           "%s.max_state",
+                                           buf);
+
+      if (closest == DS_NO_CONTACT
+          && (current == DS_PEACE
+              || current == 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 closest"
+                 " relationship player %d and player %d have had is."
+                 " Fixing it..."),
+               plrno, i);
+
+        secfile_replace_int(loading->file, current, "%s.max_state", buf);
+      }
+    }
+  }
 }
 
 /****************************************************************************


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

Reply via email to