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