Code: Select all
for r, radar_id in pairs(players[index] or {}) do
radar = radars[radar_id]
if radar then
-- snip
if player.force.is_chunk_charted(radar.surface, radar.chunk_position) then
radar.chart_tag = player.force.add_chart_tag(radar.surface, new_chart_data())
-- Chart tags can only be placed on generated chunks. If the new force
-- hasn't charted this chunk yet, schedule charting (this will raise
-- on_chunk_charted) and store the data for the new force's chart tag!
else
local x, y = radar.chart_tag.position.x, radar.chart_tag.position.y
local area = {{x - 16, y - 16}, {x + 16, y + 16}}
radar.ordered_chart = new_chart_data()
MAPS.show("radar.ordered_chart", radar.ordered_chart)
player.force.chart(radar.surface, area)
MAPS.show("Ordered charting of this area on \""..radar.surface.name.."\"", area)
end
-- Anything here won't be run if the area is charted.
end
end
For some reason, player.force.chart() never seems to return in the tick it was called. Is that intended? I realize that charting is an expensive operation which may take far longer than just one tick (that's why we can listen to on_chunk_charted). But I supposed that function would just put the area on top of the list of chunks that must be charted, then it would return to finish with the remaining code, and the actual charting would start at the end of the tick.
By the way, when exactly is a chunk regarded as charted? I'm working on a mod that's placing hidden radars (each scanning just one chunk, i.e. max_distance_of_sector_revealed and max_distance_of_nearby_sector_revealed are set to 0) that are associated with specific players. When a player changes to another force, radar.force will be set to the player's new force, so radar coverage of the player's chunks is transferred from the old to the new force. Perhaps I'd better use on_sector_scanned instead of on_chunk_charted?