hedgewars/uLandGraphics.pas
changeset 10253 ea57f2f2b98d
parent 10251 a3b42e81803c
child 10286 1940e937fc08
equal deleted inserted replaced
10252:814e137625f7 10253:ea57f2f2b98d
    47 function  DrawThickLine(X1, Y1, X2, Y2, radius: LongInt; color: Longword): Longword;
    47 function  DrawThickLine(X1, Y1, X2, Y2, radius: LongInt; color: Longword): Longword;
    48 procedure DumpLandToLog(x, y, r: LongInt);
    48 procedure DumpLandToLog(x, y, r: LongInt);
    49 procedure DrawIceBreak(x, y, iceRadius, iceHeight: Longint);
    49 procedure DrawIceBreak(x, y, iceRadius, iceHeight: Longint);
    50 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean): boolean; inline;
    50 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean): boolean; inline;
    51 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean; LandFlags: Word): boolean;
    51 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean; LandFlags: Word): boolean;
       
    52 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible, outOfMap: boolean; LandFlags: Word): boolean;
    52 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture;
    53 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture;
    53 
    54 
    54 implementation
    55 implementation
    55 uses SDLh, uLandTexture, uTextures, uVariables, uUtils, uDebug;
    56 uses SDLh, uLandTexture, uTextures, uVariables, uUtils, uDebug;
    56 
    57 
   605 UpdateLandTexture(tx, ddx, ty, ddy, false)
   606 UpdateLandTexture(tx, ddx, ty, ddy, false)
   606 end;
   607 end;
   607 
   608 
   608 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean): boolean; inline;
   609 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean): boolean; inline;
   609 begin
   610 begin
   610 TryPlaceOnLand:= TryPlaceOnLand(cpX, cpY, Obj, Frame, doPlace, indestructible, 0);
   611 TryPlaceOnLand:= TryPlaceOnLand(cpX, cpY, Obj, Frame, doPlace, indestructible, false, 0);
   611 end;
   612 end;
   612 
   613 
   613 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean; LandFlags: Word): boolean;
   614 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean; LandFlags: Word): boolean;
       
   615 begin
       
   616 TryPlaceOnLand:= TryPlaceOnLand(cpX, cpY, Obj, Frame, doPlace, indestructible, false, LandFlags);
       
   617 end;
       
   618 
       
   619 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible, outOfMap: boolean; LandFlags: Word): boolean;
   614 var X, Y, bpp, h, w, row, col, gx, gy, numFramesFirstCol: LongInt;
   620 var X, Y, bpp, h, w, row, col, gx, gy, numFramesFirstCol: LongInt;
   615     p: PByteArray;
   621     p: PByteArray;
   616     Image: PSDL_Surface;
   622     Image: PSDL_Surface;
   617 begin
   623 begin
   618 TryPlaceOnLand:= false;
   624 TryPlaceOnLand:= false;
   619 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height;
   625 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height;
       
   626 
       
   627 if outOfMap then doPlace:= false; // just using for a check
   620 
   628 
   621 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true);
   629 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true);
   622 Image:= SpritesData[Obj].Surface;
   630 Image:= SpritesData[Obj].Surface;
   623 w:= SpritesData[Obj].Width;
   631 w:= SpritesData[Obj].Width;
   624 h:= SpritesData[Obj].Height;
   632 h:= SpritesData[Obj].Height;
   635 case bpp of
   643 case bpp of
   636     4: for y:= 0 to Pred(h) do
   644     4: for y:= 0 to Pred(h) do
   637         begin
   645         begin
   638         for x:= 0 to Pred(w) do
   646         for x:= 0 to Pred(w) do
   639             if ((PLongword(@(p^[x * 4]))^) and AMask) <> 0 then
   647             if ((PLongword(@(p^[x * 4]))^) and AMask) <> 0 then
   640                 if ((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) or
   648                 if (outOfMap and 
   641                    ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0) then
   649                    ((cpY + y) < LAND_HEIGHT) and ((cpY + y) >= 0) and 
   642                     begin
   650                    ((cpX + x) < LAND_WIDTH) and ((cpX + x) >= 0) and 
   643                         if SDL_MustLock(Image) then
   651                    (Land[cpY + y, cpX + x] <> 0)) or
   644                             SDL_UnlockSurface(Image);
   652 
   645                         exit;
   653                    (not outOfMap and
   646                     end;
   654                        (((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) or
       
   655                        ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or 
       
   656                        (Land[cpY + y, cpX + x] <> 0))) then
       
   657                    begin
       
   658                    if SDL_MustLock(Image) then
       
   659                        SDL_UnlockSurface(Image);
       
   660                    exit
       
   661                    end;
   647         p:= PByteArray(@(p^[Image^.pitch]));
   662         p:= PByteArray(@(p^[Image^.pitch]));
   648         end;
   663         end;
   649     end;
   664     end;
   650 
   665 
   651 TryPlaceOnLand:= true;
   666 TryPlaceOnLand:= true;