share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua
author Wuzzy <almikes@aol.com>
Tue, 11 Apr 2017 02:44:59 +0200
changeset 12224 d62d6f8ebef1
parent 12049 030464f34d47
child 13075 730db0a3eb43
permissions -rw-r--r--
Disable Sudden Death consistently in all missions which don't require it
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"
12224
d62d6f8ebef1 Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents: 12049
diff changeset
    85
	-- Setting these 2 values to 0 is the official way to disable Sudden Death cleanly
d62d6f8ebef1 Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents: 12049
diff changeset
    86
	HealthDecrease = 0	-- Sudden Death damage
d62d6f8ebef1 Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents: 12049
diff changeset
    87
	WaterRise = 0		-- Water rise in Sudden Death
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    88
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    89
	-- Create the player team
12049
030464f34d47 Tweak flags used in all missions to fit more to the theme
Wuzzy <almikes@aol.com>
parents: 11244
diff changeset
    90
	AddTeam(loc("Grenadiers"), 14483456, "Simple", "Island", "Default", "cm_grenade")
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    91
	-- 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
    92
	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
    93
	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
    94
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    95
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    96
-- 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
    97
-- 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
    98
-- 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
    99
function onGameStart()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   100
	-- 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
   101
	spawnTarget()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   102
	
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   103
	-- 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
   104
	-- 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
   105
	-- 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
   106
	-- 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
   107
	-- 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
   108
	-- 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
   109
	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
   110
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   111
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   112
function onNewTurn()
10289
c3a77ff02a23 lua api: SetWeapon(ammoType)
sheepluva
parents: 8043
diff changeset
   113
	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
   114
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   115
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   116
-- 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
   117
-- 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
   118
-- 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
   119
-- 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
   120
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
   121
	-- 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
   122
	-- 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
   123
	-- 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
   124
	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
   125
		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
   126
		-- ... 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
   127
		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
   128
		-- 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
   129
		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
   130
		-- 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
   131
		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
   132
	end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   133
	-- 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
   134
	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
   135
		-- ... 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
   136
		-- 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
   137
		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
   138
			-- 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
   139
			if game_lost then
11244
94c0085ddac6 - Rus localization update for Basic Trainings in ru.lua
antonc27 <antonc27@mail.ru>
parents: 10590
diff changeset
   140
				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
   141
			else
11244
94c0085ddac6 - Rus localization update for Basic Trainings in ru.lua
antonc27 <antonc27@mail.ru>
parents: 10590
diff changeset
   142
				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
   143
			end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   144
			-- 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
   145
			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
   146
				team_death = true
10590
3c649bf438a3 fix for Issue 840: Basic Training - Grenade is failing to dismiss team
sheepluva
parents: 10290
diff changeset
   147
				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
   148
			end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   149
		else
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   150
			-- ... 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
   151
			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
   152
			-- 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
   153
			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
   154
		end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   155
	end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   156
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   157
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   158
-- 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
   159
-- 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
   160
function onAmmoStoreInit()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   161
	-- 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
   162
	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
   163
end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   164
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   165
-- 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
   166
-- 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
   167
-- 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
   168
-- 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
   169
-- end
7094
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   170
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   171
-- 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
   172
-- 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
   173
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
   174
	-- 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
   175
	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
   176
		-- 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
   177
		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
   178
		-- 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
   179
		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
   180
			-- ... 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
   181
			spawnTarget()
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   182
		else
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   183
			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
   184
			-- 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
   185
			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
   186
			-- 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
   187
			PlaySound(sndVictory)
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   188
			-- 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
   189
			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
   190
			end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   191
		end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   192
	end
f5a5578be66b A few scripts to try out. 2x challenge, 1x GSoC training, 1x user mission.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   193
end