Declare achievements in console statistics output 0.9.19
authorunc0rr
Tue, 06 Aug 2013 00:26:07 +0400
branch0.9.19
changeset 9135 151c8e553de2
parent 9132 57ce31b696ff
child 9138 9e94a9bc8c7e
Declare achievements in console statistics output
gameServer/OfficialServer/checker.hs
hedgewars/uScript.pas
hedgewars/uStats.pas
share/hedgewars/Data/Maps/TrophyRace/map.lua
--- a/gameServer/OfficialServer/checker.hs	Tue Jun 11 11:48:36 2013 +0200
+++ b/gameServer/OfficialServer/checker.hs	Tue Aug 06 00:26:07 2013 +0400
@@ -30,7 +30,7 @@
     deriving Show
 
 serverAddress = "netserver.hedgewars.org"
-protocolNumber = "43"
+protocolNumber = "45"
 
 getLines :: Handle -> IO [String]
 getLines h = g
@@ -45,14 +45,16 @@
                 return $ fromJust l : lst
 
 
-engineListener :: Chan Message -> Handle -> IO ()
-engineListener coreChan h = do
+engineListener :: Chan Message -> Handle -> String -> IO ()
+engineListener coreChan h fileName = do
     output <- getLines h
     debugM "Engine" $ show output
     if isNothing $ L.find start output then
         writeChan coreChan $ CheckFailed "No stats msg"
         else
         writeChan coreChan $ CheckSuccess []
+
+    removeFile fileName
     where
         start = flip L.elem ["WINNERS", "DRAW"]
 
@@ -65,18 +67,16 @@
     hFlush h
     hClose h
 
-    (_, Just hOut, _, _) <- createProcess (proc "/usr/home/unC0Rr/Sources/Hedgewars/Releases/0.9.18/bin/hwengine"
-                ["/usr/home/unC0Rr/.hedgewars"
-                , "/usr/home/unC0Rr/Sources/Hedgewars/Releases/0.9.18/share/hedgewars/Data"
-                , fileName
-                , "--set-audio"
-                , "0"
-                , "0"
-                , "0"
+    (_, Just hOut, _, _) <- createProcess (proc "/usr/home/unC0Rr/Sources/Hedgewars/Releases/0.9.19/bin/hwengine"
+                [fileName
+                , "--user-prefix", "/usr/home/unC0Rr/.hedgewars"
+                , "--prefix", "/usr/home/unC0Rr/Sources/Hedgewars/Releases/0.9.19/share/hedgewars/Data"
+                , "--nomusic"
+                , "--nosound"
                 ])
             {std_out = CreatePipe}
     hSetBuffering hOut LineBuffering
-    void $ forkIO $ engineListener coreChan hOut
+    void $ forkIO $ engineListener coreChan hOut fileName
 
 
 takePacks :: State B.ByteString [[B.ByteString]]
--- a/hedgewars/uScript.pas	Tue Jun 11 11:48:36 2013 +0200
+++ b/hedgewars/uScript.pas	Tue Aug 06 00:26:07 2013 +0400
@@ -1835,6 +1835,17 @@
         ScriptLoad(lua_tostring(L, 1));
     lc_hedgewarsscriptload:= 0;
 end;
+
+
+function lc_declareachievement(L : Plua_State) : LongInt; Cdecl;
+var gear: PGear;
+begin
+    if lua_gettop(L) <> 3 then
+        LuaError('Lua: Wrong number of parameters passed to DeclareAchievement!')
+    else
+        declareAchievement(lua_tostring(L, 1), lua_tostring(L, 2), lua_tointeger(L, 3));
+    lc_declareachievement:= 0
+end;
 ///////////////////
 
 procedure ScriptPrintStack;
@@ -2451,6 +2462,7 @@
 
 lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear);
 lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload);
+lua_register(luaState, _P'DeclareAchievement', @lc_declareachievement);
 
 
 ScriptClearStack; // just to be sure stack is empty
--- a/hedgewars/uStats.pas	Tue Jun 11 11:48:36 2013 +0200
+++ b/hedgewars/uStats.pas	Tue Aug 06 00:26:07 2013 +0400
@@ -34,9 +34,10 @@
 procedure TurnReaction;
 procedure SendStats;
 procedure hedgehogFlight(Gear: PGear; time: Longword);
+procedure declareAchievement(id, teamname: shortstring; value: LongInt);
 
 implementation
-uses uSound, uLocale, uVariables, uUtils, uIO, uCaptions, uDebug, uMisc, uConsole;
+uses uSound, uLocale, uVariables, uUtils, uIO, uCaptions, uDebug, uMisc, uConsole, uScript;
 
 var DamageClan  : Longword = 0;
     DamageTotal : Longword = 0;
@@ -297,15 +298,29 @@
 if winnersClan <> nil then 
     begin
     WriteLnToConsole('WINNERS');
+    WriteLnToConsole(inttostr(winnersClan^.TeamsNumber));
     for t:= 0 to winnersClan^.TeamsNumber - 1 do
         WriteLnToConsole(winnersClan^.Teams[t]^.TeamName);
     end
 else
     WriteLnToConsole('DRAW');
 
+ScriptCall('onAchievementsDeclaration');
++end;
+
 WriteLnToConsole('');
 end;
 
+procedure declareAchievement(id, teamname: shortstring; value: LongInt);
+begin
+    if (length(id) = 0) or (length(teamname) = 0) then exit;
+    WriteLnToConsole('ACHIEVEMENT');
+    WriteLnToConsole(id);
+    WriteLnToConsole(teamname);
+    WriteLnToConsole(inttostr(value));
+end;
+ 
+ 
 procedure initModule;
 begin
     TotalRounds:= -1;
--- a/share/hedgewars/Data/Maps/TrophyRace/map.lua	Tue Jun 11 11:48:36 2013 +0200
+++ b/share/hedgewars/Data/Maps/TrophyRace/map.lua	Tue Aug 06 00:26:07 2013 +0400
@@ -162,3 +162,9 @@
 --		
 --	end
 --end
+
+function onAchievementsDeclaration()
+    if besthog ~= nil then
+      DeclareAchievement("rope race", GetHogTeamName(besthog), besttime)
+    end
+end