Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/media/levels/CuboidSpaceStation2.3.lua @ 5312

Last change on this file since 5312 was 5310, checked in by mkaiser, 16 years ago

Some changes.

File size: 34.0 KB
Line 
1-- This lua script creates a totally random generated space station for the orxonox computer game!
2
3
4
5-- This function creates a randomly generated space station.
6-- The first argument ranSeed, must be false, or a positive Integer, if it is false your space station is always chosen randomly, if you give an integer,
7--      your space station will be generated randomly, but once you have the space station it will be the same.
8-- The argument xLen defines how large the space station will be into the x-direction.
9-- The argument xVar defines how much the space station will vary at the ends in x-direction, this is so that the station is no cube.
10-- The argument yLen is the same as xLen, but for the y-direction.
11-- The argument yVar is the same as xLen, but for the y-direction.
12-- The argument zLen is the same as xLen, but for the z-direction.
13-- The argument zVar is the same as xLen, but for the z-direction.
14-- The argument givenScale scales the station proportionally in all directions.
15function createSpaceStationPar(ranSeed, xLen, xVar, yLen, yVar, zLen, zVar, givenScale)
16
17
18
19----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
20-- This prints xml code, which creates a MovableEntity, which I need to attach all the parts of the space station.
21print("<MovableEntity scale=1 position=\"0,0,0\" >")
22-- End create Movable Entity.
23----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
24
25
26
27----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
28-- Create a randomseed, so that the math.random() function is actually random.
29if ranSeed == false then
30        math.randomseed(os.time())
31else
32        math.randomseed(ranSeed)
33end
34-- End create randomseed.
35----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
36
37
38
39----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
40-- Here you can define some global variables, with which you can modify the space station.
41
42-- Define the maximal size of the space station, this is actually just for the grid, be sure that this value is big enough.
43sSSize=30
44
45--if xLen>=yLen and xLen>=zLen then
46--      sSSize=xLen+20
47--elseif yLen>=xLen and yLen>=zLen then
48--      sSSize=yLen+20
49--elseif zLen>=xLen and zLen>=yLen then
50--      sSSize=zLen+20
51--end
52
53-- Define how many parts the space station has, this value has to be exact, so be sure to increment it if you're adding a new part.
54sSParts=9
55-- Define how many body parts the space station has, this value has to be exact. Body part means a part, which has connections at least in two directions.
56sSBodyParts=3
57-- Define how many side parts for the left side you have.
58leftSideParts=1
59-- Define how many side parts for the right side you have.
60rightSideParts=1
61-- Define how many top parts you have.
62topParts=2
63-- Define how many connection parts you have.
64connParts=1
65-- 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.
66pDim=6
67-- Define the length in x-direction of the space station which will be occupied by bodyparts.
68xBPLength=xLen
69-- Define the variation of the edges of your bodyparts in the x-direction.
70xBPVar=xVar
71-- Define the length in y-direction of the space station which will be occupied by bodyparts.
72yBPLength=yLen
73-- Define the variation of the edges of your bodyparts in the y-direction.
74yBPVar=yVar
75-- Define the length in the z-direction of the space station which will be occupied by bodyparts.
76zBPLength=zLen
77-- Define the variation of the edges of your bodyparts in the z-direction.
78zBPVar=zVar
79-- Define the scale of the space station.
80sSScale=givenScale
81-- 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:
82--      integer*(gridDim-connectionSize), then integer tells you how many griddimensions your part is.
83gridDim=2.25
84-- End define global parameters.
85----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
86
87
88
89----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
90-- This creates a 4-dimensional grid, which tells us if there is a part or not, and in which direction it has connections.
91-- The parameters x,y,z are the axis of the space station, which iterate to sSSize, the maximal size of the space station.
92-- The griddimension, this word I will use later, means that the distance of a point to the next point is gridDim in the game, so the absolute x-axis is x*gridDim*sSScale,
93--      and so on for the other dimensions y and z.
94-- grid[x][y][z][0] contains 0 if there is no part at the position (x,y,z), otherwise 1.
95-- 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,
96--      "-" if there is one in the negative x-direction, "+-" if there are in both x-directions.
97-- 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,
98--      "-" if there is one in the negative y-direction, "+-" if there are in both y-directions.
99-- 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,
100--      "-" if there is one in the negative z-direction, "+-" if there are in both z-directions.
101grid = {}
102for x=-math.floor(sSSize/2),math.floor(sSSize/2) do
103        grid[x] = {}
104        for y=-math.floor(sSSize/2),math.floor(sSSize/2) do
105                grid[x][y]= {}
106                for z=-math.floor(sSSize/2),math.floor(sSSize/2) do
107                        grid[x][y][z]={}
108                        for i=0,3 do
109                                grid[x][y][z][i]=0
110                        end
111                end
112        end
113end
114-- End create 4-dim grid.
115----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
116
117
118
119----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
120-- This creates an array which stores all the parts, it's size is depending on the global values pDim and sSParts.
121-- The first parameter i, tells us how many parts fit into the array, so it iterates from 1 to sSParts, each part has his own value i.
122-- 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.
123--      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
124--      z-axis, then you have to use the coordinate point (0,0,1).
125-- 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.
126--      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, "+-", "+", "-").
127bodyParts={}
128for i=1,sSParts do
129        bodyParts[i]={}
130        for x=-math.floor(pDim/2),math.floor(pDim/2) do
131                bodyParts[i][x]={}
132                for y=-math.floor(pDim/2),math.floor(pDim/2) do
133                        bodyParts[i][x][y]={}
134                        for z=-math.floor(pDim/2),math.floor(pDim/2) do
135                                bodyParts[i][x][y][z]={}
136                                for k=0,3 do
137                                        bodyParts[i][x][y][z][k]=0
138                                end
139                        end
140                end
141        end
142        -- This contains the name of the mesh file.
143        bodyParts[i][0][0][0][4]=""
144        -- This contains the first possible rotation of your part, pitch=... yaw=... roll=... .
145        bodyParts[i][0][0][0][5]=""
146        -- This contains the second possible rotation of your part, pitch=... yaw=... roll=... .
147        bodyParts[i][0][0][0][6]=""
148        -- This contains the third possible rotation of your part, pitch=... yaw=... roll=... .
149        bodyParts[i][0][0][0][7]=""
150        -- Contains the movement rotation, rotationaxis=... rotationrate=... .
151        bodyParts[i][0][0][0][8]=""
152        -- Contains the attachment, if your part has an attachment, e.g. <ParticleEmitter .../>.
153        bodyParts[i][0][0][0][9]=""
154end
155----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
156
157
158
159----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
160-- 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.
161
162-- The part must be inserted so, that the center of reference is at position (0,0,0).
163-- At position bodyParts[i][0][0][0][4] you have to put the mesh name of your part.
164-- 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.
165-- At bodyParts[i][0][0][0][6] you have another possibility to rotate your part in a different way, e.g. for left and right side parts.
166-- At bodyParts[i][0][0][0][7] you have a third possibility to rotate your part, e.g. connection parts must be rotated into 3 different ways.
167-- At bodyParts[i][0][0][0][8] you can rotate your part around his own axis, with rotationaxis="x,y,z" rotationrate=number.
168-- At bodyParts[i][0][0][0][9] you can attach something to your model, e.g. <ParticleEmitter .../>.
169
170-- Insert the CuboidBody, which is only one griddimension and can have connections in every direction.
171bodyParts[1][0][0][0][4]="CuboidBody.mesh"
172
173bodyParts[1][0][0][0][0]=1
174bodyParts[1][0][0][0][1]="+-"
175bodyParts[1][0][0][0][2]="+-"
176bodyParts[1][0][0][0][3]="+-"
177-- End insert CuboidBody.
178
179-- Insert the DoubleCuboidBody, which is two griddimensions long, and one wide and high and can have connections in every direction except in the middle.
180bodyParts[2][0][0][0][4]="DoubleCuboidBody.mesh"
181bodyParts[2][0][0][0][5]="pitch=-90"
182
183bodyParts[2][0][0][0][0]=1
184bodyParts[2][0][0][0][1]="+-"
185bodyParts[2][0][0][0][2]="+-"
186bodyParts[2][0][0][0][3]="-"
187
188bodyParts[2][0][0][1][0]=1
189bodyParts[2][0][0][1][1]="+-"
190bodyParts[2][0][0][1][2]="+-"
191bodyParts[2][0][0][1][3]="+"
192-- End insert DoubleCuboidBody.
193
194-- Insert the CuboidConnectionBody, it is three griddimensions long and one wide and high and can have only connections at griddimension 1
195--      (except the side in direction of griddimension 2) and griddimension 3 (except the side in direction of griddimension 2).
196bodyParts[3][0][0][0][4]="CuboidConnectionBody.mesh"
197bodyParts[3][0][0][0][5]="pitch=-90"
198
199bodyParts[3][0][0][0][0]=1
200bodyParts[3][0][0][0][1]="+-"
201bodyParts[3][0][0][0][2]="+-"
202bodyParts[3][0][0][0][3]="-"
203
204bodyParts[3][0][0][1][0]=1
205
206bodyParts[3][0][0][2][0]=1
207bodyParts[3][0][0][2][1]="+-"
208bodyParts[3][0][0][2][2]="+-"
209bodyParts[3][0][0][2][3]="+"
210-- End insert CuboidConnectionBody.
211----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
212
213----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
214-- Insert the Thruster, which is one griddimension long, wide and high, it can only have a connection into the negative z-direction.
215-- If you're space station has no thrusters, be sure to set thrusterIndex=false, but maybe you can use this also for other parts,
216--      see section Attach thrusters to learn how thrusers are attached at your space station.
217thrusterIndex=4
218bodyParts[thrusterIndex][0][0][0][4]="Thruster.mesh"
219bodyParts[thrusterIndex][0][0][0][5]="pitch=-90"
220bodyParts[thrusterIndex][0][0][0][9]="<ParticleEmitter position=\"0,0,0\" source=\"Orxonox/fire3\" />"
221
222bodyParts[thrusterIndex][0][0][0][0]=1
223bodyParts[thrusterIndex][0][0][0][3]="-"
224--End insert the Thruster.
225----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
226
227----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
228-- Insert the Cockpit. If your space station has no cockpit, be sure to set cockpitIndex=false.
229-- 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.
230cockpitIndex=5
231bodyParts[cockpitIndex][0][0][0][4]="SemiCircleCockpit.mesh"
232bodyParts[cockpitIndex][0][0][0][5]="pitch=-90 yaw=180"
233
234bodyParts[cockpitIndex][0][0][0][0]=1
235bodyParts[cockpitIndex][0][0][0][3]="+"
236
237bodyParts[cockpitIndex][-1][0][0][0]=1
238bodyParts[cockpitIndex][1][0][0][0]=1
239bodyParts[cockpitIndex][0][-1][0][0]=1
240bodyParts[cockpitIndex][0][1][0][0]=1
241bodyParts[cockpitIndex][-1][-1][0][0]=1
242bodyParts[cockpitIndex][1][-1][0][0]=1
243bodyParts[cockpitIndex][-1][1][0][0]=1
244bodyParts[cockpitIndex][1][1][0][0]=1
245bodyParts[cockpitIndex][0][0][-1][0]=1
246bodyParts[cockpitIndex][-1][0][-1][0]=1
247bodyParts[cockpitIndex][1][0][-1][0]=1
248bodyParts[cockpitIndex][0][-1][-1][0]=1
249bodyParts[cockpitIndex][0][1][-1][0]=1
250bodyParts[cockpitIndex][-1][-1][-1][0]=1
251bodyParts[cockpitIndex][1][-1][-1][0]=1
252bodyParts[cockpitIndex][-1][1][-1][0]=1
253bodyParts[cockpitIndex][1][1][-1][0]=1
254-- End insert Cockpit.
255----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
256
257----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
258-- Insert the side parts.
259-- If your space station has no left side parts, be sure to set leftsidePartsIndex[0]=false.
260-- If your space station has no right side parts, be sure to set rightsidePartsIndex[0]=false.
261leftSidePartsIndex={}
262leftSidePartsIndex[0]=""
263rightSidePartsIndex={}
264rightSidePartsIndex[0]=""
265
266-- Insert the solar panel, which i wanna use as left and right side part.
267leftSidePartsIndex[1]=6
268rightSidePartsIndex[1]=leftSidePartsIndex[1]
269bodyParts[leftSidePartsIndex[1]][0][0][0][4]="SolarPanel.mesh"
270bodyParts[leftSidePartsIndex[1]][0][0][0][5]="roll=90 pitch="..math.random(0,180)
271bodyParts[rightSidePartsIndex[1]][0][0][0][6]="roll=-90 pitch="..math.random(0,180)
272bodyParts[rightSidePartsIndex[1]][0][0][0][8]="rotationaxis=\"1,0,0\" rotationrate=5"
273bodyParts[leftSidePartsIndex[1]][0][0][0][0]=1
274bodyParts[leftSidePartsIndex[1]][0][0][1][0]=1
275bodyParts[leftSidePartsIndex[1]][0][0][-1][0]=1
276bodyParts[leftSidePartsIndex[1]][0][1][0][0]=1
277bodyParts[leftSidePartsIndex[1]][0][1][1][0]=1
278bodyParts[leftSidePartsIndex[1]][0][1][-1][0]=1
279bodyParts[leftSidePartsIndex[1]][0][-1][0][0]=1
280bodyParts[leftSidePartsIndex[1]][0][-1][1][0]=1
281bodyParts[leftSidePartsIndex[1]][0][-1][-1][0]=1
282-- End insert solar panel.
283
284-- End insert side parts.
285----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
286
287----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
288-- Insert the top parts.
289-- If you have no top parts, be sure to set topPartsIndex[0]=false
290topPartsIndex={}
291topPartsIndex[0]=""
292
293-- Insert the CuboidLandingZone.
294topPartsIndex[1]=7
295bodyParts[topPartsIndex[1]][0][0][0][4]="CuboidLandingZone.mesh"
296bodyParts[topPartsIndex[1]][0][0][0][5]="pitch=-90"
297
298bodyParts[topPartsIndex[1]][0][0][0][0]=1
299bodyParts[topPartsIndex[1]][0][0][0][2]="+-"
300bodyParts[topPartsIndex[1]][1][0][0][0]=1
301bodyParts[topPartsIndex[1]][-1][0][0][0]=1
302bodyParts[topPartsIndex[1]][0][0][1][0]=1
303bodyParts[topPartsIndex[1]][1][0][1][0]=1
304bodyParts[topPartsIndex[1]][-1][0][1][0]=1
305bodyParts[topPartsIndex[1]][0][0][2][0]=1
306bodyParts[topPartsIndex[1]][1][0][2][0]=1
307bodyParts[topPartsIndex[1]][-1][0][2][0]=1
308bodyParts[topPartsIndex[1]][0][0][3][0]=1
309bodyParts[topPartsIndex[1]][1][0][3][0]=1
310bodyParts[topPartsIndex[1]][-1][0][3][0]=1
311-- End insert the CuboidLanding Zone.
312
313-- Insert the SatelliteDish.
314topPartsIndex[2]=8
315bodyParts[topPartsIndex[2]][0][0][0][4]="SatelliteDish.mesh"
316bodyParts[topPartsIndex[2]][0][0][0][5]="pitch=-90"
317bodyParts[topPartsIndex[2]][0][0][0][8]="rotationaxis=\"0,1,0\" rotationrate=5"
318bodyParts[topPartsIndex[2]][0][0][0][0]=1
319bodyParts[topPartsIndex[2]][0][0][1][0]=1
320bodyParts[topPartsIndex[2]][0][0][-1][0]=1
321bodyParts[topPartsIndex[2]][1][0][0][0]=1
322bodyParts[topPartsIndex[2]][1][0][1][0]=1
323bodyParts[topPartsIndex[2]][1][0][-1][0]=1
324bodyParts[topPartsIndex[2]][-1][0][0][0]=1
325bodyParts[topPartsIndex[2]][-1][0][1][0]=1
326bodyParts[topPartsIndex[2]][-1][0][-1][0]=1
327-- End insert the SatelliteDish.
328
329-- End insert the top parts.
330----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
331
332----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
333-- Insert the connectionparts, which are used to connect all the bodyparts.
334-- If you're spacestation has no connectionparts, be sure to set connPartsIndex[0]=false.
335connPartsIndex={}
336connPartsIndex[0]=""
337
338-- Insert the CuboidConnection.
339connPartsIndex[1]=9
340bodyParts[connPartsIndex[1]][0][0][0][4]="CuboidConnection.mesh"
341bodyParts[connPartsIndex[1]][0][0][0][5]="roll=90"
342bodyParts[connPartsIndex[1]][0][0][0][6]=""
343bodyParts[connPartsIndex[1]][0][0][0][7]="pitch=90"
344-- End insert the CuboidConnection.
345
346-- End insert the connectionparts.
347
348-- End create array bodyParts.
349----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
350
351
352
353----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
354-- Here I define some functions which I will use later.
355
356--This function actualizes the grid, which I have to call always after I have added a new part to the space station.
357function actualizeGrid(Index,x,y,z)
358        for i=math.floor(-pDim/2),math.floor(pDim/2) do
359                for j=math.floor(-pDim/2),math.floor(pDim/2) do
360                        for k=math.floor(-pDim/2),math.floor(pDim/2) do
361                                if bodyParts[Index][i][j][k][0] == 1 then
362                                        for l=0,3 do
363                                                grid[x+i][y+j][z+k][l] = bodyParts[Index][i][j][k][l]
364                                        end
365                                end
366                        end
367                end
368        end
369end
370-- End actualizeGrid.
371
372-- This function checks wheter a given parts fits at that position or not.
373-- If the part fits there it returns 1, otherwise 0.
374function checkPart(Index,x,y,z)
375        check=1
376        for i=math.floor(-pDim/2),math.floor(pDim/2) do
377                for j=math.floor(-pDim/2),math.floor(pDim/2) do
378                        for k=math.floor(-pDim/2),math.floor(pDim/2) do
379                                -- If the part occupies the position (i,j,k), the grid must be empty there ((x+i, y+j, z+k)==0), if not, check is zero,
380                                --      which means that the part doesn't fit there.
381                                if bodyParts[Index][i][j][k][0] == 1 and grid[x+i][y+j][z+k][0] == 1 then
382                                        check=0
383                                end
384                        end
385                end
386        end
387        return check
388end
389-- End checkPart function.
390
391-- This function prints the model with tempPartIndex in the bodyParts array at position lx,ly,lz.
392-- If you need to rotate the model around his own axis, then you have to set movEntity true and define the details of the rotation in
393--      bodyParts[tempPartIndex][0][0][0][8].
394-- If your model needs to be rotated like bodyParts[tempPartIndex][0][0][0][5], then side must be 1, for bodyParts[tempPartIndex][0][0][0][6] side must be 2,
395--      for bodyParts[tempPartIndex][0][0][0][7] side must be 3.
396function printModel(lx,ly,lz,tempPartIndex,movEntity,side)
397        if movEntity == true then
398                print("<MovableEntity scale=1 position=\"") print(lx*gridDim*sSScale) print(",") print(ly*gridDim*sSScale) print(",") print(lz*gridDim*sSScale) print("\" ")
399                print(bodyParts[tempPartIndex][0][0][0][8]) print(">")
400                print("<attached>")
401                lx=0 ly=0 lz=0
402        end
403
404        print("<Model position=\"") print(lx*gridDim*sSScale) print(",") print(ly*gridDim*sSScale) print(",") print(lz*gridDim*sSScale)
405        print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[tempPartIndex][0][0][0][4]) print("\"")
406
407                if side == 1 then
408                        print(bodyParts[tempPartIndex][0][0][0][5]) print(">")
409                elseif side == 2 then
410                        print(bodyParts[tempPartIndex][0][0][0][6]) print(">")
411                elseif side == 3 then
412                        print(bodyParts[tempPartIndex][0][0][0][7]) print(">")
413                end
414
415                print("<attached>")
416                        print(bodyParts[tempPartIndex][0][0][0][9])
417                print("</attached>")
418
419        print("</Model>")
420
421        if movEntity == true then
422                print("</attached>")
423                print("</MovableEntity>")
424        end
425end
426-- End function printModel()
427
428-- End define functions.
429----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
430
431
432
433----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
434-- This is xml code, which means now we attach some parts to the MovableEntity.
435print("<attached>")
436-- End attach to the MovableEntity.
437----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
438
439
440
441----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
442-- Attach all bodyparts.
443-- Define at which position in the x-direction you're space station will start.
444x=math.random(-math.floor(xBPLength/2),-math.floor(xBPLength/2)+xBPVar)
445-- Define at which position in the x-direction you're space station will end.
446xMax=math.random(math.floor(xBPLength/2),math.floor(xBPLength/2)+xBPVar)
447while x<xMax do
448        -- The same for the y- and z-direction.
449        y=math.random(-math.floor(yBPLength/2),-math.floor(yBPLength/2)+yBPVar)
450        yMax=math.random(math.floor(yBPLength/2),math.floor(yBPLength/2)+yBPVar)
451        while y<yMax do
452                yMax=math.random(math.floor(yBPLength/2),math.floor(yBPLength/2)+yBPVar)
453                z=math.random(-math.floor(zBPLength/2),-math.floor(zBPLength/2)+zBPVar)
454                zMax=math.random(math.floor(zBPLength/2),math.floor(zBPLength/2)+zBPVar)
455                while z<zMax do
456                        -- This loop choses a bodypart, which fits at position (x,y,z).
457                        -- If after the fifth time the part does still not fit we terminate the loop and set no part at postition (x,y,z).
458                        partSet=0
459                        counter=0
460                        while counter<5 and partSet==0 do
461                                -- This choses randomly a bodyPartIndex, which is the index used for the parts in the array bodyParts.
462                                tempBodyPartIndex=math.random(1,sSBodyParts)
463                                check=checkPart(tempBodyPartIndex,x,y,z)
464                                -- If check == 1, this means that the part fits there, so we put it there and break the while true loop, to go on.
465                                if check == 1 then
466                                        -- This prints the chosen part at position (x*gridDim*sSScale,y*gridDim*sSScale,z*gridDim*sSScale).
467                                        printModel(x,y,z,tempBodyPartIndex,false,1)
468                                        -- This actualizes the grid array with the values of the array bodyParts at the position tempBodyPartIndex, which is our randomly chosen part.
469                                        actualizeGrid(tempBodyPartIndex,x,y,z)
470                                        partSet=1
471                                end
472                                counter=counter+1
473                        end
474                        z=z+1
475                end
476                y=y+1
477        end
478        x=x+1
479end
480-- End attach all bodyparts.
481----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
482
483
484
485----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
486-- Attach thrusters, if there are some.
487if thrusterIndex ~= false then
488        -- To attach thrusters we start at (-sSSize/2,-sSSize/2,-sSSize/2+1) and iterate through x and y as start points and then through z,
489        --      where we go as long as there are parts, at the first position where isn't a part we set our thruster.
490        for x=math.floor(-sSSize/2),math.floor(sSSize/2) do
491                for y=math.floor(-sSSize/2),math.floor(sSSize/2) do
492                         for z=math.floor(-sSSize/2)+1,math.floor(sSSize/2) do
493                                if grid[x][y][z-1][0] == 1 and grid[x][y][z][0] == 0 then
494                                        -- This prints the thruster.
495                                        printModel(x,y,z,thrusterIndex,false,1)
496                                        -- This actualizes the grid array with the values of the array bodyParts at the position thrusterIndex.
497                                        actualizeGrid(thrusterIndex,x,y,z)
498                                        -- This breaks out of the for z=-sSSize/2+1,sSSize/2 loop, because we have set one thruster and for the z-axis that is all we want.
499                                        break
500                                end
501                        end
502                end
503        end
504end
505-- End attach Thrusters.
506----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
507
508
509
510----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
511-- Attach cockpit, if there is one.
512function setCockpit()
513        if grid[x][y][z][0] == 0 and grid[x][y][z+1][0] == 1 then
514                -- This checks whether the cockpits fits at that position or not.
515                check=checkPart(cockpitIndex,x,y,z)
516                if check == 1 then
517                        -- This prints the cockpit.
518                        printModel(x,y,z,cockpitIndex,false,1)
519                        cockpitSet=1
520                        -- This actualizes the grid array with the values of the array bodyParts at the position cockpitIndex.
521                        actualizeGrid(cockpitIndex,x,y,z)
522                end
523        end
524end
525
526if cockpitIndex ~= false then
527        cockpitSet=0
528        z=math.floor(-sSSize/2)
529        while z<=math.floor(sSSize/2)-1 and cockpitSet==0 do
530                round=0
531                while round<=math.floor(sSSize/2)-1 and cockpitSet==0 do
532                        y=round
533                        x=-round
534                        while x<=round and cockpitSet==0 do
535                                setCockpit()
536                                x=x+1
537                        end
538                        while y>=-round and cockpitSet==0 do
539                                setCockpit()
540                                y=y-1
541                        end
542                        while x>-round and cockpitSet==0 do
543                                setCockpit()
544                                x=x-1
545                        end
546                        while y<=round and cockpitSet==0 do
547                                setCockpit()
548                                y=y+1
549                        end
550                        round=round+1
551                end
552                z=z+1
553        end
554end
555-- End attach cockpit.
556----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
557
558
559
560----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
561-- Attach parts on the left side of the space station.
562function setLeftSidePart()
563        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
564                -- This checks whether the parts fits at position x,y,z or not.
565                check=checkPart(tempSidePartIndex,x,y,z)
566                if check == 1 then
567                        -- This prints the part.
568                        printModel(x,y,z,tempSidePartIndex,true,1)
569                        partSet=1
570                        -- This actualizes the grid array with the values of the array bodyParts at the position tempSidePartIndex.
571                        actualizeGrid(tempSidePartIndex,x,y,z)
572                end
573
574        end
575end
576
577if leftSidePartsIndex[0] ~= false then
578        for sPC=1,leftSideParts do
579                tempSidePartIndex = leftSidePartsIndex[math.random(1,leftSideParts)]
580                partSet=0
581                x=math.floor(-sSSize/2)
582                while x<=math.floor(sSSize/2)-1 and partSet==0 do
583                        round=0
584                        while round<=math.floor(sSSize/2)-1 and partSet==0 do
585                                y=round
586                                z=-round
587                                while z<=round and partSet==0 do
588                                        setLeftSidePart()
589                                        z=z+1
590                                end
591                                while y>=-round and partSet==0 do
592                                        setLeftSidePart()
593                                        y=y-1
594                                end
595                                while z>=-round and partSet==0 do
596                                        setLeftSidePart()
597                                        z=z-1
598                                end
599                                while y<=round and partSet==0 do
600                                        setLeftSidePart()
601                                        y=y+1
602                                end
603                                round=round+1
604                        end
605                        x=x+1
606                end
607        end
608end
609-- End attach left side parts.
610----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
611
612
613
614----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
615-- Attach parts on the right side of the space station.
616function setRightSidePart()
617        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
618                -- This checks whether the part fits or not.
619                check=checkPart(tempSidePartIndex,x,y,z)
620                if check == 1 then
621                        -- This prints the part.
622                        printModel(x,y,z,tempSidePartIndex,true,2)
623                        partSet=1
624                        -- This actualizes the grid array with the values of the array bodyParts at the position tempSidePartIndex.
625                        actualizeGrid(tempSidePartIndex,x,y,z)
626                end
627
628        end
629end
630
631if rightSidePartsIndex[0] ~= false then
632        for sPC=1,rightSideParts do
633                tempSidePartIndex = rightSidePartsIndex[math.random(1,rightSideParts)]
634                partSet=0
635                x=math.floor(sSSize/2)
636                while x>=math.floor(-sSSize/2)+1 and partSet==0 do
637                        round=0
638                        while round<=math.floor(sSSize/2)-1 and partSet==0 do
639                                y=round
640                                z=-round
641                                while z<=round and partSet==0 do
642                                        setRightSidePart()
643                                        z=z+1
644                                end
645                                while y>=-round and partSet==0 do
646                                        setRightSidePart()
647                                        y=y-1
648                                end
649                                while z>=-round and partSet==0 do
650                                        setRightSidePart()
651                                        z=z-1
652                                end
653                                while y<=round and partSet==0 do
654                                        setRightSidePart()
655                                        y=y+1
656                                end
657                                round=round+1
658                        end
659                        x=x-1
660                end
661        end
662end
663-- End attach right side parts.
664----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
665
666
667
668----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
669-- Attach parts on top of the space station.
670function setTopPart()
671        if grid[x][y][z][0] == 0 and grid[x][y-1][z][0] == 1 and (grid[x][y-1][z][2] == "+-" or grid[x][y-1][z][2] == "+") then
672                -- This checks whether the part fits or not.
673                check=checkPart(tempTopPartIndex,x,y,z)
674                if check == 1 then
675                        -- This prints the part.
676                        printModel(x,y,z,tempTopPartIndex,true,1)
677                        partSet=1
678                        -- This actualizes the grid array with the values of the array bodyParts at the position tempTopPartIndex.
679                        actualizeGrid(tempTopPartIndex,x,y,z)
680                end
681        end
682end
683
684if topPartsIndex[0] ~= false then
685        for sPC=1,topParts do
686                tempTopPartIndex = topPartsIndex[sPC]
687                partSet=0
688                y=math.floor(sSSize/2)
689                while y>=math.floor(-sSSize/2)+1 and partSet==0 do
690                        round=0
691                        while round<=math.floor(sSSize/2)-1 and partSet==0 do
692                                x=round
693                                z=-round
694                                while z<=round and partSet==0 do
695                                        setTopPart()
696                                        z=z+1
697                                end
698                                while x>=-round and partSet==0 do
699                                        setTopPart()
700                                        x=x-1
701                                end
702                                while z>=-round and partSet==0 do
703                                        setTopPart()
704                                        z=z-1
705                                end
706                                while x<=round and partSet==0 do
707                                        setTopPart()
708                                        x=x+1
709                                end
710                                round=round+1
711                        end
712                        y=y-1
713                end
714        end
715end
716-- End attach top parts.
717----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
718
719
720
721----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
722-- Attach all connectionparts.
723-- This iterates through the whole grid array.
724if connPartsIndex[0] ~= false then
725        for x=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do
726                for y=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do
727                        for z=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do
728                                tempConnPartIndex=connPartsIndex[math.random(1,connParts)]
729                                -- 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
730                                --      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
731                                --      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.
732                                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
733                                        -- This prints the connection part, the +1/2 is because the connection is set exactly in the middle of two gridpoints.
734                                        printModel(x+1/2,y,z,tempConnPartIndex,false,1)
735                                end
736                                -- The same as in the x-direction, but for the y-direction.
737                                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
738                                        printModel(x,y+1/2,z,tempConnPartIndex,false,2)
739                                end
740                                -- The same as in the x-direction, but for the z-direction.
741                                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
742                                        printModel(x,y,z+1/2,tempConnPartIndex,false,3)
743                                end
744                        end
745                end
746        end
747end
748-- End attach all connectionparts.
749----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
750
751
752
753----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
754-- This is xml code, which ends the attachment and the MovableEntity.
755print("</attached>")
756print("</MovableEntity>")
757-- End ends attachment and MovableEntity.
758----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
759
760
761
762-- End the createSpaceStation function.
763end
764
765
766-- This function is for the lazy guys, which do not care how the space station looks like, so I use some good standard values.
767function createSpaceStation()
768        createSpaceStationPar(false,4,1,2,1,6,1,100)
769end
770
Note: See TracBrowser for help on using the repository browser.