Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated high dpi branch from trunk.
  • Modified: Use generics.collections instead of fgl.
  • Modified: Compile with Delphi syntax.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/LocalPlayer/Tribes.pas

    r349 r465  
    66uses
    77  Protocol, ScreenTools, LazFileUtils, Classes, Graphics, SysUtils, Global,
    8   UGraphicSet;
     8  GraphicSet;
    99
    1010type
     
    2020    yShield: Integer;
    2121  end;
     22
     23  { TModelPictureInfo }
    2224
    2325  TModelPictureInfo = record
     
    2729    Hash: Integer;
    2830    GrName: ShortString;
     31    function GetCommandDataSize: Byte;
    2932  end;
    3033
     
    4649    constructor Create(FileName: string);
    4750    destructor Destroy; override;
    48     function GetCityName(i: Integer): string;
    49 {$IFNDEF SCR} procedure SetCityName(i: Integer; NewName: string); {$ENDIF}
     51    function GetCityName(I: Integer): string;
     52{$IFNDEF SCR} procedure SetCityName(I: Integer; NewName: string); {$ENDIF}
    5053{$IFNDEF SCR} function TString(Template: string): string;
    5154    function TPhrase(Item: string): string; {$ENDIF}
     
    6972function CityName(Founder: Integer): string;
    7073function ModelCode(const ModelInfo: TModelInfo): Integer;
    71 procedure FindStdModelPicture(Code: Integer; var pix: Integer; var Name: string);
     74procedure FindStdModelPicture(Code: Integer; out pix: Integer; out Name: string);
    7275function GetTribeInfo(FileName: string; var Name: string; var Color: TColor): Boolean;
    73 procedure FindPosition(HGr: TGraphicSet; x, y, xmax, ymax: Integer; Mark: TColor;
     76procedure FindPosition(HGr: TGraphicSet; X, Y, xmax, ymax: Integer; Mark: TColor;
    7477  var xp, yp: Integer);
    7578
     
    212215function Get: string;
    213216var
    214   p: Integer;
     217  P: Integer;
    215218begin
    216219  while (Input <> '') and ((Input[1] = ' ') or (Input[1] = #9)) do
    217220    Delete(Input, 1, 1);
    218   p := Pos(',', Input);
    219   if p = 0 then
    220     p := Length(Input) + 1;
    221   Result := Copy(Input, 1, p - 1);
    222   Delete(Input, 1, p);
     221  P := Pos(',', Input);
     222  if P = 0 then
     223    P := Length(Input) + 1;
     224  Result := Copy(Input, 1, P - 1);
     225  Delete(Input, 1, P);
    223226end;
    224227
    225228function GetNum: Integer;
    226229var
    227   i: Integer;
    228 begin
    229   Val(Get, Result, i);
    230   if i <> 0 then
     230  I: Integer;
     231begin
     232  Val(Get, Result, I);
     233  if I <> 0 then
    231234    Result := 0;
    232235end;
    233236
    234 procedure FindStdModelPicture(Code: Integer; var pix: Integer; var Name: string);
    235 var
    236   i: Integer;
    237 begin
    238   for i := 0 to StdUnitScript.Count - 1 do
     237procedure FindStdModelPicture(Code: Integer; out pix: Integer; out Name: string);
     238var
     239  I: Integer;
     240begin
     241  for I := 0 to StdUnitScript.Count - 1 do
    239242  begin // look through StdUnits
    240     Input := StdUnitScript[i];
     243    Input := StdUnitScript[I];
    241244    pix := GetNum;
    242245    if Code = GetNum then
     
    281284  CloseFile(TribeScript);
    282285  Result := Found = 3;
     286end;
     287
     288{ TModelPictureInfo }
     289
     290function TModelPictureInfo.GetCommandDataSize: Byte;
     291begin
     292  Result := SizeOf(trix) + SizeOf(mix) + SizeOf(pix) + SizeOf(Hash) + 1 +
     293    Length(GrName);
    283294end;
    284295
     
    329340end;
    330341
    331 procedure FindPosition(HGr: TGraphicSet; x, y, xmax, ymax: Integer; Mark: TColor;
     342procedure FindPosition(HGr: TGraphicSet; X, Y, xmax, ymax: Integer; Mark: TColor;
    332343  var xp, yp: Integer);
    333344begin
    334345  xp := 0;
    335   while (xp < xmax) and (HGr.Data.Canvas.Pixels[x + 1 + xp, y] <> Mark) do
     346  while (xp < xmax) and (HGr.Data.Canvas.Pixels[X + 1 + xp, Y] <> Mark) do
    336347    Inc(xp);
    337348  yp := 0;
    338   while (yp < ymax) and (HGr.Data.Canvas.Pixels[x, y + 1 + yp] <> Mark) do
     349  while (yp < ymax) and (HGr.Data.Canvas.Pixels[X, Y + 1 + yp] <> Mark) do
    339350    Inc(yp);
    340351end;
    341352
    342 function TTribe.GetCityName(i: Integer): string;
     353function TTribe.GetCityName(I: Integer): string;
    343354begin
    344355  Result := '';
    345   if nCityLines > i then
    346   begin
    347     Result := Script[CityLine0 + i];
     356  if nCityLines > I then
     357  begin
     358    Result := Script[CityLine0 + I];
    348359    while (Result <> '') and ((Result[1] = ' ') or (Result[1] = #9)) do
    349360      Delete(Result, 1, 1);
     
    351362{$IFNDEF SCR}
    352363  else
    353     Result := Format(TPhrase('GENCITY'), [i + 1]);
     364    Result := Format(TPhrase('GENCITY'), [I + 1]);
    354365{$ENDIF}
    355366end;
    356367
    357368{$IFNDEF SCR}
    358 procedure TTribe.SetCityName(i: Integer; NewName: string);
    359 begin
    360   while nCityLines <= i do
     369procedure TTribe.SetCityName(I: Integer; NewName: string);
     370begin
     371  while nCityLines <= I do
    361372  begin
    362373    Script.Insert(CityLine0 + nCityLines, Format(TPhrase('GENCITY'),
     
    364375    Inc(nCityLines);
    365376  end;
    366   Script[CityLine0 + i] := NewName;
     377  Script[CityLine0 + I] := NewName;
    367378end;
    368379
    369380function TTribe.TString(Template: string): string;
    370381var
    371   p: Integer;
     382  P: Integer;
    372383  Variant: Char;
    373384  CaseUp: Boolean;
    374385begin
    375386  repeat
    376     p := pos('#', Template);
    377     if (p = 0) or (p = Length(Template)) then
     387    P := Pos('#', Template);
     388    if (P = 0) or (P = Length(Template)) then
    378389      Break;
    379     Variant := Template[p + 1];
     390    Variant := Template[P + 1];
    380391    CaseUp := Variant in ['A' .. 'Z'];
    381392    if CaseUp then
    382393      Inc(Variant, 32);
    383     Delete(Template, p, 2);
     394    Delete(Template, P, 2);
    384395    if Variant in ['a' .. 'z'] then
    385396    begin
    386397      if NumberName < 0 then
    387         Insert(Name[Variant], Template, p)
     398        Insert(Name[Variant], Template, P)
    388399      else
    389         Insert(Format('P%d', [NumberName]), Template, p);
    390       if CaseUp and (Length(Template) >= p) and
    391         (Template[p] in ['a' .. 'z', #$E0 .. #$FF]) then
    392         Dec(Template[p], 32);
     400        Insert(Format('P%d', [NumberName]), Template, P);
     401      if CaseUp and (Length(Template) >= P) and
     402        (Template[P] in ['a' .. 'z', #$E0 .. #$FF]) then
     403        Dec(Template[P], 32);
    393404    end
    394405  until False;
     
    407418  TLine = array [0 .. 649, 0 .. 2] of Byte;
    408419var
    409   i, x, Gray: Integer;
     420  I, X, Gray: Integer;
    410421  Item: string;
    411422begin
     
    415426  with Script do
    416427  begin
    417     i := 0;
    418     while (i < Count) and (Copy(Strings[i], 1, 6) <>
     428    I := 0;
     429    while (I < Count) and (Copy(Strings[I], 1, 6) <>
    419430        '#AGE' + char(48 + Age) + ' ') do
    420       Inc(i);
    421     if i < Count then
    422     begin
    423       Input := Strings[i];
     431      Inc(I);
     432    if I < Count then
     433    begin
     434      Input := Strings[I];
    424435      system.Delete(Input, 1, 6);
    425436      Item := Get;
     
    430441        if CompareText(Item, 'stdcities') = 0 then
    431442          case cpix of
    432             3:
    433               cpix := 0;
    434             6:
    435             begin
     443            3: cpix := 0;
     444            6: begin
    436445              cpix := 0;
    437446              Item := 'Nation2';
    438             end
     447            end;
    439448          end;
    440449        cHGr := LoadGraphicSet(Item + '.png');
    441         for x := 0 to 3 do
    442           with CityPicture[x] do
    443           begin
    444             FindPosition(cHGr, x * 65, cpix * 49, 63, 47, $00FFFF,
     450        for X := 0 to 3 do
     451          with CityPicture[X] do begin
     452            FindPosition(cHGr, X * 65, cpix * 49, 63, 47, $00FFFF,
    445453              xShield, yShield);
    446454            // FindPosition(cHGr,x*65,cpix*49,$FFFFFF,xf,yf);
     
    478486procedure TTribe.SetModelPicture(const Info: TModelPictureInfo; IsNew: Boolean);
    479487var
    480   i: Integer;
     488  I: Integer;
    481489  ok: Boolean;
    482490begin
     
    485493    if not IsNew then
    486494    begin
    487       i := nPictureList - 1;
    488       while (i >= 0) and (PictureList[i].Hash <> Info.Hash) do
    489         Dec(i);
    490       assert(i >= 0);
    491       assert(PictureList[i].HGr = LoadGraphicSet(GrName));
    492       assert(PictureList[i].pix = pix);
    493       ModelPicture[mix].HGr := PictureList[i].HGr;
    494       ModelPicture[mix].pix := PictureList[i].pix;
    495       ModelName[mix] := PictureList[i].ModelName;
     495      I := nPictureList - 1;
     496      while (I >= 0) and (PictureList[I].Hash <> Info.Hash) do
     497        Dec(I);
     498      Assert(I >= 0);
     499      Assert(PictureList[I].HGr = LoadGraphicSet(GrName));
     500      Assert(PictureList[I].pix = pix);
     501      ModelPicture[mix].HGr := PictureList[I].HGr;
     502      ModelPicture[mix].pix := PictureList[I].pix;
     503      ModelName[mix] := PictureList[I].ModelName;
    496504    end
    497505    else
     
    507515      // read model name from tribe script
    508516      ok := False;
    509       for i := 0 to Script.Count - 1 do
    510       begin
    511         Input := Script[i];
     517      for I := 0 to Script.Count - 1 do
     518      begin
     519        Input := Script[I];
    512520        if Input = '#UNITS ' + ExtractFileNameOnly(GrName) then
    513521          ok := True
     
    523531      if ModelName[mix] = '' then
    524532      begin // read model name from StdUnits.txt
    525         for i := 0 to StdUnitScript.Count - 1 do
     533        for I := 0 to StdUnitScript.Count - 1 do
    526534        begin
    527           Input := StdUnitScript[i];
     535          Input := StdUnitScript[I];
    528536          if GetNum = pix then
    529537          begin
     
    559567  Code, Turn: Integer; ForceNew: Boolean): Boolean;
    560568var
    561   i: Integer;
     569  I: Integer;
    562570  Cnt: Integer;
    563571  HGr: TGraphicSet;
     
    598606  if not ForceNew and (Picture.Hash > 0) then
    599607  begin
    600     for i := 0 to nPictureList - 1 do
    601       if PictureList[i].Hash = Picture.Hash then
    602       begin
    603         Picture.GrName := PictureList[i].HGr.Name;
    604         Picture.pix := PictureList[i].pix;
     608    for I := 0 to nPictureList - 1 do
     609      if PictureList[I].Hash = Picture.Hash then
     610      begin
     611        Picture.GrName := PictureList[I].HGr.Name;
     612        Picture.pix := PictureList[I].pix;
    605613        Result := False;
    606614        Exit;
     
    614622  TestPic.GrName := 'StdUnits.png';
    615623  HGr := HGrStdUnits;
    616   for i := 0 to StdUnitScript.Count - 1 do
     624  for I := 0 to StdUnitScript.Count - 1 do
    617625  begin // look through StdUnits
    618     Input := StdUnitScript[i];
     626    Input := StdUnitScript[I];
    619627    Check;
    620628  end;
    621629
    622630  ok := False;
    623   for i := 0 to Script.Count - 1 do
     631  for I := 0 to Script.Count - 1 do
    624632  begin // look through units defined in tribe script
    625     Input := Script[i];
     633    Input := Script[I];
    626634    if Copy(Input, 1, 6) = '#UNITS' then
    627635    begin
Note: See TracChangeset for help on using the changeset viewer.