# 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 IMAGE WATER BRIDGETYPE BEACHSIDE X Y
[terrain_graphics]
  [tile]
		x=1
		y=1
		type={BRIDGETYPE}
	[/tile]
	[tile]
		x={X}
		y={Y}
		type={WATER}
		no_flag=angleaway_{BEACHSIDE}
		{IMAGE_L_N -80 {IMAGE}-{BEACHSIDE}-end}
	[/tile]
[/terrain_graphics]
#enddef

# this macro adds ramp-style ends to bridges ending on other bridges
#define RAMP_BRIDGE IMAGE BRIDGETYPE BRIDGES 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}
		no_flag=angle_{R1},angle_{R5}
	[/tile]
	[tile]
		pos=2
		type={BRIDGES}
		no_flag=angle_{R3}
		{IMAGE_L_N -80 {IMAGE}-{R3}}
	[/tile]
[/terrain_graphics]
#enddef

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

# this macro produces Y intersections
#define BRIDGE_Y BRIDGETYPE1 BRIDGETYPE2 BRIDGETYPE3 YIMAGE 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}
		no_flag=overlay,angle_{R0},angle_{R2},angle_{R4}
		set_flag=overlay,angle_{R1},angle_{R5},angle_{R3}
		{IMAGE_L_N -80 {YIMAGE}}
	[/tile]
	[tile]
		pos=2
		no_flag=angle_{R3},angle_{R1}
		set_flag=angle_{R2}
		type={BRIDGETYPE2}
	[/tile]
	[tile]
		pos=3
		no_flag=angle_{R3},angle_{R5}
		set_flag=angle_{R4}
		type={BRIDGETYPE3}
	[/tile]
	[tile]
		pos=4
		type=!{BRIDGETYPE1}
		set_flag=angleaway_{R3}
	[/tile]
[/terrain_graphics]
#enddef

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

# this macro handles the normal corners
#define CORNER ANGLEIMAGE BRIDGETYPE1 BRIDGETYPE2 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}
		no_flag=overlay,angle_{A3},angle_{A4},angle_{A5},angle_{A6}
		set_flag=overlay,angle_{A1},angle_{A2}
		{IMAGE_L_N -80 {ANGLEIMAGE}}
	[/tile]
	[tile]
		pos=2
		type={BRIDGETYPE2}
		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 N_S NE_SW WATER NOTERM IMAGE

# find Y intersections
{BRIDGE_Y {N_S} {SE_NW} {NE_SW} {IMAGE}-joint-ne-s-nw n ne se s sw nw 2 4 3 . . .}
{BRIDGE_Y {NE_SW} {N_S} {SE_NW} {IMAGE}-joint-n-se-sw ne se s sw nw n . 2 4 3 . .}
{BRIDGE_Y {SE_NW} {NE_SW} {N_S} {IMAGE}-joint-ne-s-nw se s sw nw n ne . . 2 4 3 .}
{BRIDGE_Y {N_S} {SE_NW} {NE_SW} {IMAGE}-joint-n-se-sw s sw nw n ne se . . . 2 4 3}
{BRIDGE_Y {NE_SW} {N_S} {SE_NW} {IMAGE}-joint-ne-s-nw sw nw n ne se s 3 . . . 2 4}
{BRIDGE_Y {SE_NW} {NE_SW} {N_S} {IMAGE}-joint-n-se-sw nw n ne se s sw 4 3 . . . 2}

# make sure that colinear adjacent bridges stay connected
{BRIDGECONNECT {N_S}   n ne se s sw nw 1 0}
{BRIDGECONNECT {NE_SW} ne se s sw nw n 2 1}
{BRIDGECONNECT {SE_NW} se s sw nw n ne 2 2}

