Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Can you help improve your favourite game? Hardcore C mages, talented artists, and players with any level of experience are welcome!
Post Reply
Molo_Parko
Hardened
Posts: 200
Joined: Fri Jul 02, 2021 4:00 pm

Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Post by Molo_Parko »

Image

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.

Image

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.

Image
^ 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
^ Bash script to convert the scenario map's terrain layer, startpos, and e03_ layers from older Freeciv v1 format to Freeciv v2 format.
Attachments
bash convert Freeciv v1 scenario map to v2.6.txt.zip
(4.45 KiB) Downloaded 115 times
Caulixtla for Freeciv 2.6.x.sav.zip
(9.57 KiB) Downloaded 113 times
cazfi
Elite
Posts: 3273
Joined: Tue Jan 29, 2013 6:54 pm

Re: Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Post by cazfi »

I would load the scenario to a freeciv server version that still supported old enough format, to let everything get converted properly. Then use the "scensave" command (assuming the freeciv version in question supports "scensave". If not, regular "save", but then likely some manual editing is needed).
cazfi
Elite
Posts: 3273
Joined: Tue Jan 29, 2013 6:54 pm

Re: Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Post by cazfi »

Here's the scanario saved first from freeciv-2.5 with /scensave, then that loaded to 2.6 and /scensaved again, in case you want to compare it to your method.
Attachments
caulixtla-2.6.sav.bz2
(7.18 KiB) Downloaded 105 times
caulixtla-2.5.sav.bz2
(6.55 KiB) Downloaded 113 times
Molo_Parko
Hardened
Posts: 200
Joined: Fri Jul 02, 2021 4:00 pm

Re: Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Post by Molo_Parko »

If a person happens to have functional installs of v2.5 and 2.6 then /scensave is a nice option. If the person doesn't have functional installs then compiling them on some platforms would be a high hurdle!

Whereas copy-and-paste of the map layers between files takes about 1 minute ( for me ) and any plain text editor.

Translating the option values from version 1.9 to 2.6 without scensave would be a pain-in-the-rear, especially so if one has forgotten what effects the v1 options actually produce. An example is foodbox=10 in the original file, and scensave from Freeciv 2.5 changes it to 100 -- which may be the correct conversion given that foodbox math did change across v1.x versions, but I don't remember what a value of 10 would have done in v1.9 vs a value of 100 in v2.5. The Caulixtla original file is not really a great choice for testing value conversions because I get the impression that the file exists due to testing map conversion, and that the values included may therefore be irrelevant anyway.

The values which aren't in the .sav file bother me more than those which are defined in the file. The original Caulixtla.sav file does not list all possible options, so even if one knew the correct conversions of options values, it still wouldn't help to determine what other values were supplied as defaults by the preferences of the scenario author's Freeciv install.

For example, the v1.9 scenario file does not enable "ALLIED" victory (feature didn't exist in v1.9, I believe), but the scensave 2.5 version has it enabled because the .sav file did not have it disabled, but rather merely missing. The newer version's (2.5) ALLIED victory feature was enabled by default despite that it is not part of the original Caulixtla.sav scenario file. That is precisely an example of what I would like to prevent -- the scenario gameplay changing because a feature which did not exist when the scenario was created, defaults to enabled in a newer version.

The scensave 2.6 version is completely missing several options ( set_count=119 out of 125 or so ) and which will use whatever default values are active in the Freeciv installation which is running the scenario, and can therefore vary from one user's installation to the next. An example is "traitdistribution" which is not specified at all in the v2.6 scensave file, and probably should be set as "FIXED", but will presumably take-up at gamestart whatever default value is in the player's preferences.

I don't object to people changing a scenario's settings to alter the gameplay of the scenario, but I wish that Freeciv wouldn't do it by default!
cazfi
Elite
Posts: 3273
Joined: Tue Jan 29, 2013 6:54 pm

Re: Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Post by cazfi »

Molo_Parko wrote: Tue Dec 03, 2024 5:20 pmThe Caulixtla original file is not really a great choice for testing value conversions because I get the impression that the file exists due to testing map conversion, and that the values included may therefore be irrelevant anyway.
It's not a great choice of scenario conversion example also because it's so simple, so you don't benefit from proper conversions of, e.g., specials -> bases/roads/other specials -> extras. Resources are still not extras in freeciv-2.6, so no conversion for those is needed (such conversion is needed when moving to freeciv-3.0 format)
cazfi
Elite
Posts: 3273
Joined: Tue Jan 29, 2013 6:54 pm

Re: Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Post by cazfi »

cazfi wrote: Tue Dec 03, 2024 5:45 pm
Molo_Parko wrote: Tue Dec 03, 2024 5:20 pmThe Caulixtla original file is not really a great choice for testing value conversions because I get the impression that the file exists due to testing map conversion, and that the values included may therefore be irrelevant anyway.
It's not a great choice of scenario conversion example also because it's so simple, so you don't benefit from proper conversions of, e.g., specials -> bases/roads/other specials -> extras. Resources are still not extras in freeciv-2.6, so no conversion for those is needed (such conversion is needed when moving to freeciv-3.0 format)
But looking at our conversations, your has no resources at all while mine does.
Your has huts, mine does not.
Both have similar rivers (type of Road in newer versions)
cazfi
Elite
Posts: 3273
Joined: Tue Jan 29, 2013 6:54 pm

Re: Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Post by cazfi »

cazfi wrote: Tue Dec 03, 2024 6:01 pmBut looking at our conversations, your has no resources at all while mine does.
This is due to you setting "specials" to zero, and this scenario is yet to create the resources in the game start (so their placement is not in the maps - no such conversion needed)
cazfi wrote: Tue Dec 03, 2024 6:01 pmYour has huts, mine does not.
This is due to you setting map.have_huts to FALSE, indicating that huts should still be created. I believe that in the ancient versions huts were not added afterwards to an already created map (they were assumed to be part of the map, or left out on purpose)
Molo_Parko
Hardened
Posts: 200
Joined: Fri Jul 02, 2021 4:00 pm

Re: Moving Freeciv v1 scenario map to a Freeciv v2.6.x scenario file example

Post by Molo_Parko »

I didn't convert any of the options, but rather only "rescued" the map and pasted it into a newly generated v2.6.11 scenario file using the same map dimensions -- so the options in mine are whatever was in use when I generated the new scenario file to hold the map. I only did a "map rescue" whereas /scensave converted the options. Ah, I did change aifill to avoid the error message.


EDIT: 2023/12/06 Well I was going to detail moving the same map back to even older versions, but so far only 1.8.1 and 1.14.2 have actually compiled on this machine. In 1.14.2 the civserver is functional, the client crashes. 1.81 compiles, runs and plays well enough, but there are so many differences from 1.81 to now that it might take awhile to reacquaint myself with all the options and issues.
Post Reply