Author: cazfi
Date: Sun Mar  1 02:39:25 2015
New Revision: 28335

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

See patch #5694

Modified:
    trunk/server/diplhand.c
    trunk/server/savegame2.c
    trunk/server/savegame3.c
    trunk/server/srv_main.c

Modified: trunk/server/diplhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/diplhand.c?rev=28335&r1=28334&r2=28335&view=diff
==============================================================================
--- trunk/server/diplhand.c     (original)
+++ trunk/server/diplhand.c     Sun Mar  1 02:39:25 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: trunk/server/savegame2.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame2.c?rev=28335&r1=28334&r2=28335&view=diff
==============================================================================
--- trunk/server/savegame2.c    (original)
+++ trunk/server/savegame2.c    Sun Mar  1 02:39:25 2015
@@ -370,6 +370,8 @@
 
 static void sg_load_event_cache(struct loaddata *loading);
 
+static void sg_load_treaties(struct loaddata *loading);
+
 static void sg_load_mapimg(struct loaddata *loading);
 
 static void sg_load_sanitycheck(struct loaddata *loading);
@@ -450,6 +452,8 @@
   sg_load_researches(loading);
   /* [event_cache] */
   sg_load_event_cache(loading);
+  /* [treaties] */
+  sg_load_treaties(loading);
   /* [mapimg] */
   sg_load_mapimg(loading);
 
@@ -4394,6 +4398,86 @@
 }
 
 /* =======================================================================
+ * Load  the open treaties
+ * ======================================================================= */
+
+/****************************************************************************
+  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);
+      }
+    }
+  }
+}
+
+/* =======================================================================
  * Load the mapimg definitions.
  * ======================================================================= */
 

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=28335&r1=28334&r2=28335&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Sun Mar  1 02:39:25 2015
@@ -445,6 +445,7 @@
 static void sg_load_event_cache(struct loaddata *loading);
 static void sg_save_event_cache(struct savedata *saving);
 
+static void sg_load_treaties(struct loaddata *loading);
 static void sg_save_treaties(struct savedata *saving);
 
 static void sg_load_mapimg(struct loaddata *loading);
@@ -563,6 +564,8 @@
   sg_load_researches(loading);
   /* [event_cache] */
   sg_load_event_cache(loading);
+  /* [treaties] */
+  sg_load_treaties(loading);
   /* [mapimg] */
   sg_load_mapimg(loading);
 
@@ -6458,6 +6461,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: trunk/server/srv_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=28335&r1=28334&r2=28335&view=diff
==============================================================================
--- trunk/server/srv_main.c     (original)
+++ trunk/server/srv_main.c     Sun Mar  1 02:39:25 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