For anyone interested this is how it was solved:

Code:

deltaX = abs(pCity.getX() - capital.getX())
if map.isWrapX():
deltaX = min(deltaX, map.getGridWidth() - deltaX)
deltaY = abs(pCity.getY() - capital.getY())
if map.isWrapX():
deltaY = min(deltaY, map.getGridWidth() - deltaY)
cityDistRaw = ( deltaX**2 + deltaY**2 )**0.5

For those who don't speak code (though this should be pretty easy to decifer anyway with math)

dX(i) = |P(x) - C(x)|

For a wrapped map

dX(f) = X(max) - dX(i)

if dX(f) < dX(i) then dX(f) = dX(i)

Repeat for Y component & then apply pythagoras to deltaX and deltaY.