Move some stuff from uMisc to uUtils
authorunC0Rr
Thu, 18 Nov 2010 11:32:47 +0300
changeset 4374 bcefeeabaa33
parent 4373 fe0e3903bb9e
child 4375 ae5507ddb989
Move some stuff from uMisc to uUtils
hedgewars/CMakeLists.txt
hedgewars/hwengine.pas
hedgewars/uAI.pas
hedgewars/uAIActions.pas
hedgewars/uAIAmmoTests.pas
hedgewars/uAIMisc.pas
hedgewars/uAmmos.pas
hedgewars/uChat.pas
hedgewars/uCommands.pas
hedgewars/uConsole.pas
hedgewars/uFloat.pas
hedgewars/uGears.pas
hedgewars/uIO.pas
hedgewars/uKeys.pas
hedgewars/uLand.pas
hedgewars/uLandGraphics.pas
hedgewars/uLandObjects.pas
hedgewars/uLocale.pas
hedgewars/uMisc.pas
hedgewars/uScript.pas
hedgewars/uSound.pas
hedgewars/uStats.pas
hedgewars/uStore.pas
hedgewars/uTeams.pas
hedgewars/uUtils.pas
hedgewars/uWorld.pas
--- a/hedgewars/CMakeLists.txt	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/CMakeLists.txt	Thu Nov 18 11:32:47 2010 +0300
@@ -69,6 +69,7 @@
     uStore.pas
     uTeams.pas
     uTypes.pas
+    uUtils.pas
     uVisualGears.pas
     uWorld.pas
     CCHandlers.inc
--- a/hedgewars/hwengine.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/hwengine.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -31,7 +31,7 @@
 
 uses SDLh, uMisc, uConsole, uGame, uConsts, uLand, uAmmos, uVisualGears, uGears, uStore, uWorld, uKeys, uSound,
      uScript, uTeams, uStats, uIO, uLocale, uChat, uAI, uAIMisc, uRandom, uLandTexture, uCollisions, uMobile,
-     sysutils, uTypes, uVariables, uCommands;
+     sysutils, uTypes, uVariables, uCommands, uUtils;
 
 var isTerminated: boolean = false;
     alsoShutdownFrontend: boolean = false;
@@ -319,6 +319,7 @@
     Randomize();
 
     // uConsts does not need initialization as they are all consts
+    uUtils.initModule;
     uMisc.initModule;
     uVariables.initModule;
     uConsole.initModule;    // MUST happen after uMisc
@@ -392,6 +393,7 @@
     uCommands.freeModule;
     uConsole.freeModule;
     uVariables.freeModule;
+    uUtils.freeModule;
     uMisc.freeModule;           // uMisc closes the debug log.
 end;
 
--- a/hedgewars/uAI.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uAI.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -31,7 +31,7 @@
 implementation
 uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions, uMisc,
      uAmmos, SysUtils{$IFDEF UNIX}, cthreads{$ENDIF}, uTypes,
-     uVariables, uCommands;
+     uVariables, uCommands, uUtils;
 
 var BestActions: TActions;
     CanUseAmmo: array [TAmmoType] of boolean;
@@ -201,12 +201,12 @@
 Push(0, Actions, Me^, tmp);
 Push(0, Actions, Me^, tmp xor 3);
 
-if (Me^.State and gstAttacked) = 0 then maxticks:= max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel))
+if (Me^.State and gstAttacked) = 0 then maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel))
                                    else maxticks:= TurnTimeLeft;
 
 if (Me^.State and gstAttacked) = 0 then TestAmmos(Actions, Me, false);
 BestRate:= RatePlace(Me);
-BaseRate:= max(BestRate, 0);
+BaseRate:= Max(BestRate, 0);
 
 while (Stack.Count > 0) and (not StopThinking) and (GameFlags and gfArtillery = 0) do
     begin
--- a/hedgewars/uAIActions.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uAIActions.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -62,7 +62,7 @@
 procedure ProcessAction(var Actions: TActions; Me: PGear);
 
 implementation
-uses uMisc, uAIMisc, uAI, uAmmos, uVariables, uCommands;
+uses uMisc, uAIMisc, uAI, uAmmos, uVariables, uCommands, uUtils;
 
 const ActionIdToStr: array[0..6] of string[16] = (
 {aia_none}           '',
@@ -95,8 +95,8 @@
 else begin
    WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]);
    if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then
-      WriteLnToConsole('AI action Wait X = '+inttostr(Action.Param)+', current X = '+inttostr(hwRound(Me^.X)))
-   else if (Action.Action = aia_AwareExpl) then WriteLnToConsole('Aware X = ' + inttostr(Action.X) + ', Y = ' + inttostr(Action.Y));
+      WriteLnToConsole('AI action Wait X = '+IntToStr(Action.Param)+', current X = '+IntToStr(hwRound(Me^.X)))
+   else if (Action.Action = aia_AwareExpl) then WriteLnToConsole('Aware X = ' + IntToStr(Action.X) + ', Y = ' + IntToStr(Action.Y));
    end
 end;
 {$ENDIF}
@@ -199,7 +199,7 @@
              aim_push: s:= '+' + s;
           aim_release: s:= '-' + s;
              end
-          else if Param <> 0 then s:= s + ' ' + inttostr(Param);
+          else if Param <> 0 then s:= s + ' ' + IntToStr(Param);
         ParseCommand(s, true)
         end
      end;
--- a/hedgewars/uAIAmmoTests.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uAIAmmoTests.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -108,7 +108,7 @@
 const BadTurn = Low(LongInt) div 4;
 
 implementation
-uses uMisc, uAIMisc, uVariables;
+uses uAIMisc, uVariables, uUtils;
 
 function Metric(x1, y1, x2, y2: LongInt): LongInt;
 begin
@@ -539,7 +539,7 @@
     or (y.Round > LongWord(LAND_HEIGHT))
     or (d > 200);
 
-if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then valueResult:= max(0, (4 - d div 50) * 7 * 1024)
+if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then valueResult:= Max(0, (4 - d div 50) * 7 * 1024)
                                                            else valueResult:= BadTurn;
 TestDesertEagle:= valueResult
 end;
--- a/hedgewars/uAIMisc.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uAIMisc.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -68,7 +68,7 @@
              end;
 
 implementation
