share/hedgewars/Data/Scripts/SpeedShoppa.lua
author Wuzzy <Wuzzy2@mail.ru>
Sat, 24 Feb 2018 14:59:35 +0100
changeset 13065 a297e06d1607
parent 13034 fe9c12209f15
child 13066 ad75ed9a1e15
permissions -rw-r--r--
Display score next to team bar in singleplayer challenges
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
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    24
HedgewarsScriptLoad("/Scripts/Locale.lua")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    25
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
SpeedShoppaMission(params)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    28
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    29
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
    30
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
    31
	mandatory fields:
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    32
	- map:			the name of the map to be used
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    33
	- 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
    34
	- time:			the time limit in milliseconds
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    35
	- crates:		The coordinates of where the crates will be spawned.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    36
				It is a table containing tables containing coordinates of format
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    37
				{ x=value, y=value }. Example:
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    38
					crates = {
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    39
						{ x = 324, y = 43 },
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    40
						{ x = 123, y = 56 },
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    41
						{ x = 6, y = 0 },
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    42
					}
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    43
				There must be at least 1 crate.
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    44
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    45
	optional fields:
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    46
	- missionTitle:		the name of the mission (optional but highly recommended) (default: "Speed Shoppa")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    47
	- hogHat:		hat of the hedgehog (default: "NoHat")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    48
	- hogName:		name of the hedgehog (default: "Roper")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    49
	- teamName:		name of the hedgehog’s team (default: "Shoppers")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    50
	- teamGrave:		name of the hedgehog’s grave (default: "Statue")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    51
	- teamFlag:		name of the team’s flag (default: "cm_shoppa")
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    52
	- clanColor:		color of the (only) clan (default: 0xFF0204, which is a red tone)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    53
	- goalText:		A short string explaining the goal of the mission
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    54
				(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
    55
	- 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
    56
				(default: false (=right))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    57
	- 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
    58
				"ammo", "utility", "health". Default: "ammo"
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    59
	- 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
    60
				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
    61
	- 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
    62
]]
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    63
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    64
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    65
local playerHog
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    66
local gameStarted = false
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    67
local cratesCollected = 0
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    68
local gameEnded = false
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    69
local timeOut = false
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    70
local hogHurt = false
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    71
local endTime
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    72
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    73
local crates
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    74
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    75
function SpeedShoppaMission(params)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    76
	if params.hogHat == nil then params.hogHat = "NoHat" end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    77
	if params.hogName == nil then params.hogName = loc("Roper") end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    78
	if params.teamName == nil then params.teamName = loc("Shoppers") end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    79
	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
    80
	if params.missionTitle == nil then params.missionTitle = loc("Speed Shoppa") end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    81
	if params.clanColor == nil then params.clanColor = 0xFF0204 end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    82
	if params.teamGrave == nil then params.teamGrave = "Statue" end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    83
	if params.teamFlag == nil then params.teamFlag = "cm_shoppa" end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    84
	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
    85
	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
    86
	if params.faceLeft == nil then params.faceLeft = false end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    87
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    88
	crates = params.crates
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    89
	startTime = params.time
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    90
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    91
	_G.onGameInit = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    92
		GameFlags = gfDisableWind + gfOneClanMode + gfBorder + gfSolidLand
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    93
		TurnTime = startTime
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    94
		CaseFreq = 0 
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    95
		MinesNum = 0 
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    96
		Explosives = 0 
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    97
		Delay = 10 
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    98
		Theme = params.theme
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
    99
		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
   100
		-- Disable Sudden Death
d62d6f8ebef1 Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents: 11034
diff changeset
   101
		WaterRise = 0
d62d6f8ebef1 Disable Sudden Death consistently in all missions which don't require it
Wuzzy <almikes@aol.com>
parents: 11034
diff changeset
   102
		HealthDecrease = 0
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   103
	
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   104
		AddTeam(params.teamName, params.clanColor, params.teamGrave, "Castle", "Default", params.teamFlag)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   105
		playerHog = AddHog(params.hogName, 0, 1, params.hogHat)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   106
		HogTurnLeft(playerHog, params.faceLeft)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   107
		
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   108
		SetGearPosition(playerHog, params.hog_x, params.hog_y)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   109
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   110
		params.extra_onGameInit()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   111
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   112
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   113
	_G.onAmmoStoreInit = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   114
		SetAmmo(amRope, 9, 0, 0, 1)
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
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   117
	_G.onGameStart = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   118
		SendHealthStatsOff()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   119
		ShowMission(params.missionTitle, loc("Challenge"), params.goalText, -amRope, 5000) 
13065
a297e06d1607 Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 13034
diff changeset
   120
		-- <crates collected>/<total number of crates>
a297e06d1607 Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 13034
diff changeset
   121
		SetTeamLabel(params.teamName, string.format(loc("%d/%d"), cratesCollected, #crates))
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   122
		for i=1,#crates do
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   123
			spawnCrate(crates[i].x, crates[i].y)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   124
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   125
		params.extra_onGameStart()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   126
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   127
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   128
	_G.onNewTurn = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   129
		SetWeapon(amRope)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   130
		gameStarted = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   131
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   132
	_G.onGearDelete = function(gear)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   133
		if GetGearType(gear) == gtCase and not hogHurt and not timeOut then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   134
			cratesCollected = cratesCollected + 1
13065
a297e06d1607 Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 13034
diff changeset
   135
			-- <crates collected>/<total number of crates>
a297e06d1607 Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents: 13034
diff changeset
   136
			SetTeamLabel(params.teamName, string.format(loc("%d/%d"), cratesCollected, #crates))
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   137
			PlaySound(sndShotgunReload)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   138
			if cratesCollected == #crates then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   139
				endTime = TurnTimeLeft
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   140
				finalize()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   141
			else
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   142
				AddCaption(string.format(loc("%d crate(s) remaining"), #crates - cratesCollected))
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
		elseif gear == playerHog then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   145
			finalize()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   146
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   147
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   148
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   149
	_G.onGearDamage = function(gear)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   150
		if gear == playerHog then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   151
			hogHurt = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   152
		end
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
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.onGameTick20 = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   157
		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
   158
			timeOut = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   159
			AddCaption(loc("Time's up!"))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   160
			SetHealth(playerHog, 0)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   161
			hogHurt = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   162
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   163
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   164
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   165
	_G.finalize = function()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   166
		if not gameEnded then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   167
			if cratesCollected == #crates then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   168
				PlaySound(sndVictory, playerHog)
13034
fe9c12209f15 Make hog invulnerable after winning SpeedShoppa or TargetPractice mission
Wuzzy <Wuzzy2@mail.ru>
parents: 12224
diff changeset
   169
				SetEffect(playerHog, heInvulnerable, 1)
11034
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   170
				SetState(playerHog, bor(GetState(playerHog), gstWinner))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   171
				SetState(playerHog, band(GetState(playerHog), bnot(gstHHDriven)))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   172
				AddCaption(loc("Challenge completed!"))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   173
				SendStat(siGameResult, loc("Challenge completed!"))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   174
				SendStat(siPointType, loc("milliseconds"))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   175
				local time = startTime - endTime
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   176
				SendStat(siPlayerKills, tostring(time), params.teamName)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   177
				SendStat(siCustomAchievement, string.format(loc("You have finished the challenge in %.3f s."), (time/1000)))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   178
				TurnTimeLeft = 0
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   179
			else
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   180
				SendStat(siGameResult, loc("Challenge failed!"))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   181
				SendStat(siPointType, loc("crate(s)"))
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   182
				SendStat(siPlayerKills, tostring(cratesCollected), params.teamName)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   183
				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
   184
			end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   185
			gameEnded = true
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   186
			EndGame()
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   187
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   188
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   189
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   190
	_G.spawnCrate = function(x, y)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   191
		if params.crateType == "utility" then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   192
			SpawnFakeUtilityCrate(x, y, false, false)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   193
		elseif params.crateType == "ammo" then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   194
			SpawnFakeAmmoCrate(x, y, false, false)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   195
		elseif params.crateType == "health" then
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   196
			SpawnFakeHealthCrate(x, y, false, false)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   197
		else
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   198
			SpawnFakeAmmoCrate(x, y, false, false)
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   199
		end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   200
	end
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   201
a9bafac12634 Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff changeset
   202
end