share/hedgewars/Data/Missions/Training/Basic_Training_-_Sniper_Rifle.lua
author Wuzzy <almikes@aol.com>
Sat, 19 Nov 2016 22:17:08 +0100
changeset 11945 1e58845fa3c1
parent 11528 8826ee0afe01
permissions -rw-r--r--
Allow to ignore overwritten ammo name in GetAmmoName
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11015
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     1
-- Hedgewars SniperRifle Training
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     2
-- Scripting Example
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     3
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     4
-- Lines such as this one are comments - they are ignored
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     5
-- by the game, no matter what kind of text is in there.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     6
-- It's also possible to place a comment after some real
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     7
-- instruction as you see below. In short, everything
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     8
-- following "--" is ignored.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
     9
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    10
---------------------------------------------------------------
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    11
-- At first we implement the localization library using loadfile.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    12
-- This allows us to localize strings without needing to think
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    13
-- about translations.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    14
-- We can use the function loc(text) to localize a string.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    15
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    16
HedgewarsScriptLoad("/Scripts/Locale.lua")
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    17
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    18
-- This variable will hold the number of destroyed targets.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    19
local score = 0
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    20
-- This variable will hold the number of shots from the sniper rifle
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    21
local shots = 0
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    22
-- This variable represents the number of targets to destroy.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    23
local score_goal = 31
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    24
-- This variable controls how many milliseconds/ticks we'd
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    25
-- like to wait before we end the round once all targets
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    26
-- have been destroyed.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    27
local end_timer = 1000 -- 1000 ms = 1 s
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    28
-- This variable is set to true if the game is lost (i.e.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    29
-- time runs out).
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    30
local game_lost = false
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    31
-- This variable will point to the hog's gear
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    32
local player = nil
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    33
-- This variable will grab the time left at the end of the round
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    34
local time_goal = 0
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    35
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    36
local target = nil
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    37
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    38
local last_hit_time = 0
11528
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
    39
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
    40
local cinematic = false
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
    41
11015
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    42
-- This is a custom function to make it easier to
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    43
-- spawn more targets with just one line of code
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    44
-- You may define as many custom functions as you
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    45
-- like.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    46
function spawnTarget(x, y)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    47
	-- add a new target gear
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    48
	target = AddGear(x, y, gtTarget, 0, 0, 0, 0)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    49
	-- have the camera move to the target so the player knows where it is
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    50
	FollowGear(target)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    51
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    52
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    53
function blowUp(x, y)
11528
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
    54
    if cinematic == false then
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
    55
        cinematic = true
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
    56
        SetCinematicMode(true)
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
    57
    end
11015
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    58
	-- adds some TNT
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    59
	gear = AddGear(x, y, gtDynamite, 0, 0, 0, 0)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    60
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    61
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    62
function onNewTurn()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    63
	SetWeapon(amSniperRifle)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    64
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    65
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    66
-- This function is called before the game loads its
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    67
-- resources.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    68
-- It's one of the predefined function names that will
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    69
-- be called by the game. They give you entry points
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    70
-- where you're able to call your own code using either
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    71
-- provided instructions or custom functions.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    72
function onGameInit()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    73
	-- At first we have to overwrite/set some global variables
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    74
	-- that define the map, the game has to load, as well as
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    75
	-- other things such as the game rules to use, etc.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    76
	-- Things we don't modify here will use their default values.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    77
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    78
	-- The base number for the random number generator
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    79
	Seed = 0
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    80
	-- Game settings and rules
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    81
	GameFlags = gfMultiWeapon + gfOneClanMode + gfArtillery
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    82
	-- The time the player has to move each round (in ms)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    83
	TurnTime = 150000
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    84
	-- The frequency of crate drops
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    85
	CaseFreq = 0
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    86
	-- The number of mines being placed
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    87
	MinesNum = 0
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    88
	-- The number of explosives being placed
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    89
	Explosives = 0
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    90
	-- The delay between each round
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    91
	Delay = 0
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    92
	-- The map to be played
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    93
	Map = "Ropes"
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    94
	-- The theme to be used
