5 |
-- modify it under the terms of the GNU General Public License |
-- modify it under the terms of the GNU General Public License |
6 |
-- as published by the Free Software Foundation; either version 2 |
-- as published by the Free Software Foundation; either version 2 |
7 |
-- of the License, or (at your option) any later version. |
-- of the License, or (at your option) any later version. |
8 |
-- |
-- |
9 |
-- This program is distributed in the hope that it will be useful, |
-- This program is distributed in the hope that it will be useful, |
10 |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
-- GNU General Public License for more details. |
-- GNU General Public License for more details. |
13 |
-- |
-- |
14 |
-- You should have received a copy of the GNU General Public License along |
-- You should have received a copy of the GNU General Public License along |
15 |
-- with this program; if not, write to the Free Software Foundation, Inc., |
-- with this program; if not, write to the Free Software Foundation, Inc., |
16 |
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
62 |
-- cell0.tag removed - I'm not sure if it was ever used at all... |
-- cell0.tag removed - I'm not sure if it was ever used at all... |
63 |
-- some improvements in handling default cell key meanings at multichar maps |
-- some improvements in handling default cell key meanings at multichar maps |
64 |
-- 2003-04-12 -- interface of add_multiobject changed to match interface of other multiples |
-- 2003-04-12 -- interface of add_multiobject changed to match interface of other multiples |
65 |
|
-- 2003-04-25 -- boolean tables |
66 |
|
|
67 |
|
|
68 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
184 |
-- VISUAL MAP CREATION -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- VISUAL MAP CREATION -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
185 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
298 |
-- + item - the same, but for item |
-- + item - the same, but for item |
299 |
-- + actor - the same, but for actor |
-- + actor - the same, but for actor |
300 |
-- ++ mode - see get_actor_x() and _y() functions |
-- ++ mode - see get_actor_x() and _y() functions |
301 |
-- + pmode - parent arglist handling mode. Defaults to 0 and it means where to put (x,y) couple in arglist |
-- + mode - parent arglist handling mode. Defaults to 0 and it means where to put (x,y) couple in arglist |
302 |
-- ++ pmode = -1 => do not place the (x,y) couple to arglist |
-- ++ mode = -1 => do not place the (x,y) couple to arglist |
303 |
-- ++ pmode = +0 => place it before parent arguments |
-- ++ mode = +0 => place it before parent arguments |
304 |
|
|
305 |
-- ATTENTION: there *has* to be a coordlist even in case of pmode=-1, or NO arguments may be passed: |
-- ATTENTION: there *has* to be a coordlist even in case of pmode=-1, or NO arguments may be passed: |
306 |
-- -> func() |
-- -> func() |
338 |
if (type(parent[a][1])=="function") then |
if (type(parent[a][1])=="function") then |
339 |
-- this is O.K. => a curry function call {func, arg1, arg2, ...} |
-- this is O.K. => a curry function call {func, arg1, arg2, ...} |
340 |
else |
else |
341 |
warning("cell{}: parent element number "..a.." is a curry-function\n".. |
warning("cell{}: parent element number "..a.." acts as a curry-function\n".. |
342 |
"construction, but it's first element has to be a function, not "..type(parent[a])..".\n".. |
"construction, but it's first element isn't a function, it's "..type(parent[a])..".\n".. |
343 |
"Using empty function instead.") |
"Using empty function instead.") |
344 |
parent[a]={function() end} |
parent[a]={function() end} |
345 |
end |
end |
485 |
end |
end |
486 |
end |
end |
487 |
|
|
488 |
|
|
489 |
|
|
490 |
|
|
491 |
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
492 |
|
-- MAP RENDERING FUNCTIONS -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
493 |
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
494 |
|
|
495 |
-- render a map square by key |
-- render a map square by key |
496 |
-- rx,ry are x,y coordinates of given cell on map |
-- rx,ry are x,y coordinates of given cell on map |
497 |
-- key is a cell descriptor |
-- key is a cell descriptor |
562 |
for my = mxy0[2],mxy1[2] do |
for my = mxy0[2],mxy1[2] do |
563 |
for mx = mxy0[1],mxy1[1] do |
for mx = mxy0[1],mxy1[1] do |
564 |
render_map_cell(rx0, ry0, mx, my, map, cellfuncs); |
render_map_cell(rx0, ry0, mx, my, map, cellfuncs); |
565 |
end -- for x |
end |
566 |
end -- for y |
end |
567 |
end |
end |
568 |
|
|
569 |
-- this will draw whole map |
-- this will draw whole map |
760 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
761 |
-- SPECIAL FLOOR TYPES -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- SPECIAL FLOOR TYPES -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
762 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
763 |
-- these function are usually used as a parent functions |
-- see ant.lua documentation for extensive howto |
764 |
|
-- (this is yet to be done) |
765 |
|
|
766 |
-- draws checker floor |
-- draws checker floor |
767 |
-- sidex: horizontal size of checker square |
-- sidex: horizontal size of checker square |
876 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
877 |
-- OBJECT GROUPS [MULTIPLES] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- OBJECT GROUPS [MULTIPLES] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
878 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
879 |
-- these are common parent function, much like checkerfloor or randomfloor |
-- see ant.lua documentation for extensive howto |
|
-- usage is as follows in example: |
|
|
-- blocks = {}; |
|
|
-- cells[" "] = cell{floor={face="fl-gray"}} |
|
|
-- cells["W"] = cell{parent={cell[" "], {add_multistone, "st-block", blocks}}} |
|
|
-- |
|
|
-- this cell has two parents: |
|
|
-- cells[" "], which is some common floor of kind 'fl-gray' |
|
|
-- {add_multistone, "st-block", blocks}, which is group parent function |
|
|
-- add_multistone : add a stone to map and also to a group |
|
|
-- "st-block" : name of stone object to add |
|
|
-- blocks : LUA table that represents object group |
|
|
-- |
|
|
-- Constructed group can be used later in the functions that work with it, like |
|
|
-- send_group_message, add_rubber_bands, ... |
|
880 |
|
|
881 |
-- add a stone to a group |
-- add a stone to a group |
882 |
-- face: this is stone face |
-- face: this is stone face |
1268 |
|
|
1269 |
|
|
1270 |
|
|
1271 |
|
|
1272 |
|
|
1273 |
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
1274 |
|
-- BOOLEAN TABLES -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
1275 |
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
1276 |
|
-- see ant.lua documentation for extensive howto |
1277 |
|
-- |
1278 |
|
-- a(C, D) -> C i D ovlivnuji jednu tabulku s metodou and |
1279 |
|
-- o(a(C), D) -> C ovlivnuje jednu tabulku andem, tato tabulka a D ovlivnuji druhou orem |
1280 |
|
|
1281 |
|
-- bool_and tests table for and: all elements have to be '1' to succeed |
1282 |
|
function bool_and(tab) |
1283 |
|
return tab.count == tab.value |
1284 |
|
end |
1285 |
|
|
1286 |
|
|
1287 |
|
-- bool_or tests table for or: at least one element has to be '1' to succeed |
1288 |
|
function bool_or(tab) |
1289 |
|
return tab.value > 0 |
1290 |
|
end |
1291 |
|
|
1292 |
|
|
1293 |
|
-- bool_xor tests table for xor: odd number of elements has to be '1' to succeed |
1294 |
|
function bool_xor(tab) |
1295 |
|
return mod(tab.value, 2) ~= 0 |
1296 |
|
end |
1297 |
|
|
1298 |
|
|
1299 |
|
-- bool_table initialization |
1300 |
|
-- count_tot is number of cells in table (that is the number of triggers) |
1301 |
|
-- count_init is number of cells to init (number of negset triggers) |
1302 |
|
-- test_func is a function to get called each set and negset - a test function |
1303 |
|
-- true_func is a function to be called if test passed |
1304 |
|
-- false_func is a function to be called if test failed |
1305 |
|
function bool_table(count_tot, count_init, test_func, true_func, false_func) |
1306 |
|
local tab = {}; |
1307 |
|
|
1308 |
|
tab.test = test_func or function() return nil end; |
1309 |
|
tab.true = true_func or function() return nil end; |
1310 |
|
tab.false = false_func or function() return nil end; |
1311 |
|
tab.count = count_tot or 1; |
1312 |
|
tab.value = count_init or 0; |
1313 |
|
tab.remember= -1; |
1314 |
|
|
1315 |
|
return tab; |
1316 |
|
end |
1317 |
|
|
1318 |
|
|
1319 |
|
-- bool val set |
1320 |
|
-- this gets called upon every trigger/switcher state change |
1321 |
|
-- it changes value of one element of given table |
1322 |
|
function bool_set(value, omit, tab) |
1323 |
|
if (value == 0) then |
1324 |
|
tab.value = tab.value -1; |
1325 |
|
else |
1326 |
|
tab.value = tab.value +1; |
1327 |
|
end |
1328 |
|
|
1329 |
|
local res = tab.test(tab); |
1330 |
|
if (tab.remember ~= res) then |
1331 |
|
tab.remember = res; |
1332 |
|
|
1333 |
|
if (res) then |
1334 |
|
debug("bool_set: true") |
1335 |
|
tab.true() |
1336 |
|
else |
1337 |
|
debug("bool_set: false") |
1338 |
|
tab.false() |
1339 |
|
end |
1340 |
|
end |
1341 |
|
end |
1342 |
|
|
1343 |
|
|
1344 |
|
-- bool val negative set |
1345 |
|
-- this is similar to bool_val, except that it sets '1' if triggered off and vice versa |
1346 |
|
function bool_negset(value, omit, tab) |
1347 |
|
if (value == 0) then |
1348 |
|
bool_set(1, nil, tab) |
1349 |
|
else |
1350 |
|
bool_set(0, nil, tab) |
1351 |
|
end |
1352 |
|
end |
1353 |
|
|
1354 |
|
|
1355 |
|
|
1356 |
|
|
1357 |
|
|
1358 |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
1359 |
-- WRAPPED init.lua FUNCTIONS -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
-- WRAPPED init.lua FUNCTIONS -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |