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