# HG changeset patch
# User unc0rr
# Date 1322424802 -10800
# Node ID 11c578d30bd31b59c85dfb17838a3e08dc5bb96f
# Parent  7c6f9b6672dcf52b3420d3423c3bc5a94c746513
Countless imporvements to the parser and countless help to the parser in sources.
Now parser is able to parse the whole engine \o/

diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/GSHandlers.inc
--- a/hedgewars/GSHandlers.inc	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/GSHandlers.inc	Sun Nov 27 23:13:22 2011 +0300
@@ -4045,7 +4045,7 @@
                 continue;
         end
         else
-            if not (Gear^.dX*ox + Gear^.dY*oy).isNegative then
+            if not ((Gear^.dX*ox + Gear^.dY*oy).isNegative) then
                 continue;
 
         isbullet:= (iterator^.Kind in [gtShotgunShot, gtDEagleShot, gtSniperRifleShot, gtSineGunShot]);
@@ -4105,7 +4105,7 @@
         ny := Gear^.dX;
         // ... decide where the top is based on the hog's direction when firing the portal
         if Gear^.Elasticity.isNegative then
-            nx.isNegative := not nx.isNegative
+            nx.isNegative := (not nx.isNegative)
         else
             ny.isNegative := not ny.isNegative;
 
@@ -4137,7 +4137,7 @@
         nx := conPortal^.dY;
         ny := conPortal^.dX;
         if conPortal^.Elasticity.isNegative then
-            nx.isNegative := not nx.isNegative
+            nx.isNegative := (not nx.isNegative)
         else
             ny.isNegative := not ny.isNegative;
 
@@ -4364,7 +4364,7 @@
     newPortal^.IntersectGear := nil;
 
     if CurrentHedgehog <> nil then
-        With CurrentHedgehog^ do
+        with CurrentHedgehog^ do
         begin
             CurWeapon:= GetAmmoEntry(CurrentHedgehog^);
             // let's save the HH's dX's direction so we can decide where the "top" of the portal hole
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/HHHandlers.inc
--- a/hedgewars/HHHandlers.inc	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/HHHandlers.inc	Sun Nov 27 23:13:22 2011 +0300
@@ -1129,7 +1129,7 @@
     end;
 if (Gear^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) and
    (Gear^.State and (gstHHJumping or gstHHHJump or gstAttacking) = 0) and
-   not Gear^.dY.isNegative and
+   (not Gear^.dY.isNegative) and
    (GameTicks mod (100*LongWOrd(hwRound(cMaxWindSpeed*2/cGravity))) = 0) and
    (TestCollisionYwithGear(Gear, 1) and lfIce <> 0) then
     begin
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/LuaPas.pas
--- a/hedgewars/LuaPas.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/LuaPas.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -15,7 +15,7 @@
 {$INCLUDE "config.inc"}
 
 type
-  size_t   = type Cardinal;
+  size_t   = Cardinal;
   Psize_t  = ^size_t;
   PPointer = ^Pointer;
 
@@ -45,8 +45,8 @@
 ** ===================================================================
 *)
 type
