share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua
changeset 15494 55436712b5e9
parent 15068 6f51c75994a4
equal deleted inserted replaced
15493:6a880692afbc 15494:55436712b5e9
    12 	- Rope around obstacles
    12 	- Rope around obstacles
    13 ]]
    13 ]]
    14 
    14 
    15 HedgewarsScriptLoad("/Scripts/Locale.lua")
    15 HedgewarsScriptLoad("/Scripts/Locale.lua")
    16 HedgewarsScriptLoad("/Scripts/Utils.lua")
    16 HedgewarsScriptLoad("/Scripts/Utils.lua")
       
    17 HedgewarsScriptLoad("/Scripts/Achievements.lua")
    17 
    18 
    18 -- Map definition automatically converted from HWMAP file by hwmap2lua.sh
    19 -- Map definition automatically converted from HWMAP file by hwmap2lua.sh
    19 local map =
    20 local map =
    20 {'\2\30\7\126\135\2\28\5\52\0\1\211\6\203\135\3\207\6\189\0\3\1\5\205\135\4\120\5\203\0\2\30\5\31\135\2\35\4\173\0\1\170\4\216\135\4\150\4\248\0\3\230\4\138\135\4\54\6\22\0\3\205\6\189\135\4\154\7\91\0\4\154\7\91\135\6\57\7\41\0\4\79\6\38\135\4\221\6\112\0\4\221\6\112\135\6\27\6\70\0\3\175\6\196\135\4\51\5\235\0\3\17\6\178\135\3\161\5\226\0\4\33\7\4\135\4\191\6\93\0\4\200\7\75\135\5\45\6\137\0\6\29\6\66\135\6\98\5\123\0\6\107\7\32\135\6\237\5\249\0\6\102\5\95\135\7\169\5\6\0\7\0\5\237\135\7\235\6\20\0\7\233\6\13\135\7\226\8\43\0\13\66\6\47\135\13\100\8\57\0\7\167\5\15\135\7\164\4\51\0\7\71\4\109\135\13\235\4\132\0\13\4\6\75\135\14\242\6\57\0\14\169\6\166\135\15\183\4\86\0',
    21 {'\2\30\7\126\135\2\28\5\52\0\1\211\6\203\135\3\207\6\189\0\3\1\5\205\135\4\120\5\203\0\2\30\5\31\135\2\35\4\173\0\1\170\4\216\135\4\150\4\248\0\3\230\4\138\135\4\54\6\22\0\3\205\6\189\135\4\154\7\91\0\4\154\7\91\135\6\57\7\41\0\4\79\6\38\135\4\221\6\112\0\4\221\6\112\135\6\27\6\70\0\3\175\6\196\135\4\51\5\235\0\3\17\6\178\135\3\161\5\226\0\4\33\7\4\135\4\191\6\93\0\4\200\7\75\135\5\45\6\137\0\6\29\6\66\135\6\98\5\123\0\6\107\7\32\135\6\237\5\249\0\6\102\5\95\135\7\169\5\6\0\7\0\5\237\135\7\235\6\20\0\7\233\6\13\135\7\226\8\43\0\13\66\6\47\135\13\100\8\57\0\7\167\5\15\135\7\164\4\51\0\7\71\4\109\135\13\235\4\132\0\13\4\6\75\135\14\242\6\57\0\14\169\6\166\135\15\183\4\86\0',
    21 '\15\208\5\13\135\15\96\2\248\0\15\206\3\104\135\13\175\2\88\0\14\171\5\17\140\14\219\4\77\138\14\166\3\136\136\13\219\3\31\136\13\184\4\228\136\13\173\3\250\0\14\2\4\19\136\7\36\3\211\0\14\52\2\85\137\7\57\2\76\0\12\196\2\245\137\11\195\3\127\137\10\174\2\223\137\9\174\3\113\137\8\160\2\211\137\8\11\3\111\137\6\249\3\218\131\6\66\3\209\0\5\88\3\202\131\4\38\3\193\0\5\33\3\207\131\5\31\5\31\0\4\235\4\228\131\6\125\4\251\0\6\98\3\214\131\6\80\5\1\0\7\41\2\104\136\3\253\2\72\0\4\31\3\207\133\1\149\3\166\0\2\243\4\15\133\1\117\2\202\0\1\149\3\60\133\1\211\1\87\0\1\138\1\138\133\3\42\0\71\0\2\131\0\96\133\4\168\0\149\0\5\116\1\124\141\7\41\0\204\141\8\252\2\42\141\10\39\0\135\141\11\40\1\124\141\10\17\1\186\141',
    22 '\15\208\5\13\135\15\96\2\248\0\15\206\3\104\135\13\175\2\88\0\14\171\5\17\140\14\219\4\77\138\14\166\3\136\136\13\219\3\31\136\13\184\4\228\136\13\173\3\250\0\14\2\4\19\136\7\36\3\211\0\14\52\2\85\137\7\57\2\76\0\12\196\2\245\137\11\195\3\127\137\10\174\2\223\137\9\174\3\113\137\8\160\2\211\137\8\11\3\111\137\6\249\3\218\131\6\66\3\209\0\5\88\3\202\131\4\38\3\193\0\5\33\3\207\131\5\31\5\31\0\4\235\4\228\131\6\125\4\251\0\6\98\3\214\131\6\80\5\1\0\7\41\2\104\136\3\253\2\72\0\4\31\3\207\133\1\149\3\166\0\2\243\4\15\133\1\117\2\202\0\1\149\3\60\133\1\211\1\87\0\1\138\1\138\133\3\42\0\71\0\2\131\0\96\133\4\168\0\149\0\5\116\1\124\141\7\41\0\204\141\8\252\2\42\141\10\39\0\135\141\11\40\1\124\141\10\17\1\186\141',
    40 local barrelsBoom = false	-- barrels exploded
    41 local barrelsBoom = false	-- barrels exploded
    41 local wasFirstTurn = false	-- first turn msg was displayed
    42 local wasFirstTurn = false	-- first turn msg was displayed
    42 local gameOver = false		-- game over (only victory possible)
    43 local gameOver = false		-- game over (only victory possible)
    43 local currentTarget = 0		-- current target ID. First target = 1
    44 local currentTarget = 0		-- current target ID. First target = 1
    44 local flawless = true		-- flawless if no damage taken and no mistake made
    45 local flawless = true		-- flawless if no damage taken and no mistake made
       
    46 local flowerPower = false	-- random flower visual gears appear all ower the place
       
    47 local bonusFlowerPlaced = false -- a hidden flower sprite was placed
    45 
    48 
    46 local cpX, cpY = 208, 1384	-- hog checkpoint, initialized with start coords
    49 local cpX, cpY = 208, 1384	-- hog checkpoint, initialized with start coords
    47 
    50 
    48 -- "Constants"
    51 -- "Constants"
    49 local initHogHealth = 50
    52 local initHogHealth = 50
   116 		setPos = true
   119 		setPos = true
   117 	end
   120 	end
   118 	SetHealth(hog, initHogHealthFinal)
   121 	SetHealth(hog, initHogHealthFinal)
   119 	AddAmmo(hog, amRope, 1)
   122 	AddAmmo(hog, amRope, 1)
   120 	SetGearVelocity(hog, 0, 0)
   123 	SetGearVelocity(hog, 0, 0)
       
   124 	flowerPower = false
   121 
   125 
   122 	if setPos then
   126 	if setPos then
   123 		PlaySound(sndWarp)
   127 		PlaySound(sndWarp)
   124 		SetGearPosition(hog, cpX, cpY)
   128 		SetGearPosition(hog, cpX, cpY)
   125 		AddVisualGear(cpX, cpY, vgtExplosion, 0, false)
   129 		AddVisualGear(cpX, cpY, vgtExplosion, 0, false)
   205 		wasFirstTurn = true
   209 		wasFirstTurn = true
   206 	end
   210 	end
   207 end
   211 end
   208 
   212 
   209 function onGameTick()
   213 function onGameTick()
       
   214 
       
   215 	if flowerPower then
       
   216 		for i=1,2 do
       
   217 			AddVisualGear(math.random(-1024, LAND_WIDTH+1024), math.random(TopY-1024, LAND_HEIGHT), vgtBeeTrace, 0, false)
       
   218 		end
       
   219 	end
       
   220 
   210 	if gameOver or (not CurrentHedgehog) then
   221 	if gameOver or (not CurrentHedgehog) then
   211 		return
   222 		return
   212 	end
   223 	end
   213 
   224 
   214 	-- First rope selection
   225 	-- First rope selection
   253 		SetInputMask(band(GetInputMask(), bnot(gmAttack)))
   264 		SetInputMask(band(GetInputMask(), bnot(gmAttack)))
   254 	end
   265 	end
   255 	if isInFinalChallenge then
   266 	if isInFinalChallenge then
   256 		local dX, dY = GetGearVelocity(CurrentHedgehog)
   267 		local dX, dY = GetGearVelocity(CurrentHedgehog)
   257 		local x, y = GetGearPosition(CurrentHedgehog)
   268 		local x, y = GetGearPosition(CurrentHedgehog)
   258 		if band(GetState(CurrentHedgehog), gstHHDriven) ~= 0 and GetAmmoCount(CurrentHedgehog, amRope) == 0 and
   269 		local driven = band(GetState(CurrentHedgehog), gstHHDriven) ~= 0
       
   270 		if driven and y > 1310 and x < 338 and not flowerPower then
       
   271 			-- Player reached the bonus flower. Enable Flower Power mode!
       
   272 			PlaySound(sndKiss)
       
   273 			flowerPower = true
       
   274 		end
       
   275 		if driven and GetAmmoCount(CurrentHedgehog, amRope) == 0 and
   259 				GetFlightTime(CurrentHedgehog) == 0 and (not ropeGear) and
   276 				GetFlightTime(CurrentHedgehog) == 0 and (not ropeGear) and
   260 				math.abs(dX) < 5 and math.abs(dY) < 5 and
   277 				math.abs(dX) < 5 and math.abs(dY) < 5 and
   261 				(x < 3417 or y > 471) then
   278 				(x < 3417 or y > 471) then
   262 			flawless = false
   279 			flawless = false
   263 			AddCaption(loc("Your rope is gone! Try again!"))
   280 			AddCaption(loc("Your rope is gone! Try again!"))
   266 		end
   283 		end
   267 	end
   284 	end
   268 end
   285 end
   269 
   286 
   270 function onGameTick20()
   287 function onGameTick20()
       
   288 	if flowerPower then
       
   289 		if math.random(1,2) == 1 then
       
   290 			local vg = AddVisualGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), vgtStraightShot, sprTargetBee, false, 1)
       
   291 			SetVisualGearValues(vg, nil, nil, nil, nil, math.random(0, 360), nil, nil, nil, nil, 0xFFFFFFC0)
       
   292 		end
       
   293 	end
   271 	if not gameOver and not target1Reached and CurrentHedgehog and gearIsInCircle(CurrentHedgehog, targetData[1][1], targetData[1][2], 48, false) then
   294 	if not gameOver and not target1Reached and CurrentHedgehog and gearIsInCircle(CurrentHedgehog, targetData[1][1], targetData[1][2], 48, false) then
   272 		ShowMission(loc("Basic Rope Training"), loc("Target Puncher"),
   295 		ShowMission(loc("Basic Rope Training"), loc("Target Puncher"),
   273 		loc("Okay, now destroy the target|using the baseball bat.").."|"..
   296 		loc("Okay, now destroy the target|using the baseball bat.").."|"..
   274 		loc("Release rope: [Attack]"), 2, 9000)
   297 		loc("Release rope: [Attack]"), 2, 9000)
   275 		target1Reached = true
   298 		target1Reached = true
   360 			loc("Reach and destroy the final target to win.").."|"..
   383 			loc("Reach and destroy the final target to win.").."|"..
   361 			loc("You only get 1 rope this time, don't waste it!"),
   384 			loc("You only get 1 rope this time, don't waste it!"),
   362 			2, 25000)
   385 			2, 25000)
   363 			eraseGirder(4)
   386 			eraseGirder(4)
   364 			eraseGirder(5)
   387 			eraseGirder(5)
       
   388 			-- Sneakingly place a flower sprite near spawn when player reached the last section
       
   389 			-- When the player reaches it, Flower Power mode is enabled
       
   390 			if not bonusFlowerPlaced then
       
   391 				PlaceSprite(240, 1360, sprTargetBee, 0)
       
   392 				bonusFlowerPlaced = true
       
   393 			end
   365 			AddAmmo(hog, amRope, 1)
   394 			AddAmmo(hog, amRope, 1)
   366 			SetHealth(hog, initHogHealthFinal)
   395 			SetHealth(hog, initHogHealthFinal)
   367 			isInFinalChallenge = true
   396 			isInFinalChallenge = true
   368 		elseif currentTarget == 7 then
   397 		elseif currentTarget == 7 then
   369 			SaveMissionVar("Won", "true")
   398 			SaveMissionVar("Won", "true")
   377 			AddAmmo(hog, amBaseballBat, 0)
   406 			AddAmmo(hog, amBaseballBat, 0)
   378 			AddAmmo(hog, amGrenade, 0)
   407 			AddAmmo(hog, amGrenade, 0)
   379 			AddAmmo(hog, amRope, 0)
   408 			AddAmmo(hog, amRope, 0)
   380 			SendStat(siCustomAchievement, loc("Oh yeah! You sure know how to rope!"))
   409 			SendStat(siCustomAchievement, loc("Oh yeah! You sure know how to rope!"))
   381 			SendStat(siGameResult, loc("You have finished the Basic Rope Training!"))
   410 			SendStat(siGameResult, loc("You have finished the Basic Rope Training!"))
       
   411 			if flowerPower then
       
   412 				awardAchievement(loc("Flower Power"))
       
   413 			end
   382 			EndGame()
   414 			EndGame()
   383 			SetState(hog, gstWinner)
   415 			SetState(hog, gstWinner)
   384 			gameOver = true
   416 			gameOver = true
   385 			SetInputMask(0)
   417 			SetInputMask(0)
   386 		end
   418 		end