Module:Weapon Upgrades

--Module:Sandbox --Table local p = {}

---BUILD FUNCTION--- function p.Upgrade(frame) --Import Arguments stats = frame:getParent.args; --Read in for all weapons, pass to sub-functions mode = stats["weapon-mode"]; mk2 = Logic(stats["mark-2"]); Level_base = formatnum(stats["base-level"]); rounds = formatnum(stats["rounds"]); time_total = stats["total-upgrade-time"]; --Protect against mising time if time_total == "" then time_total = "Unknown"; end --for storing totals local cost_total = 0; --Create output variable local tab = "";

--Mode select --Normal mode if mode == "normal" then --read in mode-specific values local time_cyc = formatnum(stats["cycle-time"]); local time_reload = formatnum(stats["reload-time"]); local time_unload = time_cyc - time_reload; --get Heading local h = header_normal; --Write purchase heading and purchase table header to output tab = "==Purchase information==\n"..h[1]..Level_base.."\n|"; --Retrieve Statisics for base level local r = level_data(Level_base);

-- Run Calc local c = calc_normal(r[3],rounds,time_cyc,time_unload);

--Write purchase table to output tab = tab..r[1].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|"..c[3].."\n|}\n"; --Write Header for main table tab = tab.."===Upgrade Information===\n"..h[2];

--Loop accross remaining levels, and write each for n = (Level_base + 1),12 do           --read in statistics and run calc r = level_data(n); c = calc_normal(r[3],rounds,time_cyc,time_unload); --Write to output tab = tab.."!"..n.."\n|"..r[1].."\n|"..r[2].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|"..c[3].."\n"; --sum upgrade costs cost_total = cost_total + formatnum(r[1]); --for all levels except final, end row if n == 12 then tab = tab.."|}\n"; --otherwise start new row else tab = tab.."|-\n"; end end --Accelerated mode elseif mode == "accelerated" then --read in mode-specific values local rof_low = formatnum(stats["initial-rate-of-fire"]); local rof_high = formatnum(stats["rate-of-fire"]);

--get Heading local h = header_accel; --Write purchase heading and purchase table header to output tab = "==Purchase information==\n"..h[1]..Level_base.."\n|"; --Retrieve Statisics for base level local r = level_data(Level_base);

-- Run Calc local c = calc_accel(r[3],rounds,rof_low,rof_high);

--Write purchase table to output tab = tab..r[1].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|"..c[3].."\n|}\n"; --Write Header for main table tab = tab.."===Upgrade Information===\n"..h[2]; --Loop accross remaining levels, and write each for n = (Level_base + 1),12 do           --read in statistics and run calc r = level_data(n); c = calc_accel(r[3],rounds,rof_low,rof_high); --Write to output tab = tab.."!"..n.."\n|"..r[1].."\n|"..r[2].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|"..c[3].."\n"; --sum upgrade costs cost_total = cost_total + formatnum(r[1]); --for all levels except final, end row if n == 12 then tab = tab.."|}\n"; --otherwise start new row else tab = tab.."|-\n"; end end --FWR mode elseif mode == "FWR" then --read in mode-specific values local time_unload = formatnum(stats["unload-time"]); local time_reload = formatnum(stats["reload-time"]); --get Heading local h = header_fwr; --Write purchase heading and purchase table header to output tab = "==Purchase information==\n"..h[1]..Level_base.."\n|"; --Retrieve Statisics for base level local r = level_data(Level_base);

-- Run Calc local c = calc_fwr(r[3],rounds,time_unload,time_reload);

--Write purchase table to output tab = tab..r[1].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|"..c[3].."\n|}\n"; --Write Header for main table tab = tab.."===Upgrade Information===\n"..h[2]; --Loop accross remaining levels, and write each for n = (Level_base + 1),12 do           --read in statistics and run calc r = level_data(n); c = calc_fwr(r[3],rounds,time_unload,time_reload); --Write to output tab = tab.."!"..n.."\n|"..r[1].."\n|"..r[2].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|"..c[3].."\n"; --sum upgrade costs cost_total = cost_total + formatnum(r[1]); --for all levels except final, end row if n == 12 then tab = tab.."|}\n"; --otherwise start new row else tab = tab.."|-\n"; end end --Charge mode elseif mode == "charge" then --read in mode-specific values local time_reload = formatnum(stats["reload-time"]); local time_charge = formatnum(stats["charge-time"]); --get Heading local h = header_charge; --Write purchase heading and purchase table header to output tab = "==Purchase information==\n"..h[1]..Level_base.."\n|"; --Retrieve Statisics for base level local r = level_data(Level_base);

-- Run Calc local c = calc_charge(r[3],rounds,time_reload,time_charge);

