1
2
3HedgewarsScriptLoad("/Scripts/Locale.lua")
4HedgewarsScriptLoad("/Scripts/Utils.lua")
5HedgewarsScriptLoad("/Scripts/Achievements.lua")
6
7local player
8local playerTeamName, haplessTeamName
9local hh = {}
10local hhCount = 8
11local GameOver = false
12local introStage = 0
13local genCounter = 0
14local waterCounter = 0
15local waterPix = 0
16local frig = 0
17local watGear = nil
18local cinematic = false
19
20function printMission()
21	local highscore = tonumber(GetMissionVar("Highscore"))
22	local show = (type(highscore) == "number") and (highscore > 0)
23	local recordInfo = ""
24	if show then
25		recordInfo = getReadableChallengeRecord("Highscore")
26	end
27	ShowMission(loc("That Sinking Feeling"), loc("Challenge"), loc("Save as many hogs as possible!")
28	.. "|" .. recordInfo, 10, 0)
29end
30
31-- allow skipping of the intro via hitting precise key
32function onPrecise()
33	if introStage < 100 then
34		introStage = 110
35		genCounter = 0
36		FollowGear(CurrentHedgehog)
37		AddCaption(loc("Good luck out there!"))
38		printMission()
39		SetInputMask(0xFFFFFFFF)
40	end
41end
42
43function onGameInit()
44
45	Seed = 0
46	GameFlags = gfInfAttack + gfInvulnerable + gfOneClanMode
47	TurnTime = 90000
48	CaseFreq = 0
49	MinesNum = 0
50	MinesTime  = 3000
51	Explosives = 0
52	Map = "Islands"
53	Theme = "City"
54	HealthDecrease = 0
55	WaterRise = 0
56
57	haplessTeamName = AddTeam(loc("Hapless Hogs"), -1, "Simple", "Island", "Default_qau")
58	hh[0] = AddHog(loc("Sinky"), 1, 100, "fr_lemon")
59	hh[1] = AddHog(loc("Drowner"), 1, 100, "fr_orange")
60	hh[2] = AddHog(loc("Heavy"), 1, 100, "dish_Teapot")
61	hh[3] = AddHog(loc("Clumsy"), 1, 100, "dish_SauceBoatSilver")
62	hh[4] = AddHog(loc("Silly"), 1, 100, "dish_Ladle")
63	hh[5] = AddHog(loc("Careless"), 1, 100, "StrawHatEyes")
64	hh[6] = AddHog(loc("Sponge"), 1, 100, "sf_chunli")
65	hh[7] = AddHog(loc("Deadweight"), 1, 100, "dish_Teacup")
66
67	playerTeamName = AddMissionTeam(-1)
68	player = AddMissionHog(1)
69	HogTurnLeft(player, false)
70
71	SetGearPosition(player, 3992, 733)
72	SetGearPosition(hh[0], 938, 1369)
73	SetGearPosition(hh[1], 1301, 1439)
74	SetGearPosition(hh[2], 2093, 447)
75	SetGearPosition(hh[3], 2971, 926)
76	SetGearPosition(hh[4], 719, 545)
77	SetGearPosition(hh[5], 1630, 821)
78	SetGearPosition(hh[6], 2191, 810)
79	SetGearPosition(hh[7], 3799, 945)
80
81	-- Disable all input except [Precise] for the intro
82	SetInputMask(gmPrecise)
83end
84
85
86function onGameStart()
87	cinematic = true
88	SetCinematicMode(true)
89	SendHealthStatsOff()
90
91	printMission()
92	HideMission()
93
94	HogTurnLeft(hh[0], false)
95	HogTurnLeft(hh[1], true)
96
97	SpawnSupplyCrate(148,265,amLowGravity)
98	SpawnSupplyCrate(2124,1516,amJetpack)
99
100end
101
102
103function onNewTurn()
104	SetTurnTimeLeft(MAX_TURN_TIME)
105end
106
107function onGameTick()
108
109	-- intro sequence
110	if introStage < 100 then
111
112		frig = frig + 1
113		if frig == 50 then
114			frig = 0
115			AddCaption(loc("Press [Precise] to skip intro"))
116			if watGear ~= nil then
117				FollowGear(watGear)
118			end
119		end
120
121
122		--AddCaption(loc("Press [Precise] to skip intro"))
123		genCounter = genCounter + 1
124
125		if introStage == 0 then
126
127
128			--FollowGear(hh[0])
129
130			if genCounter == 2000 then
131				watGear = hh[0]
132				HogSay(hh[0], loc("This rain is really something..."), SAY_SAY,2)
133			elseif genCounter == 5000 then
134				introStage = 1
135				genCounter = 0
136			end
137
138		elseif introStage == 1 then
139
140			--FollowGear(hh[1])
141
142			if genCounter == 2000 then
143				watGear = hh[1]
144				HogSay(hh[1], loc("Heh, it's not that bad."), SAY_SAY,2)
145			elseif genCounter == 5000 then
146				introStage = 2
147				genCounter = 0
148			end
149
150		elseif introStage == 2 then
151
152			--FollowGear(hh[0])
153
154			if genCounter == 2000 then
155				watGear = hh[0]
156				HogSay(hh[0], loc("You'd almost swear the water was rising!"), SAY_SHOUT,2)
157			elseif genCounter == 6000 then
158				introStage = 3
159				genCounter = 0
160			end
161
162		elseif introStage == 3 then
163
164			--FollowGear(hh[1])
165
166			if genCounter == 2000 then
167				watGear = hh[1]
168				HogSay(hh[1], loc("Haha, now THAT would be something!"), SAY_SAY,2)
169			elseif genCounter == 6000 then
170				introStage = 4
171				genCounter = 0
172			end
173
174		elseif introStage == 4 then
175
176			--FollowGear(hh[0])
177
178			if genCounter == 2000 then
179				watGear = hh[0]
180				HogSay(hh[0], loc("Hahahaha!"), SAY_SHOUT,2)
181				HogSay(hh[1], loc("Hahahaha!"), SAY_SHOUT,2)
182			elseif genCounter == 3000 then
183				introStage = 5
184				genCounter = 0
185			end
186
187		elseif introStage == 5 then
188
189			--FollowGear(hh[1])
190
191			if genCounter == 2000 then
192				watGear = hh[1]
193				HogSay(hh[0], loc("..."), SAY_THINK,2)
194				HogSay(hh[1], loc("..."), SAY_THINK,2)
195			elseif genCounter == 5000 then
196				introStage = 6
197				genCounter = 0
198			end
199
200		elseif introStage == 6 then
201
202			--FollowGear(hh[0])
203
204			if genCounter == 2000 then
205				watGear = hh[0]
206				HogSay(hh[0], loc("It's a good thing SUDDEN DEATH is 99 turns away..."), SAY_THINK,2)
207			elseif genCounter == 6000 then
208				introStage = 7
209				genCounter = 0
210			end
211
212
213		elseif introStage == 7 then
214
215			if genCounter == 2000 then
216				introStage = 110
217				FollowGear(CurrentHedgehog)
218				ShowMission(loc("That Sinking Feeling"), loc("User Challenge"), loc("Save as many hogs as possible!"), 10, 0)
219				SetInputMask(0xFFFFFFFF)
220			end
221
222		end
223
224	end
225
226	-- start the water rising when the intro is finished
227	if introStage == 110 then
228
229        if cinematic then
230            SetCinematicMode(false)
231            cinematic = false
232        end
233
234		waterCounter = waterCounter + 1
235		if (waterCounter == 100) and (waterPix < 1615) then
236			waterCounter = 0
237			SetTag(AddGear(0, 0, gtWaterUp, 0, 0, 0, 0), 1)
238			waterPix = waterPix +1
239			--AddCaption(waterPix)
240
241			if (waterPix >= 1615) and (GameOver == false) then
242				GameOver = true
243				AddCaption(loc("The flood has stopped! Challenge over."))
244				SendStat(siGameResult, loc("Challenge completed!"))
245				SendStat(siPointType, "!POINTS")
246				SendStat(siPlayerKills, tostring(hhCount), playerTeamName)
247
248				-- Do not count drowning hedgehogs
249				local hhLeft = hhCount
250				for i=1,#hh do
251					local isDrowning = band(GetState(hh[i]),gstDrowning) ~= 0
252					if isDrowning then
253						hhLeft = hhLeft - 1
254					end
255				end
256
257				SendStat(siCustomAchievement, string.format(loc("You saved %d of 8 hegehogs."), hhLeft))
258
259				-- Update highscore
260				updateChallengeRecord("Highscore", hhLeft)
261
262				if hhLeft == 8 then
263					SaveMissionVar("Won", "true")
264					awardAchievement(loc("Lively Lifeguard"))
265				end
266				EndGame()
267				for _, hog in pairs(hh) do
268					SetState(hog, gstWinner)
269				end
270
271			end
272
273		end
274
275	end
276end
277
278
279function onAmmoStoreInit()
280
281	SetAmmo(amBazooka, 9, 0, 0, 0)
282
283	SetAmmo(amRope, 9, 0, 0, 0)
284	SetAmmo(amParachute, 9, 0, 0, 0)
285	SetAmmo(amJetpack, 2, 0, 0, 2)
286
287	SetAmmo(amGirder, 9, 0, 0, 0)
288	SetAmmo(amBaseballBat, 9, 0, 0, 0)
289
290	SetAmmo(amTeleport, 1, 0, 0, 1)
291	SetAmmo(amPortalGun, 3, 0, 0, 1)
292
293	SetAmmo(amLowGravity, 0, 0, 0, 1)
294
295end
296
297function onGearDelete(gear)
298
299	if GetGearType(gear) == gtHedgehog then
300		if GetHogTeamName(gear) == haplessTeamName then
301			hhCount = hhCount - 1
302			AddCaption(string.format(loc("Hedgehogs left: %d"), hhCount))
303		end
304	end
305
306	if ((gear == player) or (hhCount == 0)) and (GameOver == false) then
307		SetHealth(player, 0)
308		AddCaption(loc("Challenge failed!"))
309		if gear == player then
310			SendStat(siCustomAchievement, loc("Your hedgehog died!"))
311			SendStat(siCustomAchievement, loc("You must survive the flood in order to score."))
312		else
313			SendStat(siCustomAchievement, loc("You haven't rescued anyone."))
314		end
315		SendStat(siPointType, "!POINTS")
316		SendStat(siPlayerKills, "0", playerTeamName)
317		local highscore = tonumber(GetMissionVar("Highscore"))
318		show = (type(highscore) == "number") and (highscore > 0)
319		updateChallengeRecord("Highscore", 0, show)
320
321		SendStat(siGameResult, loc("Challenge failed!"))
322		GameOver = true
323		EndGame()
324	end
325
326end
327