-uses uMisc, uCollisions, uVariables;
+uses uMisc, uCollisions, uVariables, uUtils;
 
 
 const KillScore = 200;
--- a/hedgewars/uAmmos.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uAmmos.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -47,7 +47,7 @@
 var StoreCnt: Longword;
 
 implementation
-uses uMisc, uWorld, uLocale, uMobile, uVariables, uCommands;
+uses uMisc, uWorld, uLocale, uMobile, uVariables, uCommands, uUtils;
 
 type TAmmoCounts = array[TAmmoType] of Longword;
 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
@@ -326,7 +326,7 @@
             if (Count <> AMMO_INFINITE) and not (Hedgehog.Team^.ExtDriven or (Hedgehog.BotLevel > 0)) then
                 s:= s + ' (' + IntToStr(Count) + ')';
             if (Propz and ammoprop_Timerable) <> 0 then
-                s:= s + ', ' + inttostr(Timer div 1000) + ' ' + trammo[sidSeconds];
+                s:= s + ', ' + IntToStr(Timer div 1000) + ' ' + trammo[sidSeconds];
             AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
             end;
         if (Propz and ammoprop_NeedTarget) <> 0
--- a/hedgewars/uChat.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uChat.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -34,7 +34,7 @@
     showAll: boolean;
 
 implementation
-uses uMisc, uStore, SDLh, uKeys, uTypes, uVariables, uCommands;
+uses uMisc, uStore, SDLh, uKeys, uTypes, uVariables, uCommands, uUtils;
 
 const MaxStrIndex = 27;
 
--- a/hedgewars/uCommands.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uCommands.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -15,9 +15,9 @@
 procedure doPut(putX, putY: LongInt; fromAI: boolean);
 
 implementation
-uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uMobile,
+uses uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uMobile,
      uRandom, uAmmos, uStats, uChat, SDLh, uSound, uVisualGears, uScript, uTypes,
-     uVariables, uConsole, uFloat;
+     uVariables, uConsole, uFloat, uMisc, uUtils;
 
 type  PVariable = ^TVariable;
       TVariable = record
--- a/hedgewars/uConsole.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uConsole.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -28,7 +28,7 @@
 function  GetLastConsoleLine: shortstring;
 
 implementation
-uses uMisc, Types, uVariables;
+uses uMisc, Types, uVariables, uUtils;
 
 const cLineWidth: LongInt = 0;
       cLinesCount = 256;
--- a/hedgewars/uFloat.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uFloat.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -62,6 +62,7 @@
 function AngleSin(const Angle: Longword): hwFloat;
 function AngleCos(const Angle: Longword): hwFloat;
 function SignAs(const num, signum: hwFloat): hwFloat; inline;
+function hwSign(r: hwFloat): LongInt; inline;
 
 {$IFDEF FPC}
 {$J-}
@@ -342,6 +343,12 @@
 SignAs.isNegative:= signum.isNegative
 end;
 
+function hwSign(r: hwFloat): LongInt;
+begin
+// yes, we have negative zero for a reason
+if r.isNegative then hwSign:= -1 else hwSign:= 1
+end;
+
 {$INCLUDE "SinTable.inc"}
 
 function AngleSin(const Angle: Longword): hwFloat;
--- a/hedgewars/uGears.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uGears.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -47,7 +47,7 @@
 implementation
 uses uWorld, uMisc, uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics,
      uAIMisc, uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uMobile, uVariables,
-     uCommands;
+     uCommands, uUtils;
 
 const MAXROPEPOINTS = 384;
 var RopePoints: record
--- a/hedgewars/uIO.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uIO.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -42,7 +42,7 @@
 procedure NetGetNextCmd;
 
 implementation
-uses uConsole, uConsts, uMisc, uLand, uChat, uTeams, uTypes, uVariables, uCommands;
+uses uConsole, uConsts, uMisc, uLand, uChat, uTeams, uTypes, uVariables, uCommands, uUtils;
 
 type PCmd = ^TCmd;
      TCmd = packed record
@@ -138,7 +138,7 @@
      else
      loTicks:= SDLNet_Read16(@s[byte(s[0]) - 1]);
      AddCmd(loTicks, s);
-     {$IFDEF DEBUGFILE}AddFileLog('IPC in: '+s[1]+' ticks '+inttostr(lastcmd^.loTime));{$ENDIF}
+     {$IFDEF DEBUGFILE}AddFileLog('IPC in: '+s[1]+' ticks '+IntToStr(lastcmd^.loTime));{$ENDIF}
      end
 end;
 
@@ -311,7 +311,7 @@
         'F': TeamGone(copy(headcmd^.str, 2, Pred(headcmd^.len)));
         'N': begin
             tmpflag:= false;
-            {$IFDEF DEBUGFILE}AddFileLog('got cmd "N": time '+inttostr(hiTicks shl 16 + headcmd^.loTime)){$ENDIF}
+            {$IFDEF DEBUGFILE}AddFileLog('got cmd "N": time '+IntToStr(hiTicks shl 16 + headcmd^.loTime)){$ENDIF}
             end;
         'p': begin
             x16:= SDLNet_Read16(@(headcmd^.X));
@@ -342,8 +342,8 @@
 if (headcmd <> nil) and tmpflag and (not CurrentTeam^.hasGone) then
     TryDo(GameTicks < hiTicks shl 16 + headcmd^.loTime,
             'oops, queue error. in buffer: ' + headcmd^.cmd +
-            ' (' + inttostr(GameTicks) + ' > ' +
-            inttostr(hiTicks shl 16 + headcmd^.loTime) + ')',
+            ' (' + IntToStr(GameTicks) + ' > ' +
+            IntToStr(hiTicks shl 16 + headcmd^.loTime) + ')',
             true);
 
 isInLag:= (headcmd = nil) and tmpflag and (not CurrentTeam^.hasGone);
--- a/hedgewars/uKeys.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uKeys.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -82,7 +82,7 @@
 {$ENDIF}
 {$ENDIF}
 implementation
-uses uConsole, uCommands, uMisc, uVariables, uConsts;
+uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils;
 //const KeyNumber = 1024;
 
 var tkbd, tkbdn: TKeyboardState;
@@ -193,7 +193,7 @@
 k:= SDL_GetMouseState(nil, nil);
 {$IFNDEF IPHONEOS}pkbd:={$ENDIF}SDL_GetKeyState(@j);
 
-TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true);
+TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + IntToStr(j) + ')', true);
 
 {$IFNDEF IPHONEOS}
 for i:= 1 to pred(j) do
@@ -262,7 +262,7 @@
 for i:= 6 to cKeyMaxIndex do
     begin
     s:= shortstring(sdl_getkeyname(i));
-    //writeln(stdout,inttostr(i) + ': ' + s);
+    //writeln(stdout,IntToStr(i) + ': ' + s);
     if s = 'unknown key' then KeyNames[i]:= ''
     else 
         begin
@@ -272,7 +272,7 @@
         end;
     end;
 
-//for i:= 0 to cKeyMaxIndex do writeln(stdout,inttostr(i) + ': ' + KeyNames[i]);
+//for i:= 0 to cKeyMaxIndex do writeln(stdout,IntToStr(i) + ': ' + KeyNames[i]);
 
 // get the size of keyboard array
 SDL_GetKeyState(@k);
@@ -282,21 +282,21 @@
     begin
     for i:= 0 to Pred(ControllerNumAxes[j]) do
         begin
-        keynames[k + 0]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'u';
-        keynames[k + 1]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'd';
+        keynames[k + 0]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'u';
+        keynames[k + 1]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'd';
         inc(k, 2);
         end;
     for i:= 0 to Pred(ControllerNumHats[j]) do
         begin
-        keynames[k + 0]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'u';
-        keynames[k + 1]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'r';
-        keynames[k + 2]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'd';
-        keynames[k + 3]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'l';
+        keynames[k + 0]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'u';
+        keynames[k + 1]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'r';
+        keynames[k + 2]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'd';
+        keynames[k + 3]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'l';
         inc(k, 4);
         end;
     for i:= 0 to Pred(ControllerNumButtons[j]) do
         begin
-        keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i);
+        keynames[k]:= 'j' + IntToStr(j) + 'b' + IntToStr(i);
         inc(k, 1);
         end;
     end;
@@ -347,7 +347,7 @@
 DefaultBinds[KeyNameToCode('left_shift')]:= '+precise';
 {$ENDIF}
 
-for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+inttostr(i))]:= 'slot '+inttostr(i);
+for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i);
 
 SetDefaultBinds();
 end;
@@ -422,7 +422,7 @@
 ControllerNumControllers:= SDL_NumJoysticks();
 if ControllerNumControllers > 6 then ControllerNumControllers:= 6;
 
-WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers));
+WriteLnToConsole('Number of game controllers: ' + IntToStr(ControllerNumControllers));
 
 if ControllerNumControllers > 0 then
     begin
@@ -438,10 +438,10 @@
             //ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]);
             ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]);
             ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]);
-            WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j]));
-            //WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j]));
-            WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j]));
-            WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j]));
+            WriteLnToConsole('* Number of axes: ' + IntToStr(ControllerNumAxes[j]));
+            //WriteLnToConsole('* Number of balls: ' + IntToStr(ControllerNumBalls[j]));
+            WriteLnToConsole('* Number of hats: ' + IntToStr(ControllerNumHats[j]));
+            WriteLnToConsole('* Number of buttons: ' + IntToStr(ControllerNumButtons[j]));
             ControllerEnabled:= 1;
 
             if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20;
--- a/hedgewars/uLand.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uLand.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -36,7 +36,7 @@
 
 implementation
 uses uConsole, uStore, uMisc, uRandom, uLandObjects, Adler32, uIO, uLandTexture, sysutils,
-     uVariables;
+     uVariables, uUtils;
 
 operator=(const a, b: direction) c: Boolean;
 begin
@@ -358,7 +358,7 @@
                 r.x:= x mod tmpsurf^.w;
                 r.y:= 0;
                 r.w:= 1;
-                r.h:= min(16, yd - yu + 1);
+                r.h:= Min(16, yd - yu + 1);
                 SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
             end;
             yd:= yu - 1;
--- a/hedgewars/uLandGraphics.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uLandGraphics.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -40,25 +40,25 @@
 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean;
 
 implementation
-uses SDLh, uMisc, uLandTexture, uVariables;
+uses SDLh, uMisc, uLandTexture, uVariables, uUtils;
 
 procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword);
 var i: LongInt;
 begin
 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
         if (Land[y + dy, i] and lfIndestructible) = 0 then
             Land[y + dy, i]:= Value;
 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
         if (Land[y - dy, i] and lfIndestructible) = 0 then
             Land[y - dy, i]:= Value;
 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
         if (Land[y + dx, i] and lfIndestructible) = 0 then
             Land[y + dx, i]:= Value;
 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
         if (Land[y - dx, i] and lfIndestructible) = 0 then
             Land[y - dx, i]:= Value;
 end;
@@ -69,33 +69,33 @@
 if not doSet then
    begin
    if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+      for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
           if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data
    if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+      for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
           if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then dec(Land[y - dy, i]);
    if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+      for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
           if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then dec(Land[y + dx, i]);
    if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+      for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
           if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then dec(Land[y - dx, i]);
    end else
    begin
    if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+      for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
           if (Land[y + dy, i] < 256) then
               inc(Land[y + dy, i]);
    if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+      for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
           if (Land[y - dy, i] < 256) then
               inc(Land[y - dy, i]);
    if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+      for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
           if (Land[y + dx, i] < 256) then
               inc(Land[y + dx, i]);
    if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+      for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
           if (Land[y - dx, i] < 256) then
               inc(Land[y - dx, i]);
    end
@@ -146,7 +146,7 @@
 begin
 t:= y + dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
         if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then
             if (cReducedQuality and rqBlurryLand) = 0 then
                 LandPixels[t, i]:= 0
@@ -155,7 +155,7 @@
 
 t:= y - dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
         if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then
             if (cReducedQuality and rqBlurryLand) = 0 then
                 LandPixels[t, i]:= 0
@@ -164,7 +164,7 @@
 
 t:= y + dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
         if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then
             if (cReducedQuality and rqBlurryLand) = 0 then
                 LandPixels[t, i]:= 0
@@ -173,7 +173,7 @@
 
 t:= y - dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
         if (not isMap and ((Land[t, i] and lfIndestructible) = 0)) or ((Land[t, i] and lfBasic) <> 0) then
             if (cReducedQuality and rqBlurryLand) = 0 then
                 LandPixels[t, i]:= 0