-  LUA_NUMBER_  = type Double;            // ending underscore is needed in Pascal
-  LUA_INTEGER_ = type PtrInt;
+  LUA_NUMBER_  = Double;            // ending underscore is needed in Pascal
+  LUA_INTEGER_ = PtrInt;
 
 (*
 @@ LUA_IDSIZE gives the maximum size for the description of the source
@@ -115,7 +115,7 @@
   LUA_AUTHORS     = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
 
   (* mark for precompiled code (`<esc>Lua') *)
-  LUA_SIGNATURE = #27'Lua';
+  LUA_SIGNATURE = #27 + 'Lua';
 
   (* option for multiple returns in `lua_pcall' and `lua_call' *)
   LUA_MULTRET = -1;
@@ -429,8 +429,8 @@
 function lua_getgccount(L : Plua_State) : LongInt;
 
 type
-  lua_Chuckreader = type lua_Reader;
-  lua_Chuckwriter = type lua_Writer;
+  lua_Chuckreader = lua_Reader;
+  lua_Chuckwriter = lua_Writer;
 
 (* ====================================================================== *)
 
@@ -983,7 +983,7 @@
 begin
   if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then
     luaL_prepbuffer(B);
-  B^.p^ := c;
+  (B^.p^) := c;
   Inc(B^.p);
 end;
 
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uAIAmmoTests.pas
--- a/hedgewars/uAIAmmoTests.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uAIAmmoTests.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -470,7 +470,7 @@
             EY:= hwRound(y);
         until TestCollExcludingMe(Me, EX, EY, 5) or (EY > cWaterLine);
 
-        if (EY < cWaterLine) and not dY.isNegative then
+        if (EY < cWaterLine) and (not dY.isNegative) then
             begin
             value:= RateExplosion(Me, EX, EY, 91);
             if (value = 0) then
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uChat.pas
--- a/hedgewars/uChat.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uChat.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -327,7 +327,7 @@
     SendIPC('s' + s);
 
     if copy(s, 1, 4) = '/me ' then
-        s:= #2'* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
+        s:= #2 + '* ' + UserNick + ' ' + copy(s, 5, Length(s) - 4)
     else
         s:= #1 + UserNick + ': ' + s;
 
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uCollisions.pas
--- a/hedgewars/uCollisions.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uCollisions.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -393,7 +393,7 @@
     i, j, k, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
     tmpx, tmpy: LongWord;
     dx, dy, s: hwFloat;
-    offset: Array[0..7,0..1] of ShortInt;
+    offset: array[0..7,0..1] of ShortInt;
     isColl: Boolean;
 
 begin
@@ -523,7 +523,7 @@
 function CalcSlopeBelowGear(Gear: PGear): hwFloat;
 var dx, dy: hwFloat;
     collX, i, y, x, gx, sdx, sdy: LongInt;
-    isColl, succ: Boolean;
+    isColl, bSucc: Boolean;
 begin
 
 
@@ -560,13 +560,13 @@
 
     sdx:= 0;
     sdy:= 0;
-    succ := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 255);
+    bSucc := CalcSlopeTangent(Gear, collX, y, sdx, sdy, 255);
 
     // restore original dx/dy
     Gear^.dX := dx;
     Gear^.dY := dy;
 
-    if succ and (sdx <> 0) and (sdy <> 0) then
+    if bSucc and (sdx <> 0) and (sdy <> 0) then
     begin
         dx := int2hwFloat(sdy) / (abs(sdx) + abs(sdy));
         dx.isNegative := (sdx * sdy) < 0;
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uCommandHandlers.pas
--- a/hedgewars/uCommandHandlers.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uCommandHandlers.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -214,7 +214,7 @@
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('l');
 with CurrentHedgehog^.Gear^ do
-    Message:= Message and not (gmLeft and InputMask);
+    Message:= Message and (not (gmLeft and InputMask));
     ScriptCall('onLeftUp');
 end;
 
@@ -235,7 +235,7 @@
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('r');
 with CurrentHedgehog^.Gear^ do
-    Message:= Message and not (gmRight and InputMask);
+    Message:= Message and (not (gmRight and InputMask));
     ScriptCall('onRightUp');
 end;
 
@@ -256,7 +256,7 @@
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('u');
 with CurrentHedgehog^.Gear^ do
-    Message:= Message and not (gmUp and InputMask);
+    Message:= Message and (not (gmUp and InputMask));
     ScriptCall('onUpUp');
 end;
 
@@ -277,7 +277,7 @@
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('d');
 with CurrentHedgehog^.Gear^ do
-    Message:= Message and not (gmDown and InputMask);
+    Message:= Message and (not (gmDown and InputMask));
     ScriptCall('onDownUp');
 end;
 
@@ -298,7 +298,7 @@
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('z');
 with CurrentHedgehog^.Gear^ do
-    Message:= Message and not (gmPrecise and InputMask);
+    Message:= Message and (not (gmPrecise and InputMask));
     ScriptCall('onPreciseUp');
 end;
 
@@ -350,7 +350,7 @@
     begin
     if not CurrentTeam^.ExtDriven and
         ((Message and gmAttack) <> 0) then SendIPC('a');
-    Message:= Message and not (gmAttack and InputMask);
+    Message:= Message and (not (gmAttack and InputMask));
     ScriptCall('onAttackUp');
     end
 end;
@@ -505,7 +505,7 @@
             if bShowAmmoMenu then bShowAmmoMenu:= false
             else if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or
                     ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) or
-                    ((Gear^.State and gstHHDriven) = 0) then else bShowAmmoMenu:= true
+                    ((Gear^.State and gstHHDriven) = 0) then begin end else bShowAmmoMenu:= true
             end;
     end
 end;
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uGears.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -653,7 +653,7 @@
 
         inc(KilledHHs);
         RecountTeamHealth(team);
