Fix nemo's large land patch
authorunc0rr
Mon, 26 Jan 2009 15:53:43 +0000
changeset 1760 55a1edd97911
parent 1759 88b0cf9d6de5
child 1761 c7038eade58d
Fix nemo's large land patch
hedgewars/GSHandlers.inc
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uLand.pas
hedgewars/uLandGraphics.pas
hedgewars/uMisc.pas
hedgewars/uVisualGears.pas
hedgewars/uWorld.pas
--- a/hedgewars/GSHandlers.inc	Mon Jan 26 14:57:05 2009 +0000
+++ b/hedgewars/GSHandlers.inc	Mon Jan 26 15:53:43 2009 +0000
@@ -390,7 +390,7 @@
 	end;
 dec(i)
 until i = 0;
-if (Gear^.X < _0) or (Gear^.Y < _0) or (Gear^.X > _4096) or (Gear^.Y > _2048) then // LAND_WIDTH / LAND_HEIGHT 
+if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
 	Gear^.doStep:= @doStepShotIdle
 end;
 
@@ -420,7 +420,10 @@
    dec(Gear^.Health, Gear^.Damage);
    Gear^.Damage:= 0
    end;
-if (Gear^.Health <= 0) or (Gear^.X < _0) or (Gear^.Y < _0) or (Gear^.X > _4096) or (Gear^.Y > _2048) then // LAND_WIDTH / LAND_HEIGHT
+
+if (Gear^.Health <= 0)
+	or (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0)
+	or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
 	Gear^.doStep:= @doStepShotIdle
 end;
 
@@ -1834,7 +1837,7 @@
 if cWaterLine > 0 then
 	begin
 	dec(cWaterLine);
-	for i:= 0 to 2047 do
+	for i:= 0 to LAND_WIDTH - 1 do
 		Land[cWaterLine, i]:= 0;
 	SetAllToActive
 	end;
--- a/hedgewars/uConsts.pas	Mon Jan 26 14:57:05 2009 +0000
+++ b/hedgewars/uConsts.pas	Mon Jan 26 15:53:43 2009 +0000
@@ -138,11 +138,12 @@
 
 	MAXNAMELEN = 192;
 
-    LAND_HEIGHT = 2047;  // could these be variable instead of const?
-    LAND_HEIGHT_MASK = $FFFFF800; // derive from LAND_HEIGHT?
-    LAND_WIDTH = 4095;
-    LAND_WIDTH_MASK = $FFFFF000;
-	COLOR_LAND = $00FFFFFF;
+    LAND_WIDTH = 4096;
+    LAND_HEIGHT = 2048;
+    LAND_WIDTH_MASK  = $FFFFF000;
+    LAND_HEIGHT_MASK = $FFFFF800;
+	
+	COLOR_LAND           = $00FFFFFF;
 	COLOR_INDESTRUCTIBLE = $0000F00D;
 
 	cifRandomize = $00000001;
--- a/hedgewars/uGears.pas	Mon Jan 26 14:57:05 2009 +0000
+++ b/hedgewars/uGears.pas	Mon Jan 26 15:53:43 2009 +0000
@@ -1180,7 +1180,7 @@
 	for i:= 0 to Pred(cLandAdditions) do
 		begin
 		Gear:= AddGear(0, 0, gtMine, 0, _0, _0, 0);
-		FindPlace(Gear, false, 0, LAND_WIDTH+1)
+		FindPlace(Gear, false, 0, LAND_WIDTH)
 		end
 end;
 
@@ -1328,8 +1328,8 @@
 
 procedure AssignHHCoords;
 var i, t, p, j: LongInt;
-    ar: array[0..Pred(cMaxHHs)] of PHedgehog;
-    Count: Longword;
+	ar: array[0..Pred(cMaxHHs)] of PHedgehog;
+	Count: Longword;
 begin
 if (GameFlags and (gfForts or gfDivideTeams)) <> 0 then
 	begin
