anchor.diff:    for I := Max(TreeLoc.Y - HUT_RAD, 1) to Min(TreeLoc.Y + HUT_RAD, fTerrain.MapY - 1) do
     for K := Max(TreeLoc.X - HUT_RAD, 1) to Min(TreeLoc.X + HUT_RAD, fTerrain.MapX - 1) do
       if (fAIFields.Influences.AvoidBuilding[I,K] = 0)
  -    and (fAIFields.Influences.GetBestOwner(K, I) = fOwner)
       and fPlayers[fOwner].CanAddHousePlanAI(K, I, aHouse, False) then
       begin
         Bid := KMLength(KMPoint(K,I), TargetLoc) + KaMRandom * 5;
  -      if Bid < BestBid then
  +      TerOwner := fAIFields.Influences.GetBestOwner(K,I);
  +      if (Bid < BestBid) and ((TerOwner = fOwner) or (TerOwner = PLAYER_NONE)) then
         begin
           aLoc := KMPoint(K,I);
           BestBid := Bid;
  
positive.code: 
      function NextToOre(aHouse: THouseType; aOreType: TResourceType; out aLoc: TKMPoint): Boolean;
      function NextToHouse(aTarget: array of THouseType; aHouse: THouseType; out aLoc: TKMPoint): Boolean;
      function NextToStone(aHouse: THouseType; out aLoc: TKMPoint): Boolean;
      function NextToTrees(aTarget: array of THouseType; aHouse: THouseType; out aLoc: TKMPoint): Boolean;
      function NextToGrass(aTarget, aHouse: THouseType; out aLoc: TKMPoint): Boolean;
    public
  
negative.code: function TKMTerrainFinderCity.CanUse(const X, Y: Word): Boolean;
  begin
    case FindType of
      fnStone:  Result := (fTerrain.TileIsStone(X, Max(Y-1, 1)) > 1);
      fnCoal:   Result := (fTerrain.TileIsCoal(X, Y) > 1)
                           and fPlayers[fOwner].CanAddHousePlanAI(X, Y, ht_CoalMine, True);
      fnIron:   Result := (fTerrain.TileIsIron(X, Max(Y-1, 1)) > 0)
                           and fPlayers[fOwner].CanAddHousePlanAI(X, Y, ht_IronMine, True);
      fnGold:   Result := (fTerrain.TileIsGold(X, Max(Y-1, 1)) > 0)
                           and fPlayers[fOwner].CanAddHousePlanAI(X, Y, ht_GoldMine, True);
      else      Result := False;
    end;
  end;
  
  
  function TKMTerrainFinderCity.CanWalkHere(const X,Y: Word): Boolean;
  var
    TerOwner: TPlayerIndex;
  begin
    //Don't build on allies and/or enemies territory
    TerOwner := fAIFields.Influences.GetBestOwner(X,Y);
    Result := (TerOwner = fOwner) or (TerOwner = PLAYER_NONE);
  end;
  
  
  