@@ -189,7 +189,7 @@
 cnt:= 0;
 t:= y + dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
        if ((Land[t, i] and lfBasic) <> 0) then
            begin
            inc(cnt);
@@ -207,7 +207,7 @@
 
 t:= y - dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
        if ((Land[t, i] and lfBasic) <> 0) then
            begin
            inc(cnt);
@@ -225,7 +225,7 @@
 
 t:= y + dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+   for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
        if ((Land[t, i] and lfBasic) <> 0) then
            begin
            inc(cnt);
@@ -243,7 +243,7 @@
 
 t:= y - dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+   for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
        if ((Land[t, i] and lfBasic) <> 0) then
            begin
            inc(cnt);
@@ -266,7 +266,7 @@
 begin
 t:= y + dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
           begin
            if (cReducedQuality and rqBlurryLand) = 0 then
@@ -281,7 +281,7 @@
 
 t:= y - dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
+   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
           begin
            if (cReducedQuality and rqBlurryLand) = 0 then
@@ -295,7 +295,7 @@
 
 t:= y + dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+   for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
            begin
            if (cReducedQuality and rqBlurryLand) = 0 then
@@ -310,7 +310,7 @@
 
 t:= y - dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
+   for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
           begin
            if (cReducedQuality and rqBlurryLand) = 0 then
@@ -394,10 +394,10 @@
     if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy);
     end;
 
-tx:= max(X - Radius - 1, 0);
-dx:= min(X + Radius + 1, LAND_WIDTH) - tx;
-ty:= max(Y - Radius - 1, 0);
-dy:= min(Y + Radius + 1, LAND_HEIGHT) - ty;
+tx:= Max(X - Radius - 1, 0);
+dx:= Min(X + Radius + 1, LAND_WIDTH) - tx;
+ty:= Max(Y - Radius - 1, 0);
+dy:= Min(Y + Radius + 1, LAND_HEIGHT) - ty;
 UpdateLandTexture(tx, dx, ty, dy);
 DrawExplosion:= cnt
 end;
@@ -407,8 +407,8 @@
 begin
 for i:= 0 to Pred(Count) do
     begin
-    for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do
-        for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do
+    for ty:= Max(y - Radius, 0) to Min(y + Radius, LAND_HEIGHT) do
+        for tx:= Max(0, ar^[i].Left - Radius) to Min(LAND_WIDTH, ar^[i].Right + Radius) do
             if (Land[ty, tx] and lfBasic) <> 0 then
                 if (cReducedQuality and rqBlurryLand) = 0 then
                     LandPixels[ty, tx]:= LandBackPixel(tx, ty)
@@ -428,8 +428,8 @@
 
 for i:= 0 to Pred(Count) do
     begin
-    for ty:= max(y - Radius, 0) to min(y + Radius, LAND_HEIGHT) do
-        for tx:= max(0, ar^[i].Left - Radius) to min(LAND_WIDTH, ar^[i].Right + Radius) do
+    for ty:= Max(y - Radius, 0) to Min(y + Radius, LAND_HEIGHT) do
+        for tx:= Max(0, ar^[i].Left - Radius) to Min(LAND_WIDTH, ar^[i].Right + Radius) do
             if ((Land[ty, tx] and lfBasic) <> 0) or ((Land[ty, tx] and lfObject) <> 0) then
                 begin
                     if (cReducedQuality and rqBlurryLand) = 0 then
@@ -585,10 +585,10 @@
     ny:= ny + dX;
     end;
 
-tx:= max(stX - HalfWidth * 2 - 4 - abs(hwRound(dX * ticks)), 0);
-ty:= max(stY - HalfWidth * 2 - 4 - abs(hwRound(dY * ticks)), 0);
-ddx:= min(stX + HalfWidth * 2 + 4 + abs(hwRound(dX * ticks)), LAND_WIDTH) - tx;
-ddy:= min(stY + HalfWidth * 2 + 4 + abs(hwRound(dY * ticks)), LAND_HEIGHT) - ty;
+tx:= Max(stX - HalfWidth * 2 - 4 - abs(hwRound(dX * ticks)), 0);
+ty:= Max(stY - HalfWidth * 2 - 4 - abs(hwRound(dY * ticks)), 0);
+ddx:= Min(stX + HalfWidth * 2 + 4 + abs(hwRound(dX * ticks)), LAND_WIDTH) - tx;
+ddy:= Min(stY + HalfWidth * 2 + 4 + abs(hwRound(dY * ticks)), LAND_HEIGHT) - ty;
 
 UpdateLandTexture(tx, ddx, ty, ddy)
 end;
@@ -661,10 +661,10 @@
 if SDL_MustLock(Image) then
    SDL_UnlockSurface(Image);
 
-x:= max(cpX, leftX);
-w:= min(cpX + Image^.w, LAND_WIDTH) - x;
-y:= max(cpY, topY);
-h:= min(cpY + Image^.h, LAND_HEIGHT) - y;
+x:= Max(cpX, leftX);
+w:= Min(cpX + Image^.w, LAND_WIDTH) - x;
+y:= Max(cpY, topY);
+h:= Min(cpY + Image^.h, LAND_HEIGHT) - y;
 UpdateLandTexture(x, w, y, h)
 end;
 
--- a/hedgewars/uLandObjects.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uLandObjects.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -30,7 +30,7 @@
 
 implementation
 uses uStore, uConsts, uMisc, uConsole, uRandom, uVisualGears, uSound, GLunit,
-    uTypes, uVariables;
+     uTypes, uVariables, uUtils;
 
 const MaxRects = 512;
       MAXOBJECTRECTS = 16;
--- a/hedgewars/uLocale.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uLocale.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -35,7 +35,7 @@
 function  GetEventString(e: TEventId): ansistring;
 
 implementation
-uses uMisc, uRandom;
+uses uMisc, uRandom, uUtils;
 
 var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of ansistring;
     trevt_n: array[TEventId] of integer;
@@ -77,7 +77,7 @@
            0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b+1)]:= s;
            1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s;
            2: if (b >=0) and (b <= ord(High(TEventId))) then begin
-               TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + inttostr(a) + ':' + inttostr(b), false);
+               TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false);
                if first[TEventId(b)] then
                    begin
                    trevt_n[TEventId(b)]:= 0;
--- a/hedgewars/uMisc.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uMisc.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -21,103 +21,33 @@
 unit uMisc;
 interface
 
