#textdomain wesnoth
# This file handles transitions involving bridges

# macros to make things shorter
#define IMAGE_L_N LAYER NAME
    [image]
        layer={LAYER}
        name={NAME}
    [/image]
#enddef

# this macro adds dock-style ends to bridges ending in water
#define DOCK_END IMAGESTEM WATER_TERRAIN_NAME BRIDGETYPE_NAME BEACHSIDE_AFFIX X Y
    [terrain_graphics]
        [tile]
            x=1
            y=1
            type={BRIDGETYPE_NAME}
        [/tile]
        [tile]
            x={X}
            y={Y}
            type={WATER_TERRAIN_NAME}
            no_flag=angleaway_{BEACHSIDE_AFFIX}
            {IMAGE_L_N -80 {IMAGESTEM}-{BEACHSIDE_AFFIX}-end}
        [/tile]
    [/terrain_graphics]
#enddef

# this macro adds ramp-style ends to bridges ending on other bridges
#define RAMP_BRIDGE IMAGESTEM BRIDGETYPE_NAME BRIDGES_VALUE R0 R1 R2 R3 R4 R5 S0 S1 S2 S3 S4 S5
    [terrain_graphics]
        map="
,  {S0}
{S5},   {S1}
,  1
{S4},   {S2}
,  {S3}"
        [tile]
            pos=1
            type={BRIDGETYPE_NAME}
            no_flag=angle_{R1},angle_{R5}
        [/tile]
        [tile]
            pos=2
            type={BRIDGES_VALUE}
            no_flag=angle_{R3}
            {IMAGE_L_N -80 {IMAGESTEM}-{R3}}
        [/tile]
    [/terrain_graphics]
#enddef

# this macro adds ramp-style ends to bridges ending on land
#define RAMP_END IMAGESTEM WATER_TERRAIN_NAME NOTERM_AFFIX BRIDGETYPE_NAME R0 R1 R2 R3 R4 R5 X Y
    [terrain_graphics]
        [tile]
            x=1
            y=1
            type={BRIDGETYPE_NAME}
            no_flag=angle_{R1},angle_{R5}
        [/tile]
        [tile]
            x={X}
            y={Y}
            type=!,{BRIDGETYPE_NAME},{WATER_TERRAIN_NAME},{NOTERM_AFFIX}
            no_flag=angle_{R3}
            {IMAGE_L_N -80 {IMAGESTEM}-{R3}}
        [/tile]
    [/terrain_graphics]
#enddef

# this macro produces Y intersections
#define BRIDGE_Y BRIDGETYPE1_NAME BRIDGETYPE2_NAME BRIDGETYPE3_NAME Y_IMAGE R0 R1 R2 R3 R4 R5 S0 S1 S2 S3 S4 S5
    [terrain_graphics]
        map="
,  {S1}
{S0},   {S2}
,  1
{S5},   {S3}
,  {S4}"
        [tile]
            pos=1
            type={BRIDGETYPE1_NAME}
            no_flag=overlay,angle_{R0},angle_{R2},angle_{R4}
            set_flag=overlay,angle_{R1},angle_{R5},angle_{R3}
            {IMAGE_L_N -80 {Y_IMAGE}}
        [/tile]
        [tile]
            pos=2
            no_flag=angle_{R3},angle_{R1}
            set_flag=angle_{R2}
            type={BRIDGETYPE2_NAME}
        [/tile]
        [tile]
            pos=3
            no_flag=angle_{R3},angle_{R5}
            set_flag=angle_{R4}
            type={BRIDGETYPE3_NAME}
        [/tile]
        [tile]
            pos=4
            type=!,{BRIDGETYPE1_NAME}
            set_flag=angleaway_{R3}
        [/tile]
    [/terrain_graphics]
#enddef

# this macro keeps colinear bridges connected
#define BRIDGECONNECT BRIDGETYPE_NAME R0 R1 R2 R3 R4 R5 X Y
    [terrain_graphics]
        [tile]
            x=1
            y=1
            type={BRIDGETYPE_NAME}
            no_flag=angle_{R1},angle_{R5}
            set_flag=angle_{R0}
        [/tile]
        [tile]
            x={X}
            y={Y}
            type={BRIDGETYPE_NAME}
            no_flag=angle_{R2},angle_{R4}
            set_flag=angle_{R3}
        [/tile]
    [/terrain_graphics]
#enddef

