Engine loads team binds from team config. Frontend still sends default binds commands, and default binds in team config aren't processed.
authorunc0rr
Fri, 23 Aug 2013 16:02:08 +0400
changeset 9407 860f959f92c9
parent 9405 efc5409a141d
child 9409 6564baf7dedf
Engine loads team binds from team config. Frontend still sends default binds commands, and default binds in team config aren't processed.
QTfrontend/team.cpp
hedgewars/uPhysFSLayer.pas
hedgewars/uTeams.pas
--- a/QTfrontend/team.cpp	Tue Aug 20 14:40:27 2013 +0400
+++ b/QTfrontend/team.cpp	Fri Aug 23 16:02:08 2013 +0400
@@ -276,17 +276,6 @@
     sl.push_back(QString("evoicepack " + m_voicepack));
     sl.push_back(QString("eflag " + m_flag));
 
-    if (!m_isNetTeam)
-    {
-        for(int i = 0; i < BINDS_NUMBER; i++)
-        {
-            if(m_binds[i].strbind.isEmpty() || m_binds[i].strbind == "default")
-                sl.push_back(QString("ebind " + config->bind(i) + " " + m_binds[i].action));
-            else
-                sl.push_back(QString("ebind " + m_binds[i].strbind + " " + m_binds[i].action));
-        }
-    }
-
     for (int t = 0; t < m_numHedgehogs; t++)
     {
         sl.push_back(QString("eaddhh %1 %2 %3")
--- a/hedgewars/uPhysFSLayer.pas	Tue Aug 20 14:40:27 2013 +0400
+++ b/hedgewars/uPhysFSLayer.pas	Fri Aug 23 16:02:08 2013 +0400
@@ -145,6 +145,8 @@
     AddFileLog('[PhysFS] mount ' + PathPrefix + ': ' + inttostr(i));
     i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Data'), nil, false);
     AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Data: ' + inttostr(i));
+    i:= PHYSFS_mount(Str2PChar(UserPathPrefix + '/Teams'), '/Teams', false);
+    AddFileLog('[PhysFS] mount ' + UserPathPrefix + '/Teams: ' + inttostr(i));
 
     hedgewarsMountPackages;
 end;
--- 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;