I ran across a Freeciv v1 scenario file on the www ( http://www.samiam.org/Civ4/Caulixtla/ ) and wrote a script to convert the map sections for copy-and-paste into a Freeciv v2 scenario file. I think the original Freeciv 1 map was a result of conversion from another format, so it seemed fitting for use as a subject for this conversion.
The file had the Freeciv v1 style 3 digit map line #'s, and the ancient r#sx= style of startpos. Only 2 map layers are in the original file the "t" terrain layer and the old "n" layer needed for rivers. The script posted below converts the map layer name and line numbering schemes to their Freeciv 2 equivalents. The "NEW OUTPUT" section from the script can be copy-and-pasted over map sections in a Freeciv 2 scenario file generated with the same dimensions. Or if the dimensions are different, don't forget to change xsize and ysize in the v2 scenario [settings] section.
I thought about converting some of the other game options from the original too, but I quickly realized that I have forgotten virtually all detail of what effects Freeciv 1 settings produce, so the script does show the various sections and their settings but makes no effort to convert the "riverlength" value to some potentially matching Freeciv 2 "water on land" value, for example. One notable setting is aifill=13 but there are only 11 startpos in the original file so I set the v2 scenario file "aifill" to 11.
^ Minimap view -- nice looking continents size and shape.
Code: Select all
#!/bin/bash
declare -i section_lines=0
declare section_name="" zeroPad="0000"
declare -a lines
declare file="${1}"
declare -a startpos_x startpos_y terrain_layer e03_layer
declare -i startpos_count=0
declare temp startpos_terrains="adfghjmpst"
declare IFSoriginal="${IFS}"
IFS=$'\r\n' GLOBIGNORE='*' command eval 'lines=( $(sed -e 's/^[[:space:]]*//' "${file}") )'
IFS="${IFSoriginal}"
for (( c=0 ; c <= ${#lines[*]} ; c++ )) ; do
section_lines=$(( ${section_lines} + 1 ))
if [ "${lines[${c}]:0:1}" == "[" ] ; then
if [ "${section_name}" != "" ] ; then
echo -e "\tEnd of section ${section_name}\tlines=${section_lines}\n"
fi
section_name="${lines[${c}]}"
echo -e "\n\tsection_name=${section_name}"
section_lines=-1
continue
fi
if [ "${section_name}" == "[map]" ] ; then
if [ "${lines[${c}]:0:6}" == "width=" ] ; then
map_width="${lines[${c}]:6}"
if [ "${map_width//[0123456789]}" != "" ] ; then
echo "ERROR specified map width invalid"
exit 1
fi
fi
if [ "${lines[${c}]:0:7}" == "height=" ] ; then
map_height="${lines[${c}]:7}"
if [ "${map_height//[0123456789]}" != "" ] ; then
echo "ERROR specified map height invalid"
exit 1
fi
fi
if [ "${lines[${c}]:0:1}" == "t" ] || [ "${lines[${c}]:0:1}" == "n" ] ; then
if [ $(( ${#lines[${c}]} - 7 )) -ne "${map_width}" ] ; then
echo "LINE ${c} WIDTH MISMATCH"
exit 1
fi
fi
if [[ "${lines[${c}]:0:4}" == t[0-9][0-9][0-9] ]] ; then
terrain_layer[${#terrain_layer[*]+1}]="t0${lines[c]:1}"
elif [[ "${lines[${c}]:0:4}" == n[0-9][0-9][0-9] ]] ; then
e03_layer[${#e03_layer[*]+1}]="e03_0${lines[c]:1}"
fi
if [ "${lines[${c}]//[[:digit:]]}" == "rsx=" ] ; then
temp="${lines[${c}]#r}" ; startpos_count="${temp%%s*}"
startpos_x[${startpos_count}]="${lines[${c}]#*=}"
elif [ "${lines[${c}]//[[:digit:]]}" == "rsy=" ] ; then
temp="${lines[${c}]#r}" ; startpos_count="${temp%%s*}"
startpos_y[${startpos_count}]="${lines[${c}]#*=}"
fi
fi
if [ "${lines[${c}]}" != "" ] ; then
echo "${lines[${c}]}"
fi
done
echo -e "\tEND OF FILE"
echo ; echo ; echo
echo "NEW OUTPUT BELOW"
echo
# Output the terrain layer
for (( i=0 ; i<${#terrain_layer[*]} ; i++ )) ; do
echo "${terrain_layer[${i}]}"
done
# Output start positions
echo "startpos_count=$(( ${startpos_count} + 1 ))"
echo "startpos={\"x\",\"y\",\"exclude\",\"nations\""
for (( i=0 ; i<=${startpos_count} ; i++ )) ; do
tile="${terrain_layer[${startpos_y[${i}]}]:$(( ${startpos_x[${i}]} + 7 )):1}"
if [ "${startpos_terrains}" == "${startpos_terrains//${tile}}" ] ; then
echo " Bad startpos terrain choice? "
fi
echo -e "${startpos_x[${i}]},${startpos_y[${i}]},FALSE,\"\""
done
echo "}"
# Fake the e00, e01, e02 layers
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "e00_${zeroPad:${#i}}${i}${e03_layer[0]:8}"
done
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "e01_${zeroPad:${#i}}${i}${e03_layer[0]:8}"
done
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "e02_${zeroPad:${#i}}${i}${e03_layer[0]:8}"
done
# Output the real e03 layer (Rivers)
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "${e03_layer[${i}]}"
done
# Fake the Res layer
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
spaceline="${e03_layer[0]//0/ }"
spaceline="${spaceline:8}"
echo "res${zeroPad:${#i}}${i}${spaceline}"
done
echo
exit 0
# This part is not needed if copying to a Freeciv 2 scenario file
# Remove the exit 0 above it to enable it
# May be desirable for Freeciv 3
# Fake the e04, e05, e06, e07, e08 layers
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "e04_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""
done
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "e05_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""
done
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "e06_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""
done
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "e07_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""
done
for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; do
echo "e08_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""
done
echo
exit 0