• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Difference between revisions of "Module:ShipCapabilities"

From Kancolle Wiki
Jump to navigation Jump to search
com>Ckwng
(Add artillery spotting multipliers, fix unarmed night battle case)
com>Ckwng
(Separate presentation and data)
Line 59: Line 59:
 
-- },
 
-- },
 
-- },
 
-- },
 +
_day_battle_modes = {
 +
[1] = "Shelling",
 +
[2] = "Bombing",
 +
[3] = "Bombing, displayed as Shelling",
 +
},
 +
_artillery_spotting_modes = {
 +
[1] = "Double Attack (120% x2)",
 +
[2] = "Double Attack (120% x2) / Cut-in: Secondary Gun (110%)",
 +
[3] = "Double Attack (120% x2) / Cut-in: AP (150%)",
 +
[4] = "Cut-in: Secondary Gun (110%)",
 +
[5] = "Cut-in: Secondary Gun (110%) / Cut-in: Radar (120%)",
 +
[6] = "Cut-in: Secondary Gun (110%) / Cut-in: AP (130%)",
 +
},
 +
_night_battle_modes = {
 +
[1] = "Single Attack",
 +
[2] = "Single Torpedo",
 +
[3] = "Double Attack",
 +
[4] = "Cut-in: Main Gun",
 +
[5] = "Cut-in: Secondary Gun",
 +
[6] = "Cut-in: Mixed",
 +
[7] = "Cut-in: Torpedo",
 +
[8] = "Bombing",
 +
},
 +
_night_battle_attack_counts = {
 +
[3] = "x2",
 +
[6] = "x2",
 +
[7] = "x2",
 +
},
 +
_asw_attack_modes = {
 +
day = "Day",
 +
night = "Night",
 +
},
 
}
 
}
  
Line 86: Line 118:
 
return ship_type == 2
 
return ship_type == 2
 
or ship_type == 3
 
or ship_type == 3
 +
or ship_type == 4
 
or ship_type == 21
 
or ship_type == 21
 
end
 
end
Line 222: Line 255:
 
local firepower = self._ship:firepower_leveled()
 
local firepower = self._ship:firepower_leveled()
 
if not firepower then
 
if not firepower then
return "??"
+
return nil
 
end
 
end
 
local is_installation = self:_is_installation()
 
local is_installation = self:_is_installation()
Line 236: Line 269:
 
end
 
end
 
end
 
end
return format{"Shelling (${attack_power})", attack_power = self:_attack_power_cap(firepower + 5, 150)}
+
return 1, self:_attack_power_cap(firepower + 5, 150)
 
end
 
end
 
else
 
else
Line 267: Line 300:
 
end
 
end
 
if has_planes then
 
if has_planes then
return format{is_installation and "Bombing, displayed as Shelling (${attack_power})" or "Bombing (${attack_power})", attack_power = self:_attack_power_cap(1.5 * (firepower + torpedo) + bombing * 2 + 55, 150)}
+
return is_installation and 3 or 2, self:_attack_power_cap(1.5 * (firepower + torpedo) + bombing * 2 + 55, 150)
 
end
 
end
 
end
 
end
 
end
 
end
 
end
 
end
return "No Action"
+
return false
 +
end
 +
 
 +
function ShipCapabilities:format_day_battle(mode, attack_power)
 +
if mode then
 +
return format{self._attack_template, mode = self._day_battle_modes[mode], attack_power = attack_power}
 +
elseif mode == false then
 +
return "No Action"
 +
end
 +
return "??"
 
end
 
end
  
Line 287: Line 329:
 
end
 
end
 
end
 
end
return format{"Yes (${attack_power})", attack_power = self:_attack_power_cap(torpedo + 5, 150)}
+
return self:_attack_power_cap(torpedo + 5, 150)
 +
end
 +
return false
 +
end
 +
 
 +
function ShipCapabilities:format_torpedo(attack_power)
 +
if attack_power then
 +
return tostring(attack_power)
 
end
 
end
return "None"
+
return "No"
 
end
 
end
 +
 +
ShipCapabilities.format_closing_torpedo = ShipCapabilities.format_torpedo
  
 
function ShipCapabilities:artillery_spotting()
 
function ShipCapabilities:artillery_spotting()
 
local total_space = self._ship:total_space()
 
local total_space = self._ship:total_space()
 
