Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#2329) Re: Re: (PR#2345) Portattacks 7.1
Home

[Freeciv-Dev] (PR#2329) Re: Re: (PR#2345) Portattacks 7.1

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#2329) Re: Re: (PR#2345) Portattacks 7.1
From: "Raahul Kumar via RT" <rt@xxxxxxxxxxxxxx>
Date: Thu, 14 Nov 2002 23:50:40 -0800
Reply-to: rt@xxxxxxxxxxxxxx


--- Jason Short via RT <rt@xxxxxxxxxxxxxx> wrote:
> Raahul Kumar via RT wrote:
> > The new updated portattacks, based on Per's portattacks 4. The AI is now
> almost ready to use subs. 
> > 
> > Same as the previous portattack patches. Subs can now attack ships in
> cities, although they still can't attack land units. Coastal defence stops
sub
> attacks on cities. 
> 
> I still have the question, that was asked before (by someone else) but I 
> didn't see an answer: what happens if a sub attacks a city with a weak 
> ship defender and a strong land defender?

The sub engages the ship defender. In no circumstances can the sub attack a
land unit! If this patch ever shows that kind of behaviour(Which it has not),
it would be a major bug. 

Relevant snippet from common/combat.c

struct unit *get_defender(struct unit *attacker, int x, int y)
 {
@@ -468,9 +474,24 @@
   int bestvalue = -1, count = 0, best_cost = 0, rating_of_best = 0;
   struct player *att_owner = unit_owner(attacker);
 
+  if(!is_military_unit(attacker)) {
+    /* has no valid targets */
+    return FALSE;
+  }
   unit_list_iterate(map_get_tile(x, y)->units, defender) {
     if (pplayers_allied(att_owner, unit_owner(defender)))
       continue;
+    /* F_NO_LAND_ATTACK units can only attack seaborne units, so let us
+    give them something to chew on. Go, subs, go! {:-) - Per */
+    if (unit_flag(attacker, F_NO_LAND_ATTACK) 
+        && !is_sailing_unit(defender)) {
+      continue;
+    }

All defending units except sea units are just ignored when selecting a defender
against a sub.

> For the patch itself...
> 
> -    if (!enemy) {
> +    if (!enemy && enemy == NULL)/* no valid target */ {
> 
> This is a duplicate check.  I think the !enemy check is preferred 
> (although I have no preference).

!enemy is not optimal, because NULL no longer means there is no enemy there.
NULL now means that the defender can't be attacked by the attacker ... i.e sub
can't attack land unit.

enemy is now more of a proper bool, with TRUE and FALSE being used.

> +  unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, defender) {
> +    if (unit_flag(punit, F_NO_LAND_ATTACK) && 
> (!is_sailing_unit(defender))) {
> +      continue;
> +    }
> +  }unit_list_iterate_end;
> 
> What is this supposed to do?  It looks like it does nothing.

Cities are only vulnerable to being attacked by subs if there is a ship unit
located in the city. So if a city has no ship units, we can ignore subs as a
threat. 

But, due to suffering a zombie attack, I have no brains left, and inserted that
continue for no apparent reason. I will fix it in portattacks 7.2.

The code that should have been there is this:

unit_list_iterate(map_get_tile(pcity->x, pcity->y)->units, defender) {
      if (unit_flag(punit, F_NO_LAND_ATTACK) && (is_sailing_unit(defender))) {
       sail_units++;
     }
  }unit_list_iterate_end;
  
  if (unit_flag(punit, F_NO_LAND_ATTACK) && sail_units == 0)
  return 0;
 
> jason
> 

Aloha,
RK.

As in certain cults it is possible to kill a process if you know its true name.
-Ken Thompson and Dennis M. Ritchie

__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com



[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#2329) Re: Re: (PR#2345) Portattacks 7.1, Raahul Kumar via RT <=