Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] (PR#13678) use pointers for governments
Home

[Freeciv-Dev] (PR#13678) use pointers for governments

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13678) use pointers for governments
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 15 Aug 2005 10:05:34 -0700
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13678 >

This patch changes all users to use pointers for governments rather than 
index values.  Lots of places already used pointers, so this means fewer 
swaps.  However a few extra lines are necessary because of 
game.info.government_when_anarchy which "has" to be an index value.

-jason

Index: ai/advdiplomacy.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdiplomacy.c,v
retrieving revision 1.87
diff -p -u -r1.87 advdiplomacy.c
--- ai/advdiplomacy.c   4 Aug 2005 16:26:11 -0000       1.87
+++ ai/advdiplomacy.c   15 Aug 2005 17:03:50 -0000
@@ -1090,7 +1090,7 @@ static void ai_go_to_war(struct player *
   /* Check for Senate obstruction.  If so, dissolve it. */
   if (!pplayer_can_declare_war(pplayer, target)) {
     handle_player_change_government(pplayer, 
-                                    game.info.government_when_anarchy);
+                                    game.info.government_when_anarchy_id);
   }
 
   /* This will take us straight to war. */
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.236
diff -p -u -r1.236 aicity.c
--- ai/aicity.c 11 Aug 2005 02:22:48 -0000      1.236
+++ ai/aicity.c 15 Aug 2005 17:03:51 -0000
@@ -417,7 +417,7 @@ static void adjust_building_want_by_effe
          v += c + MIN(ai->stats.units.land, 13);
          break;
        case EFT_ANY_GOVERNMENT:
-         if (!can_change_to_government(pplayer, ai->goal.govt.idx)) {
+         if (!can_change_to_government(pplayer, ai->goal.govt.gov)) {
            v += MIN(MIN(ai->goal.govt.val, 65),
                num_unknown_techs_for_goal(pplayer, ai->goal.govt.req) * 10);
          }
Index: ai/aidata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.h,v
retrieving revision 1.33
diff -p -u -r1.33 aidata.h
--- ai/aidata.h 4 Aug 2005 16:26:12 -0000       1.33
+++ ai/aidata.h 15 Aug 2005 17:03:51 -0000
@@ -146,11 +146,11 @@ struct ai_data {
   /* Goals */
   struct {
     struct {
-      int idx;        /* Id of the ideal government */
+      struct government *gov;        /* The ideal government */
       int val;        /* Its value (relative to the current gov) */
       int req;        /* The tech requirement for the ideal gov */
     } govt;
-    int revolution;   /* The best gov of the now available */
+    struct government *revolution;   /* The best gov of the now available */
   } goal;
   
   /* If the ai doesn't want/need any research */
Index: ai/aihand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aihand.c,v
retrieving revision 1.119
diff -p -u -r1.119 aihand.c
--- ai/aihand.c 4 Aug 2005 16:26:12 -0000       1.119
+++ ai/aihand.c 15 Aug 2005 17:03:51 -0000
@@ -107,7 +107,7 @@ static void ai_manage_taxes(struct playe
     return; /* This ruleset does not support changing tax rates. */
   }
 
-  if (get_gov_pplayer(pplayer)->index == game.info.government_when_anarchy) {
+  if (get_gov_pplayer(pplayer) == game.government_when_anarchy) {
     return; /* This government does not support changing tax rates. */
   }
 
@@ -276,9 +276,9 @@ void ai_best_government(struct player *p
   struct ai_data *ai = ai_data_get(pplayer);
   int best_val = 0;
   int bonus = 0; /* in percentage */
-  int current_gov = pplayer->government;
+  struct government *current_gov = pplayer->government;
 
-  ai->goal.govt.idx = pplayer->government;
+  ai->goal.govt.gov = pplayer->government;
   ai->goal.govt.val = 0;
   ai->goal.govt.req = A_UNSET;
   ai->goal.revolution = pplayer->government;
@@ -292,14 +292,14 @@ void ai_best_government(struct player *p
       int val = 0;
       int dist;
 
-      if (gov->index == game.info.government_when_anarchy) {
+      if (gov == game.government_when_anarchy) {
         continue; /* pointless */
       }
-      if (gov->ai_better != G_MAGIC
-          && can_change_to_government(pplayer, gov->ai_better)) {
+      if (gov->ai.better
+          && can_change_to_government(pplayer, gov->ai.better)) {
         continue; /* we have better governments available */
       }
-      pplayer->government = gov->index;
+      pplayer->government = gov;
       /* Ideally we should change tax rates here, but since
        * this is a rather big CPU operation, we'd rather not. */
       check_player_government_rates(pplayer);
@@ -351,12 +351,12 @@ void ai_best_government(struct player *p
   /* Figure out which government is the best for us this turn. */
   government_iterate(gov) {
     if (ai->government_want[gov->index] > best_val 
-        && can_change_to_government(pplayer, gov->index)) {
+        && can_change_to_government(pplayer, gov)) {
       best_val = ai->government_want[gov->index];
-      ai->goal.revolution = gov->index;
+      ai->goal.revolution = gov;
     }
     if (ai->government_want[gov->index] > ai->goal.govt.val) {
-      ai->goal.govt.idx = gov->index;
+      ai->goal.govt.gov = gov;
       ai->goal.govt.val = ai->government_want[gov->index];
 
       /* FIXME: handle reqs other than technologies. */
@@ -407,7 +407,7 @@ static void ai_manage_government(struct 
     pplayer->ai.tech_want[ai->goal.govt.req] += want;
     TECH_LOG(LOG_DEBUG, pplayer, ai->goal.govt.req, "+ %d for %s in "
              "ai_manage_government", want,
-             get_government_name(ai->goal.govt.idx));
+             get_government_name(ai->goal.govt.gov));
   }
 }
 
Index: ai/aisettler.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aisettler.c,v
retrieving revision 1.28
diff -p -u -r1.28 aisettler.c
--- ai/aisettler.c      11 Aug 2005 02:22:48 -0000      1.28
+++ ai/aisettler.c      15 Aug 2005 17:03:51 -0000
@@ -116,10 +116,10 @@ void cityresult_fill(struct player *ppla
   struct city *pcity = tile_get_city(result->tile);
   int sum = 0;
   bool virtual_city = FALSE;
-  int curr_govt = pplayer->government;
+  struct government *curr_govt = pplayer->government;
   bool handicap = ai_handicap(pplayer, H_MAP);
 
-  pplayer->government = ai->goal.govt.idx;
+  pplayer->government = ai->goal.govt.gov;
 
   result->best_other = 0;
   result->other_tile = NULL;
Index: ai/aitools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.c,v
retrieving revision 1.159
diff -p -u -r1.159 aitools.c
--- ai/aitools.c        4 Aug 2005 16:26:12 -0000       1.159
+++ ai/aitools.c        15 Aug 2005 17:03:51 -0000
@@ -1062,13 +1062,13 @@ int stack_cost(struct unit *pdef)
 /**************************************************************************
   Change government, pretty fast...
 **************************************************************************/
-void ai_government_change(struct player *pplayer, int gov)
+void ai_government_change(struct player *pplayer, struct government *gov)
 {
   if (gov == pplayer->government) {
     return;
   }
 
-  handle_player_change_government(pplayer, gov);
+  handle_player_change_government(pplayer, gov->index);
 
   city_list_iterate(pplayer->cities, pcity) {
     auto_arrange_workers(pcity); /* update cities */
Index: ai/aitools.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aitools.h,v
retrieving revision 1.59
diff -p -u -r1.59 aitools.h
--- ai/aitools.h        4 Aug 2005 16:26:12 -0000       1.59
+++ ai/aitools.h        15 Aug 2005 17:03:51 -0000
@@ -87,7 +87,7 @@ bool ai_unit_move(struct unit *punit, st
 struct city *dist_nearest_city(struct player *pplayer, struct tile *ptile,
                                bool everywhere, bool enemy);
 
-void ai_government_change(struct player *pplayer, int gov);
+void ai_government_change(struct player *pplayer, struct government *gov);
 int ai_gold_reserve(struct player *pplayer);
 
 void init_choice(struct ai_choice *choice);
Index: client/climisc.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/climisc.c,v
retrieving revision 1.178
diff -p -u -r1.178 climisc.c
--- client/climisc.c    8 Aug 2005 16:15:28 -0000       1.178
+++ client/climisc.c    15 Aug 2005 17:03:51 -0000
@@ -375,7 +375,7 @@ struct sprite *client_cooling_sprite(voi
 struct sprite *client_government_sprite(void)
 {
   if (can_client_change_view() && game.control.government_count > 0) {
-    struct government *gov = get_government(game.player_ptr->government);
+    struct government *gov = game.player_ptr->government;
 
     return get_government_sprite(tileset, gov);
   } else {
Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.123
diff -p -u -r1.123 helpdata.c
--- client/helpdata.c   11 Aug 2005 02:22:48 -0000      1.123
+++ client/helpdata.c   15 Aug 2005 17:03:51 -0000
@@ -746,7 +746,7 @@ void helptext_unit(char *buf, struct uni
   }
   
   buf[0] = '\0';
-  if (utype->gov_requirement != G_MAGIC) {
+  if (utype->gov_requirement) {
     sprintf(buf + strlen(buf),
            _("* Can only be built with %s as government.\n"), 
             get_government_name(utype->gov_requirement));
@@ -1233,9 +1233,9 @@ void helptext_terrain(char *buf, const s
 /****************************************************************
   Append text for government.
 *****************************************************************/
-void helptext_government(char *buf, int i, const char *user_text)
+void helptext_government(char *buf, struct government *gov,
+                        const char *user_text)
 {
-  struct government *gov;
   bool active_types[O_MAX];
   const size_t bufsz = 64000; /* FIXME: should be passed in */
 
@@ -1252,12 +1252,6 @@ void helptext_government(char *buf, int 
   
   buf[0] = '\0';
 
-  if (i < 0 || i >= game.control.government_count) {
-    freelog(LOG_ERROR, "Unknown government %d.", i);
-    return;
-  }
-
-  gov = get_government(i);
   if (gov->helptext[0] != '\0') {
     sprintf(buf, "%s\n\n", _(gov->helptext));
   }
@@ -1471,7 +1465,7 @@ void helptext_government(char *buf, int 
   }
 #endif
   unit_type_iterate(utype) {
-    if (utype->gov_requirement == i) {
+    if (utype->gov_requirement == gov) {
       sprintf(buf + strlen(buf),
              _("* Allows you to build %s.\n"), unit_name(utype));
     }
Index: client/helpdata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.h,v
retrieving revision 1.15
diff -p -u -r1.15 helpdata.h
--- client/helpdata.h   22 Jul 2005 16:18:05 -0000      1.15
+++ client/helpdata.h   15 Aug 2005 17:03:51 -0000
@@ -45,7 +45,8 @@ void helptext_unit(char *buf, struct uni
 void helptext_tech(char *buf, int i, const char *user_text);
 void helptext_terrain(char *buf, const struct terrain *pterrain,
                      const char *user_text);
-void helptext_government(char *buf, int i, const char *user_text);
+void helptext_government(char *buf, struct government *gov,
+                        const char *user_text);
 
 char *helptext_unit_upkeep_str(struct unit_type *punittype);
 
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.541
diff -p -u -r1.541 packhand.c
--- client/packhand.c   1 Aug 2005 22:38:23 -0000       1.541
+++ client/packhand.c   15 Aug 2005 17:03:52 -0000
@@ -1342,8 +1342,9 @@ void handle_game_info(struct packet_game
 
   game.info = *pinfo;
 
+  game.government_when_anarchy
+    = get_government(game.info.government_when_anarchy_id);
   if (!can_client_change_view()) {
-    game.info.player_idx = pinfo->player_idx;
     game.player_ptr = &game.players[game.info.player_idx];
   }
   if (get_client_state() == CLIENT_PRE_GAME_STATE) {
@@ -1392,11 +1393,11 @@ static bool read_player_info_techs(struc
   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)
+void set_government_choice(struct government *government)
 {
   if (government != game.player_ptr->government
       && can_client_issue_orders()) {
-    dsend_packet_player_change_government(&aconnection, government);
+    dsend_packet_player_change_government(&aconnection, government->index);
   }
 }
 
@@ -1407,7 +1408,7 @@ void set_government_choice(int governmen
 void start_revolution(void)
 {
   dsend_packet_player_change_government(&aconnection,
-                                       game.info.government_when_anarchy);
+                                       game.info.government_when_anarchy_id);
 }
 
 /**************************************************************************
@@ -1433,8 +1434,8 @@ void handle_player_info(struct packet_pl
   pplayer->economic.tax=pinfo->tax;
   pplayer->economic.science=pinfo->science;
   pplayer->economic.luxury=pinfo->luxury;
-  pplayer->government=pinfo->government;
-  pplayer->target_government = pinfo->target_government;
+  pplayer->government = get_government(pinfo->government);
+  pplayer->target_government = get_government(pinfo->target_government);
   BV_CLR_ALL(pplayer->embassy);
   players_iterate(pother) {
     if (pinfo->embassy[pother->player_no]) {
@@ -2077,7 +2078,7 @@ void handle_ruleset_unit(struct packet_r
   u->move_rate          = p->move_rate;
   u->tech_requirement   = p->tech_requirement;
   u->impr_requirement   = p->impr_requirement;
-  u->gov_requirement    = p->gov_requirement;
+  u->gov_requirement = get_government(p->gov_requirement);
   u->vision_range       = p->vision_range;
   u->transport_capacity = p->transport_capacity;
   u->hp                 = p->hp;
@@ -2383,7 +2384,7 @@ void handle_ruleset_nation(struct packet
          sizeof(pl->init_buildings));
   memcpy(pl->init_units, p->init_units, 
          sizeof(pl->init_units));
-  pl->init_government = p->init_government;
+  pl->init_government = get_government(p->init_government);
 
   if (p->legend[0] != '\0') {
     pl->legend = mystrdup(_(p->legend));
Index: client/packhand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.h,v
retrieving revision 1.38
diff -p -u -r1.38 packhand.h
--- client/packhand.h   29 Sep 2004 02:24:19 -0000      1.38
+++ client/packhand.h   15 Aug 2005 17:03:52 -0000
@@ -26,7 +26,7 @@ void set_reports_thaw_request(int reques
 
 void play_sound_for_event(enum event_type type);
 void target_government_init(void);
-void set_government_choice(int government);
+void set_government_choice(struct government *government);
 void start_revolution(void);
 
 #endif /* FC__PACKHAND_H */
Index: client/repodlgs_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/repodlgs_common.c,v
retrieving revision 1.28
diff -p -u -r1.28 repodlgs_common.c
--- client/repodlgs_common.c    11 Aug 2005 04:43:24 -0000      1.28
+++ client/repodlgs_common.c    15 Aug 2005 17:03:52 -0000
@@ -71,7 +71,7 @@ void get_economy_report_data(struct impr
       /* Currently there is no building expense under anarchy.  It's
        * not a good idea to hard-code this in the client, but what
        * else can we do? */
-      if (game.player_ptr->government != game.info.government_when_anarchy) {
+      if (game.player_ptr->government != game.government_when_anarchy) {
         *total_cost += cost;
       }
     }
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.114
diff -p -u -r1.114 dialogs.c
--- client/gui-gtk-2.0/dialogs.c        26 Jul 2005 16:35:57 -0000      1.114
+++ client/gui-gtk-2.0/dialogs.c        15 Aug 2005 17:03:53 -0000
@@ -1008,10 +1008,10 @@ bool caravan_dialog_is_open(void)
 *****************************************************************/
 static void revolution_response(GtkWidget *w, gint response, gpointer data)
 {
-  int government = GPOINTER_TO_INT(data);
+  struct government *government = data;
 
   if (response == GTK_RESPONSE_YES) {
-    if (government == -1) {
+    if (!government) {
       start_revolution();
     } else {
       set_government_choice(government);
@@ -1025,11 +1025,11 @@ static void revolution_response(GtkWidge
 /****************************************************************
 ...
 *****************************************************************/
-void popup_revolution_dialog(int government)
+void popup_revolution_dialog(struct government *government)
 {
   static GtkWidget *shell = NULL;
 
-  if (game.player_ptr->revolution_finishes == -1) {
+  if (game.player_ptr->revolution_finishes < 0) {
     if (!shell) {
       shell = gtk_message_dialog_new(NULL,
          0,
@@ -1043,11 +1043,11 @@ void popup_revolution_dialog(int governm
          G_CALLBACK(gtk_widget_destroyed), &shell);
     }
     g_signal_connect(shell, "response",
-       G_CALLBACK(revolution_response), GINT_TO_POINTER(government));
+       G_CALLBACK(revolution_response), government);
 
     gtk_window_present(GTK_WINDOW(shell));
   } else {
-    revolution_response(shell, GTK_RESPONSE_YES, GINT_TO_POINTER(government));
+    revolution_response(shell, GTK_RESPONSE_YES, government);
   }
 }
 
Index: client/gui-gtk-2.0/dialogs.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.h,v
retrieving revision 1.8
diff -p -u -r1.8 dialogs.h
--- client/gui-gtk-2.0/dialogs.h        3 Apr 2005 11:34:58 -0000       1.8
+++ client/gui-gtk-2.0/dialogs.h        15 Aug 2005 17:03:53 -0000
@@ -19,7 +19,7 @@
 
 #include "dialogs_g.h"
 
-void popup_revolution_dialog(int government);
+void popup_revolution_dialog(struct government *government);
 void message_dialog_button_set_sensitive(GtkWidget *shl, int button,
                                         gboolean state);
 GtkWidget *popup_message_dialog(GtkWindow *parent, const gchar *dialogname,
Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/helpdlg.c,v
retrieving revision 1.61
diff -p -u -r1.61 helpdlg.c
--- client/gui-gtk-2.0/helpdlg.c        4 Aug 2005 17:49:03 -0000       1.61
+++ client/gui-gtk-2.0/helpdlg.c        15 Aug 2005 17:03:53 -0000
@@ -1142,7 +1142,7 @@ static void help_update_government(const
   if (!gov) {
     strcat(buf, pitem->text);
   } else {
-    helptext_government(buf, gov-governments, pitem->text);
+    helptext_government(buf, gov, pitem->text);
   }
   create_help_page(HELP_TEXT);
   gtk_text_buffer_set_text(help_text, buf, -1);
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.83
diff -p -u -r1.83 menu.c
--- client/gui-gtk-2.0/menu.c   8 Aug 2005 16:30:22 -0000       1.83
+++ client/gui-gtk-2.0/menu.c   15 Aug 2005 17:03:53 -0000
@@ -276,7 +276,7 @@ static void government_menu_callback(gpo
     popup_worklists_report();
     break;
   case MENU_GOVERNMENT_REVOLUTION:
-    popup_revolution_dialog(-1);
+    popup_revolution_dialog(NULL);
     break;
   }
 }
@@ -1140,7 +1140,9 @@ static void menus_rename(const char *pat
 *****************************************************************/
 static void government_callback(GtkMenuItem *item, gpointer data)
 {
-  popup_revolution_dialog(GPOINTER_TO_INT(data));
+  struct government *gov = data;
+
+  popup_revolution_dialog(gov);
 }
 
 /****************************************************************************
@@ -1203,7 +1205,7 @@ void update_menus(void)
 
       /* add new government entries. */
       government_iterate(g) {
-        if (g->index != game.info.government_when_anarchy) {
+        if (g != game.government_when_anarchy) {
           GtkWidget *item, *image;
           struct sprite *gsprite;
          char buf[256];
@@ -1218,9 +1220,9 @@ void update_menus(void)
          }
 
           g_signal_connect(item, "activate",
-            G_CALLBACK(government_callback), GINT_TO_POINTER(g->index));
+                          G_CALLBACK(government_callback), g);
 
-          if (!can_change_to_government(game.player_ptr, g->index)) {
+          if (!can_change_to_government(game.player_ptr, g)) {
             gtk_widget_set_sensitive(item, FALSE);
          }
 
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.363
diff -p -u -r1.363 city.c
--- common/city.c       1 Aug 2005 23:09:36 -0000       1.363
+++ common/city.c       15 Aug 2005 17:03:54 -0000
@@ -1508,7 +1508,7 @@ void add_tax_income(const struct player 
   }
   
   /* ANARCHY */
-  if (get_gov_pplayer(pplayer)->index == game.info.government_when_anarchy) {
+  if (get_gov_pplayer(pplayer) == game.government_when_anarchy) {
     rates[SCIENCE] = 0;
     rates[LUXURY] = 100;
     rates[TAX] = 0;
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.235
diff -p -u -r1.235 game.c
--- common/game.c       11 Aug 2005 02:39:02 -0000      1.235
+++ common/game.c       15 Aug 2005 17:03:54 -0000
@@ -240,7 +240,7 @@ void game_init(void)
 #else
   game.info.save_compress_level = GAME_NO_COMPRESS_LEVEL;
 #endif
-  game.info.government_when_anarchy = G_MAGIC;   /* flag */
+  game.info.government_when_anarchy_id = G_MAGIC;   /* flag */
 
   game.info.is_new_game   = TRUE;
   game.simultaneous_phases_stored = GAME_DEFAULT_SIMULTANEOUS_PHASES;
Index: common/game.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.h,v
retrieving revision 1.197
diff -p -u -r1.197 game.h
--- common/game.h       11 Aug 2005 02:39:03 -0000      1.197
+++ common/game.h       15 Aug 2005 17:03:54 -0000
@@ -52,6 +52,8 @@ enum client_states { 
 
 struct civ_game {
   struct packet_game_info info;
+  struct government *government_when_anarchy;
+
   struct packet_ruleset_control control;
   int version;
   char id[MAX_ID_LEN];         /* server only */
Index: common/government.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.c,v
retrieving revision 1.60
diff -p -u -r1.60 government.c
--- common/government.c 18 Jul 2005 22:46:28 -0000      1.60
+++ common/government.c 15 Aug 2005 17:03:54 -0000
@@ -29,6 +29,8 @@
 
 struct government *governments = NULL;
 
+#define CHECK_GOVERNMENT(gov) assert(&governments[(gov)->index] == (gov))
+
 /****************************************************************************
   Does a linear search of the governments to find the one that matches the
   given (translated) name.  Returns NULL if none match.
@@ -64,9 +66,9 @@ struct government *find_government_by_na
 ****************************************************************************/
 struct government *get_government(int gov)
 {
-  assert(game.control.government_count > 0 && gov >= 0
-        && gov < game.control.government_count);
-  assert(governments[gov].index == gov);
+  if (gov < 0 || gov >= game.control.government_count) {
+    return NULL;
+  }
   return &governments[gov];
 }
 
@@ -76,7 +78,7 @@ struct government *get_government(int go
 struct government *get_gov_pplayer(const struct player *pplayer)
 {
   assert(pplayer != NULL);
-  return get_government(pplayer->government);
+  return pplayer->government;
 }
 
 /****************************************************************************
@@ -92,13 +94,14 @@ struct government *get_gov_pcity(const s
 /***************************************************************
 ...
 ***************************************************************/
-const char *get_ruler_title(int gov, bool male,
+const char *get_ruler_title(const struct government *g, bool male,
                            const struct nation_type *nation)
 {
-  struct government *g = get_government(gov);
   struct ruler_title *best_match = NULL;
   int i;
 
+  CHECK_GOVERNMENT(g);
+
   for(i=0; i<g->num_ruler_titles; i++) {
     struct ruler_title *title = &g->ruler_titles[i];
 
@@ -115,7 +118,7 @@ const char *get_ruler_title(int gov, boo
   } else {
     freelog(LOG_ERROR,
            "get_ruler_title: found no title for government %d (%s) nation %d",
-           gov, g->name, nation->index);
+           g->index, g->name, nation->index);
     return male ? "Mr." : "Ms.";
   }
 }
@@ -123,11 +126,10 @@ const char *get_ruler_title(int gov, boo
 /***************************************************************
 ...
 ***************************************************************/
-const char *get_government_name(int type)
+const char *get_government_name(const struct government *gov)
 {
-  if(type >= 0 && type < game.control.government_count)
-    return governments[type].name;
-  return "";
+  CHECK_GOVERNMENT(gov);
+  return gov->name;
 }
 
 /***************************************************************
@@ -136,14 +138,10 @@ const char *get_government_name(int type
    - player has required tech
    - we have an appropriate wonder
 ***************************************************************/
-bool can_change_to_government(struct player *pplayer, int government)
+bool can_change_to_government(struct player *pplayer,
+                             const struct government *gov)
 {
-  struct government *gov = &governments[government];
-
-  if (government < 0 || government >= game.control.government_count) {
-    assert(0);
-    return FALSE;
-  }
+  CHECK_GOVERNMENT(gov);
 
   if (get_player_bonus(pplayer, EFT_ANY_GOVERNMENT) > 0) {
     /* Note, this may allow govs that are on someone else's "tech tree". */
Index: common/government.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.h,v
retrieving revision 1.47
diff -p -u -r1.47 government.h
--- common/government.h 18 Jul 2005 22:46:28 -0000      1.47
+++ common/government.h 15 Aug 2005 17:03:54 -0000
@@ -51,8 +51,6 @@ struct government
   char  graphic_alt[MAX_LEN_NAME];
   struct requirement_vector reqs;
 
-  int ai_better;               /* govt AI prefers to this one (hint) */
-
   struct ruler_title *ruler_titles;
   int   num_ruler_titles;
 
@@ -85,22 +83,28 @@ struct government
   } waste[O_MAX];
 
   char *helptext;
+
+  /* AI cached data for this government. */
+  struct {
+    struct government *better; /* hint: a better government (or NULL) */
+  } ai;
 };
 
 extern struct government *governments;
 
-struct government *get_government(int gov);
+struct government *get_government(int government_id);
 struct government *get_gov_pplayer(const struct player *pplayer);
 struct government *get_gov_pcity(const struct city *pcity);
 
 struct government *find_government_by_name(const char *name);
 struct government *find_government_by_name_orig(const char *name);
 
-const char *get_government_name(int type);
-const char *get_ruler_title(int gov, bool male,
+const char *get_government_name(const struct government *gov);
+const char *get_ruler_title(const struct government *gov, bool male,
                            const struct nation_type *pnation);
 
-bool can_change_to_government(struct player *pplayer, int government);
+bool can_change_to_government(struct player *pplayer,
+                             const struct government *gov);
 
 void set_ruler_title(struct government *gov, struct nation_type *pnation,
                      const char *male, const char *female);
Index: common/nation.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.h,v
retrieving revision 1.54
diff -p -u -r1.54 nation.h
--- common/nation.h     22 Jul 2005 16:18:06 -0000      1.54
+++ common/nation.h     15 Aug 2005 17:03:54 -0000
@@ -92,7 +92,7 @@ struct nation_type {
   /* Items given to this nation at game start.  Server only. */
   int init_techs[MAX_NUM_TECH_LIST];
   int init_buildings[MAX_NUM_BUILDING_LIST];
-  int init_government;
+  struct government *init_government;
   struct unit_type *init_units[MAX_NUM_UNIT_LIST];
 
   /* Groups which this nation is assigned to */
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.150
diff -p -u -r1.150 packets.def
--- common/packets.def  11 Aug 2005 04:43:25 -0000      1.150
+++ common/packets.def  15 Aug 2005 17:03:54 -0000
@@ -439,7 +439,7 @@ PACKET_GAME_INFO=15; sc
   UINT16 incite_improvement_factor;
   UINT16 incite_unit_factor;
   UINT16 incite_total_factor;
-  GOVERNMENT government_when_anarchy;
+  GOVERNMENT government_when_anarchy_id;
   UINT8 revolution_length;
   SINT16 base_pollution;
   UINT8 happy_cost;
Index: common/player.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.c,v
retrieving revision 1.189
diff -p -u -r1.189 player.c
--- common/player.c     20 Jul 2005 17:32:30 -0000      1.189
+++ common/player.c     15 Aug 2005 17:03:54 -0000
@@ -108,6 +108,8 @@ void player_init(struct player *plr)
   sz_strlcpy(plr->name, ANON_PLAYER_NAME);
   sz_strlcpy(plr->username, ANON_USER_NAME);
   plr->is_male = TRUE;
+  plr->government = NULL;
+  plr->target_government = NULL;
   plr->nation = NO_NATION_SELECTED;
   plr->team = NULL;
   plr->is_ready = FALSE;
Index: common/player.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/player.h,v
retrieving revision 1.162
diff -p -u -r1.162 player.h
--- common/player.h     20 Jul 2005 18:28:48 -0000      1.162
+++ common/player.h     15 Aug 2005 17:03:54 -0000
@@ -154,8 +154,8 @@ struct player {
   char name[MAX_LEN_NAME];
   char username[MAX_LEN_NAME];
   bool is_male;
-  int government;
-  int target_government;
+  struct government *government; /* may be NULL in pregame */
+  struct government *target_government; /* may be NULL */
   struct nation_type *nation;
   struct team *team;
   bool is_ready; /* Did the player click "start" yet? */
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.32
diff -p -u -r1.32 requirements.c
--- common/requirements.c       1 Aug 2005 22:38:25 -0000       1.32
+++ common/requirements.c       15 Aug 2005 17:03:55 -0000
@@ -84,7 +84,6 @@ enum req_range req_range_from_str(const 
 struct req_source req_source_from_str(const char *type, const char *value)
 {
   struct req_source source;
-  const struct government *pgov;
 
   assert(ARRAY_SIZE(req_source_type_names) == REQ_LAST);
   if (type) {
@@ -110,9 +109,8 @@ struct req_source req_source_from_str(co
     }
     break;
   case REQ_GOV:
-    pgov = find_government_by_name(value);
-    if (pgov != NULL) {
-      source.value.gov = pgov->index;
+    source.value.gov = find_government_by_name(value);
+    if (source.value.gov != NULL) {
       return source;
     }
     break;
@@ -195,7 +193,7 @@ struct req_source req_source_from_values
     source.value.tech = value;
     return source;
   case REQ_GOV:
-    source.value.gov = value;
+    source.value.gov = get_government(value);
     return source;
   case REQ_BUILDING:
     source.value.building = value;
@@ -251,7 +249,7 @@ void req_source_get_values(const struct 
     *value = source->value.tech;
     return;
   case REQ_GOV:
-    *value = source->value.gov;
+    *value = source->value.gov->index;
     return;
   case REQ_BUILDING:
     *value = source->value.building;
Index: common/requirements.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.h,v
retrieving revision 1.22
diff -p -u -r1.22 requirements.h
--- common/requirements.h       22 Jul 2005 16:18:06 -0000      1.22
+++ common/requirements.h       15 Aug 2005 17:03:55 -0000
@@ -55,7 +55,7 @@ struct req_source {
 
   union {
     Tech_type_id tech;                  /* source tech */
-    int gov;                            /* source government */
+    struct government *gov;             /* source government */
     Impr_type_id building;              /* source building */
     enum tile_special_type special;     /* source special */
     struct terrain *terrain;            /* source terrain type */
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.65
diff -p -u -r1.65 unittype.c
--- common/unittype.c   11 Aug 2005 02:39:03 -0000      1.65
+++ common/unittype.c   15 Aug 2005 17:03:55 -0000
@@ -436,7 +436,7 @@ bool can_player_build_unit_direct(const 
   if (unit_type_flag(punittype, F_NOBUILD)) {
     return FALSE;
   }
-  if (punittype->gov_requirement != G_MAGIC
+  if (punittype->gov_requirement
       && punittype->gov_requirement != p->government) {
     return FALSE;
   }
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.55
diff -p -u -r1.55 unittype.h
--- common/unittype.h   4 Aug 2005 21:34:41 -0000       1.55
+++ common/unittype.h   15 Aug 2005 17:03:55 -0000
@@ -161,7 +161,7 @@ struct unit_type {
   int move_rate;
   int tech_requirement;
   int impr_requirement;                /* should be Impr_type_id */
-  int gov_requirement;
+  struct government *gov_requirement; /* may be NULL */
   int vision_range;
   int transport_capacity;
   int hp;
Index: server/barbarian.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/barbarian.c,v
retrieving revision 1.98
diff -p -u -r1.98 barbarian.c
--- server/barbarian.c  24 Jul 2005 00:02:38 -0000      1.98
+++ server/barbarian.c  15 Aug 2005 17:03:55 -0000
@@ -153,7 +153,7 @@ static struct player *create_barbarian_p
 
   sz_strlcpy(barbarians->username, ANON_USER_NAME);
   barbarians->is_connected = FALSE;
-  barbarians->government = game.info.government_when_anarchy; 
+  barbarians->government = game.government_when_anarchy;
   barbarians->revolution_finishes = 1;
   barbarians->capital = FALSE;
   barbarians->economic.gold = 100;
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.330
diff -p -u -r1.330 cityturn.c
--- server/cityturn.c   2 Aug 2005 06:39:49 -0000       1.330
+++ server/cityturn.c   15 Aug 2005 17:03:55 -0000
@@ -1272,7 +1272,7 @@ static void pay_for_buildings(struct pla
 {
   built_impr_iterate(pcity, i) {
     if (can_city_sell_building(pcity, i)
-       && pplayer->government != game.info.government_when_anarchy) {
+       && pplayer->government != game.government_when_anarchy) {
       if (pplayer->economic.gold - improvement_upkeep(pcity, i) < 0) {
        notify_player_ex(pplayer, pcity->tile, E_IMP_AUCTIONED,
                         _("Can't afford to maintain %s in %s, "
@@ -1350,7 +1350,7 @@ int city_incite_cost(struct player *ppla
   } built_impr_iterate_end;
 
   /* Stability bonuses */
-  if (g->index != game.info.government_when_anarchy) {
+  if (g != game.government_when_anarchy) {
     if (!city_unhappy(pcity)) {
       cost *= 2;
     }
@@ -1519,7 +1519,7 @@ static void update_city_activity(struct 
       notify_player_ex(pplayer, pcity->tile, E_ANARCHY,
                       _("The people have overthrown your %s, "
                         "your country is in turmoil."),
-                      get_government_name(g->index));
+                      get_government_name(g));
       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.407
diff -p -u -r1.407 plrhand.c
--- server/plrhand.c    15 Aug 2005 16:17:21 -0000      1.407
+++ server/plrhand.c    15 Aug 2005 17:03:56 -0000
@@ -241,9 +241,9 @@ void handle_player_rates(struct player *
 **************************************************************************/
 static void finish_revolution(struct player *pplayer)
 {
-  int government = pplayer->target_government;
+  struct government *government = pplayer->target_government;
 
-  if (pplayer->target_government == game.info.government_when_anarchy) {
+  if (pplayer->target_government == game.government_when_anarchy) {
     assert(0);
     return;
   }
@@ -290,9 +290,9 @@ static void finish_revolution(struct pla
 void handle_player_change_government(struct player *pplayer, int government)
 {
   int turns;
+  struct government *gov = get_government(government);
 
-  if (government < 0 || government >= game.control.government_count
-      || !can_change_to_government(pplayer, government)) {
+  if (!gov || !can_change_to_government(pplayer, gov)) {
     return;
   }
 
@@ -300,7 +300,7 @@ void handle_player_change_government(str
          "Government changed for %s.  Target government is %s; "
          "old %s.  Revofin %d, Turn %d.",
          pplayer->name,
-         get_government_name(government),
+         get_government_name(gov),
          get_government_name(pplayer->government),
          pplayer->revolution_finishes, game.info.turn);
 
@@ -322,8 +322,8 @@ void handle_player_change_government(str
     turns = game.info.revolution_length;
   }
 
-  pplayer->government = game.info.government_when_anarchy;
-  pplayer->target_government = government;
+  pplayer->government = game.government_when_anarchy;
+  pplayer->target_government = gov;
   pplayer->revolution_finishes = game.info.turn + turns;
 
   freelog(LOG_DEBUG,
@@ -334,7 +334,7 @@ void handle_player_change_government(str
 
   /* Now see if the revolution is instantaneous. */
   if (turns <= 0
-      && pplayer->target_government != game.info.government_when_anarchy) {
+      && pplayer->target_government != game.government_when_anarchy) {
     finish_revolution(pplayer);
     return;
   } else if (turns > 0) {
@@ -351,7 +351,7 @@ void handle_player_change_government(str
                     get_nation_name_plural(pplayer->nation), turns,
                     get_government_name(pplayer->target_government));
   } else {
-    assert(pplayer->target_government == game.info.government_when_anarchy);
+    assert(pplayer->target_government == game.government_when_anarchy);
     notify_player_ex(pplayer, NULL, E_REVOLT_START,
                     _("Revolution: returning to anarchy."));
   }
@@ -400,9 +400,9 @@ void update_revolution(struct player *pp
          pplayer->name, get_government_name(pplayer->government),
          get_government_name(pplayer->target_government),
          pplayer->revolution_finishes, game.info.turn);
-  if (pplayer->government == game.info.government_when_anarchy
+  if (pplayer->government == game.government_when_anarchy
       && pplayer->revolution_finishes <= game.info.turn) {
-    if (pplayer->target_government != game.info.government_when_anarchy) {
+    if (pplayer->target_government != game.government_when_anarchy) {
       /* If the revolution is over and a target government is set, go into
        * the new government. */
       freelog(LOG_DEBUG, "Update: finishing revolution for %s.",
@@ -415,7 +415,7 @@ void update_revolution(struct player *pp
                       _("You should choose a new government from the "
                         "government menu."));
     }
-  } else if (pplayer->government != game.info.government_when_anarchy
+  } else if (pplayer->government != game.government_when_anarchy
             && pplayer->revolution_finishes < game.info.turn) {
     /* Reset the revolution counter.  If the player has another revolution
      * they'll have to re-enter anarchy. */
@@ -910,7 +910,7 @@ static void package_player_common(struct
   packet->science_cost = plr->ai.science_cost;
 
   packet->gold = plr->economic.gold;
-  packet->government = plr->government;
+  packet->government = plr->government ? plr->government->index : -1;
 }
 
 /**************************************************************************
@@ -950,7 +950,8 @@ static void package_player_info(struct p
   if (info_level >= INFO_EMBASSY
       || (receiver
          && receiver->diplstates[plr->player_no].contact_turns_left > 0)) {
-    packet->target_government = plr->target_government;
+    packet->target_government
+      = plr->target_government ? plr->target_government->index : -1;
     memset(&packet->embassy, 0, sizeof(packet->embassy));
     players_iterate(pother) {
       packet->embassy[pother->player_no]
@@ -1519,7 +1520,7 @@ static struct player *split_player(struc
 
   sz_strlcpy(cplayer->username, ANON_USER_NAME);
   cplayer->is_connected = FALSE;
-  cplayer->government = game.info.government_when_anarchy;  
+  cplayer->government = game.government_when_anarchy;  
   cplayer->revolution_finishes = game.info.turn + 1;
   cplayer->capital = TRUE;
 
@@ -1591,8 +1592,8 @@ static struct player *split_player(struc
   } tech_type_iterate_end;
   
   /* change the original player */
-  if (pplayer->government != game.info.government_when_anarchy) {
-    pplayer->government = game.info.government_when_anarchy;
+  if (pplayer->government != game.government_when_anarchy) {
+    pplayer->government = game.government_when_anarchy;
     pplayer->revolution_finishes = game.info.turn + 1;
   }
   get_player_research(pplayer)->bulbs_researched = 0;
Index: server/report.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/report.c,v
retrieving revision 1.69
diff -p -u -r1.69 report.c
--- server/report.c     26 Jul 2005 16:36:00 -0000      1.69
+++ server/report.c     15 Aug 2005 17:03:56 -0000
@@ -502,7 +502,7 @@ static int get_specialists(struct player
 
 static int get_gov(struct player *pplayer)
 {
-  return pplayer->government;
+  return pplayer->government->index;
 }
 
 static int get_corruption(struct player *pplayer)
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.278
diff -p -u -r1.278 ruleset.c
--- server/ruleset.c    1 Aug 2005 22:38:26 -0000       1.278
+++ server/ruleset.c    15 Aug 2005 17:03:57 -0000
@@ -68,8 +68,6 @@ static struct unit_type *lookup_unit_typ
 static Impr_type_id lookup_impr_type(struct section_file *file, const char 
*prefix,
                                     const char *entry, bool required,
                                     const char *filename, const char 
*description);
-static int lookup_government(struct section_file *file, const char *entry,
-                            const char *filename);
 static int lookup_city_cost(struct section_file *file, const char *prefix,
                            const char *entry, const char *filename);
 static char *lookup_helptext(struct section_file *file, char *prefix);
@@ -574,8 +572,9 @@ static Impr_type_id lookup_impr_type(str
   Lookup entry in the file and return the corresponding government index;
   dies if can't find/match.  filename is for error message.
 **************************************************************************/
-static int lookup_government(struct section_file *file, const char *entry,
-                            const char *filename)
+static struct government *lookup_government(struct section_file *file,
+                                           const char *entry,
+                                           const char *filename)
 {
   char *sval;
   struct government *gov;
@@ -587,7 +586,7 @@ static int lookup_government(struct sect
            entry, sval, filename);
     exit(EXIT_FAILURE);
   }
-  return gov->index;
+  return gov;
 }
 
 /**************************************************************************
@@ -1051,7 +1050,7 @@ if (vet_levels_default > MAX_VET_LEVELS 
       mystrlcat(tmp, ".gov_req", 200);
       u->gov_requirement = lookup_government(file, tmp, filename);
     } else {
-      u->gov_requirement = G_MAGIC; /* no requirement */
+      u->gov_requirement = NULL; /* no requirement */
     }
   } unit_type_iterate_end;
   
@@ -1695,8 +1694,9 @@ static void load_ruleset_governments(str
 
   sec = secfile_get_secnames_prefix(file, "government_", &nval);
 
-  game.info.government_when_anarchy
+  game.government_when_anarchy
     = lookup_government(file, "governments.when_anarchy", filename);
+  game.info.government_when_anarchy_id = game.government_when_anarchy->index;
 
   /* easy ones: */
   government_iterate(g) {
@@ -1709,9 +1709,9 @@ static void load_ruleset_governments(str
       char entry[100];
 
       my_snprintf(entry, sizeof(entry), "%s.ai_better", sec[i]);
-      g->ai_better = lookup_government(file, entry, filename);
+      g->ai.better = lookup_government(file, entry, filename);
     } else {
-      g->ai_better = G_MAGIC;
+      g->ai.better = NULL;
     }
     requirement_vector_copy(&g->reqs, reqs);
     
@@ -2646,7 +2646,8 @@ static void send_ruleset_units(struct co
     packet.move_rate = u->move_rate;
     packet.tech_requirement = u->tech_requirement;
     packet.impr_requirement = u->impr_requirement;
-    packet.gov_requirement = u->gov_requirement;
+    packet.gov_requirement
+      = u->gov_requirement ? u->gov_requirement->index : -1;
     packet.vision_range = u->vision_range;
     packet.transport_capacity = u->transport_capacity;
     packet.hp = u->hp;
@@ -2952,7 +2953,7 @@ static void send_ruleset_nations(struct 
            sizeof(packet.init_buildings));
     memcpy(packet.init_units, n->init_units, 
            sizeof(packet.init_units));
-    packet.init_government = n->init_government;
+    packet.init_government = n->init_government->index;
 
     sz_strlcpy(packet.legend, n->legend);
 
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.70
diff -p -u -r1.70 sanitycheck.c
--- server/sanitycheck.c        14 Jul 2005 19:25:46 -0000      1.70
+++ server/sanitycheck.c        15 Aug 2005 17:03:57 -0000
@@ -17,9 +17,11 @@
 
 #include <assert.h>
 
+#include "log.h"
+
 #include "city.h"
 #include "game.h"
-#include "log.h"
+#include "government.h"
 #include "map.h"
 #include "movement.h"
 #include "player.h"
@@ -101,6 +103,10 @@ static void check_fow(void)
       }
     } players_iterate_end;
   } whole_map_iterate_end;
+
+  SANITY_CHECK(game.government_when_anarchy != NULL);
+  SANITY_CHECK(game.government_when_anarchy
+              == get_government(game.info.government_when_anarchy_id));
 }
 
 /**************************************************************************
@@ -431,13 +437,13 @@ static void check_players(void)
     } players_iterate_end;
 
     if (pplayer->revolution_finishes == -1) {
-      if (pplayer->government == game.info.government_when_anarchy) {
+      if (pplayer->government == game.government_when_anarchy) {
         freelog(LOG_FATAL, "%s's government is anarchy but does not finish",
                 pplayer->name);
       }
-      SANITY_CHECK(pplayer->government != game.info.government_when_anarchy);
+      SANITY_CHECK(pplayer->government != game.government_when_anarchy);
     } else if (pplayer->revolution_finishes > game.info.turn) {
-      SANITY_CHECK(pplayer->government == game.info.government_when_anarchy);
+      SANITY_CHECK(pplayer->government == game.government_when_anarchy);
     } else {
       /* Things may vary in this case depending on when the sanity_check
        * call is made.  No better check is possible. */
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.274
diff -p -u -r1.274 savegame.c
--- server/savegame.c   11 Aug 2005 02:39:03 -0000      1.274
+++ server/savegame.c   15 Aug 2005 17:03:57 -0000
@@ -1701,7 +1701,7 @@ static void player_load(struct player *p
     freelog(LOG_ERROR, _("Unsupported government found (%s)"), name);
     exit(EXIT_FAILURE);
   }
-  plr->government = gov->index;
+  plr->government = gov;
 
   /* Target government */
   name = secfile_lookup_str_default(file, NULL,
@@ -1713,7 +1713,7 @@ static void player_load(struct player *p
     gov = NULL;
   }
   if (gov) {
-    plr->target_government = gov->index;
+    plr->target_government = gov;
   } else {
     /* Old servers didn't have this value. */
     plr->target_government = plr->government;
@@ -1882,7 +1882,7 @@ static void player_load(struct player *p
                                                plrno);
 
     if (revolution == 0) {
-      if (plr->government != game.info.government_when_anarchy) {
+      if (plr->government != game.government_when_anarchy) {
         revolution = -1;
       } else {
         /* some old savegames may be buggy */
@@ -2464,7 +2464,6 @@ static void player_save(struct player *p
   char invs[A_LAST+1];
   struct player_spaceship *ship = &plr->spaceship;
   struct ai_data *ai = ai_data_get(plr);
-  struct government *gov;
 
   secfile_insert_str(file, plr->name, "player%d.name", plrno);
   secfile_insert_str(file, plr->username, "player%d.username", plrno);
@@ -2478,15 +2477,14 @@ static void player_save(struct player *p
   secfile_insert_int(file, plr->team ? plr->team->index : -1,
                     "player%d.team_no", plrno);
 
-  gov = get_government(plr->government);
-  secfile_insert_str(file, gov->name_orig, "player%d.government_name", plrno);
+  secfile_insert_str(file, plr->government->name_orig,
+                    "player%d.government_name", plrno);
   /* 1.15 and later won't use "government" field; it's kept for forward 
    * compatibility */
-  secfile_insert_int(file, old_government_id(gov),
+  secfile_insert_int(file, old_government_id(plr->government),
                      "player%d.government", plrno);
 
-  gov = get_government(plr->target_government);
-  secfile_insert_str(file, gov->name_orig,
+  secfile_insert_str(file, plr->target_government->name_orig,
                     "player%d.target_government_name", plrno);
 
   players_iterate(pother) {
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.285
diff -p -u -r1.285 srv_main.c
--- server/srv_main.c   15 Aug 2005 03:33:27 -0000      1.285
+++ server/srv_main.c   15 Aug 2005 17:03:58 -0000
@@ -1763,7 +1763,7 @@ static void final_ruleset_adjustments()
 
     pplayer->government = pnation->init_government;
 
-    if (pnation->init_government == game.info.government_when_anarchy) {
+    if (pnation->init_government == game.government_when_anarchy) {
       /* If we do not do this, an assert will trigger. This enables us to
        * select a valid government on game start. */
       pplayer->revolution_finishes = 0;
Index: server/techtools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/techtools.c,v
retrieving revision 1.17
diff -p -u -r1.17 techtools.c
--- server/techtools.c  24 Jul 2005 17:01:37 -0000      1.17
+++ server/techtools.c  15 Aug 2005 17:03:58 -0000
@@ -226,7 +226,7 @@ static void update_player_after_tech_res
   /* Notify a player about new governments available */
   government_iterate(gov) {
     if (!could_switch_to_government[gov->index]
-       && can_change_to_government(plr, gov->index)) {
+       && can_change_to_government(plr, gov)) {
       notify_player_ex(plr, NULL, E_NEW_GOVERNMENT,
                       _("Discovery of %s makes the government form %s"
                         " available. You may want to start a revolution."),
@@ -249,7 +249,7 @@ static void fill_can_switch_to_governmen
   government_iterate(gov) {
     /* We do it this way so all requirements are checked, including
      * statue-of-liberty effects. */
-    can_switch[gov->index] = can_change_to_government(plr, gov->index);
+    can_switch[gov->index] = can_change_to_government(plr, gov);
   } government_iterate_end;
 } 
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13678) use pointers for governments, Jason Short <=