Changes

no edit summary
Line 6: Line 6:  
local ShipCapabilities = require('Module:ShipCapabilities')
 
local ShipCapabilities = require('Module:ShipCapabilities')
 
local StatIcons = require('Module:Data/Asset')
 
local StatIcons = require('Module:Data/Asset')
 +
local Iterator = require('Module:Iterator')
 +
local EquipInfo = require('Module:EquipmentInfoKai')
    
local format = require('Module:Core').format
 
local format = require('Module:Core').format
Line 21: Line 23:  
! style="width: 30px; text-align: center; vertical-align: middle; background-color: violet;" | ${evasion}
 
! style="width: 30px; text-align: center; vertical-align: middle; background-color: violet;" | ${evasion}
 
! style="text-align: center; vertical-align: middle;" | Armament
 
! style="text-align: center; vertical-align: middle;" | Armament
! style="text-align:left;" | Notes]],
+
! style="text-align:left;" | Notes
 +
! OASW
 +
! Opening Torpedo
 +
! Night Bombing
 +
! AACI]],
 
_columns = {
 
_columns = {
 
"card",
 
"card",
Line 35: Line 41:  
"armament",
 
"armament",
 
"notes",
 
"notes",
 +
"oasw",
 +
"otorp",
 +
"nightbombing",
 +
"aaci",
 
},
 
},
_cell = [[| style="text-align: ${text_align}; padding:5px 5px 5px 5px; background-color: ${bg_color};" |${value}]],
+
_cell = [[|style="text-align:${text_align};background-color:${bg_color}"|${value}]],
 
_column_cell_templates = {
 
_column_cell_templates = {
card = [[| style="text-align: ${text_align}; padding:5px 5px 5px 5px; background-color: ${bg_color}; background-image: ${background_image}" |${value}]],
+
card = [[|style="text-align:${text_align};background-color:${bg_color};background-image:${background_image}" |${value}]],
 +
--card = [[|style="text-align:${text_align}"|${value}]],
 
},
 
},
 
_item_class = function(item_key) return EnemyShip(item_key) end,
 
_item_class = function(item_key) return EnemyShip(item_key) end,
Line 76: Line 87:  
value = ShipBattleCardKai:get{ship = ship, size = self._size, link = ship:link(), hd = true, size = '160px', caption = ship:name()}
 
value = ShipBattleCardKai:get{ship = ship, size = self._size, link = ship:link(), hd = true, size = '160px', caption = ship:name()}
 
end
 
end
return {value = value, bg_color = bg_color, background_image = background_image or self._none, text_align = self._center_align}
+
return {
 +
value = value,
 +
bg_color = bg_color,
 +
background_image = background_image or self._none,
 +
text_align = self._center_align,
 +
}
 
end
 
end
   Line 127: Line 143:  
elseif ShipCapabilities:_is_depth_charge(equipment) then
 
elseif ShipCapabilities:_is_depth_charge(equipment) then
 
dc = true
 
dc = true
elseif ShipCapabilities._is_active_midget_submarine(equipment) then
  −
active_midget_submarine = true
   
end
 
end
 
local real_equipment = equipment:link()
 
local real_equipment = equipment:link()
Line 147: Line 161:  
end
 
end
 
table.insert(icons, icon)
 
table.insert(icons, icon)
end
  −
if ShipCapabilities:_is_submarine(ship) then
  −
if ship:suffix() and (ship:suffix():match("Elite") or ship:suffix():match("Flagship")) then
  −
table.insert(roles, self._opening_torpedo_label)
  −
end
  −
elseif active_midget_submarine then
  −
table.insert(roles, self._opening_torpedo_label)
   
end
 
end
 
if air_power then
 
if air_power then
Line 161: Line 168:  
         end
 
         end
 
table.insert(roles, ap_text)
 
table.insert(roles, ap_text)
end
  −
if ShipCapabilities:_is_night_bombing(ship) then
  −
table.insert(roles, self._night_bombing_label)
   
end
 
end
 
if sonar or dc then
 
if sonar or dc then
Line 190: Line 194:  
end
 
end
 
return {value = table.concat(value, "<br/>"), bg_color = self._transparent, text_align = self._start_align}
 
return {value = table.concat(value, "<br/>"), bg_color = self._transparent, text_align = self._start_align}
 +
end
 +
 +
function EnemyShipListKai:oasw(ship)
 +
local capabilities = ShipCapabilities{_ship = ship}
 +
local value = {}
 +
