/[enigma]/enigma/doc/ant_lua.txt
ViewVC logotype

Diff of /enigma/doc/ant_lua.txt

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by ant_39, Sun Apr 13 15:00:40 2003 UTC revision 1.2 by ant_39, Fri Apr 25 16:29:30 2003 UTC
# Line 12  functions for Enigma map designers. Line 12  functions for Enigma map designers.
12  0.1 Revision history  0.1 Revision history
13  --------------------------------------------------------------------------------  --------------------------------------------------------------------------------
14    
15    version 0.1.1: 2003-04-25:
16      Number of typos fixed
17    
18  version 0.1: 2003-04-13:  version 0.1: 2003-04-13:
19    this covers ant.lua for upcoming Enigma 0.8    this covers ant.lua for upcoming Enigma 0.8
20    first release of document    first release of document
21    
22  0.3 Table of contents  
23    0.2 Table of contents
24  --------------------------------------------------------------------------------  --------------------------------------------------------------------------------
25    
26  0] PREFACE  0] PREFACE
# Line 115  This document tris to uncover hidden tre Line 119  This document tris to uncover hidden tre
119  of helper functions for Enigma level designers. If one level is  of helper functions for Enigma level designers. If one level is
120  created with help of this, I reached my goal.  created with help of this, I reached my goal.
121    
122  Please, no great expectation. I'm not very experienced in english and  Please, no great expectations. I'm not very experienced in English and
123  I have never written such a document before. I did my best, but you  I have never written such a document before. I did my best, but you
124  know how it is.  know how it is...
125    
126    
127  1.2 How to contact author  1.2 How to contact author
# Line 157  terms: Line 161  terms:
161  1.4 New versions of this document  1.4 New versions of this document
162  --------------------------------------------------------------------------------  --------------------------------------------------------------------------------
163    
164  Most probably, any new version will be located at Enigma CVS  Most probably, any new version will be located directly at Enigma CVS
165  repository. If it isn't there, ant.lua was probably discarded from  repository. If it isn't there, ant.lua was probably discarded from
166  source tree either, and so the documentation is obsolete.  source tree either, and so the documentation is obsolete.
167    
# Line 169  There are several things missing in the Line 173  There are several things missing in the
173  complete reference of ant.lua, though I'm not very sure whether  complete reference of ant.lua, though I'm not very sure whether
174  ant.lua itself is not better source.  ant.lua itself is not better source.
175    
176  Not all examples were tested. I often rely on the knowledge, so if  Not all examples were tested. I often rely on my knowledge, so if
177  something doesn't work, the bug doesn't have to be in library.  something doesn't work, the bug doesn't have to be in library.
178    
179  Besides this, the document should be completely rewritten by someone  Besides this, the document should be completely rewritten by someone
180  better in english. This is utopia, so we simply have to get enough  better in English. This is utopia, so we simply have to get enough
181  with this.  with this.
182    
183    
184    
185  ================================================================================  ================================================================================
186  2] ABOUT ant.lua  2] ABOUT ant.lua
187  ================================================================================  ================================================================================
# Line 193  programming language. This tool made it Line 198  programming language. This tool made it
198    
199  It's possible that the editor will make this module useless, so  It's possible that the editor will make this module useless, so
200  further development will stop. It will probably stay in enigma source  further development will stop. It will probably stay in enigma source
201  repository in future, as many maps and aslo some other libraries  repository in future, as many maps and also some other libraries
202  (ralf.lua for example) use it.  (ralf.lua for example) use it.
203    
204    
# Line 203  repository in future, as many maps and a Line 208  repository in future, as many maps and a
208  Well, for creating enigma maps.  Well, for creating enigma maps.
209    
210  Now seriously. Basic idea behind creating maps to enigma is that you  Now seriously. Basic idea behind creating maps to enigma is that you
211  use a function everytime you want to place a stone, everytime you  use a function every time you want to place a stone, every time you
212  place a floor square, etc. You draw the level procedurally, use  place a floor square, etc. You draw the level procedurally, use
213  functions for filling, distribute items, stones, floors, actors,  functions for filling, distribute items, stones, floors, actors,
214  etc. There are loops, well known from programming languages (while,  etc. There are loops, well known from programming languages (while,
# Line 264  Using ant.lua, the code turns to look th Line 269  Using ant.lua, the code turns to look th
269    
270        level = {        level = {
271           "~##################*",           "~##################*",
272           "#                  #",           "#                  #",
273           "#                  #",           "#                  #",
274           "#  0            0  #",           "#  0            0  #",
275           "#                  #",           "#                  #",
276           "#                  #",           "#                  #",
277           "#         O        #",           "#         O        #",
278           "#                  #",           "#                  #",
279           "#                  #",           "#                  #",
280           "#  0            0  #",           "#  0            0  #",
281           "#                  #",           "#                  #",
282           "#                  #",           "#                  #",
283           "####################"           "####################"
284        }        }
285    
286        oxyd_default_flavor = "a"        oxyd_default_flavor = "a"
# Line 439  leaves, like here: Line 444  leaves, like here:
444    
445        level = {        level = {
446           "####################",           "####################",
447           "#....     x    ....#",           "#....     x    ....#",
448           "#XXXXxxxxxx    ....#",           "#XXXXxxxxxx    ....#",
449           "#....    xxxxxxXXXX#",           "#....    xxxxxxXXXX#",
450           "#....    x     ....#",           "#....    x     ....#",
451           "####################"           "####################"
452        }        }
453    
454  Hierarchy:  Hierarchy:
455    
456          cells[" "]  \          cells[" "]  \
457                       > -> cells["x"]                       > -> cells["x"]
458          cells["g"]  <          cells["g"]  <
459                       > -> cells["X"]                       > -> cells["X"]
460          cells["."]  /          cells["."]  /
461    
462  You can create a way more complicated trees. You may not create  You can create a way more complicated trees. You may not create
463  circular inheritance (A has parent B, whereas B has parent A). LUA  circular inheritance (A has parent B, whereas B has parent A). LUA
# Line 465  stack overflows) Line 470  stack overflows)
470  In fact, parent function may be any function that accepts x and y as  In fact, parent function may be any function that accepts x and y as
471  it's first two arguments. For example:  it's first two arguments. For example:
472    
473           function pr(x,y)           function pr(x,y)
474              print(x, y)              print(x, y)
475           end           end
476    
477           ... some LUA code ...           ... some LUA code ...
478    
479           cells["w"] = cell{parent={pr, cells["p"]}}           cells["w"] = cell{parent={pr, cells["p"]}}
480    
481  This code writes x and y coordinates of element "w" for each place  This code writes x and y coordinates of element "w" for each place
482  where element is located. This example itself is good for nothing,  where element is located. This example itself is good for nothing,
# Line 591  again to the welcome.lua example: Line 596  again to the welcome.lua example:
596    
597        level = {        level = {
598           "~##################*",           "~##################*",
599           "#                  #",           "#                  #",
600           "#                  #",           "#                  #",
601           "#  0            0  #",           "#  0            0  #",
602           "#                  #",           "#                  #",
603           "#                  #",           "#                  #",
604           "#         O        #",           "#         O        #",
605           "#                  #",           "#                  #",
606           "#                  #",           "#                  #",
607           "#  0            0  #",           "#  0            0  #",
608           "#                  #",           "#                  #",
609           "#                  #",           "#                  #",
610           "####################"           "####################"
611        }        }
612    
613  The cells '0' and 'O' are not declared at all, still they may be used  The cells '0' and 'O' are not declared at all, still they may be used
# Line 633  white marble for the level to be finishe Line 638  white marble for the level to be finishe
638  Another modes and their bindings:  Another modes and their bindings:
639    
640        multiplayer_mode()        multiplayer_mode()
641          '1' stands for black marble          '1' stands for black marble
642          '2' stands for white marble          '2' stands for white marble
643          each of these marbles gets an it-yinyang automatically, so that          each of these marbles gets an it-yinyang automatically, so that
644          the player can switch between the marbles. Letter 'O' has still          the player can switch between the marbles. Letter 'O' has still
645          its meaning of black marble without a yinyang item.          its meaning of black marble without a yinyang item.
646    
647        grass_mode()        grass_mode()
648          '#' stands for "st-rock1"          '#' stands for "st-rock1"
649          ' ' stands for "fl-leaves"          ' ' stands for "fl-leaves"
650    
651        metal_mode()        metal_mode()
652          '#' stands for "st-rock2"          '#' stands for "st-rock2"
653          ' ' stands for "fl-metal"          ' ' stands for "fl-metal"
654    
655  It's alike that more modes are to come in future.  It's alike that more modes are to come in future.
656    
# Line 714  write this, as 'cells' is being looked f Line 719  write this, as 'cells' is being looked f
719  The only tricky thing to avoid is default parent - you may not use  The only tricky thing to avoid is default parent - you may not use
720  default parents in layered maps, or, the default parent may not change  default parents in layered maps, or, the default parent may not change
721  map itself. Imagine sand floor for the default parent. You let ant.lua  map itself. Imagine sand floor for the default parent. You let ant.lua
722  draw floors, and it's ok. Then you let draw stones, and all floors are  draw floors, and it's OK. Then you let draw stones, and all floors are
723  overriden by default parent. Beware.  overridden by default parent. Beware.
724    
725    
726  3.2.4 Drawing per partes  3.2.4 Drawing per partes
# Line 744  Now we'll look on those functions briefl Line 749  Now we'll look on those functions briefl
749      key:    the cell key, like in string map      key:    the cell key, like in string map
750      cellfuncs: table of cell functions, may be omit      cellfuncs: table of cell functions, may be omit
751      *example: render_key(5,15, '#')      *example: render_key(5,15, '#')
752                render_key(5,15, ' ', cells)                render_key(5,15, ' ', cells)
753    
754    get_cell_by_xy: get a key at given map location    get_cell_by_xy: get a key at given map location
755      mx, my: coordinates of key at map      mx, my: coordinates of key at map
# Line 810  width of 2, strings in map simply cannot Line 815  width of 2, strings in map simply cannot
815    
816        level = {        level = {
817           "~~####################################**",           "~~####################################**",
818           "##                                    ##",           "##                                    ##",
819           "##                                    ##",           "##                                    ##",
820           "##    00                        00    ##",           "##    00                        00    ##",
821           "##                                    ##",           "##                                    ##",
822           "##                                    ##",           "##                                    ##",
823           "##                  OO                ##",           "##                  OO                ##",
824           "##                                    ##",           "##                                    ##",
825           "##                                    ##",           "##                                    ##",
826           "##    00                        00    ##",           "##    00                        00    ##",
827           "##                                    ##",           "##                                    ##",
828           "##                                    ##",           "##                                    ##",
829           "########################################"           "########################################"
830        }        }
831    
832        oxyd_default_flavor = "a"        oxyd_default_flavor = "a"
# Line 830  width of 2, strings in map simply cannot Line 835  width of 2, strings in map simply cannot
835        create_world_by_map(level)        create_world_by_map(level)
836        oxyd_shuffle()        oxyd_shuffle()
837    
 You see, there are a few issues with multichar maps. There are no  
 default meanings, for example, so that you have to map the keys  
 manually. Plus, you have to pick correct cell_key_width, but this  
 should not be the problem.  
   
 On the other side, the map looks a lot better - the ratio of its sides  
 is a way more similar to the ratio of Enigma's playing screen.  
   
838  How are default cell meanings parsed in case of multichar maps? Well,  How are default cell meanings parsed in case of multichar maps? Well,
839  there may be some default meanings, but it's not alike. However, the  there may be some default meanings, but it's not alike. However, the
840  engine tries. It it doesn't find any meaning among both common cell  engine tries. It it doesn't find any meaning among both common cell
# Line 865  to be no problem, but... Line 862  to be no problem, but...
862    
863  Well, it generally is not a problem in procedural way of map design.  Well, it generally is not a problem in procedural way of map design.
864  But if you have to draw the checkerboard into string map, you soon  But if you have to draw the checkerboard into string map, you soon
865  find out terrible truth.  find out terrible truth. It's boring and map looks messy.
866    
867  I tried, too. And this experience made me to create a machanism to  I tried, too. And this experience made me to create a mechanism to
868  draw checkerboard floors. This mechanism may be happily used also to  draw checkerboard floors. This mechanism may be happily used also to
869  create checkerboard stones or anything, but most common it's used for  create checkerboard stones or anything, but most common it's used for
870  creating floors.  creating floors, thus its name.
871    
872  Syntax is as follows:  Syntax is as follows:
873    
# Line 888  write something like this: Line 885  write something like this:
885  and it is the same.  and it is the same.
886    
887  By default, a grid of 1x1 square is done, checkerboard squares have  By default, a grid of 1x1 square is done, checkerboard squares have
888  got the size of one precious Enigma world stone. There are arguments,  the size of one precious Enigma world stone. There are arguments, that
889  that change this:  change this:
890    
891        sahara=     cell{floor="fl-sahara"}        sahara=     cell{floor="fl-sahara"}
892        tigris=     cell{floor="fl-tigris"}        tigris=     cell{floor="fl-tigris"}
# Line 900  squares takes up area of four stones: 2x Line 897  squares takes up area of four stones: 2x
897    
898  Argument 'offset' does exactly what it sounds like: it 'shifts' the  Argument 'offset' does exactly what it sounds like: it 'shifts' the
899  grid. By default, left top corner of first square of checkerboard is  grid. By default, left top corner of first square of checkerboard is
900  exactly at left top corner of world (square coordinates [0,0]). Offset  aligned with left top corner of world (square coordinates [0,0]).
901  of 1 moves it to the square [1,1].  Offset of 1 moves it to the square [1,1].
902    
903  Also you can create assymetric constructions. You may specify also  Also you can create asymmetric constructions. You may specify also
904  these attributes:  these attributes:
905    
906        sidex: to specify width of squares        sidex: to specify width of squares
# Line 920  upon a time and creating such a floor by Line 917  upon a time and creating such a floor by
917  very random as one wishes. That was the reason behind creating random  very random as one wishes. That was the reason behind creating random
918  floor parent.  floor parent.
919    
920  Just like the checkerfloor, also this parent may be used to construct  Just like the checker floor, also this parent may be used to construct
921  anything random. Random stones, random items, you choose.  anything random. Random stones, random items, you choose.
922    
923  Random floor is constructed like in this example:  Random floor is constructed like in this example:
# Line 929  Random floor is constructed like in this Line 926  Random floor is constructed like in this
926        invert = cell{floor="fl-inverse"}        invert = cell{floor="fl-inverse"}
927        tiles  = cell{{{randomfloor, {normal, invert}}}}        tiles  = cell{{{randomfloor, {normal, invert}}}}
928    
929  You see, the syntax is very similar to that used in checkerfloor  You see, the syntax is very similar to that used in checker floor
930  parent. Soon, you will see this is no coincidence.  parent. Soon, you will see this is no coincidence.
931    
932  You can declare as many random elements as you want:  You can declare as many random elements as you want:
# Line 941  You can declare as many random elements Line 938  You can declare as many random elements
938        tiles  = cell{{{randomfloor, {normal, invert, sahara, tigris}}}}        tiles  = cell{{{randomfloor, {normal, invert, sahara, tigris}}}}
939    
940  Great, you think. What if I want one item to occur more often? The  Great, you think. What if I want one item to occur more often? The
941  answer is item occurence factor. Each item may be followed by a  answer is item occurrence factor. Each item may be followed by a
942  number, which declares how often the tile will occur compared to  number, which declares how often the tile will occur compared to
943  others. If you omit the number (like in above examples), factor of 1  others. If you omit the number (like in above examples), factor of 1
944  is default. See the example:  is default. See the example:
# Line 958  often than samba floor. Tigris floor wil Line 955  often than samba floor. Tigris floor wil
955  approximately three times more than samba.  approximately three times more than samba.
956    
957  A function 'random' is used to pick random number. Result of the  A function 'random' is used to pick random number. Result of the
958  function may be modified by the function randomseed, which initiates  function may be modified by the function 'randomseed', which initiates
959  random seed generator:  random seed generator:
960    
961        randomseed(666) -- evil landscape        randomseed(666) -- a truly evil landscape
962          randomseed(date"%d%H%M%S") -- 'real' randomness
963    
964    
965  3.3.3 Curried function construction  3.3.3 Curried function construction
# Line 1024  leading 'parent=', you'll get to triple- Line 1022  leading 'parent=', you'll get to triple-
1022  common in maps with ant.lua:  common in maps with ant.lua:
1023    
1024        function pr(x,y, greet, name)        function pr(x,y, greet, name)
1025           print(greet..", "..name.." from ["..x..","..y.."]!")           print(greet..", "..name.." from ["..x..","..y.."]!")
1026        end        end
1027    
1028        hallo = cell{{{pr, "Hallo", "world"}}}        hallo = cell{{{pr, "Hallo", "world"}}}
# Line 1034  common in maps with ant.lua: Line 1032  common in maps with ant.lua:
1032  This code chunk will produce: "Hallo, world from [2,3]!"  This code chunk will produce: "Hallo, world from [2,3]!"
1033    
1034  Still not at the end. This construction lets you create so called  Still not at the end. This construction lets you create so called
1035  curried constructions. Curried functions are used in some programing  curried constructions. Curried functions are used in some programming
1036  languages (Haskell for example). What ant.lua provides is far from  languages (Haskell for example). What ant.lua provides is far from
1037  curried functions known from such a languages, but it's somehow  curried functions known from such a languages, but it's somehow
1038  similar. Look at this to see what's going on:  similar. Look at this to see what's going on:
# Line 1051  similar. Look at this to see what's goin Line 1049  similar. Look at this to see what's goin
1049  Of course, all these function calls produce the same output.  Of course, all these function calls produce the same output.
1050    
1051  Curried function calls are rather common in maps that use ant.lua.  Curried function calls are rather common in maps that use ant.lua.
1052  Later on we'll tke a look at 'object multiples' - this thing is  Later on we'll take a look at 'object multiples' - this thing is
1053  completely build on top of curried function call. And high-end  completely build on top of curried function call. And high-end things
1054  thingies like railway generator, puzzle generator or slope generator  like railway generator, puzzle generator or slope generator stand on
1055  stand on the shoulders of object groups. It could be said that most  the shoulders of object groups. It could be said that most features of
1056  features of ant.lua use curried call.  ant.lua use curried call.
1057    
1058    
1059  ================================================================================  ================================================================================
# Line 1066  features of ant.lua use curried call. Line 1064  features of ant.lua use curried call.
1064  --------------------------------------------------------------------------------  --------------------------------------------------------------------------------
1065    
1066  There are several functions for drawing Enigma maps in init.lua. Most  There are several functions for drawing Enigma maps in init.lua. Most
1067  of them (ifnot all) have their counterparts in ant.lua. The difference  of them (if not all) have their counterparts in ant.lua. The difference
1068  is, that init.lua functions work with stone/floor/item names, but  is, that init.lua functions work with stone/floor/item names, but
1069  ant.lua function works with functions.  ant.lua function works with functions.
1070    
# Line 1106  can happily use them: Line 1104  can happily use them:
1104        draw_border_func(stone0)        draw_border_func(stone0)
1105        actor0(5,5)        actor0(5,5)
1106    
1107  And we are done. Note that if you haven't got a stringmap, you must  And we are done. Note that if you haven't got a string map, you must
1108  use common function create_world(w,h).  use common function create_world(w,h).
1109    
1110  How to fill/border/cornerify just a given portion of map? Well, use  How to fill/border/cornerify just a given portion of map? Well, use
# Line 1193  function for each cell: Line 1191  function for each cell:
1191    
1192        draw_func({floor0, stone0}, {0,0}, {0,1}, 10)        draw_func({floor0, stone0}, {0,0}, {0,1}, 10)
1193    
1194  Last function of this subchapter is 'ngon' drawing function. It's  Last function of this sub-chapter is 'ngon' drawing function. It's
1195  particularly useful for placing several actors to circular/  particularly useful for placing several actors to circular/
1196  triangular/ pentagonal/ any other polygonal settings. Basic syntax  triangular/ pentagonal/ any other polygonal settings. Basic syntax
1197  follows:  follows:
# Line 1245  But I have no idea what would this be go Line 1243  But I have no idea what would this be go
1243  Very impressive feature of whole cell{} function mechanism is, that it  Very impressive feature of whole cell{} function mechanism is, that it
1244  provides a way to transform a coordinates automatically for you. Maybe  provides a way to transform a coordinates automatically for you. Maybe
1245  you know the problem with placing the items to lower and right edges  you know the problem with placing the items to lower and right edges
1246  of map - one never knows what exactly to substract from level_width to  of map - one never knows what exactly to subtract from level_width to
1247  get the right value.  get the right value.
1248    
1249  Look at the piece of code from the welcome-map example:  Look at the piece of code from the welcome-map example:
# Line 1328  command. Let's look at some real-world e Line 1326  command. Let's look at some real-world e
1326        add_rubber_bands(actors, stones, -10, 4)        add_rubber_bands(actors, stones, -10, 4)
1327    
1328  That's all. No matter how much actors are there, no matter how much  That's all. No matter how much actors are there, no matter how much
1329  stones are they to be bound to. We'll talk about rubberbands more  stones are they to be bound to. We'll talk about rubber bands more
1330  later. Now, as you got the idea what is iot good for, let's move on.  later. Now, as you got the idea what is it good for, let's move on.
1331    
1332    
1333  5.2 Common multiples  5.2 Common multiples
# Line 1349  Basic difference between them is obvious Line 1347  Basic difference between them is obvious
1347    
1348  Step one when creating a multiple is to define a group. It's usual to  Step one when creating a multiple is to define a group. It's usual to
1349  store the object to logical groups - doors that should open at once  store the object to logical groups - doors that should open at once
1350  have to be in one group, actors to be bound by rubberbands have to be  have to be in one group, actors to be bound by rubber bands have to be
1351  in another. To define a group, do this:  in another. To define a group, do this:
1352    
1353        group = {}        group = {}
# Line 1447  single actor in a 'actors' group, poor a Line 1445  single actor in a 'actors' group, poor a
1445  bolders. And finally, if there is a single actor and a single bolder,  bolders. And finally, if there is a single actor and a single bolder,
1446  they are simply bound together.  they are simply bound together.
1447    
1448  Another useful constructio is to create a rubber band pairs. This  Another useful construction is to create a rubber band pairs. This
1449  time, you really need two different groups. First object from first  time, you really need two different groups. First object from first
1450  group is then bound with first object from second group, second from  group is then bound with first object from second group, second from
1451  first group with second from second group, and so on:  first group with second from second group, and so on:
# Line 1479  completely. Line 1477  completely.
1477  Besides multielements representing Enigma game objects, there are  Besides multielements representing Enigma game objects, there are
1478  several so-called generic multielements. Those usually cannot accept  several so-called generic multielements. Those usually cannot accept
1479  multimessages, nor can their attributes be changed by  multimessages, nor can their attributes be changed by
1480  chage_group_attribs. These multielemts are used in special ant.lua  change_group_attribs. These multielements are used in special ant.lua
1481  utilities - train-, wormhole- and slope-generator.  utilities - train-, wormhole- and slope-generator.
1482    
1483  Everything that was said about common multielements is true for  Everything that was said about common multielements is true for
1484  generic multielements, too. They are stored in a table, that has to be  generic multielements, too. They are stored in a table, that has to be
1485  declared, do the basic construction looks like this:  declared, so the basic construction looks like this:
1486    
1487        group={}        group={}
1488        cells["!"]=cell{{{add_*, group, ...}}}        cells["!"]=cell{{{add_*, group, ...}}}
# Line 1512  Each multicell element holds three value Line 1510  Each multicell element holds three value
1510        cells["*"]=cell{{{add_multicell, slopes, -1}}}        cells["*"]=cell{{{add_multicell, slopes, -1}}}
1511    
1512  This example will add an element to the 'slopes' table for each  This example will add an element to the 'slopes' table for each
1513  asterisk in your stringmap. Every such element will be tagged to -1.  asterisk in your string map. Every such element will be tagged to -1.
1514    
1515  add_multicell element is the most widely used one.  add_multicell element is the most widely used one.
1516    
# Line 1556  nature. Line 1554  nature.
1554    
1555        function add_multitag(x, y, group, tag, func)        function add_multitag(x, y, group, tag, func)
1556    
1557  add_multitag can store several elements under one tagnumber (or  add_multitag can store several elements under one tag number (or
1558  tagstring, if you pass string for a tag). Structure of a constructed  tag-string, if you pass string for a tag). Structure of a constructed
1559  table may look like this:  table may look like this:
1560    
1561        group={        group={
# Line 1567  table may look like this: Line 1565  table may look like this:
1565    
1566  So, the idea is to store under each tag number a list of coordinates -  So, the idea is to store under each tag number a list of coordinates -
1567  thus effectively grouping several groups together. As a bonus, each  thus effectively grouping several groups together. As a bonus, each
1568  element can have a tagnumber of its own, which may look like this:  element can have a tag number of its own, which may look like this:
1569    
1570        group={        group={
1571          [1]={{5,7,"yet"},{6,7,"another"},{7,7,"boring"},{9,15,"multiple"}}          [1]={{5,7,"yet"},{6,7,"another"},{7,7,"boring"},{9,15,"multiple"}}
# Line 1618  worm hole has to be fed up with coordina Line 1616  worm hole has to be fed up with coordina
1616    
1617  The work of wormhole generator stands on top of object groups. You  The work of wormhole generator stands on top of object groups. You
1618  feed the generator with a table of worm hole items and a table of worm  feed the generator with a table of worm hole items and a table of worm
1619  hole targets, and it puts them into pairs and create apropriate items  hole targets, and it puts them into pairs and create appropriate items
1620  with the right attributes.  Both the worm holes and their targets are  with the right attributes.  Both the worm holes and their targets are
1621  special table of multicells.  special table of multicells.
1622    
# Line 1644  called 'worm_hole_pair': Line 1642  called 'worm_hole_pair':
1642        worm_hole_pair(cellfuncs, whole_cell, tgt_cell, whole_parent, tgt_parent, whole_grp, tgt_grp, tagnumber)        worm_hole_pair(cellfuncs, whole_cell, tgt_cell, whole_parent, tgt_parent, whole_grp, tgt_grp, tagnumber)
1643    
1644  * cellfuncs is a table of cell functions (usually cells[])  * cellfuncs is a table of cell functions (usually cells[])
1645  * whole_cell is a letter that will stand for worm hole on stringmap  * whole_cell is a letter that will stand for worm hole on string map
1646  * tgt_cell is a letter that will stand for a worm hole target  * tgt_cell is a letter that will stand for a worm hole target
1647  * whole_parent is a function to be used as a parent of worm hole cell  * whole_parent is a function to be used as a parent of worm hole cell
1648  * tgt_parent is a function to be used as a parent of worm hole target  * tgt_parent is a function to be used as a parent of worm hole target
# Line 1658  For example, the setting might look this Line 1656  For example, the setting might look this
1656        worm_hole_pair(cells, "B", "b", cells["_"], cells["_"], holes, targets, 2)        worm_hole_pair(cells, "B", "b", cells["_"], cells["_"], holes, targets, 2)
1657        worm_hole_pair(cells, "C", "c", cells["_"], cells["_"], holes, targets, 3)        worm_hole_pair(cells, "C", "c", cells["_"], cells["_"], holes, targets, 3)
1658    
1659  If you need some special fine-tunning, you can write the same this way  If you need some special fine-tuning, you can write the same this way
1660  (in the example, there is a "A"-"a" pair defined):  (in the example, there is a "A"-"a" pair defined):
1661    
1662        cellfuncs["A"] = cell{{cells["_"], {add_multicell, holes,   1}}}        cellfuncs["A"] = cell{{cells["_"], {add_multicell, holes,   1}}}
# Line 1669  If you need some special fine-tunning, y Line 1667  If you need some special fine-tunning, y
1667  ........................  ........................
1668    
1669  In map, you simply place the whole-letters and wtarget-letters to  In map, you simply place the whole-letters and wtarget-letters to
1670  their places, so that they represent desired actor huperjumps.  their places, so that they represent desired actor hyper-jumps.
1671    
1672        level = {        level = {
1673           "###################",           "###################",
1674           "#A       #       a#",           "#A       #       a#",
1675           "#        #        #",           "#        #        #",
1676           "#        #        #",           "#        #        #",
1677           "#b       #       B#",           "#b       #       B#",
1678           "###################"           "###################"
1679        }        }
1680    
1681    
# Line 1685  their places, so that they represent des Line 1683  their places, so that they represent des
1683  .........................  .........................
1684    
1685  When map is drawn, the mission doesn't end yet. You now have the  When map is drawn, the mission doesn't end yet. You now have the
1686  holes{} and targets{} tables filled with reasonable infomations. Now,  holes{} and targets{} tables filled with reasonable informations. Now,
1687  the worm hole generator can transform it to worm holes for you:  the worm hole generator can transform it to worm holes for you:
1688    
1689        create_world_by_map(level)        create_world_by_map(level)
# Line 1786  they gain much power, but this drawbacks Line 1784  they gain much power, but this drawbacks
1784  to four times slower than init.lua functions). Both 'construct' and  to four times slower than init.lua functions). Both 'construct' and
1785  'destruct' functions are called repeatedly each tick, for each move  'destruct' functions are called repeatedly each tick, for each move
1786  the train does. The faster they are, the better. In my opinion, it's  the train does. The faster they are, the better. In my opinion, it's
1787  better to create hardcore functions that do the dirty work fast  better to create hard-core functions that do the dirty work fast
1788  enough:  enough:
1789    
1790        function construct(x, y) set_floor("fl-normal", x, y) end        function construct(x, y) set_floor("fl-normal", x, y) end
# Line 1822  Ready. Now just draw the map and you are Line 1820  Ready. Now just draw the map and you are
1820  5.5.5 Setting up the map  5.5.5 Setting up the map
1821  ........................  ........................
1822    
1823  In your stringmap, the path will be denoted by exclamation marks, the  In your string map, the path will be denoted by exclamation marks, the
1824  train by underscores, locomotives by 'c' and last wagons by 'd'. Don't  train by underscores, locomotives by 'c' and last wagons by 'd'. Don't
1825  forget to add a timer stone '~' to make your train move!  forget to add a timer stone '~' to make your train move!
1826    
# Line 1830  Result map could look this way: Line 1828  Result map could look this way:
1828    
1829        level = {        level = {
1830           "####################",           "####################",
1831           "#!!!!!!!  !!c___d!!#",           "#!!!!!!!  !!c___d!!#",
1832           "#!     !!!!       !#",           "#!     !!!!       !#",
1833           "#!!!!!         !!!!#",           "#!!!!!         !!!!#",
1834           "#    !!!!!!!!!!!   #",           "#    !!!!!!!!!!!   #",
1835           "###################~"           "###################~"
1836        }        }
1837    
1838  And that is all. Congratulations, your map just got a train.  And that is all. Congratulations, your map just got a train.
# Line 1897  Now draw the string map: Line 1895  Now draw the string map:
1895    
1896        level = {        level = {
1897           "####################",           "####################",
1898           "#                  #",           "#                  #",
1899           "#  ***   ***       #",           "#  ***   ***       #",
1900           "#  * ***** *       #",           "#  * ***** *       #",
1901           "#***       ***     #",           "#***       ***     #",
1902           "####################"           "####################"
1903        }        }
1904    
1905  And draw it:  And draw it:
# Line 1943  should be one. Line 1941  should be one.
1941    
1942  Slopes are Enigma construction that pushes the actor to move in one  Slopes are Enigma construction that pushes the actor to move in one
1943  direction. It's gradiented floor. Gradients can create really big  direction. It's gradiented floor. Gradients can create really big
1944  constructions, beveled areas, both sunken and rised.  constructions, beveled areas, both sunken and raised.
1945    
1946  With slopes, its very similar to puzzles. Both the fact, that  With slopes, its very similar to puzzles. Both the fact, that
1947  declaring cellfuncstions is boring, and the way the slopes are  declaring cell functions is boring, and the way the slopes are
1948  generated.  generated.
1949    
1950    
# Line 1954  generated. Line 1952  generated.
1952  ..........................  ..........................
1953    
1954  Slope generator can create a wide variety of slope settings, but some  Slope generator can create a wide variety of slope settings, but some
1955  things it's really unsuitable to do. It has no inteligence, it's just  things it's really unsuitable to do. It has no intelligence, it's just
1956  automaton that reads input data and based on them it decides what kind  automaton that reads input data and based on them it decides what kind
1957  of slope will be on this or that place.  of slope will be on this or that place.
1958    
# Line 1966  for this situation, than to add another Line 1964  for this situation, than to add another
1964  database. Most of the time, the patterns match just well and slopes  database. Most of the time, the patterns match just well and slopes
1965  are happily (and correctly) generated.  are happily (and correctly) generated.
1966    
1967  Next thing is setting up where is the centre of desired shape. The  Next thing is setting up where is the center of desired shape. The
1968  program needs to know how to shape slopes, whether "up-donw" or  program needs to know how to shape slopes, whether "up-down" or
1969  "down-up". The point that declares where is the "upside" of sloped  "down-up". The point that declares where is the "upside" of sloped
1970  shape is called 'pivot'.  shape is called 'pivot'.
1971    
# Line 2000  Next, cell functions are created: Line 1998  Next, cell functions are created:
1998        cells["*"]=cell{{{add_multicell, slopes, 1}}}        cells["*"]=cell{{{add_multicell, slopes, 1}}}
1999        cells["&"]=cell{{{add_multicell, pivots, slopes}, cells[" "]}}        cells["&"]=cell{{{add_multicell, pivots, slopes}, cells[" "]}}
2000    
2001  You see, add_multicell is udes once more. Tag '1' has meaning of 'here  You see, add_multicell is used once more. Tag '1' has meaning of 'here
2002  be the slope'. Cell '&' is tagged by the slopes table. This way the  be the slope'. Cell '&' is tagged by the slopes table. This way the
2003  pivots are bound to slopes, so that it is possible to lay several  pivots are bound to slopes, so that it is possible to lay several
2004  concentric slope shapes.  concentric slope shapes.
# Line 2019  occur. Line 2017  occur.
2017    
2018        level = {        level = {
2019           "####################",           "####################",
2020           "#  **************  #",           "#  **************  #",
2021           "#  *&           *  #",           "#  *&           *  #",
2022           "#  *            *  #",           "#  *            *  #",
2023           "#  **************  #",           "#  **************  #",
2024           "####################"           "####################"
2025        }        }
2026    
2027    
# Line 2068  You have to reflect this in your map: Line 2066  You have to reflect this in your map:
2066    
2067        level = {        level = {
2068           "####################",           "####################",
2069           "#  **********      #",           "#  **********      #",
2070           "#  *@@@@@@@@^@@@   #",           "#  *@@@@@@@@^@@@   #",
2071           "#  *@&%     *  @   #",           "#  *@&%     *  @   #",
2072           "#  *@       *  @   #",           "#  *@       *  @   #",
2073           "#  *@@@@@@@@^@@@   #",           "#  *@@@@@@@@^@@@   #",
2074           "#  **********      #",           "#  **********      #",
2075           "####################"           "####################"
2076        }        }
2077    
2078  In fact this doesn't look very nice, as one slope just overrides  In fact this doesn't look very nice, as one slope just overrides
# Line 2094  slopes are tagged by the number '2': Line 2092  slopes are tagged by the number '2':
2092  5.7.8 Invert slopes  5.7.8 Invert slopes
2093  ...................  ...................
2094    
2095  If you want to create a slope that renders invertly (southwest instead  If you want to create inverted-slope (southwest instead of northeast
2096  of northeast and so on), tag it with a number -1:  and so on), tag it with a number -1:
2097    
2098        cells["+"]=cell{{{add_multicell, slopes, -1}}}        cells["+"]=cell{{{add_multicell, slopes, -1}}}
2099    
# Line 2107  argument in 'render_slopes' function: Line 2105  argument in 'render_slopes' function:
2105  In fact, you can pass anything non-nil as invert argument, and whole  In fact, you can pass anything non-nil as invert argument, and whole
2106  boundary gets inverted. If there are invert cells in boundary, the are  boundary gets inverted. If there are invert cells in boundary, the are
2107  drawn 'normally' - that is, double inversion results to original  drawn 'normally' - that is, double inversion results to original
2108  state, like in de Morgan's.  state, like in De Morgan's.
2109    
2110    
2111  5.8 Afterwords  5.8 Afterwords
# Line 2121  creating engine with slope in center, th Line 2119  creating engine with slope in center, th
2119  you don't need the slope generator. It cannot help you, unless you  you don't need the slope generator. It cannot help you, unless you
2120  want to spread tag and render slopes each round over and over.  want to spread tag and render slopes each round over and over.
2121    
2122  Well... this was core of ant.lua. Now some helper functions are behind  Well, this was the core of ant.lua. There are a few helper functions
2123  us, and a reference. But in fact, ant.lua can provide you no better  besides this, but in fact ant.lua will provide you no better
2124  functionality.  functionality.
2125    
   
2126  ================================================================================  ================================================================================
2127  6] HELPER FUNCTIONS  6] HELPER FUNCTIONS
2128  ================================================================================  ================================================================================
# Line 2208  only the first layer of values is copied Line 2205  only the first layer of values is copied
2205  Sending messages is a common way how to make one object do the things  Sending messages is a common way how to make one object do the things
2206  like opening, closing, switching on and off, triggering etc. As long  like opening, closing, switching on and off, triggering etc. As long
2207  as you use the triggers and switches for this purpose, everything is  as you use the triggers and switches for this purpose, everything is
2208  ok. If you want to send a message on your own, you have to write  OK. If you want to send a message on your own, you have to write
2209  things like this:  things like this:
2210    
2211        enigma.SendMessage(enigma.GetNamedObject("doorA"), "open", nil)        enigma.SendMessage(enigma.GetNamedObject("doorA"), "open", nil)

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26