11017
16c47a5573e4 change theme used by sniper training, for performance reasons
sheepluva
parents: 11015
diff changeset
    95
	Theme = "Golf"
11015
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    96
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    97
	-- Create the player team
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    98
	AddTeam(loc("Sniperz"), 14483456, "Simple", "Island", "Default")
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
    99
	-- And add a hog to it
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   100
	player = AddHog(loc("Hunter"), 0, 1, "Sniper")
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   101
	SetGearPosition(player, 602, 1465)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   102
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   103
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   104
-- This function is called when the round starts
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   105
-- it spawns the first target that has to be destroyed.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   106
-- In addition it shows the scenario goal(s).
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   107
function onGameStart()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   108
	-- Disable graph in stats screen
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   109
	SendHealthStatsOff()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   110
	-- Spawn the first target.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   111
	spawnTarget(860,1020)
11017
16c47a5573e4 change theme used by sniper training, for performance reasons
sheepluva
parents: 11015
diff changeset
   112
11015
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   113
	-- Show some nice mission goals.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   114
	-- Parameters are: caption, sub caption, description,
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   115
	-- extra text, icon and time to show.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   116
	-- A negative icon parameter (-n) represents the n-th weapon icon
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   117
	-- A positive icon paramter (n) represents the (n+1)-th mission icon
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   118
	-- A timeframe of 0 is replaced with the default time to show.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   119
	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)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   120
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   121
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   122
-- This function is called every game tick.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   123
-- Note that there are 1000 ticks within one second.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   124
-- You shouldn't try to calculate too complicated
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   125
-- code here as this might slow down your game.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   126
function onGameTick20()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   127
	if game_lost then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   128
		return
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   129
	end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   130
	-- after a target is destroyed, show hog, then target
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   131
	if (target ~= nil) and (TurnTimeLeft + 1300 < last_hit_time) then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   132
		-- move camera to the target
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   133
		FollowGear(target)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   134
	elseif TurnTimeLeft + 300 < last_hit_time then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   135
		-- move camera to the hog
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   136
		FollowGear(player)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   137
	end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   138
	-- If time's up, set the game to be lost.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   139
	-- We actually check the time to be "1 ms" as it
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   140
	-- will be at "0 ms" right at the start of the game.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   141
	if TurnTimeLeft < 40 and TurnTimeLeft > 0 and score < score_goal and game_lost == false then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   142
		game_lost = true
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   143
		-- ... and show a short message.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   144
		AddCaption(loc("Time's up!"))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   145
		ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Oh no! Time's up! Just try again."), -amSkip, 0)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   146
		-- and generate the stats and go to the stats screen
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   147
		generateStats()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   148
		EndGame()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   149
		-- Just to be sure set the goal time to 1 ms
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   150
		time_goal = 1
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   151
	end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   152
	-- If the goal is reached or we've lost ...
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   153
	if score == score_goal or game_lost then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   154
		-- ... check to see if the time we'd like to
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   155
		-- wait has passed and then ...
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   156
		if end_timer == 0 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   157
			-- ... end the game ...
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   158
			generateStats()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   159
			EndGame()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   160
		else
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   161
			-- ... or just lower the timer by 1.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   162
			-- Reset the time left to stop the timer
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   163
			TurnTimeLeft = time_goal
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   164
		end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   165
        end_timer = end_timer - 20
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   166
	end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   167
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   168
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   169
-- This function is called when the game is initialized
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   170
-- to request the available ammo and probabilities
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   171
function onAmmoStoreInit()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   172
	-- add an unlimited supply of shotgun ammo
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   173
	SetAmmo(amSniperRifle, 9, 0, 0, 0)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   174
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   175
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   176
-- This function is called when a new gear is added.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   177
-- We use it to count the number of shots, which we
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   178
-- in turn use to calculate the final score and stats
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   179
function onGearAdd(gear)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   180
	if GetGearType(gear) == gtSniperRifleShot then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   181
		shots = shots + 1
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   182
	end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   183
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   184
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   185
-- This function is called before a gear is destroyed.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   186
-- We use it to count the number of targets destroyed.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   187
function onGearDelete(gear)
11528
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   188
	local gt = GetGearType(gear)
