less bias towards wilderness cells

Wilderness cells all share the same name, so there would be multiple with the same name in the list of cells, leading towards those being picked slightly more often in RNG
This commit is contained in:
Lilian Jónsdóttir 2020-08-05 00:44:23 -07:00
parent ba1c4ae7fd
commit f47f90f01b

View file

@ -30,6 +30,7 @@ local function pickSpot(cell)
-- this will be the position/orientation destination of every door that puts the player into the above chosen cell -- this will be the position/orientation destination of every door that puts the player into the above chosen cell
local spots = {} local spots = {}
local spot local spot
local default = {position = tes3vector3.new(0, 0, 0), orientation = tes3vector3.new(0, 0, 0)}
-- peek through doors in that cell to pick a position/orientation for the player -- peek through doors in that cell to pick a position/orientation for the player
for cellDoor in cell:iterateReferences(tes3.objectType.door) do for cellDoor in cell:iterateReferences(tes3.objectType.door) do
@ -56,16 +57,14 @@ local function pickSpot(cell)
if #spots > 0 then if #spots > 0 then
log("There %s %s spot%s in %s", #spots > 1 and "were" or "was", #spots, #spots > 1 and "s" or "", cell.id) log("There %s %s spot%s in %s", #spots > 1 and "were" or "was", #spots, #spots > 1 and "s" or "", cell.id)
spot = table.choice(spots) spot = table.choice(spots)
else
-- if we don't find any then use 0,0,0, which can be really bad in some cells
spot = {position = tes3vector3.new(0, 0, 0), orientation = tes3vector3.new(0, 0, 0)}
end end
return spot -- if we don't find any then use 0,0,0, which can be really bad in some cells
return spot or default
end end
local function pickCell(ogDest) local function pickCell(ogDest)
local picked = table.choice(cells) local _, picked = table.choice(cells)
local cell = tes3.getCell({id = picked}) local cell = tes3.getCell({id = picked})
if config.ignoredCells[cell.id] then if config.ignoredCells[cell.id] then
@ -167,9 +166,11 @@ local function onCellChanged(e)
end end
local function onInitialized(e) local function onInitialized(e)
for cell, _ in pairs(tes3.dataHandler.nonDynamicData.cells) do table.insert(cells, cell) end for cell, _ in pairs(tes3.dataHandler.nonDynamicData.cells) do cells[cell] = true end
log("found %s cells", #cells) local i = 0
for _ in pairs(cells) do i = i + 1 end
log("found %s %s unique cell names", i)
event.register("activate", onActivate) event.register("activate", onActivate)
event.register("cellChanged", onCellChanged) event.register("cellChanged", onCellChanged)