-        if (CurrentHedgehog <> nil) and CurrentHedgehog^.Effects[heResurrectable] and not Gear^.Hedgehog^.Effects[heResurrectable] then
+        if (CurrentHedgehog <> nil) and CurrentHedgehog^.Effects[heResurrectable] and (not Gear^.Hedgehog^.Effects[heResurrectable]) then
             with CurrentHedgehog^ do 
                 begin
                 inc(Team^.stats.AIKills);
@@ -698,9 +698,9 @@
 
             if (Gear^.Hedgehog^.Team = CurrentTeam) and
                (Gear^.Damage <> Gear^.Karma) and
-                not Gear^.Hedgehog^.King and
-                not Gear^.Hedgehog^.Effects[hePoisoned] and
-                not SuddenDeathDmg then
+                (not Gear^.Hedgehog^.King) and
+                (not Gear^.Hedgehog^.Effects[hePoisoned]) and
+                (not SuddenDeathDmg) then
                 Gear^.State:= Gear^.State or gstLoser;
 
             spawnHealthTagForHH(Gear, dmg);
@@ -863,7 +863,7 @@
     stHealth: begin
             if (cWaterRise <> 0) or (cHealthDecrease <> 0) then
                 begin
-                if (TotalRounds = cSuddenDTurns) and not SuddenDeath and not isInMultiShoot then
+                if (TotalRounds = cSuddenDTurns) and (not SuddenDeath) and (not isInMultiShoot) then
                     begin
                     SuddenDeath:= true;
                     if cHealthDecrease <> 0 then
@@ -884,13 +884,13 @@
                     MusicFN:= SDMusic;
                     ChangeMusic
                     end
-                else if (TotalRounds < cSuddenDTurns) and not isInMultiShoot then
+                else if (TotalRounds < cSuddenDTurns) and (not isInMultiShoot) then
                     begin
                     i:= cSuddenDTurns - TotalRounds;
                     s:= inttostr(i);
                     if i = 1 then
                         AddCaption(trmsg[sidRoundSD], cWhiteColor, capgrpGameState)
-                    else if i in [2, 5, 10, 15, 20, 25, 50, 100] then
+                    else if (i = 2) or ((i > 0) and ((i mod 50 = 0) or ((i <= 25) and (i mod 5 = 0)))) then
                         AddCaption(Format(trmsg[sidRoundsSD], s), cWhiteColor, capgrpGameState);
                     end;
                 end;
@@ -940,14 +940,14 @@
         begin
         dec(delay2);
 
-        if ((delay2 mod cInactDelay) = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and not CurrentHedgehog^.Unplaced then
+        if ((delay2 mod cInactDelay) = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and (not CurrentHedgehog^.Unplaced) then
             begin
             if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0) and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then
                 begin
                 CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstHHChooseTarget;
                 isCursorVisible := true
                 end;
-            CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and not gstAttacked;
+            CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State and (not gstAttacked);
             end;
         if delay2 = 0 then
             begin
@@ -969,7 +969,7 @@
 if TurnTimeLeft > 0 then
         if CurrentHedgehog^.Gear <> nil then
             if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0)
-                and not isInMultiShoot then
+                and (not isInMultiShoot) then
                 begin
                 if (TurnTimeLeft = 5000)
                     and (cHedgehogTurnTime >= 10000)
@@ -1067,7 +1067,7 @@
         t:= t^.NextGear
         end;
    
-    if ((GameFlags and gfResetWeps) <> 0) and not PlacingHogs then
+    if ((GameFlags and gfResetWeps) <> 0) and (not PlacingHogs) then
         ResetWeapons;
 
     if (GameFlags and gfResetHealth) <> 0 then
@@ -1121,7 +1121,7 @@
             end;
         if ((GameFlags and gfKarma) <> 0) and
            ((GameFlags and gfInvulnerable) = 0) and
-           not CurrentHedgehog^.Gear^.Invulnerable then
+           (not CurrentHedgehog^.Gear^.Invulnerable) then
            begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid
            inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
            CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog;
@@ -1328,7 +1328,7 @@
                                 Gear^.Active:= true;
                                 if Gear^.Kind <> gtFlame then FollowGear:= Gear
                                 end;
-                            if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and not Gear^.Invulnerable then
+                            if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (not Gear^.Invulnerable) then
                                 Gear^.Hedgehog^.Effects[hePoisoned] := true;
                             end;
 
@@ -1479,7 +1479,7 @@
                         Gear^.State:= Gear^.State or gstWinner;
                     if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then 
                         begin
-                        if (Ammo^.Hedgehog^.Gear <> nil) then Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and not gstNotKickable;
+                        if (Ammo^.Hedgehog^.Gear <> nil) then Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable);
                         ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
                         end;
 
