Author: jtn
Date: Mon Jun 20 11:06:50 2016
New Revision: 32924

URL: http://svn.gna.org/viewcvs/freeciv?rev=32924&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:
    trunk/client/tilespec.c
    trunk/common/effects.c
    trunk/common/fc_types.h
    trunk/common/game.c
    trunk/common/government.c
    trunk/common/government.h
    trunk/common/networking/packets.def
    trunk/common/scriptcore/api_game_find.c
    trunk/server/plrhand.c
    trunk/server/report.c
    trunk/server/ruleset.c

Modified: trunk/client/tilespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/tilespec.c?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/client/tilespec.c     (original)
+++ trunk/client/tilespec.c     Mon Jun 20 11:06:50 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: trunk/common/effects.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/effects.c?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/common/effects.c      (original)
+++ trunk/common/effects.c      Mon Jun 20 11:06:50 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: trunk/common/fc_types.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_types.h?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/common/fc_types.h     (original)
+++ trunk/common/fc_types.h     Mon Jun 20 11:06:50 2016
@@ -145,6 +145,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: trunk/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/game.c?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/common/game.c (original)
+++ trunk/common/game.c Mon Jun 20 11:06:50 2016
@@ -305,7 +305,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: trunk/common/government.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/government.c?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/common/government.c   (original)
+++ trunk/common/government.c   Mon Jun 20 11:06:50 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: trunk/common/government.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/government.h?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/common/government.h   (original)
+++ trunk/common/government.h   Mon Jun 20 11:06:50 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: trunk/common/networking/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/networking/packets.def?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/common/networking/packets.def (original)
+++ trunk/common/networking/packets.def Mon Jun 20 11:06:50 2016
@@ -291,7 +291,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: trunk/common/scriptcore/api_game_find.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/scriptcore/api_game_find.c?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/common/scriptcore/api_game_find.c     (original)
+++ trunk/common/scriptcore/api_game_find.c     Mon Jun 20 11:06:50 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: trunk/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/plrhand.c?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/server/plrhand.c      (original)
+++ trunk/server/plrhand.c      Mon Jun 20 11:06:50 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: trunk/server/report.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/report.c?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/server/report.c       (original)
+++ trunk/server/report.c       Mon Jun 20 11:06:50 2016
@@ -766,7 +766,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: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=32924&r1=32923&r2=32924&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Mon Jun 20 11:06:50 2016
@@ -3479,12 +3479,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