<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40635 >

 This patch adds "NativeTile" base type flag. Tile where such base is,
is considered native for those units that base affects (as told by
bases native_to field).

 This is not used in official rulesets. Of the unofficial rulesets, at
least Alien World will need it.


 Applies on top of #40634


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c 2008-10-27 04:13:32.000000000 +0200
+++ freeciv/ai/aiunit.c 2009-01-07 17:23:08.000000000 +0200
@@ -2587,7 +2587,10 @@
 void unit_class_ai_init(void)
 {
   bv_special special;
+  bv_bases bases;
+
   BV_CLR_ALL(special); /* Can it move even without road */
+  BV_CLR_ALL(bases);
 
   unit_class_iterate(pclass) {
     bool move_land_enabled  = FALSE; /* Can move at some land terrains */
@@ -2596,7 +2599,7 @@
     bool move_sea_disabled  = FALSE; /* Cannot move at some ocean terrains */
 
     terrain_type_iterate(pterrain) {
-      if (is_native_to_class(pclass, pterrain, special)) {
+      if (is_native_to_class(pclass, pterrain, special, bases)) {
         /* Can move at terrain */
         if (is_ocean(pterrain)) {
           move_sea_enabled = TRUE;
diff -Nurd -X.diff_ignore freeciv/common/aicore/pf_tools.c 
freeciv/common/aicore/pf_tools.c
--- freeciv/common/aicore/pf_tools.c    2008-12-15 21:55:49.000000000 +0200
+++ freeciv/common/aicore/pf_tools.c    2009-01-07 17:19:15.000000000 +0200
@@ -825,15 +825,17 @@
     /* Unit is subject to terrain movement costs */
     struct unit_type *punittype = unit_type(punit);
     bv_special specials;
+    bv_bases bases;
 
     BV_CLR_ALL(specials); /* This works at the moment, since road is
                            * only special that affects is_native_terrain()
                            * Even if tile contains road, we can safely
                            * ignore it since movement cost for it is
                            * certainly less than SINGLE_MOVE. */
+    BV_CLR_ALL(bases);
 
     terrain_type_iterate(pterrain) {
-      if (is_native_terrain(punittype, pterrain, specials)) {
+      if (is_native_terrain(punittype, pterrain, specials, bases)) {
         /* Exact movement cost matters only if we can enter
          * the tile. */
         int mr = 2 * pterrain->movement_cost;
diff -Nurd -X.diff_ignore freeciv/common/base.c freeciv/common/base.c
--- freeciv/common/base.c       2009-01-07 17:30:30.000000000 +0200
+++ freeciv/common/base.c       2009-01-07 17:13:41.000000000 +0200
@@ -32,7 +32,7 @@
 
 static const char *base_type_flag_names[] = {
   "NoAggressive", "NoStackDeath",
-  "DiplomatDefense", "ParadropFrom"
+  "DiplomatDefense", "ParadropFrom", "NativeTile"
 };
 
 /* This must correspond to enum base_gui_type in base.h */
diff -Nurd -X.diff_ignore freeciv/common/base.h freeciv/common/base.h
--- freeciv/common/base.h       2009-01-07 17:30:30.000000000 +0200
+++ freeciv/common/base.h       2009-01-07 17:14:05.000000000 +0200
@@ -30,6 +30,7 @@
   BF_NO_STACK_DEATH,     /* Units inside will not die all at once */
   BF_DIPLOMAT_DEFENSE,   /* Base provides bonus for defending diplomat */
   BF_PARADROP_FROM,      /* Paratroopers can use base for paradrop */
+  BF_NATIVE_TILE,        /* Makes tile native terrain for units */
   BF_LAST                /* This has to be last */
 };
 
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c   2008-10-27 04:13:31.000000000 +0200
+++ freeciv/common/movement.c   2009-01-07 17:21:05.000000000 +0200
@@ -195,7 +195,7 @@
                     const struct tile *ptile)
 {
   return is_native_to_class(utype_class(punittype), tile_terrain(ptile),
-                            ptile->special);
+                            ptile->special, ptile->bases);
 }
 
 
@@ -206,9 +206,9 @@
 ****************************************************************************/
 bool is_native_terrain(const struct unit_type *punittype,
                        const struct terrain *pterrain,
-                       bv_special special)
+                       bv_special special, bv_bases bases)
 {
-  return is_native_to_class(utype_class(punittype), pterrain, special);
+  return is_native_to_class(utype_class(punittype), pterrain, special, bases);
 }
 
 /****************************************************************************
@@ -219,7 +219,8 @@
 bool is_native_tile_to_class(const struct unit_class *punitclass,
                              const struct tile *ptile)
 {
-  return is_native_to_class(punitclass, tile_terrain(ptile), 
tile_specials(ptile));
+  return is_native_to_class(punitclass, tile_terrain(ptile),
+                            tile_specials(ptile), tile_bases(ptile));
 }
 
 /****************************************************************************
@@ -228,13 +229,16 @@
 ****************************************************************************/
 bool is_native_to_class(const struct unit_class *punitclass,
                         const struct terrain *pterrain,
-                        bv_special special)
+                        bv_special special, bv_bases bases)
 {
   if (!pterrain) {
     /* Unknown is considered native terrain */
     return TRUE;
   }
 
+  if (BV_ISSET(pterrain->native_to, uclass_index(punitclass))) {
+    return TRUE;
+  }
   if (uclass_has_flag(punitclass, UCF_ROAD_NATIVE)
       && contains_special(special, S_ROAD)) {
     return TRUE;
@@ -244,7 +248,15 @@
     return TRUE;
   }
 
-  return BV_ISSET(pterrain->native_to, uclass_index(punitclass));
+  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)) {
+      return TRUE;
+    }
+  } base_type_iterate_end;
+
+  return FALSE;
 }
 
 /****************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/movement.h freeciv/common/movement.h
--- freeciv/common/movement.h   2008-10-27 04:13:31.000000000 +0200
+++ freeciv/common/movement.h   2009-01-07 17:17:39.000000000 +0200
@@ -35,10 +35,10 @@
                              const struct tile *ptile);
 bool is_native_terrain(const struct unit_type *punittype,
                        const struct terrain *pterrain,
-                       bv_special special);
+                       bv_special special, bv_bases bases);
 bool is_native_to_class(const struct unit_class *punitclass,
                         const struct terrain *pterrain,
-                        bv_special special);
+                        bv_special special, bv_bases bases);
 bool is_native_near_tile(const struct unit_type *utype, const struct tile 
*ptile);
 bool can_exist_at_tile(const struct unit_type *utype,
                        const struct tile *ptile);
diff -Nurd -X.diff_ignore freeciv/data/civ1/terrain.ruleset 
freeciv/data/civ1/terrain.ruleset
--- freeciv/data/civ1/terrain.ruleset   2009-01-07 17:30:30.000000000 +0200
+++ freeciv/data/civ1/terrain.ruleset   2009-01-07 17:24:40.000000000 +0200
@@ -671,6 +671,7 @@
 ;   - "ClaimTerritory"    = Base will claim land ownership
 ;   - "DiplomatDefense"   = Diplomats inside get bonus to diplomatic defense
 ;   - "ParadropFrom"      = Paradrop can be initiated from base
+;   - "NativeTile"        = Units consider tile native regardless of terrain
 
 [base_fortress]
 name          = _("Fortress")
diff -Nurd -X.diff_ignore freeciv/data/civ2/terrain.ruleset 
freeciv/data/civ2/terrain.ruleset
--- freeciv/data/civ2/terrain.ruleset   2009-01-07 17:30:30.000000000 +0200
+++ freeciv/data/civ2/terrain.ruleset   2009-01-07 17:24:34.000000000 +0200
@@ -785,6 +785,7 @@
 ;   - "NoStackDeath"      = Units inside do not die all at once when attacked
 ;   - "DiplomatDefense"   = Diplomats inside get bonus to diplomatic defense
 ;   - "ParadropFrom"      = Paradrop can be initiated from base
+;   - "NativeTile"        = Units consider tile native regardless of terrain
 
 [base_fortress]
 name          = _("Fortress")
diff -Nurd -X.diff_ignore freeciv/data/default/terrain.ruleset 
freeciv/data/default/terrain.ruleset
--- freeciv/data/default/terrain.ruleset        2009-01-07 17:30:30.000000000 
+0200
+++ freeciv/data/default/terrain.ruleset        2009-01-07 17:30:16.000000000 
+0200
@@ -905,6 +905,7 @@
 ;   - "NoStackDeath"      = Units inside do not die all at once when attacked
 ;   - "DiplomatDefense"   = Diplomats inside get bonus to diplomatic defense
 ;   - "ParadropFrom"      = Paradrop can be initiated from base
+;   - "NativeTile"        = Units consider tile native regardless of terrain
 
 [base_fortress]
 name          = _("Fortress")
diff -Nurd -X.diff_ignore freeciv/server/unittools.c freeciv/server/unittools.c
--- freeciv/server/unittools.c  2009-01-07 17:30:30.000000000 +0200
+++ freeciv/server/unittools.c  2009-01-07 17:25:10.000000000 +0200
@@ -2205,7 +2205,8 @@
   /* Safe terrain according to player map? */
   if (!is_native_terrain(unit_type(punit),
                          map_get_player_tile(ptile, pplayer)->terrain,
-                         map_get_player_tile(ptile, pplayer)->special)) {
+                         map_get_player_tile(ptile, pplayer)->special,
+                         map_get_player_tile(ptile, pplayer)->bases)) {
     notify_player(pplayer, ptile, E_BAD_COMMAND,
                      _("This unit cannot paradrop into %s."),
                      terrain_name_translation(
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to