File: api1init.lua

package info (click to toggle)
enigma 1.20-dfsg.1-2.1
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 64,696 kB
  • ctags: 16,496
  • sloc: xml: 153,614; cpp: 63,581; ansic: 31,088; sh: 4,825; makefile: 1,858; yacc: 288; perl: 84; sed: 16
file content (1690 lines) | stat: -rw-r--r-- 53,518 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
863
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1863
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
------------------------------------------------------------------------
-- Copyright (C) 2002,2003,2004,2005 Daniel Heck
-- Copyright (C) 2007,2008 Ronald Lamprecht
--
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2
-- of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
--
------------------------------------------------------------------------

-----------------------------------------------
-- Use Enigma internal random implementation --
-----------------------------------------------

if type(en) == "table" then
    math.random = en.random
else
    math.random = enigma.random
end
random = math.random
-- randseed is issued by Enigma application and must not be disturbed
math.randomseed = function () end

-------------------------------
-- Compatibility for old API --
-------------------------------

enigma._MakeObject = enigma.MakeObject
enigma._GetKind = enigma.GetKind
enigma._SetAttrib = enigma.SetAttrib
enigma._GetAttrib = enigma.GetAttrib
enigma._GetObjectTemplate = enigma.GetObjectTemplate

RenamingObjectsOld2New = {
}

