Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2006:
[Freeciv-Dev] Re: (PR#18481) can_attack_non_native()
Home

[Freeciv-Dev] Re: (PR#18481) can_attack_non_native()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#18481) can_attack_non_native()
From: "Marko Lindqvist" <cazfi74@xxxxxxxxx>
Date: Mon, 17 Jul 2006 14:51:08 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Marko Lindqvist wrote:
> Marko Lindqvist wrote:
>> bool can_attack_non_native(struct unit_type *utype)
>> and to add calls to it where necessary. In its first incarnation 
>> function should just compare move_type to SEA_MOVING.
> 
>   Oh, there currently is unit_type flag F_NO_LAND_ATTACK. It should be 
> respected of course.

  Untested patch. Introduces can_attack_non_native() and calls it from a 
couple of places. All there callers were already checking for 
F_NO_LAND_ATTACK, so autogames should be identical.


  - ML

diff -Nurd -X.diff_ignore freeciv/ai/aihunt.c freeciv/ai/aihunt.c
--- freeciv/ai/aihunt.c 2006-07-17 23:55:09.593750000 +0300
+++ freeciv/ai/aihunt.c 2006-07-18 00:09:48.859375000 +0300
@@ -93,7 +93,7 @@
     if (unit_type_flag(ut, F_PARTIAL_INVIS)) {
       desire += desire / 4;
     }
-    if (unit_type_flag(ut, F_NO_LAND_ATTACK)) {
+    if (!can_attack_non_native(ut)) {
       desire -= desire / 4; /* less flexibility */
     }
     /* Causes continual unhappiness */
diff -Nurd -X.diff_ignore freeciv/ai/aiunit.c freeciv/ai/aiunit.c
--- freeciv/ai/aiunit.c 2006-07-17 23:55:10.015625000 +0300
+++ freeciv/ai/aiunit.c 2006-07-18 00:31:29.109375000 +0300
@@ -1351,8 +1351,8 @@
                          && !(goto_is_sane(punit, acity->tile, TRUE) 
                               && WARMAP_COST(acity->tile) < maxd));
 
-      if (!is_ocean(tile_get_terrain(acity->tile))
-          && unit_flag(punit, F_NO_LAND_ATTACK)) {
+      if (!is_native_tile(unit_type(punit), acity->tile)
+          && !can_attack_non_native(unit_type(punit))) {
         /* Can't attack this city. It is on land. */
         continue;
       }
diff -Nurd -X.diff_ignore freeciv/common/aicore/pf_tools.c 
freeciv/common/aicore/pf_tools.c
--- freeciv/common/aicore/pf_tools.c    2006-07-17 23:55:59.531250000 +0300
+++ freeciv/common/aicore/pf_tools.c    2006-07-18 00:12:57.093750000 +0300
@@ -647,10 +647,10 @@
     }
     break;
   case SEA_MOVING:
-    if (unit_flag(punit, F_NO_LAND_ATTACK)) {
-      parameter->get_MC = seamove_no_bombard;
-    } else {
+    if (can_attack_non_native(unit_type(punit))) {
       parameter->get_MC = seamove;
+    } else {
+      parameter->get_MC = seamove_no_bombard;
     }
     break;
   case AIR_MOVING:
diff -Nurd -X.diff_ignore freeciv/common/combat.c freeciv/common/combat.c
--- freeciv/common/combat.c     2006-07-17 23:55:59.703125000 +0300
+++ freeciv/common/combat.c     2006-07-18 00:29:35.203125000 +0300
@@ -85,7 +85,6 @@
                                   const struct tile *dest_tile)
 {
   struct terrain *fromtile = punit->tile->terrain;
-  struct terrain *totile = dest_tile->terrain;
   struct city *pcity = dest_tile->city;
 
   /* 1. Can we attack _anything_ ? */
@@ -106,13 +105,10 @@
     return FALSE;
   }
 
-  /* 4. Ground units cannot attack water units */
-  if (is_ocean(totile) && is_ground_unit(punit)) {
-    return FALSE;
-  }
-
-  /* 5. Shore bombardement can be done by certain units only */
-  if (unit_flag(punit, F_NO_LAND_ATTACK) && !is_ocean(totile)) {
+  /* 4. Most units can not attack non-native terrain.
+   *    Most ships can attack land tiles (shore bombardment) */
+  if (!is_native_tile(unit_type(punit), dest_tile)
+      && !can_attack_non_native(unit_type(punit))) {
     return FALSE;
   }
 
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c   2006-07-17 23:56:00.484375000 +0300
+++ freeciv/common/movement.c   2006-07-18 00:08:05.437500000 +0300
@@ -89,6 +89,15 @@
   return can_unit_exist_at_tile(punit, punit->tile);
 }
 
+/****************************************************************************
+ This unit can attack non-native tiles (eg. Ships ability to
+ shore bombardment)
+****************************************************************************/
+bool can_attack_non_native(struct unit_type *utype)
+{
+  return (get_unit_class(utype)->move_type == SEA_MOVING
+          && !unit_type_flag(utype, F_NO_LAND_ATTACK));
+}
 
 /****************************************************************************
   Return TRUE iff the unit is a sailing/naval/sea/water unit.
diff -Nurd -X.diff_ignore freeciv/common/movement.h freeciv/common/movement.h
--- freeciv/common/movement.h   2006-07-17 23:56:00.515625000 +0300
+++ freeciv/common/movement.h   2006-07-18 00:27:32.984375000 +0300
@@ -20,6 +20,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 is_sailing_unit(const struct unit *punit);
 bool is_air_unit(const struct unit *punit);
diff -Nurd -X.diff_ignore freeciv/doc/README.rulesets 
freeciv/doc/README.rulesets
--- freeciv/doc/README.rulesets 2006-07-17 23:57:55.328125000 +0300
+++ freeciv/doc/README.rulesets 2006-07-18 00:35:17.140625000 +0300
@@ -112,6 +112,9 @@
       - "Barbarian"
       - "BarbarianTech"
 
+    - These flags and roles work only for move_type "Sea" units:
+      - "No_Land_Attack"
+
 ----------------------------------------------------------------------
 Implementation details:
 -----------------------

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