4106
|
1 |
-- Hedgewars - Roperace for 2+ Players
|
|
2 |
|
|
3 |
local caption = {
|
|
4 |
["en"] = "TrophyRace",
|
4162
|
5 |
["sv"] = "TrophyRace",
|
4170
|
6 |
["pt_PT"] = "TrophyRace"
|
4106
|
7 |
}
|
|
8 |
|
|
9 |
local goal = {
|
|
10 |
["en"] = "Use your rope to get from start to finish as fast as you can!",
|
4162
|
11 |
["sv"] = "Använd ditt rep för att ta dig från start till mål så fort som möjligt!",
|
4170
|
12 |
["pt_PT"] = "Utilizando a corda, percorre o percurso do inicio ao fim o mais rápido que conseguires!"
|
4106
|
13 |
}
|
|
14 |
|
|
15 |
local done = {
|
|
16 |
["en"] = "You've reached the goal!| |Time: ",
|
4162
|
17 |
["sv"] = "Du har nått målet!| |Tid: ",
|
4170
|
18 |
["pt_PT"] = "Chegaste ao fim!| |Tempo: "
|
4106
|
19 |
}
|
|
20 |
|
|
21 |
local eliminated = {
|
|
22 |
["en"] = "Eliminating worst hedgehog this round...| |%s is OUT!",
|
4162
|
23 |
["sv"] = "Eliminerar sämsta igelkott den här rundan...| |%s är UTE!",
|
4170
|
24 |
["pt_PT"] = "A eliminar o pior ouriço da ronda...| |% está FORA!"
|
4106
|
25 |
}
|
|
26 |
|
|
27 |
local newbesttime = {
|
|
28 |
["en"] = "NEW fastest lap: ",
|
4162
|
29 |
["sv"] = "NYTT snabbast varv: ",
|
4170
|
30 |
["pt_PT"] = "NOVA volta recorde: "
|
4106
|
31 |
}
|
|
32 |
|
|
33 |
local oldbesttime = {
|
|
34 |
["en"] = "Fastest lap: ",
|
4162
|
35 |
["sv"] = "Snabbast varv: ",
|
4170
|
36 |
["pt_PT"] = "Volta mais rápida: "
|
4106
|
37 |
}
|
|
38 |
local bestclantimes = {
|
|
39 |
["en"] = "Best laps per team: ",
|
4162
|
40 |
["sv"] = "Bästa varv per lag: ",
|
4170
|
41 |
["pt_PT"] = "Melhores voltas por equipa: "
|
4106
|
42 |
}
|
|
43 |
local clantime = {
|
|
44 |
["en"] = "Team %d: ",
|
4162
|
45 |
["sv"] = "Lag %d: ",
|
4170
|
46 |
["pt_PT"] = "Equipa %d: "
|
4106
|
47 |
}
|
|
48 |
|
|
49 |
local function loc(text)
|
|
50 |
if text == nil then return "**missing**"
|
|
51 |
elseif text[L] == nil then return text["en"]
|
|
52 |
else return text[L]
|
|
53 |
end
|
|
54 |
end
|
|
55 |
|
|
56 |
---------------------------------------------------------------
|
|
57 |
|
|
58 |
-- store number of hedgehogs
|
|
59 |
local numhhs = 0
|
|
60 |
|
|
61 |
-- store hedgehog gears
|
|
62 |
local hhs = {}
|
|
63 |
|
|
64 |
-- store best time per team
|
|
65 |
local clantimes = {}
|
|
66 |
|
|
67 |
-- store best times
|
|
68 |
local times = {}
|
|
69 |
|
|
70 |
-- in milisseconds
|
|
71 |
local maxtime = 99000
|
|
72 |
|
|
73 |
-- define start area (left, top, width, height)
|
|
74 |
local start_area = {1606, 498, 356, 80}
|
|
75 |
|
|
76 |
-- define goal area (left, top, width, height)
|
|
77 |
local goal_area = {2030, 300, 56, 280}
|
|
78 |
|
|
79 |
-- last active hog
|
|
80 |
local lasthog = nil
|
|
81 |
|
|
82 |
-- active hog reached the goal?
|
|
83 |
local reached = false
|
|
84 |
|
|
85 |
-- hog with best time
|
|
86 |
local besthog = nil
|
|
87 |
|
|
88 |
-- hog with worst time (per round)
|
|
89 |
local worsthog = nil
|
|
90 |
|
|
91 |
-- best time
|
|
92 |
local besttime = maxtime + 1
|
|
93 |
|
|
94 |
-- worst time (per round)
|
|
95 |
local worsttime = 0
|
|
96 |
|
|
97 |
function onGameInit()
|
|
98 |
GameFlags = gfSolidLand + gfInvulnerable
|
|
99 |
TurnTime = maxtime
|
|
100 |
CaseFreq = 0
|
4162
|
101 |
MinesNum = 0
|
4106
|
102 |
Explosives = 0
|
|
103 |
Delay = 500
|
|
104 |
SuddenDeathTurns = 99999 -- "disable" sudden death
|
|
105 |
Theme = 'Olympics'
|
|
106 |
end
|
|
107 |
|
|
108 |
function onGameStart()
|
|
109 |
ShowMission(loc(caption), "", loc(goal), -amRope, 0)
|
|
110 |
started = true
|
|
111 |
p=1820
|
|
112 |
for i = 0, numhhs - 1 do
|
|
113 |
p = p + 50
|
|
114 |
SetGearPosition(hhs[i], p, 0)
|
|
115 |
end
|
|
116 |
|
|
117 |
for i=0, ClansCount-1 do
|
|
118 |
clantimes[i] = 0
|
|
119 |
end
|
|
120 |
end
|
|
121 |
|
|
122 |
function onAmmoStoreInit()
|
|
123 |
SetAmmo(amRope, 9, 2, 0)
|
|
124 |
end
|
|
125 |
|
|
126 |
function onGameTick()
|
|
127 |
if TurnTimeLeft == 1 and CurrentHedgehog ~= nil then
|
|
128 |
SetHealth(CurrentHedgehog, 0)
|
|
129 |
x, y = GetGearPosition(CurrentHedgehog)
|
|
130 |
AddGear(x, y, gtAmmo_Grenade, 0, 0, 0, 0)
|
|
131 |
worsttime = 99999
|
|
132 |
worsthog = nil
|
|
133 |
elseif TurnTimeLeft == maxtime - 1 and CurrentHedgehog ~= nil then
|
|
134 |
if lasthog ~= nil then
|
|
135 |
SetGearPosition(lasthog, p , 0)
|
|
136 |
end
|
|
137 |
reached = false
|
|
138 |
SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
|
|
139 |
elseif CurrentHedgehog ~= nil then
|
|
140 |
x, y = GetGearPosition(CurrentHedgehog)
|
|
141 |
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
|
|
142 |
reached = true
|
|
143 |
local ttime = maxtime - TurnTimeLeft
|
|
144 |
--give it a sound;)
|
|
145 |
if ttime < besttime then
|
|
146 |
PlaySound (sndHomerun)
|
|
147 |
else
|
|
148 |
PlaySound (sndHellish)
|
|
149 |
end
|
|
150 |
for i = 0, numhhs - 1 do
|
|
151 |
if hhs[i] == CurrentHedgehog then
|
|
152 |
times[numhhs] = ttime
|
|
153 |
end
|
|
154 |
end
|
|
155 |
|
|
156 |
local hscore = "| |"
|
|
157 |
local clan = GetHogClan(CurrentHedgehog)
|
|
158 |
if ttime < clantimes[clan] or clantimes[clan] == 0 then
|
|
159 |
clantimes[clan] = ttime
|
|
160 |
end
|
|
161 |
|
|
162 |
if ttime < besttime then
|
|
163 |
besttime = ttime
|
|
164 |
besthog = CurrentHedgehog
|
|
165 |
hscore = hscore .. loc(newbesttime)
|
|
166 |
else
|
|
167 |
hscore = hscore .. loc(oldbesttime)
|
|
168 |
end
|
|
169 |
if ttime > worsttime then
|
|
170 |
worsttime = ttime
|
|
171 |
worsthog = CurrentHedgehog
|
|
172 |
end
|
|
173 |
hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc(bestclantimes)
|
|
174 |
|
|
175 |
if clan == ClansCount -1 then
|
|
176 |
-- Time for elimination - worst hog is out and the worst hog vars are reset.
|
|
177 |
SetHealth(worsthog, 0)
|
|
178 |
--Place a grenade to make inactive slowest hog active
|
|
179 |
x, y = GetGearPosition(worsthog)
|
4168
|
180 |
AddGear(x, y, gtShell, 0, 0, 0, 0)
|
4106
|
181 |
worsttime = 0
|
|
182 |
worsthog = nil
|
|
183 |
end
|
|
184 |
|
|
185 |
for i=0, ClansCount -1 do
|
|
186 |
local tt = "" .. (clantimes[i] / 1000) .. " s"
|
|
187 |
if clantimes[i] == 0 then
|
|
188 |
tt = "--"
|
|
189 |
end
|
|
190 |
hscore = hscore .. "|" .. string.format(loc(clantime), i+1) .. tt
|
|
191 |
end
|
|
192 |
|
|
193 |
ShowMission(loc(caption), "", loc(done) .. (ttime / 1000) .. " s" .. hscore, 0, 0)
|
|
194 |
TurnTimeLeft = 0
|
|
195 |
end
|
|
196 |
end
|
|
197 |
end
|
|
198 |
|
|
199 |
function onGearAdd(gear)
|
|
200 |
if GetGearType(gear) == gtHedgehog then
|
|
201 |
hhs[numhhs] = gear
|
|
202 |
times[numhhs] = 0
|
|
203 |
numhhs = numhhs + 1
|
|
204 |
elseif GetGearType(gear) == gtRope then -- rope is shot
|
|
205 |
|
|
206 |
end
|
|
207 |
end
|
|
208 |
|
|
209 |
function onGearDelete(gear)
|
|
210 |
if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope
|
|
211 |
--TurnTimeLeft = 0 -- end turn or not? hm...
|
|
212 |
lasthog = CurrentHedgehog
|
|
213 |
|
|
214 |
end
|
|
215 |
end
|