RenamingObjectsNew2Old = {
    ac_bug = "ac-bug",
    ac_horse = "ac-horse",
    ac_killer = "ac-killerball",
    ac_marble_black = "ac-blackball",
    ac_marble_white = "ac-whiteball",
    ac_pearl_white = "ac-whiteball-small",
    ac_rotor = "ac-rotor",
    ac_top = "ac-top",
    fl_abyss = "fl-abyss",
    fl_adhesionless = "fl-nomouse",
    fl_aquamarine = "fl-bluegreenx",
    fl_bast = "fl-floor_001",
    fl_bluegray = "fl-bluegray",
    fl_bluegreen = "fl-bluegreen",
    fl_blueslab = "fl-rough-blue",
    fl_brick = "fl-brick",
    fl_bridge = "fl-bridge",
    fl_bright = "fl-white",
    fl_concrete = "fl-concrete",
    fl_dark = "fl-black",
    fl_darkgray = "fl-darkgray",
    fl_dunes = "fl-dunes",
    fl_fake_abyss = "fl-abyss_fake",
    fl_fake_trigger = "fl-trigger",
    fl_gravel = "fl-gravel",
    fl_gray = "fl-gray",
    fl_hay = "fl-hay",
    fl_himalaya = "fl-himalaya",
    fl_ice = "fl-ice",
    fl_inverse_white = "fl-inverse",
    fl_inverse_gray = "fl-inverse2",
    fl_ivory = "fl-light",
    fl_lawn_a = "fl-leaves",
    fl_lawn_b = "fl-leavesb",
    fl_lawn_c1 = "fl-leavesc1",
    fl_lawn_c2 = "fl-leavesc2",
    fl_lawn_c3 = "fl-leavesc3",
    fl_lawn_c4 = "fl-leavesc4",
    fl_lawn_d1 = "fl-leavesd1",
    fl_lawn_d2 = "fl-leavesd2",
    fl_lawn_d3 = "fl-leavesd3",
    fl_lawn_d4 = "fl-leavesd4",
    fl_lawn_e1 = "fl-leavese1",
    fl_lawn_e2 = "fl-leavese2",
    fl_lawn_e3 = "fl-leavese3",
    fl_lawn_e4 = "fl-leavese4",
    fl_marble = "fl-marble",
    fl_metal = "fl-metal",
    fl_metal_1 = "fl-metal1",
    fl_metal_2 = "fl-metal2",
    fl_metal_3 = "fl-metal3",
    fl_metal_4 = "fl-metal4",
    fl_metal_5 = "fl-metal5",
    fl_metal_6 = "fl-metal6",
    fl_metal_7 = "fl-normal_x",
    fl_metal_7n = "fl-normal",
    fl_mortar = "fl-mortar",
    fl_pinkbumps = "fl-bumps",
    fl_plank = "fl-plank",
    fl_platinum = "fl-lightgray",
    fl_red = "fl-red",
    fl_redslab = "fl-rough-red",
    fl_rock = "fl-rock",
    fl_rough = "fl-rough",
    fl_sahara = "fl-sahara",
    fl_sand = "fl-sand",
    fl_samba = "fl-samba",
    fl_samba_h = "fl-samba1",
    fl_samba_v = "fl-samba2",
    fl_slope_ps = "fl-gradient1",
    fl_slope_pn = "fl-gradient2",
    fl_slope_pe = "fl-gradient3",
    fl_slope_pw = "fl-gradient4",
    fl_slope_ose = "fl-gradient5",
    fl_slope_osw = "fl-gradient6",
    fl_slope_one = "fl-gradient7",
    fl_slope_onw = "fl-gradient8",
    fl_slope_ise = "fl-gradient9",
    fl_slope_ine = "fl-gradient10",
    fl_slope_isw = "fl-gradient11",
    fl_slope_inw = "fl-gradient12",
    fl_slope_ts = "fl-gradient14",
    fl_slope_tn = "fl-gradient13",
    fl_slope_te = "fl-gradient16",
    fl_slope_tw = "fl-gradient15",
    fl_space = "fl-space",
    fl_stone = "fl-stone",
    fl_swamp = "fl-swamp",
    fl_thief = "fl-thief",
    fl_tigris = "fl-tigris",
    fl_water = "fl-water",
    fl_white = "fl-springboard",
    fl_wood = "fl-wood",
    fl_wood_h = "fl-wood1",
    fl_wood_v = "fl-wood2",
    fl_wood_framed = "fl-stwood",
    fl_wood_framed_h = "fl-stwood1",
    fl_wood_framed_v = "fl-stwood2",
    fl_woven = "fl-woven",
    fl_yinyang_yin_invisible = "fl-acblack",
    fl_yinyang_yang_invisible = "fl-acwhite",
    it_banana = "it-banana",
    it_bag = "it-bag",
    it_blocker = "it-blocker",
    it_blocker_new = "it-blocker-new",
    it_bomb_black = "it-blackbomb",
    it_bomb_white = "it-whitebomb",
    it_bottle_idle = "it-booze",
    it_bottle_broken = "it-booze-broken",
    it_brake = "it-brake",
    it_brush = "it-brush",
    it_burnable_invisible = "it-burnable",
    it_burnable_oil = "it-burnable_oil",
    it_burnable_ignited = "it-burnable_ignited",
    it_burnable_burning = "it-burnable_burning",
    it_burnable_ash = "it-burnable_ash",
    it_burnable_fireproof = "it-burnable_fireproof",
    it_cherry = "it-cherry",
    it_coffee = "it-coffee",
    it_coin_s = "it-coin1",
    it_coin_m = "it-coin2",
    it_coin_l = "it-coin4",
    it_crack_i = "it-crack0",
    it_crack_s = "it-crack1",
    it_crack_m = "it-crack2",
    it_crack_l = "it-crack3",
    it_cross = "it-cross",
    it_death = "it-death",
    it_document = "it-document",
    it_drop = "it-drop",
    it_dynamite = "it-dynamite",
    it_explosion_nil = "it-explosion1",
    it_explosion_hollow = "it-explosion2",
    it_explosion_debris = "it-explosion3",
    it_extinguisher_empty = "it-extinguisher_empty",
    it_extinguisher_medium = "it-extinguisher_medium",
    it_extinguisher_full = "it-extinguisher",
    it_extralife = "it-extralife",
    it_flag_black = "it-flagblack",
    it_flag_white = "it-flagwhite",
    it_floppy = "it-floppy",
    it_glasses = "it-glasses",
    it_glasses_broken = "it-glasses-broken",
    it_hammer = "it-hammer",
    it_landmine = "it-landmine",
    it_magicwand = "it-magicwand",
    it_magnet = "it-magnet",
    it_magnet_on = "it-magnet-on",
    it_magnet_off = "it-magnet-off",
    it_meditation_hollow = "it-hollow",
    it_meditation_dent = "it-tinyhollow",
    it_meditation_bump = "it-tinyhill",
    it_meditation_hill = "it-hill",
    it_odometer = "it-odometer",
    it_pencil = "it-pencil",
    it_pin = "it-pin",
    it_pipe_w = "it-pipe-w",
    it_pipe_s = "it-pipe-s",
    it_pipe_sw = "it-pipe-sw",
    it_pipe_e = "it-pipe-e",
    it_pipe_ew = "it-pipe-h",
    it_pipe_es = "it-pipe-es",
    it_pipe_n = "it-pipe-n",
    it_pipe_nw = "it-pipe-wn",
    it_pipe_ns = "it-pipe-v",
    it_pipe_ne = "it-pipe-ne",
    it_puller_w = "it-puller-w",
    it_puller_s = "it-puller-s",
    it_puller_e = "it-puller-e",
    it_puller_n = "it-puller-n",
    it_ring = "it-ring",
    it_rubberband = "it-rubberband",
    it_seed = "it-seed",
    it_seed_greenbrown = "it-seed_nowood",
    it_seed_volcano = "it-seed_volcano",
    it_spade = "it-spade",
    it_spoon = "it-spoon",
    it_spring_keep = "it-spring1",
    it_spring_drop = "it-spring2",
    it_springboard = "it-springboard",
    it_squashed = "it-squashed",
    it_shogun_s = "it-shogun-s",
    it_shogun_m = "it-shogun-m",
    it_shogun_l = "it-shogun-l",
    it_strip_ew = "it-hstrip",
    it_strip_ns = "it-vstrip",
    it_surprise = "it-surprise",
    it_sword = "it-sword",
    it_trap = "it-abyss",
    it_trigger = "it-trigger",
    it_umbrella = "it-umbrella",
    it_vortex = "it-vortex-open",
    it_vortex_open = "it-vortex-open",
    it_vortex_closed = "it-vortex-closed",
    it_weight = "it-weight",
    it_wormhole_on = "it-wormhole",
    it_wormhole_off = "it-wormhole-off",
    it_wrench = "it-wrench",
    it_yinyang = "it-yinyang",
    st_actorimpulse = "st-actorimpulse",
    st_actorimpulse_invisible = "st-actorimpulse_invisible",
    st_ancient = "st-rock9",
    st_beads = "st-beads",
    st_blocker = "st-blocker",
    st_blocker_new = "st-blocker-growing",
    st_bluegray = "st-bluegray",
    st_bluegray_hollow = "st-bluegray_hole",
    st_bluesand = "st-blue-sand",
    st_bluesand_w = "st-bigbluesand-w",
    st_bluesand_s = "st-bigbluesand-s",
    st_bluesand_sw = "st-bigbluesand-sw",
    st_bluesand_e = "st-bigbluesand-e",
    st_bluesand_ew = "st-bigbluesand-ew",
    st_bluesand_es = "st-bigbluesand-es",
    st_bluesand_esw = "st-bigbluesand-esw",
    st_bluesand_n = "st-bigbluesand-n",
    st_bluesand_nw = "st-bigbluesand-nw",
    st_bluesand_ns = "st-bigbluesand-ns",
    st_bluesand_nsw = "st-bigbluesand-nsw",
    st_bluesand_ne = "st-bigbluesand-ne",
    st_bluesand_new = "st-bigbluesand-new",
    st_bluesand_nes = "st-bigbluesand-nes",
    st_bluesand_nesw = "st-bigbluesand-nesw",
    st_blur_cross = "st-yinyang1",
    st_blur_magic = "st-yinyang3",
    st_blur_straight = "st-yinyang2",
    st_boulder = "st-bolder",
    st_boulder_n = "st-bolder-n",
    st_boulder_e = "st-bolder-e",
    st_boulder_s = "st-bolder-s",
    st_boulder_w = "st-bolder-w",
    st_box_hay = "st-flhay",
    st_box_rock = "st-flrock",
    st_box_wood = "st-wood",
    st_box_wood_growing = "st-wood-growing",
    st_box_wood_h = "st-wood1",
    st_box_wood_v = "st-wood2",
    st_brake = "st-brake",
    st_break_black = "st-break_acblack",
    st_break_boulder = "st-break_bolder",
    st_break_bug = "st-bug",
    st_break_laser = "st-laserbreak",
    st_break_oxydc = "st-stone_break",
    st_break_plain = "st-break_gray",
    st_break_white = "st-break_acwhite",
    st_brick = "st-brick",
    st_brick_w = "st-bigbrick-w",
    st_brick_s = "st-bigbrick-s",
    st_brick_sw = "st-bigbrick-sw",
    st_brick_e = "st-bigbrick-e",
    st_brick_ew = "st-bigbrick-ew",
    st_brick_es = "st-bigbrick-es",
    st_brick_esw = "st-bigbrick-esw",
    st_brick_n = "st-bigbrick-n",
    st_brick_nw = "st-bigbrick-nw",
    st_brick_ns = "st-bigbrick-ns",
    st_brick_nsw = "st-bigbrick-nsw",
    st_brick_ne = "st-bigbrick-ne",
    st_brick_new = "st-bigbrick-new",
    st_brick_nes = "st-bigbrick-nes",
    st_brick_nesw = "st-bigbrick-nesw",
    st_brownie = "st-brownie",
    st_brownmarble = "st-rock10",
    st_brownpyramid = "st-stone1",
    st_camouflage = "st-camouflage",
    st_camouflage_hollow = "st-camouflage_hole",
    st_camouflage_movable = "st-camouflage_move",
    st_chameleon = "st-chameleon",
    st_charge_minus = "st-chargeminus",
    st_charge_plus = "st-chargeplus",
    st_charge_zero = "st-chargezero",
    st_chess = "st-chess",
    st_chess_black = "st-chess_black",
    st_chess_white = "st-chess_white",
    st_coinslot = "st-coinslot",
    st_concrete = "st-rock8",
    st_dongle = "st-magic",
    st_darkglass = "st-glass2",
    st_darkglass_hollow = "st-glass2_hole",
    st_darkglass_movable = "st-glass2_move",
    st_darkgray = "st-rock2",
    st_darkgray_hollow = "st-rock2_hole",
    st_death = "st-death",
    st_death_invisible = "st-death_invisible",
    st_disco_light = "st-disco-light",
    st_disco_medium = "st-disco-medium",
    st_disco_dark = "st-disco-dark",
    st_dispenser_bombblack = "st-bombs",
    st_door_a = "st-door_a",
    st_door_b = "st-door_b",
    st_door_c = "st-door_c",
    st_fake_quake = "st-fakeoxyd",
    st_fake_oxyda = "st-likeoxyda",
    st_fake_oxydb = "st-likeoxydb",
    st_fake_oxydc = "st-likeoxydc",
    st_fake_oxydd = "st-likeoxydd",
    st_flash = "st-flash",
    st_flat = "st-plain",
    st_flat_breakable = "st-plain_break",
    st_flat_hollow = "st-plain_hole",
    st_flat_movable = "st-plain_move",
    st_flat_cracked = "st-plain_cracked",
    st_flat_burnable = "st-firebreak",
    st_flat_moveburnable = "st-firebreak_move",
    st_floppy = "st-floppy",
    st_fourswitch = "st-fourswitch",
    st_ghost_break = "st-break_invisible",
    st_ghost_greenbrown = "st-invisible_magic",
    st_ghost_purplemarble = "st-stonebrush",
    st_granite = "st-rock1",
    st_granite_hollow = "st-rock1_hole",
    st_granite_movable = "st-rock1_move",
    st_grate_cross = "st-grate1",
    st_grate_framed = "st-grate2",
    st_greenbrown = "st-greenbrown",
    st_greenbrown_hollow = "st-greenbrown_hole",
    st_greenbrown_movable = "st-greenbrown_move",
    st_greengray = "st-rock7",
    st_invisible = "st-invisible",
    st_invisible_hollow = "st-invisible_hole",
    st_invisible_movable = "st-invisible_move",
    st_jamb_black = "st-blackballs",
    st_jamb_white = "st-whiteballs",
    st_knight = "st-knight",
    st_laser_w = "st-laser-w",
    st_laser_s = "st-laser-s",
    st_laser_e = "st-laser-e",
    st_laser_n = "st-laser-n",
    st_laserswitch = "st-laserswitch",
    st_laserflop = "st-lasertimeswitch",
    st_lightglass = "st-glass1",
    st_lightglass_hollow = "st-glass1_hole",
    st_lightglass_movable = "st-glass1_move",
    st_lightpassenger = "st-lightpassenger",
    st_lightpassenger_off = "st-lightpassenger_off",
    st_magic_brick = "st-brick_magic",
    st_magic_oxyda = "st-fakeoxyda",
    st_magic_oxydc = "st-coffee",
    st_mail_w = "st-mail-w",
    st_mail_s = "st-mail-s",
    st_mail_e = "st-mail-e",
    st_mail_n = "st-mail-n",
    st_metal = "st-metal",
    st_metal_hollow = "st-metal_hole",

    st_mirror_slab_n = "st-mirror-p|",
    st_mirror_slab_e = "st-mirror-p/",
    st_mirror_slab_s = "st-mirror-p-",
    st_mirror_slab_w = "st-mirror-p\\",
    st_mirror_slab_nt = "st-mirror-p|t",
    st_mirror_slab_et = "st-mirror-p/t",
    st_mirror_slab_st = "st-mirror-p-t",
    st_mirror_slab_wt = "st-mirror-p\\t",
    st_mirror_slab_nm = "st-mirror-p|m",
    st_mirror_slab_em = "st-mirror-p/m",
    st_mirror_slab_sm = "st-mirror-p-m",
    st_mirror_slab_wm = "st-mirror-p\\m",
    st_mirror_slab_ntm = "st-mirror-p|tm",
    st_mirror_slab_etm = "st-mirror-p/tm",
    st_mirror_slab_stm = "st-mirror-p-tm",
    st_mirror_slab_wtm = "st-mirror-p\\tm",
    st_mirror_triangle_n = "st-mirror-3^",
    st_mirror_triangle_e = "st-mirror-3>",
    st_mirror_triangle_s = "st-mirror-3v",
    st_mirror_triangle_w = "st-mirror-3<",
    st_mirror_triangle_nt = "st-mirror-3^t",
    st_mirror_triangle_et = "st-mirror-3>t",
    st_mirror_triangle_st = "st-mirror-3vt",
    st_mirror_triangle_wt = "st-mirror-3<t",
    st_mirror_triangle_nm = "st-mirror-3^m",
    st_mirror_triangle_em = "st-mirror-3>m",
    st_mirror_triangle_sm = "st-mirror-3vm",
    st_mirror_triangle_wm = "st-mirror-3<m",
    st_mirror_triangle_ntm = "st-mirror-3^tm",
    st_mirror_triangle_etm = "st-mirror-3>tm",
    st_mirror_triangle_stm = "st-mirror-3vtm",
    st_mirror_triangle_wtm = "st-mirror-3<tm",

    st_monoflop = "st-timeswitch",
    st_oxyd = "st-oxyd",
    st_oneway = "st-oneway",
    st_oneway_n = "st-oneway-n",
    st_oneway_e = "st-oneway-e",
    st_oneway_s = "st-oneway-s",
    st_oneway_w = "st-oneway-w",
    st_oneway_black = "st-oneway_black",
    st_oneway_black_n = "st-oneway_black-n",
    st_oneway_black_e = "st-oneway_black-e",
    st_oneway_black_s = "st-oneway_black-s",
    st_oneway_black_w = "st-oneway_black-w",
    st_oneway_white = "st-oneway_white",
    st_oneway_white_n = "st-oneway_white-n",
    st_oneway_white_e = "st-oneway_white-e",
    st_oneway_white_s = "st-oneway_white-s",
    st_oneway_white_w = "st-oneway_white-w",
    st_panel = "st-wood_001",
    st_polarswitch = "st-polarswitch",
    st_passage_black_square = "st-black1",
    st_passage_black_slash = "st-black2",
    st_passage_black_cross = "st-black3",
    st_passage_black_frame = "st-black4",
    st_passage_white_square = "st-white1",
    st_passage_white_slash = "st-white2",
    st_passage_white_cross = "st-white3",
    st_passage_white_frame = "st-white4",
    st_pinkbumps = "st-bumps",
    st_plaster = "st-rock3",
    st_plaster_hollow = "st-rock3_hole",
    st_plaster_movable = "st-rock3_move",
    st_plaster_breakable = "st-rock3_break",
    st_plaster_movebreakable = "st-rock3_movebreak",
    st_plop = "st-block",
    st_portal_horse = "st-grate3",
    st_pull = "st-pull",
    st_purplegray = "st-rock6",
    st_purplemarble = "st-rock4",

    st_puzzle = "st-puzzle",
    st_puzzle_blue_w = "st-puzzle-w",
    st_puzzle_blue_s = "st-puzzle-s",
    st_puzzle_blue_sw = "st-puzzle-sw",
    st_puzzle_blue_e = "st-puzzle-e",
    st_puzzle_blue_ew = "st-puzzle-ew",
    st_puzzle_blue_es = "st-puzzle-es",
    st_puzzle_blue_esw = "st-puzzle-esw",
    st_puzzle_blue_n = "st-puzzle-n",
    st_puzzle_blue_nw = "st-puzzle-nw",
    st_puzzle_blue_ns = "st-puzzle-ns",
    st_puzzle_blue_nsw = "st-puzzle-nsw",
    st_puzzle_blue_ne = "st-puzzle-ne",
    st_puzzle_blue_new = "st-puzzle-new",
    st_puzzle_blue_nes = "st-puzzle-nes",
    st_puzzle_blue_nesw = "st-puzzle-nesw",
    st_puzzle_blue_nesw_hollow = "st-puzzle-hollow",
    st_puzzle_yellow_w = "st-puzzle2-w",
    st_puzzle_yellow_s = "st-puzzle2-s",
    st_puzzle_yellow_sw = "st-puzzle2-sw",
    st_puzzle_yellow_e = "st-puzzle2-e",
    st_puzzle_yellow_ew = "st-puzzle2-ew",
    st_puzzle_yellow_es = "st-puzzle2-es",
    st_puzzle_yellow_esw = "st-puzzle2-esw",
    st_puzzle_yellow_n = "st-puzzle2-n",
    st_puzzle_yellow_nw = "st-puzzle2-nw",
    st_puzzle_yellow_ns = "st-puzzle2-ns",
    st_puzzle_yellow_nsw = "st-puzzle2-nsw",
    st_puzzle_yellow_ne = "st-puzzle2-ne",
    st_puzzle_yellow_new = "st-puzzle2-new",
    st_puzzle_yellow_nes = "st-puzzle2-nes",
    st_puzzle_yellow_nesw = "st-puzzle2-nesw",
    st_puzzle_yellow_nesw_hollow = "st-puzzle2-hollow",
    st_quake = "st-fart",
    st_rawglass = "st-glass",
    st_rawglass_movable = "st-glass_move",
    st_redbrown = "st-marble",
    st_redbrown_hollow = "st-marble_hole",
    st_redbrown_movable = "st-marble_move",
    st_redfiber = "st-glass3",
    st_redmarble = "st-stone2",
    st_redrock = "st-redrock",
    st_rotator_cw = "st-rotator-right",
    st_rotator_ccw = "st-rotator-left",
    st_rotator_cw_movable = "st-rotator_move-right",
    st_rotator_ccw_movable = "st-rotator_move-left",
    st_rubberband = "st-rubberband",
    st_scissors = "st-scissors",
    st_shogun = "st-shogun",
    st_shogun_s = "st-shogun-s",
    st_shogun_m = "st-shogun-m",
    st_shogun_sm = "st-shogun-sm",
    st_shogun_l = "st-shogun-l",
    st_shogun_sl = "st-shogun-sl",
    st_shogun_ml = "st-shogun-ml",
    st_shogun_sml = "st-shogun-sml",
    st_spitter = "st-spitter",
    st_stoneimpulse = "st-stoneimpulse",
    st_stoneimpulse_hollow = "st-stoneimpulse-hollow",
    st_stoneimpulse_movable = "st-stoneimpulse_movable",
    st_surprise = "st-surprise",
    st_swap = "st-swap",
    st_switch = "st-switch",
    st_switch_black = "st-switch_black",
    st_switch_white = "st-switch_white",
    st_thief = "st-thief",
    st_tigris = "st-rock5",
    st_timer = "st-timer",
    st_turnstile_red = "st-turnstile",
    st_turnstile_green = "st-turnstile-green",
    st_turnstilearm_n = "st-turnstile-n",
    st_turnstilearm_e = "st-turnstile-e",
    st_turnstilearm_s = "st-turnstile-s",
    st_turnstilearm_w = "st-turnstile-w",
    st_volcano = "st-volcano",
    st_volcano_new = "st-volcano-growing",
    st_volcano_active = "st-volcano_active",
    st_volcano_idle = "st-volcano_inactive",
    st_window = "st-window",
    st_woven = "st-woven",
    st_yellow = "st-yellow"
}

