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

###
# AI War 2
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260414.2

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='ai-war-2'
GAME_NAME='AI War 2'

ARCHIVE_BASE_4_NAME='ai_war_2_5_804_89929.sh'
ARCHIVE_BASE_4_MD5='f258875213e7f23a0047254210cb3775'
ARCHIVE_BASE_4_SIZE='3474342'
ARCHIVE_BASE_4_VERSION='5.804-gog89929'
ARCHIVE_BASE_4_URL='https://www.gog.com/game/ai_war_2'

ARCHIVE_BASE_3_NAME='ai_war_2_5_801_89568.sh'
ARCHIVE_BASE_3_MD5='6990d100b03a8cc71d2190e0cd258d23'
ARCHIVE_BASE_3_SIZE='3473247'
ARCHIVE_BASE_3_VERSION='5.801-gog89568'

ARCHIVE_BASE_2_NAME='ai_war_2_5_615_78653.sh'
ARCHIVE_BASE_2_MD5='191ed22d5487288ec8adcb9e5e682307'
ARCHIVE_BASE_2_SIZE='3462750'
ARCHIVE_BASE_2_VERSION='5.615-gog78653'

ARCHIVE_BASE_1_NAME='ai_war_2_5_607_75309.sh'
ARCHIVE_BASE_1_MD5='cace7c4dc863f420da52b6d6a1818c2f'
ARCHIVE_BASE_1_SIZE='3461745'
ARCHIVE_BASE_1_VERSION='5.607-gog75309'

ARCHIVE_BASE_0_NAME='ai_war_2_4_006_54416.sh'
ARCHIVE_BASE_0_MD5='3bbcfa00ea5014d5d6f1258d780c97b0'
ARCHIVE_BASE_0_SIZE='3400000'
ARCHIVE_BASE_0_VERSION='4.006-gog54416'

UNITY3D_NAME='AIWar2Linux'

CONTENT_PATH_DEFAULT='data/noarch/game'
CONTENT_GAME0_BIN_FILES='
ArcenNetworkLib
CodeExternal
PlayerData
ReliableDLLStorage'
# This game seems to use a strange plugins system, so we include its directory as-is.
CONTENT_GAME1_BIN_FILES="
${UNITY3D_NAME}_Data/Plugins"
CONTENT_GAME0_DATA_FILES='
AIW2ModdingAndGUI
AssetBundles_Linux
GameData
GlobalBundles
TotalConversions
XMLMods'

USER_PERSISTENT_DIRECTORIES='
PlayerData'

# Force the use of the OpenGL renderer, the Vulkan one fails to display anything.
# TODO: Check if current game build + libvulkan.so.1 is still affected.
APP_MAIN_OPTIONS='-force-glcore'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='64'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'
PKG_BIN_DEPENDENCIES_LIBRARIES='
libc.so.6
libdl.so.2
libgcc_s.so.1
libm.so.6
libpthread.so.0
librt.so.1
libz.so.1'

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 'libplayit.sh.2 not found.\n'
	exit 1
fi
# shellcheck source=libplayit.sh.2
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default
# Drop data files specific to Windows and Mac OS.
path_archive_contents=$(path_archive_contents)
rm --force --recursive \
	"${path_archive_contents}/TotalConversions/ExampleTC/AssetBundles_OSX" \
	"${path_archive_contents}/TotalConversions/ExampleTC/AssetBundles_Win" \
	"${path_archive_contents}/XMLMods/Bonus_Assets/AssetBundles_OSX" \
	"${path_archive_contents}/XMLMods/Bonus_Assets/AssetBundles_Win"

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
