author | unC0Rr |
Wed, 18 Feb 2015 14:44:59 +0300 | |
changeset 10832 | ad257b8b2816 |
parent 10611 | 58cad46782ff |
permissions | -rw-r--r-- |
10026 | 1 |
|
2 |
local ta_pointsize = 63 |
|
3 |
local ta_radius = (ta_pointsize * 10 + 6) / 2 |
|
4 |
||
5 |
-- creates round test area |
|
6 |
function AddTestArea(testarea) |
|
7 |
step = 200 |
|
8 |
xstep = step * testarea["xdir"] |
|
9 |
ystep = step * testarea["ydir"] |
|
10 |
x = testarea["x"] |
|
11 |
y = testarea["y"] |
|
12 |
AddPoint(x, y, ta_pointsize); |
|
13 |
AddPoint(x + xstep, y + ystep); |
|
14 |
end |
|
15 |
||
16 |
-- vertical test areas |
|
17 |
local taa_v1 = {x= 350, y= 400, xdir= 0, ydir= 1} |
|
18 |
local taa_v2 = {x= 350, y=1500, xdir= 0, ydir=-1} |
|
19 |
-- horizontal test areas |
|
20 |
local taa_h1 = {x=1150, y= 400, xdir= 1, ydir= 0} |
|
21 |
local taa_h2 = {x=1200, y=1100, xdir=-1, ydir= 0} |
|
22 |
-- diagonal test areas |
|
23 |
local taa_d1 = {x=2200, y= 400, xdir= 1, ydir= 1} |
|
24 |
local taa_d2 = {x=2000, y=1500, xdir= 1, ydir=-1} |
|
25 |
local taa_d3 = {x=3300, y= 400, xdir=-1, ydir= 1} |
|
26 |
local taa_d4 = {x=3300, y=1500, xdir=-1, ydir=-1} |
|
27 |
||
28 |
-- fail counter |
|
29 |
local nfailed = 0 |
|
30 |
local nspawned = 0 |
|
31 |
local ndied = 0 |
|
32 |
||
33 |
function onGameInit() |
|
34 |
-- At first we have to overwrite/set some global variables |
|
35 |
-- that define the map, the game has to load, as well as |
|
36 |
-- other things such as the game rules to use, etc. |
|
37 |
-- Things we don't modify here will use their default values. |
|
38 |
||
39 |
-- The base number for the random number generator |
|
40 |
Seed = 1 |
|
41 |
-- The map to be played |
|
10421 | 42 |
MapGen = mgDrawn |
10026 | 43 |
-- The theme to be used |
44 |
Theme = "Bamboo" |
|
45 |
-- Game settings and rules |
|
46 |
EnableGameFlags(gfOneClanMode, gfDisableWind, gfDisableLandObjects, gfDisableGirders, gfSolidLand) |
|
47 |
CaseFreq = 0 |
|
48 |
MinesNum = 0 |
|
49 |
Explosives = 0 |
|
50 |
||
51 |
-- No damage please |
|
52 |
DamagePercent = 1 |
|
53 |
||
54 |
-- Draw Map |
|
55 |
AddPoint(10,30,0) -- hog spawn platform |
|
56 |
-- test areas |
|
57 |
AddTestArea(taa_v1) |
|
58 |
AddTestArea(taa_v2) |
|
59 |
AddTestArea(taa_h1) |
|
60 |
AddTestArea(taa_h2) |
|
61 |
AddTestArea(taa_d1) |
|
62 |
AddTestArea(taa_d2) |
|
63 |
AddTestArea(taa_d3) |
|
64 |
AddTestArea(taa_d4) |
|
65 |
||
66 |
FlushPoints() |
|
67 |
||
68 |
-- Create the player team |
|
69 |
AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default") |
|
70 |
-- And add a hog to it |
|
71 |
player = AddHog("Hunter", 0, 1, "NoHat") |
|
72 |
-- place it on how spawn platform |
|
73 |
SetGearPosition(player, 10, 10) |
|
74 |
end |
|
75 |
||
76 |
-- xdir/ydir is direction in which to fire the drills |
|
77 |
function SpawnDrillRocketArray(testarea) |
|
78 |
xdir = testarea["xdir"] |
|
79 |
ydir = testarea["ydir"] |
|
80 |
centerx = testarea["x"] |
|
81 |
centery = testarea["y"] |
|
82 |
distance = 23 |
|
83 |
d = distance |
|
84 |
radius = ta_radius |
|
85 |
local xmin, xmax, ymin, ymax |
|
10028
9e742fc72696
add a test based on unC0Rr's suggestion. still a lot of mess and redundancy involved, sry :P
sheepluva
parents:
10026
diff
changeset
|
86 |
speed = 900000; |
9e742fc72696
add a test based on unC0Rr's suggestion. still a lot of mess and redundancy involved, sry :P
sheepluva
parents:
10026
diff
changeset
|
87 |
local xmin, xmax, ymin, ymax |
10026 | 88 |
if (xdir ~= 0) and (ydir ~= 0) then |
89 |
sqrttwo = math.sqrt(2) |
|
90 |
d = d / sqrttwo |
|
91 |
radius = radius / sqrttwo |
|
10028
9e742fc72696
add a test based on unC0Rr's suggestion. still a lot of mess and redundancy involved, sry :P
sheepluva
parents:
10026
diff
changeset
|
92 |
speed = math.floor(speed / sqrttwo) |
10026 | 93 |
end |
94 |
centerx = centerx - (xdir * (radius + 20)) |
|
95 |
centery = centery - (ydir * (radius + 20)) |
|
96 |
radius = radius - 6 |
|
97 |
xn = ydir |
|
98 |
yn = -xdir |
|
99 |
startx = centerx - (radius * xn) |
|
100 |
starty = centery - (radius * yn) |
|
101 |
endx = centerx + (radius * xn) |
|
102 |
endy = centery + (radius * yn) |
|
103 |
||
104 |
-- spawn loop |
|
105 |
x = startx |
|
106 |
y = starty |
|
107 |
xd = d * xn |
|
108 |
yd = d * yn |
|
109 |
if (xd < 0) and (startx < endx) then x = endx end |
|
110 |
if (yd < 0) and (starty < endy) then y = endy end |
|
111 |
nsteps = math.floor(math.max(math.abs(startx - endx),math.abs(starty - endy)) / d) |
|
112 |
for i = 1, nsteps, 1 do |
|
10028
9e742fc72696
add a test based on unC0Rr's suggestion. still a lot of mess and redundancy involved, sry :P
sheepluva
parents:
10026
diff
changeset
|
113 |
AddGear(math.floor(x), math.floor(y), gtDrill, 0, speed * xdir, speed * ydir, 0) |
10026 | 114 |
nspawned = nspawned + 1 |
115 |
x = x + xd |
|
116 |
y = y + yd |
|
117 |
end |
|
118 |
end |
|
119 |
||
120 |
function onGearDelete(gear) |
|
121 |
if GetGearType(gear) == gtDrill then |
|
122 |
if GetTimer(gear) > 0 then |
|
123 |
nfailed = nfailed + 1 |
|
124 |
end |
|
125 |
ndied = ndied + 1 |
|
126 |
if ndied == nspawned then |
|
127 |
WriteLnToConsole('TESTRESULT: ' .. nfailed .. ' of ' .. nspawned .. ' drill rockets exploded prematurely') |
|
128 |
if (nfailed > 0) then |
|
129 |
EndLuaTest(TEST_FAILED) |
|
130 |
else |
|
131 |
EndLuaTest(TEST_SUCCESSFUL) |
|
132 |
end |
|
133 |
end |
|
134 |
end |
|
135 |
end |
|
136 |
||
137 |
function onGameStart() |
|
138 |
SetGravity(1) |
|
139 |
||
140 |
SpawnDrillRocketArray(taa_h1) |
|
141 |
SpawnDrillRocketArray(taa_h2) |
|
142 |
SpawnDrillRocketArray(taa_v1) |
|
143 |
SpawnDrillRocketArray(taa_v2) |
|
144 |
SpawnDrillRocketArray(taa_d1) |
|
145 |
SpawnDrillRocketArray(taa_d2) |
|
146 |
SpawnDrillRocketArray(taa_d3) |
|
147 |
SpawnDrillRocketArray(taa_d4) |
|
148 |
end |
|
149 |