[5298] | 1 | <?lua |
---|
| 2 | -- This lua script creates a totally random generated space station for the orxonox computer game! |
---|
| 3 | |
---|
| 4 | -- 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. |
---|
| 5 | print("<MovableEntity scale=1 position=\"0,0,-5000\" velocity=\"0,0,0\" rotationaxis=\"0,0,1\" rotationrate=0 yaw=180 >") |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | -- Create a randomseed, so that the math.random() function is actually random. |
---|
| 10 | math.randomseed(os.time()) |
---|
| 11 | -- End create randomseed. |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | -- Here you can define some global variables, with which you can modify the space station. |
---|
| 16 | -- Define the maximal size of the space station, this is actually just for the grid, be sure that this value is big enough. |
---|
| 17 | sSSize=30 |
---|
| 18 | -- 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. |
---|
| 19 | sSParts=7 |
---|
| 20 | -- 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. |
---|
| 21 | sSBodyParts=3 |
---|
| 22 | -- Define how many side parts for the left side you have. |
---|
| 23 | leftSideParts=1 |
---|
| 24 | -- Define which index your left side parts have. |
---|
| 25 | leftSidePartsIndex={} |
---|
| 26 | -- Define how many side parts for the right side you have. |
---|
| 27 | rightSideParts=1 |
---|
| 28 | -- Define which index your right side parts have. |
---|
| 29 | rightSidePartsIndex={} |
---|
| 30 | -- Define how many top parts you have. |
---|
| 31 | topParts=1 |
---|
| 32 | -- Define which index your top parts have. |
---|
| 33 | topPartsIndex={} |
---|
| 34 | -- 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. |
---|
| 35 | pDim=6 |
---|
| 36 | -- Define the length in x-direction of the space station which will be occupied by bodyparts. |
---|
| 37 | xBPLength=4 |
---|
| 38 | -- Define the variation of the edges of your bodyparts in the x-direction. |
---|
| 39 | xBPVar=1 |
---|
| 40 | -- Define the length in y-direction of the space station which will be occupied by bodyparts. |
---|
| 41 | yBPLength=2 |
---|
| 42 | -- Define the variation of the edges of your bodyparts in the y-direction. |
---|
| 43 | yBPVar=1 |
---|
| 44 | -- Define the length in the z-direction of the space station which will be occupied by bodyparts. |
---|
| 45 | zBPLength=6 |
---|
| 46 | -- Define the variation of the edges of your bodyparts in the z-direction. |
---|
| 47 | zBPVar=1 |
---|
| 48 | -- Define the scale of the space station. |
---|
| 49 | sSScale=100 |
---|
| 50 | -- 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. |
---|
| 51 | gridDim=2.25 |
---|
| 52 | -- End define global parameters. |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | -- This creates a 4-dimensional grid, which tells us if there is a part or not, and in which direction it has connections. |
---|
| 57 | -- The parameters x,y,z are the axis of the space station, which iterate to sSSize, the maximal size of the space station. |
---|
| 58 | -- 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, and so on for the other dimensions y and z. |
---|
| 59 | -- grid[x][y][z][0] contains 0 if there is no part at the position (x,y,z), otherwise 1. |
---|
| 60 | -- 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. |
---|
| 61 | -- 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. |
---|
| 62 | -- 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. |
---|
| 63 | grid = {} |
---|
| 64 | for x=-math.floor(sSSize/2),math.floor(sSSize/2) do |
---|
| 65 | grid[x] = {} |
---|
| 66 | for y=-math.floor(sSSize/2),math.floor(sSSize/2) do |
---|
| 67 | grid[x][y]= {} |
---|
| 68 | for z=-math.floor(sSSize/2),math.floor(sSSize/2) do |
---|
| 69 | grid[x][y][z]={} |
---|
| 70 | for i=0,3 do |
---|
| 71 | grid[x][y][z][i]=0 |
---|
| 72 | end |
---|
| 73 | end |
---|
| 74 | end |
---|
| 75 | end |
---|
| 76 | -- End create 4-dim grid. |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | -- This creates an array which stores all the bodyparts, it's size is depending on the global values pDim and sSParts. |
---|
| 81 | -- 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. |
---|
| 82 | -- 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). |
---|
| 83 | -- 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, "+-", "+", "-"). |
---|
| 84 | bodyParts={} |
---|
| 85 | for i=1,sSParts do |
---|
| 86 | bodyParts[i]={} |
---|
| 87 | for x=-math.floor(pDim/2),math.floor(pDim/2) do |
---|
| 88 | bodyParts[i][x]={} |
---|
| 89 | for y=-math.floor(pDim/2),math.floor(pDim/2) do |
---|
| 90 | bodyParts[i][x][y]={} |
---|
| 91 | for z=-math.floor(pDim/2),math.floor(pDim/2) do |
---|
| 92 | bodyParts[i][x][y][z]={} |
---|
| 93 | for k=0,3 do |
---|
| 94 | bodyParts[i][x][y][z][k]=0 |
---|
| 95 | end |
---|
| 96 | end |
---|
| 97 | end |
---|
| 98 | end |
---|
| 99 | bodyParts[i][0][0][0][4]="" |
---|
| 100 | bodyParts[i][0][0][0][5]="" |
---|
| 101 | bodyParts[i][0][0][0][6]="" |
---|
| 102 | end |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | -- 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. |
---|
| 107 | -- The part must be inserted so, that the center of reference is at position (0,0,0). |
---|
| 108 | -- At position bodyParts[i][0][0][0][4] you have to put the mesh name of your part. |
---|
| 109 | -- 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. |
---|
| 110 | -- At bodyParts[i][0][0][0][5] 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][6] you have to rotate the part so that it fits on the right side. |
---|
| 111 | |
---|
| 112 | -- Insert the CuboidBody, which is only one griddimension and can have connections in every direction. |
---|
| 113 | bodyParts[1][0][0][0][4]="CuboidBody.mesh" |
---|
| 114 | |
---|
| 115 | bodyParts[1][0][0][0][0]=1 |
---|
| 116 | bodyParts[1][0][0][0][1]="+-" |
---|
| 117 | bodyParts[1][0][0][0][2]="+-" |
---|
| 118 | bodyParts[1][0][0][0][3]="+-" |
---|
| 119 | -- End insert CuboidBody. |
---|
| 120 | |
---|
| 121 | -- Insert the DoubleCuboidBody, which is two griddimensions long, and one wide and high and can have connections in every direction except in the middle. |
---|
| 122 | bodyParts[2][0][0][0][4]="DoubleCuboidBody.mesh" |
---|
| 123 | bodyParts[2][0][0][0][5]="pitch=-90" |
---|
| 124 | |
---|
| 125 | bodyParts[2][0][0][0][0]=1 |
---|
| 126 | bodyParts[2][0][0][0][1]="+-" |
---|
| 127 | bodyParts[2][0][0][0][2]="+-" |
---|
| 128 | bodyParts[2][0][0][0][3]="-" |
---|
| 129 | |
---|
| 130 | bodyParts[2][0][0][1][0]=1 |
---|
| 131 | bodyParts[2][0][0][1][1]="+-" |
---|
| 132 | bodyParts[2][0][0][1][2]="+-" |
---|
| 133 | bodyParts[2][0][0][1][3]="+" |
---|
| 134 | -- End insert DoubleCuboidBody. |
---|
| 135 | |
---|
| 136 | -- Insert the CuboidConnectionBody, 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). |
---|
| 137 | bodyParts[3][0][0][0][4]="CuboidConnectionBody.mesh" |
---|
| 138 | bodyParts[3][0][0][0][5]="pitch=-90" |
---|
| 139 | |
---|
| 140 | bodyParts[3][0][0][0][0]=1 |
---|
| 141 | bodyParts[3][0][0][0][1]="+-" |
---|
| 142 | bodyParts[3][0][0][0][2]="+-" |
---|
| 143 | bodyParts[3][0][0][0][3]="-" |
---|
| 144 | |
---|
| 145 | bodyParts[3][0][0][1][0]=1 |
---|
| 146 | |
---|
| 147 | bodyParts[3][0][0][2][0]=1 |
---|
| 148 | bodyParts[3][0][0][2][1]="+-" |
---|
| 149 | bodyParts[3][0][0][2][2]="+-" |
---|
| 150 | bodyParts[3][0][0][2][3]="+" |
---|
| 151 | -- End insert CuboidConnectionBody. |
---|
| 152 | |
---|
| 153 | -- Insert the Thruster, which is one griddimension long, wide and high, it can only have a connection into the negative z-direction. |
---|
| 154 | -- 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. |
---|
| 155 | thrusterIndex=4 |
---|
| 156 | bodyParts[thrusterIndex][0][0][0][4]="Thruster.mesh" |
---|
| 157 | bodyParts[thrusterIndex][0][0][0][5]="pitch=-90" |
---|
| 158 | |
---|
| 159 | bodyParts[thrusterIndex][0][0][0][0]=1 |
---|
| 160 | bodyParts[thrusterIndex][0][0][0][3]="-" |
---|
| 161 | --End insert the Thruster. |
---|
| 162 | |
---|
| 163 | -- Insert the Cockpit. If your space station has no cockpit, be sure to set cockpitIndex=false. |
---|
| 164 | -- 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. |
---|
| 165 | cockpitIndex=5 |
---|
| 166 | bodyParts[cockpitIndex][0][0][0][4]="SemiCircleCockpit.mesh" |
---|
| 167 | bodyParts[cockpitIndex][0][0][0][5]="pitch=-90 yaw=180" |
---|
| 168 | |
---|
| 169 | bodyParts[cockpitIndex][0][0][0][0]=1 |
---|
| 170 | bodyParts[cockpitIndex][0][0][0][3]="+" |
---|
| 171 | |
---|
| 172 | bodyParts[cockpitIndex][-1][0][0][0]=1 |
---|
| 173 | bodyParts[cockpitIndex][1][0][0][0]=1 |
---|
| 174 | bodyParts[cockpitIndex][0][-1][0][0]=1 |
---|
| 175 | bodyParts[cockpitIndex][0][1][0][0]=1 |
---|
| 176 | bodyParts[cockpitIndex][-1][-1][0][0]=1 |
---|
| 177 | bodyParts[cockpitIndex][1][-1][0][0]=1 |
---|
| 178 | bodyParts[cockpitIndex][-1][1][0][0]=1 |
---|
| 179 | bodyParts[cockpitIndex][1][1][0][0]=1 |
---|
| 180 | bodyParts[cockpitIndex][0][0][-1][0]=1 |
---|
| 181 | bodyParts[cockpitIndex][-1][0][-1][0]=1 |
---|
| 182 | bodyParts[cockpitIndex][1][0][-1][0]=1 |
---|
| 183 | bodyParts[cockpitIndex][0][-1][-1][0]=1 |
---|
| 184 | bodyParts[cockpitIndex][0][1][-1][0]=1 |
---|
| 185 | bodyParts[cockpitIndex][-1][-1][-1][0]=1 |
---|
| 186 | bodyParts[cockpitIndex][1][-1][-1][0]=1 |
---|
| 187 | bodyParts[cockpitIndex][-1][1][-1][0]=1 |
---|
| 188 | bodyParts[cockpitIndex][1][1][-1][0]=1 |
---|
| 189 | -- End insert Cockpit. |
---|
| 190 | |
---|
| 191 | -- Insert the side parts. |
---|
| 192 | -- If your space station has no left side parts, be sure to set leftsidePartsIndex[0]=false. |
---|
| 193 | -- If your space station has no right side parts, be sure to set rightsidePartsIndex[0]=false. |
---|
| 194 | leftSidePartsIndex[0]="" |
---|
| 195 | rightSidePartsIndex[0]="" |
---|
| 196 | |
---|
| 197 | -- Insert the solar panel, which i wanna use as left and right side part. |
---|
| 198 | leftSidePartsIndex[1]=6 |
---|
| 199 | rightSidePartsIndex[1]=leftSidePartsIndex[1] |
---|
| 200 | bodyParts[leftSidePartsIndex[1]][0][0][0][4]="SolarPanel.mesh" |
---|
| 201 | bodyParts[leftSidePartsIndex[1]][0][0][0][5]="roll=90 pitch="..math.random(0,180) |
---|
| 202 | bodyParts[rightSidePartsIndex[1]][0][0][0][6]="roll=-90 pitch="..math.random(0,180) |
---|
| 203 | |
---|
| 204 | bodyParts[leftSidePartsIndex[1]][0][0][0][0]=1 |
---|
| 205 | bodyParts[leftSidePartsIndex[1]][0][0][1][0]=1 |
---|
| 206 | bodyParts[leftSidePartsIndex[1]][0][0][-1][0]=1 |
---|
| 207 | bodyParts[leftSidePartsIndex[1]][0][1][0][0]=1 |
---|
| 208 | bodyParts[leftSidePartsIndex[1]][0][1][1][0]=1 |
---|
| 209 | bodyParts[leftSidePartsIndex[1]][0][1][-1][0]=1 |
---|
| 210 | bodyParts[leftSidePartsIndex[1]][0][-1][0][0]=1 |
---|
| 211 | bodyParts[leftSidePartsIndex[1]][0][-1][1][0]=1 |
---|
| 212 | bodyParts[leftSidePartsIndex[1]][0][-1][-1][0]=1 |
---|
| 213 | -- End insert solar panel. |
---|
| 214 | |
---|
| 215 | -- End insert side parts. |
---|
| 216 | |
---|
| 217 | -- Insert the top parts. |
---|
| 218 | -- If you have no top parts, be sure to set topPartsIndex[0]=false |
---|
| 219 | topPartsIndex[1]=7 |
---|
| 220 | bodyParts[topPartsIndex[1]][0][0][0][4]="CuboidLandingZone.mesh" |
---|
| 221 | bodyParts[topPartsIndex[1]][0][0][0][5]="pitch=-90" |
---|
| 222 | |
---|
| 223 | bodyParts[topPartsIndex[1]][0][0][0][0]=1 |
---|
| 224 | bodyParts[topPartsIndex[1]][0][0][0][2]="+-" |
---|
| 225 | bodyParts[topPartsIndex[1]][1][0][0][0]=1 |
---|
| 226 | bodyParts[topPartsIndex[1]][-1][0][0][0]=1 |
---|
| 227 | bodyParts[topPartsIndex[1]][0][0][1][0]=1 |
---|
| 228 | bodyParts[topPartsIndex[1]][1][0][1][0]=1 |
---|
| 229 | bodyParts[topPartsIndex[1]][-1][0][1][0]=1 |
---|
| 230 | bodyParts[topPartsIndex[1]][0][0][2][0]=1 |
---|
| 231 | bodyParts[topPartsIndex[1]][1][0][2][0]=1 |
---|
| 232 | bodyParts[topPartsIndex[1]][-1][0][2][0]=1 |
---|
| 233 | bodyParts[topPartsIndex[1]][0][0][3][0]=1 |
---|
| 234 | bodyParts[topPartsIndex[1]][1][0][3][0]=1 |
---|
| 235 | bodyParts[topPartsIndex[1]][-1][0][3][0]=1 |
---|
| 236 | -- End insert the top parts. |
---|
| 237 | |
---|
| 238 | -- Insert the connectionpart, which is used to connect all the bodyparts. |
---|
| 239 | -- If you're spacestation has no connectionpart, be sure to set connPartName=false. |
---|
| 240 | connPartName="CuboidConnection.mesh" |
---|
| 241 | -- End insert the connectionparts. |
---|
| 242 | |
---|
| 243 | -- End create array bodyParts. |
---|
| 244 | |
---|
| 245 | -- Here I define some functions which I will use later. |
---|
| 246 | --This function actualizes the grid, which I have to call always after I have added a new part to the space station. |
---|
| 247 | function actualizeGrid(Index,x,y,z) |
---|
| 248 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 249 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 250 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 251 | if bodyParts[Index][i][j][k][0] == 1 then |
---|
| 252 | for l=0,3 do |
---|
| 253 | grid[x+i][y+j][z+k][l] = bodyParts[Index][i][j][k][l] |
---|
| 254 | end |
---|
| 255 | end |
---|
| 256 | end |
---|
| 257 | end |
---|
| 258 | end |
---|
| 259 | end |
---|
| 260 | -- End actualizeGrid. |
---|
| 261 | |
---|
| 262 | -- This function checks wheter a given parts fits at that position or not. |
---|
| 263 | function checkPart(Index,x,y,z) |
---|
| 264 | check=1 |
---|
| 265 | for i=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 266 | for j=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 267 | for k=math.floor(-pDim/2),math.floor(pDim/2) do |
---|
| 268 | -- 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. |
---|
| 269 | if bodyParts[Index][i][j][k][0] == 1 and grid[x+i][y+j][z+k][0] == 1 then |
---|
| 270 | check=0 |
---|
| 271 | end |
---|
| 272 | end |
---|
| 273 | end |
---|
| 274 | end |
---|
| 275 | return check |
---|
| 276 | end |
---|
| 277 | -- End checkPart function. |
---|
| 278 | -- End define functions. |
---|
| 279 | |
---|
| 280 | -- This is xml code, which means now we attach some parts to the MovableEntity. |
---|
| 281 | print("<attached>") |
---|
| 282 | |
---|
| 283 | |
---|
| 284 | |
---|
| 285 | -- Attach all bodyparts. |
---|
| 286 | -- Define at which position in the x-direction you're space station will start. |
---|
| 287 | x=math.random(-math.floor(xBPLength/2),-math.floor(xBPLength/2)+xBPVar) |
---|
| 288 | -- Define at which position in the x-direction you're space station will end. |
---|
| 289 | xMax=math.random(math.floor(xBPLength/2),math.floor(xBPLength/2)+xBPVar) |
---|
| 290 | while x<xMax do |
---|
| 291 | -- The same for the y- and z-direction. |
---|
| 292 | y=math.random(-math.floor(yBPLength/2),-math.floor(yBPLength/2)+yBPVar) |
---|
| 293 | yMax=math.random(math.floor(yBPLength/2),math.floor(yBPLength/2)+yBPVar) |
---|
| 294 | while y<yMax do |
---|
| 295 | yMax=math.random(math.floor(yBPLength/2),math.floor(yBPLength/2)+yBPVar) |
---|
| 296 | z=math.random(-math.floor(zBPLength/2),-math.floor(zBPLength/2)+zBPVar) |
---|
| 297 | zMax=math.random(math.floor(zBPLength/2),math.floor(zBPLength/2)+zBPVar) |
---|
| 298 | while z<zMax do |
---|
| 299 | -- This loop choses a bodypart, which fits at position (x,y,z). |
---|
| 300 | -- If after the fifth time the part does still not fit we terminate the loop and set no part at postition (x,y,z). |
---|
| 301 | partSet=0 |
---|
| 302 | counter=0 |
---|
| 303 | while counter<5 and partSet==0 do |
---|
| 304 | -- This choses randomly a bodyPartIndex, which is the index used for the parts in the array bodyParts. |
---|
| 305 | tempBodyPartIndex=math.random(1,sSBodyParts) |
---|
| 306 | check=checkPart(tempBodyPartIndex,x,y,z) |
---|
| 307 | -- If check == 1, this means that the part fits there, so we put it there and break the while true loop, to go on. |
---|
| 308 | if check == 1 then |
---|
| 309 | -- This is xml code which means at position (x*gridDim*sSScale) will be the randomly chosen part. |
---|
| 310 | 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(" />") |
---|
| 311 | -- This actualizes the grid array with the values of the array bodyParts at the position tempBodyPartIndex, which is our randomly chosen part. |
---|
| 312 | actualizeGrid(tempBodyPartIndex,x,y,z) |
---|
| 313 | partSet=1 |
---|
| 314 | end |
---|
| 315 | counter=counter+1 |
---|
| 316 | end |
---|
| 317 | z=z+1 |
---|
| 318 | end |
---|
| 319 | y=y+1 |
---|
| 320 | end |
---|
| 321 | x=x+1 |
---|
| 322 | end |
---|
| 323 | -- End attach all bodyparts. |
---|
| 324 | |
---|
| 325 | |
---|
| 326 | |
---|
| 327 | -- Attach thrusters, if there are some. |
---|
| 328 | if thrusterIndex ~= false then |
---|
| 329 | -- 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. |
---|
| 330 | for x=math.floor(-sSSize/2),math.floor(sSSize/2) do |
---|
| 331 | for y=math.floor(-sSSize/2),math.floor(sSSize/2) do |
---|
| 332 | for z=math.floor(-sSSize/2)+1,math.floor(sSSize/2) do |
---|
| 333 | if grid[x][y][z-1][0] == 1 and grid[x][y][z][0] == 0 then |
---|
| 334 | 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(" >") |
---|
| 335 | |
---|
| 336 | print("<attached>") |
---|
| 337 | print("<ParticleEmitter position=\"0,0,0\" source=\"Orxonox/fire3\" />") |
---|
| 338 | print("</attached>") |
---|
| 339 | print("</Model>") |
---|
| 340 | -- This actualizes the grid array with the values of the array bodyParts at the position thrusterIndex. |
---|
| 341 | actualizeGrid(thrusterIndex,x,y,z) |
---|
| 342 | -- 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. |
---|
| 343 | break |
---|
| 344 | end |
---|
| 345 | end |
---|
| 346 | end |
---|
| 347 | end |
---|
| 348 | end |
---|
| 349 | -- End attach Thrusters. |
---|
| 350 | |
---|
| 351 | |
---|
| 352 | |
---|
| 353 | -- Attach cockpit, if there is one. |
---|
| 354 | function setCockpit() |
---|
| 355 | if grid[x][y][z][0] == 0 and grid[x][y][z+1][0] == 1 then |
---|
| 356 | |
---|
| 357 | check=checkPart(cockpitIndex,x,y,z) |
---|
| 358 | |
---|
| 359 | if check == 1 then |
---|
| 360 | 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("/>") |
---|
| 361 | cockpitSet=1 |
---|
| 362 | -- This actualizes the grid array with the values of the array bodyParts at the position cockpitIndex. |
---|
| 363 | actualizeGrid(cockpitIndex,x,y,z) |
---|
| 364 | end |
---|
| 365 | |
---|
| 366 | end |
---|
| 367 | end |
---|
| 368 | |
---|
| 369 | |
---|
| 370 | if cockpitIndex ~= false then |
---|
| 371 | cockpitSet=0 |
---|
| 372 | z=math.floor(-sSSize/2) |
---|
| 373 | while z<=math.floor(sSSize/2)-1 and cockpitSet==0 do |
---|
| 374 | round=0 |
---|
| 375 | while round<=math.floor(sSSize/2)-1 and cockpitSet==0 do |
---|
| 376 | y=round |
---|
| 377 | x=-round |
---|
| 378 | while x<=round and cockpitSet==0 do |
---|
| 379 | setCockpit() |
---|
| 380 | x=x+1 |
---|
| 381 | end |
---|
| 382 | while y>=-round and cockpitSet==0 do |
---|
| 383 | setCockpit() |
---|
| 384 | y=y-1 |
---|
| 385 | end |
---|
| 386 | while x>-round and cockpitSet==0 do |
---|
| 387 | setCockpit() |
---|
| 388 | x=x-1 |
---|
| 389 | end |
---|
| 390 | while y<=round and cockpitSet==0 do |
---|
| 391 | setCockpit() |
---|
| 392 | y=y+1 |
---|
| 393 | end |
---|
| 394 | round=round+1 |
---|
| 395 | end |
---|
| 396 | z=z+1 |
---|
| 397 | end |
---|
| 398 | end |
---|
| 399 | -- End attach cockpit. |
---|
| 400 | |
---|
| 401 | |
---|
| 402 | |
---|
| 403 | -- Attach parts on the left side of the space station. |
---|
| 404 | function setLeftSidePart() |
---|
| 405 | 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 |
---|
| 406 | |
---|
| 407 | check=checkPart(tempSidePartsIndex,x,y,z) |
---|
| 408 | |
---|
| 409 | if check == 1 then |
---|
| 410 | 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("/>") |
---|
| 411 | partSet=1 |
---|
| 412 | -- This actualizes the grid array with the values of the array bodyParts at the position tempSidePartsIndex. |
---|
| 413 | actualizeGrid(tempSidePartsIndex,x,y,z) |
---|
| 414 | end |
---|
| 415 | |
---|
| 416 | end |
---|
| 417 | end |
---|
| 418 | |
---|
| 419 | |
---|
| 420 | if leftSidePartsIndex[0] ~= false then |
---|
| 421 | for sPC=1,leftSideParts do |
---|
| 422 | tempSidePartsIndex = leftSidePartsIndex[math.random(1,leftSideParts)] |
---|
| 423 | partSet=0 |
---|
| 424 | x=math.floor(-sSSize/2) |
---|
| 425 | while x<=math.floor(sSSize/2)-1 and partSet==0 do |
---|
| 426 | round=0 |
---|
| 427 | while round<=math.floor(sSSize/2)-1 and partSet==0 do |
---|
| 428 | y=round |
---|
| 429 | z=-round |
---|
| 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 | while z>=-round and partSet==0 do |
---|
| 439 | setLeftSidePart() |
---|
| 440 | z=z-1 |
---|
| 441 | end |
---|
| 442 | while y<=round and partSet==0 do |
---|
| 443 | setLeftSidePart() |
---|
| 444 | y=y+1 |
---|
| 445 | end |
---|
| 446 | round=round+1 |
---|
| 447 | end |
---|
| 448 | x=x+1 |
---|
| 449 | end |
---|
| 450 | end |
---|
| 451 | end |
---|
| 452 | -- End attach left side parts. |
---|
| 453 | |
---|
| 454 | |
---|
| 455 | |
---|
| 456 | -- Attach parts on the right side of the space station. |
---|
| 457 | function setRightSidePart() |
---|
| 458 | 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 |
---|
| 459 | |
---|
| 460 | check=checkPart(tempSidePartsIndex,x,y,z) |
---|
| 461 | |
---|
| 462 | if check == 1 then |
---|
| 463 | 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][6]) print("/>") |
---|
| 464 | partSet=1 |
---|
| 465 | -- This actualizes the grid array with the values of the array bodyParts at the position tempSidePartsIndex. |
---|
| 466 | actualizeGrid(tempSidePartsIndex,x,y,z) |
---|
| 467 | end |
---|
| 468 | |
---|
| 469 | end |
---|
| 470 | end |
---|
| 471 | |
---|
| 472 | |
---|
| 473 | if rightSidePartsIndex[0] ~= false then |
---|
| 474 | for sPC=1,rightSideParts do |
---|
| 475 | tempSidePartsIndex = rightSidePartsIndex[math.random(1,rightSideParts)] |
---|
| 476 | partSet=0 |
---|
| 477 | x=math.floor(sSSize/2) |
---|
| 478 | while x>=math.floor(-sSSize/2)+1 and partSet==0 do |
---|
| 479 | round=0 |
---|
| 480 | while round<=math.floor(sSSize/2)-1 and partSet==0 do |
---|
| 481 | y=round |
---|
| 482 | z=-round |
---|
| 483 | while z<=round and partSet==0 do |
---|
| 484 | setRightSidePart() |
---|
| 485 | z=z+1 |
---|
| 486 | end |
---|
| 487 | while y>=-round and partSet==0 do |
---|
| 488 | setRightSidePart() |
---|
| 489 | y=y-1 |
---|
| 490 | end |
---|
| 491 | while z>=-round and partSet==0 do |
---|
| 492 | setRightSidePart() |
---|
| 493 | z=z-1 |
---|
| 494 | end |
---|
| 495 | while y<=round and partSet==0 do |
---|
| 496 | setRightSidePart() |
---|
| 497 | y=y+1 |
---|
| 498 | end |
---|
| 499 | round=round+1 |
---|
| 500 | end |
---|
| 501 | x=x-1 |
---|
| 502 | end |
---|
| 503 | end |
---|
| 504 | end |
---|
| 505 | -- End attach right side parts. |
---|
| 506 | |
---|
| 507 | |
---|
| 508 | |
---|
| 509 | -- Attach parts on top of the space station. |
---|
| 510 | function setTopPart() |
---|
| 511 | 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 |
---|
| 512 | |
---|
| 513 | check=checkPart(tempTopPartsIndex,x,y,z) |
---|
| 514 | |
---|
| 515 | if check == 1 then |
---|
| 516 | 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[tempTopPartsIndex][0][0][0][4]) print("\"") print(bodyParts[tempTopPartsIndex][0][0][0][5]) print("/>") |
---|
| 517 | partSet=1 |
---|
| 518 | -- This actualizes the grid array with the values of the array bodyParts at the position tempTopPartsIndex. |
---|
| 519 | actualizeGrid(tempTopPartsIndex,x,y,z) |
---|
| 520 | end |
---|
| 521 | |
---|
| 522 | end |
---|
| 523 | end |
---|
| 524 | |
---|
| 525 | |
---|
| 526 | if topPartsIndex[0] ~= false then |
---|
| 527 | for sPC=1,topParts do |
---|
| 528 | tempTopPartsIndex = topPartsIndex[math.random(1,topParts)] |
---|
| 529 | partSet=0 |
---|
| 530 | y=math.floor(sSSize/2) |
---|
| 531 | while y>=math.floor(-sSSize/2)+1 and partSet==0 do |
---|
| 532 | round=0 |
---|
| 533 | while round<=math.floor(sSSize/2)-1 and partSet==0 do |
---|
| 534 | x=round |
---|
| 535 | z=-round |
---|
| 536 | while z<=round and partSet==0 do |
---|
| 537 | setTopPart() |
---|
| 538 | z=z+1 |
---|
| 539 | end |
---|
| 540 | while x>=-round and partSet==0 do |
---|
| 541 | setTopPart() |
---|
| 542 | x=x-1 |
---|
| 543 | end |
---|
| 544 | while z>=-round and partSet==0 do |
---|
| 545 | setTopPart() |
---|
| 546 | z=z-1 |
---|
| 547 | end |
---|
| 548 | while x<=round and partSet==0 do |
---|
| 549 | setTopPart() |
---|
| 550 | x=x+1 |
---|
| 551 | end |
---|
| 552 | round=round+1 |
---|
| 553 | end |
---|
| 554 | y=y-1 |
---|
| 555 | end |
---|
| 556 | end |
---|
| 557 | end |
---|
| 558 | -- End attach top parts. |
---|
| 559 | |
---|
| 560 | |
---|
| 561 | |
---|
| 562 | -- Attach all connectionparts. |
---|
| 563 | -- This iterates through the whole grid array. |
---|
| 564 | if connPartName ~= false then |
---|
| 565 | for x=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do |
---|
| 566 | for y=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do |
---|
| 567 | for z=math.floor(-sSSize/2),math.floor(sSSize/2)-1 do |
---|
| 568 | -- 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. |
---|
| 569 | 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 |
---|
| 570 | -- 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. |
---|
| 571 | 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 />") |
---|
| 572 | end |
---|
| 573 | -- The same as in the x-direction, but for the y-direction. |
---|
| 574 | 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 |
---|
| 575 | 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("\" />") |
---|
| 576 | end |
---|
| 577 | -- The same as in the x-direction, but for the z-direction. |
---|
| 578 | 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 |
---|
| 579 | 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 />") |
---|
| 580 | end |
---|
| 581 | end |
---|
| 582 | end |
---|
| 583 | end |
---|
| 584 | end |
---|
| 585 | -- End attach all connectionparts. |
---|
| 586 | |
---|
| 587 | |
---|
| 588 | |
---|
| 589 | -- This is xml code, which ends the attachment and the MovableEntity. |
---|
| 590 | print("</attached>") |
---|
| 591 | print("</MovableEntity>") |
---|
| 592 | |
---|
| 593 | ?> |
---|