Changes

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"
Anonymous user