-uses    SDLh, uConsts, uFloat, GLunit, Math, uTypes;
+uses    SDLh, uConsts, GLunit, uTypes;
 
 
-procedure SplitBySpace(var a, b: shortstring);
-procedure SplitByChar(var a, b: ansistring; c: char);
-function  EnumToStr(const en : TGearType) : shortstring; overload;
-function  EnumToStr(const en : TSound) : shortstring; overload;
-function  EnumToStr(const en : TAmmoType) : shortstring; overload;
-function  EnumToStr(const en : THogEffect) : shortstring; overload;
 procedure movecursor(dx, dy: LongInt);
-function  hwSign(r: hwFloat): LongInt; inline;
-function  Min(a, b: LongInt): LongInt; inline;
-function  Max(a, b: LongInt): LongInt; inline;
-procedure OutError(Msg: shortstring; isFatalError: boolean);
-procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
-procedure SDLTry(Assert: boolean; isFatal: boolean);
-function  IntToStr(n: LongInt): shortstring;
-function  FloatToStr(n: hwFloat): shortstring;
-function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
-function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
-function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
 (*
 procedure AdjustColor(var Color: Longword);
 procedure SetKB(n: Longword);
 *)
 procedure SendKB;
-procedure SetLittle(var r: hwFloat);
 procedure SendStat(sit: TStatInfoType; s: shortstring);
-function  Str2PChar(const s: shortstring): PChar;
 function  NewTexture(width, height: Longword; buf: Pointer): PTexture;
 function  Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
 procedure FreeTexture(tex: PTexture);
-function  toPowerOf2(i: Longword): Longword; inline;
-function  DecodeBase64(s: shortstring): shortstring;
 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
-function  endian(independent: LongWord): LongWord; inline;
-{$IFDEF DEBUGFILE}
-procedure AddFileLog(s: shortstring);
-(* function  RectToStr(Rect: TSDL_Rect): shortstring; *)
-{$ENDIF}
+procedure OutError(Msg: shortstring; isFatalError: boolean);
+procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline;
+procedure SDLTry(Assert: boolean; isFatal: boolean);
 procedure MakeScreenshot(filename: shortstring);
 
 procedure initModule;
 procedure freeModule;
 
 implementation
-uses uConsole, uIO, typinfo, sysutils, uVariables;
+uses uConsole, uIO, typinfo, sysutils, uVariables, uUtils;
 
 var KBnum: Longword;
-{$IFDEF DEBUGFILE}
-    f: textfile;
-{$ENDIF}
 
-// should this include "strtolower()" for the split string?
-procedure SplitBySpace(var a, b: shortstring);
-var i, t: LongInt;
-begin
-i:= Pos(' ', a);
-if i > 0 then
-    begin
-    for t:= 1 to Pred(i) do
-        if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32);
-    b:= copy(a, i + 1, Length(a) - i);
-    byte(a[0]):= Pred(i)
-    end else b:= '';
-end;
-
-procedure SplitByChar(var a, b: ansistring; c: char);
-var i: LongInt;
-begin
-i:= Pos(c, a);
-if i > 0 then
-    begin
-    b:= copy(a, i + 1, Length(a) - i);
-    setlength(a, Pred(i));
-    end else b:= '';
-end;
-
-function EnumToStr(const en : TGearType) : shortstring; overload;
-begin
-EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
-end;
-
-function EnumToStr(const en : TSound) : shortstring; overload;
-begin
-EnumToStr:= GetEnumName(TypeInfo(TSound), ord(en))
-end;
-
-function EnumToStr(const en : TAmmoType) : shortstring; overload;
-begin
-EnumToStr:= GetEnumName(TypeInfo(TAmmoType), ord(en))
-end;
-
-function EnumToStr(const en: THogEffect) : shortstring; overload;
-begin
-    EnumToStr := GetEnumName(TypeInfo(THogEffect), ord(en))
-end;
 
 procedure movecursor(dx, dy: LongInt);
 var x, y: LongInt;
@@ -130,21 +60,6 @@
 SDL_WarpMouse(x, y);
 end;
 
-function hwSign(r: hwFloat): LongInt;
-begin
-// yes, we have negative zero for a reason
-if r.isNegative then hwSign:= -1 else hwSign:= 1
-end;
-
-function Min(a, b: LongInt): LongInt;
-begin
-if a < b then Min:= a else Min:= b
-end;
-
-function Max(a, b: LongInt): LongInt;
-begin
-if a > b then Max:= a else Max:= b
-end;
 
 procedure OutError(Msg: shortstring; isFatalError: boolean);
 begin
@@ -182,16 +97,6 @@
 *)
 
 
-function IntToStr(n: LongInt): shortstring;
-begin
-str(n, IntToStr)
-end;
-
-function FloatToStr(n: hwFloat): shortstring;
-begin
-FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue))
-end;
-
 procedure SetTextureParameters(enableClamp: Boolean);
 begin
     if enableClamp and ((cReducedQuality and rqClampLess) = 0) then
@@ -203,37 +108,6 @@
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
 end;
 
-function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
-var dY, dX: Extended;
-begin
-dY:= _dY.QWordValue / $100000000;
-if _dY.isNegative then dY:= - dY;
-dX:= _dX.QWordValue / $100000000;
-if _dX.isNegative then dX:= - dX;
-DxDy2Angle:= arctan2(dY, dX) * 180 / pi
-end;
-
-function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
-const _16divPI: Extended = 16/pi;
-var dY, dX: Extended;
-begin
-dY:= _dY.QWordValue / $100000000;
-if _dY.isNegative then dY:= - dY;
-dX:= _dX.QWordValue / $100000000;
-if _dX.isNegative then dX:= - dX;
-DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f
-end;
-
-function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
-const MaxAngleDivPI: Extended = cMaxAngle/pi;
-var dY, dX: Extended;
-begin
-dY:= _dY.QWordValue / $100000000;
-if _dY.isNegative then dY:= - dY;
-dX:= _dX.QWordValue / $100000000;
-if _dX.isNegative then dX:= - dX;
-DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
-end;
 
 procedure SendKB;
 var s: shortstring;
@@ -245,11 +119,6 @@
 end
 end;
 
