Module:BATTD costs: Difference between revisions

mNo edit summary
mNo edit summary
Line 125: Line 125:
local upgradePrereqsById = {} -- key:values table - upgrade:prerequisites to purchase this upgrade
local upgradePrereqsById = {} -- key:values table - upgrade:prerequisites to purchase this upgrade
local upgradePrereqsOfById = {} -- key:values table - upgrades:upgrades this is a prerequisite of
local upgradePrereqsOfById = {} -- key:values table - upgrades:upgrades this is a prerequisite of
local notPurchasedUpgrades = {} -- this upgrade and all upgrades the player has to have already purchased to get it
local availableUpgradesById = {} -- this upgrade and all upgrades the player has to have already purchased to get it
-- cargo queries for data
-- cargo queries for data
Line 145: Line 145:
for i, upgrade in ipairs(upgrades) do
for i, upgrade in ipairs(upgrades) do
upgradesById[upgrade.id] = upgrade
upgradesById[upgrade.id] = upgrade
notPurchasedUpgrades[upgrade.id] = upgrade
availableUpgradesById[upgrade.id] = upgrade
if upgrade.name == upgradeName then upgradeId = upgrade.id end
if upgrade.name == upgradeName then upgradeId = upgrade.id end
end
end
Line 174: Line 174:
local function getAlreadyPurchasedUpgrades(myUpgradeId)
local function getAlreadyPurchasedUpgrades(myUpgradeId)
local cost = upgradesById[myUpgradeId].cost
local cost = upgradesById[myUpgradeId].cost
notPurchasedUpgrades[myUpgradeId] = nil
availableUpgradesById[myUpgradeId] = nil
for i, id in ipairs(upgradePrereqsById[myUpgradeId]) do
for i, id in ipairs(upgradePrereqsById[myUpgradeId]) do
Line 181: Line 181:
return cost
return cost
end
end
-- remove future upgrades
local function removeFutureUpgrades(myUpgradeId)
for _, id in ipairs(upgradePrereqsOfById[myUpgradeId]) do
availableUpgradesById[id] = nil
removeFutureUpgrades(id)
end
end
removeFutureUpgrades(ipgradeId)


-- build upgradeLocksById
-- build upgradeLocksById
Line 198: Line 207:
})[1].cost
})[1].cost
return GetTotalCosts(baseCost, notPurchasedUpgrades, upgradeLocksById, upgradePrereqsOfById, Y, N)
return GetTotalCosts(baseCost, availableUpgradesById, upgradeLocksById, upgradePrereqsOfById, Y, N)
end
end