From 7e96593833c2e2a0f6999e4089f6d19458252211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Sat, 3 Oct 2020 22:15:50 -0700 Subject: [PATCH] louder but maybe more readable logging --- .../NPCsGoHome/functions/cellEvaluators.lua | 6 +-- .../celediel/NPCsGoHome/functions/checks.lua | 38 +++++++++---------- .../NPCsGoHome/functions/dataTables.lua | 4 +- .../celediel/NPCsGoHome/functions/housing.lua | 12 +++--- .../NPCsGoHome/functions/npcEvaluators.lua | 2 +- MWSE/mods/celediel/NPCsGoHome/main.lua | 14 +++---- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/MWSE/mods/celediel/NPCsGoHome/functions/cellEvaluators.lua b/MWSE/mods/celediel/NPCsGoHome/functions/cellEvaluators.lua index 3e77f89..9d5a35e 100644 --- a/MWSE/mods/celediel/NPCsGoHome/functions/cellEvaluators.lua +++ b/MWSE/mods/celediel/NPCsGoHome/functions/cellEvaluators.lua @@ -17,7 +17,7 @@ this.calculateCellWorth = function(cell, proprietor) msg = msg .. string.format("%s worth:%s, ", innard.object.name, total) 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 ", " return worth end @@ -54,8 +54,8 @@ this.pickCellFaction = function(cell) -- from the majority values, return the faction with the largest percentage, or nil local picked = common.keyOfLargestValue(npcs.majorityFactions) - log(common.logLevels.medium, "Picked faction %s for cell %s", picked, cell.id) - log(common.logLevels.large, "breakdown:\n%s", json.encode(npcs, {indent = true})) + log(common.logLevels.medium, "[CELLEVAL] Picked faction %s for cell %s", picked, cell.id) + log(common.logLevels.large, "[CELLEVAL] breakdown:\n%s", json.encode(npcs, {indent = true})) return picked end diff --git a/MWSE/mods/celediel/NPCsGoHome/functions/checks.lua b/MWSE/mods/celediel/NPCsGoHome/functions/checks.lua index 7189dd3..6a0df9d 100644 --- a/MWSE/mods/celediel/NPCsGoHome/functions/checks.lua +++ b/MWSE/mods/celediel/NPCsGoHome/functions/checks.lua @@ -24,7 +24,7 @@ end local function getFightFromSpawnedReference(id) -- Spawn a reference of the given id in 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({ object = id, @@ -37,7 +37,7 @@ local function getFightFromSpawnedReference(id) 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) @@ -50,7 +50,7 @@ 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, + 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) return cell.isInterior and not cell.behavesAsExterior @@ -59,7 +59,7 @@ end this.isCityCell = function(internalCellId, externalCellId) -- easy mode 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 end @@ -69,18 +69,18 @@ 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, + log(common.logLevels.large, "[CHECKS] 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, + log(common.logLevels.large, "[CHECKS] hard mode not city: %s not in %s, %s ~= %s or both are nil", internalCellId, externalCellId, externalCity, internalCity) return false end 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") -- don't do things in the wilderness @@ -96,7 +96,7 @@ this.fargothCheck = function() if not fargothJournal then return false end -- 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) return fargothJournal > 10 and fargothJournal <= 30 @@ -210,7 +210,7 @@ this.isPublicHouse = function(cell) -- Check for NPCS of ignored classes first if not this.isIgnoredNPC(npc) 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) dataTables.createPublicHouseTableEntry(cell, npc, city, publicHouseName, @@ -237,7 +237,7 @@ this.isPublicHouse = function(cell) -- Temples are always public if npcs.factions["Temple"] and cell.name:lower():match("temple") then 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, cellEvaluators.calculateCellWorth(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, 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)) -- 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 (npcs.total >= config.minimumOccupancy or faction == "Blades") and (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, cellEvaluators.calculateCellWorth(cell), @@ -268,7 +268,7 @@ this.isPublicHouse = function(cell) 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 end @@ -276,7 +276,7 @@ end this.isIgnoredDoor = function(door, homeCellId) -- don't lock non-cell change doors 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 end @@ -301,7 +301,7 @@ this.isIgnoredDoor = function(door, homeCellId) -- don't lock doors to canton cells 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 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() local atNight = tes3.worldController.hour.value >= config.closeTime or -- AT NIGHT 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) return atNight @@ -326,15 +326,15 @@ this.isInclementWeather = function() local index = tes3.getCurrentWeather().index local isBad = index >= config.worstWeather - log(common.logLevels.large, "Weather in %s: current:%s >= configured worst:%s == %s", tes3.getRegion().id, index, - config.worstWeather, isBad) + log(common.logLevels.large, "[CHECKS] Weather in %s: current:%s >= configured worst:%s, weather is %s", tes3.getRegion().id, index, + config.worstWeather, isBad and "bad" or "great") return isBad end -- travel agents, their steeds, and argonians stick around 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 "") return this.offersTravel(npc) or npc.object.race.id == "Argonian" diff --git a/MWSE/mods/celediel/NPCsGoHome/functions/dataTables.lua b/MWSE/mods/celediel/NPCsGoHome/functions/dataTables.lua index a295ad1..96e0dcc 100644 --- a/MWSE/mods/celediel/NPCsGoHome/functions/dataTables.lua +++ b/MWSE/mods/celediel/NPCsGoHome/functions/dataTables.lua @@ -16,7 +16,7 @@ this.createHomedNPCTableEntry = function(npc, home, startingPlace, isHome, posit -- mod support for different positions in cells 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) -- 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]) 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 (npc.position and npc.position:copy() or zeroVector:copy()) diff --git a/MWSE/mods/celediel/NPCsGoHome/functions/housing.lua b/MWSE/mods/celediel/NPCsGoHome/functions/housing.lua index 180830f..ee7d786 100644 --- a/MWSE/mods/celediel/NPCsGoHome/functions/housing.lua +++ b/MWSE/mods/celediel/NPCsGoHome/functions/housing.lua @@ -22,7 +22,7 @@ this.livesInManor = function(cellName, npcName) -- surnameless peasants don't live in manors 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) end @@ -36,7 +36,7 @@ this.pickInnForNPC = function(npc, city) 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]) 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 end end @@ -48,7 +48,7 @@ this.pickPublicHouseForNPC = function(npc, city) 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.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 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 for _, data in pairs(common.runtimeData.publicHouses[city][common.publicHouseTypes.temples]) do 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 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 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) 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 common.runtimeData.publicHouses[city][common.publicHouseTypes.cantonworks] then 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 end diff --git a/MWSE/mods/celediel/NPCsGoHome/functions/npcEvaluators.lua b/MWSE/mods/celediel/NPCsGoHome/functions/npcEvaluators.lua index 745b687..e408973 100644 --- a/MWSE/mods/celediel/NPCsGoHome/functions/npcEvaluators.lua +++ b/MWSE/mods/celediel/NPCsGoHome/functions/npcEvaluators.lua @@ -43,7 +43,7 @@ this.calculateNPCWorth = function(npc, merchantCell) -- calculate the total local total = 0 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 worth.total = total diff --git a/MWSE/mods/celediel/NPCsGoHome/main.lua b/MWSE/mods/celediel/NPCsGoHome/main.lua index b50fb58..d1b63d1 100644 --- a/MWSE/mods/celediel/NPCsGoHome/main.lua +++ b/MWSE/mods/celediel/NPCsGoHome/main.lua @@ -24,7 +24,7 @@ local function buildFollowerList() for friend in tes3.iterate(tes3.mobilePlayer.friendlyActors) do if friend ~= tes3.mobilePlayer then -- ? why is the player friendly towards the player ? 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 return f @@ -86,13 +86,13 @@ local function applyChanges(cell) end local function updateCells() - log(common.logLevels.medium, "Updating active cells!") + log(common.logLevels.medium, "[MAIN] Updating active cells!") common.runtimeData.followers = buildFollowerList() processors.searchCellsForPositions() 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) end end @@ -111,7 +111,7 @@ local function updatePlayerTrespass(cell, previousCell) else tes3.player.data.NPCsGoHome.intruding = false 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 -- }}} @@ -163,7 +163,7 @@ local function onKeyDown(e) end -- if ctrl log position data formatted for positions.lua 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 @@ -172,7 +172,7 @@ end -- {{{ init local function onInitialized() -- Register events - log(common.logLevels.small, "Registering events...") + log(common.logLevels.small, "[MAIN] Registering events...") event.register("loaded", onLoaded) event.register("cellChanged", onCellChanged) event.register("activate", onActivated) @@ -180,7 +180,7 @@ local function onInitialized() -- debug events event.register("keyDown", onKeyDown, { filter = tes3.scanCode.c } ) - log(common.logLevels.none, "Successfully initialized") + log(common.logLevels.none, "[MAIN] Successfully initialized") end event.register("initialized", onInitialized)