Module:BATTD costs: Difference between revisions
mNo edit summary |
mNo edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 25: | Line 25: | ||
local upgrades, upgradePrereqs, upgradeLocks = | local upgrades, upgradePrereqs, upgradeLocks = | ||
query("battd_upgrades", "_pageName, id, name, tower, cost", { | query("battd_upgrades", "_pageName, id, name, tower, cost", { | ||
where=sFormat("tower='%s'", towerName) | where=sFormat("tower='%s'", towerName), | ||
orderBy="cost" | |||
}), | }), | ||
query("battd_upgrades=main, battd_upgrades__previous=prev", "main.id=thisId, prev._value=prevId", { | query("battd_upgrades=main, battd_upgrades__previous=prev", "main.id=thisId, prev._value=prevId", { | ||
| Line 97: | Line 98: | ||
if not alreadyPurchasedUpgrades[upgrade.id] then row[#row+1] = sFormat("!![[%s|%s]]", upgrade._pageName, upgrade.name) end | if not alreadyPurchasedUpgrades[upgrade.id] then row[#row+1] = sFormat("!![[%s|%s]]", upgrade._pageName, upgrade.name) end | ||
end | end | ||
--mw.logObject(upgradeLocksById) | |||
outputTable[1] = tConcat(row) | outputTable[1] = tConcat(row) | ||
| Line 116: | Line 119: | ||
if upgradePrereqsOfById[thisUpgradeId] then | if upgradePrereqsOfById[thisUpgradeId] then | ||
for _, nextUpgradeId in pairs(upgradePrereqsOfById[thisUpgradeId]) do | for _, nextUpgradeId in pairs(upgradePrereqsOfById[thisUpgradeId]) do | ||
if not purchasedUpgrades[nextUpgradeId] and | if not purchasedUpgrades[nextUpgradeId] then | ||
-- shallow copy purchasedUpgrades and check if nextUpgradeId is locked by another upgrade | |||
local purchasedUpgradesNext = {} | local purchasedUpgradesNext = {} | ||
local doNext = true | |||
for purchasedUpgrade, _ in pairs(purchasedUpgrades) do | |||
-- if nextUpgradeId is locked by a purchasedUpgrade then don't proceed | |||
if upgradeLocksById[purchasedUpgrade] and upgradeLocksById[purchasedUpgrade][nextUpgradeId] then | |||
doNext = false | |||
break | |||
end | |||
purchasedUpgradesNext[purchasedUpgrade] = true | |||
end | |||
-- lock this combination so it isn't repeated on the graph again | if doNext then | ||
purchasedUpgradesNext[nextUpgradeId] = true | |||
recursiveGetTotalCosts(currentCost + upgradesById[nextUpgradeId].cost, purchasedUpgradesNext) | |||
-- lock this combination so it isn't repeated on the graph again | |||
if not upgradeLocksById[thisUpgradeId] then upgradeLocksById[thisUpgradeId] = {} end | |||
upgradeLocksById[thisUpgradeId][nextUpgradeId] = true | |||
if not upgradeLocksById[nextUpgradeId] then upgradeLocksById[nextUpgradeId] = {} end | |||
upgradeLocksById[nextUpgradeId][thisUpgradeId] = true | |||
end | |||
end | end | ||
end | end | ||