louder but maybe more readable logging

This commit is contained in:
Lilian Jónsdóttir 2020-10-03 22:15:50 -07:00
parent 1fffe9cfa7
commit 7e96593833
6 changed files with 38 additions and 38 deletions

View file

@ -17,7 +17,7 @@ this.calculateCellWorth = function(cell, proprietor)
msg = msg .. string.format("%s worth:%s, ", innard.object.name, total) msg = msg .. string.format("%s worth:%s, ", innard.object.name, total)
end end
log(common.logLevels.medium, "Calculated worth of %s for cell %s", worth, cell.id) log(common.logLevels.medium, "[CELLEVAL] Calculated worth of %s for cell %s", worth, cell.id)
log(common.logLevels.large, msg:sub(1, #msg - 2)) -- strip off last ", " log(common.logLevels.large, msg:sub(1, #msg - 2)) -- strip off last ", "
return worth return worth
end end
@ -54,8 +54,8 @@ this.pickCellFaction = function(cell)
-- from the majority values, return the faction with the largest percentage, or nil -- from the majority values, return the faction with the largest percentage, or nil
local picked = common.keyOfLargestValue(npcs.majorityFactions) local picked = common.keyOfLargestValue(npcs.majorityFactions)
log(common.logLevels.medium, "Picked faction %s for cell %s", picked, cell.id) log(common.logLevels.medium, "[CELLEVAL] Picked faction %s for cell %s", picked, cell.id)
log(common.logLevels.large, "breakdown:\n%s", json.encode(npcs, {indent = true})) log(common.logLevels.large, "[CELLEVAL] breakdown:\n%s", json.encode(npcs, {indent = true}))
return picked return picked
end end

View file

@ -24,7 +24,7 @@ end
local function getFightFromSpawnedReference(id) local function getFightFromSpawnedReference(id)
-- Spawn a reference of the given id in toddtest -- Spawn a reference of the given id in toddtest
local toddTest = tes3.getCell("toddtest") local toddTest = tes3.getCell("toddtest")
log(common.logLevels.medium, "Spawning %s in %s", id, toddTest.id) log(common.logLevels.medium, "[CHECKS] Spawning %s in %s", id, toddTest.id)
local ref = tes3.createReference({ local ref = tes3.createReference({
object = id, object = id,
@ -37,7 +37,7 @@ local function getFightFromSpawnedReference(id)
local fight = ref.mobile.fight local fight = ref.mobile.fight
log(common.logLevels.medium, "Got fight of %s, time to yeet %s", fight, id) log(common.logLevels.medium, "[CHECKS] Got fight of %s, time to yeet %s", fight, id)
yeet(ref) yeet(ref)
@ -50,7 +50,7 @@ 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", cell.id, log(common.logLevels.large, "[CHECKS] Cell %s: interior: %s, behaves as exterior: %s therefore returning %s", 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
@ -59,7 +59,7 @@ end
this.isCityCell = function(internalCellId, externalCellId) this.isCityCell = function(internalCellId, externalCellId)
-- easy mode -- easy mode
if string.match(internalCellId, externalCellId) then if string.match(internalCellId, externalCellId) then
log(common.logLevels.large, "easy mode city: %s in %s", internalCellId, externalCellId) log(common.logLevels.large, "[CHECKS] easy mode city: %s in %s", internalCellId, externalCellId)
return true return true
end end
@ -69,18 +69,18 @@ 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", internalCellId, externalCellId, externalCity, log(common.logLevels.large, "[CHECKS] hard mode city: %s in %s, %s == %s", 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", internalCellId, log(common.logLevels.large, "[CHECKS] hard mode not city: %s not in %s, %s ~= %s or both are nil", internalCellId,
externalCellId, externalCity, internalCity) externalCellId, externalCity, internalCity)
return false return false
end end
this.isIgnoredCell = function(cell) this.isIgnoredCell = function(cell)
log(common.logLevels.large, "%s is %s, %s is %s", cell.id, config.ignored[cell.id] and "ignored" or "not ignored", log(common.logLevels.large, "[CHECKS] %s is %s, %s is %s", cell.id, config.ignored[cell.id] and "ignored" or "not ignored",
cell.sourceMod, config.ignored[cell.sourceMod] and "ignored" or "not ignored") cell.sourceMod, config.ignored[cell.sourceMod] and "ignored" or "not ignored")
-- don't do things in the wilderness -- don't do things in the wilderness
@ -96,7 +96,7 @@ this.fargothCheck = function()
if not fargothJournal then return false end if not fargothJournal then return false end
-- only disable Fargoth before speaking to Hrisskar, and after observing Fargoth sneak -- only disable Fargoth before speaking to Hrisskar, and after observing Fargoth sneak
log(common.logLevels.large, "Fargoth journal check %s: %s", fargothJournal, log(common.logLevels.large, "[CHECKS] Fargoth journal check %s: %s", fargothJournal,
fargothJournal > 10 and fargothJournal <= 30) fargothJournal > 10 and fargothJournal <= 30)
return fargothJournal > 10 and fargothJournal <= 30 return fargothJournal > 10 and fargothJournal <= 30
@ -210,7 +210,7 @@ this.isPublicHouse = function(cell)
-- Check for NPCS of ignored classes first -- Check for NPCS of ignored classes first
if not this.isIgnoredNPC(npc) then if not this.isIgnoredNPC(npc) then
if npc.object.class and config.ignored[npc.object.class.id] then if npc.object.class and config.ignored[npc.object.class.id] then
log(common.logLevels.medium, "NPC:\'%s\' of class:\'%s\' made %s public", npc.object.name, log(common.logLevels.medium, "[CHECKS] NPC:\'%s\' of class:\'%s\' made %s public", npc.object.name,
npc.object.class and npc.object.class.id or "none", cell.name) npc.object.class and npc.object.class.id or "none", cell.name)
dataTables.createPublicHouseTableEntry(cell, npc, city, publicHouseName, dataTables.createPublicHouseTableEntry(cell, npc, city, publicHouseName,
@ -237,7 +237,7 @@ this.isPublicHouse = function(cell)
-- Temples are always public -- Temples are always public
if npcs.factions["Temple"] and cell.name:lower():match("temple") then if npcs.factions["Temple"] and cell.name:lower():match("temple") then
local master = npcs.factions["Temple"].master local master = npcs.factions["Temple"].master
log(common.logLevels.medium, "%s is a temple, and %s, %s is the ranking member", cell.id, master.object.name, master.object.class) log(common.logLevels.medium, "[CHECKS] %s is a temple, and %s, %s is the ranking member", cell.id, master.object.name, master.object.class)
dataTables.createPublicHouseTableEntry(cell, master, city, publicHouseName, dataTables.createPublicHouseTableEntry(cell, master, city, publicHouseName,
cellEvaluators.calculateCellWorth(cell), cellEvaluators.calculateCellWorth(cell),
cellEvaluators.pickCellFaction(cell)) cellEvaluators.pickCellFaction(cell))
@ -252,14 +252,14 @@ this.isPublicHouse = function(cell)
cell.name, faction, config.ignored[faction], info.ref.playerJoined, info.total, info.percentage, cell.name, faction, config.ignored[faction], info.ref.playerJoined, info.total, info.percentage,
npcs.total) npcs.total)
-- log(common.logLevels.large, "ignored or joined:%s, occupants or blades:%s, faction percent:%s", (config.ignored[faction.id] or faction.playerJoined), -- log(common.logLevels.large, "[CHECKS] ignored or joined:%s, occupants or blades:%s, faction percent:%s", (config.ignored[faction.id] or faction.playerJoined),
-- (npcs.total >= config.minimumOccupancy or faction == "Blades"), (info.percentage >= config.factionIgnorePercentage)) -- (npcs.total >= config.minimumOccupancy or faction == "Blades"), (info.percentage >= config.factionIgnorePercentage))
-- less than configured amount of NPCs can't be a public house unless it's a Blades house -- less than configured amount of NPCs can't be a public house unless it's a Blades house
if (config.ignored[faction] or info.ref.playerJoined) and if (config.ignored[faction] or info.ref.playerJoined) and
(npcs.total >= config.minimumOccupancy or faction == "Blades") and (npcs.total >= config.minimumOccupancy or faction == "Blades") and
(info.percentage >= config.factionIgnorePercentage) then (info.percentage >= config.factionIgnorePercentage) then
log(common.logLevels.medium, "%s is %s%% faction %s, marking public.", cell.name, info.percentage, faction) log(common.logLevels.medium, "[CHECKS] %s is %s%% faction %s, marking public.", cell.name, info.percentage, faction)
dataTables.createPublicHouseTableEntry(cell, npcs.factions[faction].master, city, publicHouseName, dataTables.createPublicHouseTableEntry(cell, npcs.factions[faction].master, city, publicHouseName,
cellEvaluators.calculateCellWorth(cell), cellEvaluators.calculateCellWorth(cell),
@ -268,7 +268,7 @@ this.isPublicHouse = function(cell)
end end
end end
log(common.logLevels.large, "%s isn't public", cell.name) log(common.logLevels.large, "[CHECKS] %s isn't public", cell.name)
return false return false
end end
@ -276,7 +276,7 @@ end
this.isIgnoredDoor = function(door, homeCellId) this.isIgnoredDoor = function(door, homeCellId)
-- don't lock non-cell change doors -- don't lock non-cell change doors
if not door.destination then if not door.destination then
log(common.logLevels.large, "Non-Cell-change door %s, ignoring", door.id) log(common.logLevels.large, "[CHECKS] Non-Cell-change door %s, ignoring", door.id)
return true return true
end end
@ -301,7 +301,7 @@ this.isIgnoredDoor = function(door, homeCellId)
-- don't lock doors to canton cells -- don't lock doors to canton cells
local isCantonWorks = common.isCantonWorksCell(dest) local isCantonWorks = common.isCantonWorksCell(dest)
log(common.logLevels.large, "%s is %s, (%sin a city, is %spublic, %soccupied)", -- log(common.logLevels.large, "[CHECKS] %s is %s, (%sin a city, is %spublic, %soccupied)", --
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
@ -313,7 +313,7 @@ end
this.isNight = function() this.isNight = function()
local atNight = tes3.worldController.hour.value >= config.closeTime or -- AT NIGHT local atNight = tes3.worldController.hour.value >= config.closeTime or -- AT NIGHT
tes3.worldController.hour.value <= config.openTime tes3.worldController.hour.value <= config.openTime
log(common.logLevels.large, "Current time is %.2f (%snight), things are closed between %s and %s", log(common.logLevels.large, "[CHECKS] Current time is %.2f (%snight), things are closed between %s and %s",
tes3.worldController.hour.value, atNight and "" or "not ", config.closeTime, config.openTime) tes3.worldController.hour.value, atNight and "" or "not ", config.closeTime, config.openTime)
return atNight return atNight
@ -326,15 +326,15 @@ this.isInclementWeather = function()
local index = tes3.getCurrentWeather().index local index = tes3.getCurrentWeather().index
local isBad = index >= config.worstWeather local isBad = index >= config.worstWeather
log(common.logLevels.large, "Weather in %s: current:%s >= configured worst:%s == %s", tes3.getRegion().id, index, log(common.logLevels.large, "[CHECKS] Weather in %s: current:%s >= configured worst:%s, weather is %s", tes3.getRegion().id, index,
config.worstWeather, isBad) config.worstWeather, isBad and "bad" or "great")
return isBad return isBad
end end
-- travel agents, their steeds, and argonians stick around -- travel agents, their steeds, and argonians stick around
this.isBadWeatherNPC = function(npc) this.isBadWeatherNPC = function(npc)
log(common.logLevels.large, "NPC Inclement Weather: %s is %s%s", npc.object.name, npc.object.race.id, log(common.logLevels.large, "[CHECKS] NPC Inclement Weather: %s is %s%s", npc.object.name, npc.object.race.id,
this.offersTravel(npc) and ", travel agent" or "") this.offersTravel(npc) and ", travel agent" or "")
return this.offersTravel(npc) or npc.object.race.id == "Argonian" return this.offersTravel(npc) or npc.object.race.id == "Argonian"

View file

@ -16,7 +16,7 @@ this.createHomedNPCTableEntry = function(npc, home, startingPlace, isHome, posit
-- mod support for different positions in cells -- mod support for different positions in cells
local id = common.checkModdedCell(home.id) local id = common.checkModdedCell(home.id)
log(common.logLevels.medium, "Found %s for %s: %s... adding it to in memory table...", log(common.logLevels.medium, "[DTAB] Found %s for %s: %s... adding it to in memory table...",
isHome and "home" or "public house", npc.object.name, id) isHome and "home" or "public house", npc.object.name, id)
-- pick the position and orientation the NPC will be placed at -- pick the position and orientation the NPC will be placed at
@ -39,7 +39,7 @@ 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])
log(common.logLevels.large, "Settled on position:%s, orientation:%s for %s in %s", pickedPosition, pickedOrientation, npc.object.name, id) log(common.logLevels.large, "[DTAB] Settled on position:%s, orientation:%s for %s in %s", pickedPosition, pickedOrientation, npc.object.name, id)
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()) (npc.position and npc.position:copy() or zeroVector:copy())

View file

@ -22,7 +22,7 @@ this.livesInManor = function(cellName, npcName)
-- surnameless peasants don't live in manors -- surnameless peasants don't live in manors
if not sur then return end if not sur then return end
log(common.logLevels.large, "Checking if %s %s lives in %s", given, sur, cellName) log(common.logLevels.large, "[HOUSING] Checking if %s %s lives in %s", given, sur, cellName)
return string.match(cellName, sur) return string.match(cellName, sur)
end end
@ -36,7 +36,7 @@ this.pickInnForNPC = function(npc, city)
if common.runtimeData.publicHouses[city] and common.runtimeData.publicHouses[city][common.publicHouseTypes.inns] then if common.runtimeData.publicHouses[city] and common.runtimeData.publicHouses[city][common.publicHouseTypes.inns] then
local choice = table.choice(common.runtimeData.publicHouses[city][common.publicHouseTypes.inns]) local choice = table.choice(common.runtimeData.publicHouses[city][common.publicHouseTypes.inns])
if not choice then return nil end if not choice then return nil end
log(common.logLevels.medium, "Picking inn %s, %s for %s", choice.city, choice.name, npc.object.name) log(common.logLevels.medium, "[HOUSING] Picking inn %s, %s for %s", choice.city, choice.name, npc.object.name)
return choice.cell return choice.cell
end end
end end
@ -48,7 +48,7 @@ this.pickPublicHouseForNPC = function(npc, city)
for _, data in pairs(common.runtimeData.publicHouses[city][common.publicHouseTypes.guildhalls]) do for _, data in pairs(common.runtimeData.publicHouses[city][common.publicHouseTypes.guildhalls]) do
-- if npc's faction and proprietor's faction match, pick that one -- if npc's faction and proprietor's faction match, pick that one
if npc.object.faction == data.proprietor.object.faction then if npc.object.faction == data.proprietor.object.faction then
log(common.logLevels.medium, "Picking %s for %s based on faction", data.cell.id, npc.object.name) log(common.logLevels.medium, "[HOUSING] Picking %s for %s based on faction", data.cell.id, npc.object.name)
return data.cell return data.cell
end end
end end
@ -58,7 +58,7 @@ this.pickPublicHouseForNPC = function(npc, city)
if common.runtimeData.publicHouses[city] and common.runtimeData.publicHouses[city][common.publicHouseTypes.temples] then if common.runtimeData.publicHouses[city] and common.runtimeData.publicHouses[city][common.publicHouseTypes.temples] then
for _, data in pairs(common.runtimeData.publicHouses[city][common.publicHouseTypes.temples]) do for _, data in pairs(common.runtimeData.publicHouses[city][common.publicHouseTypes.temples]) do
if npc.object.faction == data.proprietor.object.faction then if npc.object.faction == data.proprietor.object.faction then
log(common.logLevels.medium, "Picking temple %s for %s based on faction", data.cell.id, npc.object.name) log(common.logLevels.medium, "[HOUSING] Picking temple %s for %s based on faction", data.cell.id, npc.object.name)
return data.cell return data.cell
end end
end end
@ -94,7 +94,7 @@ this.pickHomeForNPC = function(cell, npc)
-- haven't found a home, so put them in an inn or guildhall, or inside a canton -- haven't found a home, so put them in an inn or guildhall, or inside a canton
if config.homelessWanderersToPublicHouses then if config.homelessWanderersToPublicHouses then
log(common.logLevels.medium, "Didn't find a home for %s, trying inns", npc.object.name) log(common.logLevels.medium, "[HOUSING] Didn't find a home for %s, trying inns", npc.object.name)
local dest = this.pickPublicHouseForNPC(npc, city) local dest = this.pickPublicHouseForNPC(npc, city)
if dest then return dataTables.createHomedNPCTableEntry(npc, dest, cell, false) end if dest then return dataTables.createHomedNPCTableEntry(npc, dest, cell, false) end
@ -104,7 +104,7 @@ this.pickHomeForNPC = function(cell, npc)
if common.runtimeData.publicHouses[city] and if common.runtimeData.publicHouses[city] and
common.runtimeData.publicHouses[city][common.publicHouseTypes.cantonworks] then common.runtimeData.publicHouses[city][common.publicHouseTypes.cantonworks] then
local canton = table.choice(common.runtimeData.publicHouses[city][common.publicHouseTypes.cantonworks]) local canton = table.choice(common.runtimeData.publicHouses[city][common.publicHouseTypes.cantonworks])
log(common.logLevels.medium, "Picking works %s, %s for %s", canton.city, canton.name, npc.object.name) log(common.logLevels.medium, "[HOUSING] Picking works %s, %s for %s", canton.city, canton.name, npc.object.name)
if canton then return dataTables.createHomedNPCTableEntry(npc, canton.cell, cell, false) end if canton then return dataTables.createHomedNPCTableEntry(npc, canton.cell, cell, false) end
end end

View file

@ -43,7 +43,7 @@ this.calculateNPCWorth = function(npc, merchantCell)
-- calculate the total -- calculate the total
local total = 0 local total = 0
for _, v in pairs(worth) do total = total + v end for _, v in pairs(worth) do total = total + v end
log(common.logLevels.medium, "Calculated worth of %s for %s", total, npc.object.name) log(common.logLevels.medium, "[NPCEVAL] Calculated worth of %s for %s", total, npc.object.name)
-- then add it to the table -- then add it to the table
worth.total = total worth.total = total

View file

@ -24,7 +24,7 @@ local function buildFollowerList()
for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do
if friend ~= tes3.mobilePlayer then -- ? why is the player friendly towards the player ? if friend ~= tes3.mobilePlayer then -- ? why is the player friendly towards the player ?
f[friend.object.id] = true f[friend.object.id] = true
log(common.logLevels.large, "%s is follower", friend.object.id) log(common.logLevels.large, "[MAIN] %s is follower", friend.object.id)
end end
end end
return f return f
@ -86,13 +86,13 @@ local function applyChanges(cell)
end end
local function updateCells() local function updateCells()
log(common.logLevels.medium, "Updating active cells!") log(common.logLevels.medium, "[MAIN] Updating active cells!")
common.runtimeData.followers = buildFollowerList() common.runtimeData.followers = buildFollowerList()
processors.searchCellsForPositions() processors.searchCellsForPositions()
for _, cell in pairs(tes3.getActiveCells()) do for _, cell in pairs(tes3.getActiveCells()) do
log(common.logLevels.large, "Applying changes to cell %s", cell.id) log(common.logLevels.large, "[MAIN] Applying changes to cell %s", cell.id)
applyChanges(cell) applyChanges(cell)
end end
end end
@ -111,7 +111,7 @@ local function updatePlayerTrespass(cell, previousCell)
else else
tes3.player.data.NPCsGoHome.intruding = false tes3.player.data.NPCsGoHome.intruding = false
end end
log(common.logLevels.small, "Updating player trespass status to %s", tes3.player.data.NPCsGoHome.intruding) log(common.logLevels.small, "[MAIN] Updating player trespass status to %s", tes3.player.data.NPCsGoHome.intruding)
end end
-- }}} -- }}}
@ -163,7 +163,7 @@ local function onKeyDown(e)
end end
-- if ctrl log position data formatted for positions.lua -- if ctrl log position data formatted for positions.lua
if e.isControlDown then if e.isControlDown then
log(common.logLevels.none, "{position = %s, orientation = %s,", tes3.player.position, tes3.player.orientation) log(common.logLevels.none, "[MAIN] {position = %s, orientation = %s},", pos, ori)
end end
end end
@ -172,7 +172,7 @@ end
-- {{{ init -- {{{ init
local function onInitialized() local function onInitialized()
-- Register events -- Register events
log(common.logLevels.small, "Registering events...") log(common.logLevels.small, "[MAIN] Registering events...")
event.register("loaded", onLoaded) event.register("loaded", onLoaded)
event.register("cellChanged", onCellChanged) event.register("cellChanged", onCellChanged)
event.register("activate", onActivated) event.register("activate", onActivated)
@ -180,7 +180,7 @@ local function onInitialized()
-- debug events -- debug events
event.register("keyDown", onKeyDown, { filter = tes3.scanCode.c } ) event.register("keyDown", onKeyDown, { filter = tes3.scanCode.c } )
log(common.logLevels.none, "Successfully initialized") log(common.logLevels.none, "[MAIN] Successfully initialized")
end end
event.register("initialized", onInitialized) event.register("initialized", onInitialized)