sort moved/disabled NPCs by cell; fixes disable NPCs in wilderness option
This commit is contained in:
parent
c3a145a08b
commit
20fc3a90a7
2 changed files with 37 additions and 24 deletions
|
@ -2,7 +2,6 @@
|
||||||
local common = require("celediel.NPCsGoHome.common")
|
local common = require("celediel.NPCsGoHome.common")
|
||||||
local config = require("celediel.NPCsGoHome.config").getConfig()
|
local config = require("celediel.NPCsGoHome.config").getConfig()
|
||||||
local checks = require("celediel.NPCsGoHome.functions.checks")
|
local checks = require("celediel.NPCsGoHome.functions.checks")
|
||||||
local interop = require("celediel.NPCsGoHome.interop")
|
|
||||||
local housing = require("celediel.NPCsGoHome.functions.housing")
|
local housing = require("celediel.NPCsGoHome.functions.housing")
|
||||||
local dataTables = require("celediel.NPCsGoHome.functions.dataTables")
|
local dataTables = require("celediel.NPCsGoHome.functions.dataTables")
|
||||||
local positions = require("celediel.NPCsGoHome.data.positions")
|
local positions = require("celediel.NPCsGoHome.data.positions")
|
||||||
|
@ -17,11 +16,12 @@ local function moveNPC(homeData)
|
||||||
-- add to in memory table
|
-- add to in memory table
|
||||||
local badWeather = checks.isBadWeatherNPC(npc)
|
local badWeather = checks.isBadWeatherNPC(npc)
|
||||||
if badWeather then
|
if badWeather then
|
||||||
common.runtimeData.movedBadWeatherNPCs[npc.id] = homeData
|
common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] = common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] or {}
|
||||||
|
common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName][npc.id] = homeData
|
||||||
else
|
else
|
||||||
common.runtimeData.movedNPCs[npc.id] = homeData
|
common.runtimeData.movedNPCs[homeData.ogPlaceName] = common.runtimeData.movedNPCs[homeData.ogPlaceName] or {}
|
||||||
|
common.runtimeData.movedNPCs[homeData.ogPlaceName][npc.id] = homeData
|
||||||
end
|
end
|
||||||
interop.setRuntimeData(common.runtimeData)
|
|
||||||
|
|
||||||
-- set npc data, so we can move NPCs back after a load
|
-- set npc data, so we can move NPCs back after a load
|
||||||
npc.data.NPCsGoHome = {
|
npc.data.NPCsGoHome = {
|
||||||
|
@ -41,13 +41,15 @@ local function moveNPC(homeData)
|
||||||
homeData.homePosition.x, homeData.homePosition.y, homeData.homePosition.z)
|
homeData.homePosition.x, homeData.homePosition.y, homeData.homePosition.z)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function disableNPC(npc)
|
local function disableNPC(npc, cell)
|
||||||
-- same thing as moveNPC, but disables instead
|
-- same thing as moveNPC, but disables instead
|
||||||
-- add to runtimeData
|
-- add to runtimeData
|
||||||
if checks.isBadWeatherNPC(npc) then
|
if checks.isBadWeatherNPC(npc) then
|
||||||
common.runtimeData.disabledBadWeatherNPCs[npc.id] = npc
|
common.runtimeData.disabledBadWeatherNPCs[cell.id] = common.runtimeData.disabledBadWeatherNPCs[cell.id] or {}
|
||||||
|
common.runtimeData.disabledBadWeatherNPCs[cell.id][npc.id] = npc
|
||||||
else
|
else
|
||||||
common.runtimeData.disabledNPCs[npc.id] = npc
|
common.runtimeData.disabledNPCs[cell.id] = common.runtimeData.disabledNPCs[cell.id] or {}
|
||||||
|
common.runtimeData.disabledNPCs[cell.id][npc.id] = npc
|
||||||
end
|
end
|
||||||
-- set NPC data
|
-- set NPC data
|
||||||
npc.data.NPCsGoHome = {disabled = true}
|
npc.data.NPCsGoHome = {disabled = true}
|
||||||
|
@ -84,8 +86,6 @@ local function putNPCsBack(npcData)
|
||||||
-- reset loaded position data
|
-- reset loaded position data
|
||||||
common.runtimeData.positions = {}
|
common.runtimeData.positions = {}
|
||||||
this.searchCellsForPositions()
|
this.searchCellsForPositions()
|
||||||
|
|
||||||
interop.setRuntimeData(common.runtimeData)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function reEnableNPCs(npcs)
|
local function reEnableNPCs(npcs)
|
||||||
|
@ -99,8 +99,6 @@ local function reEnableNPCs(npcs)
|
||||||
npcs[id] = nil
|
npcs[id] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
interop.setRuntimeData(common.runtimeData)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function disableOrMove(npc, cell)
|
local function disableOrMove(npc, cell)
|
||||||
|
@ -109,7 +107,7 @@ local function disableOrMove(npc, cell)
|
||||||
if npcHome then
|
if npcHome then
|
||||||
moveNPC(npcHome)
|
moveNPC(npcHome)
|
||||||
else
|
else
|
||||||
disableNPC(npc)
|
disableNPC(npc, cell)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -134,9 +132,11 @@ local function checkForMovedOrDisabledNPCs(cell)
|
||||||
if npc.data.NPCsGoHome.disabled then
|
if npc.data.NPCsGoHome.disabled then
|
||||||
-- disabled NPC
|
-- disabled NPC
|
||||||
if badWeather then
|
if badWeather then
|
||||||
common.runtimeData.disabledBadWeatherNPCs[npc.id] = npc
|
common.runtimeData.disabledBadWeatherNPCs[cell.id] = common.runtimeData.disabledBadWeatherNPCs[cell.id] or {}
|
||||||
|
common.runtimeData.disabledBadWeatherNPCs[cell.id][npc.id] = npc
|
||||||
else
|
else
|
||||||
common.runtimeData.disabledNPCs[npc.id] = npc
|
common.runtimeData.disabledNPCs[cell.id] = common.runtimeData.disabledNPCs[cell.id] or {}
|
||||||
|
common.runtimeData.disabledNPCs[cell.id][npc.id] = npc
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- homed NPC
|
-- homed NPC
|
||||||
|
@ -147,9 +147,11 @@ local function checkForMovedOrDisabledNPCs(cell)
|
||||||
|
|
||||||
-- add to in memory table
|
-- add to in memory table
|
||||||
if badWeather then
|
if badWeather then
|
||||||
common.runtimeData.movedBadWeatherNPCs[npc.id] = homeData
|
common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] = common.runtimeData.movedBadWeatherNPCs[homeData.ogPlaceName] or {}
|
||||||
|
common.runtimeData.movedBadWeatherNPCs[cell.id][npc.id] = homeData
|
||||||
else
|
else
|
||||||
common.runtimeData.movedNPCs[npc.id] = homeData
|
common.runtimeData.movedNPCs[homeData.ogPlaceName] = common.runtimeData.movedNPCs[homeData.ogPlaceName] or {}
|
||||||
|
common.runtimeData.movedNPCs[cell.id][npc.id] = homeData
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -214,8 +216,8 @@ this.processNPCs = function(cell)
|
||||||
-- LuaFormatter off
|
-- LuaFormatter off
|
||||||
-- check for bad weather NPCs that have been disabled, and re-enable them
|
-- check for bad weather NPCs that have been disabled, and re-enable them
|
||||||
if config.keepBadWeatherNPCs then
|
if config.keepBadWeatherNPCs then
|
||||||
if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs) end
|
if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs[cell.id]) end
|
||||||
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs) end
|
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs[cell.id]) end
|
||||||
end
|
end
|
||||||
elseif night then
|
elseif night then
|
||||||
log(common.logLevels.large, "[PROC] !!Good or bad weather and night!!")
|
log(common.logLevels.large, "[PROC] !!Good or bad weather and night!!")
|
||||||
|
@ -226,10 +228,10 @@ this.processNPCs = function(cell)
|
||||||
else
|
else
|
||||||
log(common.logLevels.large, "[PROC] !!Good weather and not night!!")
|
log(common.logLevels.large, "[PROC] !!Good weather and not night!!")
|
||||||
-- put everyone back
|
-- put everyone back
|
||||||
if not common.isEmptyTable(common.runtimeData.movedNPCs) then putNPCsBack(common.runtimeData.movedNPCs) end
|
if not common.isEmptyTable(common.runtimeData.movedNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedNPCs[cell.id]) end
|
||||||
if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs) end
|
if not common.isEmptyTable(common.runtimeData.movedBadWeatherNPCs[cell.id]) then putNPCsBack(common.runtimeData.movedBadWeatherNPCs[cell.id]) end
|
||||||
if not common.isEmptyTable(common.runtimeData.disabledNPCs) then reEnableNPCs(common.runtimeData.disabledNPCs) end
|
if not common.isEmptyTable(common.runtimeData.disabledNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledNPCs[cell.id]) end
|
||||||
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs) end
|
if not common.isEmptyTable(common.runtimeData.disabledBadWeatherNPCs[cell.id]) then reEnableNPCs(common.runtimeData.disabledBadWeatherNPCs[cell.id]) end
|
||||||
-- LuaFormatter on
|
-- LuaFormatter on
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,7 @@ local config = require("celediel.NPCsGoHome.config").getConfig()
|
||||||
local common = require("celediel.NPCsGoHome.common")
|
local common = require("celediel.NPCsGoHome.common")
|
||||||
local checks = require("celediel.NPCsGoHome.functions.checks")
|
local checks = require("celediel.NPCsGoHome.functions.checks")
|
||||||
local processors = require("celediel.NPCsGoHome.functions.processors")
|
local processors = require("celediel.NPCsGoHome.functions.processors")
|
||||||
|
local interop = require("celediel.NPCsGoHome.interop")
|
||||||
local inspect = require("inspect")
|
local inspect = require("inspect")
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
|
@ -49,7 +50,8 @@ end
|
||||||
local function checkEnteredPublicHouse(cell, city)
|
local function checkEnteredPublicHouse(cell, city)
|
||||||
local typeOfPub = common.pickPublicHouseType(cell)
|
local typeOfPub = common.pickPublicHouseType(cell)
|
||||||
|
|
||||||
local publicHouse = common.runtimeData.publicHouses.byName[city] and common.runtimeData.publicHouses.byName[city][cell.id]
|
local publicHouse = common.runtimeData.publicHouses.byName[city] and
|
||||||
|
common.runtimeData.publicHouses.byName[city][cell.id]
|
||||||
|
|
||||||
if publicHouse then
|
if publicHouse then
|
||||||
local msg = string.format("Entering public space %s, a%s %s in the town of %s.", publicHouse.name,
|
local msg = string.format("Entering public space %s, a%s %s in the town of %s.", publicHouse.name,
|
||||||
|
@ -97,8 +99,16 @@ local function updateCells()
|
||||||
|
|
||||||
for _, cell in pairs(tes3.getActiveCells()) do
|
for _, cell in pairs(tes3.getActiveCells()) do
|
||||||
log(common.logLevels.large, "[MAIN] Applying changes to cell %s", cell.id)
|
log(common.logLevels.large, "[MAIN] Applying changes to cell %s", cell.id)
|
||||||
|
|
||||||
|
-- initialize runtime data if needed
|
||||||
|
for _, t in pairs({"movedNPCs", "movedBadWeatherNPCs", "disabledNPCs", "disabledBadWeatherNPCs"}) do
|
||||||
|
common.runtimeData[t][cell.id] = common.runtimeData[t][cell.id] or {}
|
||||||
|
end
|
||||||
applyChanges(cell)
|
applyChanges(cell)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- update interop runtime data after changes have been applied
|
||||||
|
interop.setRuntimeData(common.runtimeData)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- todo: more robust trespass checking... maybe take faction and rank into account?
|
-- todo: more robust trespass checking... maybe take faction and rank into account?
|
||||||
|
@ -134,7 +144,8 @@ eventFunctions.onActivated = function(e)
|
||||||
|
|
||||||
if tes3.player.data.NPCsGoHome.intruding and not checks.isIgnoredNPC(npc) then
|
if tes3.player.data.NPCsGoHome.intruding and not checks.isIgnoredNPC(npc) then
|
||||||
if npc.disposition and npc.disposition <= config.minimumTrespassDisposition then
|
if npc.disposition and npc.disposition <= config.minimumTrespassDisposition then
|
||||||
log(common.logLevels.medium, "Disabling dialogue with %s because trespass and disposition:%s", npc.object.name, npc.disposition)
|
log(common.logLevels.medium, "Disabling dialogue with %s because trespass and disposition:%s",
|
||||||
|
npc.object.name, npc.disposition)
|
||||||
tes3.messageBox(string.format("%s: Get out before I call the guards!", npc.object.name))
|
tes3.messageBox(string.format("%s: Get out before I call the guards!", npc.object.name))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue