author | Wuzzy <Wuzzy2@mail.ru> |
Wed, 19 Dec 2018 05:50:02 +0100 | |
changeset 14480 | 2113296b7a29 |
parent 14469 | ead8928a59f8 |
child 14485 | 208359558642 |
permissions | -rw-r--r-- |
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 |
|
14480
2113296b7a29
Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents:
14469
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") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
48 |
- hogHat: hat of the hedgehog (default: "NoHat") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
49 |
- hogName: name of the hedgehog (default: "Roper") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
50 |
- teamName: name of the hedgehog’s team (default: "Shoppers") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
51 |
- teamGrave: name of the hedgehog’s grave (default: "Statue") |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
52 |
- teamFlag: name of the team’s flag (default: "cm_shoppa") |
13588
141cdfe0f3ca
Switch almost all Lua calls of AddTeam to using default clan colors instead of hardcoded color
Wuzzy <Wuzzy2@mail.ru>
parents:
13071
diff
changeset
|
53 |
- 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
|
54 |
- goalText: A short string explaining the goal of the mission |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
55 |
(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
|
56 |
- 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
|
57 |
(default: false (=right)) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
58 |
- 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
|
59 |
"ammo", "utility", "health". Default: "ammo" |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
60 |
- 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
|
61 |
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
|
62 |
- 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
|
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 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
66 |
local playerHog |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
67 |
local gameStarted = false |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
68 |
local cratesCollected = 0 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
69 |
local gameEnded = false |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
70 |
local timeOut = false |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
71 |
local hogHurt = false |
14236
74bf2d906097
Turn accidental globals to locals in Lua libraries
Wuzzy <Wuzzy2@mail.ru>
parents:
13745
diff
changeset
|
72 |
local startTime, endTime |
11034
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
73 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
74 |
local crates |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
75 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
76 |
function SpeedShoppaMission(params) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
77 |
if params.hogHat == nil then params.hogHat = "NoHat" end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
78 |
if params.hogName == nil then params.hogName = loc("Roper") end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
79 |
if params.teamName == nil then params.teamName = loc("Shoppers") end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
80 |
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
|
81 |
if params.missionTitle == nil then params.missionTitle = loc("Speed Shoppa") end |
13588
141cdfe0f3ca
Switch almost all Lua calls of AddTeam to using default clan colors instead of hardcoded color
Wuzzy <Wuzzy2@mail.ru>
parents:
13071
diff
changeset
|
82 |
if params.clanColor == nil then params.clanColor = -1 end |
11034
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
83 |
if params.teamGrave == nil then params.teamGrave = "Statue" end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
84 |
if params.teamFlag == nil then params.teamFlag = "cm_shoppa" end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
if params.faceLeft == nil then params.faceLeft = false end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
88 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
89 |
crates = params.crates |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
90 |
startTime = params.time |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
91 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
92 |
_G.onGameInit = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
93 |
GameFlags = gfDisableWind + gfOneClanMode + gfBorder + gfSolidLand |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
94 |
TurnTime = startTime |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
95 |
CaseFreq = 0 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
96 |
MinesNum = 0 |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
97 |
Explosives = 0 |
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 |
12229
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() |
14480
2113296b7a29
Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents:
14469
diff
changeset
|
119 |
local append = getReadableChallengeRecord("TimeRecord") |
2113296b7a29
Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents:
14469
diff
changeset
|
120 |
ShowMission(params.missionTitle, loc("Challenge"), params.goalText .. "|" .. append, -amRope, 5000) |
13070
a297e06d1607
Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents:
13039
diff
changeset
|
121 |
-- <crates collected>/<total number of crates> |
a297e06d1607
Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents:
13039
diff
changeset
|
122 |
SetTeamLabel(params.teamName, string.format(loc("%d/%d"), cratesCollected, #crates)) |
11034
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
123 |
for i=1,#crates do |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
124 |
spawnCrate(crates[i].x, crates[i].y) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
125 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
126 |
params.extra_onGameStart() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
127 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
128 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
129 |
_G.onNewTurn = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
130 |
SetWeapon(amRope) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
131 |
gameStarted = true |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
132 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
133 |
_G.onGearDelete = function(gear) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
134 |
if GetGearType(gear) == gtCase and not hogHurt and not timeOut then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
135 |
cratesCollected = cratesCollected + 1 |
13070
a297e06d1607
Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents:
13039
diff
changeset
|
136 |
-- <crates collected>/<total number of crates> |
a297e06d1607
Display score next to team bar in singleplayer challenges
Wuzzy <Wuzzy2@mail.ru>
parents:
13039
diff
changeset
|
137 |
SetTeamLabel(params.teamName, string.format(loc("%d/%d"), cratesCollected, #crates)) |
11034
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
138 |
PlaySound(sndShotgunReload) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
139 |
if cratesCollected == #crates then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
140 |
endTime = TurnTimeLeft |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
141 |
finalize() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
142 |
else |
13071
ad75ed9a1e15
RC Plane Challenge: Switch to using fake crates only
Wuzzy <Wuzzy2@mail.ru>
parents:
13070
diff
changeset
|
143 |
AddCaption(string.format(loc("Crates left: %d"), #crates - cratesCollected)) |
11034
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 |
elseif gear == playerHog then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
146 |
finalize() |
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 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
149 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
150 |
_G.onGearDamage = function(gear) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
151 |
if gear == playerHog then |
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 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
157 |
_G.onGameTick20 = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
158 |
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
|
159 |
timeOut = true |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
160 |
AddCaption(loc("Time's up!")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
161 |
SetHealth(playerHog, 0) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
162 |
hogHurt = true |
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 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
165 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
166 |
_G.finalize = function() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
167 |
if not gameEnded then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
168 |
if cratesCollected == #crates then |
14469
ead8928a59f8
Report mission victory for most missions
Wuzzy <Wuzzy2@mail.ru>
parents:
14406
diff
changeset
|
169 |
SaveMissionVar("Won", "true") |
11034
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
170 |
PlaySound(sndVictory, playerHog) |
13039
fe9c12209f15
Make hog invulnerable after winning SpeedShoppa or TargetPractice mission
Wuzzy <Wuzzy2@mail.ru>
parents:
12229
diff
changeset
|
171 |
SetEffect(playerHog, heInvulnerable, 1) |
11034
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
172 |
SetState(playerHog, bor(GetState(playerHog), gstWinner)) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
173 |
SetState(playerHog, band(GetState(playerHog), bnot(gstHHDriven))) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
174 |
AddCaption(loc("Challenge completed!")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
175 |
SendStat(siGameResult, loc("Challenge completed!")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
176 |
SendStat(siPointType, loc("milliseconds")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
177 |
local time = startTime - endTime |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
178 |
SendStat(siPlayerKills, tostring(time), params.teamName) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
179 |
SendStat(siCustomAchievement, string.format(loc("You have finished the challenge in %.3f s."), (time/1000))) |
13745
2bb7141496a9
Use SetTurnTimeLeft and SetReadyTimeLeft in all scripts
Wuzzy <Wuzzy2@mail.ru>
parents:
13588
diff
changeset
|
180 |
SetTurnTimeLeft(0) |
14480
2113296b7a29
Keep track of singleplayer high scores in challenges
Wuzzy <Wuzzy2@mail.ru>
parents:
14469
diff
changeset
|
181 |
updateChallengeRecord("TimeRecord", time) |
11034
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
182 |
else |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
183 |
SendStat(siGameResult, loc("Challenge failed!")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
184 |
SendStat(siPointType, loc("crate(s)")) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
185 |
SendStat(siPlayerKills, tostring(cratesCollected), params.teamName) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
186 |
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
|
187 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
188 |
gameEnded = true |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
189 |
EndGame() |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
190 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
191 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
192 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
193 |
_G.spawnCrate = function(x, y) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
194 |
if params.crateType == "utility" then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
195 |
SpawnFakeUtilityCrate(x, y, false, false) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
196 |
elseif params.crateType == "ammo" then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
197 |
SpawnFakeAmmoCrate(x, y, false, false) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
198 |
elseif params.crateType == "health" then |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
199 |
SpawnFakeHealthCrate(x, y, false, false) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
200 |
else |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
201 |
SpawnFakeAmmoCrate(x, y, false, false) |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
202 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
203 |
end |
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
204 |
|
a9bafac12634
Add Wuzzy's SpeedShoppa challenges.
mikade <redgrinner@gmail.com>
parents:
diff
changeset
|
205 |
end |