1 -- spawns 2000 mines in a bit to see if engine can deal with it |
|
2 |
|
3 -- taken from http://code.google.com/p/hedgewars/wiki/LuaDrawing |
|
4 PointsBuffer = '' -- A string to accumulate points in |
|
5 function AddPoint(x, y, width, erase) |
|
6 PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff)) |
|
7 if width then |
|
8 width = bor(width,0x80) |
|
9 if erase then |
|
10 width = bor(width,0x40) |
|
11 end |
|
12 PointsBuffer = PointsBuffer .. string.char(width) |
|
13 else |
|
14 PointsBuffer = PointsBuffer .. string.char(0) |
|
15 end |
|
16 if #PointsBuffer > 245 then |
|
17 ParseCommand('draw '..PointsBuffer) |
|
18 PointsBuffer = '' |
|
19 end |
|
20 end |
|
21 function FlushPoints() |
|
22 if #PointsBuffer > 0 then |
|
23 ParseCommand('draw '..PointsBuffer) |
|
24 PointsBuffer = '' |
|
25 end |
|
26 end |
|
27 |
|
28 |
|
29 local ta_pointsize = 63 |
|
30 local ta_radius = (ta_pointsize * 10 + 6) / 2 |
|
31 |
|
32 local sqrttwo = math.sqrt(2) |
|
33 |
|
34 -- creates round test area |
|
35 function AddTestArea(testarea) |
|
36 step = 100 |
|
37 xstep = step * testarea["xdir"] |
|
38 ystep = step * testarea["ydir"] |
|
39 x = testarea["x"] |
|
40 y = testarea["y"] |
|
41 if xstep * ystep ~= 0 then |
|
42 xstep = math.floor(xstep / sqrttwo) |
|
43 ystep = math.floor(ystep / sqrttwo) |
|
44 end |
|
45 AddPoint(x, y, ta_pointsize); |
|
46 AddPoint(x + xstep, y + ystep, ta_pointsize, true); |
|
47 end |
|
48 |
|
49 -- vertical test area |
|
50 local taa_v2 = {x= 350, y=1500, xdir= 0, ydir=-1} |
|
51 |
|
52 -- fail counter |
|
53 local nfailed = 0 |
|
54 local nspawned = 0 |
|
55 local ndied = 0 |
|
56 |
|
57 function onGameInit() |
|
58 -- At first we have to overwrite/set some global variables |
|
59 -- that define the map, the game has to load, as well as |
|
60 -- other things such as the game rules to use, etc. |
|
61 -- Things we don't modify here will use their default values. |
|
62 |
|
63 -- The base number for the random number generator |
|
64 Seed = 1 |
|
65 -- The map to be played |
|
66 MapGen = mgDrawn |
|
67 -- The theme to be used |
|
68 Theme = "Bamboo" |
|
69 -- Game settings and rules |
|
70 EnableGameFlags(gfOneClanMode, gfDisableWind, gfDisableLandObjects, gfDisableGirders, gfSolidLand) |
|
71 CaseFreq = 0 |
|
72 MinesNum = 0 |
|
73 Explosives = 0 |
|
74 |
|
75 -- No damage please |
|
76 DamagePercent = 1 |
|
77 |
|
78 -- Draw Map |
|
79 AddPoint(10,30,0) -- hog spawn platform |
|
80 -- test areas |
|
81 AddTestArea(taa_v2) |
|
82 |
|
83 FlushPoints() |
|
84 |
|
85 -- Create the player team |
|
86 AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default") |
|
87 -- And add a hog to it |
|
88 player = AddHog("Hunter", 0, 1, "NoHat") |
|
89 -- place it on how spawn platform |
|
90 SetGearPosition(player, 10, 10) |
|
91 end |
|
92 |
|
93 local pass = 0 |
|
94 local nMines = 0 |
|
95 local maxMines = 2000 |
|
96 |
|
97 function onGameStart() |
|
98 local maxPass = maxMines / 25 |
|
99 for pass = 1, maxPass, 1 do |
|
100 pass = pass + 1 |
|
101 -- spawn 25 mines |
|
102 for i = 0, 480, 20 do |
|
103 AddGear(110 + i, 1000 - i - (pass * 30), gtMine, 0, 0, 0, 0) |
|
104 nMines = nMines + 1 |
|
105 end |
|
106 end |
|
107 end |
|
108 |
|
109 function onNewTurn() |
|
110 WriteLnToConsole('Engine succeessfully dealt with ' .. nMines .. ' mines!') |
|
111 EndLuaTest(TEST_SUCCESSFUL) |
|
112 end |
|