for k,v in pairs(RenamingObjectsNew2Old) do
    RenamingObjectsOld2New[v] = k
end

function enigma.MakeObject(name)
    if name.sub(2,2) == "_" then
        error("Unknown object kind '"..name.."' in api 1.")
    end
    if name == "ac-whiteball-small" then
        local obj = enigma._MakeObject("ac_pearl_white")
        enigma._SetAttrib(obj, "owner", nil)
        return obj
    elseif name == "fl-gradient" then
        local obj = enigma._MakeObject("fl_slope_ps")
        return obj
    elseif name == "fl-bridge-open" then
        local obj = enigma._MakeObject("fl_bridge")
        return obj
    elseif name == "fl-bridge-closed" then
        local obj = enigma._MakeObject("fl_bridge")
        enigma._SetAttrib(obj, "state", 0)
        return obj
    elseif name == "fl-rough_medium" then
        local obj = enigma._MakeObject("fl_rough")
        enigma._SetAttrib(obj, "friction", 5.0)
        enigma._SetAttrib(obj, "adhesion", 1.2)
        return obj
    elseif name == "fl-rough_slow" then
        local obj = enigma._MakeObject("fl_rough")
        enigma._SetAttrib(obj, "friction", 7.0)
        enigma._SetAttrib(obj, "adhesion", 0.5)
        return obj
    elseif name == "st-key" then
        local obj = enigma._MakeObject("st_key")
        -- Old API keycode default was 0 for st-key, but 1 for it-key!
        enigma._SetAttrib(obj, "code", 0)
        return obj
    elseif name == "st-key_a" then
        local obj = enigma._MakeObject("st_key")
        enigma._SetAttrib(obj, "code", 1)
        return obj
    elseif name == "st-key_b" then
        local obj = enigma._MakeObject("st_key")
        enigma._SetAttrib(obj, "code", 2)
        return obj
    elseif name == "st-key_c" then
        local obj = enigma._MakeObject("st_key")
        enigma._SetAttrib(obj, "code", 3)
        return obj
    elseif name == "st-switch" then
        local obj = enigma._MakeObject("st_switch")
        enigma._SetAttrib(obj, "instant", true)
        return obj
    elseif name == "st-switch_black" then
        local obj = enigma._MakeObject("st_switch_black")
        enigma._SetAttrib(obj, "instant", true)
        return obj
    elseif name == "st-switch_white" then
        local obj = enigma._MakeObject("st_switch_white")
        enigma._SetAttrib(obj, "instant", true)
        return obj
    elseif name == "it-key_a" or  name == "it-key" then
        local obj = enigma._MakeObject("it_key")
        enigma._SetAttrib(obj, "code", 1)
        return obj
    elseif name == "it-key_b" then
        local obj = enigma._MakeObject("it_key")
        enigma._SetAttrib(obj, "code", 2)
        return obj
    elseif name == "it-key_c" then
        local obj = enigma._MakeObject("it_key")
        enigma._SetAttrib(obj, "code", 3)
        return obj
    elseif name == "it-sensor" then
        local obj = enigma._MakeObject("it_sensor")
        enigma._SetAttrib(obj, "invisible", true)
        return obj
    elseif name == "it-inversesensor" then
        local obj = enigma._MakeObject("it_sensor")
        enigma._SetAttrib(obj, "invisible", true)
        enigma._SetAttrib(obj, "inverse", true)
        return obj
    elseif name == "it-wormhole" then
        local obj = enigma._MakeObject("it_wormhole_on")
        enigma._SetAttrib(obj, "scissor", false)
        return obj
    elseif name == "it-wormhole-off" then
        local obj = enigma._MakeObject("it_wormhole_off")
        enigma._SetAttrib(obj, "scissor", false)
        return obj
    elseif name == "it-vortex-open" then
        local obj = enigma._MakeObject("it_vortex_open")
        enigma._SetAttrib(obj, "scissor", false)
        return obj
    elseif name == "it-vortex-closed" then
        local obj = enigma._MakeObject("it_vortex_closed")
        enigma._SetAttrib(obj, "scissor", false)
        enigma._SetAttrib(obj, "autoclose", true)
        return obj
    elseif name == "st-pmirror" then
        return enigma._MakeObject("st_mirror_slab_e")
    elseif name == "st-3mirror" then
        return enigma._MakeObject("st_mirror_triangle_s")
    elseif name == "st-scissors" then
        local obj = enigma._MakeObject("st_scissors")
        enigma._SetAttrib(obj, "inverse", true)
        return obj
    elseif name == "st-door-h" or name == "st-door" then
        local obj = enigma._MakeObject("st_door_d")
        enigma._SetAttrib(obj, "faces", "ns")
        return obj
    elseif name == "st-door-h-open" then
        local obj = enigma._MakeObject("st_door_d")
        enigma._SetAttrib(obj, "faces", "ns")
        enigma._SetAttrib(obj, "state", 1)
        return obj
    elseif name == "st-door-v" then
        local obj = enigma._MakeObject("st_door_d")
        enigma._SetAttrib(obj, "faces", "ew")
        return obj
    elseif name == "st-door-v-open" then
        local obj = enigma._MakeObject("st_door_d")
        enigma._SetAttrib(obj, "faces", "ew")
        enigma._SetAttrib(obj, "state", 1)
        return obj
    elseif name == "st-likeoxyda-open" then
        local obj = enigma._MakeObject("st_fake_oxyda")
        enigma._SetAttrib(obj, "state", 1)
        return obj
    elseif name == "st-likeoxydb-open" then
        local obj = enigma._MakeObject("st_fake_oxydb")
        enigma._SetAttrib(obj, "state", 1)
        return obj
    elseif name == "st-likeoxydc-open" then
        local obj = enigma._MakeObject("st_fake_oxydc")
        enigma._SetAttrib(obj, "state", 1)
        return obj
    elseif name == "st-likeoxydd-open" then
        local obj = enigma._MakeObject("st_fake_oxydd")
        enigma._SetAttrib(obj, "state", 1)
        return obj
    elseif name == "st-spitter" then
        local obj = enigma._MakeObject("st_spitter")
        enigma._SetAttrib(obj, "secure", true)
        return obj
    end
    newname = RenamingObjectsOld2New[name]

    if name == "st-laser" then
        newname = "st_laser_e"
    end

    if newname ~= nil then
        return enigma._MakeObject(newname)
    else
        error("Unknown object kind '"..name.."' in api 1.")
    end
