-- sam686: http://bitfighter.org/forums/ucp.php?i=pm&mode=compose&u=122 logprint("generating map 6357.levelgen") -- note, there is one more row and one more column then what it inputs sizex = tonumber(arg[1]) or 12 sizey = tonumber(arg[2]) or 10 sizecount = tonumber(arg[3]) or 150 totalteams = tonumber(arg[4]) or 1 -- flagbits -- +1 for BotNavMeshZone -- +2 for forcefield -- +4 for mirrorX -- +8 for mirrorY -- +16 for turrets -- +32 for turret and forcefield in teams -- +64 for flags being far away (for CTF) -- +128 for goals being far away flagbits = tonumber(arg[5]) or 1 useBotNavMeshZone = 0 useforcefield = 0 useGoalZones = 0 mirrorX = 0 mirrorY = 0 useTurrets = 0 TurretTeams = 0 flagFar = 0 goalFar = 0 offsetx=math.floor(sizex/2) offsety=math.floor(sizey/2) if(flagbits>=128) then goalFar = 1 flagbits=flagbits-128 end if(flagbits>=64) then flagFar = 1 flagbits=flagbits-64 end if(flagbits>=32) then TurretTeams = 1 flagbits=flagbits-32 end if(flagbits>=16) then useTurrets = 1 flagbits=flagbits-16 end if(flagbits>=8) then mirrorY = 1 offsety = 0 flagbits=flagbits-8 end if(flagbits>=4) then mirrorX = 1 offsetx = 0 flagbits=flagbits-4 end if(flagbits>=2) then useforcefield = 1 flagbits=flagbits-2 end if(flagbits>=1) then useBotNavMeshZone = 1 end useLoadout = tonumber(arg[6]) or 0 useTeamLoadout = tonumber(arg[7]) or 0 useGoalZones = tonumber(arg[8]) or 0 useTeamGoalZones = tonumber(arg[9]) or 0 useFlagItem = tonumber(arg[10]) or 0 useTeamFlagItem = tonumber(arg[11]) or 0 useRepairItem = tonumber(arg[12]) or 0 used = {} used2 = {} function output1(str1) -- logprint(str1) levelgen:addLevelLine(str1) end function randommaze() local x=offsetx local y=offsety for a = 0, sizecount do local b=0 if(math.random(2) < 2) then b=1 end if(math.random(2) < 2) then b=b+2 end if(b == 0 and x == 0) then b=2 end if(b == 1 and y == 0) then b=3 end if(b == 2 and x == sizex) then b=0 end if(b == 3 and y == sizey) then b=1 end -- logprint(b .. " " .. x .. " " .. y) if(b==2) then b=used[y][x] if(b==0) then b=1 end if(b==2) then b=3 end used[y][x]=b x=x+1 else if(b==3) then b=used[y][x] if(b<2) then b=b+2 end used[y][x]=b y=y+1 else if(b==0) then x=x-1 b=used[y][x] if(b==0) then b=1 end if(b==2) then b=3 end used[y][x]=b else if(b==1) then y=y-1 b=used[y][x] if(b<2) then b=b+2 end used[y][x]=b end end end end end end function writepath(t,x,y,x1,y1,x2,y2) -- for wall at N S output1("BarrierMaker 50 " .. (y2 * 0.1 + x) .. " " .. (y1 * 0.1 + y) .. " " .. (y2 * 0.1 + x1 + x) .. " " .. (y1 * 0.1 + x2 + y)) output1("BarrierMaker 50 " .. (y2 * 0.9 + x) .. " " .. (y1 * 0.9 + y) .. " " .. (y2 * 0.9 + x1 + x) .. " " .. (y1 * 0.9 + x2 + y)) if(useforcefield == 1) then output1("ForceFieldProjector " .. (t) .. " " .. (x1 * 0.5 + y2 * 0.2 + x) .. " " .. (y1 * 0.2 + x2 * 0.5 + y) .. " 0") end if(useBotNavMeshZone == 1) then output1("BotNavMeshZone " .. (y2 * 0.2 + x) .. " " .. (y1 * 0.2 + y) .. " " .. (y2 * 0.2 + x1 + x) .. " " .. (y1 * 0.2 + x2 + y) .. " " .. (y2 * 0.8 + x1 + x) .. " " .. (y1 * 0.8 + x2 + y) .. " " .. (y2 * 0.8 + x) .. " " .. (y1 * 0.8 + y)) end end function writeturn(t,x,y,x1,y1,x2,y2) -- for wall at S E output1("BarrierMaker 50 " .. (y2*.9+x) .. " " .. (y1*.9+y) .. " " .. (x1*.3+y2*.9+x) .. " " .. (y1*.9+x2*.3+y) .. " " .. (x1*.6+y2*.8+x) .. " " .. (y1*.8+x2*.6+y) .. " " .. (x1*.8+y2*.6+x) .. " " .. (y1*.6+x2*.8+y) .. " " .. (x1*.9+y2*.3+x) .. " " .. (y1*.3+x2*.9+y) .. " " .. (x1*.9+x) .. " " .. (x2*.9+y)) if(useBotNavMeshZone == 1) then output1("BotNavMeshZone " .. (x) .. " " .. (y) .. " " .. (x1 * 0.8 + x) .. " " .. (x2 * 0.8 + y) .. " " .. (x1 * 0.8 + y2 * 0.8 + x) .. " " .. (y1 * 0.8 + x2 * 0.8 + y) .. " " .. (y2 * 0.8 + x) .. " " .. (y1 * 0.8 + y)) end end function writethreeway(t,x,y,x1,y1,x2,y2) -- for wall at N output1("BarrierMaker 50 " .. (y2 * 0.1 + x) .. " " .. (y1 * 0.1 + y) .. " " .. (y2 * 0.1 + x1 + x) .. " " .. (y1 * 0.1 + x2 + y)) if(useTurrets == 1) then output1("Turret " .. (t) .. " " .. (x1 * 0.5 + y2 * 0.2 + x) .. " " .. (y1 * 0.2 + x2 * 0.5 + y) .. " 0") end if(useBotNavMeshZone == 1) then output1("BotNavMeshZone " .. (y2 * 0.2 + x) .. " " .. (y1 * 0.2 + y) .. " " .. (y2 * 0.2 + x1 + x) .. " " .. (y1 * 0.2 + x2 + y) .. " " .. (x1 + y2 + x) .. " " .. (y1 + x2 + y) .. " " .. (y2 + x) .. " " .. (y1 + y)) end end function writedeadend(t,x,y,x1,y1,x2,y2) -- for wall at N S E output1("BarrierMaker 50 " .. (y2*.1+x) .. " " .. (y1*.1+y) .. " " .. (x1*.9+y2*.1+x) .. " " .. (y1*.1+x2*.9+y) .. " " .. (x1*.9+y2*.9+x) .. " " .. (y1*.9+x2*.9+y) .. " " .. (y2*.9+x) .. " " .. (y1*.9+y)) if(useBotNavMeshZone == 1) then output1("BotNavMeshZone " .. (y2 * 0.2 + x) .. " " .. (y1 * 0.2 + y) .. " " .. (x1 * 0.8 + y2 * 0.2 + x) .. " " .. (y1 * 0.2 + x2 * 0.8 + y) .. " " .. (x1 * 0.8 + y2 * 0.8 + x) .. " " .. (y1 * 0.8 + x2 * 0.8 + y) .. " " .. (y2 * 0.8 + x) .. " " .. (y1 * 0.8 + y)) end end function writefourway(t,x,y,x1,y1,x2,y2) if(useBotNavMeshZone == 1) then output1("BotNavMeshZone " .. (x) .. " " .. (y) .. " " .. (x1 + x) .. " " .. (x2 + y) .. " " .. (x1 + y2 + x) .. " " .. (y1 + x2 + y) .. " " .. (y2 + x) .. " " .. (y1 + y)) end end function writedir(t,x,y,n,e,w,s) if(TurretTeams==0 or t>=totalteams) then t=-1 end -- if true then it is a wall if(n == 1) then if(e == 1) then if(w == 1) then if(s == 1) then -- all 4 sides is walls else writedeadend(t,x+1,y+1,0,0,-1,-1) end else if(s == 1) then writedeadend(t,x,y,1,1,0,0) else writeturn(t,x,y+1,1,-1,0,0) end end else if(w == 1) then if(s == 1) then writedeadend(t,x+1,y,-1,1,0,0) else writeturn(t,x+1,y+1,-1,-1,0,0) end else if(s == 1) then writepath(t,x,y,1,1,0,0) else writethreeway(t,x,y,1,1,0,0) end end end else if(e == 1) then if(w == 1) then if(s == 1) then writedeadend(t,x,y,0,0,1,1) else writepath(t,x,y,0,0,1,1) end else if(s == 1) then writeturn(t,x,y,1,1,0,0) else writethreeway(t,x+1,y+1,0,0,-1,-1) end end else if(w == 1) then if(s == 1) then writeturn(t,x+1,y,-1,1,0,0) else writethreeway(t,x,y,0,0,1,1) end else if(s == 1) then writethreeway(t,x+1,y+1,-1,-1,0,0) else writefourway(t,x,y,1,1,0,0) end end end end end function spawn1(x,y,t) if(t 0) then c=used[i-1][j] end if(c < 2) then c=1 else c=0 end if(a >= 2) then a=a-2 b=0 end a=1-a if(c == 0 or a == 0 or g == 0 or b == 0) then used2[i][j]=1 if(mirrorX==1) then if(j==0) then g=0 end end if(mirrorY==1) then if(i == 0) then c=0 end writedir(teamnum3s,j-offsetx,-i-offsety-1,b,a,g,c) if(mirrorX==1) then writedir(teamnum4s,-j-offsetx-1,-i-offsety-1,b,g,a,c) end end writedir(0,j-offsetx,i-offsety,c,a,g,b) if(mirrorX==1) then writedir(teamnum2s,-j-offsetx-1,i-offsety,c,g,a,b) end spawn1(j-offsetx,i-offsety,teamnum1) if(mirrorX) then spawn1(-j-offsetx-1,i-offsety,teamnum2) teamnum2=teamnum2+teamnumstep if(teamnum2>=totalteams) then teamnum2=teamnum2s end end if(mirrorY) then spawn1(j-offsetx,-i-offsety-1,teamnum3) teamnum3=teamnum3+teamnumstep if(teamnum3>=totalteams) then teamnum3=teamnum3s end if(mirrorX) then spawn1(-j-offsetx-1,i-offsety-1,teamnum4) teamnum4=teamnum4+teamnumstep if(teamnum4>=totalteams) then teamnum4=teamnum4s end end end teamnum1=teamnum1+teamnumstep if(teamnum1>=totalteams) then teamnum1=0 end else used2[i][j]=0 end g=a end end function putitem1(type,x,y,str1,str1after) if(type==1) then output1(str1 .. (x+0.3) .. " " .. (y+0.3) .. " " .. (x+0.7) .. " " .. (y+0.3) .. " " .. (x+0.7) .. " " .. (y+0.7) .. " " .. (x+0.3) .. " " .. (y+0.7) .. str1after) elseif(type==2) then output1(str1 .. (x+0.3) .. " " .. (y+0.5) .. " " .. (x+0.5) .. " " .. (y+0.3) .. " " .. (x+0.7) .. " " .. (y+0.5) .. " " .. (x+0.5) .. " " .. (y+0.7) .. str1after) else output1(str1 .. (x+0.5) .. " " .. (y+0.5) .. str1after) end end function randomitem1(type,str1,str1after) local tt=0 local isteams=0 local isfaraway=0 if(type>=200) then type=type-200 isfaraway=1 end if(type>=100) then type=type-100 isteams=1 end for a=0, 50000 do local x=math.random(sizex+1)-1 local y=math.random(sizey+1)-1 if(isfaraway==1) then local a1=math.floor(a/16) if(mirrorX) then if(asizex) then x=sizex end if(y>sizey) then y=sizey end if(used2[y][x]==1) then used2[y][x]=2 if(isteams==1) then putitem1(type,x-offsetx,y-offsety,str1 .. (tt) .. " ",str1after) tt=tt+1 if(tt>=totalteams) then return 0 end if(mirrorX==1) then putitem1(type,-x-offsetx-1,y-offsety,str1 .. (tt) .. " ",str1after) tt=tt+1 if(tt>=totalteams) then return 0 end end if(mirrorY==1) then putitem1(type,x-offsetx,-y-offsety-1,str1 .. (tt) .. " ",str1after) tt=tt+1 if(tt>=totalteams) then return 0 end if(mirrorX==1) then putitem1(type,-x-offsetx-1,-y-offsety-1,str1 .. (tt) .. " ",str1after) tt=tt+1 if(tt>=totalteams) then return 0 end end end else putitem1(type,x-offsetx,y-offsety,str1,str1after) if(mirrorX==1) then putitem1(type,-x-offsetx-1,y-offsety,str1,str1after) end if(mirrorY==1) then putitem1(type,x-offsetx,-y-offsety-1,str1,str1after) if(mirrorX==1) then putitem1(type,-x-offsetx-1,-y-offsety-1,str1,str1after) end end return 0 end end end return 1 end for d=1,useLoadout do randomitem1(2,"LoadoutZone -1 ","") end for d=1,useGoalZones do randomitem1(goalFar*200+1,"GoalZone -1 ","") end for d=1,useFlagItem do randomitem1(flagFar*200,"FlagItem -1 ","") end for d=1,useRepairItem do randomitem1(0,"RepairItem ","") end for d=1,useTeamLoadout do randomitem1(102,"LoadoutZone ","") end for d=1,useTeamGoalZones do randomitem1(goalFar*200+101,"GoalZone ","") end for d=1,useTeamFlagItem do randomitem1(flagFar*200+100,"FlagItem ","") end