@@ -1964,7 +1964,7 @@
 
         dec(Delta, 60)
     until (cnt2 > 0) or (Delta < 70);
-    if (cnt2 = 0) and skipProximity and not reallySkip then tryAgain:= true
+    if (cnt2 = 0) and skipProximity and (not reallySkip) then tryAgain:= true
     else tryAgain:= false;
     reallySkip:= true;
     end;
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uGearsRender.pas
--- a/hedgewars/uGearsRender.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uGearsRender.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -197,7 +197,7 @@
     HH:= Gear^.Hedgehog;
     if HH^.Unplaced then exit;
     m:= 1;
-    if ((Gear^.State and gstHHHJump) <> 0) and not cArtillery then m:= -1;
+    if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then m:= -1;
     sx:= ox + 1; // this offset is very common
     sy:= oy - 3;
     sign:= hwSign(Gear^.dX);
@@ -542,7 +542,7 @@
             begin
             if (TWave(Gear^.Tag) < Low(TWave)) or (TWave(Gear^.Tag) > High(TWave)) then
                 begin
-                Gear^.State:= Gear^.State and not gstAnimation;
+                Gear^.State:= Gear^.State and (not gstAnimation);
                 end
             else
                 begin
@@ -805,7 +805,7 @@
 
     with HH^ do
         begin
-        if ((Gear^.State and not gstWinner) = 0)
+        if ((Gear^.State and (not gstWinner)) = 0)
             or ((Gear^.State = gstWait) and (Gear^.dY.QWordValue = 0))
             or (bShowFinger and ((Gear^.State and gstHHDriven) <> 0)) then
             begin
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uIO.pas
--- a/hedgewars/uIO.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uIO.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -142,8 +142,7 @@
 procedure IPCCheckSock;
 const ss: shortstring = '';
 var i: LongInt;
-    buf: array[0..255] of byte;
-    s: shortstring absolute buf;
+    s: shortstring;
 begin
 if IPCSock = nil then
    exit;
@@ -153,10 +152,10 @@
 
 while SDLNet_CheckSockets(fds, 0) > 0 do
     begin
-    i:= SDLNet_TCP_Recv(IPCSock, @buf[1], 255 - Length(ss));
+    i:= SDLNet_TCP_Recv(IPCSock, @s[1], 255 - Length(ss));
     if i > 0 then
         begin
-        buf[0]:= i;
+        s[0]:= char(i);
         ss:= ss + s;
         while (Length(ss) > 1) and (Length(ss) > byte(ss[1])) do
             begin
@@ -171,8 +170,7 @@
 var f: file;
     ss: shortstring = '';
     i: LongInt;
-    buf: array[0..255] of byte;
-    s: shortstring absolute buf;
+    s: shortstring;
 begin
 
 // set RDNLY on file open
@@ -184,12 +182,12 @@
 tryDo(IOResult = 0, 'Error opening file ' + fileName, true);
 
 i:= 0; // avoid compiler hints
-buf[0]:= 0;
+s[0]:= #0;
 repeat
-    BlockRead(f, buf[1], 255 - Length(ss), i);
+    BlockRead(f, s[1], 255 - Length(ss), i);
     if i > 0 then
         begin
-        buf[0]:= i;
+        s[0]:= char(i);
         ss:= ss + s;
         while (Length(ss) > 1)and(Length(ss) > byte(ss[1])) do
             begin
@@ -315,7 +313,7 @@
             end;
         'b': begin
             s:= copy(headcmd^.str, 2, Pred(headcmd^.len));
-            ParseCommand('chatmsg '#4 + s, true);
+            ParseCommand('chatmsg ' + #4 + s, true);
             WriteLnToConsole(s)
             end;
 // TODO: deprecate 'F'
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uLand.pas
--- a/hedgewars/uLand.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uLand.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -38,7 +38,7 @@
 uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, sysutils,
      uVariables, uUtils, uCommands, Adler32, uDebug, uLandPainted, uTextures;
 
-operator=(const a, b: direction) c: Boolean;
+operator = (const a, b: direction) c: Boolean;
 begin
     c := (a.x = b.x) and (a.y = b.y);
 end;
@@ -685,7 +685,7 @@
 if getrandom(2) = 1 then next_dir_clockwise := true
 else next_dir_clockwise := false;
 
-while (tries < 5) and not found_cell do
+while (tries < 5) and (not found_cell) do
 begin
     if when_seen(x + dir.x, y + dir.y) = current_step then //we are seeing ourselves, try another direction
     begin
@@ -1076,7 +1076,7 @@
                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1]
                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x]
                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x];
