use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
authorXeli
Thu, 09 Feb 2012 14:12:50 +0100
changeset 6654 120e95c10532
parent 6653 d45b6dbd2ad6
child 6660 99ecc7e17c4f
use the way actions are initiated the same way as koda implemented with PascalExports, using boolean values such as upKey and enterKey, this prevents the user from being able to control the AI
hedgewars/uKeys.pas
hedgewars/uTouch.pas
--- a/hedgewars/uKeys.pas	Wed Feb 08 15:49:55 2012 +0400
+++ b/hedgewars/uKeys.pas	Thu Feb 09 14:12:50 2012 +0100
@@ -40,7 +40,7 @@
 procedure ControllerHatEvent(joy, hat, value: Byte);
 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
 
-{$IFDEF IPHONEOS}
+{$IFDEF MOBILE}
 procedure setiPhoneBinds;
 {$ENDIF}
 
@@ -63,7 +63,7 @@
 var  i, j, k: LongInt;
      s: shortstring;
      Trusted: boolean;
-{$IFNDEF IPHONEOS}pkbd: PByteArray;{$ENDIF}
+{$IFNDEF MOBILE}pkbd: PByteArray;{$ENDIF}
 begin
 hideAmmoMenu:= false;
 Trusted:= (CurrentTeam <> nil)
@@ -76,7 +76,7 @@
 
 k:= SDL_GetMouseState(nil, nil);
 
-{$IFDEF IPHONEOS}
+{$IFDEF MOBILE}
 SDL_GetKeyState(@j);
 {$ELSE}
 pkbd:= SDL_GetKeyState(@j);
@@ -100,7 +100,7 @@
 wheelUp:= false;
 wheelDown:= false;
 
-{$IFDEF IPHONEOS}
+{$IFDEF MOBILE}
 setiPhoneBinds();
 {$ELSE}
 // Controller(s)
@@ -170,18 +170,18 @@
 
 procedure ResetKbd;
 var j, k, t: LongInt;
-{$IFNDEF IPHONEOS}
+{$IFNDEF MOBILE}
     i: LongInt;
     pkbd: PByteArray;
 {$ENDIF}
 begin
 
 k:= SDL_GetMouseState(nil, nil);
-{$IFNDEF IPHONEOS}pkbd:={$ENDIF}SDL_GetKeyState(@j);
+{$IFNDEF MOBILE}pkbd:={$ENDIF}SDL_GetKeyState(@j);
 
 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + IntToStr(j) + ')', true);
 
-{$IFNDEF IPHONEOS}
+{$IFNDEF MOBILE}
 for i:= 1 to pred(j) do
     tkbdn[i]:= pkbd^[i];
 {$ENDIF}
@@ -202,7 +202,7 @@
 wheelUp:= false;
 wheelDown:= false;
 
-{$IFDEF IPHONEOS}
+{$IFDEF MOBILE}
 setiPhoneBinds();
 {$ELSE}
 // Controller(s)
@@ -325,7 +325,7 @@
 DefaultBinds[ 9]:= 'switch';
 DefaultBinds[13]:= 'ljump';
 DefaultBinds[32]:= '+attack';
-{$IFDEF IPHONEOS}
+{$IFDEF MOBILE}
 DefaultBinds[23]:= '+up';
 DefaultBinds[24]:= '+down';
 DefaultBinds[25]:= '+left';
@@ -349,7 +349,7 @@
 
 procedure SetBinds(var binds: TBinds);
 begin
-{$IFDEF IPHONEOS}
+{$IFDEF MOBILE}
     binds:= binds; // avoid hint
     CurrentBinds:= DefaultBinds;
 {$ELSE}
@@ -362,7 +362,7 @@
     CurrentBinds:= DefaultBinds;
 end;
 
-{$IFDEF IPHONEOS}
+{$IFDEF MOBILE}
 procedure setiPhoneBinds;
 begin
     tkbdn[ 1]:= ord(leftClick);
@@ -411,7 +411,7 @@
 var i, j: Integer;
 begin
 ControllerEnabled:= 0;
-{$IFDEF IPHONEOS}
+{$IFDEF MOBILE}
 exit; // joystick subsystem disabled on iPhone
 {$ENDIF}
 
--- a/hedgewars/uTouch.pas	Wed Feb 08 15:49:55 2012 +0400
+++ b/hedgewars/uTouch.pas	Thu Feb 09 14:12:50 2012 +0100
@@ -22,7 +22,7 @@
 
 interface
 
-uses sysutils, math, uConsole, uVariables, SDLh, uTypes, uFloat, uConsts, uIO, uCommands, GLUnit;
+uses sysutils, math, uConsole, uVariables, SDLh, uFloat, uConsts, uIO, GLUnit;
 
 // TODO: this type should be Int64
 // TODO: this type should be named TSDL_FingerId
