hedgewars/uLand.pas
branchqmlfrontend
changeset 11071 3851ce4f2061
parent 11046 47a8c19ecb60
child 11342 ed5a6478e710
--- a/hedgewars/uLand.pas	Sat Aug 15 16:23:00 2015 +0300
+++ b/hedgewars/uLand.pas	Thu Sep 03 20:59:48 2015 +0300
@@ -1,6 +1,6 @@
 (*
  * Hedgewars, a free turn based strategy game
- * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
+ * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -36,6 +36,7 @@
      uLandGenTemplateBased, uLandUtils;
 
 var digest: shortstring;
+    maskOnly: boolean;
 
 
 procedure PrettifyLandAlpha();
@@ -50,24 +51,32 @@
 var tmpsurf: PSDL_Surface;
     r, rr: TSDL_Rect;
     x, yd, yu: LongInt;
+    targetMask: Word;
 begin
     tmpsurf:= LoadDataImage(ptCurrTheme, 'Border', ifCritical or ifIgnoreCaps or ifTransparent);
+
+    // if mask only, all land gets filled with landtex and therefore needs borders
+    if maskOnly then
+        targetMask:= lfLandMask
+    else
+        targetMask:= lfBasic;
+
     for x:= 0 to LAND_WIDTH - 1 do
     begin
         yd:= LAND_HEIGHT - 1;
         repeat
-            while (yd > 0) and (Land[yd, x] <> lfBasic) do dec(yd);
+            while (yd > 0) and ((Land[yd, x] and targetMask) = 0) do dec(yd);
 
             if (yd < 0) then
                 yd:= 0;
 
-            while (yd < LAND_HEIGHT) and (Land[yd, x] = lfBasic) do
+            while (yd < LAND_HEIGHT) and ((Land[yd, x] and targetMask) <> 0) do
                 inc(yd);
             dec(yd);
             yu:= yd;
 
-            while (yu > 0  ) and (Land[yu, x] = lfBasic) do dec(yu);
-            while (yu < yd ) and (Land[yu, x] <>  lfBasic) do inc(yu);
+            while (yu > 0  ) and ((Land[yu, x] and targetMask) <> 0) do dec(yu);
+            while (yu < yd ) and ((Land[yu, x] and targetMask) =  0) do inc(yu);
 
             if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then
                 begin
@@ -372,8 +381,16 @@
 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
 SDL_FreeSurface(tmpsurf);
 
-tmpsurf:= LoadDataImage(ptForts, ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
-BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
+// not critical because if no R we can fallback to mirrored L
+tmpsurf:= LoadDataImage(ptForts, ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
+// fallback
+if tmpsurf = nil then
+    begin
+    tmpsurf:= LoadDataImage(ptForts, ClansArray[1]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
+    BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf, 0, true);
+    end
+else
+    BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
 SDL_FreeSurface(tmpsurf);
 end;
 
@@ -517,7 +534,6 @@
 procedure GenMap;
 var x, y, w, c: Longword;
     map, mask: shortstring;
-    maskOnly: boolean;
 begin
     hasBorder:= false;
     maskOnly:= false;
@@ -802,6 +818,7 @@
 
     LandBackSurface:= nil;
     digest:= '';
+    maskOnly:= false;
     LAND_WIDTH:= 0;
     LAND_HEIGHT:= 0;
 (*