Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 30, 2012, 11:08:17 PM (12 years ago)
Author:
landauf
Message:

merged branch presentation2012merge back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/data/levels/includes/CuboidSpaceStation.lua

    r7163 r9348  
    11----------------------------------------------------------------------------------------------------
    22-- This lua script creates a totally random generated space station for the orxonox computer game!--
    3 -- (c) Wallah 2008, published under GPL licence!                                                                                                  --
     3-- (c) Wallah 2008, published under GPL licence!                                                  --
    44----------------------------------------------------------------------------------------------------
    55
    66--------------------------------------------------------------------------------------------------------------------------------------------------------------------
    7 -- IMPORTANT: If you need more parameters, do the following: copy the actual function (just the headline and the end statement) to the end of the file,                   --
     7-- IMPORTANT: If you need more parameters, do the following: copy the actual function (just the headline and the end statement) to the end of the file,           --
    88-- like I did with createSpaceStation() and let that function call the new function where you can modify the parameters. For all parameters which the old function--
    99-- doesn't have you just give the standard default values, which I have defined. This is to make sure, that anyone else who uses the old function can still use it--
    10 -- the same way he/she always did. If you want a function with less parameters, just create a new one at the end of the file and call this function with some     --
    11 -- default values. REMEMBER: Function overloading is not possible, be sure to call your function differently from others already existing ones.                                   --
     10-- the same way he/she always did. If you want a function with less parameters, just create a new one at the end of the file and call this function with some     --
     11-- default values. REMEMBER: Function overloading is not possible, be sure to call your function differently from others already existing ones.                   --
    1212--------------------------------------------------------------------------------------------------------------------------------------------------------------------
    1313
    1414-- This function creates a randomly generated space station.
    1515-- The first argument ranSeed, must be 0, or a positive Integer, if it is 0 your space station is always chosen randomly, if you give an integer,
    16 --      your space station will be generated randomly, but once you have the space station it will always be the same.
     16--  your space station will be generated randomly, but once you have the space station it will always be the same.
    1717-- The argument xLength defines how large the space station will be into the x-direction.
    1818-- The argument xVar defines how much the space station will vary at the ends in x-direction, this is so that the station is no cube.
     
    3737-- Create a randomseed, so that the math.random() function is actually random.
    3838if ranSeed == 0 then
    39         math.randomseed(os.time())
     39    math.randomseed(os.time())
    4040else
    41         math.randomseed(ranSeed)
     41    math.randomseed(ranSeed)
    4242end
    4343-- End create randomseed.
     
    5252sSSize=30
    5353if xLength>=yLength and xLength>=zLength then
    54         sSSize=xLength+20
     54    sSSize=xLength+20
    5555elseif yLength>=xLength and yLength>=zLength then
    56         sSSize=yLength+20
     56    sSSize=yLength+20
    5757elseif zLength>=xLength and zLength>=yLength then
    58         sSSize=zLength+20
     58    sSSize=zLength+20
    5959end
    6060-- 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.
     
    7878pDim=6
    7979-- 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:
    80 --      integer*(gridDim-connectionSize), then integer tells you how many griddimensions your part is.
     80--  integer*(gridDim-connectionSize), then integer tells you how many griddimensions your part is.
    8181gridDim=2.25
    8282-- End define global parameters.
     
    8989-- The parameters x,y,z are the axis of the space station, which iterate to sSSize, the maximal size of the space station.
    9090-- 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,
    91 --      and so on for the other dimensions y and z.
     91--  and so on for the other dimensions y and z.
    9292-- grid[x][y][z][0] contains 0 if there is no part at the position (x,y,z), otherwise 1.
    9393-- 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,
    94 --      "-" if there is one in the negative x-direction, "+-" if there are in both x-directions.
     94--  "-" if there is one in the negative x-direction, "+-" if there are in both x-directions.
    9595-- 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,
    96 --      "-" if there is one in the negative y-direction, "+-" if there are in both y-directions.
     96--  "-" if there is one in the negative y-direction, "+-" if there are in both y-directions.
    9797-- 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,
    98 --      "-" if there is one in the negative z-direction, "+-" if there are in both z-directions.
     98--  "-" if there is one in the negative z-direction, "+-" if there are in both z-directions.
    9999grid = {}
    100100for x=-math.floor(sSSize/2),math.floor(sSSize/2) do
    101         grid[x] = {}
    102         for y=-math.floor(sSSize/2),math.floor(sSSize/2) do
    103                 grid[x][y]= {}
    104                 for z=-math.floor(sSSize/2),math.floor(sSSize/2) do
    105                         grid[x][y][z]={}
    106                         for i=0,3 do
    107                                 grid[x][y][z][i]=0
    108                         end
    109                 end
    110         end
     101    grid[x] = {}
     102    for y=-math.floor(sSSize/2),math.floor(sSSize/2) do
     103        grid[x][y]= {}
     104        for z=-math.floor(sSSize/2),math.floor(sSSize/2) do
     105            grid[x][y][z]={}
     106            for i=0,3 do
     107                grid[x][y][z][i]=0
     108            end
     109        end
     110    end
    111111end
    112112-- End create 4-dim grid.
     
    119119-- 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.
    120120-- 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.
    121 --      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
    122 --      z-axis, then you have to use the coordinate point (0,0,1).
     121--  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
     122--  z-axis, then you have to use the coordinate point (0,0,1).
    123123-- 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.
    124 --      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, "+-", "+", "-").
     124--  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, "+-", "+", "-").
    125125bodyParts={}
    126126for i=1,sSParts do
    127         bodyParts[i]={}
    128         for x=-math.floor(pDim/2),math.floor(pDim/2) do
    129                 bodyParts[i][x]={}
    130                 for y=-math.floor(pDim/2),math.floor(pDim/2) do
    131                         bodyParts[i][x][y]={}
    132                         for z=-math.floor(pDim/2),math.floor(pDim/2) do
    133                                 bodyParts[i][x][y][z]={}
    134                                 for k=0,3 do
    135                                         bodyParts[i][x][y][z][k]=0
    136                                 end
    137                         end
    138                 end
    139         end
    140         -- This contains the name of the mesh file.
    141         bodyParts[i][0][0][0][4]=""
    142         -- This contains the first possible rotation of your part, pitch=... yaw=... roll=... .
    143         bodyParts[i][0][0][0][5]=""
    144         -- This contains the second possible rotation of your part, pitch=... yaw=... roll=... .
    145         bodyParts[i][0][0][0][6]=""
    146         -- This contains the third possible rotation of your part, pitch=... yaw=... roll=... .
    147         bodyParts[i][0][0][0][7]=""
    148         -- Contains the movement rotation, rotationaxis=... rotationrate=... .
    149         bodyParts[i][0][0][0][8]=""
    150         -- Contains the attachment, if your part has an attachment, e.g. <ParticleEmitter .../>.
    151         bodyParts[i][0][0][0][9]=""
    152         -- Contains how many of this part you want to attach to your space station.
    153         bodyParts[i][0][0][0][10]=1
     127    bodyParts[i]={}
     128    for x=-math.floor(pDim/2),math.floor(pDim/2) do
     129        bodyParts[i][x]={}
     130        for y=-math.floor(pDim/2),math.floor(pDim/2) do
     131            bodyParts[i][x][y]={}
     132            for z=-math.floor(pDim/2),math.floor(pDim/2) do
     133                bodyParts[i][x][y][z]={}
     134                for k=0,3 do
     135                    bodyParts[i][x][y][z][k]=0
     136                end
     137            end
     138        end
     139    end
     140    -- This contains the name of the mesh file.
     141    bodyParts[i][0][0][0][4]=""
     142    -- This contains the first possible rotation of your part, pitch=... yaw=... roll=... .
     143    bodyParts[i][0][0][0][5]=""
     144    -- This contains the second possible rotation of your part, pitch=... yaw=... roll=... .
     145    bodyParts[i][0][0][0][6]=""
     146    -- This contains the third possible rotation of your part, pitch=... yaw=... roll=... .
     147    bodyParts[i][0][0][0][7]=""
     148    -- Contains the movement rotation, rotationaxis=... rotationrate=... .
     149    bodyParts[i][0][0][0][8]=""
     150    -- Contains the attachment, if your part has an attachment, e.g. <ParticleEmitter .../>.
     151    bodyParts[i][0][0][0][9]=""
     152    -- Contains how many of this part you want to attach to your space station.
     153    bodyParts[i][0][0][0][10]=1
    154154end
    155155----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    193193
    194194-- Insert the CuboidConnectionBody, it is three griddimensions long and one wide and high and can have only connections at griddimension 1
    195 --      (except the side in direction of griddimension 2) and griddimension 3 (except the side in direction of griddimension 2).
     195--  (except the side in direction of griddimension 2) and griddimension 3 (except the side in direction of griddimension 2).
    196196bodyParts[3][0][0][0][4]="CuboidConnBody.mesh"
    197197bodyParts[3][0][0][0][5]="pitch=-90"
     
    373373--This function actualizes the grid, which I have to call always after I have added a new part to the space station.
    374374function actualizeGrid(Index,x,y,z)
    375         for i=math.floor(-pDim/2)+1,math.floor(pDim/2) do
    376                 for j=math.floor(-pDim/2)+1,math.floor(pDim/2) do
    377                         for k=math.floor(-pDim/2)+1,math.floor(pDim/2) do
    378                                 if bodyParts[Index][i][j][k][0] == 1 then
    379                                         for l=0,3 do
    380                                                 grid[x+i][y+j][z+k][l] = bodyParts[Index][i][j][k][l]
    381                                         end
    382                                 end
    383                         end
    384                 end
    385         end
     375    for i=math.floor(-pDim/2)+1,math.floor(pDim/2) do
     376        for j=math.floor(-pDim/2)+1,math.floor(pDim/2) do
     377            for k=math.floor(-pDim/2)+1,math.floor(pDim/2) do
     378                if bodyParts[Index][i][j][k][0] == 1 then
     379                    for l=0,3 do
     380                        grid[x+i][y+j][z+k][l] = bodyParts[Index][i][j][k][l]
     381                    end
     382                end
     383            end
     384        end
     385    end
    386386end
    387387-- End actualizeGrid.
     
    390390-- If the part fits there it returns 1, otherwise 0.
    391391function checkPart(Index,x,y,z)
    392         check=1
    393         for i=math.floor(-pDim/2)+1,math.floor(pDim/2) do
    394                 for j=math.floor(-pDim/2)+1,math.floor(pDim/2) do
    395                         for k=math.floor(-pDim/2)+1,math.floor(pDim/2) do
    396                                 -- 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,
    397                                 --      which means that the part doesn't fit there.
    398                                 if bodyParts[Index][i][j][k][0] == 1 and grid[x+i][y+j][z+k][0] == 1 then
    399                                         check=0
    400                                 end
    401                         end
    402                 end
    403         end
    404         return check
     392    check=1
     393    for i=math.floor(-pDim/2)+1,math.floor(pDim/2) do
     394        for j=math.floor(-pDim/2)+1,math.floor(pDim/2) do
     395            for k=math.floor(-pDim/2)+1,math.floor(pDim/2) do
     396                -- 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,
     397                --  which means that the part doesn't fit there.
     398                if bodyParts[Index][i][j][k][0] == 1 and grid[x+i][y+j][z+k][0] == 1 then
     399                    check=0
     400                end
     401            end
     402        end
     403    end
     404    return check
    405405end
    406406-- End checkPart function.
     
    408408-- This function prints the model with tempPartIndex in the bodyParts array at position lx,ly,lz.
    409409-- If you need to rotate the model around his own axis, then you have to set movEntity true and define the details of the rotation in
    410 --      bodyParts[tempPartIndex][0][0][0][8].
     410--  bodyParts[tempPartIndex][0][0][0][8].
    411411-- If your model needs to be rotated like bodyParts[tempPartIndex][0][0][0][5], then side must be 1, for bodyParts[tempPartIndex][0][0][0][6] side must be 2,
    412 --      for bodyParts[tempPartIndex][0][0][0][7] side must be 3.
     412--  for bodyParts[tempPartIndex][0][0][0][7] side must be 3.
    413413function printModel(lx,ly,lz,tempPartIndex,movEntity,side)
    414         if movEntity == true then
    415                 print("<MovableEntity scale=1 position=\"") print(lx*gridDim*sSScale) print(",") print(ly*gridDim*sSScale) print(",") print(lz*gridDim*sSScale) print("\" ")
    416                 print(bodyParts[tempPartIndex][0][0][0][8]) print(">")
    417                 print("<attached>")
    418                 lx=0 ly=0 lz=0
    419         end
    420 
    421         print("<Model position=\"") print(lx*gridDim*sSScale) print(",") print(ly*gridDim*sSScale) print(",") print(lz*gridDim*sSScale)
    422         print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[tempPartIndex][0][0][0][4]) print("\"")
    423 
    424                 if side == 1 then
    425                         print(bodyParts[tempPartIndex][0][0][0][5]) print(">")
    426                 elseif side == 2 then
    427                         print(bodyParts[tempPartIndex][0][0][0][6]) print(">")
    428                 elseif side == 3 then
    429                         print(bodyParts[tempPartIndex][0][0][0][7]) print(">")
    430                 end
    431 
    432                 print("<attached>")
    433                         print(bodyParts[tempPartIndex][0][0][0][9])
    434                 print("</attached>")
    435 
    436         print("</Model>")
    437 
    438         if movEntity == true then
    439                 print("</attached>")
    440                 print("</MovableEntity>")
    441         end
     414    if movEntity == true then
     415        print("<MovableEntity scale=1 position=\"") print(lx*gridDim*sSScale) print(",") print(ly*gridDim*sSScale) print(",") print(lz*gridDim*sSScale) print("\" ")
     416        print(bodyParts[tempPartIndex][0][0][0][8]) print(">")
     417        print("<attached>")
     418        lx=0 ly=0 lz=0
     419    end
     420
     421    print("<Model position=\"") print(lx*gridDim*sSScale) print(",") print(ly*gridDim*sSScale) print(",") print(lz*gridDim*sSScale)
     422    print("\" scale=") print(sSScale) print(" mesh= \"") print(bodyParts[tempPartIndex][0][0][0][4]) print("\"")
     423
     424        if side == 1 then
     425            print(bodyParts[tempPartIndex][0][0][0][5]) print(">")
     426        elseif side == 2 then
     427            print(bodyParts[tempPartIndex][0][0][0][6]) print(">")
     428        elseif side == 3 then
     429            print(bodyParts[tempPartIndex][0][0][0][7]) print(">")
     430        end
     431
     432        print("<attached>")
     433            print(bodyParts[tempPartIndex][0][0][0][9])
     434        print("</attached>")
     435
     436    print("</Model>")
     437
     438    if movEntity == true then
     439        print("</attached>")
     440        print("</MovableEntity>")
     441    end
    442442end
    443443-- End function printModel().
     
    446446-- The arguments lx,ly,lz are the coordinates of the grid, where you want to set the part.
    447447-- The arguments xAxis,yAxis,zAxis can be 0 or 1, but only one argument out of the three can be 1. This means two of them must always be zero. You have to set xAxis to one,
    448 --      if your part is attached to a side, which faces into the x-direction (negative or positive, this is later specified with Dir), that means the x-Axis is a normal vector
    449 --      of the side to which you want to attach the part. The same for yAxis and zAxis.
     448--  if your part is attached to a side, which faces into the x-direction (negative or positive, this is later specified with Dir), that means the x-Axis is a normal vector
     449--  of the side to which you want to attach the part. The same for yAxis and zAxis.
    450450-- The argument Dir must be 1 if your side, where you want to attach the part, faces into the positive direction, -1 if the side faces into the negative direction. The side
    451 --      faces into the positive direction means, that the side of the side where the part will be attached is directed into the direction of the positive direction of the
    452 --      corresponding axis.
     451--  faces into the positive direction means, that the side of the side where the part will be attached is directed into the direction of the positive direction of the
     452--  corresponding axis.
    453453-- The argument index is the index of the part for the bodyParts array.
    454454-- The argument printMovEnt must be false if your part doesn't need to be attached to an extra MovableEntity. If your part must be attached to an extra MovableEntity
    455 --      this argument must be true. The extra MovableEntity is used to rotate the part around his own axis, or something like that.
     455--  this argument must be true. The extra MovableEntity is used to rotate the part around his own axis, or something like that.
    456456-- The argument printSide is like the argument side of the printModel() function. It defines how your part will be rotated. Read the commentary there.
    457457-- The function returns 0 if the part couldn't be set, because it did not fit there or there was no side to attach the part. It returns 1 if the part is successfully set.
    458458function setPart(lx,ly,lz,xAxis,yAxis,zAxis,Dir,index,printMovEnt,printSide)
    459459
    460         partSet=0
    461         -- For the bodyParts array I use 1 as x-, 2 as y- and 3 as z-Axis for the definition in which directions a part can have connections.
    462         coord=1*xAxis+2*yAxis+3*zAxis
    463         -- If I try to attach the part from the positive direction to the side of the space station, the part of the station (where I want to attach the new part) must have
    464         --      a connection into the positive direction. Otherwise I look from the negative side and so the part of the station must have a connection into the negative direction.
    465         if Dir==1 then
    466                 conn="+"
    467         elseif Dir==-1 then
    468                 conn="-"
    469         end
    470         -- I look from the direction defined through Dir, and here I check, whether I have reached a side of the space station, which means at position lx,ly,lz is nothing and
    471         --      at the next position is a part which can have a connection into the direction from where I look.
    472         if grid[lx][ly][lz][0] == 0 and grid[lx+(-1*xAxis*Dir)][ly+(-1*yAxis*Dir)][lz+(-1*zAxis*Dir)][0] == 1 and (grid[lx+(-1*xAxis*Dir)][ly+(-1*yAxis*Dir)][lz+(-1*zAxis*Dir)][coord]=="+-" or grid[lx+(-1*xAxis*Dir)][ly+(-1*yAxis*Dir)][lz+(-1*zAxis*Dir)][coord]==conn) then
    473                 -- This checks whether the part fits at that position or not.
    474                 check=checkPart(index,lx,ly,lz)
    475                 if check == 1 then
    476                         -- This prints the part.
    477                         printModel(lx,ly,lz,index,printMovEnt,printSide)
    478                         partSet=1
    479                         -- This actualizes the grid array with the values of the array bodyParts at the position index.
    480                         actualizeGrid(index,lx,ly,lz)
    481                 end
    482         end
    483         return partSet
     460    partSet=0
     461    -- For the bodyParts array I use 1 as x-, 2 as y- and 3 as z-Axis for the definition in which directions a part can have connections.
     462    coord=1*xAxis+2*yAxis+3*zAxis
     463    -- If I try to attach the part from the positive direction to the side of the space station, the part of the station (where I want to attach the new part) must have
     464    --  a connection into the positive direction. Otherwise I look from the negative side and so the part of the station must have a connection into the negative direction.
     465    if Dir==1 then
     466        conn="+"
     467    elseif Dir==-1 then
     468        conn="-"
     469    end
     470    -- I look from the direction defined through Dir, and here I check, whether I have reached a side of the space station, which means at position lx,ly,lz is nothing and
     471    --  at the next position is a part which can have a connection into the direction from where I look.
     472    if grid[lx][ly][lz][0] == 0 and grid[lx+(-1*xAxis*Dir)][ly+(-1*yAxis*Dir)][lz+(-1*zAxis*Dir)][0] == 1 and (grid[lx+(-1*xAxis*Dir)][ly+(-1*yAxis*Dir)][lz+(-1*zAxis*Dir)][coord]=="+-" or grid[lx+(-1*xAxis*Dir)][ly+(-1*yAxis*Dir)][lz+(-1*zAxis*Dir)][coord]==conn) then
     473        -- This checks whether the part fits at that position or not.
     474        check=checkPart(index,lx,ly,lz)
     475        if check == 1 then
     476            -- This prints the part.
     477            printModel(lx,ly,lz,index,printMovEnt,printSide)
     478            partSet=1
     479            -- This actualizes the grid array with the values of the array bodyParts at the position index.
     480            actualizeGrid(index,lx,ly,lz)
     481        end
     482    end
     483    return partSet
    484484end
    485485-- End function setPart().
     
    490490-- The argument parts is the number of different parts which you want to attach to a side.
    491491function spiralSet(xAxis,yAxis,zAxis,Dir,index,parts,printMovEnt,printSide)
    492         if index[0] ~= false then
    493                 -- The array vector contains the actual position where you try to set the part. vector[0],vector[1] and vector[3] contains the x,y,z-coordinate.
    494                 vector={}
    495                 -- This must be done, because there are different sides from where I try to attach a part.
    496                 coord1=1*yAxis+2*zAxis
    497                 coord2=math.mod(coord1+1,3)
    498                 coord3=math.mod(coord2+1,3)
    499 
    500                 for pc=1,parts do
    501                         tempIndex = index[pc]
    502                         for eachPart=1,bodyParts[tempIndex][0][0][0][10] do
    503                                 partSet=0
    504                                 vector[coord1]=math.floor(Dir*sSSize/2)-2*Dir
    505                                 while vector[coord1]~=math.floor(-1*Dir*sSSize/2)+2*Dir and partSet==0 do
    506                                         round=0
    507                                         while round<=math.floor(sSSize/2)-2 and partSet==0 do
    508                                                 vector[coord2]=round
    509                                                 vector[coord3]=-round
    510                                                 while vector[coord3]<=round and partSet==0 do
    511                                                         partSet=setPart(vector[0],vector[1],vector[2],xAxis,yAxis,zAxis,Dir,tempIndex,printMovEnt,printSide)
    512                                                         vector[coord3]=vector[coord3]+1
    513                                                 end
    514                                                 while vector[coord2]>=-round and partSet==0 do
    515                                                         partSet=setPart(vector[0],vector[1],vector[2],xAxis,yAxis,zAxis,Dir,tempIndex,printMovEnt,printSide)
    516                                                         vector[coord2]=vector[coord2]-1
    517                                                 end
    518                                                 while vector[coord3]>-round and partSet==0 do
    519                                                         partSet=setPart(vector[0],vector[1],vector[2],xAxis,yAxis,zAxis,Dir,tempIndex,printMovEnt,printSide)
    520                                                         vector[coord3]=vector[coord3]-1
    521                                                 end
    522                                                 while vector[coord2]<=round and partSet==0 do
    523                                                         partSet=setPart(vector[0],vector[1],vector[2],xAxis,yAxis,zAxis,Dir,tempIndex,printMovEnt,printSide)
    524                                                         vector[coord2]=vector[coord2]+1
    525                                                 end
    526                                                 round=round+1
    527                                         end
    528                                         vector[coord1]=vector[coord1]-Dir
    529                                 end
    530                         end
    531                 end
    532         end
     492    if index[0] ~= false then
     493        -- The array vector contains the actual position where you try to set the part. vector[0],vector[1] and vector[3] contains the x,y,z-coordinate.
     494        vector={}
     495        -- This must be done, because there are different sides from where I try to attach a part.
     496        coord1=1*yAxis+2*zAxis
     497        coord2=math.mod(coord1+1,3)
     498        coord3=math.mod(coord2+1,3)
     499
     500        for pc=1,parts do
     501            tempIndex = index[pc]
     502            for eachPart=1,bodyParts[tempIndex][0][0][0][10] do
     503                partSet=0
     504                vector[coord1]=math.floor(Dir*sSSize/2)-2*Dir
     505                while vector[coord1]~=math.floor(-1*Dir*sSSize/2)+2*Dir and partSet==0 do
     506                    round=0
     507                    while round<=math.floor(sSSize/2)-2 and partSet==0 do
     508                        vector[coord2]=round
     509                        vector[coord3]=-round
     510                        while vector[coord3]<=round and partSet==0 do
     511                            partSet=setPart(vector[0],vector[1],vector[2],xAxis,yAxis,zAxis,Dir,tempIndex,printMovEnt,printSide)
     512                            vector[coord3]=vector[coord3]+1
     513                        end
     514                        while vector[coord2]>=-round and partSet==0 do
     515                            partSet=setPart(vector[0],vector[1],vector[2],xAxis,yAxis,zAxis,Dir,tempIndex,printMovEnt,printSide)
     516                            vector[coord2]=vector[coord2]-1
     517                        end
     518                        while vector[coord3]>-round and partSet==0 do
     519                            partSet=setPart(vector[0],vector[1],vector[2],xAxis,yAxis,zAxis,Dir,tempIndex,printMovEnt,printSide)
     520                            vector[coord3]=vector[coord3]-1
     521                        end
     522                        while vector[coord2]<=round and partSet==0 do
     523                            partSet=setPart(vector[0],vector[1],vector[2],xAxis,yAxis,zAxis,Dir,tempIndex,printMovEnt,printSide)
     524                            vector[coord2]=vector[coord2]+1
     525                        end
     526                        round=round+1
     527                    end
     528                    vector[coord1]=vector[coord1]-Dir
     529                end
     530            end
     531        end
     532    end
    533533end
    534534-- End function spiralSet().
     
    554554xMax=math.random(math.floor(xLength/2),math.floor(xLength/2)+xVar)
    555555while x<xMax do
    556         -- The same for the y- and z-direction.
    557         y=math.random(-math.floor(yLength/2),-math.floor(yLength/2)+yVar)
    558         yMax=math.random(math.floor(yLength/2),math.floor(yLength/2)+yVar)
    559         while y<yMax do
    560                 yMax=math.random(math.floor(yLength/2),math.floor(yLength/2)+yVar)
    561                 z=math.random(-math.floor(zLength/2),-math.floor(zLength/2)+zVar)
    562                 zMax=math.random(math.floor(zLength/2),math.floor(zLength/2)+zVar)
    563                 while z<zMax do
    564                         -- This loop choses a bodypart, which fits at position (x,y,z).
    565                         -- If after the fifth time the part does still not fit we terminate the loop and set no part at postition (x,y,z).
    566                         partSet=0
    567                         counter=0
    568                         while counter<5 and partSet==0 do
    569                                 -- This choses randomly a bodyPartIndex, which is the index used for the parts in the array bodyParts.
    570                                 tempBodyPartIndex=math.random(1,sSBodyParts)
    571                                 check=checkPart(tempBodyPartIndex,x,y,z)
    572                                 -- If check == 1, this means that the part fits there, so we put it there and break the while true loop, to go on.
    573                                 if check == 1 then
    574                                         -- This prints the chosen part at position (x*gridDim*sSScale,y*gridDim*sSScale,z*gridDim*sSScale).
    575                                         printModel(x,y,z,tempBodyPartIndex,false,1)
    576                                         -- This actualizes the grid array with the values of the array bodyParts at the position tempBodyPartIndex, which is our randomly chosen part.
    577                                         actualizeGrid(tempBodyPartIndex,x,y,z)
    578                                         partSet=1
    579                                 end
    580                                 counter=counter+1
    581                         end
    582                         z=z+1
    583                 end
    584                 y=y+1
    585         end
    586         x=x+1
     556    -- The same for the y- and z-direction.
     557    y=math.random(-math.floor(yLength/2),-math.floor(yLength/2)+yVar)
     558    yMax=math.random(math.floor(yLength/2),math.floor(yLength/2)+yVar)
     559    while y<yMax do
     560        yMax=math.random(math.floor(yLength/2),math.floor(yLength/2)+yVar)
     561        z=math.random(-math.floor(zLength/2),-math.floor(zLength/2)+zVar)
     562        zMax=math.random(math.floor(zLength/2),math.floor(zLength/2)+zVar)
     563        while z<zMax do
     564            -- This loop choses a bodypart, which fits at position (x,y,z).
     565            -- If after the fifth time the part does still not fit we terminate the loop and set no part at postition (x,y,z).
     566            partSet=0
     567            counter=0
     568            while counter<5 and partSet==0 do
     569                -- This choses randomly a bodyPartIndex, which is the index used for the parts in the array bodyParts.
     570                tempBodyPartIndex=math.random(1,sSBodyParts)
     571                check=checkPart(tempBodyPartIndex,x,y,z)
     572                -- If check == 1, this means that the part fits there, so we put it there and break the while true loop, to go on.
     573                if check == 1 then
     574                    -- This prints the chosen part at position (x*gridDim*sSScale,y*gridDim*sSScale,z*gridDim*sSScale).
     575                    printModel(x,y,z,tempBodyPartIndex,false,1)
     576                    -- This actualizes the grid array with the values of the array bodyParts at the position tempBodyPartIndex, which is our randomly chosen part.
     577                    actualizeGrid(tempBodyPartIndex,x,y,z)
     578                    partSet=1
     579                end
     580                counter=counter+1
     581            end
     582            z=z+1
     583        end
     584        y=y+1
     585    end
     586    x=x+1
    587587end
    588588-- End attach all bodyparts.
     
    593593----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    594594-- Attach backParts, if there are some.
    595         spiralSet(0,0,1,1,backPartsIndex,backParts,false,1)
     595    spiralSet(0,0,1,1,backPartsIndex,backParts,false,1)
    596596-- End attach backParts.
    597597----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    599599----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    600600-- Attach frontParts, if there are.
    601         spiralSet(0,0,1,-1,frontPartsIndex,frontParts,false,1)
     601    spiralSet(0,0,1,-1,frontPartsIndex,frontParts,false,1)
    602602-- End attach frontParts.
    603603----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    605605----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    606606-- Attach parts on the left side of the space station.
    607         spiralSet(1,0,0,-1,leftSidePartsIndex,leftSideParts,true,1)
     607    spiralSet(1,0,0,-1,leftSidePartsIndex,leftSideParts,true,1)
    608608-- End attach left side parts.
    609609----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    611611----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    612612-- Attach parts on the right side of the space station.
    613         spiralSet(1,0,0,1,rightSidePartsIndex,rightSideParts,true,2)
     613    spiralSet(1,0,0,1,rightSidePartsIndex,rightSideParts,true,2)
    614614-- End attach right side parts.
    615615----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    617617----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    618618-- Attach parts on top of the space station.
    619         spiralSet(0,1,0,1,topPartsIndex,topParts,true,1)
     619    spiralSet(0,1,0,1,topPartsIndex,topParts,true,1)
    620620-- End attach top parts.
    621621----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    627627-- This iterates through the whole grid array.
    628628if connPartsIndex[0] ~= false then
    629         for x=math.floor(-sSSize/2)+2,math.floor(sSSize/2)-2 do
    630                 for y=math.floor(-sSSize/2)+2,math.floor(sSSize/2)-2 do
    631                         for z=math.floor(-sSSize/2)+2,math.floor(sSSize/2)-2 do
    632                                 tempConnPartIndex=connPartsIndex[math.random(1,connParts)]
    633                                 -- 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
    634                                 --      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
    635                                 --      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.
    636                                 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
    637                                         -- This prints the connection part, the +1/2 is because the connection is set exactly in the middle of two gridpoints.
    638                                         printModel(x+1/2,y,z,tempConnPartIndex,false,1)
    639                                 end
    640                                 -- The same as in the x-direction, but for the y-direction.
    641                                 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
    642                                         printModel(x,y+1/2,z,tempConnPartIndex,false,2)
    643                                 end
    644                                 -- The same as in the x-direction, but for the z-direction.
    645                                 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
    646                                         printModel(x,y,z+1/2,tempConnPartIndex,false,3)
    647                                 end
    648                         end
    649                 end
    650         end
     629    for x=math.floor(-sSSize/2)+2,math.floor(sSSize/2)-2 do
     630        for y=math.floor(-sSSize/2)+2,math.floor(sSSize/2)-2 do
     631            for z=math.floor(-sSSize/2)+2,math.floor(sSSize/2)-2 do
     632                tempConnPartIndex=connPartsIndex[math.random(1,connParts)]
     633                -- 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
     634                --  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
     635                --  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.
     636                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
     637                    -- This prints the connection part, the +1/2 is because the connection is set exactly in the middle of two gridpoints.
     638                    printModel(x+1/2,y,z,tempConnPartIndex,false,1)
     639                end
     640                -- The same as in the x-direction, but for the y-direction.
     641                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
     642                    printModel(x,y+1/2,z,tempConnPartIndex,false,2)
     643                end
     644                -- The same as in the x-direction, but for the z-direction.
     645                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
     646                    printModel(x,y,z+1/2,tempConnPartIndex,false,3)
     647                end
     648            end
     649        end
     650    end
    651651end
    652652-- End attach all connectionparts.
     
    671671-- This function is for the lazy guys, which do not care how the space station looks like, so I use some good standard values.
    672672function createSpaceStation()
    673         createSpaceStationPar(0,4,1,2,1,6,1,100)
     673    createSpaceStationPar(0,4,1,2,1,6,1,100)
    674674end
    675675-- End createSpaceStaion() function.
Note: See TracChangeset for help on using the changeset viewer.