if not total_space or total_space <= 0 then
 
if not total_space or total_space <= 0 then
return "No"
+
return false
 
end
 
end
 
local main_guns, secondary_guns, seaplanes, radars, ap_shells = 0, 0, 0, 0, 0
 
local main_guns, secondary_guns, seaplanes, radars, ap_shells = 0, 0, 0, 0, 0
Line 317: Line 368:
 
if main_guns >= 2 then
 
if main_guns >= 2 then
 
if ap_shells >= 1 then
 
if ap_shells >= 1 then
return "Double Attack (120% x2) / Cut-in: AP (150%)"
+
return 3
 
elseif secondary_guns >= 1 then
 
elseif secondary_guns >= 1 then
return "Double Attack (120% x2) / Cut-in: Secondary Gun (110%)"
+
return 2
 
end
 
end
return "Double Attack (120% x2)"
+
return 1
 
elseif main_guns == 1 and secondary_guns >= 1 then
 
elseif main_guns == 1 and secondary_guns >= 1 then
 
if radars >= 1 then
 
if radars >= 1 then
return "Cut-in: Secondary Gun (110%) / Cut-in: Radar (120%)"
+
return 5
 
elseif ap_shells >= 1 then
 
elseif ap_shells >= 1 then
return "Cut-in: Secondary Gun (110%) / Cut-in: AP (130%)"
+
return 6
 
end
 
end
return "Cut-in: Secondary Gun (110%)"
+
return 4
 
end
 
end
 +
end
 +
return false
 +
end
 +
 +
function ShipCapabilities:format_artillery_spotting(mode)
 +
if mode then
 +
return self._artillery_spotting_modes[mode]
 
end
 
end
 
return "No"
 
return "No"
Line 337: Line 395:
 
local main_guns, secondary_guns, torpedoes, has_planes, firepower, torpedo = 0, 0, 0, false, self._ship:firepower_leveled(), self._ship:torpedo_leveled()
 
local main_guns, secondary_guns, torpedoes, has_planes, firepower, torpedo = 0, 0, 0, false, self._ship:firepower_leveled(), self._ship:torpedo_leveled()
 
if not firepower or not torpedo then
 
if not firepower or not torpedo then
return "Unknown"
+
return nil
 
end
 
end
 
for i = 1, self._ship:slots() or 0 do
 
for i = 1, self._ship:slots() or 0 do
Line 367: Line 425:
 
if self:_is_carrier() then
 
if self:_is_carrier() then
 
if has_planes and self._ship:night_bombing() then
 
if has_planes and self._ship:night_bombing() then
return format{"Bombing (${attack_power})", attack_power = self:_attack_power_cap(firepower + torpedo, 300)}
+
return 8, self:_attack_power_cap(firepower + torpedo, 300)
 
end
 
end
return "No Action"
+
return false
 
else
 
else
 
if torpedoes >= 2 and torpedo > 0 then
 
if torpedoes >= 2 and torpedo > 0 then
return format{"Cut-in: Torpedo (${attack_power} x2)", attack_power = self:_attack_power_cap((firepower + torpedo) * 1.5, 300)}
+
return 7, self:_attack_power_cap((firepower + torpedo) * 1.5, 300)
 
elseif main_guns >= 3 and firepower > 0 then
 
elseif main_guns >= 3 and firepower > 0 then
return format{"Cut-in: Main Gun (${attack_power})", attack_power = self:_attack_power_cap((firepower + torpedo) * 2, 300)}
+
return 4, self:_attack_power_cap((firepower + torpedo) * 2, 300)
 
elseif main_guns >= 2 and secondary_guns >= 1 and firepower > 0 then
 
elseif main_guns >= 2 and secondary_guns >= 1 and firepower > 0 then
return format{"Cut-in: Secondary Gun (${attack_power})", attack_power = self:_attack_power_cap((firepower + torpedo) * 1.75, 300)}
+
return 5, self:_attack_power_cap((firepower + torpedo) * 1.75, 300)
 
elseif main_guns >= 1 and torpedoes == 1 and firepower > 0 and torpedo > 0 then
 
elseif main_guns >= 1 and torpedoes == 1 and firepower > 0 and torpedo > 0 then
return format{"Cut-in: Mixed (${attack_power} x2)", attack_power = self:_attack_power_cap((firepower + torpedo) * 1.3, 300)}
+
return 6, self:_attack_power_cap((firepower + torpedo) * 1.3, 300)
 
