Finish rework of default binds system. Default binds now work even before first turn.
authorunc0rr
Sat, 21 Sep 2013 23:54:57 +0400
changeset 9464 901e363d5837
parent 9462 4cbc9a8fd559
child 9466 8b48c27201af
child 9646 7588daa8d28f
Finish rework of default binds system. Default binds now work even before first turn.
hedgewars/hwengine.pas
hedgewars/uInputHandler.pas
hedgewars/uTeams.pas
tools/hashTest.hs
--- a/hedgewars/hwengine.pas	Sat Sep 21 22:32:01 2013 +0400
+++ b/hedgewars/hwengine.pas	Sat Sep 21 23:54:57 2013 +0400
@@ -71,6 +71,7 @@
             end;
         gsStart:
             begin
+            SetDefaultBinds;
             if HasBorder then
                 DisableSomeWeapons;
             AddClouds;
--- a/hedgewars/uInputHandler.pas	Sat Sep 21 22:32:01 2013 +0400
+++ b/hedgewars/uInputHandler.pas	Sat Sep 21 23:54:57 2013 +0400
@@ -314,8 +314,6 @@
 DefaultBinds[KeyNameToCode('j0a1d')]:= '+down';
 for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i);
 for i:= 1 to 5  do DefaultBinds[KeyNameToCode(IntToStr(i))]:= 'timer '+IntToStr(i);
-
-SetDefaultBinds();
 end;
 
 procedure SetBinds(var binds: TBinds);
--- a/hedgewars/uTeams.pas	Sat Sep 21 22:32:01 2013 +0400
+++ b/hedgewars/uTeams.pas	Sat Sep 21 23:54:57 2013 +0400
@@ -363,7 +363,7 @@
 inc(TeamsCount);
 
 for t:= 0 to cKbdMaxIndex do
-    team^.Binds[t]:= '';
+    team^.Binds[t]:= DefaultBinds[t];
 
 c:= Pred(ClansCount);
 while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c);
@@ -607,7 +607,7 @@
                     inc(i, 3)
                     end;
                 end;
-            
+
             if i < length(l) then
                 begin
                 l:= copy(l, i + 1, length(l) - i);
@@ -618,7 +618,7 @@
                     end
                 end
             end;
-            
+
         pfsClose(f)
         end
 end;
@@ -666,7 +666,7 @@
 
 procedure chBind(var id: shortstring);
 var KeyName, Modifier, tmp: shortstring;
-    b: LongInt;
+    i, b: LongInt;
 begin
 KeyName:= '';
 Modifier:= '';
@@ -691,7 +691,17 @@
 if b = 0 then
     OutError(errmsgUnknownVariable + ' "' + id + '"', false)
 else
+    begin 
+    // add bind: first check if this cmd is already bound, and remove old bind
+    i:= cKbdMaxIndex;
+    repeat
+        dec(i)
+    until (i < 0) or (CurrentTeam^.Binds[i] = KeyName);
+    if (i >= 0) then
+        CurrentTeam^.Binds[i]:= '';
+
     CurrentTeam^.Binds[b]:= KeyName;
+    end
 end;
 
 procedure chTeamGone(var s:shortstring);
--- a/tools/hashTest.hs	Sat Sep 21 22:32:01 2013 +0400
+++ b/tools/hashTest.hs	Sat Sep 21 23:54:57 2013 +0400
@@ -44,7 +44,9 @@
 
 didIunderstand' = do
     a <- liftM lines getContents
+    print $ length a
     print . IS.size . IS.fromList . map (testHash . map fromEnum) $ a
     where
-        testHash s = let l = length s in
+        testHash s = let l = length s in (
                          (s !! (l - 2) * s !! 1) + s !! (l - 1) - s !! 0
+                         ) `mod` 256