share/hedgewars/Data/Missions/Training/SniperRifle.lua
changeset 3271 0405e07ca44b
child 3273 d398b7bb3ecd
equal deleted inserted replaced
3270:9bd8fb1707b9 3271:0405e07ca44b
       
     1 -- Hedgewars SniperRifle Training
       
     2 -- Scripting Example
       
     3 
       
     4 -- Lines such as this one are comments - they are ignored
       
     5 -- by the game, no matter what kind of text is in there.
       
     6 -- It's also possible to place a comment after some real
       
     7 -- instruction as you see below. In short, everything
       
     8 -- following "--" is ignored.
       
     9 
       
    10 ---------------------------------------------------------------
       
    11 -- At first we put all text we'd like to use in some arrays.
       
    12 -- This way we're able to localize the text to be shown without
       
    13 -- modifying other files.
       
    14 -- The language to be used is stored in the global variable
       
    15 -- 'L' that is set by the game (string).
       
    16 -- Text may then be accessed using "arrayname[L]".
       
    17 
       
    18 local caption = {
       
    19 	["en"] = "Sniper Training",
       
    20 	["de"] = "Scharfschützen-Training"
       
    21 	-- To add other languages, just add lines similar to the
       
    22 	-- existing ones - don't forget the trailing ","!
       
    23 	}
       
    24 
       
    25 local subcaption = {
       
    26 	["en"] = "Aiming Practice",
       
    27 	["de"] = "Zielübung",
       
    28 	["es"] = "Practica tu puntería",
       
    29 	["pl"] = "Potrenuj celność",
       
    30 	["pt_PT"] = "Pratica a tua pontaria"
       
    31 	}
       
    32 
       
    33 local goal = {
       
    34 	["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.",
       
    35 	["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.",
       
    36 	["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada.",
       
    37 	["pl"] = "Zniszcz wszystkie cele zanim upłynie czas.|W tej misji masz nieskończoną ilość amunicji.",
       
    38 	["pt_PT"] = "Destrói todos os alvos antes do tempo terminar.|Tens munições infinitas para esta missão."
       
    39 	}
       
    40 
       
    41 local timeout = {
       
    42 	["en"] = "Oh no! Time's up! Just try again.",
       
    43 	["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.",
       
    44 	["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?",
       
    45 	["pl"] = "Ajajaj! Koniec czasu! Spróbuj jeszcze raz.",
       
    46 	["pt_PT"] = "Oh não! Acabou o tempo! Tenta novamente."
       
    47 	}
       
    48 
       
    49 local success = {
       
    50 	["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.",
       
    51 	["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.",
       
    52 	["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido.",
       
    53 	["pl"] = "Gratulacje! Zniszczyłeś wszystkie cele przed upłynięciem czasu.",
       
    54 	["pt_PT"] = "Parabéns! Eliminaste todos os alvos|dentro do tempo limite."
       
    55 	}
       
    56 
       
    57 local teamname = {
       
    58 	["en"] = "Sniperz",
       
    59 	["de"] = "Heckenschützen"
       
    60 	}
       
    61 
       
    62 local hogname = {
       
    63 	["en"] = "Hunter",
       
    64 	["de"] = "Jäger",
       
    65 	["es"] = "Cazador",
       
    66 	["pl"] = "Strzelec",
       
    67 	["pt_PT"] = "Comando"
       
    68 	}
       
    69 
       
    70 -- To handle missing texts we define a small wrapper function that
       
    71 -- we'll use to retrieve text.
       
    72 local function loc(text)
       
    73 	if text == nil then return "**missing**"
       
    74 	elseif text[L] == nil then return text["en"]
       
    75 	else return text[L]
       
    76 	end
       
    77 end
       
    78 
       
    79 ---------------------------------------------------------------
       
    80 
       
    81 -- This variable will hold the number of destroyed targets.
       
    82 local score = 0
       
    83 -- This variable represents the number of targets to destroy.
       
    84 local score_goal = 31
       
    85 -- This variable controls how many milliseconds/ticks we'd
       
    86 -- like to wait before we end the round once all targets
       
    87 -- have been destroyed.
       
    88 local end_timer = 5000 -- 5000 ms = 5 s
       
    89 -- This variable is set to true if the game is lost (i.e.
       
    90 -- time runs out).
       
    91 local game_lost = false
       
    92 -- This variable will point to the hog's gear
       
    93 local player = nil
       
    94 -- This variable will grab the time left at the end of the round
       
    95 local time_goal = 0
       
    96 
       
    97 local target = nil
       
    98 
       
    99 local last_hit_time = 0
       
   100 -- This is a custom function to make it easier to
       
   101 -- spawn more targets with just one line of code
       
   102 -- You may define as many custom functions as you
       
   103 -- like.
       
   104 function spawnTarget(x, y)
       
   105 	-- add a new target gear
       
   106 	target = AddGear(x, y, gtTarget, 0, 0, 0, 0)
       
   107     -- have the camera move to the target so the player knows where it is
       
   108     FollowGear(target)
       
   109 end
       
   110 
       
   111 function blowUp(x, y)
       
   112 	-- adds some TNT
       
   113 	gear = AddGear(x, y, gtDynamite, 0, 0, 0, 0)
       
   114 end
       
   115 
       
   116 -- This function is called before the game loads its
       
   117 -- resources.
       
   118 -- It's one of the predefined function names that will
       
   119 -- be called by the game. They give you entry points
       
   120 -- where you're able to call your own code using either
       
   121 -- provided instructions or custom functions.
       
   122 function onGameInit()
       
   123 	-- At first we have to overwrite/set some global variables
       
   124 	-- that define the map, the game has to load, as well as
       
   125 	-- other things such as the game rules to use, etc.
       
   126 	-- Things we don't modify here will use their default values.
       
   127 
       
   128 	-- The base number for the random number generator
       
   129 	Seed = 0
       
   130 	-- Game settings and rules
       
   131 	GameFlags = gfMultiWeapon + gfOneClanMode + gfArtillery
       
   132 	-- The time the player has to move each round (in ms)
       
   133 	TurnTime = 150000
       
   134 	-- The frequency of crate drops
       
   135 	CaseFreq = 0
       
   136 	-- The number of mines being placed
       
   137 	LandAdds = 0
       
   138 	-- The number of explosives being placed
       
   139 	Explosives = 0
       
   140 	-- The delay between each round
       
   141 	Delay = 0
       
   142 	-- The map to be played
       
   143 	Map = "Ropes"
       
   144 	-- The theme to be used
       
   145 	Theme = "City"
       
   146 
       
   147 	-- Create the player team
       
   148 	AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default")
       
   149 	-- And add a hog to it
       
   150 	player = AddHog(loc(hogname), 0, 1, "Sniper")
       
   151 	SetGearPosition(player, 602, 1465);
       
   152 end
       
   153 
       
   154 -- This function is called when the round starts
       
   155 -- it spawns the first target that has to be destroyed.
       
   156 -- In addition it shows the scenario goal(s).
       
   157 function onGameStart()
       
   158 	-- Spawn the first target.
       
   159 	spawnTarget(860,1020)
       
   160 	
       
   161 	-- Show some nice mission goals.
       
   162 	-- Parameters are: caption, sub caption, description,
       
   163 	-- extra text, icon and time to show.
       
   164 	-- A negative icon parameter (-n) represents the n-th weapon icon
       
   165 	-- A positive icon paramter (n) represents the (n+1)-th mission icon
       
   166 	-- A timeframe of 0 is replaced with the default time to show.
       
   167 	ShowMission(loc(caption), loc(subcaption), loc(goal), -amSniperRifle, 0);
       
   168 end
       
   169 
       
   170 -- This function is called every game tick.
       
   171 -- Note that there are 1000 ticks within one second.
       
   172 -- You shouldn't try to calculate too complicated
       
   173 -- code here as this might slow down your game.
       
   174 function onGameTick()
       
   175     if game_lost then
       
   176         return
       
   177     end
       
   178     -- after a target is destroyed, show hog, then target
       
   179     if (target ~= nil) and (TurnTimeLeft + 1300 < last_hit_time) then
       
   180         -- move camera to the target
       
   181         FollowGear(target)
       
   182     elseif TurnTimeLeft + 300 < last_hit_time then
       
   183         -- move camera to the hog
       
   184         FollowGear(player)
       
   185     end
       
   186 	-- If time's up, set the game to be lost.
       
   187 	-- We actually check the time to be "1 ms" as it
       
   188 	-- will be at "0 ms" right at the start of the game.
       
   189 	if TurnTimeLeft == 1 and score < score_goal then
       
   190 		game_lost = true
       
   191 		-- ... and show a short message.
       
   192 		ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0);
       
   193 		-- How about killing our poor hog due to his poor performance?
       
   194 		SetHealth(player, 0);
       
   195         TurnTimeLeft = 0
       
   196 		-- Just to be sure set the goal time to 1 ms
       
   197 		time_goal = 1
       
   198 	end
       
   199 	-- If the goal is reached or we've lost ...
       
   200 	if score == score_goal or game_lost then
       
   201 		-- ... check to see if the time we'd like to
       
   202 		-- wait has passed and then ...
       
   203 		if end_timer == 0 then
       
   204 			-- ... end the game ...
       
   205 			EndGame()
       
   206 		else
       
   207 			-- ... or just lower the timer by 1.
       
   208 			end_timer = end_timer - 1
       
   209 			-- Reset the time left to stop the timer
       
   210 			TurnTimeLeft = time_goal
       
   211 		end
       
   212 	end
       
   213 end
       
   214 
       
   215 -- This function is called when the game is initialized
       
   216 -- to request the available ammo and probabilities
       
   217 function onAmmoStoreInit()
       
   218 	-- add an unlimited supply of shotgun ammo
       
   219 	SetAmmo(amSniperRifle, 9, 0, 0)
       
   220 end
       
   221 
       
   222 -- This function is called when a new gear is added.
       
   223 -- We don't need it for this training, so we can
       
   224 -- keep it empty.
       
   225 function onGearAdd(gear)
       
   226 end
       
   227 
       
   228 -- This function is called before a gear is destroyed.
       
   229 -- We use it to count the number of targets destroyed.
       
   230 function onGearDelete(gear)
       
   231     
       
   232     if GetGearType(gear) == gtCase then
       
   233         game_lost = true
       
   234         return
       
   235     end
       
   236 	
       
   237 	if (GetGearType(gear) == gtTarget) then
       
   238         -- remember when the target was hit for adjusting the camera
       
   239         last_hit_time = TurnTimeLeft
       
   240 		-- Add one point to our score/counter
       
   241 		score = score + 1
       
   242 		-- If we haven't reached the goal ...
       
   243 		if score < score_goal then
       
   244 			-- ... spawn another target.
       
   245             if score == 1 then
       
   246                 spawnTarget(1520,1350)
       
   247             elseif score == 2 then
       
   248                 spawnTarget(1730,1040)
       
   249             elseif score == 3 then
       
   250                 spawnTarget(2080,780)
       
   251             elseif score == 4 then
       
   252                 blowUp(1730,1226)
       
   253                 blowUp(1440,1595)
       
   254                 blowUp(1527,1575)
       
   255                 blowUp(1614,1595)
       
   256                 blowUp(1420,1675)
       
   257                 blowUp(1527,1675)
       
   258                 blowUp(1634,1675)
       
   259                 blowUp(1440,1755)
       
   260                 blowUp(1527,1775)
       
   261                 blowUp(1614,1755)
       
   262                 spawnTarget(1527,1667)
       
   263             elseif score == 5 then
       
   264                 spawnTarget(1527,1667)
       
   265             elseif score == 6 then
       
   266                 spawnTarget(2175,1300)
       
   267             elseif score == 7 then
       
   268                 spawnTarget(2250,940)
       
   269             elseif score == 8 then
       
   270                 spawnTarget(2665,1540)
       
   271             elseif score == 9 then
       
   272                 spawnTarget(3040,1160)
       
   273             elseif score == 10 then
       
   274                 spawnTarget(2930,1500)
       
   275             elseif score == 11 then
       
   276                 spawnTarget(700,720)
       
   277             elseif score == 12 then
       
   278                 blowUp(914,1222)
       
   279                 blowUp(1050,1222)
       
   280                 blowUp(1160,1008)
       
   281                 blowUp(1160,1093)
       
   282                 blowUp(1160,1188)
       
   283                 blowUp(375,911)
       
   284                 blowUp(510,911)
       
   285                 blowUp(640,911)
       
   286                 blowUp(780,911)
       
   287                 blowUp(920,911)
       
   288                 blowUp(1060,913)
       
   289                 blowUp(1198,913)
       
   290                 spawnTarget(1200,730)
       
   291             elseif score == 13 then
       
   292                 spawnTarget(1200,830)
       
   293             elseif score == 14 then
       
   294                 spawnTarget(1430,450)
       
   295             elseif score == 15 then
       
   296                 spawnTarget(796,240)
       
   297             elseif score == 16 then
       
   298                 spawnTarget(300,10)
       
   299             elseif score == 17 then
       
   300                 spawnTarget(2080,820)
       
   301             elseif score == 18 then
       
   302                 blowUp(2110,920)
       
   303                 blowUp(2210,920)
       
   304                 blowUp(2200,305)
       
   305                 blowUp(2300,305)
       
   306                 blowUp(2300,400)
       
   307                 blowUp(2300,500)
       
   308                 blowUp(2300,600)
       
   309                 blowUp(2300,700)
       
   310                 blowUp(2300,800)
       
   311                 blowUp(2300,900)
       
   312                 blowUp(2401,305)
       
   313                 blowUp(2532,305)
       
   314                 blowUp(2663,305)
       
   315                 spawnTarget(2300,760)
       
   316             elseif score == 19 then
       
   317                 spawnTarget(2300,760)
       
   318             elseif score == 20 then
       
   319                 spawnTarget(2738,190)
       
   320             elseif score == 21 then
       
   321                 spawnTarget(2590,-100)
       
   322             elseif score == 22 then
       
   323                 blowUp(2790,305)
       
   324                 blowUp(2930,305)
       
   325                 blowUp(3060,305)
       
   326                 blowUp(3190,305)
       
   327                 blowUp(3310,305)
       
   328                 blowUp(3393,613)
       
   329                 blowUp(2805,370)
       
   330                 blowUp(2805,500)
       
   331                 blowUp(2805,630)
       
   332                 blowUp(2805,760)
       
   333                 blowUp(2805,890)
       
   334                 blowUp(2700,890)
       
   335                 blowUp(3258,370)
       
   336                 blowUp(3258,475)
       
   337                 blowUp(3264,575)
       
   338                 spawnTarget(3230,240)
       
   339             elseif score == 23 then
       
   340                 spawnTarget(3230,290)
       
   341             elseif score == 24 then
       
   342                 spawnTarget(3670,250)
       
   343             elseif score == 25 then
       
   344                 spawnTarget(2620,-100)
       
   345             elseif score == 26 then
       
   346                 spawnTarget(2870,300)
       
   347             elseif score == 27 then
       
   348                 spawnTarget(3850,900)
       
   349             elseif score == 28 then
       
   350                 spawnTarget(3780,300)
       
   351             elseif score == 29 then
       
   352                 spawnTarget(3670,0)
       
   353             elseif score == 30 then
       
   354                 spawnTarget(3480,1200)
       
   355             end
       
   356 		else
       
   357 			if not game_lost then
       
   358 			-- Otherwise show that the goal was accomplished
       
   359 			ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0);
       
   360 			-- Also let the hogs shout "victory!"
       
   361 			PlaySound(sndVictory)
       
   362 			-- Save the time left so we may keep it.
       
   363 			time_goal = TurnTimeLeft
       
   364 			end
       
   365 		end
       
   366 	end
       
   367 end