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

 This introduces can_attack_from_non_native() and just one caller.
Many other places are required to check can_attack_from_non_native()
before it can be generalized for unit classes. Currently SEA_MOVING
and F_MARINES can attack from non-native tiles.


 - ML

diff -Nurd -X.diff_ignore freeciv/common/combat.c freeciv/common/combat.c
--- freeciv/common/combat.c	2007-03-06 03:34:32.000000000 +0200
+++ freeciv/common/combat.c	2007-03-09 16:44:04.000000000 +0200
@@ -85,7 +85,6 @@
 				  const struct unit *pdefender,
                                   const struct tile *dest_tile)
 {
-  struct terrain *fromtile = punit->tile->terrain;
   struct city *pcity = dest_tile->city;
 
   /* 1. Can we attack _anything_ ? */
@@ -101,9 +100,8 @@
   }
 
   /* 3. Can't attack with ground unit from ocean, except for marines */
-  if (is_ocean(fromtile)
-      && is_ground_unit(punit)
-      && !unit_flag(punit, F_MARINES)) {
+  if (!is_native_tile(unit_type(punit), punit->tile)
+      && !can_attack_from_non_native(unit_type(punit))) {
     return FALSE;
   }
 
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c	2007-03-08 03:23:04.000000000 +0200
+++ freeciv/common/movement.c	2007-03-09 16:41:24.000000000 +0200
@@ -93,6 +93,22 @@
 }
 
 /****************************************************************************
+ This unit can attack from non-native tiles (Marines can attack from
+ transport, ships from harbour cities)
+****************************************************************************/
+bool can_attack_from_non_native(struct unit_type *utype)
+{
+  /* It's clear that LAND_MOVING should not be able to attack from
+   * non-native (unless F_MARINES) and it's clear that SEA_MOVING
+   * should be able to attack from non-native. It's not clear what to do
+   * with HELI_MOVING and AIR_MOVING. At the moment we return FALSE for
+   * them. One can always give "Marines" flag for them. This should be
+   * generalized for unit_classes anyway. */
+  return (get_unit_class(utype)->move_type == SEA_MOVING
+          || unit_type_flag(utype, F_MARINES));
+}
+
+/****************************************************************************
   Return TRUE iff the unit is a sailing/naval/sea/water unit.
 ****************************************************************************/
 bool is_sailing_unit(const struct unit *punit)
diff -Nurd -X.diff_ignore freeciv/common/movement.h freeciv/common/movement.h
--- freeciv/common/movement.h	2007-03-08 03:23:04.000000000 +0200
+++ freeciv/common/movement.h	2007-03-09 16:36:03.000000000 +0200
@@ -21,6 +21,7 @@
 int unit_move_rate(const struct unit *punit);
 bool unit_can_defend_here(const struct unit *punit);
 bool can_attack_non_native(struct unit_type *utype);
+bool can_attack_from_non_native(struct unit_type *utype);
 
 bool is_sailing_unit(const struct unit *punit);
 bool is_air_unit(const struct unit *punit);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to