Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2002:
[Freeciv-Dev] Re: [Patch] Cleanup can_establish_trade_route
Home

[Freeciv-Dev] Re: [Patch] Cleanup can_establish_trade_route

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: rf13@xxxxxxxxxxxxxxxxxxxxxx, freeciv development list <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: [Patch] Cleanup can_establish_trade_route
From: Gregory Berkolaiko <gberkolaiko@xxxxxxxxxxx>
Date: Mon, 11 Feb 2002 14:41:01 +0000 (GMT)

 --- Raimar Falke <hawk@xxxxxxxxxxxxxxxxxxxxxxx> wrote: 
> Index: common/city.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
> retrieving revision 1.137
> diff -u -r1.137 city.c
> --- common/city.c     2002/02/11 13:55:49     1.137
> +++ common/city.c     2002/02/11 14:16:31
> @@ -827,22 +827,30 @@
> 
>
**************************************************************************/
>  int can_establish_trade_route(struct city *pc1, struct city *pc2)
>  {
> -  int i;
> -  int r=1;
> +  int i, used1 = 0, used2 = 0;
> +
>    if (!pc1 || !pc2 || pc1 == pc2
>        || (pc1->owner == pc2->owner
> -       && map_distance(pc1->x, pc1->y, pc2->x, pc2->y) <= 8))
> +       && map_distance(pc1->x, pc1->y, pc2->x, pc2->y) <= 8)) {
>      return FALSE;
> -  
> -  for(i=0;i<4;i++) {
> -    r*=pc1->trade[i];
> -    if (pc1->trade[i]==pc2->id) return 0;
>    }
> -  if (r) return 0;
> -  r = 1;
> -  for (i=0;i<4;i++) 
> -    r*=pc2->trade[i];
> -  return (!r);
> +
> +  for (i = 0; i < 4; i++) {
> +    if (pc1->trade[i] == pc2->id || pc2->trade[i] == pc1->id) {
> +      /* cities already have a traderoute */
> +      return FALSE;
> +    }
> +
> +    if (pc1->trade[i] != 0) {
> +      used1++;
> +    }
> +    if (pc2->trade[i] != 0) {
> +      used2++;
> +    }
> +  }
> +
> +  /* both cities need a free slot */
> +  return (used1 < 4 && used2 < 4);
>  }

The new version is way clearer and probably fater too.
One suggestion, however, which is probably quite useless, but I'm sure
Raimar will like it.  How about
#define MAX_NUM_TRADEROUTES 4
?

Best,
G.


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


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