hedgewars/uTeams.pas
changeset 9407 860f959f92c9
parent 9295 f8819c3dde54
child 9464 901e363d5837
--- a/hedgewars/uTeams.pas	Tue Aug 20 14:40:27 2013 +0400
+++ b/hedgewars/uTeams.pas	Fri Aug 23 16:02:08 2013 +0400
@@ -43,7 +43,7 @@
 
 implementation
 uses uLocale, uAmmos, uChat, uVariables, uUtils, uIO, uCaptions, uCommands, uDebug,
-    uGearsUtils, uGearsList, uVisualGearsList
+    uGearsUtils, uGearsList, uVisualGearsList, uPhysFSLayer
     {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF};
 
 var MaxTeamHealth: LongInt;
@@ -568,6 +568,61 @@
     end
 end;
 
+procedure loadTeamBinds(s: shortstring);
+var i: LongInt;
+    f: PFSFile;
+    p, l: shortstring;
+    b: byte;
+begin
+    l:= '';
+    
+    for i:= 1 to length(s) do
+        if s[i] in ['\', '/', ':'] then s[i]:= '_';
+        
+    s:= cPathz[ptTeams] + '/' + s + '.hwt';
+    if pfsExists(s) then
+        begin
+        AddFileLog('Loading binds from: ' + s);
+        f:= pfsOpenRead(s);
+        while (not pfsEOF(f)) and (l <> '[Binds]') do
+            pfsReadLn(f, l);
+
+        while (not pfsEOF(f)) and (l <> '') do
+            begin
+            pfsReadLn(f, l);
+
+            p:= '';
+            i:= 1;
+            while (i <= length(l)) and (l[i] <> '=') do
+                begin
+                if l[i] <> '%' then
+                    begin
+                    p:= p + l[i];
+                    inc(i)
+                    end else
+                    begin
+                    l[i]:= '$';
+                    val(copy(l, i, 3), b);
+                    p:= p + char(b);
+                    inc(i, 3)
+                    end;
+                end;
+            
+            if i < length(l) then
+                begin
+                l:= copy(l, i + 1, length(l) - i);
+                if l <> 'default' then
+                    begin
+                    p:= 'bind ' + l + ' ' + p;
+                    ParseCommand(p, true)
+                    end
+                end
+            end;
+            
+        pfsClose(f)
+        end
+end;
+
 procedure chAddTeam(var s: shortstring);
 var Color: Longword;
     ts, cs: shortstring;
@@ -586,6 +641,8 @@
     AddTeam(Color);
     CurrentTeam^.TeamName:= ts;
     CurrentTeam^.PlayerHash:= s;
+    loadTeamBinds(ts);
+    
     if GameType in [gmtDemo, gmtSave, gmtRecord] then
         CurrentTeam^.ExtDriven:= true;