
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:
#!/bin/bashdeclare -i section_lines=0declare section_name="" zeroPad="0000"declare -a linesdeclare file="${1}"declare -a startpos_x startpos_y terrain_layer e03_layerdeclare -i startpos_count=0declare 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++ )) ; dosection_lines=$(( ${section_lines} + 1 ))if [ "${lines[${c}]:0:1}" == "[" ] ; thenif [ "${section_name}" != "" ] ; thenecho -e "\tEnd of section ${section_name}\tlines=${section_lines}\n"fisection_name="${lines[${c}]}"echo -e "\n\tsection_name=${section_name}"section_lines=-1continuefiif [ "${section_name}" == "[map]" ] ; thenif [ "${lines[${c}]:0:6}" == "width=" ] ; thenmap_width="${lines[${c}]:6}"if [ "${map_width//[0123456789]}" != "" ] ; thenecho "ERROR specified map width invalid"exit 1fifiif [ "${lines[${c}]:0:7}" == "height=" ] ; thenmap_height="${lines[${c}]:7}"if [ "${map_height//[0123456789]}" != "" ] ; thenecho "ERROR specified map height invalid"exit 1fifiif [ "${lines[${c}]:0:1}" == "t" ] || [ "${lines[${c}]:0:1}" == "n" ] ; thenif [ $(( ${#lines[${c}]} - 7 )) -ne "${map_width}" ] ; thenecho "LINE ${c} WIDTH MISMATCH"exit 1fifiif [[ "${lines[${c}]:0:4}" == t[0-9][0-9][0-9] ]] ; thenterrain_layer[${#terrain_layer[*]+1}]="t0${lines[c]:1}"elif [[ "${lines[${c}]:0:4}" == n[0-9][0-9][0-9] ]] ; thene03_layer[${#e03_layer[*]+1}]="e03_0${lines[c]:1}"fiif [ "${lines[${c}]//[[:digit:]]}" == "rsx=" ] ; thentemp="${lines[${c}]#r}" ; startpos_count="${temp%%s*}"startpos_x[${startpos_count}]="${lines[${c}]#*=}"elif [ "${lines[${c}]//[[:digit:]]}" == "rsy=" ] ; thentemp="${lines[${c}]#r}" ; startpos_count="${temp%%s*}"startpos_y[${startpos_count}]="${lines[${c}]#*=}"fifiif [ "${lines[${c}]}" != "" ] ; thenecho "${lines[${c}]}"fidoneecho -e "\tEND OF FILE"echo ; echo ; echoecho "NEW OUTPUT BELOW"echo# Output the terrain layerfor (( i=0 ; i<${#terrain_layer[*]} ; i++ )) ; doecho "${terrain_layer[${i}]}"done# Output start positionsecho "startpos_count=$(( ${startpos_count} + 1 ))"echo "startpos={\"x\",\"y\",\"exclude\",\"nations\""for (( i=0 ; i<=${startpos_count} ; i++ )) ; dotile="${terrain_layer[${startpos_y[${i}]}]:$(( ${startpos_x[${i}]} + 7 )):1}"if [ "${startpos_terrains}" == "${startpos_terrains//${tile}}" ] ; thenecho " Bad startpos terrain choice? "fiecho -e "${startpos_x[${i}]},${startpos_y[${i}]},FALSE,\"\""doneecho "}"# Fake the e00, e01, e02 layersfor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "e00_${zeroPad:${#i}}${i}${e03_layer[0]:8}"donefor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "e01_${zeroPad:${#i}}${i}${e03_layer[0]:8}"donefor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "e02_${zeroPad:${#i}}${i}${e03_layer[0]:8}"done# Output the real e03 layer (Rivers)for (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "${e03_layer[${i}]}"done# Fake the Res layerfor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; dospaceline="${e03_layer[0]//0/ }"spaceline="${spaceline:8}"echo "res${zeroPad:${#i}}${i}${spaceline}"doneechoexit 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 layersfor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "e04_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""donefor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "e05_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""donefor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "e06_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""donefor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "e07_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""donefor (( i=0 ; i<${#e03_layer[*]} ; i++ )) ; doecho "e08_${zeroPad:${#i}}${i}\"${e03_layer[0]:8}\""doneechoexit 0
Statistics: Posted by Molo_Parko — Tue Dec 03, 2024 5:47 am — Replies 7 — Views 148