# Copyright (c) 2020 by Peter van der Meer
#
# Endless Sky is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later version.
#
# Endless Sky is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <https://www.gnu.org/licenses/>.

test-data "Three Earthly Barges Save"
	category "savegame"
	contents
		pilot Bobbi Bughunter
		date 16 11 3013
		system Sol
		planet Earth
		clearance
		# Set some reputations to positive to avoid combat
		"reputation with"
			Bounty 1
			"Bounty Hunter" 1
			Pirate 1
		# What you own:
		ship "Star Barge"
			name "Buggy Barge"
			sprite "ship/star barge"
			attributes
				category "Light Freighter"
				cost 190000
				mass 70
				bunks 3
				"cargo space" 50
				drag 2.1
				"engine capacity" 400
				"fuel capacity" 300
				"heat dissipation" 0.8
				hull 1000
				"outfit space" 1300
				"required crew" 1
				shields 600
				"turret mounts" 1
				"weapon capacity" 200
			outfits
				"X1700 Ion Thruster"
				"X1200 Ion Steering"
				Hyperdrive
				"Anti-Missile Turret"
				"D14-RN Shield Generator"
				"nGVF-BB Fuel Cell"
				"LP036a Battery Pack"
			crew 1
			fuel 300
			shields 600
			hull 1000
			engine -9 38 1
			engine 9 38 1
			turret 0 -8 "Anti-Missile Turret"
			leak leak 60 50
			explode "tiny explosion" 10
			explode "small explosion" 10
			system Sol
			planet Earth
		ship "Star Barge"
			name "Critical Container"
			sprite "ship/star barge"
			attributes
				category "Light Freighter"
				cost 190000
				mass 70
				bunks 3
				"cargo space" 50
				drag 2.1
				"engine capacity" 400
				"fuel capacity" 300
				"heat dissipation" 0.8
				hull 1000
				"outfit space" 1300
				"required crew" 1
				shields 600
				"turret mounts" 1
				"weapon capacity" 200
			outfits
				"X1700 Ion Thruster"
				"X1200 Ion Steering"
				Hyperdrive
				"Anti-Missile Turret"
				"D14-RN Shield Generator"
				"nGVF-BB Fuel Cell"
				"LP036a Battery Pack"
			crew 1
			fuel 300
			shields 600
			hull 1000
			engine -9 38 1
			engine 9 38 1
			turret 0 -8 "Anti-Missile Turret"
			leak leak 60 50
			explode "tiny explosion" 10
			explode "small explosion" 10
			system Sol
			planet Earth
		ship "Star Barge"
			name "Errorous Enclosement"
			sprite "ship/star barge"
			attributes
				category "Light Freighter"
				cost 190000
				mass 70
				bunks 3
				"cargo space" 50
				drag 2.1
				"engine capacity" 400
				"fuel capacity" 300
				"heat dissipation" 0.8
				hull 1000
				"outfit space" 1300
				"required crew" 1
				shields 600
				"turret mounts" 1
				"weapon capacity" 200
			outfits
				"X1700 Ion Thruster"
				"X1200 Ion Steering"
				Hyperdrive
				"Anti-Missile Turret"
				"D14-RN Shield Generator"
				"nGVF-BB Fuel Cell"
				"LP036a Battery Pack"
			crew 1
			fuel 300
			shields 600
			hull 1000
			engine -9 38 1
			engine 9 38 1
			turret 0 -8 "Anti-Missile Turret"
			leak leak 60 50
			explode "tiny explosion" 10
			explode "small explosion" 10
			system Sol
			planet Earth
		account
			credits 131000
			score 400
			history
		cargo
			commodities
				Food 150
		visited Sol
		"visited planet" Earth
		visited "Alpha Centauri"
		visited "Vega"
		visited "Menkent"