11017
16c47a5573e4 change theme used by sniper training, for performance reasons
sheepluva
parents: 11015
diff changeset
   189
11528
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   190
	if gt == gtCase then
11015
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   191
		game_lost = true
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   192
		return
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   193
	end
11017
16c47a5573e4 change theme used by sniper training, for performance reasons
sheepluva
parents: 11015
diff changeset
   194
11528
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   195
	if (gt == gtDynamite) and cinematic then
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   196
		cinematic = false
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   197
		SetCinematicMode(false)
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   198
		return
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   199
	end
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   200
8826ee0afe01 tweak sniper training
sheepluva
parents: 11017
diff changeset
   201
	if gt == gtTarget then
11015
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   202
		-- remember when the target was hit for adjusting the camera
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   203
		last_hit_time = TurnTimeLeft
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   204
		-- Add one point to our score/counter
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   205
		score = score + 1
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   206
		-- If we haven't reached the goal ...
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   207
		if score < score_goal then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   208
			-- ... spawn another target.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   209
			if score == 1 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   210
				spawnTarget(1520,1350)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   211
			elseif score == 2 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   212
				spawnTarget(1730,1040)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   213
			elseif score == 3 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   214
				spawnTarget(2080,780)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   215
			elseif score == 4 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   216
				AddCaption(loc("Good so far!") .. " " .. loc("Keep it up!"));
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   217
				blowUp(1730,1226)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   218
				blowUp(1440,1595)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   219
				blowUp(1527,1575)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   220
				blowUp(1614,1595)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   221
				blowUp(1420,1675)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   222
				blowUp(1527,1675)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   223
				blowUp(1634,1675)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   224
				blowUp(1440,1755)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   225
				blowUp(1527,1775)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   226
				blowUp(1614,1755)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   227
				spawnTarget(1527,1667)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   228
			elseif score == 5 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   229
				spawnTarget(1527,1667)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   230
			elseif score == 6 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   231
				spawnTarget(2175,1300)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   232
			elseif score == 7 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   233
				spawnTarget(2250,940)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   234
			elseif score == 8 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   235
				spawnTarget(2665,1540)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   236
			elseif score == 9 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   237
				spawnTarget(3040,1160)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   238
			elseif score == 10 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   239
				spawnTarget(2930,1500)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   240
			elseif score == 11 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   241
				AddCaption(loc("This one's tricky."));
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   242
				spawnTarget(700,720)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   243
			elseif score == 12 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   244
				AddCaption(loc("Well done."));
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   245
				blowUp(914,1222)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   246
				blowUp(1050,1222)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   247
				blowUp(1160,1008)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   248
				blowUp(1160,1093)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   249
				blowUp(1160,1188)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   250
				blowUp(375,911)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   251
				blowUp(510,911)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   252
				blowUp(640,911)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   253
				blowUp(780,911)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   254
				blowUp(920,911)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   255
				blowUp(1060,913)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   256
				blowUp(1198,913)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   257
				spawnTarget(1200,730)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   258
			elseif score == 13 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   259
				spawnTarget(1200,830)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   260
			elseif score == 14 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   261
				spawnTarget(1430,450)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   262
			elseif score == 15 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   263
				spawnTarget(796,240)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   264
			elseif score == 16 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   265
				spawnTarget(300,10)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   266
			elseif score == 17 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   267
				spawnTarget(2080,820)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   268
			elseif score == 18 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   269
				AddCaption(loc("Demolition is fun!"));
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   270
				blowUp(2110,920)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   271
				blowUp(2210,920)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   272
				blowUp(2200,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   273
				blowUp(2300,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   274
				blowUp(2300,400)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   275
				blowUp(2300,500)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   276
				blowUp(2300,600)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   277
				blowUp(2300,700)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   278
				blowUp(2300,800)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   279
				blowUp(2300,900)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   280
				blowUp(2401,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   281
				blowUp(2532,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   282
				blowUp(2663,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   283
				spawnTarget(2300,760)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   284
			elseif score == 19 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   285
				spawnTarget(2300,760)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   286
			elseif score == 20 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   287
				spawnTarget(2738,190)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   288
			elseif score == 21 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   289
				spawnTarget(2590,-100)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   290
			elseif score == 22 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   291
				AddCaption(loc("Will this ever end?"));
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   292
				blowUp(2790,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   293
				blowUp(2930,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   294
				blowUp(3060,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   295
				blowUp(3190,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   296
				blowUp(3310,305)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   297
				blowUp(3393,613)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   298
				blowUp(2805,370)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   299
				blowUp(2805,500)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   300
				blowUp(2805,630)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   301
				blowUp(2805,760)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   302
				blowUp(2805,890)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   303
				blowUp(3258,370)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   304
				blowUp(3258,475)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   305
				blowUp(3264,575)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   306
				spawnTarget(3230,240)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   307
			elseif score == 23 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   308
				spawnTarget(3230,290)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   309
			elseif score == 24 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   310
				spawnTarget(3670,250)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   311
			elseif score == 25 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   312
				spawnTarget(2620,-100)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   313
			elseif score == 26 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   314
				spawnTarget(2870,300)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   315
			elseif score == 27 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   316
				spawnTarget(3850,900)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   317
			elseif score == 28 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   318
				spawnTarget(3780,300)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   319
			elseif score == 29 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   320
				spawnTarget(3670,0)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   321
			elseif score == 30 then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   322
				AddCaption(loc("Last Target!"));
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   323
				spawnTarget(3480,1200)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   324
			end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   325
		else
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   326
			if not game_lost then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   327
			-- Otherwise show that the goal was accomplished
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   328
			ShowMission(loc("Sniper Training"), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets|within the allowed time frame."), 0, 0)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   329
			-- Also let the hogs shout "victory!"
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   330
			PlaySound(sndVictory)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   331
			-- Save the time left so we may keep it.
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   332
			time_goal = TurnTimeLeft
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   333
			end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   334
		end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   335
	end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   336
end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   337
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   338
-- This function calculates the final score of the player and provides some texts and
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   339
-- data for the final stats screen
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   340
function generateStats()
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   341
	local accuracy = (score/shots)*100
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   342
	local end_score_targets = (score * 200)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   343
	local end_score_overall
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   344
	if not game_lost then
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   345
		local end_score_time = math.ceil(time_goal/5)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   346
		local end_score_accuracy = math.ceil(accuracy * 100)
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   347
		end_score_overall = end_score_time + end_score_targets + end_score_accuracy
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   348
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   349
		SendStat(siGameResult, loc("You have successfully finished the sniper rifle training!"))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   350
		SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   351
		SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   352
		SendStat(siCustomAchievement, string.format(loc("Accuracy bonus: +%d points"), end_score_accuracy))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   353
		SendStat(siCustomAchievement, string.format(loc("You had %.2fs remaining on the clock (+%d points)."), (time_goal/1000), end_score_time))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   354
	else
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   355
		SendStat(siGameResult, loc("You lose!"))
11017
16c47a5573e4 change theme used by sniper training, for performance reasons
sheepluva
parents: 11015
diff changeset
   356
11015
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   357
		SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), score, score_goal, end_score_targets))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   358
		SendStat(siCustomAchievement, string.format(loc("You have made %d shots."), shots))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   359
		end_score_overall = end_score_targets
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   360
	end
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   361
	SendStat(siPlayerKills, tostring(end_score_overall), loc("Sniperz"))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   362
	SendStat(siPointType, loc("points"))
7a905f0070ce CRLF purge
nemo
parents: 10655
diff changeset
   363
end