-procedure SetLittle(var r: hwFloat);
-begin
-r:= SignAs(cLittle, r)
-end;
-
 procedure SendStat(sit: TStatInfoType; s: shortstring);
 const stc: array [TStatInfoType] of char = 'rDkKHTPsSB';
 var buf: shortstring;
@@ -258,26 +127,6 @@
 SendIPCRaw(@buf[0], length(buf) + 1)
 end;
 
-function Str2PChar(const s: shortstring): PChar;
-const CharArray: array[byte] of Char = '';
-begin
-CharArray:= s;
-CharArray[Length(s)]:= #0;
-Str2PChar:= @CharArray
-end;
-
-function isPowerOf2(i: Longword): boolean;
-begin
-if i = 0 then exit(true);
-while (i and 1) = 0 do i:= i shr 1;
-isPowerOf2:= (i = 1)
-end;
-
-function toPowerOf2(i: Longword): Longword;
-begin
-toPowerOf2:= 1;
-while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1
-end;
 
 procedure ResetVertexArrays(texture: PTexture);
 begin
@@ -425,33 +274,6 @@
     end
 end;
 
-function DecodeBase64(s: shortstring): shortstring;
-const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
-var i, t, c: Longword;
-begin
-c:= 0;
-for i:= 1 to Length(s) do
-    begin
-    t:= Pos(s[i], table);
-    if s[i] = '=' then inc(c);
-    if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0
-    end;
-
-i:= 1;
-t:= 1;
-while i <= length(s) do
-    begin
-    DecodeBase64[t    ]:= char((byte(s[i    ]) shl 2) or (byte(s[i + 1]) shr 4));
-    DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2));
-    DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3])      ));
-    inc(t, 3);
-    inc(i, 4)
-    end;
-
-if c < 3 then t:= t - c;
-
-byte(DecodeBase64[0]):= t - 1
-end;
 
 procedure MakeScreenshot(filename: shortstring);
 var p: Pointer;
@@ -523,20 +345,6 @@
 FreeMem(p)
 end;
 
-{$IFDEF DEBUGFILE}
-procedure AddFileLog(s: shortstring);
-begin
-writeln(f, GameTicks: 6, ': ', s);
-flush(f)
-end;
-(*
-function RectToStr(Rect: TSDL_Rect): shortstring;
-begin
-RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')'
-end;
-*)
-{$ENDIF}
-
 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
 {* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *}
 var convertedSurf: PSDL_Surface = nil;
@@ -551,69 +359,16 @@
     exit(tmpsurf);
 end;
 
-function endian(independent: LongWord): LongWord; inline;
-begin
-{$IFDEF ENDIAN_LITTLE}
-endian:= independent;
-{$ELSE}
-endian:= (((independent and $FF000000) shr 24) or
-          ((independent and $00FF0000) shr 8) or
-          ((independent and $0000FF00) shl 8) or
-          ((independent and $000000FF) shl 24))
-{$ENDIF}
-end;
-
 
 procedure initModule;
-{$IFDEF DEBUGFILE}{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}{$ENDIF}
 begin
     KBnum           := 0;
-
-{$IFDEF DEBUGFILE}
-{$I-}
-{$IFDEF IPHONEOS}
-    Assign(f,'../Documents/hw-' + cLogfileBase + '.log');
-    Rewrite(f);
-{$ELSE}
-    if (ParamStr(1) <> '') and (ParamStr(2) <> '') then
-        if (ParamCount <> 3) and (ParamCount <> cDefaultParamNum) then
-        begin
-            for i:= 0 to 7 do
-            begin
-                assign(f, ExtractFileDir(ParamStr(2)) + '/' + cLogfileBase + inttostr(i) + '.log');
-                rewrite(f);
-                if IOResult = 0 then break;
-            end;
-            if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
-        end
-        else
-        begin
-            for i:= 0 to 7 do
-            begin
-                assign(f, ParamStr(1) + '/Logs/' + cLogfileBase + inttostr(i) + '.log');
-                rewrite(f);
-                if IOResult = 0 then break;
-            end;
-            if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
-        end
-    else
-        f:= stderr;
-{$ENDIF}
-{$I+}
-{$ENDIF}
-
 end;
 
 procedure freeModule;
 begin
     recordFileName:= '';
     while TextureList <> nil do FreeTexture(TextureList);
-
-{$IFDEF DEBUGFILE}
-    writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft);
-    flush(f);
-    close(f);
-{$ENDIF}
 end;
 
 end.
--- a/hedgewars/uScript.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uScript.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -54,7 +54,8 @@
     uRandom,
     uTypes,
     uVariables,
-    uCommands;
+    uCommands,
+    uUtils;
 
 var luaState : Plua_State;
     ScriptAmmoLoadout : shortstring;
--- a/hedgewars/uSound.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uSound.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -46,7 +46,7 @@
 
 
 implementation
-uses uMisc, uVariables, uConsole;
+uses uMisc, uVariables, uConsole, uUtils;
 
 const chanTPU = 32;
 var Volume: LongInt;
--- a/hedgewars/uStats.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uStats.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -35,7 +35,7 @@
 procedure SendStats;
 
 implementation
-uses uTeams, uSound, uMisc, uLocale, uWorld, uVariables;
+uses uTeams, uSound, uMisc, uLocale, uWorld, uVariables, uUtils;
 
 var DamageGiven : Longword = 0;
     DamageClan  : Longword = 0;
@@ -158,7 +158,7 @@
 for t:= 0 to Pred(ClansCount) do
     with ClansArray[t]^ do
         begin
-        SendStat(siClanHealth, inttostr(Color) + ' ' + inttostr(ClanHealth));
+        SendStat(siClanHealth, IntToStr(Color) + ' ' + IntToStr(ClanHealth));
         end;
 
 Kills:= 0;
@@ -218,8 +218,8 @@
 
         { send player stats for winner teams }
         if Clan^.ClanHealth > 0 then begin
-            SendStat(siPlayerKills, inttostr(Clan^.Color) + ' ' +
-                inttostr(stats.Kills) + ' ' + TeamName);
+            SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
+                IntToStr(stats.Kills) + ' ' + TeamName);
         end;
 
         { determine maximum values of TeamKills, TurnSkips, TeamDamage }
@@ -242,25 +242,25 @@
 for t:= 0 to Pred(TeamsCount) do begin
     with TeamsArray[t]^ do begin
         if Clan^.ClanHealth = 0 then begin
