share/hedgewars/Data/Scripts/TargetPractice.lua
changeset 14591 b4089fa16b34
parent 14590 c5f18710a184
child 14593 c3bbe56156e5
equal deleted inserted replaced
14590:c5f18710a184 14591:b4089fa16b34
   270 			end
   270 			end
   271 		end
   271 		end
   272 	end
   272 	end
   273 
   273 
   274 	_G.generateStats = function()
   274 	_G.generateStats = function()
   275 		local accuracy = (scored/shots)*100
   275 		local accuracy, accuracy_int
       
   276 		if(shots > 0) then
       
   277 			accuracy = (scored/shots)*100
       
   278 			accuracy_int = div(scored*100, shots)
       
   279 		end
   276 		local end_score_targets = getTargetsScore()
   280 		local end_score_targets = getTargetsScore()
   277 		local end_score_overall
   281 		local end_score_overall
   278 		if not game_lost then
   282 		if not game_lost then
   279 			local end_score_time = math.ceil(time_goal/(params.time/6000))
   283 			local end_score_time = math.ceil(time_goal/(params.time/6000))
   280 			local end_score_accuracy = math.ceil(accuracy * 60)
   284 			local end_score_accuracy = 0
       
   285 			if(shots > 0) then
       
   286 				end_score_accuracy = math.ceil(accuracy * 60)
       
   287 			end
   281 			end_score_overall = end_score_time + end_score_targets + end_score_accuracy
   288 			end_score_overall = end_score_time + end_score_targets + end_score_accuracy
   282 			SetTeamLabel(GetHogTeamName(player), tostring(end_score_overall))
   289 			SetTeamLabel(GetHogTeamName(player), tostring(end_score_overall))
   283 
   290 
   284 			SendStat(siGameResult, loc("You have finished the target practice!"))
   291 			SendStat(siGameResult, loc("You have finished the target practice!"))
   285 
   292 
   286 			SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), scored, total_targets, end_score_targets))
   293 			SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), scored, total_targets, end_score_targets))
   287 			SendStat(siCustomAchievement, string.format(params.shootText, shots))
   294 			SendStat(siCustomAchievement, string.format(params.shootText, shots))
   288 			SendStat(siCustomAchievement, string.format(loc("Your accuracy was %.1f%% (+%d points)."), accuracy, end_score_accuracy))
   295 			if(shots > 0) then
       
   296 				SendStat(siCustomAchievement, string.format(loc("Your accuracy was %.1f%% (+%d points)."), accuracy, end_score_accuracy))
       
   297 			end
   289 			SendStat(siCustomAchievement, string.format(loc("You had %.1fs remaining on the clock (+%d points)."), (time_goal/1000), end_score_time))
   298 			SendStat(siCustomAchievement, string.format(loc("You had %.1fs remaining on the clock (+%d points)."), (time_goal/1000), end_score_time))
       
   299 
       
   300 			if(shots > 0) then
       
   301 				updateChallengeRecord("AccuracyRecord", accuracy_int)
       
   302 			end
   290 		else
   303 		else
   291 			SendStat(siGameResult, loc("Challenge over!"))
   304 			SendStat(siGameResult, loc("Challenge over!"))
   292 
   305 
   293 			SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), scored, total_targets, end_score_targets))
   306 			SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), scored, total_targets, end_score_targets))
   294 			SendStat(siCustomAchievement, string.format(params.shootText, shots))
   307 			SendStat(siCustomAchievement, string.format(params.shootText, shots))