1HedgewarsScriptLoad("/Scripts/Utils.lua")
2HedgewarsScriptLoad("/Scripts/Locale.lua")
3
4local hhs = {}
5local missionWon = nil
6local missionEndHandled = false
7local endTimer = 1000
8local hogsKilled = 0
9local finishTime
10local ouchies = false
11local valkyriesTimer = -1
12
13local HogData =	{
14					{"amn",			"NinjaFull",false},
15					{"alfadur",		"NoHat",false},
16					{"Anachron",		"war_americanww2helmet",false},
17					{"Bufon", 			"ShaggyYeti",false},
18					{"burp", 			"lambda",false},
19					{"Blue", 			"cap_blue",false},
20					{"bender", 			"NoHat",false},
21					{"Castell",			"NoHat",false},
22					{"cekoto", 			"NoHat",false},
23					{"CheezeMonkey",	"NoHat",false},
24					{"claymore", 		"NoHat",false},
25					{"CIA-144", 		"cyborg1",false},
26					{"cri.the.grinch",	"sf_blanka",false},
27					{"eldiablo",		"Evil",false},
28					{"Displacer",		"fr_lemon",false},
29					{"doomy", 			"NoHat",false},
30					{"Falkenauge", 		"NoHat",false},
31					{"FadeOne", 		"NoHat",false},
32					{"hayaa", 			"NoHat",false},
33					{"Hermes", 			"laurel",false},
34					{"Henek", 		"WizardHat",false},
35					{"HedgeKing",		"NoHat",false},
36					{"Izack1535", 		"NoHat",false},
37					{"Kiofspa", 		"NoHat",false},
38					{"KoBeWi",		"NoHat",false},
39					{"Komplex", 		"NoHat",false},
40					{"koda", 			"poke_mudkip",false},
41					{"Lalo", 			"NoHat",false},
42					{"Logan", 			"NoHat",false},
43					{"lollkiller", 		"NoHat",false},
44					{"Luelle", 			"NoHat",false},
45					{"mikade", 			"Skull",false},
46					{"Mushi", 			"sm_daisy",false},
47					{"Naboo", 			"NoHat",false},
48					{"nemo", 			"bb_bub",false},
49					{"practice", 		"NoHat",false},
50					{"Prof. Panic",  	"NoHat",false},
51					{"Randy",			"zoo_Sheep",false},
52					{"rhino", 			"NinjaTriangle",false},
53					{"Radissthor",  	"NoHat",false},
54					{"Sami",			"sm_peach",false},
55					{"soreau", 			"NoHat",false},
56					{"Solar",		"pinksunhat",false},
57					{"sparkle",		"NoHat",false},
58					{"szczur", 		"mp3",false},
59					{"sdw195", 			"NoHat",false},
60					{"sphrix", 			"TeamTopHat",false},
61					{"sheepluva",		"zoo_Sheep",false},
62					{"Smaxx", 			"NoHat",false},
63					{"shadowzero", 		"NoHat",false},
64					{"Star and Moon",	"SparkleSuperFun",false},
65					{"The 24",			"NoHat",false},
66					{"TLD",				"NoHat",false},
67					{"Tiyuri", 			"sf_ryu",false},
68					{"unC0Rr", 			"cyborg1",false},
69					{"Waldsau", 		"cyborg1",false},
70					{"wolfmarc", 		"knight",false},
71					{"Wuzzy",		"fr_orange",false},
72					{"Xeli", 			"android",false}
73
74				}
75
76local playerTeamName
77
78function GetKillScore()
79	return math.ceil((hogsKilled / 16)*6000)
80end
81
82function ProtectEnemies()
83	for i=1, 16 do
84		if hhs[i] and GetHealth(hhs[i]) then
85			SetEffect(hhs[i], heInvulnerable, 1)
86		end
87	end
88end
89
90function GameOverMan()
91	StopMusicSound(sndRideOfTheValkyries)
92	valkyriesTimer = -1
93	missionWon = false
94	ProtectEnemies()
95	SendStat(siGameResult, loc("Challenge over!"))
96	local score = GetKillScore()
97	SendStat(siCustomAchievement, string.format(loc("You have killed %d of 16 hedgehogs (+%d points)."), hogsKilled, score))
98	SendStat(siPointType, "!POINTS")
99	SendStat(siPlayerKills, tostring(score), playerTeamName)
100
101	-- Update highscore
102	updateChallengeRecord("Highscore", score)
103
104	EndGame()
105end
106
107function GG()
108	missionWon = true
109	local completeTime = (TurnTime - finishTime) / 1000
110	ShowMission(loc("Rope-knocking Challenge"), loc("Challenge completed!"), loc("Congratulations!") .. "|" .. string.format(loc("Completion time: %.2fs"), completeTime), 0, 0)
111	PlaySound(sndHomerun)
112	SendStat(siGameResult, loc("Challenge completed!"))
113	local hogScore = GetKillScore()
114	local timeScore = math.ceil((finishTime/TurnTime)*6000)
115	local score = hogScore + timeScore
116
117	SendStat(siCustomAchievement, string.format(loc("You have killed %d of 16 hedgehogs (+%d points)."), hogsKilled, hogScore))
118	SendStat(siCustomAchievement, string.format(loc("You have completed this challenge in %.2f s (+%d points)."), completeTime, timeScore))
119	SendStat(siPointType, "!POINTS")
120	SendStat(siPlayerKills, tostring(score), playerTeamName)
121	SetTeamLabel(playerTeamName, tostring(score))
122
123	-- Update highscore
124	updateChallengeRecord("Highscore", score)
125
126	if hhs[0] and GetHealth(hhs[0]) then
127		SetEffect(hhs[0], heInvulnerable, 1)
128	end
129	SetTurnTimeLeft(MAX_TURN_TIME)
130end
131
132function AssignCharacter(p)
133
134	done = false
135	sanityCheck = 0
136
137	while(done == false) do
138
139		i = 1+ GetRandom(#HogData)
140		if HogData[i][3] == false then
141			HogData[i][3] = true
142			done = true
143			SetHogName(hhs[p], HogData[i][1])
144			SetHogHat(hhs[p], HogData[i][2])
145		elseif HogData[i][3] == true then
146			sanityCheck = sanityCheck +1
147			if sanityCheck == 100 then
148				done = true
149				SetHogName(hhs[p], "Newbie")
150				SetHogHat(hhs[p], "NoHat")
151			end
152		end
153
154	end
155
156end
157
158function onGameInit()
159
160	--Seed = 1
161	GameFlags = gfBorder + gfSolidLand
162
163	TurnTime = 180 * 1000
164	Map = "Ropes"
165	Theme = "Eyes"
166
167	-- Disable Sudden Death
168	WaterRise = 0
169	HealthDecrease = 0
170
171	CaseFreq = 0
172	MinesNum = 0
173	Explosives = 0
174
175	playerTeamName = AddMissionTeam(-1)
176	hhs[0] = AddMissionHog(1)
177
178	AddTeam(loc("Unsuspecting Louts"), -2, "Simple", "Island", "Default", "cm_face")
179	for i = 1, 8 do
180		-- The name "generic" is a placeholder and will be replaced in AssignCharacter
181		hhs[i] = AddHog("generic", 0, 1, "NoHat")
182	end
183
184	AddTeam(loc("Unlucky Sods"), -2, "Simple", "Island", "Default", "cm_balrog")
185	for i = 9, 16 do
186		hhs[i] = AddHog("generic", 0, 1, "NoHat")
187	end
188
189end
190
191
192
193function onGameStart()
194	SendHealthStatsOff()
195
196	local recordInfo = getReadableChallengeRecord("Highscore")
197	if recordInfo == nil then
198		recordInfo = ""
199	else
200		recordInfo = "|" .. recordInfo
201	end
202	ShowMission     (
203                        loc("Rope-knocking Challenge"),
204                        loc("Challenge"),
205                        loc("Use the rope to knock your enemies to their doom.") .. "|" ..
206                        loc("Finish this challenge as fast as possible to earn bonus points.").. recordInfo,
207                        -amRope, 4000)
208	SetTeamLabel(playerTeamName, "0")
209
210	PlaceGirder(46,1783, 0)
211
212	SetGearPosition(hhs[0], 2419, 1769)
213	SetGearPosition(hhs[1], 3350, 570)
214	SetGearPosition(hhs[2], 3039, 1300)
215	SetGearPosition(hhs[3], 2909, 430)
216	SetGearPosition(hhs[4], 2150, 879)
217	SetGearPosition(hhs[5], 1735, 1136)
218	SetGearPosition(hhs[6], 1563, 553)
219	SetGearPosition(hhs[7], 679, 859)
220	SetGearPosition(hhs[8], 1034, 251)
221	SetGearPosition(hhs[9], 255, 67)
222	SetGearPosition(hhs[10], 2671, 7)
223	SetGearPosition(hhs[11], 2929, 244)
224	SetGearPosition(hhs[12], 1946, 221)
225	SetGearPosition(hhs[13], 3849, 1067)
226	SetGearPosition(hhs[14], 3360, 659)
227	SetGearPosition(hhs[15], 3885, 285)
228	SetGearPosition(hhs[16], 935, 1160)
229	HogTurnLeft(hhs[0], true)
230
231	for i = 1, 16 do
232		AssignCharacter(i)
233	end
234
235end
236
237function onGameTick()
238
239	if (TurnTimeLeft == 1) and (missionWon == nil) then
240		GameOverMan()
241	end
242
243	if missionWon ~= nil then
244
245		endTimer = endTimer - 1
246		if endTimer == 1 then
247			EndGame()
248		end
249
250		if not missionEndHandled then
251			if missionWon == true then
252				SaveMissionVar("Won", "true")
253				AddCaption(loc("Victory!"), capcolDefault, capgrpGameState)
254			end
255			missionEndHandled = true
256		end
257
258	end
259
260end
261
262function onGameTick20()
263	if (valkyriesTimer > 0) then
264		valkyriesTimer = valkyriesTimer - 20
265		if valkyriesTimer <= 0 then
266			StopMusicSound(sndRideOfTheValkyries)
267		end
268	end
269end
270
271function onGearDamage(gear, damage)
272
273	if gear == hhs[0] then
274		ouchies = true
275		StopMusicSound(sndRideOfTheValkyries)
276		valkyriesTimer = -1
277		ProtectEnemies()
278	end
279
280	if gear ~= hhs[0] and GetGearType(gear) == gtHedgehog and missionWon == nil and ouchies == false then
281
282		AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false)
283		DeleteGear(gear)
284		PlaySound(sndExplosion)
285		AddCaption(string.format(knockTaunt(), GetHogName(gear)), capcolDefault, capgrpMessage)
286
287		hogsKilled = hogsKilled +1
288		SetTeamLabel(playerTeamName, tostring(GetKillScore()))
289
290		if hogsKilled == 15 then
291			PlayMusicSound(sndRideOfTheValkyries)
292			-- Time in ms after which to return to normal music
293			valkyriesTimer = 20000
294		elseif hogsKilled == 16 then
295			finishTime = TurnTimeLeft
296			GG()
297		end
298
299	end
300
301end
302
303function knockTaunt()
304	local r = math.random(0,23)
305	local taunt
306	if r == 0 then taunt =		loc("%s has been knocked out.")
307	elseif r == 1 then taunt =	loc("%s hit the ground.")
308	elseif r == 2 then taunt =	loc("%s splatted.")
309	elseif r == 3 then taunt =	loc("%s was smashed.")
310	elseif r == 4 then taunt =	loc("%s felt unstable.")
311	elseif r == 5 then taunt =	loc("%s exploded.")
312	elseif r == 6 then taunt =	loc("%s fell from a high cliff.")
313	elseif r == 7 then taunt =	loc("%s goes the way of the lemming.")
314	elseif r == 8 then taunt =	loc("%s was knocked away.")
315	elseif r == 9 then taunt =	loc("%s was really unlucky.")
316	elseif r == 10 then taunt =	loc("%s felt victim to rope-knocking.")
317	elseif r == 11 then taunt =	loc("%s had no chance.")
318	elseif r == 12 then taunt =	loc("%s was a good target.")
319	elseif r == 13 then taunt =	loc("%s spawned at a really bad position.")
320	elseif r == 14 then taunt =	loc("%s was doomed from the beginning.")
321	elseif r == 15 then taunt =	loc("%s has fallen victim to gravity.")
322	elseif r == 16 then taunt =	loc("%s hates Newton.")		-- Isaac Newton
323	elseif r == 17 then taunt =	loc("%s had it coming.")
324	elseif r == 18 then taunt =	loc("%s is eliminated!")
325	elseif r == 19 then taunt =	loc("%s fell too fast.")
326	elseif r == 20 then taunt =	loc("%s flew like a rock.")
327	elseif r == 21 then taunt =	loc("%s stumbled.")
328	elseif r == 22 then taunt =	loc("%s was shoved away.")
329	elseif r == 23 then taunt =	loc("%s didn't expect that.")
330	end
331	return taunt
332end
333
334function onGearDelete(gear)
335
336	if (gear == hhs[0]) and (missionWon == nil) then
337		GameOverMan()
338	end
339
340end
341
342function onAmmoStoreInit()
343	SetAmmo(amRope, 9, 0, 0, 0)
344end
345
346function onNewTurn()
347 	SetWeapon(amRope)
348end
349