1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/maps/scrap_towny_ffa/limited_radar.lua
2022-10-22 22:13:35 +02:00

68 lines
1.9 KiB
Lua

local Event = require 'utils.event'
local ScenarioTable = require 'maps.scrap_towny_ffa.table'
local Public = {}
function Public.reset()
local this = ScenarioTable.get_table()
if this.testing_mode then
return
end
for index = 1, table.size(game.forces), 1 do
local force = game.forces[index]
if force ~= nil then
force.clear_chart('nauvis')
end
end
end
local function add_force(id, force_name)
local forces = rendering.get_forces(id)
for _, force in ipairs(forces) do
if force.name == force_name or force == force_name then
return
end
end
forces[#forces + 1] = force_name
rendering.set_forces(id, forces)
end
local function update_forces(id)
local forces = rendering.get_forces(id)
local new_forces = {}
for _, force in ipairs(forces) do
if force ~= nil and force.valid then
new_forces[#new_forces + 1] = force.name
end
end
rendering.set_forces(id, new_forces)
end
local function on_chunk_charted(event)
local surface = game.surfaces[event.surface_index]
local force = event.force
local area = event.area
local markets = surface.find_entities_filtered({area = area, name = 'market'})
for _, market in pairs(markets) do
local force_name = market.force.name
local this = ScenarioTable.get_table()
local town_center = this.town_centers[force_name]
if not town_center then
return
end
-- town caption
local town_caption = town_center.town_caption
update_forces(town_caption)
add_force(town_caption, force.name)
-- health text
local health_text = town_center.health_text
update_forces(health_text)
add_force(health_text, force.name)
end
end
Event.add(defines.events.on_chunk_charted, on_chunk_charted)
return Public