end

function enigma.GetKind(obj)
    local _newname = enigma.GetClass(obj)
    local _oldname = RenamingObjectsNew2Old[_newname]

    if _oldname == nil then
        _oldname = RenamingObjectsNew2Old[enigma._GetKind(obj)]
    end

    if _newname == "st_key" then
        local code = enigma._GetAttrib(obj, "code")
        if code == 0 then
            return "st-key"
        elseif code == 1 then
            return "st-key_a"
        elseif code == 2 then
            return "st-key_b"
        elseif code == 3 then
            return "st-key_c"
        else -- arbitrary keycodes
            return "st-key"
        end
    end
    if _newname == "it_key" then
        local code = enigma._GetAttrib(obj, "code")
        if code == 1 then
            return "it-key_a"
        elseif code == 2 then
            return "it-key_b"
        elseif code == 3 then
            return "it-key_c"
        else -- arbitrary keycodes
            return "it-key_a"
        end
    end
    if _newname == "st_door" then
        local flavor = enigma._GetAttrib(obj, "flavor")
        if flavor == "d" then
            return "st-door"
        else
            return "st-door_" .. flavor
        end
    end
    if _newname == "st_puzzle" then
        return "st-puzzle"
    end
    if _newname == "it_sensor" then
        local code = enigma._GetAttrib(obj, "inverse")
        if code == false then
            return "it-sensor"
        else
            return "it-inversesensor"
        end
    end
    if string.sub(_newname, 1, 8) == "st_laser" then
        return "st-laser"
    end
    if _newname == "st_mirror" then
        return "st-mirror"
    end
    if _newname == "fl_slope" then
        return "fl-gradient"
    end
    if _newname == "st_fake_oxydc" then
        local state = enigma._GetAttrib(obj, "state")
        if state == 0 then
            return "st-likeoxydc"
        else
            return "st-likeoxydc-open"
        end
    end
    if _oldname ~= nil then
        return _oldname
    else
        return _newname
    end