--Write purchase table to output tab = tab..r[1].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|"..c[3].."\n|\n"..c[4].."\n|}\n"; --Write Header for main table tab = tab.."===Upgrade Information===\n"..h[2]; --Loop accross remaining levels, and write each for n = (Level_base + 1),12 do           --read in statistics and run calc r = level_data(n); c = calc_charge(r[3],rounds,time_reload,time_charge); --Write to output tab = tab.."!"..n.."\n|"..r[1].."\n|"..r[2].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|"..c[3].."\n|"..c[4].."\n"; --sum upgrade costs cost_total = cost_total + formatnum(r[1]); --for all levels except final, end row if n == 12 then tab = tab.."|}\n"; --otherwise start new row else tab = tab.."|-\n"; end end --Burst mode elseif mode == "burst" then --read in mode-specific values local time_reload = formatnum(stats["reload-time"]); --get Heading local h = header_burst; --Write purchase heading and purchase table header to output tab = "==Purchase information==\n"..h[1]..Level_base.."\n|"; --Retrieve Statisics for base level local r = level_data(Level_base);

-- Run Calc local c = calc_burst(r[3],rounds,time_reload);

--Write purchase table to output tab = tab..r[1].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n|}\n"; --Write Header for main table tab = tab.."===Upgrade Information===\n"..h[2]; --Loop accross remaining levels, and write each for n = (Level_base + 1),12 do           --read in statistics and run calc r = level_data(n); c = calc_burst(r[3],rounds,time_reload); --Write to output tab = tab.."!"..n.."\n|"..r[1].."\n|"..r[2].."\n|"..r[3].."\n|"..c[1].."\n|"..c[2].."\n"; --sum upgrade costs cost_total = cost_total + formatnum(r[1]); --for all levels except final, end row if n == 12 then tab = tab.."|}\n"; --otherwise start new row else tab = tab.."|-\n"; end end --Constant mode elseif mode == "constant" then --No mode-specific values, skip this step --get Heading local h = header_const; --Write purchase heading and purchase table header to output tab = "==Purchase information==\n"..h[1]..Level_base.."\n|"; --Retrieve Statisics for base level local r = level_data(Level_base);

-- Run Calc local c = calc_const(r[3],rounds);

--Write purchase table to output tab = tab..r[1].."\n|"..r[3].."\n|"..c.."\n|}\n"; --Write Header for main table tab = tab.."===Upgrade Information===\n"..h[2]; --Loop accross remaining levels, and write each for n = (Level_base + 1),12 do           --read in statistics and run calc r = level_data(n); c = calc_const(r[3],rounds); --Write to output tab = tab.."!"..n.."\n|"..r[1].."\n|"..r[2].."\n|"..r[3].."\n|"..c.."\n"; --sum upgrade costs cost_total = cost_total + formatnum(r[1]); --for all levels except final, end row if n == 12 then tab = tab.."|}\n"; --otherwise start new row else tab = tab.."|-\n"; end end --Error mode else --what to return if the mode selector is invalid return "UNRECOGNIZED MODE: "..mode; end --Create totals table tab = tab..header_totals..cost_total.."\n|"..time_total.."\n|}\n"; --DEBUG OUTPUT, ONLY ENABLE IF THERE IS AN ERROR --return " "..tab.." "

return tab; end

---FETCH FUNCTIONS-- --This function retrieves level-specific data, provided it is given --the target level function level_data(level) --convert input in a fixed way level = string.format( "%02d", level); --Retrive Statistics from template local cost = stats["level-"..level.."-cost"]; local time_upgrade = stats["level-"..level.."-time"]; local dmg = stats["level-"..level.."-damage"]; --Handle empty strings if cost == "" then cost = "Unknown"; end if time_upgrade == "" then time_upgrade = "''Unkown"; end if dmg == "" then dmg = -1; --Also convert dmg to a number if valid else dmg = formatnum(dmg); end return {cost, time_upgrade, dmg}; end

CALCULATOR FUNCTIONS --Normal mode calculator function calc_normal(dmg,rounds,time_cyc,time_unload) local dmg_cyc = dmg * rounds; local dps_burst = round(dmg_cyc / time_unload); local dps_cyc = round(dmg_cyc / time_cyc); return {dmg_cyc, dps_burst, dps_cyc}; end

--Accelerated mode Calculator (Machine guns, Auto-cannons) function calc_accel(dmg,rounds,rof_low,rof_high) local dmg_cyc = dmg * rounds; local dps_low = round(dmg * rof_low); local dps_high = round(dmg * rof_high); return {dmg_cyc, dps_low, dps_high}; end

--FWR mode Calculator (Rockets, Shotguns, Lasers, Dragoon) function calc_fwr(dmg,rounds,time_unload,time_reload) local dmg_cyc = dmg * rounds; local dps_burst = round(dmg_cyc / time_unload); local dps_const = round(dmg_cyc / time_reload); return {dmg_cyc, dps_burst, dps_const} ; end

--Charge mode Calculator (Energy Snipers, Shocktrain) function calc_charge(dmg,rounds,time_reload,time_charge) local dmg_cyc = dmg * rounds; local dps_cyc = round(dmg_high / (time_reload + time_charge)); local dmg_cyc_low = dmg; local dps_cyc_low = round(dmg_low / time_reload); return {dmg_cyc,dps_cyc,dmg_cyc_low,dps_cyc_low}; end

