Author: cazfi
Date: Sat Jul  2 17:04:49 2016
New Revision: 33144

URL: http://svn.gna.org/viewcvs/freeciv?rev=33144&view=rev
Log:
Removed separate id number from resources

See patch #7340

Modified:
    trunk/client/editor.c
    trunk/client/packhand.c
    trunk/common/networking/packets.def
    trunk/common/terrain.c
    trunk/common/terrain.h
    trunk/fc_version
    trunk/server/maphand.c
    trunk/server/ruleset.c
    trunk/server/savecompat.c
    trunk/tools/ruleutil/rulesave.c

Modified: trunk/client/editor.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/editor.c?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/client/editor.c       (original)
+++ trunk/client/editor.c       Sat Jul  2 17:04:49 2016
@@ -368,12 +368,13 @@
   case ETT_ROAD:
     return road_count() > 0;
   case ETT_TERRAIN_RESOURCE:
-    return resource_count() > 0;
+    return game.control.num_resource_types > 0;
   case ETT_UNIT:
     return utype_count() > 0;
   default:
     break;
   }
+
   return TRUE;
 }
 
@@ -1615,8 +1616,8 @@
 
   presource = tile_resource(ptile);
   packet->resource = presource
-                     ? resource_number(presource)
-                     : resource_count();
+                     ? extra_number(presource)
+                     : extra_count();
 
   pterrain = tile_terrain(ptile);
   packet->terrain = pterrain

Modified: trunk/client/packhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/packhand.c?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/client/packhand.c     (original)
+++ trunk/client/packhand.c     Sat Jul  2 17:04:49 2016
@@ -2815,7 +2815,7 @@
   bool tile_changed = FALSE;
   struct player *powner = player_by_number(packet->owner);
   struct player *eowner = player_by_number(packet->extras_owner);
-  struct extra_type *presource = resource_by_number(packet->resource);
+  struct extra_type *presource = extra_by_number(packet->resource);
   struct terrain *pterrain = terrain_by_number(packet->terrain);
   struct tile *ptile = index_to_tile(packet->tile);
 
