Author: cazfi
Date: Tue Nov 10 21:38:57 2015
New Revision: 30513

URL: http://svn.gna.org/viewcvs/freeciv?rev=30513&view=rev
Log:
Made is_native_to_class() to take extras parameter as an pointer.

See patch #6552

Modified:
    trunk/client/editor.c
    trunk/client/gui-gtk-2.0/editprop.c
    trunk/client/gui-gtk-3.0/editprop.c
    trunk/client/helpdata.c
    trunk/client/tilespec.c
    trunk/common/movement.c
    trunk/common/movement.h
    trunk/common/tile.c
    trunk/common/tile.h
    trunk/common/unittype.c
    trunk/server/advisors/advruleset.c
    trunk/server/generator/mapgen.c
    trunk/server/rssanity.c
    trunk/server/unittools.c

Modified: trunk/client/editor.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/editor.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/client/editor.c       (original)
+++ trunk/client/editor.c       Tue Nov 10 21:38:57 2015
@@ -1588,7 +1588,7 @@
     return;
   }
   packet->tile = tile_index(ptile);
-  packet->extras = tile_extras(ptile);
+  packet->extras = *tile_extras(ptile);
 
   presource = tile_resource(ptile);
   packet->resource = presource

Modified: trunk/client/gui-gtk-2.0/editprop.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-2.0/editprop.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/client/gui-gtk-2.0/editprop.c (original)
+++ trunk/client/gui-gtk-2.0/editprop.c Tue Nov 10 21:38:57 2015
@@ -2204,7 +2204,7 @@
       }
 
       packet->tile = tile_index(ptile);
-      packet->extras = tile_extras(ptile);
+      packet->extras = *tile_extras(ptile);
       /* TODO: Set more packet fields. */
     }
     return;

Modified: trunk/client/gui-gtk-3.0/editprop.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-gtk-3.0/editprop.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/client/gui-gtk-3.0/editprop.c (original)
+++ trunk/client/gui-gtk-3.0/editprop.c Tue Nov 10 21:38:57 2015
@@ -2204,7 +2204,7 @@
       }
 
       packet->tile = tile_index(ptile);
-      packet->extras = tile_extras(ptile);
+      packet->extras = *tile_extras(ptile);
       /* TODO: Set more packet fields. */
     }
     return;

