Module:CargoShip

-- local p = {} -- Function to calculate the cost in gold for each Cargo ship up to 180 function countcost(lvl) local n = 4500*1.03^tonumber(lvl)-4475 return 3*(n%1>=0.5 and math.ceil(n) or math.floor(n)) end function p.table(frame) -- Ambrosia values from 181 to 220. They don't follow a formula, that's why the following table is used. local ambr = {74,71,68,65,63,61,59,57,55,53,51,49,47,45,43,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17} -- The following parameters are used to filter the result of the module. If no parameters are given, there will be created 4 tables local from = tonumber(frame.args[1] or frame.args['from'] or 1) local to = tonumber(frame.args[2] or frame.args['to'] or 20) -- Get the title of the page in order to reset the ship count column when it is the Phoenician Merchant Ship page local ttl = frame:preprocess('') -- Set of variables local rows = '' local acc = 0 local cost = 0 local acccost = '' local hd = '' local ft = '' local cn = '' local acccn = '' local ln = 0 -- Contents of header of the table depending on the defined limits (from, to) if from>=1 and to<=180 then -- Cargo Ships cn = frame:preprocess(' ') acccn = 'Accumulated '..frame:preprocess(' ') elseif from>=181 and to<=220 then -- Phoenician Merchant Ships cn = frame:preprocess('') acccn = 'Accumulated '..frame:preprocess('') elseif from>=221 and to<=234 then -- Cargo Ships from Form of Government or 7th day bonus cn = 'Cost(s)' acccn = 'Accumulated Cost(s)' elseif from>=235 and to<=306 then -- Cargo Ships from Friend List (NOT implemented any more due to Lobby) cn = 'Cost(s)' acccn = 'Accumulated Cost(s)' end -- Generate the rows of the main body of the table for i=1,306 do -- Calculation of the Accumulated values if i>=1 and i<=180 then acc = (i==1 and 0 or acc)+countcost(i) elseif i>=181 and i<=220 then acc = (i==181 and 0 or acc)+ambr[i-180] end acccost = acccost..(i==180 and frame:preprocess() or )..(i==220 and ' '..frame:preprocess() or ) if i>=from and i<=to then if i>=1 and i<=180 then -- Cargo Ships cost = frame:preprocess('NaN') elseif i>=181 and i<=220 then -- Phoenician Merchant Ships cost = frame:preprocess('NaN') elseif i>=221 and i<=306 then -- Rest of ships cost = ' Government / Daily Bonus = FREE ' acc = acccost if i>=235 then ln = 1 end end rows = rows..' '..(i-((i>180 and ttl=='Phoenician Merchant Ship') and 180 or 0))..'  '..cost..'  '..frame:preprocess('NaN')..'  '..frame:preprocess('NaN')..'  ' end end -- Assembling the header and footer of the table hd = ' '..from..' - '..to..' Cargo Ships   Ship Count '..cn..'  '..acccn..'  Accumulated Cargo ' ft = ' Ship Count '..cn..'  '..acccn..'  Accumulated Cargo  ' -- Generate the final structure and contents of the table return hd..rows..ft end return p