# HG changeset patch
# User koda
# Date 1272825739 0
# Node ID 8fdb08497bf17b7e265b8edf102a12a61655f2e4
# Parent  d445798e5fe26a80716180d2f1d4f275e05a9c14
js' patch that restores Vsync on snow leopard
fix water zoom
portait rotation now display water correctly (but not the other ui elements)

diff -r d445798e5fe2 -r 8fdb08497bf1 cocoaTouch/MasterViewController.m
--- a/cocoaTouch/MasterViewController.m	Sun May 02 18:25:13 2010 +0000
+++ b/cocoaTouch/MasterViewController.m	Sun May 02 18:42:19 2010 +0000
@@ -25,7 +25,7 @@
 
 #pragma mark -
 #pragma mark View lifecycle
-- (void)viewDidLoad {
+-(void) viewDidLoad {
     [super viewDidLoad];
     
     // the list of selectable controllers
@@ -64,34 +64,6 @@
     return cell;
 }
 
-/*
-// Override to support editing the table view.
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-    
-    if (editingStyle == UITableViewCellEditingStyleDelete) {
-        // Delete the row from the data source
-        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
-    }   
-    else if (editingStyle == UITableViewCellEditingStyleInsert) {
-        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
-    }   
-}
-*/
-
-/*
-// Override to support rearranging the table view.
-- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
-}
-*/
-
-/*
-// Override to support conditional rearranging of the table view.
-- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
-    // Return NO if you do not want the item to be re-orderable.
-    return YES;
-}
-*/
-
 #pragma mark -
 #pragma mark Table view delegate
 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
diff -r d445798e5fe2 -r 8fdb08497bf1 cocoaTouch/OverlayViewController.m
--- a/cocoaTouch/OverlayViewController.m	Sun May 02 18:25:13 2010 +0000
+++ b/cocoaTouch/OverlayViewController.m	Sun May 02 18:42:19 2010 +0000
@@ -69,7 +69,6 @@
 }
 
 -(void) viewDidLoad {
-
     isPopoverVisible = NO;
     self.view.alpha = 0;
     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
diff -r d445798e5fe2 -r 8fdb08497bf1 cocoaTouch/SplitViewRootController.m
--- a/cocoaTouch/SplitViewRootController.m	Sun May 02 18:25:13 2010 +0000
+++ b/cocoaTouch/SplitViewRootController.m	Sun May 02 18:42:19 2010 +0000
@@ -47,7 +47,8 @@
         UINavigationController *mainNavController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
     
         masterViewController.detailViewController = detailViewController;
-
+        //[splitViewRootController setDelegate:detailViewController];
+        
         [masterViewController release];
 
         [splitViewRootController setViewControllers:[NSArray arrayWithObjects: mainNavController, detailedNavController, nil]];
diff -r d445798e5fe2 -r 8fdb08497bf1 cocoaTouch/otherSrc/CommodityFunctions.m
--- a/cocoaTouch/otherSrc/CommodityFunctions.m	Sun May 02 18:25:13 2010 +0000
+++ b/cocoaTouch/otherSrc/CommodityFunctions.m	Sun May 02 18:42:19 2010 +0000
@@ -44,7 +44,7 @@
 
 BOOL rotationManager (UIInterfaceOrientation interfaceOrientation) {
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
-        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
+        return YES;
     else
         return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
 
diff -r d445798e5fe2 -r 8fdb08497bf1 hedgewars/CCHandlers.inc
--- a/hedgewars/CCHandlers.inc	Sun May 02 18:25:13 2010 +0000
+++ b/hedgewars/CCHandlers.inc	Sun May 02 18:42:19 2010 +0000
@@ -665,12 +665,12 @@
         cScreenHeight:= cInitHeight
     end;
 
-    // load window icon
 {$IFDEF SDL_IMAGE_NEWER}
     WriteToConsole('Init SDL_image... ');
     SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
     WriteLnToConsole(msgOK);
 {$ENDIF}
+    // load engine icon
 {$IFDEF DARWIN}
     ico:= LoadImage(Pathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
 {$ELSE}
diff -r d445798e5fe2 -r 8fdb08497bf1 hedgewars/PascalExports.pas
--- a/hedgewars/PascalExports.pas	Sun May 02 18:25:13 2010 +0000
+++ b/hedgewars/PascalExports.pas	Sun May 02 18:42:19 2010 +0000
@@ -140,22 +140,23 @@
 end;
 
 procedure HW_setLandscape(landscape: boolean); cdecl; export;
+var tmp:LongInt;
 begin
     if landscape then
     begin
         rotationQt:= -90;
         uStore.wScreen:= cScreenWidth;
         uStore.hScreen:= cScreenHeight;
-        //uWorld.w:= cScreenWidth;
-        //uWorld.h:= cScreenHeight;
+        uWorld.wScreen:= cScreenWidth;
+        uWorld.hScreen:= cScreenHeight;
     end
     else
     begin
         rotationQt:= 270;
         uStore.wScreen:= cScreenHeight;
         uStore.hScreen:= cScreenWidth;
-        //uWorld.w:= cScreenHeight;
-        //uWorld.h:= cScreenWidth;
+        uWorld.wScreen:= cScreenHeight;
+        uWorld.hScreen:= cScreenWidth;
     end;
 end;
 {$ENDIF}
diff -r d445798e5fe2 -r 8fdb08497bf1 hedgewars/SDLh.pas
--- a/hedgewars/SDLh.pas	Sun May 02 18:25:13 2010 +0000
+++ b/hedgewars/SDLh.pas	Sun May 02 18:42:19 2010 +0000
@@ -60,6 +60,7 @@
     {$linkframework SDL_image}
     {$linkframework SDL_ttf}
     {$linkframework SDL_mixer}
+    {$linkframework OpenGL}
   {$ENDIF}
 {$ENDIF}
 
@@ -732,6 +733,12 @@
 function SDL_putenv(const text: PChar): LongInt; cdecl; external SDLLibName;
 function SDL_getenv(const text: PChar): PChar; cdecl; external SDLLibName;
 
+{* OpenGL *}
+{$IFDEF DARWIN}
+function CGLGetCurrentContext(): Pointer; cdecl; external 'OpenGL';
+procedure CGLSetParameter(context: Pointer; option: LongInt; value: Pointer); cdecl; external 'OpenGL';
+{$ENDIF}
+
 (*  SDL_TTF  *)
 function  TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
 procedure TTF_Quit; cdecl; external SDL_TTFLibName;
diff -r d445798e5fe2 -r 8fdb08497bf1 hedgewars/uAmmos.pas
--- a/hedgewars/uAmmos.pas	Sun May 02 18:25:13 2010 +0000
+++ b/hedgewars/uAmmos.pas	Sun May 02 18:42:19 2010 +0000
@@ -41,7 +41,7 @@
 procedure SetWeapon(weap: TAmmoType);
 procedure DisableSomeWeapons;
 procedure ResetWeapons;
-function GetAmmoByNum(num: Longword): PHHAmmo;
+function  GetAmmoByNum(num: Longword): PHHAmmo;
 
 var shoppa: boolean;
 
diff -r d445798e5fe2 -r 8fdb08497bf1 hedgewars/uGears.pas
--- a/hedgewars/uGears.pas	Sun May 02 18:25:13 2010 +0000
+++ b/hedgewars/uGears.pas	Sun May 02 18:42:19 2010 +0000
@@ -89,10 +89,10 @@
 procedure FreeGearsList;
 procedure AddMiscGears;
 procedure AssignHHCoords;
-function GearByUID(uid : Longword) : PGear;
+function  GearByUID(uid : Longword) : PGear;
 procedure InsertGearToList(Gear: PGear);
 procedure RemoveGearFromList(Gear: PGear);
-function ModifyDamage(dmg: Longword; Gear: PGear): Longword;
+function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
 
 implementation
diff -r d445798e5fe2 -r 8fdb08497bf1 hedgewars/uStore.pas
--- a/hedgewars/uStore.pas	Sun May 02 18:25:13 2010 +0000
+++ b/hedgewars/uStore.pas	Sun May 02 18:42:19 2010 +0000
@@ -608,7 +608,7 @@
 
 procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real);
 begin
-DrawRotatedTex(SpritesData[Sprite].Texture,
+    DrawRotatedTex(SpritesData[Sprite].Texture,
         SpritesData[Sprite].Width,
         SpritesData[Sprite].Height,
         X, Y, Dir, Angle)
@@ -711,11 +711,11 @@
 procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt);
 var r: TSDL_Rect;
 begin
-r.x:= FrameX * SpritesData[Sprite].Width;
-r.w:= SpritesData[Sprite].Width;
-r.y:= FrameY * SpritesData[Sprite].Height;
-r.h:= SpritesData[Sprite].Height;
-DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture)
+    r.x:= FrameX * SpritesData[Sprite].Width;
+    r.w:= SpritesData[Sprite].Width;
+    r.y:= FrameY * SpritesData[Sprite].Height;
+    r.h:= SpritesData[Sprite].Height;
+    DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture)
 end;
 
 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
