Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10151) store the target government at the server
Home

[Freeciv-Dev] (PR#10151) store the target government at the server

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10151) store the target government at the server
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 16 Sep 2004 15:45:21 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10151 >

See PR#2327.

This patch causes the target government to be stored at the server.

- When a revolution is started at the client, the target government is 
sent to the server.  This government may be anarchy.  The client will 
not by default allow you to change back to the same government you're in.

- When the government receives the change_government packet, it sets the 
target government.  Then if a revolution is already in progress, it 
checks to see if the revolution can now be finished.  If there's no 
revolution in progress, it starts one.

- When a revolution is in progress the revolution_finishes counter gives 
the turn in which it will be complete.  As long as this turn isn't 
reached, the target government may be changed at will.  Once this turn 
is reached, the target government will automatically be switched to 
unless it's anarchy.  However the counter won't be reset until the next 
turn, so during the turn when the revolution ends you may switch at will.

- When starting a revolution, the revolution_finishes value is set. 
Setting this checks AI control (there's no AI handicap for this, yet) 
and statue-of-liberty effects.

- The target government is saved in the savegame.

- The target government is sent to players with INFO_EMBASSY level or 
higher.

I didn't change the GUIs but lots of improvements are possible.  The 
"choose government" dialog can be changed to a checkbox menu.  The 
inteldlg can show the target government for you or other players. 
Wherever it tells you you're in anarchy it can tell you the target 
government as well.

I tested it a fair amount but there's still a good chance of bugs.  In 
particular I've found there are bugs with events not showing up in the 
mssagedlg.  I think this is a larger bug than just revolutions, though...

jason

? drawn_sprites.diff
? freeciv.spec
? ftwl.diff
? settler_recursion_crash
? client/tilespec.diff
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.124
diff -u -r1.124 aitools.c
--- ai/aitools.c        13 Sep 2004 15:54:49 -0000      1.124
+++ ai/aitools.c        16 Sep 2004 22:42:43 -0000
@@ -637,14 +637,9 @@
   if (gov == pplayer->government) {
     return;
   }
-  pplayer->government = game.government_when_anarchy;
 
-  /* The AI cheats by having instant revolutions.
-   * TODO: turn this into a player handicap. */
-  pplayer->revolution_finishes = game.turn;
+  handle_player_change_government(pplayer, gov);
 
-  handle_player_government(pplayer, gov);
-  /* The revolution_finishes value need not be reset at this point. */
   city_list_iterate(pplayer->cities, pcity) {
     auto_arrange_workers(pcity); /* update cities */
   } city_list_iterate_end;
Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.195
diff -u -r1.195 civclient.c
--- client/civclient.c  12 Sep 2004 21:44:10 -0000      1.195
+++ client/civclient.c  16 Sep 2004 22:42:43 -0000
@@ -398,7 +398,6 @@
   game_init();
   attribute_init();
   agents_init();
-  target_government_init();
 }
 
 /**************************************************************************
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.402
diff -u -r1.402 packhand.c
--- client/packhand.c   13 Sep 2004 15:54:50 -0000      1.402
+++ client/packhand.c   16 Sep 2004 22:42:44 -0000
@@ -1462,41 +1462,15 @@
 }
 
 /**************************************************************************
-  government_selected will be set if the player has chosen a 'target'
-  government.  If so, then government_choice holds that government value.
-
-  revolution_over is set if the revolution is complete but the government
-  has not been set yet (it's still anarchy).  This value is used to
-  avoid giving the user duplicate messages or government choice menus.
-**************************************************************************/
-static bool government_selected = FALSE;
-static int government_choice;
-static bool revolution_over = FALSE;
-
-/**************************************************************************
-  Reset the target government (for instance when you disconnect from a
-  server).
-**************************************************************************/
-void target_government_init(void)
-{
-  /* We have to reset this, otherwise if we joined a new game where we
-   * were already in anarchy, odd behavior would result. */
-  government_selected = FALSE;
-  revolution_over = FALSE;
-}
-
-/**************************************************************************
   Sets the target government.  This will automatically start a revolution
   if the target government differs from the current one.
 **************************************************************************/
 void set_government_choice(int government)
 {
-  if (!government_selected && government != game.player_ptr->government
+  if (government != game.player_ptr->government
       && can_client_issue_orders()) {
-    send_packet_player_revolution(&aconnection);
-    government_selected = TRUE;
+    dsend_packet_player_change_government(&aconnection, government);
   }
-  government_choice = government;
 }
 
 /**************************************************************************
@@ -1505,37 +1479,8 @@
 **************************************************************************/
 void start_revolution(void)
 {
-  government_selected = FALSE;
-  send_packet_player_revolution(&aconnection);
-}
-
-/**************************************************************************
-  Choose the government after a revolution completes, either by taking the
-  government that the player has already specified or by popping up a
-  dialog to ask.
-**************************************************************************/
-static void choose_government(void)
-{
-  if (government_selected) {
-    dsend_packet_player_government(&aconnection, government_choice);
-
-    government_selected = FALSE;
-  } else if (!client_is_observer()) {
-    int i = 0, governments = game.government_count - 1;
-    struct government *government[governments];
-
-    assert(game.government_when_anarchy >= 0
-          && game.government_when_anarchy < game.government_count);
-
-    government_iterate(g) {
-      if (g->index != game.government_when_anarchy) {
-       government[i] = g;
-       i++;
-      }
-    } government_iterate_end;
-
-    popup_government_dialog(governments, government);
-  }
+  dsend_packet_player_change_government(&aconnection,
+                                       game.government_when_anarchy);
 }
 
 /**************************************************************************
@@ -1559,6 +1504,7 @@
   pplayer->economic.science=pinfo->science;
   pplayer->economic.luxury=pinfo->luxury;
   pplayer->government=pinfo->government;
+  pplayer->target_government = pinfo->target_government;
   pplayer->embassy=pinfo->embassy;
   pplayer->gives_shared_vision = pinfo->gives_shared_vision;
   pplayer->city_style=pinfo->city_style;
@@ -1644,15 +1590,8 @@
       && pplayer->revolution_finishes <= game.turn
       && pplayer->government == game.government_when_anarchy
       && (!game.player_ptr->ai.control || ai_popup_windows)
-      && can_client_change_view()
-      && !revolution_over) {
+      && can_client_change_view()) {
     create_event(-1, -1, E_REVOLT_DONE, _("Game: Revolution finished"));
-
-    choose_government();
-    revolution_over = TRUE;
-  } else if (pplayer == game.player_ptr
-            && pplayer->government != game.government_when_anarchy) {
-    revolution_over = FALSE; /* No revolution right now. */
   }
   
   update_players_dialog();
