60 local end_timer = 1000 |
60 local end_timer = 1000 |
61 local game_lost = false |
61 local game_lost = false |
62 local time_goal = 0 |
62 local time_goal = 0 |
63 local total_targets |
63 local total_targets |
64 local targets |
64 local targets |
|
65 local target_radar = false |
|
66 local next_target_circle = nil |
65 local gearsInGameCount = 0 |
67 local gearsInGameCount = 0 |
66 local gearsInGame = {} |
68 local gearsInGame = {} |
67 |
69 |
68 --[[ |
70 --[[ |
69 TrainingMission(params) |
71 TrainingMission(params) |
96 - clanColor: color of the (only) clan (default: -1, default first clan color) |
98 - clanColor: color of the (only) clan (default: -1, default first clan color) |
97 - goalText: A short string explaining the goal of the mission |
99 - goalText: A short string explaining the goal of the mission |
98 (default: "Destroy all targets within the time!") |
100 (default: "Destroy all targets within the time!") |
99 - shootText: A string which says how many times the player shot, ā%dā is replaced |
101 - shootText: A string which says how many times the player shot, ā%dā is replaced |
100 by the number of shots. (default: "You have shot %d times.") |
102 by the number of shots. (default: "You have shot %d times.") |
|
103 - useRadar Whether to use target radar (small circles that mark the position |
|
104 of the next target). (default: true). Note: Still needs to be unlocked. |
|
105 - radarTint: RGBA color of the target radar (default: 0x8080FFFF). Use this field |
|
106 if the target radar would be hard to see against the background. |
101 ]] |
107 ]] |
102 |
108 |
103 |
109 |
104 local getTargetsScore = function() |
110 local getTargetsScore = function() |
105 return scored * math.ceil(6000/#targets) |
111 return scored * math.ceil(6000/#targets) |
108 function TargetPracticeMission(params) |
114 function TargetPracticeMission(params) |
109 if params.goalText == nil then params.goalText = loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.") end |
115 if params.goalText == nil then params.goalText = loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.") end |
110 if params.shootText == nil then params.shootText = loc("You have shot %d times.") end |
116 if params.shootText == nil then params.shootText = loc("You have shot %d times.") end |
111 if params.clanColor == nil then params.clanColor = -1 end |
117 if params.clanColor == nil then params.clanColor = -1 end |
112 if params.wind == nil then params.wind = 0 end |
118 if params.wind == nil then params.wind = 0 end |
|
119 if params.radarTint == nil then params.radarTint = 0x8080FFFF end |
|
120 if params.useRadar == nil then params.useRadar = true end |
113 |
121 |
114 local solid, artillery |
122 local solid, artillery |
115 if params.solidLand == true then solid = gfSolidLand else solid = 0 end |
123 if params.solidLand == true then solid = gfSolidLand else solid = 0 end |
116 if params.artillery == true then artillery = gfArtillery else artillery = 0 end |
124 if params.artillery == true then artillery = gfArtillery else artillery = 0 end |
117 |
125 |
148 |
156 |
149 AddMissionTeam(params.clanColor) |
157 AddMissionTeam(params.clanColor) |
150 |
158 |
151 player = AddMissionHog(1) |
159 player = AddMissionHog(1) |
152 SetGearPosition(player, params.hog_x, params.hog_y) |
160 SetGearPosition(player, params.hog_x, params.hog_y) |
|
161 |
|
162 local won = GetMissionVar("Won") |
|
163 -- Unlock the target radar when the player has completed |
|
164 -- the target practice before (any score). |
|
165 -- Target radar might be disabled by config, however. |
|
166 if won == "true" and params.useRadar == true then |
|
167 target_radar = true |
|
168 end |
|
169 |
153 end |
170 end |
154 |
171 |
155 _G.onGameStart = function() |
172 _G.onGameStart = function() |
156 SendHealthStatsOff() |
173 SendHealthStatsOff() |
157 local recordInfo = getReadableChallengeRecord("Highscore") |
174 local recordInfo = getReadableChallengeRecord("Highscore") |
163 _G.onNewTurn = function() |
180 _G.onNewTurn = function() |
164 SetWeapon(params.ammoType) |
181 SetWeapon(params.ammoType) |
165 end |
182 end |
166 |
183 |
167 _G.spawnTarget = function() |
184 _G.spawnTarget = function() |
|
185 -- Spawn next target |
168 local gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0) |
186 local gear = AddGear(0, 0, gtTarget, 0, 0, 0, 0) |
169 |
187 |
170 local x = targets[scored+1].x |
188 local x = targets[scored+1].x |
171 local y = targets[scored+1].y |
189 local y = targets[scored+1].y |
172 |
190 |
173 SetGearPosition(gear, x, y) |
191 SetGearPosition(gear, x, y) |
|
192 |
|
193 -- Target radar: Highlight position of the upcoming target. |
|
194 -- This must be unlocked by the player first. |
|
195 if target_radar then |
|
196 if (not next_target_circle) and targets[scored+2] then |
|
197 next_target_circle = AddVisualGear(0,0,vgtCircle,90,true) |
|
198 end |
|
199 if targets[scored+2] then |
|
200 SetVisualGearValues(next_target_circle, targets[scored+2].x, targets[scored+2].y, 205, 255, 1, 20, nil, nil, 3, params.radarTint) |
|
201 elseif next_target_circle then |
|
202 DeleteVisualGear(next_target_circle) |
|
203 next_target_circle = nil |
|
204 end |
|
205 end |
174 |
206 |
175 return gear |
207 return gear |
176 end |
208 end |
177 |
209 |
178 _G.onGameTick20 = function() |
210 _G.onGameTick20 = function() |
294 SendStat(siCustomAchievement, string.format(params.shootText, shots)) |
326 SendStat(siCustomAchievement, string.format(params.shootText, shots)) |
295 if(shots > 0) then |
327 if(shots > 0) then |
296 SendStat(siCustomAchievement, string.format(loc("Your accuracy was %.1f%% (+%d points)."), accuracy, end_score_accuracy)) |
328 SendStat(siCustomAchievement, string.format(loc("Your accuracy was %.1f%% (+%d points)."), accuracy, end_score_accuracy)) |
297 end |
329 end |
298 SendStat(siCustomAchievement, string.format(loc("You had %.1fs remaining on the clock (+%d points)."), (time_goal/1000), end_score_time)) |
330 SendStat(siCustomAchievement, string.format(loc("You had %.1fs remaining on the clock (+%d points)."), (time_goal/1000), end_score_time)) |
|
331 if (not target_radar) and (#targets > 1) and (params.useRadar == true) then |
|
332 SendStat(siCustomAchievement, loc("You have unlocked the target radar!")) |
|
333 end |
299 |
334 |
300 if(shots > 0) then |
335 if(shots > 0) then |
301 updateChallengeRecord("AccuracyRecord", accuracy_int) |
336 updateChallengeRecord("AccuracyRecord", accuracy_int) |
302 end |
337 end |
303 else |
338 else |