@@ -803,14 +803,15 @@
 procedure StoreRelease;
 var ii: TSprite;
 begin
-for ii:= Low(TSprite) to High(TSprite) do
+    for ii:= Low(TSprite) to High(TSprite) do
     begin
-    FreeTexture(SpritesData[ii].Texture);
-    if SpritesData[ii].Surface <> nil then SDL_FreeSurface(SpritesData[ii].Surface)
+        FreeTexture(SpritesData[ii].Texture);
+        if SpritesData[ii].Surface <> nil then
+            SDL_FreeSurface(SpritesData[ii].Surface)
     end;
-SDL_FreeSurface(MissionIcons);
-FreeTexture(ropeIconTex);
-FreeTexture(HHTexture)
+    SDL_FreeSurface(MissionIcons);
+    FreeTexture(ropeIconTex);
+    FreeTexture(HHTexture);
 end;
 
 
@@ -1134,12 +1135,32 @@
 
 procedure SetupOpenGL;
 var vendor: shortstring;
+{$IFDEF DARWIN}
+    one: LongInt;
+{$ENDIF}
 begin
+    // initialized here because when initModule is called cScreenWidth/Height are not yet set
+    if (uStore.wScreen = 0) and (uStore.hScreen = 0) then
+    begin
+        uStore.wScreen:= cScreenWidth; 
+        uStore.hScreen:= cScreenHeight;
+    end;
+
 {$IFDEF IPHONEOS}
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); // no double buffering
     SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
 {$ELSE}
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+{$IFNDEF SDL13}
+// this attribute is default in 1.3 and must be enabled in MacOSX
+    if cVSyncInUse then
+        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
+{$IFDEF DARWIN}
+// fixes vsync in Snow Leopard
+    one := 1;
+    CGLSetParameter(CGLGetCurrentContext(), 222, @one);
+{$ENDIF}
+{$ENDIF}
 {$ENDIF}
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // no depth buffer
     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
