share/hedgewars/Data/Missions/Training/Bazooka Training.lua
author smxx
Wed, 17 Mar 2010 22:56:23 +0000
changeset 3013 dfc1f16aeb53
parent 3011 73c8f618fd8b
child 3223 f0e590790f3b
permissions -rw-r--r--
General: * Updated Spanish translation by Palewolf Maps: * Updated Knockball to use less strings and placeholders
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3011
73c8f618fd8b General:
smxx
parents:
diff changeset
     1
-- Hedgewars Bazooka Training
73c8f618fd8b General:
smxx
parents:
diff changeset
     2
-- Scripting Example
73c8f618fd8b General:
smxx
parents:
diff changeset
     3
73c8f618fd8b General:
smxx
parents:
diff changeset
     4
-- Lines such as this one are comments - they are ignored
73c8f618fd8b General:
smxx
parents:
diff changeset
     5
-- by the game, no matter what kind of text is in there.
73c8f618fd8b General:
smxx
parents:
diff changeset
     6
-- It's also possible to place a comment after some real
73c8f618fd8b General:
smxx
parents:
diff changeset
     7
-- instruction as you see below. In short, everything
73c8f618fd8b General:
smxx
parents:
diff changeset
     8
-- following "--" is ignored.
73c8f618fd8b General:
smxx
parents:
diff changeset
     9
73c8f618fd8b General:
smxx
parents:
diff changeset
    10
---------------------------------------------------------------
73c8f618fd8b General:
smxx
parents:
diff changeset
    11
-- At first we put all text we'd like to use in some arrays.
73c8f618fd8b General:
smxx
parents:
diff changeset
    12
-- This way we're able to localize the text to be shown without
73c8f618fd8b General:
smxx
parents:
diff changeset
    13
-- modifying other files.
73c8f618fd8b General:
smxx
parents:
diff changeset
    14
-- The language to be used is stored in the global variable
73c8f618fd8b General:
smxx
parents:
diff changeset
    15
-- 'L' that is set by the game (string).
73c8f618fd8b General:
smxx
parents:
diff changeset
    16
-- Text may then be accessed using "arrayname[L]".
73c8f618fd8b General:
smxx
parents:
diff changeset
    17
73c8f618fd8b General:
smxx
parents:
diff changeset
    18
local caption = {
73c8f618fd8b General:
smxx
parents:
diff changeset
    19
	["en"] = "Bazooka Training",
3013
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    20
	["de"] = "Bazooka-Training",
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    21
	["es"] = "Entrenamiento con bazuca"
3011
73c8f618fd8b General:
smxx
parents:
diff changeset
    22
	-- To add other languages, just add lines similar to the
73c8f618fd8b General:
smxx
parents:
diff changeset
    23
	-- existing ones - don't forget the trailing ","!
73c8f618fd8b General:
smxx
parents:
diff changeset
    24
	}
73c8f618fd8b General:
smxx
parents:
diff changeset
    25
73c8f618fd8b General:
smxx
parents:
diff changeset
    26
local subcaption = {
73c8f618fd8b General:
smxx
parents:
diff changeset
    27
	["en"] = "Aiming Practice",
3013
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    28
	["de"] = "Zielübung",
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    29
	["es"] = "Practica tu puntería"
3011
73c8f618fd8b General:
smxx
parents:
diff changeset
    30
	}
73c8f618fd8b General:
smxx
parents:
diff changeset
    31
73c8f618fd8b General:
smxx
parents:
diff changeset
    32
local goal = {
73c8f618fd8b General:
smxx
parents:
diff changeset
    33
	["en"] = "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.",
3013
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    34
	["de"] = "Eliminiere alle Ziele bevor die Zeit ausläuft.|Du hast in dieser Mission unbegrenzte Munition.",
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    35
	["es"] = "Destruye todos los objetivos antes de que se agote el tiempo.|La munición en esta misión es ilimitada."
3011
73c8f618fd8b General:
smxx
parents:
diff changeset
    36
	}