elseif main_guns + secondary_guns >= 2 and firepower > 0 then
 
elseif main_guns + secondary_guns >= 2 and firepower > 0 then
return format{"Double Attack (${attack_power} x2)", attack_power = self:_attack_power_cap((firepower + torpedo) * 1.2, 300)}
+
return 3, self:_attack_power_cap((firepower + torpedo) * 1.2, 300)
 
elseif torpedoes > 0 and torpedo > 0 then
 
elseif torpedoes > 0 and torpedo > 0 then
return format{"Single Torpedo (${attack_power})", attack_power = self:_attack_power_cap(firepower + torpedo, 300)}
+
return 2, self:_attack_power_cap(firepower + torpedo, 300)
 
elseif firepower > 0 then
 
elseif firepower > 0 then
return format{"Single Attack (${attack_power})", attack_power = self:_attack_power_cap(firepower + torpedo, 300)}
+
return 1, self:_attack_power_cap(firepower + torpedo, 300)
 
else
 
else
return "No Action"
+
return false
 +
end
 +
end
 +
end
 +
 
 +
function ShipCapabilities:format_night_battle(mode, attack_power)
 +
if mode then
 +
local multiplier = self._night_battle_attack_counts[mode]
 +
if multiplier then
 +
attack_power = tostring(attack_power) .. " " .. multiplier
 
end
 
end
 +
return format{self._attack_template, mode = self._night_battle_modes[mode], attack_power = attack_power}
 +
elseif mode == false then
 +
return "No Action"
 
end
 
end
 +
return "Unknown"
 
end
 
end
  
Line 395: Line 466:
 
local opening_torpedo = self._ship:opening_torpedo()
 
local opening_torpedo = self._ship:opening_torpedo()
 
if (opening_torpedo ~= true) and (opening_torpedo == false or not torpedo or torpedo <= 0) then
 
if (opening_torpedo ~= true) and (opening_torpedo == false or not torpedo or torpedo <= 0) then
return "No"
+
return false
 
end
 
end
 
if self:_is_submarine() then
 
if self:_is_submarine() then
Line 416: Line 487:
 
end
 
end
 
if opening_torpedo then
 
if opening_torpedo then
return format{"Yes (${attack_power})", attack_power = self:_attack_power_cap(torpedo + 5, 150)}
+
return self:_attack_power_cap(torpedo + 5, 150)
 
end
 
end
return "No"
+
return false
 
end
 
end
 +
 +
ShipCapabilities.format_opening_torpedo = ShipCapabilities.format_torpedo
  
 
function ShipCapabilities:asw_attack()
 
function ShipCapabilities:asw_attack()
 
local base_asw
 
local base_asw
local asw_override, phases = self._ship:asw_attack(), "Day/Night"
+
local asw_override, day, night = self._ship:asw_attack(), true, true
 
if asw_override == false then
 
if asw_override == false then
return "No"
+
return false
 
elseif self:_is_asw_surface_ship() then
 
elseif self:_is_asw_surface_ship() then
 
base_asw = 25
 
base_asw = 25
Line 431: Line 504:
 
base_asw = 10
 
base_asw = 10
 
if not self._ship:night_bombing() then
 
if not self._ship:night_bombing() then
phases = "Day Only"
+
night = false
 
end
 
end
 
else
 
else
return "No"
+
return false
 
end
 
end
 
local asw_leveled = self._ship:asw_leveled()
 
local asw_leveled = self._ship:asw_leveled()
Line 454: Line 527:
 
end
 
end
 
if self:_is_light_carrier() and not bomber then
 
if self:_is_light_carrier() and not bomber then
return "No"
+
return false
 
end
 
end
 
local depth_charge_sonar_boost = 1
 
local depth_charge_sonar_boost = 1
Line 460: Line 533:
 
depth_charge_sonar_boost = 1.15
 
depth_charge_sonar_boost = 1.15
 
end
 
end
return format{"Yes (${attack_power}${plus}, ${phases})", attack_power = self:_attack_power_cap(depth_charge_sonar_boost * (base_asw + 2 * equipment_asw + ship_asw / 5), 100), plus = (not asw_leveled) and "+" or "", phases = phases}
+
return self:_attack_power_cap(depth_charge_sonar_boost * (base_asw + 2 * equipment_asw + ship_asw / 5), 100), day, night, not asw_leveled
 +