@@ -1149,14 +1170,6 @@
     SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer has to be 16 bit only
     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // try to prefer hardware rendering
 
-{$IFNDEF SDL13}
-// this attribute is default in 1.3 and must be enabled in MacOSX
-{$IFNDEF DARWIN}
-    if cVSyncInUse then
-{$ENDIF}
-        SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
-{$ENDIF}
-
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
 
     vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
@@ -1276,7 +1289,7 @@
     r.w:= squaresize;
     r.h:= squaresize;
     
-    DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
+    DrawFromRect( -squaresize div 2, (hScreen - squaresize) shr 1, @r, ProgrTex);
 
     SDL_GL_SwapBuffers();
 {$IFDEF SDL13}
@@ -1554,8 +1567,10 @@
 {$ELSE}
     cGPUVendor:= gvUnknown;
 {$ENDIF}
-    uStore.wScreen:= cScreenWidth; 
-    uStore.hScreen:= cScreenHeight;
+    // really initalized in storeLoad
+    uStore.wScreen:= 0; 
+    uStore.hScreen:= 0;
+    
     cScaleFactor:= 2.0;
     SupportNPOTT:= false;
     Step:= 0;
diff -r d445798e5fe2 -r 8fdb08497bf1 hedgewars/uWorld.pas
--- a/hedgewars/uWorld.pas	Sun May 02 18:25:13 2010 +0000
+++ b/hedgewars/uWorld.pas	Sun May 02 18:42:19 2010 +0000
@@ -37,7 +37,9 @@
 {$IFDEF COUNTTICKS}
     cntTicks: LongWord;
 {$ENDIF}
