Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2003:
[Freeciv-Dev] (PR#6721) A Quincuncial topology
Home

[Freeciv-Dev] (PR#6721) A Quincuncial topology

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: mburda@xxxxxxxxx
Subject: [Freeciv-Dev] (PR#6721) A Quincuncial topology
From: "Guest" <rt-guest@xxxxxxxxxxx>
Date: Thu, 6 Nov 2003 12:47:47 -0800
Reply-to: rt@xxxxxxxxxxx

as info my 14.1 working code (seteable at compile time ! ) 
void map_distance_vector(int *dx, int *dy, int x0, int y0, int x1, int y1) 
{ 
    int Dx,Dy,D_,D__; 
    nearest_real_pos(&x0,&y0); 
    nearest_real_pos(&x1,&y1); 
    CHECK_MAP_POS(x0, y0); 
    CHECK_MAP_POS(x1, y1); 
    if(MB_FLAT) 
    { 
        *dx = x1 - x0; 
        *dy = y1 - y0; 
    } 
    else if( MB_CYLINDRICAL) 
    { 
        *dx = x1 - x0; 
        while (*dx >   map.xsize / 2) *dx -= map.xsize; 
        while (*dx <= -map.xsize / 2) *dx += map.xsize; 
        *dy = y1 - y0; 
    } else if(MB_TORUS) 
 { 
        *dx = x1 - x0; 
        while (*dx >   map.xsize / 2) *dx -= map.xsize; 
        while (*dx <= -map.xsize / 2) *dx += map.xsize; 
        *dy = y1 - y0; 
        while (*dy >   map.ysize / 2) *dy -= map.ysize; 
        while (*dy <= -map.ysize / 2) *dy += map.ysize; 
    } 
    else /* if (MB_QUINCUNCIAL) TODO QUINCUNCIAL_SQ */ 
    { 
        /* periodicity in x, as cylindical  */ 
        *dx = x1 - x0; 
        while (*dx >   map.xsize / 2) *dx -= map.xsize; 
        while (*dx <= -map.xsize / 2) *dx += map.xsize; 
        *dy = y1 - y0; 
        D_=MAX(abs(*dx),abs(*dy)); 
 
        // first central symetry 
        Dy=(-1-y1) - y0; 
        Dx=(map.xsize-x1-1) - x0; 
        while (Dx >   map.xsize / 2) Dx -= map.xsize; 
        while (Dx <= -map.xsize / 2) Dx += map.xsize; 
        D__=MAX(abs(Dx),abs(Dy)); 
        // get the best way  
if(D__<D_) 
        { 
            D_=D__; 
            *dx=Dx; 
            *dy=Dy; 
        } 
        // second central symetry 
        Dy=(2*map.ysize-y1-1) - y0; 
        Dx=(map.xsize-x1-1) - x0; 
        while (Dx >   map.xsize / 2) Dx -= map.xsize; 
        while (Dx <= -map.xsize / 2) Dx += map.xsize; 
        D__=MAX(abs(Dx),abs(Dy)); 
        // get the best way 
        if(D__<D_) 
        { 
            *dx=Dx; 
            *dy=Dy; 
        } 
 
    } 
} 
Marcelo 


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