Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2002:
[Freeciv-Dev] Re: goto_is_sane() is insane (PR#2131)
Home

[Freeciv-Dev] Re: goto_is_sane() is insane (PR#2131)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Sylvain Tricot <sylvaintricot@xxxxxxx>
Cc: Freeciv Development List <freeciv-dev@xxxxxxxxxxx>, Freeciv Bugs/Patch Tracking <bugs@xxxxxxxxxxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: goto_is_sane() is insane (PR#2131)
From: Gregory Berkolaiko <Gregory.Berkolaiko@xxxxxxxxxxxx>
Date: Tue, 8 Oct 2002 16:59:00 +0100 (BST)

I completely reworked goto_is_sane function.  The patch is attached.
I hope the function is more sane now.  Or at least commented.

I don't think reading diff is very pleasant in this case, so I just put 
the entire function below (.diff is still attached):


/**************************************************************************
Basic checks as to whether a GOTO is possible.
The target (x,y) should be on the same continent as punit is,
up to embarkation/disembarkation.
**************************************************************************/
bool goto_is_sane(struct unit *punit, int x, int y, bool omni)
{  
  struct player *pplayer = unit_owner(punit);
  
  if (same_pos(punit->x, punit->y, x, y)) {
    return TRUE;
  }
  
  if ( !(omni || map_get_known_and_seen(x, y, pplayer)) ) {
    /* The destination is in unknown -- assume sane */
    return TRUE;
  }
  
  switch (unit_type(punit)->move_type) {

  case LAND_MOVING:
    if (map_get_terrain(x, y) == T_OCEAN) {
      /* Going to a sea tile, the target should be next to our continent 
       * and with a boat */
      if (ground_unit_transporter_capacity(x, y, pplayer) > 0) {
        adjc_iterate(x, y, tmp_x, tmp_y) {
          if (map_get_continent(tmp_x, tmp_y) == 
              map_get_continent(punit->x, punit->y))
            /* The target is adjacent to our continent! */
            return TRUE;
        } adjc_iterate_end;
      }
    } else {
      /* Going to a land tile: better be our continent */
      if (map_get_continent(punit->x, punit->y) == map_get_continent(x, y)) {
        return TRUE;
      } else {
        /* Well, it's not our continent, but maybe we are on a boat
         * adjacent to the target continent? */
        adjc_iterate(punit->x, punit->y, tmp_x, tmp_y) {
          if (map_get_continent(tmp_x, tmp_y) == map_get_continent(x, y)) {
            return TRUE;
          }
        } adjc_iterate_end;
      }
    }
      
    return FALSE;

  case SEA_MOVING:
    if (map_get_terrain(x, y) == T_OCEAN 
        && is_terrain_near_tile(x, y, T_OCEAN)) {
      /* The target is sea or is accessible from sea 
       * (allow for bombardment and visiting ports) */
      return TRUE;
    }
    return FALSE;

  default:
    return TRUE;
  }

}

Attachment: goto_is_sane.diff
Description: Text document


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