share/hedgewars/Data/Scripts/Multiplayer/Tunnels.lua
changeset 7785 9b5dceaea976
child 7791 b937274608ba
equal deleted inserted replaced
7784:cf6261f7fdb5 7785:9b5dceaea976
       
     1  PointsBuffer = ''  -- A string to accumulate points in
       
     2  function AddPoint(x, y, width, erase)
       
     3      PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff))
       
     4      if width then
       
     5          width = bor(width,0x80)
       
     6          if erase then
       
     7              width = bor(width,0x40)
       
     8          end
       
     9          PointsBuffer = PointsBuffer .. string.char(width)
       
    10      else
       
    11          PointsBuffer = PointsBuffer .. string.char(0)
       
    12      end
       
    13      if #PointsBuffer > 245 then
       
    14          ParseCommand('draw '..PointsBuffer)
       
    15          PointsBuffer = ''
       
    16      end
       
    17  end
       
    18  function FlushPoints()
       
    19      if #PointsBuffer > 0 then
       
    20          ParseCommand('draw '..PointsBuffer)
       
    21          PointsBuffer = ''
       
    22      end
       
    23  end
       
    24 
       
    25 
       
    26 function onGameInit()
       
    27     MapGen = 2
       
    28     TemplateFilter = 0
       
    29     for i = 200,2000,600 do
       
    30         AddPoint(1,i,63)
       
    31         AddPoint(4000,i)
       
    32     end
       
    33 
       
    34         side = 0
       
    35     for i = 0,GetRandom(15)+30 do
       
    36         size = GetRandom(15)+3
       
    37         --side = GetRandom(4)
       
    38         dx = div(size,4)
       
    39         maxshift = dx
       
    40         dy = dx
       
    41         if side == 0 then
       
    42             x = 0
       
    43             y = GetRandom(2048)
       
    44             dy = 0
       
    45         elseif side == 1 then
       
    46             x = GetRandom(4096)
       
    47             y = 0
       
    48             dx = 0
       
    49         elseif side == 2 then
       
    50             x = 4096
       
    51             y = GetRandom(2048)
       
    52             dx = -dx
       
    53             dy = 0
       
    54         elseif side == 3 then
       
    55             x = GetRandom(4096)
       
    56             y = 2048
       
    57             dx = 0
       
    58             dy = -dy
       
    59         elseif side == 4 then
       
    60             x = GetRandom(2500)+500
       
    61             y = GetRandom(1250)+250
       
    62             dx = GetRandom(maxshift*2)-maxshift
       
    63             dy = GetRandom(maxshift*2)-maxshift
       
    64         end
       
    65         length = GetRandom(500)+500
       
    66         while (length > 0) and (x > -300) and (y > -300) and (x < 4400) and (y < 2400) do
       
    67             length = length - 1
       
    68             AddPoint(x,y,size,true)
       
    69             x = x + dx
       
    70             y = y + dy
       
    71             if GetRandom(4) == 0 then
       
    72                 shift = GetRandom(10)-5
       
    73                 if (shift > 0) and (dx < maxshift) then
       
    74                     dx = dx + shift
       
    75                 elseif (shift < 0) and (dx > -maxshift) then
       
    76                     dx = dx + shift
       
    77                 end
       
    78                 shift = GetRandom(10)-5
       
    79                 if (shift > 0) and (dy < maxshift) then
       
    80                     dy = dy + shift
       
    81                 elseif (shift < 0) and (dy > -maxshift) then
       
    82                     dy = dy + shift
       
    83                 end
       
    84             end
       
    85         end
       
    86         if side < 5 then
       
    87             side = side + 1
       
    88         else 
       
    89             side = 0
       
    90         end
       
    91     end
       
    92 
       
    93     FlushPoints()
       
    94 end