adds sphere analysis

This commit is contained in:
duncathan 2021-04-05 23:58:00 -06:00
parent 170e60dcdd
commit ea6549139c
4 changed files with 47 additions and 10 deletions

View file

@ -28,6 +28,7 @@ end
function C:setItem(item)
item.placed = true
item.location_name = self.name
self.item = item
end

View file

@ -695,9 +695,11 @@ function worldGraph:writeItems(tscFiles)
self.hintregion:writeItems(tscFiles)
end
function worldGraph:collect(preCollectedItems)
local collected = _.clone(preCollectedItems) or {}
local availableLocations = self:getFilledLocations()
function worldGraph:collect(preCollectedItems, locations, singleSphere)
local collected = _.clone(preCollectedItems, singleSphere) or {}
local availableLocations = locations or self:getFilledLocations()
local inventory = (singleSphere and preCollectedItems) or collected
local foundItems = 0
repeat
@ -707,7 +709,7 @@ function worldGraph:collect(preCollectedItems)
local j, n = 1, #availableLocations
for i = 1, n do
local location = availableLocations[i]
if location:canAccess(collected) then
if location:canAccess(inventory) then
table.insert(collected, location.item)
foundItems = foundItems + 1
availableLocations[i] = nil
@ -724,7 +726,7 @@ function worldGraph:collect(preCollectedItems)
--[[local s = "Collected items: "
for k,v in ipairs(collected) do s = s .. v.name .. ", " end
logDebug(s)]]
return collected
return collected, availableLocations
end
function worldGraph.locationsArray(locations)

View file

@ -1,4 +1,4 @@
local LOG_LEVEL, _logCounts, _logLines = 4, nil, nil
local LOG_LEVEL, _logCounts, _logLines = 6, nil, nil
local function _log(level, prefix, text, ...)
if LOG_LEVEL >= level then
local text = prefix .. text
@ -13,8 +13,10 @@ function logError(...) _log(1, 'ERROR: ', ...) end
function logWarning(...) _log(2, 'WARNING: ', ...) end
function logNotice(...) _log(3, 'NOTICE: ', ...) end
function logSpoiler(...) _log(4, 'SPOILER: ', ...) end
function logInfo(...) _log(5, 'INFO: ', ...) end
function logDebug(...) _log(6, 'DEBUG: ', ...) end
function logSphere(...) _log(5, 'SPHERE: ', ...) end
function logRoute(...) _log(6, 'ROUTE: ', ...) end
function logInfo(...) _log(7, 'INFO: ', ...) end
function logDebug(...) _log(8, 'DEBUG: ', ...) end
function countLogWarningsAndErrors()
return _logCounts[2], _logCounts[1]
end
@ -22,7 +24,7 @@ function getLogText()
return table.concat(_logLines, "\r\n")
end
function resetLog()
_logCounts = {0, 0, 0, 0, 0, 0}
_logCounts = {0, 0, 0, 0, 0, 0, 0, 0}
_logLines = {}
end
resetLog()

View file

@ -77,6 +77,9 @@ function C:randomize()
self:_generateHash()
if self.shuffleMusic then self.music:shuffleMusic(tscFiles) end
self:_analyzeSpheres()
self:_generateRoute()
self:_writeModifiedData(tscFiles)
self:_writePlaintext(tscFiles)
self:_writeLog()
@ -231,7 +234,7 @@ function C:_fillItems(items, locations)
local filter = function(k,v) return not v:hasItem() and v:canAccess(assumed) end
if self.completableLogic and self.worldGraph:canBeatGame(assumed) then
if self.completableLogic and self.worldGraph:canBeatGame(assumed, self.obj) then
filter = function(k,v) return not v:hasItem() end
end
@ -256,6 +259,35 @@ function C:_fastFillItems(items, locations)
end
end
function C:_analyzeSpheres()
local spheres = {}
local items = {}
local locations
local i = 0
repeat
i = i+1
local collected
collected, locations = self.worldGraph:collect(items, locations, true)
local sphereItems = _.difference(collected, items)
items = collected
if #sphereItems == 0 then break end
logSphere(("Sphere %i"):format(i))
for k,v in pairs(sphereItems) do
if not self.worldGraph:_has({v}, "abstract") then
logSphere(("\t %s: %s"):format(v.location_name, v.name))
end
end
until false
end
function C:_generateRoute()
return
end
function C:_generateHints()
local toHint = _.shuffle(self.worldGraph:getHintableLocations(self.obj))
for k, hintLocation in ipairs(_.shuffle(self.worldGraph:getHintLocations())) do