@@ -3626,7 +3626,7 @@
   pterrain->resources = fc_calloc(p->num_resources + 1,
                                   sizeof(*pterrain->resources));
   for (j = 0; j < p->num_resources; j++) {
-    pterrain->resources[j] = resource_by_number(p->resources[j]);
+    pterrain->resources[j] = extra_by_number(p->resources[j]);
     if (!pterrain->resources[j]) {
       log_error("handle_ruleset_terrain() "
                 "Mismatched resource %d for terrain \"%s\".",
@@ -3700,13 +3700,12 @@
 {
   struct resource_type *presource;
 
-  if (p->id < 0 || p->id > MAX_RESOURCE_TYPES
-      || p->extra < 0 || p->extra > MAX_EXTRA_TYPES) {
+  if (p->id < 0 || p->id > MAX_EXTRA_TYPES) {
     log_error("Bad resource %d.", p->id);
     return;
   }
 
-  presource = resource_type_init(extra_by_number(p->extra), p->id);
+  presource = resource_type_init(extra_by_number(p->id));
 
   output_type_iterate(o) {
     presource->output[o] = p->output[o];

Modified: trunk/common/networking/packets.def
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/networking/packets.def?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/common/networking/packets.def (original)
+++ trunk/common/networking/packets.def Sat Jul  2 17:04:49 2016
@@ -1917,8 +1917,7 @@
 end
 
 PACKET_RULESET_RESOURCE = 177; sc, lsend
-  RESOURCE id;
-  UINT8 extra;
+  UINT8 id;
 
   UINT8 output[O_LAST];
 end

Modified: trunk/common/terrain.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/terrain.c?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/common/terrain.c      (original)
+++ trunk/common/terrain.c      Sat Jul  2 17:04:49 2016
@@ -34,7 +34,6 @@
 #include "terrain.h"
 
 static struct terrain civ_terrains[MAX_NUM_TERRAINS];
-static struct extra_type *civ_resources[MAX_RESOURCE_TYPES];
 static struct user_flag user_terrain_flags[MAX_NUM_USER_TER_FLAGS];
 
 /****************************************************************************
@@ -255,7 +254,7 @@
 /****************************************************************************
   Initialize resource_type structure.
 ****************************************************************************/
-struct resource_type *resource_type_init(struct extra_type *pextra, int idx)
+struct resource_type *resource_type_init(struct extra_type *pextra)
 {
   struct resource_type *presource;
 
@@ -263,12 +262,8 @@
 
   pextra->data.resource = presource;
 
-  presource->item_number = idx;
   presource->self = pextra;
 
-  /* Save also to the old array, to be removed in the future. */
-  civ_resources[idx] = pextra;
-
   return presource;
 }
 
@@ -277,15 +272,7 @@
 ****************************************************************************/
 void resource_types_free(void)
 {
-  int i;
-
-  /* Resource structure itself is freed as part of extras destruction.
-   * here we just make sure no dangling pointers are left to old
-   * civ_resources[] */
-
-  for (i = 0; i < MAX_RESOURCE_TYPES; i++) {
-    civ_resources[i] = NULL;
-  }
+  /* Resource structure itself is freed as part of extras destruction. */
 }
 
 /**************************************************************************
@@ -294,70 +281,6 @@
 struct extra_type *resource_extra_get(const struct resource_type *presource)
 {
   return presource->self;
-}
-
-/**************************************************************************
-  Return the first item of resources.
-**************************************************************************/
-struct extra_type *resource_array_first(void)
-{
-  return civ_resources[0];
-}
-
-/**************************************************************************
-  Return the last item of resources.
-**************************************************************************/
-const struct extra_type *resource_array_last(void)
-{
-  return civ_resources[game.control.num_resource_types - 1];
-}
-
-/**************************************************************************
-  Return the resource count.
-**************************************************************************/
-Resource_type_id resource_count(void)
-{
-  return game.control.num_resource_types;
-}
-
-/**************************************************************************
-  Return the resource index.
-
-  Currently same as resource_number(), paired with resource_count()
-  indicates use as an array index.
-
-  FIXME: Get rid of this. _index() makes no sense when they are not
-  in an array.
-**************************************************************************/
-Resource_type_id resource_index(const struct extra_type *presource)
-{
-  fc_assert_ret_val(NULL != presource, -1);
-
-  /* FIXME: */
-  /* return presource - resources; */
-  return resource_number(presource);
-}
-
-/**************************************************************************
-  Return the resource index.
-**************************************************************************/
-Resource_type_id resource_number(const struct extra_type *presource)
-{
-  fc_assert_ret_val(NULL != presource, -1);
-
-  return presource->data.resource->item_number;
-}
-
-/****************************************************************************
-  Return the resource for the given resource index.
-****************************************************************************/
-struct extra_type *resource_by_number(const Resource_type_id type)
-{
-  if (type < 0 || type >= game.control.num_resource_types) {
-    /* This isn't an error; some callers depend on it. */
-    return NULL;
-  }
-  return civ_resources[type];
 }
 
 /****************************************************************************

Modified: trunk/common/terrain.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/terrain.h?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/common/terrain.h      (original)
+++ trunk/common/terrain.h      Sat Jul  2 17:04:49 2016
@@ -41,7 +41,6 @@
 /* === */
 
 struct resource_type {
-  int item_number;
 
   char id_old_save; /* Single-character identifier used in old savegames. */
 #define RESOURCE_NULL_IDENTIFIER '\0'
@@ -302,17 +301,10 @@
                            const struct extra_type *pres,
                            bool check_self);
 
-struct resource_type *resource_type_init(struct extra_type *pextra, int idx);
+struct resource_type *resource_type_init(struct extra_type *pextra);
 void resource_types_free(void);
 
 struct extra_type *resource_extra_get(const struct resource_type *presource);
-
-/* General resource accessor functions. */
-Resource_type_id resource_count(void);
-Resource_type_id resource_index(const struct extra_type *presource);
-Resource_type_id resource_number(const struct extra_type *presource);
-
-struct extra_type *resource_by_number(const Resource_type_id id);
 
 /* Special helper functions */
 const char *get_infrastructure_text(bv_extras extras);
@@ -340,20 +332,6 @@
                                     enum terrain_alteration talter);
 
 /* Initialization and iteration */
-struct extra_type *resource_array_first(void);
-const struct extra_type *resource_array_last(void);
-
-#define resource_type_iterate(_p)                                      \
-{                                                                      \
-  int _ri_##p;                                                          \
-  for (_ri_##p = 0; _ri_##p < game.control.num_resource_types; _ri_##p++) { \
-    struct extra_type *_p = resource_by_number(_ri_##p);
-
-#define resource_type_iterate_end                                      \
-  }                                                                    \
-}
-
-/* Initialization and iteration */
 void terrains_init(void);
 void terrains_free(void);
 

Modified: trunk/fc_version
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/fc_version?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/fc_version    (original)
+++ trunk/fc_version    Sat Jul  2 17:04:49 2016
@@ -56,7 +56,7 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Jun.30b"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel-3.0-2016.Jun.30c"
 NETWORK_CAPSTRING_OPTIONAL=""
 
 FREECIV_DISTRIBUTOR=""

Modified: trunk/server/maphand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/maphand.c?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/server/maphand.c      (original)
+++ trunk/server/maphand.c      Sat Jul  2 17:04:49 2016
@@ -509,8 +509,8 @@
                       ? terrain_number(tile_terrain(ptile))
                       : terrain_count();
       info.resource = (NULL != tile_resource(ptile))
-                       ? resource_number(tile_resource(ptile))
-                       : resource_count();
+                       ? extra_number(tile_resource(ptile))
+                       : extra_count();
 
       info.extras = ptile->extras;
 
@@ -541,8 +541,8 @@
                       ? terrain_number(plrtile->terrain)
                       : terrain_count();
       info.resource = (NULL != plrtile->resource)
-                       ? resource_number(plrtile->resource)
-                       : resource_count();
+                       ? extra_number(plrtile->resource)
+                       : extra_count();
 
       info.extras = plrtile->extras;
 
@@ -562,7 +562,7 @@
       info.worked = IDENTITY_NUMBER_ZERO;
 
       info.terrain = terrain_count();
-      info.resource = resource_count();
+      info.resource = extra_count();
 
       BV_CLR_ALL(info.extras);
 

Modified: trunk/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/ruleset.c?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/server/ruleset.c      (original)
+++ trunk/server/ruleset.c      Sat Jul  2 17:04:49 2016
@@ -2592,7 +2592,7 @@
         pextra = extra_type_by_rule_name(resource_name);
 
         if (pextra != NULL) {
-          resource_type_init(pextra, idx);
+          resource_type_init(pextra);
           section_strlcpy(&resource_sections[idx * MAX_SECTION_LABEL], 
sec_name);
         } else {
           ruleset_error(LOG_ERROR,
@@ -2925,57 +2925,6 @@
   }
 
   if (ok) {
-    /* resource details */
-
-    resource_type_iterate(presource) {
-      char identifier[MAX_LEN_NAME];
-      const int i = resource_index(presource);
-      const char *rsection = &resource_sections[i * MAX_SECTION_LABEL];
-
-      output_type_iterate (o) {
-        presource->data.resource->output[o] =
-         secfile_lookup_int_default(file, 0, "%s.%s", rsection,
-                                     get_output_identifier(o));
-      } output_type_iterate_end;
-
-      sz_strlcpy(identifier,
-                 secfile_lookup_str(file,"%s.identifier", rsection));
-      presource->data.resource->id_old_save = identifier[0];
-      if (RESOURCE_NULL_IDENTIFIER == presource->data.resource->id_old_save) {
-        ruleset_error(LOG_ERROR, "\"%s\" [%s] identifier missing value.",
-                      filename, rsection);
-        ok = FALSE;
-        break;
-      }
-      if (RESOURCE_NONE_IDENTIFIER == presource->data.resource->id_old_save) {
-        ruleset_error(LOG_ERROR,
-                      "\"%s\" [%s] cannot use '%c' as an identifier;"
-                      " it is reserved.",
-                      filename, rsection, 
presource->data.resource->id_old_save);
-        ok = FALSE;
-        break;
-      }
-      for (j = 0; j < i; j++) {
-        if (presource->data.resource->id_old_save
-            == resource_by_number(j)->data.resource->id_old_save) {
-          ruleset_error(LOG_ERROR,
-                        "\"%s\" [%s] has the same identifier as [%s].",
-                        filename,
-                        rsection,
-                        &resource_sections[j * MAX_SECTION_LABEL]);
-          ok = FALSE;
-          break;
-        }
-      }
-
-      if (!ok) {
-        break;
-      }
-
-    } resource_type_iterate_end;
-  }
-
-  if (ok) {
     /* extra details */
     extra_type_iterate(pextra) {
       BV_CLR_ALL(pextra->conflicts);
@@ -3243,6 +3192,58 @@
         pextra->helptext = lookup_strvec(file, section, "helptext");
       }
     } extra_type_iterate_end;
+  }
+
+  if (ok) {
+    int i = 0;
+    /* resource details */
+
+    extra_type_by_cause_iterate(EC_RESOURCE, presource) {
+      char identifier[MAX_LEN_NAME];
+      const char *rsection = &resource_sections[i * MAX_SECTION_LABEL];
+
+      output_type_iterate (o) {
+        presource->data.resource->output[o] =
+         secfile_lookup_int_default(file, 0, "%s.%s", rsection,
+                                     get_output_identifier(o));
+      } output_type_iterate_end;
+
+      sz_strlcpy(identifier,
+                 secfile_lookup_str(file,"%s.identifier", rsection));
+      presource->data.resource->id_old_save = identifier[0];
+      if (RESOURCE_NULL_IDENTIFIER == presource->data.resource->id_old_save) {
+        ruleset_error(LOG_ERROR, "\"%s\" [%s] identifier missing value.",
+                      filename, rsection);
+        ok = FALSE;
+        break;
+      }
+      if (RESOURCE_NONE_IDENTIFIER == presource->data.resource->id_old_save) {
+        ruleset_error(LOG_ERROR,
+                      "\"%s\" [%s] cannot use '%c' as an identifier;"
+                      " it is reserved.",
+                      filename, rsection, 
presource->data.resource->id_old_save);
+        ok = FALSE;
+        break;
+      }
+      extra_type_by_cause_iterate(EC_RESOURCE, pres2) {
+        if (presource->data.resource->id_old_save == 
pres2->data.resource->id_old_save
+            && presource != pres2) {
+          ruleset_error(LOG_ERROR,
+                        "\"%s\" [%s] has the same identifier as [%s].",
+                        filename,
+                        rsection,
+                        extra_rule_name(pres2));
+          ok = FALSE;
+          break;
+        }
+      } extra_type_by_cause_iterate_end;
+
+      if (!ok) {
+        break;
+      }
+
+      i++;
+    } extra_type_by_cause_iterate_end;
   }
 
   if (ok) {
@@ -6827,7 +6828,7 @@
 
     packet.num_resources = 0;
     for (r = pterrain->resources; *r; r++) {
-      packet.resources[packet.num_resources++] = resource_number(*r);
+      packet.resources[packet.num_resources++] = extra_number(*r);
     }
 
     output_type_iterate(o) {
@@ -6877,16 +6878,15 @@
 {
   struct packet_ruleset_resource packet;
 
-  resource_type_iterate(presource) {
-    packet.id = resource_number(presource);
-    packet.extra = extra_index(presource);
+  extra_type_by_cause_iterate(EC_RESOURCE, presource) {
+    packet.id = extra_index(presource);
 
     output_type_iterate(o) {
       packet.output[o] = presource->data.resource->output[o];
     } output_type_iterate_end;
 
     lsend_packet_ruleset_resource(dest, &packet);
-  } resource_type_iterate_end;
+  } extra_type_by_cause_iterate_end;
 }
 
 /**************************************************************************

Modified: trunk/server/savecompat.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/savecompat.c?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/server/savecompat.c   (original)
+++ trunk/server/savecompat.c   Sat Jul  2 17:04:49 2016
@@ -254,11 +254,11 @@
 ****************************************************************************/
 struct extra_type *resource_by_identifier(const char identifier)
 {
-  resource_type_iterate(presource) {
+  extra_type_by_cause_iterate(EC_RESOURCE, presource) {
     if (presource->data.resource->id_old_save == identifier) {
       return presource;
     }
-  } resource_type_iterate_end;
+  } extra_type_by_cause_iterate_end;
 
   return NULL;
 }

Modified: trunk/tools/ruleutil/rulesave.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/tools/ruleutil/rulesave.c?rev=33144&r1=33143&r2=33144&view=diff
==============================================================================
--- trunk/tools/ruleutil/rulesave.c     (original)
+++ trunk/tools/ruleutil/rulesave.c     Sat Jul  2 17:04:49 2016
@@ -2020,7 +2020,7 @@
   } terrain_type_iterate_end;
 
   sect_idx = 0;
-  resource_type_iterate(pres) {
+  extra_type_by_cause_iterate(EC_RESOURCE, pres) {
     char path[512];
     char identifier[2];
 
@@ -2039,7 +2039,7 @@
     identifier[0] = pres->data.resource->id_old_save;
     identifier[1] = '\0';
     secfile_insert_str(sfile, identifier, "%s.identifier", path);
-  } resource_type_iterate_end;
+  } extra_type_by_cause_iterate_end;
 
   secfile_insert_str(sfile, terrain_control.gui_type_base0,
                      "extraui.ui_name_base_fortress");


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

Reply via email to