end

function enigma.SetAttrib(obj, key, val)
     local _val = val
     local _key = key
     local _obj_name = enigma.GetKind(obj)

     if _obj_name == "st-oxyd" then
         if key == "color" then
             _val = 0   val   -- convert to int
             _key = "oxydcolor"
         end
     end
     if key == "connections" then
         if  val == 2  then _val = "w"
         elseif  val == 3  then _val = "s"
         elseif  val == 4  then _val = "sw"
         elseif  val == 5  then _val = "e"
         elseif  val == 6  then _val = "ew"
         elseif  val == 7  then _val = "es"
         elseif  val == 8  then _val = "esw"
         elseif  val == 9  then _val = "n"
         elseif  val == 10 then _val = "nw"
         elseif  val == 11 then _val = "ns"
         elseif  val == 12 then _val = "nsw"
         elseif  val == 13 then _val = "ne"
         elseif  val == 14 then _val = "new"
         elseif  val == 15 then _val = "nes"
         elseif  val == 16 then _val = "nesw"
         elseif  val == 1 and _obj_name ~= "st-puzzle" then _val = ""
         elseif  val == 1 and _obj_name == "st-puzzle" then
             _key = "hollow"
             _val = true
             enigma._SetAttrib(obj, "connections", "nesw")
         end
     end
     if key == "oxyd" then
        _key = "color"
        if val == 0 then _val = 2 else _val = 3 end
     end
     if key == "keycode" then
         _key = "code"
     end
     if key == "delay" then
         _key = "interval"
     end
     if key == "dir" or key == "direction" then
         _key = "orientation"
     end
     if key == "on" then
         _key = "state"
     end
     if key == "value" then
         _key = "coin_value"
     end
     if key == "load" then
         _key = "state"
     end
     if key == "force" then
         _key = "strength"
     end
     if key == "friction_factor" then
         _key = "friction"
     end
     if key == "gradient_factor" then
         _key = "gradient"
     end
     if key == "minlength"  then
         _key = "threshold"
     end
     if key == "target" and (_obj_name == "it-rubberband") then
         _key = "anchor2"
     end
     if key == "targetx" then
         local d = enigma._GetAttrib(obj, "destination")
         if (en.usertype(d) == "position") then
             _val = po(0   val, d.y)
         else
             _val = po(0   val, 0)
         end
         _key = "destination"
     end
     if key == "targety" then
         local d = enigma._GetAttrib(obj, "destination")
         if (en.usertype(d) == "position") then
             _val = po(d.x, 0   val)
         else
             _val = po(0, 0   val)
         end
         _key = "destination"
     end
     if key == "target1" or key == "target2" or key == "target3" or key == "target4" then
        local i = 0   string.sub(key, -1)  -- the target number
        local d = enigma._GetAttrib(obj, "destination")
        if (d == nil) or (type(d) ~= "table") then
            d = {}
        end

        local c = {}

        for str in string.gmatch(val, "%d ") do
            table.insert(c, 0   str)
        end
        d[i] = enigma.GetFloor(c[1], c[2]) -- requires floor to be set first (invalid for Nat method - level Bodyguard)
        if d[i] == nil then
             error("Actor Horse without floor error")
        end
        for j = 1, i do
           if d[j] == nil then
              d[j] = d[i]
           end
        end
        _key = "destination"
        _val = d
     end
     if key == "invisible" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "loop" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "scissor" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "static" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "orientation" and _obj_name == "st-mirror" then
         _val = (6 - val) % 4
     end
     if key == "transparent" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "movable" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "burnable" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "eternal" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "fastfire" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "ignitable" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "initfire" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "noash" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "secure" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "type" and _obj_name == "st-door" then
         _key = "faces"
         if val == "h" then _val = "ns" else _val = "ew" end
     end
     if key == "type" and _obj_name == "fl-bridge" then
         _key = "flavor"
         if val == "x" then _val = "bw"
         elseif val == "y" then _val = "bn"
         else _val = "gc"
         end
     end
     if key == "type" and string.find(_obj_name, "fl-gradient", 1, true) == 1 then
         if val == 1 then
             enigma._SetAttrib(obj, "shape", "ps")
             enigma._SetAttrib(obj, "slope", 1)
         elseif val == 2 then
             enigma._SetAttrib(obj, "shape", "pn")
             enigma._SetAttrib(obj, "slope", 3)
         elseif val == 3 then
             enigma._SetAttrib(obj, "shape", "pe")
             enigma._SetAttrib(obj, "slope", 2)
         elseif val == 4 then
             enigma._SetAttrib(obj, "shape", "pw")
             enigma._SetAttrib(obj, "slope", 0)
         elseif val == 5 then
             enigma._SetAttrib(obj, "shape", "ose")
             enigma._SetAttrib(obj, "slope", 6)
         elseif val == 6 then
             enigma._SetAttrib(obj, "shape", "osw")
             enigma._SetAttrib(obj, "slope", 5)
         elseif val == 7 then
             enigma._SetAttrib(obj, "shape", "one")
             enigma._SetAttrib(obj, "slope", 7)
         elseif val == 8 then
             enigma._SetAttrib(obj, "shape", "onw")
             enigma._SetAttrib(obj, "slope", 4)
         elseif val == 9 then
             enigma._SetAttrib(obj, "shape", "ise")
             enigma._SetAttrib(obj, "slope", 6)
         elseif val == 10 then
             enigma._SetAttrib(obj, "shape", "ine")
             enigma._SetAttrib(obj, "slope", 7)
         elseif val == 11 then
             enigma._SetAttrib(obj, "shape", "isw")
             enigma._SetAttrib(obj, "slope", 5)
         elseif val == 12 then
             enigma._SetAttrib(obj, "shape", "inw")
             enigma._SetAttrib(obj, "slope", 4)
         elseif val == 13 then
             enigma._SetAttrib(obj, "shape", "twr")
             enigma._SetAttrib(obj, "slope", 5)
         elseif val == 14 then
             enigma._SetAttrib(obj, "shape", "twl")
             enigma._SetAttrib(obj, "slope", 4)
         elseif val == 15 then
             enigma._SetAttrib(obj, "shape", "tel")
             enigma._SetAttrib(obj, "slope", 6)
         elseif val == 16 then
             enigma._SetAttrib(obj, "shape", "ter")
             enigma._SetAttrib(obj, "slope", 7)
         elseif val == 17 then
             enigma._SetAttrib(obj, "shape", "tnl")
             enigma._SetAttrib(obj, "slope", 7)
         elseif val == 18 then
             enigma._SetAttrib(obj, "shape", "tnr")
             enigma._SetAttrib(obj, "slope", 4)
         elseif val == 19 then
             enigma._SetAttrib(obj, "shape", "tsr")
             enigma._SetAttrib(obj, "slope", 6)
         elseif val == 20 then
             enigma._SetAttrib(obj, "shape", "tsl")
             enigma._SetAttrib(obj, "slope", 5)
         elseif val == 21 then
             enigma._SetAttrib(obj, "shape", "ts")
             enigma._SetAttrib(obj, "slope", 1)
         elseif val == 22 then
             enigma._SetAttrib(obj, "shape", "tn")
             enigma._SetAttrib(obj, "slope", 3)
         elseif val == 23 then
             enigma._SetAttrib(obj, "shape", "te")
             enigma._SetAttrib(obj, "slope", 2)
         elseif val == 24 then
             enigma._SetAttrib(obj, "shape", "tw")
             enigma._SetAttrib(obj, "slope", 0)
         end
         return
     end

     if key == "hit_factor" then
         _key = "hit_strength"
     end
     if key == "mousefactor" then
         _key = "adhesion"
     end
     if key == "mouseforce" then
         _key = "adhesion"
     end
     if key == "blinking" then
         _key = "state"
     end
     if key == "attacknearest" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "gohome" then
         if val == 1 then _val = true else _val = false end
     end
     if key == "fixed" then
         if val == 1 then
             enigma._SetAttrib(obj, "fragility", 0.0)
             enigma._SetAttrib(obj, "spreading", 0.0)
         else
             enigma._SetAttrib(obj, "fragility", nil)
             enigma._SetAttrib(obj, "spreading", nil)
         end
         return
     end
     if key == "player" then
         _key = "owner"
     end
     if key == "essential" then
        if val == -1 then
            _val = 1
        elseif val == 1 then
            _val = 2
        end
     end
     enigma._SetAttrib(obj, _key, _val)
