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