Changeset 327


Ignore:
Timestamp:
Mar 25, 2021, 2:09:42 PM (7 months ago)
Author:
chronos
Message:
  • Modified: Use enumeration type for MapOptions and game options.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/ClientTools.pas

    r326 r327  
    1616  TEnhancementJobs = array [0 .. 11, 0 .. 7] of byte;
    1717  JobResultSet = set of 0 .. 39;
     18
     19  TMapOption = (
     20    // options switched by buttons
     21    moPolitical = 0, moCityNames = 1, moGreatWall = 4, moGrid = 5, moBareTerrain = 6,
     22    // other options
     23    moEditMode = 16, moLocCodes = 17
     24  );
     25  TMapOptions = set of TMapOption;
     26
     27  TSaveOption = (soAlEffectiveMovesOnly = 0, soEnMoves = 1, soEnAttacks = 2,
     28    soEnNoMoves = 3, soWaitTurn = 4, soEffectiveMovesOnly = 5, soEnFastMoves = 6,
     29    soSlowMoves = 7, soFastMoves = 8, soVeryFastMoves = 9, soNames = 10,
     30    soRepList = 11, soRepScreens = 12, soSoundOff = 13, soSoundOn = 14,
     31    soSoundOnAlt = 15, soScrollSlow = 16, soScrollFast = 17, soScrollOff = 18,
     32    soAlSlowMoves = 19, soAlFastMoves = 20, somAlNoMoves = 21, soTellAI = 30);
     33  TSaveOptions = set of TSaveOption;
    1834
    1935var
  • trunk/LocalPlayer/IsoEngine.pas

    r326 r327  
    6666  end;
    6767
    68 const
    69   // options switched by buttons
    70   moPolitical = 0;
    71   moCityNames = 1;
    72   moGreatWall = 4;
    73   moGrid = 5;
    74   moBareTerrain = 6;
    75 
    76   // other options
    77   moEditMode = 16;
    78   moLocCodes = 17;
    79 
    8068var
    8169  NoMap: TIsoMap;
    82   Options: Integer;
     70  MapOptions: TMapOptions;
    8371  pDebugMap: Integer; // -1 for off
    8472
     
    1004992  begin
    1005993    BehindCityInfo.Loc := Loc - 2 * G.lx;
    1006     if ShowCityNames and (Options and (1 shl moEditMode) = 0) and
     994    if ShowCityNames and not (moEditMode in MapOptions) and
    1007995      (BehindCityInfo.Loc >= 0) and (BehindCityInfo.Loc < G.lx * G.ly) and
    1008996      (MyMap[BehindCityInfo.Loc] and fCity <> 0) then
     
    10251013  procedure ShowSpacePort;
    10261014  begin
    1027     if ShowObjects and (Options and (1 shl moEditMode) = 0) and
     1015    if ShowObjects and not (moEditMode in MapOptions) and
    10281016      (Tile and fCity <> 0) and (CityInfo.Flags and ciSpacePort <> 0) then
    10291017      TSprite(x + xxt, y - 6, spSpacePort);
     
    10931081  else
    10941082    Tile := MyMap[Loc];
    1095   if ShowObjects and (Options and (1 shl moEditMode) = 0) and
     1083  if ShowObjects and not (moEditMode in MapOptions) and
    10961084    (Tile and fCity <> 0) then
    10971085    GetCityInfo(Loc, cix, CityInfo);
     
    11481136    TSprite(x, y, spMinerals + (Tile shr 25 and 3) * TerrainIconCols);
    11491137
    1150   if Options and (1 shl moEditMode) <> 0 then
     1138  if moEditMode in MapOptions then
    11511139    fog := (Loc < 0) or (Loc >= G.lx * G.ly)
    11521140    // else if CityLoc>=0 then
     
    11821170  end;
    11831171{$ENDIF}
    1184   if Options and (1 shl moEditMode) <> 0 then
     1172  if moEditMode in MapOptions then
    11851173  begin
    11861174    if Tile and fPrefStartPos <> 0 then
     
    14271415begin
    14281416  FoW := true;
    1429   ShowLoc := Options and (1 shl moLocCodes) <> 0;
     1417  ShowLoc := moLocCodes in MapOptions;
    14301418  ShowDebug := pDebugMap >= 0;
    1431   ShowObjects := (CityOwner >= 0) or (Options and (1 shl moBareTerrain) = 0);
     1419  ShowObjects := (CityOwner >= 0) or not (moBareTerrain in MapOptions);
    14321420  ShowCityNames := ShowObjects and (CityOwner < 0) and
    1433     (Options and (1 shl moCityNames) <> 0);
     1421    (moCityNames in MapOptions);
    14341422  ShowBorder := true;
    14351423  ShowMyBorder := CityOwner < 0;
    1436   ShowGrWall := (CityOwner < 0) and (Options and (1 shl moGreatWall) <> 0);
     1424  ShowGrWall := (CityOwner < 0) and (moGreatWall in MapOptions);
    14371425  if ShowDebug then
    14381426    Server(sGetDebugMap, me, pDebugMap, DebugMap)
     
    16221610  else
    16231611  begin
    1624     if ShowLoc or (Options and (1 shl moEditMode) <> 0) or
    1625       (Options and (1 shl moGrid) <> 0) then
     1612    if ShowLoc or (moEditMode in MapOptions) or
     1613      (moGrid in MapOptions) then
    16261614      PaintGrid(x, y, nx, ny);
    16271615    for dy := -2 to ny + 1 do
  • trunk/LocalPlayer/NatStat.pas

    r315 r327  
    141141  ScrollDownBtn.Visible := (CurrentReport.TurnOfCivilReport >= 0) and
    142142    (ReportText.Count > ReportLines);
    143   if OptionChecked and (1 shl soTellAI) <> 0 then
     143  if soTellAI in OptionChecked then
    144144    TellAIBtn.ButtonIndex := 3
    145145  else
     
    390390    end;
    391391
    392     if OptionChecked and (1 shl soTellAI) <> 0 then
    393     begin
     392    if soTellAI in OptionChecked then begin
    394393      Server(sGetAIInfo, me, pView, ps);
    395394      LoweredTextOut(Canvas, -1, MainTexture, 42, 445, ps);
    396     end
    397     else
     395    end else
    398396      LoweredTextOut(Canvas, -2, MainTexture, 42, 445,
    399397        Phrases2.Lookup('MENU_TELLAI'));
     
    537535procedure TNatStatDlg.TellAIBtnClick(Sender: TObject);
    538536begin
    539   OptionChecked := OptionChecked xor (1 shl soTellAI);
    540   if OptionChecked and (1 shl soTellAI) <> 0 then
     537  if soTellAI in OptionChecked then OptionChecked := OptionChecked - [soTellAI]
     538    else OptionChecked := OptionChecked + [soTellAI];
     539  if soTellAI in OptionChecked then
    541540    TellAIBtn.ButtonIndex := 3
    542541  else
  • trunk/LocalPlayer/Term.pas

    r326 r327  
    271271    procedure InitModule;
    272272    procedure InitTurn(NewPlayer: integer);
     273    procedure SaveMenuItemsState;
    273274    procedure ScrollBarUpdate(Sender: TObject);
    274275    procedure ArrangeMidPanel;
     
    421422  // lines of system icons in icons.bmp before improvements
    422423
    423   // save options apart from what's defined by SaveOption
    424   soTellAI = 30;
    425   soExtraMask = $40000000;
    426 
    427424  nCityEventPriority = 16;
    428425  CityEventPriority: array [0 .. nCityEventPriority - 1] of integer =
     
    485482  Age: Integer;
    486483  UnFocus: Integer;
    487   OptionChecked: Integer;
    488   MapOptionChecked: Integer;
     484  OptionChecked: TSaveOptions;
     485  MapOptionChecked: TMapOptions;
    489486  nLostArmy: Integer;
    490487  ScienceSum: Integer;
     
    570567  flImmUpdate = $0002;
    571568
    572   nSaveOption = 22;
    573 
    574569var
    575570  Jump: array [0 .. nPl - 1] of integer;
     
    577572  SmallScreen, GameOK, MapValid, skipped, idle: boolean;
    578573
    579   SaveOption: array [0..nSaveOption - 1] of integer;
     574  SaveOption: array of integer;
    580575  MiniColors: array [0..11, 0..1] of TColor;
    581576  MainMap: TIsoMap;
     
    12661261procedure TMainScreen.SetMapOptions;
    12671262begin
    1268   MiniMap.Options := MapOptionChecked;
    1269   IsoEngine.Options := MapOptionChecked;
     1263  MiniMap.MapOptions := MapOptionChecked;
     1264  IsoEngine.MapOptions := MapOptionChecked;
    12701265  if ClientMode = cEditMap then
    1271     IsoEngine.Options := IsoEngine.Options or (1 shl moEditMode);
     1266    IsoEngine.MapOptions := IsoEngine.MapOptions + [moEditMode];
    12721267  if mLocCodes.Checked then
    1273     IsoEngine.Options := IsoEngine.Options or (1 shl moLocCodes);
     1268    IsoEngine.MapOptions := IsoEngine.MapOptions + [moLocCodes];
    12741269end;
    12751270
     
    34583453  BaseWin.CreateOffscreen(Offscreen);
    34593454
    3460    // define which menu settings to save
     3455  // define which menu settings to save
     3456  SetLength(SaveOption, 22);
    34613457  SaveOption[0] := mAlEffectiveMovesOnly.Tag;
    34623458  SaveOption[1] := mEnMoves.Tag;
     
    34903486  for i := 0 to ComponentCount - 1 do
    34913487    if Components[i].Tag and $FF <> 0 then
    3492       if Components[i] is TMenuItem then
    3493       begin
     3488      if Components[i] is TMenuItem then begin
    34943489        TMenuItem(Components[i]).Caption := Phrases.Lookup('CONTROLS',
    34953490          -1 + Components[i].Tag and $FF);
    3496         for j := 0 to nSaveOption - 1 do
     3491        for j := 0 to Length(SaveOption) - 1 do
    34973492          if Components[i].Tag and $FF = SaveOption[j] then
    3498             TMenuItem(Components[i]).Checked := ((1 shl j) and OptionChecked) <> 0;
    3499       end
    3500       else if Components[i] is TButtonBase then
    3501       begin
     3493            TMenuItem(Components[i]).Checked := TSaveOption(j) in OptionChecked;
     3494      end else
     3495      if Components[i] is TButtonBase then begin
    35023496        TButtonBase(Components[i]).Hint := Phrases.Lookup('CONTROLS',
    35033497          -1 + Components[i].Tag and $FF);
     
    35053499          (TButtonC(Components[i]).ButtonIndex <> 1) then
    35063500          TButtonC(Components[i]).ButtonIndex :=
    3507             MapOptionChecked shr (Components[i].Tag shr 8) and 1 + 2
     3501            Integer(MapOptionChecked) shr (Components[i].Tag shr 8) and 1 + 2
    35083502      end;
    35093503
     
    50155009procedure TMainScreen.Timer1Timer(Sender: TObject);
    50165010var
    5017   dx, dy, speed: integer;
     5011  dx, dy, ScrollSpeed: integer;
    50185012begin
    50195013  if idle and (me >= 0) and (GameMode <> cMovie) then
     
    50365030      if Application.Active and not mScrollOff.Checked then
    50375031      begin
    5038         if mScrollFast.Checked then
    5039           speed := 2
    5040         else
    5041           speed := 1;
     5032        if mScrollFast.Checked then ScrollSpeed := 2
     5033          else ScrollSpeed := 1;
    50425034        dx := 0;
    50435035        dy := 0;
    50445036        if Mouse.CursorPos.y < Screen.height - PanelHeight then
    50455037          if Mouse.CursorPos.x = 0 then
    5046             dx := -speed // scroll left
     5038            dx := -ScrollSpeed // scroll left
    50475039          else if Mouse.CursorPos.x = Screen.width - 1 then
    5048             dx := speed; // scroll right
     5040            dx := ScrollSpeed; // scroll right
    50495041        if Mouse.CursorPos.y = 0 then
    5050           dy := -speed // scroll up
     5042          dy := -ScrollSpeed // scroll up
    50515043        else if (Mouse.CursorPos.y = Screen.height - 1) and
    50525044          (Mouse.CursorPos.x >= TerrainBtn.Left + TerrainBtn.width) and
    50535045          (Mouse.CursorPos.x < xRightPanel + 10 - 8) then
    5054           dy := speed; // scroll down
     5046          dy := ScrollSpeed; // scroll down
    50555047        if (dx <> 0) or (dy <> 0) then
    50565048        begin
     
    63826374begin
    63836375  IsoEngine.pDebugMap := p;
    6384   IsoEngine.Options := IsoEngine.Options and not(1 shl moLocCodes);
     6376  IsoEngine.MapOptions := IsoEngine.MapOptions - [moLocCodes];
    63856377  mLocCodes.Checked := false;
    63866378  MapValid := false;
     
    77067698var
    77077699  Reg: TRegistry;
    7708   DefaultOptionChecked: Integer;
    7709 begin
    7710   DefaultOptionChecked := 1 shl 1 + 1 shl 7 + 1 shl 10 + 1 shl 12 + 1 shl 14 +
    7711     1 shl 18 + 1 shl 19;
     7700  DefaultOptionChecked: TSaveOptions;
     7701begin
     7702  DefaultOptionChecked := [soEnMoves, soSlowMoves, soNames, soRepScreens,
     7703    soSoundOn, soScrollOff, soAlSlowMoves];
    77127704  Reg := TRegistry.Create;
    77137705  with Reg do try
     
    77177709    xxt := TileSizes[TileSize].X;
    77187710    yyt := TileSizes[TileSize].Y;
    7719     if ValueExists('OptionChecked') then OptionChecked := ReadInteger('OptionChecked')
     7711    if ValueExists('OptionChecked') then OptionChecked := TSaveOptions(ReadInteger('OptionChecked'))
    77207712      else OptionChecked := DefaultOptionChecked;
    7721     if ValueExists('MapOptionChecked') then MapOptionChecked := ReadInteger('MapOptionChecked')
    7722       else MapOptionChecked := 1 shl moCityNames;
     7713    if ValueExists('MapOptionChecked') then MapOptionChecked := TMapOptions(ReadInteger('MapOptionChecked'))
     7714      else MapOptionChecked := [moCityNames];
    77237715    if ValueExists('CityReport') then CityRepMask := Cardinal(ReadInteger('CityReport'))
    77247716      else CityRepMask := Cardinal(not chPopIncrease and not chNoGrowthWarning and
    77257717          not chCaptured);
    7726     if OptionChecked and (7 shl 16) = 0 then
    7727       OptionChecked := OptionChecked or (1 shl 16);
     7718    if (not (soScrollFast in OptionChecked)) and (not (soScrollSlow in OptionChecked)) and
     7719      (not (soScrollOff in OptionChecked)) then
     7720      OptionChecked := OptionChecked + [soScrollSlow];
    77287721      // old regver with no scrolling
    77297722  finally
     
    77317724  end;
    77327725
    7733   if 1 shl 13 and OptionChecked <> 0 then
     7726  if soSoundOff in OptionChecked then
    77347727    SoundMode := smOff
    7735   else if 1 shl 15 and OptionChecked <> 0 then
     7728  else if soSoundOnAlt in OptionChecked then
    77367729    SoundMode := smOnAlt
    77377730  else
     
    78037796  with TButtonC(Sender) do
    78047797  begin
    7805     MapOptionChecked := MapOptionChecked xor (1 shl (Tag shr 8));
     7798    MapOptionChecked := TMapOptions(Integer(MapOptionChecked) xor (1 shl (Tag shr 8)));
    78067799    SetMapOptions;
    7807     ButtonIndex := MapOptionChecked shr (Tag shr 8) and 1 + 2;
     7800    ButtonIndex := Integer(MapOptionChecked) shr (Tag shr 8) and 1 + 2;
    78087801  end;
    78097802  if Sender = MapBtn0 then
     
    78237816  if TButtonBase(Sender).Down then
    78247817  begin
    7825     MapOptionChecked := MapOptionChecked or (1 shl moGreatWall);
     7818    MapOptionChecked := MapOptionChecked + [moGreatWall];
    78267819    TButtonBase(Sender).Hint := '';
    78277820  end
    78287821  else
    78297822  begin
    7830     MapOptionChecked := MapOptionChecked and not(1 shl moGreatWall);
     7823    MapOptionChecked := MapOptionChecked - [moGreatWall];
    78317824    TButtonBase(Sender).Hint := Phrases.Lookup('CONTROLS',
    78327825      -1 + TButtonBase(Sender).Tag and $FF);
     
    78417834  if TButtonBase(Sender).Down then
    78427835  begin
    7843     MapOptionChecked := MapOptionChecked or (1 shl moBareTerrain);
     7836    MapOptionChecked := MapOptionChecked + [moBareTerrain];
    78447837    TButtonBase(Sender).Hint := '';
    78457838  end
    78467839  else
    78477840  begin
    7848     MapOptionChecked := MapOptionChecked and not(1 shl moBareTerrain);
     7841    MapOptionChecked := MapOptionChecked - [moBareTerrain];
    78497842    TButtonBase(Sender).Hint := Phrases.Lookup('CONTROLS',
    78507843      -1 + TButtonBase(Sender).Tag and $FF);
     
    79737966end;
    79747967
     7968procedure TMainScreen.SaveMenuItemsState;
     7969var
     7970  i, j: integer;
     7971begin
     7972  if soTellAI in OptionChecked then OptionChecked := [soTellAI]
     7973    else OptionChecked := [];
     7974  for i := 0 to ComponentCount - 1 do
     7975    if Components[i] is TMenuItem then
     7976      for j := 0 to Length(SaveOption) - 1 do
     7977        if TMenuItem(Components[i]).Checked and
     7978          (TMenuItem(Components[i]).Tag = SaveOption[j]) then
     7979          OptionChecked := OptionChecked + [TSaveOption(j)];
     7980end;
     7981
    79757982procedure TMainScreen.SaveSettings;
    79767983var
    7977   i, j: integer;
    79787984  Reg: TRegistry;
    79797985begin
    7980   OptionChecked := OptionChecked and soExtraMask;
    7981   for i := 0 to ComponentCount - 1 do
    7982     if Components[i] is TMenuItem then
    7983       for j := 0 to nSaveOption - 1 do
    7984         if TMenuItem(Components[i]).Checked and
    7985           (TMenuItem(Components[i]).Tag = SaveOption[j]) then
    7986           inc(OptionChecked, 1 shl j);
     7986  SaveMenuItemsState;
    79877987
    79887988  Reg := TRegistry.Create;
     
    79917991    OpenKey(AppRegistryKey, true);
    79927992    WriteInteger('TileSize', Integer(TileSize));
    7993     WriteInteger('OptionChecked', OptionChecked);
    7994     WriteInteger('MapOptionChecked', MapOptionChecked);
     7993    WriteInteger('OptionChecked', Integer(OptionChecked));
     7994    WriteInteger('MapOptionChecked', Integer(MapOptionChecked));
    79957995    WriteInteger('CityReport', integer(CityRepMask));
    79967996  finally
  • trunk/UMiniMap.pas

    r326 r327  
    55
    66uses
    7   Classes, SysUtils, Graphics, Protocol;
     7  Classes, SysUtils, Graphics, Protocol, ClientTools;
    88
    99type
     
    2222    Colors: array [0 .. 11, 0 .. 1] of TColor;
    2323    Mode: TMiniMode;
    24     Options: Integer;
     24    MapOptions: TMapOptions;
    2525    procedure LoadFromLogFile(FileName: string; var LastTurn: Integer; DefaultSize: TPoint);
    2626    procedure LoadFromMapFile(FileName: string; var nMapLandTiles, nMapStartPositions: Integer);
     
    3737
    3838uses
    39   ScreenTools, UPixelPointer, Global, GameServer, IsoEngine, Tribes, ClientTools;
     39  ScreenTools, UPixelPointer, Global, GameServer, IsoEngine, Tribes;
    4040
    4141const
     
    310310            cm := $808080 or cm shr 1; { increase brightness }
    311311          end
    312           else if Options and (1 shl moPolitical) <> 0 then begin
     312          else if moPolitical in MapOptions then begin
    313313            // Political
    314314            if MyMap[Loc] and fTerrain < fGrass then
Note: See TracChangeset for help on using the changeset viewer.