use utf8;
use strict;

my $RT = 1.4;  # real-time speed factor to faster

my $hots = do 'sc-units-hots.inc.pl' or die $!;
my %unit;
for my $row (@{$hots}) {
	ref $row eq 'HASH' or next;
	for ($row, @{ $row->{special} }, @{ $row->{upgrade} }) {
		$_ *= $RT for $_->{speed} // ();
		$_ /= $RT for $_->{build} // (), $_->{transform} // (), $_->{warp} // (), $_->{cooldown} // ();
		$_->{cooldown} and $_->{cooldown} /= $RT for @{ $_->{attack} // [] };
	}
	$unit{ lc $row->{name} =~ tr/ /_/r } = $row;
}

[
'patch 4.1.4',

# protoss

$unit{probe},

$unit{photon_cannon},

{
	%{ $unit{mothership} },
	speed => 2.62,
},

$unit{nexus},

{
	%{ $unit{zealot} },
	special => [
		{
			name => 'Charge',
			abbr => 'ch',
			desc => 'on attack, increases movement speed to 8.47 for 2.5s and deals 8 damage on hit',
			min => 100, # changed in 3.14.0
			gas => 100,
			build => 100,
			speed => .5,
			range => 4,
			duration => 2.5,
			cooldown => 7,
		},
	],
	upgrade => [
		{
			name => 'Charge',
			speed => .98,
		},
	],
},

$unit{sentry},

{
	%{ $unit{stalker} },
	attack => [
		{
			%{ $unit{stalker}->{attack}->[0] }, # particle disruptors
			damage => 13,
			bonus => {
				armored => 5,
				-armored => 1,
			},
			cooldown => 1.34,
		},
	],
},

{
	race => 'protoss',
	cat => 'gateway',
	name => 'Adept',
	pop => 2,
	min => 100,
	gas => 25,
	build => 27,
	warp => 20,
	size => 1,
	cargo => 2,
	armor => 1,
	hp => 70,
	shield => 70,
	attr => {
		light => 1,
		organic => 1,
	},
	attack => [
		{
			anti => 1,
			name => undef, #TODO
			damage => 10,
			upgrade => 1,
			bonus => {
				light => 12,
				-light => 1,
			},
			type => 'projectile', #XXX: assumption
			cooldown => 1.61,
			range => 4,
		},
	],
	speed => 3.5,
	sight => 9,
	special => [
		{
			name => 'Psionic Transfer',
			abbr => 'pt',
			desc => 'project shade, teleport after 7s',
			cooldown => 11,

			alt => 'Shade',
			build => 0,
			size => 0,
			cargo => 0,
			hp => -1,
			attack => [], #TODO: indicate diff from parent
			speed => 5, #XXX: faster than 3.5
			range => 7, #XXX: calculate from speed
			sight => 4,
		},
	],
	upgrade => [
		{
			name => 'Resonating Glaives',
			min => 100,
			gas => 100,
			build => 100,
			attack => [
				{
					cooldown => -.5, # +45%
				},
			],
		},
	],
},

{
	%{ $unit{high_templar} },
	attack => [
		{
			anti => 1,
			name => '?', #XXX
			damage => 4,
			upgrade => 1,
			cooldown => 1.25,
			range => 6,
		},
	],
},

$unit{dark_templar},
$unit{archon},
$unit{observer},

{
	%{ $unit{warp_prism} },
	hp => 80,
	upgrade => [
		{
			%{ $unit{warp_prism}->{special}->[0] }, # gravitic drive
			speed => 1.23,
		},
	],
},

$unit{immortal},

{
	%{ $unit{colossus} },
	attack => [
		{
			%{ $unit{colossus}->{attack}->[0] }, # thermal lances
			damage => 10,
			upgrade => 1,
			bonus => {
				light => 5,
				-light => 1,
			},
#			cooldown => 1.18, #XXX
		},
	],
},

{
	race => 'protoss',
	cat => 'robotic',
	name => 'Disruptor',
	pop => 3,
	min => 150,
	gas => 150,
	build => 36,
	size => 1,
	cargo => 4,
	armor => 1,
	hp => 100,
	shield => 100,
	attr => {
		armored => 1,
		mech => 1,
	},
	attack => [
		{
			anti => 1,
			name => 'Purification Nova',
			damage => 145,
			bonus => {
				shields => 55,
			},
			type => 'trans', #TODO: indicate
			splash => 1.5,
			cooldown => 14.3,
			range => 13, # 2s
		},
	],
	speed => 3.15,
	sight => 9,
},

$unit{phoenix},

{
	%{ $unit{void_ray} },
	speed => 3.5,
},

{
	%{ $unit{oracle} },
	build => 37,
	attack => [
		{
			%{ $unit{oracle}->{attack}->[0] }, # pulsar beam
			bonus => {
				light => 7,
			},
		},
	],
	special => [
		{
			name => 'Revelation',
			abbr => 'rv',
			desc => 'hit enemy units and buildings are revealed for ½ minute',
			cost => 50,
			range => 9,
			cooldown => 2.2,
			duration => 30,
			radius => 6,
		},
		{
			name => 'Stasis Ward',
			abbr => 'sw',
			desc => 'places ward for 170s',
			cost => 50,
			range => 6,
			build => 3.58,
			duration => 170,
			alt => 'Stasis Ward',
			hp => 30,
			shield => 30,
			armor => 0,
			attr => {
				light => 1,
				structure => 1,
			},
			sight => 0,
			speed => 0,
			special => [
				{
					name => 'Permanent Cloak',
					abbr => 'cl',
					desc => 'cloaked at all times',
					duration => -1,
				},
				{
					name => 'Stasis Trap',
					abbr => 'st',
					desc => 'triggered by nearby ground units, trapping them for 21½s',
				},
			],
		},
	],
},

{
	%{ $unit{tempest} },
	hp => 300,
	shield => 150,
	attack => [
		{
			%{ $unit{tempest}->{attack}->[0] }, # kinetic overload
			bonus => {
				massive => 22,
				-massive => 2,
			},
		},
		{
			%{ $unit{tempest}->{attack}->[1] }, # resonance coil
			damage => 40,
			upgrade => 4,
		},
	],
},

{
	%{ $unit{carrier} },
	hp => 250,
	special => [
		{
			%{ $unit{carrier}->{special}->[0] }, # interceptor
			min => 5,
		},
	],
},

# terran

$unit{scv},
$unit{mule},
$unit{missile_turret},
$unit{planetary_fortress},

$unit{marine},

{
	%{ $unit{marauder} },
	attack => [
		{
			%{ $unit{marauder}->{attack}->[0] }, # punisher grenades
			count => 2,
			damage => 5,
			upgrade => 1,
			bonus => {
				armored => 5,
				-armored => 0,
			},
		},
	],
},

{
	%{ $unit{reaper} },
	build => 32,
},

{
	%{ $unit{ghost} },
	min => 150,
	gas => 125,
	speed => 3.94,
	special => [
		{
			# replaces Sniper Round
			name => 'Steady Targeting',
			abbr => 'st',
			desc => '170 damage ignoring armor to a biological unit after 1.43s without damage',
			cost => 50,
			range => 10,
			duration => 1.43,
		},
		$unit{ghost}->{special}->[1], # emp round
		$unit{ghost}->{special}->[2], # cloak
		$unit{ghost}->{special}->[3], # tac nuke strike
	],
},

{
	%{ $unit{hellion} },
	attack => [
		{
			%{ $unit{hellion}->{attack}->[0] }, # infernal flamethrower
			bonus => {
				light => 5,
				-light => 0,
			},
		},
	],
	#TODO smart servos
},

{
	%{ $unit{hellbat} },
	special => [
		$unit{hellbat}->{special}->[0], # Hellion Mode
		{
			name => 'Smart Servos',
			min => 100,
			gas => 100,
			build => 79,
			transform => -1.43, # halve #TODO: alter special duration?
		},
	],
},

{
	%{ $unit{widow_mine} },
	build => 21,
	attack => [
		{
			%{ $unit{widow_mine}->{attack}->[0] }, # Sentinel Missiles
			bonus => {
				shields => 25,
			},
		},
	],
},

{
	%{ $unit{siege_tank} },
	hp => 175,
	special => [
		{
			%{ $unit{siege_tank}->{special}->[0] }, # siege mode
			attack => [
				{
					%{ $unit{siege_tank}->{special}->[0]->{attack}->[0] }, # shock cannon
					damage => 40,
					upgrade => 4,
					bonus => {
						armored => 30,
						-armored => 1,
					},
					cooldown => 2.14,
				},
			],
		},
	],
},

{
	race => 'terran',
	cat => 'factory',
	name => 'Cyclone',
	pop => 3,
	min => 150,
	gas => 100,
	build => 32,
	size => 1.5,
	cargo => 3,
	armor => 1,
	hp => 180,
	attr => {
		armored => 1,
		mech => 1,
	},
	attack => [
		{
			anti => 1,
			name => 'Typhoon Blaster',
			damage => 3,
			upgrade => 1,
			bonus => {
				armored => 2,
				-armored => 0,
			},
			cooldown => .1,
			range => 6,
		},
	],
	speed => 4.13,
	sight => 11,
	special => [
		{
			name => 'Lock On',
			abbr => 'lo',
			desc => 'target air for 160 damage ignoring armor while visible and within 15 range',
			range => 7,
			duration => 14,
			cooldown => 4,
		},
		{
			name => 'Rapid Fire Launchers',
			abbr => 'rf',
			desc => 'rapid first 12 Lock On shots',
			min => 75,
			gas => 75,
			build => 79,
		},
	],
},

{
	%{ $unit{thor} },
	armor => 2,
	attack => [
		$unit{thor}->{attack}->[0],
		$unit{thor}->{attack}->[1],
		{
			%{ $unit{thor}->{attack}->[2] }, # high impact
			damage => 35,
			upgrade => 3,
			bonus => {
				armored => 15,
				-armored => 2,
			},
			cooldown => 2.14,
		},
	],
	#TODO smart servos
},

$unit{viking},
$unit{medivac},

{
	race => 'terran',
	cat => 'starport',
	name => 'Liberator',

	pop => 3,
	min => 150,
	gas => 150,
	build => 43,
	size => 1.5,
	armor => 0,
	hp => 180,
	attr => {
		armored => 1,
		mech => 1,
		flying => 1,
	},
	attack => [
		{
			anti => 2,
			name => 'Lexington Rockets',
			damage => 5,
			upgrade => 1,
			type => 'projectile',
			cooldown => 1.29,
			count => 2,
			range => 5,
		},
	],
	special => [
		{
			name => 'Defender Mode',
			abbr => 'dm',
			transform => 2.88, # 1.46s to revert
			alt => 'Defender Liberator',
			attack => [
				{
					anti => 1,
					name => 'Concord Cannon',
					desc => 'within 5 diameter circle',
					damage => 75,
					upgrade => 5,
					cooldown => 1.14,
					range => 10,
				},
			],
			speed => 0,
			sight => 15, # only targeted area
			upgrade => [
				{
					name => 'Advanced Ballistics',
					min => 150,
					gas => 150,
					build => 79,
					attack => [
						{
							range => 4,
						},
					],
					sight => 4,
				},
			],
		},
	],
	speed => 4.72,
	sight => 10,
},

$unit{banshee},

{
	%{ $unit{raven} },
	speed => 3.85,
	special => [
		{
			%{ $unit{raven}->{special}->[0] }, # auto-turret
			attack => [
				{
					anti => 3,
					name => '12 mm Gauss Cannon',
					damage => 18,
					cooldown => .57,
					range => 6,
				},
			],
			range => 1,
			duration => 10,
			upgrade => [
				$unit{raven}->{special}->[0]->{upgrade}->[0], # hi-sec auto tracking
				$unit{raven}->{special}->[0]->{upgrade}->[1], # structure armor
				# no more durable materials
			],
		},
		{
			name => 'Interference Matrix',
			abbr => 'im',
			desc => 'disable target mech or psionic unit rendering it unable to attack or cast',
			cost => 50,
			range => 9,
			duration => 7.9,
		},
		{
			name => 'Anti-Armor Missile',
			abbr => 'aa',
			desc => 'launches missile to do 30 splash damage and reduces armor by 3',
			range => 10,
			size => 2.88,
			attack => [
				{
					damage => 30,
					splash => 1,
				},
			],
			cost => 75,
			duration => 21,
		},
	],
},

$unit{battlecruiser},

# zerg

$unit{drone},

{
	%{ $unit{queen} },
	attack => [
		$unit{queen}->{attack}->[0], # claws
		{
			%{ $unit{queen}->{attack}->[1] }, # acid spines
			range => 8,
		},
	],
	range => 8,
},

{
	%{ $unit{overlord} },
	speed => .902, # changed in 4.0.0
	upgrade => [
		{
			%{ $unit{overlord}->{upgrade}->[0] }, # carapace
			speed => 2.63-.902,
		},
		$unit{overlord}->{upgrade}->[1], # sacs
	],
},

$unit{overseer},

$unit{larva},
$unit{spine_crawler},

{
	%{ $unit{spore_crawler} },
	attack => [
		{
			%{ $unit{spore_crawler}->{attack}->[0] }, # seeker spores
			bonus => {
				organic => 15,
			},
		},
	],
	speed => (1.5),
	creep => 2.6,
},

$unit{zergling},

{
	%{ $unit{baneling} },
	min => 25,
	upgrade => [
		{
			%{ $unit{baneling}->{upgrade}->[0] }, # centrifugal hooks
			hp => 5,
		},
	],
},

$unit{roach},

{
	race => 'zerg',
	cat => 'hatchery',
	name => 'Ravager',
	base => ['Roach'],
	pop => 3,
	min => 25,
	gas => 75,
	build => 9,
	size => 1.5,
	cargo => 4,
	armor => 1,
	hp => 120,
	attr => {
		organic => 1,
	},
	attack => [
		{
			anti => 1,
			name => '?',
			damage => 16,
			upgrade => 2,
			type => 'projectile',
			cooldown => 1.14,
			range => 6,
		},
	],
	speed => 3.85,
	creep => 1.3,
	sight => 9,
},

{
	%{ $unit{hydralisk} },
	hp => 90,
	upgrade => [
		{
			%{ $unit{hydralisk}->{upgrade}->[0] }, # grooved spines
			attack => [
				{
					range => 2,
				},
			],
		},
		$unit{hydralisk}->{upgrade}->[1], # muscular augments
	],
},

{
	race => 'zerg',
	cat => 'lair',
	name => 'Lurker',
	base => ['Hydralisk'],
	pop => 3,
	min => 50,
	gas => 100,
	build => 18,
	cargo => 4,
	armor => 1,
	hp => 200,
	attr => {
		armored => 1,
		organic => 1,
	},
	attack => [
		{
			anti => 1,
			name => '?',
			damage => 20,
			upgrade => 2,
			splash => 'line',
			cooldown => 1.43,
			range => 9,
			bonus => {
				armored => 10,
				-armored => 1,
			},
		},
	],
	speed => 4.13,
	creep => 1.3,
	sight => 10,
},

$unit{infestor},
$unit{nydus_worm},

{
	%{ $unit{swarm_host} },
	gas => 75,
	special => [
		{
			%{ $unit{swarm_host}->{special}->[0] }, # locust
			hp => 50,
		},
	],
	upgrade => [],
},

$unit{mutalisk},
$unit{corruptor},
$unit{brood_lord},
$unit{viper},

{
	%{ $unit{ultralisk} },
	armor => 2,
},

]
