| Line 1: |
Line 1: |
| | + | local U = require("Module:Core") |
| | local BaseData = require("Module:BaseData") | | local BaseData = require("Module:BaseData") |
| | + | local Formatting = require('Module:Formatting') |
| | local Equipment | | local Equipment |
| | local EquipmentFrom | | local EquipmentFrom |
| − | local EquipmentCompatibility --lazily loaded when equippable() is called | + | local EquipmentCompatibility |
| − | local Formatting = require('Module:Formatting')
| |
| | | | |
| | local EquipmentData = BaseData({ | | local EquipmentData = BaseData({ |
| Line 11: |
Line 12: |
| | _display_none_css = {display = "none"}, | | _display_none_css = {display = "none"}, |
| | _constructor_module = "Module:Equipment", | | _constructor_module = "Module:Equipment", |
| − | _from_api_module = "Module:EquipmentFrom",
| |
| | }) | | }) |
| | | | |
| Line 48: |
Line 48: |
| | --Returns the equipment's id. | | --Returns the equipment's id. |
| | function EquipmentData:id() | | function EquipmentData:id() |
| − | return self._id | + | return self._is_enemy and self._id and self._id < 1501 and self._id + 1000 or self._id |
| | end | | end |
| | | | |
| Line 172: |
Line 172: |
| | function EquipmentData:type() | | function EquipmentData:type() |
| | return self._type | | return self._type |
| | + | end |
| | + | |
| | + | function EquipmentData:types() |
| | + | return self._types |
| | end | | end |
| | | | |
| Line 210: |
Line 214: |
| | end | | end |
| | | | |
| − | function EquipmentData:card() | + | function EquipmentData:card(as_item) |
| | + | if self._item or as_item and self._item_id then |
| | + | return Formatting:item_card(self:asset_name()) |
| | + | end |
| | if self._card then | | if self._card then |
| | return self._card | | return self._card |
| Line 218: |
Line 225: |
| | end | | end |
| | local api_id = self:api_id() | | local api_id = self:api_id() |
| − | if api_id then | + | if self._item then |
| | + | return Formatting:equipment_card(false, self:asset_name()) |
| | + | elseif api_id ~= nil then |
| | return Formatting:equipment_card(api_id, self:asset_name()) | | return Formatting:equipment_card(api_id, self:asset_name()) |
| − | end
| + | end |
| − | return self._card
| |
| | end | | end |
| | | | |
| Line 241: |
Line 249: |
| | if self._cg then | | if self._cg then |
| | return self._cg | | return self._cg |
| − | elseif self._cg_reference then | + | end |
| | + | if self._cg == false then |
| | + | return false |
| | + | end |
| | + | local id = self:api_id() |
| | + | if id and id > 1500 then |
| | + | local new_id = require('Module:Data/EnemyEquipmentCG')[id] |
| | + | new_id = new_id or id - 1500 |
| | + | local reference |
| | + | if new_id and new_id ~= id and new_id > 1500 then |
| | + | local EnemyEquipment = require('Module:Collection/EnemyEquipment') |
| | + | reference = U.find(EnemyEquipment, new_id, '_id') |
| | + | end |
| | + | if new_id and new_id ~= id and new_id <= 1500 then |
| | + | local ShipEquipment = require('Module:Data/Equipment') |
| | + | reference = U.find(ShipEquipment, new_id, '_id') |
| | + | end |
| | + | if reference then |
| | + | Equipment = Equipment or require(self._constructor_module) |
| | + | return Equipment(reference._name):cg() |
| | + | end |
| | + | end |
| | + | --[[ |
| | + | if self._cg_reference then |
| | Equipment = Equipment or require(self._constructor_module) | | Equipment = Equipment or require(self._constructor_module) |
| | return Equipment(self._cg_reference):cg() | | return Equipment(self._cg_reference):cg() |
| | end | | end |
| − | local api_id = self:api_id() | + | ]]-- |
| − | if api_id then | + | if id then |
| − | if api_id > 500 then
| + | return Formatting:equipment_cg(id, self:asset_name()) |
| − | local equipment_type = self:type()
| |
| − | if equipment_type < 6
| |
| − | or (equipment_type > 11 and equipment_type ~= 25 and equipment_type ~= 26 and equipment_type ~= 41
| |
| − | and equipment_type ~= 45 and equipment_type ~= 47 and equipment_type ~= 48 and equipment_type ~= 94) then
| |
| − | Equipment = Equipment or require(self._constructor_module)
| |
| − | EquipmentFrom = EquipmentFrom or require(self._from_api_module)
| |
| − | return Equipment(EquipmentFrom:api_id_lookup{api_id - 500}):cg()
| |
| − | end
| |
| − | end
| |
| − | return Formatting:equipment_cg(api_id, self:asset_name()) | |
| | end | | end |
| − | return self._cg | + | return false |
| | end | | end |
| | | | |
| Line 281: |
Line 302: |
| | end | | end |
| | | | |
| − | function EquipmentData:icon() | + | function EquipmentData:icon(as_item) |
| − | return self._icon
| + | if self._item or as_item and self._item_id then |
| | + | return Formatting:item_icon(self:asset_name()) |
| | + | end |
| | + | if self._icon or self._icon == false then |
| | + | return self._icon |
| | + | else |
| | + | return Formatting:equipment_image('Icon', false, self:asset_name()) |
| | + | end |
| | end | | end |
| | | | |
| Line 388: |
Line 416: |
| | | | |
| | function EquipmentData:is_lbas_plane() | | function EquipmentData:is_lbas_plane() |
| | + | self:_load_compatibility() |
| | + | return EquipmentCompatibility.AirBase[self:type()] or false |
| | + | -- local eq_type = self:type() |
| | + | -- return eq_type == 6 -- Carrier-based Fighter Aircraft |
| | + | -- or eq_type == 7 -- Carrier-based Dive Bomber |
| | + | -- or eq_type == 8 -- Carrier-based Torpedo Bomber |
| | + | -- or eq_type == 9 -- Carrier-based Reconnaissance Aircraft |
| | + | -- or eq_type == 10 -- Reconnaissance Seaplane |
| | + | -- or eq_type == 11 -- Seaplane Bomber |
| | + | -- or eq_type == 25 -- Rotorcraft |
| | + | -- or eq_type == 26 -- Anti-submarine Patrol Aircraft |
| | + | -- or eq_type == 41 -- Large Flying Boat |
| | + | -- or eq_type == 45 -- Seaplane Fighter |
| | + | -- or eq_type == 47 -- Land-based Attack Aircraft |
| | + | -- or eq_type == 48 -- Land-based Fighter |
| | + | -- or eq_type == 49 -- Land-based Reconnaissance Aircraft |
| | + | -- or eq_type == 53 -- Large Land-based Aircraft |
| | + | -- or eq_type == 56 -- Jet-powered Fighter Aircraft |
| | + | -- or eq_type == 57 -- Jet-powered Fighter-Bomber |
| | + | -- or eq_type == 58 -- Jet-powered Attack Aircraft |
| | + | -- or eq_type == 59 -- Jet-powered Recon Aircraft |
| | + | -- or eq_type == 91 -- Jet-powered Fighter-Bomber (II) |
| | + | -- or eq_type == 94 -- Carrier-based Reconnaissance Aircraft (II) |
| | + | end |
| | + | |
| | + | function EquipmentData:is_lbas_ha_bomber() |
| | + | return self:id() >= 1501 and self:type() == 7 and self:range() == 4 |
| | + | end |
| | + | |
| | + | function EquipmentData:is_lbas_attack_aircraft() |
| | + | return self:type() == 47 or self:type() == 53 |
| | + | end |
| | + | |
| | + | function EquipmentData:is_large_caliber_main_gun() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 3 -- Large Caliber Main Gun |
| | + | or eq_type == 38 -- Large Caliber Main Gun (II) |
| | + | end |
| | + | |
| | + | function EquipmentData:is_main_gun() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 1 -- Small Caliber Main Guns |
| | + | or eq_type == 2 -- Medium Caliber Main Guns |
| | + | or eq_type == 3 -- Large Caliber Main Guns |
| | + | or eq_type == 38 -- Large Caliber Main Guns (II) |
| | + | end |
| | + | |
| | + | function EquipmentData:is_aafd() |
| | + | return self:aa() and self:aa() >= 8 |
| | + | end |
| | + | |
| | + | function EquipmentData:is_not_aafd() |
| | + | return not (self:is_aafd()) |
| | + | end |
| | + | |
| | + | function EquipmentData:is_fighter_aircraft() |
| | local eq_type = self:type() | | local eq_type = self:type() |
| | return eq_type == 6 -- Carrier-based Fighter Aircraft | | return eq_type == 6 -- Carrier-based Fighter Aircraft |
| | + | or eq_type == 45 -- Seaplane Fighter |
| | + | or eq_type == 48 -- Land-based Fighter |
| | + | or eq_type == 56 -- Jet-powered Fighter Aircraft |
| | + | end |
| | + | |
| | + | function EquipmentData:is_bomber_aircraft() |
| | + | local eq_type = self:type() |
| | or eq_type == 7 -- Carrier-based Dive Bomber | | or eq_type == 7 -- Carrier-based Dive Bomber |
| | or eq_type == 8 -- Carrier-based Torpedo Bomber | | or eq_type == 8 -- Carrier-based Torpedo Bomber |
| − | or eq_type == 9 -- Carrier-based Reconnaissance Aircraft
| |
| − | or eq_type == 10 -- Reconnaissance Seaplane
| |
| | or eq_type == 11 -- Seaplane Bomber | | or eq_type == 11 -- Seaplane Bomber |
| − | or eq_type == 41 -- Large Flying Boat
| + | -- or eq_type == 25 -- Rotorcraft |
| − | or eq_type == 45 -- Seaplane Fighter | + | or eq_type == 26 -- Anti-submarine Patrol Aircraft |
| | or eq_type == 47 -- Land-based Attack Aircraft | | or eq_type == 47 -- Land-based Attack Aircraft |
| − | or eq_type == 48 -- Interceptor Fighter | + | or eq_type == 53 -- Large Land-based Aircraft |
| − | or eq_type == 56 -- Jet-powered Fighter Aircraft
| |
| | or eq_type == 57 -- Jet-powered Fighter-Bomber | | or eq_type == 57 -- Jet-powered Fighter-Bomber |
| | or eq_type == 58 -- Jet-powered Attack Aircraft | | or eq_type == 58 -- Jet-powered Attack Aircraft |
| − | or eq_type == 59 -- Jet-powered Recon Aircraft | + | or eq_type == 91 -- Jet-powered Fighter-Bomber (II) |
| − | or eq_type == 94 -- Carrier-based Reconnaissance Aircraft (II)
| |
| | end | | end |
| | | | |
| − | function EquipmentData:is_large_caliber_main_gun() | + | function EquipmentData:is_reconnaissance_aircraft() |
| | local eq_type = self:type() | | local eq_type = self:type() |
| − | return eq_type == 3 -- Large Caliber Main Gun | + | return eq_type == 9 -- Carrier-based Reconnaissance Aircraft |
| − | or eq_type == 38 -- Large Caliber Main Gun (II) | + | or eq_type == 10 -- Reconnaissance Seaplanes |
| | + | or eq_type == 49 -- Land-based Reconnaissance Aircraft |
| | + | or eq_type == 94 -- Carrier-based Reconnaissance Aircraft (II) |
| | end | | end |
| | | | |
| Line 422: |
Line 511: |
| | return eq_type == 5 -- Torpedo | | return eq_type == 5 -- Torpedo |
| | or eq_type == 32 -- Submarine Torpedo | | or eq_type == 32 -- Submarine Torpedo |
| | + | end |
| | + | |
| | + | function EquipmentData:is_radar() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 12 -- Small Radar |
| | + | or eq_type == 13 -- Large Radar |
| | + | or eq_type == 93 -- Large Radar (II) |
| | + | end |
| | + | |
| | + | function EquipmentData:is_large_radar() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 13 -- Large Radar |
| | + | or eq_type == 93 -- Large Radar (II) |
| | + | end |
| | + | |
| | + | function EquipmentData:is_sonar() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 14 -- Sonar |
| | + | or eq_type == 40 -- Large Sonar |
| | + | end |
| | + | |
| | + | function EquipmentData:is_asw_aircraft() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 25 -- Autogyro |
| | + | or eq_type == 26 -- Anti-submarine Patrol Aircraft |
| | + | end |
| | + | |
| | + | function EquipmentData:is_extra_armor() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 16 -- Extra Armor |
| | + | or eq_type == 27 -- Extra Armor (Medium) |
| | + | or eq_type == 28 -- Extra Armor (Large) |
| | + | end |
| | + | |
| | + | function EquipmentData:is_secondary_gun() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 4 -- Secondary Guns |
| | + | or eq_type == 95 -- Secondary Guns (II) |
| | + | end |
| | + | |
| | + | function EquipmentData:is_jet_powered_fighter_bomber() |
| | + | local eq_type = self:type() |
| | + | return eq_type == 57 -- Jet-powered Fighter-Bombers |
| | + | or eq_type == 91 -- Jet-powered Fighter-Bombers (II) |
| | end | | end |
| | | | |
| | function EquipmentData:scrap() | | function EquipmentData:scrap() |
| | return {fuel = self._scrap_fuel, ammo = self._scrap_ammo, steel = self._scrap_steel, bauxite = self._scrap_bauxite, devmat = false, conmat = false, screw = false} | | return {fuel = self._scrap_fuel, ammo = self._scrap_ammo, steel = self._scrap_steel, bauxite = self._scrap_bauxite, devmat = false, conmat = false, screw = false} |
| | + | end |
| | + | |
| | + | function EquipmentData:info() |
| | + | return self._info |
| | + | end |
| | + | |
| | + | function EquipmentData:info_en() |
| | + | return self._info_en |
| | + | end |
| | + | |
| | + | function EquipmentData:wikipedia() |
| | + | return self._wikipedia |
| | end | | end |
| | | | |
| | function EquipmentData:buildable() | | function EquipmentData:buildable() |
| | return self._buildable | | return self._buildable |
| | + | end |
| | + | |
| | + | function EquipmentData:improvable() |
| | + | return self._improvements and true or false |
| | end | | end |
| | | | |
| Line 550: |
Line 699: |
| | function EquipmentData:gun_fit_group() | | function EquipmentData:gun_fit_group() |
| | return self._gun_fit_group | | return self._gun_fit_group |
| | + | end |
| | + | |
| | + | function EquipmentData:_load_compatibility() |
| | + | if not EquipmentCompatibility then |
| | + | EquipmentCompatibility = mw.loadData('Module:Data/EquipmentRefit') |
| | + | end |
| | + | end |
| | + | |
| | + | local function convert_compatibility(compatibility_table, equipment_type, name) |
| | + | local value = compatibility_table[name] or compatibility_table[equipment_type] |
| | + | return value == true and 1 or type(value) == 'string' and {value = U.startsWith(value, 'Only') and 2 or 3, note = value, code = value} or 0 |
| | end | | end |
| | | | |
| | function EquipmentData:equippable(ship_type) | | function EquipmentData:equippable(ship_type) |
| | self:_load_compatibility() | | self:_load_compatibility() |
| − | local equipment_type = self:type()
| |
| | if not ship_type then | | if not ship_type then |
| | local result = {} | | local result = {} |
| | for ship_type, compatibility_table in pairs(EquipmentCompatibility) do | | for ship_type, compatibility_table in pairs(EquipmentCompatibility) do |
| − | result[ship_type] = compatibility_table[equipment_type] | + | result[ship_type] = convert_compatibility(compatibility_table, self:type(), self:name()) |
| | end | | end |
| | return result | | return result |
| | + | end |
| | + | local compatibility_table = EquipmentCompatibility[ship_type] |
| | + | if not compatibility_table then |
| | + | return nil |
| | + | end |
| | + | local compatibility = convert_compatibility(compatibility_table, self:type(), self:name()) |
| | + | if type(compatibility) ~= "table" then |
| | + | return compatibility |
| | else | | else |
| − | local compatibility_table = EquipmentCompatibility[ship_type] | + | return compatibility.value, compatibility.note |
| − | if compatibility_table then
| |
| − | local compatibility = compatibility_table[equipment_type]
| |
| − | if type(compatibility) ~= "table" then
| |
| − | return compatibility
| |
| − | else
| |
| − | return compatibility.value, compatibility.note
| |
| − | end
| |
| − | end
| |
| − | end
| |
| − | end
| |
| − | | |
| − | function EquipmentData:_load_compatibility()
| |
| − | if not EquipmentCompatibility then
| |
| − | EquipmentCompatibility = mw.loadData('Module:EquipmentCompatibility')
| |
| | end | | end |
| | end | | end |