-- place this script at the bottom of level lines, -- not the top, to make sure script runs last. -- it is not perfect, uses too much bot zones (2000+), but it works -- Client may lag out severely caused by sending too much bot zones. -- Script zzzzz.levelgen 16 0.2 255 -- Script zzzzz.levelgen [size] [min-block-size] [gridsize] -- the Gridsize needs to be equal to the level "Gridsize" -- to test a robot in Capture the Flag. -- Robot 0 quickbotv2.bot .5 1 0 1 .25 -- get quickbotv2 from bitfighter.org forum -- SAM686 -- remove "--" to test if pointCanSeePoint works. -- Pt1 = Point(100,0) -- Pt2 = Point(99,1) -- logprint(levelgen:pointCanSeePoint(Pt1,Pt2) ) function output1(str1) -- logprint(str1) levelgen:addLevelLine(str1) end size=tonumber(arg[1]) or 16 minsize=tonumber(arg[2]) or 0.2 -- GRID SIZE - problem can be caused by comparing while not the grid size. gridsize=tonumber(arg[3]) or 255 function CalcLinePart(x1,y1,x2,y2) local mid=0.5 local c=0.25 local main = Point(y1)*gridsize,x1*gridsize) while(c > 0.1) local test = Point((y1*mid+y2*(1-mid))*gridsize,(x1*mid+x2*(1-mid))*gridsize) if(levelgen:pointCanSeePoint(nw,se) == true) then mid = mid + c else mid = mid - c endif c = c * 0.5 end mid = mid - c return mid end function CalcBot(n,w,s,e) local nw = Point(n*gridsize,w*gridsize) local ne = Point(n*gridsize,e*gridsize) local sw = Point(s*gridsize,w*gridsize) local se = Point(s*gridsize,e*gridsize) local nwd = levelgen:pointCanSeePoint(nw,se) local ned = levelgen:pointCanSeePoint(ne,sw) local ww = levelgen:pointCanSeePoint(nw,sw) local ee = levelgen:pointCanSeePoint(ne,se) local nn = levelgen:pointCanSeePoint(nw,ne) local ss = levelgen:pointCanSeePoint(sw,se) if(nwd == true && ned==true && nn==true && ss==true && ee==true && ww==true) then output1("BotNavMeshZone " .. n .. " " .. w .. " " .. n .. " " .. e .. " " .. s .. " " .. e .. " " .. s .. " " .. w); else if(e > w+minsize and s > n+minsize) then local midx = (n + s) * 0.5 local midy = (w + e) * 0.5 CalcBot(n,w,midx,midy) CalcBot(n,midy,midx,e) CalcBot(midx,w,s,midy) CalcBot(midx,midy,s,e) else if(nwd==true) then if(nn==true and ee==true) then output1("BotNavMeshZone " .. n .. " " .. w .. " " .. n .. " " .. e .. " " .. s .. " " .. e); end if(ss==true and ww==true) then output1("BotNavMeshZone " .. n .. " " .. w .. " " .. s .. " " .. e .. " " .. s .. " " .. w); end elseif(ned==true) then if(nn==true and ww==true) then output1("BotNavMeshZone " .. n .. " " .. w .. " " .. n .. " " .. e .. " " .. s .. " " .. w); end if(ss==true and ee==true) then output1("BotNavMeshZone " .. n .. " " .. e .. " " .. s .. " " .. e .. " " .. s .. " " .. w); end elseif(nn==true or ss==true) then if(nn=true) then local w1=CalcLinePart(n,w,s,w) local e1=CalcLinePart(n,e,s,e) if(w1 > 0.05 and e1 > 0.05) then output1("BotNavMeshZone " .. n .. " " .. w .. " " .. n .. " " .. e .. " " .. (s*e1+n*(1.0-e1)) .. " " .. e .. " " .. (s*w1+n*(1.0-w1)) .. " " .. w); end end if(ss=true) then local w1=CalcLinePart(s,w,n,w) local e1=CalcLinePart(s,e,n,e) if(w1 > 0.05 and e1 > 0.05) then output1("BotNavMeshZone " .. (n*w1+s*(1.0-w1)) .. " " .. w .. " " .. (n*e1+s*(1.0-e1)) .. " " .. e .. " " .. s .. " " .. e .. " " .. s .. " " .. w); end end else if(ww=true) then local n1=CalcLinePart(n,w,n,e) local s1=CalcLinePart(s,w,s,e) if(w1 > 0.05 and e1 > 0.05) then output1("BotNavMeshZone " .. n .. " " .. w .. " " .. n .. " " .. (e*n1+w*(1.0-n1)) .. " " .. s .. " " .. (e*s1+w*(1.0-s1)) .. " " .. s .. " " .. w); end end if(ee=true) then local n1=CalcLinePart(n,e,n,w) local s1=CalcLinePart(s,e,s,w) if(w1 > 0.05 and e1 > 0.05) then output1("BotNavMeshZone " .. n .. " " .. (w*n1+e*(1.0-n1)) .. " " .. n .. " " .. e .. " " .. s .. " " .. e .. " " .. s .. " " .. (w*s1+e*(1.0-s1))); end end end end end end CalcBot(-size,-size,size,size)