share/hedgewars/Data/Scripts/SpeedShoppa.lua
author Wuzzy <Wuzzy2@mail.ru>
Thu, 18 Jul 2019 03:39:58 +0200
changeset 15273 515a4a317e52
parent 15035 f877fbeaee6c
permissions -rw-r--r--
CTF: Fix clan not winning if enemy hog was time-travelling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     1
--[=[
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     2
Speed Shoppa Mission Framework for Hedgewars
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     3
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     4
This is a simple library intended to make setting up simple training missions a trivial
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     5
task. The library has been created to reduce redundancy in Lua scripts.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     6
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     7
The framework generates complete and fully Speed Shoppa missions by just
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     8
one function call.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
     9
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    10
The missions generated by this script are all the same:
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    11
- The player will get a team with a single hedgehog.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    12
- The team gets infinite ropes.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    13
- A fixed set of crates will spawn at predefined positions.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    14
- The mission ends successfully when all crates have been collected
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    15
- The mission ends unsuccessfully when the time runs out or the hedgehog dies
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    16
- When the mission ends, the time it took to finish the mission is shown
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    17
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    18
To use this library, you first have to load it and to call SpeedShoppaMission once with
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    19
the appropriate parameters. Really, that’s all!
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    20
See the comment of SpeedShoppaMission for a specification of all parameters.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    21
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    22
]=]
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    23
14496
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14485
diff changeset
    24
HedgewarsScriptLoad("/Scripts/Utils.lua")
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    25
HedgewarsScriptLoad("/Scripts/Locale.lua")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    26
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    27
--[[
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    28
SpeedShoppaMission(params)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    29
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    30
This function sets up the *entire* mission and needs one argument: params.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    31
The argument “params” is a table containing fields which describe the training mission.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    32
	mandatory fields:
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    33
	- map:			the name of the map to be used
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    34
	- theme:		the name of the theme (does not need to be a standalone theme)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    35
	- time:			the time limit in milliseconds
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    36
	- crates:		The coordinates of where the crates will be spawned.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    37
				It is a table containing tables containing coordinates of format
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    38
				{ x=value, y=value }. Example:
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    39
					crates = {
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    40
						{ x = 324, y = 43 },
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    41
						{ x = 123, y = 56 },
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    42
						{ x = 6, y = 0 },
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    43
					}
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    44
				There must be at least 1 crate.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    45
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    46
	optional fields:
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    47
	- missionTitle:		the name of the mission (optional but highly recommended) (default: "Speed Shoppa")
13583
141cdfe0f3ca Switch almost all Lua calls of AddTeam to using default clan colors instead of hardcoded color
Wuzzy <Wuzzy2@mail.ru>
parents: 13066
diff changeset
    48
	- clanColor:		color of the (only) clan (default: -1, default first clan color)
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    49
	- goalText:		A short string explaining the goal of the mission
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    50
				(default: "Use your rope to collect all crates as fast as possible.")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    51
	- faceLeft:		If true, the hog faces to the left initially, if false, it faces to the right.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    52
				(default: false (=right))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    53
	- crateType		Specify the type of crate (this has no gameplay effect), pick one of
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    54
				"ammo", "utility", "health". Default: "ammo"
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    55
	- extra_onGameStart:	A function which is called at the end of this script's onGameStart. It takes no parameters.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    56
				You could use this to spawn additional gears like girders or mines.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    57
	- extra_onGameInit:	A function which is called at the end of this script's onGameInit.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    58
]]
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    59
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    60
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    61
local playerHog
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    62
local gameStarted = false
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    63
local cratesCollected = 0
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    64
local gameEnded = false
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    65
local timeOut = false
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    66
local hogHurt = false
14252
74bf2d906097 Turn accidental globals to locals in Lua libraries
Wuzzy <Wuzzy2@mail.ru>
parents: 13742
diff changeset
    67
local startTime, endTime
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    68
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    69
local crates
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    70
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    71
function SpeedShoppaMission(params)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    72
	if params.goalText == nil then params.goalText = loc("Use your rope to collect all crates as fast as possible.") end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    73
	if params.missionTitle == nil then params.missionTitle = loc("Speed Shoppa") end
