Author: cazfi
Date: Tue Nov 10 21:39:30 2015
New Revision: 30515

URL: http://svn.gna.org/viewcvs/freeciv?rev=30515&view=rev
Log:
Made is_native_to_class() to take bases and roads parameters as pointers.

See patch #6552

Modified:
    branches/S2_5/client/editor.c
    branches/S2_5/client/gui-gtk-2.0/editprop.c
    branches/S2_5/client/gui-gtk-3.0/editprop.c
    branches/S2_5/client/helpdata.c
    branches/S2_5/client/tilespec.c
    branches/S2_5/common/aicore/pf_tools.c
    branches/S2_5/common/movement.c
    branches/S2_5/common/movement.h
    branches/S2_5/common/tile.c
    branches/S2_5/common/tile.h
    branches/S2_5/server/advisors/advruleset.c
    branches/S2_5/server/generator/mapgen.c
    branches/S2_5/server/ruleset.c
    branches/S2_5/server/unittools.c

Modified: branches/S2_5/client/editor.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/editor.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/client/editor.c       (original)
+++ branches/S2_5/client/editor.c       Tue Nov 10 21:39:30 2015
@@ -1496,13 +1496,13 @@
       break;
     case EBT_BASE:
       if (tile_has_any_bases(ptile)) {
-        tile_set_bases(vtile, tile_bases(ptile));
+        tile_set_bases(vtile, *tile_bases(ptile));
         copied = TRUE;
       }
       break;
     case EBT_ROAD:
       if (BV_ISSET_ANY(ptile->roads)) {
-        vtile->roads = tile_roads(ptile);
+        vtile->roads = *tile_roads(ptile);
         copied = TRUE;
       }
       break;
@@ -1566,8 +1566,8 @@
   }
   packet->tile = tile_index(ptile);
   packet->specials = tile_specials(ptile);
-  packet->bases = tile_bases(ptile);
-  packet->roads = tile_roads(ptile);
+  packet->bases = *tile_bases(ptile);
+  packet->roads = *tile_roads(ptile);
 
   presource = tile_resource(ptile);
   packet->resource = presource
@@ -1629,11 +1629,11 @@
       send_edit_tile = TRUE;
       break;
     case EBT_BASE:
-      tile_packet.bases = tile_bases(vtile);
+      tile_packet.bases = *tile_bases(vtile);
       send_edit_tile = TRUE;
       break;
     case EBT_ROAD:
-      tile_packet.roads = tile_roads(vtile);
+      tile_packet.roads = *tile_roads(vtile);
       send_edit_tile = TRUE;
       break;
     case EBT_UNIT:

Modified: branches/S2_5/client/gui-gtk-2.0/editprop.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-2.0/editprop.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-2.0/editprop.c (original)
+++ branches/S2_5/client/gui-gtk-2.0/editprop.c Tue Nov 10 21:39:30 2015
@@ -1506,10 +1506,10 @@
         pv->data.v_bv_special = tile_specials(ptile);
         break;
       case OPID_TILE_ROADS:
-        pv->data.v_bv_roads = tile_roads(ptile);
+        pv->data.v_bv_roads = *tile_roads(ptile);
         break;
       case OPID_TILE_BASES:
-        pv->data.v_bv_bases = tile_bases(ptile);
+        pv->data.v_bv_bases = *tile_bases(ptile);
         break;
       case OPID_TILE_VISION:
         pv->data.v_tile_vision = fc_malloc(sizeof(struct tile_vision_data));
@@ -2173,8 +2173,8 @@
 
       packet->tile = tile_index(ptile);
       packet->specials = tile_specials(ptile);
-      packet->bases = tile_bases(ptile);
-      packet->roads = tile_roads(ptile);
+      packet->bases = *tile_bases(ptile);
+      packet->roads = *tile_roads(ptile);
       /* TODO: Set more packet fields. */
     }
     return;

Modified: branches/S2_5/client/gui-gtk-3.0/editprop.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-gtk-3.0/editprop.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/client/gui-gtk-3.0/editprop.c (original)
+++ branches/S2_5/client/gui-gtk-3.0/editprop.c Tue Nov 10 21:39:30 2015
@@ -1506,10 +1506,10 @@
         pv->data.v_bv_special = tile_specials(ptile);
         break;
       case OPID_TILE_ROADS:
