*set oppo_hp 100
*temp lucy 1

*label your_turn

*gosub_scene ship_status_check

⚔️ [b]${ship_name} vs ${oppo_name}[/b]

[i]${ship_name}[/i] status: ${ship_status}

🛡️ Shields: ${shield_charge}%
*line_break
🔋 Battery power remaining: ${battery}
*line_break
🚇 Torpedoes: ${torpedoes}
*line_break

*gosub oppo_ship_status_check

[i]${oppo_name}[/i] status:  ${oppo_status}

[b]:::[/b] What do you want to do, Captain ${name}?

*fake_choice
	#🛰️ Scan [i]${oppo_name}[/i]
		*goto scan_ship
	*selectable_if (battery > 0) #🛡️ Adjust shield power
		*goto engage_shields
	*selectable_if (battery > 0) #💈 Fire phasers
		*goto fire_phasers
	*selectable_if (torpedoes > 0) #🚇 Fire a torpedo
		*goto fire_torpedo
	*selectable_if (fuel > 20) #💫 Make emergency warp jump
		*goto warp
	
*label scan_ship

*if sound
	*sound scan.wav

Scans reveal tactical information about [b]${oppo_name}[/b]:

🔰 Shields: Engaged
*line_break
🔋 Battery: ${oppo_battery}
*line_break
🚇 Torpedoes: ${oppo_torpedoes}
*line_break
📮 Hull integrity: ${oppo_hp}%

*page_break ${oppo_emoji}

*goto oppo_turn
	
*label engage_shields
	
⚔️ [b]${ship_name} vs ${oppo_name}[/b]

🔋 Battery power available: ${battery}

[b]:::[/b] How much power would you like to divert to the shields, Captain?

*temp shields 0

*input_number shields 0 battery

⚔️ [b]${ship_name} vs ${oppo_name}[/b]

*if shields = 0
	🛡️ Shields are now disengaged!
	*set shield_charge 0
	*goto a_menu

*if shields > 0
	*if sound
		*sound shieldcharge.wav

*set battery - shields
*set shield_charge + shields
	
🛡️ Shields now engaged to ${shield_charge}%

*label a_menu

[b]:::[/b] What do you want to do, Captain ${name}?

*fake_choice
	#🛰️ Scan the other ship
		*goto scan_ship
	*selectable_if (battery > 0) #💈 Fire phasers
		*goto fire_phasers
	*selectable_if (torpedoes > 0) #🚇 Fire a torpedo
		*goto fire_torpedo
	*selectable_if (fuel > 20) #💫 Make emergency warp jump
		*goto warp
	
*goto oppo_turn

*label fire_phasers

⚔️ [b]${ship_name} vs ${oppo_name}[/b]

🔋 Battery: ${battery}

[b]:::[/b] How much battery power would you like to divert to the phasers for the attack, Captain?

*temp phase_power 0

*input_number phase_power 1 battery

⚔️ [b]${ship_name} vs ${oppo_name}[/b]

*if sound
	*sound batterycharge.wav

Tactical reports phasers charged to ${phase_power}%.

*page_break 💥 Fire!

⚔️ [b]${ship_name} vs ${oppo_name}[/b]

*if sound
	*sound phaserblast.wav

*if oppo_torpedoes > 0
	*set oppo_shield_charge oppo_battery
	*set oppo_battery - oppo_shield_charge
	
*if (oppo_torpedoes = 0) and (torpedoes = 0)
	*set oppo_shield_charge (oppo_battery / 2)
	*set oppo_battery - oppo_shield_charge
	*set oppo_shield_charge round(oppo_shield_charge)
	*set oppo_battery round(oppo_battery)
	
*if (oppo_torpedoes = 0) and (torpedoes > 0)
	*set oppo_shield_charge (oppo_battery * 0.8)
	*set oppo_battery - oppo_shield_charge
	*set oppo_shield_charge round(oppo_shield_charge)
	*set oppo_battery round(oppo_battery)

*set battery - phase_power

💈 You light up the [i]${oppo_name}[/i] with your phasers.

*if oppo_shield_charge >= phase_power
	*set oppo_shield_charge - phase_power
	*set phase_power 0
	🔰 The [i]${oppo_name}[/i]'s shields completely absorb your phaser blast.
	
*if oppo_shield_charge < phase_power
	*set phase_power - oppo_shield_charge
	*set battery + phase_power
	*set oppo_hp - phase_power
	*set phase_power 0
	
*if oppo_hp < 1
	*goto you_won

*page_break ${oppo_emoji}

*goto oppo_turn

*label fire_torpedo

⚔️ [b]${ship_name} vs ${oppo_name}[/b]

*if sound
	*sound fillsack.wav