test-data "Fighters and Carriers and Escorts Save"
	category "savegame"
	contents
		pilot Bobby Bughunter
		date 16 11 3013
		system Rutilicus
		planet "New Boston"
		clearance
		"map coloring" -6
		"map zoom" 0
		account
			credits 200000000
		conditions
			"Intro [0]: declined"
			"Intro [0]: offered"
		ship Finch
			name "Flame Meteor"
			sprite ship/finch
			thumbnail thumbnail/finch
			attributes
				category Fighter
				cost 126000
				mass 40
				bunks 1
				drag 0.83
				"engine capacity" 400
				"gun ports" 2
				"heat dissipation" 0.85
				hull 200
				"outfit space" 1100
				"required crew" 1
				shields 1100
				"weapon capacity" 200
			outfits
				"Emergency Ramscoop"
				Flamethrower
				"Fuel Pod"
				"Meteor Missile" 30
				"Meteor Missile Launcher"
				"Millennium Cell"
				"Small Heat Shunt"
				"Small Steering Module"
				"Small Thrust Module"
				Supercapacitor
				"Thruster (Comet Class)"
			crew 1
			fuel 100
			shields 1100
			hull 200
			position 0 0
			engine -5 32
				zoom 1
				angle 0
				under
			engine 5 32
				zoom 1
				angle 0
				under
			gun -7 -14 "Meteor Missile Launcher"
				under
			gun 7 -14 Flamethrower
				under
			explode "small explosion" 5
			explode "tiny explosion" 15
			system Rutilicus
			planet "New Boston"
		ship Finch
			name "Torpedo Javelin"
			sprite ship/finch
			thumbnail thumbnail/finch
			attributes
				category Fighter
				cost 126000
				mass 40
				bunks 1
				drag 0.83
				"engine capacity" 400
				"gun ports" 2
				"heat dissipation" 0.85
				hull 200
				"outfit space" 1100
				"required crew" 1
				shields 1100
				"weapon capacity" 200
			outfits
				"Emergency Ramscoop"
				"Fuel Pod"
				Javelin 200
				"Javelin Pod"
				"Millennium Cell"
				"Small Heat Shunt"
				"Small Steering Module"
				"Small Thrust Module"
				Supercapacitor
				"Thruster (Comet Class)"
				Torpedo 3
				"Torpedo Pod"
			crew 1
			fuel 100
			shields 1100
			hull 200
			position 0 0
			engine -5 32
				zoom 1
				angle 0
				under
			engine 5 32
				zoom 1
				angle 0
				under
			gun -7 -14 "Torpedo Pod"
				under
			gun 7 -14 "Javelin Pod"
				under
			explode "small explosion" 5
			explode "tiny explosion" 15
			system Rutilicus
			planet "New Boston"
		ship Bactrian
			name "Sidewinder Tracker Carrier"
			sprite ship/bactrian
			thumbnail thumbnail/bactrian
			uuid b80ffe76-5796-4b56-a481-c85c8e561bdb
			attributes
				category "Heavy Warship"
				cost 17600000
				mass 940
				bunks 245
				"cargo space" 530
				drag 16.1
				"engine capacity" 1800
				"fuel capacity" 700
				"gun ports" 4
				"heat dissipation" 0.4
				hull 8600
				"outfit space" 7400
				"required crew" 70
				shields 17500
				"turret mounts" 6
				"weapon capacity" 3000
			outfits
				"Antimatter Core"
				"Hai Tracker" 112
				"Hai Tracker Pod" 2
				Hyperdrive
				"Large Battery Module"
				"Large Radar Jammer"
				"Laser Rifle" 15
				"Quarg Skylance" 2
				Ramscoop
				"Sidewinder Missile" 90
				"Sidewinder Missile Launcher" 2
				"Systems Core (Large)"
				"Tier 3 Anti-Missile"
				"X4700 Ion Thruster"
				"X5200 Ion Steering"
			crew 72
			fuel 700
			shields 17500
			hull 8600
			position 0 0
			engine -18 230
				zoom 1
				angle 0
				under
			engine 18 230
				zoom 1
				angle 0
				under
			gun -15 -226 "Hai Tracker Pod"
				under
			gun 15 -226 "Hai Tracker Pod"
				under
			gun -40 -133 "Sidewinder Missile Launcher"
				under
			gun -45 -128 "Sidewinder Missile Launcher"
				under
			turret -22 -148 "Quarg Skylance"
				over
			turret 26 -80
				over
			turret -41 -20
				over
			turret 32 -7 "Tier 3 Anti-Missile"
				over
			turret 53 82
				over
			turret -37 186 "Quarg Skylance"
				over
			bay Fighter -38 -26
				"launch effect" "basic launch"
			bay Fighter 35 36
				"launch effect" "basic launch"
			bay Fighter -47 97
				"launch effect" "basic launch"
			leak leak 30 50
			leak flame 30 80
			leak "big leak" 50 30
			explode "huge explosion" 30
			explode "large explosion" 45
			explode "medium explosion" 35
			explode "small explosion" 25
			"final explode" "final explosion large" 1
			system Rutilicus
			planet "New Boston"
		ship "Aerie"
			name "Sidewinder Carrier"
			sprite "ship/aerie"
			thumbnail "thumbnail/aerie"
			attributes
				category "Medium Warship"
				"cost" 3500000
				"shields" 5700
				"hull" 1900
				"required crew" 10
				"bunks" 28
				"mass" 130
				"drag" 4.1
				"heat dissipation" .7
				"fuel capacity" 500
				"cargo space" 50
				"outfit space" 3900
				"weapon capacity" 1500
				"engine capacity" 950
				weapon
					"blast radius" 80
					"shield damage" 800
					"hull damage" 400
					"hit force" 1200
			outfits
				"Sidewinder Missile Launcher" 2
				"Sidewinder Missile" 136
				"Sidewinder Missile Rack" 2
				"Heavy Laser Turret" 2
				"Heavy Anti-Missile Turret"

				"NT-200 Nucleovoltaic"
				"KP-6 Photovoltaic Panel" 2
				"LP072a Battery Pack"
				"D41-HY Shield Generator"
				"Large Radar Jammer"
				"Laser Rifle" 3

				"X3700 Ion Thruster"
				"X3200 Ion Steering"
				"Hyperdrive"
			crew 10
			fuel 500
			shields 5700
			hull 1900
			position 0 0
			engine -10 91
			engine 10 91
			gun -13 -79 "Sidewinder Missile Launcher"
			gun 13 -79 "Sidewinder Missile Launcher"
			turret 0 0 "Heavy Anti-Missile Turret"
			turret -17 14 "Heavy Laser Turret"
			turret 17 14 "Heavy Laser Turret"
			bay "Fighter" -42 -2
			bay "Fighter" 42 2
			leak "leak" 50 50
			leak "flame" 50 80
			leak "big leak" 90 30
			explode "tiny explosion" 10
			explode "small explosion" 25
			explode "medium explosion" 25
			explode "large explosion" 10
			"final explode" "final explosion medium"
			system Rutilicus
			planet "New Boston"
		ship Sparrow
			name "Escort 1"
			sprite ship/sparrow
			thumbnail thumbnail/sparrow
			attributes
				category Interceptor
				cost 225000
				mass 50
				bunks 2
				"cargo space" 15
				drag 0.9
				"engine capacity" 400
				"fuel capacity" 300
				"gun ports" 2
				"heat dissipation" 0.8
				hull 300
				"outfit space" 1300
				"required crew" 1
				shields 1200
				"weapon capacity" 200
			outfits
				"Beam Laser" 2
				"Chipmunk Plasma Steering"
				"Chipmunk Plasma Thruster"
				"D14-RN Shield Generator"
				Hyperdrive
				"LP036a Battery Pack"
				"nGVF-BB Fuel Cell"
			crew 1
			fuel 300
			shields 1200
			hull 300
			position 0 0
			engine -5 35
				zoom 1
				angle 0
				under
			engine 5 35
				zoom 1
				angle 0
				under
			gun -7 -10 "Beam Laser"
				under
			gun 7 -10 "Beam Laser"
				under
			leak flame 60 80
			explode "small explosion" 5
			explode "tiny explosion" 15
			system Sol
			planet Earth
		ship Sparrow
			name "Escort 2"
			sprite ship/sparrow
			thumbnail thumbnail/sparrow
			attributes
				category Interceptor
				cost 225000
				mass 50
				bunks 2
				"cargo space" 15
				drag 0.9
				"engine capacity" 400
				"fuel capacity" 3000
				"gun ports" 2
				"heat dissipation" 0.8
				hull 300
				"outfit space" 1300
				"required crew" 1
				shields 1200
				"weapon capacity" 200
			outfits
				"Beam Laser" 2
				"Chipmunk Plasma Steering"
				"Chipmunk Plasma Thruster"
				"D14-RN Shield Generator"
				Hyperdrive
				"LP036a Battery Pack"
				"nGVF-BB Fuel Cell"
			crew 1
			fuel 300
			shields 1200
			hull 300
			position 0 0
			engine -5 35
				zoom 1
				angle 0
				under
			engine 5 35
				zoom 1
				angle 0
				under
			gun -7 -10 "Beam Laser"
				under
			gun 7 -10 "Beam Laser"
				under
			leak flame 60 80
			explode "small explosion" 5
			explode "tiny explosion" 15
			system Sol
			planet Earth
		visited Rutilicus
		"visited planet" "New Boston"
		visited Sol
		"visited planet" "Earth"
		visited Vega
		visited Menkent


