Bump version to 0.1.6, add player kill tracking, and enhance power/lab stats handling
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"Lua.workspace.userThirdParty": [
|
"Lua.workspace.userThirdParty": [
|
||||||
"c:\\Users\\jangr\\AppData\\Roaming\\Code\\User\\workspaceStorage\\8bef1fd407f1cda3acb8320784a68ee6\\justarandomgeek.factoriomod-debug\\sumneko-3rd"
|
"c:\\Users\\jangr\\AppData\\Roaming\\Code\\User\\workspaceStorage\\071322d83ef859d27b899371aa0efcc4\\justarandomgeek.factoriomod-debug\\sumneko-3rd"
|
||||||
],
|
],
|
||||||
"Lua.workspace.checkThirdParty": "ApplyInMemory",
|
"Lua.workspace.checkThirdParty": "ApplyInMemory",
|
||||||
"factorio.versions": [
|
"factorio.versions": [
|
||||||
|
|||||||
77
control.lua
77
control.lua
@@ -10,7 +10,6 @@ udpAddress = 52555
|
|||||||
isInitialized = false
|
isInitialized = false
|
||||||
sendIndex = 0
|
sendIndex = 0
|
||||||
serverIndex = 0
|
serverIndex = 0
|
||||||
LabsScanned = false
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
enableMod = false,
|
enableMod = false,
|
||||||
@@ -34,6 +33,11 @@ script.on_init(function ()
|
|||||||
storage.totalResearchSpeed = 0
|
storage.totalResearchSpeed = 0
|
||||||
storage.totalReseachProductivity = 0
|
storage.totalReseachProductivity = 0
|
||||||
storage.labs = {}
|
storage.labs = {}
|
||||||
|
storage.playerKillCount = {}
|
||||||
|
storage.representativePoles = {}
|
||||||
|
|
||||||
|
storage.scannedGrids = false
|
||||||
|
storage.scannedLabs = false
|
||||||
sendIndex = 0
|
sendIndex = 0
|
||||||
|
|
||||||
options.enableMod = settings.global["factorio-metrics-exporter-enable"].value
|
options.enableMod = settings.global["factorio-metrics-exporter-enable"].value
|
||||||
@@ -73,6 +77,11 @@ script.on_configuration_changed(function()
|
|||||||
storage.totalLabCount = storage.totalLabCount or 0
|
storage.totalLabCount = storage.totalLabCount or 0
|
||||||
storage.totalReseachProductivity = storage.totalReseachProductivity or 0
|
storage.totalReseachProductivity = storage.totalReseachProductivity or 0
|
||||||
storage.totalResearchSpeed = storage.totalResearchSpeed or 0
|
storage.totalResearchSpeed = storage.totalResearchSpeed or 0
|
||||||
|
storage.playerKillCount = storage.playerKillCount or {}
|
||||||
|
storage.representativePoles = storage.representativePoles or {}
|
||||||
|
storage.scannedGrids = storage.scannedGrids or false
|
||||||
|
storage.scannedLabs = storage.scannedLabs or false
|
||||||
|
ScanNetworks()
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -122,10 +131,22 @@ end)
|
|||||||
|
|
||||||
|
|
||||||
script.on_event(defines.events.on_player_died, function(event)
|
script.on_event(defines.events.on_player_died, function(event)
|
||||||
|
if event.cause.is_player() then
|
||||||
|
local killer_index = event.cause.player.index
|
||||||
|
local victim_index = event.player_index
|
||||||
|
|
||||||
|
storage.playerKillCount[killer_index] =
|
||||||
|
storage.playerKillCount[killer_index] or {}
|
||||||
|
|
||||||
|
storage.playerKillCount[killer_index][victim_index] =
|
||||||
|
(storage.playerKillCount[killer_index][victim_index] or 0) + 1
|
||||||
|
end
|
||||||
--local player = game.get_player(event.player_index)
|
--local player = game.get_player(event.player_index)
|
||||||
storage.playerDeathCount[event.player_index] = (storage.playerDeathCount[event.player_index] or 0) + 1
|
storage.playerDeathCount[event.player_index] = (storage.playerDeathCount[event.player_index] or 0) + 1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function SendGameStats(event)
|
function SendGameStats(event)
|
||||||
local returnParts = {}
|
local returnParts = {}
|
||||||
returnParts[#returnParts+1] = GetMods()
|
returnParts[#returnParts+1] = GetMods()
|
||||||
@@ -149,22 +170,23 @@ function SendAll(event)
|
|||||||
end
|
end
|
||||||
isInitialized = true
|
isInitialized = true
|
||||||
|
|
||||||
log("ServerIndex is "..serverIndex.." now")
|
--log("ServerIndex is "..serverIndex.." now")
|
||||||
|
|
||||||
if PowerGridScanned == false then
|
if storage.scannedGrids == false then
|
||||||
GenerateNetworks()
|
ScanNetworks()
|
||||||
|
storage.scannedGrids = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if LabsScanned == false then
|
if storage.scannedLabs == false then
|
||||||
GenerateLabInfo()
|
ScanLabs()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if options.enableMod==true then
|
if options.enableMod==true then
|
||||||
|
|
||||||
if (event.tick % math.floor(tickInterval/7) ~= 0) then return end
|
if (event.tick % math.floor(tickInterval/8) ~= 0) then return end
|
||||||
|
|
||||||
sendIndex = (sendIndex % 7) + 1
|
sendIndex = (sendIndex % 8) + 1
|
||||||
if sendIndex == 1 then SendProductionStats() end
|
if sendIndex == 1 then SendProductionStats() end
|
||||||
if sendIndex == 2 then SendPollutionStats() end
|
if sendIndex == 2 then SendPollutionStats() end
|
||||||
if sendIndex == 3 then SendKillStats() end
|
if sendIndex == 3 then SendKillStats() end
|
||||||
@@ -172,6 +194,7 @@ function SendAll(event)
|
|||||||
if sendIndex == 5 then SendBuildStats() end
|
if sendIndex == 5 then SendBuildStats() end
|
||||||
if sendIndex == 6 then SendResearchStats() end
|
if sendIndex == 6 then SendResearchStats() end
|
||||||
if sendIndex == 7 then SendLogisticStats() end
|
if sendIndex == 7 then SendLogisticStats() end
|
||||||
|
if sendIndex == 8 then SendPowerStats() end
|
||||||
|
|
||||||
if(event.tick % tickInterval*2 == 0) then
|
if(event.tick % tickInterval*2 == 0) then
|
||||||
if options.enablePlayers then
|
if options.enablePlayers then
|
||||||
@@ -180,13 +203,41 @@ function SendAll(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UpdateStorage(event)
|
||||||
|
if not event then return end
|
||||||
|
if event.entity.type == "lab" then
|
||||||
|
UpdateLabs(event)
|
||||||
|
end
|
||||||
|
if event.entity.type == "electric-pole" then
|
||||||
|
AddPowerPole(event)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function RemoveStorage(event)
|
||||||
|
if not event then return end
|
||||||
|
if event.entity.type =="lab" then
|
||||||
|
RemoveLab(event)
|
||||||
|
end
|
||||||
|
if event.entity.type == "electric-pole" then
|
||||||
|
RemovePowerPole(event)
|
||||||
|
end
|
||||||
|
if event.entity.name == "crash-site-spaceship" then
|
||||||
|
if event.name == defines.events.on_player_mined_entity then
|
||||||
|
if settings.global["factorio-metrics-exporter-enable_denkmalschutz"].value == true then
|
||||||
|
game.ban_player(event.player_index,"You violated the rules of DENKMALSCHUTZ!!!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
script.on_event(defines.events.on_tick, SendAll)
|
script.on_event(defines.events.on_tick, SendAll)
|
||||||
|
|
||||||
--Script hooks for power stats
|
--Script hooks for power and lab stats
|
||||||
script.on_event(defines.events.on_built_entity,UpdateGrids,{{filter = "type", type = "electric-pole"}})
|
script.on_event(defines.events.on_built_entity,UpdateStorage,{{filter = "type", type = "electric-pole" or "lab"}})
|
||||||
script.on_event(defines.events.on_player_mined_entity, PurgeNetworks,{{filter = "type", type = "electric-pole"}})
|
script.on_event(defines.events.on_player_mined_entity, RemoveStorage,{{filter = "type", type = "electric-pole"or "lab" or "container"}})
|
||||||
script.on_event(defines.events.on_robot_built_entity,UpdateGrids,{{filter = "type", type = "electric-pole"}})
|
script.on_event(defines.events.on_robot_built_entity,UpdateStorage,{{filter = "type", type = "electric-pole" or "lab"}})
|
||||||
script.on_event(defines.events.on_robot_mined_entity,PurgeNetworks,{{filter = "type", type = "electric-pole"}})
|
script.on_event(defines.events.on_robot_mined_entity,RemoveStorage,{{filter = "type", type = "electric-pole" or "lab" or "container"}})
|
||||||
|
script.on_event(defines.events.on_entity_died,RemoveStorage,{{filter = "type", type = "electric-pole" or "lab" or "container"}})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "factorio-metrics-exporter",
|
"name": "factorio-metrics-exporter",
|
||||||
"version": "0.1.5",
|
"version": "0.1.6",
|
||||||
"title": "Prometheus Metrics Exporter",
|
"title": "Prometheus Metrics Exporter",
|
||||||
"author": "Jan Grießhaber",
|
"author": "Jan Grießhaber",
|
||||||
"contact": "jan@griesshaber.systems",
|
"contact": "jan@griesshaber.systems",
|
||||||
|
|||||||
@@ -1,42 +1,63 @@
|
|||||||
PowerGridScanned = false
|
function AddPowerPole(event)
|
||||||
function GetGlobalGridSurfaces()
|
local e = event.entity
|
||||||
local globalGrids = {}
|
if e and e.valid and e.type == "electric-pole" then
|
||||||
|
storage.representativePoles[e.unit_number] = e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function RemovePowerPole(event)
|
||||||
|
local e = event.entity
|
||||||
|
if e then
|
||||||
|
storage.representativePoles[e.unit_number] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function GetNetworks()
|
||||||
|
local networks = {}
|
||||||
|
|
||||||
|
for _, pole in pairs(storage.representativePoles) do
|
||||||
|
if pole.valid then
|
||||||
|
local net = pole.electric_network_id
|
||||||
|
if net then
|
||||||
|
networks[net] = pole
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return networks
|
||||||
|
end
|
||||||
|
|
||||||
|
function ScanNetworks()
|
||||||
|
storage.representative_poles = {}
|
||||||
|
|
||||||
for _, surface in pairs(game.surfaces) do
|
for _, surface in pairs(game.surfaces) do
|
||||||
if(surface.has_global_electric_network) then
|
for _, pole in pairs(surface.find_entities_filtered{type = "electric-pole"}) do
|
||||||
globalGrids[#globalGrids+1] = surface
|
if pole.valid and pole.electric_network_id then
|
||||||
|
storage.representativePoles[pole.unit_number] = pole
|
||||||
end
|
end
|
||||||
--log("Surface: "..surface.name.." has global electric network: "..tostring(grids))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function UpdateGrids(event)
|
|
||||||
local entity = event.entity
|
|
||||||
local gridID = entity.electric_network_id
|
|
||||||
if gridID == nil then return end
|
|
||||||
storage.electricGrids[gridID] = (storage.electricGrids[gridID] or 0) + 1
|
|
||||||
log(("Network %d has counter of %d"):format(gridID,storage.electricGrids[gridID]))
|
|
||||||
end
|
|
||||||
|
|
||||||
function PurgeNetworks()
|
|
||||||
for ID, Counter in pairs(storage.electricGrids) do
|
|
||||||
if Counter <= 0 then
|
|
||||||
table.remove(storage.electricGrids, ID)
|
|
||||||
log(("Removed electric network with id %d from list"):format(ID))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function SendPowerStats()
|
||||||
function GenerateNetworks()
|
if options.enablePower then
|
||||||
if PowerGridScanned==false then
|
local powerPart = {}
|
||||||
for _,surface in pairs(game.surfaces) do
|
powerPart[#powerPart+1] = "---power-stats---\n"
|
||||||
for _, powerPole in pairs(surface.find_entities_filtered({filter = "type",type = "electric-pole"})) do
|
for _, pole in pairs(GetNetworks()) do
|
||||||
storage.electricGrids[powerPole.electric_network_id] = (storage.electricGrids[powerPole.electric_network_id] or 0) + 1
|
if pole.valid and pole.type == "electric-pole" then
|
||||||
|
local input = pole.electric_network_statistics.input_counts
|
||||||
|
local output = pole.electric_network_statistics.output_counts
|
||||||
|
local surfaceName = pole.surface.name
|
||||||
|
for item,value in pairs(input) do
|
||||||
|
powerPart[#powerPart+1] = ("%s:%d:in:%s:%d"):format(surfaceName, pole.electric_network_id, item, value)
|
||||||
end
|
end
|
||||||
|
for item, value in pairs(output) do
|
||||||
|
powerPart[#powerPart+1] = ("%s:%d:out:%s:%d"):format(surfaceName,pole.electric_network_id, item, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
PowerGridScanned = true
|
end
|
||||||
|
helpers.send_udp(udpAddress,table.concat(powerPart,"\n"),serverIndex)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,33 @@
|
|||||||
storage.totalLabCount = 0
|
|
||||||
local labBaseSpeed = 1
|
local labBaseSpeed = 1
|
||||||
local biolabBaseSpeed = 2
|
local biolabBaseSpeed = 2
|
||||||
|
|
||||||
LabsScanned = false
|
|
||||||
|
|
||||||
|
function ScanLabs()
|
||||||
function GenerateLabInfo()
|
|
||||||
storage.labs = {}
|
storage.labs = {}
|
||||||
for _, surface in pairs(game.surfaces) do
|
for _, surface in pairs(game.surfaces) do
|
||||||
local labs = surface.find_entities_filtered({type="lab"})
|
local labs = surface.find_entities_filtered({type="lab"})
|
||||||
for index, lab in pairs(labs) do
|
for _, lab in pairs(labs) do
|
||||||
if lab.valid then
|
storage.labs[lab.unit_number] = lab
|
||||||
storage.labs[index] = lab
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
storage.scannedLabs = true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function UpdateLabs(event)
|
||||||
|
local lab = event.entity
|
||||||
|
if lab and lab.valid then
|
||||||
|
storage.labs[lab.unit_number] = lab
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function RemoveLab(event)
|
||||||
|
local lab = event.entity
|
||||||
|
if lab and lab.valid then
|
||||||
|
storage.labs[lab.unit_number] = nil
|
||||||
end
|
end
|
||||||
LabsScanned = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -58,7 +70,6 @@ function UpdateLabInfos()
|
|||||||
end
|
end
|
||||||
local labSpeed = (labBase + (labBase * game.forces["player"].laboratory_speed_modifier)) * (lab.effects.speed or 1)
|
local labSpeed = (labBase + (labBase * game.forces["player"].laboratory_speed_modifier)) * (lab.effects.speed or 1)
|
||||||
totalSpeed = totalSpeed + (labSpeed* (1+(lab.effects.productivity or 0)))
|
totalSpeed = totalSpeed + (labSpeed* (1+(lab.effects.productivity or 0)))
|
||||||
--local labSpeed = labBaseSpeed * lab.effects.speed
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ data:extend({
|
|||||||
setting_type = "runtime-global",
|
setting_type = "runtime-global",
|
||||||
default_value = true,
|
default_value = true,
|
||||||
order = "i"
|
order = "i"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "bool-setting",
|
||||||
|
name = "factorio-metrics-exporter-enable_denkmalschutz",
|
||||||
|
setting_type = "runtime-global",
|
||||||
|
default_value = false,
|
||||||
|
order = "z"
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user