hedgewars/uLandObjects.pas
changeset 4782 603916ddf4b6
parent 4669 296dbccdf376
child 4792 68f9b331014a
equal deleted inserted replaced
4780:8571151411b3 4782:603916ddf4b6
    28 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface);
    28 procedure BlitImageAndGenerateCollisionInfo(cpX, cpY, Width: Longword; Image: PSDL_Surface);
    29 procedure AddOnLandObjects(Surface: PSDL_Surface);
    29 procedure AddOnLandObjects(Surface: PSDL_Surface);
    30 
    30 
    31 implementation
    31 implementation
    32 uses uStore, uConsts, uConsole, uRandom, uVisualGears, uSound, GLunit,
    32 uses uStore, uConsts, uConsole, uRandom, uVisualGears, uSound, GLunit,
    33      uTypes, uVariables, uUtils, uDebug;
    33      uTypes, uVariables, uUtils, uDebug, sysutils;
    34 
    34 
    35 const MaxRects = 512;
    35 const MaxRects = 512;
    36       MAXOBJECTRECTS = 16;
    36       MAXOBJECTRECTS = 16;
    37       MAXTHEMEOBJECTS = 32;
    37       MAXTHEMEOBJECTS = 32;
    38 
    38 
   364     end;
   364     end;
   365 TryPut:= bRes;
   365 TryPut:= bRes;
   366 end;
   366 end;
   367 
   367 
   368 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
   368 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
   369 var s: shortstring;
   369 var s, key: shortstring;
   370     f: textfile;
   370     f: textfile;
   371     i, ii, numFlakes: LongInt;
   371     i, ii, numFlakes: LongInt;
   372     c1, c2: TSDL_Color;
   372     c1, c2: TSDL_Color;
   373 
   373 
   374     procedure CheckRect(Width, Height, x, y, w, h: LongWord);
   374     procedure CheckRect(Width, Height, x, y, w, h: LongWord);
   386 Assign(f, s);
   386 Assign(f, s);
   387 {$I-}
   387 {$I-}
   388 filemode:= 0; // readonly
   388 filemode:= 0; // readonly
   389 Reset(f);
   389 Reset(f);
   390 
   390 
   391 // read sky and explosion border colors
   391 ThemeObjects.Count:= 0;
   392 Readln(f, c1.r, c1.g, c1. b);
   392 SprayObjects.Count:= 0;
   393 Readln(f, c2.r, c2.g, c2. b);
   393 
   394 // read water gradient colors
   394 while not eof(f) do
   395 Readln(f, WaterColorArray[0].r, WaterColorArray[0].g, WaterColorArray[0].b);
       
   396 Readln(f, WaterColorArray[2].r, WaterColorArray[2].g, WaterColorArray[2].b, cWaterOpacity);
       
   397 WaterColorArray[0].a := 255;
       
   398 WaterColorArray[2].a := 255;
       
   399 WaterColorArray[1]:= WaterColorArray[0];
       
   400 WaterColorArray[3]:= WaterColorArray[2];
       
   401 
       
   402 glClearColor(c1.r / 255, c1.g / 255, c1.b / 255, 0.99); // sky color
       
   403 cExplosionBorderColor:= c2.value or AMask;
       
   404 
       
   405 ReadLn(f, s);
       
   406 if MusicFN = '' then MusicFN:= s;
       
   407 
       
   408 ReadLn(f, cCloudsNumber);
       
   409 
       
   410 // TODO - adjust all the theme cloud numbers. This should not be a permanent fix
       
   411 //cCloudsNumber:= cCloudsNumber * (LAND_WIDTH div 2048);
       
   412 
       
   413 // scale number of clouds depending on screen space (two times land width)
       
   414 cCloudsNumber:= cCloudsNumber * cScreenSpace div LAND_WIDTH;
       
   415 
       
   416 Readln(f, ThemeObjects.Count);
       
   417 for i:= 0 to Pred(ThemeObjects.Count) do
       
   418     begin
   395     begin
   419     Readln(f, s); // filename
   396     Readln(f, s);
   420     with ThemeObjects.objs[i] do
   397     if Length(s) = 0 then continue;
       
   398     if s[1] = ';' then continue;
       
   399 
       
   400     i:= Pos('=', s);
       
   401     key:= Trim(Copy(s, 1, i - 1));
       
   402     Delete(s, 1, i);
       
   403 
       
   404     if key = 'sky' then
       
   405         begin
       
   406         i:= Pos(',', s);
       
   407         c1.r:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   408         Delete(s, 1, i);
       
   409         i:= Pos(',', s);
       
   410         c1.g:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   411         Delete(s, 1, i);
       
   412         c1.b:= StrToInt(Trim(s));
       
   413         glClearColor(c1.r / 255, c1.g / 255, c1.b / 255, 0.99);
       
   414         end
       
   415     else if key = 'border' then
       
   416         begin
       
   417         i:= Pos(',', s);
       
   418         c2.r:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   419         Delete(s, 1, i);
       
   420         i:= Pos(',', s);
       
   421         c2.g:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   422         Delete(s, 1, i);
       
   423         c2.b:= StrToInt(Trim(s));
       
   424         cExplosionBorderColor:= c2.value or AMask;
       
   425         end
       
   426     else if key = 'water-top' then
       
   427         begin
       
   428         i:= Pos(',', s);
       
   429         WaterColorArray[0].r:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   430         Delete(s, 1, i);
       
   431         i:= Pos(',', s);
       
   432         WaterColorArray[0].g:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   433         Delete(s, 1, i);
       
   434         WaterColorArray[0].b:= StrToInt(Trim(s));
       
   435         WaterColorArray[0].a := 255;
       
   436         WaterColorArray[1]:= WaterColorArray[0];
       
   437         end
       
   438     else if key = 'water-bottom' then
       
   439         begin
       
   440         i:= Pos(',', s);
       
   441         WaterColorArray[2].r:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   442         Delete(s, 1, i);
       
   443         i:= Pos(',', s);
       
   444         WaterColorArray[2].g:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   445         Delete(s, 1, i);
       
   446         WaterColorArray[2].b:= StrToInt(Trim(s));
       
   447         WaterColorArray[2].a := 255;
       
   448         WaterColorArray[3]:= WaterColorArray[2];
       
   449         end
       
   450     else if key = 'water-opacity' then cWaterOpacity:= StrToInt(Trim(s))
       
   451     else if key = 'music' then MusicFN:= Trim(s)
       
   452     else if key = 'clouds' then cCloudsNumber:= StrToInt(Trim(s)) * cScreenSpace div LAND_WIDTH
       
   453     else if key = 'object' then
       
   454         begin
       
   455         inc(ThemeObjects.Count);
       
   456         with ThemeObjects.objs[Pred(ThemeObjects.Count)] do
   421             begin
   457             begin
   422             Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + s, ifCritical or ifTransparent or ifIgnoreCaps);
   458             i:= Pos(',', s);
       
   459             Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, i - 1)), ifCritical or ifTransparent or ifIgnoreCaps);
   423             Width:= Surf^.w;
   460             Width:= Surf^.w;
   424             Height:= Surf^.h;
   461             Height:= Surf^.h;
   425             Read(f, Maxcnt);
   462             Delete(s, 1, i);
       
   463             i:= Pos(',', s);
       
   464             Maxcnt:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   465             Delete(s, 1, i);
   426             if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then OutError('Object''s max count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
   466             if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then OutError('Object''s max count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
   427             with inland do
   467             with inland do
   428                 begin
   468                 begin
   429                 Read(f, x, y, w, h);
   469                 i:= Pos(',', s);
       
   470                 x:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   471                 Delete(s, 1, i);
       
   472                 i:= Pos(',', s);
       
   473                 y:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   474                 Delete(s, 1, i);
       
   475                 i:= Pos(',', s);
       
   476                 w:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   477                 Delete(s, 1, i);
       
   478                 i:= Pos(',', s);
       
   479                 h:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   480                 Delete(s, 1, i);
   430                 CheckRect(Width, Height, x, y, w, h)
   481                 CheckRect(Width, Height, x, y, w, h)
   431                 end;
   482                 end;
   432             Read(f, rectcnt);
   483             i:= Pos(',', s);
       
   484             rectcnt:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   485             Delete(s, 1, i);
   433             for ii:= 1 to rectcnt do
   486             for ii:= 1 to rectcnt do
   434                 with outland[ii] do
   487                 with outland[ii] do
   435                     begin
   488                     begin
   436                     Read(f, x, y, w, h);
   489                     i:= Pos(',', s);
       
   490                     x:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   491                     Delete(s, 1, i);
       
   492                     i:= Pos(',', s);
       
   493                     y:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   494                     Delete(s, 1, i);
       
   495                     i:= Pos(',', s);
       
   496                     w:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   497                     Delete(s, 1, i);
       
   498                     if ii = rectcnt then h:= StrToInt(Trim(s))
       
   499                     else
       
   500                         begin
       
   501                         i:= Pos(',', s);
       
   502                         h:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   503                         Delete(s, 1, i)
       
   504                         end;
   437                     CheckRect(Width, Height, x, y, w, h)
   505                     CheckRect(Width, Height, x, y, w, h)
   438                     end;
   506                     end;
   439             ReadLn(f)
       
   440             end;
   507             end;
       
   508         end
       
   509     else if key = 'spray' then
       
   510         begin
       
   511         inc(SprayObjects.Count);
       
   512         with SprayObjects.objs[Pred(SprayObjects.Count)] do
       
   513             begin
       
   514             i:= Pos(',', s);
       
   515             Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, i - 1)), ifCritical or ifTransparent or ifIgnoreCaps);
       
   516             Width:= Surf^.w;
       
   517             Height:= Surf^.h;
       
   518             Delete(s, 1, i);
       
   519             Maxcnt:= StrToInt(Trim(s));
       
   520             end;
       
   521         end
       
   522     else if key = 'flakes' then
       
   523         begin
       
   524         i:= Pos(',', s);
       
   525         vobCount:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   526         Delete(s, 1, i);
       
   527         if vobCount > 0 then
       
   528             begin
       
   529             i:= Pos(',', s);
       
   530             vobFramesCount:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   531             Delete(s, 1, i);
       
   532             i:= Pos(',', s);
       
   533             vobFrameTicks:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   534             Delete(s, 1, i);
       
   535             i:= Pos(',', s);
       
   536             vobVelocity:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   537             Delete(s, 1, i);
       
   538             vobFallSpeed:= StrToInt(Trim(s));
       
   539             end;
       
   540         end
       
   541     else if key = 'sd-water-top' then
       
   542         begin
       
   543         i:= Pos(',', s);
       
   544         SDWaterColorArray[0].r:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   545         Delete(s, 1, i);
       
   546         i:= Pos(',', s);
       
   547         SDWaterColorArray[0].g:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   548         Delete(s, 1, i);
       
   549         SDWaterColorArray[0].b:= StrToInt(Trim(s));
       
   550         SDWaterColorArray[0].a := 255;
       
   551         SDWaterColorArray[1]:= SDWaterColorArray[0];
       
   552         end
       
   553     else if key = 'sd-water-bottom' then
       
   554         begin
       
   555         i:= Pos(',', s);
       
   556         SDWaterColorArray[2].r:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   557         Delete(s, 1, i);
       
   558         i:= Pos(',', s);
       
   559         SDWaterColorArray[2].g:= StrToInt(Trim(Copy(s, 1, i - 1)));
       
   560         Delete(s, 1, i);
       
   561         SDWaterColorArray[2].b:= StrToInt(Trim(s));
       
   562         SDWaterColorArray[2].a := 255;
       
   563         SDWaterColorArray[3]:= SDWaterColorArray[2];
       
   564         end
       
   565     else if key = 'sd-water-opacity' then continue //cSDWaterOpacity:= StrToInt(Trim(s))
       
   566     else if key = 'sd-clouds' then continue //cSDCloudsNumber:= StrToInt(Trim(s)) * cScreenSpace div LAND_WIDTH
       
   567     else if key = 'sd-flakes' then continue //TODO: make :P
   441     end;
   568     end;
   442 
       
   443 // sprays
       
   444 Readln(f, SprayObjects.Count);
       
   445 for i:= 0 to Pred(SprayObjects.Count) do
       
   446     begin
       
   447     Readln(f, s); // filename
       
   448     with SprayObjects.objs[i] do
       
   449          begin
       
   450          Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + s, ifCritical or ifTransparent or ifIgnoreCaps);
       
   451          Width:= Surf^.w;
       
   452          Height:= Surf^.h;
       
   453          ReadLn(f, Maxcnt)
       
   454          end;
       
   455     end;
       
   456 
       
   457 // snowflakes
       
   458 Readln(f, vobCount);
       
   459 if vobCount > 0 then
       
   460     Readln(f, vobFramesCount, vobFrameTicks, vobVelocity, vobFallSpeed);
       
   461 
   569 
   462 // adjust amount of flakes scaled by screen space
   570 // adjust amount of flakes scaled by screen space
   463 vobCount:= longint(vobCount);
   571 vobCount:= longint(vobCount);
   464 numFlakes:= vobCount * cScreenSpace div LAND_WIDTH;
   572 numFlakes:= vobCount * cScreenSpace div LAND_WIDTH;
   465 
   573