@@ -114,42 +114,42 @@
             if isOnRect(fireButtonX, fireButtonY, fireButtonW, fireButtonH, finger^) then
             begin
                 stopFiring:= false;
-                ParseCommand('+attack', true);
+                spaceKey:= true;
                 exit;
             end;
             if isOnRect(arrowLeftX, arrowLeftY, arrowLeftW, arrowLeftH, finger^) then
             begin
-                ParseCommand('+left', true);
+                leftKey:= true;
                 walkingLeft := true;
                 exit;
             end;
             if isOnRect(arrowRightX, arrowRightY, arrowRightW, arrowRightH, finger^) then
             begin
-                ParseCommand('+right', true);
+                rightKey:= true;
                 walkingRight:= true;
                 exit;
             end;
             if isOnRect(arrowUpX, arrowUpY, arrowUpW, arrowUpH, finger^) then
             begin
-                ParseCommand('+up', true);
+                upKey:= true;
                 aimingUp:= true;
                 exit;
             end;
             if isOnRect(arrowDownX, arrowDownY, arrowUpW, arrowUpH, finger^) then
             begin
-                ParseCommand('+down', true);
+                downKey:= true;
                 aimingDown:= true;
                 exit;
             end;
 
             if isOnRect(backjumpX, backjumpY, backjumpW, backjumpH, finger^) then
             begin
-                ParseCommand('hjump', true);
+                enterKey:= true;
                 exit;
             end;
             if isOnRect(forwardjumpX, forwardjumpY, forwardjumpW, forwardjumpH, finger^) then
             begin
-                ParseCommand('ljump', true);
+                backspaceKey:= true;
                 exit;
             end;
             moveCursor:= not bShowAmmoMenu;
@@ -224,24 +224,24 @@
 
 if walkingLeft then
     begin
-    ParseCommand('-left', true);
+    leftKey:= false;
     walkingLeft := false;
     end;
 
 if walkingRight then
     begin
-    ParseCommand('-right', true);
+    rightKey:= false;
     walkingRight := false;
     end;
 
 if aimingUp then
     begin
-    ParseCommand('-up', true);
+    upKey:= false;
     aimingUp:= false;
     end;
 if aimingDown then
     begin
-    ParseCommand('-down', true);
+    downKey:= false;
     aimingDown:= false;
     end;
 end;
@@ -249,7 +249,6 @@
 procedure onTouchDoubleClick(finger: Touch_Finger);
 begin
 finger := finger;//avoid compiler hint
-//ParseCommand('ljump', true);
 end;
 
 procedure onTouchClick(finger: Touch_Finger);
@@ -257,7 +256,7 @@
 if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then
     begin
     onTouchDoubleClick(finger);
-    timeSinceClick:= -1;
+    timeSinceClick:= 0;//we make an assumption there won't be an 'click' in the first 300 ticks(milliseconds) 
     exit; 
     end;
 
@@ -284,12 +283,6 @@
     bShowAmmoMenu := true;
     exit;
     end;
-
-{if finger.y < topButtonBoundary then
-    begin
-    ParseCommand('hjump', true);
-    exit;
-    end;}
 end;
 
 function addFinger(x,y: Longword; id: SDL_FingerId): PTouch_Finger;
@@ -377,12 +370,12 @@
             begin
             if aimingUp then
                 begin
-                ParseCommand('-up', true);
+                upKey:= false;
                 aimingUp:= false;
                 end;
             if aimingDown then
                 begin
-                ParseCommand('-down', true);
+                downKey:= false;
                 aimingDown:= false;
                 end
             end
@@ -392,20 +385,20 @@
                 begin
                 if aimingUp then
                     begin
-                    ParseCommand('-up', true);
+                    upKey:= false;
                     aimingUp:= false;
                     end;
-                ParseCommand('+down', true);
+                downKey:= true;
                 aimingDown:= true;
                 end
             else
                 begin
                 if aimingDown then
                     begin
-                    ParseCommand('-down', true);
+                    downKey:= false;
                     aimingDown:= false;
                     end;
-                ParseCommand('+up', true);
+                upKey:= true;
                 aimingUp:= true;
                 end; 
             end;
@@ -414,32 +407,32 @@
         begin
         if aimingUp then
             begin
-            ParseCommand('-up', true);
+            upKey:= false;
             aimingUp:= false;
             end;
         if aimingDown then
             begin
-            ParseCommand('-down', true);
+            upKey:= false;
             aimingDown:= false;
             end;
         end;
        
 if stopFiring then 
     begin
-    ParseCommand('-attack', true);
+    spaceKey:= false;
     stopFiring:= false;
     end;
 
 if stopRight then
     begin
     stopRight := false;
-    ParseCommand('-right', true);
+    rightKey:= false;
     end;
  
 if stopLeft then
     begin
     stopLeft := false;
-    ParseCommand('-left', true);
+    leftKey:= false;
     end;
     
 end;