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