@@ -1344,14 +1344,14 @@
 						with Hedgehogs[i] do
 							if (Gear <> nil) and (Gear^.X.QWordValue = 0) then
 								begin
-								FindPlace(Gear, false, t, t + 1024);// could make Gear == nil
+								FindPlace(Gear, false, t, t + LAND_WIDTH div 2);// could make Gear == nil
 								if Gear <> nil then
 									begin
 									Gear^.Pos:= GetRandom(19);
 									Gear^.dX.isNegative:= p = 1;
 									end
 								end;
-		inc(t, 1024)
+		t:= LAND_WIDTH div 2
 		end
 	end else // mix hedgehogs
 	begin
@@ -1371,10 +1371,10 @@
 	while (Count > 0) do
 		begin
 		i:= GetRandom(Count);
-		FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH+1);
+		FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH);
 		if ar[i]^.Gear <> nil then
 			begin
-			ar[i]^.Gear^.dX.isNegative:= ar[i]^.Gear^.X > _4096; // LAND_WIDTH
+			ar[i]^.Gear^.dX.isNegative:= hwRound(ar[i]^.Gear^.X) > LAND_WIDTH div 2;
 			ar[i]^.Gear^.Pos:= GetRandom(19);
 			ar[i]:= ar[Count - 1]
 			end;
@@ -1482,7 +1482,8 @@
         FollowGear^.State:= Longword(i)
         end;
      end;
-FindPlace(FollowGear, true, 0, 4096)
+ 
+FindPlace(FollowGear, true, 0, LAND_WIDTH)
 end;
 
 procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt);
@@ -1493,7 +1494,7 @@
 	begin
 	Result:= 0;
 	if (y and LAND_HEIGHT_MASK) = 0 then
-		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH-4) do
+		for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
 			if Land[y, i] <> 0 then inc(Result);
 	CountNonZeroz:= Result
 	end;
@@ -1517,13 +1518,13 @@
 			begin
 			repeat
 				inc(y, 2);
-			until (y > LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0);
+			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) = 0);
 			
 			sy:= y;
 
 			repeat
 				inc(y);
-			until (y > LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0);
+			until (y >= LAND_HEIGHT) or (CountNonZeroz(x, y, Gear^.Radius - 1) <> 0);
 			
 			if (y - sy > Gear^.Radius * 2)
 				and (y < LAND_HEIGHT)
@@ -1546,6 +1547,7 @@
 				inc(cnt2)
 				end
 	until (x + Delta > Right);
+	
 	dec(Delta, 60)
 until (cnt2 > 0) or (Delta < 70);
 
--- a/hedgewars/uLand.pas	Mon Jan 26 14:57:05 2009 +0000
+++ b/hedgewars/uLand.pas	Mon Jan 26 15:53:43 2009 +0000
@@ -20,9 +20,9 @@
 interface
 uses SDLh, uLandTemplates, uFloat, GL, uConsts;
 {$include options.inc}
-type TLandArray = packed array[0..LAND_HEIGHT, 0..LAND_WIDTH] of LongWord;
-     TPreview = packed array[0..127, 0..31] of byte;
-     TDirtyTag = packed array[0..63, 0..127] of byte;
+type TLandArray = packed array[0 .. LAND_HEIGHT - 1, 0 .. LAND_WIDTH - 1] of LongWord;
+	TPreview  = packed array[0..127, 0..31] of byte;
+	TDirtyTag = packed array[0 .. LAND_HEIGHT div 32 - 1, 0 .. LAND_WIDTH div 32 - 1] of byte;
 
 var  Land: TLandArray;
      LandPixels: TLandArray;
@@ -245,7 +245,7 @@
     begin
     TryDo(Stack.Count <= 8192, 'FillLand: stack overflow', true);
     _y:= _y + _dir;
