Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2002:
[Freeciv-Dev] Re: attacking transport (PR#2025)
Home

[Freeciv-Dev] Re: attacking transport (PR#2025)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <per@xxxxxxxxxxx>
Cc: Freeciv Development List <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: attacking transport (PR#2025)
From: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Wed, 25 Sep 2002 10:59:10 +0100 (BST)

On Sun, 22 Sep 2002, Per I. Mathisen wrote:

> On Sun, 22 Sep 2002, Gregory Berkolaiko wrote:
> > Attached is a patch which prohibits units with attack strength of 0 to
> > attack anything.There will be generic message
> >     Game: You can't attack there.
> > printed if a player attempts such an attack.
> 
> Index: server/unittools.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
> retrieving revision 1.181
> diff -u -r1.181 unittools.c
> --- server/unittools.c        2002/08/31 02:24:34     1.181
> +++ server/unittools.c        2002/09/22 17:50:37
> @@ -159,6 +159,12 @@
>  bool can_unit_attack_tile(struct unit *punit, int dest_x, int dest_y)
>  {
>    struct unit *pdefender;
> +
> +  if (unit_type(punit)->attack_strength == 0) {
> +    /* This unit can't attack anything */
> +    return FALSE;
> +  }
> +
>    pdefender=get_defender(punit, dest_x, dest_y);
>    if (!pdefender) {
>      struct city *pcity = map_get_city(dest_x, dest_y);
> 
> This should be in can_unit_attack_unit_at_tile(), not here.

Well, I actually think it belongs to "can_unit_attack", since the 
condition depends neither on the tile nore on the defender of the tile.

But I agree to the changes you've committed.

You should have gone one step further though: can_unit_attack_tile is 
called only twice and in both cases there is a defender readily computed.  
Thus the right function to be called is actually 
can_unit_attack_unit_at_tile in both cases, saves you calling 
get_defender.  And get_defender is not one of the fastest functions.

I'll make the patch when I get back (in the evening).

G.




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