# HG changeset patch # User koda # Date 1390344408 -3600 # Node ID ca075f0f7cfb3ee2e4652114d51176a799472187 # Parent 703931eec680470d46f1a5a21270c164a00d4ea2 ok really restore tests diff -r 703931eec680 -r ca075f0f7cfb tests/lua/drillrockets_boom.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/lua/drillrockets_boom.lua Tue Jan 21 23:46:48 2014 +0100 @@ -0,0 +1,188 @@ + + -- taken from http://code.google.com/p/hedgewars/wiki/LuaDrawing + PointsBuffer = '' -- A string to accumulate points in + function AddPoint(x, y, width, erase) + PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff)) + if width then + width = bor(width,0x80) + if erase then + width = bor(width,0x40) + end + PointsBuffer = PointsBuffer .. string.char(width) + else + PointsBuffer = PointsBuffer .. string.char(0) + end + if #PointsBuffer > 245 then + ParseCommand('draw '..PointsBuffer) + PointsBuffer = '' + end + end + function FlushPoints() + if #PointsBuffer > 0 then + ParseCommand('draw '..PointsBuffer) + PointsBuffer = '' + end + end + + +local ta_pointsize = 63 +local ta_radius = (ta_pointsize * 10 + 6) / 2 + +local sqrttwo = math.sqrt(2) + +-- creates round test area +function AddTestArea(testarea) + step = 100 + xstep = step * testarea["xdir"] + ystep = step * testarea["ydir"] + x = testarea["x"] + y = testarea["y"] + if xstep * ystep ~= 0 then + xstep = math.floor(xstep / sqrttwo) + ystep = math.floor(ystep / sqrttwo) + end + AddPoint(x, y, ta_pointsize); + AddPoint(x + xstep, y + ystep, ta_pointsize, true); +end + +-- vertical test areas +local taa_v1 = {x= 350, y= 400, xdir= 0, ydir= 1} +local taa_v2 = {x= 350, y=1500, xdir= 0, ydir=-1} +-- horizontal test areas +local taa_h1 = {x=1150, y= 400, xdir= 1, ydir= 0} +local taa_h2 = {x=1200, y=1100, xdir=-1, ydir= 0} +-- diagonal test areas +local taa_d1 = {x=2200, y= 400, xdir= 1, ydir= 1} +local taa_d2 = {x=2000, y=1500, xdir= 1, ydir=-1} +local taa_d3 = {x=3300, y= 400, xdir=-1, ydir= 1} +local taa_d4 = {x=3300, y=1500, xdir=-1, ydir=-1} + +-- fail counter +local nfailed = 0 +local nspawned = 0 +local ndied = 0 + +function onGameInit() + -- At first we have to overwrite/set some global variables + -- that define the map, the game has to load, as well as + -- other things such as the game rules to use, etc. + -- Things we don't modify here will use their default values. + + -- The base number for the random number generator + Seed = 1 + -- The map to be played + MapGen = 2 + -- The theme to be used + Theme = "Bamboo" + -- Game settings and rules + EnableGameFlags(gfOneClanMode, gfDisableWind, gfDisableLandObjects, gfDisableGirders, gfSolidLand) + CaseFreq = 0 + MinesNum = 0 + Explosives = 0 + + -- No damage please + DamagePercent = 1 + + -- Draw Map + AddPoint(10,30,0) -- hog spawn platform + -- test areas + AddTestArea(taa_v1) + AddTestArea(taa_v2) + AddTestArea(taa_h1) + AddTestArea(taa_h2) + AddTestArea(taa_d1) + AddTestArea(taa_d2) + AddTestArea(taa_d3) + AddTestArea(taa_d4) + + FlushPoints() + + -- Create the player team + AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default") + -- And add a hog to it + player = AddHog("Hunter", 0, 1, "NoHat") + -- place it on how spawn platform + SetGearPosition(player, 10, 10) +end + +-- xdir/ydir is direction in which to fire the drills +function SpawnDrillRocketArray(testarea) + xdir = testarea["xdir"] + ydir = testarea["ydir"] + centerx = testarea["x"] + centery = testarea["y"] + distance = 23 + d = distance + radius = ta_radius + speed = 900000; + local xmin, xmax, ymin, ymax + if (xdir ~= 0) and (ydir ~= 0) then + d = d / sqrttwo + radius = radius / sqrttwo + speed = math.floor(speed / sqrttwo) + end + centerx = centerx - (xdir * (radius + 20)) + centery = centery - (ydir * (radius + 20)) + radius = radius - 6 + xn = ydir + yn = -xdir + startx = centerx - (radius * xn) + starty = centery - (radius * yn) + endx = centerx + (radius * xn) + endy = centery + (radius * yn) + + -- spawn loop + x = startx + y = starty + xd = d * xn + yd = d * yn + if (xd < 0) and (startx < endx) then x = endx end + if (yd < 0) and (starty < endy) then y = endy end + nsteps = math.floor(math.max(math.abs(startx - endx),math.abs(starty - endy)) / d) + for i = 1, nsteps, 1 do + AddGear(math.floor(x), math.floor(y), gtDrill, gsttmpFlag * (i % 2), speed * xdir, speed * ydir, 0) + nspawned = nspawned + 1 + x = x + xd + y = y + yd + end +end + +function onGearDelete(gear) + if GetGearType(gear) == gtDrill then + -- the way to check state will change in API at some point + if band(GetState(gear), gsttmpFlag) == 0 then + -- regular drill rocket + if (GetTimer(gear) < 2000) or (GetTimer(gear) > 3000) then + nfailed = nfailed + 1 + end + else + -- airstrike drill rocket + if GetTimer(gear) > 0 then + nfailed = nfailed + 1 + end + end + ndied = ndied + 1 + if ndied == nspawned then + WriteLnToConsole('TESTRESULT: ' .. nfailed .. ' of ' .. nspawned .. ' drill rockets did not explode as expected') + if (nfailed > 0) then + EndLuaTest(TEST_FAILED) + else + EndLuaTest(TEST_SUCCESSFUL) + end + end + end +end + +function onGameStart() + SetGravity(1) + + SpawnDrillRocketArray(taa_h1) + SpawnDrillRocketArray(taa_h2) + SpawnDrillRocketArray(taa_v1) + SpawnDrillRocketArray(taa_v2) + SpawnDrillRocketArray(taa_d1) + SpawnDrillRocketArray(taa_d2) + SpawnDrillRocketArray(taa_d3) + SpawnDrillRocketArray(taa_d4) +end + diff -r 703931eec680 -r ca075f0f7cfb tests/lua/drillrockets_drill.lua --- a/tests/lua/drillrockets_drill.lua Tue Jan 21 23:25:57 2014 +0100 +++ b/tests/lua/drillrockets_drill.lua Tue Jan 21 23:46:48 2014 +0100 @@ -109,10 +109,13 @@ d = distance radius = ta_radius local xmin, xmax, ymin, ymax + speed = 900000; + local xmin, xmax, ymin, ymax if (xdir ~= 0) and (ydir ~= 0) then sqrttwo = math.sqrt(2) d = d / sqrttwo radius = radius / sqrttwo + speed = math.floor(speed / sqrttwo) end centerx = centerx - (xdir * (radius + 20)) centery = centery - (ydir * (radius + 20)) @@ -133,7 +136,7 @@ if (yd < 0) and (starty < endy) then y = endy end nsteps = math.floor(math.max(math.abs(startx - endx),math.abs(starty - endy)) / d) for i = 1, nsteps, 1 do - AddGear(math.floor(x), math.floor(y), gtDrill, 0, 900000 * xdir, 900000 * ydir, 0) + AddGear(math.floor(x), math.floor(y), gtDrill, 0, speed * xdir, speed * ydir, 0) nspawned = nspawned + 1 x = x + xd y = y + yd diff -r 703931eec680 -r ca075f0f7cfb tests/lua/luaAPI/gravity_get_set.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/lua/luaAPI/gravity_get_set.lua Tue Jan 21 23:46:48 2014 +0100 @@ -0,0 +1,107 @@ + + +-- * let grenade fall +-- * after a second capture fall distance +-- * change gravity value every second and see if the fall distance in the +-- following second is about what we'd expect it to be + +local spawnX = 10 +local spawnY = -500 + +local defaultG = nil +local currentG = nil + +local defaultDY = nil +local expectedY = nil + +local testGs = nil + +local nFails = 0 + +function onGameInit() + + + -- The base number for the random number generator + Seed = 1 + -- The map to be played + Map = "Ruler" + -- The theme to be used + Theme = "Bamboo" + -- Game settings and rules + EnableGameFlags(gfOneClanMode, gfInvulnerable) + CaseFreq = 0 + MinesNum = 0 + Explosives = 0 + + -- Create the player team + AddTeam("O_o", 14483456, "Simple", "Island", "Default") + -- And add a hog to it + player = AddHog("o_O", 0, 1, "NoHat") + SetGearPosition(player, 100, 100) +end + +local tol = 0 + +function IsKindaSame(a, b) + tol = 1 + math.max(1,math.abs(currentG) / 100) + return (a >= b-tol) and (a <= b+tol) +end + +function SpawnGrenade() + AddGear(spawnX, spawnY, gtGrenade, 0, 0, 0, 1000) +end + +local gIdx = 1 + +function onGearDelete(gear) + if GetGearType(gear) ~= gtGrenade then + return + end + + -- catch initial measuring drop + if defaultDY == nil then + defaultDY = GetY(gear) - spawnY + elseif not IsKindaSame(GetY(gear), expectedY) then + nFails = nFails + 1 + WriteLnToConsole("FAIL: Unexpected Y position! " .. GetY(gear) .. " returned, expected " .. expectedY .. ' (max tolerated difference = ' .. tol .. ')') + else + WriteLnToConsole("Y position OK! " .. GetY(gear) .. " returned, expected " .. expectedY .. ' (max tolerated difference = ' .. tol .. ')') + end + + returnedG = GetGravity() + if (returnedG ~= currentG) then + WriteLnToConsole("GetGravity did not return the value that we used with SetGravity! " .. returnedG .. " returned, expected " .. currentG) + nFails = nFails + 1 + end + + currentG = testGs[gIdx] + gIdx = gIdx + 1 + -- after last test + if currentG == nil then + if (nFails > 0) then + EndLuaTest(TEST_FAILED) + else + EndLuaTest(TEST_SUCCESSFUL) + end + end + + WriteLnToConsole("SetGravity(" .. currentG .. ") ...") + SetGravity(currentG) + + SpawnGrenade() + expectedY = spawnY + math.floor(currentG * defaultDY / 100) +end + +function onGameStart() + currentG = 100 + defaultG = GetGravity() + if (defaultG ~= 100) then + WriteLnToConsole("GetGravity did not return 100 at game start") + nFails = 1 + end + + SpawnGrenade() + + testGs = {150, 200, 300, 10, 1, 13, 15, 0, 27, -600, -10, nil} +end +