#!/bin/bash

echo "
s/spec2/spec3/g
s/s0e0/e0s0/g
s/s1e0/e0s1/g
s/s0e1/e1s0/g
s/s1e1/e1s1/g
s/d_road_n0e0s0w0/d_road_ne0se0sw0nw0/g
s/d_road_n1e0s0w0/d_road_ne1se0sw0nw0/g
s/d_road_n0e1s0w0/d_road_ne0se1sw0nw0/g
s/d_road_n1e1s0w0/d_road_ne1se1sw0nw0/g
s/d_road_n0e0s1w0/d_road_ne0se0sw1nw0/g
s/d_road_n1e0s1w0/d_road_ne1se0sw1nw0/g
s/d_road_n0e1s1w0/d_road_ne0se1sw1nw0/g
s/d_road_n1e1s1w0/d_road_ne1se1sw1nw0/g
s/d_road_n0e0s0w1/d_road_ne0se0sw0nw1/g
s/d_road_n1e0s0w1/d_road_ne1se0sw0nw1/g
s/d_road_n0e1s0w1/d_road_ne0se1sw0nw1/g
s/d_road_n1e1s0w1/d_road_ne1se1sw0nw1/g
s/d_road_n0e0s1w1/d_road_ne0se0sw1nw1/g
s/d_road_n1e0s1w1/d_road_ne1se0sw1nw1/g
s/d_road_n0e1s1w1/d_road_ne0se1sw1nw1/g
s/d_road_n1e1s1w1/d_road_ne1se1sw1nw1/g
s/d_rail_n0e0s0w0/d_rail_ne0se0sw0nw0/g
s/d_rail_n1e0s0w0/d_rail_ne1se0sw0nw0/g
s/d_rail_n0e1s0w0/d_rail_ne0se1sw0nw0/g
s/d_rail_n1e1s0w0/d_rail_ne1se1sw0nw0/g
s/d_rail_n0e0s1w0/d_rail_ne0se0sw1nw0/g
s/d_rail_n1e0s1w0/d_rail_ne1se0sw1nw0/g
s/d_rail_n0e1s1w0/d_rail_ne0se1sw1nw0/g
s/d_rail_n1e1s1w0/d_rail_ne1se1sw1nw0/g
s/d_rail_n0e0s0w1/d_rail_ne0se0sw0nw1/g
s/d_rail_n1e0s0w1/d_rail_ne1se0sw0nw1/g
s/d_rail_n0e1s0w1/d_rail_ne0se1sw0nw1/g
s/d_rail_n1e1s0w1/d_rail_ne1se1sw0nw1/g
s/d_rail_n0e0s1w1/d_rail_ne0se0sw1nw1/g
s/d_rail_n1e0s1w1/d_rail_ne1se0sw1nw1/g
s/d_rail_n0e1s1w1/d_rail_ne0se1sw1nw1/g
s/d_rail_n1e1s1w1/d_rail_ne1se1sw1nw1/g
s/explode.iso_nuke/explode.nuke/g
s/tx.s_forest_/t.forest_/g
s/tx.s_hill_/t.hills_/g
s/tx.s_mountain_/t.mountains_/g
s/tx.coast_cape_u0/t.ocean_cell_u000/
s/tx.coast_cape_u1/t.ocean_cell_u100/
s/tx.coast_cape_u2/t.ocean_cell_u010/
s/tx.coast_cape_u3/t.ocean_cell_u110/
s/tx.coast_cape_u4/t.ocean_cell_u001/
s/tx.coast_cape_u5/t.ocean_cell_u101/
s/tx.coast_cape_u6/t.ocean_cell_u011/
s/tx.coast_cape_u7/t.ocean_cell_u111/
s/tx.coast_cape_d0/t.ocean_cell_d000/
s/tx.coast_cape_d1/t.ocean_cell_d100/
s/tx.coast_cape_d2/t.ocean_cell_d010/
s/tx.coast_cape_d3/t.ocean_cell_d110/
s/tx.coast_cape_d4/t.ocean_cell_d001/
s/tx.coast_cape_d5/t.ocean_cell_d101/
s/tx.coast_cape_d6/t.ocean_cell_d011/
s/tx.coast_cape_d7/t.ocean_cell_d111/
s/tx.coast_cape_r0/t.ocean_cell_r000/
s/tx.coast_cape_r1/t.ocean_cell_r100/
s/tx.coast_cape_r2/t.ocean_cell_r010/
s/tx.coast_cape_r3/t.ocean_cell_r110/
s/tx.coast_cape_r4/t.ocean_cell_r001/
s/tx.coast_cape_r5/t.ocean_cell_r101/
s/tx.coast_cape_r6/t.ocean_cell_r011/
s/tx.coast_cape_r7/t.ocean_cell_r111/
s/tx.coast_cape_l0/t.ocean_cell_l000/
s/tx.coast_cape_l1/t.ocean_cell_l100/
s/tx.coast_cape_l2/t.ocean_cell_l010/
s/tx.coast_cape_l3/t.ocean_cell_l110/
s/tx.coast_cape_l4/t.ocean_cell_l001/
s/tx.coast_cape_l5/t.ocean_cell_l101/
s/tx.coast_cape_l6/t.ocean_cell_l011/
s/tx.coast_cape_l7/t.ocean_cell_l111/
s/citizen.entertainer/specialist.elvis_0/
s/citizen.scientist/specialist.scientist_0/
s/citizen.tax_collector/specialist.taxman_0/
" > script.$$