-        pv->data.v_bv_roads = tile_roads(ptile);
+        pv->data.v_bv_roads = *tile_roads(ptile);
         break;
       case OPID_TILE_BASES:
-        pv->data.v_bv_bases = tile_bases(ptile);
+        pv->data.v_bv_bases = *tile_bases(ptile);
         break;
       case OPID_TILE_VISION:
         pv->data.v_tile_vision = fc_malloc(sizeof(struct tile_vision_data));
@@ -2173,8 +2173,8 @@
 
       packet->tile = tile_index(ptile);
       packet->specials = tile_specials(ptile);
-      packet->bases = tile_bases(ptile);
-      packet->roads = tile_roads(ptile);
+      packet->bases = *tile_bases(ptile);
+      packet->roads = *tile_roads(ptile);
       /* TODO: Set more packet fields. */
     }
     return;

Modified: branches/S2_5/client/helpdata.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/helpdata.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/client/helpdata.c     (original)
+++ branches/S2_5/client/helpdata.c     Tue Nov 10 21:39:30 2015
@@ -3183,14 +3183,9 @@
   {
     const char *classes[uclass_count()];
     int i = 0;
-    bv_bases bases;
-    bv_roads roads;
-
-    BV_CLR_ALL(bases);
-    BV_CLR_ALL(roads);
 
     unit_class_iterate(uclass) {
-      if (is_native_to_class(uclass, pterrain, bases, roads)) {
+      if (is_native_to_class(uclass, pterrain, NULL, NULL)) {
         classes[i++] = uclass_name_translation(uclass);
       }
     } unit_class_iterate_end;

Modified: branches/S2_5/client/tilespec.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/tilespec.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/client/tilespec.c     (original)
+++ branches/S2_5/client/tilespec.c     Tue Nov 10 21:39:30 2015
@@ -3671,7 +3671,7 @@
       if (NULL != terrain1) {
         tterrain_near[dir] = terrain1;
         tspecial_near[dir] = tile_specials(tile1);
-        troad_near[dir] = tile_roads(tile1);
+        troad_near[dir] = *tile_roads(tile1);
         continue;
       }
       log_error("build_tile_data() tile (%d,%d) has no terrain!",
@@ -4871,7 +4871,7 @@
 
   if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
     tspecial = tile_specials(ptile);
-    troad = tile_roads(ptile);
+    troad = *tile_roads(ptile);
     pterrain = tile_terrain(ptile);
 
     if (NULL != pterrain) {

Modified: branches/S2_5/common/aicore/pf_tools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/aicore/pf_tools.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/common/aicore/pf_tools.c      (original)
+++ branches/S2_5/common/aicore/pf_tools.c      Tue Nov 10 21:39:30 2015
@@ -704,15 +704,8 @@
   parameter->unknown_MC = SINGLE_MOVE;
 
   if (uclass_has_flag(punitclass, UCF_TERRAIN_SPEED)) {
-    /* Unit is subject to terrain movement costs */
-    bv_bases bases;
-    bv_roads roads;
-
-    BV_CLR_ALL(bases);
-    BV_CLR_ALL(roads);
-
     terrain_type_iterate(pterrain) {
-      if (is_native_terrain(punittype, pterrain, bases, roads)) {
+      if (is_native_terrain(punittype, pterrain, NULL, NULL)) {
         /* Exact movement cost matters only if we can enter
          * the tile. */
         int mr = 2 * pterrain->movement_cost;

Modified: branches/S2_5/common/movement.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/movement.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/common/movement.c     (original)
+++ branches/S2_5/common/movement.c     Tue Nov 10 21:39:30 2015
@@ -170,7 +170,7 @@
         continue;
       } else if (piter != pexclude
                  && is_native_to_class(punitclass, tile_terrain(piter),
-                                       piter->bases, piter->roads)) {
+                                       tile_bases(piter), tile_roads(piter))) {
         found = TRUE;
         break;
       } else if (piter != pexclude
@@ -252,7 +252,7 @@
 ****************************************************************************/
 bool is_native_terrain(const struct unit_type *punittype,
                        const struct terrain *pterrain,
-                       bv_bases bases, bv_roads roads)
+                       const bv_bases *bases, const bv_roads *roads)
 {
   return is_native_to_class(utype_class(punittype), pterrain, bases, roads);
 }
@@ -275,7 +275,7 @@
 ****************************************************************************/
 bool is_native_to_class(const struct unit_class *punitclass,
                         const struct terrain *pterrain,
-                        bv_bases bases, bv_roads roads)
+                        const bv_bases *bases, const bv_roads *roads)
 {
   if (!pterrain) {
     /* Unknown is considered native terrain */
@@ -286,17 +286,21 @@
     return TRUE;
   }
 
-  road_type_list_iterate(punitclass->cache.native_tile_roads, proad) {
-    if (BV_ISSET(roads, road_index(proad))) {
-      return TRUE;
-    }
-  } road_type_list_iterate_end;
-
-  base_type_list_iterate(punitclass->cache.native_tile_bases, pbase) {
-    if (BV_ISSET(bases, base_index(pbase))) {
-      return TRUE;
-    }
-  } base_type_list_iterate_end;
+  if (roads != NULL) {
+    road_type_list_iterate(punitclass->cache.native_tile_roads, proad) {
+      if (BV_ISSET(*roads, road_index(proad))) {
+        return TRUE;
+      }
+    } road_type_list_iterate_end;
+  }
+
+  if (bases != NULL) {
+    base_type_list_iterate(punitclass->cache.native_tile_bases, pbase) {
+      if (BV_ISSET(*bases, base_index(pbase))) {
+        return TRUE;
+      }
+    } base_type_list_iterate_end;
+  }
 
   return FALSE;
 }

Modified: branches/S2_5/common/movement.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/movement.h?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/common/movement.h     (original)
+++ branches/S2_5/common/movement.h     Tue Nov 10 21:39:30 2015
@@ -65,10 +65,10 @@
                              const struct tile *ptile);
 bool is_native_terrain(const struct unit_type *punittype,
                        const struct terrain *pterrain,
-                       bv_bases bases, bv_roads roads);
+                       const bv_bases *bases, const bv_roads *roads);
 bool is_native_to_class(const struct unit_class *punitclass,
                         const struct terrain *pterrain,
-                        bv_bases bases, bv_roads roads);
+                        const bv_bases *bases, const bv_roads *roads);
 bool is_native_near_tile(const struct unit_class *uclass, const struct tile 
*ptile);
 bool can_exist_at_tile(const struct unit_type *utype,
                        const struct tile *ptile);

Modified: branches/S2_5/common/tile.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/tile.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/common/tile.c (original)
+++ branches/S2_5/common/tile.c Tue Nov 10 21:39:30 2015
@@ -29,6 +29,9 @@
 #include "unitlist.h"
 
 #include "tile.h"
+
+static bv_bases empty_bases;
+static bv_roads empty_roads;
 
 #ifndef tile_index
 /****************************************************************************
@@ -189,28 +192,39 @@
 /****************************************************************************
   Returns a bit vector of the bases present at the tile.
 ****************************************************************************/
-bv_bases tile_bases(const struct tile *ptile)
+const bv_bases *tile_bases(const struct tile *ptile)
 {
   if (!ptile) {
-    bv_bases empty;
-    BV_CLR_ALL(empty);
-    return empty;
-  }
-  return ptile->bases;
+    static bool empty_cleared = FALSE;
+
+    if (!empty_cleared) {
+      BV_CLR_ALL(empty_bases);
+      empty_cleared = TRUE;
+    }
+
+    return &empty_bases;
+  }
+
+  return &(ptile->bases);
 }
 
 /****************************************************************************
   Returns a bit vector of the roads present at the tile.
 ****************************************************************************/
-bv_roads tile_roads(const struct tile *ptile)
+const bv_roads *tile_roads(const struct tile *ptile)
 {
   if (!ptile) {
-    bv_roads empty;
-    BV_CLR_ALL(empty);
-    return empty;
-  }
-
-  return ptile->roads;
+    static bool empty_cleared = FALSE;
+
+    if (!empty_cleared) {
+      BV_CLR_ALL(empty_roads);
+      empty_cleared = TRUE;
+    }
+
+    return &empty_roads;
+  }
+
+  return &(ptile->roads);
 }
 
 /****************************************************************************

Modified: branches/S2_5/common/tile.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/common/tile.h?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/common/tile.h (original)
+++ branches/S2_5/common/tile.h Tue Nov 10 21:39:30 2015
@@ -120,8 +120,8 @@
 void tile_clear_special(struct tile *ptile, enum tile_special_type spe);
 void tile_clear_all_specials(struct tile *ptile);
 
-bv_bases tile_bases(const struct tile *ptile);
-bv_roads tile_roads(const struct tile *ptile);
+const bv_bases *tile_bases(const struct tile *ptile);
+const bv_roads *tile_roads(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);
 bool tile_has_conflicting_base(const struct tile *ptile, const struct 
base_type *pbase);

Modified: branches/S2_5/server/advisors/advruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/advisors/advruleset.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/server/advisors/advruleset.c  (original)
+++ branches/S2_5/server/advisors/advruleset.c  Tue Nov 10 21:39:30 2015
@@ -27,12 +27,6 @@
 **************************************************************************/
 void adv_units_ruleset_init(void)
 {
-  bv_bases bases;
-  bv_roads roads;
-
-  BV_CLR_ALL(bases);
-  BV_CLR_ALL(roads); /* 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 */
@@ -40,7 +34,7 @@
     bool move_sea_disabled  = FALSE; /* Cannot move at some ocean terrains */
 
     terrain_type_iterate(pterrain) {
-      if (is_native_to_class(pclass, pterrain, bases, roads)) {
+      if (is_native_to_class(pclass, pterrain, NULL, NULL)) {
         /* Can move at terrain */
         if (is_ocean(pterrain)) {
           move_sea_enabled = TRUE;

Modified: branches/S2_5/server/generator/mapgen.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/generator/mapgen.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/server/generator/mapgen.c     (original)
+++ branches/S2_5/server/generator/mapgen.c     Tue Nov 10 21:39:30 2015
@@ -3594,7 +3594,7 @@
       pftile->pterrain = tile_terrain(ptile);
       pftile->presource = tile_resource(ptile);
       pftile->specials = tile_specials(ptile);
-      pftile->roads = tile_roads(ptile);
+      pftile->roads = *tile_roads(ptile);
     } whole_map_iterate_end;
 
     /* Create main player island. */

Modified: branches/S2_5/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/ruleset.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/server/ruleset.c      (original)
+++ branches/S2_5/server/ruleset.c      Tue Nov 10 21:39:30 2015
@@ -1723,13 +1723,7 @@
         } base_type_iterate_end;
 
         terrain_type_iterate(pterrain) {
-          bv_bases bases;
-          bv_roads roads;
-
-          BV_CLR_ALL(bases);
-          BV_CLR_ALL(roads);
-
-          if (is_native_to_class(uc, pterrain, bases, roads)) {
+          if (is_native_to_class(uc, pterrain, NULL, NULL)) {
             if (is_ocean(pterrain)) {
               sea_moving = TRUE;
             } else {

Modified: branches/S2_5/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/unittools.c?rev=30515&r1=30514&r2=30515&view=diff
==============================================================================
--- branches/S2_5/server/unittools.c    (original)
+++ branches/S2_5/server/unittools.c    Tue Nov 10 21:39:30 2015
@@ -1033,8 +1033,8 @@
     struct act_tgt tgt;
 
     bv_special specials = tile_specials(ptile);
-    bv_bases bases = tile_bases(ptile);
-    bv_roads roads = tile_roads(ptile);
+    bv_bases bases = *tile_bases(ptile);
+    bv_roads roads = *tile_roads(ptile);
 
     while (get_preferred_pillage(&tgt, specials, bases, roads)) {
 
@@ -2804,7 +2804,7 @@
 
     if (NULL == plrtile->site
         && !is_native_to_class(unit_class(punit), plrtile->terrain,
-                               plrtile->bases, plrtile->roads)) {
+                               &(plrtile->bases), &(plrtile->roads))) {
       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