Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] (PR#18734) [Patch] Build units only near native terrain
Home

[Freeciv-Dev] (PR#18734) [Patch] Build units only near native terrain

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#18734) [Patch] Build units only near native terrain
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Wed, 19 Jul 2006 18:31:13 -0700
Reply-to: bugs@xxxxxxxxxxx

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


  SEA_MOVING units cannot be built inland. This patch generalizes that 
rule. Units cannot be built in cities surrounded by non-native tiles. To 
override this, unit class flag "BuildAnywhere" is introduced. Flag is 
needed for ocean cities to be able build land units.


  - ML


diff -Nurd -X.diff_ignore freeciv/common/city.c freeciv/common/city.c
--- freeciv/common/city.c       2006-07-20 03:29:40.652774800 +0300
+++ freeciv/common/city.c       2006-07-20 04:01:33.996524800 +0300
@@ -475,7 +475,8 @@
   }
 
   /* You can't build naval units inland. */
-  if (!is_ocean_near_tile(pcity->tile) && is_sailing_unittype(punittype)) {
+  if (!unit_class_flag(get_unit_class(punittype), UCF_BUILD_ANYWHERE)
+      && !is_native_near_tile(punittype, pcity->tile)) {
     return FALSE;
   }
   return TRUE;
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c   2006-07-20 03:29:43.199649800 +0300
+++ freeciv/common/movement.c   2006-07-20 04:06:57.340274800 +0300
@@ -245,6 +245,20 @@
 }
 
 /****************************************************************************
+  Is there native tile adjacent to given tile
+****************************************************************************/
+bool is_native_near_tile(const struct unit_type *utype, const struct tile 
*ptile)
+{
+  adjc_iterate(ptile, ptile2) {
+    if (is_native_tile(utype, ptile2)) {
+      return TRUE;
+    }
+  } adjc_iterate_end;
+
+  return FALSE;
+}
+
+/****************************************************************************
   Return TRUE iff the unit can "survive" at this location.  This means it can
   not only be physically present at the tile but will be able to survive
   indefinitely on its own (without a transporter).  Units that require fuel
diff -Nurd -X.diff_ignore freeciv/common/movement.h freeciv/common/movement.h
--- freeciv/common/movement.h   2006-07-20 03:29:43.293399800 +0300
+++ freeciv/common/movement.h   2006-07-20 04:05:59.652774800 +0300
@@ -41,6 +41,7 @@
 bool is_native_to_class(const struct unit_class *punitclass,
                         const struct terrain *pterrain,
                         bv_special special);
+bool is_native_near_tile(const struct unit_type *utype, const struct tile 
*ptile);
 bool can_unit_exist_at_tile(const struct unit *punit, const struct tile 
*ptile);
 bool can_unit_survive_at_tile(const struct unit *punit,
                              const struct tile *ptile);
diff -Nurd -X.diff_ignore freeciv/common/unittype.c freeciv/common/unittype.c
--- freeciv/common/unittype.c   2006-07-20 03:29:44.762149800 +0300
+++ freeciv/common/unittype.c   2006-07-20 04:01:07.277774800 +0300
@@ -41,7 +41,7 @@
 
 static const char *unit_class_flag_names[] = {
   "TerrainSpeed", "DamageSlows", "CanOccupy", "Missile",
-  "RoadNative"
+  "RoadNative", "BuildAnywhere"
 };
 static const char *flag_names[] = {
   "TradeRoute" ,"HelpWonder", "IgZOC", "NonMil", "IgTer", 
diff -Nurd -X.diff_ignore freeciv/common/unittype.h freeciv/common/unittype.h
--- freeciv/common/unittype.h   2006-07-20 03:29:44.793399800 +0300
+++ freeciv/common/unittype.h   2006-07-20 04:05:17.027774800 +0300
@@ -31,6 +31,7 @@
   UCF_CAN_OCCUPY,
   UCF_MISSILE,
   UCF_ROAD_NATIVE,
+  UCF_BUILD_ANYWHERE,
   UCF_LAST
 };
 
diff -Nurd -X.diff_ignore freeciv/data/civ1/units.ruleset 
freeciv/data/civ1/units.ruleset
--- freeciv/data/civ1/units.ruleset     2006-07-20 03:29:53.762149800 +0300
+++ freeciv/data/civ1/units.ruleset     2006-07-20 04:03:30.480899800 +0300
@@ -58,17 +58,18 @@
 ;
 ; ** Unit class Flags **
 ;
-; "TerrainSpeed" = Units use terrain spesific speed
-; "DamageSlows"  = Damages units are slowed down
-; "CanOccupy"    = Military units of this class can occupy enemy cities
-; "Missile"      = Unit is destroyed when it attacks
-; "RoadNative"   = Road tiles are always considered native terrain
+; "TerrainSpeed"  = Units use terrain spesific speed
+; "DamageSlows"   = Damages units are slowed down
+; "CanOccupy"     = Military units of this class can occupy enemy cities
+; "Missile"       = Unit is destroyed when it attacks
+; "RoadNative"    = Road tiles are always considered native terrain
+; "BuildAnywhere" = Unit can be built even in the middle of non-native terrain
 
 [unitclass_land]
 name          = _("Land")
 move_type     = "Land"
 hp_loss_pct   = 0
-flags         = "TerrainSpeed", "DamageSlows", "CanOccupy"
+flags         = "TerrainSpeed", "DamageSlows", "CanOccupy", "BuildAnywhere"
 
 [unitclass_sea]
 name          = _("Sea")
diff -Nurd -X.diff_ignore freeciv/data/civ2/units.ruleset 
freeciv/data/civ2/units.ruleset
--- freeciv/data/civ2/units.ruleset     2006-07-20 03:29:56.137149800 +0300
+++ freeciv/data/civ2/units.ruleset     2006-07-20 04:03:36.855899800 +0300
@@ -58,11 +58,12 @@
 ;
 ; ** Unit class Flags **
 ;
-; "TerrainSpeed" = Units use terrain spesific speed
-; "DamageSlows"  = Damages units are slowed down
-; "CanOccupy"    = Military units of this class can occupy enemy cities
-; "Missile"      = Unit is destroyed when it attacks
-; "RoadNative"   = Road tiles are always considered native terrain
+; "TerrainSpeed"  = Units use terrain spesific speed
+; "DamageSlows"   = Damages units are slowed down
+; "CanOccupy"     = Military units of this class can occupy enemy cities
+; "Missile"       = Unit is destroyed when it attacks
+; "RoadNative"    = Road tiles are always considered native terrain
+; "BuildAnywhere" = Unit can be built even in the middle of non-native terrain
 
 [unitclass_missile]
 name          = _("Missile")
@@ -74,7 +75,7 @@
 name          = _("Land")
 move_type     = "Land"
 hp_loss_pct   = 0
-flags         = "TerrainSpeed", "DamageSlows", "CanOccupy"
+flags         = "TerrainSpeed", "DamageSlows", "CanOccupy", "BuildAnywhere"
 
 [unitclass_sea]
 name          = _("Sea")
diff -Nurd -X.diff_ignore freeciv/data/default/units.ruleset 
freeciv/data/default/units.ruleset
--- freeciv/data/default/units.ruleset  2006-07-20 03:29:57.902774800 +0300
+++ freeciv/data/default/units.ruleset  2006-07-20 04:02:41.293399800 +0300
@@ -64,11 +64,12 @@
 ;
 ; ** Unit class Flags **
 ;
-; "TerrainSpeed" = Units use terrain spesific speed
-; "DamageSlows"  = Damages units are slowed down
-; "CanOccupy"    = Military units of this class can occupy enemy cities
-; "Missile"      = Unit is destroyed when it attacks
-; "RoadNative"   = Road tiles are always considered native terrain
+; "TerrainSpeed"  = Units use terrain spesific speed
+; "DamageSlows"   = Damages units are slowed down
+; "CanOccupy"     = Military units of this class can occupy enemy cities
+; "Missile"       = Unit is destroyed when it attacks
+; "RoadNative"    = Road tiles are always considered native terrain
+; "BuildAnywhere" = Unit can be built even in the middle of non-native terrain
 
 [unitclass_missile]
 name          = _("Missile")
@@ -80,7 +81,7 @@
 name          = _("Land")
 move_type     = "Land"
 hp_loss_pct   = 0
-flags         = "TerrainSpeed", "DamageSlows", "CanOccupy"
+flags         = "TerrainSpeed", "DamageSlows", "CanOccupy", "BuildAnywhere"
 
 [unitclass_sea]
 name          = _("Sea")

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#18734) [Patch] Build units only near native terrain, Marko Lindqvist <=