73c8f618fd8b General:
smxx
parents:
diff changeset
    37
73c8f618fd8b General:
smxx
parents:
diff changeset
    38
local timeout = {
73c8f618fd8b General:
smxx
parents:
diff changeset
    39
	["en"] = "Oh no! Time's up! Just try again.",
3013
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    40
	["de"] = "Oh nein! Die Zeit ist um! Versuche es nochmal.",
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    41
	["es"] = "¡Oh, no, se te acabó el tiempo! ¿Por qué no lo intentas de nuevo?"
3011
73c8f618fd8b General:
smxx
parents:
diff changeset
    42
	}
73c8f618fd8b General:
smxx
parents:
diff changeset
    43
73c8f618fd8b General:
smxx
parents:
diff changeset
    44
local success = {
73c8f618fd8b General:
smxx
parents:
diff changeset
    45
	["en"] = "Congratulations! You've eliminated all targets|within the allowed time frame.",
3013
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    46
	["de"] = "Gratulation! Du hast alle Ziele innerhalb der|verfügbaren Zeit ausgeschaltet.",
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    47
	["es"] = "¡Felicidades! Has destruido todos los objectivos|dentro del tiempo establecido."
3011
73c8f618fd8b General:
smxx
parents:
diff changeset
    48
	}
73c8f618fd8b General:
smxx
parents:
diff changeset
    49
73c8f618fd8b General:
smxx
parents:
diff changeset
    50
local teamname = {
73c8f618fd8b General:
smxx
parents:
diff changeset
    51
	["en"] = "'Zooka Team",
3013
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    52
	["de"] = "Die Knalltüten",
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    53
	["es"] = "Bazuqueros"
3011
73c8f618fd8b General:
smxx
parents:
diff changeset
    54
	}
73c8f618fd8b General:
smxx
parents:
diff changeset
    55
73c8f618fd8b General:
smxx
parents:
diff changeset
    56
local hogname = {
73c8f618fd8b General:
smxx
parents:
diff changeset
    57
	["en"] = "Hunter",
3013
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    58
	["de"] = "Jäger",
dfc1f16aeb53 General:
smxx
parents: 3011
diff changeset
    59
	["es"] = "Artillero"
3011
73c8f618fd8b General:
smxx
parents:
diff changeset
    60
	}
73c8f618fd8b General:
smxx
parents:
diff changeset
    61
73c8f618fd8b General:
smxx
parents:
diff changeset
    62
-- To handle missing texts we define a small wrapper function that
73c8f618fd8b General:
smxx
parents:
diff changeset
    63
-- we'll use to retrieve text.
73c8f618fd8b General:
smxx
parents:
diff changeset
    64
local function loc(text)
73c8f618fd8b General:
smxx
parents:
diff changeset
    65
	if text == nil then return "**missing**"
73c8f618fd8b General:
smxx
parents:
diff changeset
    66
	elseif text[L] == nil then return text["en"]
73c8f618fd8b General:
smxx
parents:
diff changeset
    67
	else return text[L]
73c8f618fd8b General:
smxx
parents:
diff changeset
    68
	end
73c8f618fd8b General:
smxx
parents:
diff changeset
    69
end
73c8f618fd8b General:
smxx
parents:
diff changeset
    70
73c8f618fd8b General:
smxx
parents:
diff changeset
    71
---------------------------------------------------------------
73c8f618fd8b General:
smxx
parents:
diff changeset
    72
73c8f618fd8b General:
smxx
parents:
diff changeset
    73
-- This variable will hold the number of destroyed targets.
73c8f618fd8b General:
smxx
parents:
diff changeset
    74
local score = 0
73c8f618fd8b General:
smxx
parents:
diff changeset
    75
-- This variable represents the number of targets to destroy.
73c8f618fd8b General:
smxx
parents:
diff changeset
    76
local score_goal = 5
73c8f618fd8b General:
smxx
parents:
diff changeset
    77
-- This variable controls how many milliseconds/ticks we'd
73c8f618fd8b General:
smxx
parents:
diff changeset
    78
