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