end
 +
 
 +
function ShipCapabilities:format_asw_attack(attack_power, day, night, uncertain)
 +
if attack_power then
 +
local phases = {}
 +
if day then
 +
table.insert(phases, self._asw_attack_modes.day)
 +
end
 +
if night then
 +
table.insert(phases, self._asw_attack_modes.night)
 +
end
 +
if #phases == 1 then
 +
phases[1] = phases[1] .. " Only"
 +
end
 +
if uncertain then
 +
attack_power = attack_power .. "+"
 +
end
 +
return format{self._attack_template, mode = table.concat(phases, "/"), attack_power = attack_power}
 +
end
 +
return "No"
 
end
 
end
  
 
function ShipCapabilities:opening_airstrike()
 
function ShipCapabilities:opening_airstrike()
 
if not self:_is_aviation_ship() then
 
if not self:_is_aviation_ship() then
return "No"
+
return false
 
end
 
end
 
local airstrikes = {}
 
local airstrikes = {}
Line 474: Line 567:
 
local attack_power = (equipment_torpedo + equipment_bombing) * math.sqrt(size) + 25
 
local attack_power = (equipment_torpedo + equipment_bombing) * math.sqrt(size) + 25
 
if self:_is_torpedo_bomber(equipment) then
 
if self:_is_torpedo_bomber(equipment) then
table.insert(airstrikes, format{"${low}/${high}", low = self:_attack_power_cap(attack_power * 0.8, 150), high = self:_attack_power_cap(attack_power * 1.5, 150)})
+
table.insert(airstrikes, self:_attack_power_cap(attack_power * 1.5, 150))
 
else
 
else
table.insert(airstrikes, tostring(self:_attack_power_cap(attack_power, 150)))
+
table.insert(airstrikes, self:_attack_power_cap(attack_power, 150))
 
end
 
end
 
end
 
end
 
end
 
end
 
if #airstrikes > 0 then
 
if #airstrikes > 0 then
return format{"Yes (${airstrikes})", airstrikes = table.concat(airstrikes, ",")}
+
return airstrikes
 +
end
 +
return false
 +
end
 +
 
 +
function ShipCapabilities:format_opening_airstrike(attacks)
 +
if attacks then
 +
local result = {}
 +
for _, attack in ipairs(attacks) do
 +
table.insert(result, tostring(attack))
 +
end
 +
return table.concat(result, ",")
 
end
 
end
 
return "No"
 
return "No"

Revision as of 00:49, 7 June 2015

Documentation for this module may be created at Module:ShipCapabilities/doc

local BaseData = require("Module:BaseData")

local format = require('Module:StringInterpolation').format