13583
141cdfe0f3ca Switch almost all Lua calls of AddTeam to using default clan colors instead of hardcoded color
Wuzzy <Wuzzy2@mail.ru>
parents: 13066
diff changeset
    74
	if params.clanColor == nil then params.clanColor = -1 end
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    75
	if params.extra_onGameInit == nil then params.extra_onGameInit = function() end end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    76
	if params.extra_onGameStart == nil then params.extra_onGameStart = function() end end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    77
	if params.faceLeft == nil then params.faceLeft = false end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    78
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    79
	crates = params.crates
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    80
	startTime = params.time
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    81
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    82
	_G.onGameInit = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    83
		GameFlags = gfDisableWind + gfOneClanMode + gfBorder + gfSolidLand
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    84
		TurnTime = startTime
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    85
		CaseFreq = 0 
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    86
		MinesNum = 0 
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    87
		Explosives = 0 
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    88
		Theme = params.theme
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    89
		Map = params.map
12224
d62d6f8ebef1 Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents: 11034
diff changeset
    90
		-- Disable Sudden Death
d62d6f8ebef1 Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents: 11034
diff changeset
    91
		WaterRise = 0
d62d6f8ebef1 Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents: 11034
diff changeset
    92
		HealthDecrease = 0
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    93
	
14501
208359558642 Use player-chosen team identity for training and a few challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14496
diff changeset
    94
		AddMissionTeam(params.clanColor)
208359558642 Use player-chosen team identity for training and a few challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14496
diff changeset
    95
		playerHog = AddMissionHog(1)
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    96
		HogTurnLeft(playerHog, params.faceLeft)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    97
		
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    98
		SetGearPosition(playerHog, params.hog_x, params.hog_y)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    99
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   100
		params.extra_onGameInit()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   101
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   102
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   103
	_G.onAmmoStoreInit = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   104
		SetAmmo(amRope, 9, 0, 0, 1)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   105
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   106
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   107
	_G.onGameStart = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   108
		SendHealthStatsOff()
14496
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14485
diff changeset
   109
		local append = getReadableChallengeRecord("TimeRecord")
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14485
diff changeset
   110
		ShowMission(params.missionTitle, loc("Challenge"), params.goalText .. "|" .. append, -amRope, 5000)
13065
a297e06d1607 Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 13034
diff changeset
   111
		-- <crates collected>/<total number of crates>
