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

###
# The Elder Scrolls: Arena
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260509.1

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='the-elder-scrolls-1-arena'
GAME_NAME='The Elder Scrolls: Arena'

ARCHIVE_BASE_1_NAME='setup_the_elder_scrolls_arena_1.07_(28043).exe'
ARCHIVE_BASE_1_MD5='53a12a1cc3955776f06fba5906cdc6fe'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_SIZE='120000'
ARCHIVE_BASE_1_VERSION='1.07-gog28043'

ARCHIVE_BASE_0_NAME='setup_tes_arena_2.0.0.5.exe'
ARCHIVE_BASE_0_MD5='ca5a894aa852f9dbb3ede787e51ec828'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='130000'
ARCHIVE_BASE_0_VERSION='1.07-gog2.0.0.5'

CONTENT_PATH_DEFAULT='.'
CONTENT_PATH_DEFAULT_0='app'
CONTENT_GAME_MAIN_FILES='
*.ADV
*.FLC
*.MIF
2651.GLD
ACD.EXE
ARROWS.CIF
BOOTEXEC.CPY
BS5.MIF
CHARSHT.COL
CHARSPEL.IMG
CITYDATA.65
CONFIG.CPY
CRYSTAL3.INF
DAYTIME.COL
DISKS.BAK
DREARY.COL
DUNGEON.TXT
FANFARE?.VOC
FOG.LGT
FOG.TXT
GLOBAL.BSA
GM?.BNK
HELP.TXT
IMPPAL?.INF
INSTALL.CFG
INSTALL.EXE
IVB.NTZ
LAVAANI.RCI
MAGE.CEL
MAPBTNS.MNU
MT?.BNK
NAMES.CLR
NORMAL.LGT
PAL.COL
QUESTION.TXT
ROGUE.CEL
SAMPLE.AD
SAMPLE.OPL
SCROLL03.IMG
SOUND.CFG
SPELLMKR.TXT
SPELLS.65
SPELLSG.65
SPELLS.LST
SPPARTS.RCI
STARTGAM.MNU
STATES.65
TAMRIEL.MNU
TITLE.IMG
ULTRAMID.EXE
ULTRAMID.INI
VILPAL3.MIF
WARRIOR.CEL
WATERANI.RCI
WINGAME.XFM
SPEECH'
# The following must be listed explicitly, as *.DAT would grab __support/save/NAMES.DAT
CONTENT_GAME0_MAIN_FILES='
ARENAFNT.DAT
ARTFACT?.DAT
CHARFNT.DAT
CHARSPEL.DAT
CLASSES.DAT
EQUIP.DAT
FONT4.DAT
FONT_?.DAT
GUARD.DAT
JAGTEMP.DAT
MUGUILD.DAT
NAMECHNK.DAT
POINTER1.DAT
RAND.DAT
SELLING.DAT
TAVERN.DAT
TEENYFNT.DAT
TEMPLATE.DAT'
CONTENT_GAME1_MAIN_RELATIVE_PATH='__support/save'
CONTENT_GAME1_MAIN_FILES='
NAMES.DAT'
# TODO: Check if this is a game file or some documenation.
CONTENT_GAME2_MAIN_FILES='
Passwords.txt'
CONTENT_DOC_MAIN_FILES='
Arena Codex Scientia.pdf
Manual.pdf
Player Guide.pdf
Quick Reference Card.pdf
READ.ME
README.TXT'

DOSBOX_DISK_IMAGE_PATH='.'
DOSBOX_DISK_IMAGE_TYPE='cdrom'

USER_PERSISTENT_DIRECTORIES='
arena_cd'
USER_PERSISTENT_FILES='
NAMES.DAT'

APP_MAIN_EXE='ACD.EXE'
APP_MAIN_OPTIONS='-SSBPDIG.ADV -IOS220 -IRQS7 -DMAS1 -MGENMIDI.ADV -IOM330 -IRQM2 -DMAM1'
APP_MAIN_ICON='ARENA.ICO'
APP_MAIN_DOSBOX_PRERUN='config -set cpu cycles=fixed 20000
d:'
# The type can not be omitted, because the binary is actually on the CD-ROM image.
APP_MAIN_TYPE='dosbox'

# Easier upgrade from pre-20190302.3 packages
PKG_MAIN_PROVIDES='
the-elder-scrolls-1-arena-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

# Include game data.

content_inclusion_icons
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