test "Open Menu"
	status partial
	description "Helper function to open the in-game menu."
	sequence
		input
			key "escape"


test "Load First Savegame"
	status partial
	description "Helper function to load the first savegame. Typically used directly after save-game inject."
	sequence
		input
			key l
		input
			key l


test "Create New Pilot"
	status partial
	description "Helper function to create a new pilot."
	sequence
		input
			key l
		# new pilot
		input
			key n
		# start
		input
			key s
		# first name: a
		input
			key a
		input
			key "return"
		# last name: b
		input
			key b
		input
			key "return"
		# skip text
		input
			key "return"
		# go to the main landing panel
		input
			key l


test "Buy First Ship"
	status partial
	description "Helper function to buy the first ship of the shipyard, starting from the planet panel."
	sequence
		input
			key s
		# buy first ship
		input
			key "down"
		input
			key b
		# confirm
		input
			key "return"
		# back to landing
		input
			key l


test "Wait 55 steps"
	status partial
	description "Wait 55 steps for something that requires some time, like launching or loading the game."
	sequence
		apply
			"test: wait 55" = 55
		label wait_load
		apply
			"test: wait 55" -= 1
		input
		branch wait_load
			"test: wait 55" > 0


test "Wait 10 steps"
	status partial
	description "Wait 10 steps, for instance to give time for the game to propagate conditions, or load something."
	sequence
		apply
			"test: wait 10" = 10
		label wait
		apply
			"test: wait 10" -= 1
		input
		branch wait
			"test: wait 10" > 0


