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}
-- 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

View file

@ -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
@ -292,11 +293,8 @@ this.isIgnoredDoor = function(door, homeCellId)
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
return
this.isIgnoredCell(dest) or not this.isInteriorCell(dest) or isCantonWorks or not inCity or leadsToPublicCell or
not hasOccupants
end
@ -327,9 +325,7 @@ 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
return obj.class.name == "Caravaner" or obj.class.name == "Gondolier" or obj.class.name == "Shipmaster" or
obj.race.id == "Argonian"
end

View file

@ -51,10 +51,7 @@ 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
@ -69,12 +66,10 @@ 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
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
local ogOrientation = orientation and (tes3vector3.new(orientation.x, orientation.y, orientation.z)) or
(npc.orientation and npc.orientation:copy() or zeroVector:copy())
local entry = {
@ -117,9 +112,12 @@ 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] = {
common.runtimeData.publicHouses[city][typeOfPub][publicCell.id] =
{
name = name,
city = city,
cell = publicCell,

View file

@ -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,8 +132,7 @@ 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
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)

View file

@ -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

View file

@ -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?",
@ -61,7 +53,7 @@ category:createDropdown({
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")