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

2007/1/24 Marko Lindqvist:
>
>  Currently "AttackAny" unit can attack any "Unreachable" units.
> However, if reasons for unreachability differ between units, it makes
> no sense that same unit can work as killer for all of them.

This patch replaces "AttackAny" flag with list of (unreachable)
classes unit can attack against.


- ML

diff -Nurd -X.diff_ignore freeciv/client/helpdata.c freeciv/client/helpdata.c
--- freeciv/client/helpdata.c   2008-07-23 03:30:10.000000000 +0300
+++ freeciv/client/helpdata.c   2008-08-08 21:53:07.000000000 +0300
@@ -947,9 +947,6 @@
   if (utype_has_flag(utype, F_UNBRIBABLE)) {
     CATLSTR(buf, bufsz, _("* May not be bribed.\n"));
   }
-  if (utype_has_flag(utype, F_ATTACK_ANY)) {
-    CATLSTR(buf, bufsz, _("* Can attack otherwise unreachable enemy 
units.\n"));
-  }
   if (utype_has_flag(utype, F_PARTIAL_INVIS)) {
     CATLSTR(buf, bufsz,
             _("* Is invisible except when next to an enemy unit or city.\n"));
@@ -1070,6 +1067,13 @@
         break;
     };
   }
+  unit_class_iterate(pclass) {
+    if (uclass_has_flag(pclass, UCF_UNREACHABLE)
+        && BV_ISSET(utype->targets, uclass_index(pclass))) {
+      cat_snprintf(buf, bufsz, "* Can attack against %s units, which are 
usually not reachable.\n",
+                   uclass_name_translation(pclass));
+    }
+  } unit_class_iterate_end;
   if (utype->fuel > 0) {
     char allowed_units[10][64];
     int num_allowed_units = 0;
diff -Nurd -X.diff_ignore freeciv/client/packhand.c freeciv/client/packhand.c
--- freeciv/client/packhand.c   2008-08-08 18:44:49.000000000 +0300
+++ freeciv/client/packhand.c   2008-08-08 21:32:30.000000000 +0300
@@ -2569,6 +2569,7 @@
   u->paratroopers_mr_sub = p->paratroopers_mr_sub;
   u->bombard_rate       = p->bombard_rate;
   u->cargo              = p->cargo;
+  u->targets            = p->targets;
 
   for (i = 0; i < MAX_VET_LEVELS; i++) {
     sz_strlcpy(u->veteran[i].name, p->veteran_name[i]);
diff -Nurd -X.diff_ignore freeciv/common/combat.c freeciv/common/combat.c
--- freeciv/common/combat.c     2008-01-15 04:53:46.000000000 +0200
+++ freeciv/common/combat.c     2008-08-08 21:57:26.000000000 +0300
@@ -71,9 +71,9 @@
                                const struct unit *attacker)
 {
   struct unit_class *dclass = unit_class(defender);
+  struct unit_type *atype = unit_type(attacker);
 
-  return unit_has_type_flag(attacker, F_ATTACK_ANY)
-    || !uclass_has_flag(dclass, UCF_UNREACHABLE);
+  return BV_ISSET(atype->targets, uclass_index(dclass));
 }
 
 /***********************************************************************
diff -Nurd -X.diff_ignore freeciv/common/packets.def freeciv/common/packets.def
--- freeciv/common/packets.def  2008-08-01 23:07:37.000000000 +0300
+++ freeciv/common/packets.def  2008-08-08 21:31:33.000000000 +0300
@@ -1113,6 +1113,7 @@
   UINT8 bombard_rate;
 
   BV_UNIT_CLASSES cargo;
+  BV_UNIT_CLASSES targets;
 
   STRING helptext[MAX_LEN_PACKET];
 
diff -Nurd -X.diff_ignore freeciv/common/unittype.c freeciv/common/unittype.c
--- freeciv/common/unittype.c   2008-07-25 00:24:17.000000000 +0300
+++ freeciv/common/unittype.c   2008-08-08 21:24:27.000000000 +0300
@@ -47,7 +47,7 @@
 static const char *flag_names[] = {
   "TradeRoute", "HelpWonder", "IgZOC", "NonMil", "IgTer", 
   "OneAttack", "Pikemen", "Horse", "IgWall", "FieldUnit", 
-  "AEGIS", "AttackAny", "Marines", "Partial_Invis", "Settlers", "Diplomat",
+  "AEGIS", "Marines", "Partial_Invis", "Settlers", "Diplomat",
   "Trireme", "Nuclear", "Spy", "Transform", "Paratroopers",
   "Airbase", "Cities", "No_Land_Attack",
   "AddToCity", "Fanatic", "GameLoss", "Unique", "Unbribable", 
diff -Nurd -X.diff_ignore freeciv/common/unittype.h freeciv/common/unittype.h
--- freeciv/common/unittype.h   2008-07-25 00:24:17.000000000 +0300
+++ freeciv/common/unittype.h   2008-08-08 21:26:33.000000000 +0300
@@ -80,8 +80,7 @@
   F_HORSE,       
   F_IGWALL,      
   F_FIELDUNIT,   
-  F_AEGIS,       
-  F_ATTACK_ANY,       /* Can attack even unreachable units */
+  F_AEGIS,
   F_MARINES,     
   F_PARTIAL_INVIS,    /* Invisibile except when adjacent (Submarine) */   
   F_SETTLERS,         /* Does not include ability to found cities */
@@ -217,11 +216,12 @@
   struct unit_class *uclass;
 
   bv_unit_classes cargo;
-  
+
+  bv_unit_classes targets; /* Can attack these classes even if they are 
otherwise "Unreachable" */
+
   char *helptext;
 };
 
-
 #define CHECK_UNIT_TYPE(ut) (assert((ut) != NULL                           \
                             && (utype_by_number((ut)->item_number) == (ut))))
 