echo "


; Use roadstyle 0 (old iso style)
roadstyle = 0

; Use fogstyle  (old iso style)
fogstyle = 0

; Use darkness style 1 (single-sprite)
darkness_style = 1
 
; offset the flags by this amount when drawing units
flag_offset_x = 17
flag_offset_y = 11


; Terrain info - see README.graphics

[layer0]
match_style = \"BOOL\"
match_types = \"ocean\", \"other\"

[layer1]
match_style = \"BOOL\"
match_types = \"forest\", \"hills\", \"mountains\"

[terrain_arctic]
is_blended = 1
num_layers = 1
layer0_match_type = \"other\"
mine_sprite = \"tx.oil_mine\"

[terrain_desert]
is_blended = 1
num_layers = 1
layer0_match_type = \"other\"
mine_sprite = \"tx.oil_mine\"

[terrain_forest]
is_blended = 1
num_layers = 2
layer0_match_type = \"other\"
layer1_match_type = \"forest\"
layer1_match_style = \"bool\"

[terrain_grassland]
is_blended = 1
num_layers = 1
layer0_match_type = \"other\"

[terrain_hills]
is_blended = 1
num_layers = 2
layer0_match_type = \"other\"
layer1_match_type = \"hills\"
layer1_match_style = \"bool\"
mine_sprite = \"tx.mine\"

[terrain_jungle]
is_blended = 1
num_layers = 1
layer0_match_type = \"other\"

[terrain_mountains]
is_blended = 1
num_layers = 2
layer0_match_type = \"other\"
layer1_match_type = \"mountains\"
layer1_match_style = \"bool\"
mine_sprite = \"tx.mine\"

[terrain_ocean]
is_blended = 1
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"ocean\"
layer0_cell_type = \"rect\"

[terrain_plains]
is_blended = 1
num_layers = 1
layer0_match_type = \"other\"

[terrain_swamp]
is_blended = 1
num_layers = 1
layer0_match_type = \"other\"

[terrain_tundra]
is_blended = 1
num_layers = 1
layer0_match_type = \"other\"
" > isometric.$$

echo "


; Use roadstyle 1 (old non-iso style)
roadstyle = 1

; Use fogstyle 1 (old non-iso style)
fogstyle = 0

; Use darkness style 3 (15 sprites)
darkness_style = 3
 
; offset the flags by this amount when drawing units
flag_offset_x = 0
flag_offset_y = 0


; Terrain info - see README.graphics

[layer0]
match_style = \"BOOL\"
match_types = \"arctic\", \"desert\", \"forest\", \"grassland\", \"hills\", \"jungle\", \"mountains\", \"ocean\", \"plains\", \"swamp\", \"tundra\"

[layer1]
match_style = \"BOOL\"
match_types = \"ocean\"

[terrain_arctic]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"arctic\"
mine_sprite = \"tx.oil_mine\"

[terrain_desert]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"desert\"
mine_sprite = \"tx.oil_mine\"

[terrain_forest]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"forest\"

[terrain_grassland]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"grassland\"

[terrain_hills]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"hills\"
mine_sprite = \"tx.mine\"

[terrain_jungle]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"jungle\"

[terrain_mountains]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"mountains\"
mine_sprite = \"tx.mine\"

[terrain_ocean]
is_blended = 0
num_layers = 2
layer0_match_style = \"bool\"
layer0_match_type = \"ocean\"
layer1_match_style = \"bool\"
layer1_match_type = \"ocean\"
layer1_cell_type = \"rect\"

[terrain_plains]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"plains\"

[terrain_swamp]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"swamp\"

[terrain_tundra]
is_blended = 0
num_layers = 1
layer0_match_style = \"bool\"
layer0_match_type = \"tundra\"
" > nonisometric.$$

echo "Updating tilespec files for freeciv 2.0"
files=`find . -name "*.tilespec"`
for file in $files; do
    if grep "spec3" "$file" >/dev/null 2>&1; then
      # Nothing!
      :
    else 
	if grep "is_isometric.*=.*1" $file >/dev/null 2>&1; then
	    cat isometric.$$ >> "$file"
	else
	    cat nonisometric.$$ >> "$file"
	fi

        cat "$file" | sed "s/spec2/spec3/g" > "$file.$$"
        mv "$file.$$" "$file"

	echo "  $file"
    fi
done

echo "Updating specfiles for freeciv 2.0"
files=`find . -name "*.spec"`
for file in $files; do
    cat "$file" | sed -f script.$$ > "$file.$$"

    cmp $file $file.$$ >/dev/null \
	|| (mv $file.$$ $file && echo "  $file")
    rm -f $file.$$
done

rm -f script.$$ isometric.$$ nonisometric.$$