-    if (_y < 0) or (_y > LAND_HEIGHT) then exit;
+    if (_y < 0) or (_y >= LAND_HEIGHT) then exit;
     with Stack.points[Stack.Count] do
          begin
          xl:= _xl;
@@ -279,7 +279,7 @@
       begin
       Pop(xl, xr, y, dir);
       while (xl > 0) and (Land[y, xl] <> 0) do dec(xl);
-      while (xr < LAND_WIDTH) and (Land[y, xr] <> 0) do inc(xr);
+      while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> 0) do inc(xr);
       while (xl < xr) do
             begin
             while (xl <= xr) and (Land[y, xl] = 0) do inc(xl);
@@ -305,10 +305,10 @@
 begin
 tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/LandTex', false, true, false);
 r.y:= 0;
-while r.y < 2048 do
+while r.y < LAND_HEIGHT do
 	begin
 	r.x:= 0;
-	while r.x <= LAND_WIDTH do
+	while r.x < LAND_WIDTH do
 		begin
 		SDL_UpperBlit(tmpsurf, nil, Surface, @r);
 		inc(r.x, tmpsurf^.w)
@@ -318,22 +318,22 @@
 SDL_FreeSurface(tmpsurf);
 
 tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Border', false, true, true);
-for x:= 0 to 4095 do
+for x:= 0 to LAND_WIDTH - 1 do
 	begin
-	yd:= LAND_HEIGHT;
+	yd:= LAND_HEIGHT - 1;
 	repeat
-		while (yd > 0   ) and (Land[yd, x] =  0) do dec(yd);
+		while (yd > 0) and (Land[yd, x] =  0) do dec(yd);
 		
 		if (yd < 0) then yd:= 0;
 
-		while (yd <= LAND_HEIGHT) and (Land[yd, x] <> 0) do inc(yd);
+		while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do inc(yd);
 		dec(yd);
 		yu:= yd;
 		
 		while (yu > 0  ) and (Land[yu, x] <> 0) do dec(yu);
 		while (yu < yd ) and (Land[yu, x] =  0) do inc(yu);
 		
-		if (yd < LAND_HEIGHT) and ((yd - yu) >= 16) then
+		if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then
 			begin
 			rr.x:= x;
 			rr.y:= yd - 15;
@@ -375,18 +375,18 @@
            begin
            for i:= 0 to pred(BasePointsCount) do
              if pa.ar[i].x <> NTPX then
-               pa.ar[i].x:= LAND_WIDTH - pa.ar[i].x;
+               pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x;
            for i:= 0 to pred(FillPointsCount) do
-               FillPoints^[i].x:= LAND_WIDTH - FillPoints^[i].x;
+               FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x;
            end;
 
      if canFlip then
         if getrandom(2) = 0 then
            begin
            for i:= 0 to pred(BasePointsCount) do
-               pa.ar[i].y:= LAND_HEIGHT - pa.ar[i].y;
+               pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y;
            for i:= 0 to pred(FillPointsCount) do
-               FillPoints^[i].y:= LAND_HEIGHT - FillPoints^[i].y;
+               FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y;
            end;
      end
 end;
@@ -440,8 +440,8 @@
   with pa.ar[i] do
     if x <> NTPX then
       begin
-      radz[i]:= Min(Max(x - cEdge, 0), Max(LAND_WIDTH + 1 - cEdge - x, 0));
-      radz[i]:= Min(radz[i], Min(Max(y - cEdge, 0), Max(LAND_HEIGHT + 1 - cEdge - y, 0)));
+      radz[i]:= Min(Max(x - cEdge, 0), Max(LAND_WIDTH - cEdge - x, 0));
+      radz[i]:= Min(radz[i], Min(Max(y - cEdge, 0), Max(LAND_HEIGHT - cEdge - y, 0)));
       if radz[i] > 0 then
         for k:= 0 to Pred(i) do
           begin
@@ -473,8 +473,8 @@
     i: Longword;
     y, x: Longword;
 begin
