formatting
This commit is contained in:
parent
ec2a570b30
commit
c00fb8b4ea
|
@ -15,7 +15,13 @@ this.logLevels = {none = 0, small = 1, medium = 2, large = 3}
|
|||
this.waist = {neither = 0, exterior = 1, public = 2}
|
||||
|
||||
-- for runtime data
|
||||
this.publicHouseTypes = {inns = "Inns", guildhalls = "Guildhalls", temples = "Temples", houses = "Houses", cantonworks = "Cantonworks"}
|
||||
this.publicHouseTypes = {
|
||||
inns = "Inns",
|
||||
guildhalls = "Guildhalls",
|
||||
temples = "Temples",
|
||||
houses = "Houses",
|
||||
cantonworks = "Cantonworks"
|
||||
}
|
||||
-- }}}
|
||||
|
||||
-- {{{ Filled at runtime
|
||||
|
@ -23,10 +29,7 @@ this.runtimeData = {
|
|||
-- cells marked as public
|
||||
publicHouses = {},
|
||||
-- homes picked for NPCs
|
||||
homes = {
|
||||
byName = {},
|
||||
byCell = {}
|
||||
},
|
||||
homes = {byName = {}, byCell = {}},
|
||||
-- NPCs who have been moved
|
||||
movedNPCs = {},
|
||||
-- positions that haven't been used
|
||||
|
|
|
@ -57,8 +57,8 @@ local this = {}
|
|||
this.isInteriorCell = function(cell)
|
||||
if not cell then return end
|
||||
|
||||
log(common.logLevels.large, "Cell %s: interior: %s, behaves as exterior: %s therefore returning %s",
|
||||
cell.id, cell.isInterior, cell.behavesAsExterior, cell.isInterior and not cell.behavesAsExterior)
|
||||
log(common.logLevels.large, "Cell %s: interior: %s, behaves as exterior: %s therefore returning %s", cell.id,
|
||||
cell.isInterior, cell.behavesAsExterior, cell.isInterior and not cell.behavesAsExterior)
|
||||
|
||||
return cell.isInterior and not cell.behavesAsExterior
|
||||
end
|
||||
|
@ -76,13 +76,13 @@ this.isCityCell = function(internalCellId, externalCellId)
|
|||
local _, _, externalCity = string.find(externalCellId, cityMatch)
|
||||
|
||||
if externalCity and externalCity == internalCity then
|
||||
log(common.logLevels.large, "hard mode city: %s in %s, %s == %s",
|
||||
internalCellId, externalCellId, externalCity, internalCity)
|
||||
log(common.logLevels.large, "hard mode city: %s in %s, %s == %s", internalCellId, externalCellId, externalCity,
|
||||
internalCity)
|
||||
return true
|
||||
end
|
||||
|
||||
log(common.logLevels.large, "hard mode not city: %s not in %s, %s ~= %s or both are nil",
|
||||
internalCellId, externalCellId, externalCity, internalCity)
|
||||
log(common.logLevels.large, "hard mode not city: %s not in %s, %s ~= %s or both are nil", internalCellId,
|
||||
externalCellId, externalCity, internalCity)
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -105,9 +105,7 @@ end
|
|||
this.isCantonCell = function(cell)
|
||||
if this.isInteriorCell(cell) then return false end
|
||||
for door in cell:iterateReferences(tes3.objectType.door) do
|
||||
if door.destination and this.isCantonWorksCell(door.destination.cell) then
|
||||
return true
|
||||
end
|
||||
if door.destination and this.isCantonWorksCell(door.destination.cell) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
@ -200,7 +198,10 @@ this.isPublicHouse = function(cell)
|
|||
end
|
||||
|
||||
-- don't iterate NPCs in the cell if we've already marked it public
|
||||
if common.runtimeData.publicHouses[city] and (common.runtimeData.publicHouses[city][typeOfPub] and common.runtimeData.publicHouses[city][typeOfPub][cell.id]) then return true end
|
||||
if common.runtimeData.publicHouses[city] and
|
||||
(common.runtimeData.publicHouses[city][typeOfPub] and common.runtimeData.publicHouses[city][typeOfPub][cell.id]) then
|
||||
return true
|
||||
end
|
||||
|
||||
-- if it's a waistworks cell, it's public, with no proprietor
|
||||
if config.waistWorks == common.waist.public and cell.id:match(waistworks) then
|
||||
|
@ -289,15 +290,12 @@ this.isIgnoredDoor = function(door, homeCellId)
|
|||
local isCantonWorks = this.isCantonWorksCell(dest)
|
||||
|
||||
log(common.logLevels.large, "%s is %s, (%sin a city, is %spublic, %soccupied)", --
|
||||
dest.id, this.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
|
||||
dest.id, this.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
|
||||
|
||||
return this.isIgnoredCell(dest) or
|
||||
not this.isInteriorCell(dest) or
|
||||
isCantonWorks or
|
||||
not inCity or
|
||||
leadsToPublicCell or
|
||||
not hasOccupants
|
||||
return
|
||||
this.isIgnoredCell(dest) or not this.isInteriorCell(dest) or isCantonWorks or not inCity or leadsToPublicCell or
|
||||
not hasOccupants
|
||||
end
|
||||
|
||||
-- AT NIGHT
|
||||
|
@ -327,10 +325,8 @@ this.isBadWeatherNPC = function(npc)
|
|||
|
||||
-- todo: better detection of NPCs who offer travel services
|
||||
-- found a rogue "shipmaster" in molag mar
|
||||
return obj.class.name == "Caravaner" or
|
||||
obj.class.name == "Gondolier" or
|
||||
obj.class.name == "Shipmaster" or
|
||||
obj.race.id == "Argonian"
|
||||
return obj.class.name == "Caravaner" or obj.class.name == "Gondolier" or obj.class.name == "Shipmaster" or
|
||||
obj.race.id == "Argonian"
|
||||
end
|
||||
|
||||
return this
|
||||
|
|
|
@ -51,17 +51,14 @@ this.createHomedNPCTableEntry = function(npc, home, startingPlace, isHome, posit
|
|||
if isHome and positions.npcs[npc.object.name] then
|
||||
pos = positions.npcs[npc.object.name].position
|
||||
ori = positions.npcs[npc.object.name].orientation
|
||||
-- elseif positions.cells[id] then
|
||||
elseif common.runtimeData.positions[id] then
|
||||
-- pos = table.choice(positions.cells[id]).position
|
||||
-- ori = table.choice(positions.cells[id]).orientation
|
||||
local choice, index = table.choice(common.runtimeData.positions[id])
|
||||
pos = choice.position
|
||||
ori = choice.orientation
|
||||
table.remove(common.runtimeData.positions[id], index)
|
||||
else
|
||||
pos = {0,0,0}
|
||||
ori = {0,0,0}
|
||||
pos = {0, 0, 0}
|
||||
ori = {0, 0, 0}
|
||||
end
|
||||
|
||||
log(common.logLevels.large, "Settled on position:%s, orientation:%s for %s in %s", pos, ori, npc.object.name, id)
|
||||
|
@ -69,13 +66,11 @@ this.createHomedNPCTableEntry = function(npc, home, startingPlace, isHome, posit
|
|||
pickedPosition = tes3vector3.new(pos[1], pos[2], pos[3])
|
||||
pickedOrientation = tes3vector3.new(ori[1], ori[2], ori[3])
|
||||
|
||||
local ogPosition = position and
|
||||
(tes3vector3.new(position.x, position.y, position.z)) or
|
||||
(npc.position and npc.position:copy() or zeroVector:copy())
|
||||
local ogPosition = position and (tes3vector3.new(position.x, position.y, position.z)) or
|
||||
(npc.position and npc.position:copy() or zeroVector:copy())
|
||||
|
||||
local ogOrientation = orientation and
|
||||
(tes3vector3.new(orientation.x, orientation.y, orientation.z)) or
|
||||
(npc.orientation and npc.orientation:copy() or zeroVector:copy())
|
||||
local ogOrientation = orientation and (tes3vector3.new(orientation.x, orientation.y, orientation.z)) or
|
||||
(npc.orientation and npc.orientation:copy() or zeroVector:copy())
|
||||
|
||||
local entry = {
|
||||
name = npc.object.name, -- string
|
||||
|
@ -117,16 +112,19 @@ this.createPublicHouseTableEntry = function(publicCell, proprietor, city, name)
|
|||
local proprietorName = proprietor and proprietor.object.name or "no one"
|
||||
|
||||
if not common.runtimeData.publicHouses[city] then common.runtimeData.publicHouses[city] = {} end
|
||||
if not common.runtimeData.publicHouses[city][typeOfPub] then common.runtimeData.publicHouses[city][typeOfPub] = {} end
|
||||
if not common.runtimeData.publicHouses[city][typeOfPub] then
|
||||
common.runtimeData.publicHouses[city][typeOfPub] = {}
|
||||
end
|
||||
|
||||
common.runtimeData.publicHouses[city][typeOfPub][publicCell.id] = {
|
||||
name = name,
|
||||
city = city,
|
||||
cell = publicCell,
|
||||
proprietor = proprietor,
|
||||
proprietorName = proprietorName,
|
||||
worth = worth
|
||||
}
|
||||
common.runtimeData.publicHouses[city][typeOfPub][publicCell.id] =
|
||||
{
|
||||
name = name,
|
||||
city = city,
|
||||
cell = publicCell,
|
||||
proprietor = proprietor,
|
||||
proprietorName = proprietorName,
|
||||
worth = worth
|
||||
}
|
||||
|
||||
interop.setRuntimeData(common.runtimeData)
|
||||
end
|
||||
|
|
|
@ -16,9 +16,7 @@ this.updatePositions = function(cell)
|
|||
-- update runtime positions in cell, but don't overwrite loaded positions
|
||||
if not common.runtimeData.positions[id] and positions.cells[id] then
|
||||
common.runtimeData.positions[id] = {}
|
||||
for _, data in pairs(positions.cells[id]) do
|
||||
table.insert(common.runtimeData.positions[id], data)
|
||||
end
|
||||
for _, data in pairs(positions.cells[id]) do table.insert(common.runtimeData.positions[id], data) end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,7 +30,9 @@ this.searchCellsForPositions = function()
|
|||
this.updatePositions(door.destination.cell)
|
||||
-- one more time
|
||||
for internalDoor in door.destination.cell:iterateReferences(tes3.objectType.door) do
|
||||
if internalDoor.destination then this.updatePositions(internalDoor.destination.cell) end
|
||||
if internalDoor.destination then
|
||||
this.updatePositions(internalDoor.destination.cell)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -47,7 +47,8 @@ this.checkForMovedNPCs = function(cell)
|
|||
log(common.logLevels.medium, "Looking for moved NPCs in cell %s", cell.id)
|
||||
for npc in cell:iterateReferences(tes3.objectType.npc) do
|
||||
if npc.data and npc.data.NPCsGoHome then
|
||||
dataTables.createHomedNPCTableEntry(npc, cell, tes3.getCell(npc.data.NPCsGoHome.cell), true, npc.data.NPCsGoHome.position, npc.data.NPCsGoHome.orientation)
|
||||
dataTables.createHomedNPCTableEntry(npc, cell, tes3.getCell(npc.data.NPCsGoHome.cell), true,
|
||||
npc.data.NPCsGoHome.position, npc.data.NPCsGoHome.orientation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -73,16 +74,8 @@ this.moveNPC = function(homeData)
|
|||
-- set npc data, so we can move NPCs back after a load
|
||||
local npc = homeData.npc
|
||||
npc.data.NPCsGoHome = {
|
||||
position = {
|
||||
x = npc.position.x,
|
||||
y = npc.position.y,
|
||||
z = npc.position.z,
|
||||
},
|
||||
orientation = {
|
||||
x = npc.orientation.x,
|
||||
y = npc.orientation.y,
|
||||
z = npc.orientation.z,
|
||||
},
|
||||
position = {x = npc.position.x, y = npc.position.y, z = npc.position.z},
|
||||
orientation = {x = npc.orientation.x, y = npc.orientation.y, z = npc.orientation.z},
|
||||
cell = homeData.ogPlaceName
|
||||
}
|
||||
|
||||
|
@ -139,12 +132,11 @@ this.processNPCs = function(cell)
|
|||
npcHome and npcHome.home or "nowhere", npcHome and (npcHome.isHome and "." or " at night.") or ".")
|
||||
|
||||
-- disable or move NPCs
|
||||
if (checks.checkTime() or
|
||||
(checks.checkWeather(cell) and
|
||||
(not checks.isBadWeatherNPC(npc) or (checks.isBadWeatherNPC(npc) and not config.keepBadWeatherNPCs)))) then
|
||||
if (checks.checkTime() or (checks.checkWeather(cell) and
|
||||
(not checks.isBadWeatherNPC(npc) or (checks.isBadWeatherNPC(npc) and not config.keepBadWeatherNPCs)))) then
|
||||
if npcHome then
|
||||
this.moveNPC(npcHome)
|
||||
-- elseif not npc.data.NPCsGoHome.modified then
|
||||
-- elseif not npc.data.NPCsGoHome.modified then
|
||||
elseif not npc.disabled then
|
||||
log(common.logLevels.medium, "Disabling homeless %s", npc.object.name)
|
||||
-- npc:disable() -- ! this one sometimes causes crashes
|
||||
|
@ -211,13 +203,13 @@ this.processPets = function(cell)
|
|||
-- disable
|
||||
if not creature.disabled then
|
||||
log(common.logLevels.medium, "Disabling NPC Pet %s!", creature.object.id)
|
||||
mwscript.disable({reference = creature })
|
||||
mwscript.disable({reference = creature})
|
||||
end
|
||||
else
|
||||
-- enable
|
||||
if creature.disabled then
|
||||
log(common.logLevels.medium, "Enabling NPC Pet %s!", creature.object.id)
|
||||
mwscript.enable({reference = creature })
|
||||
mwscript.enable({reference = creature})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -48,14 +48,17 @@ end
|
|||
local function checkEnteredPublicHouse(cell, city)
|
||||
local typeOfPub = common.pickPublicHouseType(cell)
|
||||
|
||||
local publicHouse = publicHouses[city] and (publicHouses[city][typeOfPub] and publicHouses[city][typeOfPub][cell.name])
|
||||
local publicHouse = publicHouses[city] and
|
||||
(publicHouses[city][typeOfPub] and publicHouses[city][typeOfPub][cell.name])
|
||||
|
||||
if publicHouse then
|
||||
local msg = string.format("Entering public space %s, a%s %s in the town of %s.",
|
||||
publicHouse.name, common.vowel(typeOfPub), typeOfPub:gsub("s$", ""), publicHouse.city)
|
||||
local msg = string.format("Entering public space %s, a%s %s in the town of %s.", publicHouse.name,
|
||||
common.vowel(typeOfPub), typeOfPub:gsub("s$", ""), publicHouse.city)
|
||||
|
||||
if publicHouse.proprietor then
|
||||
msg = msg .. string.format(" Talk to %s, %s for services.", publicHouse.proprietor.object.name, publicHouse.proprietor.object.class)
|
||||
msg = msg ..
|
||||
string.format(" Talk to %s, %s for services.", publicHouse.proprietor.object.name,
|
||||
publicHouse.proprietor.object.class)
|
||||
end
|
||||
|
||||
log(common.logLevels.small, msg)
|
||||
|
@ -71,9 +74,8 @@ local function applyChanges(cell)
|
|||
if checks.isIgnoredCell(cell) then return end
|
||||
|
||||
-- Interior cell, except Canton cells, don't do anything
|
||||
if checks.isInteriorCell(cell) and not (config.waistWorks == common.waist.exterior and checks.isCantonWorksCell(cell)) then
|
||||
return
|
||||
end
|
||||
if checks.isInteriorCell(cell) and
|
||||
not (config.waistWorks == common.waist.exterior and checks.isCantonWorksCell(cell)) then return end
|
||||
|
||||
-- don't do anything to public houses
|
||||
if checks.isPublicHouse(cell) then return end
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
local config = require("celediel.NPCsGoHome.config").getConfig()
|
||||
local common = require("celediel.NPCsGoHome.common")
|
||||
|
||||
local function createTableVar(id)
|
||||
return mwse.mcm.createTableVariable({id = id, table = config})
|
||||
end
|
||||
local function createTableVar(id) return mwse.mcm.createTableVariable({id = id, table = config}) end
|
||||
|
||||
local template = mwse.mcm.createTemplate({name = common.modName})
|
||||
template:saveOnClose(common.configPath, config)
|
||||
|
@ -28,15 +26,9 @@ category:createDropdown({
|
|||
variable = createTableVar("logLevel")
|
||||
})
|
||||
|
||||
category:createYesNoButton({
|
||||
label = "Lock doors and containers at night?",
|
||||
variable = createTableVar("lockDoors")
|
||||
})
|
||||
category:createYesNoButton({label = "Lock doors and containers at night?", variable = createTableVar("lockDoors")})
|
||||
|
||||
category:createYesNoButton({
|
||||
label = "Disable non-Guard NPCs at night?",
|
||||
variable = createTableVar("disableNPCs")
|
||||
})
|
||||
category:createYesNoButton({label = "Disable non-Guard NPCs at night?", variable = createTableVar("disableNPCs")})
|
||||
|
||||
category:createYesNoButton({
|
||||
label = "Move NPCs into their homes at night and in bad weather instead of disabling them?",
|
||||
|
@ -56,12 +48,12 @@ category:createYesNoButton({
|
|||
category:createDropdown({
|
||||
label = "Treat Canton waistworks as exteriors, public spaces, or neither",
|
||||
description = "If canton cells are treated as exterior, inside NPCs will be disabled, and doors will be locked.\n" ..
|
||||
"If they're treated as public spaces, inside NPCs won't be disabled, and homeless NPCs will be moved inside "..
|
||||
"(if configured to do so).\n\nIf neither, canton cells will be treated as any other.",
|
||||
"If they're treated as public spaces, inside NPCs won't be disabled, and homeless NPCs will be moved inside " ..
|
||||
"(if configured to do so).\n\nIf neither, canton cells will be treated as any other.",
|
||||
options = {
|
||||
{label = "Neither", value = common.waist.neither},
|
||||
{label = "Exterior", value = common.waist.exterior},
|
||||
{label = "Public", value = common.waist.public},
|
||||
{label = "Public", value = common.waist.public}
|
||||
},
|
||||
defaultSetting = common.waist.neither,
|
||||
variable = createTableVar("waistWorks")
|
||||
|
|
Loading…
Reference in a new issue