end

function enigma.GetAttrib(obj, key)
     local _key = key
     local _obj_name = enigma.GetKind(obj)
     if key == "keycode" then
         _key = "code"
     end
     if key == "delay" then
         _key = "interval"
     end
     if key == "value" then
         _key = "coin_value"
     end
     if key == "force" then
         _key = "strength"
     end
     if key == "friction_factor" then
         _key = "friction"
     end
     if key == "gradient_factor" then
         _key = "gradient"
     end
     if key == "minlength"  then
         _key = "threshold"
     end
     if key == "target" and (_obj_name == "it-rubberband") then
         _key = "anchor2"
     end
     if key == "blackball" or key == "whiteball" then
         _key = "color"
     end
     if _obj_name == "st-oxyd" then
         _key = "oxydcolor"
     end
     if key == "dir" or key == "direction" then
         _key = "orientation"
     end
     if key == "on" then
         _key = "state"
     end
     if key == "load" then
         _key = "state"
     end
     if key == "blinking" then
         _key = "state"
     end
     if key == "mouseforce" then
         _key = "adhesion"
     end
     if key == "hit_factor" then
         _key = "hit_strength"
     end
     if key == "type" and _obj_name == "st-door" then
         local faces = enigma._GetAttrib(obj, "faces")
         if faces == "ns" then val = "h" else val = "v" end
         return val
     end
     if key == "type" and _obj_name == "fl-bridge" then
         local flavor = enigma._GetAttrib(obj, "flavor")
         if flavor == "bw" then return "x"
         elseif flavor == "bn" then return "y"
         else return "a"
         end
     end
     if key == "oxyd" and _obj_name == "st-puzzle" then
         local color = enigma._GetAttrib(obj, "color")
         if color == 2 then val = 0 else val = 1 end
         return val
     end
     if key == "player" then
         _key = "owner"
     end

     local val = enigma._GetAttrib(obj, _key)

     if key == "blackball" then
        if val == 0 then val = 1 else val = 0 end
     end
     if key == "whiteball" then
        if val == 1 then val = 1 else val = 0 end
     end
     if key == "connections" then
         if val == "" then val = 1
         elseif  val == "w"    then val = 2
         elseif  val == "s"    then val = 3
         elseif  val == "sw"   then val = 4
         elseif  val == "e"    then val = 5
         elseif  val == "ew"   then val = 6
         elseif  val == "es"   then val = 7
         elseif  val == "esw"  then val = 8
         elseif  val == "n"    then val = 9
         elseif  val == "nw"   then val = 10
         elseif  val == "ns"   then val = 11
         elseif  val == "nsw"  then val = 12
         elseif  val == "ne"   then val = 13
         elseif  val == "new"  then val = 14
         elseif  val == "nes"  then val = 15
         elseif  val == "nesw" then val = 16
         end
     end
     if _obj_name == "st-oxyd" then
         if key == "color" then
             val = "" .. val   -- convert to string
         end
     end
     if key == "targetx" then
         local d = enigma._GetAttrib(obj, "destination")
         if (en.usertype(d) == "position") then
             val = d.x
         end
     end
     if key == "targety" then
         local d = enigma._GetAttrib(obj, "destination")
         if (en.usertype(d) == "position") then
             val = d.y
         end
     end
     if key == "invisible" then
         if val == false then val = 0 else val = 1 end
     end
     if key == "orientation" and _obj_name == "st-mirror" then
         val = (5 - val) % 4   1
     end
     if key == "transparent" then
         if val == false then val = 0 else val = 1 end
     end
     if key == "movable" then
         if val == false then val = 0 else val = 1 end
     end
     if key == "attacknearest" then
         if val == false then val = 0 else val = 1 end
     end
     if key == "gohome" then
         if val == false then val = 0 else val = 1 end
     end
     if key == "essential" then
        if val == 1 then
            val = -1
        elseif val == 2 then
            val = 1
        end
     end
     return val
