Module:SouthernApproachesCommandBVR

From MicrasWiki
Revision as of 22:55, 20 November 2026 by NewZimiaGov (talk | contribs) (Created page with "-- Module:SouthernApproachesCommandBVR -- BH-054 joint command reporting. Scribunto / MediaWiki Lua 5.1 compatible. -- Historical events are explicit in /Events; scheduled readiness is deterministic. -- NO random seizures, attacks, border crossings, claims of consent or exception orders. local p = {} local d = mw.loadData('Module:SouthernApproachesCommandBVR/Data') local events = mw.loadData('Module:SouthernApproachesCommandBVR/Events') local concat = table.concat local...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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

-- Module:SouthernApproachesCommandBVR
-- BH-054 joint command reporting. Scribunto / MediaWiki Lua 5.1 compatible.
-- Historical events are explicit in /Events; scheduled readiness is deterministic.
-- NO random seizures, attacks, border crossings, claims of consent or exception orders.
local p = {}
local d = mw.loadData('Module:SouthernApproachesCommandBVR/Data')
local events = mw.loadData('Module:SouthernApproachesCommandBVR/Events')
local concat = table.concat

local function getArgs(frame)
    local a = {}
    if frame and frame.getParent and frame:getParent() then
        for k,v in pairs(frame:getParent().args) do if v ~= '' then a[k]=v end end
    end
    if frame and frame.args then
        for k,v in pairs(frame.args) do if v ~= '' then a[k]=v end end
    end
    return a
end

local function safe(v)
    return tostring(v == nil and '' or v):gsub('|','|'):gsub('[\r\n]',' ')
end

local function num(v)
    return tostring(tonumber(v) or 0)
end

local function displayDate(date)
    return tostring(date.day)..'/'..tostring(date.month)..'/'..tostring(date.year)..' [[PSSC]]'
end

local function ordinal(date)
    return 183*date.year + 61*(date.month-1) + date.day
end

local function parsePSSC(s)
    if not s then return nil end
    local day,month,year = tostring(s):match('^(%d+)%/(%d+)%/(%d+)')
    day,month,year = tonumber(day),tonumber(month),tonumber(year)
    if day and month and year and day>=1 and day<=61 and month>=1 and month<=3 and year>=0 then
        return {day=day, month=month, year=year}
    end
    return nil
end

local function dateFor(args)
    if args.date then
        local valid=parsePSSC(args.date)
        if valid then return valid end
    end
    local year = tonumber(args.year or args.psscyear)
    local month = tonumber(args.month)
    local day = tonumber(args.day)
    if year and month and day and year>=0 and month>=1 and month<=3 and day>=1 and day<=61 then
        return {day=day, month=month, year=year}
    end
    local doy=tonumber(args.dayofyear or args.doy)
    if year and doy and doy>=1 and doy<=183 then
        return {day=((doy-1)%61)+1,month=math.floor((doy-1)/61)+1,year=year}
    end
    -- This matches the PSSC calendar epoch used by existing War League modules.
    local epoch=os.time({year=1999,month=8,day=6,hour=0,min=0,sec=0})
    local elapsed=math.floor((os.time()-epoch)/86400)
    if elapsed < 0 then elapsed=0 end
    return {year=math.floor(elapsed/183),month=math.floor((elapsed%183)/61)+1,day=((elapsed%183)%61)+1}
end

local function tableWiki(caption, headers, body)
    local s = {'{| class="wikitable sortable" style="width:100%;"'}
    if caption and caption~='' then s[#s+1]='|+ '..caption end
    s[#s+1]='|-'
    for _,head in ipairs(headers) do s[#s+1]='! '..safe(head) end
    for _,row in ipairs(body) do
        s[#s+1]='|-'
        for _,cell in ipairs(row) do s[#s+1]='| '..safe(cell) end
    end
    s[#s+1]='|}'
    return concat(s,'\n')
end

local function total(rows, field)
    local result=0
    for _,row in ipairs(rows) do result=result+(tonumber(row[field]) or 0) end
    return result
end

local function sourceTotal(rows,source,field)
    local result=0
    for _,row in ipairs(rows) do
        if row.source==source then result=result+(tonumber(row[field]) or 0) end
    end
    return result
end

local function established(date)
    return ordinal(date)>=ordinal(d.start)
end

local function accessStatement(date)
    local start=ordinal(d.harbor.start)
    local expiry=ordinal(d.harbor.expiry)
    local value=ordinal(date)
    if value<start then
        return 'No Blore Heath access had been entered for the selected date.'
    elseif value<=expiry then
        return 'Recorded access minute in its original term: maximum '..num(d.harbor.maxUniformed)..' uniformed personnel at designated premises and up to '..num(d.harbor.maxCivilian)..' civilians; no citywide stationing entitlement.'
    else
        return 'The original Blore Heath harbor minute reached its scheduled end on 40/2/54 PSSC. No extension was recorded in these module data; continuing access required a separately documented renewal.'
    end
end

local function extraNote(s)
    return '<p><small>'..s..'</small></p>'
end

function p.command(frame)
    local date=dateFor(getArgs(frame))
    if not established(date) then
        return "''The BH-054 joint command had not yet been established on "..displayDate(date)..".''"
    end
    local rows={
        {'Ground component assigned (distributed)',num(d.totalUniformed),'Four parent divisions; excluded ship and aircraft crews'},
        {'Commissioned naval hulls',num(d.totalHulls),'Distributed: outer, middle, entrance stations'},
        {'Aerial platforms',num(d.totalAir),'Based or tasked only under applicable airspace rights'},
        {'Blore Heath admitted on-site maximum',num(d.harbor.maxUniformed),'Specified premises only, during valid minute'},
        {'Sardis-related northern support',num(d.sardis.allocated),'Outside Lydia; local admitted strength '..num(d.sardis.localAdmitted)},
        {'Privateer secondments active',num(d.privateerSecondments.active),'Six listed as conditional, not activated'},
    }
    return "'''Southern Approaches Joint Command (BH-054) — command establishment'''\n\n"
       ..tableWiki('Command allocation / '..displayDate(date),{'Component','Recorded establishment','Qualification'},rows)
       ..extraNote(accessStatement(date)..' Northern local stationing remained unauthorized in the attested register.')
end

function p.orderOfBattle(frame)
    local args=getArgs(frame)
    local rows={}
    for _,x in ipairs(d.personnel) do
        local station = x.sector=='SRD' and 'Northern support, outside Lydia' or 'Blore Heath sector, distributed'
        rows[#rows+1]={"'''"..x.id.."'''",x.source,num(x.strength),station,x.name}
    end
    rows[#rows+1]={"'''TOTAL'''",'Four divisions',"'''"..num(total(d.personnel,'strength')).."'''",'Distributed, not on-site','Embarked crews excluded'}
    return tableWiki('Ground allocation / permanent BH-054 identifiers',{'Designation','Parent division','Personnel','Reporting allocation','Functional group'},rows)
          ..extraNote('Only '..num(d.harbor.maxUniformed)..' uniformed personnel were admitted to specified Blore Heath harbor premises under the initial minute; the '..num(d.sardis.allocated)..'-person northern allocation remained outside Lydia.')
end

local function totalFilteredNaval(group)
    local n=0
    for _,x in ipairs(d.naval) do if group=='' or x.group==group then n=n+x.count end end
    return n
end

function p.fleet(frame)
    local args=getArgs(frame)
    local filter=args.group or ''
    local rows={}
    for _,x in ipairs(d.naval) do
        if filter=='' or x.group==filter then
            rows[#rows+1]={x.group,x.source,x.class,num(x.count),x.mission}
        end
    end
    rows[#rows+1]={"'''TOTAL / displayed'''",'', '',"'''"..num(totalFilteredNaval(filter)).."'''",'Allocated commissioned hulls, not clearances to transit'}
    return tableWiki('Commissioned naval allocation',{'Echelon','Source','Class','Hulls','Recorded purpose'},rows)
           ..extraNote('The 25 hulls were not automatically eligible for simultaneous Strait passage. Warship displacement, submarine rules and applicable clearance were checked separately. Six privateer commissions remained conditional secondments and were excluded from the hull total.')
end

function p.air(frame)
    local rows={}
    for _,x in ipairs(d.air) do
        rows[#rows+1]={x.source,x.class,num(x.count),x.zone,x.mission}
    end
    rows[#rows+1]={"'''TOTAL'''",'',"'''"..num(total(d.air,'count')).."'''",'', 'Foreign basing and flights remained subject to clearance'}
    return tableWiki('Aerial platform allocation',{'Source','Platform','Number','Operating classification','Recorded role'},rows)
        ..extraNote('Swarm carriers and UAV allocation did not confer autonomous-launch, ISR or military-overflight rights in regulated pilotage waters or in Lydia.')
end

function p.groundEquipment(frame)
    local rows={}
    for _,x in ipairs(d.equipment) do
        local all=x.haifan+x.hatch+x.jangsong+x.vaeringheim
        rows[#rows+1]={x.name,num(x.haifan),num(x.hatch),num(x.jangsong),num(x.vaeringheim),num(all),x.purpose}
    end
    local extra={}
    for _,x in ipairs(d.walkers) do extra[#extra+1]={x.name,x.source,num(x.count),x.purpose} end
    return tableWiki('Allocated armored, engineering and sensor systems',{'Equipment','Haifan','Hatch','New South Jangsong','Vaeringheim','Total','Role'},rows)
       ..'\n\n'..tableWiki('Specialized walkers',{'Type','Source','Number','Role'},extra)
       ..extraNote('Source-division allocations were not new manufacture; heavy equipment outside permitted sites did not acquire foreign stationing authority.')
end

local function stableIndex(date,serial,choices)
    local seed=ordinal(date)*193 + serial*977 + 1709
    return (seed % #choices)+1
end

function p.dailyOperations(frame)
    local args=getArgs(frame)
    local date=dateFor(args)
    if not established(date) then
        return "''No BH-054 joint-command readiness schedule had been established by "..displayDate(date)..".''"
    end
    local wanted=tostring(args.domain or 'all'):lower()
    local maxrows=tonumber(args.rows) or 18
    maxrows=math.max(1,math.min(60,math.floor(maxrows)))
    local records={}
    local duties={
        'Command and communications watch',
        'Systems safety and maintenance return',
        'Navigation and rescue coordination',
        'Legally bounded escort / observation readiness',
        'Supply, crew and technical rotation',
    }
    if wanted=='all' or wanted=='naval' then
        for _,x in ipairs(d.navalGroups) do
            records[#records+1]={x.id,'Naval',x.zone,duties[stableIndex(date,#records+1,duties)],num(x.count)..' assigned hulls; clearance checked individually'}
        end
    end
    if wanted=='all' or wanted=='air' or wanted=='aerial' then
        local sources={'Hatch Ministry','Haifan Bassaridia','New South Jangsong','Vaeringheim'}
        for _,name in ipairs(sources) do
            records[#records+1]={'BH-054-AIR-'..tostring(#records+1),'Aerial',name..' air allocation',duties[stableIndex(date,#records+1,duties)],num(sourceTotal(d.air,name,'count'))..' platforms; no foreign basing inferred'}
        end
    end
    if wanted=='all' or wanted=='ground' then
        for _,x in ipairs(d.personnel) do
            local location=x.sector=='SRD' and 'Outside Lydia — northern support' or 'Distributed BH sector / existing bases'
            records[#records+1]={x.id,'Ground',location,duties[stableIndex(date,#records+1,duties)],num(x.strength)..' assigned; local access separately limited'}
        end
    end
    local rows={}
    for i=1,math.min(#records,maxrows) do rows[#rows+1]=records[i] end
    return tableWiki('Routine administrative readiness rotation / '..displayDate(date),{'BH-054 ID','Domain','Reporting station','Rotating administrative duty','Assigned establishment'},rows)
      ..extraNote('This date-stable readiness roster was generated from the standing allocation. It did not record completed searches, arrests, seizures, combats, diplomatic agreements, property transfers or exceptional authorizations. Those events required explicit historical entries.')
end

function p.timeline(frame)
    local args=getArgs(frame)
    local cap=tonumber(args.rows) or #events
    cap=math.max(1,math.min(cap,100))
    local rows={}
    local historicalLimit = (args.date or args.year or args.psscyear) and dateFor(args) or nil
    local shown=0
    for _,e in ipairs(events) do
        local eDate=parsePSSC(e.date)
        if not historicalLimit or (eDate and ordinal(eDate)<=ordinal(historicalLimit)) then
            shown=shown+1
            if shown>cap then break end
            rows[#rows+1]={e.date..' PSSC',"'''"..e.id.."'''",e.kind,e.station,e.summary}
        end
    end
    return tableWiki('Attested establishment events',{'Date','Instrument / ID','Type','Reporting station','Recorded development'},rows)
      ..extraNote('Later decisions were not backfilled automatically. An event was added only when its date, authority and outcome had been recorded.')
end

function p.maritimeRegister(frame)
    local rows={}
    for _,x in ipairs(d.maritimeRules) do rows[#rows+1]={x.subject,x.vessels,x.condition,x.authority} end
    return tableWiki('Published maritime controls and applicable authorities',{'Control','Covered traffic','Requirement or limit','Authority'},rows)
      ..extraNote('This table described governing procedures; it was not a count of completed inspections or prizes. Foreign nonalignment alone was not an offence.')
end

function p.complianceRegister(frame)
    local args=getArgs(frame)
    local date=dateFor(args)
    local rows={}
    for _,x in ipairs(d.laws) do rows[#rows+1]={'[['..x.name..']]',x.status,x.effect} end
    local out=tableWiki('Legislative status at the recorded 26/2/54 PSSC docket',{'Instrument','Recorded status','Material BH-054 condition'},rows)
    out=out..extraNote('Legislative status was fixed to the verified historical docket and was not automatically upgraded when the current calendar advanced. '..accessStatement(date))
    return out
end

function p.reviewSchedule(frame)
    local args=getArgs(frame)
    local date=dateFor(args)
    local rows={}
    for _,x in ipairs(d.reviews) do
        local due=parsePSSC(x.date)
        local phase=(due and ordinal(date)>ordinal(due)) and 'Past due in calendar; completion not entered' or 'Due by the recorded date; completion not entered'
        rows[#rows+1]={x.date..' PSSC',x.matter,x.basis,phase}
    end
    return tableWiki('Statutory review and renewal control',{'Date','Review / limit','Basis','Status in module'},rows)
end

function p.northernStation(frame)
    return tableWiki('BH-054-S3 — Sardis-related allocation',{'Parent division','Allocated personnel','Locally admitted','Position'}, {
         {'Haifan Bassaridia','160','0','Outside Lydian jurisdiction'},
         {'Hatch Ministry','96','0','Outside Lydian jurisdiction'},
         {'New South Jangsong','24','0','Outside Lydian jurisdiction'},
         {"'''TOTAL'''","'''280'''","'''0'''",'No Lydian access compact was entered in the record'},
    })..extraNote('Northern stationing required a separately concluded agreement with competent Lydian authorities and appropriate Bassaridian authorization. This module did not presume such consent.')
end

function p.civilian(frame)
    return tableWiki('General Port and continuity offices',{'Record','Recorded responsibility','Legal qualification'}, {
      {'General Port civilian allocation','110 civilian personnel across the distributed command','Excluded from uniformed ground strength'},
      {'Blore Heath locally admitted civilians','Up to 20 under the initial minute','Separately accredited; no transfer of public authority'},
      {'Imperial-era contracts','Title, payroll, ownership and claimant reconciliation','No automatic vesting of foreign parent companies'},
      {'Medical and dock services','Clinic, safety, water and emergency transport coordination','Local consent and applicable public-health authority'},
      {'HCE White-Lane','Humanitarian passage and observer support','Not conditioned on political alignment'},
      {'Sardis civilian desk','Northern commercial reference and lawful remote correspondence','Not a locally admitted Lydian office'},
    })..extraNote('No report of completed acquisition or compulsory purchase was generated from these planning and recordkeeping allocations.')
end

function p.audit(frame)
    local navalGroups={}
    for _,x in ipairs(d.naval) do navalGroups[x.group]=(navalGroups[x.group] or 0)+x.count end
    local faults={}
    if total(d.personnel,'strength') ~= d.totalUniformed then faults[#faults+1]='Ground allocation total mismatch' end
    if total(d.naval,'count') ~= d.totalHulls then faults[#faults+1]='Naval hull allocation mismatch' end
    if total(d.air,'count') ~= d.totalAir then faults[#faults+1]='Aerial allocation mismatch' end
    for _,x in ipairs(d.navalGroups) do
        if (navalGroups[x.id] or 0) ~= x.count then faults[#faults+1]='Task group mismatch: '..x.id end
    end
    local northern=0
    for _,x in ipairs(d.personnel) do if x.sector=='SRD' then northern=northern+x.strength end end
    if northern~=d.sardis.allocated then faults[#faults+1]='Northern allocation mismatch' end
    local sources={'Hatch Ministry','Haifan Bassaridia','New South Jangsong','Vaeringheim'}
    local rows={}
    for _,name in ipairs(sources) do
        rows[#rows+1]={name,num(sourceTotal(d.personnel,name,'strength')),num(sourceTotal(d.naval,name,'count')),num(sourceTotal(d.air,name,'count'))}
    end
    rows[#rows+1]={"'''TOTAL'''","'''"..num(d.totalUniformed).."'''","'''"..num(d.totalHulls).."'''","'''"..num(d.totalAir).."'''"}
    local status=(#faults==0) and "'''PASS — allocation arithmetic reconciled.'''" or "'''CHECK:''' "..concat(faults,'; ')
    return status..'\n\n'..tableWiki('BH-054 arithmetic audit',{'Parent','Ground personnel','Hulls','Air platforms'},rows)
      ..extraNote('This audit checked arithmetic only. It did not independently certify national inventory availability, vessel tonnage, current physical location, foreign consent or the completion of statutory returns.')
end

return p