Module:Township: Difference between revisions

From Melvor Idle
(Add land cost functions)
No edit summary
Line 605: Line 605:
-- Gets the cost of the current price of land
-- Gets the cost of the current price of land
-- Taken from township.js -> Township.getNextSectionCost
-- Taken from township.js -> Township.getNextSectionCost
function p.GetLandCost(nthland)
function p._GetLandCost(frame)
local nthland = frame.args ~= nil and frame.args[1] or frame
return p._GetLandCost(nthland)
end
 
function p._GetLandCost(nthland)
-- First FREE_LAND plots of land are free
-- First FREE_LAND plots of land are free
if nthland <= FREE_LAND then
if nthland <= FREE_LAND then
Line 615: Line 620:
-- Gets the cost to buy land until you have X amount of available land
-- Gets the cost to buy land until you have X amount of available land
-- Currently the max is 2048 land
-- Currently the max is 2048 land
function p.GetCumulativeLandCost(totalLand)
function p.GetCumulativeLandCost(frame)
local totalLand = frame.args ~= nil and frame.args[1] or frame
return p._GetCumulativeLandCost(totalLand)
end
 
function p._GetCumulativeLandCost(totalLand)
local cost = 0
local cost = 0
while totalLand > FREE_LAND do
while totalLand > FREE_LAND do
Line 623: Line 633:
return cost
return cost
end
end


-- Returns a table showing the land cost of a town
-- Returns a table showing the land cost of a town
Line 630: Line 641:
table.insert(ret, '\r\n|- style="text-align:center" \r\n! Total Land \r\n! Single Land Cost \r\n! Total Cost')
table.insert(ret, '\r\n|- style="text-align:center" \r\n! Total Land \r\n! Single Land Cost \r\n! Total Cost')
for i=FREE_LAND,Township.maxTownSize,FREE_LAND do
for i=FREE_LAND,Township.maxTownSize,FREE_LAND do
table.insert(ret, '\r\n|-\r\n|'..i..'\r\n|'..Icons.GP(p.GetLandCost(i))..'\r\n|'..Icons.GP(p.GetCumulativeLandCost(i)))
table.insert(ret, '\r\n|-\r\n|'..i..'\r\n|'..Icons.GP(p._GetLandCost(i))..'\r\n|'..Icons.GP(p._GetCumulativeLandCost(i)))
end
end
table.insert(ret, '\r\n|}')
table.insert(ret, '\r\n|}')