# HG changeset patch
# User unc0rr
# Date 1377293840 -14400
# Node ID 0dceffbaa4ee67b19e9ca9b4e2570e56f457476d
# Parent  a6bb1fde2939e5c3d50924a8d6f7141f1f8cf2f3
Fix script flaw in detection of best team when sending achievement info

diff -r a6bb1fde2939 -r 0dceffbaa4ee hedgewars/uStats.pas
--- a/hedgewars/uStats.pas	Sat Aug 24 01:22:45 2013 +0400
+++ b/hedgewars/uStats.pas	Sat Aug 24 01:37:20 2013 +0400
@@ -309,8 +309,8 @@
 end;
 
 procedure declareAchievement(id, teamname, location: shortstring; value: LongInt);
-begin
-    if (length(id) = 0) or (length(teamname) = 0) then exit;
+begin 
+if (length(id) = 0) or (length(teamname) = 0) or (length(location) = 0) then exit;
     WriteLnToConsole('ACHIEVEMENT');
     WriteLnToConsole(id);
     WriteLnToConsole(teamname);
diff -r a6bb1fde2939 -r 0dceffbaa4ee share/hedgewars/Data/Maps/TrophyRace/map.lua
--- a/share/hedgewars/Data/Maps/TrophyRace/map.lua	Sat Aug 24 01:22:45 2013 +0400
+++ b/share/hedgewars/Data/Maps/TrophyRace/map.lua	Sat Aug 24 01:37:20 2013 +0400
@@ -31,6 +31,7 @@
 
 -- hog with best time
 local besthog = nil
+local besthogteam = ""
 
 -- hog with worst time (per round)
 local worsthog = nil
@@ -112,6 +113,7 @@
 			if ttime < besttime then
 				besttime = ttime
 				besthog = CurrentHedgehog
+                besthogteam = GetHogTeamName(besthog)
 				hscore = hscore .. loc("NEW fastest lap: ")
 			else
 				hscore = hscore .. loc("Fastest lap: ")
@@ -165,6 +167,6 @@
 
 function onAchievementsDeclaration()
     if besthog ~= nil then
-      DeclareAchievement("rope race", GetHogTeamName(besthog), "TrophyRace", besttime)
+      DeclareAchievement("rope race", besthogteam, "TrophyRace", besttime)
     end
 end