-for y:= 0 to LAND_HEIGHT do
-    for x:= 0 to LAND_WIDTH do
+for y:= 0 to LAND_HEIGHT - 1 do
+    for x:= 0 to LAND_WIDTH - 1 do
         Land[y, x]:= COLOR_LAND;
 
 SetPoints(Template, pa);
@@ -512,10 +512,11 @@
 	SDLTry(SDL_LockSurface(Surface) >= 0, true);
 
 p:= Surface^.pixels;
-for y:= 0 to LAND_HEIGHT do
+for y:= 0 to LAND_HEIGHT - 1 do
 	begin
-	for x:= 0 to LAND_WIDTH do
+	for x:= 0 to LAND_WIDTH - 1 do
 		if Land[y, x] <> 0 then LandPixels[y, x]:= p^[x] or $FF000000;
+		
 	p:= @(p^[Surface^.pitch div 4]);
 	end;
 
@@ -532,7 +533,7 @@
 
 AddProgress;
 
-tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH+1, LAND_HEIGHT+1, 32, RMask, GMask, BMask, 0);
+tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, 0);
 
 TryDo(tmpsurf <> nil, 'Error creating pre-land surface', true);
 ColorizeLand(tmpsurf);
@@ -554,13 +555,12 @@
 WriteLnToConsole('Generating forts land...');
 
 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', true, true, true);
-BlitImageAndGenerateCollisionInfo(0, 0, LAND_WIDTH+1, tmpsurf);
+BlitImageAndGenerateCollisionInfo(0, 0, LAND_HEIGHT, tmpsurf);
 SDL_FreeSurface(tmpsurf);
 
 tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', true, true, true);
-BlitImageAndGenerateCollisionInfo(2048, 0, LAND_WIDTH+1, tmpsurf);
+BlitImageAndGenerateCollisionInfo(LAND_WIDTH - 1024, 0, LAND_HEIGHT, tmpsurf);
 SDL_FreeSurface(tmpsurf);
-
 end;
 
 procedure LoadMap;
@@ -569,18 +569,16 @@
 WriteLnToConsole('Loading land from file...');
 AddProgress;
 tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', true, true, true);
-TryDo((tmpsurf^.w = LAND_WIDTH+1) and (tmpsurf^.h = LAND_HEIGHT+1), 'Map dimensions should be 4096x2048!', true);
+TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true);
 
 TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Map should be 32bit', true);
 
-BlitImageAndGenerateCollisionInfo(0, 0, LAND_WIDTH+1, tmpsurf);
+BlitImageAndGenerateCollisionInfo(0, 0, LAND_WIDTH, tmpsurf);
 SDL_FreeSurface(tmpsurf);
 
 end;
 
 procedure GenMap;
-var x, y: LongInt;
-    c: LongWord;
 begin
 LoadThemeConfig;
 
@@ -589,43 +587,9 @@
                                 else GenLandSurface
                                else MakeFortsMap;
 AddProgress;
+
 {$IFDEF DEBUGFILE}LogLandDigest;{$ENDIF}
 
