ignore doors to underworks, and some cleanup

This commit is contained in:
Lilian Jónsdóttir 2020-08-16 17:56:54 -07:00
parent 8b2788fbf0
commit 53d522adf3

View file

@ -9,7 +9,15 @@ local positions = require("celediel.NPCsGoHome.positions")
-- {{{ variables and such -- {{{ variables and such
-- Waistworks string match -- Waistworks string match
-- I'm probably trying too hard to avoid false positives -- I'm probably trying too hard to avoid false positives
local waistworks = {"^[Vv]ivec,?.*[Ww]aist", "[Cc]analworks", "[Ww]aistworks"} local waistworks = {
"^[Vv]ivec,.*[Ww]aist", -- St Olms and St Delyn have Waist North|South
"^[Vv]ivec,.*[Cc]anal", -- and Canal North|South cells
"[Cc]analworks", -- These will match vanilla Molag Mar
"[Ww]aistworks" -- and Almas Thirr from Tamriel Rebuilt
}
-- these are separate because doors to underworks should be ignored
-- but NPCs in underworks should not be disabled
local underworks = "[Uu]nderworks"
-- timers -- timers
local updateTimer local updateTimer
@ -143,6 +151,7 @@ local function checkManor(cellName, npcName)
return string.match(cellName, sur) return string.match(cellName, sur)
end end
-- todo: pick this better
local function pickPublicHouseType(cellName) local function pickPublicHouseType(cellName)
if cellName:match("Guild") then if cellName:match("Guild") then
return publicHouseTypes.guildhalls return publicHouseTypes.guildhalls
@ -240,15 +249,15 @@ local function createHomedNPCTableEntry(npc, home, startingPlace, isHome, positi
(npc.orientation and npc.orientation:copy() or zeroVector:copy()) (npc.orientation and npc.orientation:copy() or zeroVector:copy())
local this = { local this = {
name = npc.object.name, name = npc.object.name, -- string
npc = npc, -- tes3npc npc = npc, -- tes3npc
isHome = isHome, -- bool isHome = isHome, -- bool
home = home, -- tes3cell home = home, -- tes3cell
homeName = home.id, homeName = home.id, -- string
ogPlace = startingPlace, -- tes3cell ogPlace = startingPlace, -- tes3cell
ogPlaceName = startingPlace.id, ogPlaceName = startingPlace.id,
ogPosition = ogPosition, ogPosition = ogPosition, -- tes3vector3
ogOrientation = ogOrientation, ogOrientation = ogOrientation, -- tes3vector3
homePosition = pickedPosition, -- tes3vector3 homePosition = pickedPosition, -- tes3vector3
homeOrientation = pickedOrientation, -- tes3vector3 homeOrientation = pickedOrientation, -- tes3vector3
worth = calculateNPCWorth(npc) -- int worth = calculateNPCWorth(npc) -- int
@ -521,28 +530,34 @@ local function isIgnoredDoor(door, homeCellId)
return true return true
end end
-- we use this a lot, so set a reference to it
local dest = door.destination.cell
-- Only doors in cities and towns (interior cells with names that contain the exterior cell) -- Only doors in cities and towns (interior cells with names that contain the exterior cell)
local inCity = isCityCell(door.destination.cell.id, homeCellId) local inCity = isCityCell(dest.id, homeCellId)
-- peek inside doors to look for guild halls, inns and clubs -- peek inside doors to look for guild halls, inns and clubs
local leadsToPublicCell = isPublicHouse(door.destination.cell) local leadsToPublicCell = isPublicHouse(dest)
-- don't lock unoccupied cells -- don't lock unoccupied cells
local hasOccupants = false local hasOccupants = false
for npc in door.destination.cell:iterateReferences(tes3.objectType.npc) do for npc in dest:iterateReferences(tes3.objectType.npc) do
if not isIgnoredNPC(npc) then if not isIgnoredNPC(npc) then
hasOccupants = true hasOccupants = true
break break
end end
end end
-- don't lock doors to underworks in addition to other canton cells
local isCanton = isCantonCell(dest.id) or dest.id:match(underworks)
log(common.logLevels.large, "%s is %s, (%sin a city, is %spublic, %soccupied)", -- log(common.logLevels.large, "%s is %s, (%sin a city, is %spublic, %soccupied)", --
door.destination.cell.id, isIgnoredCell(door.destination.cell) and "ignored" or "not ignored", -- destination is ignored dest.id, isIgnoredCell(dest) and "ignored" or "not ignored", -- destination is ignored
inCity and "" or "not ", leadsToPublicCell and "" or "not ", hasOccupants and "" or "un") -- in a city, is public, is ocupado inCity and "" or "not ", leadsToPublicCell and "" or "not ", hasOccupants and "" or "un") -- in a city, is public, is ocupado
return isIgnoredCell(door.destination.cell) or return isIgnoredCell(dest) or
not isInteriorCell(door.destination.cell) or not isInteriorCell(dest) or
isCantonCell(door.destination.cell.id) or isCanton or
not inCity or not inCity or
leadsToPublicCell or leadsToPublicCell or
not hasOccupants not hasOccupants
@ -856,7 +871,7 @@ local function applyChanges(cell)
if isIgnoredCell(cell) then return end if isIgnoredCell(cell) then return end
-- Interior cell, except Waistworks, don't do anything -- Interior cell, except Canton cells, don't do anything
if isInteriorCell(cell) and not (config.waistWorks and isCantonCell(cell.id)) then return end if isInteriorCell(cell) and not (config.waistWorks and isCantonCell(cell.id)) then return end
-- don't do anything to public houses -- don't do anything to public houses