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