-- like to wait before we end the round once all targets
73c8f618fd8b General:
smxx
parents:
diff changeset
    79
-- have been destroyed.
73c8f618fd8b General:
smxx
parents:
diff changeset
    80
local end_timer = 5000 -- 5000 ms = 5 s
73c8f618fd8b General:
smxx
parents:
diff changeset
    81
-- This variable is set to true if the game is lost (i.e.
73c8f618fd8b General:
smxx
parents:
diff changeset
    82
-- time runs out).
73c8f618fd8b General:
smxx
parents:
diff changeset
    83
local game_lost = false
73c8f618fd8b General:
smxx
parents:
diff changeset
    84
-- This variable will point to the hog's gear
73c8f618fd8b General:
smxx
parents:
diff changeset
    85
local player = nil
73c8f618fd8b General:
smxx
parents:
diff changeset
    86
-- This variable will grab the time left at the end of the round
73c8f618fd8b General:
smxx
parents:
diff changeset
    87
local time_goal = 0
73c8f618fd8b General:
smxx
parents:
diff changeset
    88
73c8f618fd8b General:
smxx
parents:
diff changeset
    89
-- This is a custom function to make it easier to
73c8f618fd8b General:
smxx
parents:
diff changeset
    90
-- spawn more targets with just one line of code
73c8f618fd8b General:
smxx
parents:
diff changeset
    91
-- You may define as many custom functions as you
73c8f618fd8b General:
smxx
parents:
diff changeset
    92
-- like.
73c8f618fd8b General:
smxx
parents:
diff changeset
    93
function spawnTarget()
73c8f618fd8b General:
smxx
parents:
diff changeset
    94
	-- add a new target gear
73c8f618fd8b General:
smxx
parents:
diff changeset
    95
	gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
73c8f618fd8b General:
smxx
parents:
diff changeset
    96
	
73c8f618fd8b General:
smxx
parents:
diff changeset
    97
	-- move it to a random position within 0 and
73c8f618fd8b General:
smxx
parents:
diff changeset
    98
	-- LAND_WIDTH - the width of the map
73c8f618fd8b General:
smxx
parents:
diff changeset
    99
	FindPlace(gear, true, 0, LAND_WIDTH)
73c8f618fd8b General:
smxx
parents:
diff changeset
   100
	
73c8f618fd8b General:
smxx
parents:
diff changeset
   101
	-- move the target to a higher vertical position
73c8f618fd8b General:
smxx
parents:
diff changeset
   102
	-- to ensure it's not somewhere down below
73c8f618fd8b General:
smxx
parents:
diff changeset
   103
	x, y = GetGearPosition(gear)
73c8f618fd8b General:
smxx
parents:
diff changeset
   104
	SetGearPosition(gear, x, 500)
73c8f618fd8b General:
smxx
parents:
diff changeset
   105
end
73c8f618fd8b General:
smxx
parents:
diff changeset
   106
73c8f618fd8b General:
smxx
parents:
diff changeset
   107
-- This function is called before the game loads its
73c8f618fd8b General:
smxx
parents:
diff changeset
   108
-- resources.
73c8f618fd8b General:
smxx
parents:
diff changeset
   109
-- It's one of the predefined function names that will
73c8f618fd8b General:
smxx
parents:
diff changeset
   110
-- be called by the game. They give you entry points
73c8f618fd8b General:
smxx
parents:
diff changeset
   111
-- where you're able to call your own code using either
73c8f618fd8b General:
smxx
parents:
diff changeset
   112
-- provided instructions or custom functions.
73c8f618fd8b General:
smxx
parents:
diff changeset
   113
function onGameInit()
73c8f618fd8b General:
smxx
parents:
diff changeset
   114
	-- At first we have to overwrite/set some global variables
73c8f618fd8b General:
smxx
parents:
diff changeset
   115
	-- that define the map, the game has to load, as well as
73c8f618fd8b General:
smxx
parents:
diff changeset
   116
	-- other things such as the game rules to use, etc.