# normal corners
{CORNER {IMAGE}-joint-s-nw  {N_S} {SE_NW}   s  nw se n  sw ne 2 3 . . . .}
{CORNER {IMAGE}-joint-ne-s  {N_S} {NE_SW}   s  ne sw n  se nw . 3 2 . . .}
{CORNER {IMAGE}-joint-n-sw  {NE_SW} {N_S}   sw n  s  ne nw se . 2 3 . . .}
{CORNER {IMAGE}-joint-se-sw {NE_SW} {SE_NW} sw se nw ne s  n  . . 3 2 . .}
{CORNER {IMAGE}-joint-ne-nw {SE_NW} {NE_SW} nw ne sw se n  s  . . 2 3 . .}
{CORNER {IMAGE}-joint-s-nw  {SE_NW} {N_S}   nw s  n  se sw ne . . . 3 2 .}
{CORNER {IMAGE}-joint-n-se  {N_S} {SE_NW}   n  se nw s  ne sw . . . 2 3 .}
{CORNER {IMAGE}-joint-n-sw  {N_S} {NE_SW}   n  sw ne s  nw se . . . . 3 2}
{CORNER {IMAGE}-joint-ne-s  {NE_SW} {N_S}   ne s  n  sw se nw . . . . 2 3}
{CORNER {IMAGE}-joint-ne-nw {NE_SW} {SE_NW} ne nw se sw n  s  2 . . . . 3}
{CORNER {IMAGE}-joint-se-sw {SE_NW} {NE_SW} se sw ne nw s  n  3 . . . . 2}
{CORNER {IMAGE}-joint-n-se  {SE_NW} {N_S}   se n  s  nw ne sw 3 2 . . . .}

# these 3 macros define the default straight bridges
{TERRAIN_BASE_OV {N_S}  {IMAGE}-n-s}
{TERRAIN_BASE_OV {NE_SW}  {IMAGE}-ne-sw}
{TERRAIN_BASE_OV {SE_NW}  {IMAGE}-se-nw}

# add ramps where straight bridges intersect Ys
{RAMP_BRIDGE {IMAGE} {N_S}   {N_S}{NE_SW}{SE_NW} n ne se s sw nw 2 . . . . .}
{RAMP_BRIDGE {IMAGE} {NE_SW} {N_S}{NE_SW}{SE_NW} ne se s sw nw n . 2 . . . .}
{RAMP_BRIDGE {IMAGE} {SE_NW} {N_S}{NE_SW}{SE_NW} se s sw nw n ne . . 2 . . .}
{RAMP_BRIDGE {IMAGE} {N_S}   {N_S}{NE_SW}{SE_NW} s sw nw n ne se . . . 2 . .}
{RAMP_BRIDGE {IMAGE} {NE_SW} {N_S}{NE_SW}{SE_NW} sw nw n ne se s . . . . 2 .}
{RAMP_BRIDGE {IMAGE} {SE_NW} {N_S}{NE_SW}{SE_NW} nw n ne se s sw . . . . . 2}

# add ramps where straight bridges end on land
{RAMP_END {IMAGE} {WATER} {NOTERM} {N_S}   n ne se s sw nw 1 0}
{RAMP_END {IMAGE} {WATER} {NOTERM} {NE_SW} ne se s sw nw n 2 1}
{RAMP_END {IMAGE} {WATER} {NOTERM} {SE_NW} se s sw nw n ne 2 2}
{RAMP_END {IMAGE} {WATER} {NOTERM} {N_S}   s sw nw n ne se 1 2}
{RAMP_END {IMAGE} {WATER} {NOTERM} {NE_SW} sw nw n ne se s 0 2}
{RAMP_END {IMAGE} {WATER} {NOTERM} {SE_NW} nw n ne se s sw 0 1}

# add dock-style ends to bridges ending in water
{DOCK_END {IMAGE} {WATER} {N_S}   s  1 0}
{DOCK_END {IMAGE} {WATER} {NE_SW} sw 2 1}
{DOCK_END {IMAGE} {WATER} {SE_NW} nw 2 2}
{DOCK_END {IMAGE} {WATER} {N_S}   n  1 2}
{DOCK_END {IMAGE} {WATER} {NE_SW} ne 0 2}
{DOCK_END {IMAGE} {WATER} {SE_NW} se 0 1}

#enddef
