[5300] | 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. |
---|
| 7 | print("<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 big enough. |
---|
| 19 | sSSize=30 |
---|
| 20 | -- 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. |
---|
| 21 | sSParts=6 |
---|
| 22 | -- 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. |
---|
| 23 | sSBodyParts=3 |
---|
| 24 | -- Define how many side parts for the left side you have. |
---|
| 25 | leftSideParts=1 |
---|
| 26 | -- Define which index your left side parts have. |
---|
| 27 | leftSidePartsIndex={} |
---|
| 28 | -- 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. |
---|
| 29 | pDim=6 |
---|
| 30 | -- Define the length in x-direction of the space station which will be occupied by bodyparts. |
---|
| 31 | xBPLength=4 |
---|
| 32 | -- Define the variation of the edges of your bodyparts in the x-direction. |
---|
| 33 | xBPVar=1 |
---|
| 34 | -- Define the length in y-direction of the space station which will be occupied by bodyparts. |
---|
| 35 | yBPLength=4 |
---|
| 36 | -- Define the variation of the edges of your bodyparts in the y-direction. |
---|
| 37 | yBPVar=1 |
---|
| 38 | -- Define the length in the z-direction of the space station which will be occupied by bodyparts. |
---|
| 39 | zBPLength=6 |
---|
| 40 | -- Define the variation of the edges of your bodyparts in the z-direction. |
---|
| 41 | zBPVar=1 |
---|
| 42 | -- Define the scale of the space station. |
---|
| 43 | sSScale=100 |
---|
| 44 | -- 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. |
---|
| 45 | gridDim=2.25 |
---|
| 46 | -- End define global parameters. |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | -- This creates a 4-dimensional grid, which tells us if there is a part or not, and in which direction it has connections. |
---|
| 51 | -- The parameters x,y,z are the axis of the space station, which iterate to sSSize, the maximal size of the space station. |
---|
| 52 | -- 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. |
---|
| 53 | -- grid[x][y][z][0] contains 0 if there is no part at the position (x,y,z), otherwise 1. |
---|
| 54 | -- 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. |
---|
| 55 | -- 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. |
---|
| 56 | -- 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. |
---|
| 57 | grid = {} |
---|
| 58 | for x=-math.floor(sSSize/2),math.floor(sSSize/2) do |
---|
| 59 | grid[x] = {} |
---|
| 60 | for y=-math.floor(sSSize/2),math.floor(sSSize/2) do |
---|
| 61 | grid[x][y]= {} |
---|
| 62 | for z=-math.floor(sSSize/2),math.floor(sSSize/2) do |
---|
| 63 | grid[x][y][z]={} |
---|
| 64 | for i=0,3 do |
---|
| 65 | grid[x][y][z][i]=0 |
---|
| 66 | end |
---|
| 67 | end |
---|
| 68 | end |
---|
| 69 | end |
---|
| 70 | -- End create 4-dim grid. |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | -- This creates an array which stores all the bodyparts, it's size is depending on the global values pDim and sSParts. |
---|
| 75 | -- 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. |
---|
| 76 | -- 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). |
---|
| 77 | -- 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, "+-", "+", "-"). |
---|
| 78 | bodyParts={} |
---|
| 79 | for i=1,sSParts do |
---|
| 80 | bodyParts[i]={} |
---|
| 81 | for x=-math.floor(pDim/2),math.floor(pDim/2) do |
---|
| 82 | bodyParts[i][x]={} |
---|
| 83 | for y=-math.floor(pDim/2),math.floor(pDim/2) do |
---|
| 84 | bodyParts[i][x][y]={} |
---|
| 85 | for z=-math.floor(pDim/2),math.floor(pDim/2) do |
---|
| 86 | bodyParts[i][x][y][z]={} |
---|
| 87 | for k=0,3 do |
---|
| 88 | bodyParts[i][x][y][z][k]=0 |
---|
| 89 | end |
---|
| 90 | end |
---|
| 91 | end |
---|
| 92 | end |
---|
| 93 | bodyParts[i][0][0][0][4]="" |
---|
| 94 | bodyParts[i][0][0][0][5]="" |
---|
| 95 | end |
---|
| 96 | |
---|
| 97 | -- 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. |
---|
| 98 | -- The part must be inserted so, that the center of reference is at position (0,0,0). |
---|
| 99 | -- At position bodyParts[i][0][0][0][4] you have to put the mesh name of your part. |
---|
| 100 | -- 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. |
---|
| 101 | -- 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. |
---|
| 102 | |
---|
| 103 | -- Insert the CuboidBody, which is only one griddimension and can have connections in every direction. |
---|
| 104 | bodyParts[1][0][0][0][4]="CuboidBody.mesh" |
---|
| 105 | bodyParts[1][0][0][0][5]="" |
---|
| 106 | |
---|
| 107 | bodyParts[1][0][0][0][0]=1 |
---|
| 108 | bodyParts[1][0][0][0][1]="+-" |
---|
| 109 | bodyParts[1][0][0][0][2]="+-" |
---|
| 110 | bodyParts[1][0][0][0][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[2][0][0][0][4]="DoubleCuboidBody.mesh" |
---|
| 115 | bodyParts[2][0][0][0][5]="pitch=-90" |
---|
| 116 | |
---|
| 117 | bodyParts[2][0][0][0][0]=1 |
---|
| 118 | bodyParts[2][0][0][0][1]="+-" |
---|
| 119 | bodyParts[2][0][0][0][2]="+-" |
---|
| 120 | bodyParts[2][0][0][0][3]="-" |
---|
| 121 | |
---|
| 122 | bodyParts[2][0][0][1][0]=1 |
---|
| 123 | bodyParts[2][0][0][1][1]="+-" |
---|
| 124 | bodyParts[2][0][0][1][2]="+-" |
---|
| 125 | bodyParts[2][0][0][1][3]="+" |
---|
| 126 | -- End insert DoubleCuboidBody. |
---|
| 127 | |
---|
| 128 | -- 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). |
---|
| 129 | bodyParts[3][0][0][0][4]="CuboidConnectionBody.mesh" |
---|
| 130 | bodyParts[3][0][0][0][5]="pitch=-90" |
---|
| 131 | |
---|
| 132 | bodyParts[3][0][0][0][0]=1 |
---|
| 133 | bodyParts[3][0][0][0][1]="+-" |
---|
| 134 | bodyParts[3][0][0][0][2]="+-" |
---|
| 135 | bodyParts[3][0][0][0][3]="-" |
---|
| 136 | |
---|
| 137 | bodyParts[3][0][0][1][0]=1 |
---|
| 138 | |
---|
| 139 | bodyParts[3][0][0][2][0]=1 |
---|
| 140 | bodyParts[3][0][0][2][1]="+-" |
---|
| 141 | bodyParts[3][0][0][2][2]="+-" |
---|
| 142 | bodyParts[3][0][0][2][3]="+" |
---|
| 143 | -- End insert CuboidConnectionLong. |
---|
| 144 | |
---|
| 145 | -- Insert the Thruster, which is one griddimension long, wide and high, it can only have a connection into the negative z-direction. |
---|
| 146 | -- 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. |
---|
| 147 | thrusterIndex=4 |
---|
| 148 | bodyParts[thrusterIndex][0][0][0][4]="Thruster.mesh" |
---|
| 149 | bodyParts[thrusterIndex][0][0][0][5]="pitch=-90" |
---|
| 150 | |
---|
| 151 | bodyParts[thrusterIndex][0][0][0][0]=1 |
---|
| 152 | bodyParts[thrusterIndex][0][0][0][3]="-" |
---|
| 153 | --End insert the Thruster. |
---|
| 154 | |
---|
| 155 | -- Insert the Cockpit. If your space station has no cockpit, be sure to set cockpitIndex=false. |
---|
| 156 | -- 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. |
---|
| 157 | cockpitIndex=5 |
---|
| 158 | bodyParts[cockpitIndex][0][0][0][4]="SemiCircleCockpit.mesh" |
---|
| 159 | bodyParts[cockpitIndex][0][0][0][5]="pitch=-90 yaw=180" |
---|
| 160 | |
---|
| 161 | bodyParts[cockpitIndex][0][0][0][0]=1 |
---|
| 162 | bodyParts[cockpitIndex][0][0][0][3]="+" |
---|
| 163 | |
---|
| 164 | bodyParts[cockpitIndex][-1][0][0][0]=1 |
---|
| 165 | bodyParts[cockpitIndex][1][0][0][0]=1 |
---|
| 166 | bodyParts[cockpitIndex][0][-1][0][0]=1 |
---|
| 167 | bodyParts[cockpitIndex][0][1][0][0]=1 |
---|
| 168 | bodyParts[cockpitIndex][-1][-1][0][0]=1 |
---|
| 169 | bodyParts[cockpitIndex][1][-1][0][0]=1 |
---|
| 170 | bodyParts[cockpitIndex][-1][1][0][0]=1 |
---|
| 171 | bodyParts[cockpitIndex][1][1][0][0]=1 |
---|
| 172 | bodyParts[cockpitIndex][0][0][-1][0]=1 |
---|
| 173 | bodyParts[cockpitIndex][-1][0][-1][0]=1 |
---|
| 174 | bodyParts[cockpitIndex][1][0][-1][0]=1 |
---|
| 175 | bodyParts[cockpitIndex][0][-1][-1][0]=1 |
---|
| 176 | bodyParts[cockpitIndex][0][1][-1][0]=1 |
---|
| 177 | bodyParts[cockpitIndex][-1][-1][-1][0]=1 |
---|
| 178 | bodyParts[cockpitIndex][1][-1][-1][0]=1 |
---|
| 179 | bodyParts[cockpitIndex][-1][1][-1][0]=1 |
---|
| 180 | bodyParts[cockpitIndex][1][1][-1][0]=1 |
---|
| 181 | -- End insert Cockpit. |
---|
| 182 | |
---|
| 183 | -- Insert the side parts. If your space station has no sideparts, be sure to set sidePartsIndex[0]=false. |
---|
| 184 | leftSidePartsIndex[1]=6 |
---|
| 185 | bodyParts[leftSidePartsIndex[1]][0][0][0][4]="SolarPanel.mesh" |
---|
| 186 | panelRot=math.random(0,180) |
---|
| 187 | bodyParts[leftSidePartsIndex[1]][0][0][0][5]="roll=90 pitch="..panelRot |
---|
| 188 | |
---|
| 189 | bodyParts[leftSidePartsIndex[1]][0][0][0][0]=1 |
---|
| 190 | bodyParts[leftSidePartsIndex[1]][0][0][1][0]=1 |
---|
| 191 | bodyParts[leftSidePartsIndex[1]][0][0][-1][0]=1 |
---|
| 192 | -- End insert side parts. |
---|
| 193 | |
---|
| 194 | -- Insert the connectionpart, which is used to connect all the bodyparts. |
---|
| 195 | -- If you're spacestation has no connectionpart, be sure to set connPartName=false. |
---|
| 196 | connPartName="CuboidConnection.mesh" |
---|
| 197 | -- End insert the connectionparts. |
---|
| 198 | |
---|
| 199 | -- End create array bodyParts. |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | -- This is xml code, which means now we attach some parts to the MovableEntity. |
---|
| 204 | print("<attached>") |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | -- Attach all bodyparts. |
---|
| 209 | -- Define at which position in the x-direction you're space station will start. |
---|
| 210 | x=math.random(-math.floor(xBPLength/2),-math.floor(xBPLength/2)+xBPVar) |
---|
| 211 | -- Define at which position in the x-direction you're space station will end. |
---|
| 212 | xMax=math.random(math.floor(xBPLength/2),math.floor(xBPLength/2)+xBPVar) |
---|
| 213 | while x<xMax do |
---|
| 214 | -- The same for the y- and z-direction. |
---|
| 215 | y=math.random(-math.floor(yBPLength/2),-math.floor(yBPLength/2)+yBPVar) |
---|
| 216 | yMax=math.random(math.floor(yBPLength/2),math.floor(yBPLength/2)+yBPVar) |
---|
| 217 | while y<yMax do |
---|
| 218 | yMax=math.random(math.floor(yBPLength/2),math.floor(yBPLength/2)+yBPVar) |
---|
| 219 | z=math.random(-math.floor(zBPLength/2),-math.floor(zBPLength/2)+zBPVar) |
---|
| 220 | zMax=math.random(math.floor(zBPLength/2),math.floor(zBPLength/2)+zBPVar) |
---|
| 221 | while z<zMax do |
---|
| 222 | -- 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). |
---|
| 223 | check=1 |
---|
| 224 | counter=0 |
---|
| 225 | while counter <5 and check==1 do |
---|
| 226 | -- This choses randomly a bodyPartIndex, which is the index used for the parts in the array bodyParts. |
---|
| 227 | tempBodyPartIndex=math.random(1,sSBodyParts) |
---|
| 228 | -- Check whether the randomly chosen part fits at that position or not. |
---|
| 229 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 230 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 231 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 232 | -- 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, which means that the part doesn't fit there, so we do the while loop again. |
---|
| 233 | if bodyParts[tempBodyPartIndex][i][j][k][0] == 1 and grid[x+i][y+j][z+k][0] == 1 then |
---|
| 234 | check=0 |
---|
| 235 | end |
---|
| 236 | end |
---|
| 237 | end |
---|
| 238 | end |
---|
| 239 | -- If check == 1, this means that the part fits there, so we put it there and break the while true loop, to go on. |
---|
| 240 | if check == 1 then |
---|
| 241 | -- This is xml code which means at position (x*gridDim*sSScale) will be the randomly chosen part. |
---|
| 242 | print("<Model position=\"") print(x*gridDim*sSScale) print(",") print(y*gridDim*sSScale) print(",") print(z*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[tempBodyPartIndex][0][0][0][4]) print("\"") print(bodyParts[tempBodyPartIndex][0][0][0][5]) print(" />") |
---|
| 243 | -- This actualizes the grid array with the values of the array bodyParts at the position tempBodyPartIndex, which is our randomly chosen part. |
---|
| 244 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 245 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 246 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 247 | if bodyParts[tempBodyPartIndex][i][j][k][0] == 1 then |
---|
| 248 | for l=0,3 do |
---|
| 249 | grid[x+i][y+j][z+k][l] = bodyParts[tempBodyPartIndex][i][j][k][l] |
---|
| 250 | end |
---|
| 251 | end |
---|
| 252 | end |
---|
| 253 | end |
---|
| 254 | end |
---|
| 255 | end |
---|
| 256 | counter=counter+1 |
---|
| 257 | end |
---|
| 258 | z=z+1 |
---|
| 259 | end |
---|
| 260 | y=y+1 |
---|
| 261 | end |
---|
| 262 | x=x+1 |
---|
| 263 | end |
---|
| 264 | -- End attach all bodyparts. |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | -- Attach thrusters, if there are some. |
---|
| 269 | if thrusterIndex ~= false then |
---|
| 270 | -- 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, where we go as long as there are parts, at the first position where isn't a part we set our thruster. |
---|
| 271 | for x=math.floor(-sSSize/2),math.floor(sSSize/2) do |
---|
| 272 | for y=math.floor(-sSSize/2),math.floor(sSSize/2) do |
---|
| 273 | for z=math.floor(-sSSize/2)+1,math.floor(sSSize/2) do |
---|
| 274 | if grid[x][y][z-1][0] == 1 and grid[x][y][z][0] == 0 then |
---|
| 275 | print("<Model position=\"") print(x*gridDim*sSScale) print(",") print(y*gridDim*sSScale) print(",") print(z*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[thrusterIndex][0][0][0][4]) print("\"") print(bodyParts[thrusterIndex][0][0][0][5]) print(" >") |
---|
| 276 | |
---|
| 277 | print("<attached>") |
---|
| 278 | print("<ParticleEmitter position=\"0,0,0\" source=\"Orxonox/fire3\" />") |
---|
| 279 | print("</attached>") |
---|
| 280 | print("</Model>") |
---|
| 281 | |
---|
| 282 | -- This actualizes the array grid. |
---|
| 283 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 284 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 285 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 286 | if bodyParts[tempBodyPartIndex][i][j][k][0] == 1 then |
---|
| 287 | for l=0,3 do |
---|
| 288 | grid[x+i][y+j][z+k][l] = bodyParts[thrusterIndex][i][j][k][l] |
---|
| 289 | end |
---|
| 290 | end |
---|
| 291 | end |
---|
| 292 | end |
---|
| 293 | end |
---|
| 294 | -- 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. |
---|
| 295 | break |
---|
| 296 | end |
---|
| 297 | end |
---|
| 298 | end |
---|
| 299 | end |
---|
| 300 | end |
---|
| 301 | -- End attach Thrusters. |
---|
| 302 | |
---|
| 303 | |
---|
| 304 | |
---|
| 305 | -- Attach cockpit, if there is one. |
---|
| 306 | |
---|
| 307 | function setCockpit() |
---|
| 308 | if grid[x][y][z][0] == 0 and grid[x][y][z+1][0] == 1 then |
---|
| 309 | |
---|
| 310 | check=1 |
---|
| 311 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 312 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 313 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 314 | if bodyParts[cockpitIndex][i][j][k][0] == 1 and grid[x+i][y+j][z+k][0] == 1 then |
---|
| 315 | check=0 |
---|
| 316 | end |
---|
| 317 | end |
---|
| 318 | end |
---|
| 319 | end |
---|
| 320 | |
---|
| 321 | if check == 1 then |
---|
| 322 | print("<Model position=\"") print(x*gridDim*sSScale) print(",") print(y*gridDim*sSScale) print(",") print(z*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[cockpitIndex][0][0][0][4]) print("\"") print(bodyParts[cockpitIndex][0][0][0][5]) print("/>") |
---|
| 323 | cockpitSet=1 |
---|
| 324 | |
---|
| 325 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 326 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 327 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 328 | if bodyParts[cockpitIndex][i][j][k][0] == 1 then |
---|
| 329 | for l=0,3 do |
---|
| 330 | grid[x+i][y+j][z+k][l] = bodyParts[cockpitIndex][i][j][k][l] |
---|
| 331 | end |
---|
| 332 | end |
---|
| 333 | end |
---|
| 334 | end |
---|
| 335 | end |
---|
| 336 | |
---|
| 337 | end |
---|
| 338 | |
---|
| 339 | end |
---|
| 340 | end |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | if cockpitIndex ~= false then |
---|
| 344 | cockpitSet=0 |
---|
| 345 | z=math.floor(-sSSize/2) |
---|
| 346 | while z<=math.floor(sSSize/2)-1 and cockpitSet==0 do |
---|
| 347 | round=0 |
---|
| 348 | while round<=math.floor(sSSize/2)-1 and cockpitSet==0 do |
---|
| 349 | y=round |
---|
| 350 | x=-round |
---|
| 351 | while x<=round and cockpitSet==0 do |
---|
| 352 | setCockpit() |
---|
| 353 | x=x+1 |
---|
| 354 | end |
---|
| 355 | while y>=-round and cockpitSet==0 do |
---|
| 356 | setCockpit() |
---|
| 357 | y=y-1 |
---|
| 358 | end |
---|
| 359 | while x>-round and cockpitSet==0 do |
---|
| 360 | setCockpit() |
---|
| 361 | x=x-1 |
---|
| 362 | end |
---|
| 363 | while y<=round and cockpitSet==0 do |
---|
| 364 | setCockpit() |
---|
| 365 | y=y+1 |
---|
| 366 | end |
---|
| 367 | round=round+1 |
---|
| 368 | end |
---|
| 369 | z=z+1 |
---|
| 370 | end |
---|
| 371 | end |
---|
| 372 | -- End attach cockpit. |
---|
| 373 | |
---|
| 374 | |
---|
| 375 | |
---|
| 376 | -- Attach parts on the left side of the space station. |
---|
| 377 | function setLeftSidePart() |
---|
| 378 | 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 |
---|
| 379 | |
---|
| 380 | check=1 |
---|
| 381 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 382 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 383 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 384 | if bodyParts[tempSidePartsIndex][i][j][k][0] == 1 and grid[x+i][y+j][z+k][0] == 1 then |
---|
| 385 | check=0 |
---|
| 386 | end |
---|
| 387 | end |
---|
| 388 | end |
---|
| 389 | end |
---|
| 390 | |
---|
| 391 | if check == 1 then |
---|
| 392 | print("<Model position=\"") print(x*gridDim*sSScale) print(",") print(y*gridDim*sSScale) print(",") print(z*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[tempSidePartsIndex][0][0][0][4]) print("\"") print(bodyParts[tempSidePartsIndex][0][0][0][5]) print("/>") |
---|
| 393 | partSet=1 |
---|
| 394 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 395 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 396 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 397 | if bodyParts[tempSidePartsIndex][i][j][k][0] == 1 then |
---|
| 398 | for l=0,3 do |
---|
| 399 | grid[x+i][y+j][z+k][l] = bodyParts[tempSidePartsIndex][i][j][k][l] |
---|
| 400 | end |
---|
| 401 | end |
---|
| 402 | end |
---|
| 403 | end |
---|
| 404 | end |
---|
| 405 | |
---|
| 406 | end |
---|
| 407 | |
---|
| 408 | end |
---|
| 409 | end |
---|
| 410 | |
---|
| 411 | |
---|
| 412 | if leftSidePartsIndex[0] ~= false then |
---|
| 413 | for sPC=1,leftSideParts do |
---|
| 414 | tempSidePartsIndex = leftSidePartsIndex[math.random(1,leftSideParts)] |
---|
| 415 | partSet=0 |
---|
| 416 | x=math.floor(-sSSize/2) |
---|
| 417 | while x<=math.floor(sSSize/2)-1 and partSet==0 do |
---|
| 418 | round=0 |
---|
| 419 | while round<=math.floor(sSSize/2)-1 and partSet==0 do |
---|
| 420 | y=round |
---|
| 421 | z=-round |
---|
| 422 | while z<=round and partSet==0 do |
---|
| 423 | setLeftSidePart() |
---|
| 424 | z=z+1 |
---|
| 425 | end |
---|
| 426 | while y>=-round and partSet==0 do |
---|
| 427 | setLeftSidePart() |
---|
| 428 | y=y-1 |
---|
| 429 | end |
---|
| 430 | while z>=-round and partSet==0 do |
---|
| 431 | setLeftSidePart() |
---|
| 432 | z=z-1 |
---|
| 433 | end |
---|
| 434 | while y<=round and partSet==0 do |
---|
| 435 | setLeftSidePart() |
---|
| 436 | y=y+1 |
---|
| 437 | end |
---|
| 438 | round=round+1 |
---|
| 439 | end |
---|
| 440 | x=x+1 |
---|
| 441 | end |
---|
| 442 | end |
---|
| 443 | end |
---|
| 444 | -- End attach side parts. |
---|
| 445 | |
---|
| 446 | |
---|
| 447 | |
---|
| 448 | -- Attach all connectionparts. |
---|
| 449 | -- This iterates through the whole grid array. |
---|
| 450 | if connPartName ~= false then |
---|
| 451 | for x=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do |
---|
| 452 | for y=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do |
---|
| 453 | for z=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do |
---|
| 454 | -- 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. |
---|
| 455 | 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 |
---|
| 456 | -- 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. |
---|
| 457 | print("<Model position=\"") print(x*gridDim*sSScale+gridDim*sSScale/2) print(",") print(y*gridDim*sSScale) print(",") print(z*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh=\"") print(connPartName) print("\" roll=90 />") |
---|
| 458 | end |
---|
| 459 | -- The same as in the x-direction, but for the y-direction. |
---|
| 460 | 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 |
---|
| 461 | print("<Model position=\"") print(x*gridDim*sSScale) print(",") print(y*gridDim*sSScale+gridDim*sSScale/2) print(",") print(z*gridDim*sSScale) print("\" scale=") print(sSScale) print(" mesh=\"") print(connPartName) print("\" />") |
---|
| 462 | end |
---|
| 463 | -- The same as in the x-direction, but for the z-direction. |
---|
| 464 | 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 |
---|
| 465 | print("<Model position=\"") print(x*gridDim*sSScale) print(",") print(y*gridDim*sSScale) print(",") print(z*gridDim*sSScale+gridDim*sSScale/2) print("\" scale=") print(sSScale) print(" mesh=\"") print(connPartName) print("\" pitch=90 />") |
---|
| 466 | end |
---|
| 467 | end |
---|
| 468 | end |
---|
| 469 | end |
---|
| 470 | end |
---|
| 471 | -- End attach all connectionparts. |
---|
| 472 | |
---|
| 473 | |
---|
| 474 | |
---|
| 475 | -- This is xml code, which ends the attachment and the MovableEntity. |
---|
| 476 | print("</attached>") |
---|
| 477 | print("</MovableEntity>") |
---|
| 478 | ?> |
---|