Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/contentcreation/pps/MirkoKaiser/CuboidSS/Version1/SpaceStation1.0.lua @ 6638

Last change on this file since 6638 was 5300, checked in by mkaiser, 16 years ago

New build.

File size: 22.3 KB
Line 
1<?lua
2-- This lua script creates a totally random generated space station for the orxonox computer game!
3
4
5
6-- This prints xml code, which creates a MovableEntity, which I need to attach all the parts of the space station, if you want to move, rotate or displace the whole space station, this is the line you have to change.
7print("<MovableEntity scale=1 position=\"0,0,-1000\" velocity=\"0,0,0\" rotationaxis=\"0,0,1\" rotationrate=0>")
8
9
10
11-- Create a randomseed, so that the math.random() function is actually random.
12        math.randomseed(os.time())
13-- End create randomseed.
14
15
16
17-- Here you can define some global variables, with which you can modify the space station.
18        -- Define the maximal size of the space station, this is actually just for the grid, be sure that this value is enough big.
19        -- To actually define the size of the space station you have to change the values in the section Attach all bodyparts, be sure that that values are some griddimensions (at least the sSSize-(pDim)) smaller than sSSize.
20        sSSize=30
21        -- Define how many parts the space station have, this value has to be exact, so be sure to increment if you're adding a new part.
22        sSParts=6
23        -- Define how many body parts the space station have, this value has to be exact. Body part means a part, which has connections at least in two directions.
24        sSBodyParts=3
25        -- Define how many side parts for the left side you have.
26        leftSideParts=1
27        -- Define which index your left side parts have.
28        leftSidePartsIndex={}
29        -- Define the maximal dimension of a single part, be sure this value is big enough, better it's too big, it's only a matter of efficiency.
30        pDim=6
31        -- Define the length in x-direction of the space station which will be occupied by bodyparts.
32        xBPLength=3
33        -- Define the variation of the edges of your bodyparts in the x-direction.
34        xBPVar=1
35        -- Define the length in y-direction of the space station which will be occupied by bodyparts.
36        yBPLength=3
37        -- Define the variation of the edges of your bodyparts in the y-direction.
38        yBPVar=1
39        -- Define the length in the z-direction of the space station which will be occupied by bodyparts.
40        zBPLength=6
41        -- Define the variation of the edges of your bodyparts in the z-direction.
42        zBPVar=1
43        -- Define the scale of the space station.
44        sSScale=100
45        -- Define the griddimension, be sure this value matches the size of a single space station part plus the size of a connection part, which means your parts must be: integer*(gridDim-connectionSize), then integer tells you how many griddimensions your part is.
46        gridDim=2.25
47-- End define global parameters.
48
49
50
51-- This creates a 4-dimensional grid, which tells us if there is a part or not, and in which direction it has connections.
52-- The parameters x,y,z are the axis of the space station, which iterate to sSSize, the maximal size of the space station.
53-- The griddimension, this word I will use later, means that the distance of a point to the next point is 2,25 in the game, so the absolute x-axis is x*2,25*sSScale, and so on for the other dimensions y and z.
54-- grid[x][y][z][0] contains 0 if there is no part at the position (x,y,z), otherwise 1.
55-- grid[x][y][z][1] contains 0 if there is no connection from (x,y,z) in x-direction, "+" if there is one in the positive x-direction, "-" if there is one in the negative x-direction, "+-" if there are in both x-directions.
56-- grid[x][y][z][2] contains 0 if there is no connection from (x,y,z) in y-direction, "+" if there is one in the positive y-direction, "-" if there is one in the negative y-direction, "+-" if there are in both y-directions.
57-- grid[x][y][z][3] contains 0 if there is no connection from (x,y,z) in z-direction, "+" if there is one in the positive z-direction, "-" if there is one in the negative z-direction, "+-" if there are in both z-directions.
58        grid = {}
59        for x=0,sSSize do
60                grid[x] = {}
61                for y=0,sSSize do
62                        grid[x][y]= {}
63                        for z=0,sSSize do
64                                grid[x][y][z]={}
65                                for i=0,3 do
66                                        grid[x][y][z][i]=0
67                                end
68                        end
69                end
70        end
71-- End create 4-dim grid.
72
73
74
75-- This creates an array which stores all the bodyparts, it's size is depending on the global values pDim and sSParts.
76-- The first parameter i, tells us how many parts fit into the array, so it iterates from 0 to sSParts-1, each part has his own value i.
77-- The second, third and fourth parameters are the relative coordinates of the part, you have to start at (0,0,0) and be sure you fill the array into the right direction. A short example: your part is 2 griddimensions long and you place it in the game, that the relative coordinate point is at (0,0,0) and the part lies in the positive z-axis, then you have to use the coordinate point (0,0,1).
78-- The fifth parameter is an array with size 4, at index=0, you have to set 1 if your part covers the gridpoint at (x,y,z), otherwise 0. At index=1,2,3 you define the possible connection directions (1 for x, 2 for y and 3 for z), be sure to use the notation from above (0, "+-", "+", "-").
79        bodyParts={}
80        for i=0,sSParts-1 do
81                bodyParts[i]={}
82                for x=0,pDim do
83                        bodyParts[i][x]={}
84                        for y=0,pDim do
85                                bodyParts[i][x][y]={}
86                                for z=0,pDim do
87                                        bodyParts[i][x][y][z]={}
88                                        for k=0,3 do
89                                                bodyParts[i][x][y][z][k]=0
90                                        end
91                                        bodyParts[i][x][y][z][4]=""
92                                        bodyParts[i][x][y][z][5]=""
93                                end
94                        end
95                end
96        end
97       
98        -- Here you can add a part to the space station, there are some examples here and how to describe your part is written above in the commentary.
99        -- The part must be inserted so, that the center of reference is at position (pDim/2,pDim/2,pDim/2), this is to use negativ positions.
100        -- At position bodyParts[i][0][0][0][4] you have to put the mesh name of your part.
101        -- At bodyParts[i][0][0][0][5] you can rotate your part, with pitch=angle, yaw=angle or roll=angle (x,y or z). Positive angle means in screw direction.
102        -- At bodyParts[i][0][0][0][6] you have to rotate your part so that it fits on the left side of your station, left means in the direction of the negative x-direction. This is to be done if your part is a side part. Also if the part is a sidepart at bodyParts[i][0][0][0][5] you have to rotate the part so that it fits on the right side.
103       
104        -- Insert the CuboidBody, which is only one griddimension and can have connections in every direction.
105        bodyParts[0][0][0][0][4]="CuboidBody.mesh"
106        bodyParts[0][0][0][0][5]=""
107        bodyParts[0][pDim/2][pDim/2][pDim/2][0]=1
108        bodyParts[0][pDim/2][pDim/2][pDim/2][1]="+-"
109        bodyParts[0][pDim/2][pDim/2][pDim/2][2]="+-"
110        bodyParts[0][pDim/2][pDim/2][pDim/2][3]="+-"
111        -- End insert CuboidBody.
112
113        -- Insert the DoubleCuboidBody, which is two griddimensions long, and one wide and high and can have connections in every direction except in the middle.
114        bodyParts[1][0][0][0][4]="DoubleCuboidBody.mesh"
115        bodyParts[1][0][0][0][5]="pitch=-90"
116        bodyParts[1][pDim/2][pDim/2][pDim/2][0]=1
117        bodyParts[1][pDim/2][pDim/2][pDim/2][1]="+-"
118        bodyParts[1][pDim/2][pDim/2][pDim/2][2]="+-"
119        bodyParts[1][pDim/2][pDim/2][pDim/2][3]="-"
120        bodyParts[1][pDim/2][pDim/2][pDim/2+1][0]=1
121        bodyParts[1][pDim/2][pDim/2][pDim/2+1][1]="+-"
122        bodyParts[1][pDim/2][pDim/2][pDim/2+1][2]="+-"
123        bodyParts[1][pDim/2][pDim/2][pDim/2+1][3]="+"
124        -- End insert DoubleCuboidBody.
125
126        -- Insert the CuboidConnectionLong, which is a Bodypart indeed, it is three griddimensions long and one wide and high and can have only connections at griddimension 1 (except the side in direction of griddimension 2) and griddimension 3 (except the side in direction of griddimension 2).
127        bodyParts[2][0][0][0][4]="CuboidConnectionBody.mesh"
128        bodyParts[2][0][0][0][5]="pitch=-90"
129        bodyParts[2][pDim/2][pDim/2][pDim/2][0]=1
130        bodyParts[2][pDim/2][pDim/2][pDim/2][1]="+-"
131        bodyParts[2][pDim/2][pDim/2][pDim/2][2]="+-"
132        bodyParts[2][pDim/2][pDim/2][pDim/2][3]="-"
133        bodyParts[2][pDim/2][pDim/2][pDim/2+1][0]=1
134        bodyParts[2][pDim/2][pDim/2][pDim/2+1][1]=0
135        bodyParts[2][pDim/2][pDim/2][pDim/2+1][2]=0
136        bodyParts[2][pDim/2][pDim/2][pDim/2+1][3]=0
137        bodyParts[2][pDim/2][pDim/2][pDim/2+2][0]=1
138        bodyParts[2][pDim/2][pDim/2][pDim/2+2][1]="+-"
139        bodyParts[2][pDim/2][pDim/2][pDim/2+2][2]="+-"
140        bodyParts[2][pDim/2][pDim/2][pDim/2+2][3]="+"
141        -- End insert CuboidConnectionLong.
142
143        -- Insert the Thruster, which is one griddimension long, wide and high, it can only have a connection into the negative z-direction.
144        -- If you're space station has no thrusters, be sure to set thrusterIndex=false, but maybe you can use this also for other parts, see section Attach thrusters to learn how thrusers are attached at your space station.
145        thrusterIndex=3
146        bodyParts[thrusterIndex][0][0][0][4]="Thruster.mesh"
147        bodyParts[thrusterIndex][0][0][0][5]="pitch=-90"
148        bodyParts[thrusterIndex][pDim/2][pDim/2][pDim/2][0]=1
149        bodyParts[thrusterIndex][pDim/2][pDim/2][pDim/2][1]=0
150        bodyParts[thrusterIndex][pDim/2][pDim/2][pDim/2][2]=0
151        bodyParts[thrusterIndex][pDim/2][pDim/2][pDim/2][3]="-"
152        --End insert the Thruster.
153
154        -- Insert the Cockpit. If your space station has no cockpit, be sure to set cockpitIndex=false.
155        -- The Cockpit is 3 x-griddimensions long, 3 y-griddimensions and 2 z-griddimensions, it can only have a connection in the positive z-direction.
156        cockpitIndex=4
157        bodyParts[cockpitIndex][0][0][0][4]="SemiCircleCockpit.mesh"
158        bodyParts[cockpitIndex][0][0][0][5]="pitch=-90 yaw=180"
159        bodyParts[cockpitIndex][pDim/2][pDim/2][pDim/2][0]=1
160        bodyParts[cockpitIndex][pDim/2][pDim/2][pDim/2][3]="+"
161        bodyParts[cockpitIndex][pDim/2-1][pDim/2][pDim/2][0]=1
162        bodyParts[cockpitIndex][pDim/2+1][pDim/2][pDim/2][0]=1
163        bodyParts[cockpitIndex][pDim/2][pDim/2-1][pDim/2][0]=1
164        bodyParts[cockpitIndex][pDim/2][pDim/2+1][pDim/2][0]=1
165        bodyParts[cockpitIndex][pDim/2-1][pDim/2-1][pDim/2][0]=1
166        bodyParts[cockpitIndex][pDim/2+1][pDim/2-1][pDim/2][0]=1
167        bodyParts[cockpitIndex][pDim/2-1][pDim/2+1][pDim/2][0]=1
168        bodyParts[cockpitIndex][pDim/2+1][pDim/2+1][pDim/2][0]=1
169        bodyParts[cockpitIndex][pDim/2][pDim/2][pDim/2-1][0]=1
170        bodyParts[cockpitIndex][pDim/2-1][pDim/2][pDim/2-1][0]=1
171        bodyParts[cockpitIndex][pDim/2+1][pDim/2][pDim/2-1][0]=1
172        bodyParts[cockpitIndex][pDim/2][pDim/2-1][pDim/2-1][0]=1
173        bodyParts[cockpitIndex][pDim/2][pDim/2+1][pDim/2-1][0]=1
174        bodyParts[cockpitIndex][pDim/2-1][pDim/2-1][pDim/2-1][0]=1
175        bodyParts[cockpitIndex][pDim/2+1][pDim/2-1][pDim/2-1][0]=1
176        bodyParts[cockpitIndex][pDim/2-1][pDim/2+1][pDim/2-1][0]=1
177        bodyParts[cockpitIndex][pDim/2+1][pDim/2+1][pDim/2-1][0]=1
178        -- End insert Cockpit.
179
180        -- Insert the side parts. If your space station has no sideparts, be sure to set sidePartsIndex[0]=false.
181        leftSidePartsIndex[0]=5
182        bodyParts[leftSidePartsIndex[0]][0][0][0][4]="SolarPanel.mesh"
183        panelRot=math.random(0,180)
184        bodyParts[leftSidePartsIndex[0]][0][0][0][5]="roll=90 pitch=90"
185        bodyParts[leftSidePartsIndex[0]][pDim/2][pDim/2][pDim/2][0]=1
186        bodyParts[leftSidePartsIndex[0]][pDim/2][pDim/2][pDim/2+1][0]=1
187        bodyParts[leftSidePartsIndex[0]][pDim/2][pDim/2][pDim/2-1][0]=1
188       
189        -- End insert side parts.
190
191        -- Insert the connectionpart, which is used to connect all the bodyparts.
192        -- If you're spacestation has no connectionpart, be sure to set connPartName=false.
193        connPartName="CuboidConnection.mesh"
194        -- End insert the connectionparts.
195
196-- End create array bodyParts.
197
198
199
200-- This is xml code, which means now we attach some parts to the MovableEntity.
201print("<attached>")
202
203
204
205-- Attach all bodyparts.
206-- This needs some explanation: My grid can't have negative indexes, but if the space station should rotate around it's own middle, i have to put the space station around the point (0,0,0), which means about half of the station has negative coordinates, to solve this problem, i do the following. I start in the middle of my grid (sSSize/2), subtract (BPLength/2) and let it run up to sSSize/2+BPLength/2, so in the grid my bodyparts will be placed around the middle of my grid, with some randomly chosen variation for each coordinate, so my station isn't a cubus. To transform that into the game i simply subtract 1/2*sSSize, so the space station is around the point (0,0,0).
207        -- Define at which position in the x-direction you're space station will start.
208        x=math.random(math.floor(sSSize/2)-xBPLength/2,math.floor(sSSize/2)-xBPLength/2+xBPVar)
209        -- Define at which position in the x-direction you're space station will end.
210        xMax=math.random(math.floor(sSSize/2)+xBPLength/2,math.floor(sSSize/2)+xBPLength/2+xBPVar)
211        while x<xMax do
212                -- The same for the y- and z-direction.
213                y=math.random(math.floor(sSSize/2)-yBPLength/2,math.floor(sSSize/2)-yBPLength/2+yBPVar)
214                yMax=math.random(math.floor(sSSize/2)+yBPLength/2,math.floor(sSSize/2)+yBPLength/2+yBPVar)
215                while y<yMax do
216                        yMax=math.random(math.floor(sSSize/2)+yBPLength/2,math.floor(sSSize/2)+yBPLength/2+yBPVar)
217                        z=math.random(math.floor(sSSize/2)-zBPLength/2,math.floor(sSSize/2)-zBPLength/2+zBPVar)
218                        zMax=math.random(math.floor(sSSize/2)+zBPLength/2,math.floor(sSSize/2)+zBPLength/2+zBPVar)
219                        while z<zMax do
220                                -- This loop choses a bodypart, which fits at position (x,y,z), check=1 is to start the loop, if after the fifth time the part does still not fit we terminate the loop and set no part at postition (x,y,z).
221                                check=1
222                                counter=0
223                                while counter <5 and check==1 do
224                                        -- This choses randomly a bodyPartIndex, which is the index used for the parts in the array bodyParts.
225                                        tempBodyPartIndex=math.random(0,sSBodyParts-1)
226                                        -- Check whether the randomly chosen part fits at that position or not.
227                                        for i=0,pDim do
228                                                for j=0,pDim do
229                                                        for k=0,pDim do
230                                                                -- If the part occupies the position (i,j,k), the grid must be empty there ((x+i-pDim/2, y+j-pDim/2, z+k-pDim/2)==0), if not check is zero, which means that the part doesn't fit there, so we do the while loop again.
231                                                                if bodyParts[tempBodyPartIndex][i][j][k][0] == 1 and grid[x+i-pDim/2][y+j-pDim/2][z+k-pDim/2][0] == 1 then
232                                                                        check=0
233                                                                end
234                                                        end
235                                                end
236                                        end
237                                        -- If check == 1, this means that the part fits there, so we put it there and break the while true loop, to go on.
238                                        if check == 1 then
239                                                -- This is xml code which means at position (x*gridDim*sSScale) will be the randomly chosen part.
240                                                print("<Model position=\"") print((x-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((y-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((z-math.floor(1/2*sSSize))*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[tempBodyPartIndex][0][0][0][4]) print("\"") print(bodyParts[tempBodyPartIndex][0][0][0][5]) print(" />")
241                                                -- This actualizes the grid array with the values of the array bodyParts at the position tempBodyPartIndex, which is our randomly chosen part.
242                                                for i=0,pDim do
243                                                        for j=0,pDim do
244                                                                for k=0,pDim do
245                                                                        if bodyParts[tempBodyPartIndex][i][j][k][0] == 1 then
246                                                                                for l=0,3 do
247                                                                                        grid[x+i-pDim/2][y+j-pDim/2][z+k-pDim/2][l] = bodyParts[tempBodyPartIndex][i][j][k][l]
248                                                                                end
249                                                                        end
250                                                                end
251                                                        end
252                                                end
253                                        end
254                                        counter=counter+1
255                                end
256                                z=z+1
257                        end
258                        y=y+1
259                end
260                x=x+1
261        end
262-- End attach all bodyparts.
263
264
265
266-- Attach thrusters, if there are some.
267        if thrusterIndex ~= false then
268                -- To attach thrusters we start at (0,0,1) and iterate through x and y as start points and then through z, where we go as long as there are parts, at the first position where isn't a part we set our thruster.
269                for x=0,sSSize do
270                        for y=0,sSSize do
271                                 for z=1,sSSize do
272                                        if grid[x][y][z-1][0] == 1 and grid[x][y][z][0] == 0 then
273                                                print("<Model position=\"") print((x-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((y-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((z-math.floor(1/2*sSSize))*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[thrusterIndex][0][0][0][4]) print("\"") print(bodyParts[thrusterIndex][0][0][0][5]) print(" >")
274
275                                        print("<attached>")
276                                                print("<ParticleEmitter position=\"0,0,0\" source=\"Orxonox/fire3\" />")
277                                        print("</attached>")
278                                        print("</Model>")
279
280                                                -- This actualizes the array grid.
281                                                for i=0,pDim do
282                                                        for j=0,pDim do
283                                                                for k=0,pDim do
284                                                                        if bodyParts[tempBodyPartIndex][i][j][k][0] == 1 then
285                                                                                for l=0,3 do
286                                                                                        grid[x+i-pDim/2][y+j-pDim/2][z+k-pDim/2][l] = bodyParts[thrusterIndex][i][j][k][l]
287                                                                                end
288                                                                        end
289                                                                end
290                                                        end
291                                                end
292                                                -- This breaks out of the for z=0,sSSize loop, because we have set one thruster and for the z-axis that is all we want.
293                                                break
294                                        end
295                                end
296                        end
297                end
298        end
299-- End attach Thrusters.
300
301
302
303-- Attach cockpit, if there is one.
304
305function setCockpit()
306        if grid[x][y][z][0] == 0 and grid[x][y][z+1][0] == 1 then
307
308                check=1
309                for i=0,pDim do
310                        for j=0,pDim do
311                                for k=0,pDim do
312                                        if bodyParts[cockpitIndex][i][j][k][0] == 1 and grid[x+i-pDim/2][y+j-pDim/2][z+k-pDim/2][0] == 1 then
313                                                check=0
314                                        end
315                                end
316                        end
317                end
318
319                if check == 1 then
320                        print("<Model position=\"") print((x-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((y-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((z-math.floor(1/2*sSSize))*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[cockpitIndex][0][0][0][4]) print("\"") print(bodyParts[cockpitIndex][0][0][0][5]) print("/>")
321                        cockpitSet=1
322
323                        for i=0,pDim do
324                                for j=0,pDim do
325                                        for k=0,pDim do
326                                                if bodyParts[cockpitIndex][i][j][k][0] == 1 then
327                                                        for l=0,3 do
328                                                                grid[x+i-pDim/2][y+j-pDim/2][z+k-pDim/2][l] = bodyParts[cockpitIndex][i][j][k][l]
329                                                        end
330                                                end
331                                        end
332                                end
333                        end
334
335                end
336
337        end
338end
339
340
341        if cockpitIndex ~= false then
342                cockpitSet=0
343                z=0
344                while z<=sSSize-1 and cockpitSet==0 do
345                        round=0
346                        while round<=math.floor(sSSize/2)-1 and cockpitSet==0 do
347                                y=math.floor(sSSize/2)+round
348                                x=math.floor(sSSize/2)-round
349                                while x<=math.floor(sSSize/2)+round and cockpitSet==0 do
350                                        setCockpit()
351                                        x=x+1
352                                end
353                                while y>=math.floor(sSSize/2)-round and cockpitSet==0 do
354                                        setCockpit()
355                                        y=y-1
356                                end
357                                while x>=math.floor(sSSize/2)-round and cockpitSet==0 do
358                                        setCockpit()
359                                        x=x-1
360                                end
361                                while y<=math.floor(sSSize/2)+round and cockpitSet==0 do
362                                        setCockpit()
363                                        y=y+1
364                                end
365                                round=round+1
366                        end
367                        z=z+1
368                end
369        end
370-- End attach cockpit.
371
372
373
374-- Attach parts on the left side of the space station.
375function setLeftSidePart()
376        if grid[x][y][z][0] == 0 and grid[x+1][y][z][0] == 1 and (grid[x+1][y][z][1] == "+-" or grid[x+1][y][z][1] == "-") then
377
378                check=1
379                for i=0,pDim do
380                        for j=0,pDim do
381                                for k=0,pDim do
382                                        if bodyParts[tempSidePartsIndex][i][j][k][0] == 1 and grid[x+i-pDim/2][y+j-pDim/2][z+k-pDim/2][0] == 1 then
383                                                check=0
384                                        end
385                                end
386                        end
387                end
388
389                if check == 1 then
390                        print("<Model position=\"") print((x-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((y-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((z-math.floor(1/2*sSSize))*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[tempSidePartsIndex][0][0][0][4]) print("\"") print(bodyParts[tempSidePartsIndex][0][0][0][5]) print("/>")
391                        partSet=1
392                        for i=0,pDim do
393                                for j=0,pDim do
394                                        for k=0,pDim do
395                                                if bodyParts[tempSidePartsIndex][i][j][k][0] == 1 then
396                                                        for l=0,3 do
397                                                                grid[x+i-pDim/2][y+j-pDim/2][z+k-pDim/2][l] = bodyParts[tempSidePartsIndex][i][j][k][l]
398                                                        end
399                                                end
400                                        end
401                                end
402                        end
403
404                end
405
406        end
407end
408
409
410        if leftSidePartsIndex[0] ~= false then
411                for sPC=1,leftSideParts do
412                        tempSidePartsIndex = leftSidePartsIndex[math.random(0,leftSideParts-1)]
413                        partSet=0
414                        x=0
415                        while x<=sSSize-1 and partSet==0 do
416                                round=0
417                                while round<=math.floor(sSSize/2)-1 and partSet==0 do
418                                        y=math.floor(sSSize/2)+round
419                                        z=math.floor(sSSize/2)-round
420                                        while z<=math.floor(sSSize/2)+round and partSet==0 do
421                                                setLeftSidePart()
422                                                z=z+1
423                                        end
424                                        while y>=math.floor(sSSize/2)-round and partSet==0 do
425                                                setLeftSidePart()
426                                                y=y-1
427                                        end
428                                        while z>=math.floor(sSSize/2)-round and partSet==0 do
429                                                setLeftSidePart()
430                                                z=z-1
431                                        end
432                                        while y<=math.floor(sSSize/2)+round and partSet==0 do
433                                                setLeftSidePart()
434                                                y=y+1
435                                        end
436                                        round=round+1
437                                end
438                                x=x+1
439                        end
440                end
441        end
442-- End attach side parts.
443
444
445
446-- Attach all connectionparts.
447        -- This iterates through the whole grid array.
448        if connPartName ~= false then
449                for x=0,sSSize-1 do
450                        for y=0,sSSize-1 do
451                                for z=0,sSSize-1 do
452                                        -- This checks whether there has to be a connection part between (x,y,z) and (x+1,y,z) or not. First it checks if there is a part at (x,y,z) and then it checks if that part can have a connection into the positive x-direction, if it can, it checks if there is a part at (x+1,y,z) and if that part can have a connection into the negative x-direction, if both can, it prints the xml code to set a connection part.
453                                        if grid[x][y][z][0]==1 and ( grid[x][y][z][1]=="+" or grid[x][y][z][1]=="+-" ) and grid[x+1][y][z][0]==1 and ( grid[x+1][y][z][1]=="-" or grid[x+1][y][z][1]=="+-" ) then
454                                                -- This is xml code which prints the connection part, the +gridDim*sSScale/2 is because the connection is set exactly in the middle of two gridpoints.
455                                                print("<Model position=\"") print((x-math.floor(1/2*sSSize))*gridDim*sSScale+gridDim*sSScale/2) print(",") print((y-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((z-math.floor(1/2*sSSize))*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh=\"") print(connPartName) print("\" roll=90 />")
456                                        end
457                                        -- The same as in the x-direction, but for the y-direction.
458                                        if grid[x][y][z][0]==1 and ( grid[x][y][z][2]=="+" or grid[x][y][z][2]=="+-" ) and grid[x][y+1][z][0]==1 and ( grid[x][y+1][z][2]=="-" or grid[x][y+1][z][2]=="+-" ) then
459                                                print("<Model position=\"") print((x-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((y-math.floor(1/2*sSSize))*gridDim*sSScale+gridDim*sSScale/2) print(",") print((z-math.floor(1/2*sSSize))*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh=\"") print(connPartName) print("\" />")
460                                        end
461                                        -- The same as in the x-direction, but for the z-direction.
462                                        if grid[x][y][z][0]==1 and ( grid[x][y][z][3]=="+" or grid[x][y][z][3]=="+-" ) and grid[x][y][z+1][0]==1 and ( grid[x][y][z+1][3]=="-" or grid[x][y][z+1][3]=="+-" ) then
463                                                print("<Model position=\"") print((x-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((y-math.floor(1/2*sSSize))*gridDim*sSScale) print(",") print((z-math.floor(1/2*sSSize))*gridDim*sSScale+gridDim*sSScale/2) print("\" scale=") print(sSScale) print(" mesh=\"") print(connPartName) print("\" pitch=90 />")
464                                        end
465                                end
466                        end
467                end
468        end
469-- End attach all connectionparts.
470
471
472
473-- This is xml code, which ends the attachment and the MovableEntity.
474print("</attached>")
475print("</MovableEntity>")
476?>
Note: See TracBrowser for help on using the repository browser.