author | unc0rr |
Fri, 25 Jul 2014 14:00:51 +0400 | |
changeset 10366 | b451b8f69f44 |
parent 9985 | 42cd42e44c9a |
child 10509 | d62d3c706947 |
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 |
|
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
14 |
local script2_onNewTurn |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
15 |
local script2_onGameTick20 |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
16 |
local script2_onGameStart |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
17 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
18 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
19 |
function grav_onNewTurn() |
9836 | 20 |
SetGravity(gravity) |
21 |
wdGameTicks = GameTime |
|
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
22 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
23 |
if script2_onNewTurn ~= nil then |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
24 |
script2_onNewTurn() |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
25 |
end |
9816 | 26 |
end |
27 |
||
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
28 |
function grav_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
|
29 |
if wdGameTicks + 15000 < GameTime then |
9816 | 30 |
SetGravity(100) |
9908 | 31 |
else |
32 |
if wdTTL ~= TurnTimeLeft then |
|
33 |
wdGameTicks = GameTime |
|
34 |
end |
|
35 |
||
36 |
if delta == nil then |
|
37 |
if periodtimer == 0 then |
|
38 |
periodtimer = period * 2 |
|
39 |
SetGravity(div(GetRandom(maxgravity - mingravity) + mingravity, mln)) |
|
40 |
else |
|
41 |
periodtimer = periodtimer - 1 |
|
42 |
end |
|
43 |
elseif delta == 0 then |
|
44 |
SetGravity(gravity) |
|
45 |
else |
|
46 |
if delta > 0 and gravity + delta > maxgravity then |
|
47 |
gravity = maxgravity |
|
48 |
delta = -delta |
|
49 |
elseif delta < 0 and gravity - delta < mingravity then |
|
50 |
gravity = mingravity |
|
51 |
delta = -delta |
|
52 |
else |
|
53 |
gravity = gravity + delta |
|
54 |
end |
|
55 |
||
56 |
SetGravity(div(gravity, mln)) |
|
57 |
end |
|
9816 | 58 |
end |
9836 | 59 |
|
60 |
wdTTL = TurnTimeLeft |
|
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
61 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
62 |
if script2_onGameTick20 ~= nil then |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
63 |
script2_onGameTick20() |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
64 |
end |
9816 | 65 |
end |
9836 | 66 |
|
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
67 |
function onParameters() |
9906
93c16a4b0c6a
Only emit roomNameUpdated when it actually is changed
unc0rr
parents:
9902
diff
changeset
|
68 |
parseParams() |
9908 | 69 |
|
70 |
gravity = params["g"] |
|
71 |
||
72 |
mingravity = gravity |
|
73 |
maxgravity = params["g2"] |
|
74 |
period = params["period"] |
|
75 |
||
76 |
if mingravity ~= nil and maxgravity ~= nil then |
|
77 |
if period ~= nil then |
|
78 |
period = div(period, 40) |
|
79 |
else |
|
80 |
period = 125 |
|
81 |
end |
|
82 |
||
83 |
if mingravity > maxgravity then |
|
84 |
mingravity, maxgravity = maxgravity, mingravity |
|
85 |
end |
|
86 |
||
87 |
mingravity = mingravity * mln |
|
88 |
maxgravity = maxgravity * mln |
|
89 |
gravity = mingravity |
|
90 |
||
91 |
if period > 0 then |
|
92 |
delta = div(maxgravity - mingravity, period) |
|
93 |
else |
|
94 |
period = -period |
|
95 |
delta = nil |
|
96 |
end |
|
97 |
end |
|
98 |
||
99 |
if gravity == nil then |
|
100 |
gravity = 100 |
|
101 |
end |
|
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
102 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
103 |
secondScript = params["script2"] |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
104 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
105 |
if secondScript ~= nil then |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
106 |
onParameters = nil |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
107 |
HedgewarsScriptLoad("/Scripts/Multiplayer/" .. secondScript .. ".lua") |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
108 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
109 |
script2_onNewTurn = onNewTurn |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
110 |
script2_onGameTick20 = onGameTick20 |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
111 |
script2_onGameStart = onGameStart |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
112 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
113 |
if onParameters ~= nil then |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
114 |
onParameters() |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
115 |
end |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
116 |
end |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
117 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
118 |
onNewTurn = grav_onNewTurn |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
119 |
onGameTick20 = grav_onGameTick20 |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
120 |
onGameStart = grav_onGameStart |
9836 | 121 |
end |
122 |
||
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
123 |
function grav_onGameStart() |
9908 | 124 |
if delta == nil then |
125 |
v = string.format(loc("random in range from %i%% to %i%% with period of %i msec"), div(mingravity, mln), div(maxgravity, mln), period * 40) |
|
126 |
elseif period ~= nil then |
|
127 |
v = string.format(loc("changing range from %i%% to %i%% with period of %i msec"), div(mingravity, mln), div(maxgravity, mln), period * 40) |
|
128 |
else |
|
9910 | 129 |
v = gravity .. "%" |
9908 | 130 |
end |
131 |
||
9836 | 132 |
ShowMission(loc("Gravity"), |
9908 | 133 |
loc("Current setting is ") .. v, |
134 |
loc("Setup:|'g=150', where 150 is 150% of normal gravity") .. "|" |
|
135 |
.. loc("or 'g=50, g2=150, period=4000' for gravity changing|from 50 to 150 and back with period of 4000 msec") |
|
136 |
.. "||" .. loc("Set period to negative value for random gravity"), |
|
9836 | 137 |
0, 5000) |
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
138 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
139 |
if script2_onGameStart ~= nil then |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
140 |
script2_onGameStart() |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
141 |
end |
9902 | 142 |
end |
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
143 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
144 |