Module:NanaminFunctions

Revision as of 20:13, 22 April 2015 by Nanamin (talk | contribs)

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

local NanaminFunctions = {}

function NanaminFunctions.split(haystack, needle)
    local result = {}
    while mw.ustring.find(haystack, needle) do
        local split = mw.ustring.find(haystack, needle)
        table.insert(result, mw.ustring.sub(haystack, 1, split - 1))
        haystack = mw.ustring.sub(haystack, split + 1)
    end
    table.insert(result, haystack)
    return result
end

function NanaminFunctions.add_to_fighter_power(current_fp, equip, planes)
    --Only fighter planes, dive bombers, torpedo bombers and seaplane bombers with an AA stat are counted
    local types_allowed = { [6] = true, [7] = true, [8] = true, [11] = true }
    if types_allowed[equip:type()] and equip:aa() then
        current_fp = current_fp + math.floor(math.sqrt(planes) * equip:aa())
    end
    return current_fp
end

function NanaminFunctions.add_to_elos(current_elos, equip)
    --[[Effective LoS = Dive Bomber LoS x (1.04) + Torpedo Bomber LoS x (1.37)
    + Carrier-based Recon Plane LoS x (1.66) + Recon Seaplane LoS x (2.00)
    + Seaplane Bomber LoS x (1.78) + Small Radar LoS x (1.00) + Large Radar LoS x (0.99)
    + Searchlight LoS x (0.91) + √(base LoS of each ship) * (1.69)
    + (HQ Lv. rounded up to the next multiple of 5) x (-0.61)--]]
    local multiplier = { [7] = 1.04, [8] = 1.04, [9] = 1.66, [10] = 2.00, [11] = 1.78, [12] = 1.00, [13] = 0.99, [29] = 0.91 }
    if multiplier[equip:type()] ~= nil and equip:los() then
        current_elos = current_elos + (equip:los() * multiplier[equip:type()])
    end
    return current_elos
end

return NanaminFunctions