--Burst mode Calculator (Burst Missiles, Kinetic Snipers, Lightning Cannons, Spiral, Noricum) function calc_burst(dmg,rounds,time_reload) local dmg_cyc = dmg * rounds; local dps_cyc = round(dmg_cyc / time_reload); return {dmg_cyc,dps_cyc}; end

--Constant mode Calculator (Magnum) function calc_const(dmg, rounds) local dps = dmg * rounds; return dps; end

--HEADER FUNCTIONS-- --The header for the totals table, which is shared function header_totals return "{|class=\"article-table weapon-upgrades\"\n!\n!Cost\n!Time\n|-\n!Totals\n|" end --The header strings for the NORMAL mode function header_normal local purchase = "{|class=\"article-table weapon-upgrades\"\n!Purchase Level\n!Purchase Cost\n!Damage\n!Cycle Damage\n!Burst DPS\n!Cycle DPS\n|-\n!"; local normal = "{| class=\"article-table weapon-upgrades\"\n! Level\n! Cost (Ag)\n!Time\n! Damage\n!Cycle Damage\n!Burst DPS\n!Cycle DPS\n|-\n"; local rank_up = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost\n!Damage\n!Cycle Damage\n!Burst DPS\n!Cycle DPS\n|-\n!"; return {purchase, normal, rank_up}; end

--The header strings for the ACCELERATED mode function header_accel local purchase = "{|class=\"article-table weapon-upgrades\"\n!Purchase Level\n!Purchase Cost\n!Damage\n!Cycle Damage\n!Intial DPS\n!Full DPS\n|-\n!"; local normal = "{| class=\"article-table weapon-upgrades\"\n! Level\n! Cost (Ag)\n!Time\n! Damage\n!Cycle Damage\n!Intial DPS\n!Full DPS\n|-\n"; local rank_up = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost\n!Damage\n!Cycle Damage\n!Intial DPS\n!Full DPS\n|-\n!"; return {purchase, normal, rank_up}; end

--The header strings for the FIRE-WHILE-RELOADING mode function header_fwr local purchase = "{|class=\"article-table weapon-upgrades\"\n!Purchase Level\n!Purchase Cost\n!Damage\n!Cycle Damage\n!Burst DPS\n!Continuous DPS\n|-\n!"; local normal = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost(Ag)\n!Time\n!Damage\n!Cycle Damage\n!Burst DPS\n!Continuous DPS\n|-\n"; local rank_up = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost\n!Damage\n!Cycle Damage\n!Burst DPS\n!Continuous DPS\n|-\n!"; return {purchase, normal, rank_up}; end

--The header strings for the CHARGE mode function header_charge local purchase = "{|class=\"article-table weapon-upgrades\"\n!Purchase Level\n!Purchase Cost\n!Damage\n!Cycle Damage\n!Cycle DPS\n!Rapid Cycle Damage\n!Rapid Cycle DPS\n|-\n!"; local normal = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost(Ag)\n!Time\n!Damage\n!Cycle Damage\n!Cycle DPS\n!Rapid Cycle Damage\n!Rapid Cycle DPS\n|-\n"; local rank_up = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost\n!Damage\n!Cycle Damage\n!Cycle DPS\n!Rapid Cycle Damage\n!Rapid Cycle DPS\n|-\n!"; return {purchase, normal, rank_up} end

--The header strings for the BURST mode function header_burst local purchase = "{|class=\"article-table weapon-upgrades\"\n!Purchase Level\n!Purchase Cost\n!Damage\n!Cycle Damage\n!Cycle DPS\n|-\n!"; local normal = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost(Ag)\n!Time\n!Damage\n!Cycle Damage\n!Cycle DPS\n|-\n"; local rank_up = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost\n!Damage\n!Cycle Damage\n!Cycle DPS\n|-\n!"; return {purchase, normal, rank_up}; end

--The header strings for the CONSTANT mode function header_const local purchase = "{|class=\"article-table weapon-upgrades\"\n!Purchase Level\n!Purchase Cost\n!Damage\n!DPS\n|-\n!"; local normal = "{| class=\"article-table weapon-upgrades\"\n! Level\n! Cost (Ag)\n!Time\n! Damage\n!DPS\n|-\n"; local rank_up = "{|class=\"article-table weapon-upgrades\"\n!Level\n!Cost\n!Damage\n!DPS\n|-\n!"; return {purchase, normal, rank_up}; end

--MISCELANEOUS REQUIRED FUNCTIONS--- --Function for rounding function round(x) return math.floor(x+.5); end

--Function for converting strings to numbers function formatnum(str) return tonumber(string.gsub(str,",",""),10); end

--Function for converting Logic-string inputs to logic values function Logic(val) if val == "true" then return true; else return false; end end

--Current test function, call using --CONTENTS OF FUNCTION WILL NOT BE COMMENTED, DUE TO FREQUENT CHANGES --function p.test --end --Return table return p;