Modified: trunk/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/helpdata.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/client/helpdata.c     (original)
+++ trunk/client/helpdata.c     Tue Nov 10 21:38:57 2015
@@ -4654,12 +4654,9 @@
   {
     const char *classes[uclass_count()];
     int i = 0;
-    bv_extras extras;
-
-    BV_CLR_ALL(extras);
 
     unit_class_iterate(uclass) {
-      if (is_native_to_class(uclass, pterrain, extras)) {
+      if (is_native_to_class(uclass, pterrain, NULL)) {
         classes[i++] = uclass_name_translation(uclass);
       }
     } unit_class_iterate_end;

Modified: trunk/client/tilespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/tilespec.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/client/tilespec.c     (original)
+++ trunk/client/tilespec.c     Tue Nov 10 21:38:57 2015
@@ -3809,7 +3809,7 @@
 
       if (NULL != terrain1) {
         tterrain_near[dir] = terrain1;
-        textras_near[dir] = tile_extras(tile1);
+        textras_near[dir] = *tile_extras(tile1);
         continue;
       }
       log_error("build_tile_data() tile (%d,%d) has no terrain!",
@@ -5072,7 +5072,7 @@
   }
 
   if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
-    textras = tile_extras(ptile);
+    textras = *tile_extras(ptile);
     pterrain = tile_terrain(ptile);
 
     if (NULL != pterrain) {

Modified: trunk/common/movement.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/movement.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/common/movement.c     (original)
+++ trunk/common/movement.c     Tue Nov 10 21:38:57 2015
@@ -102,10 +102,7 @@
 int utype_unknown_move_cost(const struct unit_type *utype)
 {
   const struct unit_class *uclass = utype_class(utype);
-  bv_extras extras;
   int move_cost;
-
-  BV_CLR_ALL(extras);
 
   if (!uclass_has_flag(uclass, UCF_TERRAIN_SPEED)) {
     /* Unit is not subject to terrain movement costs. */
@@ -117,7 +114,7 @@
     /* Unit is subject to terrain movement costs. */
     move_cost = 1; /* Arbitrary minimum. */
     terrain_type_iterate(pterrain) {
-      if (is_native_to_class(uclass, pterrain, extras)
+      if (is_native_to_class(uclass, pterrain, NULL)
           && pterrain->movement_cost > move_cost) {
         /* Exact movement cost matters only if we can enter
          * the tile. */
@@ -132,7 +129,7 @@
    * N.B.: We don't take in account terrain no unit can enter here. */
   terrain_type_iterate(pterrain) {
     if (BV_ISSET_ANY(pterrain->native_to)
-        && !is_native_to_class(uclass, pterrain, extras)) {
+        && !is_native_to_class(uclass, pterrain, NULL)) {
       /* Units that may encounter unsuitable terrain explore less. */
       move_cost *= 2;
       break;
@@ -292,7 +289,7 @@
 ****************************************************************************/
 bool is_native_to_class(const struct unit_class *punitclass,
                         const struct terrain *pterrain,
-                        bv_extras extras)
+                        const bv_extras *extras)
 {
   if (!pterrain) {
     /* Unknown is considered native terrain */
@@ -303,11 +300,13 @@
     return TRUE;
   }
 
-  extra_type_list_iterate(punitclass->cache.native_tile_extras, pextra) {
-    if (BV_ISSET(extras, extra_index(pextra))) {
-      return TRUE;
-    }
-  } extra_type_list_iterate_end;
+  if (extras != NULL) {
+    extra_type_list_iterate(punitclass->cache.native_tile_extras, pextra) {
+      if (BV_ISSET(*extras, extra_index(pextra))) {
+        return TRUE;
+      }
+    } extra_type_list_iterate_end;
+  }
 
   return FALSE;
 }
@@ -324,16 +323,14 @@
                     const struct tile *dst_tile)
 {
   const struct road_type *proad;
-  bv_extras none;
-
-  BV_CLR_ALL(none);
-  if (is_native_to_class(punitclass, tile_terrain(dst_tile), none)) {
+
+  if (is_native_to_class(punitclass, tile_terrain(dst_tile), NULL)) {
     /* We aren't using extras to make the destination native. */
     return TRUE;
   } else if (!is_native_tile_to_class(punitclass, src_tile)) {
     /* Disembarking or leaving port, so ignore road connectivity. */
     return TRUE;
-  } else if (is_native_to_class(punitclass, tile_terrain(src_tile), none)) {
+  } else if (is_native_to_class(punitclass, tile_terrain(src_tile), NULL)) {
     /* Native source terrain depends entirely on destination tile nativity. */
     return is_native_tile_to_class(punitclass, dst_tile);
   }

Modified: trunk/common/movement.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/movement.h?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/common/movement.h     (original)
+++ trunk/common/movement.h     Tue Nov 10 21:38:57 2015
@@ -68,7 +68,7 @@
                              const struct tile *ptile);
 bool is_native_to_class(const struct unit_class *punitclass,
                         const struct terrain *pterrain,
-                        bv_extras extras);
+                        const bv_extras *extras);
 bool is_native_move(const struct unit_class *punitclass,
                     const struct tile *src_tile,
                     const struct tile *dst_tile);

Modified: trunk/common/tile.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/tile.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/common/tile.c (original)
+++ trunk/common/tile.c Tue Nov 10 21:38:57 2015
@@ -30,6 +30,8 @@
 #include "unitlist.h"
 
 #include "tile.h"
+
+static bv_extras empty_extras;
 
 #ifndef tile_index
 /****************************************************************************
@@ -150,16 +152,20 @@
 /****************************************************************************
   Returns a bit vector of the extras present at the tile.
 ****************************************************************************/
-bv_extras tile_extras(const struct tile *ptile)
+const bv_extras *tile_extras(const struct tile *ptile)
 {
   if (!ptile) {
-    bv_extras empty;
-
-    BV_CLR_ALL(empty);
-    return empty;
-  }
-
-  return ptile->extras;
+    static bool empty_cleared = FALSE;
+
+    if (!empty_cleared) {
+      BV_CLR_ALL(empty_extras);
+      empty_cleared = TRUE;
+    }
+
+    return &(empty_extras);
+  }
+
+  return &(ptile->extras);
 }
 
 /****************************************************************************

Modified: trunk/common/tile.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/tile.h?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/common/tile.h (original)
+++ trunk/common/tile.h Tue Nov 10 21:38:57 2015
@@ -108,7 +108,7 @@
 /* struct city *tile_worked(const struct tile *ptile); */
 void tile_set_worked(struct tile *ptile, struct city *pcity);
 
-bv_extras tile_extras(const struct tile *ptile);
+const bv_extras *tile_extras(const struct tile *ptile);
 void tile_set_bases(struct tile *ptile, bv_bases bases);
 bool tile_has_base(const struct tile *ptile, const struct base_type *pbase);
 void tile_add_base(struct tile *ptile, const struct base_type *pbase);

Modified: trunk/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unittype.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/common/unittype.c     (original)
+++ trunk/common/unittype.c     Tue Nov 10 21:38:57 2015
@@ -1953,11 +1953,7 @@
   } extra_type_iterate_end;
 
   terrain_type_iterate(pterrain) {
-    bv_extras extras;
-
-    BV_CLR_ALL(extras);
-
-    if (is_native_to_class(puclass, pterrain, extras)) {
+    if (is_native_to_class(puclass, pterrain, NULL)) {
       if (is_ocean(pterrain)) {
         sea_moving = TRUE;
       } else {

Modified: trunk/server/advisors/advruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/advisors/advruleset.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/server/advisors/advruleset.c  (original)
+++ trunk/server/advisors/advruleset.c  Tue Nov 10 21:38:57 2015
@@ -28,10 +28,6 @@
 **************************************************************************/
 void adv_units_ruleset_init(void)
 {
-  bv_extras extras;
-
-  BV_CLR_ALL(extras); /* Can it move even without road */
-
   unit_class_iterate(pclass) {
     bool move_land_enabled  = FALSE; /* Can move at some land terrains */
     bool move_land_disabled = FALSE; /* Cannot move at some land terrains */
@@ -39,7 +35,7 @@
     bool move_sea_disabled  = FALSE; /* Cannot move at some ocean terrains */
 
     terrain_type_iterate(pterrain) {
-      if (is_native_to_class(pclass, pterrain, extras)) {
+      if (is_native_to_class(pclass, pterrain, NULL)) {
         /* Can move at terrain */
         if (is_ocean(pterrain)) {
           move_sea_enabled = TRUE;

Modified: trunk/server/generator/mapgen.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/generator/mapgen.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/server/generator/mapgen.c     (original)
+++ trunk/server/generator/mapgen.c     Tue Nov 10 21:38:57 2015
@@ -3605,7 +3605,7 @@
       }
       pftile->pterrain = tile_terrain(ptile);
       pftile->presource = tile_resource(ptile);
-      pftile->extras = tile_extras(ptile);
+      pftile->extras = *tile_extras(ptile);
     } whole_map_iterate_end;
 
     /* Create main player island. */

Modified: trunk/server/rssanity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rssanity.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/server/rssanity.c     (original)
+++ trunk/server/rssanity.c     Tue Nov 10 21:38:57 2015
@@ -900,11 +900,7 @@
 
   terrain_type_iterate(pterr) {
     if (pterr->animal != NULL) {
-      bv_extras no_extras;
-
-      BV_CLR_ALL(no_extras);
-
-      if (!is_native_to_class(utype_class(pterr->animal), pterr, no_extras)) {
+      if (!is_native_to_class(utype_class(pterr->animal), pterr, NULL)) {
         ruleset_error(LOG_ERROR,
                       "%s has %s as animal to appear, but it's not native to 
the terrain.",
                       terrain_rule_name(pterr), 
utype_rule_name(pterr->animal));

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=30513&r1=30512&r2=30513&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Tue Nov 10 21:38:57 2015
@@ -1021,7 +1021,7 @@
     struct tile *ptile = unit_tile(punit);
     struct extra_type *tgt;
 
-    bv_extras extras = tile_extras(ptile);
+    bv_extras extras = *tile_extras(ptile);
 
     while ((tgt = get_preferred_pillage(extras))) {
 
@@ -2700,7 +2700,7 @@
 
     if (NULL == plrtile->site
         && !is_native_to_class(unit_class_get(punit), plrtile->terrain,
-                               plrtile->extras)) {
+                               &(plrtile->extras))) {
       notify_player(pplayer, ptile, E_BAD_COMMAND, ftc_server,
                     _("This unit cannot paradrop into %s."),
                     terrain_name_translation(plrtile->terrain));


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

Reply via email to