Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] Re: (PR#13337) [Patch] Read native terrains from ruleset
Home

[Freeciv-Dev] Re: (PR#13337) [Patch] Read native terrains from ruleset

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: marko.lindqvist@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#13337) [Patch] Read native terrains from ruleset
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Fri, 14 Jul 2006 03:01:06 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> Marko Lindqvist wrote:
>>   Read information about native terrains for unit classes from 
>> terrain.ruleset.

  - Updated against svn
  - Given Helicopters move ability
  - Changed terrain.ruleset comment a bit

  This time I mean to commit this.


  - ML

diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c   2006-07-14 01:42:13.156250000 +0300
+++ freeciv/client/packhand.c   2006-07-14 01:50:53.765625000 +0300
@@ -2367,6 +2367,7 @@
     return;
   }
 
+  pterrain->native_to = p->native_to;
   sz_strlcpy(pterrain->name_orig, p->name_orig);
   pterrain->name = Q_(pterrain->name_orig); /* See translate_data_names */
   sz_strlcpy(pterrain->graphic_str, p->graphic_str);
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c   2006-07-14 01:42:21.046875000 +0300
+++ freeciv/common/movement.c   2006-07-14 01:53:15.593750000 +0300
@@ -198,14 +198,11 @@
 bool is_native_to_class(const struct unit_class *punitclass,
                         const struct terrain *pterrain)
 {
-  switch (punitclass->move_type) {
-  case LAND_MOVING:
-    return !is_ocean(pterrain);
-  case SEA_MOVING:
-    return is_ocean(pterrain);
-  default:
+  if (!pterrain) {
+    /* Unknown is considered native terrain */
     return TRUE;
   }
+  return BV_ISSET(pterrain->native_to, punitclass->id);
 }
 
 /****************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def  2006-07-14 01:42:21.203125000 +0300
+++ freeciv/common/packets.def  2006-07-14 01:54:18.140625000 +0300
@@ -1220,6 +1220,7 @@
   TERRAIN id;
 
   BV_TERRAIN_FLAGS flags;
+  BV_UNIT_CLASSES native_to;
 
   STRING name_orig[MAX_LEN_NAME];
   STRING graphic_str[MAX_LEN_NAME];
diff -Nurd -X.diff_ignore freeciv/common/terrain.h freeciv/common/terrain.h
--- freeciv/common/terrain.h    2006-07-14 01:42:22.437500000 +0300
+++ freeciv/common/terrain.h    2006-07-14 01:50:53.953125000 +0300
@@ -17,6 +17,9 @@
 
 #include "fc_types.h"
 
+#include "unittype.h"
+
+
 enum special_river_move {
   RMV_NORMAL=0, RMV_FAST_STRICT=1, RMV_FAST_RELAXED=2, RMV_FAST_ALWAYS=3
 };
@@ -158,6 +161,8 @@
    * then 70% of 'mountainous' tiles will be given mountains. */
   int property[MG_LAST];
 
+  bv_unit_classes native_to;
+
   bv_terrain_flags flags;
 
   char *helptext;
diff -Nurd -X.diff_ignore freeciv/data/civ1/terrain.ruleset 
freeciv/data/civ1/terrain.ruleset
--- freeciv/data/civ1/terrain.ruleset   2006-07-14 01:42:33.093750000 +0300
+++ freeciv/data/civ1/terrain.ruleset   2006-07-14 02:12:36.734375000 +0300
@@ -131,6 +131,7 @@
 ;                        see warmer_wetter_result
 ; cooler_drier_result  = result of nuclear winter for dry terrains;
 ;                        see warmer_wetter_result
+; native_to            = List of unit classes that can move here
 ; flags                = General flags for this terrain:
 ;   - NoBarbs          = Barbarians will not be spawned here.
 ;   - NoPollution      = Pollution will not be put on this terrain type.
@@ -174,6 +175,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile"
 flags                = "NoBarbs"
 property_frozen      = 100
 helptext            = _("\
@@ -239,6 +241,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile"
 flags                = "Starter"
 property_temperate   = 50
 property_foliage     = 50
@@ -272,6 +275,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile"
 flags                = "Starter", "CanHaveRiver"
 property_temperate   = 50
 property_green       = 50
@@ -304,6 +308,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile"
 flags                = "Starter"
 property_mountainous = 30
 property_green       = 10
@@ -400,6 +405,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Sea", "Air", "Missile"
 flags                = "Oceanic", "NoPollution", "UnsafeCoast", "NoCities"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
@@ -433,6 +439,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile"
 flags                = "Starter"
 property_temperate   = 50
 property_green       = 50
@@ -498,6 +505,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "Arctic"
 cooler_drier_result  = "Arctic"
+native_to            = "Land", "Air", "Missile"
 flags                = "Starter", "NoBarbs"
 property_cold        = 50
 helptext            = _("\
diff -Nurd -X.diff_ignore freeciv/data/civ2/terrain.ruleset 
freeciv/data/civ2/terrain.ruleset
--- freeciv/data/civ2/terrain.ruleset   2006-07-14 01:42:34.593750000 +0300
+++ freeciv/data/civ2/terrain.ruleset   2006-07-14 02:11:43.968750000 +0300
@@ -140,6 +140,7 @@
 ;                        see warmer_wetter_result
 ; cooler_drier_result  = result of nuclear winter for dry terrains;
 ;                        see warmer_wetter_result
+; native_to            = List of unit classes that can move here
 ; flags                = General flags for this terrain:
 ;   - NoBarbs          = Barbarians will not be spawned here.
 ;   - NoPollution      = Pollution will not be put on this terrain type.
@@ -183,6 +184,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "NoBarbs", "CanHaveRiver"
 property_frozen      = 100
 helptext            = _("\
@@ -216,6 +218,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "CanHaveRiver"
 property_dry         = 100
 property_tropical    = 50
@@ -249,6 +252,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "CanHaveRiver"
 property_temperate   = 50
 property_foliage     = 50
@@ -282,6 +286,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "CanHaveRiver"
 property_temperate   = 50
 property_green       = 50
@@ -314,6 +319,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "CanHaveRiver"
 property_green       = 50
 property_mountainous = 30
@@ -347,6 +353,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "CanHaveRiver"
 property_tropical    = 50
 property_foliage     = 50
@@ -381,6 +388,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "CanHaveRiver"
 property_mountainous = 70
 helptext            = _("\
@@ -413,6 +421,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Sea", "Air", "Missile", "Helicopter"
 flags                = "Oceanic", "NoPollution", "UnsafeCoast", "NoCities"
 helptext            = _("\
 Oceans cover much of the world, and only sea units (Triremes and\
@@ -446,6 +455,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "CanHaveRiver"
 property_green       = 50
 property_temperate   = 50
@@ -479,6 +489,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "CanHaveRiver"
 property_wet         = 100
 property_foliage     = 10
@@ -512,6 +523,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "Glacier"
 cooler_drier_result  = "Glacier"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "NoBarbs", "CanHaveRiver"
 property_cold        = 50
 helptext            = _("\
diff -Nurd -X.diff_ignore freeciv/data/default/terrain.ruleset 
freeciv/data/default/terrain.ruleset
--- freeciv/data/default/terrain.ruleset        2006-07-14 01:42:37.187500000 
+0300
+++ freeciv/data/default/terrain.ruleset        2006-07-14 02:12:08.656250000 
+0300
@@ -143,6 +143,7 @@
 ;                        see warmer_wetter_result
 ; cooler_drier_result  = result of nuclear winter for dry terrains;
 ;                        see warmer_wetter_result
+; native_to            = List of unit classes that can move here
 ; flags                = General flags for this terrain:
 ;   - NoBarbs          = Barbarians will not be spawned here.
 ;   - NoPollution      = Pollution will not be put on this terrain type.
@@ -208,6 +209,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "NoBarbs", "NoCities", "CanHaveRiver"
 property_frozen      = 100
 helptext            = _("\
@@ -246,6 +248,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "CanHaveRiver"
 property_dry         = 100
 property_tropical    = 50
@@ -284,6 +287,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter","CanHaveRiver"
 property_temperate   = 50
 property_foliage     = 50
@@ -322,6 +326,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "CanHaveRiver"
 property_temperate   = 50
 property_green       = 50
@@ -359,6 +364,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "CanHaveRiver"
 property_green       = 50
 property_mountainous = 30
@@ -397,6 +403,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "CanHaveRiver"
 property_tropical    = 50
 property_foliage     = 50
@@ -436,6 +443,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "CanHaveRiver"
 property_mountainous = 70
 helptext            = _("\
@@ -473,6 +481,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "no"
 cooler_drier_result  = "no"
+native_to            = "Sea", "Air", "Missile", "Helicopter"
 flags                = "Oceanic", "NoPollution", "UnsafeCoast", "NoCities"
 property_ocean_depth = 10
 helptext            = _("\
@@ -512,6 +521,7 @@
 warmer_drier_result  = "Desert"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "CanHaveRiver"
 property_green       = 50
 property_temperate   = 50
@@ -550,6 +560,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "Desert"
 cooler_drier_result  = "Tundra"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "CanHaveRiver"
 property_wet         = 100
 property_foliage     = 10
@@ -588,6 +599,7 @@
 warmer_drier_result  = "no"
 cooler_wetter_result = "Glacier"
 cooler_drier_result  = "Glacier"
+native_to            = "Land", "Air", "Missile", "Helicopter"
 flags                = "Starter", "NoBarbs", "CanHaveRiver"
 property_cold        = 50
 helptext            = _("\
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c    2006-07-14 01:44:42.906250000 +0300
+++ freeciv/server/ruleset.c    2006-07-14 01:51:01.312500000 +0300
@@ -1684,6 +1684,28 @@
                                                         sec[i], mg_names[j]);
     }
 
+    slist = secfile_lookup_str_vec(file, &nval, "%s.native_to", sec[i]);
+    BV_CLR_ALL(pterrain->native_to);
+    for (j = 0; j < nval; j++) {
+      struct unit_class *class = unit_class_from_str(slist[j]);
+
+      if (!class) {
+        /* TRANS: message for an obscure ruleset error. */
+        freelog(LOG_FATAL, _("Terrain %s is native to unknown unit class %s"),
+                pterrain->name, slist[j]);
+        exit(EXIT_FAILURE);
+      } else if (is_ocean(pterrain) && class->move_type == LAND_MOVING) {
+        freelog(LOG_FATAL, _("Oceanic terrain %s is native to land units."),
+                pterrain->name);
+        exit(EXIT_FAILURE);
+      } else if (!is_ocean(pterrain) && class->move_type == SEA_MOVING) {
+        freelog(LOG_FATAL, _("Non oceanic terrain %s is native to sea units."),
+                pterrain->name);
+        exit(EXIT_FAILURE);
+      } else {
+        BV_SET(pterrain->native_to, class->id);
+      }
+    }
     pterrain->helptext = lookup_helptext(file, sec[i]);
   } terrain_type_iterate_end;
 
@@ -2858,6 +2880,7 @@
     const struct resource **r;
 
     packet.id = i;
+    packet.native_to = pterrain->native_to;
 
     sz_strlcpy(packet.name_orig, pterrain->name_orig);
     sz_strlcpy(packet.graphic_str, pterrain->graphic_str);
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in  2006-07-14 01:44:55.156250000 +0300
+++ freeciv/version.in  2006-07-14 01:51:53.453125000 +0300
@@ -24,4 +24,4 @@
 #   - Avoid adding a new manditory capbility to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2006.Jul.10")
+FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2006.Jul.14")

[Prev in Thread] Current Thread [Next in Thread]