-            SendStat(siPlayerKills, inttostr(Clan^.Color) + ' ' +
-                inttostr(stats.Kills) + ' ' + TeamName);
+            SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
+                IntToStr(stats.Kills) + ' ' + TeamName);
         end;
     end;
 end;
 
 if msdhh <> nil then
-    SendStat(siMaxStepDamage, inttostr(msd) + ' ' + msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
+    SendStat(siMaxStepDamage, IntToStr(msd) + ' ' + msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
 if mskcnt = 1 then
-    SendStat(siMaxStepKills, inttostr(msk) + ' ' + mskhh^.Name + ' (' + mskhh^.Team^.TeamName + ')');
+    SendStat(siMaxStepKills, IntToStr(msk) + ' ' + mskhh^.Name + ' (' + mskhh^.Team^.TeamName + ')');
 
 if maxTeamKills > 1 then
-    SendStat(siMaxTeamKills, inttostr(maxTeamKills) + ' ' + maxTeamKillsName);
+    SendStat(siMaxTeamKills, IntToStr(maxTeamKills) + ' ' + maxTeamKillsName);
 if maxTurnSkips > 2 then
-    SendStat(siMaxTurnSkips, inttostr(maxTurnSkips) + ' ' + maxTurnSkipsName);
+    SendStat(siMaxTurnSkips, IntToStr(maxTurnSkips) + ' ' + maxTurnSkipsName);
 if maxTeamDamage > 30 then
-    SendStat(siMaxTeamDamage, inttostr(maxTeamDamage) + ' ' + maxTeamDamageName);
+    SendStat(siMaxTeamDamage, IntToStr(maxTeamDamage) + ' ' + maxTeamDamageName);
 
-if KilledHHs > 0 then SendStat(siKilledHHs, inttostr(KilledHHs));
+if KilledHHs > 0 then SendStat(siKilledHHs, IntToStr(KilledHHs));
 end;
 
 procedure initModule;
--- a/hedgewars/uStore.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uStore.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -66,7 +66,7 @@
 procedure Tint(c: Longword); inline;
 
 implementation
-uses uMisc, uConsole, uLocale, uMobile, uVariables;
+uses uMisc, uConsole, uLocale, uMobile, uVariables, uUtils;
 
 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
 
--- a/hedgewars/uTeams.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uTeams.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -37,7 +37,7 @@
 function  GetTeamStatString(p: PTeam): shortstring;
 
 implementation
-uses uMisc, uWorld, uLocale, uAmmos, uChat, uMobile, uVariables;
+uses uMisc, uWorld, uLocale, uAmmos, uChat, uMobile, uVariables, uUtils;
 const MaxTeamHealth: LongInt = 0;
 
 function CheckForWin: boolean;
@@ -413,7 +413,7 @@
 function GetTeamStatString(p: PTeam): shortstring;
 var s: ansistring;
 begin
-    s:= p^.TeamName + ':' + inttostr(p^.TeamHealth) + ':';
+    s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':';
     GetTeamStatString:= s;
 end;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uUtils.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -0,0 +1,280 @@
+{$INCLUDE "options.inc"}
+unit uUtils;
+
+interface
+uses uTypes, uFloat, GLunit;
+
+procedure SplitBySpace(var a, b: shortstring);
+procedure SplitByChar(var a, b: ansistring; c: char);
+
+function  EnumToStr(const en : TGearType) : shortstring; overload;
+function  EnumToStr(const en : TSound) : shortstring; overload;
+function  EnumToStr(const en : TAmmoType) : shortstring; overload;
+function  EnumToStr(const en : THogEffect) : shortstring; overload;
+
+function  Min(a, b: LongInt): LongInt; inline;
+function  Max(a, b: LongInt): LongInt; inline;
+
+function  IntToStr(n: LongInt): shortstring;
+function  FloatToStr(n: hwFloat): shortstring;
+
+function  DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
+function  DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
+function  DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
+
+procedure SetLittle(var r: hwFloat);
+
+function  Str2PChar(const s: shortstring): PChar;
+function  DecodeBase64(s: shortstring): shortstring;
+
+function  isPowerOf2(i: Longword): boolean;
+function  toPowerOf2(i: Longword): Longword; inline;
+
+function  endian(independent: LongWord): LongWord; inline;
+
+{$IFDEF DEBUGFILE}
+procedure AddFileLog(s: shortstring);
+{$ENDIF}
+
+procedure initModule;
+procedure freeModule;
+
+implementation
+uses typinfo, Math, uConsts, uVariables, SysUtils;
+
+var
+{$IFDEF DEBUGFILE}
+    f: textfile;
+{$ENDIF}
+
+// should this include "strtolower()" for the split string?
+procedure SplitBySpace(var a, b: shortstring);
+var i, t: LongInt;
+begin
+i:= Pos(' ', a);
+if i > 0 then
+    begin
+    for t:= 1 to Pred(i) do
+        if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32);
+    b:= copy(a, i + 1, Length(a) - i);
+    byte(a[0]):= Pred(i)
+    end else b:= '';
+end;
+
+procedure SplitByChar(var a, b: ansistring; c: char);
+var i: LongInt;
+begin
+i:= Pos(c, a);
+if i > 0 then
+    begin
+    b:= copy(a, i + 1, Length(a) - i);
+    setlength(a, Pred(i));
+    end else b:= '';
+end;
+
+function EnumToStr(const en : TGearType) : shortstring; overload;
+begin
+EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en))
+end;
+
+function EnumToStr(const en : TSound) : shortstring; overload;
+begin
+EnumToStr:= GetEnumName(TypeInfo(TSound), ord(en))
+end;
+
+function EnumToStr(const en : TAmmoType) : shortstring; overload;
+begin
+EnumToStr:= GetEnumName(TypeInfo(TAmmoType), ord(en))
+end;
+
+function EnumToStr(const en: THogEffect) : shortstring; overload;
+begin
+    EnumToStr := GetEnumName(TypeInfo(THogEffect), ord(en))
+end;
+
+
+function Min(a, b: LongInt): LongInt;
+begin
+if a < b then Min:= a else Min:= b
+end;
+
+function Max(a, b: LongInt): LongInt;
+begin
+if a > b then Max:= a else Max:= b
+end;
+
+
+function IntToStr(n: LongInt): shortstring;
+begin
+str(n, IntToStr)
+end;
+
+function FloatToStr(n: hwFloat): shortstring;
+begin
+FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue))
+end;
+
+
+function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat;
+var dY, dX: Extended;
+begin
+dY:= _dY.QWordValue / $100000000;
+if _dY.isNegative then dY:= - dY;
+dX:= _dX.QWordValue / $100000000;
+if _dX.isNegative then dX:= - dX;
+DxDy2Angle:= arctan2(dY, dX) * 180 / pi
+end;
+
+function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt;
+const _16divPI: Extended = 16/pi;
+var dY, dX: Extended;
+begin
+dY:= _dY.QWordValue / $100000000;
+if _dY.isNegative then dY:= - dY;
+dX:= _dX.QWordValue / $100000000;
+if _dX.isNegative then dX:= - dX;
+DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f
+end;
+
+function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt;
+const MaxAngleDivPI: Extended = cMaxAngle/pi;
+var dY, dX: Extended;
+begin
+dY:= _dY.QWordValue / $100000000;
+if _dY.isNegative then dY:= - dY;
+dX:= _dX.QWordValue / $100000000;
+if _dX.isNegative then dX:= - dX;
+DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
+end;
+
+
+procedure SetLittle(var r: hwFloat);
+begin
+r:= SignAs(cLittle, r)
+end;
+
+
+function isPowerOf2(i: Longword): boolean;
+begin
+if i = 0 then exit(true);
+while not odd(i) do i:= i shr 1;
+isPowerOf2:= (i = 1)
+end;
+
+function toPowerOf2(i: Longword): Longword;
+begin
+toPowerOf2:= 1;
+while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1
+end;
+
+
+function DecodeBase64(s: shortstring): shortstring;
+const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
+var i, t, c: Longword;
+begin
+c:= 0;
+for i:= 1 to Length(s) do
+    begin
+    t:= Pos(s[i], table);
+    if s[i] = '=' then inc(c);
+    if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0
+    end;
+
+i:= 1;
+t:= 1;
+while i <= length(s) do
+    begin
+    DecodeBase64[t    ]:= char((byte(s[i    ]) shl 2) or (byte(s[i + 1]) shr 4));
+    DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2));
+    DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3])      ));
+    inc(t, 3);
+    inc(i, 4)
+    end;
+
+if c < 3 then t:= t - c;
+
+byte(DecodeBase64[0]):= t - 1
+end;
+
+
+function Str2PChar(const s: shortstring): PChar;
+const CharArray: array[byte] of Char = '';
+begin
+CharArray:= s;
+CharArray[Length(s)]:= #0;
+Str2PChar:= @CharArray
+end;
+
+
+function endian(independent: LongWord): LongWord; inline;
+begin
+{$IFDEF ENDIAN_LITTLE}
+endian:= independent;
+{$ELSE}
+endian:= (((independent and $FF000000) shr 24) or
+          ((independent and $00FF0000) shr 8) or
+          ((independent and $0000FF00) shl 8) or
+          ((independent and $000000FF) shl 24))
+{$ENDIF}
+end;
+
+
+{$IFDEF DEBUGFILE}
+procedure AddFileLog(s: shortstring);
+begin
+writeln(f, GameTicks: 6, ': ', s);
+flush(f)
+end;
+{$ENDIF}
+
+
+procedure initModule;
+{$IFDEF DEBUGFILE}{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}{$ENDIF}
+begin
+{$IFDEF DEBUGFILE}
+{$I-}
+{$IFDEF IPHONEOS}
+    Assign(f,'../Documents/hw-' + cLogfileBase + '.log');
+    Rewrite(f);
+{$ELSE}
+    if (ParamStr(1) <> '') and (ParamStr(2) <> '') then
+        if (ParamCount <> 3) and (ParamCount <> cDefaultParamNum) then
+        begin
+            for i:= 0 to 7 do
+            begin
+                assign(f, ExtractFileDir(ParamStr(2)) + '/' + cLogfileBase + inttostr(i) + '.log');
+                rewrite(f);
+                if IOResult = 0 then break;
+            end;
+            if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
+        end
+        else
+        begin
+            for i:= 0 to 7 do
+            begin
+                assign(f, ParamStr(1) + '/Logs/' + cLogfileBase + inttostr(i) + '.log');
+                rewrite(f);
+                if IOResult = 0 then break;
+            end;
+            if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr
+        end
+    else
+        f:= stderr;
+{$ENDIF}
+{$I+}
+{$ENDIF}
+
+end;
+
+procedure freeModule;
+begin
+    recordFileName:= '';
+
+{$IFDEF DEBUGFILE}
+    writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft);
+    flush(f);
+    close(f);
+{$ENDIF}
+end;
+
+end.
\ No newline at end of file
--- a/hedgewars/uWorld.pas	Thu Nov 18 09:12:27 2010 +0300
+++ b/hedgewars/uWorld.pas	Thu Nov 18 11:32:47 2010 +0300
@@ -45,7 +45,8 @@
     uChat,
     uLandTexture,
     GLunit,