🚇 Torpedo ready to launch.

*set torpedoes - 1

*page_break 💥 Fire!

*if sound
	*sound torpedofire.wav

⚔️ [b]${ship_name} vs ${oppo_name}[/b]

🚇 Tactical reports a direct hit!

*if oppo_shield_charge >= 90
	*set oppo_shield_charge - 90
	🛡️ The [i]${oppo_name}[/i]'s shields completely absorbed your torpedo strike.
	
*if oppo_shield_charge < 90
	*set damage (90 - oppo_shield_charge)
	*set oppo_shield_charge 0
	*set oppo_hp - damage
	🛡️ Your torpedo strike obliterates the [i]${oppo_name}[/i]'s shields.
	
*if oppo_hp < 1
	*goto you_won

📉 Tactical reports that the ${oppo_name}'s hull integrity is now at [b]${oppo_hp}[/b]%

*page_break ${oppo_emoji}

*goto oppo_turn

*label oppo_turn

⚔️ [b]${ship_name} vs ${oppo_name}[/b]

*if oppo_hp < 31
	*if sound
		*sound enemywarp.mp3
		
	💫 Tactical reports that [i]${oppo_name}[/i] is spinning up its warp drive!
	
	A moment later, the ship disappears in a flash of light.
	
	*page_break 😌
	*if trader_present = true
		*rand trader1_quadrant 1 111
		*rand trader2_quadrant 1 111
		*rand trader3_quadrant 1 111
		*rand trader4_quadrant 1 111
		*rand trader5_quadrant 1 111
		
	*goto_scene startrip_main

*if oppo_torpedoes > 0
	*goto oppo_torpedo

*goto oppo_phaser

Mistake happened!

*ending

*label oppo_phaser

💈 The [i]${oppo_name}[/i] rakes your hull with phaser fire.

*if sound
	*sound phaserblast.wav

*if oppo_battery >= shield_charge
	*set damage (oppo_battery - shield_charge)
	*set ship_hp - damage
	*set oppo_battery 0
	*set oppo_battery + oppo_shield_charge
	*set shield_charge 0
	*set oppo_shield_charge 0
	📉 Tactical reports hull integrity is now at [b]${ship_hp}[/b]%
	
*if ship_hp < 1
	*goto you_dead

*if shield_charge > oppo_battery
	*set shield_charge - oppo_battery
	*set oppo_battery 0
	*set oppo_battery + oppo_shield_charge
	*set oppo_shield_charge 0
	🛡️ Your shields managed to absorb the phaser fire.
	
*set battery + shield_charge
*set shield_charge 0
	
*page_break ${player_emoji}
*goto your_turn


*label oppo_torpedo

*set oppo_torpedoes - 1

*if sound
	*sound torpedofire.wav

The [i]${oppo_name}[/i] has launched a torpedo!

💥  Direct hit!

*if shield_charge >= 90
	Thankfully, your shields absorbed the blast from the torpedo strike.
	*set shield_charge -90
	*page_break
	*goto your_turn

*if shield_charge < 90
	*set damage (90 - shield_charge)
	*set shield_charge 0
	*set ship_hp - damage
	*if ship_hp > 0
		The torpedo strike completely destroyed your shields.
		
*if ship_hp < 1
	*goto you_dead

📉 Tactical reports hull integrity is now at [b]${ship_hp}[/b]%

*set oppo_battery + oppo_shield_charge
*set oppo_shield_charge 0

*page_break
*goto your_turn

*label warp

*if sound
	*sound emergency.wav

Without hesitating, you punch in the codes to execute an emergency warp jump in order to flee the [i]${oppo_name}[/i].

*page_break 💫 Engage!

*if sound
	*sound fuelburn.mp3

*if story_mode = true
	*rand quadrant 1 111
	*rand sector 1 4
	
*if story_mode = false
	*rand dieroll 1 11
	*temp gringo ""
	*set gringo "starbase${dieroll}_quadrant"
	*set quadrant {gringo}
	*set gringo "starbase${dieroll}_sector"
	*set sector {gringo}

*temp fuel_burn 0
*set fuel_burn fuel

*set fuel (fuel / 3)
*set fuel round(fuel)
*set fuel_burn (fuel_burn - fuel)

🔥 Fuel burned: ${fuel_burn}
*line_break
Fuel remaining: ${fuel}
*line_break

*goto_scene startrip_main

*label oppo_ship_status_check
	
*if oppo_hp < 100
	*set oppo_status "Amber 🟠" 

*if oppo_hp < 50
	*set oppo_status "Red 🔴"


*return

*label you_won

*page_break 💥

🌌  [b]Current Location[/b]: Quadrant ${quadrant}, Sector ${sector}