14501
208359558642 Use player-chosen team identity for training and a few challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14496
diff changeset
   112
		SetTeamLabel(GetHogTeamName(playerHog), string.format(loc("%d/%d"), cratesCollected, #crates))
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   113
		for i=1,#crates do
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   114
			spawnCrate(crates[i].x, crates[i].y)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   115
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   116
		params.extra_onGameStart()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   117
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   118
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   119
	_G.onNewTurn = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   120
		SetWeapon(amRope)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   121
		gameStarted = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   122
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   123
	_G.onGearDelete = function(gear)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   124
		if GetGearType(gear) == gtCase and not hogHurt and not timeOut then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   125
			cratesCollected = cratesCollected + 1
13065
a297e06d1607 Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 13034
diff changeset
   126
			-- <crates collected>/<total number of crates>
14501
208359558642 Use player-chosen team identity for training and a few challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14496
diff changeset
   127
			SetTeamLabel(GetHogTeamName(playerHog), string.format(loc("%d/%d"), cratesCollected, #crates))
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   128
			PlaySound(sndShotgunReload)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   129
			if cratesCollected == #crates then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   130
				endTime = TurnTimeLeft
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   131
				finalize()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   132
			else
13066
ad75ed9a1e15 RC Plane Challenge: Switch to using fake crates only
Wuzzy <Wuzzy2@mail.ru>
parents: 13065
diff changeset
   133
				AddCaption(string.format(loc("Crates left: %d"), #crates - cratesCollected))
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   134
			end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   135
		elseif gear == playerHog then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   136
			finalize()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   137
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   138
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   139
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   140
	_G.onGearDamage = function(gear)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   141
		if gear == playerHog then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   142
			hogHurt = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   143
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   144
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   145
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   146
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   147
	_G.onGameTick20 = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   148
		if TurnTimeLeft < 40 and TurnTimeLeft > 0 and gameStarted and not timeOut and not gameEnded then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   149
			timeOut = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   150
			AddCaption(loc("Time's up!"))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   151
			SetHealth(playerHog, 0)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   152
			hogHurt = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   153
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   154
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   155
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   156
	_G.finalize = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   157
		if not gameEnded then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   158
			if cratesCollected == #crates then
14485
ead8928a59f8 Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents: 14422
diff changeset
   159
				SaveMissionVar("Won", "true")
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   160
				PlaySound(sndVictory, playerHog)
13034
fe9c12209f15 Make hog invulnerable after winning SpeedShoppa or TargetPractice mission
Wuzzy <Wuzzy2@mail.ru>
parents: 12224
diff changeset
   161
				SetEffect(playerHog, heInvulnerable, 1)
15035
f877fbeaee6c Speed Shoppa: Set hog dy=0 on victory
Wuzzy <Wuzzy2@mail.ru>
parents: 14949
diff changeset
   162
				local dx, dy = GetGearVelocity(playerHog)
f877fbeaee6c Speed Shoppa: Set hog dy=0 on victory
Wuzzy <Wuzzy2@mail.ru>
parents: 14949
diff changeset
   163
				SetGearVelocity(playerHog, 0, dy)
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   164
				AddCaption(loc("Challenge completed!"))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   165
				SendStat(siGameResult, loc("Challenge completed!"))
14599
50f511588635 Outsource commonly used words in siPointType to QTfrontend
Wuzzy <Wuzzy2@mail.ru>
parents: 14501
diff changeset
   166
				SendStat(siPointType, "!TIME")
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   167
				local time = startTime - endTime
14501
208359558642 Use player-chosen team identity for training and a few challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14496
diff changeset
   168
				SendStat(siPlayerKills, tostring(time), GetHogTeamName(playerHog))
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   169
				SendStat(siCustomAchievement, string.format(loc("You have finished the challenge in %.3f s."), (time/1000)))
13742
2bb7141496a9 Use SetTurnTimeLeft and SetReadyTimeLeft in all scripts
Wuzzy <Wuzzy2@mail.ru>
parents: 13583
diff changeset
   170
				SetTurnTimeLeft(0)
14496
2113296b7a29 Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14485
diff changeset
   171
				updateChallengeRecord("TimeRecord", time)
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   172
			else
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   173
				SendStat(siGameResult, loc("Challenge failed!"))
14599
50f511588635 Outsource commonly used words in siPointType to QTfrontend
Wuzzy <Wuzzy2@mail.ru>
parents: 14501
diff changeset
   174
				SendStat(siPointType, "!CRATES")
14501
208359558642 Use player-chosen team identity for training and a few challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 14496
diff changeset
   175
				SendStat(siPlayerKills, tostring(cratesCollected), GetHogTeamName(playerHog))
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   176
				SendStat(siCustomAchievement, string.format(loc("You have collected %d out of %d crate(s)."), cratesCollected, #crates))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   177
			end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   178
			gameEnded = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   179
			EndGame()
14949
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14781
diff changeset
   180
			if cratesCollected == #crates then
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14781
diff changeset
   181
				SetState(playerHog, gstWinner)
4c5fb1ee75b7 Add winner animation for missions that didn't have it
Wuzzy <Wuzzy2@mail.ru>
parents: 14781
diff changeset
   182
			end
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   183
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   184
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   185
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   186
	_G.spawnCrate = function(x, y)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   187
		if params.crateType == "utility" then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   188
			SpawnFakeUtilityCrate(x, y, false, false)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   189
		elseif params.crateType == "ammo" then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   190
			SpawnFakeAmmoCrate(x, y, false, false)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   191
		elseif params.crateType == "health" then
14781
75bd27700837 Update health crate tooltips in missions with fake health crates
Wuzzy <Wuzzy2@mail.ru>
parents: 14599
diff changeset
   192
			local crate = SpawnFakeHealthCrate(x, y, false, false)
75bd27700837 Update health crate tooltips in missions with fake health crates
Wuzzy <Wuzzy2@mail.ru>
parents: 14599
diff changeset
   193
			SetGearValues(crate, nil, nil, nil, nil, nil, 0) -- Karma
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   194
		else
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   195
			SpawnFakeAmmoCrate(x, y, false, false)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   196
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   197
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   198
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   199
end