-for y:= 0 to 63 do
-	for x:= 0 to 127 do
-	    LandDirty[y, x]:= 0;  // TODO - ask unC0Rr why he took this out of merge - doesn't it need initialising? seems random values could result in some unintended smoothing of initial map edges. also be slower.
-
-// experiment hardcoding cave
-for y:= 0 to LAND_HEIGHT do
-    begin
-    Land[y, 0]:= COLOR_INDESTRUCTIBLE;
-    Land[y, 1]:= COLOR_INDESTRUCTIBLE;
-    Land[y, 2]:= COLOR_INDESTRUCTIBLE;
-    Land[y, LAND_WIDTH-2]:= COLOR_INDESTRUCTIBLE;
-    Land[y, LAND_WIDTH-1]:= COLOR_INDESTRUCTIBLE;
-    Land[y, LAND_WIDTH]:= COLOR_INDESTRUCTIBLE;
-    if y mod 32 < 16 then c:= $FF000000
-    else c:= $FF00FFFF;   
-    LandPixels[y, 0]:= c;           
-    LandPixels[y, 1]:= c;           
-    LandPixels[y, 2]:= c;           
-    LandPixels[y, LAND_WIDTH-2]:= c;           
-    LandPixels[y, LAND_WIDTH-1]:= c;           
-    LandPixels[y, LAND_WIDTH]:= c;           
-    end;
-
-for x:= 0 to LAND_WIDTH do
-    begin
-    Land[0, x]:= COLOR_INDESTRUCTIBLE;
-    Land[1, x]:= COLOR_INDESTRUCTIBLE;
-    Land[2, x]:= COLOR_INDESTRUCTIBLE;
-    if x mod 32 < 16 then c:= $FF000000
-    else c:= $FF00FFFF;   
-    LandPixels[0, x]:= c;           
-    LandPixels[1, x]:= c;           
-    LandPixels[2, x]:= c;           
-    end;
-
 UpdateLandTexture(0, LAND_HEIGHT);
 end;
 
@@ -643,8 +607,8 @@
         for bit:= 0 to 7 do
             begin
             t:= 0;
-            for yy:= y * 16 to y * 16 + 7 do
-                for xx:= x * 128 + bit * 8 to x * 128 + bit * 8 + 7 do
+            for yy:= y * (LAND_HEIGHT div 128) to y * (LAND_HEIGHT div 128) + 7 do
+                for xx:= x * (LAND_WIDTH div 32) + bit * 8 to x * (LAND_WIDTH div 32) + bit * 8 + 7 do
                     if Land[yy, xx] <> 0 then inc(t);
             if t > 8 then Preview[y, x]:= Preview[y, x] or ($80 shr bit)
             end
@@ -655,15 +619,16 @@
 procedure UpdateLandTexture(Y, Height: LongInt);
 begin
 if (Height <= 0) then exit;
-TryDo((Y >= 0) and (Y <= LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true);
-TryDo(Y + Height <= LAND_WIDTH, 'UpdateLandTexture: wrong Height parameter', true);
+
+TryDo((Y >= 0) and (Y < LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true);
+TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true);
 
 if LandTexture = nil then
-	LandTexture:= NewTexture(LAND_WIDTH+1, LAND_HEIGHT+1, @LandPixels)
+	LandTexture:= NewTexture(LAND_WIDTH, LAND_HEIGHT, @LandPixels)
 else
 	begin
 	glBindTexture(GL_TEXTURE_2D, LandTexture^.id);
-	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, Y, LAND_WIDTH+1, Height, GL_RGBA, GL_UNSIGNED_BYTE, @LandPixels[Y, 0]);
+	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, Y, LAND_WIDTH, Height, GL_RGBA, GL_UNSIGNED_BYTE, @LandPixels[Y, 0]);
 	end
 end;
 
--- a/hedgewars/uLandGraphics.pas	Mon Jan 26 14:57:05 2009 +0000
+++ b/hedgewars/uLandGraphics.pas	Mon Jan 26 15:53:43 2009 +0000
@@ -43,19 +43,19 @@
 var i: LongInt;
 begin
 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dx, 0) to min(x + dx, 4095) do 
+    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do 
         if Land[y + dy, i] <> COLOR_INDESTRUCTIBLE 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, 4095) do 
+   for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do 
         if Land[y - dy, i] <> COLOR_INDESTRUCTIBLE 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, 4095) do 
+    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do 
         if Land[y + dx, i] <> COLOR_INDESTRUCTIBLE 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, 4095) do 
+    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do 
         if Land[y - dx, i] <> COLOR_INDESTRUCTIBLE then
             Land[y - dx, i]:= Value;
 end;
@@ -66,27 +66,27 @@
 if not doSet then
    begin
    if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dx, 0) to min(x + dx, 4095) do
