share/hedgewars/Data/Missions/Training/Basic_Training_-_Rope.lua
changeset 12050 daf63e2a21d2
parent 12049 030464f34d47
child 12344 877f55c77a3f
equal deleted inserted replaced
12049:030464f34d47 12050:daf63e2a21d2
    12 
    12 
    13 local Player = nil -- Pointer to hog created in: onGameInit
    13 local Player = nil -- Pointer to hog created in: onGameInit
    14 local Target = nil -- Pointer to target hog
    14 local Target = nil -- Pointer to target hog
    15 local GameLost = false -- You lost the game
    15 local GameLost = false -- You lost the game
    16 local Objective = false -- Get to the target
    16 local Objective = false -- Get to the target
    17 
    17 local RopeMaster = false -- Achievement
    18 local WaitTime = 10000 -- Wait 10sec before quit
    18 local StatsSent = false -- Remember whether the stats have been sent already
       
    19 
       
    20 local WaitTime = 1000 -- Wait 1sec before quit
    19 local FollowTime = 1500 -- For use with FollowGear
    21 local FollowTime = 1500 -- For use with FollowGear
    20 local FollowingGear = false
    22 local FollowingGear = false
    21 local BaseballIntro = false -- Fail safe for ticker
    23 local BaseballIntro = false -- Fail safe for ticker
    22 local TargetNumber = 0 -- The current target number
    24 local TargetNumber = 0 -- The current target number
    23 
    25 
    24 local TargetPos = {} -- Tabel of targets
    26 local TargetPos = {} -- Tabel of targets
    25 local Timers = {}
    27 local Timers = {}
    26 local GetTime = 0
    28 local GetTime = 0
    27 
    29 
    28 TargetPos[ 1 ] = { X = 1100, Y = 1100, Message = loc("Now find the next target! |Tip: Normally you lose health by falling down, so be careful!") }
    30 TargetPos[ 1 ] = { X = 1100, Y = 1100, Message = loc("Now find the next target! |Tip: Normally you lose health by falling down, so be careful!") }
    29 TargetPos[ 2 ] = { X = 1500, Y = 1490, Message = loc("You're getting pretty good! |Tip: When you shorten you rope you move faster! |and when you lengthen it you move slower") }
    31 TargetPos[ 2 ] = { X = 1500, Y = 1490, Message = loc("You're getting pretty good! |Tip: When you shorten you rope, you move faster!|And when you lengthen it, you move slower.") }
    30 TargetPos[ 3 ] = { X = 2200, Y = 800, Message = loc("The next one is pretty hard! |Tip: You have to do multiple swings!") }
    32 TargetPos[ 3 ] = { X = 2200, Y = 800, Message = loc("The next one is pretty hard! |Tip: You have to do multiple swings!") }
    31 TargetPos[ 4 ] = { X = 2870, Y = 400, Message = loc("I don't know how you did that.. But good work! |The next one should be easy as cake for you!") }
    33 TargetPos[ 4 ] = { X = 2870, Y = 400, Message = loc("I don't know how you did that .. But good work! |The next one should be easy as cake for you!") }
    32 TargetPos[ 5 ] = { X = 4000, Y = 1750, Message = "" }
    34 TargetPos[ 5 ] = { X = 4000, Y = 1750, Message = "" }
    33 TargetPos[ 6 ] = { Modifier = true, Func = function() -- Last target is ALWAYS the "winning" target!
    35 TargetPos[ 6 ] = { Modifier = true, Func = function() -- Last target is ALWAYS the "winning" target!
    34 	Info( loc("Congratulations"), loc("Congratulations! You've completed the Rope tutorial! |- Tutorial ends in 10 seconds!"), 0 ) -- Congrats
    36 	Info( loc("Congratulations"), loc("Congratulations! You've completed the Basic Rope Training!"), 0 ) -- Congrats
    35 	HogSay( Player, loc("Victory!"), SAY_SHOUT) -- You win!
    37 	PlaySound( sndVictory, Player )
    36 	PlaySound( sndVictory )
    38 
    37 
    39 	AddCaption( loc( "Victory!" ))
    38 	if TurnTimeLeft >= 250000 then -- If you very fast, unlock the ahievement "Rope Master!"
    40 	if TurnTimeLeft >= 250000 then -- If you very fast, unlock the ahievement "Rope Master!"
    39 		AddCaption( loc( "Achievement Unlocked" ) .. ": " .. loc( "Rope Master!" ),0xffba00ff,capgrpAmmoinfo )
    41 		RopeMaster = true
       
    42 		AddCaption( loc( "Achievement obtained: Rope Master!" ),0xffba00ff,capgrpAmmoinfo )
    40 		PlaySound( sndHomerun )
    43 		PlaySound( sndHomerun )
    41 	end
    44 	end
    42 
       
    43 	Objective = true
    45 	Objective = true
    44 end }
    46 end }
    45 
    47 
    46 function Info( Title, Text, Icon ) -- I made a small wrapper to ease the process
    48 function Info( Title, Text, Icon ) -- I made a small wrapper to ease the process
    47 	ShowMission( loc("Rope Training"), Title, Text, Icon, 0 )
    49 	ShowMission( loc("Rope Training"), Title, Text, Icon, 0 )
    65 		TargetPos[ TargetNumber ].Func()
    67 		TargetPos[ TargetNumber ].Func()
    66 		return true
    68 		return true
    67 	end
    69 	end
    68 
    70 
    69 	if TargetNumber > 1 then
    71 	if TargetNumber > 1 then
    70 		Info(loc("Aiming Practice"), TargetPos[ TargetNumber - 1 ].Message, -amRope )
    72 		Info(loc("Training"), TargetPos[ TargetNumber - 1 ].Message, -amRope )
    71 	end
    73 	end
    72 
    74 
    73 	SpawnTarget( TargetPos[ TargetNumber ].X, TargetPos[ TargetNumber ].Y ) -- Spawn target on the next position
    75 	SpawnTarget( TargetPos[ TargetNumber ].X, TargetPos[ TargetNumber ].Y ) -- Spawn target on the next position
    74 end
    76 end
    75 
    77 
    81 
    83 
    82 function CheckPosition( Hog, Distance ) -- Show a message when you get close to the current target!
    84 function CheckPosition( Hog, Distance ) -- Show a message when you get close to the current target!
    83 	if (not BaseballIntro and not Objective) and (CurrentHedgehog ~= nil) then --Fail safe check
    85 	if (not BaseballIntro and not Objective) and (CurrentHedgehog ~= nil) then --Fail safe check
    84 		if InRange( Hog, 1100, 1100, Distance ) then -- Check if the player is within predefined position of the first target
    86 		if InRange( Hog, 1100, 1100, Distance ) then -- Check if the player is within predefined position of the first target
    85 			BaseballIntro = true
    87 			BaseballIntro = true
    86 			Info(loc("Aiming Practice"), loc("Great work! Now hit it with your Baseball Bat! |Tip: You can change weapon with 'Right Click'!"), -amRope ) -- Guide them
    88 			Info(loc("Training"), loc("Great work! Now hit it with your Baseball Bat! |Tip: You can change weapon with 'Right Click'!"), -amRope ) -- Guide them
    87 			Timer( 10000, loc("Remember: The rope only bend around objects, |if it doesn't hit anything it's always stright!"))
    89 			Timer( 10000, loc("Remember: The rope only bend around objects, |if it doesn't hit anything it's always stright!"))
    88 		end
    90 		end
    89 	end
    91 	end
    90 end
    92 end
    91 
    93 
   105 	MinesNum = 0 -- Never place any mines on the map
   107 	MinesNum = 0 -- Never place any mines on the map
   106 	Explosives = 0 -- Never place any explosives
   108 	Explosives = 0 -- Never place any explosives
   107 	Delay = 1 -- We don't wont to wait between each round ( as the only is one )
   109 	Delay = 1 -- We don't wont to wait between each round ( as the only is one )
   108 	Map = "Ropes" -- Map name
   110 	Map = "Ropes" -- Map name
   109 	Theme = "Nature" -- Map theme
   111 	Theme = "Nature" -- Map theme
       
   112 	-- Disable Sudden Death
       
   113 	SuddenDeathTurns = 50
       
   114 	WaterRise = 0
       
   115 	HealthDecrease = 0
   110 
   116 
   111 	AddTeam( loc( "Rope Team" ), 14483456, "Simple", "Island", "Default", "cm_shoppa" ) -- Lets make the team
   117 	AddTeam( loc( "Rope Team" ), 14483456, "Simple", "Island", "Default", "cm_shoppa" ) -- Lets make the team
   112 	Player = AddHog( loc( "Hunter" ), 0, 1, "StrawHat" ) -- Add a hog for it, and name it "Hunter"
   118 	Player = AddHog( loc( "Hunter" ), 0, 1, "StrawHat" ) -- Add a hog for it, and name it "Hunter"
   113 	SetGearPosition( Player, 420, 1750 ) -- Set player position
   119 	SetGearPosition( Player, 420, 1750 ) -- Set player position
   114 
   120 
   115 	SetEffect( Player, heResurrectable, 1 ) -- By Suggestion :)
   121 	SetEffect( Player, heResurrectable, 1 ) -- By Suggestion :)
   116 end
   122 end
   117 
   123 
   118 function onGameStart() -- Called when the game starts
   124 function onGameStart() -- Called when the game starts
       
   125 	SendHealthStatsOff()
   119 	AutoSpawn() -- Spawn our 1st target using the wrapper function
   126 	AutoSpawn() -- Spawn our 1st target using the wrapper function
   120 
   127 
   121 	SetHealth( Player, 100 ) -- Give the player 100 Health points
   128 	SetHealth( Player, 100 ) -- Give the player 100 Health points
   122 
   129 
   123 	Info(loc("Aiming Practice"), loc("Get to the target using your rope! |Controls: Left & Right to swing the rope - Up & Down to Contract and Expand!"), -amRope ) -- Short intro to tell the player what to do
   130 	PlaceGirder(46,1783, 0) -- Place a girder to prevent the player falling into the water
   124 	Timer( 10000, loc("Tip: The rope physics are different than in the real world, |use it to your advantage!") ) -- After 15 sec, give them more help
   131 
       
   132 	local message = loc("Get to the target using your rope!") .. "|" .. loc("Controls: Hold the Attack key (space by default) to|fire the rope, then, once attached use:|Left and Right to swing the rope;|Up and Down to contract and expand.")
       
   133 	Info(loc("Training"), message, -amRope ) -- Short intro to tell the player what to do
       
   134 	Timer( 10000, message .. "|" .. loc("Tip: The rope physics are different than in the real world, |use it to your advantage!") ) -- After 15 sec, give them more help
   125 end
   135 end
   126 
   136 
   127 function onNewTurn()
   137 function onNewTurn()
   128 	SetWeapon(amRope) -- Set the default weapon to Rope
   138 	SetWeapon(amRope) -- Set the default weapon to Rope
   129 end
   139 end
   130 
   140 
   131 function onGameTick20()
   141 function onGameTick20()
   132 	if TurnTimeLeft < 40 and TurnTimeLeft > 0 then -- Round starts at 0, so we check if the round is finished by using 1
   142 	if TurnTimeLeft < 40 and TurnTimeLeft > 0 then -- Round starts at 0, so we check if the round is finished by using 1
   133 		GameLost = true -- You lost the game
   143 		GameLost = true -- You lost the game
   134 		Info(loc("Aiming Practice"), loc("You did not make it in time, try again!"), -amSkip )
   144 		Info(loc("Training"), loc("You did not make it in time, try again!"), -amSkip )
       
   145 		if not StatsSent then
       
   146 			SendStat(siGameResult, loc("You failed!"))
       
   147 			SendStat(siCustomAchievement, loc("You did not make it in time, try again!"))
       
   148 			StatsSent = true
       
   149 		end
   135 		SetHealth( Player, 0 ) -- Kill the player so he can't keep moving!
   150 		SetHealth( Player, 0 ) -- Kill the player so he can't keep moving!
   136 
   151 
   137 		SetEffect( Player, heResurrectable, 0 )
   152 		SetEffect( Player, heResurrectable, 0 )
   138 
   153 
   139 	end
   154 	end
   140 
   155 
   141 	-- If the player gets to the last target, they win OR
   156 	-- If the player gets to the last target, they win OR
   142 	-- If round is finished and your not at the target you lose
   157 	-- If round is finished and your not at the target you lose
   143 	-- in either case, end the game
   158 	-- in either case, end the game
   144 	if (Objective == true) or (GameLost == true) then
   159 	if (Objective == true) or (GameLost == true) then
   145 		if (WaitTime == 0) then
   160 		if (WaitTime == 0 and not StatsSent) then
   146 			DismissTeam(loc( "Rope Team" ))
   161 			SendStat(siGameResult, loc("You have finished the Basic Rope Training!"))
   147 
   162 			SendStat(siCustomAchievement, loc("Good job!"))
   148 			--SetHealth( Player, 0 ) -- Kill the player so he can't keep moving!
   163 			SendStat(siPlayerKills, "0", loc("Rope Team"))
   149 			--SetEffect( Player, heResurrectable, 0 )
   164 			if RopeMaster then
   150 			TurnTimeLeft = 1
   165 				SendStat(siCustomAchievement, loc("You earned the \"Rope Master\" achievement for finishing in under 50 seconds."))
   151 
   166 			end
   152 			WaitTime = -1
   167 			StatsSent = true
       
   168 			EndGame()
   153 		else
   169 		else
   154 			WaitTime = WaitTime - 20
   170 			WaitTime = WaitTime - 20
   155 		end
   171 		end
   156 	end
   172 	end
   157 
   173 
   165 		end
   181 		end
   166 	end
   182 	end
   167 
   183 
   168 	for k, v in pairs( Timers ) do
   184 	for k, v in pairs( Timers ) do
   169 		if v.End <= GetTime then
   185 		if v.End <= GetTime then
   170 			Info(loc("Aiming Practice"), v.Message, -amRope )
   186 			Info(loc("Training"), v.Message, -amRope )
   171 			Timers[ k ] = nil
   187 			Timers[ k ] = nil
   172 		end
   188 		end
   173 	end
   189 	end
   174 
   190 
   175 	GetTime = GetTime + 20
   191 	GetTime = GetTime + 20
   180 function onAmmoStoreInit()
   196 function onAmmoStoreInit()
   181 	SetAmmo( amRope, 9, 2, 0, 0 ) -- Player ammo, Rope
   197 	SetAmmo( amRope, 9, 2, 0, 0 ) -- Player ammo, Rope
   182 	SetAmmo( amBaseballBat, 9, 2, 0, 0 ) --Baseball bat
   198 	SetAmmo( amBaseballBat, 9, 2, 0, 0 ) --Baseball bat
   183 end
   199 end
   184 
   200 
   185 function onGearResurrect( Gear )
       
   186 	if TargetNumber > 1 then
       
   187 		SetGearPosition( Player, TargetPos[ TargetNumber - 1 ].X, TargetPos[ TargetNumber - 1 ].Y ) -- If the player dies spawn him where he last killed a target
       
   188 		Info(loc("Aiming Practice"), loc("You have been respawned, at your last checkpoint!"), -amRope )
       
   189 	else
       
   190 		SetGearPosition( Player, 420, 1750 ) -- If the player dies and didn't kill a target just spawn him at the default spawn
       
   191 		Info(loc("Aiming Practice"), loc("You have been respawned, be more carefull next time!"), -amRope )
       
   192 	end
       
   193 end
       
   194 
       
   195 function onGearDelete( Gear )
   201 function onGearDelete( Gear )
   196 	if GetGearType( Gear ) == gtTarget then
   202 	if GetGearType( Gear ) == gtTarget then
   197 		AutoSpawn() -- When a target is deleted / destroyed, spawn a new one!
   203 		AutoSpawn() -- When a target is deleted / destroyed, spawn a new one!
   198 	end
   204 	end
   199 end
   205 end