73c8f618fd8b General:
smxx
parents:
diff changeset
   117
	-- Things we don't modify here will use their default values.
73c8f618fd8b General:
smxx
parents:
diff changeset
   118
73c8f618fd8b General:
smxx
parents:
diff changeset
   119
	-- The base number for the random number generator
73c8f618fd8b General:
smxx
parents:
diff changeset
   120
	Seed = 0
73c8f618fd8b General:
smxx
parents:
diff changeset
   121
	-- Game settings and rules
73c8f618fd8b General:
smxx
parents:
diff changeset
   122
	GameFlags = gfMultiWeapon + gfOneClanMode + gfSolidLand
73c8f618fd8b General:
smxx
parents:
diff changeset
   123
	-- The time the player has to move each round (in ms)
73c8f618fd8b General:
smxx
parents:
diff changeset
   124
	TurnTime = 60000
73c8f618fd8b General:
smxx
parents:
diff changeset
   125
	-- The frequency of crate drops
73c8f618fd8b General:
smxx
parents:
diff changeset
   126
	CaseFreq = 0
73c8f618fd8b General:
smxx
parents:
diff changeset
   127
	-- The number of mines being placed
73c8f618fd8b General:
smxx
parents:
diff changeset
   128
	LandAdds = 0
73c8f618fd8b General:
smxx
parents:
diff changeset
   129
	-- The number of explosives being placed
73c8f618fd8b General:
smxx
parents:
diff changeset
   130
	Explosives = 0
73c8f618fd8b General:
smxx
parents:
diff changeset
   131
	-- The delay between each round
73c8f618fd8b General:
smxx
parents:
diff changeset
   132
	Delay = 0
73c8f618fd8b General:
smxx
parents:
diff changeset
   133
	-- The map to be played
73c8f618fd8b General:
smxx
parents:
diff changeset
   134
	Map = "Bamboo"
73c8f618fd8b General:
smxx
parents:
diff changeset
   135
	-- The theme to be used
73c8f618fd8b General:
smxx
parents:
diff changeset
   136
	Theme = "Bamboo"
73c8f618fd8b General:
smxx
parents:
diff changeset
   137
73c8f618fd8b General:
smxx
parents:
diff changeset
   138
	-- Create the player team
73c8f618fd8b General:
smxx
parents:
diff changeset
   139
	AddTeam(loc(teamname), 14483456, "Simple", "Island", "Default")
73c8f618fd8b General:
smxx
parents:
diff changeset
   140
	-- And add a hog to it
73c8f618fd8b General:
smxx
parents:
diff changeset
   141
	player = AddHog(loc(hogname), 0, 1, "NoHat")
73c8f618fd8b General:
smxx
parents:
diff changeset
   142
	SetGearPosition(player, 1960, 1160);
73c8f618fd8b General:
smxx
parents:
diff changeset
   143
end
73c8f618fd8b General:
smxx
parents:
diff changeset
   144
73c8f618fd8b General:
smxx
parents:
diff changeset
   145
-- This function is called when the round starts
73c8f618fd8b General:
smxx
parents:
diff changeset
   146
-- it spawns the first target that has to be destroyed.
73c8f618fd8b General:
smxx
parents:
diff changeset
   147
-- In addition it shows the scenario goal(s).
73c8f618fd8b General:
smxx
parents:
diff changeset
   148
function onGameStart()
73c8f618fd8b General:
smxx
parents:
diff changeset
   149
	-- Spawn the first target.
73c8f618fd8b General:
smxx
parents:
diff changeset
   150
	spawnTarget()
73c8f618fd8b General:
smxx
parents:
diff changeset
   151
	
73c8f618fd8b General:
smxx
parents:
diff changeset
   152
	-- Show some nice mission goals.
73c8f618fd8b General:
smxx
parents:
diff changeset
   153
	-- Parameters are: caption, sub caption, description,
73c8f618fd8b General:
smxx
parents:
diff changeset
   154
	-- extra text, icon and time to show.