Index: client/gui-gtk/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v
retrieving revision 1.145
diff -u -r1.145 dialogs.c
--- client/gui-gtk/dialogs.c    10 Sep 2004 21:20:52 -0000      1.145
+++ client/gui-gtk/dialogs.c    16 Sep 2004 22:42:44 -0000
@@ -1179,7 +1179,7 @@
 *****************************************************************/
 static void government_callback(gpointer data)
 {
-  dsend_packet_player_government(&aconnection, GPOINTER_TO_INT(data));
+  set_government_choice(GPOINTER_TO_INT(data));
 
   assert(government_dialog_is_open);
   government_dialog_is_open = FALSE;
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.c,v
retrieving revision 1.72
diff -u -r1.72 dialogs.c
--- client/gui-gtk-2.0/dialogs.c        15 Sep 2004 19:49:09 -0000      1.72
+++ client/gui-gtk-2.0/dialogs.c        16 Sep 2004 22:42:44 -0000
@@ -1017,7 +1017,7 @@
 *****************************************************************/
 static void government_callback(GtkWidget *w, gpointer data)
 {
-  dsend_packet_player_government(&aconnection, GPOINTER_TO_INT(data));
+  set_government_choice(GPOINTER_TO_INT(data));
   is_showing_government_dialog = FALSE;
 }
 
Index: client/gui-sdl/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-sdl/dialogs.c,v
retrieving revision 1.48
diff -u -r1.48 dialogs.c
--- client/gui-sdl/dialogs.c    10 Sep 2004 21:20:52 -0000      1.48
+++ client/gui-sdl/dialogs.c    16 Sep 2004 22:42:45 -0000
@@ -3647,7 +3647,7 @@
 **************************************************************************/
 static int government_dlg_callback(struct GUI *pGov_Button)
 {
-  dsend_packet_player_government(&aconnection, MAX_ID - pGov_Button->ID);
+  set_government_choice(MAX_ID - pGov_Button->ID);
   popdown_window_group_dialog(pGov_Dlg->pBeginWidgetList,
                              pGov_Dlg->pEndWidgetList);
   FREE(pGov_Dlg);
Index: client/gui-win32/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/dialogs.c,v
retrieving revision 1.53
diff -u -r1.53 dialogs.c
--- client/gui-win32/dialogs.c  15 Sep 2004 19:49:09 -0000      1.53
+++ client/gui-win32/dialogs.c  16 Sep 2004 22:42:45 -0000
@@ -916,7 +916,7 @@
 **************************************************************************/ 
 static void government_callback(HWND w, void *data)
 {
-  dsend_packet_player_government(&aconnection, (size_t)data);
+  set_government_choice((size_t)data);
  
   destroy_message_dialog(w);
   is_showing_government_dialog=0;
Index: client/gui-xaw/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/dialogs.c,v
retrieving revision 1.101
diff -u -r1.101 dialogs.c
--- client/gui-xaw/dialogs.c    15 Sep 2004 19:49:10 -0000      1.101
+++ client/gui-xaw/dialogs.c    16 Sep 2004 22:42:45 -0000
@@ -1223,7 +1223,7 @@
 static void government_callback(Widget w, XtPointer client_data,
                                XtPointer call_data)
 {
-  dsend_packet_player_government(&aconnection, (size_t) client_data);
+  set_government_choice((size_t) client_data);
   destroy_message_dialog(w);
   is_showing_government_dialog = 0;
 }
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.51
diff -u -r1.51 packets.def
--- common/packets.def  13 Sep 2004 15:54:51 -0000      1.51
+++ common/packets.def  16 Sep 2004 22:42:46 -0000
@@ -535,6 +535,7 @@
   STRING name[MAX_LEN_NAME];
   BOOL is_male;
   GOVERNMENT government;
+  GOVERNMENT target_government;
   UINT32 embassy;
   UINT8 city_style;
   NATION nation;
@@ -572,10 +573,7 @@
   PERCENT tax, luxury, science;
 end
 
-PACKET_PLAYER_REVOLUTION=42;cs
-end
-
-PACKET_PLAYER_GOVERNMENT=43;cs,dsend
+PACKET_PLAYER_CHANGE_GOVERNMENT=43;cs,dsend
   GOVERNMENT government;
 end
 
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.125
diff -u -r1.125 player.h
--- common/player.h     15 Sep 2004 09:31:56 -0000      1.125
+++ common/player.h     16 Sep 2004 22:42:46 -0000
@@ -181,6 +181,7 @@
   char username[MAX_LEN_NAME];
   bool is_male;
   int government;
+  int target_government;
   Nation_Type_id nation;
   Team_Type_id team;
   bool turn_done;
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.262
diff -u -r1.262 cityturn.c
--- server/cityturn.c   14 Sep 2004 17:39:32 -0000      1.262
+++ server/cityturn.c   16 Sep 2004 22:42:46 -0000
@@ -1352,7 +1352,7 @@
                       _("Game: The people have overthrown your %s, "
                         "your country is in turmoil."),
                       get_government_name(g->index));
-      handle_player_revolution(pplayer);
+      handle_player_change_government(pplayer, g->index);
     }
     sanity_check_city(pcity);
   }
