Jump to content

Module:USN fleet totals

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 15:48, 1 October 2022. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local data = mw.loadData ('Module:USN fleet totals/data');						-- get the detailed list of ship types and their counts, the grand total of active and reserve ships, and the total planned ships


--[[--------------------------< R O U N D >--------------------------------------------------------------------

rounds <count> to nearest multiple of 5.

]]

local function round (count)
	if 0 == count % 5 then
		return count;															-- <count> is xx0, xx5 so return unmolested
	elseif 2.5 > (count % 5) then
		return count - (count % 5);												-- <count> is xx1, xx2 so return xx0
	else
		return count + (5 - (count % 5));										-- <count> is xx3, xx4 so return xx5
	end
end


--[[--------------------------< U S N _ F L E E T _ T O T A L S >----------------------------------------------

This function returns one of three values:
	the long string of fleet totals created by Module:USN fleet totals			-- {{USN fleet totals}}
	the 'grand total' (active and reserved fleets) rounded to the nearest multiple of 5					-- {{USN fleet totals|active}}
	the 'planned total' (ships under construction or on order) rounded to the nearest multiple of 5		-- {{USN fleet totals|active}}

]]

local function USN_fleet_totals (frame)
	if not frame.args[1] or ('' == frame.args[1]) then							-- {{{1}}} empty or nil
		return data.fleet_totals_str;											-- return the detailed fleet totals
	elseif 'active' == frame.args[1] then										-- number of active and reseved fleet ships
		return round (data.grand_total);										-- round to nearest multiple of 5
	elseif 'planned' == frame.args[1] then										-- under of under construction and on-order ships
		return round (data.planned_total);										-- round to nearest multiple of 5
	end
end


--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]

return 
	{
	USN_fleet_totals = USN_fleet_totals,
	}