Drawing maps with Lua (OUTDATED)
Starting in 0.9.18 it is possible to reliably use drawn map mode to draw maps with scripts.
A simple example is given below. Note that Drawn maps use an area of 4096x2048. The examples below are static, but obviously this could be used for a random map variation - for example, simulating the Cave map by doing the fill below, then drawing random tunnels using circles that shift their course smoothly.
First, a couple of convenience functions for drawing to the map.
PointsBuffer = '' -- A string to accumulate points in
function AddPoint(x, y, width, erase)
PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff))
if width then
width = bor(width,0x80)
if erase then
width = bor(width,0x40)
PointsBuffer = PointsBuffer .. string.char(width)
PointsBuffer = PointsBuffer .. string.char(0)
if #PointsBuffer > 245 then
PointsBuffer = ''
if #PointsBuffer > 0 then
PointsBuffer = ''
takes an x and y location for the point, a width (indicates the start of a new line) and erase (whether the line is erasing from the map). The width calculation is described in DrawnMapFormat
FlushPoints? writes out any values from PointsBuffer? that have not already been sent to the engine.
It would be called at the end of a drawing session.
A simple example below.
MapGen = 2
TemplateFilter = 0
for i = 63,2,-4 do
for i = 1,2000,50 do
The first set of AddPoints? draws a large X and erases the centre.
The following loop draws a set of nested points, alternating erasure and fill, which results in a set of concentric circles.
The 2nd loop draws a web of lines and frames it using some final AddPoints.
Another brief example.
for i = 200,2000,600 do
for i = 500,3500,1000 do
This one fills the map with solid land, and draws 4 circular erased points in it.