test "Start Game"
	status active
	description "Test if one can start the game correctly: choose a name and buy a ship."
	sequence
		watchdog 1000
		call "Create New Pilot"
		# the game needs a few steps to load the new pilot
		call "Wait 55 steps"
		call "Buy First Ship"
		# game needs time to process showing the mission
		call "Wait 10 steps"
		# beat it, old timer
		input
			key 3
		input
			key "return"
		# to be sure
		input
			key l
		# normally the mission being launched means the conditions are refreshed (or they always are?) and we don't need to launch
		# but to be sure:
		# save these in temporary conditions to know what they are if it fails, for easier debugging
		apply
			"test: Intro [0]: offered" = "Intro [0]: offered"
			"test: Intro [0]: declined" = "Intro [0]: declined"
			"test: ship model: Shuttle" = "ship model: Shuttle"
			"test: ship model: Sparrow" = "ship model: Sparrow"
			"test: ship model: Star Barge" = "ship model: Star Barge"
		assert
			"name: a b" == 1
			"total ships" == 1
			# Not checking for the intro mission conditions because the test shouldn't fail if the mission isn't offered or its name changes.


test "Save To Default Snapshot"
	status active
	description "Helper function to save the game to the first snapshot. Typically used directly after opening the menu."
	sequence
		# Open the menu.
		# Future versions should detect if the menu is active and only open the menu when required.
		# But the derived test-conditions that are required for such detection are not yet available.
		input
			key "escape"
		# Go to Load/Save.
		input
			key l
		# Add snapshot.
		input
			key a
		# Confirm usage of the default snapshot name.
		input
			key "Return"
		# Exit the menu that we are in (and return to the game)
		input
			key b
		input
			key e


test "Depart"
	status partial
	description "Helper function to depart from a planet."
	sequence
		input
			key d
		# The game needs 2 gamesteps for processing the launch before commands like the jump command can be given.
		# Using empty inputs to trigger those game loops.
		input
		input
		# The ships zoom gets restored at a rate of .02 per step, so wait for a bit more than 50 steps to get to full zoom/full control.
		call "Wait 55 steps"


test "Depart and Ignore Warning Message"
	status partial
	description "Helper function to depart from a planet when a message requiring acknowledgement via keyboard input is expected."
	sequence
		input
			key d
		# The game needs 2 gamesteps for processing the launch before commands like the jump command can be given.
		# Using empty inputs to trigger those game loops.
		input
		input
		# Acknowledge the expected message
		input
			key "Return"
		# The ships zoom gets restored at a rate of .02 per step, so wait for a bit more than 50 steps to get to full zoom/full control.
		call "Wait 55 steps"


test "Depart and Abort on Warning Message"
	status partial
	description "Helper function to attempt departure from a planet, then stop when an expected warning message is given."
	sequence
		input
			key d
		# The game needs 2 gamesteps for processing the launch before commands like the jump command can be given.
		# Using empty inputs to trigger those game loops.
		input
		input
		# Acknowledge the expected message and abort take off.
		input
			key "Escape"


test "Sell first ship"
	status partial
	description "Test procedure that handles selling of the first ship in the list."
	sequence
		# Goto shipyard
		input
			key "s"
		# Sell the first ship
		input
			key "s"
		input
			key "Return"
		# Go back to the planet menu.
		input
			key "l"



test "Land"
	status partial
	description "Helper for landing."
	sequence
		input
			command land
		label "landing"
		# empty input to make time pass
		input
		branch "landing"
			"flagship landed" == 0



test "Trigger Ruin Spaceport Mission"
	status partial
	description "Launch, land, and go to the spaceport to trigger any potential missions."
	sequence
		call "Depart"
		call "Land"
		input
			key p


test "Trigger Prime Spaceport Mission"
	status partial
	description "Launch, land, and go to the spaceport to trigger any potential missions."
	sequence
		call "Depart"
		call "Land"
		input
			key p


test "Skip Spaceport Mission"
	status partial
	description "Just skip a mission by pressing return twice."
	sequence
		# press accept (or decline, depending on if it is shown) and then skip the dialog once
		input
			key "Return"
		input
			key "Return"
