public Point mousePosToTile(int mousex, int mousey)
    {
        final int w = map.getWidth();
        final int h = map.getHeight();

        int best = 99999999;
        int bestRow = 0;

        mousex -= tileLocator.getCursorX() / 2;
        mousey -= tileLocator.getRasterY() / 2;
        
        // Find best row by quick scan
        for(int y=0; y<h; y+=2) {
            for(int x=0; x<w; x+=5) {
                final int xpos = xoff + tileLocator.getTileScreenX(x,y);
                final int ypos = yoff + tileLocator.getTileScreenY(x,y);

                final int dist = (xpos-mousex)*(xpos-mousex) + (ypos-mousey) * (ypos-mousey);
                if(dist < best) {
                    best = dist;
                    bestRow = y;
                }
            }
        }
        
        best = 999999;

        // System.err.println("Best row: " + bestRow);

        for(int y=bestRow-5; y<bestRow+5; y++) {
            for(int x=0; x<w; x++) {
                final int xpos = xoff + tileLocator.getTileScreenX(x,y);
                final int ypos = yoff + tileLocator.getTileScreenY(x,y);

                final int dist = (xpos-mousex)*(xpos-mousex) + (ypos-mousey) * (ypos-mousey);
                if(dist < best) {
                    mouseToTile.x = x;
                    mouseToTile.y = y;
                    best = dist;
                    
                    if(best < 16) {
                        return mouseToTile;
                    }
                }
            }
        }

        return mouseToTile;
    }