-    uVariables
+    uVariables,
+    uUtils
     ;
 
 type TCaptionStr = record
@@ -385,7 +386,7 @@
 {$IFDEF IPHONEOS}
     ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, AMyOffset - 1);
 {$ELSE}
-    ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
+    ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, Min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
 {$ENDIF}
 
 bSelected:= false;
@@ -570,7 +571,7 @@
     begin
         // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway
         ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine);
-        offsetY:= 10 * min(0, -145 - ScreenBottom);
+        offsetY:= 10 * Min(0, -145 - ScreenBottom);
         SkyOffset:= offsetY div 35 + cWaveHeight;
         HorizontOffset:= SkyOffset;
         if ScreenBottom > SkyOffset then
@@ -864,7 +865,7 @@
     if (ReadyTimeLeft = 0) and (missionTimer > 0) then dec(missionTimer, Lag);
     if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0
     if missionTex <> nil then
-        DrawCentered(0, min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
+        DrawCentered(0, Min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
     end;
 
 // fps
@@ -1155,7 +1156,7 @@
 
 procedure ShakeCamera(amount: LongWord);
 begin
-    amount:= max(1, amount);
+    amount:= Max(1, amount);
     WorldDx:= WorldDx - amount + LongInt(getRandom(1 + amount * 2));
     WorldDy:= WorldDy - amount + LongInt(getRandom(1 + amount * 2));
 end;