4106
|
1 |
-- Hedgewars - Roperace for 2+ Players
|
|
2 |
|
|
3 |
local caption = {
|
|
4 |
["en"] = "TrophyRace",
|
|
5 |
}
|
|
6 |
|
|
7 |
local goal = {
|
|
8 |
["en"] = "Use your rope to get from start to finish as fast as you can!",
|
|
9 |
}
|
|
10 |
|
|
11 |
local done = {
|
|
12 |
["en"] = "You've reached the goal!| |Time: ",
|
|
13 |
}
|
|
14 |
|
|
15 |
local eliminated = {
|
|
16 |
["en"] = "Eliminating worst hedgehog this round...| |%s is OUT!",
|
|
17 |
}
|
|
18 |
|
|
19 |
local newbesttime = {
|
|
20 |
["en"] = "NEW fastest lap: ",
|
|
21 |
}
|
|
22 |
|
|
23 |
local oldbesttime = {
|
|
24 |
["en"] = "Fastest lap: ",
|
|
25 |
}
|
|
26 |
local bestclantimes = {
|
|
27 |
["en"] = "Best laps per team: ",
|
|
28 |
}
|
|
29 |
local clantime = {
|
|
30 |
["en"] = "Team %d: ",
|
|
31 |
}
|
|
32 |
|
|
33 |
local function loc(text)
|
|
34 |
if text == nil then return "**missing**"
|
|
35 |
elseif text[L] == nil then return text["en"]
|
|
36 |
else return text[L]
|
|
37 |
end
|
|
38 |
end
|
|
39 |
|
|
40 |
---------------------------------------------------------------
|
|
41 |
|
|
42 |
-- store number of hedgehogs
|
|
43 |
local numhhs = 0
|
|
44 |
|
|
45 |
-- store hedgehog gears
|
|
46 |
local hhs = {}
|
|
47 |
|
|
48 |
-- store best time per team
|
|
49 |
local clantimes = {}
|
|
50 |
|
|
51 |
-- store best times
|
|
52 |
local times = {}
|
|
53 |
|
|
54 |
-- in milisseconds
|
|
55 |
local maxtime = 99000
|
|
56 |
|
|
57 |
-- define start area (left, top, width, height)
|
|
58 |
local start_area = {1606, 498, 356, 80}
|
|
59 |
|
|
60 |
-- define goal area (left, top, width, height)
|
|
61 |
local goal_area = {2030, 300, 56, 280}
|
|
62 |
|
|
63 |
-- last active hog
|
|
64 |
local lasthog = nil
|
|
65 |
|
|
66 |
-- active hog reached the goal?
|
|
67 |
local reached = false
|
|
68 |
|
|
69 |
-- hog with best time
|
|
70 |
local besthog = nil
|
|
71 |
|
|
72 |
-- hog with worst time (per round)
|
|
73 |
local worsthog = nil
|
|
74 |
|
|
75 |
-- best time
|
|
76 |
local besttime = maxtime + 1
|
|
77 |
|
|
78 |
-- worst time (per round)
|
|
79 |
local worsttime = 0
|
|
80 |
|
|
81 |
function onGameInit()
|
|
82 |
GameFlags = gfSolidLand + gfInvulnerable
|
|
83 |
TurnTime = maxtime
|
|
84 |
CaseFreq = 0
|
|
85 |
LandAdds = 0
|
|
86 |
Explosives = 0
|
|
87 |
Delay = 500
|
|
88 |
SuddenDeathTurns = 99999 -- "disable" sudden death
|
|
89 |
Theme = 'Olympics'
|
|
90 |
end
|
|
91 |
|
|
92 |
function onGameStart()
|
|
93 |
ShowMission(loc(caption), "", loc(goal), -amRope, 0)
|
|
94 |
started = true
|
|
95 |
p=1820
|
|
96 |
for i = 0, numhhs - 1 do
|
|
97 |
p = p + 50
|
|
98 |
SetGearPosition(hhs[i], p, 0)
|
|
99 |
end
|
|
100 |
|
|
101 |
for i=0, ClansCount-1 do
|
|
102 |
clantimes[i] = 0
|
|
103 |
end
|
|
104 |
end
|
|
105 |
|
|
106 |
function onAmmoStoreInit()
|
|
107 |
SetAmmo(amRope, 9, 2, 0)
|
|
108 |
end
|
|
109 |
|
|
110 |
function onGameTick()
|
|
111 |
if TurnTimeLeft == 1 and CurrentHedgehog ~= nil then
|
|
112 |
SetHealth(CurrentHedgehog, 0)
|
|
113 |
x, y = GetGearPosition(CurrentHedgehog)
|
|
114 |
AddGear(x, y, gtAmmo_Grenade, 0, 0, 0, 0)
|
|
115 |
worsttime = 99999
|
|
116 |
worsthog = nil
|
|
117 |
elseif TurnTimeLeft == maxtime - 1 and CurrentHedgehog ~= nil then
|
|
118 |
if lasthog ~= nil then
|
|
119 |
SetGearPosition(lasthog, p , 0)
|
|
120 |
end
|
|
121 |
reached = false
|
|
122 |
SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
|
|
123 |
elseif CurrentHedgehog ~= nil then
|
|
124 |
x, y = GetGearPosition(CurrentHedgehog)
|
|
125 |
if not reached and x > goal_area[1] and x < goal_area[1] + goal_area[3] and y > goal_area[2] and y < goal_area[2] + goal_area[4] then -- hog is within goal rectangle
|
|
126 |
reached = true
|
|
127 |
local ttime = maxtime - TurnTimeLeft
|
|
128 |
--give it a sound;)
|
|
129 |
if ttime < besttime then
|
|
130 |
PlaySound (sndHomerun)
|
|
131 |
else
|
|
132 |
PlaySound (sndHellish)
|
|
133 |
end
|
|
134 |
for i = 0, numhhs - 1 do
|
|
135 |
if hhs[i] == CurrentHedgehog then
|
|
136 |
times[numhhs] = ttime
|
|
137 |
end
|
|
138 |
end
|
|
139 |
|
|
140 |
local hscore = "| |"
|
|
141 |
local clan = GetHogClan(CurrentHedgehog)
|
|
142 |
if ttime < clantimes[clan] or clantimes[clan] == 0 then
|
|
143 |
clantimes[clan] = ttime
|
|
144 |
end
|
|
145 |
|
|
146 |
if ttime < besttime then
|
|
147 |
besttime = ttime
|
|
148 |
besthog = CurrentHedgehog
|
|
149 |
hscore = hscore .. loc(newbesttime)
|
|
150 |
else
|
|
151 |
hscore = hscore .. loc(oldbesttime)
|
|
152 |
end
|
|
153 |
if ttime > worsttime then
|
|
154 |
worsttime = ttime
|
|
155 |
worsthog = CurrentHedgehog
|
|
156 |
end
|
|
157 |
hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc(bestclantimes)
|
|
158 |
|
|
159 |
if clan == ClansCount -1 then
|
|
160 |
-- Time for elimination - worst hog is out and the worst hog vars are reset.
|
|
161 |
SetHealth(worsthog, 0)
|
|
162 |
--Place a grenade to make inactive slowest hog active
|
|
163 |
x, y = GetGearPosition(worsthog)
|
|
164 |
AddGear(x, y, gtAmmo_Grenade, 0, 0, 0, 0)
|
|
165 |
worsttime = 0
|
|
166 |
worsthog = nil
|
|
167 |
end
|
|
168 |
|
|
169 |
for i=0, ClansCount -1 do
|
|
170 |
local tt = "" .. (clantimes[i] / 1000) .. " s"
|
|
171 |
if clantimes[i] == 0 then
|
|
172 |
tt = "--"
|
|
173 |
end
|
|
174 |
hscore = hscore .. "|" .. string.format(loc(clantime), i+1) .. tt
|
|
175 |
end
|
|
176 |
|
|
177 |
ShowMission(loc(caption), "", loc(done) .. (ttime / 1000) .. " s" .. hscore, 0, 0)
|
|
178 |
TurnTimeLeft = 0
|
|
179 |
end
|
|
180 |
end
|
|
181 |
end
|
|
182 |
|
|
183 |
function onGearAdd(gear)
|
|
184 |
if GetGearType(gear) == gtHedgehog then
|
|
185 |
hhs[numhhs] = gear
|
|
186 |
times[numhhs] = 0
|
|
187 |
numhhs = numhhs + 1
|
|
188 |
elseif GetGearType(gear) == gtRope then -- rope is shot
|
|
189 |
|
|
190 |
end
|
|
191 |
end
|
|
192 |
|
|
193 |
function onGearDelete(gear)
|
|
194 |
if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope
|
|
195 |
--TurnTimeLeft = 0 -- end turn or not? hm...
|
|
196 |
lasthog = CurrentHedgehog
|
|
197 |
|
|
198 |
end
|
|
199 |
end
|