local ShipCapabilities = BaseData{
	-- _anti_air_cut_in_types = {
	-- 	{
	-- 		name = "Akizuki (HA HA R)", 
	-- 		ship = {"Akizuki"},
	-- 		equipment = {"High-angle Gun", "High-angle Gun", "Radar"},
	-- 	},
	-- 	{
	-- 		name = "Akizuki (HA AAR)",
	-- 		ship = {"Akizuki"},
	-- 		equipment = {"High-angle Gun", "Radar"},
	-- 	},
	-- 	{
	-- 		name = "Akizuki (HA HA)",
	-- 		ship = {"Akizuki"},
	-- 		equipment = {"High-angle Gun", "High-angle Gun"}
	-- 	},
	-- 	{
	-- 		name = "Type 3 AAR",
	-- 		equipment = {"Large Caliber Main Gun", "Type 3 Shell", "Anti-Aircraft Fire Director", "Anti-Air Radar"},
	-- 	},
	-- 	{
	-- 		name = "HAFD HAFD AAR",
	-- 		equipment = {"High-angle Gun + Fire Director", "High-angle Gun + Fire Director", "Anti-Air Radar"},
	-- 	},
	-- 	{
	-- 		name = "Type 3",
	-- 		equipment = {"Large Caliber Main Gun", "Type 3 Shell", "Anti-Aircraft Fire Director"},
	-- 	},
	-- 	{
	-- 		name = "HA AAFD AAR",
	-- 		equipment = {"High-angle Gun", "Anti-Aircraft Fire Director", "Anti-Air Radar"},
	-- 	},
	-- 	{
	-- 		name = "HAFD AAR",
	-- 		equipment = {"High-angle Gun + Fire Director", "Anti-Air Radar"},
	-- 	},
	-- 	{
	-- 		name = "HA AAFD",
	-- 		equipment = {"High-angle Gun + Fire Director", "Anti-Air Radar"},
	-- 	},
	-- 	{
	-- 		name = "Maya Kai Ni (HA CD AAR)",
	-- 		ship = {"Maya/Kai Ni"},
	-- 		equipment = {"High-angle Gun", "25mm Triple Autocannon Mount Concentrated Deployment", "Anti-Air Radar"},
	-- 	},
	-- 	{
	-- 		name = "Maya Kai Ni (HA CD)",
	-- 		ship = {"Maya/Kai Ni"},
	-- 		equipment = {"High-angle Gun", "25mm Triple Autocannon Mount Concentrated Deployment"},
	-- 	},
	-- 	{
	-- 		name = "CD AAMG AAR",
	-- 		equipment = {"25mm Triple Autocannon Mount Concentrated Deployment", "Anti-Air Machine Gun", "Anti-Air Radar"}
	-- 	},
	-- },
	_day_battle_modes = {
		[1] = "Shelling",
		[2] = "Bombing",
		[3] = "Bombing, displayed as Shelling",
	},
	_artillery_spotting_modes = {
		[1] = "Double Attack (120% x2)",
		[2] = "Double Attack (120% x2) / Cut-in: Secondary Gun (110%)",
		[3] = "Double Attack (120% x2) / Cut-in: AP (150%)",
		[4] = "Cut-in: Secondary Gun (110%)",
		[5] = "Cut-in: Secondary Gun (110%) / Cut-in: Radar (120%)",
		[6] = "Cut-in: Secondary Gun (110%) / Cut-in: AP (130%)",
	},
	_night_battle_modes = {
		[1] = "Single Attack",
		[2] = "Single Torpedo",
		[3] = "Double Attack",
		[4] = "Cut-in: Main Gun",
		[5] = "Cut-in: Secondary Gun",
		[6] = "Cut-in: Mixed",
		[7] = "Cut-in: Torpedo",
		[8] = "Bombing",
	},
	_night_battle_attack_counts = {
		[3] = "x2",
		[6] = "x2",
		[7] = "x2",
	},
	_asw_attack_modes = {
		day = "Day",
		night = "Night",
	},
}

function ShipCapabilities:create(data)
	if data.ship then
		data._ship = data.ship
		data.ship = nil
	end
	setmetatable(data, data)
	data.__index = self
	return data
end

--function ShipCapabilities:anti_air_cut_in()
	--local result = false
	--base_name = self._ship:base_name()
	--if base_name == "Akizuki" then
	--	result = self:akizuki_anti_air_cut_in()
	--elseif base_name == "Maya" and self._ship:suffix() == "Kai Ni" then
	--	result = self:maya_kai_ni_anti_air_cut_in()

function ShipCapabilities:_is_asw_surface_ship(ship)
	if not ship then
		ship = self._ship
	end
	local ship_type = ship:type()
	return ship_type == 2
		or ship_type == 3
		or ship_type == 4
		or ship_type == 21
end

function ShipCapabilities:_is_asw_aviation_ship(ship)
	if not ship then
		ship = self._ship
	end
	local ship_type = ship:type()
	return ship_type == 6
		or ship_type == 7
		or ship_type == 10
		or ship_type == 16
end

function ShipCapabilities:_is_aviation_ship(ship)
	if not ship then
		ship = self._ship
	end
	local ship_type = ship:type()
	return ship_type == 6
		or ship_type == 7
		or ship_type == 10
		or ship_type == 11
		or ship_type == 14
		or ship_type == 16
		or ship_type == 17
		or ship_type == 18
end

function ShipCapabilities:_is_light_carrier(ship)
	if not ship then
		ship = self._ship
	end
	return ship:type() == 7
end

function ShipCapabilities:_is_carrier(ship)
	if not ship then
		ship = self._ship
	end
	local ship_type = ship:type()
	return ship_type == 7
		or ship_type == 11
		or ship_type == 18
end

function ShipCapabilities:_is_submarine(ship)
	if not ship then
		ship = self._ship
	end
	local ship_type = ship:type()
	return ship_type == 13
		or ship_type == 14
