I've created spaghetti so this is what I've resorted to

This commit is contained in:
Lilian Jónsdóttir 2020-10-04 01:15:07 -07:00
parent 8708e5e52e
commit d8c1aaf0f6

View file

@ -6,16 +6,32 @@ local this = {}
local function log(level, ...) if config.logLevel >= level then common.log(...) end end
-- cellEvaluators can't require checks because checks already requires cellEvaluators
-- this means I have too much spaghetti
local function isIgnoredNPCLite(npc)
local obj = npc.baseObject and npc.baseObject or npc.object
local isGuard = obj.isGuard or (obj.name and (obj.name:lower():match("guard") and true or false) or false) -- maybe this should just be an if else
local isVampire = obj.head and (obj.head.vampiric and true or false) or false
return config.ignored[obj.id:lower()] or
config.ignored[obj.sourceMod:lower()] or
isGuard or
isVampire
end
-- cell worth is combined worth of all NPCs
this.calculateCellWorth = function(cell, proprietor)
local worth = 0
local msg = "breakdown:\n"
for innard in cell:iterateReferences(tes3.objectType.npc) do
if not isIgnoredNPCLite(innard) then
local total = npcEvaluators.calculateNPCWorth(innard, innard == proprietor and cell or nil).total
worth = worth + total
msg = msg .. string.format("%s worth:%s, ", innard.object.name, total)
end
end
log(common.logLevels.medium, "[CELLEVAL] Calculated worth of %s for cell %s", worth, cell.id)
log(common.logLevels.large, "[CELLEVAL] " .. msg:sub(1, #msg - 2)) -- strip off last ", "
@ -29,6 +45,7 @@ this.pickCellFaction = function(cell)
-- count all the npcs with factions
for npc in cell:iterateReferences(tes3.objectType.npc) do
if not isIgnoredNPCLite(npc) then
local faction = npc.object.faction
if faction then
@ -42,6 +59,7 @@ this.pickCellFaction = function(cell)
npcs.total = npcs.total + 1
end
end
-- pick out all the factions that make up a percentage of the cell greater than the configured value
-- as long as the cell passes the minimum requirement check