# this macro handles the normal corners
#define CORNER ANGLE_IMAGE BRIDGETYPE1_NAME BRIDGETYPE2_NAME A1 A2 A3 A4 A5 A6 S0 S1 S2 S3 S4 S5
    [terrain_graphics]
        map="
,  {S1}
{S0},   {S2}
,  1
{S5},   {S3}
,  {S4}"
        [tile]
            pos=1
            type={BRIDGETYPE1_NAME}
            no_flag=overlay,angle_{A3},angle_{A4},angle_{A5},angle_{A6}
            set_flag=overlay,angle_{A1},angle_{A2}
            {IMAGE_L_N -80 {ANGLE_IMAGE}}
        [/tile]
        [tile]
            pos=2
            type={BRIDGETYPE2_NAME}
            no_flag=angle_{A1},angle_{A6}
            set_flag=angle_{A3}
        [/tile]
        [tile]
            pos=3
            set_flag=angleaway_{A1}
        [/tile]
    [/terrain_graphics]
#enddef

# the main macro, called from terrain-graphics.cfg
#define BRIDGE SE_NW_VALUE N_S_VALUE NE_SW_VALUE WATER_TERRAIN_NAME NOTERM_AFFIX IMAGESTEM

    # find Y intersections
    {BRIDGE_Y {N_S_VALUE} {SE_NW_VALUE} {NE_SW_VALUE} {IMAGESTEM}-joint-ne-s-nw n ne se s sw nw 2 4 3 . . .}
    {BRIDGE_Y {NE_SW_VALUE} {N_S_VALUE} {SE_NW_VALUE} {IMAGESTEM}-joint-n-se-sw ne se s sw nw n . 2 4 3 . .}
    {BRIDGE_Y {SE_NW_VALUE} {NE_SW_VALUE} {N_S_VALUE} {IMAGESTEM}-joint-ne-s-nw se s sw nw n ne . . 2 4 3 .}
    {BRIDGE_Y {N_S_VALUE} {SE_NW_VALUE} {NE_SW_VALUE} {IMAGESTEM}-joint-n-se-sw s sw nw n ne se . . . 2 4 3}
    {BRIDGE_Y {NE_SW_VALUE} {N_S_VALUE} {SE_NW_VALUE} {IMAGESTEM}-joint-ne-s-nw sw nw n ne se s 3 . . . 2 4}
    {BRIDGE_Y {SE_NW_VALUE} {NE_SW_VALUE} {N_S_VALUE} {IMAGESTEM}-joint-n-se-sw nw n ne se s sw 4 3 . . . 2}

    # make sure that colinear adjacent bridges stay connected
    {BRIDGECONNECT {N_S_VALUE}   n ne se s sw nw 1 0}
    {BRIDGECONNECT {NE_SW_VALUE} ne se s sw nw n 2 1}
    {BRIDGECONNECT {SE_NW_VALUE} se s sw nw n ne 2 2}

    # normal corners
    {CORNER {IMAGESTEM}-joint-s-nw  {N_S_VALUE} {SE_NW_VALUE}   s  nw se n  sw ne 2 3 . . . .}
    {CORNER {IMAGESTEM}-joint-ne-s  {N_S_VALUE} {NE_SW_VALUE}   s  ne sw n  se nw . 3 2 . . .}
    {CORNER {IMAGESTEM}-joint-n-sw  {NE_SW_VALUE} {N_S_VALUE}   sw n  s  ne nw se . 2 3 . . .}
    {CORNER {IMAGESTEM}-joint-se-sw {NE_SW_VALUE} {SE_NW_VALUE} sw se nw ne s  n  . . 3 2 . .}
    {CORNER {IMAGESTEM}-joint-ne-nw {SE_NW_VALUE} {NE_SW_VALUE} nw ne sw se n  s  . . 2 3 . .}
    {CORNER {IMAGESTEM}-joint-s-nw  {SE_NW_VALUE} {N_S_VALUE}   nw s  n  se sw ne . . . 3 2 .}
    {CORNER {IMAGESTEM}-joint-n-se  {N_S_VALUE} {SE_NW_VALUE}   n  se nw s  ne sw . . . 2 3 .}
    {CORNER {IMAGESTEM}-joint-n-sw  {N_S_VALUE} {NE_SW_VALUE}   n  sw ne s  nw se . . . . 3 2}
    {CORNER {IMAGESTEM}-joint-ne-s  {NE_SW_VALUE} {N_S_VALUE}   ne s  n  sw se nw . . . . 2 3}
    {CORNER {IMAGESTEM}-joint-ne-nw {NE_SW_VALUE} {SE_NW_VALUE} ne nw se sw n  s  2 . . . . 3}
    {CORNER {IMAGESTEM}-joint-se-sw {SE_NW_VALUE} {NE_SW_VALUE} se sw ne nw s  n  3 . . . . 2}
    {CORNER {IMAGESTEM}-joint-n-se  {SE_NW_VALUE} {N_S_VALUE}   se n  s  nw ne sw 3 2 . . . .}

    # these 3 macros define the default straight bridges
    {TERRAIN_BASE_OV {N_S_VALUE}  {IMAGESTEM}-n-s}
    {TERRAIN_BASE_OV {NE_SW_VALUE}  {IMAGESTEM}-ne-sw}
    {TERRAIN_BASE_OV {SE_NW_VALUE}  {IMAGESTEM}-se-nw}

    # add ramps where straight bridges intersect Ys
    {RAMP_BRIDGE {IMAGESTEM} {N_S_VALUE}   ({N_S_VALUE}, {NE_SW_VALUE}, {SE_NW_VALUE}) n ne se s sw nw 2 . . . . .}
    {RAMP_BRIDGE {IMAGESTEM} {NE_SW_VALUE} ({N_S_VALUE}, {NE_SW_VALUE}, {SE_NW_VALUE}) ne se s sw nw n . 2 . . . .}
    {RAMP_BRIDGE {IMAGESTEM} {SE_NW_VALUE} ({N_S_VALUE}, {NE_SW_VALUE}, {SE_NW_VALUE}) se s sw nw n ne . . 2 . . .}
    {RAMP_BRIDGE {IMAGESTEM} {N_S_VALUE}   ({N_S_VALUE}, {NE_SW_VALUE}, {SE_NW_VALUE}) s sw nw n ne se . . . 2 . .}
    {RAMP_BRIDGE {IMAGESTEM} {NE_SW_VALUE} ({N_S_VALUE}, {NE_SW_VALUE}, {SE_NW_VALUE}) sw nw n ne se s . . . . 2 .}
    {RAMP_BRIDGE {IMAGESTEM} {SE_NW_VALUE} ({N_S_VALUE}, {NE_SW_VALUE}, {SE_NW_VALUE}) nw n ne se s sw . . . . . 2}

    # add ramps where straight bridges end on land
    {RAMP_END {IMAGESTEM} {WATER_TERRAIN_NAME} {NOTERM_AFFIX} {N_S_VALUE}   n ne se s sw nw 1 0}
    {RAMP_END {IMAGESTEM} {WATER_TERRAIN_NAME} {NOTERM_AFFIX} {NE_SW_VALUE} ne se s sw nw n 2 1}
    {RAMP_END {IMAGESTEM} {WATER_TERRAIN_NAME} {NOTERM_AFFIX} {SE_NW_VALUE} se s sw nw n ne 2 2}
    {RAMP_END {IMAGESTEM} {WATER_TERRAIN_NAME} {NOTERM_AFFIX} {N_S_VALUE}   s sw nw n ne se 1 2}
    {RAMP_END {IMAGESTEM} {WATER_TERRAIN_NAME} {NOTERM_AFFIX} {NE_SW_VALUE} sw nw n ne se s 0 2}
    {RAMP_END {IMAGESTEM} {WATER_TERRAIN_NAME} {NOTERM_AFFIX} {SE_NW_VALUE} nw n ne se s sw 0 1}

    # add dock-style ends to bridges ending in water
    {DOCK_END {IMAGESTEM} {WATER_TERRAIN_NAME} {N_S_VALUE}   s  1 0}
    {DOCK_END {IMAGESTEM} {WATER_TERRAIN_NAME} {NE_SW_VALUE} sw 2 1}
    {DOCK_END {IMAGESTEM} {WATER_TERRAIN_NAME} {SE_NW_VALUE} nw 2 2}
    {DOCK_END {IMAGESTEM} {WATER_TERRAIN_NAME} {N_S_VALUE}   n  1 2}
    {DOCK_END {IMAGESTEM} {WATER_TERRAIN_NAME} {NE_SW_VALUE} ne 0 2}
    {DOCK_END {IMAGESTEM} {WATER_TERRAIN_NAME} {SE_NW_VALUE} se 0 1}

#enddef
