Author: cazfi
Date: Tue Dec 15 15:16:47 2015
New Revision: 31008

URL: http://svn.gna.org/viewcvs/freeciv?rev=31008&view=rev
Log:
Save player flags to savegame.

See patch #6674

Modified:
    trunk/server/savecompat.c
    trunk/server/savegame3.c

Modified: trunk/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=31008&r1=31007&r2=31008&view=diff
==============================================================================
--- trunk/server/savecompat.c   (original)
+++ trunk/server/savecompat.c   Tue Dec 15 15:16:47 2015
@@ -1127,7 +1127,9 @@
 static void compat_load_030000(struct loaddata *loading)
 {
   bool randsaved;
-  
+  int plrno;
+  int nplayers;
+
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
 
@@ -1139,6 +1141,20 @@
   } else {
     log_sg("random.save: %s", secfile_error());
   }
+
+  nplayers = secfile_lookup_int_default(loading->file, 0, "players.nplayers");
+
+  for (plrno = 0; plrno < nplayers; plrno++) {
+    const char *flag_names[1];
+
+    if (secfile_lookup_bool_default(loading->file, FALSE, 
"player%d.ai.control",
+                                    plrno)) {
+      flag_names[0] = plr_flag_id_name(PLRF_AI);
+
+      secfile_insert_str_vec(loading->file, flag_names, 1,
+                             "player%d.flags", plrno);
+    }
+  }
 }
 
 #ifdef FREECIV_DEV_SAVE_COMPAT
@@ -1188,6 +1204,19 @@
   }
 
   nplayers = secfile_lookup_int_default(loading->file, 0, "players.nplayers");
+
+  /* Convert ai.control to a player flag */
+  for (plrno = 0; plrno < nplayers; plrno++) {
+    const char *flag_names[1];
+
+    if (secfile_lookup_bool_default(loading->file, FALSE, 
"player%d.ai.control",
+                                    plrno)) {
+      flag_names[0] = plr_flag_id_name(PLRF_AI);
+
+      secfile_insert_str_vec(loading->file, flag_names, 1,
+                             "player%d.flags", plrno);
+    }
+  }
 
   for (plrno = 0; plrno < nplayers; plrno++) {
     /* Add 'anonymous' qualifiers for user names */

Modified: trunk/server/savegame3.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savegame3.c?rev=31008&r1=31007&r2=31008&view=diff
==============================================================================
--- trunk/server/savegame3.c    (original)
+++ trunk/server/savegame3.c    Tue Dec 15 15:16:47 2015
@@ -3570,12 +3570,13 @@
 static void sg_load_player_main(struct loaddata *loading,
                                 struct player *plr)
 {
+  const char **slist;
   int i, plrno = player_number(plr);
   const char *string;
   struct government *gov;
   const char *level;
   const char *barb_str;
-  bool ai_controlled;
+  size_t nval;
 
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
@@ -3605,6 +3606,17 @@
     player_delegation_set(plr, string);
   }
 
+  /* Player flags */
+  BV_CLR_ALL(plr->flags);
+  slist = secfile_lookup_str_vec(loading->file, &nval, "player%d.flags", 
plrno);
+  for (i = 0; i < nval; i++) {
+    const char *sval = slist[i];
+    enum plr_flag_id fid = plr_flag_id_by_name(sval, fc_strcasecmp);
+
+    BV_SET(plr->flags, fid);
+  }
+  free(slist);
+
   /* Nation */
   string = secfile_lookup_str(loading->file, "player%d.nation", plrno);
   player_set_nation(plr, nation_by_rule_name(string));
@@ -3636,15 +3648,6 @@
                                      &plr->server.got_first_city,
                                      "player%d.got_first_city", plrno),
                  "%s", secfile_error());
-
-  sg_failure_ret(secfile_lookup_bool(loading->file, &ai_controlled,
-                                     "player%d.ai.control", plrno),
-                 "%s", secfile_error());
-  if (ai_controlled) {
-    set_as_ai(player_by_number(plrno));
-  } else {
-    set_as_human(player_by_number(plrno));
-  }
 
   /* Load diplomatic data (diplstate + embassy + vision).
    * Shared vision is loaded in sg_load_players(). */
@@ -4028,9 +4031,21 @@
 {
   int i, k, plrno = player_number(plr);
   struct player_spaceship *ship = &plr->spaceship;
+  const char *flag_names[PLRF_COUNT];
+  int set_count;
 
   /* Check status and return if not OK (sg_success != TRUE). */
   sg_check_ret();
+
+  set_count = 0;
+  for (i = 0; i < PLRF_COUNT; i++){
+    if (player_has_flag(plr, i)) {
+      flag_names[set_count++] = plr_flag_id_name(i);
+    }
+  }
+
+  secfile_insert_str_vec(saving->file, flag_names, set_count,
+                         "player%d.flags", plrno);
 
   secfile_insert_str(saving->file, ai_name(plr->ai),
                      "player%d.ai_type", plrno);
@@ -4082,8 +4097,6 @@
                      "player%d.turns_alive", plrno);
   secfile_insert_int(saving->file, plr->last_war_action,
                      "player%d.last_war", plrno);
-  secfile_insert_bool(saving->file, is_ai(plr),
-                      "player%d.ai.control", plrno);
   secfile_insert_bool(saving->file, plr->phase_done,
                       "player%d.phase_done", plrno);
 


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

Reply via email to