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