local attack_power, opening, day, night, uncertain = capabilities:asw_attack()
 +
local label = opening and "Yes" or "No"
 +
 +
return {value = label, bg_color = opening and "green" or self._transparent, text_align = self._start_align}
 +
end
 +
 +
function EnemyShipListKai:otorp(ship)
 +
local roles = {}
 +
local active_midget_submarine = false
 +
 +
for i = 1, ship:slots_length() do
 +
local equipment, size, estimation = ship:slot(i)
 +
if equipment then
 +
if ShipCapabilities._is_active_midget_submarine(equipment) then
 +
active_midget_submarine = true
 +
end
 +
end
 +
end
 +
 +
local can_otorp = false
 +
 +
if ShipCapabilities:_is_submarine(ship) then
 +
if ship:suffix() and (ship:suffix():match("Elite") or ship:suffix():match("Flagship")) then
 +
can_otorp = true
 +
end
 +
elseif active_midget_submarine then
 +
can_otorp = true
 +
end
 +
local label = can_otorp and "Yes" or "No"
 +
 +
return {value = label, bg_color = can_otorp and "green" or self._transparent, text_align = self._start_align}
 +
end
 +
 +
function EnemyShipListKai:nightbombing(ship)
 +
local roles = {}
 +
local can_night = false
 +
 +
if ShipCapabilities:_is_night_bombing(ship) then
 +
can_night = true
 +
end
 +
local label = can_night and "Yes" or "No"
 +
 +
return {value = label, bg_color = can_night and "green" or self._transparent, text_align = self._start_align}
 +
end
 +
 +
function EnemyShipListKai:aaci(ship)
 +
local ha_aafd, cd_mg, other_mg, air_radar = 0, 0, 0, 0
 +
 +
for i = 1, ship:slots_length() do
 +
local equipment, size, estimation = ship:slot(i)
 +
local equipment_type
 +
if equipment then
 +
equipment_type = equipment:type()
 +
 +
if ShipCapabilities:_is_main_gun(equipment) or ShipCapabilities:_is_secondary_gun(equipment) then
 +
if equipment:is_aafd() then
 +
ha_aafd = ha_aafd + 1
 +
end
 +
elseif ShipCapabilities:_is_radar(equipment) then
 +
if equipment:aa() and equipment:aa() > 2 then
 +
air_radar = air_radar + 1
 +
end
 +
elseif equipment_type == 21 then --AA guns
 +
if equipment:aa() >= 9 then
 +
cd_mg = cd_mg + 1
 +
elseif equipment:aa() >= 3 then
 +
other_mg = other_mg + 1
 +
end
 +
end
 +
end
 +
end
 +
 +
local can_aaci = true
 +
local api = nil
 +
 +
if ha_aafd >= 2 and air_radar >= 1 then
 +
api = 5
 +
elseif ha_aafd >= 1 and air_radar >= 1 then
 +
api = 8
 +
elseif cd_mg >= 1 and other_mg >= 1 and air_radar >= 1 then
 +
api = 12
 +
else
 +
can_aaci = false
 +
end
 +
local label = can_aaci and "API: " .. api or "No"
 +
 +
return {value = label, bg_color = can_aaci and "green" or self._transparent, text_align = self._start_align}
 
end
 
end
   Line 216: Line 312:  
return EnemyShipListKai:Table(args)
 
return EnemyShipListKai:Table(args)
 
end
 
end
 +
 +
-- * Tests.
 +
function EnemyShipListKai.test()
 +
    function testList(name, args)
 +
    local names = {}
 +
        local iterator = Iterator[name](args)
 +
        local i = 0
 +
        while iterator.next() do
 +
            names[i] = iterator.current() or '?'
 +
            i = i + 1
 +
        end
 +
        return names
 +
    end
 +
   
 +
    local result = testList('enemiesByTypeAndInstallationAndBoss', { type = '9', boss = 'no', installation='yes'})
 +
    mw.log(EnemyShipListKai:Table(result))
 +
   
 +
    result = testList('enemiesByTypeAndInstallationAndBoss', { type = '2', boss = 'no' , listBase = 'true'})
 +
mw.log(EnemyShipListKai:Table(result))
 +
 +
    result = testList('enemiesByTypeAndInstallationAndBoss', { type = '-13', boss = 'yes' , installation = 'no'})
 +
mw.log(EnemyShipListKai:Table(result))
 +
end
 +
-- p.test()
    
return EnemyShipListKai
 
return EnemyShipListKai
cssedit, gkautomate
7,064

edits