formatting

This commit is contained in:
Lilian Jónsdóttir 2020-08-23 23:58:12 -07:00
parent ec2a570b30
commit c00fb8b4ea
6 changed files with 72 additions and 89 deletions

View file

@ -15,7 +15,13 @@ this.logLevels = {none = 0, small = 1, medium = 2, large = 3}
this.waist = {neither = 0, exterior = 1, public = 2} this.waist = {neither = 0, exterior = 1, public = 2}
-- for runtime data -- 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 -- {{{ Filled at runtime
@ -23,10 +29,7 @@ this.runtimeData = {
-- cells marked as public -- cells marked as public
publicHouses = {}, publicHouses = {},
-- homes picked for NPCs -- homes picked for NPCs
homes = { homes = {byName = {}, byCell = {}},
byName = {},
byCell = {}
},
-- NPCs who have been moved -- NPCs who have been moved
movedNPCs = {}, movedNPCs = {},
-- positions that haven't been used -- positions that haven't been used

View file

@ -57,8 +57,8 @@ local this = {}
this.isInteriorCell = function(cell) this.isInteriorCell = function(cell)
if not cell then return end if not cell then return end
log(common.logLevels.large, "Cell %s: interior: %s, behaves as exterior: %s therefore returning %s", log(common.logLevels.large, "Cell %s: interior: %s, behaves as exterior: %s therefore returning %s", cell.id,
cell.id, cell.isInterior, cell.behavesAsExterior, cell.isInterior and not cell.behavesAsExterior) cell.isInterior, cell.behavesAsExterior, cell.isInterior and not cell.behavesAsExterior)
return cell.isInterior and not cell.behavesAsExterior return cell.isInterior and not cell.behavesAsExterior
end end
@ -76,13 +76,13 @@ this.isCityCell = function(internalCellId, externalCellId)
local _, _, externalCity = string.find(externalCellId, cityMatch) local _, _, externalCity = string.find(externalCellId, cityMatch)
if externalCity and externalCity == internalCity then if externalCity and externalCity == internalCity then
log(common.logLevels.large, "hard mode city: %s in %s, %s == %s", log(common.logLevels.large, "hard mode city: %s in %s, %s == %s", internalCellId, externalCellId, externalCity,
internalCellId, externalCellId, externalCity, internalCity) internalCity)
return true return true
end end
log(common.logLevels.large, "hard mode not city: %s not in %s, %s ~= %s or both are nil", log(common.logLevels.large, "hard mode not city: %s not in %s, %s ~= %s or both are nil", internalCellId,
internalCellId, externalCellId, externalCity, internalCity) externalCellId, externalCity, internalCity)
return false return false
end end
@ -105,9 +105,7 @@ end
this.isCantonCell = function(cell) this.isCantonCell = function(cell)
if this.isInteriorCell(cell) then return false end if this.isInteriorCell(cell) then return false end
for door in cell:iterateReferences(tes3.objectType.door) do for door in cell:iterateReferences(tes3.objectType.door) do
if door.destination and this.isCantonWorksCell(door.destination.cell) then if door.destination and this.isCantonWorksCell(door.destination.cell) then return true end
return true
end
end end
return false return false
end end
@ -200,7 +198,10 @@ this.isPublicHouse = function(cell)
end end
-- don't iterate NPCs in the cell if we've already marked it public -- 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 it's a waistworks cell, it's public, with no proprietor
if config.waistWorks == common.waist.public and cell.id:match(waistworks) then if config.waistWorks == common.waist.public and cell.id:match(waistworks) then
@ -292,11 +293,8 @@ this.isIgnoredDoor = function(door, homeCellId)
dest.id, this.isIgnoredCell(dest) and "ignored" or "not ignored", -- destination is ignored 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 inCity and "" or "not ", leadsToPublicCell and "" or "not ", hasOccupants and "" or "un") -- in a city, is public, is ocupado
return this.isIgnoredCell(dest) or return
not this.isInteriorCell(dest) or this.isIgnoredCell(dest) or not this.isInteriorCell(dest) or isCantonWorks or not inCity or leadsToPublicCell or
isCantonWorks or
not inCity or
leadsToPublicCell or
not hasOccupants not hasOccupants
end end
@ -327,9 +325,7 @@ this.isBadWeatherNPC = function(npc)
-- todo: better detection of NPCs who offer travel services -- todo: better detection of NPCs who offer travel services
-- found a rogue "shipmaster" in molag mar -- found a rogue "shipmaster" in molag mar
return obj.class.name == "Caravaner" or return obj.class.name == "Caravaner" or obj.class.name == "Gondolier" or obj.class.name == "Shipmaster" or
obj.class.name == "Gondolier" or
obj.class.name == "Shipmaster" or
obj.race.id == "Argonian" obj.race.id == "Argonian"
end end

View file

@ -51,10 +51,7 @@ this.createHomedNPCTableEntry = function(npc, home, startingPlace, isHome, posit
if isHome and positions.npcs[npc.object.name] then if isHome and positions.npcs[npc.object.name] then
pos = positions.npcs[npc.object.name].position pos = positions.npcs[npc.object.name].position
ori = positions.npcs[npc.object.name].orientation ori = positions.npcs[npc.object.name].orientation
-- elseif positions.cells[id] then
elseif common.runtimeData.positions[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]) local choice, index = table.choice(common.runtimeData.positions[id])
pos = choice.position pos = choice.position
ori = choice.orientation ori = choice.orientation
@ -69,12 +66,10 @@ this.createHomedNPCTableEntry = function(npc, home, startingPlace, isHome, posit
pickedPosition = tes3vector3.new(pos[1], pos[2], pos[3]) pickedPosition = tes3vector3.new(pos[1], pos[2], pos[3])
pickedOrientation = tes3vector3.new(ori[1], ori[2], ori[3]) pickedOrientation = tes3vector3.new(ori[1], ori[2], ori[3])
local ogPosition = position and local ogPosition = position and (tes3vector3.new(position.x, position.y, position.z)) or
(tes3vector3.new(position.x, position.y, position.z)) or
(npc.position and npc.position:copy() or zeroVector:copy()) (npc.position and npc.position:copy() or zeroVector:copy())
local ogOrientation = orientation and local ogOrientation = orientation and (tes3vector3.new(orientation.x, orientation.y, orientation.z)) or
(tes3vector3.new(orientation.x, orientation.y, orientation.z)) or
(npc.orientation and npc.orientation:copy() or zeroVector:copy()) (npc.orientation and npc.orientation:copy() or zeroVector:copy())
local entry = { local entry = {
@ -117,9 +112,12 @@ this.createPublicHouseTableEntry = function(publicCell, proprietor, city, name)
local proprietorName = proprietor and proprietor.object.name or "no one" 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] 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] = { common.runtimeData.publicHouses[city][typeOfPub][publicCell.id] =
{
name = name, name = name,
city = city, city = city,
cell = publicCell, cell = publicCell,

View file

@ -16,9 +16,7 @@ this.updatePositions = function(cell)
-- update runtime positions in cell, but don't overwrite loaded positions -- update runtime positions in cell, but don't overwrite loaded positions
if not common.runtimeData.positions[id] and positions.cells[id] then if not common.runtimeData.positions[id] and positions.cells[id] then
common.runtimeData.positions[id] = {} common.runtimeData.positions[id] = {}
for _, data in pairs(positions.cells[id]) do for _, data in pairs(positions.cells[id]) do table.insert(common.runtimeData.positions[id], data) end
table.insert(common.runtimeData.positions[id], data)
end
end end
end end
@ -32,7 +30,9 @@ this.searchCellsForPositions = function()
this.updatePositions(door.destination.cell) this.updatePositions(door.destination.cell)
-- one more time -- one more time
for internalDoor in door.destination.cell:iterateReferences(tes3.objectType.door) do 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 end
end end
@ -47,7 +47,8 @@ this.checkForMovedNPCs = function(cell)
log(common.logLevels.medium, "Looking for moved NPCs in cell %s", cell.id) log(common.logLevels.medium, "Looking for moved NPCs in cell %s", cell.id)
for npc in cell:iterateReferences(tes3.objectType.npc) do for npc in cell:iterateReferences(tes3.objectType.npc) do
if npc.data and npc.data.NPCsGoHome then 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 end
end end
@ -73,16 +74,8 @@ this.moveNPC = function(homeData)
-- set npc data, so we can move NPCs back after a load -- set npc data, so we can move NPCs back after a load
local npc = homeData.npc local npc = homeData.npc
npc.data.NPCsGoHome = { npc.data.NPCsGoHome = {
position = { position = {x = npc.position.x, y = npc.position.y, z = npc.position.z},
x = npc.position.x, orientation = {x = npc.orientation.x, y = npc.orientation.y, z = npc.orientation.z},
y = npc.position.y,
z = npc.position.z,
},
orientation = {
x = npc.orientation.x,
y = npc.orientation.y,
z = npc.orientation.z,
},
cell = homeData.ogPlaceName cell = homeData.ogPlaceName
} }
@ -139,8 +132,7 @@ this.processNPCs = function(cell)
npcHome and npcHome.home or "nowhere", npcHome and (npcHome.isHome and "." or " at night.") or ".") npcHome and npcHome.home or "nowhere", npcHome and (npcHome.isHome and "." or " at night.") or ".")
-- disable or move NPCs -- disable or move NPCs
if (checks.checkTime() or if (checks.checkTime() or (checks.checkWeather(cell) and
(checks.checkWeather(cell) and
(not checks.isBadWeatherNPC(npc) or (checks.isBadWeatherNPC(npc) and not config.keepBadWeatherNPCs)))) then (not checks.isBadWeatherNPC(npc) or (checks.isBadWeatherNPC(npc) and not config.keepBadWeatherNPCs)))) then
if npcHome then if npcHome then
this.moveNPC(npcHome) this.moveNPC(npcHome)

View file

@ -48,14 +48,17 @@ end
local function checkEnteredPublicHouse(cell, city) local function checkEnteredPublicHouse(cell, city)
local typeOfPub = common.pickPublicHouseType(cell) 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 if publicHouse then
local msg = string.format("Entering public space %s, a%s %s in the town of %s.", local msg = string.format("Entering public space %s, a%s %s in the town of %s.", publicHouse.name,
publicHouse.name, common.vowel(typeOfPub), typeOfPub:gsub("s$", ""), publicHouse.city) common.vowel(typeOfPub), typeOfPub:gsub("s$", ""), publicHouse.city)
if publicHouse.proprietor then 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 end
log(common.logLevels.small, msg) log(common.logLevels.small, msg)
@ -71,9 +74,8 @@ local function applyChanges(cell)
if checks.isIgnoredCell(cell) then return end if checks.isIgnoredCell(cell) then return end
-- Interior cell, except Canton cells, don't do anything -- 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 if checks.isInteriorCell(cell) and
return not (config.waistWorks == common.waist.exterior and checks.isCantonWorksCell(cell)) then return end
end
-- don't do anything to public houses -- don't do anything to public houses
if checks.isPublicHouse(cell) then return end if checks.isPublicHouse(cell) then return end

View file

@ -1,9 +1,7 @@
local config = require("celediel.NPCsGoHome.config").getConfig() local config = require("celediel.NPCsGoHome.config").getConfig()
local common = require("celediel.NPCsGoHome.common") local common = require("celediel.NPCsGoHome.common")
local function createTableVar(id) local function createTableVar(id) return mwse.mcm.createTableVariable({id = id, table = config}) end
return mwse.mcm.createTableVariable({id = id, table = config})
end
local template = mwse.mcm.createTemplate({name = common.modName}) local template = mwse.mcm.createTemplate({name = common.modName})
template:saveOnClose(common.configPath, config) template:saveOnClose(common.configPath, config)
@ -28,15 +26,9 @@ category:createDropdown({
variable = createTableVar("logLevel") variable = createTableVar("logLevel")
}) })
category:createYesNoButton({ category:createYesNoButton({label = "Lock doors and containers at night?", variable = createTableVar("lockDoors")})
label = "Lock doors and containers at night?",
variable = createTableVar("lockDoors")
})
category:createYesNoButton({ category:createYesNoButton({label = "Disable non-Guard NPCs at night?", variable = createTableVar("disableNPCs")})
label = "Disable non-Guard NPCs at night?",
variable = createTableVar("disableNPCs")
})
category:createYesNoButton({ category:createYesNoButton({
label = "Move NPCs into their homes at night and in bad weather instead of disabling them?", label = "Move NPCs into their homes at night and in bad weather instead of disabling them?",
@ -61,7 +53,7 @@ category:createDropdown({
options = { options = {
{label = "Neither", value = common.waist.neither}, {label = "Neither", value = common.waist.neither},
{label = "Exterior", value = common.waist.exterior}, {label = "Exterior", value = common.waist.exterior},
{label = "Public", value = common.waist.public}, {label = "Public", value = common.waist.public}
}, },
defaultSetting = common.waist.neither, defaultSetting = common.waist.neither,
variable = createTableVar("waistWorks") variable = createTableVar("waistWorks")