share/hedgewars/Data/Missions/Training/Shotgun.lua
author nemo
Wed, 19 May 2010 02:10:28 +0000
changeset 3476 1ec68b8d3bd1
parent 3456 e19e017691e4
child 4162 923db448ad16
permissions -rw-r--r--
Henek adds a flamethrower, updates some translations, and tweaks how fire works.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     1
-- Hedgewars Shotgun Training
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     2
-- Scripting Example
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     3
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     4
-- Lines such as this one are comments - they are ignored
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     5
-- by the game, no matter what kind of text is in there.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     6
-- It's also possible to place a comment after some real
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     7
-- instruction as you see below. In short, everything
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     8
-- following "--" is ignored.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
     9
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    10
---------------------------------------------------------------
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    11
-- At first we put all text we'd like to use in some arrays.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    12
-- This way we're able to localize the text to be shown without
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    13
-- modifying other files.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    14
-- The language to be used is stored in the global variable
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    15
-- 'L' that is set by the game (string).
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    16
-- Text may then be accessed using "arrayname[L]".
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    17
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    18
local caption = {
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    19
	["en"] = "Shotgun Training",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    20
	["de"] = "Schrotflinten-Training",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    21
	["es"] = "Entrenamiento con escopeta",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    22
	["pl"] = "Trening strzelecki",
3456
e19e017691e4 More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents: 3346
diff changeset
    23
	["pt_PT"] = "Treino com Caçadeira",
3476
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    24
	["pt_BR"] = "Treino com a Escopeta",
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    25
	["sv"] = "Hagelgevärsträning"
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    26
	-- To add other languages, just add lines similar to the
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    27
	-- existing ones - don't forget the trailing ","!
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    28
	}
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    29
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    30
local subcaption = {
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    31
	["en"] = "Aiming Practice",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    32
	["de"] = "Zielübung",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    33
	["es"] = "Practica tu puntería",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    34
	["pl"] = "Potrenuj celność",
3456
e19e017691e4 More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents: 3346
diff changeset
    35
	["pt_PT"] = "Pratica a tua pontaria",
3476
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    36
	["pt_BR"] = "Pratique a sua pontaria",
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    37
	["sv"] = "Siktesövning"
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    38
	}
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    39
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    40
local goal = {
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    41
	["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    42
	["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    43
	["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada.",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    44
	["pl"] = "Zniszcz wszystkie cele zanim upłynie czas.|W tej misji masz nieskończoną ilość amunicji.",
3456
e19e017691e4 More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents: 3346
diff changeset
    45
	["pt_PT"] = "Destrói todos os alvos antes do tempo terminar.|Tens munições infinitas para esta missão.",
3476
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    46
	["pt_BR"] = "Destrua todos os alvos antes que o tempo acabe.|Você tem munição infinita para esta missão.",
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    47
	["sv"] = "Förstör alla målen innan din tid tar slut.|Du har obegränsad ammunition för deta uppdrag"
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    48
	}
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    49
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    50
local timeout = {
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    51
	["en"] = "Oh no! Time's up! Just try again.",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    52
	["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    53
	["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    54
	["pl"] = "Ajajaj! Koniec czasu! Spróbuj jeszcze raz.",
3456
e19e017691e4 More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents: 3346
diff changeset
    55
	["pt_PT"] = "Oh não! Acabou o tempo! Tenta novamente.",
3476
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    56
	["pt_BR"] = "Oh não! O tempo acabou! Tente novamente.",
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    57
	["sv"] = "Åh nej! Tiden är ute! Pröva igen."
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    58
	}
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    59
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    60
local success = {
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    61
	["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    62
	["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    63
	["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido.",
3235
c7ceda2f5d4a Trainings:
smxx
parents: 3234
diff changeset
    64
	["pl"] = "Gratulacje! Zniszczyłeś wszystkie cele przed upłynięciem czasu.",
3456
e19e017691e4 More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents: 3346
diff changeset
    65
	["pt_PT"] = "Parabéns! Eliminaste todos os alvos|dentro do tempo limite.",
3476
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    66
	["pt_BR"] = "Parabéns! Você eliminou todos os alvos|dentro do tempo limite.",
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    67
	["sv"] = "Grattis! Du har förstört alla målen inom den|tillåtna tidsramen."
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    68
	}
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    69
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    70
local teamname = {
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    71
	["en"] = "Shotgun Team",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    72
	["de"] = "Die Knalltüten",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    73
	["es"] = "Escopeteros",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    74
	["pl"] = "Shotgun Team",
3456
e19e017691e4 More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents: 3346
diff changeset
    75
	["pt_PT"] = "Caçadores",
3476
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    76
	["pt_PT"] = "Carabineiros",
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    77
	["sv"] = "Hagelgevärslaget"
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    78
	}
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    79
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    80
local hogname = {
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    81
	["en"] = "Hunter",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    82
	["de"] = "Jäger",
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    83
	["es"] = "Cazador",
3247
045a76b9f32f Shotgun Training: * '["en"]' was supposed to be '["pl"]' (Mmmmh, copypasta :D)
sheepluva
parents: 3235
diff changeset
    84
	["pl"] = "Strzelec",
3456
e19e017691e4 More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents: 3346
diff changeset
    85
	["pt_PT"] = "Comando",
e19e017691e4 More translation work by arrom (restored some numerusform, lot more flavour text etc)
nemo
parents: 3346
diff changeset
    86
	["pt_BR"] = "Caçador",
3476
1ec68b8d3bd1 Henek adds a flamethrower, updates some translations, and tweaks how fire works.
nemo
parents: 3456
diff changeset
    87
	["sv"] = "Jägare"
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    88
	}
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    89
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    90
-- To handle missing texts we define a small wrapper function that
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    91
-- we'll use to retrieve text.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    92
local function loc(text)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    93
	if text == nil then return "**missing**"
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    94
	elseif text[L] == nil then return text["en"]
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    95
	else return text[L]
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    96
	end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    97
end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    98
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
    99
---------------------------------------------------------------
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   100
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   101
-- This variable will hold the number of destroyed targets.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   102
local score = 0
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   103
-- This variable represents the number of targets to destroy.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   104
local score_goal = 5
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   105
-- This variable controls how many milliseconds/ticks we'd
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   106
-- like to wait before we end the round once all targets
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   107
-- have been destroyed.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   108
local end_timer = 5000 -- 5000 ms = 5 s
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   109
-- This variable is set to true if the game is lost (i.e.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   110
-- time runs out).
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   111
local game_lost = false
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   112
-- This variable will point to the hog's gear
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   113
local player = nil
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   114
-- This variable will grab the time left at the end of the round
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   115
local time_goal = 0
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   116
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   117
-- This is a custom function to make it easier to
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   118
-- spawn more targets with just one line of code
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   119
-- You may define as many custom functions as you
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   120
-- like.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   121
function spawnTarget()
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   122
	-- add a new target gear
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   123
	gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   124
	
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   125
	-- move it to a random position within 0 and
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   126
	-- LAND_WIDTH - the width of the map
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   127
	FindPlace(gear, true, 0, LAND_WIDTH)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   128
	
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   129
	-- move the target to a higher vertical position
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   130
	-- to ensure it's not somewhere down below
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   131
	x, y = GetGearPosition(gear)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   132
	SetGearPosition(gear, x, 500)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   133
end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   134
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   135
-- This function is called before the game loads its
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   136
-- resources.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   137
-- It's one of the predefined function names that will
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   138
-- be called by the game. They give you entry points
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   139
-- where you're able to call your own code using either
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   140
-- provided instructions or custom functions.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   141
function onGameInit()
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   142
	-- At first we have to overwrite/set some global variables
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   143
	-- that define the map, the game has to load, as well as
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   144
	-- other things such as the game rules to use, etc.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   145
	-- Things we don't modify here will use their default values.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   146
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   147
	-- The base number for the random number generator
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   148
	Seed = 0
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   149
	-- Game settings and rules
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   150
	GameFlags = gfMultiWeapon + gfOneClanMode
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   151
	-- The time the player has to move each round (in ms)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   152
	TurnTime = 25000
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   153
	-- The frequency of crate drops
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   154
	CaseFreq = 0
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   155
	-- The number of mines being placed
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   156
	LandAdds = 0
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   157
	-- The number of explosives being placed
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   158
	Explosives = 0
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   159
	-- The delay between each round
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   160
	Delay = 0
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   161
	-- The map to be played
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   162
	Map = "Mushrooms"
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   163
	-- The theme to be used
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   164
	Theme = "Nature"
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   165
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   166
	-- Create the player team
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   167
	AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default")
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   168
	-- And add a hog to it
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   169
	player = AddHog(loc(hogname), 0, 1, "NoHat")
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   170
	SetGearPosition(player, 2334, 1254);
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   171
end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   172
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   173
-- This function is called when the round starts
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   174
-- it spawns the first target that has to be destroyed.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   175
-- In addition it shows the scenario goal(s).
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   176
function onGameStart()
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   177
	-- Spawn the first target.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   178
	spawnTarget()
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   179
	
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   180
	-- Show some nice mission goals.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   181
	-- Parameters are: caption, sub caption, description,
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   182
	-- extra text, icon and time to show.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   183
	-- A negative icon parameter (-n) represents the n-th weapon icon
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   184
	-- A positive icon paramter (n) represents the (n+1)-th mission icon
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   185
	-- A timeframe of 0 is replaced with the default time to show.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   186
	ShowMission(loc(caption), loc(subcaption), loc(goal), -amShotgun, 0);
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   187
end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   188
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   189
-- This function is called every game tick.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   190
-- Note that there are 1000 ticks within one second.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   191
-- You shouldn't try to calculate too complicated
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   192
-- code here as this might slow down your game.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   193
function onGameTick()
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   194
	-- If time's up, set the game to be lost.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   195
	-- We actually check the time to be "1 ms" as it
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   196
	-- will be at "0 ms" right at the start of the game.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   197
	if TurnTimeLeft == 1 and score < score_goal then
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   198
		game_lost = true
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   199
		-- ... and show a short message.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   200
		ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0);
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   201
		-- How about killing our poor hog due to his poor performance?
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   202
		SetHealth(player, 0);
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   203
		-- Just to be sure set the goal time to 1 ms
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   204
		time_goal = 1
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   205
	end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   206
	-- If the goal is reached or we've lost ...
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   207
	if score == score_goal or game_lost then
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   208
		-- ... check to see if the time we'd like to
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   209
		-- wait has passed and then ...
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   210
		if end_timer == 0 then
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   211
			-- ... end the game ...
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   212
			EndGame()
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   213
		else
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   214
			-- ... or just lower the timer by 1.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   215
			end_timer = end_timer - 1
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   216
			-- Reset the time left to stop the timer
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   217
			TurnTimeLeft = time_goal
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   218
		end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   219
	end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   220
end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   221
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   222
-- This function is called when the game is initialized
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   223
-- to request the available ammo and probabilities
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   224
function onAmmoStoreInit()
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   225
	-- add an unlimited supply of shotgun ammo
3346
967fd96f7373 Engine/Frontend:
smxx
parents: 3247
diff changeset
   226
	SetAmmo(amShotgun, 9, 0, 0, 0)
3234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   227
end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   228
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   229
-- This function is called when a new gear is added.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   230
-- We don't need it for this training, so we can
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   231
-- keep it empty.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   232
function onGearAdd(gear)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   233
end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   234
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   235
-- This function is called before a gear is destroyed.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   236
-- We use it to count the number of targets destroyed.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   237
function onGearDelete(gear)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   238
	-- We're only interested in target gears.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   239
	if GetGearType(gear) == gtTarget then
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   240
		-- Add one point to our score/counter
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   241
		score = score + 1
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   242
		-- If we haven't reached the goal ...
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   243
		if score < score_goal then
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   244
			-- ... spawn another target.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   245
			spawnTarget()
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   246
		else
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   247
			if not game_lost then
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   248
			-- Otherwise show that the goal was accomplished
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   249
			ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0);
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   250
			-- Also let the hogs shout "victory!"
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   251
			PlaySound(sndVictory)
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   252
			-- Save the time left so we may keep it.
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   253
			time_goal = TurnTimeLeft
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   254
			end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   255
		end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   256
	end
668c7d0a00a6 Trainings:
smxx
parents:
diff changeset
   257
end