Author: jtn
Date: Mon Jun 20 11:07:42 2016
New Revision: 32926

URL: http://svn.gna.org/viewcvs/freeciv?rev=32926&view=rev
Log:
Create a Government_type_id, following the pattern of Impr_type_id etc.

Get rid of G_MAGIC and the (unused) G_CITY_SIZE_FREE.

See gna patch #7277.

Modified:
    branches/S2_6/client/gui-xaw/menu.c
    branches/S2_6/client/tilespec.c
    branches/S2_6/common/effects.c
    branches/S2_6/common/fc_types.h
    branches/S2_6/common/game.c
    branches/S2_6/common/government.c
    branches/S2_6/common/government.h
    branches/S2_6/common/packets.def
    branches/S2_6/common/scriptcore/api_game_find.c
    branches/S2_6/server/plrhand.c
    branches/S2_6/server/report.c
    branches/S2_6/server/ruleset.c

Modified: branches/S2_6/client/gui-xaw/menu.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-xaw/menu.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/client/gui-xaw/menu.c (original)
+++ branches/S2_6/client/gui-xaw/menu.c Mon Jun 20 11:07:42 2016
@@ -137,7 +137,7 @@
 
 /* One entry for every government, appended to the government menu. */
 static int num_government_entries = 0;
-static Widget government_widgets[G_MAGIC];
+static Widget government_widgets[G_LAST];
 
 static struct MenuEntry view_menu_entries[]={
     { { N_("Map Grid"), 0             }, "ctl-g", MENU_VIEW_SHOW_MAP_GRID, 0 },

Modified: branches/S2_6/client/tilespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/tilespec.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/client/tilespec.c     (original)
+++ branches/S2_6/client/tilespec.c     Mon Jun 20 11:07:42 2016
@@ -232,7 +232,7 @@
 
   struct sprite *tech[A_LAST];
   struct sprite *building[B_LAST];
-  struct sprite *government[G_MAGIC];
+  struct sprite *government[G_LAST];
 
   struct {
     struct sprite *icon[U_LAST];

Modified: branches/S2_6/common/effects.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/effects.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/common/effects.c      (original)
+++ branches/S2_6/common/effects.c      Mon Jun 20 11:07:42 2016
@@ -115,7 +115,7 @@
     /* This cache shows for each building, which effects it provides. */
     struct effect_list *buildings[B_LAST];
     /* Same for governments */
-    struct effect_list *govs[G_MAGIC];
+    struct effect_list *govs[G_LAST];
     /* ...advances... */
     struct effect_list *advances[A_LAST];
   } reqs;

Modified: branches/S2_6/common/fc_types.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/fc_types.h?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/common/fc_types.h     (original)
+++ branches/S2_6/common/fc_types.h     Mon Jun 20 11:07:42 2016
@@ -144,6 +144,7 @@
 typedef enum output_type_id Output_type_id;
 typedef enum unit_activity Activity_type_id;
 typedef int Nation_type_id;
+typedef int Government_type_id;
 typedef int Unit_type_id;
 typedef int Base_type_id;
 typedef int Road_type_id;

Modified: branches/S2_6/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/game.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/common/game.c (original)
+++ branches/S2_6/common/game.c Mon Jun 20 11:07:42 2016
@@ -304,7 +304,7 @@
   game.info.global_warming   = GAME_DEFAULT_GLOBAL_WARMING;
   game.info.gold             = GAME_DEFAULT_GOLD;
   game.info.revolentype      = GAME_DEFAULT_REVOLENTYPE;
-  game.info.government_during_revolution_id = G_MAGIC; /* flag */
+  game.info.government_during_revolution_id = G_LAST;
   game.info.happyborders     = GAME_DEFAULT_HAPPYBORDERS;
   game.info.heating          = 0;
   game.info.is_edit_mode     = FALSE;

Modified: branches/S2_6/common/government.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/government.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/common/government.c   (original)
+++ branches/S2_6/common/government.c   Mon Jun 20 11:07:42 2016
@@ -67,7 +67,7 @@
 /**************************************************************************
   Return the number of governments.
 **************************************************************************/
-int government_count(void)
+Government_type_id government_count(void)
 {
   return game.control.government_count;
 }
@@ -78,7 +78,7 @@
   Currently same as government_number(), paired with government_count()
   indicates use as an array index.
 **************************************************************************/
-int government_index(const struct government *pgovern)
+Government_type_id government_index(const struct government *pgovern)
 {
   fc_assert_ret_val(NULL != pgovern, -1);
   return pgovern - governments;
@@ -87,7 +87,7 @@
 /**************************************************************************
   Return the government index.
 **************************************************************************/
-int government_number(const struct government *pgovern)
+Government_type_id government_number(const struct government *pgovern)
 {
   fc_assert_ret_val(NULL != pgovern, -1);
   return pgovern->item_number;
@@ -99,7 +99,7 @@
   This function returns NULL for an out-of-range index (some callers
   rely on this).
 ****************************************************************************/
-struct government *government_by_number(const int gov)
+struct government *government_by_number(const Government_type_id gov)
 {
   if (gov < 0 || gov >= game.control.government_count) {
     return NULL;

Modified: branches/S2_6/common/government.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/government.h?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/common/government.h   (original)
+++ branches/S2_6/common/government.h   Mon Jun 20 11:07:42 2016
@@ -40,15 +40,17 @@
                           NAME_rule_title)
 #define ruler_titles_iterate_end HASH_DATA_ITERATE_END
 
-#define G_MAGIC (127)          /* magic constant */
-
-/* special values for free_* fields -- SKi */
-#define G_CITY_SIZE_FREE          G_MAGIC
+/* G_LAST is a value guaranteed to be larger than any valid
+ * Government_type_id. It defines the maximum number of governments
+ * (so can also be used to size static arrays indexed by governments);
+ * it is sometimes used as a sentinel value (but not in the network
+ * protocol, which generally uses government_count()). */
+#define G_LAST (127)
 
 /* This is struct government itself.  All information about a form of
  * government is contained inhere. -- SKi */
 struct government {
-  int item_number;
+  Government_type_id item_number;
   struct name_translation name;
   char graphic_str[MAX_LEN_NAME];
   char graphic_alt[MAX_LEN_NAME];
@@ -65,11 +67,11 @@
 
 
 /* General government accessor functions. */
-int government_count(void);
-int government_index(const struct government *pgovern);
-int government_number(const struct government *pgovern);
+Government_type_id government_count(void);
+Government_type_id government_index(const struct government *pgovern);
+Government_type_id government_number(const struct government *pgovern);
 
-struct government *government_by_number(const int gov);
+struct government *government_by_number(const Government_type_id gov);
 struct government *government_of_player(const struct player *pplayer);
 struct government *government_of_city(const struct city *pcity);
 

Modified: branches/S2_6/common/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/packets.def?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/common/packets.def    (original)
+++ branches/S2_6/common/packets.def    Mon Jun 20 11:07:42 2016
@@ -281,7 +281,7 @@
 type CITYSPE            = SINT32
 type CONNECTION         = SINT16
 type CONTINENT          = sint16(Continent_id)
-type GOVERNMENT         = UINT8
+type GOVERNMENT         = sint8(Government_type_id)
 type IMPROVEMENT        = uint8(Impr_type_id)
 type MULTIPLIER         = uint8(Multiplier_type_id)
 type NATION             = sint16(Nation_type_id)

Modified: branches/S2_6/common/scriptcore/api_game_find.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/scriptcore/api_game_find.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/common/scriptcore/api_game_find.c     (original)
+++ branches/S2_6/common/scriptcore/api_game_find.c     Mon Jun 20 11:07:42 2016
@@ -132,7 +132,7 @@
 }
 
 /*****************************************************************************
-  Return the government with the given government_id index.
+  Return the government with the given Government_type_id index.
 *****************************************************************************/
 Government *api_find_government(lua_State *L, int government_id)
 {

Modified: branches/S2_6/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/plrhand.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/server/plrhand.c      (original)
+++ branches/S2_6/server/plrhand.c      Mon Jun 20 11:07:42 2016
@@ -423,7 +423,8 @@
 /**************************************************************************
   Called by the client or AI to change government.
 **************************************************************************/
-void handle_player_change_government(struct player *pplayer, int government)
+void handle_player_change_government(struct player *pplayer,
+                                     Government_type_id government)
 {
   int turns;
   struct government *gov = government_by_number(government);

Modified: branches/S2_6/server/report.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/report.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/server/report.c       (original)
+++ branches/S2_6/server/report.c       Mon Jun 20 11:07:42 2016
@@ -767,7 +767,7 @@
 ****************************************************************************/
 static int get_gov(const struct player *pplayer)
 {
-  return government_number(government_of_player(pplayer));
+  return (int) government_number(government_of_player(pplayer));
 }
 
 /****************************************************************************

Modified: branches/S2_6/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/ruleset.c?rev=32926&r1=32925&r2=32926&view=diff
==============================================================================
--- branches/S2_6/server/ruleset.c      (original)
+++ branches/S2_6/server/ruleset.c      Mon Jun 20 11:07:42 2016
@@ -3284,12 +3284,9 @@
   if (NULL == sec || 0 == (nval = section_list_size(sec))) {
     ruleset_error(LOG_ERROR, "\"%s\": No governments?!?", filename);
     ok = FALSE;
-  } else if (nval > G_MAGIC) {
-    /* upper limit is really about 255 for 8-bit id values, but
-       use G_MAGIC elsewhere as a sanity check, and should be plenty
-       big enough --dwp */
+  } else if (nval > G_LAST) {
     ruleset_error(LOG_ERROR, "\"%s\": Too many governments (%d, max %d)",
-                  filename, nval, G_MAGIC);
+                  filename, nval, G_LAST);
     ok = FALSE;
   }
 


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

Reply via email to