tests/lua/stuckcake.lua
author Wuzzy <Wuzzy2@mail.ru>
Sat, 15 Jun 2019 19:49:02 +0200
changeset 15164 fcd697bce2a8
parent 12645 36a650c0a885
permissions -rw-r--r--
Fix mapgen flowers being placed into indestructible map border
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12645
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     1
--[[ Stuck Cake Test
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     2
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     3
In this test, 2 hedgehogs are placed very close to each other, tightly
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     4
crammed between girders. The first hog (Cake Hog) launches a cake. Now
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     5
the test waits until the cake explodes due to time.
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     6
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     7
The cake must not take too long or forever to explode. The test succeeds
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     8
if the cake explodes before CAKE_MAX_EXPLOSION_TIME ticks (rough estimate)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
     9
after the cake spawned and fails otherwise.
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    10
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    11
This test case has been written in response to bug 194.
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    12
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    13
]]
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    14
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    15
-- Cake must explode before this many ticks for the test to succeed
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    16
local CAKE_MAX_EXPLOSION_TIME = 15000
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    17
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    18
-- Give up if cake is still running after this many ticks
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    19
local CAKE_GIVE_UP_TIME = 20000 
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    20
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    21
local hhs = {}
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    22
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    23
function onGameInit()
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    24
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    25
	ClearGameFlags()
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    26
	EnableGameFlags(gfDisableWind, gfPerHogAmmo, gfOneClanMode, gfInvulnerable, gfSolidLand)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    27
	Map = ""
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    28
	Seed = "{84f5e62e-6a12-4444-b53c-2bc62cfd9c62}"
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    29
	Theme = "Cave"
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    30
	MapGen = mgDrawn
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    31
	MapFeatureSize = 12
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    32
	TemplateFilter = 3
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    33
	TemplateNumber = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    34
	TurnTime = 9999000
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    35
	Explosives = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    36
	MinesNum = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    37
	CaseFreq = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    38
	WaterRise = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    39
	HealthDecrease = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    40
	Ready = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    41
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    42
	------ TEAM LIST ------
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    43
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    44
	AddTeam("Test Team", 0xFFFF02, "Statue", "Tank", "Default", "cm_test")
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    45
	
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    46
	hhs[1] = AddHog("Cake Hog", 0, 100, "NoHat")
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    47
	SetGearPosition(hhs[1], 771, 1344)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    48
	
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    49
	hhs[2] = AddHog("Passive Hog", 0, 100, "NoHat")
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    50
	SetGearPosition(hhs[2], 772, 1344)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    51
	HogTurnLeft(hhs[2], true)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    52
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    53
end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    54
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    55
function onAmmoStoreInit()
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    56
	SetAmmo(amCake, 9, 0, 0, 0)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    57
	SetAmmo(amSkip, 9, 0, 0, 0)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    58
end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    59
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    60
function onGameStart()
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    61
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    62
	PlaceSprite(784, 1361, sprAmGirder, 4, 0xFFFFFFFF, nil, nil, nil, lfNormal)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    63
	PlaceSprite(730, 1271, sprAmGirder, 6, 0xFFFFFFFF, nil, nil, nil, lfNormal)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    64
	PlaceSprite(753, 1270, sprAmGirder, 6, 0xFFFFFFFF, nil, nil, nil, lfNormal)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    65
	PlaceSprite(798, 1271, sprAmGirder, 6, 0xFFFFFFFF, nil, nil, nil, lfNormal)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    66
	PlaceSprite(777, 1243, sprAmGirder, 6, 0xFFFFFFFF, nil, nil, nil, lfNormal)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    67
	
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    68
end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    69
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    70
local cakeTestPhase = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    71
--[[ Test phases:
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    72
 0: Waiting for turn start
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    73
 1: Cake selected, waiting for attack
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    74
 2: Cake gear added
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    75
 3: Cake gead destroyed ]]
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    76
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    77
function onNewTurn()
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    78
	if cakeTestPhase == 0 then
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    79
		SetWeapon(amCake)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    80
		cakeTestPhase = 1
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    81
	end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    82
end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    83
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    84
local cakeTicks = 0
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    85
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    86
function onGearAdd(gear)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    87
	if GetGearType(gear) == gtCake then
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    88
		cakeTestPhase = 2
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    89
	end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    90
end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    91
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    92
function onGearDelete(gear)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    93
	if GetGearType(gear) == gtCake and cakeTestPhase == 2 then
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    94
		WriteLnToConsole(string.format("TEST: The cake exploded after %d ticks.", cakeTicks))
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    95
		cakeTestPhase = 3
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    96
		if cakeTicks > CAKE_MAX_EXPLOSION_TIME then
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    97
			WriteLnToConsole("TEST RESULT: Failed because cake took too long to explode.")
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    98
			EndLuaTest(TEST_FAILED)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
    99
		else
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   100
			WriteLnToConsole("TEST RESULT: Succeeded because cake exploded in time.")
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   101
			EndLuaTest(TEST_SUCCESSFUL)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   102
		end			
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   103
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   104
	end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   105
end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   106
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   107
function onGameTick()
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   108
	if cakeTestPhase == 1 then
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   109
		ParseCommand("+attack")
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   110
	elseif cakeTestPhase == 2 then
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   111
		cakeTicks = cakeTicks + 1
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   112
		if cakeTicks > CAKE_GIVE_UP_TIME then
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   113
			WriteLnToConsole(string.format("TEST RESULT: Failed because the cake still didn't explode after %d ticks.", CAKE_GIVE_UP_TIME))
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   114
			cakeTestPhase = 3
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   115
			EndLuaTest(TEST_FAILED)
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   116
		end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   117
	end
36a650c0a885 Add test case to test if cake explodes in time when stuck in tight space
Wuzzy <almikes@aol.com>
parents:
diff changeset
   118
end