-
+    wScreen: LongInt;
+    hScreen: LongInt;
+    
 procedure initModule;
 procedure freeModule;
 
@@ -94,7 +96,13 @@
         AddGoal:= s;
     end;
 begin
-missionTimer:= 0;
+    missionTimer:= 0;
+    // initialized here because when initModule is called cScreenWidth/Height are not yet set
+    if (uWorld.wScreen = 0) and (uWorld.hScreen = 0) then
+    begin
+        uWorld.wScreen:= cScreenWidth; 
+        uWorld.hScreen:= cScreenHeight;
+    end;
 
 if (GameFlags and gfRandomOrder) <> 0 then  // shuffle them up a bit
    begin
@@ -170,6 +178,7 @@
 HorizontOffset:= 0;
 end;
 
+
 procedure ShowAmmoMenu;
 const MENUSPEED = 15;
 {$IFDEF IPHONEOS}
@@ -181,141 +190,151 @@
     Slot, Pos: LongInt;
     Ammo: PHHAmmo;
 begin
-if  (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or ((CurAmmoGear^.Ammo^.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) then bShowAmmoMenu:= false;
-if bShowAmmoMenu then
-   begin
-   FollowGear:= nil;
-   if AMxShift = MENUWIDTH then prevPoint.X:= 0;
-   if cReducedQuality then
-       AMxShift:= 0
-   else
-       if AMxShift > 0 then dec(AMxShift, MENUSPEED);
-   end else
-   begin
-   if AMxShift = 0 then
-      begin
-      CursorPoint.X:= cScreenWidth shr 1;
-      CursorPoint.Y:= cScreenHeight shr 1;
-      prevPoint:= CursorPoint;
-      SDL_WarpMouse(CursorPoint.X  + cScreenWidth div 2, cScreenHeight - CursorPoint.Y)
-      end;
-   if cReducedQuality then
-       AMxShift:= MENUWIDTH
-   else
-       if AMxShift < MENUWIDTH then inc(AMxShift, MENUSPEED);
-   end;
-Ammo:= nil;
-if (CurrentTeam <> nil) and (CurrentHedgehog <> nil) and (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then
-   Ammo:= CurrentHedgehog^.Ammo
-else if (LocalAmmo <> -1) then
-   Ammo:= GetAmmoByNum(LocalAmmo);
-Slot:= 0;
-Pos:= -1;
-if Ammo = nil then
+    if (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or 
+       ((CurAmmoGear^.Ammo^.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) then
+            bShowAmmoMenu:= false;
+    if bShowAmmoMenu then
+    begin
+        FollowGear:= nil;
+        if AMxShift = MENUWIDTH then 
+            prevPoint.X:= 0;
+        if cReducedQuality then
+            AMxShift:= 0
+        else
+            if AMxShift > 0 then 
+                dec(AMxShift, MENUSPEED);
+    end
+    else
     begin
-    bShowAmmoMenu:= false;
-    exit
+        if AMxShift = 0 then
+        begin
+            CursorPoint.X:= cScreenWidth shr 1;
+            CursorPoint.Y:= cScreenHeight shr 1;
+            prevPoint:= CursorPoint;
+            SDL_WarpMouse(CursorPoint.X  + cScreenWidth div 2, cScreenHeight - CursorPoint.Y)
+        end;
+        if cReducedQuality then
+            AMxShift:= MENUWIDTH
+    else
+        if AMxShift < MENUWIDTH then
+            inc(AMxShift, MENUSPEED);
     end;
-SlotsNum:= 0;
-x:= (cScreenWidth shr 1) - MENUWIDTH + AMxShift;
-y:= cScreenHeight - 40;
+   
+    Ammo:= nil;
+    if (CurrentTeam <> nil) and (CurrentHedgehog <> nil) and (not CurrentTeam^.ExtDriven) and
+       (CurrentHedgehog^.BotLevel = 0) then
+        Ammo:= CurrentHedgehog^.Ammo
+    else
+        if (LocalAmmo <> -1) then
+            Ammo:= GetAmmoByNum(LocalAmmo);
+        Slot:= 0;
+        Pos:= -1;
+        if Ammo = nil then
+        begin
+            bShowAmmoMenu:= false;
+            exit
+        end;
+        SlotsNum:= 0;
+        x:= (cScreenWidth shr 1) - MENUWIDTH + AMxShift;
+        y:= cScreenHeight - 40;
 
 {$IFDEF IPHONEOS}
-dec(y);
-DrawSprite(sprAMBordersIPhone, x, y, 0);
-dec(y);
-DrawSprite(sprAMBordersIPhone, x, y, 1);
-dec(y, 33);
-DrawSprite(sprAMSlotNameIPhone, x, y, 0);
+        dec(y);
+        DrawSprite(sprAMBordersIPhone, x, y, 0);
+        dec(y);
+        DrawSprite(sprAMBordersIPhone, x, y, 1);
+        dec(y, 33);
+        DrawSprite(sprAMSlotNameIPhone, x, y, 0);
 {$ELSE}
-dec(y);
-DrawSprite(sprAMBorders, x, y, 0);
-dec(y);
-DrawSprite(sprAMBorders, x, y, 1);
-dec(y, 33);
-DrawSprite(sprAMSlotName, x, y, 0);
+        dec(y);
+        DrawSprite(sprAMBorders, x, y, 0);
+        dec(y);
+        DrawSprite(sprAMBorders, x, y, 1);
+        dec(y, 33);
+        DrawSprite(sprAMSlotName, x, y, 0);
 {$ENDIF}
 
-for i:= cMaxSlotIndex downto 0 do
-    if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
-        begin
-        if (cScreenHeight - CursorPoint.Y >= y - 33) and (cScreenHeight - CursorPoint.Y < y) then Slot:= i;
-        dec(y, 33);
-        inc(SlotsNum);
-        {$IFDEF IPHONEOS}
-        DrawSprite(sprAMSlotIPhone, x, y, 0);
-        {$ELSE}
-        DrawSprite(sprAMSlot, x, y, 0);
-        DrawSprite(sprAMSlotKeys, x + 2, y + 1, i);
-        {$ENDIF}
-        t:= 0;
-        {$IFDEF IPHONEOS}
-        g:= -1;
-        {$ELSE}
-        g:= 0;
-        {$ENDIF}
-        while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
+        for i:= cMaxSlotIndex downto 0 do
+            if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
             begin
-            if (Ammo^[i, t].AmmoType <> amNothing) then
+                if (cScreenHeight - CursorPoint.Y >= y - 33) and (cScreenHeight - CursorPoint.Y < y) then 
+                    Slot:= i;
+                dec(y, 33);
+                inc(SlotsNum);
+{$IFDEF IPHONEOS}
+                DrawSprite(sprAMSlotIPhone, x, y, 0);
+                g:= -1;
+{$ELSE}
+                DrawSprite(sprAMSlot, x, y, 0);
+                DrawSprite(sprAMSlotKeys, x + 2, y + 1, i);
+                g:= 0;
+{$ENDIF}
+                t:= 0;
+
+                while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
                 begin
-                l:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
+                    if (Ammo^[i, t].AmmoType <> amNothing) then
+                    begin
+                        l:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
 
-                if l >= 0 then
-                    begin
-                    DrawSprite(sprAMAmmosBW, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
-                    if l < 100 then DrawSprite(sprTurnsLeft, x + g * 33 + 51, y + 17, l);
-                    end else
-                    DrawSprite(sprAMAmmos, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
-                if (Slot = i)
-                and (CursorPoint.X >= x + g * 33 + 35)
-                and (CursorPoint.X < x + g * 33 + 68) then
-                    begin
-                    if (l < 0) then DrawSprite(sprAMSelection, x + g * 33 + 35, y + 1, 0);
-                    Pos:= t;
+                        if l >= 0 then
+                        begin
+                            DrawSprite(sprAMAmmosBW, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
+                            if l < 100 then
+                                DrawSprite(sprTurnsLeft, x + g * 33 + 51, y + 17, l);
+                        end
+                        else
+                            DrawSprite(sprAMAmmos, x + g * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
+                        if (Slot = i) and (CursorPoint.X >= x + g * 33 + 35) and (CursorPoint.X < x + g * 33 + 68) then
+                        begin
+                            if (l < 0) then 
+                                DrawSprite(sprAMSelection, x + g * 33 + 35, y + 1, 0);
+                            Pos:= t;
+                        end;
+                        inc(g);
                     end;
-                inc(g)
+                    inc(t);
                 end;
-                inc(t)
-            end
-        end;
-dec(y, 1);
+            end;
+    dec(y, 1);
 {$IFDEF IPHONEOS}
-DrawSprite(sprAMBordersIPhone, x, y, 0);
+    DrawSprite(sprAMBordersIPhone, x, y, 0);
 {$ELSE}
-DrawSprite(sprAMBorders, x, y, 0);
+    DrawSprite(sprAMBorders, x, y, 0);
 {$ENDIF}
 
-if (Pos >= 0) then
+    if (Pos >= 0) then
     begin
-    if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
-        if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
+        if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
+            if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
             begin
-            amSel:= Ammo^[Slot, Pos].AmmoType;
-            RenderWeaponTooltip(amSel)
+                amSel:= Ammo^[Slot, Pos].AmmoType;
+                RenderWeaponTooltip(amSel)
             end;
         
-        DrawTexture(cScreenWidth div 2 - (MENUWIDTH - 10) + AMxShift, cScreenHeight - 68, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
+            DrawTexture(cScreenWidth div 2 - (MENUWIDTH - 10) + AMxShift, cScreenHeight - 68, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
 
-        if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
-            DrawTexture(cScreenWidth div 2 + AMxShift - 35, cScreenHeight - 68, CountTexz[Ammo^[Slot, Pos].Count]);
+            if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
+                DrawTexture(cScreenWidth div 2 + AMxShift - 35, cScreenHeight - 68, CountTexz[Ammo^[Slot, Pos].Count]);
 
-        if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
+            if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
             begin
-            bShowAmmoMenu:= false;
-            SetWeapon(Ammo^[Slot, Pos].AmmoType);
-            bSelected:= false;
-            FreeWeaponTooltip;
-            exit
+                bShowAmmoMenu:= false;
+                SetWeapon(Ammo^[Slot, Pos].AmmoType);
+                bSelected:= false;
+                FreeWeaponTooltip;
+                exit();
             end;
     end
-else
-    FreeWeaponTooltip;
+    else
+        FreeWeaponTooltip;
 
-if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
-    ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y, cScreenHeight - WeaponTooltipTex^.h - 40));
+    if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
+        ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y, cScreenHeight - WeaponTooltipTex^.h - 40));
 
-bSelected:= false;
-if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
+    bSelected:= false;
+    if AMxShift = 0 then 
+        DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
 end;
 
 procedure MoveCamera; forward;
@@ -325,57 +344,58 @@
     r: TSDL_Rect;
     lw, lh: GLfloat;
 begin
-WaterColorArray[0].a := Alpha;
-WaterColorArray[1].a := Alpha;
-WaterColorArray[2].a := Alpha;
-WaterColorArray[3].a := Alpha;
+    WaterColorArray[0].a := Alpha;
+    WaterColorArray[1].a := Alpha;
+    WaterColorArray[2].a := Alpha;
+    WaterColorArray[3].a := Alpha;
 
-lw:= cScreenWidth / cScaleFactor;
-lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
-// Water
-r.y:= OffsetY + WorldDy + cWaterLine;
-if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
+    lw:= wScreen / cScaleFactor;
+    lh:= trunc(hScreen / cScaleFactor) + hScreen div 2 + 16;
+    
+    // Water
+    r.y:= OffsetY + WorldDy + cWaterLine;
+    if WorldDy < trunc(hScreen / cScaleFactor) + hScreen div 2 - cWaterLine then
     begin
-    if r.y < 0 then r.y:= 0;
+        if r.y < 0 then
+            r.y:= 0;
 
-    glDisable(GL_TEXTURE_2D);
-    VertexBuffer[0].X:= -lw;
-    VertexBuffer[0].Y:= r.y;
-    VertexBuffer[1].X:= lw;
-    VertexBuffer[1].Y:= r.y;
-    VertexBuffer[2].X:= lw;
-    VertexBuffer[2].Y:= lh;
-    VertexBuffer[3].X:= -lw;
-    VertexBuffer[3].Y:= lh;
+        glDisable(GL_TEXTURE_2D);
+        VertexBuffer[0].X:= -lw;
+        VertexBuffer[0].Y:= r.y;
+        VertexBuffer[1].X:= lw;
+        VertexBuffer[1].Y:= r.y;
+        VertexBuffer[2].X:= lw;
+        VertexBuffer[2].Y:= lh;
+        VertexBuffer[3].X:= -lw;
+        VertexBuffer[3].Y:= lh;
 
-    glEnableClientState (GL_COLOR_ARRAY);
-    glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
+        glEnableClientState (GL_COLOR_ARRAY);
+        glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
 
-    glEnableClientState(GL_VERTEX_ARRAY);
-    glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
+        glEnableClientState(GL_VERTEX_ARRAY);
+        glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 
-    glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
+        glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
-    glDisableClientState(GL_VERTEX_ARRAY);
-    glDisableClientState(GL_COLOR_ARRAY);
+        glDisableClientState(GL_VERTEX_ARRAY);
+        glDisableClientState(GL_COLOR_ARRAY);
 
-    glColor4ub($FF, $FF, $FF, $FF); // disable coloring
-    glEnable(GL_TEXTURE_2D)
-    end
+        Tint($FF, $FF, $FF, $FF); // disable coloring
+        glEnable(GL_TEXTURE_2D);
+    end;
 end;
 
 procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
 var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
     lw, waves, shift: GLfloat;
 begin
-lw:= cScreenWidth / cScaleFactor;
+lw:= wScreen / cScaleFactor;
 waves:= lw * 2 / cWaveWidth;
 
-Tint(
-      (tnt * WaterColorArray[2].r div 255) + (255-tnt)
-    , (tnt * WaterColorArray[2].g div 255) + (255-tnt)
-    , (tnt * WaterColorArray[2].b div 255) + (255-tnt)
-    , 255
+Tint((tnt * WaterColorArray[2].r div 255) + (255-tnt),
+     (tnt * WaterColorArray[2].g div 255) + (255-tnt),
+     (tnt * WaterColorArray[2].b div 255) + (255-tnt),
+      255
 );
 
 glBindTexture(GL_TEXTURE_2D, SpritesData[sprWater].Texture^.id);
@@ -420,37 +440,36 @@
 procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift, OffsetY: LongInt);
 var i, w, sw: LongInt;
 begin
-sw:= round(cScreenWidth / cScaleFactor);
-if (SpritesData[sprL].Texture = nil) or (SpritesData[sprR].Texture = nil) then
+    sw:= round(cScreenWidth / cScaleFactor);
+    if (SpritesData[sprL].Texture = nil) or (SpritesData[sprR].Texture = nil) then
     begin
-    w:= SpritesData[spr].Width;
-    i:= Shift mod w;
-    if i > 0 then dec(i, w);
-    dec(i, w * (sw div w + 1));
-    repeat
-        DrawSprite(spr, i, WorldDy + LAND_HEIGHT + OffsetY - SpritesData[spr].Height, 0);
-        inc(i, w)
-    until i > sw
-    end else
+        w:= SpritesData[spr].Width;
+        i:= Shift mod w;
+        if i > 0 then dec(i, w);
+        dec(i, w * (sw div w + 1));
+        repeat
+            DrawSprite(spr, i, WorldDy + LAND_HEIGHT + OffsetY - SpritesData[spr].Height, 0);
+            inc(i, w)
+        until i > sw
+    end
+    else
     begin
-    w:= SpritesData[spr].Width;
-    dec(Shift, w div 2);
-    DrawSprite(spr, Shift, WorldDy + LAND_HEIGHT + OffsetY - SpritesData[spr].Height, 0);
-
-    sw:= round(cScreenWidth / cScaleFactor);
+        w:= SpritesData[spr].Width;
+        dec(Shift, w div 2);
+        DrawSprite(spr, Shift, WorldDy + LAND_HEIGHT + OffsetY - SpritesData[spr].Height, 0);
     
-    i:= Shift - SpritesData[sprL].Width;
-    while i >= -sw - SpritesData[sprL].Width do
+        i:= Shift - SpritesData[sprL].Width;
+        while i >= -sw - SpritesData[sprL].Width do
         begin
-        DrawSprite(sprL, i, WorldDy + LAND_HEIGHT + OffsetY - SpritesData[sprL].Height, 0);
-        dec(i, SpritesData[sprL].Width);
+            DrawSprite(sprL, i, WorldDy + LAND_HEIGHT + OffsetY - SpritesData[sprL].Height, 0);
+            dec(i, SpritesData[sprL].Width);
         end;
         
-    i:= Shift + w;
-    while i <= sw do
+        i:= Shift + w;
+        while i <= sw do
         begin
-        DrawSprite(sprR, i, WorldDy + LAND_HEIGHT + OffsetY - SpritesData[sprR].Height, 0);
-        inc(i, SpritesData[sprR].Width)
+            DrawSprite(sprR, i, WorldDy + LAND_HEIGHT + OffsetY - SpritesData[sprR].Height, 0);
+            inc(i, SpritesData[sprR].Width)
         end
     end
 end;
@@ -727,33 +746,34 @@
 
 // Wind bar
 {$IFDEF IPHONEOS}
-offsetX:= cScreenHeight - 13;
-offsetY:= (cScreenWidth shr 1) + 74;
+    offsetX:= cScreenHeight - 13;
+    offsetY:= (cScreenWidth shr 1) + 74;
 {$ELSE}
-offsetX:= 30;
-offsetY:= 180;
+    offsetX:= 30;
+    offsetY:= 180;
 {$ENDIF}
-DrawSprite(sprWindBar, (cScreenWidth shr 1) - offsetY, cScreenHeight - offsetX, 0);
-if WindBarWidth > 0 then
-   begin
-   {$WARNINGS OFF}
-   r.x:= 8 - (RealTicks shr 6) mod 8;
-   {$WARNINGS ON}
-   r.y:= 0;
-   r.w:= WindBarWidth;
-   r.h:= 13;
-   DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - offsetY + 77, cScreenHeight - offsetX + 2, 13, 0);
-   end else
- if WindBarWidth < 0 then
-   begin
-   {$WARNINGS OFF}
-   r.x:= (WindBarWidth + RealTicks shr 6) mod 8;
-   {$WARNINGS ON}
-   r.y:= 0;
-   r.w:= - WindBarWidth;
-   r.h:= 13;
-   DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
-   end;
+    DrawSprite(sprWindBar, (cScreenWidth shr 1) - offsetY, cScreenHeight - offsetX, 0);
+    if WindBarWidth > 0 then
+    begin
+        {$WARNINGS OFF}
+        r.x:= 8 - (RealTicks shr 6) mod 8;
+        {$WARNINGS ON}
+        r.y:= 0;
+        r.w:= WindBarWidth;
+        r.h:= 13;
+        DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - offsetY + 77, cScreenHeight - offsetX + 2, 13, 0);
+    end
+    else
+        if WindBarWidth < 0 then
+        begin
+            {$WARNINGS OFF}
+            r.x:= (WindBarWidth + RealTicks shr 6) mod 8;
+            {$WARNINGS ON}
+            r.y:= 0;
+            r.w:= - WindBarWidth;
+            r.h:= 13;
+            DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
+        end;
 
 // AmmoMenu
 if (AMxShift < 210) or bShowAmmoMenu then ShowAmmoMenu;
@@ -1051,6 +1071,10 @@
     WorldDx:= -512;
     WorldDy:= -256;
     
+    // really initalized in initWorld
+    uWorld.wScreen:= 0; 
+    uWorld.hScreen:= 0;
+    
     FPS:= 0;
     CountTicks:= 0;
     SoundTimerTicks:= 0;
diff -r d445798e5fe2 -r 8fdb08497bf1 project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sun May 02 18:25:13 2010 +0000
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sun May 02 18:42:19 2010 +0000
@@ -1209,6 +1209,7 @@
 				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
 				SDKROOT = iphoneos3.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
+				VALIDATE_PRODUCT = NO;
 			};
 			name = Distribution;
 		};
@@ -1409,6 +1410,7 @@
 				PREBINDING = NO;
 				SDKROOT = iphoneos3.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
+				VALIDATE_PRODUCT = NO;
 			};
 			name = Debug;
 		};
@@ -1448,6 +1450,7 @@
 				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
 				SDKROOT = iphoneos3.2;
 				TARGETED_DEVICE_FAMILY = "1,2";
+				VALIDATE_PRODUCT = NO;
 			};
 			name = Release;
 		};