Author: cazfi
Date: Sun Mar  1 02:39:32 2015
New Revision: 28336

URL: http://svn.gna.org/viewcvs/freeciv?rev=28336&view=rev
Log:
Added loading currently open diplomatic meetings from the savegame.

See patch #5694

Modified:
    branches/S2_6/server/diplhand.c
    branches/S2_6/server/savegame2.c
    branches/S2_6/server/srv_main.c

Modified: branches/S2_6/server/diplhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/diplhand.c?rev=28336&r1=28335&r2=28336&view=diff
==============================================================================
--- branches/S2_6/server/diplhand.c     (original)
+++ branches/S2_6/server/diplhand.c     Sun Mar  1 02:39:32 2015
@@ -835,13 +835,14 @@
                                              pclause->type,
                                              pclause->value);
       } clause_list_iterate_end;
+
       if (ptreaty->plr0 == pplayer) {
         dsend_packet_diplomacy_accept_treaty(dest, player_number(other),
-                                             ptreaty->accept0, 
+                                             ptreaty->accept0,
                                              ptreaty->accept1);
       } else {
         dsend_packet_diplomacy_accept_treaty(dest, player_number(other),
-                                             ptreaty->accept1, 
+                                             ptreaty->accept1,
                                              ptreaty->accept0);
       }
     }

Modified: branches/S2_6/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/savegame2.c?rev=28336&r1=28335&r2=28336&view=diff
==============================================================================
--- branches/S2_6/server/savegame2.c    (original)
+++ branches/S2_6/server/savegame2.c    Sun Mar  1 02:39:32 2015
@@ -447,6 +447,8 @@
 
 static void sg_save_treaties(struct savedata *saving);
 
+static void sg_load_treaties(struct loaddata *loading);
+
 static void sg_load_mapimg(struct loaddata *loading);
 static void sg_save_mapimg(struct savedata *saving);
 
@@ -564,6 +566,8 @@
   sg_load_researches(loading);
   /* [event_cache] */
   sg_load_event_cache(loading);
+  /* [treaties] */
+  sg_load_treaties(loading);
   /* [mapimg] */
   sg_load_mapimg(loading);
 
@@ -6519,6 +6523,82 @@
  * ======================================================================= */
 
 /****************************************************************************
+  Load '[treaty_xxx]'.
+****************************************************************************/
+static void sg_load_treaties(struct loaddata *loading)
+{
+  int tidx;
+  const char *plr0;
+  struct treaty_list *treaties = get_all_treaties();
+
+  for (tidx = 0; (plr0 = secfile_lookup_str_default(loading->file, NULL,
+                                                    "treaty%d.plr0", tidx)) != 
NULL ;
+       tidx++) {
+    const char *plr1;
+    const char *ct;
+    int cidx;
+    struct player *p0, *p1;
+
+    plr1 = secfile_lookup_str(loading->file, "treaty%d.plr1", tidx);
+
+    p0 = player_by_name(plr0);
+    p1 = player_by_name(plr1);
+
+    if (p0 == NULL || p1 == NULL) {
+      log_error("Treaty between unknown players %s and %s", plr0, plr1);
+    } else {
+      struct Treaty *ptreaty = fc_malloc(sizeof(*ptreaty));
+
+      init_treaty(ptreaty, p0, p1);
+      treaty_list_prepend(treaties, ptreaty);
+      
+      for (cidx = 0; (ct = secfile_lookup_str_default(loading->file, NULL,
+                                                      "treaty%d.clause%d.type",
+                                                      tidx, cidx)) != NULL ;
+           cidx++ ) {
+        enum clause_type type = clause_type_by_name(ct, fc_strcasecmp);
+        const char *plrx;
+
+        if (!clause_type_is_valid(type)) {
+          log_error("Invalid clause type \"%s\"", ct);
+        } else {
+          struct player *pgiver = NULL;
+
+          plrx = secfile_lookup_str(loading->file, "treaty%d.clause%d.from",
+                                    tidx, cidx);
+
+          if (!fc_strcasecmp(plrx, plr0)) {
+            pgiver = p0;
+          } else if (!fc_strcasecmp(plrx, plr1)) {
+            pgiver = p1;
+          } else {
+            log_error("Clause giver %s is not participant of the treaty"
+                      "between %s and %s", plrx, plr0, plr1);
+          }
+
+          if (pgiver != NULL) {
+            int value;
+
+            value = secfile_lookup_int_default(loading->file, 0,
+                                               "treaty%d.clause%d.value",
+                                               tidx, cidx);
+
+            add_clause(ptreaty, pgiver, type, value);
+          }
+        }
+
+        /* These must be after clauses have been added so that acceptance
+         * does not get cleared by what seems like changes to the treaty. */
+        ptreaty->accept0 = secfile_lookup_bool_default(loading->file, FALSE,
+                                                       "treaty%d.accept0", 
tidx);
+        ptreaty->accept1 = secfile_lookup_bool_default(loading->file, FALSE,
+                                                       "treaty%d.accept1", 
tidx);
+      }
+    }
+  }
+}
+
+/****************************************************************************
   Save '[treaty_xxx]'.
 ****************************************************************************/
 static void sg_save_treaties(struct savedata *saving)

Modified: branches/S2_6/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=28336&r1=28335&r2=28336&view=diff
==============================================================================
--- branches/S2_6/server/srv_main.c     (original)
+++ branches/S2_6/server/srv_main.c     Sun Mar  1 02:39:32 2015
@@ -973,6 +973,12 @@
 
   dlsend_packet_start_phase(game.est_connections, game.info.phase);
 
+  if (!is_new_phase) {
+    conn_list_iterate(game.est_connections, pconn) {
+      send_diplomatic_meetings(pconn);
+    } conn_list_iterate_end;
+  }
+
   /* Must be the first thing as it is needed for lots of functions below! */
   phase_players_iterate(pplayer) {
     /* human players also need this for building advice */


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

Reply via email to