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