1
2-- This function is called before the game loads its
3-- resources.
4-- It's one of the predefined function names that will
5-- be called by the game. They give you entry points
6-- where you're able to call your own code using either
7-- provided instructions or custom functions.
8function onGameInit()
9	-- At first we have to overwrite/set some global variables
10	-- that define the map, the game has to load, as well as
11	-- other things such as the game rules to use, etc.
12	-- Things we don't modify here will use their default values.
13
14	-- The base number for the random number generator
15	Seed = 1
16	-- The map to be played
17	Map = "Bamboo"
18	-- The theme to be used
19	Theme = "Bamboo"
20	-- Game settings and rules
21	EnableGameFlags(gfOneClanMode)
22
23	-- Create the player team
24	AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default")
25	-- And add a hog to it
26	player = AddHog("Hunter", 0, 1, "NoHat")
27	SetGearPosition(player, 936, 136)
28end
29
30-- from lua API wiki:
31local minZoom = 1.0;
32local maxZoom = 3.0;
33local defaultZoom = 2.0;
34
35local nFails = 0;
36
37function TestZoom(value)
38	exp = math.max(minZoom, math.min(maxZoom, value))
39	SetZoom(value)
40	z = GetZoom()
41	-- compare with some tolerance - because of float inprecision
42	if (z > exp + 0.01) or (z < exp - 0.01) then
43		WriteLnToConsole("Expected zoom value " .. exp .. " (after setting go zoom to " .. value .. "), but got: " .. z )
44		nFails = nFails + 1
45	end
46end
47
48function onGameStart()
49	if (GetZoom() ~= defaultZoom) then
50		WriteLnToConsole("Game did not start with zoom level of " .. defaultZoom)
51		nFails = 1
52	end
53
54	TestZoom(0)
55	TestZoom(1)
56	TestZoom(0.5)
57	TestZoom(3.5)
58	TestZoom(7)
59	TestZoom(2.0)
60	TestZoom(2.2)
61
62	if (nFails > 0) then
63		EndLuaTest(TEST_FAILED)
64	else
65		EndLuaTest(TEST_SUCCESSFUL)
66	end
67end
68
69