*check_achievements
*if choice_achieved_red_baron = false
	*achieve red_baron

*gosub salvage

*if sound
	*sound ship-explosion.mp3

A moment later, you see [i]${oppo_name} [/i] explode in a fiery ball of light.

Scanners track an escape pod as it escapes the debris field.

Salvageable material from the wreckage:

$!{salvage_resource}: ${salvage_units} units

::: What do you want to do, Captain?

*fake_choice
	*selectable_if (cargo_space_free > 0) #📦 Salvage resources
	#🛥️  Navigate away from the debris field
			*goto_scene startrip_main
		
🌌  [b]Current Location[/b]: Quadrant ${quadrant}, Sector ${sector}

*if sound
	*sound teleport.wav
	
*temp taken_units 0

*if cargo_space_free >= salvage_units
	*set taken_units salvage_units
	
*if cargo_space_free < salvage_units
	*set taken_units cargo_space_free
	
*if salvage_resource = resource1
	*set resource1_carrying + taken_units
	
*if salvage_resource = resource2
	*set resource2_carrying + taken_units
	
*if salvage_resource = resource3
	*set resource3_carrying + taken_units
	
*if salvage_resource = resource4
	*set resource4_carrying + taken_units
	
*if salvage_resource = resource5
	*set resource5_carrying + taken_units
	
*if salvage_resource = resource6
	*set resource6_carrying + taken_units
	
*if salvage_resource = resource7
	*set resource7_carrying + taken_units
	
*if salvage_resource = resource8
	*set resource8_carrying + taken_units
	
*if salvage_resource = resource9
	*set resource9_carrying + taken_units
	
*if salvage_resource = resource10
	*set resource10_carrying + taken_units
	
*if salvage_resource = resource11
	*set resource11_carrying + taken_units
	
*set cargo_space_free - taken_units

*if taken_units > 1
	Using ${ship_name}'s tractor beam, you bring ${taken_units} units of ${salvage_resource} on board the ${ship_name}.
	
*if taken_units = 1
	Using ${ship_name}'s tractor beam, you bring one unit of ${salvage_resource} on board the ${ship_name}.

After the last unit is properly stowed away, you take a brief moment to salute all those who were on board [i]${oppo_name}[/i].

*page_break 😌

*goto_scene startrip_main

*label salvage

*temp salvage_resource ""

*rand dieroll 1 11

*if dieroll = 1
	*set salvage_resource resource1
	
*if dieroll = 2
	*set salvage_resource resource2
	
*if dieroll = 3
	*set salvage_resource resource3
	
*if dieroll = 4
	*set salvage_resource resource4
	
*if dieroll = 5
	*set salvage_resource resource5
	
*if dieroll = 6
	*set salvage_resource resource6
	
*if dieroll = 7
	*set salvage_resource resource7
	
*if dieroll = 8
	*set salvage_resource resource8
	
*if dieroll = 9
	*set salvage_resource resource9
	
*if dieroll = 10
	*set salvage_resource resource10
	
*if dieroll = 11
	*set salvage_resource resource11
	
*if pirate_present
	*rand dieroll 10 100
	
*if trader_present
	*rand dieroll 2 17
	
*if police_alerted
	*rand dieroll 2 7
	
*temp salvage_units 0
*set salvage_units dieroll
	
*return

*label you_dead

*check_achievements
*if choice_achieved_loser = false
	*achieve loser

*page_break

*if sound
	*sound explosion.mp3

Realizing that your ship is in imminent peril of destruction, you run to the escape pod.

A moment later, your ship disintegrates into a million pieces.

*set ship_class "🔸 Dunkirk"
*set ship_name "escape pod from ${ship_name}"
*set fuel_max 20
*set fuel 20
*set battery_max 50
*set battery 50
*set cargo_holds 1
*set cargo_space_free 1
*set speed 1
*set torpedoes_max 0
*set passengers_max 0
*set berths_available passengers_max
*set passengers_carrying 0

*set ship_hp 100

*set resource1_carrying 0
*set resource2_carrying 0
*set resource3_carrying 0
*set resource4_carrying 0
*set resource5_carrying 0
*set resource6_carrying 0
*set resource7_carrying 0
*set resource8_carrying 0
*set resource9_carrying 0
*set resource10_carrying 0
*set resource11_carrying 0
*set colonists_carrying 0

Engaging emergency thrusters, you narrowly avoid sustaining damage from the debris field.

Through the tiny forward window, you watch [i]${oppo_name}[/i] begin salvage operations to recover the materials from your former ship.

*page_break 😌

*set sector +1
*if sector = 5
	*set sector 1
	
*goto_scene startrip_main

*label oppo_flees