-                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and not AMask) or (128 shl AShift)
+                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
                     end;
                 Land[y,x]:= lfObject
             end
@@ -1096,7 +1096,7 @@
                     else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1]
                     else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x]
                     else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x];
-                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and not AMask) or (64 shl AShift)
+                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
                     end;
                 Land[y,x]:= lfObject
             end;
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uLandGraphics.pas
--- a/hedgewars/uLandGraphics.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uLandGraphics.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -298,7 +298,7 @@
                begin
                by:= t div 2; bx:= i div 2;
                end;
-           if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and not (disableLandBack) then
+           if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
                begin
                inc(cnt);
                LandPixels[by, bx]:= LandBackPixel(i, t)
@@ -676,7 +676,7 @@
      4: for y:= 0 to Pred(h) do
             begin
             for x:= 0 to Pred(w) do
-                if PLongword(@(p^[x * 4]))^ <> 0 then
+                if (PLongword(@(p^[x * 4]))^) <> 0 then
                    if ((cpY + y) <= Longint(topY)) or
                       ((cpY + y) >= LAND_HEIGHT) or
                       ((cpX + x) <= Longint(leftX)) or
@@ -705,7 +705,7 @@
      4: for y:= 0 to Pred(h) do
             begin
             for x:= 0 to Pred(w) do
-                if PLongword(@(p^[x * 4]))^ <> 0 then
+                if (PLongword(@(p^[x * 4]))^) <> 0 then
                    begin
                    if (cReducedQuality and rqBlurryLand) = 0 then
                        begin
@@ -781,7 +781,7 @@
 
     if c < 4 then // 0-3 neighbours
         begin
-        if ((Land[Y, X] and lfBasic) <> 0) and not disableLandBack then
+        if ((Land[Y, X] and lfBasic) <> 0) and (not disableLandBack) then
             LandPixels[yy, xx]:= LandBackPixel(X, Y)
         else
             LandPixels[yy, xx]:= 0;
@@ -804,7 +804,7 @@
         begin
         if (cReducedQuality and rqBlurryLand) = 0 then
             begin
-            if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and not AMask) or (128 shl AShift)
+            if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (128 shl AShift)
             else
                 LandPixels[y,x]:=
                                 (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or
@@ -826,7 +826,7 @@
         begin
         if (cReducedQuality and rqBlurryLand) = 0 then
             begin
-            if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and not AMask) or (64 shl AShift)
+            if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (64 shl AShift)
             else
                 LandPixels[y,x]:=
                                 (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uLandObjects.pas
--- a/hedgewars/uLandObjects.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uLandObjects.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -192,7 +192,7 @@
         k:= CountNonZeroz(x2, y)
         until (x2 >= (rightX-150)) or (k = 0) or (k = 16) or (x2 > i) or (x2 - x1 >= 768);
         if (x2 < (rightX - 150)) and (k = 16) and (x2 - x1 > 250) and (x2 - x1 < 768)
-            and not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144) then break;
+            and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then break;
         end;
 x1:= 0;
 until y > (LAND_HEIGHT-125);
@@ -345,7 +345,7 @@
         y:= 8;
         repeat
             if CheckLand(r, x, y - 8, lfBasic)
-            and not CheckIntersect(x, y, Width, Height) then
+            and (not CheckIntersect(x, y, Width, Height)) then
             begin
             ar[cnt].x:= x;
             ar[cnt].y:= y;
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uLocale.pas
--- a/hedgewars/uLocale.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uLocale.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -58,7 +58,7 @@
        begin
        readln(f, s);
        if Length(s) = 0 then continue;
-       if not (s[1] in ['0'..'9']) then continue;
+       if (s[1] < '0') or (s[1] > '9') then continue;
        TryDo(Length(s) > 6, 'Load locale: empty string', true);
        val(s[1]+s[2], a, c);
        TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true);
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uScript.pas
--- a/hedgewars/uScript.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uScript.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -53,7 +53,7 @@
 
 implementation
 {$IFNDEF LUA_DISABLED}
-uses LuaPas in 'LuaPas.pas',
+uses LuaPas,
     uConsole,
     uConsts,
     uVisualGears,
@@ -1715,7 +1715,7 @@
 
 procedure ScriptCall(fname : shortstring);
 begin
-if not ScriptLoaded or not ScriptExists(fname) then
+if not ScriptLoaded or (not ScriptExists(fname)) then
     exit;
 SetGlobals;
 lua_getglobal(luaState, Str2PChar(fname));
