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