For part of the game I'm working on there is a hex map. I use 1 tile hex turfs and set the x offset to 8*(map.maxx-src.x) and shift every odd hex (x=1, x=3, x=5, etc) down by 16 pixels (y offset = -16).
The tile outlay is fine, as you can see here:

The problem, as shown above, is that ranges work a tad . . . oddly. The pic above shows a range of 3 generated with a modified circle generator; it treats anything with an x larger than the src.x as being 1 higher. I've also tried circles, straight range(), etc. After mapping out on a pad of graph paper the tiles that I would need to generate something like this (range of 2):

I realised that the pattern was irregular. More specifically, for a range of 2 it needed to be
#
#####
#####
#####
###
A range of 3 was similar:
#
#####
#######
#######
#######
#######
###
I haven't mapped out any other ranges, although I will if needed. What I'm trying to do is work out an algorithm that will take a range as a number and return a list of turfs in that range, as they appear on the hex map. I'm sure I can brute-force it but I'd rather finesse it, if possible. Any one out here dealt with something like this?
------------------------------------------------------
EDIT: Problem solved. I ended up going turf by turf in a line range tiles long from the centerpoint out in either direction horizontally, and adding a block of turfs 1 turf wide by (rng*2)+1-i, where i is the current iteration (1 to range), shifting up or down as needed.
However, the illustrations of what your pattern looks like to the code seem almost exactly like the patterns I was finding in an isometric range I was trying to create. I tried many things, but no amount of clever maths on my part yeilded a correct rendering. So, I decided to take a simpler approach.
I suggest you define your own coordinate system to fit your hex map, then write your own procs to use this new coordinate layout to calculate your range and distance. Once you have a coordinate system that works, the code practically writes itself. Plus, you're not trying to do tricky math, since your grid matches your code, everything is simple to calculate, and runs faster than a convoluted formula.
~X
I know this may not help directly, but here are my iso procs to handle stuff like this. Once you have a working coordinate system laid out, these will probably help in writing your own procs.