end

function ShipCapabilities:_is_installation(ship)
	if not ship then
		ship = self._ship
	end
	return ship:is_installation()
end

function ShipCapabilities:_is_main_gun(equipment)
	local equipment_type = equipment:type()
	return equipment_type == 1
		or equipment_type == 2
		or equipment_type == 3
		or equipment_type == 38
end

function ShipCapabilities:_is_secondary_gun(equipment)
	return equipment:type() == 4
end

function ShipCapabilities:_is_torpedo(equipment)
	local equipment_type = equipment:type()
	return equipment_type == 5
		or equipment_type == 32
end

function ShipCapabilities:_is_bomber(equipment)
	local equipment_type = equipment:type()
	return equipment_type == 7
		or equipment_type == 8
		or equipment_type == 11
end

function ShipCapabilities:_is_torpedo_bomber(equipment)
	return equipment:type() == 8
end

function ShipCapabilities:_is_reconnaissance_seaplane(equipment)
	return equipment:type() == 10
end

function ShipCapabilities:_is_seaplane(equipment)
	local equipment_type = equipment:type()
	return equipment_type == 10
		or equipment_type == 11
end

function ShipCapabilities:_is_radar(equipment)
	local equipment_type = equipment:type()
	return equipment_type == 12
		or equipment_type == 13
end

function ShipCapabilities:_is_sonar(equipment)
	local equipment_type = equipment:type()
	return equipment_type == 14
		or equipment_type == 40
end

function ShipCapabilities:_is_depth_charge(equipment)
	return equipment:type() == 15
end

function ShipCapabilities:_is_ap_shell(equipment)
	return equipment:type() == 19
end

function ShipCapabilities:_is_midget_submarine(equipment)
	return equipment:type() == 22
end

function ShipCapabilities:_attack_power_cap(attack_power, cap)
	if attack_power > cap then
		return math.floor(cap + math.sqrt(attack_power - cap))
	end
	return math.floor(attack_power)
end

function ShipCapabilities:day_battle()
	if not self:_is_submarine() then
		local firepower = self._ship:firepower_leveled()
		if not firepower then
			return nil
		end
		local is_installation = self:_is_installation()
		if not self:_is_carrier() and not is_installation then
			if firepower > 0 then
				for i = 1, self._ship:slots() do
					local equipment, size = self._ship:slot(i)
					if equipment then
						local equipment_firepower = equipment:firepower()
						if equipment_firepower then
							firepower = firepower + equipment_firepower
						end
					end
				end
				return 1, self:_attack_power_cap(firepower + 5, 150)
			end
		else
			local total_space = self._ship:total_space()
			if total_space and total_space > 0 then
				local has_planes, torpedo, bombing = false, self._ship:torpedo_leveled() or 0, 0
				for i = 1, self._ship:slots() do
					local equipment, size = self._ship:slot(i)
					if equipment then
						local is_bomber, equipment_firepower, equipment_torpedo, equipment_bombing = self:_is_bomber(equipment), equipment:firepower(), equipment:torpedo(), equipment:bombing()
						if is_bomber then
							if size and size > 0 then
								has_planes = true
							else
								equipment_firepower = 0
								equipment_torpedo = 0
								equipment_bombing = 0
							end
						end
						if equipment_firepower then
							firepower = firepower + equipment_firepower
						end
						if equipment_torpedo then
							torpedo = torpedo + equipment_torpedo
						end
						if equipment_bombing then
							bombing = bombing + equipment_bombing
						end
					end
				end
				if has_planes then
					return is_installation and 3 or 2, self:_attack_power_cap(1.5 * (firepower + torpedo) + bombing * 2 + 55, 150)
				end
			end
		end
	end
	return false
end

function ShipCapabilities:format_day_battle(mode, attack_power)
	if mode then
		return format{self._attack_template, mode = self._day_battle_modes[mode], attack_power = attack_power}
	elseif mode == false then
		return "No Action"
	end
	return "??"
end

function ShipCapabilities:closing_torpedo()
	local torpedo = self._ship:torpedo_leveled()
	if torpedo and torpedo > 0 then
		for i = 1, self._ship:slots() do
			local equipment, size = self._ship:slot(i)
			if equipment then
				local equipment_torpedo = equipment:torpedo()
				if equipment_torpedo then
					torpedo = torpedo + equipment_torpedo
				end
			end
		end
		return self:_attack_power_cap(torpedo + 5, 150)
	end
	return false