Index: server/plrhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/plrhand.c,v
retrieving revision 1.325
diff -u -r1.325 plrhand.c
--- server/plrhand.c    15 Sep 2004 09:42:58 -0000      1.325
+++ server/plrhand.c    16 Sep 2004 22:42:47 -0000
@@ -157,39 +157,6 @@
   }
 }
 
-/**************************************************************************
-  See if the player has finished their revolution.  This function should
-  be called at the beginning of a player's phase.
-**************************************************************************/
-void update_revolution(struct player *pplayer)
-{
-  /* The player's revolution counter is stored in the revolution_finishes
-   * field.  This value has the following meanings:
-   *   - If negative (-1), then the player is not in a revolution.  In this
-   *     case the player should never be in anarchy.
-   *   - If positive, the player is in the middle of a revolution.  In this
-   *     case the value indicates the turn in which the revolution finishes.
-   *     * If this value is > than the current turn, then the revolution is
-   *       in progress.  In this case the player should always be in anarchy.
-   *     * If the value is == to the current turn, then the revolution is
-   *       finished.  The player may now choose a government.  However the
-   *       value isn't reset until the end of the turn.  If the player has
-   *       chosen a government by the end of the turn, then the revolution is
-   *       over and the value is reset to -1.
-   *     * If the player doesn't pick a government then the revolution
-   *       continues.  At this point the value is <= to the current turn,
-   *       and the player can leave the revolution at any time.  The value
-   *       is reset at the end of any turn when a non-anarchy government is
-   *       chosen.
-   */
-  if (pplayer->revolution_finishes <= game.turn
-      && pplayer->government != game.government_when_anarchy) {
-    /* Reset the revolution counter.  If the player has another revolution
-     * they'll have to re-enter anarchy. */
-    pplayer->revolution_finishes = -1;
-  }
-}
-
 /****************************************************************************
   Check all players to see if they are dying.  Kill them if so.
 
@@ -872,21 +839,30 @@
 }
 
 /**************************************************************************
-...
+  Finish the revolution and set the player's government.  Call this as soon
+  as the player has set a target_government and the revolution_finishes
+  turn has arrived.
 **************************************************************************/
