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