diff -Nurd -X.diff_ignore freeciv/data/civ1/units.ruleset 
freeciv/data/civ1/units.ruleset
--- freeciv/data/civ1/units.ruleset     2008-07-25 00:24:19.000000000 +0300
+++ freeciv/data/civ1/units.ruleset     2008-08-08 22:03:43.000000000 +0300
@@ -64,8 +64,8 @@
 ; "RoadNative"    = Road tiles are always considered native terrain
 ; "RiverNative"   = River tiles are always considered native terrain
 ; "BuildAnywhere" = Unit can be built even in the middle of non-native terrain
-; "Unreachable"   = Unit can be attacked only by units with "AttackAny" flag 
or on
-;                   city or airbase
+; "Unreachable"   = Unit can be attacked only by units explicitly listing this 
class as target
+;                   or on city or airbase
 ; "CollectRansom" = Unit can collect ransom when killing lone barbarian leader
 ; "ZOC"           = Unit is subject to ZOC rules. Unit type flag "IgZOC" can
 ;                   override this
@@ -650,8 +650,8 @@
 uk_happy      = 1
 uk_shield     = 1
 uk_food       = 0
-uk_gold       = 0
-flags         = "FieldUnit", "Fighter", "AirUnit", "AttackAny"
+uk_gold       = "Air", "Missile"
+flags         = "FieldUnit", "Fighter", "AirUnit"
 roles         = ""
 helptext      = _("\
 Fighters are your first airborne units. They can\
diff -Nurd -X.diff_ignore freeciv/data/civ2/units.ruleset 
freeciv/data/civ2/units.ruleset
--- freeciv/data/civ2/units.ruleset     2008-07-25 00:24:19.000000000 +0300
+++ freeciv/data/civ2/units.ruleset     2008-08-08 22:02:11.000000000 +0300
@@ -64,8 +64,8 @@
 ; "RoadNative"    = Road tiles are always considered native terrain
 ; "RiverNative"   = River tiles are always considered native terrain
 ; "BuildAnywhere" = Unit can be built even in the middle of non-native terrain
-; "Unreachable"   = Unit can be attacked only by units with "AttackAny" flag 
or on
-;                   city or airbase
+; "Unreachable"   = Unit can be attacked only by units explicitly listing this 
class as target
+;                   or on city or airbase
 ; "CollectRansom" = Unit can collect ransom when killing lone barbarian leader
 ; "ZOC"           = Unit is subject to ZOC rules. Unit type flag "IgZOC" can
 ;                   override this
@@ -1091,7 +1091,8 @@
 uk_shield     = 1
 uk_food       = 0
 uk_gold       = 0
-flags         = "Fighter", "AirUnit", "AttackAny"
+targets       = "Air", "Missile"
+flags         = "Fighter", "AirUnit"
 roles         = ""
 helptext      = _("\
 Fighters are your first airborne units. They can\
@@ -1190,7 +1191,8 @@
 uk_shield     = 1
 uk_food       = 0
 uk_gold       = 0
-flags         = "Fighter", "AirUnit", "AttackAny"
+targets       = "Air", "Missile"
+flags         = "Fighter", "AirUnit"
 roles         = ""
 helptext      = _("\
 An improved Fighter, with improved attack and a higher movement\
diff -Nurd -X.diff_ignore freeciv/data/default/units.ruleset 
freeciv/data/default/units.ruleset
--- freeciv/data/default/units.ruleset  2008-07-25 00:24:19.000000000 +0300
+++ freeciv/data/default/units.ruleset  2008-08-08 22:00:02.000000000 +0300
@@ -70,8 +70,8 @@
 ; "RoadNative"    = Road tiles are always considered native terrain
 ; "RiverNative"   = River tiles are always considered native terrain
 ; "BuildAnywhere" = Unit can be built even in the middle of non-native terrain
-; "Unreachable"   = Unit can be attacked only by units with "AttackAny" flag 
or on
-;                   city or airbase
+; "Unreachable"   = Unit can be attacked only by units explicitly listing this 
class as target
+;                   or on city or airbase
 ; "CollectRansom" = Unit can collect ransom when killing lone barbarian leader
 ; "ZOC"           = Unit is subject to ZOC rules. Unit type flag "IgZOC" can
 ;                   override this
@@ -179,7 +179,6 @@
 ; "IgWall"     = ignore effect of city walls
 ; "FieldUnit"  = cause unhappiness even when not being aggressive
 ; "AEGIS"      = fivefold increased defence against "AirUnit" attacks
-; "AttackAny"   = can attack unreachable units
 ; "Marines"    = (land only) can attack from transports
 ; "Partial_Invis" = visible only to adjancent units; does not hide transported
 ;                units other than missiles
@@ -1145,7 +1144,8 @@
 uk_shield     = 1
 uk_food       = 0
 uk_gold       = 0
-flags         = "AttackAny", "AirUnit", "Fighter"
+targets       = "Air", "Missile" 
+flags         = "AirUnit", "Fighter"
 roles         = ""
 helptext      = _("\
 Fighters are your first airborne units. They can\
@@ -1244,7 +1244,8 @@
 uk_shield     = 1
 uk_food       = 0
 uk_gold       = 0
-flags         = "Partial_Invis", "AttackAny", "AirUnit", "Fighter"
+targets       = "Air", "Missile"
+flags         = "Partial_Invis", "AirUnit", "Fighter"
 roles         = ""
 helptext      = _("\
 An improved Fighter, with improved attack and a higher movement\
diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c    2008-07-25 00:24:19.000000000 +0300
+++ freeciv/server/ruleset.c    2008-08-08 21:56:59.000000000 +0300
@@ -1246,6 +1246,29 @@
       BV_SET(u->cargo, uclass_index(class));
     }
 
+    slist = secfile_lookup_str_vec(file, &nval, "%s.targets", sec[i]);
+    BV_CLR_ALL(u->targets);
+    for (j = 0; j < nval; j++) {
+      struct unit_class *class = find_unit_class_by_rule_name(slist[j]);
+
+      if (!class) {
+        ruleset_error(LOG_FATAL,
+                      "\"%s\" unit_type \"%s\":"
+                      "has unknown unit class %s as target.",
+                      filename,
+                      utype_rule_name(u),
+                      slist[j]);
+      }
+
+      BV_SET(u->targets, uclass_index(class));
+    }
+    /* Set also all classes that are never unreachable as targets. */
+    unit_class_iterate(pclass) {
+      if (!uclass_has_flag(pclass, UCF_UNREACHABLE)) {
+        BV_SET(u->targets, uclass_index(pclass));
+      }
+    } unit_class_iterate_end;
+
     u->helptext = lookup_helptext(file, sec[i]);
 
     u->paratroopers_range = secfile_lookup_int_default(file,
diff -Nurd -X.diff_ignore freeciv/version.in freeciv/version.in
--- freeciv/version.in  2008-08-01 23:07:38.000000000 +0300
+++ freeciv/version.in  2008-08-08 21:24:39.000000000 +0300
@@ -23,5 +23,5 @@
 #   - Avoid adding a new mandatory capability to the development branch for
 #     as long as possible.  We want to maintain network compatibility with
 #     the stable branch for as long as possible.
-NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel.2008.Aug.01"
+NETWORK_CAPSTRING_MANDATORY="+Freeciv.Devel.2008.Aug.08"
 NETWORK_CAPSTRING_OPTIONAL=""
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to