@@ -1763,7 +1763,7 @@
 
 function ScriptCall(fname : shortstring; par1, par2, par3, par4 : LongInt) : LongInt;
 begin
-if not ScriptLoaded or not ScriptExists(fname) then
+if not ScriptLoaded or (not ScriptExists(fname)) then
     exit;
 SetGlobals;
 lua_getglobal(luaState, Str2PChar(fname));
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uStats.pas
--- a/hedgewars/uStats.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uStats.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -130,7 +130,7 @@
     else if AmmoDamagingUsed then
         AddVoice(sndMissed, PreviousTeam^.voicepack)
     else if (AmmoUsedCount > 0) and (not isTurnSkipped) then
-        // nothing ?
+        begin end// nothing ?
     else if isTurnSkipped then
         begin
         AddVoice(sndBoring, PreviousTeam^.voicepack);
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uStore.pas
--- a/hedgewars/uStore.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uStore.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -413,7 +413,7 @@
         begin
         FreeTexture(SpritesData[ii].Texture);
         SpritesData[ii].Texture:= nil;
-        if (SpritesData[ii].Surface <> nil) and not reload then
+        if (SpritesData[ii].Surface <> nil) and (not reload) then
             begin
             SDL_FreeSurface(SpritesData[ii].Surface);
             SpritesData[ii].Surface:= nil
@@ -955,7 +955,7 @@
     {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF}
     {$IFDEF SDL13}x, y: LongInt;{$ENDIF}
 begin
-    if Length(s) = 0 then cFullScreen:= not cFullScreen
+    if Length(s) = 0 then cFullScreen:= (not cFullScreen)
     else cFullScreen:= s = '1';
 
     AddFileLog('Preparing to change video parameters...');
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uVisualGears.pas
--- a/hedgewars/uVisualGears.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uVisualGears.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -120,11 +120,11 @@
 begin
 AddVisualGear:= nil;
 if ((GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet))) and // we are scrolling now
-   ((Kind <> vgtCloud) and not Critical) then exit;
+   ((Kind <> vgtCloud) and (not Critical)) then exit;
 
 if ((cReducedQuality and rqAntiBoom) <> 0) and
-   not Critical and
-   not (Kind in
+   (not Critical) and
+   (not (Kind in
    [vgtTeamHealthSorter,
     vgtSmallDamageTag,
     vgtSpeechBubble,
@@ -133,7 +133,7 @@
     vgtSmokeTrace,
     vgtEvilTrace,
     vgtNote,
-    vgtSmoothWindBar]) then exit;
+    vgtSmoothWindBar])) then exit;
 
 inc(VGCounter);
 New(gear);
diff -r 7c6f9b6672dc -r 11c578d30bd3 hedgewars/uWorld.pas
--- a/hedgewars/uWorld.pas	Sun Nov 27 19:34:08 2011 +0300
+++ b/hedgewars/uWorld.pas	Sun Nov 27 23:13:22 2011 +0300
@@ -1220,11 +1220,11 @@
     PrevSentPointTime: LongWord = 0;
 begin
 {$IFNDEF MOBILE}
-if (not (CurrentTeam^.ExtDriven and isCursorVisible and not bShowAmmoMenu)) and cHasFocus and (GameState <> gsConfirm) then
+if (not (CurrentTeam^.ExtDriven and isCursorVisible and (not bShowAmmoMenu))) and cHasFocus and (GameState <> gsConfirm) then
     uCursor.updatePosition();
 {$ENDIF}
 z:= round(200/zoom);
-if not PlacingHogs and (FollowGear <> nil) and not isCursorVisible and not bShowAmmoMenu and not fastUntilLag then
+if not PlacingHogs and (FollowGear <> nil) and (not isCursorVisible) and (not bShowAmmoMenu) and (not fastUntilLag) then
     if (not autoCameraOn) or ((abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y)) > 4) then
         begin
         FollowGear:= nil;
diff -r 7c6f9b6672dc -r 11c578d30bd3 tools/PascalBasics.hs
--- a/tools/PascalBasics.hs	Sun Nov 27 19:34:08 2011 +0300
+++ b/tools/PascalBasics.hs	Sun Nov 27 23:13:22 2011 +0300
@@ -8,7 +8,7 @@
 import Text.Parsec.Language
 import Data.Char
 
-builtin = ["succ", "pred", "low", "high"]
+builtin = ["succ", "pred", "low", "high", "ord"]
     
 pascalLanguageDef
     = emptyDef
