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