hedgewars/uStore.pas
changeset 53 0e27949850e3
parent 49 3afe33c1cf06
child 54 839fd258ae6f
equal deleted inserted replaced
52:ae2950c5465c 53:0e27949850e3
    63 
    63 
    64 var PixelFormat: PSDL_PixelFormat;
    64 var PixelFormat: PSDL_PixelFormat;
    65  SDLPrimSurface: PSDL_Surface;
    65  SDLPrimSurface: PSDL_Surface;
    66 
    66 
    67 implementation
    67 implementation
    68 uses uMisc, uIO, uConsole, uLand;
    68 uses uMisc, uIO, uConsole, uLand, uCollisions;
    69 
    69 
    70 var StoreSurface,
    70 var StoreSurface,
    71      TempSurface,
    71      TempSurface,
    72        HHSurface: PSDL_Surface;
    72        HHSurface: PSDL_Surface;
    73 
    73 
    74 procedure DrawExplosion(X, Y, Radius: integer);
    74 procedure DrawExplosion(X, Y, Radius: integer);
    75 var ty, tx, p: integer;
    75 var ty, tx, p: integer;
    76 begin
    76 begin
    77 for ty:= max(-Radius, -y) to min(radius, 1023 - y) do
    77 FillRoundInLand(X, Y, Radius, 0);
    78     for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
       
    79         Land[ty + y, tx]:= 0;
       
    80 
    78 
    81 if SDL_MustLock(LandSurface) then
    79 if SDL_MustLock(LandSurface) then
    82    SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
    80    SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
    83 
    81 
    84 p:= integer(LandSurface.pixels);
    82 p:= integer(LandSurface.pixels);
   103 
   101 
   104 case LandSurface.format.BytesPerPixel of
   102 case LandSurface.format.BytesPerPixel of
   105      1: ;// not supported
   103      1: ;// not supported
   106      2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   104      2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   107             for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
   105             for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
   108                if Land[y + ty, tx] <> 0 then
   106                if Land[y + ty, tx] = $FFFFFF then
   109                   PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
   107                   PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
   110      3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   108      3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   111             for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
   109             for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
   112                if Land[y + ty, tx] <> 0 then
   110                if Land[y + ty, tx] = $FFFFFF then
   113                 begin
   111                 begin
   114                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
   112                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
   115                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
   113                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
   116                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
   114                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
   117                 end;
   115                 end;
   118      4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   116      4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   119             for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
   117             for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
   120                if Land[y + ty, tx] <> 0 then
   118                if Land[y + ty, tx] = $FFFFFF then
   121                    PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
   119                    PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
   122      end;
   120      end;
   123 
   121 
   124 if SDL_MustLock(LandSurface) then
   122 if SDL_MustLock(LandSurface) then
   125    SDL_UnlockSurface(LandSurface);
   123    SDL_UnlockSurface(LandSurface);
   162     begin
   160     begin
   163     case LandSurface.format.BytesPerPixel of
   161     case LandSurface.format.BytesPerPixel of
   164      1: ;
   162      1: ;
   165      2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   163      2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   166             for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
   164             for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
   167                if Land[y + ty, tx] <> 0 then
   165                if Land[y + ty, tx] = $FFFFFF then
   168                   PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
   166                   PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
   169      3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   167      3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   170             for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
   168             for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
   171                if Land[y + ty, tx] <> 0 then
   169                if Land[y + ty, tx] = $FFFFFF then
   172                 begin
   170                 begin
   173                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
   171                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
   174                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
   172                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
   175                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
   173                 PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
   176                 end;
   174                 end;
   177      4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   175      4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
   178             for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
   176             for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
   179                if Land[y + ty, tx] <> 0 then
   177                if Land[y + ty, tx] = $FFFFFF then
   180                    PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
   178                    PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
   181      end;
   179      end;
   182     inc(y, dY)
   180     inc(y, dY)
   183     end;
   181     end;
   184 
   182 
   384     begin
   382     begin
   385     r.x:= 0;
   383     r.x:= 0;
   386     r.y:= 256;
   384     r.y:= 256;
   387     r.w:= 16;
   385     r.w:= 16;
   388     r.h:= 16;
   386     r.h:= 16;
   389     s:= Pathz[ptGraphics] + cCHFileName;
   387     s:= Pathz[ptGraphics] + '/' + cCHFileName;
   390     WriteToConsole(msgLoading + s + ' ');
   388     WriteToConsole(msgLoading + s + ' ');
   391     tmpsurf:= IMG_Load(PChar(s));
   389     tmpsurf:= IMG_Load(PChar(s));
   392     TryDo(tmpsurf <> nil, msgFailed, true);
   390     TryDo(tmpsurf <> nil, msgFailed, true);
   393     WriteLnToConsole(msgOK);
   391     WriteLnToConsole(msgOK);
   394     TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF);
   392     TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF);
   434     l:= 512;
   432     l:= 512;
   435     while p <> nil do
   433     while p <> nil do
   436           begin
   434           begin
   437           dec(l, 32);
   435           dec(l, 32);
   438           if p.GraveName = '' then p.GraveName:= 'Simple';
   436           if p.GraveName = '' then p.GraveName:= 'Simple';
   439           LoadToSurface(Pathz[ptGraves] + p.GraveName + '.png', StoreSurface, l, 512);
   437           LoadToSurface(Pathz[ptGraves] + '/' + p.GraveName + '.png', StoreSurface, l, 512);
   440           p.GraveRect.x:= l;
   438           p.GraveRect.x:= l;
   441           p.GraveRect.y:= 512;
   439           p.GraveRect.y:= 512;
   442           p.GraveRect.w:= 32;
   440           p.GraveRect.w:= 32;
   443           p.GraveRect.h:= 256;
   441           p.GraveRect.h:= 256;
   444           p:= p.Next
   442           p:= p.Next
   463 
   461 
   464     procedure GetExplosionBorderColor;
   462     procedure GetExplosionBorderColor;
   465     var f: textfile;
   463     var f: textfile;
   466         c: integer;
   464         c: integer;
   467     begin
   465     begin
   468     s:= Pathz[ptThemeCurrent] + cThemeCFGFilename;
   466     s:= Pathz[ptThemeCurrent] + '/' + cThemeCFGFilename;
   469     WriteToConsole(msgLoading + s + ' ');
   467     WriteToConsole(msgLoading + s + ' ');
   470     AssignFile(f, s);
   468     AssignFile(f, s);
   471     {$I-}
   469     {$I-}
   472     Reset(f);
   470     Reset(f);
   473     Readln(f, s);
   471     Readln(f, s);
   488 
   486 
   489 begin
   487 begin
   490 for fi:= Low(THWFont) to High(THWFont) do
   488 for fi:= Low(THWFont) to High(THWFont) do
   491     with Fontz[fi] do
   489     with Fontz[fi] do
   492          begin
   490          begin
   493          s:= Pathz[ptFonts] + Name;
   491          s:= Pathz[ptFonts] + '/' + Name;
   494          WriteToConsole(msgLoading + s + ' ');
   492          WriteToConsole(msgLoading + s + ' ');
   495          Handle:= TTF_OpenFont(PChar(s), Height);
   493          Handle:= TTF_OpenFont(PChar(s), Height);
   496          TryDo(Handle <> nil, msgFailed, true);
   494          TryDo(Handle <> nil, msgFailed, true);
   497          WriteLnToConsole(msgOK)
   495          WriteLnToConsole(msgOK)
   498          end;
   496          end;
   499 AddProgress;
   497 AddProgress;
   500 //s:= Pathz[ptMapCurrent] + cLandFileName;
   498 
   501 //WriteToConsole(msgLoading + s + ' ');         
       
   502 //tmpsurf:= IMG_Load(PChar(s));
       
   503 tmpsurf:= LandSurface;
   499 tmpsurf:= LandSurface;
   504 TryDo(tmpsurf <> nil, msgFailed, true);
   500 TryDo(tmpsurf <> nil, msgFailed, true);
   505 if cFullScreen then
   501 if cFullScreen then
   506    begin
   502    begin
   507    LandSurface:= SDL_DisplayFormat(tmpsurf);
   503    LandSurface:= SDL_DisplayFormat(tmpsurf);
   512 
   508 
   513 GetExplosionBorderColor;
   509 GetExplosionBorderColor;
   514 
   510 
   515 AddProgress;
   511 AddProgress;
   516 for i:= Low(TStuff) to High(TStuff) do
   512 for i:= Low(TStuff) to High(TStuff) do
   517     LoadToSurface(Pathz[StuffLoadData[i].Path] + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y);
   513     LoadToSurface(Pathz[StuffLoadData[i].Path] + '/' + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y);
   518 
   514 
   519 AddProgress;
   515 AddProgress;
   520 WriteNames(fnt16);
   516 WriteNames(fnt16);
   521 MakeCrosshairs;
   517 MakeCrosshairs;
   522 LoadGraves;
   518 LoadGraves;
   524 GetSkyColor;
   520 GetSkyColor;
   525 
   521 
   526 AddProgress;
   522 AddProgress;
   527 for ii:= Low(TSprite) to High(TSprite) do
   523 for ii:= Low(TSprite) to High(TSprite) do
   528     with SpritesData[ii] do
   524     with SpritesData[ii] do
   529          Surface:= LoadImage(Pathz[Path] + FileName, hasAlpha);
   525          Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha);
   530 
   526 
   531 AddProgress;
   527 AddProgress;
   532 tmpsurf:= LoadImage(Pathz[ptGraphics] + cHHFileName, false);
   528 tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false);
   533 TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
   529 TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
   534 HHSurface:= SDL_DisplayFormat(tmpsurf);
   530 HHSurface:= SDL_DisplayFormat(tmpsurf);
   535 SDL_FreeSurface(tmpsurf);
   531 SDL_FreeSurface(tmpsurf);
   536 
   532 
   537 InitHealth;
   533 InitHealth;