-void handle_player_government(struct player *pplayer, int government)
+static void finish_revolution(struct player *pplayer)
 {
-  if (government < 0 || government >= game.government_count ||
-      !can_change_to_government(pplayer, government)) {
+  int government = pplayer->target_government;
+
+  if (pplayer->target_government == game.government_when_anarchy) {
+    assert(0);
     return;
   }
-
-  if (pplayer->revolution_finishes < 0
-      || pplayer->revolution_finishes > game.turn) {
+  if (pplayer->revolution_finishes > game.turn) {
+    assert(0);
     return;
   }
 
   pplayer->government = government;
+  /* Leave the target government the same. */
+
+  freelog(LOG_DEBUG,
+         "Revolution finished for %s.  Government is %s.  Revofin %d (%d).",
+         pplayer->name, get_government_name(government),
+         pplayer->revolution_finishes, game.turn);
   notify_player(pplayer, _("Game: %s now governs the %s as a %s."), 
                pplayer->name, 
                get_nation_name_plural(pplayer->nation),
@@ -897,11 +873,14 @@
 
   if (!pplayer->ai.control) {
     /* Keep luxuries if we have any.  Try to max out science. -GJW */
-    pplayer->economic.science = MIN (100 - pplayer->economic.luxury,
-                                    get_government_max_rate 
(pplayer->government));
-    pplayer->economic.tax = MIN(100 - (pplayer->economic.luxury + 
pplayer->economic.science),
-                               get_government_max_rate (pplayer->government));
-    pplayer->economic.luxury = 100 - pplayer->economic.science - 
pplayer->economic.tax;
+    int max = get_government_max_rate(pplayer->government);
+
+    pplayer->economic.science
+      = MIN(100 - pplayer->economic.luxury, max);
+    pplayer->economic.tax
+      = MIN(100 - pplayer->economic.luxury - pplayer->economic.science, max);
+    pplayer->economic.luxury
+      = 100 - pplayer->economic.science - pplayer->economic.tax;
   }
 
   check_player_government_rates(pplayer);
@@ -910,39 +889,138 @@
 }
 
 /**************************************************************************
-...
+  Start a revolution.  This can be called even for AI players; it will
+  call finish_revolution immediately if no revolution is needed.
 **************************************************************************/
-void handle_player_revolution(struct player *pplayer)
+static void start_revolution(struct player *pplayer)
 {
-  if (pplayer->government == game.government_when_anarchy) {
-    /* Already having a revolution. */
-    return;
-  }
-  if (pplayer->revolution_finishes < 0) {
-    /* Start a revolution from scratch (otherwise a revolution is in
-     * progress, even if the player isn't in anarchy). */
-    if (game.revolution_length == 0) {
-      pplayer->revolution_finishes = game.turn + myrand(5) + 1;
-    } else {
-      pplayer->revolution_finishes = game.revolution_length;
-    }
+  pplayer->government = game.government_when_anarchy;
+
+  /* Set revolution_finishes value. */
+  if (pplayer->revolution_finishes > 0) {
+    /* Player already has an active revolution. */
+  } else if (pplayer->ai.control
+            || get_player_bonus(pplayer, EFT_NO_ANARCHY)) {
+    /* TODO: Make this a handicap. */
+    pplayer->revolution_finishes = game.turn;
+  } else if (game.revolution_length == 0) {
+    pplayer->revolution_finishes = game.turn + myrand(5) + 1;
+  } else {
+    pplayer->revolution_finishes = game.revolution_length;
   }
-  pplayer->government=game.government_when_anarchy;
+
+  freelog(LOG_DEBUG,
+         "Revolution started for %s.  Target government is %s.  "
+         "Revofin %d (%d).",
+         pplayer->name, get_government_name(pplayer->target_government),
+         pplayer->revolution_finishes, game.turn);
   notify_player_ex(pplayer, -1, -1, E_REVOLT_START,
                   _("Game: The %s have incited a revolt!"),
                   get_nation_name_plural(pplayer->nation));
   gamelog(GAMELOG_REVOLT, _("The %s revolt!"),
          get_nation_name_plural(pplayer->nation));
 
+  /* Now see if the revolution is instantaneous. */
+  if (pplayer->revolution_finishes <= game.turn
+      && pplayer->target_government != game.government_when_anarchy) {
+    finish_revolution(pplayer);
+    return;
+  }
+
   check_player_government_rates(pplayer);
   global_city_refresh(pplayer);
-  if (get_player_bonus(pplayer, EFT_NO_ANARCHY) > 0) {
-    pplayer->revolution_finishes = game.turn;
-  }
   send_player_info(pplayer, pplayer);
 }
 
 /**************************************************************************
+  Called by the client or AI to change government.
+**************************************************************************/
+void handle_player_change_government(struct player *pplayer, int government)
+{
+  if (government < 0 || government >= game.government_count
+      || !can_change_to_government(pplayer, government)) {
+    return;
+  }
+
+  pplayer->target_government = government;
+
+  freelog(LOG_DEBUG,
+         "Government changed for %s.  Target government is %s; "
+         "old %s.  Revofin %d, Turn %d.",
+         pplayer->name,
+         get_government_name(pplayer->target_government),
+         get_government_name(pplayer->government),
+         pplayer->revolution_finishes, game.turn);
+
+  if (pplayer->government == game.government_when_anarchy) {
+    /* Already having a revolution. */
+    assert(pplayer->revolution_finishes >= 0);
+    if (pplayer->revolution_finishes <= game.turn) {
+      /* The revolution was already over.  Now we should enter the new
+       * government immediately. */
+      finish_revolution(pplayer);
+    }
+  } else {
+    /* No revolution: start one. */
+    start_revolution(pplayer);
+  }
+
+  freelog(LOG_DEBUG,
+         "Government change complete for %s.  Target government is %s; "
+         "now %s.  Turn %d; revofin %d.",
+         pplayer->name,
+         get_government_name(pplayer->target_government),
+         get_government_name(pplayer->government),
+         game.turn, pplayer->revolution_finishes);
+}
+
+/**************************************************************************
+  See if the player has finished their revolution.  This function should
+  be called at the beginning of a player's phase.
+**************************************************************************/
+void update_revolution(struct player *pplayer)
+{
+  /* The player's revolution counter is stored in the revolution_finishes
+   * field.  This value has the following meanings:
+   *   - If negative (-1), then the player is not in a revolution.  In this
+   *     case the player should never be in anarchy.
+   *   - If positive, the player is in the middle of a revolution.  In this
+   *     case the value indicates the turn in which the revolution finishes.
+   *     * If this value is > than the current turn, then the revolution is
+   *       in progress.  In this case the player should always be in anarchy.
+   *     * If the value is == to the current turn, then the revolution is
+   *       finished.  The player may now choose a government.  However the
+   *       value isn't reset until the end of the turn.  If the player has
+   *       chosen a government by the end of the turn, then the revolution is
+   *       over and the value is reset to -1.
+   *     * If the player doesn't pick a government then the revolution
+   *       continues.  At this point the value is <= to the current turn,
+   *       and the player can leave the revolution at any time.  The value
+   *       is reset at the end of any turn when a non-anarchy government is
+   *       chosen.
+   */
+  freelog(LOG_DEBUG, "Update revolution for %s.  Current government %s, "
+         "target %s, revofin %d, turn %d.",
+         pplayer->name, get_government_name(pplayer->government),
+         get_government_name(pplayer->target_government),
+         pplayer->revolution_finishes, game.turn);
+  if (pplayer->government == game.government_when_anarchy
+      && pplayer->target_government != game.government_when_anarchy
+      && pplayer->revolution_finishes == game.turn) {
+    freelog(LOG_DEBUG, "Update: finishing revolution for %s.",
+           pplayer->name);
+    finish_revolution(pplayer);
+  } else if (pplayer->government != game.government_when_anarchy
+            && pplayer->revolution_finishes < game.turn) {
+    /* Reset the revolution counter.  If the player has another revolution
+     * they'll have to re-enter anarchy. */
+    freelog(LOG_DEBUG, "Update: resetting revofin for %s.",
+           pplayer->name);
+    pplayer->revolution_finishes = -1;
+  }
+}
+
+/**************************************************************************
 The following checks that government rates are acceptable for the present
 form of government. Has to be called when switching governments or when
 toggling from AI to human.
@@ -1103,7 +1181,7 @@
         notify_player_ex(pplayer, -1, -1, E_ANARCHY,
                          _("Game: The senate decides to dissolve "
                          "rather than support your actions any longer."));
-       handle_player_revolution(pplayer);
+       handle_player_change_government(pplayer, pplayer->government);
       }
     }
   }
@@ -1411,6 +1489,7 @@
    * contact with. */
   if (info_level >= INFO_EMBASSY
       || receiver->diplstates[plr->player_no].contact_turns_left > 0) {
+    packet->target_government = plr->target_government;
     packet->embassy = plr->embassy;
     packet->gives_shared_vision = plr->gives_shared_vision;
     for(i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
@@ -1421,6 +1500,7 @@
       packet->diplstates[i].has_reason_to_cancel = 
plr->diplstates[i].has_reason_to_cancel;
     }
   } else {
+    packet->target_government = packet->government;
     if (!receiver || !player_has_embassy(plr, receiver)) {
       packet->embassy  = 0;
     } else {
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.187
diff -u -r1.187 savegame.c
--- server/savegame.c   16 Sep 2004 04:38:25 -0000      1.187
+++ server/savegame.c   16 Sep 2004 22:42:48 -0000
@@ -1507,7 +1507,23 @@
     exit(EXIT_FAILURE);
   }
   plr->government = gov->index;
-  
+
+  /* Target government */
+  name = secfile_lookup_str_default(file, NULL,
+                                   "player%d.target_government_name",
+                                   plrno);
+  if (name) {
+    gov = find_government_by_name_orig(name);
+  } else {
+    gov = NULL;
+  }
+  if (gov) {
+    plr->target_government = gov->index;
+  } else {
+    /* Old servers didn't have this value. */
+    plr->target_government = plr->government;
+  }
+
   plr->embassy=secfile_lookup_int(file, "player%d.embassy", plrno);
 
   p = secfile_lookup_str_default(file, NULL, "player%d.city_style_by_name",
@@ -2229,6 +2245,10 @@
    * compatibility */
   secfile_insert_int(file, old_government_id(gov),
                      "player%d.government", plrno);
+
+  gov = get_government(plr->target_government);
+  secfile_insert_str(file, gov->name_orig,
+                    "player%d.target_government_name", plrno);
   
   secfile_insert_int(file, plr->embassy, "player%d.embassy", plrno);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#10151) store the target government at the server, Jason Short <=