hedgewars/uLandObjects.pas
changeset 10941 6f1b2d0dacdf
parent 10878 963bc20f511c
child 11006 cb06b7985261
equal deleted inserted replaced
10940:096be1230a46 10941:6f1b2d0dacdf
   217     until (i = RectCount) or (res);
   217     until (i = RectCount) or (res);
   218 CheckIntersect:= res;
   218 CheckIntersect:= res;
   219 end;
   219 end;
   220 
   220 
   221 
   221 
   222 function CountNonZeroz(x, y: LongInt): Longword;
   222 function CountNonZeroz(x, y, h: LongInt): Longword;
   223 var i: LongInt;
   223 var i: LongInt;
   224     lRes: Longword;
   224     lRes: Longword;
   225 begin
   225 begin
   226     lRes:= 0;
   226     lRes:= 0;
   227     for i:= y to y + 15 do
   227     for i:= y to Pred(y + h) do
   228         if Land[i, x] <> 0 then
   228         if Land[i, x] <> 0 then
   229             inc(lRes);
   229             inc(lRes);
   230     CountNonZeroz:= lRes;
   230     CountNonZeroz:= lRes;
   231 end;
   231 end;
   232 
   232 
   233 function AddGirder(gX: LongInt; var girSurf: PSDL_Surface): boolean;
   233 function AddGirder(gX: LongInt; var girSurf: PSDL_Surface): boolean;
   234 var x1, x2, y, k, i: LongInt;
   234 var x1, x2, y, k, i, girderHeight: LongInt;
   235     rr: TSDL_Rect;
   235     rr: TSDL_Rect;
   236     bRes: boolean;
   236     bRes: boolean;
   237 begin
   237 begin
       
   238 if girSurf = nil then
       
   239     girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifTransparent or ifIgnoreCaps);
       
   240 
       
   241 girderHeight:= girSurf^.h;
       
   242 
   238 y:= topY+150;
   243 y:= topY+150;
   239 repeat
   244 repeat
   240     inc(y, 24);
   245     inc(y, 24);
   241     x1:= gX;
   246     x1:= gX;
   242     x2:= gX;
   247     x2:= gX;
   243 
   248 
   244     while (x1 > Longint(leftX)+150) and (CountNonZeroz(x1, y) = 0) do
   249     while (x1 > Longint(leftX)+150) and (CountNonZeroz(x1, y, girderHeight) = 0) do
   245         dec(x1, 2);
   250         dec(x1, 2);
   246 
   251 
   247     i:= x1 - 12;
   252     i:= x1 - 12;
   248     repeat
   253     repeat
   249         dec(x1, 2);
   254         k:= CountNonZeroz(x1, y, girderHeight);
   250         k:= CountNonZeroz(x1, y)
   255         dec(x1, 2)
   251     until (x1 < Longint(leftX)+150) or (k = 0) or (k = 16) or (x1 < i);
   256     until (x1 < Longint(leftX) + 100) or (k = 0) or (k = girderHeight) or (x1 < i);
   252 
   257 
   253     inc(x1, 2);
   258     inc(x1, 2);
   254     if k = 16 then
   259     if k = girderHeight then
   255         begin
   260         begin
   256         while (x2 < (LongInt(rightX)-150)) and (CountNonZeroz(x2, y) = 0) do
   261         while (x2 < (LongInt(rightX) - 100)) and (CountNonZeroz(x2, y, girderHeight) = 0) do
   257             inc(x2, 2);
   262             inc(x2, 2);
   258         i:= x2 + 12;
   263         i:= x2 + 12;
   259         repeat
   264         repeat
   260         inc(x2, 2);
   265         inc(x2, 2);
   261         k:= CountNonZeroz(x2, y)
   266         k:= CountNonZeroz(x2, y, girderHeight)
   262         until (x2 >= (LongInt(rightX)-150)) or (k = 0) or (k = 16) or (x2 > i) or (x2 - x1 >= 768);
   267         until (x2 >= (LongInt(rightX)-150)) or (k = 0) or (k = girderHeight) or (x2 > i) or (x2 - x1 >= 900);
   263 
   268 
   264         if (x2 < (LongInt(rightX) - 150)) and (k = 16) and (x2 - x1 > 250) and (x2 - x1 < 768)
   269         if (x2 < (LongInt(rightX) - 100)) and (k = girderHeight) and (x2 - x1 > 200) and (x2 - x1 < 900)
   265         and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then
   270         and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then
   266                 break;
   271                 break;
   267         end;
   272         end;
   268 x1:= 0;
   273 x1:= 0;
   269 until y > (LAND_HEIGHT-125);
   274 until y > (LAND_HEIGHT-125);
   270 
   275 
   271 if x1 > 0 then
   276 if x1 > 0 then
   272 begin
   277 begin
   273     bRes:= true;
   278     bRes:= true;
   274     if girSurf = nil then
       
   275         girSurf:= LoadDataImageAltPath(ptCurrTheme, ptGraphics, 'Girder', ifCritical or ifTransparent or ifIgnoreCaps);
       
   276 
   279 
   277     rr.x:= x1;
   280     rr.x:= x1;
   278     while rr.x < x2 do
   281     while rr.x < x2 do
   279         begin
   282         begin
   280         if cIce then
   283         if cIce then