share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua
author mikade <redgrinner@gmail.com>
Thu, 11 Dec 2014 20:38:03 +0900
changeset 10655 1c85a442bd56
parent 10289 c3a77ff02a23
child 11015 7a905f0070ce
permissions -rw-r--r--
Wuzzy's changes to stats for some of the training missions.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10655
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     1
-- Hedgewars Bazooka Training
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     2
-- Scripting Example
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     3
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     4
-- Lines such as this one are comments - they are ignored
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     5
-- by the game, no matter what kind of text is in there.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     6
-- It's also possible to place a comment after some real
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     7
-- instruction as you see below. In short, everything
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     8
-- following "--" is ignored.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
     9
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    10
---------------------------------------------------------------
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    11
-- At first we implement the localization library using loadfile.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    12
-- This allows us to localize strings without needing to think
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    13
-- about translations.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    14
-- We can use the function loc(text) to localize a string.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    15
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    16
HedgewarsScriptLoad("/Scripts/Locale.lua")
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    17
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    18
-- This variable will hold the number of destroyed targets.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    19
local score = 0
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    20
-- This variable represents the number of targets to destroy.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    21
local score_goal = 5
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    22
-- This variable controls how many milliseconds/ticks we'd
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    23
-- like to wait before we end the round once all targets
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    24
-- have been destroyed.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    25
local end_timer = 1000 -- 1000 ms = 1 s
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    26
-- This variable is set to true if the game is lost (i.e.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    27
-- time runs out).
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    28
local game_lost = false
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    29
-- This variable will point to the hog's gear
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    30
local player = nil
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    31
-- This variable will grab the time left at the end of the round
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    32
local time_goal = 0
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    33
-- This variable stores the number of bazooka shots
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    34
local shots = 0
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    35
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    36
-- This is a custom function to make it easier to
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    37
-- spawn more targets with just one line of code
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    38
-- You may define as many custom functions as you
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    39
-- like.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    40
function spawnTarget()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    41
	-- add a new target gear
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    42
	gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    43
	
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    44
	-- move it to a random position within 0 and
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    45
	-- LAND_WIDTH - the width of the map
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    46
	FindPlace(gear, true, 0, LAND_WIDTH)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    47
	
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    48
	-- move the target to a higher vertical position
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    49
	-- to ensure it's not somewhere down below
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    50
	x, y = GetGearPosition(gear)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    51
	SetGearPosition(gear, x, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    52
end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    53
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    54
-- This function is called before the game loads its
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    55
-- resources.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    56
-- It's one of the predefined function names that will
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    57
-- be called by the game. They give you entry points
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    58
-- where you're able to call your own code using either
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    59
-- provided instructions or custom functions.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    60
function onGameInit()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    61
	-- At first we have to overwrite/set some global variables
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    62
	-- that define the map, the game has to load, as well as
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    63
	-- other things such as the game rules to use, etc.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    64
	-- Things we don't modify here will use their default values.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    65
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    66
	-- The base number for the random number generator
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    67
	Seed = 1
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    68
	-- Game settings and rules
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    69
    EnableGameFlags(gfMultiWeapon, gfOneClanMode, gfSolidLand)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    70
    -- Uncommenting this wouldn't do anything
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    71
    --EnableGameFlags(gfMultiWeapon, gfOneClanMode, gfSolidLand)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    72
    -- Neither this
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    73
    --DisableGameFlags(gfArtillery)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    74
    -- Uncommenting this would make the terrain damageable
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    75
    --DisableGameFlags(gfSolidLand)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    76
    -- Uncommenting this would remove all flags set previously
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    77
    --ClearGameFlags()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    78
	-- The time the player has to move each round (in ms)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    79
	TurnTime = 60000
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    80
	-- The frequency of crate drops
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    81
	CaseFreq = 0
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    82
	-- The number of mines being placed
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    83
	MinesNum = 0
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    84
	-- The number of explosives being placed
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    85
	Explosives = 0
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    86
	-- The delay between each round
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    87
	Delay = 0
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    88
	-- The map to be played
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    89
	Map = "Bamboo"
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    90
	-- The theme to be used
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    91
	Theme = "Bamboo"
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    92
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    93
	-- Create the player team
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    94
	AddTeam(loc("'Zooka Team"), 14483456, "Simple", "Island", "Default")
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    95
	-- And add a hog to it
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    96
	player = AddHog(loc("Hunter"), 0, 1, "NoHat")
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    97
	SetGearPosition(player, 936, 136)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    98
end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
    99
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   100
-- This function is called when the round starts
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   101
-- it spawns the first target that has to be destroyed.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   102
-- In addition it shows the scenario goal(s).
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   103
function onGameStart()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   104
	-- Disable the graph in the stats screen, we don't need it
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   105
	SendHealthStatsOff()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   106
	-- Spawn the first target.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   107
	spawnTarget()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   108
	
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   109
	-- Show some nice mission goals.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   110
	-- Parameters are: caption, sub caption, description,
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   111
	-- extra text, icon and time to show.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   112
	-- A negative icon parameter (-n) represents the n-th weapon icon
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   113
	-- A positive icon paramter (n) represents the (n+1)-th mission icon
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   114
	-- A timeframe of 0 is replaced with the default time to show.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   115
	ShowMission(loc("Bazooka Training"), loc("Aiming Practice"), loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission."), -amBazooka, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   116
end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   117
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   118
function onNewTurn()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   119
	SetWeapon(amBazooka)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   120
end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   121
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   122
-- This function is called every game tick.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   123
-- Note that there are 1000 ticks within one second.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   124
-- You shouldn't try to calculate too complicated
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   125
-- code here as this might slow down your game.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   126
function onGameTick20()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   127
	-- If time's up, set the game to be lost.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   128
	-- We actually check the time to be "1 ms" as it
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   129
	-- will be at "0 ms" right at the start of the game.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   130
	if TurnTimeLeft < 40 and TurnTimeLeft > 0 and score < score_goal and not game_lost then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   131
		game_lost = true
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   132
		-- ... and show a short message.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   133
		ShowMission(loc("Bazooka Training"), loc("Aiming Practice"), loc("Oh no! Time's up! Just try again."), -amSkip, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   134
		-- How about killing our poor hog due to his poor performance?
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   135
		SetHealth(player, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   136
		-- Just to be sure set the goal time to 1 ms
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   137
		time_goal = 1
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   138
	end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   139
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   140
	if band(GetState(player), gstDrowning) == gstDrowning and game_lost == false and score < score_goal then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   141
		game_lost = true
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   142
		time_goal = 1
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   143
		AddCaption(loc("You lose!"), 0xFFFFFFFF, capgrpGameState)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   144
		ShowMission(loc("Bazooka Training"), loc("Aiming practice"), loc("Oh no! You failed! Just try again."), -amSkip, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   145
	end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   146
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   147
	-- If the goal is reached or we've lost ...
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   148
	if score == score_goal or game_lost then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   149
		-- ... check to see if the time we'd like to
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   150
		-- wait has passed and then ...
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   151
		if end_timer == 0 then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   152
			-- Let’s create some stats for the stats screen!
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   153
			-- We will expose the number of hit targets hit, launched bazooka and the accuracy
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   154
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   155
			SendStat(siPointType, loc("hits"))
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   156
			SendStat(siPlayerKills, tostring(score), loc("'Zooka Team"))
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   157
			SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets."), score, score_goal))
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   158
			SendStat(siCustomAchievement, string.format(loc("You have launched %d bazookas."), shots))
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   159
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   160
			-- We must avoid a division by zero
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   161
			if(shots > 0) then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   162
				SendStat(siCustomAchievement, string.format(loc("Your accuracy was %.1f%%."), (score/shots)*100))
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   163
			end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   164
			if score == score_goal then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   165
				SendStat(siGameResult, "You have finished the bazooka training!")
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   166
				SendStat(siCustomAchievement, string.format(loc("%.1f seconds were remaining."), (time_goal/1000), math.ceil(time_goal/12)))
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   167
			end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   168
			if game_lost then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   169
				SendStat(siGameResult, "You lose!")
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   170
			end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   171
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   172
			-- Finally we end the game ...
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   173
			EndGame()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   174
		else
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   175
			-- ... or just lower the timer by 20ms.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   176
			-- Reset the time left to stop the timer
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   177
			TurnTimeLeft = time_goal
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   178
		end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   179
        end_timer = end_timer - 20
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   180
	end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   181
end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   182
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   183
-- This function is called when the game is initialized
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   184
-- to request the available ammo and probabilities
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   185
function onAmmoStoreInit()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   186
	-- add an unlimited supply of bazooka ammo
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   187
	SetAmmo(amBazooka, 9, 0, 0, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   188
end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   189
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   190
-- This function is called when a new gear is added.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   191
-- We don't need it for this training, so we can
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   192
-- keep it empty.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   193
-- function onGearAdd(gear)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   194
-- end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   195
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   196
-- This function is called before a gear is destroyed.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   197
-- We use it to count the number of targets destroyed.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   198
function onGearDelete(gear)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   199
	-- We're only interested in target gears.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   200
	if GetGearType(gear) == gtTarget then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   201
		-- Add one point to our score/counter
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   202
		score = score + 1
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   203
		-- If we haven't reached the goal ...
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   204
		if score < score_goal then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   205
			-- ... spawn another target.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   206
			spawnTarget()
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   207
		else
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   208
			if not game_lost then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   209
			-- Otherwise show that the goal was accomplished
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   210
			ShowMission(loc("Bazooka Training"), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets|within the allowed time frame."), 0, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   211
			-- Also let the hogs shout "victory!"
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   212
			PlaySound(sndVictory)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   213
			-- Save the time left so we may keep it.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   214
			time_goal = TurnTimeLeft
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   215
			end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   216
		end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   217
	end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   218
end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   219
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   220
-- This function is called when a gear has been damaged.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   221
-- We only use it to determine wheather our hog took damage in order to abort the mission.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   222
function onGearDamage(gear, damage)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   223
	if GetGearType(gear) == gtHedgehog then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   224
		if not game_lost then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   225
			game_lost = true
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   226
			AddCaption(loc("You lose!", 0xFFFFFFFF, capgrpGameState))
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   227
			ShowMission(loc("Bazooka Training") , loc("Aiming practice"), loc("Oh no! You failed! Just try again."), -amSkip, 0)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   228
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   229
			time_goal = 1
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   230
		end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   231
	end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   232
end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   233
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   234
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   235
-- This function is called after a gear is added.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   236
-- We use it to count the number of bazooka shots.
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   237
function onGearAdd(gear)
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   238
	-- Count the number of bazooka shots for our stats
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   239
	if GetGearType(gear) == gtShell then
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   240
		shots = shots + 1
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   241
	end
1c85a442bd56 Wuzzy's changes to stats for some of the training missions.
mikade <redgrinner@gmail.com>
parents: 10289
diff changeset
   242
end