73c8f618fd8b General:
smxx
parents:
diff changeset
   155
	-- A negative icon parameter (-n) represents the n-th weapon icon
73c8f618fd8b General:
smxx
parents:
diff changeset
   156
	-- A positive icon paramter (n) represents the (n+1)-th mission icon
73c8f618fd8b General:
smxx
parents:
diff changeset
   157
	-- A timeframe of 0 is replaced with the default time to show.
73c8f618fd8b General:
smxx
parents:
diff changeset
   158
	ShowMission(loc(caption), loc(subcaption), loc(goal), -amBazooka, 0);
73c8f618fd8b General:
smxx
parents:
diff changeset
   159
end
73c8f618fd8b General:
smxx
parents:
diff changeset
   160
73c8f618fd8b General:
smxx
parents:
diff changeset
   161
-- This function is called every game tick.
73c8f618fd8b General:
smxx
parents:
diff changeset
   162
-- Note that there are 1000 ticks within one second.
73c8f618fd8b General:
smxx
parents:
diff changeset
   163
-- You shouldn't try to calculate too complicated
73c8f618fd8b General:
smxx
parents:
diff changeset
   164
-- code here as this might slow down your game.
73c8f618fd8b General:
smxx
parents:
diff changeset
   165
function onGameTick()
73c8f618fd8b General:
smxx
parents:
diff changeset
   166
	-- If time's up, set the game to be lost.
73c8f618fd8b General:
smxx
parents:
diff changeset
   167
	-- We actually check the time to be "1 ms" as it
73c8f618fd8b General:
smxx
parents:
diff changeset
   168
	-- will be at "0 ms" right at the start of the game.
73c8f618fd8b General:
smxx
parents:
diff changeset
   169
	if TurnTimeLeft == 1 and score < score_goal then
73c8f618fd8b General:
smxx
parents:
diff changeset
   170
		game_lost = true
73c8f618fd8b General:
smxx
parents:
diff changeset
   171
		-- ... and show a short message.
73c8f618fd8b General:
smxx
parents:
diff changeset
   172
		ShowMission(loc(caption), loc(subcaption), loc(timeout), -amSkip, 0);
73c8f618fd8b General:
smxx
parents:
diff changeset
   173
		-- How about killing our poor hog due to his poor performance?
73c8f618fd8b General:
smxx
parents:
diff changeset
   174
		SetHealth(player, 0);
73c8f618fd8b General:
smxx
parents:
diff changeset
   175
		-- Just to be sure set the goal time to 1 ms
73c8f618fd8b General:
smxx
parents:
diff changeset
   176
		time_goal = 1
73c8f618fd8b General:
smxx
parents:
diff changeset
   177
	end
73c8f618fd8b General:
smxx
parents:
diff changeset
   178
	-- If the goal is reached or we've lost ...
73c8f618fd8b General:
smxx
parents:
diff changeset
   179
	if score == score_goal or game_lost then
73c8f618fd8b General:
smxx
parents:
diff changeset
   180
		-- ... check to see if the time we'd like to
73c8f618fd8b General:
smxx
parents:
diff changeset
   181
		-- wait has passed and then ...
73c8f618fd8b General:
smxx
parents:
diff changeset
   182
		if end_timer == 0 then
73c8f618fd8b General:
smxx
parents:
diff changeset
   183
			-- ... end the game ...
73c8f618fd8b General:
smxx
parents:
diff changeset
   184
			EndGame()
73c8f618fd8b General:
smxx
parents:
diff changeset
   185
		else
73c8f618fd8b General:
smxx
parents:
diff changeset
   186
			-- ... or just lower the timer by 1.
73c8f618fd8b General:
smxx
parents:
diff changeset
   187
			end_timer = end_timer - 1
73c8f618fd8b General:
smxx
parents:
diff changeset
   188
			-- Reset the time left to stop the timer
73c8f618fd8b General:
smxx
parents:
diff changeset
   189
			TurnTimeLeft = time_goal
