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 |
-- Autofringe Script
-- Robert Edwards 2003
-- This script is in the public domain and can be used for any purpose
-- I just hope its useful.
function ShowError(message)
mappy.msgBox("Error ...", message, mappy.MMB_OK, mappy.MMB_ICONEXCLAMATION)
end
function ShowMessage(message)
mappy.msgBox("Message ...", message, mappy.MMB_OK, mappy.MMB_ICONNONE)
end
function TestBlock(i, j, testfor)
toff = 0
if mappy.getBlock(i,j) == testfor then
return 0
end
if j-1 > 0 then
if mappy.getBlock(i,j-1) == testfor then
toff = mappy.orVal(1, toff)
end
end
if j+1 < mappy.getValue(mappy.MAPHEIGHT) then
if mappy.getBlock(i,j+1) == testfor then
toff = mappy.orVal(2, toff)
end
end
if i-1 > 0 then
if mappy.getBlock(i-1,j) == testfor then
toff = mappy.orVal(4, toff)
end
end
if i+1 < mappy.getValue(mappy.MAPWIDTH) then
if mappy.getBlock(i+1,j) == testfor then
toff = mappy.orVal(8, toff)
end
end
if mappy.andVal(toff,15) == 0 then
-- this is a could be a corner piece
-- so check the corners
if i-1 > 0 then
if j-1 > 0 then
if mappy.getBlock(i-1,j-1) == testfor then
toff = mappy.orVal(16,toff)
end
end
if j+1 < mappy.getValue(mappy.MAPHEIGHT) then
if mappy.getBlock(i-1,j+1) == testfor then
toff = mappy.orVal(32,toff)
end
end
end
if i+1 < mappy.getValue(mappy.MAPWIDTH) then
if j-1 > 0 then
if mappy.getBlock(i+1,j-1) == testfor then
toff = mappy.orVal(64,toff)
end
end
if j+1 < mappy.getValue(mappy.MAPHEIGHT) then
if mappy.getBlock(i+1,j+1) == testfor then
toff = mappy.orVal(128,toff)
end
end
end
if toff == 16 then
return 8
end
if toff == 32 then
return 6
end
if toff == 64 then
return 7
end
if toff == 128 then
return 5
end
else
-- try to identify the type of piece
if toff == 2 then
return 12
end
if toff == 1 then
return 11
end
if toff == 4 then
return 9
end
if toff == 8 then
return 10
end
if toff == mappy.andVal(toff,10) then
return 4
end
if toff == mappy.andVal(toff,6) then
return 3
end
if toff == mappy.andVal(toff,9) then
return 2
end
if toff == mappy.andVal(toff,5) then
return 1
end
end
return 0
end
function main()
if mappy.msgBox("AutoFringe", "This will automatically fringe the selected block", mappy.MMB_OKCANCEL, mappy.MMB_ICONQUESTION ) == mappy.MMB_OK then
mappy.copyLayer(mappy.getValue(mappy.CURLAYER),mappy.MPY_UNDO)
cur_block = mappy.getValue(mappy.CURBLOCK)
w,h = mappy.getValue(mappy.MAPWIDTH),mappy.getValue(mappy.MAPHEIGHT)
for j = 0,(h-1) do
for i= 0,(w-1) do
a = TestBlock(i,j, cur_block)
if a > 0 then
mappy.setBlock( i,j,cur_block+a)
end
end
end
mappy.updateScreen()
end
end
test, errormsg = pcall( main )
if not test then
ShowError(errormsg)
end |