Access to map chart data
Posted: Fri Jul 11, 2025 12:11 pm
Currently we have APIs on LuaForce for creating/updating/clearing/copying charts. However, there is no way to read the chart data. The best approximation we can get is reading out all the tiles, getting their map_color, then reading all entities and getting the map_color and colission box for those as well and layering it. Even then, we still need to hardcode the map representation of stuff like curved rails.
An example of how this looks can be found here: https://github.com/Danielv123/gridworld ... tities.lua
This still doesn't handle different forces having explored different amounts of land or rail corners.
The data is already stored in memory directly as a bitmap. I suggest a function to read the bitmap for a chunk and get back RGB values.
Internally the data is stored as RGB 565 - I don't really care whether we return it in that format or 888 or 8888. For my purposes the smaller represenation is better because its faster on the game side, and I can unpack it externally. Another alternative is passing a third argument for PixelType and remapping that based on demand.
Suggested API:
LuaForce.get_chunk_chart(surface, chunkPosition)
Returns a 2048 byte string where each 2 bytes represents one RGB pixel. This covers a 32x32 chunk. Returns nil if the chunk is not charted.
I am also interested in being able to write directly to the chart data, but I don't quite know how I'd even like that to look, as considerations should be made to not fight the vanilla charting from radars or nearby players. For now I think simpleentities or luarendering is plenty for that purpose.
Related proposals:
- viewtopic.php?t=76539 - Implemented by Ghenis in 2.0.56
- viewtopic.php?p=163859 - No comment since 2016
An example of how this looks can be found here: https://github.com/Danielv123/gridworld ... tities.lua
This still doesn't handle different forces having explored different amounts of land or rail corners.
The data is already stored in memory directly as a bitmap. I suggest a function to read the bitmap for a chunk and get back RGB values.
Internally the data is stored as RGB 565 - I don't really care whether we return it in that format or 888 or 8888. For my purposes the smaller represenation is better because its faster on the game side, and I can unpack it externally. Another alternative is passing a third argument for PixelType and remapping that based on demand.
Suggested API:
LuaForce.get_chunk_chart(surface, chunkPosition)
Returns a 2048 byte string where each 2 bytes represents one RGB pixel. This covers a 32x32 chunk. Returns nil if the chunk is not charted.
Code: Select all
local pos = game.player.position;
local p = game.player.force.get_chunk_chart(game.player.surface, {pos.x/32, pos.y/32});
if p then
local v=string.byte(p,1)+string.byte(p,2)*256;
game.print(
string.format("First pixel RGB: %d, %d, %d",
math.floor(bit32.rshift(v,11)*255/31),
math.floor(bit32.rshift(bit32.band(v,0x07E0),5)*255/63),
math.floor(bit32.band(v,0x001F)*255/31))
);
else
game.print("No chart data");
end
Related proposals:
- viewtopic.php?t=76539 - Implemented by Ghenis in 2.0.56
- viewtopic.php?p=163859 - No comment since 2016