Complete.Org: Mailing Lists: Archives: freeciv-ai: December 2002:
[freeciv-ai] Re: settlers.c question
Home

[freeciv-ai] Re: settlers.c question

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: "Per I. Mathisen" <per@xxxxxxxxxxx>
Cc: freeciv-ai@xxxxxxxxxxx
Subject: [freeciv-ai] Re: settlers.c question
From: "Ross W. Wetmore" <rwetmore@xxxxxxxxxxxx>
Date: Wed, 04 Dec 2002 19:03:56 -0500

This is what I worked out once upon a time for the corecleanups.

The comments may or may not be as insightful as I understood them 
when I first wrote them.

Certainly is_non_allied_unit_tile() doesn't capture all the subtleties
this code has built into it. I also think you have only begun to scratch
the surface and need to scratch a little harder to work things out in
their full glory.

Cheers,
RossW
=====

At 02:18 PM 02/12/04 +0000, Per I. Mathisen wrote:
>
>Please take a look at the attached patch and tell me why
>is_already_assigned() can't be removed in this way (you will also need to
>look at the code in question, merely looking at the patch is not enough).
>AFAICS this function is totally braindamaged, and the only useful thing it
>can possibly do can done better by is_non_allied_unit_tile().
>
>Possibly it was once intended to stop many settlers from trying to do the
>same thing, but it doesn't do that either...
>
>  - Per
>
>Attachment Converted: "c:\program files\eudora\attach\settlersc1.diff"


/**************************************************************************
 return 1 if there is already a unit on this square or one destined for it
 (via goto)
**************************************************************************/
static bool is_already_assigned(struct unit *myunit, struct player *pplayer,
  int x, int y)
{
  /* Settlers can help current operation, treat as unassigned */
  if (same_pos(myunit->x, myunit->y, x, y)) {
    if (unit_flag(myunit, F_SETTLERS))
      return FALSE;
  } else
  if (myunit->activity == ACTIVITY_GOTO
    && same_pos(myunit->goto_dest_x, myunit->goto_dest_y, x, y)) {
    bool is_military = is_military_unit(myunit);
    bool is_settlers = unit_flag(myunit, F_SETTLERS);
    unit_list_iterate(map_get_tile(x, y)->units, punit)
      /* non-military assignments are off if currently enemy occupied
       *   or being actively worked by an allied settler */
      if (!is_military)
        if (!pplayers_allied(unit_owner(punit), pplayer)
          || (is_settlers && unit_flag(punit, F_SETTLERS)) )
          return TRUE;
    unit_list_iterate_end;
    /* myunit may be assigned and possibly other active GOTOs,
     *   but count only what is already there */
    return FALSE;
  }
  return TEST_BIT(map_get_tile(x, y)->assigned, pplayer->player_no);
}
   




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