share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua
author unc0rr
Sat, 14 Nov 2015 17:39:45 +0300
changeset 11385 ff0fa38bdb18
parent 11248 94c0085ddac6
child 12054 030464f34d47
permissions -rw-r--r--
Some WIP
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     1
-- Hedgewars Grenade Training
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     2
-- Scripting Example
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     3
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     4
-- Lines such as this one are comments - they are ignored
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     5
-- by the game, no matter what kind of text is in there.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     6
-- It's also possible to place a comment after some real
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     7
-- instruction as you see below. In short, everything
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     8
-- following "--" is ignored.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     9
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    10
---------------------------------------------------------------
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    11
-- At first we implement the localization library using loadfile.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    12
-- This allows us to localize strings without needing to think
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    13
-- about translations.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    14
-- We can use the function loc(text) to localize a string.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    15
8043
da083f8d95e6 We need custom script loading function in lua now
unc0rr
parents: 7877
diff changeset
    16
HedgewarsScriptLoad("/Scripts/Locale.lua")
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    17
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    18
-- This variable will hold the number of destroyed targets.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    19
local score = 0
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    20
-- This variable represents the number of targets to destroy.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    21
local score_goal = 5
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    22
-- This variable controls how many milliseconds/ticks we'd
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    23
-- like to wait before we end the round once all targets
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    24
-- have been destroyed.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    25
local end_timer = 4000 -- 5000 ms = 5 s
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    26
-- This variable is set to true if the game is lost (i.e.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    27
-- time runs out).
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    28
local game_lost = false
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    29
-- This variable ensures that the death function isn't called
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    30
-- repeatedly when game is over.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    31
local team_death = false
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    32
-- This variable will point to the hog's gear
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    33
local player = nil
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    34
-- This variable will grab the time left at the end of the round
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    35
local time_goal = 0
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    36
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    37
-- This is a custom function to make it easier to
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    38
-- spawn more targets with just one line of code
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    39
-- You may define as many custom functions as you
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    40
-- like.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    41
function spawnTarget()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    42
	-- add a new target gear
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    43
	gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    44
	
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    45
	-- move it to a random position within 0 and
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    46
	-- LAND_WIDTH - the width of the map
7877
b3fb94986255 Fix training script positions altered by variable land dimension change. Issue #453
nemo
parents: 7165
diff changeset
    47
	FindPlace(gear, true, 0, LAND_WIDTH-326)
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    48
	
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    49
	-- move the target to a higher vertical position
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    50
	-- to ensure it's not somewhere down below
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    51
	x, y = GetGearPosition(gear)
7877
b3fb94986255 Fix training script positions altered by variable land dimension change. Issue #453
nemo
parents: 7165
diff changeset
    52
	SetGearPosition(gear, x, 0)
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    53
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    54
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    55
-- This function is called before the game loads its
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    56
-- resources.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    57
-- It's one of the predefined function names that will
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    58
-- be called by the game. They give you entry points
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    59
-- where you're able to call your own code using either
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    60
-- provided instructions or custom functions.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    61
function onGameInit()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    62
	-- At first we have to overwrite/set some global variables
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    63
	-- that define the map, the game has to load, as well as
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    64
	-- other things such as the game rules to use, etc.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    65
	-- Things we don't modify here will use their default values.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    66
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    67
	-- The base number for the random number generator
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    68
	Seed = 1
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    69
	-- Game settings and rules
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    70
	GameFlags = gfInfAttack + gfOneClanMode 
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    71
	-- The time the player has to move each round (in ms)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    72
	TurnTime = 60000
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    73
	-- The frequency of crate drops
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    74
	CaseFreq = 0
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    75
	-- The number of mines being placed
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    76
	MinesNum = 0
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    77
	-- The number of explosives being placed
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    78
	Explosives = 0
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    79
	-- The delay between each round
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    80
	Delay = 1
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    81
	-- The map to be played
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    82
	Map = "Battlefield"
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    83
	-- The theme to be used
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    84
	Theme = "Castle"
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    85
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    86
	-- Create the player team
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    87
	AddTeam(loc("Grenadiers"), 14483456, "Simple", "Island", "Default")
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    88
	-- And add a hog to it
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    89
	player = AddHog(loc("Nade Boy"), 0, 1, "war_grenadier1")
