share/hedgewars/Data/Missions/Training/SniperRifle.lua
changeset 4506 37744d5c877e
parent 4493 45db8e97d282
equal deleted inserted replaced
4505:4a8f87eb67cb 4506:37744d5c877e
     6 -- It's also possible to place a comment after some real
     6 -- It's also possible to place a comment after some real
     7 -- instruction as you see below. In short, everything
     7 -- instruction as you see below. In short, everything
     8 -- following "--" is ignored.
     8 -- following "--" is ignored.
     9 
     9 
    10 ---------------------------------------------------------------
    10 ---------------------------------------------------------------
    11 -- At first we put all text we'd like to use in some arrays.
    11 -- At first we implement the localization library using loadfile.
    12 -- This way we're able to localize the text to be shown without
    12 -- This allows us to localize strings without needing to think
    13 -- modifying other files.
    13 -- about translations.
    14 -- The language to be used is stored in the global variable
    14 -- We can use the function loc(text) to localize a string.
    15 -- 'L' that is set by the game (string).
    15 
    16 -- Text may then be accessed using "arrayname[L]".
    16 loadfile(GetDataPath() .. "Scripts/Locale.lua")()
    17 
       
    18 local caption = {
       
    19 	["en"] = "Sniper Training",
       
    20 	["de"] = "Scharfschützen-Training",
       
    21 	["es"] = "Entrenamiento con rifle francotirador",
       
    22 	["pl"] = "Trening Snajperski",
       
    23 	["pt_PT"] = "Treino com Sniper",
       
    24 	["pt_BR"] = "Treino com o Rifle Sniper",
       
    25 	["sv"] = "Prickskyttesträning",
       
    26 	["sk"] = "Tréning pre ostreľovačov"
       
    27 	-- To add other languages, just add lines similar to the
       
    28 	-- existing ones - don't forget the trailing ","!
       
    29 	}
       
    30 
       
    31 local subcaption = {
       
    32 	["en"] = "Aiming Practice",
       
    33 	["de"] = "Zielübung",
       
    34 	["es"] = "Practica tu puntería",
       
    35 	["pl"] = "Potrenuj celność",
       
    36 	["pt_PT"] = "Pratica a tua pontaria",
       
    37 	["pt_BR"] = "Pratique a sua pontaria",
       
    38 	["sv"] = "Siktesövning",
       
    39 	["sk"] = "Tréning presnosti"
       
    40 	}
       
    41 
       
    42 local goal = {
       
    43 	["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.",
       
    44 	["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.",
       
    45 	["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada.",
       
    46 	["pl"] = "Zniszcz wszystkie cele zanim upłynie czas.|W tej misji masz nieskończoną ilość amunicji.",
       
    47 	["pt_PT"] = "Destrói todos os alvos antes do tempo terminar.|Tens munições infinitas para esta missão.",
       
    48 	["pt_BR"] = "Destrua todos os alvos antes que o tempo acabe.|Você tem munição infinita para esta missão.",
       
    49 	["sv"] = "Förstör alla målen innan din tid tar slut.|Du har obegränsad ammunition för deta uppdrag",
       
    50 	["sk"] = "Zneškodnite všetky ciele pred vypršaním času.|Na túto misiu máte neobmedzené množstvo streliva."
       
    51 	}
       
    52 
       
    53 local timeout = {
       
    54 	["en"] = "Oh no! Time's up! Just try again.",
       
    55 	["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.",
       
    56 	["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?",
       
    57 	["pl"] = "Ajajaj! Koniec czasu! Spróbuj jeszcze raz.",
       
    58 	["pt_PT"] = "Oh não! Acabou o tempo! Tenta novamente.",
       
    59 	["pt_BR"] = "Oh não! O tempo acabou! Tente novamente.",
       
    60 	["sv"] = "Åh nej! Tiden är ute! Pröva igen.",
       
    61 	["sk"] = "Ale nie! Čas vypršal! Tak to skúste znovu."
       
    62 	}
       
    63 
       
    64 local success = {
       
    65 	["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.",
       
    66 	["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.",
       
    67 	["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido.",
       
    68 	["pl"] = "Gratulacje! Zniszczyłeś wszystkie cele przed upłynięciem czasu.",
       
    69 	["pt_PT"] = "Parabéns! Eliminaste todos os alvos|dentro do tempo limite.",
       
    70 	["pt_BR"] = "Parabéns! Você eliminou todos os alvos|dentro do tempo limite.",
       
    71 	["sv"] = "Grattis! Du har förstört alla målen inom den|tillåtna tidsramen.",
       
    72 	["sk"] = "Gratulujem! Zneškodnili ste všetky ciele|v stanovenom čase."
       
    73 	}
       
    74 
       
    75 local teamname = {
       
    76 	["en"] = "Sniperz",
       
    77 	["de"] = "Heckenschützen",
       
    78 	["es"] = "Fusileros",
       
    79 	["pl"] = "Snajperzy",
       
    80 	["pt_BR"] = "Franco-Atiradores",
       
    81 	["sv"] = "Prickskyttarna",
       
    82 	["sk"] = "Ostreľovači"
       
    83 	}
       
    84 
       
    85 local hogname = {
       
    86 	["en"] = "Hunter",
       
    87 	["de"] = "Jäger",
       
    88 	["es"] = "Francotirador",
       
    89 	["pl"] = "Strzelec",
       
    90 	["pt_PT"] = "Comando",
       
    91 	["pt_BR"] = "Caçador",
       
    92 	["sv"] = "Jägare",
       
    93 	["sk"] = "Lovec"
       
    94 	}
       
    95 
       
    96 -- To handle missing texts we define a small wrapper function that
       
    97 -- we'll use to retrieve text.
       
    98 local function loc(text)
       
    99 	if text == nil then return "**missing**"
       
   100 	elseif text[L] == nil then return text["en"]
       
   101 	else return text[L]
       
   102 	end
       
   103 end
       
   104 
       
   105 ---------------------------------------------------------------
       
   106 
    17 
   107 -- This variable will hold the number of destroyed targets.
    18 -- This variable will hold the number of destroyed targets.
   108 local score = 0
    19 local score = 0
   109 -- This variable represents the number of targets to destroy.
    20 -- This variable represents the number of targets to destroy.
   110 local score_goal = 31
    21 local score_goal = 31
   169 	Map = "Ropes"
    80 	Map = "Ropes"
   170 	-- The theme to be used
    81 	-- The theme to be used
   171 	Theme = "City"
    82 	Theme = "City"
   172 
    83 
   173 	-- Create the player team
    84 	-- Create the player team
   174 	AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default")
    85 	AddTeam(loc("Sniperz"), 14483456, "Simple", "Island", "Default")
   175 	-- And add a hog to it
    86 	-- And add a hog to it
   176 	player = AddHog(loc(hogname), 0, 1, "Sniper")
    87 	player = AddHog(loc("Hunter"), 0, 1, "Sniper")
   177 	SetGearPosition(player, 602, 1465)
    88 	SetGearPosition(player, 602, 1465)
   178 end
    89 end
   179 
    90 
   180 -- This function is called when the round starts
    91 -- This function is called when the round starts
   181 -- it spawns the first target that has to be destroyed.
    92 -- it spawns the first target that has to be destroyed.
   188 	-- Parameters are: caption, sub caption, description,
    99 	-- Parameters are: caption, sub caption, description,
   189 	-- extra text, icon and time to show.
   100 	-- extra text, icon and time to show.
   190 	-- A negative icon parameter (-n) represents the n-th weapon icon
   101 	-- A negative icon parameter (-n) represents the n-th weapon icon
   191 	-- A positive icon paramter (n) represents the (n+1)-th mission icon
   102 	-- A positive icon paramter (n) represents the (n+1)-th mission icon
   192 	-- A timeframe of 0 is replaced with the default time to show.
   103 	-- A timeframe of 0 is replaced with the default time to show.
   193 	ShowMission(loc(caption), loc(subcaption), loc(goal), -amSniperRifle, 0)
   104 	ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission."), -amSniperRifle, 0)
   194 end
   105 end
   195 
   106 
   196 -- This function is called every game tick.
   107 -- This function is called every game tick.
   197 -- Note that there are 1000 ticks within one second.
   108 -- Note that there are 1000 ticks within one second.
   198 -- You shouldn't try to calculate too complicated
   109 -- You shouldn't try to calculate too complicated
   213 	-- We actually check the time to be "1 ms" as it
   124 	-- We actually check the time to be "1 ms" as it
   214 	-- will be at "0 ms" right at the start of the game.
   125 	-- will be at "0 ms" right at the start of the game.
   215 	if TurnTimeLeft == 1 and score < score_goal then
   126 	if TurnTimeLeft == 1 and score < score_goal then
   216 		game_lost = true
   127 		game_lost = true
   217 		-- ... and show a short message.
   128 		-- ... and show a short message.
   218 		ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0)
   129 		ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Oh no! Time's up! Just try again."), -amSkip, 0)
   219 		-- How about killing our poor hog due to his poor performance?
   130 		-- How about killing our poor hog due to his poor performance?
   220 		SetHealth(player, 0)
   131 		SetHealth(player, 0)
   221 		-- Just to be sure set the goal time to 1 ms
   132 		-- Just to be sure set the goal time to 1 ms
   222 		time_goal = 1
   133 		time_goal = 1
   223 	end
   134 	end
   379 				spawnTarget(3480,1200)
   290 				spawnTarget(3480,1200)
   380 			end
   291 			end
   381 		else
   292 		else
   382 			if not game_lost then
   293 			if not game_lost then
   383 			-- Otherwise show that the goal was accomplished
   294 			-- Otherwise show that the goal was accomplished
   384 			ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0)
   295 			ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets|within the allowed time frame."), 0, 0)
   385 			-- Also let the hogs shout "victory!"
   296 			-- Also let the hogs shout "victory!"
   386 			PlaySound(sndVictory)
   297 			PlaySound(sndVictory)
   387 			-- Save the time left so we may keep it.
   298 			-- Save the time left so we may keep it.
   388 			time_goal = TurnTimeLeft
   299 			time_goal = TurnTimeLeft
   389 			end
   300 			end