end

function enigma.GetObjectTemplate(kind)
    local _kind = RenamingObjectsOld2New[kind]
    if _kind == nil then
        _kind = kind
    end
    if kind == "st-key" or kind == "st-key_a" or kind == "st-key_b" or kind == "st-key_c" then
        _kind = "st_key"
    end
    return enigma._GetObjectTemplate(_kind)
end

MessageRenaming = {
    fl_bridge__openclose = "toggle",
    fl_bridge__signal = "toggle",
    it_blocker__trigger = "toggle",
    it_blocker__openclose = "toggle",
    it_burnable__trigger = "ignite",
    it_magnet__onoff = "toggle",
    it_meditation__trigger = "flip",
    it_vortex__openclose = "toggle",
    it_vortex__trigger = "toggle",
    it_wormhole__onoff = "toggle",
    st_blocker__openclose = "toggle",
    st_blocker__trigger = "toggle",
    st_blocker_new__openclose = "toggle",
    st_blocker_new__trigger = "toggle",
    st_boulder__direction = "orientate",
    st_door__openclose = "toggle",
    st_fourswitch__trigger = "toggle",
    st_floppy__onoff = "toggle",
    st_key__onoff = "toggle",
    st_laser__onoff = "toggle",
    st_lightpassenger__trigger = "toggle",
    st_lightpassenger__onoff = "toggle",
    st_mirror__trigger = "turn",
    st_oneway__direction = "orientate",
    st_oxyd__trigger = "open",
    st_passage__trigger = "signal",
    st_flat__trigger = "signal",
    st_polarswitch__onoff = "toggle",
    st_quake__trigger = "toggle",
    st_stoneimpulse__trigger = "signal",
    st_switch__onoff = "toggle",
    st_volcano__trigger = "toggle"
}
----------------------
-- old API 1.0      --
----------------------

TRUE = 1
FALSE = 0

EASY = 1
HARD = 2

difficult = options.Difficulty==2

function Tick (deltatime)
    -- do nothing by default
end

if difficult then
    enigma.SetScrambleIntensity(10)
else
    enigma.SetScrambleIntensity(3)
end

----------------------
-- Global variables --
----------------------

level_width = 0
level_height = 0

oxyd_default_flavor = "b"       -- Default flavor for oxyd stones.
oxyd_count = 0
oxyd_current_color = 0

DefaultAttribs = {}

---------------------
-- Helper routines --
---------------------

function PrintTable(t)
    for i,v in pairs(t) do
        if type(v)=="table" then
            print (i.." - "..v[1]..","..v[2])
        else
            print (i.." - "..v)
        end
    end
end


function Require(filename)
    enigma.LoadLib(string.sub(filename,8,string.len(filename)-4))
end


----------------------------------
-- Routines for creating levels --
----------------------------------

function CreateWorld(w, h)
    oxyd_default_flavor = "b"
    oxyd_count = 0
    oxyd_current_color = 0
    DefaultAttribs = {}

    level_width = w
    level_height = h
    world.Resize(w, h)

    -- Make sure there is no tile without a floor.
    -- Otherwise Enigma crashes in some situations.
    fill_floor("fl-metal")
end


function SetDefaultAttribs(objname, attribs)
    local list = DefaultAttribs[objname]
    if list then
        for key,val in pairs(attribs) do list[key] = val end
    else
        DefaultAttribs[objname]= attribs
    end
end

function SetAttrib(obj, key,val)
    if key == "name" then
        enigma.NameObject(obj, val)
    end
    enigma.SetAttrib(obj, key, val)
end

GetAttrib = enigma.GetAttrib
GetKind   = enigma.GetKind

function set_attribs(obj, attrs)
    if not attrs then return end
    if type(attrs) ~= "table" then
        error("Can't assign attributes, expected table but got "..type(attrs)..".")
    end
    for key,val in pairs(attrs) do
        set_attrib(obj, key, val)
    end
end

function MakeObject(name, attrs)
    local obj = enigma.MakeObject(name)
    local a=DefaultAttribs[name]
    if a then set_attribs(obj, a) end
    set_attribs(obj, attrs)
    return obj
end

function set_floor(name, x, y, attrs)
    local obj = make_object(name, attrs)
    enigma.SetFloor(x,y,obj)
    return obj
end
function set_item(name, x, y, attrs)
    local obj = make_object(name, attrs)
    enigma.SetItem(x,y,obj)
    return obj
end
function set_stone(name, x,y, attrs)
    local obj=make_object(name, attrs)
    enigma.SetStone(x,y,obj)
    return obj
end

kill_stone = enigma.KillStone
kill_item = enigma.KillItem

function SendMessage (target, msg, arg)
    if type(target) == "string" then
        enigma.SendMessage (enigma.GetNamedObject (target), msg, arg)
    else
        enigma.SendMessage (target, msg, arg)
    end
end

function SetAttribs (target, attribs)
    if type (target) == "string" then
        set_attribs(enigma.GetNamedObject(target), attribs)
    else
        set_attribs(target, attribs)
    end
end


function AddRubberBand(obj1,obj2, strength,length, minlen)
    enigma.AddRubberBand(obj1,obj2, strength or 10, length or 2, minlen or 0)
end

function fill_floor(name, x0,y0, w,h)
    if x0 == nil then x0 = 0 end
    if y0 == nil then y0 = 0 end
    if w  == nil then w  = level_width end
    if h  == nil then h  = level_height end
    for y=y0,y0 h-1 do
        for x=x0,x0 w-1 do
            set_floor(name, x, y)
        end
    end
end

function fill_items(name, x0,y0,w,h)
    for y=y0,y0 h-1 do
        for x=x0,x0 w-1 do set_item(name, x, y) end
    end
end

function fill_stones(name, x0,y0, w,h)
    for y=y0,y0 h-1 do
        for x=x0,x0 w-1 do set_stone(name, x, y) end
    end
end

function draw_floor(name, xy0, xystep, n, attrs)
    local x,y = xy0[1],xy0[2]
    for i=1,n do
        set_floor(name, x, y, attrs)
        x = x xystep[1]
        y = y xystep[2]
    end
end

function draw_checkerboard_floor (name1, name2, x, y, w, h, attrs)
    if x == nil then x = 0 end
    if y == nil then y = 0 end
    if w  == nil then w  = level_width end
    if h  == nil then h  = level_height end
    for i=1,h do
        for j=1,w do
             if mod(i,2) == mod(j,2) then
                 set_floor (name1, x j-1, y i-1, attrs )
             else
                 set_floor (name2, x j-1, y i-1, attrs )
            end
        end
    end