diff -r 7c6f9b6672dc -r 11c578d30bd3 tools/PascalParser.hs
--- a/tools/PascalParser.hs	Sun Nov 27 19:34:08 2011 +0300
+++ b/tools/PascalParser.hs	Sun Nov 27 23:13:22 2011 +0300
@@ -16,6 +16,7 @@
 data PascalUnit =
     Program Identifier Implementation Phrase
     | Unit Identifier Interface Implementation (Maybe Initialize) (Maybe Finalize)
+    | System
     deriving Show
 data Interface = Interface Uses TypesAndVars
     deriving Show
@@ -57,7 +58,7 @@
         | ForCycle Identifier Expression Expression Phrase
         | WithBlock Reference Phrase
         | Phrases [Phrase]
-        | SwitchCase Expression [([InitExpression], Phrase)] (Maybe Phrase)
+        | SwitchCase Expression [([InitExpression], Phrase)] (Maybe [Phrase])
         | Assignment Reference Expression
         | NOP
     deriving Show
@@ -78,11 +79,12 @@
     deriving Show
 data Reference = ArrayElement [Expression] Reference
     | FunCall [Expression] Reference
-    | TypeCast Identifier Reference
+    | TypeCast Identifier Expression
     | SimpleReference Identifier
     | Dereference Reference
     | RecordField Reference Reference
     | Address Reference
+    | RefExpression Expression
     deriving Show
 data InitExpression = InitBinOp String InitExpression InitExpression
     | InitPrefixOp String InitExpression
@@ -95,11 +97,14 @@
     | InitString String
     | InitChar String
     | BuiltInFunction String [InitExpression]
-    | InitSet [Identifier]
+    | InitSet [InitExpression]
+    | InitAddress InitExpression
     | InitNull
+    | InitRange Range
+    | InitTypeCast Identifier InitExpression
     deriving Show
     
-knownTypes = ["shortstring"]
+knownTypes = ["shortstring", "char", "byte"]
 
 pascalUnit = do
     comments
@@ -126,14 +131,13 @@
 reference = buildExpressionParser table term <?> "reference"
     where
     term = comments >> choice [
-        parens pas (reference >>= postfixes) >>= postfixes
-        , typeCast >>= postfixes
+        parens pas (liftM RefExpression expression >>= postfixes) >>= postfixes
+        , try $ typeCast >>= postfixes
         , char '@' >> liftM Address reference >>= postfixes
         , liftM SimpleReference iD >>= postfixes 
         ] <?> "simple reference"
 
     table = [ 
-            [Infix (try (char '.' >> notFollowedBy (char '.')) >> return RecordField) AssocLeft]
         ]
     
     postfixes r = many postfix >>= return . foldl (flip ($)) r
@@ -141,13 +145,14 @@
             parens pas (option [] parameters) >>= return . FunCall
           , char '^' >> return Dereference
           , (brackets pas) (commaSep1 pas $ expression) >>= return . ArrayElement
+          , (char '.' >> notFollowedBy (char '.')) >> liftM RecordField reference
         ]
 
     typeCast = do
         t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes
-        r <- parens pas reference
+        e <- parens pas expression
         comments
-        return $ TypeCast (Identifier t) r
+        return $ TypeCast (Identifier t) e
         
     
 varsDecl1 = varsParser sepEndBy1    
@@ -293,6 +298,7 @@
         semi pas
         comments
         return $ TypeDeclaration i t
