#!/bin/sh
# SPDX-License-Identifier: ACSL
# SPDX-FileCopyrightText: © 2016 Antoine Le Gonidec <vv221@dotslashplay.it>
set -o errexit

###
# Warlords Battlecry 2
# send your bug reports to vv221@dotslashplay.it
###

script_version=20260310.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='warlords-battlecry-2'
GAME_NAME='Warlords Battlecry II'

ARCHIVE_BASE_1_NAME='setup_warlords_battlecry_2_1.04_(30487).exe'
ARCHIVE_BASE_1_MD5='25cf7418f5b954b97fc0e8b6d32039f2'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_SIZE='930000'
ARCHIVE_BASE_1_VERSION='1.04-gog30487'
ARCHIVE_BASE_1_URL='https://www.gog.com/game/warlords_battlecry_2'

ARCHIVE_BASE_0_NAME='setup_warlords_battlecry2_2.0.0.4.exe'
ARCHIVE_BASE_0_MD5='baa54ca0285182d18d532abfcbb8769f'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='940000'
ARCHIVE_BASE_0_VERSION='1.04-gog2.0.0.4'

CONTENT_PATH_DEFAULT='.'
CONTENT_PATH_DEFAULT_0='app'
# TODO: Check if all libraries are required.
CONTENT_LIBS_BIN_FILES='
binkw32.dll
mss32.dll
WETSTD32.DLL'
CONTENT_GAME_BIN_FILES='
Battlecry II.exe
Mp3dec.asi
Mssv??.asi
Mss*.m3d'
CONTENT_GAME_DATA_FILES='
CampaignScenario
CustomAI
CustomUnitAI
Data
Documentation
English
Events
Fonts
HeroData
Music
NamingSets
Scenario
SoundFX
Tutorial
Video
Terrain.cfg
War4Gfx.xcg
War4Int.xci
WBC.DAT
*.xcr'
CONTENT_DOC_DATA_FILES='
manual.pdf
reference card.pdf'

# Write access to .ini files is required.
USER_PERSISTENT_FILES='
*.ini'

WINE_PERSISTENT_DIRECTORIES='
users/${USER}/Documents/Warlords Battlecry II'

APP_MAIN_EXE='Battlecry II.exe'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'

# Load common functions.

if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${HOME}/.local/lib/play.it" \
		'/usr/local/lib/play.it' \
		'/usr/lib/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit.sh.2"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit2.sh not found.\n'
	exit 1
fi
# shellcheck source=libplayit2.sh
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

# Install shipped libraries.
wineprefix_init_custom() {
	cat <<- EOF
	# Install shipped libraries.
	ln --force --symbolic $(path_libraries)/* "\${PATH_PREFIX}"
	EOF
}

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