end

function ShipCapabilities:format_torpedo(attack_power)
	if attack_power then
		return tostring(attack_power)
	end
	return "No"
end

ShipCapabilities.format_closing_torpedo = ShipCapabilities.format_torpedo

function ShipCapabilities:artillery_spotting()
	local total_space = self._ship:total_space()
	if not total_space or total_space <= 0 then
		return false
	end
	local main_guns, secondary_guns, seaplanes, radars, ap_shells = 0, 0, 0, 0, 0
	for i = 1, self._ship:slots() or 0 do
		local equipment, size = self._ship:slot(i)
		if equipment then
			if self:_is_main_gun(equipment) then
				main_guns = main_guns + 1
			elseif self:_is_secondary_gun(equipment) then
				secondary_guns = secondary_guns + 1
			elseif self:_is_seaplane(equipment) and size and size > 0 then
				seaplanes = seaplanes + 1
			elseif self:_is_radar(equipment) then
				radars = radars + 1
			elseif self:_is_ap_shell(equipment) then
				ap_shells = ap_shells + 1
			end
		end
	end
	if seaplanes >= 1 then
		if main_guns >= 2 then
			if ap_shells >= 1 then
				return 3
			elseif secondary_guns >= 1 then
				return 2
			end
			return 1
		elseif main_guns == 1 and secondary_guns >= 1 then
			if radars >= 1 then
				return 5
			elseif ap_shells >= 1 then
				return 6
			end
			return 4
		end
	end
	return false
end

function ShipCapabilities:format_artillery_spotting(mode)
	if mode then
		return self._artillery_spotting_modes[mode]
	end
	return "No"
end

function ShipCapabilities:night_battle()
	local main_guns, secondary_guns, torpedoes, has_planes, firepower, torpedo = 0, 0, 0, false, self._ship:firepower_leveled(), self._ship:torpedo_leveled()
	if not firepower or not torpedo then
		return nil
	end
	for i = 1, self._ship:slots() or 0 do
		local equipment, size = self._ship:slot(i)
		if equipment then
			local equipment_firepower, equipment_torpedo = equipment:firepower(), equipment:torpedo()
			if self:_is_main_gun(equipment) then
				main_guns = main_guns + 1
			elseif self:_is_secondary_gun(equipment) then
				secondary_guns = secondary_guns + 1
			elseif self:_is_torpedo(equipment) then
				torpedoes = torpedoes + 1
			elseif self:_is_bomber(equipment) then
				if size and size > 0 then
					has_planes = true
				else
					equipment_firepower = 0
					equipment_torpedo = 0
				end
			end
			if equipment_firepower then
				firepower = firepower + equipment_firepower
			end
			if equipment_torpedo then
				torpedo = torpedo + equipment_torpedo
			end
		end
	end
	if self:_is_carrier() then
		if has_planes and self._ship:night_bombing() then
			return 8, self:_attack_power_cap(firepower + torpedo, 300)
		end
		return false
	else
		if torpedoes >= 2 and torpedo > 0 then
			return 7, self:_attack_power_cap((firepower + torpedo) * 1.5, 300)
		elseif main_guns >= 3 and firepower > 0 then
			return 4, self:_attack_power_cap((firepower + torpedo) * 2, 300)
		elseif main_guns >= 2 and secondary_guns >= 1 and firepower > 0 then
			return 5, self:_attack_power_cap((firepower + torpedo) * 1.75, 300)
		elseif main_guns >= 1 and torpedoes == 1 and firepower > 0 and torpedo > 0 then
			return 6, self:_attack_power_cap((firepower + torpedo) * 1.3, 300)
		elseif main_guns + secondary_guns >= 2 and firepower > 0 then
			return 3, self:_attack_power_cap((firepower + torpedo) * 1.2, 300)
		elseif torpedoes > 0 and torpedo > 0 then
			return 2, self:_attack_power_cap(firepower + torpedo, 300)
		elseif firepower > 0 then
			return 1, self:_attack_power_cap(firepower + torpedo, 300)
		else
			return false
		end
	end
end

