From f47f90f01b1b6d91480ee0ee81d00ea54b3c7efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Wed, 5 Aug 2020 00:44:23 -0700 Subject: [PATCH] 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 --- MWSE/mods/celediel/DoorRandomizer/main.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/MWSE/mods/celediel/DoorRandomizer/main.lua b/MWSE/mods/celediel/DoorRandomizer/main.lua index 8af8fae..5a15bb0 100644 --- a/MWSE/mods/celediel/DoorRandomizer/main.lua +++ b/MWSE/mods/celediel/DoorRandomizer/main.lua @@ -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 local spots = {} 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 for cellDoor in cell:iterateReferences(tes3.objectType.door) do @@ -56,16 +57,14 @@ local function pickSpot(cell) 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) 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 - 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 local function pickCell(ogDest) - local picked = table.choice(cells) + local _, picked = table.choice(cells) local cell = tes3.getCell({id = picked}) if config.ignoredCells[cell.id] then @@ -167,9 +166,11 @@ local function onCellChanged(e) end 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("cellChanged", onCellChanged)