author | unc0rr |
Fri, 03 Jan 2014 00:37:48 +0400 | |
changeset 9908 | 81eb25ddf594 |
parent 9906 | 93c16a4b0c6a |
child 9910 | b0988e40e411 |
permissions | -rw-r--r-- |
9836 | 1 |
HedgewarsScriptLoad("/Scripts/Locale.lua") |
9906
93c16a4b0c6a
Only emit roomNameUpdated when it actually is changed
unc0rr
parents:
9902
diff
changeset
|
2 |
HedgewarsScriptLoad("/Scripts/Params.lua") |
9836 | 3 |
|
4 |
local gravity = 100 |
|
9908 | 5 |
local mingravity |
6 |
local maxgravity |
|
7 |
local delta = 0 |
|
8 |
local period |
|
9 |
local periodtimer = 0 |
|
9836 | 10 |
local wdGameTicks = 0 |
11 |
local wdTTL = 0 |
|
9908 | 12 |
local mln = 1000000 |
9836 | 13 |
|
9816 | 14 |
function onNewTurn() |
9836 | 15 |
SetGravity(gravity) |
16 |
wdGameTicks = GameTime |
|
9816 | 17 |
end |
18 |
||
19 |
function onGameTick20() |
|
9898
b87695f82d2e
Don't set gravity to normal immediately on turn end, let watchdog do its job if game gets frozen
unc0rr
parents:
9836
diff
changeset
|
20 |
if wdGameTicks + 15000 < GameTime then |
9816 | 21 |
SetGravity(100) |
9908 | 22 |
else |
23 |
if wdTTL ~= TurnTimeLeft then |
|
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 |
|
9816 | 49 |
end |
9836 | 50 |
|
51 |
wdTTL = TurnTimeLeft |
|
9816 | 52 |
end |
9836 | 53 |
|
54 |
function onGameInit() |
|
9906
93c16a4b0c6a
Only emit roomNameUpdated when it actually is changed
unc0rr
parents:
9902
diff
changeset
|
55 |
parseParams() |
9908 | 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 |
|
9836 | 89 |
end |
90 |
||
91 |
function onGameStart() |
|
9908 | 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 |
||
9836 | 100 |
ShowMission(loc("Gravity"), |
9908 | 101 |
loc("Current setting is ") .. v, |
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"), |
|
9836 | 105 |
0, 5000) |
9902 | 106 |
end |