[Freeciv-Dev] Re: (PR#18734) [Patch] Build units only near native terrai
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] Re: (PR#18734) [Patch] Build units only near native terrain |
From: |
"Marko Lindqvist" <cazfi74@xxxxxxxxx> |
Date: |
Fri, 21 Jul 2006 09:29:05 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=18734 >
Marko Lindqvist wrote:
>
> Marko Lindqvist wrote:
>> 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.
>
> - Fixed can_eventually_build_unit()
- Allow building if city center tile is native terrain
- ML
diff -Nurd -X.diff_ignore freeciv/common/city.c freeciv/common/city.c
--- freeciv/common/city.c 2006-07-21 16:11:44.187500000 +0300
+++ freeciv/common/city.c 2006-07-21 19:06:49.515625000 +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;
@@ -513,7 +514,8 @@
/* Some units can be built only in certain cities -- for instance,
ships may be built only in cities adjacent to ocean. */
- 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;
}
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c 2006-07-21 16:10:44.859375000 +0300
+++ freeciv/common/movement.c 2006-07-21 19:07:23.406250000 +0300
@@ -245,6 +245,24 @@
}
/****************************************************************************
+ Is there native tile adjacent to given tile
+****************************************************************************/
+bool is_native_near_tile(const struct unit_type *utype, const struct tile
*ptile)
+{
+ if (is_native_tile(utype, ptile)) {
+ return TRUE;
+ }
+
+ 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-21 16:10:44.953125000 +0300
+++ freeciv/common/movement.h 2006-07-21 19:06:49.546875000 +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-21 16:10:46.703125000 +0300
+++ freeciv/common/unittype.c 2006-07-21 19:06:49.578125000 +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-21 16:10:46.734375000 +0300
+++ freeciv/common/unittype.h 2006-07-21 19:06:49.593750000 +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-21 16:10:58.250000000 +0300
+++ freeciv/data/civ1/units.ruleset 2006-07-21 19:06:49.609375000 +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-21 16:11:00.187500000 +0300
+++ freeciv/data/civ2/units.ruleset 2006-07-21 19:06:49.640625000 +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-21 16:11:02.031250000 +0300
+++ freeciv/data/default/units.ruleset 2006-07-21 19:06:49.656250000 +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")
|
|