7877
b3fb94986255 Fix training script positions altered by variable land dimension change. Issue #453
nemo
parents: 7165
diff changeset
    90
	SetGearPosition(player, 506, 76)
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    91
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    92
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    93
-- This function is called when the round starts
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    94
-- it spawns the first target that has to be destroyed.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    95
-- In addition it shows the scenario goal(s).
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    96
function onGameStart()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    97
	-- Spawn the first target.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    98
	spawnTarget()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    99
	
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   100
	-- Show some nice mission goals.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   101
	-- Parameters are: caption, sub caption, description,
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   102
	-- extra text, icon and time to show.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   103
	-- A negative icon parameter (-n) represents the n-th weapon icon
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   104
	-- A positive icon paramter (n) represents the (n+1)-th mission icon
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   105
	-- A timeframe of 0 is replaced with the default time to show.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   106
	ShowMission(loc("Grenade Training"), loc("Aiming Practice"), loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission."), -amGrenade, 0)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   107
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   108
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   109
function onNewTurn()
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 8043
diff changeset
   110
	SetWeapon(amGrenade)
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   111
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   112
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   113
-- This function is called every game tick.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   114
-- Note that there are 1000 ticks within one second.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   115
-- You shouldn't try to calculate too complicated
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   116
-- code here as this might slow down your game.
7165
aad1aea05f1e add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents: 7094
diff changeset
   117
function onGameTick20()
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   118
	-- If time's up, set the game to be lost.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   119
	-- We actually check the time to be "1 ms" as it
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   120
	-- will be at "0 ms" right at the start of the game.
7165
aad1aea05f1e add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents: 7094
diff changeset
   121
	if TurnTimeLeft < 40 and TurnTimeLeft > 0 and score < score_goal then
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   122
		game_lost = true
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   123
		-- ... and show a short message.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   124
		ShowMission(loc("Grenade Training"), loc("Aiming Practice"), loc("Oh no! Time's up! Just try again."), -amSkip, 0)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   125
		-- How about killing our poor hog due to his poor performance?
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   126
		SetHealth(player, 0)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   127
		-- Just to be sure set the goal time to 1 ms
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   128
		time_goal = 1
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   129
	end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   130
	-- If the goal is reached or we've lost ...
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   131
	if score == score_goal or game_lost then
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   132
		-- ... check to see if the time we'd like to
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   133
		-- wait has passed and then ...
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   134
		if end_timer == 0 then
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   135
			-- Override the 'Draw' message with the appropriate message.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   136
			if game_lost then
11248
94c0085ddac6 - Rus localization update for Basic Trainings in ru.lua
antonc27 <antonc27@mail.ru>
parents: 10590
diff changeset
   137
				AddCaption(loc("Mission lost!"), 0xffba00ff,capgrpGameState)
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   138
			else
11248
94c0085ddac6 - Rus localization update for Basic Trainings in ru.lua
antonc27 <antonc27@mail.ru>
parents: 10590
diff changeset
   139
				AddCaption(loc("Mission won!"), 0xffba00ff,capgrpGameState)
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   140
			end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   141
			-- Remove the team to end the game. Only do this once.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   142
			if team_death == false then
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   143
				team_death = true
10590
3c649bf438a3 fix for Issue 840: Basic Training - Grenade is failing to dismiss team
sheepluva
parents: 10290
diff changeset
   144
				DismissTeam(loc("Grenadiers"))
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   145
			end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   146
		else
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   147
			-- ... or just lower the timer by 1.
7165
aad1aea05f1e add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents: 7094
diff changeset
   148
			end_timer = end_timer - 20
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   149
			-- Reset the time left to stop the timer
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   150
			TurnTimeLeft = time_goal
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   151
		end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   152
	end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   153
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   154
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   155
-- This function is called when the game is initialized
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   156
-- to request the available ammo and probabilities
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   157
function onAmmoStoreInit()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   158
	-- add an unlimited supply of bazooka ammo
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   159
	SetAmmo(amGrenade, 9, 0, 0, 0)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   160
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   161
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   162
-- This function is called when a new gear is added.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   163
-- We don't need it for this training, so we can
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   164
-- keep it empty.
7165
aad1aea05f1e add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents: 7094
diff changeset
   165
-- function onGearAdd(gear)
aad1aea05f1e add onGameTick20 to basic training, extend laser sight out way more (it was visible at top when completely zoomed out), move call of new turn to after AfterSwitchHedgehog to avoid lua issues in onNewTurn - if this causes problems, lua can do delayed actions in onGameTick
nemo
parents: 7094
diff changeset
   166
-- end
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   167
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   168
-- This function is called before a gear is destroyed.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   169
-- We use it to count the number of targets destroyed.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   170
function onGearDelete(gear)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   171
	-- We're only interested in target gears.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   172
	if GetGearType(gear) == gtTarget then
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   173
		-- Add one point to our score/counter
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   174
		score = score + 1
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   175
		-- If we haven't reached the goal ...
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   176
		if score < score_goal then
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   177
			-- ... spawn another target.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   178
			spawnTarget()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   179
		else
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   180
			if not game_lost then
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   181
			-- Otherwise show that the goal was accomplished
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   182
			ShowMission(loc("Grenade Training"), loc("Aiming Practice"), loc("Congratulations! You've eliminated all targets|within the allowed time frame."), 0, 0)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   183
			-- Also let the hogs shout "victory!"
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   184
			PlaySound(sndVictory)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   185
			-- Save the time left so we may keep it.
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   186
			time_goal = TurnTimeLeft
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   187
			end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   188
		end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   189
	end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   190
end