[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]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13337 >
Marko Lindqvist wrote:
> <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 for testing other patches. No plans to commit this yet.
>
Less buggy version.
- ML
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c 2006-07-08 19:15:21.515625000 +0300
+++ freeciv/client/packhand.c 2006-07-08 20:25:50.093750000 +0300
@@ -2366,6 +2366,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-08 19:15:30.984375000 +0300
+++ freeciv/common/movement.c 2006-07-08 20:26:40.171875000 +0300
@@ -182,19 +182,18 @@
/****************************************************************************
This terrain is native to unit. Units that require fuel dont survive
- even on native terrain. All terrains are native to air units.
+ even on native terrain.
****************************************************************************/
bool is_native_terrain(const struct unit_type *punittype,
const struct terrain *pterrain)
{
- switch (get_unit_move_type(punittype)) {
- case LAND_MOVING:
- return !is_ocean(pterrain);
- case SEA_MOVING:
- return is_ocean(pterrain);
- default:
+ Unit_Class_id class = get_unit_class(punittype)->id;
+
+ if (!pterrain) {
+ /* Unknown is considered native terrain */
return TRUE;
}
+ return BV_ISSET(pterrain->native_to, class);
}
/****************************************************************************
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def 2006-07-08 19:15:31.125000000 +0300
+++ freeciv/common/packets.def 2006-07-08 20:24:41.765625000 +0300
@@ -199,6 +199,7 @@
type BV_FLAGS = bitvector(bv_flags)
type BV_ROLES = bitvector(bv_roles)
type BV_TERRAIN_FLAGS = bitvector(bv_terrain_flags)
+type BV_UNIT_CLASSES = bitvector(bv_unit_classes)
type BV_CITY_OPTIONS = bitvector(bv_city_options)
type BV_SPECIAL = bitvector(bv_special)
type BV_PLAYER = bitvector(bv_player)
@@ -1219,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-08 19:15:32.562500000 +0300
+++ freeciv/common/terrain.h 2006-07-08 20:24:41.781250000 +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/common/unittype.h freeciv/common/unittype.h
--- freeciv/common/unittype.h 2006-07-08 19:15:32.828125000 +0300
+++ freeciv/common/unittype.h 2006-07-08 20:24:41.796875000 +0300
@@ -31,6 +31,7 @@
UCF_LAST
};
+BV_DEFINE(bv_unit_classes, UCL_LAST);
BV_DEFINE(bv_unit_class_flags, UCF_LAST);
struct unit_class {
diff -Nurd -X.diff_ignore freeciv/data/civ1/terrain.ruleset
freeciv/data/civ1/terrain.ruleset
--- freeciv/data/civ1/terrain.ruleset 2006-07-08 19:15:44.515625000 +0300
+++ freeciv/data/civ1/terrain.ruleset 2006-07-08 20:24:41.812500000 +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 this is native terrain to
; 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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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-08 19:15:46.687500000 +0300
+++ freeciv/data/civ2/terrain.ruleset 2006-07-08 20:24:41.828125000 +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 this is native terrain to
; 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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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-08 19:15:48.500000000
+0300
+++ freeciv/data/default/terrain.ruleset 2006-07-08 20:24:41.843750000
+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 this is native terrain to
; 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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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", "Nuclear"
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-08 19:19:11.031250000 +0300
+++ freeciv/server/ruleset.c 2006-07-08 20:25:21.125000000 +0300
@@ -1683,6 +1683,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;
@@ -2857,6 +2879,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-08 19:19:26.828125000 +0300
+++ freeciv/version.in 2006-07-08 20:24:41.875000000 +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.08")
+FREECIV_NETWORK_CAPSTRING("+Freeciv.Devel.2006.Jul.08-2")
|
|