+      for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
           if (Land[y + dy, i] > 0) 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, 4095) do
+      for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
           if (Land[y - dy, i] > 0) 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, 4095) do
+      for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
           if (Land[y + dx, i] > 0) 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, 4095) do
+      for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
           if (Land[y - dx, i] > 0) 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, 4095) do inc(Land[y + dy, i]);
+      for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do inc(Land[y + dy, i]);
    if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dx, 0) to min(x + dx, 4095) do inc(Land[y - dy, i]);
+      for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do inc(Land[y - dy, i]);
    if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dy, 0) to min(x + dy, 4095) do inc(Land[y + dx, i]);
+      for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do inc(Land[y + dx, i]);
    if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= max(x - dy, 0) to min(x + dy, 4095) do inc(Land[y - dx, i]);
+      for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do inc(Land[y - dx, i]);
    end
 end;
 
@@ -134,19 +134,19 @@
 var i: LongInt;
 begin
 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dx, 0) to min(x + dx, 4095) do 
+    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do 
         if Land[y + dy, i] <> COLOR_INDESTRUCTIBLE then
             LandPixels[y + dy, i]:= 0;
 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dx, 0) to min(x + dx, 4095) do 
+    for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do 
         if Land[y - dy, i] <> COLOR_INDESTRUCTIBLE then
              LandPixels[y - dy, i]:= 0;
 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dy, 0) to min(x + dy, 4095) do 
+    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do 
         if Land[y + dx, i] <> COLOR_INDESTRUCTIBLE then
             LandPixels[y + dx, i]:= 0;
 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - dy, 0) to min(x + dy, 4095) do 
+    for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do 
         if Land[y - dx, i] <> COLOR_INDESTRUCTIBLE then
              LandPixels[y - dx, i]:= 0;
 end;
@@ -155,7 +155,7 @@
 var i: LongInt;
 begin
 if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dx, 0) to min(x + dx, 4095) do
+   for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
        if Land[y + dy, i] = COLOR_LAND then 
           begin
           LandPixels[y + dy, i]:= cExplosionBorderColor;
@@ -163,7 +163,7 @@
           LandDirty[(y + dy) div 32, i div 32]:= 1;
           end;
 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dx, 0) to min(x + dx, 4095) do
+   for i:= max(x - dx, 0) to min(x + dx, LAND_WIDTH - 1) do
        if Land[y - dy, i] = COLOR_LAND then
           begin
           LandPixels[y - dy, i]:= cExplosionBorderColor;
@@ -171,7 +171,7 @@
           LandDirty[(y - dy) div 32, i div 32]:= 1;
           end;
 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dy, 0) to min(x + dy, 4095) do
+   for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
        if Land[y + dx, i] = COLOR_LAND then
            begin
            LandPixels[y + dx, i]:= cExplosionBorderColor;
@@ -179,7 +179,7 @@
            LandDirty[(y + dx) div 32, i div 32]:= 1;
            end;
 if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-   for i:= max(x - dy, 0) to min(x + dy, 4095) do
+   for i:= max(x - dy, 0) to min(x + dy, LAND_WIDTH - 1) do
        if Land[y - dx, i] = COLOR_LAND then
           begin
           LandPixels[y - dx, i]:= cExplosionBorderColor;
@@ -226,7 +226,7 @@
   if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy);
 
 d:= max(Y - Radius - 1, 0);
-dy:= min(Y + Radius + 1, 2047) - d;
+dy:= min(Y + Radius + 1, LAND_HEIGHT) - d;
 UpdateLandTexture(d, dy)
 end;
 
@@ -445,10 +445,7 @@
 		end;
 	
 	if updatedRow then
-		if y = 63 then
-			UpdateLandTexture(LAND_HEIGHT-31, 31)
-		else
-			UpdateLandTexture(y*32, 32);
+		UpdateLandTexture(y * 32, 32);
 	end;
 end;
 