end

function draw_items(name, xy0, xystep, n, attrs)
    local x,y = xy0[1],xy0[2]
    for i=1,n do
        set_item(name, x, y, attrs)
        x = x xystep[1]
        y = y xystep[2]
    end
end

function draw_stones(name, xy0, xystep, n, attrs)
    local x,y = xy0[1],xy0[2]
    for i=1,n do
        set_stone(name, x, y, attrs)
        x = x xystep[1]
        y = y xystep[2]
    end
end

function draw_border(stonename, x0, y0, w, h)
    if x0 == nil then x0 = 0 end
    if y0 == nil then y0 = 0 end
    if w  == nil then w  = level_width end
    if h  == nil then h  = level_height end
    draw_stones(stonename, {x0,y0}, {1,0}, w)
    draw_stones(stonename, {x0,y0 h-1},{1,0}, w)
    draw_stones(stonename, {x0,y0}, {0,1}, h)
    draw_stones(stonename, {x0 w-1,y0},{0,1}, h)
end

function set_stones(name, poslist, attrs)
    for i,xy in pairs(poslist) do
        set_stone(name, xy[1], xy[2], attrs)
    end
end

function SetActor(name, x, y, attrs)
    local obj=make_object(name, attrs)
    enigma.SetActor(x, y,obj)
    return obj
end

---------------------------------------------
-- Creation of particular kinds of objects --
---------------------------------------------
function fakeoxyd(x,y)
    return set_stone("st-fakeoxyd",x,y)
end


-- Create an oxyd stone with the current default flavor.
function oxyd(x, y, flavor, color)
    local f = flavor or oxyd_default_flavor
    local c = color or oxyd_current_color
    local a = {flavor=f, color=""..c}
    local obj = set_stone("st-oxyd", x, y, a)

    -- if "color" argument not provided, use next available color
    if not color then
        oxyd_count = oxyd_count  1

        if oxyd_count == 2 then
            oxyd_count = 0
            oxyd_current_color = oxyd_current_color   1
        end
    end

    return obj
end

-- Shuffle the colors of all oxyd stones in the current landscape.
function oxyd_shuffle()
    enigma.SendMessage(enigma.GetObjectTemplate("st-oxyd"), "shuffle", nil)
end

-- Close all oxyd stones in the current landscape
function oxyd_closeall()
    enigma.SendMessage(enigma.GetObjectTemplate("st-oxyd"), "closeall", nil)
end

function oneway(x,y,orient)
    return set_stone("st-oneway",x,y,{orientation=orient})
end
function laser(x,y,is_on,dir)
    return set_stone("st-laser",x,y,{on=is_on, dir=dir})
end

function mirrorp(x,y,movable, transp,orient)
    return set_stone("st-pmirror", x, y, {movable=movable, transparent=transp,
                         orientation=orient})
end
function mirror3(x,y,movable, transp, orient)
    return set_stone("st-3mirror", x, y, {movable=movable, transparent=transp,
                         orientation = orient})
end

PUZ_0000=1                      -- hollow
PUZ_0001=2                      -- w
PUZ_0010=3                      -- s
PUZ_0011=4                      -- sw
PUZ_0100=5                      -- e
PUZ_0101=6                      -- ew
PUZ_0110=7                      -- es
PUZ_0111=8                      -- esw
PUZ_1000=9                      -- n
PUZ_1001=10                     -- nw
PUZ_1010=11                     -- ns
PUZ_1011=12                     -- nsw
PUZ_1100=13                     -- ne
PUZ_1101=14                     -- new
PUZ_1110=15                     -- nes
PUZ_1111=16                     -- nesw

-- functions using puzzle-style tiles:

function puzzle(x, y, conn)
    return set_stone("st-puzzle", x,y, {connections=conn})
end
function puzzle2(x, y, conn)
    return set_stone("st-puzzle", x,y, {connections=conn,oxyd=1})
end
function bigbrick(x, y, conn)
   return set_stone("st-bigbrick-n",x,y,{connections=conn})
end

--

function switch(x,y,target,action)
    return set_stone("st-switch", x,y, {target=target, action=action})
end

function abyss(x,y) set_floor("fl-abyss",x,y) end




-----------
-- ITEMS --
-----------
function hollow(x,y) set_item("it-hollow", x,y) end
function Document(x,y,t) set_item("it-document", x, y, {text=t}) end
function hammer(x,y) set_item("it-hammer",x,y) end
function dynamite(x,y) set_item("it-dynamite",x,y) end
function bomb(x,y) set_item("it-blackbomb",x,y) end
function keya(x,y) set_item("it-key", x,y, {keycode=1.0}) end
function keyb(x,y) set_item("it-key", x,y, {keycode=2.0}) end
function keyc(x,y) set_item("it-key", x,y, {keycode=3.0}) end

function shogundot1(x,y,attrs) set_item("it-shogun-s", x, y, attrs) end
function shogundot2(x,y,attrs) set_item("it-shogun-m", x, y, attrs) end
function shogundot3(x,y,attrs) set_item("it-shogun-l", x, y, attrs) end

function Wormhole(x,y,targetx, targety, attribs)
    local attrs = attribs or {}
    attrs.targetx = targetx
    attrs.targety = targety

    set_item("it-wormhole", x,y, attrs)
end

function Doorh(x,y,attrs)
    local attrs = attrs or {}
    attrs.type="h"
    set_stone("st-door",x,y,attrs)
end
function Doorv(x,y,attrs)
    local attrs = attrs or {}
    attrs.type="v"
    set_stone("st-door",x,y,attrs)
end

EAST = enigma.EAST
NORTH = enigma.NORTH
SOUTH = enigma.SOUTH
WEST = enigma.WEST

---------------
-- GRADIENTS --
---------------

SLOPE_S         = 1
SLOPE_N         = 2
SLOPE_E         = 3
SLOPE_W         = 4
SLOPE_LARGE_SE  = 5
SLOPE_LARGE_SW  = 6
SLOPE_LARGE_NE  = 7
SLOPE_LARGE_NW  = 8
SLOPE_SMALL_SE  = 9
SLOPE_SMALL_NE  = 10
SLOPE_SMALL_SW  = 11
SLOPE_SMALL_NW  = 12
SLOPE_S_FORCE_W = 13
SLOPE_N_FORCE_W = 14
SLOPE_S_FORCE_E = 15
SLOPE_N_FORCE_E = 16
SLOPE_E_FORCE_N = 17
SLOPE_W_FORCE_N = 18
SLOPE_E_FORCE_S = 19
SLOPE_W_FORCE_S = 20
FLAT_FORCE_S    = 21
FLAT_FORCE_N    = 22
FLAT_FORCE_E    = 23
FLAT_FORCE_W    = 24

function Gradient( x, y, type )
   if (type==nil) then error("Illegal gradient type"); end
   if (type>=1 and type<=24) then
      set_floor( "fl-gradient", x, y, {type=type} )
   else
      error("Unknown gradient type '"..type.."'");
   end
end


Signal = enigma.AddSignal
SetItem = set_item

----------------------------------------------------
-- Define lowercase aliases for various functions --
----------------------------------------------------

create_world = CreateWorld
get_attrib = GetAttrib
get_kind = GetKind
set_attrib = SetAttrib
make_object = MakeObject
set_actor = SetActor

document = Document
doorh    = Doorh
doorv    = Doorv
gradient = Gradient
wormhole = Wormhole