#!/bin/bash

# Capability strings to set at d3f time.

./scripts/capabilities -c "tilespec"  -s "+Freeciv-3.3-tilespec"
#./scripts/capabilities -c "soundspec" -s "+Freeciv-3.2-soundset"
#./scripts/capabilities -c "musicspec" -s "+Freeciv-3.2-musicspec"
./scripts/capabilities -c "spec"      -s "+Freeciv-3.3-spec"
./scripts/capabilities -c "ruleset"   -s "+Freeciv-3.3-ruleset"

# capabilities script has no ability to handle sdl2/sdl3-client themes.
# Check also those. ( .themespec & .tspec )
# For freeciv-3.3 the .tspec capability: "+Freeciv-3.3-sdl2-spec" / "+Freeciv-3.3-sdl3-spec",
# and .themespec capability: "+Freeciv-3.3-sdl2-themespec" / "+Freeciv-3.3-sdl3-themespec"

find data/themes/gui-sdl2 -name "*.tspec" | (while read FILE; do sed 's/+Freeciv-sdl2-3.3-spec-Devel-2023-Jun-10/+Freeciv-3.3-sdl2-spec/' $FILE > $FILE.new && mv $FILE.new $FILE ; done )
sed 's/+Freeciv-sdl2-3.3-spec-Devel-2023-Jun-10/+Freeciv-3.3-sdl2-spec/' client/gui-sdl2/themespec.c > ts.c.new && mv ts.c.new client/gui-sdl2/themespec.c
find data/themes/gui-sdl2 -name "*.themespec" | (while read FILE; do sed 's/+Freeciv-sdl2-3.3-themespec-Devel-2023-Jun-07/+Freeciv-3.3-sdl2-themespec/' $FILE > $FILE.new && mv $FILE.new $FILE ; done )
sed 's/+Freeciv-sdl2-3.3-themespec-Devel-2023-Jun-07/+Freeciv-3.3-sdl2-themespec/' client/gui-sdl2/themespec.c > ts.c.new && mv ts.c.new client/gui-sdl2/themespec.c

find data/themes/gui-sdl3 -name "*.tspec" | (while read FILE; do sed 's/+Freeciv-sdl3-3.3-spec-Devel-2023-Jun-10/+Freeciv-3.3-sdl3-spec/' $FILE > $FILE.new && mv $FILE.new $FILE ; done )
sed 's/+Freeciv-sdl3-3.3-spec-Devel-2023-Jun-10/+Freeciv-3.3-sdl3-spec/' client/gui-sdl3/themespec.c > ts.c.new && mv ts.c.new client/gui-sdl3/themespec.c
find data/themes/gui-sdl3 -name "*.themespec" | (while read FILE; do sed 's/+Freeciv-sdl3-3.3-themespec-Devel-2023-Jun-07/+Freeciv-3.3-sdl3-themespec/' $FILE > $FILE.new && mv $FILE.new $FILE ; done )
sed 's/+Freeciv-sdl3-3.3-themespec-Devel-2023-Jun-07/+Freeciv-3.3-sdl3-themespec/' client/gui-sdl3/themespec.c > ts.c.new && mv ts.c.new client/gui-sdl3/themespec.c

# capabilities script has no ability to handle modlist or mpdb capabilities
# Check also those

CAP_MODLIST_OLD="+Freeciv-modlist-Devel-3.3-2024.Sep.18"
CAP_MODLIST_NEW="+Freeciv-3.3-modlist"
CAP_MODPACK_OLD="+Freeciv-mpdl-Devel-3.2-2024.Sep.18"
CAP_MODPACK_NEW="+Freeciv-3.3-mpdl"

sed -e "s/${CAP_MODLIST_OLD}/${CAP_MODLIST_NEW}/" \
    -e "s/${CAP_MODPACK_OLD}/${CAP_MODPACK_NEW}/" tools/fcmp/download.h \
    > dl.h.new && mv dl.h.new tools/fcmp/download.h

sed -e "s/${CAP_MODLIST_OLD}/${CAP_MODLIST_NEW}/" \
    -e "s/${CAP_MODPACK_OLD}/${CAP_MODPACK_NEW}/" doc/README.modpack_installer \
    > rmi.h.new && mv rmi.h.new doc/README.modpack_installer


# capabilities script has no ability to handle modpack capabilities
# Check also those

CAP_MODPACK_OLD="+Freeciv-modpack-3.3-Devel-2024.Apr.14"
CAP_MODPACK_NEW="+Freeciv-3.3-modpack"

find data -name "*.modpack" | (while read FILE ; do sed "s/${CAP_MODPACK_OLD}/${CAP_MODPACK_NEW}/" "${FILE}" > "${FILE}.new" && mv "${FILE}.new" "${FILE}" ; done )
sed -e "s/${CAP_MODPACK_OLD}/${CAP_MODPACK_NEW}/" common/modpack.h \
    > mp.h.new && mv mp.h.new common/modpack.h