73c8f618fd8b General:
smxx
parents:
diff changeset
   190
		end
73c8f618fd8b General:
smxx
parents:
diff changeset
   191
	end
73c8f618fd8b General:
smxx
parents:
diff changeset
   192
end
73c8f618fd8b General:
smxx
parents:
diff changeset
   193
73c8f618fd8b General:
smxx
parents:
diff changeset
   194
-- This function is called when the game is initialized
73c8f618fd8b General:
smxx
parents:
diff changeset
   195
-- to request the available ammo and probabilities
73c8f618fd8b General:
smxx
parents:
diff changeset
   196
function onAmmoStoreInit()
73c8f618fd8b General:
smxx
parents:
diff changeset
   197
	-- add an unlimited supply of bazooka ammo
73c8f618fd8b General:
smxx
parents:
diff changeset
   198
	SetAmmo(amBazooka, 9, 0, 0)
73c8f618fd8b General:
smxx
parents:
diff changeset
   199
end
73c8f618fd8b General:
smxx
parents:
diff changeset
   200
73c8f618fd8b General:
smxx
parents:
diff changeset
   201
-- This function is called when a new gear is added.
73c8f618fd8b General:
smxx
parents:
diff changeset
   202
-- We don't need it for this training, so we can
73c8f618fd8b General:
smxx
parents:
diff changeset
   203
-- keep it empty.
73c8f618fd8b General:
smxx
parents:
diff changeset
   204
function onGearAdd(gear)
73c8f618fd8b General:
smxx
parents:
diff changeset
   205
end
73c8f618fd8b General:
smxx
parents:
diff changeset
   206
73c8f618fd8b General:
smxx
parents:
diff changeset
   207
-- This function is called before a gear is destroyed.
73c8f618fd8b General:
smxx
parents:
diff changeset
   208
-- We use it to count the number of targets destroyed.
73c8f618fd8b General:
smxx
parents:
diff changeset
   209
function onGearDelete(gear)
73c8f618fd8b General:
smxx
parents:
diff changeset
   210
	-- We're only interested in target gears.
73c8f618fd8b General:
smxx
parents:
diff changeset
   211
	if GetGearType(gear) == gtTarget then
73c8f618fd8b General:
smxx
parents:
diff changeset
   212
		-- Add one point to our score/counter
73c8f618fd8b General:
smxx
parents:
diff changeset
   213
		score = score + 1
73c8f618fd8b General:
smxx
parents:
diff changeset
   214
		-- If we haven't reached the goal ...
73c8f618fd8b General:
smxx
parents:
diff changeset
   215
		if score < score_goal then
73c8f618fd8b General:
smxx
parents:
diff changeset
   216
			-- ... spawn another target.
73c8f618fd8b General:
smxx
parents:
diff changeset
   217
			spawnTarget()
73c8f618fd8b General:
smxx
parents:
diff changeset
   218
		else
73c8f618fd8b General:
smxx
parents:
diff changeset
   219
			if not game_lost then
73c8f618fd8b General:
smxx
parents:
diff changeset
   220
			-- Otherwise show that the goal was accomplished
73c8f618fd8b General:
smxx
parents:
diff changeset
   221
			ShowMission(loc(caption), loc(subcaption), loc(success), 0, 0);
73c8f618fd8b General:
smxx
parents:
diff changeset
   222
			-- Also let the hogs shout "victory!"
73c8f618fd8b General:
smxx
parents:
diff changeset
   223
			PlaySound(sndVictory)
73c8f618fd8b General:
smxx
parents:
diff changeset
   224
			-- Save the time left so we may keep it.
73c8f618fd8b General:
smxx
parents:
diff changeset
   225
			time_goal = TurnTimeLeft
73c8f618fd8b General:
smxx
parents:
diff changeset
   226
			end
73c8f618fd8b General:
smxx
parents:
diff changeset
   227
		end
73c8f618fd8b General:
smxx
parents:
diff changeset
   228
	end
73c8f618fd8b General:
smxx
parents:
diff changeset
   229
end