function ShipCapabilities:format_night_battle(mode, attack_power)
	if mode then
		local multiplier = self._night_battle_attack_counts[mode]
		if multiplier then
			attack_power = tostring(attack_power) .. " " .. multiplier
		end
		return format{self._attack_template, mode = self._night_battle_modes[mode], attack_power = attack_power}
	elseif mode == false then
		return "No Action"
	end
	return "Unknown"
end

function ShipCapabilities:opening_torpedo()
	local torpedo = self._ship:torpedo_leveled()
	local opening_torpedo = self._ship:opening_torpedo()
	if (opening_torpedo ~= true) and (opening_torpedo == false or not torpedo or torpedo <= 0) then
		return false
	end
	if self:_is_submarine() then
		local level = self._ship:level()
		if level and level >= 10 then
			opening_torpedo = true
		end
	end
	for i = 1, self._ship:slots() or 0 do
		local equipment, size = self._ship:slot(i)
		if equipment then
			if self:_is_midget_submarine(equipment) then
				opening_torpedo = true
			end
			local equipment_torpedo = equipment:torpedo()
			if equipment_torpedo then
				torpedo = torpedo + equipment_torpedo
			end
		end
	end
	if opening_torpedo then
		return self:_attack_power_cap(torpedo + 5, 150)
	end
	return false
end

ShipCapabilities.format_opening_torpedo = ShipCapabilities.format_torpedo

function ShipCapabilities:asw_attack()
	local base_asw
	local asw_override, day, night = self._ship:asw_attack(), true, true
	if asw_override == false then
		return false
	elseif self:_is_asw_surface_ship() then
		base_asw = 25
	elseif self:_is_asw_aviation_ship() then
		base_asw = 10
		if not self._ship:night_bombing() then
			night = false
		end
	else
		return false
	end
	local asw_leveled = self._ship:asw_leveled()
	local ship_asw, equipment_asw, depth_charge, sonar, bomber = (asw_leveled or 0) / 5, 0, false, false, false
	for i = 1, self._ship:slots() or 0 do
		local equipment, size = self._ship:slot(i)
		if equipment then
			if not self:_is_reconnaissance_seaplane(equipment) then
				if self:_is_sonar(equipment) then
					sonar = true
				elseif self:_is_depth_charge(equipment) then
					depth_charge = true
				elseif self:_is_bomber(equipment) then
					bomber = true
				end
				equipment_asw = equipment_asw + (equipment:asw() or 0)
			end
		end
	end
	if self:_is_light_carrier() and not bomber then
		return false
	end
	local depth_charge_sonar_boost = 1
	if depth_charge and sonar then
		depth_charge_sonar_boost = 1.15
	end
	return self:_attack_power_cap(depth_charge_sonar_boost * (base_asw + 2 * equipment_asw + ship_asw / 5), 100), day, night, not asw_leveled
end

function ShipCapabilities:format_asw_attack(attack_power, day, night, uncertain)
	if attack_power then
		local phases = {}
		if day then
			table.insert(phases, self._asw_attack_modes.day)
		end
		if night then
			table.insert(phases, self._asw_attack_modes.night)
		end
		if #phases == 1 then
			phases[1] = phases[1] .. " Only"
		end
		if uncertain then
			attack_power = attack_power .. "+"
		end
		return format{self._attack_template, mode = table.concat(phases, "/"), attack_power = attack_power}
	end
	return "No"
end

function ShipCapabilities:opening_airstrike()
	if not self:_is_aviation_ship() then
		return false
	end
	local airstrikes = {}
	for i = 1, self._ship:slots() or 0 do
		local equipment, size = self._ship:slot(i)
		if size and size > 0 and equipment and self:_is_bomber(equipment) then
			local equipment_torpedo, equipment_bombing = equipment:torpedo() or 0, equipment:bombing() or 0
			local attack_power = (equipment_torpedo + equipment_bombing) * math.sqrt(size) + 25
			if self:_is_torpedo_bomber(equipment) then
				table.insert(airstrikes, self:_attack_power_cap(attack_power * 1.5, 150))
			else
				table.insert(airstrikes, self:_attack_power_cap(attack_power, 150))
			end
		end
	end
	if #airstrikes > 0 then
		return airstrikes
	end
	return false
end

function ShipCapabilities:format_opening_airstrike(attacks)
	if attacks then
		local result = {}
		for _, attack in ipairs(attacks) do
			table.insert(result, tostring(attack))
		end
		return table.concat(result, ",")
	end
	return "No"
end

return ShipCapabilities