share/hedgewars/Data/Missions/Bazooka Training.hwt
author smxx
Mon, 15 Feb 2010 21:54:26 +0000
changeset 2814 71e80c6e74bb
parent 2790 83630d5f94db
child 2815 c1daf1213cbe
permissions -rw-r--r--
Engine: * Removed some commented out lines * Added "SetHealth" script command * Added support for global variables (between lua and game) Training Missions: * Once again fail if your time runs out * Training missions show a "You've lost!" message * Changed Shotgun training back to mushrooms map
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
---------------------------------------------------------------
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    11
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    12
-- This variable will hold the number of destroyed targets.
2814
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    13
local score = 0
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    14
-- This variable represents the number of targets to destroy.
2814
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    15
local score_goal = 5
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    16
-- This variable controls how many milliseconds/ticks we'd
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    17
-- like to wait before we end the round once all targets
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    18
-- have been destroyed.
2814
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    19
local end_timer = 5000 -- 5000 ms = 5 s
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    20
-- This variable is set to true if the game is lost (i.e.
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    21
-- time runs out).
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    22
local game_lost = false
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    23
-- This variable will point to the hog's gear
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    24
local player = nil
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    25
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    26
-- This is a custom function to make it easier to
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    27
-- spawn more targets with just one line of code
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    28
-- You may define as many custom functions as you
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    29
-- like.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    30
function spawnTarget()
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    31
	-- add a new target gear
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    32
	gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    33
	
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    34
	-- move it to a random position within 0 and
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    35
	-- LAND_WIDTH - the width of the map
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    36
	FindPlace(gear, true, 0, LAND_WIDTH)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    37
	
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    38
	-- move the target to a higher vertical position
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    39
	-- to ensure it's not somewhere down below
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    40
	x, y = GetGearPosition(gear)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    41
	SetGearPosition(gear, x, 500)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    42
end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    43
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    44
-- This function is called before the game loads its
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    45
-- resources.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    46
-- It's one of the predefined function names that will
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    47
-- be called by the game. They give you entry points
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    48
-- where you're able to call your own code using either
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    49
-- provided instructions or custom functions.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    50
function onGameInit()
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    51
	-- At first we have to overwrite/set some global variables
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    52
	-- that define the map, the game has to load, as well as
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    53
	-- other things such as the game rules to use, etc.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    54
	-- Things we don't modify here will use their default values.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    55
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    56
	-- The base number for the random number generator
2790
83630d5f94db Engine:
smxx
parents: 2786
diff changeset
    57
	Seed = 0
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    58
	-- Game settings and rules
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    59
	GameFlags = gfMultiWeapon + gfOneClanMode + gfSolidLand
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    60
	-- The time the player has to move each round (in ms)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    61
	TurnTime = 25000
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    62
	-- The frequency of crate drops
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    63
	CaseFreq = 0
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    64
	-- The number of land objects being placed
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    65
	LandAdds = 0
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    66
	-- The delay between each round
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    67
	Delay = 0
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    68
	-- The map to be played
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    69
	Map = "Bamboo"
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    70
	-- The theme to be used
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    71
	Theme = "Bamboo"
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    72
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    73
	-- Create the player team
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    74
	AddTeam("'Zooka Team", 14483456, "Simple", "Island", "Default")
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    75
	-- And add a hog to it
2814
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    76
	player = AddHog("Hunter", 0, 1, "NoHat")
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
    77
	SetGearPosition(player, 1960, 1160);
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    78
end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    79
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    80
-- This function is called when the round starts
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    81
-- it spawns the first target that has to be destroyed.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    82
-- In addition it shows the scenario goal(s).
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    83
function onGameStart()
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    84
	-- Spawn the first target.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    85
	spawnTarget()
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    86
	
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    87
	-- Show some nice mission goals.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    88
	-- Parameters are: caption, sub caption, description,
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    89
	-- extra text, icon and time to show.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    90
	-- A negative icon parameter (-n) represents the n-th weapon icon
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    91
	-- A positive icon paramter (n) represents the (n+1)-th mission icon
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    92
	-- A timeframe of 0 is replaced with the default time to show.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    93
	ShowMission("Bazooka Training", "Aiming Practice", "Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.", -amBazooka, 0);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    94
end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    95
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    96
-- This function is called every game tick.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    97
-- Note that there are 1000 ticks within one second.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    98
-- You shouldn't try to calculate too complicated
85f6425a4d74 Engine:
smxx
parents:
diff changeset
    99
-- code here as this might slow down your game.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   100
function onGameTick()
2814
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   101
	-- If time's up, set the game to be lost.
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   102
	-- We actually check the time to be "1 ms" as it
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   103
	-- will be at "0 ms" right at the start of the game.
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   104
	if TurnTimeLeft == 1 then
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   105
		game_lost = true
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   106
		-- ... and show a short message.
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   107
		ShowMission("Bazooka Training", "Aiming Practice", "Oh no! Time's up! Just try again.", -amSkip, 0);
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   108
		-- How about killing our poor hog due to his poor performance?
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   109
		SetHealth(player, 0);
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   110
	end
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   111
	-- If the goal is reached or we've lost ...
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   112
	if score == score_goal or game_lost then
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   113
		-- ... check to see if the time we'd like to
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   114
		-- wait has passed and then ...
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   115
		if end_timer == 0 then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   116
			-- ... end the game ...
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   117
			EndGame()
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   118
		else
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   119
			-- ... or just lower the timer by 1.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   120
			end_timer = end_timer - 1
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   121
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   122
	end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   123
end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   124
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   125
-- This function is called when the game is initialized
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   126
-- to request the available ammo and probabilities
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   127
function onAmmoStoreInit()
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   128
	-- add an unlimited supply of bazooka ammo
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   129
	SetAmmo(amBazooka, 9, 0)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   130
end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   131
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   132
-- This function is called when a new gear is added.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   133
-- We don't need it for this training, so we can
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   134
-- keep it empty.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   135
function onGearAdd(gear)
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 before a gear is destroyed.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   139
-- We use it to count the number of targets destroyed.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   140
function onGearDelete(gear)
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   141
	-- We're only interested in target gears.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   142
	if GetGearType(gear) == gtTarget then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   143
		-- Add one point to our score/counter
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   144
		score = score + 1
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   145
		-- If we haven't reached the goal ...
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   146
		if score < score_goal then
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   147
			-- ... spawn another target.
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   148
			spawnTarget()
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   149
		else
2814
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   150
			if not game_lost then
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   151
			-- Otherwise show that the goal was accomplished
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   152
			ShowMission("Bazooka Training", "Aiming Practice", "Congratulations! You've eliminated all targets|within the allowed time frame.", 0, 0);
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   153
			-- Also let the hogs shout "victory!"
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   154
			PlaySound(sndVictory)
2814
71e80c6e74bb Engine:
smxx
parents: 2790
diff changeset
   155
			end
2786
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   156
		end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   157
	end
85f6425a4d74 Engine:
smxx
parents:
diff changeset
   158
end