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