+
         
 rangeDecl = choice [
     try $ rangeft
@@ -303,7 +309,7 @@
     e1 <- initExpression
     string ".."
     e2 <- initExpression
-    return $ RangeFromTo e1 e2
+    return $ RangeFromTo e1 e2        
     
 typeVarDeclaration isImpl = (liftM concat . many . choice) [
     varSection,
@@ -385,8 +391,10 @@
         
     functionDecorator = choice [
         try $ string "inline;"
-        , try $ string "cdecl;"
+        , try $ caseInsensitiveString "cdecl;"
         , try $ string "overload;"
+        , try $ string "export;"
+        , try $ string "varargs;"
         , try (string "external") >> comments >> iD >> optional (string "name" >> comments >> stringLiteral pas)>> string ";"
         ] >> comments
         
@@ -431,7 +439,7 @@
     where
     term = comments >> choice [
         builtInFunction expression >>= \(n, e) -> return $ BuiltInFunCall e (SimpleReference (Identifier n))
-        , parens pas $ expression 
+        , try (parens pas $ expression >>= \e -> notFollowedBy (comments >> char '.') >> return e)
         , brackets pas (commaSep pas iD) >>= return . SetExpression
         , try $ natural pas >>= \i -> notFollowedBy (char '.') >> (return . NumberLiteral . show) i
         , float pas >>= return . FloatLiteral . show
@@ -490,6 +498,7 @@
         , forCycle
         , (try $ reference >>= \r -> string ":=" >> return r) >>= \r -> expression >>= return . Assignment r
         , procCall
+        , char ';' >> comments >> return NOP
         ]
     optional $ char ';'
     comments
@@ -572,7 +581,7 @@
     o2 <- optionMaybe $ do
         try $ string "else" >> notFollowedBy alphaNum
         comments
-        o <- phrase
+        o <- many phrase
         comments
         return o
     string "end"
@@ -580,7 +589,7 @@
     return $ SwitchCase e cs o2
     where
     aCase = do
-        e <- (commaSep pas) initExpression
+        e <- (commaSep pas) $ (liftM InitRange rangeDecl <|> initExpression)
         comments
         char ':'
         comments
@@ -617,16 +626,18 @@
     where
     term = comments >> choice [
         liftM (uncurry BuiltInFunction) $ builtInFunction initExpression 
-        , try $ brackets pas (commaSep pas $ iD) >>= return . InitSet
+        , try $ brackets pas (commaSep pas $ initExpression) >>= return . InitSet
         , try $ parens pas (commaSep pas $ initExpression) >>= return . InitArray
-        , parens pas (semiSep pas $ recField) >>= return . InitRecord
+        , parens pas (sepEndBy recField (char ';' >> comments)) >>= return . InitRecord
         , try $ integer pas >>= \i -> notFollowedBy (char '.') >> (return . InitNumber . show) i
         , try $ float pas >>= return . InitFloat . show
         , try $ integer pas >>= return . InitNumber . show
         , stringLiteral pas >>= return . InitString
         , char '#' >> many digit >>= \c -> comments >> return (InitChar c)
         , char '$' >> many hexDigit >>= \h -> comments >> return (InitHexNumber h)
+        , char '@' >> initExpression >>= \c -> comments >> return (InitAddress c)
         , try $ string "nil" >> return InitNull
+        , itypeCast
         , iD >>= return . InitReference
         ]
         
@@ -666,6 +677,12 @@
         , [Prefix (try (string "not") >> return (InitPrefixOp "not"))]
         ]
 
+    itypeCast = do
+        t <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) knownTypes
+        i <- parens pas initExpression
+        comments
+        return $ InitTypeCast (Identifier t) i
+        
 builtInFunction e = do
     name <- choice $ map (\s -> try $ caseInsensitiveString s >>= \i -> notFollowedBy alphaNum >> return i) builtin
     spaces
diff -r 7c6f9b6672dc -r 11c578d30bd3 tools/PascalPreprocessor.hs
--- a/tools/PascalPreprocessor.hs	Sun Nov 27 19:34:08 2011 +0300
+++ b/tools/PascalPreprocessor.hs	Sun Nov 27 23:13:22 2011 +0300
@@ -58,6 +58,7 @@
         s <- choice [
             include
             , ifdef
+            , if'
             , elseSwitch
             , endIf
             , define
@@ -89,10 +90,20 @@
         
         updateState $ \(m, b) ->
             (m, (f $ d `Map.member` m) : b)
-        
       
         return ""
+
+    if' = do
+        s <- try (string "IF" >> notFollowedBy alphaNum)
         
+        manyTill anyChar (char '}')
+        --char '}'
+        
+        updateState $ \(m, b) ->
+            (m, False : b)
+      
+        return ""
+
     elseSwitch = do
         try $ string "ELSE}"
         updateState $ \(m, b:bs) -> (m, (not b):bs)
diff -r 7c6f9b6672dc -r 11c578d30bd3 tools/pas2c.hs
--- a/tools/pas2c.hs	Sun Nov 27 19:34:08 2011 +0300
+++ b/tools/pas2c.hs	Sun Nov 27 23:13:22 2011 +0300
@@ -30,7 +30,9 @@
                 $ tryJust (guard . isDoesNotExistError) 
                 $ hPutStr stderr ("Preprocessing '" ++ fileName ++ ".pas'... ") >> preprocess (fileName ++ ".pas")
             case fc' of
-                (Left a) -> printLn "doesn't exist"
+                (Left a) -> do
+                    modify (Map.insert fileName System)
+                    printLn "doesn't exist"
                 (Right fc) -> do
                     printLn "ok"
                     let ptree = parse pascalUnit fileName fc