author kyberneticist@gmail.com Fri, 19 Oct 2012 20:58:54 +0000 changeset 254 a21261c77793 parent 253 d7db074d6efa child 255 18e1a94e1591
Created wiki page through web user interface.
 LuaDrawing.wiki file | annotate | diff | comparison | revisions
```--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LuaDrawing.wiki	Fri Oct 19 20:58:54 2012 +0000
@@ -0,0 +1,72 @@
+#summary Drawing maps with Lua.
+
+= Drawing Maps With Lua =
+
+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
+
+= Details =
+
+First, a couple of convenience functions for drawing to the map.
+<code lang="lua">
+PointsBuffer = ''  -- A string to accumulate points in
+function AddPoint(x, y, new, size, erase)
+    PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff))
+    if new then
+		size = bor(size,0x80)
+        if erase then
+			size = bor(size,0x40)
+		end
+		PointsBuffer = PointsBuffer .. string.char(size)
+	else
+		PointsBuffer = PointsBuffer .. string.char(0)
+    end
+    if #PointsBuffer > 245 then
+		ParseCommand('draw '..PointsBuffer)
+        PointsBuffer = ''
+	end
+end
+function FlushPoints()
+    if #PointsBuffer > 0 then
+		ParseCommand('draw '..PointsBuffer)
+        PointsBuffer = ''
+    end
+end
+</code>
+AddPoint takes an x and y location for the point, 2 booleans: new (start of a line or not), erase (whether the line is erasing from the map) and size (size of the line - a value from 1 to 63)
+FlushPoints writes out any values from PointsBuffer that had not already been sent to the engine.  It would be called at the end of a drawing session.
+
+A simple example below.
+
+<code lang="lua">
+function onGameInit()
+	MapGen = 2
+	TemplateFilter = 0
+
+
+    for i = 63,2,-4 do
+    end
+
+    for i = 1,2000,50 do
+    end
+