Author: cazfi
Date: Sun Mar 30 15:37:07 2014
New Revision: 24740

URL: http://svn.gna.org/viewcvs/freeciv?rev=24740&view=rev
Log:
Create cache listing extra types that can provide tile nativity to the unit 
class
at the ruleset loading time. Iterate over that list only when checking if tile
is native for a unit.

See patch #4609

Modified:
    branches/S2_4/client/client_main.c
    branches/S2_4/common/base.h
    branches/S2_4/common/game.c
    branches/S2_4/common/movement.c
    branches/S2_4/common/unittype.c
    branches/S2_4/common/unittype.h
    branches/S2_4/server/ruleset.c

Modified: branches/S2_4/client/client_main.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/client/client_main.c?rev=24740&r1=24739&r2=24740&view=diff
==============================================================================
--- branches/S2_4/client/client_main.c  (original)
+++ branches/S2_4/client/client_main.c  Sun Mar 30 15:37:07 2014
@@ -794,6 +794,13 @@
       audio_stop();     /* stop intro sound loop. */
     }
 
+    /* This cannot be in handling the rulesets_ready packet,
+     * as that packet is only added via optional capability -
+     * first 2.4 versions didn't have it. */
+    unit_class_iterate(pclass) {
+      set_unit_class_caches(pclass);
+    } unit_class_iterate_end;
+
     init_city_report_game_data();
     options_dialogs_set();
     create_event(NULL, E_GAME_START, ftc_client, _("Game started."));

Modified: branches/S2_4/common/base.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/base.h?rev=24740&r1=24739&r2=24740&view=diff
==============================================================================
--- branches/S2_4/common/base.h (original)
+++ branches/S2_4/common/base.h Sun Mar 30 15:37:07 2014
@@ -81,6 +81,15 @@
 
 #define BASE_NONE       -1
 
+/* get 'struct base_type_list' and related functions: */
+#define SPECLIST_TAG base_type
+#define SPECLIST_TYPE struct base_type
+#include "speclist.h"
+
+#define base_type_list_iterate(baselist, pbase) \
+    TYPED_LIST_ITERATE(struct base_type, baselist, pbase)
+#define base_type_list_iterate_end LIST_ITERATE_END
+
 /* General base accessor functions. */
 Base_type_id base_count(void);
 Base_type_id base_index(const struct base_type *pbase);

Modified: branches/S2_4/common/game.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/game.c?rev=24740&r1=24739&r2=24740&view=diff
==============================================================================
--- branches/S2_4/common/game.c (original)
+++ branches/S2_4/common/game.c Sun Mar 30 15:37:07 2014
@@ -511,6 +511,7 @@
   } players_iterate_end;
   game.government_during_revolution = NULL;
 
+  unit_classes_free();
   specialists_free();
   techs_free();
   governments_free();

Modified: branches/S2_4/common/movement.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/movement.c?rev=24740&r1=24739&r2=24740&view=diff
==============================================================================
--- branches/S2_4/common/movement.c     (original)
+++ branches/S2_4/common/movement.c     Sun Mar 30 15:37:07 2014
@@ -298,13 +298,11 @@
     return TRUE;
   }
 
-  base_type_iterate(pbase) {
-    if (BV_ISSET(bases, base_index(pbase))
-        && base_has_flag(pbase, BF_NATIVE_TILE)
-        && is_native_base_to_uclass(pbase, punitclass)) {
+  base_type_list_iterate(punitclass->cache.native_tile_bases, pbase) {
+    if (BV_ISSET(bases, base_index(pbase))) {
       return TRUE;
     }
-  } base_type_iterate_end;
+  } base_type_list_iterate_end;
 
   return FALSE;
 }

Modified: branches/S2_4/common/unittype.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/unittype.c?rev=24740&r1=24739&r2=24740&view=diff
==============================================================================
--- branches/S2_4/common/unittype.c     (original)
+++ branches/S2_4/common/unittype.c     Sun Mar 30 15:37:07 2014
@@ -1098,6 +1098,22 @@
    * num_unit_classes isn't known yet. */
   for (i = 0; i < ARRAY_SIZE(unit_classes); i++) {
     unit_classes[i].item_number = i;
+    unit_classes[i].cache.native_tile_bases = NULL;
+  }
+}
+
+/****************************************************************************
+  Free resources allocated for unit classes.
+****************************************************************************/
+void unit_classes_free(void)
+{
+  int i;
+
+  for (i = 0; i < ARRAY_SIZE(unit_classes); i++) {
+    if (unit_classes[i].cache.native_tile_bases != NULL) {
+      base_type_list_destroy(unit_classes[i].cache.native_tile_bases);
+      unit_classes[i].cache.native_tile_bases = NULL;
+    }
   }
 }
 
@@ -1227,3 +1243,18 @@
   vlevel->raise_chance = vlist_raise;
   vlevel->work_raise_chance = vlist_wraise;
 }
+
+/****************************************************************************
+  Set caches for unit class.
+****************************************************************************/
+void set_unit_class_caches(struct unit_class *pclass)
+{
+  pclass->cache.native_tile_bases = base_type_list_new();
+
+  base_type_iterate(pbase) {
+    if (is_native_base_to_uclass(pbase, pclass)
+        && base_has_flag(pbase, BF_NATIVE_TILE)) {
+        base_type_list_append(pclass->cache.native_tile_bases, pbase);
+    }
+  } base_type_iterate_end;
+}

Modified: branches/S2_4/common/unittype.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/common/unittype.h?rev=24740&r1=24739&r2=24740&view=diff
==============================================================================
--- branches/S2_4/common/unittype.h     (original)
+++ branches/S2_4/common/unittype.h     Sun Mar 30 15:37:07 2014
@@ -96,6 +96,10 @@
     enum move_level land_move;
     enum move_level sea_move;
   } adv;
+
+  struct {
+    struct base_type_list *native_tile_bases;
+  } cache;
 };
 
 /* Unit "special effects" flags:
@@ -411,6 +415,9 @@
 
 /* Initialization and iteration */
 void unit_classes_init(void);
+void unit_classes_free(void);
+
+void set_unit_class_caches(struct unit_class *pclass);
 
 struct unit_class *unit_class_array_first(void);
 const struct unit_class *unit_class_array_last(void);

Modified: branches/S2_4/server/ruleset.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_4/server/ruleset.c?rev=24740&r1=24739&r2=24740&view=diff
==============================================================================
--- branches/S2_4/server/ruleset.c      (original)
+++ branches/S2_4/server/ruleset.c      Sun Mar 30 15:37:07 2014
@@ -1349,6 +1349,8 @@
     fc_strlcat(tmp, sec_name, 200);
     fc_strlcat(tmp, ".move_type", 200);
     uc->move_type = lookup_move_type(file, tmp, filename);
+
+    set_unit_class_caches(uc);
 
     if (!unit_move_type_is_valid(uc->move_type)) {
       /* Not explicitly given, determine automatically */


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

Reply via email to