1 HedgewarsScriptLoad("/Scripts/Locale.lua") |
1 HedgewarsScriptLoad("/Scripts/Locale.lua") |
2 HedgewarsScriptLoad("/Scripts/Params.lua") |
2 HedgewarsScriptLoad("/Scripts/Params.lua") |
3 |
3 |
4 local gravity = 100 |
4 local gravity = 100 |
|
5 local mingravity |
|
6 local maxgravity |
|
7 local delta = 0 |
|
8 local period |
|
9 local periodtimer = 0 |
5 local wdGameTicks = 0 |
10 local wdGameTicks = 0 |
6 local wdTTL = 0 |
11 local wdTTL = 0 |
|
12 local mln = 1000000 |
7 |
13 |
8 function onNewTurn() |
14 function onNewTurn() |
9 SetGravity(gravity) |
15 SetGravity(gravity) |
10 wdGameTicks = GameTime |
16 wdGameTicks = GameTime |
11 end |
17 end |
12 |
18 |
13 function onGameTick20() |
19 function onGameTick20() |
14 if wdGameTicks + 15000 < GameTime then |
20 if wdGameTicks + 15000 < GameTime then |
15 SetGravity(100) |
21 SetGravity(100) |
16 elseif wdTTL ~= TurnTimeLeft then |
22 else |
17 wdGameTicks = GameTime |
23 if wdTTL ~= TurnTimeLeft then |
18 SetGravity(gravity) |
24 wdGameTicks = GameTime |
|
25 end |
|
26 |
|
27 if delta == nil then |
|
28 if periodtimer == 0 then |
|
29 periodtimer = period * 2 |
|
30 SetGravity(div(GetRandom(maxgravity - mingravity) + mingravity, mln)) |
|
31 else |
|
32 periodtimer = periodtimer - 1 |
|
33 end |
|
34 elseif delta == 0 then |
|
35 SetGravity(gravity) |
|
36 else |
|
37 if delta > 0 and gravity + delta > maxgravity then |
|
38 gravity = maxgravity |
|
39 delta = -delta |
|
40 elseif delta < 0 and gravity - delta < mingravity then |
|
41 gravity = mingravity |
|
42 delta = -delta |
|
43 else |
|
44 gravity = gravity + delta |
|
45 end |
|
46 |
|
47 SetGravity(div(gravity, mln)) |
|
48 end |
19 end |
49 end |
20 |
50 |
21 wdTTL = TurnTimeLeft |
51 wdTTL = TurnTimeLeft |
22 end |
52 end |
23 |
53 |
24 function onGameInit() |
54 function onGameInit() |
25 parseParams() |
55 parseParams() |
26 gravity = ScriptParam |
56 |
|
57 gravity = params["g"] |
|
58 |
|
59 mingravity = gravity |
|
60 maxgravity = params["g2"] |
|
61 period = params["period"] |
|
62 |
|
63 if mingravity ~= nil and maxgravity ~= nil then |
|
64 if period ~= nil then |
|
65 period = div(period, 40) |
|
66 else |
|
67 period = 125 |
|
68 end |
|
69 |
|
70 if mingravity > maxgravity then |
|
71 mingravity, maxgravity = maxgravity, mingravity |
|
72 end |
|
73 |
|
74 mingravity = mingravity * mln |
|
75 maxgravity = maxgravity * mln |
|
76 gravity = mingravity |
|
77 |
|
78 if period > 0 then |
|
79 delta = div(maxgravity - mingravity, period) |
|
80 else |
|
81 period = -period |
|
82 delta = nil |
|
83 end |
|
84 end |
|
85 |
|
86 if gravity == nil then |
|
87 gravity = 100 |
|
88 end |
27 end |
89 end |
28 |
90 |
29 function onGameStart() |
91 function onGameStart() |
|
92 if delta == nil then |
|
93 v = string.format(loc("random in range from %i%% to %i%% with period of %i msec"), div(mingravity, mln), div(maxgravity, mln), period * 40) |
|
94 elseif period ~= nil then |
|
95 v = string.format(loc("changing range from %i%% to %i%% with period of %i msec"), div(mingravity, mln), div(maxgravity, mln), period * 40) |
|
96 else |
|
97 v = div(gravity, mln) .. "%" |
|
98 end |
|
99 |
30 ShowMission(loc("Gravity"), |
100 ShowMission(loc("Gravity"), |
31 loc("Current value is ") .. gravity .. "%", |
101 loc("Current setting is ") .. v, |
32 loc("Set any gravity value you want by adjusting get away time"), |
102 loc("Setup:|'g=150', where 150 is 150% of normal gravity") .. "|" |
|
103 .. loc("or 'g=50, g2=150, period=4000' for gravity changing|from 50 to 150 and back with period of 4000 msec") |
|
104 .. "||" .. loc("Set period to negative value for random gravity"), |
33 0, 5000) |
105 0, 5000) |
34 end |
106 end |