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