author | Wuzzy <almikes@aol.com> |
Wed, 13 Apr 2016 00:49:34 +0200 | |
changeset 11724 | 9fea4e2dceaa |
parent 10758 | 0f3a0f117810 |
child 11898 | 25a6faa5ac46 |
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() |
10738
62659c427e5d
Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents:
10509
diff
changeset
|
20 |
if delta ~= nil and period == nil then |
62659c427e5d
Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents:
10509
diff
changeset
|
21 |
SetGravity(gravity) |
62659c427e5d
Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents:
10509
diff
changeset
|
22 |
else |
62659c427e5d
Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents:
10509
diff
changeset
|
23 |
SetGravity(div(gravity, mln)) |
62659c427e5d
Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents:
10509
diff
changeset
|
24 |
end |
62659c427e5d
Fix setting gravity multiplied by million for a moment of time on new turn on certain circumstances
unc0rr
parents:
10509
diff
changeset
|
25 |
|
9836 | 26 |
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
|
27 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
28 |
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
|
29 |
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
|
30 |
end |
9816 | 31 |
end |
32 |
||
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
33 |
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
|
34 |
if wdGameTicks + 15000 < GameTime then |
9816 | 35 |
SetGravity(100) |
9908 | 36 |
else |
37 |
if wdTTL ~= TurnTimeLeft then |
|
38 |
wdGameTicks = GameTime |
|
39 |
end |
|
40 |
||
41 |
if delta == nil then |
|
42 |
if periodtimer == 0 then |
|
43 |
periodtimer = period * 2 |
|
10758
0f3a0f117810
Random gravity values interval should include maxgravity
unc0rr
parents:
10738
diff
changeset
|
44 |
SetGravity(div(GetRandom(maxgravity - mingravity + 1) + mingravity, mln)) |
9908 | 45 |
else |
46 |
periodtimer = periodtimer - 1 |
|
47 |
end |
|
48 |
elseif delta == 0 then |
|
49 |
SetGravity(gravity) |
|
50 |
else |
|
51 |
if delta > 0 and gravity + delta > maxgravity then |
|
52 |
gravity = maxgravity |
|
53 |
delta = -delta |
|
10509 | 54 |
elseif delta < 0 and gravity + delta < mingravity then |
9908 | 55 |
gravity = mingravity |
56 |
delta = -delta |
|
57 |
else |
|
58 |
gravity = gravity + delta |
|
59 |
end |
|
60 |
||
61 |
SetGravity(div(gravity, mln)) |
|
62 |
end |
|
9816 | 63 |
end |
9836 | 64 |
|
65 |
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
|
66 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
67 |
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
|
68 |
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
|
69 |
end |
9816 | 70 |
end |
9836 | 71 |
|
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
72 |
function onParameters() |
9906
93c16a4b0c6a
Only emit roomNameUpdated when it actually is changed
unc0rr
parents:
9902
diff
changeset
|
73 |
parseParams() |
9908 | 74 |
|
75 |
gravity = params["g"] |
|
76 |
||
77 |
mingravity = gravity |
|
78 |
maxgravity = params["g2"] |
|
79 |
period = params["period"] |
|
80 |
||
81 |
if mingravity ~= nil and maxgravity ~= nil then |
|
82 |
if period ~= nil then |
|
83 |
period = div(period, 40) |
|
84 |
else |
|
85 |
period = 125 |
|
86 |
end |
|
87 |
||
10509 | 88 |
mingravity = mingravity * mln |
89 |
maxgravity = maxgravity * mln |
|
90 |
||
91 |
-- note: mingravity and maxgravity MUST NOT be strings at this point |
|
9908 | 92 |
if mingravity > maxgravity then |
93 |
mingravity, maxgravity = maxgravity, mingravity |
|
94 |
end |
|
95 |
||
96 |
gravity = mingravity |
|
97 |
||
98 |
if period > 0 then |
|
99 |
delta = div(maxgravity - mingravity, period) |
|
100 |
else |
|
101 |
period = -period |
|
102 |
delta = nil |
|
103 |
end |
|
104 |
end |
|
105 |
||
106 |
if gravity == nil then |
|
107 |
gravity = 100 |
|
108 |
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
|
109 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
110 |
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
|
111 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
120 |
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
|
121 |
onParameters() |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
122 |
end |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
123 |
end |
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
124 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
onGameStart = grav_onGameStart |
9836 | 128 |
end |
129 |
||
9985
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
130 |
function grav_onGameStart() |
9908 | 131 |
if delta == nil then |
132 |
v = string.format(loc("random in range from %i%% to %i%% with period of %i msec"), div(mingravity, mln), div(maxgravity, mln), period * 40) |
|
133 |
elseif period ~= nil then |
|
134 |
v = string.format(loc("changing range from %i%% to %i%% with period of %i msec"), div(mingravity, mln), div(maxgravity, mln), period * 40) |
|
135 |
else |
|
9910 | 136 |
v = gravity .. "%" |
9908 | 137 |
end |
138 |
||
9836 | 139 |
ShowMission(loc("Gravity"), |
9908 | 140 |
loc("Current setting is ") .. v, |
141 |
loc("Setup:|'g=150', where 150 is 150% of normal gravity") .. "|" |
|
142 |
.. loc("or 'g=50, g2=150, period=4000' for gravity changing|from 50 to 150 and back with period of 4000 msec") |
|
143 |
.. "||" .. loc("Set period to negative value for random gravity"), |
|
9836 | 144 |
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
|
145 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
146 |
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
|
147 |
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
|
148 |
end |
9902 | 149 |
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
|
150 |
|
42cd42e44c9a
GravRacer, GravHigh, GravMutant, Grav... uhm... shoppamap? Easy! Gravity script could be combined with any other script now.
unc0rr
parents:
9910
diff
changeset
|
151 |