--- a/hedgewars/uMisc.pas	Mon Jan 26 14:57:05 2009 +0000
+++ b/hedgewars/uMisc.pas	Mon Jan 26 15:53:43 2009 +0000
@@ -49,7 +49,7 @@
 	cBitsStr         : string[2] = '16';
 	cTagsMask        : byte = 7;
 
-	cWaterLine       : LongInt = LAND_HEIGHT+1;
+	cWaterLine       : LongInt = LAND_HEIGHT;
 	cVisibleWater    : LongInt = 128;
 	cGearScrEdgesDist: LongInt = 240;
 	cCursorEdgesDist : LongInt = 100;
--- a/hedgewars/uVisualGears.pas	Mon Jan 26 14:57:05 2009 +0000
+++ b/hedgewars/uVisualGears.pas	Mon Jan 26 15:53:43 2009 +0000
@@ -89,9 +89,9 @@
 Gear^.Y:= Gear^.Y + (Gear^.dY + cGravity * vobFallSpeed) * Steps;
 Gear^.Angle:= Gear^.Angle + Gear^.dAngle * Steps;
 
-if hwRound(Gear^.X) < -cScreenWidth - 64 then Gear^.X:= int2hwFloat(cScreenWidth + LAND_WIDTH + 1) else
-if hwRound(Gear^.X) > cScreenWidth + LAND_WIDTH + 1 then Gear^.X:= int2hwFloat(-cScreenWidth - 64);
-if hwRound(Gear^.Y) > (LAND_HEIGHT+75) then Gear^.Y:= Gear^.Y - int2hwFloat(LAND_HEIGHT+200)
+if hwRound(Gear^.X) < -cScreenWidth - 64 then Gear^.X:= int2hwFloat(cScreenWidth + LAND_WIDTH) else
+if hwRound(Gear^.X) > cScreenWidth + LAND_WIDTH then Gear^.X:= int2hwFloat(-cScreenWidth - 64);
+if hwRound(Gear^.Y) > (LAND_HEIGHT + 75) then Gear^.Y:= Gear^.Y - int2hwFloat(LAND_HEIGHT + 200)
 end;
 
 procedure doStepCloud(Gear: PVisualGear; Steps: Longword);
--- a/hedgewars/uWorld.pas	Mon Jan 26 14:57:05 2009 +0000
+++ b/hedgewars/uWorld.pas	Mon Jan 26 15:53:43 2009 +0000
@@ -64,8 +64,8 @@
 SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
 prevPoint.X:= cScreenWidth div 2;
 prevPoint.Y:= cScreenHeight div 2;
-WorldDx:=  - (LAND_WIDTH shr 1) + cScreenWidth div 2;
-WorldDy:=  - (LAND_HEIGHT shr 1) + cScreenHeight div 2;
+WorldDx:=  - (LAND_WIDTH div 2) + cScreenWidth div 2;
+WorldDy:=  - (LAND_HEIGHT div 2) + cScreenHeight div 2;
 AMxShift:= 210
 end;
 
@@ -177,7 +177,7 @@
     i:= Shift mod w;
     if i > 0 then dec(i, w);
     repeat
-      DrawSprite(spr, i, WorldDy + LAND_HEIGHT + 1 - SpritesData[spr].Height, 0);
+      DrawSprite(spr, i, WorldDy + LAND_HEIGHT - SpritesData[spr].Height, 0);
       inc(i, w)
     until i > cScreenWidth
     end;
@@ -491,9 +491,9 @@
 if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y);
 prevPoint:= CursorPoint;
 if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater;
-if WorldDy >  LAND_HEIGHT then WorldDy:=  LAND_HEIGHT;
+if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
 if WorldDx < -LAND_WIDTH then WorldDx:= -LAND_WIDTH;
-if WorldDx > cScreenWidth then WorldDx:=  cScreenWidth;
+if WorldDx > cScreenWidth then WorldDx:= cScreenWidth;
 end;
 
 initialization