Changeset 465 for branches


Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Updated high dpi branch from trunk.
  • Modified: Use generics.collections instead of fgl.
  • Modified: Compile with Delphi syntax.
Location:
branches/highdpi
Files:
10 added
1 deleted
108 edited
16 moved

Legend:

Unmodified
Added
Removed
  • branches/highdpi/AI/StdAI/AI.pas

    r349 r465  
    2323
    2424  nResearchOrder = 46;
    25   ResearchOrder: array[0..1, 0..nResearchOrder - 1] of integer =
     25  ResearchOrder: array[0..1, 0..nResearchOrder - 1] of Integer =
    2626    ((adWheel, adWarriorCode, adHorsebackRiding, adCeremonialBurial, adPolytheism,
    2727    adMonarchy, adMysticism, adPoetry, adAstronomy, adMonotheism,
     
    7676
    7777  // mil research
    78   BetterQuality: array[0..nModelCat - 1] of integer = (50, 50, 80, 80);
     78  BetterQuality: array[0..nModelCat - 1] of Integer = (50, 50, 80, 80);
    7979  MaxBuildWorseThanBestModel = 20;
    8080  MaxExistWorseThanBestModel = 50;
     
    8585  nRequestedTechs = 48;
    8686
    87   PlayerHash: array[0..nPl - 1] of integer =
     87  PlayerHash: array[0..nPl - 1] of Integer =
    8888    (7, 6, 0, 2, 10, 8, 12, 14, 4, 1, 3, 5, 9, 11, 13);
    8989
     
    9292
    9393  TPersistentData = record
    94     LastResearchTech, BehaviorFlags, TheologyPartner: integer;
     94    LastResearchTech, BehaviorFlags, TheologyPartner: Integer;
    9595    RejectTurn: array[Suggestion, 0..15] of smallint;
    96     RequestedTechs: array[0..nRequestedTechs - 1] of integer;
     96    RequestedTechs: array[0..nRequestedTechs - 1] of Integer;
    9797    // ad + p shl 8 + Turn shl 16
    9898  end;
    9999
    100100  TAI = class(TBarbarina)
    101     constructor Create(Nation: integer); override;
     101    constructor Create(Nation: Integer); override;
    102102
    103103    procedure SetDataDefaults; override;
     
    106106    Data: ^TPersistentData;
    107107    WarNations, BombardingNations, mixSettlers, mixCaravan, mixTownGuard,
    108     mixSlaves, mixMilitia, mixCruiser, OceanWithShip: integer;
     108    mixSlaves, mixMilitia, mixCruiser, OceanWithShip: Integer;
    109109    NegoCause: (Routine, CheckBarbarina);
    110     SettlerSurplus: array[0..maxCOD - 1] of integer;
    111     uixPatrol: array[0..maxCOD - 1] of integer;
    112 
    113     ContinentPresence: array[0..maxCOD - 1] of integer;
    114     OceanPresence: array[0..maxCOD - 1] of integer;
    115     UnitLack: array[0..maxCOD - 1, mctGroundDefender..mctGroundAttacker] of integer;
    116 
    117     TotalPopulation: array[0..nPl - 1] of integer;
    118     ContinentPopulation: array[0..nPl - 1, 0..maxCOD - 1] of integer;
     110    SettlerSurplus: array[0..maxCOD - 1] of Integer;
     111    uixPatrol: array[0..maxCOD - 1] of Integer;
     112
     113    ContinentPresence: array[0..maxCOD - 1] of Integer;
     114    OceanPresence: array[0..maxCOD - 1] of Integer;
     115    UnitLack: array[0..maxCOD - 1, mctGroundDefender..mctGroundAttacker] of Integer;
     116
     117    TotalPopulation: array[0..nPl - 1] of Integer;
     118    ContinentPopulation: array[0..nPl - 1, 0..maxCOD - 1] of Integer;
    119119    // 1 means enemy territory spotted but no city
    120     DistrictPopulation: array[0..maxCOD - 1] of integer;
    121 
    122     ModelCat: array[0..nMmax - 1] of integer;
    123     ModelQuality: array[0..nMmax - 1] of integer;
    124     ModelBestQuality: array[0..nModelCat - 1] of integer;
    125 
    126     AdvanceValue: array[0..nAdv - 1] of integer;
    127     AdvanceValuesSet: boolean;
     120    DistrictPopulation: array[0..maxCOD - 1] of Integer;
     121
     122    ModelCat: array[0..nMmax - 1] of Integer;
     123    ModelQuality: array[0..nMmax - 1] of Integer;
     124    ModelBestQuality: array[0..nModelCat - 1] of Integer;
     125
     126    AdvanceValue: array[0..nAdv - 1] of Integer;
     127    AdvanceValuesSet: Boolean;
    128128
    129129    procedure DoTurn; override;
    130130    procedure DoNegotiation; override;
    131     function ChooseResearchAdvance: integer; override;
    132     function ChooseStealAdvance: integer; override;
    133     function ChooseGovernment: integer; override;
    134     function WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; override;
    135     function OnNegoRejected_CancelTreaty: boolean; override;
    136 
    137     procedure FindBestTrade(Nation: integer; var adWanted, adGiveAway: integer);
     131    function ChooseResearchAdvance: Integer; override;
     132    function ChooseStealAdvance: Integer; override;
     133    function ChooseGovernment: Integer; override;
     134    function WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; override;
     135    function OnNegoRejected_CancelTreaty: Boolean; override;
     136
     137    procedure FindBestTrade(Nation: Integer; var adWanted, adGiveAway: Integer);
    138138    procedure CheckGender;
    139139    procedure AnalyzeMap;
     
    141141    procedure AttackAndPatrol;
    142142    procedure MoveUnitsHome;
    143     procedure CheckAttack(uix: integer);
    144     procedure Patrol(uix: integer);
     143    procedure CheckAttack(uix: Integer);
     144    procedure Patrol(uix: Integer);
    145145    procedure SetCityProduction;
    146146    procedure SetAdvanceValues;
    147     function HavePort: boolean;
    148   {$IFDEF DEBUG}procedure TraceAdvanceValues(Nation: integer);{$ENDIF}
     147    function HavePort: Boolean;
     148  {$IFDEF DEBUG}procedure TraceAdvanceValues(Nation: Integer);{$ENDIF}
    149149
    150150    // research
    151     procedure RateModel(const mi: TModelInfo; var Category, Quality: integer);
    152     procedure RateMyModel(mix: integer; var Category, Quality: integer);
    153     function IsBetterModel(const mi: TModelInfo): boolean;
     151    procedure RateModel(const mi: TModelInfo; var Category, Quality: Integer);
     152    procedure RateMyModel(mix: Integer; var Category, Quality: Integer);
     153    function IsBetterModel(const mi: TModelInfo): Boolean;
    154154
    155155    //terraforming
    156     procedure TileWorkPlan(Loc, cix: integer; var Value, NextJob, TotalWork: integer);
     156    procedure TileWorkPlan(Loc, cix: Integer; var Value, NextJob, TotalWork: Integer);
    157157    procedure ProcessSettlers;
    158158
    159159    // diplomacy
    160     function MostWanted(Nation, adGiveAway: integer): integer;
     160    function MostWanted(Nation, adGiveAway: Integer): Integer;
    161161
    162162  end;
     
    174174
    175175var
    176   LeaveOutValue: array[0..nAdv - 1] of integer;
    177 
    178 
    179 constructor TAI.Create(Nation: integer);
     176  LeaveOutValue: array[0..nAdv - 1] of Integer;
     177
     178constructor TAI.Create(Nation: Integer);
    180179begin
    181180  inherited;
    182   Data := pointer(RO.Data);
     181  Data := Pointer(RO.Data);
    183182{$IFDEF DEBUG}
    184183  if Nation = 1 then
     
    193192  begin
    194193    LastResearchTech := -1;
    195     if PlayerHash[me] > 7 then
     194    if PlayerHash[Me] > 7 then
    196195      BehaviorFlags := bFemale
    197196    else
     
    199198    DebugMessage(1, 'Gender:=' + char(48 + BehaviorFlags and bGender));
    200199    TheologyPartner := -1;
    201     fillchar(RejectTurn, sizeof(RejectTurn), $FF);
    202     Fillchar(RequestedTechs, sizeof(RequestedTechs), $FF);
     200    FillChar(RejectTurn, SizeOf(RejectTurn), $FF);
     201    Fillchar(RequestedTechs, SizeOf(RequestedTechs), $FF);
    203202  end;
    204203end;
    205204
    206 function TAI.OnNegoRejected_CancelTreaty: boolean;
     205function TAI.OnNegoRejected_CancelTreaty: Boolean;
    207206begin
    208207  Data.RejectTurn[suContact, Opponent] := RO.Turn;
     
    210209end;
    211210
    212 
    213211//-------------------------------
    214212//            RESEARCH
    215213//-------------------------------
    216214
    217 procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: integer);
     215procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: Integer);
    218216var
    219   EffectiveTransport: integer;
     217  EffectiveTransport: Integer;
    220218begin
    221219  if mi.Kind >= mkScout then
    222220  begin
    223221    Category := mctNone;
    224     exit;
     222    Exit;
    225223  end;
    226224  case mi.Domain of
     
    294292end;
    295293
    296 procedure TAI.RateMyModel(mix: integer; var Category, Quality: integer);
     294procedure TAI.RateMyModel(mix: Integer; var Category, Quality: Integer);
    297295var
    298296  mi: TModelInfo;
    299297begin
    300   MakeModelInfo(me, mix, MyModel[mix], mi);
     298  MakeModelInfo(Me, mix, MyModel[mix], mi);
    301299  RateModel(mi, Category, Quality);
    302300end;
    303301
    304 function TAI.IsBetterModel(const mi: TModelInfo): boolean;
     302function TAI.IsBetterModel(const mi: TModelInfo): Boolean;
    305303var
    306   mix, Cat, Quality, Cat1, Quality1: integer;
     304  mix, Cat, Quality, Cat1, Quality1: Integer;
    307305begin
    308306  RateModel(mi, Cat, Quality);
     
    314312      begin
    315313        Result := False;
    316         exit;
     314        Exit;
    317315      end;
    318316    end;
     
    320318end;
    321319
    322 function TAI.ChooseResearchAdvance: integer;
     320function TAI.ChooseResearchAdvance: Integer;
    323321var
    324   adNext, iad, i, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut,
    325   NewResearch, StateOfArt, mix: integer;
     322  adNext, iad, I, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut,
     323  NewResearch, StateOfArt, mix: Integer;
    326324  mi: TModelInfo;
    327   Entry: array[0..nAdv - 1] of boolean;
    328   ok: boolean;
    329 
    330   function MarkEntry(ad: integer): boolean;
     325  Entry: array[0..nAdv - 1] of Boolean;
     326  ok: Boolean;
     327
     328  function MarkEntry(ad: Integer): Boolean;
    331329  begin
    332330    if RO.Tech[ad] >= tsApplicable then
     
    375373  end;
    376374
    377   procedure OptimizeDevModel(OptimizeCaps: integer);
     375  procedure OptimizeDevModel(OptimizeCaps: Integer);
    378376  var
    379     f, Cat, OriginalCat, Quality, BestQuality, Best: integer;
     377    F, Cat, OriginalCat, Quality, BestQuality, Best: Integer;
    380378    mi: TModelInfo;
    381379  begin
    382     MakeModelInfo(me, 0, RO.DevModel, mi);
     380    MakeModelInfo(Me, 0, RO.DevModel, mi);
    383381    RateModel(mi, OriginalCat, BestQuality);
    384382    repeat
    385383      Best := -1;
    386       for f := 0 to nFeature - 1 do
    387         if (1 shl f and OptimizeCaps <> 0) and
    388           ((Feature[f].Preq < 0) or IsResearched(Feature[f].Preq)) // check prerequisite
    389           and (RO.DevModel.Weight + Feature[f].Weight <= RO.DevModel.MaxWeight) and
    390           not ((f >= mcFirstNonCap) and (RO.DevModel.Cap[f] > 0)) then
    391         begin
    392           if SetNewModelFeature(f, RO.DevModel.Cap[f] + 1) >= rExecuted then
     384      for F := 0 to nFeature - 1 do
     385        if (1 shl F and OptimizeCaps <> 0) and
     386          ((Feature[F].Preq < 0) or IsResearched(Feature[F].Preq)) // check prerequisite
     387          and (RO.DevModel.Weight + Feature[F].Weight <= RO.DevModel.MaxWeight) and
     388          not ((F >= mcFirstNonCap) and (RO.DevModel.Cap[F] > 0)) then
     389        begin
     390          if SetNewModelFeature(F, RO.DevModel.Cap[F] + 1) >= rExecuted then
    393391          begin
    394             MakeModelInfo(me, 0, RO.DevModel, mi);
     392            MakeModelInfo(Me, 0, RO.DevModel, mi);
    395393            RateModel(mi, Cat, Quality);
    396             assert(Cat = OriginalCat);
     394            Assert(Cat = OriginalCat);
    397395            if Quality > BestQuality then
    398396            begin
    399               Best := f;
     397              Best := F;
    400398              BestQuality := Quality;
    401399            end;
    402             SetNewModelFeature(f, RO.DevModel.Cap[f] - 1);
     400            SetNewModelFeature(F, RO.DevModel.Cap[F] - 1);
    403401          end;
    404402        end;
     
    408406  end;
    409407
    410   function LeaveOutsMissing(ad: integer): boolean;
     408  function LeaveOutsMissing(ad: Integer): Boolean;
    411409  var
    412     i: integer;
     410    I: Integer;
    413411  begin
    414412    Result := False;
     
    424422        Result := True
    425423      else
    426         for i := 0 to 1 do
    427           if AdvPreq[ad, i] >= 0 then
    428             Result := Result or LeaveOutsMissing(AdvPreq[ad, i]);
     424        for I := 0 to 1 do
     425          if AdvPreq[ad, I] >= 0 then
     426            Result := Result or LeaveOutsMissing(AdvPreq[ad, I]);
    429427  end;
    430428
     
    434432    Result := Barbarina_ChooseResearchAdvance;
    435433    if Result >= 0 then
    436       exit;
     434      Exit;
    437435  end;
    438436
     
    446444      Result := ad;
    447445  if Result >= 0 then
    448     exit;
     446    Exit;
    449447
    450448  if Data.BehaviorFlags and bBarbarina = 0 then
     
    462460      OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl
    463461        mcMob + 1 shl mcLongRange + 1 shl mcFanatic);
    464       MakeModelInfo(me, 0, RO.DevModel, mi);
     462      MakeModelInfo(Me, 0, RO.DevModel, mi);
    465463      if IsBetterModel(mi) then
    466464      begin
    467465        Result := adMilitary;
    468         exit;
     466        Exit;
    469467      end;
    470468
     
    473471      SetNewModelFeature(mcOffense, 1);
    474472      OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl mcFanatic);
    475       MakeModelInfo(me, 0, RO.DevModel, mi);
     473      MakeModelInfo(Me, 0, RO.DevModel, mi);
    476474      if IsBetterModel(mi) then
    477475      begin
    478476        Result := adMilitary;
    479         exit;
     477        Exit;
    480478      end;
    481479    end;
     
    493491        SetNewModelFeature(mcWeapons, 0);
    494492        SetNewModelFeature(mcDefense, 3);
    495         exit;
     493        Exit;
    496494      end;
    497495    end;
     
    508506      OptimizeDevModel(1 shl mcDefense+1 shl mcSeaTrans+1 shl mcTurbines
    509507        +1 shl mcAirDef);
    510       MakeModelInfo(me,0,RO.DevModel,mi);
     508      MakeModelInfo(Me,0,RO.DevModel,mi);
    511509      if IsBetterModel(mi) then
    512         begin result:=adMilitary; exit end;
     510        begin Result:=adMilitary; Exit end;
    513511      end;
    514512
     
    521519      OptimizeDevModel(1 shl mcOffense+1 shl mcDefense
    522520        +1 shl mcLongRange+1 shl mcAirDef+1 shl mcRadar);
    523       MakeModelInfo(me,0,RO.DevModel,mi);
     521      MakeModelInfo(Me,0,RO.DevModel,mi);
    524522      if IsBetterModel(mi) then
    525         begin result:=adMilitary; exit end;
     523        begin Result:=adMilitary; Exit end;
    526524      end
    527525    end;
     
    547545        begin
    548546          ok := True;
    549           break;
     547          Break;
    550548        end;
    551549      if not ok then
     
    590588        begin // 2 of 3 required
    591589          Count := 0;
    592           for i := 0 to 2 do
    593             if RO.Tech[AdvPreq[ad, i]] >= tsApplicable then
     590          for I := 0 to 2 do
     591            if RO.Tech[AdvPreq[ad, I]] >= tsApplicable then
    594592              Inc(Count);
    595593          if Count >= 2 then
    596594          begin
    597595            Result := ad;
    598             exit;
     596            Exit;
    599597          end;
    600598        end
     
    604602        begin
    605603          Result := ad;
    606           exit;
     604          Exit;
    607605        end;
    608606      end;
     
    620618    begin // go for future techs
    621619      Result := -1;
    622       i := 0;
     620      I := 0;
    623621      for ad := nAdv - 4 to nAdv - 1 do
    624622        if (RO.Tech[ad] < MaxFutureTech) and (RO.Tech[AdvPreq[ad, 0]] >=
    625623          tsApplicable) then
    626624        begin
    627           Inc(i);
    628           if random(i) = 0 then
     625          Inc(I);
     626          if random(I) = 0 then
    629627            Result := ad;
    630628        end;
    631       assert((Result < 0) or AdvanceResearchable(Result));
    632       exit;
    633     end;
    634 
    635   assert(NewResearch >= 0);
    636   fillchar(Entry, sizeof(Entry), False);
     629      Assert((Result < 0) or AdvanceResearchable(Result));
     630      Exit;
     631    end;
     632
     633  Assert(NewResearch >= 0);
     634  FillChar(Entry, SizeOf(Entry), False);
    637635  MarkEntry(NewResearch);
    638636  Result := -1;
     
    640638    if Entry[ad] and ((Result < 0) or (Advancedness[ad] > Advancedness[Result])) then
    641639      Result := ad;
    642   assert(Result >= 0);
     640  Assert(Result >= 0);
    643641end;
    644642
    645 function TAI.ChooseStealAdvance: integer;
     643function TAI.ChooseStealAdvance: Integer;
    646644var
    647   ad: integer;
     645  ad: Integer;
    648646begin
    649647  Result := -1;
     
    654652end;
    655653
    656 
    657654//-------------------------------
    658655//         TERRAFORMING
     
    662659  twpAllowFarmland = $0001;
    663660
    664 procedure TAI.TileWorkPlan(Loc, cix: integer; var Value, NextJob, TotalWork: integer);
     661procedure TAI.TileWorkPlan(Loc, cix: Integer; var Value, NextJob, TotalWork: Integer);
    665662var
    666   OldTile, TerrType: cardinal;
     663  OldTile, TerrType: Cardinal;
    667664  TileInfo: TTileInfo;
    668665begin
     
    672669  begin
    673670    Value := 3 * 8 - 1;
    674     exit;
     671    Exit;
    675672  end; // better than any tile with 2 food
    676673
     
    693690      Map[Loc] := Map[Loc] and not fTerrain or fGrass;
    694691      TerrType := fGrass;
    695       Map[Loc] := Map[Loc] or cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5);
     692      Map[Loc] := Map[Loc] or Cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5);
    696693    end
    697694    else if IsResearched(adExplosives) and
     
    704701      Map[Loc] := Map[Loc] and not fTerrain or fGrass;
    705702      TerrType := fGrass;
    706       Map[Loc] := Map[Loc] or cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5);
     703      Map[Loc] := Map[Loc] or Cardinal(SpecialTile(Loc, TerrType, G.lx) shl 5);
    707704    end;
    708705    if (Terrain[TerrType].MineEff > 0) and (RO.Government <> gDespotism) then
     
    767764    end;
    768765  end;
    769   Server(sGetTileInfo, me, Loc, TileInfo);
     766  Server(sGetTileInfo, Me, Loc, TileInfo);
    770767  Value := TileInfo.Food * 8 + TileInfo.Prod * 2 + TileInfo.Trade;
    771768  Map[Loc] := OldTile;
     
    775772procedure TAI.ProcessSettlers;
    776773var
    777   i, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade,
     774  I, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade,
    778775  CityFood, Happy, TestScore, BestNearCityScore, BestUnusedValue,
    779   BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: integer;
    780   Tile: cardinal;
    781   FoodOk, Started: boolean;
     776  BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: Integer;
     777  Tile: Cardinal;
     778  FoodOk, Started: Boolean;
    782779  Radius: TVicinity21Loc;
    783780  CityAreaInfo: TCityAreaInfo;
    784   TileFood, ResourceScore, CityScore: array[0..lxmax * lymax - 1] of integer;
    785 
    786   procedure AddJob(Loc, Job, Score: integer);
     781  TileFood, ResourceScore, CityScore: array[0..lxmax * lymax - 1] of Integer;
     782
     783  procedure AddJob(Loc, Job, Score: Integer);
    787784  // set Score=1 for low-priority jobs
    788785  begin
     
    792789  end;
    793790
    794   procedure ReserveCityRadius(Loc: integer);
     791  procedure ReserveCityRadius(Loc: Integer);
    795792  var
    796     V21, RadiusLoc: integer;
     793    V21, RadiusLoc: Integer;
    797794    Radius: TVicinity21Loc;
    798795  begin
     
    811808  procedure ScoreRoadConnections;
    812809  var
    813     V8, nFragments, Loc, Loc1, History, RoadScore, a, b, FullyDeveloped,
    814     ConnectMask: integer;
    815     BridgeOk: boolean;
     810    V8, nFragments, Loc, Loc1, History, RoadScore, A, B, FullyDeveloped,
     811    ConnectMask: Integer;
     812    BridgeOk: Boolean;
    816813    Adjacent: TVicinity8Loc;
    817814  begin
     
    824821      if ((1 shl (Map[Loc] and fTerrain)) and (1 shl fOcean or 1 shl
    825822        fShore or 1 shl fDesert or 1 shl fArctic or 1 shl fUNKNOWN) = 0) and
    826         (RO.Territory[Loc] = me) and (Map[Loc] and FullyDeveloped = 0) and
     823        (RO.Territory[Loc] = Me) and (Map[Loc] and FullyDeveloped = 0) and
    827824        (BridgeOk or (Map[Loc] and fRiver = 0)) then
    828825      begin
     
    838835          Loc1 := Adjacent[V8 and 7];
    839836          History := History shl 1;
    840           if (Loc1 >= 0) and (RO.Territory[Loc1] = me) and
     837          if (Loc1 >= 0) and (RO.Territory[Loc1] = Me) and
    841838            (Map[Loc1] and ConnectMask <> 0) then
    842839          begin
     
    854851                  else if History and 4 <> 0 then
    855852                  begin
    856                     V8_to_ab((V8 - 1) and 7, a, b);
    857                     ab_to_Loc(Loc, a shl 1, b shl 1, Loc1);
     853                    V8_to_ab((V8 - 1) and 7, A, B);
     854                    ab_to_Loc(Loc, A shl 1, B shl 1, Loc1);
    858855                    if (Loc1 >= 0) and (Map[Loc1] and ConnectMask <> 0) then
    859856                      Dec(nFragments);
     
    879876
    880877begin
    881   fillchar(SettlerSurplus, sizeof(SettlerSurplus), 0);
     878  FillChar(SettlerSurplus, SizeOf(SettlerSurplus), 0);
    882879  JobAssignment_Initialize;
    883880
    884881  if (Data.BehaviorFlags and bBarbarina = 0) or (RO.nCity < 3) then
    885882  begin
    886     fillchar(TileFood, sizeof(TileFood), 0);
    887     fillchar(ResourceScore, sizeof(ResourceScore), 0);
     883    FillChar(TileFood, SizeOf(TileFood), 0);
     884    FillChar(ResourceScore, SizeOf(ResourceScore), 0);
    888885    for Loc := 0 to MapSize - 1 do
    889886      if Map[Loc] and fTerrain <> fUNKNOWN then
     
    926923
    927924    // rate possible new cities
    928     fillchar(CityScore, MapSize * sizeof(integer), 0);
     925    FillChar(CityScore, MapSize * SizeOf(Integer), 0);
    929926    for Loc := 0 to MapSize - 1 do
    930927    begin
     
    933930        ((RO.Government <> gDespotism) or (Map[Loc] and fSpecial = fSpecial1)) or
    934931        (Map[Loc] and (fTerrain or fSpecial) = fPrairie or fSpecial1));
    935       if FoodOk and ((RO.Territory[Loc] < 0) or (RO.Territory[Loc] = me)) then
     932      if FoodOk and ((RO.Territory[Loc] < 0) or (RO.Territory[Loc] = Me)) then
    936933      begin
    937934        TestScore := 0;
     
    953950        if CityFood >= MinCityFood then // city is worth founding
    954951        begin
    955           TestScore := (72 + 2 * TestScore) shl 8 + ((loc xor me) * 4567) mod 251;
     952          TestScore := (72 + 2 * TestScore) shl 8 + ((loc xor Me) * 4567) mod 251;
    956953          // some unexactness, random but always the same for this tile
    957954          if TestScore > BestNearCityScore then
     
    991988              if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then
    992989              begin
    993                 assert(RadiusLoc >= 0);
     990                Assert(RadiusLoc >= 0);
    994991                TileWorkPlan(RadiusLoc, cix, Value, NextJob, TotalWork);
    995992                if (NextJob = jRoad) and (Built[imPalace] +
     
    10031000            begin // tile could be exploited
    10041001              RadiusLoc := Radius[V21];
    1005               assert(RadiusLoc >= 0);
     1002              Assert(RadiusLoc >= 0);
    10061003              if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then
    10071004              begin
     
    10271024  if Data.BehaviorFlags and bBarbarina = 0 then // low priority jobs
    10281025    for Loc := 0 to MapSize - 1 do
    1029       if RO.Territory[Loc] = me then
     1026      if RO.Territory[Loc] = Me then
    10301027      begin
    10311028        Tile := Map[Loc];
     
    10511048  begin
    10521049    for part := 0 to nShipPart - 1 do
    1053       for i := 0 to ColonyShipPlan[part].nLocFoundCity - 1 do
    1054       begin
    1055         Loc := ColonyShipPlan[part].LocFoundCity[i];
     1050      for I := 0 to ColonyShipPlan[part].nLocFoundCity - 1 do
     1051      begin
     1052        Loc := ColonyShipPlan[part].LocFoundCity[I];
    10561053        Started := False;
    10571054        for uix := 0 to RO.nUn - 1 do
     
    10591056          begin
    10601057            Started := True;
    1061             break;
     1058            Break;
    10621059          end;
    10631060        if not Started then
     
    11221119            begin // settlers could be added to this city
    11231120              Happy := BasicHappy;
    1124               for i := 0 to nWonder - 1 do
    1125                 if Built[i] > 0 then
     1121              for I := 0 to nWonder - 1 do
     1122                if Built[I] > 0 then
    11261123                  Inc(Happy);
    11271124              if Built[imTemple] > 0 then
     
    11301127              begin
    11311128                Inc(Happy, 2);
    1132                 if RO.Wonder[woBach].EffectiveOwner = me then
     1129                if RO.Wonder[woBach].EffectiveOwner = Me then
    11331130                  Inc(Happy, 1);
    11341131              end;
     
    11451142        end;
    11461143      end;
    1147 end; // ProcessSettlers
    1148 
     1144end;
    11491145
    11501146//-------------------------------
     
    11541150procedure TAI.DoTurn;
    11551151var
    1156   emix, i, p1, TaxSum, ScienceSum, NewTaxRate: integer;
    1157   AllHateMe: boolean;
     1152  emix, I, p1, TaxSum, ScienceSum, NewTaxRate: Integer;
     1153  AllHateMe: Boolean;
    11581154{$IFDEF PERF}
    11591155  PF, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9: int64;
     
    11611157begin
    11621158{$IFDEF DEBUG}
    1163   fillchar(DebugMap, sizeof(DebugMap), 0);
     1159  FillChar(DebugMap, SizeOf(DebugMap), 0);
    11641160{$ENDIF}
    11651161
     
    11731169  WarNations := PresenceUnknown;
    11741170  for p1 := 0 to nPl - 1 do
    1175     if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] < trPeace) then
     1171    if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] < trPeace) then
    11761172      Inc(WarNations, 1 shl p1);
    11771173  BombardingNations := 0;
     
    11891185    CheckGender;
    11901186
    1191   if G.Difficulty[me] < MaxDiff then // not on beginner level
     1187  if G.Difficulty[Me] < MaxDiff then // not on beginner level
    11921188  begin
    11931189    if (Data.LastResearchTech = adHorsebackRiding) and (RO.ResearchTech < 0) and
    11941190      (random(6) = 0) and (HavePort or (ContinentPresence[0] and not
    1195       (1 shl me or PresenceUnknown) <> 0)) then
     1191      (1 shl Me or PresenceUnknown) <> 0)) then
    11961192    begin
    11971193      Data.BehaviorFlags := Data.BehaviorFlags or bBarbarina_Hide;
     
    12101206          begin
    12111207            AllHateMe := False;
    1212             break;
     1208            Break;
    12131209          end;
    12141210      if AllHateMe then
     
    13061302  else
    13071303  begin
    1308     if (RO.TaxRate = 0) or (RO.Money < (TotalPopulation[me] - 4) * 2) then
     1304    if (RO.TaxRate = 0) or (RO.Money < (TotalPopulation[Me] - 4) * 2) then
    13091305      NewTaxRate := RO.TaxRate // don't check decreasing tax
    13101306    else
     
    13131309    begin
    13141310      SumCities(NewTaxRate, TaxSum, ScienceSum);
    1315       if RO.Money + TaxSum >= (TotalPopulation[me] - 4) then
    1316         break; // enough
     1311      if RO.Money + TaxSum >= (TotalPopulation[Me] - 4) then
     1312        Break; // enough
    13171313      Inc(NewTaxRate, 10);
    13181314    end;
     
    13281324    // research completed
    13291325    for p1 := 0 to nPl - 1 do
    1330       if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and
     1326      if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and
    13311327        (RO.EnemyReport[p1].TurnOfCivilReport + TechReportOutdated > RO.Turn) and
    13321328        (RO.EnemyReport[p1].Tech[Data.LastResearchTech] < tsSeen) then
    13331329      begin // latest researched advance might be of interest to this nation
    1334         for i := 0 to nRequestedTechs - 1 do
    1335           if (Data.RequestedTechs[i] >= 0) and
    1336             (Data.RequestedTechs[i] shr 8 and $F = p1) then
    1337             Data.RequestedTechs[i] := -1;
     1330        for I := 0 to nRequestedTechs - 1 do
     1331          if (Data.RequestedTechs[I] >= 0) and
     1332            (Data.RequestedTechs[I] shr 8 and $F = p1) then
     1333            Data.RequestedTechs[I] := -1;
    13381334      end;
    13391335  if RO.ResearchTech = adMilitary then
     
    13411337  else
    13421338    Data.LastResearchTech := RO.ResearchTech;
    1343   for i := 0 to nRequestedTechs - 1 do
    1344     if (Data.RequestedTechs[i] >= 0) and
    1345       (RO.Tech[Data.RequestedTechs[i] and $FF] >= tsSeen) then
    1346       Data.RequestedTechs[i] := -1;
     1339  for I := 0 to nRequestedTechs - 1 do
     1340    if (Data.RequestedTechs[I] >= 0) and
     1341      (RO.Tech[Data.RequestedTechs[I] and $FF] >= tsSeen) then
     1342      Data.RequestedTechs[I] := -1;
    13471343
    13481344  // prepare negotiation
     
    13501346  SetAdvanceValues;
    13511347
    1352 
    13531348{$IFDEF DEBUG}
    13541349(*for p1:=0 to nPl-1 do
    1355   if (p1<>me) and (1 shl p1 and RO.Alive<>0) and (RO.Treaty[p1]>=trPeace)
     1350  if (p1<>Me) and (1 shl p1 and RO.Alive<>0) and (RO.Treaty[p1]>=trPeace)
    13561351    and (RO.EnemyReport[p1].TurnOfCivilReport>=0) then
    13571352    TraceAdvanceValues(p1);*)
     
    13681363
    13691364{$IFDEF DEBUG}
    1370 procedure TAI.TraceAdvanceValues(Nation: integer);
     1365procedure TAI.TraceAdvanceValues(Nation: Integer);
    13711366var
    1372   ad: integer;
     1367  ad: Integer;
    13731368begin
    13741369  for ad := 0 to nAdv - 1 do
     
    13801375    end;
    13811376end;
    1382 
    13831377{$ENDIF}
    1384 
    13851378
    13861379procedure TAI.CheckGender;
    13871380var
    1388   p1, NewGender: integer;
     1381  p1, NewGender: Integer;
    13891382begin
    13901383  NewGender := -1;
    13911384  for p1 := 0 to nPl - 1 do
    1392     if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and
     1385    if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and
    13931386      (RO.Treaty[p1] >= trFriendlyContact) then
    1394       if PlayerHash[me] > PlayerHash[p1] then
     1387      if PlayerHash[Me] > PlayerHash[p1] then
    13951388      begin
    13961389        if NewGender = bMale then
    13971390        begin
    13981391          NewGender := -2;
    1399           break;
     1392          Break;
    14001393        end; // ambiguous, don't change gender
    14011394        NewGender := bFemale;
     
    14061399        begin
    14071400          NewGender := -2;
    1408           break;
     1401          Break;
    14091402        end; // ambiguous, don't change gender
    14101403        NewGender := bMale;
     
    14171410end;
    14181411
    1419 
    14201412procedure TAI.SetAdvanceValues;
    14211413
    1422   procedure RateResearchAdv(ad, Time: integer);
     1414  procedure RateResearchAdv(ad, Time: Integer);
    14231415  var
    1424     Value: integer;
     1416    Value: Integer;
    14251417  begin
    14261418    if Time = 0 then
     
    14321424  end;
    14331425
    1434   procedure SetPreqValues(ad, Value: integer);
     1426  procedure SetPreqValues(ad, Value: Integer);
    14351427  begin
    14361428    if (RO.Tech[ad] < tsSeen) and (ad <> RO.ResearchTech) then
     
    14551447  end;
    14561448
    1457   procedure RateImpPreq(iix, Value: integer);
     1449  procedure RateImpPreq(iix, Value: Integer);
    14581450  begin
    14591451    if (Value > 0) and (Imp[iix].Preq >= 0) then
     
    14621454
    14631455var
    1464   emix, cix, adMissing, iad, ad, Count, i, Time, d, CurrentCost,
    1465   CurrentStrength, MaxSize, MaxTrade: integer;
    1466   PreView, Emergency, Bombarded: boolean;
     1456  emix, cix, adMissing, iad, ad, Count, I, Time, D, CurrentCost,
     1457  CurrentStrength, MaxSize, MaxTrade: Integer;
     1458  PreView, Emergency, Bombarded: Boolean;
    14671459begin
    14681460  if AdvanceValuesSet then
    1469     exit;
     1461    Exit;
    14701462  AdvanceValuesSet := True;
    14711463
    1472   fillchar(AdvanceValue, sizeof(AdvanceValue), 0);
     1464  FillChar(AdvanceValue, SizeOf(AdvanceValue), 0);
    14731465
    14741466  // rate techs to ensure research progress
     
    14901482      begin // 2 of 3 required
    14911483        Count := 0;
    1492         for i := 0 to 2 do
    1493           if (AdvPreq[ad, i] = RO.ResearchTech) or
    1494             (RO.Tech[AdvPreq[ad, i]] >= tsSeen) then
     1484        for I := 0 to 2 do
     1485          if (AdvPreq[ad, I] = RO.ResearchTech) or
     1486            (RO.Tech[AdvPreq[ad, I]] >= tsSeen) then
    14951487            Inc(Count);
    14961488        if Count >= 2 then
     
    15001492          if ad <> adMassProduction then // don't score third preq for MP
    15011493          begin
    1502             for i := 0 to 2 do
    1503               if (AdvPreq[ad, i] <> RO.ResearchTech) and
    1504                 (RO.Tech[AdvPreq[ad, i]] < tsSeen) then
    1505                 RateResearchAdv(AdvPreq[ad, i], Time);
     1494            for I := 0 to 2 do
     1495              if (AdvPreq[ad, I] <> RO.ResearchTech) and
     1496                (RO.Tech[AdvPreq[ad, I]] < tsSeen) then
     1497                RateResearchAdv(AdvPreq[ad, I], Time);
    15061498          end;
    15071499          Inc(Time, 2 - Count);
     
    15111503      begin
    15121504        Count := 0;
    1513         for i := 0 to 1 do
    1514           if (AdvPreq[ad, i] <> preNone) and (AdvPreq[ad, i] <> RO.ResearchTech) and
    1515             (RO.Tech[AdvPreq[ad, i]] < tsSeen) then
     1505        for I := 0 to 1 do
     1506          if (AdvPreq[ad, I] <> preNone) and (AdvPreq[ad, I] <> RO.ResearchTech) and
     1507            (RO.Tech[AdvPreq[ad, I]] < tsSeen) then
    15161508          begin
    1517             RateResearchAdv(AdvPreq[ad, i], Time);
     1509            RateResearchAdv(AdvPreq[ad, I], Time);
    15181510            Inc(Count);
    15191511          end;
     
    15441536
    15451537  // rate military techs
    1546   for d := 0 to nDomains - 1 do
     1538  for D := 0 to nDomains - 1 do
    15471539  begin
    15481540    CurrentCost := 0;
    15491541    CurrentStrength := 0;
    15501542    for PreView := True downto False do
    1551       for i := 0 to nUpgrade - 1 do
    1552         with Upgrade[d, i] do
     1543      for I := 0 to nUpgrade - 1 do
     1544        with Upgrade[D, I] do
    15531545          if (Preq >= 0) and not (Preq in FutureTech) then
    15541546            if ((Ro.ResearchTech = Preq) or (RO.Tech[Preq] >= tsSeen)) = PreView then
     
    15611553              else
    15621554              begin // rate
    1563                 if (i > 0) and (Trans > 0) then
     1555                if (I > 0) and (Trans > 0) then
    15641556                  Inc(AdvanceValue[Preq], $400);
    15651557                if Cost <= CurrentCost then
    1566                   Inc(AdvanceValue[Preq], (4 - d) * Strength * $400 div
    1567                     (CurrentStrength + Upgrade[d, 0].Strength))
     1558                  Inc(AdvanceValue[Preq], (4 - D) * Strength * $400 div
     1559                    (CurrentStrength + Upgrade[D, 0].Strength))
    15681560                else
    1569                   Inc(AdvanceValue[Preq], (4 - d) * Strength * $200 div
    1570                     (CurrentStrength + Upgrade[d, 0].Strength));
     1561                  Inc(AdvanceValue[Preq], (4 - D) * Strength * $200 div
     1562                    (CurrentStrength + Upgrade[D, 0].Strength));
    15711563              end;
    15721564  end;
     
    16481640procedure TAI.AnalyzeMap;
    16491641var
    1650   cix, Loc, Loc1, V8, f1, p1: integer;
     1642  cix, Loc, Loc1, V8, f1, p1: Integer;
    16511643  Adjacent: TVicinity8Loc;
    16521644begin
     
    16541646
    16551647  // collect nation presence information for continents and oceans
    1656   fillchar(ContinentPresence, sizeof(ContinentPresence), 0);
    1657   fillchar(OceanPresence, sizeof(OceanPresence), 0);
     1648  FillChar(ContinentPresence, SizeOf(ContinentPresence), 0);
     1649  FillChar(OceanPresence, SizeOf(OceanPresence), 0);
    16581650  for Loc := 0 to MapSize - 1 do
    16591651  begin
     
    17071699  end;
    17081700
    1709   fillchar(TotalPopulation, sizeof(TotalPopulation), 0);
    1710   fillchar(ContinentPopulation, sizeof(ContinentPopulation), 0);
    1711   fillchar(DistrictPopulation, 4 * nDistrict, 0);
     1701  FillChar(TotalPopulation, SizeOf(TotalPopulation), 0);
     1702  FillChar(ContinentPopulation, SizeOf(ContinentPopulation), 0);
     1703  FillChar(DistrictPopulation, 4 * nDistrict, 0);
    17121704
    17131705  // count population
     
    17241716      if Loc >= 0 then
    17251717      begin
    1726         Inc(TotalPopulation[me], Size);
    1727         assert(District[Loc] >= 0);
     1718        Inc(TotalPopulation[Me], Size);
     1719        Assert(District[Loc] >= 0);
    17281720        if District[Loc] < maxCOD then
    17291721          Inc(DistrictPopulation[District[Loc]], Size);
     
    17331725procedure TAI.CollectModelCatStat;
    17341726var
    1735   i, uix, Cat, mix, Quality: integer;
     1727  I, uix, Cat, mix, Quality: Integer;
    17361728begin
    17371729  // categorize models
     
    17791771        if (Loc >= 0) and (mix = mixCruiser) and (Map[Loc] and fTerrain < fGrass) then
    17801772        begin
    1781           i := Formation[Loc];
    1782           if (i >= 0) and (i < maxCOD) then
    1783             OceanWithShip := OceanWithShip or (1 shl i);
     1773          I := Formation[Loc];
     1774          if (I >= 0) and (I < maxCOD) then
     1775            OceanWithShip := OceanWithShip or (1 shl I);
    17841776        end;
    17851777end;
    1786 
    17871778
    17881779procedure TAI.MoveUnitsHome;
    17891780const
    17901781  PatrolDestination = lxmax * lymax;
    1791   FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of integer = (2, 1);
     1782  FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of Integer = (2, 1);
    17921783var
    1793   Cat, i, mix, cix, uix, Loop, nModelOrder: integer;
     1784  Cat, I, mix, cix, uix, Loop, nModelOrder: Integer;
    17941785  Adjacent: TVicinity8Loc;
    1795   LocNeed: array[0..lxmax * lymax - 1] of shortint;
    1796   Destination: array[0..nUmax - 1] of integer;
    1797   DistrictNeed, DistrictNeed0: array[0..maxCOD - 1] of integer;
    1798   ModelOrder: array[0..nMmax - 1] of integer;
    1799   complete, Fortified: boolean;
    1800 
    1801   function IsBombarded(cix: integer): boolean;
     1786  LocNeed: array[0..lxmax * lymax - 1] of ShortInt;
     1787  Destination: array[0..nUmax - 1] of Integer;
     1788  DistrictNeed, DistrictNeed0: array[0..maxCOD - 1] of Integer;
     1789  ModelOrder: array[0..nMmax - 1] of Integer;
     1790  complete, Fortified: Boolean;
     1791
     1792  function IsBombarded(cix: Integer): Boolean;
    18021793  var
    1803     Loc1, V8: integer;
     1794    Loc1, V8: Integer;
    18041795    Adjacent: TVicinity8Loc;
    18051796  begin
     
    18181809          begin
    18191810            Result := True;
    1820             exit;
     1811            Exit;
    18211812          end;
    18221813        end;
     
    18241815  end;
    18251816
    1826   procedure TryUtilize(uix: integer);
     1817  procedure TryUtilize(uix: Integer);
    18271818  var
    1828     cix, ProdCost, UtilizeCost: integer;
     1819    cix, ProdCost, UtilizeCost: Integer;
    18291820  begin
    18301821    if (MyUnit[uix].Health = 100) and (Map[MyUnit[uix].Loc] and
     
    18381829          UtilizeCost := MyModel[MyUnit[uix].mix].Cost;
    18391830          if Prod < (ProdCost - UtilizeCost * 2 div 3) *
    1840             BuildCostMod[G.Difficulty[me]] div 12 then
     1831            BuildCostMod[G.Difficulty[Me]] div 12 then
    18411832            Unit_Disband(uix);
    18421833        end;
     
    18441835  end;
    18451836
    1846   procedure FindDestination(uix: integer);
     1837  procedure FindDestination(uix: Integer);
    18471838  var
    1848     MoveStyle, V8, Loc1, Time, NextLoc, NextTime, RecoverTurns: integer;
    1849     Reached: array[0..lxmax * lymax - 1] of boolean;
    1850   begin
    1851     fillchar(Reached, MapSize, False);
     1839    MoveStyle, V8, Loc1, Time, NextLoc, NextTime, RecoverTurns: Integer;
     1840    Reached: array[0..lxmax * lymax - 1] of Boolean;
     1841  begin
     1842    FillChar(Reached, MapSize, False);
    18521843    Pile.Create(MapSize);
    18531844    with MyUnit[uix] do
     
    18631854        if (District[Loc1] >= 0) and (District[Loc1] < maxCOD) then
    18641855        begin
    1865           assert(DistrictNeed[District[Loc1]] > 0);
     1856          Assert(DistrictNeed[District[Loc1]] > 0);
    18661857          Dec(DistrictNeed[District[Loc1]]);
    18671858        end;
    18681859        Destination[uix] := Loc1;
    1869         break;
     1860        Break;
    18701861      end;
    18711862      Reached[Loc1] := True;
     
    18741865      begin
    18751866        NextLoc := Adjacent[V8];
    1876         if (NextLoc >= 0) and not Reached[NextLoc] and (RO.Territory[NextLoc] = me) then
     1867        if (NextLoc >= 0) and not Reached[NextLoc] and (RO.Territory[NextLoc] = Me) then
    18771868          case CheckStep(MoveStyle, Time, V8 and 1, NextTime, RecoverTurns,
    18781869              Map[Loc1], Map[NextLoc], False) of
     
    18821873              Reached[NextLoc] := True; // don't check moving there again
    18831874            csCheckTerritory:
    1884               assert(False);
     1875              Assert(False);
    18851876          end;
    18861877      end;
     
    18961887          Unit_Disband(uix);
    18971888
    1898   fillchar(UnitLack, sizeof(UnitLack), 0);
    1899   fillchar(Destination, 4 * RO.nUn, $FF);
    1900   for i := 0 to maxCOD - 1 do
    1901     if uixPatrol[i] >= 0 then
    1902       Destination[uixPatrol[i]] := PatrolDestination;
     1889  FillChar(UnitLack, SizeOf(UnitLack), 0);
     1890  FillChar(Destination, 4 * RO.nUn, $FF);
     1891  for I := 0 to maxCOD - 1 do
     1892    if uixPatrol[I] >= 0 then
     1893      Destination[uixPatrol[I]] := PatrolDestination;
    19031894  for uix := 0 to RO.nUn - 1 do
    19041895    if (MyUnit[uix].mix = mixMilitia) or (MyUnit[uix].mix = mixCruiser) then
     
    19121903      if ModelCat[mix] = Cat then
    19131904      begin
    1914         i := nModelOrder;
    1915         while (i > 0) and (ModelQuality[mix] < ModelQuality[ModelOrder[i - 1]]) do
    1916         begin
    1917           ModelOrder[i] := ModelOrder[i - 1];
    1918           Dec(i);
    1919         end;
    1920         ModelOrder[i] := mix;
     1905        I := nModelOrder;
     1906        while (I > 0) and (ModelQuality[mix] < ModelQuality[ModelOrder[I - 1]]) do
     1907        begin
     1908          ModelOrder[I] := ModelOrder[I - 1];
     1909          Dec(I);
     1910        end;
     1911        ModelOrder[I] := mix;
    19211912        Inc(nModelOrder);
    19221913      end;
     
    19311922              TryUtilize(uix);
    19321923
    1933       fillchar(LocNeed, MapSize, 0);
    1934       fillchar(DistrictNeed, sizeof(DistrictNeed), 0);
     1924      FillChar(LocNeed, MapSize, 0);
     1925      FillChar(DistrictNeed, SizeOf(DistrictNeed), 0);
    19351926
    19361927      for cix := 0 to RO.nCity - 1 do
     
    19551946        for uix := 0 to RO.nUn - 1 do
    19561947          with MyUnit[uix] do
    1957             if (Loc >= 0) and (Job = jCity) and (RO.Territory[Loc] = me) then
     1948            if (Loc >= 0) and (Job = jCity) and (RO.Territory[Loc] = Me) then
    19581949            begin
    19591950              LocNeed[Loc] := 1;
     
    19631954
    19641955      complete := Loop >= FirstSurplusLoop[Cat];
    1965       for i := nModelOrder - 1 downto 0 do
     1956      for I := nModelOrder - 1 downto 0 do
    19661957      begin
    19671958        for Fortified := True downto False do
    19681959          for uix := 0 to RO.nUn - 1 do
    19691960            with MyUnit[uix] do
    1970               if (mix = ModelOrder[i]) and (Loc >= 0) and
     1961              if (mix = ModelOrder[I]) and (Loc >= 0) and
    19711962                (Destination[uix] < 0) and (Master < 0) and
    19721963                ((Flags and unFortified <> 0) = Fortified) and (LocNeed[Loc] > 0) then
     
    19811972        for uix := 0 to RO.nUn - 1 do
    19821973          with MyUnit[uix] do
    1983             if (mix = ModelOrder[i]) and (Loc >= 0) and (Destination[uix] < 0) and
     1974            if (mix = ModelOrder[I]) and (Loc >= 0) and (Destination[uix] < 0) and
    19841975              (Master < 0) then
    19851976              if (District[Loc] >= 0) and (District[Loc] < maxCOD) and
     
    19981989  // distribute obsolete settlers
    19991990  repeat
    2000     fillchar(LocNeed, MapSize, 0);
    2001     fillchar(DistrictNeed, sizeof(DistrictNeed), 0);
     1991    FillChar(LocNeed, MapSize, 0);
     1992    FillChar(DistrictNeed, SizeOf(DistrictNeed), 0);
    20021993
    20031994    for cix := 0 to RO.nCity - 1 do
     
    20492040  for uix := 0 to RO.nUn - 1 do
    20502041    with MyUnit[uix] do
    2051       if (Loc >= 0) and (RO.Territory[Loc] = me) and (District[Loc] >= 0) and
     2042      if (Loc >= 0) and (RO.Territory[Loc] = Me) and (District[Loc] >= 0) and
    20522043        (District[Loc] < maxCOD) and (ModelQuality[mix] > 0) then
    20532044        case ModelCat[mix] of
     
    20552046            Dec(UnitLack[District[Loc], ModelCat[mix]])
    20562047        end;
    2057 end; // MoveUnitsHome
    2058 
    2059 
    2060 procedure TAI.CheckAttack(uix: integer);
     2048end;
     2049
     2050procedure TAI.CheckAttack(uix: Integer);
    20612051var
    20622052  AttackScore, BestCount, AttackLoc, TestLoc, NextLoc, TestTime, V8,
    20632053  TestScore, euix, MyDamage, EnemyDamage, OldLoc, AttackForecast,
    2064   MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: integer;
    2065   Tile: cardinal;
    2066   Exhausted: boolean;
     2054  MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: Integer;
     2055  Tile: Cardinal;
     2056  Exhausted: Boolean;
    20672057  Adjacent: TVicinity8Loc;
    2068   Reached: array[0..lxmax * lymax - 1] of boolean;
     2058  Reached: array[0..lxmax * lymax - 1] of Boolean;
    20692059
    20702060begin
     
    20752065      AttackScore := -999999;
    20762066      AttackLoc := -1;
    2077       fillchar(Reached, MapSize, False);
     2067      FillChar(Reached, MapSize, False);
    20782068      Pile.Create(MapSize);
    20792069      Pile.Put(Loc, $800 - Movement);
     
    20872077        if ((Tile and fUnit) <> 0) and ((Tile and fOwned) = 0) then
    20882078        begin // enemy unit
    2089           assert(TestTime < $1000);
     2079          Assert(TestTime < $1000);
    20902080          Unit_FindEnemyDefender(TestLoc, euix);
    20912081          if RO.Treaty[RO.EnemyUn[euix].Owner] < trPeace then
     
    21762166    until Exhausted;
    21772167  end;
    2178 end; // CheckAttack
    2179 
    2180 
    2181 procedure TAI.Patrol(uix: integer);
     2168end;
     2169
     2170procedure TAI.Patrol(uix: Integer);
    21822171const
    21832172  DistanceScore = 4;
    21842173var
    21852174  PatrolScore, BestCount, PatrolLoc, TestLoc, NextLoc, TestTime, V8,
    2186   TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: integer;
    2187   Tile: cardinal;
    2188   Exhausted, CaptureOnly: boolean;
     2175  TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: Integer;
     2176  Tile: Cardinal;
     2177  Exhausted, CaptureOnly: Boolean;
    21892178  Adjacent: TVicinity8Loc;
    2190   AdjacentUnknown: array[0..lxmax * lymax - 1] of shortint;
     2179  AdjacentUnknown: array[0..lxmax * lymax - 1] of ShortInt;
    21912180
    21922181begin
     
    22072196          // assume a score of 50 is the best achievable
    22082197          or CaptureOnly and (TestTime >= $1000) then
    2209           break;
     2198          Break;
    22102199
    22112200        TestScore := 0;
     
    22822271    until Exhausted;
    22832272  end;
    2284 end; // Patrol
     2273end;
    22852274
    22862275procedure TAI.AttackAndPatrol;
    22872276const
    22882277  nAttackCatOrder = 3;
    2289   AttackCatOrder: array[0..nAttackCatOrder - 1] of integer =
     2278  AttackCatOrder: array[0..nAttackCatOrder - 1] of Integer =
    22902279    (mctGroundAttacker, mctCruiser, mctGroundDefender);
    22912280var
    2292   iCat, uix, uix1: integer;
    2293   IsPatrolUnit, Fortified: boolean;
     2281  iCat, uix, uix1: Integer;
     2282  IsPatrolUnit, Fortified: Boolean;
    22942283begin
    22952284  for uix := 0 to RO.nUn - 1 do
     
    23102299              CheckAttack(uix);
    23112300
    2312   fillchar(uixPatrol, sizeof(uixPatrol), $FF);
     2301  FillChar(uixPatrol, SizeOf(uixPatrol), $FF);
    23132302  for uix := 0 to RO.nUn - 1 do
    23142303    with MyUnit[uix], MyModel[mix] do
     
    23422331          Patrol(uix);
    23432332      end;
    2344 end; // AttackAndPatrol
    2345 
    2346 
    2347 function TAI.HavePort: boolean;
     2333end;
     2334
     2335function TAI.HavePort: Boolean;
    23482336var
    2349   V8, cix, AdjacentLoc, f: integer;
     2337  V8, cix, AdjacentLoc, F: Integer;
    23502338  Adjacent: TVicinity8Loc;
    23512339begin
     
    23612349          if (AdjacentLoc >= 0) and ((Map[AdjacentLoc] and fTerrain) < fGrass) then
    23622350          begin
    2363             f := Formation[AdjacentLoc];
    2364             if (f >= 0) and (f < maxCOD) and (OceanPresence[f] and
    2365               not (1 shl me) <> 0) then
     2351            F := Formation[AdjacentLoc];
     2352            if (F >= 0) and (F < maxCOD) and (OceanPresence[F] and
     2353              not (1 shl Me) <> 0) then
    23662354              Result := True;
    23672355          end;
     
    23692357      end;
    23702358end;
    2371 
    23722359
    23732360procedure TAI.SetCityProduction;
    23742361var
    23752362  uix, cix, iix, dtr, V8, V21, NewImprovement, AdjacentLoc, MaxSettlers,
    2376   maxcount, cixMilAcademy: integer;
    2377   TerrType: cardinal;
     2363  maxcount, cixMilAcademy: Integer;
     2364  TerrType: Cardinal;
    23782365  IsPort, IsNavalBase, NeedCruiser, CheckProd, Destructed, ProduceSettlers,
    2379   ProduceMil: boolean;
     2366  ProduceMil: Boolean;
    23802367  Adjacent: TVicinity8Loc;
    23812368  Radius: TVicinity21Loc;
    23822369  Report: TCityReport;
    2383   HomeCount, CityProdRep: array[0..nCmax - 1] of integer;
    2384   MilProdCity: array[0..nCmax - 1] of boolean;
    2385 
    2386   procedure TryBuild(Improvement: integer);
     2370  HomeCount, CityProdRep: array[0..nCmax - 1] of Integer;
     2371  MilProdCity: array[0..nCmax - 1] of Boolean;
     2372
     2373  procedure TryBuild(Improvement: Integer);
    23872374  begin
    23882375    if (NewImprovement = imTrGoods) // not already improvement of higher priority found
     
    23942381  end;
    23952382
    2396   procedure TryDestruct(Improvement: integer);
     2383  procedure TryDestruct(Improvement: Integer);
    23972384  begin
    23982385    if Destructed or (MyCity[cix].Built[Improvement] = 0) then
    2399       exit;
     2386      Exit;
    24002387    if City_CurrentImprovementProject(cix) >= 0 then
    24012388      City_RebuildImprovement(cix, Improvement)
     
    24052392      and (Imp[CurrentImprovementProject].Kind in [ikCommon,ikNatGlobal,ikNatLocal])
    24062393      and ((Imp[CurrentImprovementProject].Cost*3-Imp[Improvement].Cost*2)
    2407       *BuildCostMod[G.Difficulty[me]]>MyCity[cix].Prod*(12*3)) then}
     2394      *BuildCostMod[G.Difficulty[Me]]>MyCity[cix].Prod*(12*3)) then}
    24082395    Destructed := True;
    24092396  end;
    24102397
    2411   function ChooseBuildModel(Cat: integer): integer;
     2398  function ChooseBuildModel(Cat: Integer): Integer;
    24122399  var
    2413     Count, mix: integer;
     2400    Count, mix: Integer;
    24142401  begin
    24152402    Count := 0;
     
    24222409          Result := mix;
    24232410      end;
    2424     assert(Count > 0);
     2411    Assert(Count > 0);
    24252412  end;
    24262413
     
    24282415  // find military production cities
    24292416  var
    2430     cix, Total, d, Threshold, NewThreshold, Share, SharePlus, cixWorst: integer;
    2431   begin
    2432     fillchar(MilProdCity, RO.nCity, 0);
     2417    cix, Total, D, Threshold, NewThreshold, Share, SharePlus, cixWorst: Integer;
     2418  begin
     2419    FillChar(MilProdCity, RO.nCity, 0);
    24332420    GetCityProdPotential;
    2434     for d := 0 to maxCOD - 1 do
     2421    for D := 0 to maxCOD - 1 do
    24352422    begin
    24362423      Total := 0;
    24372424      for cix := 0 to RO.nCity - 1 do
    24382425        with MyCity[cix] do
    2439           if (Loc >= 0) and (District[Loc] = d) then
     2426          if (Loc >= 0) and (District[Loc] = D) then
    24402427            Total := Total + CityResult[cix];
    24412428      if Total = 0 then
     
    24462433      for cix := 0 to RO.nCity - 1 do
    24472434        with MyCity[cix] do
    2448           if (Loc >= 0) and (District[Loc] = d) and
     2435          if (Loc >= 0) and (District[Loc] = D) and
    24492436            (Built[imBarracks] + Built[imMilAcademy] > 0) then
    24502437          begin
     
    24612448        for cix := 0 to RO.nCity - 1 do
    24622449          with MyCity[cix] do
    2463             if (Loc >= 0) and (District[Loc] = d) and
     2450            if (Loc >= 0) and (District[Loc] = D) and
    24642451              (Built[imBarracks] + Built[imMilAcademy] = 0) and
    24652452              (Built[imObservatory] = 0) and (CityResult[cix] < Threshold) and
     
    24782465      for cix := 0 to RO.nCity - 1 do
    24792466        with MyCity[cix] do
    2480           if (Loc >= 0) and (District[Loc] = d) and
     2467          if (Loc >= 0) and (District[Loc] = D) and
    24812468            (Built[imBarracks] + Built[imMilAcademy] = 0) and
    24822469            (CityResult[cix] >= Threshold) then
     
    24842471{    if (cixWorst>=0)
    24852472      and (Share-CityResult[cixWorst]*2>=Total*MilProdShare div 100) then
    2486       MilProdCity[cixWorst]:=false;}
     2473      MilProdCity[cixWorst]:=False;}
    24872474    end;
    24882475
     
    24912478    if cixStateImp[imPalace] >= 0 then
    24922479    begin
    2493       d := District[MyCity[cixStateImp[imPalace]].Loc];
    2494       if (d >= 0) and (d < maxCOD) then
     2480      D := District[MyCity[cixStateImp[imPalace]].Loc];
     2481      if (D >= 0) and (D < maxCOD) then
    24952482      begin
    24962483        cixMilAcademy := -1;
    24972484        for cix := 0 to RO.nCity - 1 do
    24982485          with MyCity[cix] do
    2499             if (Loc >= 0) and (District[Loc] = d) and
     2486            if (Loc >= 0) and (District[Loc] = D) and
    25002487              (Built[imObservatory] + Built[imPalace] = 0) and
    25012488              ((cixMilAcademy < 0) or (CityResult[cix] > CityResult[cixMilAcademy])) then
     
    25132500  procedure ChangeHomeCities;
    25142501  var
    2515     uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: integer;
     2502    uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: Integer;
    25162503  begin
    25172504    if RO.Government in [gAnarchy, gFundamentalism] then
    2518       exit;
     2505      Exit;
    25192506    for uix := 0 to RO.nUn - 1 do
    25202507      with MyUnit[uix] do
     
    25642551
    25652552begin
    2566   fillchar(HomeCount, 4 * RO.nCity, 0);
     2553  FillChar(HomeCount, 4 * RO.nCity, 0);
    25672554  for uix := 0 to RO.nUn - 1 do
    25682555    with MyUnit[uix] do
     
    27572744                    begin
    27582745                      TryBuild(imHarbor);
    2759                       break;
     2746                      Break;
    27602747                    end;
    27612748                  end;
     
    27752762              TryBuild(imRecycling);
    27762763            if (Report.Trade - Report.Corruption >= 11) and
    2777               (RO.Money < TotalPopulation[me] * 2) then
     2764              (RO.Money < TotalPopulation[Me] * 2) then
    27782765              TryBuild(imBank);
    27792766            if (RO.NatBuilt[imStockEx] = 0) and
     
    28122799
    28132800          // rebuild imps no longer needed
    2814           if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[me] * 4) then
     2801          if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[Me] * 4) then
    28152802            TryDestruct(imBank)
    28162803          else if Report.Happy * 2 >= Size + 6 then
     
    28362823
    28372824  ChangeHomeCities;
    2838 end; // SetCityProduction
    2839 
    2840 
    2841 function TAI.ChooseGovernment: integer;
     2825end;
     2826
     2827function TAI.ChooseGovernment: Integer;
    28422828begin
    28432829  if Data.BehaviorFlags and bBarbarina <> 0 then
     
    28562842end;
    28572843
    2858 
    28592844//-------------------------------
    28602845//           DIPLOMACY
    28612846//-------------------------------
    28622847
    2863 function TAI.MostWanted(Nation, adGiveAway: integer): integer;
     2848function TAI.MostWanted(Nation, adGiveAway: Integer): Integer;
    28642849var
    2865   ad: integer;
     2850  ad: Integer;
    28662851begin
    28672852  Result := -1;
     
    28912876end;
    28922877
    2893 procedure TAI.FindBestTrade(Nation: integer; var adWanted, adGiveAway: integer);
     2878procedure TAI.FindBestTrade(Nation: Integer; var adWanted, adGiveAway: Integer);
    28942879var
    2895   i, ad, ead, adTestGiveAway: integer;
     2880  I, ad, ead, adTestGiveAway: Integer;
    28962881begin
    28972882  adWanted := -1;
     
    29032888    begin
    29042889      adTestGiveAway := -1;
    2905       for i := 0 to nRequestedTechs - 1 do
    2906         if (Data.RequestedTechs[i] >= 0) and
    2907           (Data.RequestedTechs[i] and $FFFF = Nation shl 8 + ead) then
     2890      for I := 0 to nRequestedTechs - 1 do
     2891        if (Data.RequestedTechs[I] >= 0) and
     2892          (Data.RequestedTechs[I] and $FFFF = Nation shl 8 + ead) then
    29082893          adTestGiveAway := -2; // already requested before
    29092894      if adTestGiveAway = -1 then
     
    29282913end;
    29292914
    2930 
    2931 function TAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;
     2915function TAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean;
    29322916var
    2933   p1, Count, adWanted, adGiveAway: integer;
     2917  p1, Count, adWanted, adGiveAway: Integer;
    29342918begin
    29352919  if Data.BehaviorFlags and bBarbarina = bBarbarina then
    29362920  begin
    29372921    Result := Barbarina_WantNegotiation(Nation, NegoTime);
    2938     exit;
     2922    Exit;
    29392923  end;
    29402924
     
    29442928    begin
    29452929      Result := False;
    2946       exit;
     2930      Exit;
    29472931    end;
    29482932    Count := 0;
    29492933    for p1 := 0 to nPl - 1 do
    2950       if (p1 <> me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] >= trPeace) then
     2934      if (p1 <> Me) and (1 shl p1 and RO.Alive <> 0) and (RO.Treaty[p1] >= trPeace) then
    29512935        Inc(Count);
    29522936    if Count >= 3 then // enough peace made
    29532937    begin
    29542938      Result := False;
    2955       exit;
     2939      Exit;
    29562940    end;
    29572941  end;
     
    29942978procedure TAI.DoNegotiation;
    29952979var
    2996   i, adWanted, adGiveAway, adToGet, Slot: integer;
    2997   BuildFreeOffer: boolean;
     2980  I, adWanted, adGiveAway, adToGet, Slot: Integer;
     2981  BuildFreeOffer: Boolean;
    29982982begin
    29992983  if MyLastAction = scDipOffer then
     
    30263010  begin
    30273011    Barbarina_DoNegotiation;
    3028     exit;
     3012    Exit;
    30293013  end;
    30303014
     
    30323016  begin
    30333017    Barbarina_DoCheckNegotiation;
    3034     exit;
     3018    Exit;
    30353019  end;
    30363020
     
    30473031      (OppoOffer.nDeliver + OppoOffer.nCost = 1) and
    30483032      (OppoOffer.Price[0] and opMask = opTreaty) and
    3049       (integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and
     3033      (Integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and
    30503034      ((OppoOffer.Price[0] - opTreaty < trAlliance) or
    30513035      (RO.Tech[adScience] >= tsSeen)) then
    30523036      MyAction := scDipAccept // accept all treaties
    30533037    else if (RO.Treaty[Opponent] >= trPeace) and (OppoOffer.nDeliver = 1) and
    3054       (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + cardinal(Opponent) shl 16) and
     3038      (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + Cardinal(Opponent) shl 16) and
    30553039      (OppoOffer.nCost = 1) and (OppoOffer.Price[1] and $FFFF0000 =
    3056       opCivilReport + cardinal(me) shl 16) then
     3040      opCivilReport + Cardinal(Me) shl 16) then
    30573041      MyAction := scDipAccept // accept exchange of civil reports
    30583042    else if (OppoOffer.nDeliver = 1) and (OppoOffer.nCost = 1) and
     
    30843068        adWanted := MostWanted(Opponent, OppoOffer.Price[1] - opTech);
    30853069        if (OppoOffer.Price[0] and opMask = opTech) and
    3086           (cardinal(adWanted) = OppoOffer.Price[0] - opTech) then
     3070          (Cardinal(adWanted) = OppoOffer.Price[0] - opTech) then
    30873071          MyAction := scDipAccept // opponent's offer is already perfect
    30883072        else if adWanted >= 0 then
     
    31403124        MyOffer.Price[1] := opTech + adWanted;
    31413125        MyAction := scDipOffer;
    3142         for i := 0 to nRequestedTechs - 1 do
    3143           if Data.RequestedTechs[i] < 0 then
     3126        for I := 0 to nRequestedTechs - 1 do
     3127          if Data.RequestedTechs[I] < 0 then
    31443128          begin
    3145             Slot := i;
    3146             break;
     3129            Slot := I;
     3130            Break;
    31473131          end
    3148           else if (i = 0) or (Data.RequestedTechs[i] shr 16 <
     3132          else if (I = 0) or (Data.RequestedTechs[I] shr 16 <
    31493133            Data.RequestedTechs[Slot] shr 16) then // find most outdated entry
    3150             Slot := i;
     3134            Slot := I;
    31513135        Data.RequestedTechs[Slot] := RO.Turn shl 16 + Opponent shl 8 + adWanted;
    31523136      end;
    31533137    end;
    31543138  end;
    3155 end; // Negotiation
    3156 
     3139end;
    31573140
    31583141procedure SetLeaveOutValue;
    31593142
    3160   procedure Process(ad: integer);
     3143  procedure Process(ad: Integer);
    31613144  var
    3162     i: integer;
     3145    I: Integer;
    31633146  begin
    31643147    if LeaveOutValue[ad] < 0 then
    31653148    begin
    31663149      LeaveOutValue[ad] := 0;
    3167       for i := 0 to 1 do
    3168         if AdvPreq[ad, i] >= 0 then
    3169         begin
    3170           Process(AdvPreq[ad, i]);
    3171           if AdvPreq[ad, i] in LeaveOutTechs then
    3172             Inc(LeaveOutValue[ad], LeaveOutValue[AdvPreq[ad, i]] + 1);
     3150      for I := 0 to 1 do
     3151        if AdvPreq[ad, I] >= 0 then
     3152        begin
     3153          Process(AdvPreq[ad, I]);
     3154          if AdvPreq[ad, I] in LeaveOutTechs then
     3155            Inc(LeaveOutValue[ad], LeaveOutValue[AdvPreq[ad, I]] + 1);
    31733156        end;
    31743157    end;
     
    31763159
    31773160var
    3178   ad: integer;
     3161  ad: Integer;
    31793162begin
    31803163  FillChar(LeaveOutValue, SizeOf(LeaveOutValue), $FF);
     
    31853168
    31863169initialization
    3187   RWDataSize := sizeof(TPersistentData);
     3170  RWDataSize := SizeOf(TPersistentData);
    31883171  SetLeaveOutValue;
    31893172
  • branches/highdpi/AI/StdAI/Barbarina.pas

    r349 r465  
    2525type
    2626  TColonyShipPlan = array[0..nShipPart - 1] of record
    27     cixProducing: integer;
    28     LocResource: array[0..maxModern - 1] of integer;
    29     nLocResource: integer;
    30     LocFoundCity: array[0..maxModern - 1] of integer;
    31     nLocFoundCity: integer;
     27    cixProducing: Integer;
     28    LocResource: array[0..maxModern - 1] of Integer;
     29    nLocResource: Integer;
     30    LocFoundCity: array[0..maxModern - 1] of Integer;
     31    nLocFoundCity: Integer;
    3232  end;
    3333
    3434  TBarbarina = class(TToolAI)
    35     constructor Create(Nation: integer); override;
     35    constructor Create(Nation: Integer); override;
    3636
    3737  protected
    3838    ColonyShipPlan: TColonyShipPlan;
    39     function Barbarina_GoHidden: boolean; // whether we should prepare for barbarina mode
    40     function Barbarina_Go: boolean; // whether we should switch to barbarina mode now
     39    function Barbarina_GoHidden: Boolean; // whether we should prepare for barbarina mode
     40    function Barbarina_Go: Boolean; // whether we should switch to barbarina mode now
    4141    procedure Barbarina_DoTurn;
    4242    procedure Barbarina_SetCityProduction;
    43     function Barbarina_ChooseResearchAdvance: integer;
    44     function Barbarina_WantCheckNegotiation(Nation: integer): boolean;
     43    function Barbarina_ChooseResearchAdvance: Integer;
     44    function Barbarina_WantCheckNegotiation(Nation: Integer): Boolean;
    4545    procedure Barbarina_DoCheckNegotiation;
    46     function Barbarina_WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;
     46    function Barbarina_WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean;
    4747    procedure Barbarina_DoNegotiation;
    4848    procedure MakeColonyShipPlan;
    4949
    5050  private
    51     TurnOfMapAnalysis, Neighbours: integer;
    52     ContinentPresence: array[0..maxCOD - 1] of integer;
    53     OceanPresence: array[0..maxCOD - 1] of integer;
    54     ContinentSize: array[0..maxCOD - 1] of integer;
    55     OceanSize: array[0..maxCOD - 1] of integer;
    56     mixBest: array[0..nModelCategory - 1] of integer;
     51    TurnOfMapAnalysis, Neighbours: Integer;
     52    ContinentPresence: array[0..maxCOD - 1] of Integer;
     53    OceanPresence: array[0..maxCOD - 1] of Integer;
     54    ContinentSize: array[0..maxCOD - 1] of Integer;
     55    OceanSize: array[0..maxCOD - 1] of Integer;
     56    mixBest: array[0..nModelCategory - 1] of Integer;
    5757    NegoCause: (CancelTreaty);
    58     function IsModelAvailable(rmix: integer): boolean;
     58    function IsModelAvailable(rmix: Integer): Boolean;
    5959    procedure FindBestModels;
    6060    procedure AnalyzeMap;
    61     procedure RateAttack(uix: integer);
    62     function DoAttack(uix, AttackLoc: integer): boolean;
    63     function ProcessMove(uix: integer): boolean;
     61    procedure RateAttack(uix: Integer);
     62    function DoAttack(uix, AttackLoc: Integer): Boolean;
     63    function ProcessMove(uix: Integer): Boolean;
    6464    procedure AttackAndPatrol;
    6565  end;
     
    7373type
    7474  TResearchModel = record
    75     Category, Domain, Weight, adStop, FutMStrength: integer;
    76     Upgrades: cardinal;
    77     Cap: array [0..nFeature - 1] of integer;
     75    Category, Domain, Weight, adStop, FutMStrength: Integer;
     76    Upgrades: Cardinal;
     77    Cap: array [0..nFeature - 1] of Integer;
    7878  end;
    7979
     
    9393
    9494  nResearchOrder = 40;
    95   ResearchOrder: array[0..nResearchOrder - 1] of integer =
     95  ResearchOrder: array[0..nResearchOrder - 1] of Integer =
    9696    (adBronzeWorking, -adMapMaking, adChivalry, adMonotheism, adIronWorking,
    9797    adGunPowder, adTheology, adConstruction, adCodeOfLaws, -adEngineering,
     
    171171
    172172var
    173   Moved: array[0..numax - 1] of boolean;
    174   UnitPresence: array[0..lxmax * lymax - 1] of byte;
     173  Moved: array[0..numax - 1] of Boolean;
     174  UnitPresence: array[0..lxmax * lymax - 1] of Byte;
    175175  euixMap: array[0..lxmax * lymax - 1] of smallint;
    176176  uixAttack: array[0..neumax - 1] of smallint;
    177   AttackScore: array[0..neumax - 1] of integer;
    178 
    179 constructor TBarbarina.Create(Nation: integer);
     177  AttackScore: array[0..neumax - 1] of Integer;
     178
     179constructor TBarbarina.Create(Nation: Integer);
    180180begin
    181181  inherited;
     
    184184
    185185// whether one of the existing models matches a specific research model
    186 function TBarbarina.IsModelAvailable(rmix: integer): boolean;
     186function TBarbarina.IsModelAvailable(rmix: Integer): Boolean;
    187187var
    188   i, mix, MStrength: integer;
     188  I, mix, MStrength: Integer;
    189189begin
    190190  Result := False;
     
    199199        Result := MStrength < (MyModel[mix].MStrength * 3) div 2;
    200200        // for future techs: don't count model available if 50% stronger possible
    201         for i := 0 to nFeature - 1 do
    202           if MyModel[mix].Cap[i] < Cap[i] then
     201        for I := 0 to nFeature - 1 do
     202          if MyModel[mix].Cap[I] < Cap[I] then
    203203          begin
    204204            Result := False;
    205             break;
     205            Break;
    206206          end;
    207207        if Result then
    208           break;
     208          Break;
    209209      end;
    210210  end;
    211211end;
    212212
    213 function TBarbarina.Barbarina_GoHidden: boolean;
     213function TBarbarina.Barbarina_GoHidden: Boolean;
    214214var
    215   V21, Loc1, cix: integer;
     215  V21, Loc1, cix: Integer;
    216216  Radius: TVicinity21Loc;
    217217begin
     
    238238end;
    239239
    240 function TBarbarina.Barbarina_Go: boolean;
     240function TBarbarina.Barbarina_Go: Boolean;
    241241begin
    242242  if IsResearched(adMassProduction) then
     
    249249    Result := (RO.nCity >= 3) and IsResearched(adMapMaking) and
    250250      IsModelAvailable(EntryModel_Base);
    251     exit;
     251    Exit;
    252252  end;
    253253  Result := Result and ((RO.nUn >= RO.nCity * 3) or
    254     (RO.Wonder[woZeus].EffectiveOwner = me));
     254    (RO.Wonder[woZeus].EffectiveOwner = Me));
    255255end;
    256256
    257257procedure TBarbarina.AnalyzeMap;
    258258var
    259   Loc, Loc1, V8, f1, p1, cix: integer;
     259  Loc, Loc1, V8, f1, p1, cix: Integer;
    260260  Adjacent: TVicinity8Loc;
    261261begin
    262262  if TurnOfMapAnalysis = RO.Turn then
    263     exit;
     263    Exit;
    264264
    265265  // inherited;
    266266
    267267  // collect nation presence information for continents and oceans
    268   fillchar(ContinentPresence, sizeof(ContinentPresence), 0);
    269   fillchar(OceanPresence, sizeof(OceanPresence), 0);
    270   fillchar(ContinentSize, sizeof(ContinentSize), 0);
    271   fillchar(OceanSize, sizeof(OceanSize), 0);
     268  FillChar(ContinentPresence, SizeOf(ContinentPresence), 0);
     269  FillChar(OceanPresence, SizeOf(OceanPresence), 0);
     270  FillChar(ContinentSize, SizeOf(ContinentSize), 0);
     271  FillChar(OceanSize, SizeOf(OceanSize), 0);
    272272  for Loc := 0 to MapSize - 1 do
    273273  begin
     
    339339procedure TBarbarina.FindBestModels;
    340340var
    341   i, mix, rmix, cat: integer;
     341  I, mix, rmix, cat: Integer;
    342342begin
    343   for i := 0 to nModelCategory - 1 do
    344     mixBest[i] := -1;
     343  for I := 0 to nModelCategory - 1 do
     344    mixBest[I] := -1;
    345345  for rmix := nResearchModel - 1 downto 0 do
    346346    with ResearchModel[rmix] do
     
    351351          begin
    352352            mixBest[Category] := mix;
    353             for i := 0 to nFeature - 1 do
    354               if MyModel[mix].Cap[i] < Cap[i] then
     353            for I := 0 to nFeature - 1 do
     354              if MyModel[mix].Cap[I] < Cap[I] then
    355355              begin
    356356                mixBest[Category] := -1;
    357                 break;
     357                Break;
    358358              end;
    359359            if mixBest[Category] >= 0 then
    360               break;
     360              Break;
    361361          end;
    362362  for mix := 3 to RO.nModel - 1 do
     
    387387      begin
    388388        mixBest[ctSeaTrans] := mix;
    389         break;
     389        Break;
    390390      end;
    391391end;
     
    406406
    407407// find one unit to destroy each known enemy unit, result in uixAttack
    408 procedure TBarbarina.RateAttack(uix: integer);
     408procedure TBarbarina.RateAttack(uix: Integer);
    409409var
    410410  MoveStyle, TestLoc, TestTime, NextLoc, NextTime, V8, RemHealth,
    411   RecoverTurns, Score, BestScore, euixBest, uixOld: integer;
    412   NextTile: cardinal;
     411  RecoverTurns, Score, BestScore, euixBest, uixOld: Integer;
     412  NextTile: Cardinal;
    413413  Adjacent: TVicinity8Loc;
    414414  Defense: ^TUnitInfo;
    415   Reached: array[0..lxmax * lymax - 1] of boolean;
     415  Reached: array[0..lxmax * lymax - 1] of Boolean;
    416416begin
    417417  with MyUnit[uix] do
     
    419419    begin
    420420      BestScore := 0;
    421       fillchar(Reached, MapSize, False);
     421      FillChar(Reached, MapSize, False);
    422422      MoveStyle := GetMyMoveStyle(mix, Health);
    423423      Pile.Create(MapSize);
     
    494494end;
    495495
    496 function TBarbarina.DoAttack(uix, AttackLoc: integer): boolean;
     496function TBarbarina.DoAttack(uix, AttackLoc: Integer): Boolean;
    497497  // AttackLoc=maNextCity means bombard only
    498498var
    499499  MoveResult, Kind, Temp, MoveStyle, TestLoc, TestTime, NextLoc,
    500   NextTime, V8, RecoverTurns, ecix: integer;
    501   NextTile: cardinal;
    502   AttackPositionReached, IsBombardment: boolean;
     500  NextTime, V8, RecoverTurns, ecix: Integer;
     501  NextTile: Cardinal;
     502  AttackPositionReached, IsBombardment: Boolean;
    503503  Adjacent: TVicinity8Loc;
    504   PreLoc: array[0..lxmax * lymax - 1] of word;
    505   Reached: array[0..lxmax * lymax - 1] of boolean;
     504  PreLoc: array[0..lxmax * lymax - 1] of Word;
     505  Reached: array[0..lxmax * lymax - 1] of Boolean;
    506506begin
    507507  Result := False;
     
    516516    else
    517517      Kind := 0;
    518     fillchar(Reached, MapSize, False);
     518    FillChar(Reached, MapSize, False);
    519519    AttackPositionReached := False;
    520520    MoveStyle := GetMyMoveStyle(mix, Health);
     
    524524    begin
    525525      if (TestTime >= $800) or (AttackLoc = maNextCity) and (TestTime > $800 - 100) then
    526         break;
     526        Break;
    527527      Reached[TestLoc] := True;
    528528      V8_to_Loc(TestLoc, Adjacent);
     
    537537          begin
    538538            City_FindEnemyCity(NextLoc, ecix);
    539             assert(ecix >= 0);
     539            Assert(ecix >= 0);
    540540            with RO.EnemyCity[ecix] do
    541541              if (Size > 2) and (Flags and ciCoastalFort = 0) then
     
    547547          begin
    548548            AttackPositionReached := True;
    549             break;
     549            Break;
    550550          end
    551551          else if not Reached[NextLoc] then
     
    572572      begin
    573573        PreLoc[NextLoc] := TestLoc;
    574         break;
     574        Break;
    575575      end;
    576576    end;
    577577    Pile.Free;
    578578    if not AttackPositionReached then
    579       exit;
     579      Exit;
    580580
    581581    TestLoc := AttackLoc;
     
    601601    begin
    602602      City_FindEnemyCity(AttackLoc, ecix);
    603       assert(ecix >= 0);
     603      Assert(ecix >= 0);
    604604      while (Movement >= 100) and (RO.EnemyCity[ecix].Size > 2) do
    605605        Unit_Step(uix, AttackLoc);
     
    611611end;
    612612
    613 function TBarbarina.ProcessMove(uix: integer): boolean;
     613function TBarbarina.ProcessMove(uix: Integer): Boolean;
    614614  // return true if no new enemy spotted
    615615const
     
    618618  PatrolScore, BestCount, PatrolLoc, TestLoc, NextLoc, TestTime, V8,
    619619  TestScore, MoveResult, MoveStyle, NextTime, TerrOwner, Kind, Temp,
    620   RecoverTurns, MaxScore: integer;
    621   Tile, NextTile: cardinal;
    622   CaptureOnly, PeaceBorder, done, NextToEnemyCity: boolean;
     620  RecoverTurns, MaxScore: Integer;
     621  Tile, NextTile: Cardinal;
     622  CaptureOnly, PeaceBorder, done, NextToEnemyCity: Boolean;
    623623  Adjacent: TVicinity8Loc;
    624   AdjacentUnknown: array[0..lxmax * lymax - 1] of shortint;
    625   PreLoc: array[0..lxmax * lymax - 1] of word;
    626   MoreTurn: array[0..lxmax * lymax - 1] of byte;
     624  AdjacentUnknown: array[0..lxmax * lymax - 1] of ShortInt;
     625  PreLoc: array[0..lxmax * lymax - 1] of Word;
     626  MoreTurn: array[0..lxmax * lymax - 1] of Byte;
    627627
    628628begin
     
    637637        if Map[Loc] and fCity = 0 then
    638638          Unit_MoveEx(uix, maNextCity);
    639         exit;
     639        Exit;
    640640      end;
    641641
     
    666666          // assume a score of $400 is the best achievable
    667667          or CaptureOnly and (TestTime >= $1000) then
    668           break;
     668          Break;
    669669
    670670        TestScore := 0;
    671671        Tile := Map[TestLoc];
    672         assert(Tile and (fUnit or fOwned) <> fUnit);
     672        Assert(Tile and (fUnit or fOwned) <> fUnit);
    673673        TerrOwner := RO.Territory[TestLoc];
    674674        AdjacentUnknown[TestLoc] := 0;
     
    743743              TestScore := $400 - 14
    744744            else if AdjacentUnknown[TestLoc] > 0 then
    745               if PeaceBorder or (TerrOwner >= 0) and (TerrOwner <> me) and
     745              if PeaceBorder or (TerrOwner >= 0) and (TerrOwner <> Me) and
    746746                (RO.Treaty[TerrOwner] < trPeace) then
    747747                TestScore := $400 - 32 + AdjacentUnknown[TestLoc]
     
    790790        end;
    791791        if PatrolLoc = Loc then
    792           exit;
     792          Exit;
    793793        TestLoc := PatrolLoc;
    794794        NextLoc := PreLoc[TestLoc];
     
    814814            Result := MoveResult and rEnemySpotted = 0;
    815815            done := True;
    816             break;
    817           end;
    818           assert(Loc = NextLoc);
     816            Break;
     817          end;
     818          Assert(Loc = NextLoc);
    819819        end;
    820820        if Loc >= 0 then
     
    833833  if Result then
    834834    Moved[uix] := True;
    835 end; // ProcessMove
     835end;
    836836
    837837procedure TBarbarina.AttackAndPatrol;
     
    839839  procedure SetCityDefenders;
    840840  var
    841     uix, cix, V8, Loc1, Best, uixBest, det: integer;
     841    uix, cix, V8, Loc1, Best, uixBest, det: Integer;
    842842    Adjacent: TVicinity8Loc;
    843     IsPort: boolean;
     843    IsPort: Boolean;
    844844  begin
    845845    for cix := 0 to RO.nCity - 1 do
     
    887887  procedure ProcessSeaTransport;
    888888  var
    889     i, f, uix, Loc1, a, b: integer;
    890     ready, go: boolean;
     889    I, F, uix, Loc1, A, B: Integer;
     890    ready, go: Boolean;
    891891    TransportPlan: TGroupTransportPlan;
    892892  begin
    893893    go := False;
    894     for f := 0 to maxCOD - 1 do
    895       if (f < nContinent) and (ContinentPresence[f] and not
    896         (1 shl me or PresenceUnknown) <> 0) then
     894    for F := 0 to maxCOD - 1 do
     895      if (F < nContinent) and (ContinentPresence[F] and not
     896        (1 shl Me or PresenceUnknown) <> 0) then
    897897        go := True; // any enemy island known?
    898898    if not go then
    899       exit;
     899      Exit;
    900900
    901901    SeaTransport_BeginInitialize;
     
    907907            (MyModel[mix].Attack > 0) and (Map[Loc] and fTerrain >= fGrass) then
    908908          begin
    909             f := Formation[Loc];
    910             if (f >= 0) and (f < maxCOD) and (ContinentPresence[f] and
    911               not (1 shl me) = 0) then
     909            F := Formation[Loc];
     910            if (F >= 0) and (F < maxCOD) and (ContinentPresence[F] and
     911              not (1 shl Me) = 0) then
    912912            begin
    913913              go := True;
     
    932932        if Map[Loc1] and fTerrain >= fGrass then
    933933        begin
    934           f := Formation[Loc1];
    935           if (f >= 0) and (f < maxCOD) and (ContinentPresence[f] and
    936             not (1 shl me or PresenceUnknown) <> 0) then
     934          F := Formation[Loc1];
     935          if (F >= 0) and (F < maxCOD) and (ContinentPresence[F] and
     936            not (1 shl Me or PresenceUnknown) <> 0) then
    937937            SeaTransport_AddDestination(Loc1);
    938938        end;
     
    948948      end;
    949949      if ready then
    950         for i := 0 to TransportPlan.nLoad - 1 do
     950        for I := 0 to TransportPlan.nLoad - 1 do
    951951        begin
    952952          Loc_to_ab(TransportPlan.LoadLoc,
    953             MyUnit[TransportPlan.uixLoad[i]].Loc, a, b);
    954           ready := ready and (abs(a) <= 1) and (abs(b) <= 1);
     953            MyUnit[TransportPlan.uixLoad[I]].Loc, A, B);
     954          ready := ready and (abs(A) <= 1) and (abs(B) <= 1);
    955955        end;
    956956      if ready then
    957957      begin
    958         for i := 0 to TransportPlan.nLoad - 1 do
    959         begin
    960           Unit_Step(TransportPlan.uixLoad[i], TransportPlan.LoadLoc);
    961           Moved[TransportPlan.uixLoad[i]] := True;
     958        for I := 0 to TransportPlan.nLoad - 1 do
     959        begin
     960          Unit_Step(TransportPlan.uixLoad[I], TransportPlan.LoadLoc);
     961          Moved[TransportPlan.uixLoad[I]] := True;
    962962        end;
    963963      end
    964964      else
    965965      begin
    966         for i := 0 to TransportPlan.nLoad - 1 do
    967         begin
    968           Unit_MoveEx(TransportPlan.uixLoad[i], TransportPlan.LoadLoc, mxAdjacent);
    969           Moved[TransportPlan.uixLoad[i]] := True;
     966        for I := 0 to TransportPlan.nLoad - 1 do
     967        begin
     968          Unit_MoveEx(TransportPlan.uixLoad[I], TransportPlan.LoadLoc, mxAdjacent);
     969          Moved[TransportPlan.uixLoad[I]] := True;
    970970        end;
    971971      end;
     
    973973  end;
    974974
    975   procedure ProcessUnload(uix: integer);
    976 
    977     procedure Unload(Kind, ToLoc: integer);
     975  procedure ProcessUnload(uix: Integer);
     976
     977    procedure Unload(Kind, ToLoc: Integer);
    978978    var
    979       uix1: integer;
     979      uix1: Integer;
    980980    begin
    981981      for uix1 := 0 to RO.nUn - 1 do
     
    987987            Unit_Step(uix1, ToLoc);
    988988            UnitPresence[ToLoc] := UnitPresence[ToLoc] or Kind;
    989             break;
     989            Break;
    990990          end;
    991991    end;
     
    993993  var
    994994    uix1, MoveStyle, TestLoc, TestTime, NextLoc, NextTime, V8,
    995     RecoverTurns, nSlow, nFast, SlowUnloadLoc, FastUnloadLoc, EndLoc, f: integer;
    996     NextTile: cardinal;
     995    RecoverTurns, nSlow, nFast, SlowUnloadLoc, FastUnloadLoc, EndLoc, F: Integer;
     996    NextTile: Cardinal;
    997997    Adjacent: TVicinity8Loc;
    998     Reached: array[0..lxmax * lymax - 1] of boolean;
     998    Reached: array[0..lxmax * lymax - 1] of Boolean;
    999999  begin
    10001000    // inventory
     
    10171017        FastUnloadLoc := -1;
    10181018        EndLoc := -1;
    1019         fillchar(Reached, MapSize, False);
     1019        FillChar(Reached, MapSize, False);
    10201020        Pile.Create(MapSize);
    10211021        Pile.Put(Loc, $800 - Movement);
     
    10341034              else if NextTile and fTerrain >= fGrass then
    10351035              begin
    1036                 f := Formation[NextLoc];
    1037                 if (f >= 0) and (f < maxCOD) and
    1038                   (ContinentPresence[f] and not (1 shl me or PresenceUnknown) <> 0) and
     1036                F := Formation[NextLoc];
     1037                if (F >= 0) and (F < maxCOD) and
     1038                  (ContinentPresence[F] and not (1 shl Me or PresenceUnknown) <> 0) and
    10391039                  (NextTile and (fUnit or fOwned) <> fUnit) then
    10401040                begin
     
    10741074
    10751075        if EndLoc < 0 then
    1076           exit;
     1076          Exit;
    10771077        if Loc <> EndLoc then
    10781078          Unit_MoveEx(uix, EndLoc);
    10791079        if Loc <> EndLoc then
    1080           exit;
     1080          Exit;
    10811081        if SlowUnloadLoc >= 0 then
    10821082        begin
     
    10921092        begin
    10931093          Moved[uix] := False;
    1094           exit;
     1094          Exit;
    10951095        end
    10961096      until False;
     
    10991099
    11001100var
    1101   uix, euix, Kind, euixBest, AttackLoc: integer;
    1102   OldTile: cardinal;
    1103   BackToStart, FirstLoop: boolean;
     1101  uix, euix, Kind, euixBest, AttackLoc: Integer;
     1102  OldTile: Cardinal;
     1103  BackToStart, FirstLoop: Boolean;
    11041104begin
    1105   fillchar(UnitPresence, MapSize, 0);
     1105  FillChar(UnitPresence, MapSize, 0);
    11061106  for uix := 0 to RO.nUn - 1 do
    11071107    with MyUnit[uix] do
     
    11161116      end;
    11171117
    1118   fillchar(Moved, RO.nUn, False);
     1118  FillChar(Moved, RO.nUn, False);
    11191119  for uix := 0 to RO.nUn - 1 do
    11201120    if (MyUnit[uix].Master >= 0) or (MyUnit[uix].TroopLoad > 0) then
     
    11281128      if RO.nEnemyUn > 0 then
    11291129      begin
    1130         fillchar(euixMap, MapSize * 2, $FF);
    1131         fillchar(AttackScore, RO.nEnemyUn * 4, 0);
     1130        FillChar(euixMap, MapSize * 2, $FF);
     1131        FillChar(AttackScore, RO.nEnemyUn * 4, 0);
    11321132        for euix := 0 to RO.nEnemyUn - 1 do
    11331133          with RO.EnemyUn[euix] do
     
    11401140      end;
    11411141      if not BackToStart then
    1142         break;
     1142        Break;
    11431143
    11441144      for uix := 0 to RO.nUn - 1 do
     
    11551155            euixBest := euix;
    11561156        if euixBest < 0 then
    1157           break;
     1157          Break;
    11581158        uix := uixAttack[euixBest];
    11591159        AttackLoc := RO.EnemyUn[euixBest].Loc;
     
    12021202            begin
    12031203              BackToStart := True;
    1204               break;
     1204              Break;
    12051205            end
    12061206  until not BackToStart;
    1207 end; // AttackAndPatrol
     1207end;
    12081208
    12091209procedure TBarbarina.Barbarina_SetCityProduction;
     
    12141214    1 shl woMagellan + 1 shl woEiffel + 1 shl woLiberty + 1 shl woShinkansen;
    12151215
    1216   function LowPriority(cix: integer): boolean;
     1216  function LowPriority(cix: Integer): Boolean;
    12171217  var
    1218     part, cixHighPriority, TestDistance: integer;
     1218    part, cixHighPriority, TestDistance: Integer;
    12191219  begin
    12201220    Result := False;
     
    12281228        begin
    12291229          Result := True;
    1230           exit;
     1230          Exit;
    12311231        end;
    12321232      end;
     
    12341234  end;
    12351235
    1236   function ChooseWonderToBuild(WonderAvailable: integer; AllowCoastal: boolean): integer;
     1236  function ChooseWonderToBuild(WonderAvailable: Integer; AllowCoastal: Boolean): Integer;
    12371237  var
    1238     Count, iix: integer;
     1238    Count, iix: Integer;
    12391239  begin
    12401240    if (WonderAvailable and PrimeWonder > 0) and (AllowCoastal or
     
    12671267      begin
    12681268        Result := iix;
    1269         exit;
     1269        Exit;
    12701270      end;
    12711271    end;
     
    12731273
    12741274var
    1275   i, iix, cix, mix, uix, mixProduce, mixShip, V8, V21, Loc1, TotalPop,
    1276   AlonePop, f, f1, nTownGuard, ShipPart, ProduceShipPart, TestDistance,
    1277   part, WonderAvailable, WonderInWork, cixNewCapital, Center, Score, BestScore: integer;
    1278   mixCount: array[0..nmmax - 1] of integer;
     1275  I, iix, cix, mix, uix, mixProduce, mixShip, V8, V21, Loc1, TotalPop,
     1276  AlonePop, F, f1, nTownGuard, ShipPart, ProduceShipPart, TestDistance,
     1277  part, WonderAvailable, WonderInWork, cixNewCapital, Center, Score, BestScore: Integer;
     1278  mixCount: array[0..nmmax - 1] of Integer;
    12791279  //RareLoc: array[0..5] of integer;
    12801280  Adjacent: TVicinity8Loc;
    12811281  IsCoastal, IsPort, IsUnitProjectObsolete, HasSettler, SpezializeShipProduction,
    12821282  AlgaeAvailable, ProjectComplete, DoLowPriority, WillProduceColonyShip,
    1283   ImportantCity: boolean;
     1283  ImportantCity: Boolean;
    12841284  Radius: TVicinity21Loc;
    12851285  Report: TCityReportNew;
     
    12891289  FindBestModels;
    12901290
    1291   fillchar(mixCount, RO.nModel * 4, 0);
     1291  FillChar(mixCount, RO.nModel * 4, 0);
    12921292  for uix := 0 to RO.nUn - 1 do
    12931293    with MyUnit[uix] do
     
    13171317      begin
    13181318        Inc(TotalPop, Size);
    1319         f := Formation[Loc];
    1320         if (f < 0) or (f >= maxCOD) or (ContinentPresence[f] = 1 shl me) then
     1319        F := Formation[Loc];
     1320        if (F < 0) or (F >= maxCOD) or (ContinentPresence[F] = 1 shl Me) then
    13211321          Inc(AlonePop, Size);
    13221322      end;
     
    13581358              if (f1 >= 0) and (f1 < maxCOD) and
    13591359                ((OceanSize[f1] >= 8) or (OceanPresence[f1] and not
    1360                 (1 shl me) <> 0)) then
     1360                (1 shl Me) <> 0)) then
    13611361              begin // prefer non-coastal cities
    13621362                Dec(Score, 18);
    1363                 break;
     1363                Break;
    13641364              end;
    13651365            end;
     
    13901390          (LowPriority(cix) = DoLowPriority) then
    13911391        begin
    1392           f := Formation[Loc];
     1392          F := Formation[Loc];
    13931393          IsCoastal := False;
    13941394          IsPort := False;
     
    14021402              f1 := Formation[Loc1];
    14031403              if (f1 >= 0) and (f1 < maxCOD) and (OceanSize[f1] >= 8) and
    1404                 (OceanPresence[f1] and not (1 shl me) <> 0) then
     1404                (OceanPresence[f1] and not (1 shl Me) <> 0) then
    14051405              begin
    14061406                IsPort := True;
    1407                 break;
     1407                Break;
    14081408              end;
    14091409            end;
     
    14121412            (RO.Model[City_CurrentUnitProject(cix)].Kind <> mkSettler) then
    14131413          begin
    1414             i := nModelCategory - 1;
    1415             while (i >= 0) and (City_CurrentUnitProject(cix) <> mixBest[i]) do
    1416               Dec(i);
    1417             IsUnitProjectObsolete := i < 0;
     1414            I := nModelCategory - 1;
     1415            while (I >= 0) and (City_CurrentUnitProject(cix) <> mixBest[I]) do
     1416              Dec(I);
     1417            IsUnitProjectObsolete := I < 0;
    14181418          end
    14191419          else
     
    15811581              City_StartImprovement(cix,imMissileBat)}
    15821582                else if IsPort and (not SpezializeShipProduction or
    1583                   (f < 0) or (f >= maxCOD) or (ContinentPresence[f] = 1 shl me)) and
     1583                  (F < 0) or (F >= maxCOD) or (ContinentPresence[F] = 1 shl Me)) and
    15841584                  (Built[imDockyard] = 0) and City_Improvable(cix, imDockyard) then
    15851585                  City_StartImprovement(cix, imDockyard)
    15861586                else if IsPort and (mixShip >= 0) and
    1587                   (not SpezializeShipProduction or (f < 0) or
    1588                   (f >= maxCOD) or (ContinentPresence[f] = 1 shl me)) then
     1587                  (not SpezializeShipProduction or (F < 0) or
     1588                  (F >= maxCOD) or (ContinentPresence[F] = 1 shl Me)) then
    15891589                  City_StartUnitProduction(cix, mixShip)
    15901590                else if (Built[imBarracks] + Built[imMilAcademy] = 0) and
     
    16001600          if (City_CurrentImprovementProject(cix) = imCourt) and
    16011601            (Built[imTownHall] > 0) and (prod >= imp[imCourt].cost *
    1602             BuildCostMod[G.Difficulty[me]] div 12 -
    1603             (imp[imTownHall].cost * BuildCostMod[G.Difficulty[me]] div 12) *
     1602            BuildCostMod[G.Difficulty[Me]] div 12 -
     1603            (imp[imTownHall].cost * BuildCostMod[G.Difficulty[Me]] div 12) *
    16041604            2 div 3) then
    16051605            City_RebuildImprovement(cix, imTownHall)
     
    16141614                if City_RebuildImprovement(cix, iix) < rExecuted then
    16151615                  City_SellImprovement(cix, iix);
    1616                 break;
     1616                Break;
    16171617              end;
    16181618        end;
    16191619end;
    16201620
    1621 function TBarbarina.Barbarina_ChooseResearchAdvance: integer;
     1621function TBarbarina.Barbarina_ChooseResearchAdvance: Integer;
    16221622var
    1623   nPreq, rmix, rmixChosen, i, MaxWeight, MaxDefense, ChosenPreq: integer;
    1624   NeedSeaUnits, ready: boolean;
     1623  nPreq, rmix, rmixChosen, I, MaxWeight, MaxDefense, ChosenPreq: Integer;
     1624  NeedSeaUnits, ready: Boolean;
    16251625  ModelExists: set of 0..nModelCategory - 1;
    1626   known: array[0..nAdv - 1] of integer;
    1627 
    1628   procedure ChoosePreq(ad: integer);
     1626  known: array[0..nAdv - 1] of Integer;
     1627
     1628  procedure ChoosePreq(ad: Integer);
    16291629  var
    1630     i: integer;
    1631     PreqOk: boolean;
     1630    I: Integer;
     1631    PreqOk: Boolean;
    16321632  begin
    1633     assert(RO.Tech[ad] < tsApplicable);
     1633    Assert(RO.Tech[ad] < tsApplicable);
    16341634    if known[ad] = 0 then
    16351635    begin
     
    16371637      PreqOk := True;
    16381638      if not (ad in [adScience, adMassProduction]) and (RO.Tech[ad] < tsSeen) then
    1639         for i := 0 to 1 do
    1640           if (AdvPreq[ad, i] >= 0) and (RO.Tech[AdvPreq[ad, i]] < tsApplicable) then
     1639        for I := 0 to 1 do
     1640          if (AdvPreq[ad, I] >= 0) and (RO.Tech[AdvPreq[ad, I]] < tsApplicable) then
    16411641          begin
    16421642            PreqOk := False;
    1643             ChoosePreq(AdvPreq[ad, i]);
     1643            ChoosePreq(AdvPreq[ad, I]);
    16441644          end;
    16451645      if PreqOk then
     
    16971697        ready := (MaxWeight >= Weight) and (MaxDefense >= Cap[mcDefense]);
    16981698        if ready then
    1699           for i := 0 to nFeature - 1 do
    1700             if (Cap[i] > 0) and (Feature[i].Preq <> preNone) and
    1701               ((Feature[i].Preq < 0) or not IsResearched(Feature[i].Preq)) then
     1699          for I := 0 to nFeature - 1 do
     1700            if (Cap[I] > 0) and (Feature[I].Preq <> preNone) and
     1701              ((Feature[I].Preq < 0) or not IsResearched(Feature[I].Preq)) then
    17021702              ready := False;
    17031703        if ready then
    17041704        begin
    1705           for i := 0 to nUpgrade - 1 do
    1706             if (Upgrades and (1 shl i) <> 0) and not
    1707               IsResearched(Upgrade[Domain, i].Preq) then
     1705          for I := 0 to nUpgrade - 1 do
     1706            if (Upgrades and (1 shl I) <> 0) and not
     1707              IsResearched(Upgrade[Domain, I].Preq) then
    17081708              ready := False;
    17091709        end;
    17101710        if ready then
    17111711        begin
    1712           include(ModelExists, Category);
     1712          Include(ModelExists, Category);
    17131713          if not IsModelAvailable(rmix) then
    17141714            rmixChosen := rmix;
     
    17191719    begin
    17201720      PrepareNewModel(Domain);
    1721       for i := 0 to nFeature - 1 do
    1722         if (i < 2) or (Cap[i] > 0) then
    1723           SetNewModelFeature(i, Cap[i]);
    1724       if RO.Wonder[woSun].EffectiveOwner = me then
     1721      for I := 0 to nFeature - 1 do
     1722        if (I < 2) or (Cap[I] > 0) then
     1723          SetNewModelFeature(I, Cap[I]);
     1724      if RO.Wonder[woSun].EffectiveOwner = Me then
    17251725      begin
    17261726        //if Cap[mcWeapons]>=2*Cap[mcArmor] then
     
    17301730      end;
    17311731      Result := adMilitary;
    1732       exit;
     1732      Exit;
    17331733    end;
    17341734
    17351735  NeedSeaUnits := True;
    1736   i := 0;
    1737   while (i < nResearchOrder) and (not NeedSeaUnits and (ResearchOrder[i] < 0) or
    1738       IsResearched(abs(ResearchOrder[i]))) do
    1739     Inc(i);
    1740   if i >= nResearchOrder then // list done, continue with future tech
     1736  I := 0;
     1737  while (I < nResearchOrder) and (not NeedSeaUnits and (ResearchOrder[I] < 0) or
     1738      IsResearched(abs(ResearchOrder[I]))) do
     1739    Inc(I);
     1740  if I >= nResearchOrder then // list done, continue with future tech
    17411741  begin
    17421742    if random(2) = 1 then
     
    17501750    nPreq := 0;
    17511751    ChosenPreq := -1;
    1752     ChoosePreq(abs(ResearchOrder[i]));
    1753     assert(nPreq > 0);
     1752    ChoosePreq(abs(ResearchOrder[I]));
     1753    Assert(nPreq > 0);
    17541754    Result := ChosenPreq;
    17551755  end;
    17561756end;
    17571757
    1758 function TBarbarina.Barbarina_WantCheckNegotiation(Nation: integer): boolean;
     1758function TBarbarina.Barbarina_WantCheckNegotiation(Nation: Integer): Boolean;
    17591759begin
    17601760  if (RO.Tech[adTheRepublic] < tsSeen) and (RO.Tech[adTheology] >= tsApplicable) and
     
    17691769begin
    17701770  if RO.Tech[adTheRepublic] >= tsSeen then
    1771     exit; // default reaction
     1771    Exit; // default reaction
    17721772  if MyLastAction = scContact then
    17731773  begin
     
    17971797end;
    17981798
    1799 function TBarbarina.Barbarina_WantNegotiation(Nation: integer;
    1800   NegoTime: TNegoTime): boolean;
     1799function TBarbarina.Barbarina_WantNegotiation(Nation: Integer;
     1800  NegoTime: TNegoTime): Boolean;
    18011801var
    1802   uix, TestLoc, V8: integer;
     1802  uix, TestLoc, V8: Integer;
    18031803  Adjacent: TVicinity8Loc;
    18041804begin
     
    18121812      if RO.Turn >= RO.LastCancelTreaty[Nation] + CancelTreatyTurns then
    18131813      begin
    1814         if (RO.Turn and 3 = (Nation + $F - me) and 3) and
     1814        if (RO.Turn and 3 = (Nation + $F - Me) and 3) and
    18151815          (RO.Treaty[Nation] > trPeace) then
    18161816        begin
     
    18381838                    NegoCause := CancelTreaty;
    18391839                    Result := True;
    1840                     exit;
     1840                    Exit;
    18411841                  end;
    18421842                end;
     
    18581858procedure TBarbarina.MakeColonyShipPlan;
    18591859var
    1860   i, V21, V21C, CityLoc, Loc1, part, cix, BestValue, TestValue, FoodCount,
    1861   ProdCount, ProdExtra, Score, BestScore: integer;
    1862   Tile: cardinal;
    1863   ok, check: boolean;
     1860  I, V21, V21C, CityLoc, Loc1, part, cix, BestValue, TestValue, FoodCount,
     1861  ProdCount, ProdExtra, Score, BestScore: Integer;
     1862  Tile: Cardinal;
     1863  ok, check: Boolean;
    18641864  Radius, RadiusC: TVicinity21Loc;
    18651865begin
     
    18871887              begin
    18881888                part := (Tile and fModern) shr 25 - 1;
    1889                 if RO.Ship[me].Parts[part] < ShipNeed[part] then
     1889                if RO.Ship[Me].Parts[part] < ShipNeed[part] then
    18901890                  // not enough of this kind already
    18911891                begin
     
    18931893                  if ColonyShipPlan[part].cixProducing >= 0 then
    18941894                  begin // another city is already assigned to this ship part, choose one of the two
    1895                     TestValue := (ID and $FFF) shl 4 + ((ID shr 12) + 15 - me) and $F;
     1895                    TestValue := (ID and $FFF) shl 4 + ((ID shr 12) + 15 - Me) and $F;
    18961896                    BestValue :=
    18971897                      (MyCity[ColonyShipPlan[part].cixProducing].ID and $FFF) shl
    18981898                      4 + ((MyCity[ColonyShipPlan[part].cixProducing].ID shr 12) +
    1899                       15 - me) and $F;
     1899                      15 - Me) and $F;
    19001900                    if TestValue <= BestValue then
    19011901                      ok := False;
     
    19121912    check := False;
    19131913    for part := 0 to nShipPart - 1 do
    1914       if (RO.Ship[me].Parts[part] < ShipNeed[part]) // not enough of this kind already
     1914      if (RO.Ship[Me].Parts[part] < ShipNeed[part]) // not enough of this kind already
    19151915        and (ColonyShipPlan[part].cixProducing < 0) then // no city to produce
    19161916        check := True;
     
    19311931      end;
    19321932      for part := 0 to nShipPart - 1 do
    1933         if (RO.Ship[me].Parts[part] < ShipNeed[part]) // not enough of this kind already
     1933        if (RO.Ship[Me].Parts[part] < ShipNeed[part]) // not enough of this kind already
    19341934          and (ColonyShipPlan[part].cixProducing < 0) // no city to produce
    19351935          and (ColonyShipPlan[part].nLocResource > 0) then // resource is known
    19361936        begin
    1937           for i := 0 to ColonyShipPlan[part].nLocResource - 1 do
     1937          for I := 0 to ColonyShipPlan[part].nLocResource - 1 do
    19381938          begin
    19391939            BestScore := 0;
    1940             V21_to_Loc(ColonyShipPlan[part].LocResource[i], Radius);
     1940            V21_to_Loc(ColonyShipPlan[part].LocResource[I], Radius);
    19411941            for V21 := 1 to 26 do
    19421942            begin // check all potential cities in range
     
    19841984                      Dec(ProdCount, 5 - FoodCount);
    19851985                    Score := ProdCount * 4 + ProdExtra * 8 + FoodCount;
    1986                     Score := Score shl 8 + ((CityLoc xor me) * 4567) mod 251;
     1986                    Score := Score shl 8 + ((CityLoc xor Me) * 4567) mod 251;
    19871987                    // some unexactness, random but always the same for this tile
    19881988                  end;
  • branches/highdpi/AI/StdAI/CustomAI.pas

    r303 r465  
    1313  TCustomAI = class
    1414  public
    15     procedure Process(Command: integer; var Data);
     15    procedure Process(Command: Integer; var Data);
    1616
    1717    // overridables
    18     constructor Create(Nation: integer); virtual;
     18    constructor Create(Nation: Integer); virtual;
    1919    destructor Destroy; override;
    2020    procedure SetDataDefaults; virtual;
    2121    procedure SetDataRandom; virtual;
    2222    procedure OnBeforeEnemyAttack(UnitInfo: TUnitInfo;
    23       ToLoc, EndHealth, EndHealthDef: integer); virtual;
    24     procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer); virtual;
     23      ToLoc, EndHealth, EndHealthDef: Integer); virtual;
     24    procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer); virtual;
    2525    procedure OnAfterEnemyAttack; virtual;
    2626    procedure OnAfterEnemyCapture; virtual;
    2727
    2828  protected
    29     me: integer; // index of the controlled nation
     29    Me: Integer; // index of the controlled nation
    3030    RO: ^TPlayerContext;
    3131    Map: ^TTileList;
     
    3434    MyModel: ^TModelList;
    3535
    36     cixStateImp: array[imPalace..imSpacePort] of integer;
     36    cixStateImp: array[imPalace..imSpacePort] of Integer;
    3737
    3838    // negotiation
    39     Opponent: integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode
    40     MyAction, MyLastAction, OppoAction: integer;
     39    Opponent: Integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode
     40    MyAction, MyLastAction, OppoAction: Integer;
    4141    MyOffer, MyLastOffer, OppoOffer: TOffer;
    4242
     
    4444    procedure DoTurn; virtual;
    4545    procedure DoNegotiation; virtual;
    46     function ChooseResearchAdvance: integer; virtual;
    47     function ChooseStealAdvance: integer; virtual;
    48     function ChooseGovernment: integer; virtual;
    49     function WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; virtual;
    50     function OnNegoRejected_CancelTreaty: boolean; virtual;
     46    function ChooseResearchAdvance: Integer; virtual;
     47    function ChooseStealAdvance: Integer; virtual;
     48    function ChooseGovernment: Integer; virtual;
     49    function WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; virtual;
     50    function OnNegoRejected_CancelTreaty: Boolean; virtual;
    5151
    5252    // general functions
    53     function IsResearched(Advance: integer): boolean;
    54     function ResearchCost: integer;
    55     function ChangeAttitude(Nation, Attitude: integer): integer;
    56     function Revolution: integer;
    57     function ChangeRates(Tax, Lux: integer): integer;
    58     function PrepareNewModel(Domain: integer): integer;
    59     function SetNewModelFeature(F, Count: integer): integer;
    60     function AdvanceResearchable(Advance: integer): boolean;
    61     function AdvanceStealable(Advance: integer): boolean;
    62     function GetJobProgress(Loc: integer; var JobProgress: TJobProgressData): boolean;
    63     function DebugMessage(Level: integer; Text: string): boolean;
    64     function SetDebugMap(var DebugMap): boolean;
     53    function IsResearched(Advance: Integer): Boolean;
     54    function ResearchCost: Integer;
     55    function ChangeAttitude(Nation, Attitude: Integer): Integer;
     56    function Revolution: Integer;
     57    function ChangeRates(Tax, Lux: Integer): Integer;
     58    function PrepareNewModel(Domain: Integer): Integer;
     59    function SetNewModelFeature(F, Count: Integer): Integer;
     60    function AdvanceResearchable(Advance: Integer): Boolean;
     61    function AdvanceStealable(Advance: Integer): Boolean;
     62    function GetJobProgress(Loc: Integer; var JobProgress: TJobProgressData): Boolean;
     63    function DebugMessage(Level: Integer; Text: string): Boolean;
     64    function SetDebugMap(var DebugMap): Boolean;
    6565
    6666    // unit functions
    67     procedure Unit_FindMyDefender(Loc: integer; var uix: integer);
    68     procedure Unit_FindEnemyDefender(Loc: integer; var euix: integer);
    69     function Unit_Move(uix, ToLoc: integer): integer;
    70     function Unit_Step(uix, ToLoc: integer): integer;
    71     function Unit_Attack(uix, ToLoc: integer): integer;
    72     function Unit_DoMission(uix, MissionType, ToLoc: integer): integer;
    73     function Unit_MoveForecast(uix, ToLoc: integer;
    74       var RemainingMovement: integer): boolean;
    75     function Unit_AttackForecast(uix, ToLoc, AttackMovement: integer;
    76       var RemainingHealth: integer): boolean;
    77     function Unit_DefenseForecast(euix, ToLoc: integer;
    78       var RemainingHealth: integer): boolean;
    79     function Unit_Disband(uix: integer): integer;
    80     function Unit_StartJob(uix, NewJob: integer): integer;
    81     function Unit_SetHomeHere(uix: integer): integer;
    82     function Unit_Load(uix: integer): integer;
    83     function Unit_Unload(uix: integer): integer;
    84     function Unit_SelectTransport(uix: integer): integer;
    85     function Unit_AddToCity(uix: integer): integer;
     67    procedure Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     68    procedure Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
     69    function Unit_Move(uix, ToLoc: Integer): Integer;
     70    function Unit_Step(uix, ToLoc: Integer): Integer;
     71    function Unit_Attack(uix, ToLoc: Integer): Integer;
     72    function Unit_DoMission(uix, MissionType, ToLoc: Integer): Integer;
     73    function Unit_MoveForecast(uix, ToLoc: Integer;
     74      var RemainingMovement: Integer): Boolean;
     75    function Unit_AttackForecast(uix, ToLoc, AttackMovement: Integer;
     76      var RemainingHealth: Integer): Boolean;
     77    function Unit_DefenseForecast(euix, ToLoc: Integer;
     78      var RemainingHealth: Integer): Boolean;
     79    function Unit_Disband(uix: Integer): Integer;
     80    function Unit_StartJob(uix, NewJob: Integer): Integer;
     81    function Unit_SetHomeHere(uix: Integer): Integer;
     82    function Unit_Load(uix: Integer): Integer;
     83    function Unit_Unload(uix: Integer): Integer;
     84    function Unit_SelectTransport(uix: Integer): Integer;
     85    function Unit_AddToCity(uix: Integer): Integer;
    8686
    8787    // city functions
    88     procedure City_FindMyCity(Loc: integer; var cix: integer);
    89     procedure City_FindEnemyCity(Loc: integer; var ecix: integer);
    90     function City_HasProject(cix: integer): boolean;
    91     function City_CurrentImprovementProject(cix: integer): integer;
    92     function City_CurrentUnitProject(cix: integer): integer;
    93     function City_GetTileInfo(cix, TileLoc: integer; var TileInfo: TTileInfo): integer;
    94     function City_GetReport(cix: integer; var Report: TCityReport): integer;
    95     function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;
    96       var Report: TCityReport): integer;
    97     function City_GetReportNew(cix: integer; var Report: TCityReportNew): integer;
    98     function City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate, HypoLuxuryRate: integer;
    99       var Report: TCityReportNew): integer;
    100     function City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    101     function City_StartUnitProduction(cix, mix: integer): integer;
    102     function City_StartEmigration(cix, mix: integer;
    103       AllowDisbandCity, AsConscripts: boolean): integer;
    104     function City_StartImprovement(cix, iix: integer): integer;
    105     function City_Improvable(cix, iix: integer): boolean;
    106     function City_StopProduction(cix: integer): integer;
    107     function City_BuyProject(cix: integer): integer;
    108     function City_SellImprovement(cix, iix: integer): integer;
    109     function City_RebuildImprovement(cix, iix: integer): integer;
    110     function City_SetTiles(cix, NewTiles: integer): integer;
    111     procedure City_OptimizeTiles(cix: integer; ResourceWeights: cardinal = rwMaxGrowth);
     88    procedure City_FindMyCity(Loc: Integer; var cix: Integer);
     89    procedure City_FindEnemyCity(Loc: Integer; var ecix: Integer);
     90    function City_HasProject(cix: Integer): Boolean;
     91    function City_CurrentImprovementProject(cix: Integer): Integer;
     92    function City_CurrentUnitProject(cix: Integer): Integer;
     93    function City_GetTileInfo(cix, TileLoc: Integer; var TileInfo: TTileInfo): Integer;
     94    function City_GetReport(cix: Integer; var Report: TCityReport): Integer;
     95    function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer;
     96      var Report: TCityReport): Integer;
     97    function City_GetReportNew(cix: Integer; var Report: TCityReportNew): Integer;
     98    function City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate, HypoLuxuryRate: Integer;
     99      var Report: TCityReportNew): Integer;
     100    function City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     101    function City_StartUnitProduction(cix, mix: Integer): Integer;
     102    function City_StartEmigration(cix, mix: Integer;
     103      AllowDisbandCity, AsConscripts: Boolean): Integer;
     104    function City_StartImprovement(cix, iix: Integer): Integer;
     105    function City_Improvable(cix, iix: Integer): Boolean;
     106    function City_StopProduction(cix: Integer): Integer;
     107    function City_BuyProject(cix: Integer): Integer;
     108    function City_SellImprovement(cix, iix: Integer): Integer;
     109    function City_RebuildImprovement(cix, iix: Integer): Integer;
     110    function City_SetTiles(cix, NewTiles: Integer): Integer;
     111    procedure City_OptimizeTiles(cix: Integer; ResourceWeights: Cardinal = rwMaxGrowth);
    112112
    113113    // negotiation
    114     function Nego_CheckMyAction: integer;
     114    function Nego_CheckMyAction: Integer;
    115115
    116116  private
    117     HaveTurned: boolean;
     117    HaveTurned: Boolean;
    118118    UnwantedNego: set of 0..nPl - 1;
    119119    Contacted: set of 0..nPl - 1;
     
    125125  Server: TServerCall;
    126126  G: TNewGameData;
    127   RWDataSize, MapSize: integer;
    128   decompose24: cardinal;
    129   nodata: pointer;
     127  RWDataSize, MapSize: Integer;
     128  decompose24: Cardinal;
     129  nodata: Pointer;
    130130
    131131const
     
    139139
    140140type
    141   TVicinity8Loc = array[0..7] of integer;
    142   TVicinity21Loc = array[0..27] of integer;
     141  TVicinity8Loc = array[0..7] of Integer;
     142  TVicinity21Loc = array[0..27] of Integer;
    143143
    144144
    145145procedure Init(NewGameData: TNewGameData);
    146146
    147 procedure ab_to_Loc(Loc0, a, b: integer; var Loc: integer);
    148 procedure Loc_to_ab(Loc0, Loc: integer; var a, b: integer);
    149 procedure ab_to_V8(a, b: integer; var V8: integer);
    150 procedure V8_to_ab(V8: integer; var a, b: integer);
    151 procedure ab_to_V21(a, b: integer; var V21: integer);
    152 procedure V21_to_ab(V21: integer; var a, b: integer);
    153 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    154 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    155 function Distance(Loc0, Loc1: integer): integer;
     147procedure ab_to_Loc(Loc0, A, B: Integer; var Loc: Integer);
     148procedure Loc_to_ab(Loc0, Loc: Integer; var A, B: Integer);
     149procedure ab_to_V8(A, B: Integer; var V8: Integer);
     150procedure V8_to_ab(V8: Integer; var A, B: Integer);
     151procedure ab_to_V21(A, B: Integer; var V21: Integer);
     152procedure V21_to_ab(V21: Integer; var A, B: Integer);
     153procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     154procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
     155function Distance(Loc0, Loc1: Integer): Integer;
    156156
    157157
     
    159159
    160160const
    161   ab_v8: array[-4..4] of integer = (5, 6, 7, 4, -1, 0, 3, 2, 1);
    162   v8_a: array[0..7] of integer = (1, 1, 0, -1, -1, -1, 0, 1);
    163   v8_b: array[0..7] of integer = (0, 1, 1, 1, 0, -1, -1, -1);
    164 
    165 
    166 procedure ab_to_Loc(Loc0, a, b: integer; var Loc: integer);
     161  ab_v8: array[-4..4] of Integer = (5, 6, 7, 4, -1, 0, 3, 2, 1);
     162  v8_a: array[0..7] of Integer = (1, 1, 0, -1, -1, -1, 0, 1);
     163  v8_b: array[0..7] of Integer = (0, 1, 1, 1, 0, -1, -1, -1);
     164
     165
     166procedure ab_to_Loc(Loc0, A, B: Integer; var Loc: Integer);
    167167{relative location from Loc0}
    168168var
    169   y0: integer;
    170 begin
    171   assert((Loc0 >= 0) and (Loc0 < MapSize) and (a - b + G.lx >= 0));
    172   y0 := cardinal(Loc0) * decompose24 shr 24;
    173   Loc := (Loc0 + (a - b + y0 and 1 + G.lx + G.lx) shr 1) mod G.lx + G.lx * (y0 + a + b);
     169  y0: Integer;
     170begin
     171  Assert((Loc0 >= 0) and (Loc0 < MapSize) and (A - B + G.lx >= 0));
     172  y0 := Cardinal(Loc0) * decompose24 shr 24;
     173  Loc := (Loc0 + (A - B + y0 and 1 + G.lx + G.lx) shr 1) mod G.lx + G.lx * (y0 + A + B);
    174174  if Loc >= MapSize then
    175175    Loc := -$1000;
    176176end;
    177177
    178 procedure Loc_to_ab(Loc0, Loc: integer; var a, b: integer);
     178procedure Loc_to_ab(Loc0, Loc: Integer; var A, B: Integer);
    179179{$IFDEF FPC}// freepascal
    180180var
    181   dx, dy: integer;
     181  dx, dy: Integer;
    182182begin
    183183  dx := ((Loc mod G.lx * 2 + Loc div G.lx and 1) - (Loc0 mod G.lx * 2 + Loc0 div
    184184    G.lx and 1) + 3 * G.lx) mod (2 * G.lx) - G.lx;
    185185  dy := Loc div G.lx - Loc0 div G.lx;
    186   a := (dx + dy) div 2;
    187   b := (dy - dx) div 2;
     186  A := (dx + dy) div 2;
     187  B := (dy - dx) div 2;
    188188end;
    189189
     
    195195// calculate
    196196push ecx
    197 div byte ptr [G]
     197div Byte ptr [G]
    198198xor ebx,ebx
    199199mov bl,ah  // ebx:=Loc0 mod G.lx
     
    201201and ecx,$000000FF // ecx:=Loc0 div G.lx
    202202mov eax,edx
    203 div byte ptr [G]
     203div Byte ptr [G]
    204204xor edx,edx
    205205mov dl,ah // edx:=Loc mod G.lx
     
    218218mov edx,dword ptr [G]
    219219cmp eax,edx
    220 jl @a
     220jl @A
    221221  sub eax,edx
    222222  sub eax,edx
    223223  jmp @ok
    224 @a:
     224@A:
    225225neg edx
    226226cmp eax,edx
     
    235235add eax,ebx
    236236sar edx,1 // edx:=b
    237 mov ebx,[b]
     237mov ebx,[B]
    238238mov [ebx],edx
    239239sar eax,1 // eax:=a
    240 mov [a],eax
     240mov [A],eax
    241241
    242242pop ebx
     
    244244{$ENDIF}
    245245
    246 procedure ab_to_V8(a, b: integer; var V8: integer);
    247 begin
    248   assert((abs(a) <= 1) and (abs(b) <= 1) and ((a <> 0) or (b <> 0)));
    249   V8 := ab_v8[2 * b + b + a];
    250 end;
    251 
    252 procedure V8_to_ab(V8: integer; var a, b: integer);
    253 begin
    254   a := v8_a[V8];
    255   b := V8_b[V8];
    256 end;
    257 
    258 procedure ab_to_V21(a, b: integer; var V21: integer);
    259 begin
    260   V21 := (a + b + 3) shl 2 + (a - b + 3) shr 1;
    261 end;
    262 
    263 procedure V21_to_ab(V21: integer; var a, b: integer);
    264 var
    265   dx, dy: integer;
     246procedure ab_to_V8(A, B: Integer; var V8: Integer);
     247begin
     248  Assert((abs(A) <= 1) and (abs(B) <= 1) and ((A <> 0) or (B <> 0)));
     249  V8 := ab_v8[2 * B + B + A];
     250end;
     251
     252procedure V8_to_ab(V8: Integer; var A, B: Integer);
     253begin
     254  A := v8_a[V8];
     255  B := V8_b[V8];
     256end;
     257
     258procedure ab_to_V21(A, B: Integer; var V21: Integer);
     259begin
     260  V21 := (A + B + 3) shl 2 + (A - B + 3) shr 1;
     261end;
     262
     263procedure V21_to_ab(V21: Integer; var A, B: Integer);
     264var
     265  dx, dy: Integer;
    266266begin
    267267  dy := V21 shr 2 - 3;
    268268  dx := V21 and 3 shl 1 - 3 + (dy + 3) and 1;
    269   a := (dx + dy) div 2;
    270   b := (dy - dx) div 2;
    271 end;
    272 
    273 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    274 var
    275   x0, y0, lx: integer;
     269  A := (dx + dy) div 2;
     270  B := (dy - dx) div 2;
     271end;
     272
     273procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     274var
     275  x0, y0, lx: Integer;
    276276begin
    277277  lx := G.lx;
    278   y0 := cardinal(Loc0) * decompose24 shr 24;
     278  y0 := Cardinal(Loc0) * decompose24 shr 24;
    279279  x0 := Loc0 - y0 * lx; // Loc0 mod lx;
    280280  VicinityLoc[1] := Loc0 + lx * 2;
     
    323323end;
    324324
    325 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    326 var
    327   dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;
    328   dst: ^integer;
    329 begin
    330   y0 := cardinal(Loc0) * decompose24 shr 24;
     325procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
     326var
     327  dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: Integer;
     328  dst: ^Integer;
     329begin
     330  y0 := Cardinal(Loc0) * decompose24 shr 24;
    331331  xComp0 := Loc0 - y0 * G.lx - 1; // Loc0 mod G.lx -1
    332332  xCompSwitch := xComp0 - 1 + y0 and 1;
     
    368368end;
    369369
    370 function Distance(Loc0, Loc1: integer): integer;
    371 var
    372   a, b, dx, dy: integer;
    373 begin
    374   Loc_to_ab(Loc0, Loc1, a, b);
    375   dx := abs(a - b);
    376   dy := abs(a + b);
     370function Distance(Loc0, Loc1: Integer): Integer;
     371var
     372  A, B, dx, dy: Integer;
     373begin
     374  Loc_to_ab(Loc0, Loc1, A, B);
     375  dx := abs(A - B);
     376  dy := abs(A + B);
    377377  Result := dx + dy + abs(dx - dy) shr 1;
    378378end;
     
    381381procedure Init(NewGameData: TNewGameData);
    382382{$IFDEF DEBUG}var
    383   Loc: integer;
     383  Loc: Integer;
    384384{$ENDIF}
    385385begin
     
    389389{$IFDEF DEBUG}
    390390  for Loc := 0 to MapSize - 1 do
    391     assert(cardinal(Loc) * decompose24 shr 24 = cardinal(Loc div G.lx));
     391    Assert(Cardinal(Loc) * decompose24 shr 24 = Cardinal(Loc div G.lx));
    392392{$ENDIF}
    393393end;
    394394
    395395
    396 constructor TCustomAI.Create(Nation: integer);
     396constructor TCustomAI.Create(Nation: Integer);
    397397begin
    398398  inherited Create;
    399   me := Nation;
    400   RO := pointer(G.RO[Nation]);
    401   Map := pointer(RO.Map);
    402   MyUnit := pointer(RO.Un);
    403   MyCity := pointer(RO.City);
    404   MyModel := pointer(RO.Model);
     399  Me := Nation;
     400  RO := Pointer(G.RO[Nation]);
     401  Map := Pointer(RO.Map);
     402  MyUnit := Pointer(RO.Un);
     403  MyCity := Pointer(RO.City);
     404  MyModel := Pointer(RO.Model);
    405405  Opponent := -1;
    406406end;
     
    408408destructor TCustomAI.Destroy;
    409409begin
    410   Server(sSetDebugMap, me, 0, nodata^);
    411 end;
    412 
    413 
    414 procedure TCustomAI.Process(Command: integer; var Data);
    415 var
    416   Nation, NewResearch, NewGov, Count, ad, cix, iix: integer;
     410  Server(sSetDebugMap, Me, 0, nodata^);
     411end;
     412
     413
     414procedure TCustomAI.Process(Command: Integer; var Data);
     415var
     416  Nation, NewResearch, NewGov, Count, ad, cix, iix: Integer;
    417417  NegoTime: TNegoTime;
    418418begin
     
    420420    cTurn, cContinue:
    421421    begin
    422       if RO.Alive and (1 shl me) = 0 then
     422      if RO.Alive and (1 shl Me) = 0 then
    423423      begin // I'm dead, huhu
    424         Server(sTurn, me, 0, nodata^);
    425         exit;
     424        Server(sTurn, Me, 0, nodata^);
     425        Exit;
    426426      end;
    427427      if Command = cTurn then
    428428      begin
    429         fillchar(cixStateImp, sizeof(cixStateImp), $FF);
     429        FillChar(cixStateImp, SizeOf(cixStateImp), $FF);
    430430        for cix := 0 to RO.nCity - 1 do
    431431          if MyCity[cix].Loc >= 0 then
     
    437437          NewGov := ChooseGovernment;
    438438          if NewGov > gAnarchy then
    439             Server(sSetGovernment, me, NewGov, nodata^);
     439            Server(sSetGovernment, Me, NewGov, nodata^);
    440440        end;
    441441        HaveTurned := False;
     
    446446        if OnNegoRejected_CancelTreaty then
    447447          if RO.Treaty[Opponent] >= trPeace then
    448             if Server(sCancelTreaty, me, 0, nodata^) < rExecuted then
    449               assert(False);
     448            if Server(sCancelTreaty, Me, 0, nodata^) < rExecuted then
     449              Assert(False);
    450450      end
    451451      else
     
    459459        if RO.Government <> gAnarchy then
    460460          for Nation := 0 to nPl - 1 do
    461             if (Nation <> me) and (1 shl Nation and RO.Alive <> 0) and
     461            if (Nation <> Me) and (1 shl Nation and RO.Alive <> 0) and
    462462              (RO.Treaty[Nation] >= trNone) and not (Nation in Contacted) and not
    463463              (Nation in UnwantedNego) and
    464               (Server(scContact - sExecute + Nation shl 4, me, 0, nodata^) >= rExecuted) then
     464              (Server(scContact - sExecute + Nation shl 4, Me, 0, nodata^) >= rExecuted) then
    465465              if WantNegotiation(Nation, NegoTime) then
    466466              begin
    467                 if Server(scContact + Nation shl 4, me, 0, nodata^) >= rExecuted then
     467                if Server(scContact + Nation shl 4, Me, 0, nodata^) >= rExecuted then
    468468                begin
    469                   include(Contacted, Nation);
     469                  Include(Contacted, Nation);
    470470                  Opponent := Nation;
    471471                  MyAction := scContact;
    472                   exit;
     472                  Exit;
    473473                end;
    474474              end
    475475              else
    476                 include(UnwantedNego, Nation);
     476                Include(UnwantedNego, Nation);
    477477        if NegoTime = BeginOfTurn then
    478478        begin
     
    483483        end
    484484        else
    485           break;
     485          Break;
    486486      until False;
    487487      if RO.Happened and phTech <> 0 then
     
    499499            end;
    500500        end;
    501         Server(sSetResearch, me, NewResearch, nodata^);
     501        Server(sSetResearch, Me, NewResearch, nodata^);
    502502      end;
    503       if Server(sTurn, me, 0, nodata^) < rExecuted then
    504         assert(False);
     503      if Server(sTurn, Me, 0, nodata^) < rExecuted then
     504        Assert(False);
    505505    end;
    506506    scContact:
    507       if WantNegotiation(integer(Data), EnemyCalled) then
     507      if WantNegotiation(Integer(Data), EnemyCalled) then
    508508      begin
    509         if Server(scDipStart, me, 0, nodata^) < rExecuted then
    510           assert(False);
    511         Opponent := integer(Data);
     509        if Server(scDipStart, Me, 0, nodata^) < rExecuted then
     510          Assert(False);
     511        Opponent := Integer(Data);
    512512        MyAction := scDipStart;
    513513      end
    514514      else
    515515      begin
    516         if Server(scReject, me, 0, nodata^) < rExecuted then
    517           assert(False);
     516        if Server(scReject, Me, 0, nodata^) < rExecuted then
     517          Assert(False);
    518518      end;
    519519    scDipStart, scDipNotice, scDipAccept, scDipCancelTreaty, scDipOffer, scDipBreak:
     
    538538      end;
    539539      DoNegotiation;
    540       assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
     540      Assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
    541541        (MyAction = scDipCancelTreaty) or (MyAction = scDipOffer) or (MyAction = scDipBreak));
    542542      if MyAction = scDipOffer then
    543         Server(MyAction, me, 0, MyOffer)
     543        Server(MyAction, Me, 0, MyOffer)
    544544      else
    545         Server(MyAction, me, 0, nodata^);
     545        Server(MyAction, Me, 0, nodata^);
    546546    end;
    547547    cShowEndContact:
     
    568568
    569569procedure TCustomAI.OnBeforeEnemyAttack(UnitInfo: TUnitInfo;
    570   ToLoc, EndHealth, EndHealthDef: integer);
    571 begin
    572 end;
    573 
    574 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer);
     570  ToLoc, EndHealth, EndHealthDef: Integer);
     571begin
     572end;
     573
     574procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer);
    575575begin
    576576end;
     
    584584end;
    585585
    586 function TCustomAI.ChooseResearchAdvance: integer;
     586function TCustomAI.ChooseResearchAdvance: Integer;
    587587begin
    588588  Result := -1;
    589589end;
    590590
    591 function TCustomAI.ChooseStealAdvance: integer;
     591function TCustomAI.ChooseStealAdvance: Integer;
    592592begin
    593593  Result := -1;
    594594end;
    595595
    596 function TCustomAI.ChooseGovernment: integer;
     596function TCustomAI.ChooseGovernment: Integer;
    597597begin
    598598  Result := gDespotism;
    599599end;
    600600
    601 function TCustomAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;
     601function TCustomAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean;
    602602begin
    603603  Result := False;
    604604end;
    605605
    606 function TCustomAI.OnNegoRejected_CancelTreaty: boolean;
     606function TCustomAI.OnNegoRejected_CancelTreaty: Boolean;
    607607begin
    608608  Result := False;
     
    613613procedure TCustomAI.StealAdvance;
    614614var
    615   Steal, ad, Count: integer;
     615  Steal, ad, Count: Integer;
    616616begin
    617617  Steal := ChooseStealAdvance;
     
    628628  end;
    629629  if Steal >= 0 then
    630     Server(sStealTech, me, Steal, nodata^);
     630    Server(sStealTech, Me, Steal, nodata^);
    631631  RO.Happened := RO.Happened and not phStealTech;
    632632end;
    633633
    634 function TCustomAI.IsResearched(Advance: integer): boolean;
     634function TCustomAI.IsResearched(Advance: Integer): Boolean;
    635635begin
    636636  Result := (Advance = preNone) or (Advance <> preNA) and (RO.Tech[Advance] >= tsApplicable);
    637637end;
    638638
    639 function TCustomAI.ResearchCost: integer;
    640 begin
    641   Server(sGetTechCost, me, 0, Result);
    642 end;
    643 
    644 function TCustomAI.ChangeAttitude(Nation, Attitude: integer): integer;
    645 begin
    646   Result := Server(sSetAttitude + Nation shl 4, me, Attitude, nodata^);
    647 end;
    648 
    649 function TCustomAI.Revolution: integer;
    650 begin
    651   Result := Server(sRevolution, me, 0, nodata^);
    652 end;
    653 
    654 function TCustomAI.ChangeRates(Tax, Lux: integer): integer;
    655 begin
    656   Result := Server(sSetRates, me, Tax div 10 and $f + Lux div 10 and $f shl 4, nodata^);
    657 end;
    658 
    659 function TCustomAI.PrepareNewModel(Domain: integer): integer;
    660 begin
    661   Result := Server(sCreateDevModel, me, Domain, nodata^);
    662 end;
    663 
    664 function TCustomAI.SetNewModelFeature(F, Count: integer): integer;
    665 begin
    666   Result := Server(sSetDevModelCap + Count shl 4, me, F, nodata^);
    667 end;
    668 
    669 function TCustomAI.AdvanceResearchable(Advance: integer): boolean;
    670 begin
    671   Result := Server(sSetResearch - sExecute, me, Advance, nodata^) >= rExecuted;
    672 end;
    673 
    674 function TCustomAI.AdvanceStealable(Advance: integer): boolean;
    675 begin
    676   Result := Server(sStealTech - sExecute, me, Advance, nodata^) >= rExecuted;
    677 end;
    678 
    679 function TCustomAI.GetJobProgress(Loc: integer;
    680   var JobProgress: TJobProgressData): boolean;
    681 begin
    682   Result := Server(sGetJobProgress, me, Loc, JobProgress) >= rExecuted;
    683 end;
    684 
    685 function TCustomAI.DebugMessage(Level: integer; Text: string): boolean;
    686 begin
    687   Text := copy('P' + char(48 + me) + ' ' + Text, 1, 254);
    688   Server(sMessage, me, Level, PChar(Text)^);
     639function TCustomAI.ResearchCost: Integer;
     640begin
     641  Server(sGetTechCost, Me, 0, Result);
     642end;
     643
     644function TCustomAI.ChangeAttitude(Nation, Attitude: Integer): Integer;
     645begin
     646  Result := Server(sSetAttitude + Nation shl 4, Me, Attitude, nodata^);
     647end;
     648
     649function TCustomAI.Revolution: Integer;
     650begin
     651  Result := Server(sRevolution, Me, 0, nodata^);
     652end;
     653
     654function TCustomAI.ChangeRates(Tax, Lux: Integer): Integer;
     655begin
     656  Result := Server(sSetRates, Me, Tax div 10 and $F + Lux div 10 and $F shl 4, nodata^);
     657end;
     658
     659function TCustomAI.PrepareNewModel(Domain: Integer): Integer;
     660begin
     661  Result := Server(sCreateDevModel, Me, Domain, nodata^);
     662end;
     663
     664function TCustomAI.SetNewModelFeature(F, Count: Integer): Integer;
     665begin
     666  Result := Server(sSetDevModelCap + Count shl 4, Me, F, nodata^);
     667end;
     668
     669function TCustomAI.AdvanceResearchable(Advance: Integer): Boolean;
     670begin
     671  Result := Server(sSetResearch - sExecute, Me, Advance, nodata^) >= rExecuted;
     672end;
     673
     674function TCustomAI.AdvanceStealable(Advance: Integer): Boolean;
     675begin
     676  Result := Server(sStealTech - sExecute, Me, Advance, nodata^) >= rExecuted;
     677end;
     678
     679function TCustomAI.GetJobProgress(Loc: Integer;
     680  var JobProgress: TJobProgressData): Boolean;
     681begin
     682  Result := Server(sGetJobProgress, Me, Loc, JobProgress) >= rExecuted;
     683end;
     684
     685function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean;
     686begin
     687  Text := Copy('P' + char(48 + Me) + ' ' + Text, 1, 254);
     688  Server(sMessage, Me, Level, PChar(Text)^);
    689689
    690690  Result := True;
     
    693693end;
    694694
    695 function TCustomAI.SetDebugMap(var DebugMap): boolean;
    696 begin
    697   Server(sSetDebugMap, me, 0, DebugMap);
     695function TCustomAI.SetDebugMap(var DebugMap): Boolean;
     696begin
     697  Server(sSetDebugMap, Me, 0, DebugMap);
    698698
    699699  Result := True;
     
    702702end;
    703703
    704 procedure TCustomAI.Unit_FindMyDefender(Loc: integer; var uix: integer);
    705 begin
    706   if Server(sGetDefender, me, Loc, uix) < rExecuted then
     704procedure TCustomAI.Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     705begin
     706  if Server(sGetDefender, Me, Loc, uix) < rExecuted then
    707707    uix := -1;
    708708end;
    709709
    710 procedure TCustomAI.Unit_FindEnemyDefender(Loc: integer; var euix: integer);
     710procedure TCustomAI.Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
    711711begin
    712712  euix := RO.nEnemyUn - 1;
     
    715715end;
    716716
    717 function TCustomAI.Unit_Move(uix, ToLoc: integer): integer;
    718 var
    719   Step: integer;
    720   DestinationReached: boolean;
     717function TCustomAI.Unit_Move(uix, ToLoc: Integer): Integer;
     718var
     719  Step: Integer;
     720  DestinationReached: Boolean;
    721721  Advice: TMoveAdviceData;
    722722begin
    723   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
     723  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
    724724{Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    725 assert((a<>0) or (b<>0));
    726 if (a>=-1) and (a<=1) and (b>=-1) and (b<=1) then
     725Assert((A<>0) or (B<>0));
     726if (A>=-1) and (A<=1) and (B>=-1) and (B<=1) then
    727727  begin // move to adjacent tile
    728   !!!problem: if move is invalid, return codes are not consistent with other branch (eNoWay)
     728  !!!problem: if Move is invalid, return codes are not consistent with other branch (eNoWay)
    729729  Advice.nStep:=1;
    730   Advice.dx[0]:=a-b;
    731   Advice.dy[0]:=a+b;
     730  Advice.dx[0]:=A-B;
     731  Advice.dy[0]:=A+B;
    732732  Advice.MoreTurns:=0;
    733733  Advice.MaxHostile_MovementLeft:=MyUnit[uix].Movement;
    734   result:=eOK;
     734  Result:=eOK;
    735735  end
    736736else}
     
    739739    Advice.MoreTurns := 9999;
    740740    Advice.MaxHostile_MovementLeft := 100;
    741     Result := Server(sGetMoveAdvice, me, uix, Advice);
     741    Result := Server(sGetMoveAdvice, Me, uix, Advice);
    742742  end;
    743743  if Result = eOk then
     
    755755        begin
    756756          DestinationReached := True;
    757           break;
     757          Break;
    758758        end // stop next to destination
    759759        else if Step = Advice.nStep then
     
    761761
    762762      if (Step = Advice.nStep) or (Result <> eOK) and (Result <> eLoaded) then
    763         break;
     763        Break;
    764764
    765765      Result := Server(sMoveUnit + (Advice.dx[Step] and 7) shl 4 +
    766         (Advice.dy[Step] and 7) shl 7, me, uix, nodata^);
     766        (Advice.dy[Step] and 7) shl 7, Me, uix, nodata^);
    767767      Inc(Step);
    768768      if RO.Happened and phStealTech <> 0 then
     
    779779end;
    780780
    781 function TCustomAI.Unit_Step(uix, ToLoc: integer): integer;
    782 var
    783   a, b: integer;
    784 begin
    785   Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    786   assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
    787   Result := Server(sMoveUnit + ((a - b) and 7) shl 4 + ((a + b) and 7) shl 7, me, uix, nodata^);
     781function TCustomAI.Unit_Step(uix, ToLoc: Integer): Integer;
     782var
     783  A, B: Integer;
     784begin
     785  Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     786  Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
     787  Result := Server(sMoveUnit + ((A - B) and 7) shl 4 + ((A + B) and 7) shl 7, Me, uix, nodata^);
    788788  if RO.Happened and phStealTech <> 0 then
    789789    StealAdvance;
    790790end;
    791791
    792 function TCustomAI.Unit_Attack(uix, ToLoc: integer): integer;
    793 var
    794   a, b: integer;
    795 begin
    796   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     792function TCustomAI.Unit_Attack(uix, ToLoc: Integer): Integer;
     793var
     794  A, B: Integer;
     795begin
     796  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    797797    and ((Map[ToLoc] and (fUnit or fOwned) = fUnit) // is an attack
    798798    or (Map[ToLoc] and (fCity or fOwned) = fCity) and
    799799    (MyModel[MyUnit[uix].mix].Domain <> dGround))); // is a bombardment
    800   Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    801   assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
     800  Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     801  Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
    802802  // attack to adjacent tile
    803   Result := Server(sMoveUnit + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^);
    804 end;
    805 
    806 function TCustomAI.Unit_DoMission(uix, MissionType, ToLoc: integer): integer;
    807 var
    808   a, b: integer;
    809 begin
    810   Result := Server(sSetSpyMission + MissionType shl 4, me, 0, nodata^);
     803  Result := Server(sMoveUnit + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^);
     804end;
     805
     806function TCustomAI.Unit_DoMission(uix, MissionType, ToLoc: Integer): Integer;
     807var
     808  A, B: Integer;
     809begin
     810  Result := Server(sSetSpyMission + MissionType shl 4, Me, 0, nodata^);
    811811  if Result >= rExecuted then
    812812  begin
    813     assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     813    Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    814814      and (MyModel[MyUnit[uix].mix].Kind = mkDiplomat)); // is a commando
    815     Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    816     assert(((a <> 0) or (b <> 0)) and (a >= -1) and (a <= 1) and (b >= -1) and (b <= 1));
     815    Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     816    Assert(((A <> 0) or (B <> 0)) and (A >= -1) and (A <= 1) and (B >= -1) and (B <= 1));
    817817    // city must be adjacent
    818     Result := Server(sMoveUnit - sExecute + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^);
     818    Result := Server(sMoveUnit - sExecute + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^);
    819819    if Result = eMissionDone then
    820       Result := Server(sMoveUnit + (a - b) and 7 shl 4 + (a + b) and 7 shl 7, me, uix, nodata^)
     820      Result := Server(sMoveUnit + (A - B) and 7 shl 4 + (A + B) and 7 shl 7, Me, uix, nodata^)
    821821    else if (Result <> eNoTime_Move) and (Result <> eTreaty) and (Result <> eNoTurn) then
    822822      Result := eInvalid; // not a special commando mission!
     
    824824end;
    825825
    826 function TCustomAI.Unit_MoveForecast(uix, ToLoc: integer;
    827   var RemainingMovement: integer): boolean;
     826function TCustomAI.Unit_MoveForecast(uix, ToLoc: Integer;
     827  var RemainingMovement: Integer): Boolean;
    828828var
    829829  Advice: TMoveAdviceData;
    830830begin
    831   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
     831  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0)); // is a unit
    832832  Advice.ToLoc := ToLoc;
    833833  Advice.MoreTurns := 0;
    834834  Advice.MaxHostile_MovementLeft := 100;
    835   if Server(sGetMoveAdvice, me, uix, Advice) = eOk then
     835  if Server(sGetMoveAdvice, Me, uix, Advice) = eOk then
    836836  begin
    837837    RemainingMovement := Advice.MaxHostile_MovementLeft;
     
    846846
    847847// negative RemainingHealth is remaining helth of defender if lost
    848 function TCustomAI.Unit_AttackForecast(uix, ToLoc, AttackMovement: integer;
    849   var RemainingHealth: integer): boolean;
     848function TCustomAI.Unit_AttackForecast(uix, ToLoc, AttackMovement: Integer;
     849  var RemainingHealth: Integer): Boolean;
    850850var
    851851  BattleForecast: TBattleForecast;
    852852begin
    853   assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
     853  Assert((uix >= 0) and (uix < RO.nUn) and (MyUnit[uix].Loc >= 0) // is a unit
    854854    and (Map[ToLoc] and (fUnit or fOwned) = fUnit)); // is an attack
    855855  RemainingHealth := -$100;
     
    858858    with MyUnit[uix] do
    859859    begin
    860       BattleForecast.pAtt := me;
     860      BattleForecast.pAtt := Me;
    861861      BattleForecast.mixAtt := mix;
    862862      BattleForecast.HealthAtt := Health;
     
    864864      BattleForecast.FlagsAtt := Flags;
    865865      BattleForecast.Movement := AttackMovement;
    866       if Server(sGetBattleForecast, me, ToLoc, BattleForecast) >= rExecuted then
     866      if Server(sGetBattleForecast, Me, ToLoc, BattleForecast) >= rExecuted then
    867867      begin
    868868        if BattleForecast.EndHealthAtt > 0 then
     
    875875end;
    876876
    877 function TCustomAI.Unit_DefenseForecast(euix, ToLoc: integer;
    878   var RemainingHealth: integer): boolean;
     877function TCustomAI.Unit_DefenseForecast(euix, ToLoc: Integer;
     878  var RemainingHealth: Integer): Boolean;
    879879var
    880880  BattleForecast: TBattleForecast;
    881881begin
    882   assert((euix >= 0) and (euix < RO.nEnemyUn) and (RO.EnemyUn[euix].Loc >= 0) // is an enemy unit
     882  Assert((euix >= 0) and (euix < RO.nEnemyUn) and (RO.EnemyUn[euix].Loc >= 0) // is an enemy unit
    883883    and (Map[ToLoc] and (fUnit or fOwned) = (fUnit or fOwned))); // is an attack
    884884  RemainingHealth := $100;
     
    892892    BattleForecast.FlagsAtt := Flags;
    893893    BattleForecast.Movement := 100;
    894     if Server(sGetBattleForecast, me, ToLoc, BattleForecast) >= rExecuted then
     894    if Server(sGetBattleForecast, Me, ToLoc, BattleForecast) >= rExecuted then
    895895    begin
    896896      if BattleForecast.EndHealthDef > 0 then
     
    903903end;
    904904
    905 function TCustomAI.Unit_Disband(uix: integer): integer;
    906 begin
    907   Result := Server(sRemoveUnit, me, uix, nodata^);
    908 end;
    909 
    910 function TCustomAI.Unit_StartJob(uix, NewJob: integer): integer;
    911 begin
    912   Result := Server(sStartJob + NewJob shl 4, me, uix, nodata^);
    913 end;
    914 
    915 function TCustomAI.Unit_SetHomeHere(uix: integer): integer;
    916 begin
    917   Result := Server(sSetUnitHome, me, uix, nodata^);
    918 end;
    919 
    920 function TCustomAI.Unit_Load(uix: integer): integer;
    921 begin
    922   Result := Server(sLoadUnit, me, uix, nodata^);
    923 end;
    924 
    925 function TCustomAI.Unit_Unload(uix: integer): integer;
    926 begin
    927   Result := Server(sUnloadUnit, me, uix, nodata^);
    928 end;
    929 
    930 function TCustomAI.Unit_AddToCity(uix: integer): integer;
    931 begin
    932   Result := Server(sAddToCity, me, uix, nodata^);
    933 end;
    934 
    935 function TCustomAI.Unit_SelectTransport(uix: integer): integer;
    936 begin
    937   Result := Server(sSelectTransport, me, uix, nodata^);
    938 end;
    939 
    940 
    941 procedure TCustomAI.City_FindMyCity(Loc: integer; var cix: integer);
     905function TCustomAI.Unit_Disband(uix: Integer): Integer;
     906begin
     907  Result := Server(sRemoveUnit, Me, uix, nodata^);
     908end;
     909
     910function TCustomAI.Unit_StartJob(uix, NewJob: Integer): Integer;
     911begin
     912  Result := Server(sStartJob + NewJob shl 4, Me, uix, nodata^);
     913end;
     914
     915function TCustomAI.Unit_SetHomeHere(uix: Integer): Integer;
     916begin
     917  Result := Server(sSetUnitHome, Me, uix, nodata^);
     918end;
     919
     920function TCustomAI.Unit_Load(uix: Integer): Integer;
     921begin
     922  Result := Server(sLoadUnit, Me, uix, nodata^);
     923end;
     924
     925function TCustomAI.Unit_Unload(uix: Integer): Integer;
     926begin
     927  Result := Server(sUnloadUnit, Me, uix, nodata^);
     928end;
     929
     930function TCustomAI.Unit_AddToCity(uix: Integer): Integer;
     931begin
     932  Result := Server(sAddToCity, Me, uix, nodata^);
     933end;
     934
     935function TCustomAI.Unit_SelectTransport(uix: Integer): Integer;
     936begin
     937  Result := Server(sSelectTransport, Me, uix, nodata^);
     938end;
     939
     940
     941procedure TCustomAI.City_FindMyCity(Loc: Integer; var cix: Integer);
    942942begin
    943943  if Map[Loc] and (fCity or fOwned) <> fCity or fOwned then
     
    951951end;
    952952
    953 procedure TCustomAI.City_FindEnemyCity(Loc: integer; var ecix: integer);
     953procedure TCustomAI.City_FindEnemyCity(Loc: Integer; var ecix: Integer);
    954954begin
    955955  if Map[Loc] and (fCity or fOwned) <> fCity then
     
    963963end;
    964964
    965 function TCustomAI.City_HasProject(cix: integer): boolean;
     965function TCustomAI.City_HasProject(cix: Integer): Boolean;
    966966begin
    967967  Result := MyCity[cix].Project and (cpImp + cpIndex) <> cpImp + imTrGoods;
    968968end;
    969969
    970 function TCustomAI.City_CurrentImprovementProject(cix: integer): integer;
     970function TCustomAI.City_CurrentImprovementProject(cix: Integer): Integer;
    971971begin
    972972  if MyCity[cix].Project and cpImp = 0 then
     
    980980end;
    981981
    982 function TCustomAI.City_CurrentUnitProject(cix: integer): integer;
     982function TCustomAI.City_CurrentUnitProject(cix: Integer): Integer;
    983983begin
    984984  if MyCity[cix].Project and cpImp <> 0 then
     
    988988end;
    989989
    990 function TCustomAI.City_GetTileInfo(cix, TileLoc: integer;
    991   var TileInfo: TTileInfo): integer;
     990function TCustomAI.City_GetTileInfo(cix, TileLoc: Integer;
     991  var TileInfo: TTileInfo): Integer;
    992992begin
    993993  TileInfo.ExplCity := cix;
    994   Result := Server(sGetHypoCityTileInfo, me, TileLoc, TileInfo);
    995 end;
    996 
    997 function TCustomAI.City_GetReport(cix: integer; var Report: TCityReport): integer;
     994  Result := Server(sGetHypoCityTileInfo, Me, TileLoc, TileInfo);
     995end;
     996
     997function TCustomAI.City_GetReport(cix: Integer; var Report: TCityReport): Integer;
    998998begin
    999999  Report.HypoTiles := -1;
    10001000  Report.HypoTax := -1;
    10011001  Report.HypoLux := -1;
    1002   Result := Server(sGetCityReport, me, cix, Report);
    1003 end;
    1004 
    1005 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;
    1006   var Report: TCityReport): integer;
     1002  Result := Server(sGetCityReport, Me, cix, Report);
     1003end;
     1004
     1005function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer;
     1006  var Report: TCityReport): Integer;
    10071007begin
    10081008  Report.HypoTiles := HypoTiles;
    10091009  Report.HypoTax := HypoTax;
    10101010  Report.HypoLux := HypoLux;
    1011   Result := Server(sGetCityReport, me, cix, Report);
    1012 end;
    1013 
    1014 function TCustomAI.City_GetReportNew(cix: integer; var Report: TCityReportNew): integer;
     1011  Result := Server(sGetCityReport, Me, cix, Report);
     1012end;
     1013
     1014function TCustomAI.City_GetReportNew(cix: Integer; var Report: TCityReportNew): Integer;
    10151015begin
    10161016  Report.HypoTiles := -1;
    10171017  Report.HypoTaxRate := -1;
    10181018  Report.HypoLuxuryRate := -1;
    1019   Result := Server(sGetCityReportNew, me, cix, Report);
     1019  Result := Server(sGetCityReportNew, Me, cix, Report);
    10201020end;
    10211021
    10221022function TCustomAI.City_GetHypoReportNew(cix, HypoTiles, HypoTaxRate,
    1023   HypoLuxuryRate: integer; var Report: TCityReportNew): integer;
     1023  HypoLuxuryRate: Integer; var Report: TCityReportNew): Integer;
    10241024begin
    10251025  Report.HypoTiles := HypoTiles;
    10261026  Report.HypoTaxRate := HypoTaxRate;
    10271027  Report.HypoLuxuryRate := HypoLuxuryRate;
    1028   Result := Server(sGetCityReportNew, me, cix, Report);
    1029 end;
    1030 
    1031 function TCustomAI.City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    1032 begin
    1033   Result := Server(sGetCityAreaInfo, me, cix, AreaInfo);
    1034 end;
    1035 
    1036 function TCustomAI.City_StartUnitProduction(cix, mix: integer): integer;
     1028  Result := Server(sGetCityReportNew, Me, cix, Report);
     1029end;
     1030
     1031function TCustomAI.City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     1032begin
     1033  Result := Server(sGetCityAreaInfo, Me, cix, AreaInfo);
     1034end;
     1035
     1036function TCustomAI.City_StartUnitProduction(cix, mix: Integer): Integer;
    10371037begin
    10381038  if (MyCity[cix].Project and (cpImp + cpIndex) <> mix) then
    10391039    // not already producing that
    1040     Result := Server(sSetCityProject, me, cix, mix);
    1041 end;
    1042 
    1043 function TCustomAI.City_StartEmigration(cix, mix: integer;
    1044   AllowDisbandCity, AsConscripts: boolean): integer;
    1045 var
    1046   NewProject: integer;
     1040    Result := Server(sSetCityProject, Me, cix, mix);
     1041end;
     1042
     1043function TCustomAI.City_StartEmigration(cix, mix: Integer;
     1044  AllowDisbandCity, AsConscripts: Boolean): Integer;
     1045var
     1046  NewProject: Integer;
    10471047begin
    10481048  NewProject := mix;
     
    10511051  if AsConscripts then
    10521052    NewProject := NewProject or cpConscripts;
    1053   Result := Server(sSetCityProject, me, cix, NewProject);
    1054 end;
    1055 
    1056 function TCustomAI.City_StartImprovement(cix, iix: integer): integer;
    1057 var
    1058   NewProject: integer;
     1053  Result := Server(sSetCityProject, Me, cix, NewProject);
     1054end;
     1055
     1056function TCustomAI.City_StartImprovement(cix, iix: Integer): Integer;
     1057var
     1058  NewProject: Integer;
    10591059begin
    10601060  NewProject := iix + cpImp;
    10611061  if (MyCity[cix].Project and (cpImp + cpIndex) <> NewProject) then
    10621062    // not already producing that
    1063     Result := Server(sSetCityProject, me, cix, NewProject);
    1064 end;
    1065 
    1066 function TCustomAI.City_Improvable(cix, iix: integer): boolean;
    1067 var
    1068   NewProject: integer;
     1063    Result := Server(sSetCityProject, Me, cix, NewProject);
     1064end;
     1065
     1066function TCustomAI.City_Improvable(cix, iix: Integer): Boolean;
     1067var
     1068  NewProject: Integer;
    10691069begin
    10701070  NewProject := iix + cpImp;
    1071   Result := Server(sSetCityProject - sExecute, me, cix, NewProject) >= rExecuted;
    1072 end;
    1073 
    1074 function TCustomAI.City_StopProduction(cix: integer): integer;
    1075 var
    1076   NewProject: integer;
     1071  Result := Server(sSetCityProject - sExecute, Me, cix, NewProject) >= rExecuted;
     1072end;
     1073
     1074function TCustomAI.City_StopProduction(cix: Integer): Integer;
     1075var
     1076  NewProject: Integer;
    10771077begin
    10781078  NewProject := imTrGoods + cpImp;
    1079   Result := Server(sSetCityProject, me, cix, NewProject);
    1080 end;
    1081 
    1082 function TCustomAI.City_BuyProject(cix: integer): integer;
    1083 begin
    1084   Result := Server(sBuyCityProject, me, cix, nodata^);
    1085 end;
    1086 
    1087 function TCustomAI.City_SellImprovement(cix, iix: integer): integer;
    1088 begin
    1089   Result := Server(sSellCityImprovement, me, cix, iix);
    1090 end;
    1091 
    1092 function TCustomAI.City_RebuildImprovement(cix, iix: integer): integer;
    1093 begin
    1094   Result := Server(sRebuildCityImprovement, me, cix, iix);
    1095 end;
    1096 
    1097 function TCustomAI.City_SetTiles(cix, NewTiles: integer): integer;
    1098 begin
    1099   Result := Server(sSetCityTiles, me, cix, NewTiles);
    1100 end;
    1101 
    1102 procedure TCustomAI.City_OptimizeTiles(cix: integer; ResourceWeights: cardinal);
     1079  Result := Server(sSetCityProject, Me, cix, NewProject);
     1080end;
     1081
     1082function TCustomAI.City_BuyProject(cix: Integer): Integer;
     1083begin
     1084  Result := Server(sBuyCityProject, Me, cix, nodata^);
     1085end;
     1086
     1087function TCustomAI.City_SellImprovement(cix, iix: Integer): Integer;
     1088begin
     1089  Result := Server(sSellCityImprovement, Me, cix, iix);
     1090end;
     1091
     1092function TCustomAI.City_RebuildImprovement(cix, iix: Integer): Integer;
     1093begin
     1094  Result := Server(sRebuildCityImprovement, Me, cix, iix);
     1095end;
     1096
     1097function TCustomAI.City_SetTiles(cix, NewTiles: Integer): Integer;
     1098begin
     1099  Result := Server(sSetCityTiles, Me, cix, NewTiles);
     1100end;
     1101
     1102procedure TCustomAI.City_OptimizeTiles(cix: Integer; ResourceWeights: Cardinal);
    11031103var
    11041104  Advice: TCityTileAdviceData;
    11051105begin
    11061106  Advice.ResourceWeights := ResourceWeights;
    1107   Server(sGetCityTileAdvice, me, cix, Advice);
     1107  Server(sGetCityTileAdvice, Me, cix, Advice);
    11081108  City_SetTiles(cix, Advice.Tiles);
    11091109end;
     
    11111111
    11121112// negotiation
    1113 function TCustomAI.Nego_CheckMyAction: integer;
    1114 begin
    1115   assert(Opponent >= 0); // only allowed in negotiation mode
    1116   assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
     1113function TCustomAI.Nego_CheckMyAction: Integer;
     1114begin
     1115  Assert(Opponent >= 0); // only allowed in negotiation mode
     1116  Assert((MyAction = scDipNotice) or (MyAction = scDipAccept) or
    11171117    (MyAction = scDipCancelTreaty) or (MyAction = scDipOffer) or (MyAction = scDipBreak));
    11181118  if MyAction = scDipOffer then
    1119     Result := Server(MyAction - sExecute, me, 0, MyOffer)
     1119    Result := Server(MyAction - sExecute, Me, 0, MyOffer)
    11201120  else
    1121     Result := Server(MyAction - sExecute, me, 0, nodata^);
     1121    Result := Server(MyAction - sExecute, Me, 0, nodata^);
    11221122end;
    11231123
    11241124
    11251125initialization
    1126   nodata := pointer(0);
     1126  nodata := Pointer(0);
    11271127  RWDataSize := 0;
    11281128
  • branches/highdpi/AI/StdAI/CustomAI_Reload.pas

    r210 r465  
    1313TCustomAI=class
    1414public
    15   procedure Process(Command: integer; var Data);
     15  procedure Process(Command: Integer; var Data);
    1616
    1717  // overridables
    18   constructor Create(Nation: integer); virtual;
     18  constructor Create(Nation: Integer); virtual;
    1919  destructor Destroy; override;
    2020  procedure SetDataDefaults; virtual;
    2121  procedure SetDataRandom; virtual;
    2222  procedure OnBeforeEnemyAttack(UnitInfo: TUnitInfo;
    23     ToLoc, EndHealth, EndHealthDef: integer); virtual;
    24   procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer); virtual;
     23    ToLoc, EndHealth, EndHealthDef: Integer); virtual;
     24  procedure OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer); virtual;
    2525  procedure OnAfterEnemyAttack; virtual;
    2626  procedure OnAfterEnemyCapture; virtual;
    2727
    2828protected
    29   me: integer; // index of the controlled nation
     29  Me: Integer; // index of the controlled nation
    3030  RO: ^TPlayerContext;
    3131  Map: ^TTileList;
     
    3434  MyModel: ^TModelList;
    3535
    36   cixStateImp: array[imPalace..imSpacePort] of integer;
     36  cixStateImp: array[imPalace..imSpacePort] of Integer;
    3737
    3838  // negotiation
    39   Opponent: integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode
    40   MyAction, MyLastAction, OppoAction: integer;
     39  Opponent: Integer; // nation i'm in negotiation with, -1 indicates no-negotiation mode
     40  MyAction, MyLastAction, OppoAction: Integer;
    4141  MyOffer, MyLastOffer, OppoOffer: TOffer;
    4242
     
    4444  procedure DoTurn; virtual;
    4545  procedure DoNegotiation; virtual;
    46   function ChooseResearchAdvance: integer; virtual;
    47   function ChooseStealAdvance: integer; virtual;
    48   function ChooseGovernment: integer; virtual;
    49   function WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean; virtual;
    50   function OnNegoRejected_CancelTreaty: boolean; virtual;
     46  function ChooseResearchAdvance: Integer; virtual;
     47  function ChooseStealAdvance: Integer; virtual;
     48  function ChooseGovernment: Integer; virtual;
     49  function WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean; virtual;
     50  function OnNegoRejected_CancelTreaty: Boolean; virtual;
    5151
    5252  // general functions
    53   function IsResearched(Advance: integer): boolean;
    54   function ResearchCost: integer;
    55   function ChangeAttitude(Nation, Attitude: integer): integer;
    56   function Revolution: integer;
    57   function ChangeRates(Tax,Lux: integer): integer;
    58   function PrepareNewModel(Domain: integer): integer;
    59   function SetNewModelFeature(F, Count: integer): integer;
    60   function AdvanceResearchable(Advance: integer): boolean;
    61   function AdvanceStealable(Advance: integer): boolean;
    62   function DebugMessage(Level: integer; Text: string): boolean;
    63   function SetDebugMap(var DebugMap): boolean;
     53  function IsResearched(Advance: Integer): Boolean;
     54  function ResearchCost: Integer;
     55  function ChangeAttitude(Nation, Attitude: Integer): Integer;
     56  function Revolution: Integer;
     57  function ChangeRates(Tax,Lux: Integer): Integer;
     58  function PrepareNewModel(Domain: Integer): Integer;
     59  function SetNewModelFeature(F, Count: Integer): Integer;
     60  function AdvanceResearchable(Advance: Integer): Boolean;
     61  function AdvanceStealable(Advance: Integer): Boolean;
     62  function DebugMessage(Level: Integer; Text: string): Boolean;
     63  function SetDebugMap(var DebugMap): Boolean;
    6464
    6565  // unit functions
    66   procedure Unit_FindMyDefender(Loc: integer; var uix: integer);
    67   procedure Unit_FindEnemyDefender(Loc: integer; var euix: integer);
    68   function Unit_Move(uix,ToLoc: integer): integer;
    69   function Unit_Step(uix,ToLoc: integer): integer;
    70   function Unit_Attack(uix,ToLoc: integer): integer;
    71   function Unit_DoMission(uix,MissionType,ToLoc: integer): integer;
    72   function Unit_MoveForecast(uix,ToLoc: integer; var RemainingMovement: integer): boolean;
    73   function Unit_AttackForecast(uix,ToLoc,AttackMovement: integer; var RemainingHealth: integer): boolean;
    74   function Unit_DefenseForecast(euix,ToLoc: integer; var RemainingHealth: integer): boolean;
    75   function Unit_Disband(uix: integer): integer;
    76   function Unit_StartJob(uix,NewJob: integer): integer;
    77   function Unit_SetHomeHere(uix: integer): integer;
    78   function Unit_Load(uix: integer): integer;
    79   function Unit_Unload(uix: integer): integer;
    80   function Unit_AddToCity(uix: integer): integer;
     66  procedure Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     67  procedure Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
     68  function Unit_Move(uix,ToLoc: Integer): Integer;
     69  function Unit_Step(uix,ToLoc: Integer): Integer;
     70  function Unit_Attack(uix,ToLoc: Integer): Integer;
     71  function Unit_DoMission(uix,MissionType,ToLoc: Integer): Integer;
     72  function Unit_MoveForecast(uix,ToLoc: Integer; var RemainingMovement: Integer): Boolean;
     73  function Unit_AttackForecast(uix,ToLoc,AttackMovement: Integer; var RemainingHealth: Integer): Boolean;
     74  function Unit_DefenseForecast(euix,ToLoc: Integer; var RemainingHealth: Integer): Boolean;
     75  function Unit_Disband(uix: Integer): Integer;
     76  function Unit_StartJob(uix,NewJob: Integer): Integer;
     77  function Unit_SetHomeHere(uix: Integer): Integer;
     78  function Unit_Load(uix: Integer): Integer;
     79  function Unit_Unload(uix: Integer): Integer;
     80  function Unit_AddToCity(uix: Integer): Integer;
    8181
    8282  // city functions
    83   procedure City_FindMyCity(Loc: integer; var cix: integer);
    84   procedure City_FindEnemyCity(Loc: integer; var ecix: integer);
    85   function City_HasProject(cix: integer): boolean;
    86   function City_CurrentImprovementProject(cix: integer): integer;
    87   function City_CurrentUnitProject(cix: integer): integer;
    88   function City_GetTileInfo(cix,TileLoc: integer; var TileInfo: TTileInfo): integer;
    89   function City_GetReport(cix: integer; var Report: TCityReport): integer;
    90   function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer; var Report: TCityReport): integer;
    91   function City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    92   function City_StartUnitProduction(cix,mix: integer): integer;
    93   function City_StartEmigration(cix,mix: integer; AllowDisbandCity, AsConscripts: boolean): integer;
    94   function City_StartImprovement(cix,iix: integer): integer;
    95   function City_Improvable(cix,iix: integer): boolean;
    96   function City_StopProduction(cix: integer): integer;
    97   function City_BuyProject(cix: integer): integer;
    98   function City_SellImprovement(cix,iix: integer): integer;
    99   function City_RebuildImprovement(cix,iix: integer): integer;
    100   function City_SetTiles(cix,NewTiles: integer): integer;
     83  procedure City_FindMyCity(Loc: Integer; var cix: Integer);
     84  procedure City_FindEnemyCity(Loc: Integer; var ecix: Integer);
     85  function City_HasProject(cix: Integer): Boolean;
     86  function City_CurrentImprovementProject(cix: Integer): Integer;
     87  function City_CurrentUnitProject(cix: Integer): Integer;
     88  function City_GetTileInfo(cix,TileLoc: Integer; var TileInfo: TTileInfo): Integer;
     89  function City_GetReport(cix: Integer; var Report: TCityReport): Integer;
     90  function City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer; var Report: TCityReport): Integer;
     91  function City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     92  function City_StartUnitProduction(cix,mix: Integer): Integer;
     93  function City_StartEmigration(cix,mix: Integer; AllowDisbandCity, AsConscripts: Boolean): Integer;
     94  function City_StartImprovement(cix,iix: Integer): Integer;
     95  function City_Improvable(cix,iix: Integer): Boolean;
     96  function City_StopProduction(cix: Integer): Integer;
     97  function City_BuyProject(cix: Integer): Integer;
     98  function City_SellImprovement(cix,iix: Integer): Integer;
     99  function City_RebuildImprovement(cix,iix: Integer): Integer;
     100  function City_SetTiles(cix,NewTiles: Integer): Integer;
    101101
    102102  // negotiation
    103   function Nego_CheckMyAction: integer;
     103  function Nego_CheckMyAction: Integer;
    104104
    105105private
    106   HaveTurned: boolean;
     106  HaveTurned: Boolean;
    107107  UnwantedNego: set of 0..nPl-1;
    108108  Contacted: set of 0..nPl-1;
     
    114114Server: TServerCall;
    115115G: TNewGameData;
    116 RWDataSize, MapSize: integer;
    117 decompose24: cardinal;
    118 nodata: pointer;
     116RWDataSize, MapSize: Integer;
     117decompose24: Cardinal;
     118nodata: Pointer;
    119119
    120120const
     
    126126
    127127type
    128 TVicinity8Loc=array[0..7] of integer;
    129 TVicinity21Loc=array[0..27] of integer;
     128TVicinity8Loc=array[0..7] of Integer;
     129TVicinity21Loc=array[0..27] of Integer;
    130130
    131131
    132132procedure Init(NewGameData: TNewGameData);
    133133
    134 procedure ab_to_Loc(Loc0,a,b: integer; var Loc: integer);
    135 procedure Loc_to_ab(Loc0,Loc: integer; var a,b: integer);
    136 procedure ab_to_V8(a,b: integer; var V8: integer);
    137 procedure V8_to_ab(V8: integer; var a,b: integer);
    138 procedure ab_to_V21(a,b: integer; var V21: integer);
    139 procedure V21_to_ab(V21: integer; var a,b: integer);
    140 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    141 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
     134procedure ab_to_Loc(Loc0,A,B: Integer; var Loc: Integer);
     135procedure Loc_to_ab(Loc0,Loc: Integer; var A,B: Integer);
     136procedure ab_to_V8(A,B: Integer; var V8: Integer);
     137procedure V8_to_ab(V8: Integer; var A,B: Integer);
     138procedure ab_to_V21(A,B: Integer; var V21: Integer);
     139procedure V21_to_ab(V21: Integer; var A,B: Integer);
     140procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     141procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
    142142
    143143
     
    145145
    146146const
    147 ab_v8: array[-4..4] of integer = (5,6,7,4,-1,0,3,2,1);
    148 v8_a: array[0..7] of integer = (1,1,0,-1,-1,-1,0,1);
    149 v8_b: array[0..7] of integer = (0,1,1,1,0,-1,-1,-1);
    150 
    151 
    152 procedure ab_to_Loc(Loc0,a,b: integer; var Loc: integer);
     147ab_v8: array[-4..4] of Integer = (5,6,7,4,-1,0,3,2,1);
     148v8_a: array[0..7] of Integer = (1,1,0,-1,-1,-1,0,1);
     149v8_b: array[0..7] of Integer = (0,1,1,1,0,-1,-1,-1);
     150
     151
     152procedure ab_to_Loc(Loc0,A,B: Integer; var Loc: Integer);
    153153{relative location from Loc0}
    154154var
    155 y0: integer;
    156 begin
    157 assert((Loc0>=0) and (Loc0<MapSize) and (a-b+G.lx>=0));
    158 y0:=cardinal(Loc0)*decompose24 shr 24;
    159 Loc:=(Loc0+(a-b+y0 and 1+G.lx+G.lx) shr 1) mod G.lx +G.lx*(y0+a+b);
     155y0: Integer;
     156begin
     157Assert((Loc0>=0) and (Loc0<MapSize) and (A-B+G.lx>=0));
     158y0:=Cardinal(Loc0)*decompose24 shr 24;
     159Loc:=(Loc0+(A-B+y0 and 1+G.lx+G.lx) shr 1) mod G.lx +G.lx*(y0+A+B);
    160160if Loc>=MapSize then Loc:=-$1000
    161161end;
    162162
    163 procedure Loc_to_ab(Loc0,Loc: integer; var a,b: integer);
     163procedure Loc_to_ab(Loc0,Loc: Integer; var A,B: Integer);
    164164{$IFDEF FPC} // freepascal
    165165var
    166 dx,dy: integer;
     166dx,dy: Integer;
    167167begin
    168168dx:=((Loc mod G.lx *2 +Loc div G.lx and 1)
    169169  -(Loc0 mod G.lx *2 +Loc0 div G.lx and 1)+3*G.lx) mod (2*G.lx) -G.lx;
    170170dy:=Loc div G.lx-Loc0 div G.lx;
    171 a:=(dx+dy) div 2;
    172 b:=(dy-dx) div 2;
     171A:=(dx+dy) div 2;
     172B:=(dy-dx) div 2;
    173173end;
    174174{$ELSE} // delphi
     
    179179// calculate
    180180push ecx
    181 div byte ptr [G]
     181div Byte ptr [G]
    182182xor ebx,ebx
    183183mov bl,ah  // ebx:=Loc0 mod G.lx
     
    185185and ecx,$000000FF // ecx:=Loc0 div G.lx
    186186mov eax,edx
    187 div byte ptr [G]
     187div Byte ptr [G]
    188188xor edx,edx
    189189mov dl,ah // edx:=Loc mod G.lx
     
    202202mov edx,dword ptr [G]
    203203cmp eax,edx
    204 jl @a
     204jl @A
    205205  sub eax,edx
    206206  sub eax,edx
    207207  jmp @ok
    208 @a:
     208@A:
    209209neg edx
    210210cmp eax,edx
     
    219219add eax,ebx
    220220sar edx,1 // edx:=b
    221 mov ebx,[b]
     221mov ebx,[B]
    222222mov [ebx],edx
    223223sar eax,1 // eax:=a
    224 mov [a],eax
     224mov [A],eax
    225225
    226226pop ebx
     
    228228{$ENDIF}
    229229
    230 procedure ab_to_V8(a,b: integer; var V8: integer);
    231 begin
    232 assert((abs(a)<=1) and (abs(b)<=1) and ((a<>0) or (b<>0)));
    233 V8:=ab_v8[2*b+b+a];
    234 end;
    235 
    236 procedure V8_to_ab(V8: integer; var a,b: integer);
    237 begin
    238 a:=v8_a[V8]; b:=V8_b[V8];
    239 end;
    240 
    241 procedure ab_to_V21(a,b: integer; var V21: integer);
    242 begin
    243 V21:=(a+b+3) shl 2+(a-b+3) shr 1;
    244 end;
    245 
    246 procedure V21_to_ab(V21: integer; var a,b: integer);
    247 var
    248 dx,dy: integer;
     230procedure ab_to_V8(A,B: Integer; var V8: Integer);
     231begin
     232Assert((abs(A)<=1) and (abs(B)<=1) and ((A<>0) or (B<>0)));
     233V8:=ab_v8[2*B+B+A];
     234end;
     235
     236procedure V8_to_ab(V8: Integer; var A,B: Integer);
     237begin
     238A:=v8_a[V8]; B:=V8_b[V8];
     239end;
     240
     241procedure ab_to_V21(A,B: Integer; var V21: Integer);
     242begin
     243V21:=(A+B+3) shl 2+(A-B+3) shr 1;
     244end;
     245
     246procedure V21_to_ab(V21: Integer; var A,B: Integer);
     247var
     248dx,dy: Integer;
    249249begin
    250250dy:=V21 shr 2-3;
    251251dx:=V21 and 3 shl 1 -3 + (dy+3) and 1;
    252 a:=(dx+dy) div 2;
    253 b:=(dy-dx) div 2;
    254 end;
    255 
    256 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    257 var
    258 x0,y0,lx: integer;
     252A:=(dx+dy) div 2;
     253B:=(dy-dx) div 2;
     254end;
     255
     256procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     257var
     258x0,y0,lx: Integer;
    259259begin
    260260lx:=G.lx;
    261 y0:=cardinal(Loc0)*decompose24 shr 24;
     261y0:=Cardinal(Loc0)*decompose24 shr 24;
    262262x0:=Loc0-y0*lx; // Loc0 mod lx;
    263263VicinityLoc[1]:=Loc0+lx*2;
     
    265265VicinityLoc[5]:=Loc0-lx*2;
    266266VicinityLoc[7]:=Loc0+1;
    267 inc(Loc0,y0 and 1);
     267Inc(Loc0,y0 and 1);
    268268VicinityLoc[0]:=Loc0+lx;
    269269VicinityLoc[2]:=Loc0+lx-1;
     
    276276  if x0=0 then
    277277    begin
    278     inc(VicinityLoc[3],lx);
     278    Inc(VicinityLoc[3],lx);
    279279    if y0 and 1=0 then
    280280      begin
    281       inc(VicinityLoc[2],lx);
    282       inc(VicinityLoc[4],lx);
     281      Inc(VicinityLoc[2],lx);
     282      Inc(VicinityLoc[4],lx);
    283283      end
    284284    end
     
    286286else
    287287  begin
    288   dec(VicinityLoc[7],lx);
     288  Dec(VicinityLoc[7],lx);
    289289  if y0 and 1=1 then
    290290    begin
    291     dec(VicinityLoc[0],lx);
    292     dec(VicinityLoc[6],lx);
     291    Dec(VicinityLoc[0],lx);
     292    Dec(VicinityLoc[6],lx);
    293293    end
    294294  end;
     
    306306end;
    307307
    308 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    309 var
    310 dx,dy,bit,y0,xComp,yComp,xComp0,xCompSwitch: integer;
    311 dst: ^integer;
    312 begin
    313 y0:=cardinal(Loc0)*decompose24 shr 24;
     308procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
     309var
     310dx,dy,bit,y0,xComp,yComp,xComp0,xCompSwitch: Integer;
     311dst: ^Integer;
     312begin
     313y0:=Cardinal(Loc0)*decompose24 shr 24;
    314314xComp0:=Loc0-y0*G.lx-1; // Loc0 mod G.lx -1
    315315xCompSwitch:=xComp0-1+y0 and 1;
    316 if xComp0<0 then inc(xComp0,G.lx);
    317 if xCompSwitch<0 then inc(xCompSwitch,G.lx);
     316if xComp0<0 then Inc(xComp0,G.lx);
     317if xCompSwitch<0 then Inc(xCompSwitch,G.lx);
    318318xCompSwitch:=xCompSwitch xor xComp0;
    319319yComp:=G.lx*(y0-3);
     
    329329      if bit and $67F7F76<>0 then dst^:=xComp+yComp
    330330      else dst^:=-1;
    331       inc(xComp);
    332       if xComp>=G.lx then dec(xComp, G.lx);
    333       inc(dst);
     331      Inc(xComp);
     332      if xComp>=G.lx then Dec(xComp, G.lx);
     333      Inc(dst);
    334334      bit:=bit shl 1;
    335335      end;
    336     inc(yComp,G.lx);
     336    Inc(yComp,G.lx);
    337337    end
    338338  else
    339339    begin
    340340    for dx:=0 to 3 do
    341       begin dst^:=-$1000; inc(dst); end;
     341      begin dst^:=-$1000; Inc(dst); end;
    342342    end
    343343end;
     
    345345
    346346procedure Init(NewGameData: TNewGameData);
    347 {$IFDEF DEBUG}var Loc: integer;{$ENDIF}
     347{$IFDEF DEBUG}var Loc: Integer;{$ENDIF}
    348348begin
    349349G:=NewGameData;
    350350MapSize:=G.lx*G.ly;
    351351decompose24:=(1 shl 24-1) div G.lx +1;
    352 {$IFDEF DEBUG}for Loc:=0 to MapSize-1 do assert(cardinal(Loc)*decompose24 shr 24=cardinal(Loc div G.lx));{$ENDIF}
    353 end;
    354 
    355 
    356 constructor TCustomAI.Create(Nation: integer);
     352{$IFDEF DEBUG}for Loc:=0 to MapSize-1 do Assert(Cardinal(Loc)*decompose24 shr 24=Cardinal(Loc div G.lx));{$ENDIF}
     353end;
     354
     355
     356constructor TCustomAI.Create(Nation: Integer);
    357357begin
    358358inherited Create;
    359 me:=Nation;
    360 RO:=pointer(G.RO[Nation]);
    361 Map:=pointer(RO.Map);
    362 MyUnit:=pointer(RO.Un);
    363 MyCity:=pointer(RO.City);
    364 MyModel:=pointer(RO.Model);
     359Me:=Nation;
     360RO:=Pointer(G.RO[Nation]);
     361Map:=Pointer(RO.Map);
     362MyUnit:=Pointer(RO.Un);
     363MyCity:=Pointer(RO.City);
     364MyModel:=Pointer(RO.Model);
    365365Opponent:=-1;
    366366end;
     
    368368destructor TCustomAI.Destroy;
    369369begin
    370 Server(sSetDebugMap,me,0,nodata^);
    371 end;
    372 
    373 
    374 procedure TCustomAI.Process(Command: integer; var Data);
    375 var
    376 Nation,NewResearch,NewGov,count,ad,cix,iix: integer;
     370Server(sSetDebugMap,Me,0,nodata^);
     371end;
     372
     373
     374procedure TCustomAI.Process(Command: Integer; var Data);
     375var
     376Nation,NewResearch,NewGov,count,ad,cix,iix: Integer;
    377377NegoTime: TNegoTime;
    378378begin
     
    380380  cTurn, cContinue:
    381381    begin
    382     if RO.Alive and (1 shl me)=0 then
     382    if RO.Alive and (1 shl Me)=0 then
    383383      begin // I'm dead, huhu
    384       Server(sTurn,me,0,nodata^);
    385       exit
     384      Server(sTurn,Me,0,nodata^);
     385      Exit
    386386      end;
    387387    if Command=cTurn then
    388388      begin
    389       fillchar(cixStateImp, sizeof(cixStateImp), $FF);
     389      FillChar(cixStateImp, SizeOf(cixStateImp), $FF);
    390390      for cix:=0 to RO.nCity-1 do if MyCity[cix].Loc>=0 then
    391391        for iix:=imPalace to imSpacePort do
     
    396396        NewGov:=ChooseGovernment;
    397397        if NewGov>gAnarchy then
    398           Server(sSetGovernment,me,NewGov,nodata^);
     398          Server(sSetGovernment,Me,NewGov,nodata^);
    399399        end;
    400       HaveTurned:=false;
     400      HaveTurned:=False;
    401401      Contacted:=[];
    402402      end;
     
    405405      if OnNegoRejected_CancelTreaty then
    406406        if RO.Treaty[Opponent]>=trPeace then
    407           if Server(sCancelTreaty,me,0,nodata^)<rExecuted then
    408             assert(false)
     407          if Server(sCancelTreaty,Me,0,nodata^)<rExecuted then
     408            Assert(False)
    409409      end
    410410    else UnwantedNego:=[];
     
    415415      if RO.Government<>gAnarchy then
    416416        for Nation:=0 to nPl-1 do
    417            if (Nation<>me) and (1 shl Nation and RO.Alive<>0)
     417           if (Nation<>Me) and (1 shl Nation and RO.Alive<>0)
    418418             and (RO.Treaty[Nation]>=trNone)
    419419             and not (Nation in Contacted) and not (Nation in UnwantedNego)
    420              and (Server(scContact-sExecute + Nation shl 4, me, 0, nodata^)>=rExecuted) then
     420             and (Server(scContact-sExecute + Nation shl 4, Me, 0, nodata^)>=rExecuted) then
    421421             if WantNegotiation(Nation, NegoTime) then
    422422               begin
    423                if Server(scContact + Nation shl 4, me, 0, nodata^)>=rExecuted then
     423               if Server(scContact + Nation shl 4, Me, 0, nodata^)>=rExecuted then
    424424                 begin
    425                  include(Contacted, Nation);
     425                 Include(Contacted, Nation);
    426426                 Opponent:=Nation;
    427427                 MyAction:=scContact;
    428                  exit;
     428                 Exit;
    429429                 end;
    430430               end
    431              else include(UnwantedNego,Nation);
     431             else Include(UnwantedNego,Nation);
    432432      if NegoTime=BeginOfTurn then
    433433        begin
    434434        DoTurn;
    435         HaveTurned:=true;
     435        HaveTurned:=True;
    436436        Contacted:=[];
    437437        UnwantedNego:=[];
    438438        end
    439       else break;
    440     until false;
     439      else Break;
     440    until False;
    441441    if RO.Happened and phTech<>0 then
    442442      begin
     
    446446        count:=0;
    447447        for ad:=0 to nAdv-1 do if AdvanceResearchable(ad) then
    448           begin inc(count); if random(count)=0 then NewResearch:=ad end
     448          begin Inc(count); if random(count)=0 then NewResearch:=ad end
    449449        end;
    450       Server(sSetResearch,me,NewResearch,nodata^)
     450      Server(sSetResearch,Me,NewResearch,nodata^)
    451451      end;
    452     if (me=1) and (RO.Turn=800) then
     452    if (Me=1) and (RO.Turn=800) then
    453453      begin
    454454      count:=0;
    455       Server(sReload,me,0,count)
     455      Server(sReload,Me,0,count)
    456456      end
    457457    else if (RO.Turn>10) and (random(1000)=0) then
    458458      begin
    459459      count:=RO.Turn-10;
    460       Server(sReload,me,0,count)
     460      Server(sReload,Me,0,count)
    461461      end
    462     else if Server(sTurn,me,0,nodata^)<rExecuted then
    463       assert(false);
     462    else if Server(sTurn,Me,0,nodata^)<rExecuted then
     463      Assert(False);
    464464    end;
    465465  scContact:
    466     if WantNegotiation(integer(Data), EnemyCalled) then
     466    if WantNegotiation(Integer(Data), EnemyCalled) then
    467467      begin
    468       if Server(scDipStart, me, 0, nodata^)<rExecuted then
    469         assert(false);
    470       Opponent:=integer(Data);
     468      if Server(scDipStart, Me, 0, nodata^)<rExecuted then
     469        Assert(False);
     470      Opponent:=Integer(Data);
    471471      MyAction:=scDipStart;
    472472      end
    473473    else
    474474      begin
    475       if Server(scReject, me, 0, nodata^)<rExecuted then
    476         assert(false);
     475      if Server(scReject, Me, 0, nodata^)<rExecuted then
     476        Assert(False);
    477477      end;
    478478  scDipStart, scDipNotice, scDipAccept, scDipCancelTreaty, scDipOffer, scDipBreak:
     
    486486    else begin MyAction:=scDipOffer; MyOffer.nDeliver:=0; MyOffer.nCost:=0; end;
    487487    DoNegotiation;
    488     assert((MyAction=scDipNotice) or (MyAction=scDipAccept)
     488    Assert((MyAction=scDipNotice) or (MyAction=scDipAccept)
    489489      or (MyAction=scDipCancelTreaty) or (MyAction=scDipOffer)
    490490      or (MyAction=scDipBreak));
    491     if MyAction=scDipOffer then Server(MyAction, me, 0, MyOffer)
    492     else Server(MyAction, me, 0, nodata^);
     491    if MyAction=scDipOffer then Server(MyAction, Me, 0, MyOffer)
     492    else Server(MyAction, Me, 0, nodata^);
    493493    end;
    494494  cShowEndContact:
     
    515515
    516516procedure TCustomAI.OnBeforeEnemyAttack(UnitInfo: TUnitInfo; ToLoc, EndHealth,
    517   EndHealthDef: integer);
    518 begin
    519 end;
    520 
    521 procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: integer);
     517  EndHealthDef: Integer);
     518begin
     519end;
     520
     521procedure TCustomAI.OnBeforeEnemyCapture(UnitInfo: TUnitInfo; ToLoc: Integer);
    522522begin
    523523end;
     
    531531end;
    532532
    533 function TCustomAI.ChooseResearchAdvance: integer;
    534 begin
    535 result:=-1
    536 end;
    537 
    538 function TCustomAI.ChooseStealAdvance: integer;
    539 begin
    540 result:=-1
    541 end;
    542 
    543 function TCustomAI.ChooseGovernment: integer;
    544 begin
    545 result:=gDespotism
    546 end;
    547 
    548 function TCustomAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;
    549 begin
    550 result:=false;
    551 end;
    552 
    553 function TCustomAI.OnNegoRejected_CancelTreaty: boolean;
    554 begin
    555 result:=false;
     533function TCustomAI.ChooseResearchAdvance: Integer;
     534begin
     535Result:=-1
     536end;
     537
     538function TCustomAI.ChooseStealAdvance: Integer;
     539begin
     540Result:=-1
     541end;
     542
     543function TCustomAI.ChooseGovernment: Integer;
     544begin
     545Result:=gDespotism
     546end;
     547
     548function TCustomAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean;
     549begin
     550Result:=False;
     551end;
     552
     553function TCustomAI.OnNegoRejected_CancelTreaty: Boolean;
     554begin
     555Result:=False;
    556556end;
    557557{$HINTS ON}
     
    559559procedure TCustomAI.StealAdvance;
    560560var
    561 Steal, ad, count: integer;
     561Steal, ad, count: Integer;
    562562begin
    563563Steal:=ChooseStealAdvance;
     
    566566  count:=0;
    567567  for ad:=0 to nAdv-1 do if AdvanceStealable(ad) then
    568     begin inc(count); if random(count)=0 then Steal:=ad end
     568    begin Inc(count); if random(count)=0 then Steal:=ad end
    569569  end;
    570 if Steal>=0 then Server(sStealTech,me,Steal,nodata^);
     570if Steal>=0 then Server(sStealTech,Me,Steal,nodata^);
    571571RO.Happened:=RO.Happened and not phStealTech
    572572end;
    573573
    574 function TCustomAI.IsResearched(Advance: integer): boolean;
    575 begin
    576 result:= RO.Tech[Advance]>=tsApplicable
    577 end;
    578 
    579 function TCustomAI.ResearchCost: integer;
    580 begin
    581 Server(sGetTechCost,me,0,result)
    582 end;
    583 
    584 function TCustomAI.ChangeAttitude(Nation, Attitude: integer): integer;
    585 begin
    586 result:=Server(sSetAttitude+Nation shl 4,me,Attitude,nodata^)
    587 end;
    588 
    589 function TCustomAI.Revolution: integer;
    590 begin
    591 result:=Server(sRevolution,me,0,nodata^);
    592 end;
    593 
    594 function TCustomAI.ChangeRates(Tax,Lux: integer): integer;
    595 begin
    596 result:=Server(sSetRates,me,Tax div 10 and $f+Lux div 10 and $f shl 4,nodata^)
    597 end;
    598 
    599 function TCustomAI.PrepareNewModel(Domain: integer): integer;
    600 begin
    601 result:=Server(sCreateDevModel,me,Domain,nodata^);
    602 end;
    603 
    604 function TCustomAI.SetNewModelFeature(F, Count: integer): integer;
    605 begin
    606 result:=Server(sSetDevModelCap+Count shl 4,me,F,nodata^)
    607 end;
    608 
    609 function TCustomAI.AdvanceResearchable(Advance: integer): boolean;
    610 begin
    611 result:= Server(sSetResearch-sExecute,me,Advance,nodata^)>=rExecuted;
    612 end;
    613 
    614 function TCustomAI.AdvanceStealable(Advance: integer): boolean;
    615 begin
    616 result:= Server(sStealTech-sExecute,me,Advance,nodata^)>=rExecuted;
    617 end;
    618 
    619 function TCustomAI.DebugMessage(Level: integer; Text: string): boolean;
    620 begin
    621 Text:=copy('P'+char(48+me)+' '+Text,1,254);
    622 Server(sMessage,me,Level,pchar(Text)^);
    623 
    624 result:=true;
     574function TCustomAI.IsResearched(Advance: Integer): Boolean;
     575begin
     576Result:= RO.Tech[Advance]>=tsApplicable
     577end;
     578
     579function TCustomAI.ResearchCost: Integer;
     580begin
     581Server(sGetTechCost,Me,0,Result)
     582end;
     583
     584function TCustomAI.ChangeAttitude(Nation, Attitude: Integer): Integer;
     585begin
     586Result:=Server(sSetAttitude+Nation shl 4,Me,Attitude,nodata^)
     587end;
     588
     589function TCustomAI.Revolution: Integer;
     590begin
     591Result:=Server(sRevolution,Me,0,nodata^);
     592end;
     593
     594function TCustomAI.ChangeRates(Tax,Lux: Integer): Integer;
     595begin
     596Result:=Server(sSetRates,Me,Tax div 10 and $F+Lux div 10 and $F shl 4,nodata^)
     597end;
     598
     599function TCustomAI.PrepareNewModel(Domain: Integer): Integer;
     600begin
     601Result:=Server(sCreateDevModel,Me,Domain,nodata^);
     602end;
     603
     604function TCustomAI.SetNewModelFeature(F, Count: Integer): Integer;
     605begin
     606Result:=Server(sSetDevModelCap+Count shl 4,Me,F,nodata^)
     607end;
     608
     609function TCustomAI.AdvanceResearchable(Advance: Integer): Boolean;
     610begin
     611Result:= Server(sSetResearch-sExecute,Me,Advance,nodata^)>=rExecuted;
     612end;
     613
     614function TCustomAI.AdvanceStealable(Advance: Integer): Boolean;
     615begin
     616Result:= Server(sStealTech-sExecute,Me,Advance,nodata^)>=rExecuted;
     617end;
     618
     619function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean;
     620begin
     621Text:=Copy('P'+char(48+Me)+' '+Text,1,254);
     622Server(sMessage,Me,Level,PChar(Text)^);
     623
     624Result:=True;
    625625  // always returns true so that it can be used like
    626626  // "assert(DebugMessage(...));" -> not compiled in release build
    627627end;
    628628
    629 function TCustomAI.SetDebugMap(var DebugMap): boolean;
    630 begin
    631 Server(sSetDebugMap, me, 0, DebugMap);
    632 
    633 result:=true;
     629function TCustomAI.SetDebugMap(var DebugMap): Boolean;
     630begin
     631Server(sSetDebugMap, Me, 0, DebugMap);
     632
     633Result:=True;
    634634  // always returns true so that it can be used like
    635635  // "assert(SetDebugMap(...));" -> not compiled in release build
    636636end;
    637637
    638 procedure TCustomAI.Unit_FindMyDefender(Loc: integer; var uix: integer);
    639 begin
    640 if Server(sGetDefender,me,Loc,uix)<rExecuted then uix:=-1
    641 end;
    642 
    643 procedure TCustomAI.Unit_FindEnemyDefender(Loc: integer; var euix: integer);
     638procedure TCustomAI.Unit_FindMyDefender(Loc: Integer; var uix: Integer);
     639begin
     640if Server(sGetDefender,Me,Loc,uix)<rExecuted then uix:=-1
     641end;
     642
     643procedure TCustomAI.Unit_FindEnemyDefender(Loc: Integer; var euix: Integer);
    644644begin
    645645euix:=RO.nEnemyUn-1;
    646646while (euix>=0) and (RO.EnemyUn[euix].Loc<>Loc) do
    647   dec(euix);
    648 end;
    649 
    650 function TCustomAI.Unit_Move(uix,ToLoc: integer): integer;
    651 var
    652 Step: integer;
    653 DestinationReached: boolean;
     647  Dec(euix);
     648end;
     649
     650function TCustomAI.Unit_Move(uix,ToLoc: Integer): Integer;
     651var
     652Step: Integer;
     653DestinationReached: Boolean;
    654654Advice: TMoveAdviceData;
    655655begin
    656 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit
     656Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit
    657657{Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    658 assert((a<>0) or (b<>0));
    659 if (a>=-1) and (a<=1) and (b>=-1) and (b<=1) then
     658Assert((A<>0) or (B<>0));
     659if (A>=-1) and (A<=1) and (B>=-1) and (B<=1) then
    660660  begin // move to adjacent tile
    661   !!!problem: if move is invalid, return codes are not consistent with other branch (eNoWay)
     661  !!!problem: if Move is invalid, return codes are not consistent with other branch (eNoWay)
    662662  Advice.nStep:=1;
    663   Advice.dx[0]:=a-b;
    664   Advice.dy[0]:=a+b;
     663  Advice.dx[0]:=A-B;
     664  Advice.dy[0]:=A+B;
    665665  Advice.MoreTurns:=0;
    666666  Advice.MaxHostile_MovementLeft:=MyUnit[uix].Movement;
    667   result:=eOK;
     667  Result:=eOK;
    668668  end
    669669else}
     
    672672  Advice.MoreTurns:=9999;
    673673  Advice.MaxHostile_MovementLeft:=100;
    674   result:=Server(sGetMoveAdvice,me,uix,Advice);
     674  Result:=Server(sGetMoveAdvice,Me,uix,Advice);
    675675  end;
    676 if result=eOk then
     676if Result=eOk then
    677677  begin
    678   DestinationReached:=false;
     678  DestinationReached:=False;
    679679  Step:=0;
    680680  repeat
    681     if result and (rExecuted or rUnitRemoved)=rExecuted then // check if destination reached
     681    if Result and (rExecuted or rUnitRemoved)=rExecuted then // check if destination reached
    682682      if (ToLoc>=0) and (Advice.MoreTurns=0) and (Step=Advice.nStep-1)
    683683        and ((Map[ToLoc] and (fUnit or fOwned)=fUnit) // attack
     
    685685          and ((MyModel[MyUnit[uix].mix].Domain<>dGround) // bombardment
    686686            or (MyModel[MyUnit[uix].mix].Flags and mdCivil<>0))) then // can't capture
    687         begin DestinationReached:=true; break end // stop next to destination
     687        begin DestinationReached:=True; Break end // stop next to destination
    688688      else if Step=Advice.nStep then
    689         DestinationReached:=true; // normal move -- stop at destination
    690 
    691     if (Step=Advice.nStep) or (result<>eOK) and (result<>eLoaded) then
    692       break;
    693 
    694     result:=Server(sMoveUnit+(Advice.dx[Step] and 7) shl 4 +(Advice.dy[Step] and 7) shl 7,
    695       me,uix,nodata^);
    696     inc(Step);
     689        DestinationReached:=True; // normal move -- stop at destination
     690
     691    if (Step=Advice.nStep) or (Result<>eOK) and (Result<>eLoaded) then
     692      Break;
     693
     694    Result:=Server(sMoveUnit+(Advice.dx[Step] and 7) shl 4 +(Advice.dy[Step] and 7) shl 7,
     695      Me,uix,nodata^);
     696    Inc(Step);
    697697    if RO.Happened and phStealTech<>0 then StealAdvance;
    698   until false;
     698  until False;
    699699  if DestinationReached then
    700700    if Advice.nStep=25 then
    701       result:=Unit_Move(uix,ToLoc) // Shinkansen
     701      Result:=Unit_Move(uix,ToLoc) // Shinkansen
    702702    else if Advice.MoreTurns=0 then
    703       result:=result or rLocationReached
    704     else result:=result or rMoreTurns;
    705   end
    706 end;
    707 
    708 function TCustomAI.Unit_Step(uix,ToLoc: integer): integer;
    709 var
    710 a,b: integer;
    711 begin
    712 Loc_to_ab(MyUnit[uix].Loc, ToLoc, a, b);
    713 assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1));
    714 result:=Server(sMoveUnit+((a-b) and 7) shl 4 +((a+b) and 7) shl 7, me, uix, nodata^);
     703      Result:=Result or rLocationReached
     704    else Result:=Result or rMoreTurns;
     705  end
     706end;
     707
     708function TCustomAI.Unit_Step(uix,ToLoc: Integer): Integer;
     709var
     710A,B: Integer;
     711begin
     712Loc_to_ab(MyUnit[uix].Loc, ToLoc, A, B);
     713Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1));
     714Result:=Server(sMoveUnit+((A-B) and 7) shl 4 +((A+B) and 7) shl 7, Me, uix, nodata^);
    715715if RO.Happened and phStealTech<>0 then StealAdvance;
    716716end;
    717717
    718 function TCustomAI.Unit_Attack(uix,ToLoc: integer): integer;
    719 var
    720 a,b: integer;
    721 begin
    722 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
     718function TCustomAI.Unit_Attack(uix,ToLoc: Integer): Integer;
     719var
     720A,B: Integer;
     721begin
     722Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
    723723  and ((Map[ToLoc] and (fUnit or fOwned)=fUnit) // is an attack
    724724  or (Map[ToLoc] and (fCity or fOwned)=fCity)
    725725  and (MyModel[MyUnit[uix].mix].Domain<>dGround))); // is a bombardment
    726 Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    727 assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1)); // attack to adjacent tile
    728 result:=Server(sMoveUnit+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^);
    729 end;
    730 
    731 function TCustomAI.Unit_DoMission(uix,MissionType,ToLoc: integer): integer;
    732 var
    733 a,b: integer;
    734 begin
    735 result:=Server(sSetSpyMission + MissionType shl 4,me,0,nodata^);
    736 if result>=rExecuted then
     726Loc_to_ab(MyUnit[uix].Loc,ToLoc,A,B);
     727Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1)); // attack to adjacent tile
     728Result:=Server(sMoveUnit+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^);
     729end;
     730
     731function TCustomAI.Unit_DoMission(uix,MissionType,ToLoc: Integer): Integer;
     732var
     733A,B: Integer;
     734begin
     735Result:=Server(sSetSpyMission + MissionType shl 4,Me,0,nodata^);
     736if Result>=rExecuted then
    737737  begin
    738   assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
     738  Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
    739739    and (MyModel[MyUnit[uix].mix].Kind=mkDiplomat)); // is a commando
    740   Loc_to_ab(MyUnit[uix].Loc,ToLoc,a,b);
    741   assert(((a<>0) or (b<>0)) and (a>=-1) and (a<=1) and (b>=-1) and (b<=1)); // city must be adjacent
    742   result:=Server(sMoveUnit-sExecute+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^);
    743   if result=eMissionDone then
    744     result:=Server(sMoveUnit+(a-b) and 7 shl 4 +(a+b) and 7 shl 7,me,uix,nodata^)
    745   else if (result<>eNoTime_Move) and (result<>eTreaty) and (result<>eNoTurn) then
    746     result:=eInvalid // not a special commando mission!
    747   end
    748 end;
    749 
    750 function TCustomAI.Unit_MoveForecast(uix,ToLoc: integer;
    751   var RemainingMovement: integer): boolean;
     740  Loc_to_ab(MyUnit[uix].Loc,ToLoc,A,B);
     741  Assert(((A<>0) or (B<>0)) and (A>=-1) and (A<=1) and (B>=-1) and (B<=1)); // city must be adjacent
     742  Result:=Server(sMoveUnit-sExecute+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^);
     743  if Result=eMissionDone then
     744    Result:=Server(sMoveUnit+(A-B) and 7 shl 4 +(A+B) and 7 shl 7,Me,uix,nodata^)
     745  else if (Result<>eNoTime_Move) and (Result<>eTreaty) and (Result<>eNoTurn) then
     746    Result:=eInvalid // not a special commando mission!
     747  end
     748end;
     749
     750function TCustomAI.Unit_MoveForecast(uix,ToLoc: Integer;
     751  var RemainingMovement: Integer): Boolean;
    752752var
    753753Advice: TMoveAdviceData;
    754754begin
    755 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit
     755Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0)); // is a unit
    756756Advice.ToLoc:=ToLoc;
    757757Advice.MoreTurns:=0;
    758758Advice.MaxHostile_MovementLeft:=100;
    759 if Server(sGetMoveAdvice,me,uix,Advice)=eOk then
     759if Server(sGetMoveAdvice,Me,uix,Advice)=eOk then
    760760  begin
    761761  RemainingMovement:=Advice.MaxHostile_MovementLeft;
    762   result:=true
     762  Result:=True
    763763  end
    764764else
    765765  begin
    766766  RemainingMovement:=-1;
    767   result:=false
    768   end
    769 end;
    770 
    771 function TCustomAI.Unit_AttackForecast(uix,ToLoc,AttackMovement: integer;
    772   var RemainingHealth: integer): boolean;
     767  Result:=False
     768  end
     769end;
     770
     771function TCustomAI.Unit_AttackForecast(uix,ToLoc,AttackMovement: Integer;
     772  var RemainingHealth: Integer): Boolean;
    773773var
    774774BattleForecast: TBattleForecast;
    775775begin
    776 assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
     776Assert((uix>=0) and (uix<RO.nUn) and (MyUnit[uix].Loc>=0) // is a unit
    777777  and (Map[ToLoc] and (fUnit or fOwned)=fUnit)); // is an attack
    778778RemainingHealth:=-$100;
    779 result:=false;
     779Result:=False;
    780780if AttackMovement>=0 then with MyUnit[uix] do
    781781  begin
    782   BattleForecast.pAtt:=me;
     782  BattleForecast.pAtt:=Me;
    783783  BattleForecast.mixAtt:=mix;
    784784  BattleForecast.HealthAtt:=Health;
     
    786786  BattleForecast.FlagsAtt:=Flags;
    787787  BattleForecast.Movement:=AttackMovement;
    788   if Server(sGetBattleForecast,me,ToLoc,BattleForecast)>=rExecuted then
     788  if Server(sGetBattleForecast,Me,ToLoc,BattleForecast)>=rExecuted then
    789789    begin
    790790    if BattleForecast.EndHealthAtt>0 then
    791791      RemainingHealth:=BattleForecast.EndHealthAtt
    792792    else RemainingHealth:=-BattleForecast.EndHealthDef;
    793     result:=true
     793    Result:=True
    794794    end
    795795  end
    796796end;
    797797
    798 function TCustomAI.Unit_DefenseForecast(euix,ToLoc: integer;
    799   var RemainingHealth: integer): boolean;
     798function TCustomAI.Unit_DefenseForecast(euix,ToLoc: Integer;
     799  var RemainingHealth: Integer): Boolean;
    800800var
    801801BattleForecast: TBattleForecast;
    802802begin
    803 assert((euix>=0) and (euix<RO.nEnemyUn) and (RO.EnemyUn[euix].Loc>=0) // is an enemy unit
     803Assert((euix>=0) and (euix<RO.nEnemyUn) and (RO.EnemyUn[euix].Loc>=0) // is an enemy unit
    804804  and (Map[ToLoc] and (fUnit or fOwned)=(fUnit or fOwned))); // is an attack
    805805RemainingHealth:=$100;
    806 result:=false;
     806Result:=False;
    807807with RO.EnemyUn[euix] do
    808808  begin
     
    813813  BattleForecast.FlagsAtt:=Flags;
    814814  BattleForecast.Movement:=100;
    815   if Server(sGetBattleForecast,me,ToLoc,BattleForecast)>=rExecuted then
     815  if Server(sGetBattleForecast,Me,ToLoc,BattleForecast)>=rExecuted then
    816816    begin
    817817    if BattleForecast.EndHealthDef>0 then
    818818      RemainingHealth:=BattleForecast.EndHealthDef
    819819    else RemainingHealth:=-BattleForecast.EndHealthAtt;
    820     result:=true
     820    Result:=True
    821821    end
    822822  end
    823823end;
    824824
    825 function TCustomAI.Unit_Disband(uix: integer): integer;
    826 begin
    827 result:=Server(sRemoveUnit,me,uix,nodata^)
    828 end;
    829 
    830 function TCustomAI.Unit_StartJob(uix,NewJob: integer): integer;
    831 begin
    832 result:=Server(sStartJob+NewJob shl 4,me,uix,nodata^)
    833 end;
    834 
    835 function TCustomAI.Unit_SetHomeHere(uix: integer): integer;
    836 begin
    837 result:=Server(sSetUnitHome,me,uix,nodata^)
    838 end;
    839 
    840 function TCustomAI.Unit_Load(uix: integer): integer;
    841 begin
    842 result:=Server(sLoadUnit,me,uix,nodata^)
    843 end;
    844 
    845 function TCustomAI.Unit_Unload(uix: integer): integer;
    846 begin
    847 result:=Server(sUnloadUnit,me,uix,nodata^)
    848 end;
    849 
    850 function TCustomAI.Unit_AddToCity(uix: integer): integer;
    851 begin
    852 result:=Server(sAddToCity,me,uix,nodata^)
    853 end;
    854 
    855 
    856 procedure TCustomAI.City_FindMyCity(Loc: integer; var cix: integer);
     825function TCustomAI.Unit_Disband(uix: Integer): Integer;
     826begin
     827Result:=Server(sRemoveUnit,Me,uix,nodata^)
     828end;
     829
     830function TCustomAI.Unit_StartJob(uix,NewJob: Integer): Integer;
     831begin
     832Result:=Server(sStartJob+NewJob shl 4,Me,uix,nodata^)
     833end;
     834
     835function TCustomAI.Unit_SetHomeHere(uix: Integer): Integer;
     836begin
     837Result:=Server(sSetUnitHome,Me,uix,nodata^)
     838end;
     839
     840function TCustomAI.Unit_Load(uix: Integer): Integer;
     841begin
     842Result:=Server(sLoadUnit,Me,uix,nodata^)
     843end;
     844
     845function TCustomAI.Unit_Unload(uix: Integer): Integer;
     846begin
     847Result:=Server(sUnloadUnit,Me,uix,nodata^)
     848end;
     849
     850function TCustomAI.Unit_AddToCity(uix: Integer): Integer;
     851begin
     852Result:=Server(sAddToCity,Me,uix,nodata^)
     853end;
     854
     855
     856procedure TCustomAI.City_FindMyCity(Loc: Integer; var cix: Integer);
    857857begin
    858858if Map[Loc] and (fCity or fOwned)<>fCity or fOwned then
     
    862862  cix:=RO.nCity-1;
    863863  while (cix>=0) and (MyCity[cix].Loc<>Loc) do
    864     dec(cix);
    865   end
    866 end;
    867 
    868 procedure TCustomAI.City_FindEnemyCity(Loc: integer; var ecix: integer);
     864    Dec(cix);
     865  end
     866end;
     867
     868procedure TCustomAI.City_FindEnemyCity(Loc: Integer; var ecix: Integer);
    869869begin
    870870if Map[Loc] and (fCity or fOwned)<>fCity then
     
    874874  ecix:=RO.nEnemyCity-1;
    875875  while (ecix>=0) and (RO.EnemyCity[ecix].Loc<>Loc) do
    876     dec(ecix);
    877   end
    878 end;
    879 
    880 function TCustomAI.City_HasProject(cix: integer): boolean;
    881 begin
    882 result:= MyCity[cix].Project and (cpImp+cpIndex)<>cpImp+imTrGoods
    883 end;
    884 
    885 function TCustomAI.City_CurrentImprovementProject(cix: integer): integer;
    886 begin
    887 if MyCity[cix].Project and cpImp=0 then result:=-1
     876    Dec(ecix);
     877  end
     878end;
     879
     880function TCustomAI.City_HasProject(cix: Integer): Boolean;
     881begin
     882Result:= MyCity[cix].Project and (cpImp+cpIndex)<>cpImp+imTrGoods
     883end;
     884
     885function TCustomAI.City_CurrentImprovementProject(cix: Integer): Integer;
     886begin
     887if MyCity[cix].Project and cpImp=0 then Result:=-1
    888888else
    889889  begin
    890   result:=MyCity[cix].Project and cpIndex;
    891   if result=imTrGoods then result:=-1
    892   end
    893 end;
    894 
    895 function TCustomAI.City_CurrentUnitProject(cix: integer): integer;
    896 begin
    897 if MyCity[cix].Project and cpImp<>0 then result:=-1
    898 else result:=MyCity[cix].Project and cpIndex;
    899 end;
    900 
    901 function TCustomAI.City_GetTileInfo(cix,TileLoc: integer; var TileInfo: TTileInfo): integer;
     890  Result:=MyCity[cix].Project and cpIndex;
     891  if Result=imTrGoods then Result:=-1
     892  end
     893end;
     894
     895function TCustomAI.City_CurrentUnitProject(cix: Integer): Integer;
     896begin
     897if MyCity[cix].Project and cpImp<>0 then Result:=-1
     898else Result:=MyCity[cix].Project and cpIndex;
     899end;
     900
     901function TCustomAI.City_GetTileInfo(cix,TileLoc: Integer; var TileInfo: TTileInfo): Integer;
    902902begin
    903903TileInfo.ExplCity:=cix;
    904 result:=Server(sGetHypoCityTileInfo,me,TileLoc,TileInfo)
    905 end;
    906 
    907 function TCustomAI.City_GetReport(cix: integer; var Report: TCityReport): integer;
     904Result:=Server(sGetHypoCityTileInfo,Me,TileLoc,TileInfo)
     905end;
     906
     907function TCustomAI.City_GetReport(cix: Integer; var Report: TCityReport): Integer;
    908908begin
    909909Report.HypoTiles:=-1;
    910910Report.HypoTax:=-1;
    911911Report.HypoLux:=-1;
    912 result:=Server(sGetCityReport,me,cix,Report)
    913 end;
    914 
    915 function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: integer;
    916   var Report: TCityReport): integer;
     912Result:=Server(sGetCityReport,Me,cix,Report)
     913end;
     914
     915function TCustomAI.City_GetHypoReport(cix, HypoTiles, HypoTax, HypoLux: Integer;
     916  var Report: TCityReport): Integer;
    917917begin
    918918Report.HypoTiles:=HypoTiles;
    919919Report.HypoTax:=HypoTax;
    920920Report.HypoLux:=HypoLux;
    921 result:=Server(sGetCityReport,me,cix,Report)
    922 end;
    923 
    924 function TCustomAI.City_GetAreaInfo(cix: integer; var AreaInfo: TCityAreaInfo): integer;
    925 begin
    926 result:=Server(sGetCityAreaInfo,me,cix,AreaInfo)
    927 end;
    928 
    929 function TCustomAI.City_StartUnitProduction(cix,mix: integer): integer;
    930 begin
    931 result:=Server(sSetCityProject,me,cix,mix)
    932 end;
    933 
    934 function TCustomAI.City_StartEmigration(cix,mix: integer;
    935   AllowDisbandCity, AsConscripts: boolean): integer;
    936 var
    937 NewProject: integer;
     921Result:=Server(sGetCityReport,Me,cix,Report)
     922end;
     923
     924function TCustomAI.City_GetAreaInfo(cix: Integer; var AreaInfo: TCityAreaInfo): Integer;
     925begin
     926Result:=Server(sGetCityAreaInfo,Me,cix,AreaInfo)
     927end;
     928
     929function TCustomAI.City_StartUnitProduction(cix,mix: Integer): Integer;
     930begin
     931Result:=Server(sSetCityProject,Me,cix,mix)
     932end;
     933
     934function TCustomAI.City_StartEmigration(cix,mix: Integer;
     935  AllowDisbandCity, AsConscripts: Boolean): Integer;
     936var
     937NewProject: Integer;
    938938begin
    939939NewProject:=mix;
    940940if AllowDisbandCity then NewProject:=NewProject or cpDisbandCity;
    941941if AsConscripts then NewProject:=NewProject or cpConscripts;
    942 result:=Server(sSetCityProject,me,cix,NewProject)
    943 end;
    944 
    945 function TCustomAI.City_StartImprovement(cix,iix: integer): integer;
    946 var
    947 NewProject: integer;
     942Result:=Server(sSetCityProject,Me,cix,NewProject)
     943end;
     944
     945function TCustomAI.City_StartImprovement(cix,iix: Integer): Integer;
     946var
     947NewProject: Integer;
    948948begin
    949949NewProject:=iix+cpImp;
    950 result:=Server(sSetCityProject,me,cix,NewProject)
    951 end;
    952 
    953 function TCustomAI.City_Improvable(cix,iix: integer): boolean;
    954 var
    955 NewProject: integer;
     950Result:=Server(sSetCityProject,Me,cix,NewProject)
     951end;
     952
     953function TCustomAI.City_Improvable(cix,iix: Integer): Boolean;
     954var
     955NewProject: Integer;
    956956begin
    957957NewProject:=iix+cpImp;
    958 result:= Server(sSetCityProject-sExecute,me,cix,NewProject)>=rExecuted;
    959 end;
    960 
    961 function TCustomAI.City_StopProduction(cix: integer): integer;
    962 var
    963 NewProject: integer;
     958Result:= Server(sSetCityProject-sExecute,Me,cix,NewProject)>=rExecuted;
     959end;
     960
     961function TCustomAI.City_StopProduction(cix: Integer): Integer;
     962var
     963NewProject: Integer;
    964964begin
    965965NewProject:=imTrGoods+cpImp;
    966 result:=Server(sSetCityProject,me,cix,NewProject)
    967 end;
    968 
    969 function TCustomAI.City_BuyProject(cix: integer): integer;
    970 begin
    971 result:=Server(sBuyCityProject,me,cix,nodata^)
    972 end;
    973 
    974 function TCustomAI.City_SellImprovement(cix,iix: integer): integer;
    975 begin
    976 result:=Server(sSellCityImprovement,me,cix,iix)
    977 end;
    978 
    979 function TCustomAI.City_RebuildImprovement(cix,iix: integer): integer;
    980 begin
    981 result:=Server(sRebuildCityImprovement,me,cix,iix)
    982 end;
    983 
    984 function TCustomAI.City_SetTiles(cix,NewTiles: integer): integer;
    985 begin
    986 result:=Server(sSetCityTiles,me,cix,NewTiles)
     966Result:=Server(sSetCityProject,Me,cix,NewProject)
     967end;
     968
     969function TCustomAI.City_BuyProject(cix: Integer): Integer;
     970begin
     971Result:=Server(sBuyCityProject,Me,cix,nodata^)
     972end;
     973
     974function TCustomAI.City_SellImprovement(cix,iix: Integer): Integer;
     975begin
     976Result:=Server(sSellCityImprovement,Me,cix,iix)
     977end;
     978
     979function TCustomAI.City_RebuildImprovement(cix,iix: Integer): Integer;
     980begin
     981Result:=Server(sRebuildCityImprovement,Me,cix,iix)
     982end;
     983
     984function TCustomAI.City_SetTiles(cix,NewTiles: Integer): Integer;
     985begin
     986Result:=Server(sSetCityTiles,Me,cix,NewTiles)
    987987end;
    988988
    989989
    990990// negotiation
    991 function TCustomAI.Nego_CheckMyAction: integer;
    992 begin
    993 assert(Opponent>=0); // only allowed in negotiation mode
    994 assert((MyAction=scDipNotice) or (MyAction=scDipAccept)
     991function TCustomAI.Nego_CheckMyAction: Integer;
     992begin
     993Assert(Opponent>=0); // only allowed in negotiation mode
     994Assert((MyAction=scDipNotice) or (MyAction=scDipAccept)
    995995  or (MyAction=scDipCancelTreaty) or (MyAction=scDipOffer)
    996996  or (MyAction=scDipBreak));
    997 if MyAction=scDipOffer then result:=Server(MyAction-sExecute, me, 0, MyOffer)
    998 else result:=Server(MyAction-sExecute, me, 0, nodata^);
     997if MyAction=scDipOffer then Result:=Server(MyAction-sExecute, Me, 0, MyOffer)
     998else Result:=Server(MyAction-sExecute, Me, 0, nodata^);
    999999end;
    10001000
    10011001
    10021002initialization
    1003 nodata:=pointer(0);
     1003nodata:=Pointer(0);
    10041004RWDataSize:=0;
    10051005
  • branches/highdpi/AI/StdAI/Pile.pas

    r303 r465  
    88interface
    99
    10 procedure Create(Size: integer);
     10procedure Create(Size: Integer);
    1111procedure Free;
    1212procedure Empty;
    13 function Put(Item, Value: integer): boolean;
    14 function TestPut(Item, Value: integer): boolean;
    15 function Get(var Item, Value: integer): boolean;
     13function Put(Item, Value: Integer): Boolean;
     14function TestPut(Item, Value: Integer): Boolean;
     15function Get(var Item, Value: Integer): Boolean;
    1616
    1717
     
    2323type
    2424  TheapItem = record
    25     Item: integer;
    26     Value: integer;
     25    Item: Integer;
     26    Value: Integer;
    2727  end;
    2828
    2929var
    3030  bh: array[0..MaxSize - 1] of TheapItem;
    31   Ix: array[0..MaxSize - 1] of integer;
    32   n, CurrentSize: integer;
    33 {$IFDEF DEBUG}InUse: boolean;{$ENDIF}
     31  Ix: array[0..MaxSize - 1] of Integer;
     32  N, CurrentSize: Integer;
     33{$IFDEF DEBUG}InUse: Boolean;{$ENDIF}
    3434
    3535
    36 procedure Create(Size: integer);
     36procedure Create(Size: Integer);
    3737begin
    3838  {$IFDEF DEBUG}
    39   assert(not InUse, 'Pile is a single instance class, ' +
     39  Assert(not InUse, 'Pile is a single instance class, ' +
    4040    'no multiple usage possible. Always call Pile.Free after use.');
    4141{$ENDIF}
    42   assert(Size <= MaxSize);
    43   if (n <> 0) or (Size > CurrentSize) then
     42  Assert(Size <= MaxSize);
     43  if (N <> 0) or (Size > CurrentSize) then
    4444  begin
    45     FillChar(Ix, Size * sizeOf(integer), 255);
    46     n := 0;
     45    FillChar(Ix, Size * sizeOf(Integer), 255);
     46    N := 0;
    4747  end;
    4848  CurrentSize := Size;
     
    5555begin
    5656        {$IFDEF DEBUG}
    57   assert(InUse);
     57  Assert(InUse);
    5858  InUse := False;
    5959{$ENDIF}
     
    6262procedure Empty;
    6363begin
    64   if n <> 0 then
     64  if N <> 0 then
    6565  begin
    66     FillChar(Ix, CurrentSize * sizeOf(integer), 255);
    67     n := 0;
     66    FillChar(Ix, CurrentSize * sizeOf(Integer), 255);
     67    N := 0;
    6868  end;
    6969end;
    7070
    7171//Parent(i) = (i-1)/2.
    72 function Put(Item, Value: integer): boolean; //O(lg(n))
     72function Put(Item, Value: Integer): Boolean; //O(lg(n))
    7373var
    74   i, j: integer;
     74  I, J: Integer;
    7575begin
    76   assert(Item < CurrentSize);
    77   i := Ix[Item];
    78   if i >= 0 then
     76  Assert(Item < CurrentSize);
     77  I := Ix[Item];
     78  if I >= 0 then
    7979  begin
    80     if bh[i].Value <= Value then
     80    if bh[I].Value <= Value then
    8181    begin
    8282      Result := False;
    83       exit;
     83      Exit;
    8484    end;
    8585  end
    8686  else
    8787  begin
    88     i := n;
    89     Inc(n);
     88    I := N;
     89    Inc(N);
    9090  end;
    9191
    92   while i > 0 do
     92  while I > 0 do
    9393  begin
    94     j := (i - 1) shr 1;  //Parent(i) = (i-1)/2
    95     if Value >= bh[j].Value then
    96       break;
    97     bh[i] := bh[j];
    98     Ix[bh[i].Item] := i;
    99     i := j;
     94    J := (I - 1) shr 1;  //Parent(i) = (i-1)/2
     95    if Value >= bh[J].Value then
     96      Break;
     97    bh[I] := bh[J];
     98    Ix[bh[I].Item] := I;
     99    I := J;
    100100  end;
    101101  //  Insert the new Item at the insertion point found.
    102   bh[i].Value := Value;
    103   bh[i].Item := Item;
    104   Ix[bh[i].Item] := i;
     102  bh[I].Value := Value;
     103  bh[I].Item := Item;
     104  Ix[bh[I].Item] := I;
    105105  Result := True;
    106106end;
    107107
    108 function TestPut(Item, Value: integer): boolean;
     108function TestPut(Item, Value: Integer): Boolean;
    109109var
    110   i: integer;
     110  I: Integer;
    111111begin
    112   assert(Item < CurrentSize);
    113   i := Ix[Item];
    114   Result := (i < 0) or (bh[i].Value > Value);
     112  Assert(Item < CurrentSize);
     113  I := Ix[Item];
     114  Result := (I < 0) or (bh[I].Value > Value);
    115115end;
    116116
    117117//Left(i) = 2*i+1.
    118118//Right(i) = 2*i+2 => Left(i)+1
    119 function Get(var Item, Value: integer): boolean; //O(lg(n))
     119function Get(var Item, Value: Integer): Boolean; //O(lg(n))
    120120var
    121   i, j: integer;
    122   last: TheapItem;
     121  I, J: Integer;
     122  Last: TheapItem;
    123123begin
    124   if n = 0 then
     124  if N = 0 then
    125125  begin
    126126    Result := False;
    127     exit;
     127    Exit;
    128128  end;
    129129
     
    133133  Ix[Item] := -1;
    134134
    135   Dec(n);
    136   if n > 0 then
     135  Dec(N);
     136  if N > 0 then
    137137  begin
    138     last := bh[n];
    139     i := 0;
    140     j := 1;
    141     while j < n do
     138    Last := bh[N];
     139    I := 0;
     140    J := 1;
     141    while J < N do
    142142    begin
    143143      //  Right(i) = Left(i)+1
    144       if (j < n - 1) and (bh[j].Value > bh[j + 1].Value) then
    145         Inc(j);
    146       if last.Value <= bh[j].Value then
    147         break;
     144      if (J < N - 1) and (bh[J].Value > bh[J + 1].Value) then
     145        Inc(J);
     146      if Last.Value <= bh[J].Value then
     147        Break;
    148148
    149       bh[i] := bh[j];
    150       Ix[bh[i].Item] := i;
    151       i := j;
    152       j := j shl 1 + 1;  //Left(j) = 2*j+1
     149      bh[I] := bh[J];
     150      Ix[bh[I].Item] := I;
     151      I := J;
     152      J := J shl 1 + 1;  //Left(j) = 2*j+1
    153153    end;
    154154
    155155    // Insert the root in the correct place in the heap.
    156     bh[i] := last;
    157     Ix[last.Item] := i;
     156    bh[I] := Last;
     157    Ix[Last.Item] := I;
    158158  end;
    159159  Result := True;
     
    161161
    162162initialization
    163   n := 0;
     163  N := 0;
    164164  CurrentSize := 0;
    165165        {$IFDEF DEBUG}
  • branches/highdpi/AI/StdAI/Protocol.pas

    r349 r465  
    916916  Cost: Integer;
    917917  Maint: Integer;
    918   Expiration: integer;
     918  Expiration: Integer;
    919919end
    920920= ((Kind: ikWonder; Preq: adMathematics; Cost: 400; Maint: 0;
     
    11201120  Strength: Integer;
    11211121  Trans: Integer;
    1122   Cost: integer;
     1122  Cost: Integer;
    11231123end
    11241124= (((Preq: adWarriorCode; Strength: 4; Trans: 0; Cost: 3),
     
    15101510  TGetCityData = record
    15111511    Owner: Integer;
    1512     c: TCity;
     1512    C: TCity;
    15131513  end;
    15141514
     
    15911591  TCreateUnitData = record
    15921592    Loc: Integer;
    1593     p: Integer;
     1593    P: Integer;
    15941594    mix: Integer;
    15951595  end;
     
    16001600  TOwnerList = array [0 .. INFIN] of ShortInt;
    16011601  TByteList = array [0 .. INFIN] of Byte;
    1602   TIntList = array [0 .. INFIN] of integer;
     1602  TIntList = array [0 .. INFIN] of Integer;
    16031603  TCityList = array [0 .. INFIN] of TCity;
    16041604  TUnList = array [0 .. INFIN] of TUn;
     
    17611761    0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
    17621762
    1763   SpecialModelPreq: array [0 .. nSpecialModel - 1] of integer = (preNone,
     1763  SpecialModelPreq: array [0 .. nSpecialModel - 1] of Integer = (preNone,
    17641764    adExplosives, preNone, preNone, (* adWri, *) adIntelligence, adTrade,
    17651765    (* adTheCorporation,adHorsebackRiding,adAutomobile,adNavigation,
     
    17701770  DelphiRandSeed: Integer;
    17711771
    1772 procedure MakeUnitInfo(p: Integer; const u: TUn; var ui: TUnitInfo);
    1773 procedure MakeModelInfo(p, mix: Integer; const m: TModel; var mi: TModelInfo);
     1772procedure MakeUnitInfo(P: Integer; const U: TUn; var ui: TUnitInfo);
     1773procedure MakeModelInfo(P, mix: Integer; const M: TModel; var mi: TModelInfo);
    17741774function IsSameModel(const mi1, mi2: TModelInfo): Boolean;
    17751775function SpecialTile(Loc, TerrType, lx: Integer): Integer;
     
    17811781implementation
    17821782
    1783 procedure MakeUnitInfo(p: Integer; const u: TUn; var ui: TUnitInfo);
     1783procedure MakeUnitInfo(P: Integer; const U: TUn; var ui: TUnitInfo);
    17841784begin
    1785   ui.Owner := p;
    1786   ui.Loc := u.Loc;
    1787   ui.Health := u.Health;
    1788   ui.Fuel := u.Fuel;
    1789   ui.Job := u.Job;
    1790   ui.Exp := u.Exp;
    1791   ui.Load := u.TroopLoad + u.AirLoad;
    1792   ui.mix := u.mix;
    1793   ui.Flags := u.Flags;
     1785  ui.Owner := P;
     1786  ui.Loc := U.Loc;
     1787  ui.Health := U.Health;
     1788  ui.Fuel := U.Fuel;
     1789  ui.Job := U.Job;
     1790  ui.Exp := U.Exp;
     1791  ui.Load := U.TroopLoad + U.AirLoad;
     1792  ui.mix := U.mix;
     1793  ui.Flags := U.Flags;
    17941794end;
    17951795
    1796 procedure MakeModelInfo(p, mix: Integer; const m: TModel; var mi: TModelInfo);
     1796procedure MakeModelInfo(P, mix: Integer; const M: TModel; var mi: TModelInfo);
    17971797var
    1798   i: Integer;
     1798  I: Integer;
    17991799begin
    1800   mi.Owner := p;
     1800  mi.Owner := P;
    18011801  mi.mix := mix;
    1802   mi.ID := m.ID;
    1803   mi.Domain := m.Domain;
    1804   if m.Kind = mkEnemyDeveloped then
     1802  mi.ID := M.ID;
     1803  mi.Domain := M.Domain;
     1804  if M.Kind = mkEnemyDeveloped then
    18051805    mi.Kind := mkSelfDeveloped // important for IsSameModel()
    18061806  else
    1807     mi.Kind := m.Kind;
    1808   mi.Attack := m.Attack;
    1809   mi.Defense := m.Defense;
    1810   mi.Speed := m.Speed;
    1811   mi.Cost := m.Cost;
     1807    mi.Kind := M.Kind;
     1808  mi.Attack := M.Attack;
     1809  mi.Defense := M.Defense;
     1810  mi.Speed := M.Speed;
     1811  mi.Cost := M.Cost;
    18121812  if mi.Domain = dAir then
    18131813  begin
    1814     mi.TTrans := m.Cap[mcAirTrans] * m.MTrans;
    1815     mi.ATrans_Fuel := m.Cap[mcFuel];
     1814    mi.TTrans := M.Cap[mcAirTrans] * M.MTrans;
     1815    mi.ATrans_Fuel := M.Cap[mcFuel];
    18161816  end
    18171817  else
    18181818  begin
    1819     mi.TTrans := m.Cap[mcSeaTrans] * m.MTrans;
    1820     mi.ATrans_Fuel := m.Cap[mcCarrier] * m.MTrans;
    1821   end;
    1822   mi.Bombs := m.Cap[mcBombs] * m.MStrength * 2;
     1819    mi.TTrans := M.Cap[mcSeaTrans] * M.MTrans;
     1820    mi.ATrans_Fuel := M.Cap[mcCarrier] * M.MTrans;
     1821  end;
     1822  mi.Bombs := M.Cap[mcBombs] * M.MStrength * 2;
    18231823  mi.Cap := 0;
    1824   for i := mcFirstNonCap to nFeature - 1 do
    1825     if m.Cap[i] > 0 then
    1826       mi.Cap := mi.Cap or (1 shl (i - mcFirstNonCap));
     1824  for I := mcFirstNonCap to nFeature - 1 do
     1825    if M.Cap[I] > 0 then
     1826      mi.Cap := mi.Cap or (1 shl (I - mcFirstNonCap));
    18271827  mi.MaxUpgrade := 0;
    1828   for i := 1 to nUpgrade - 1 do
    1829     if m.Upgrades and (1 shl i) <> 0 then
    1830       mi.MaxUpgrade := i;
    1831   mi.Weight := m.Weight;
     1828  for I := 1 to nUpgrade - 1 do
     1829    if M.Upgrades and (1 shl I) <> 0 then
     1830      mi.MaxUpgrade := I;
     1831  mi.Weight := M.Weight;
    18321832  mi.Lost := 0;
    18331833end;
     
    18411841  Compare1 := @mi1;
    18421842  Compare2 := @mi2;
    1843   result := (Compare1[1] and $FFFF0000 = Compare2[1] and $FFFF0000) and
     1843  Result := (Compare1[1] and $FFFF0000 = Compare2[1] and $FFFF0000) and
    18441844    (Compare1[2] = Compare2[2]) and (Compare1[3] = Compare2[3]) and
    18451845    (Compare1[4] = Compare2[4]) and (Compare1[5] = Compare2[5])
     
    18481848function SpecialTile(Loc, TerrType, lx: Integer): Integer;
    18491849var
    1850   x, y, qx, qy, a: Integer;
     1850  X, Y, qx, qy, A: Integer;
    18511851begin
    18521852  if TerrType = fOcean then
    1853     result := 0
     1853    Result := 0
    18541854  else
    18551855  begin
    1856     y := Loc div lx;
    1857     x := Loc - y * lx;
     1856    Y := Loc div lx;
     1857    X := Loc - Y * lx;
    18581858    if TerrType = fGrass then { formula for productive grassland }
    1859       if Odd((lymax + x - y shr 1) shr 1 + x + (y + 1) shr 1) then
    1860         result := 1
     1859      if Odd((lymax + X - Y shr 1) shr 1 + X + (Y + 1) shr 1) then
     1860        Result := 1
    18611861      else
    1862         result := 0
     1862        Result := 0
    18631863    else { formula for special resources }
    18641864    begin
    1865       a := 4 * x - y + 9980;
    1866       qx := a div 10;
    1867       if (qx * 10 = a) and (qx and 3 <> 0) then
     1865      A := 4 * X - Y + 9980;
     1866      qx := A div 10;
     1867      if (qx * 10 = A) and (qx and 3 <> 0) then
    18681868      begin
    1869         qy := (y + x) div 5;
     1869        qy := (Y + X) div 5;
    18701870        if qy and 3 <> qx shr 2 and 1 * 2 then
    18711871          if (TerrType = fArctic) or (TerrType = fSwamp) then
    1872             result := 1
     1872            Result := 1
    18731873          else if TerrType = fShore then
    18741874          begin
    18751875            if (qx + qy) and 1 = 0 then
    18761876              if qx and 3 = 2 then
    1877                 result := 2
     1877                Result := 2
    18781878              else
    1879                 result := 1
     1879                Result := 1
    18801880            else
    1881               result := 0
     1881              Result := 0
    18821882          end
    18831883          else
    1884             result := (qx + qy) and 1 + 1
     1884            Result := (qx + qy) and 1 + 1
    18851885        else
    1886           result := 0;
     1886          Result := 0;
    18871887      end
    18881888      else
    1889         result := 0;
     1889        Result := 0;
    18901890    end
    18911891  end;
  • branches/highdpi/AI/StdAI/StdAI.ai.txt

    r124 r465  
    55#PATH_WIN32 StdAI-win32.dll
    66#PATH_WIN64 StdAI-win64.dll
    7 #PATH_LINUX32 libstdai-i386.so
    8 #PATH_LINUX64 libstdai-amd64.so
     7#PATH_LINUX_I386 libstdai-i386.so
     8#PATH_LINUX_AMD64 libstdai-amd64.so
     9#PATH_LINUX_ARM32 libstdai-arm32.so
     10#PATH_LINUX_ARM64 libstdai-arm64.so
    911#CREDITS Standard AI by Steffen Gerlach.
  • branches/highdpi/AI/StdAI/StdAI.lpr

    r303 r465  
    1212var
    1313  AIList: array[0..nPl - 1] of TCustomAI;
    14   Defender: integer;
     14  Defender: Integer;
    1515
    1616
    17   procedure Client(Command, Player: integer; var Data); stdcall;
     17  procedure Client(Command, Player: Integer; var Data); stdcall;
    1818  var
    19     p, y0, ToLoc: integer;
     19    P, y0, ToLoc: Integer;
    2020    UnitInfo: TUnitInfo;
    2121  begin
     
    3232{$ENDIF}
    3333        CustomAI.Init(TNewGameData(Data));
    34         for p := nPl - 1 downto 0 do
    35           if G.RO[p] <> nil then
     34        for P := nPl - 1 downto 0 do
     35          if G.RO[P] <> nil then
    3636          begin
    37             AIList[p] := TAI.Create(p);
    38             AIList[p].SetDataDefaults;
     37            AIList[P] := TAI.Create(P);
     38            AIList[P].SetDataDefaults;
    3939          end
    4040          else
    41             AIList[p] := nil;
     41            AIList[P] := nil;
    4242        Defender := -1;
    4343      end;
    4444      cGetReady:
    45         for p := nPl - 1 downto 0 do
    46           if AIList[p] <> nil then
    47             AIList[p].SetDataRandom;
     45        for P := nPl - 1 downto 0 do
     46          if AIList[P] <> nil then
     47            AIList[P].SetDataRandom;
    4848      cBreakGame:
    49         for p := 0 to nPl - 1 do
    50           if AIList[p] <> nil then
    51             AIList[p].Free;
     49        for P := 0 to nPl - 1 do
     50          if AIList[P] <> nil then
     51            AIList[P].Free;
    5252
    5353      cTurn, cContinue, scContact..scDipBreak, cShowEndContact:
  • branches/highdpi/AI/StdAI/ToolAI.pas

    r349 r465  
    1111type
    1212  TGroupTransportPlan = record
    13     LoadLoc, uixTransport, nLoad, TurnsEmpty, TurnsLoaded: integer;
    14     uixLoad: array[0..15] of integer;
     13    LoadLoc, uixTransport, nLoad, TurnsEmpty, TurnsLoaded: Integer;
     14    uixLoad: array[0..15] of Integer;
    1515  end;
    1616
     
    1818  TToolAI = class(TCustomAI)
    1919  protected
    20   {$IFDEF DEBUG}DebugMap: array[0..lxmax * lymax - 1] of integer;{$ENDIF}
    21 
    22     function CenterOfEmpire: integer;
     20  {$IFDEF DEBUG}DebugMap: array[0..lxmax * lymax - 1] of Integer;{$ENDIF}
     21
     22    function CenterOfEmpire: Integer;
    2323    // tile that is in the middle of all own cities
    2424
    25     function CityTaxBalance(cix: integer; const CityReport: TCityReport): integer;
     25    function CityTaxBalance(cix: Integer; const CityReport: TCityReport): Integer;
    2626    // calculates exact difference of income and maintenance cost for a single city
    2727    // positive result = income higher than maintenance
     
    2929    // respects production and food converted to gold
    3030    // CityReport must have been prepared before
    31     procedure SumCities(TaxRate: integer; var TaxSum, ScienceSum: integer);
     31    procedure SumCities(TaxRate: Integer; var TaxSum, ScienceSum: Integer);
    3232    // calculates exact total tax and science income
    3333    // tax is reduced by maintenance (so might be negative)
     
    4646    procedure JobAssignment_Initialize;
    4747    // initialization, must be called first of the JobAssignment functions
    48     procedure JobAssignment_AddJob(Loc, Job, Score: integer);
     48    procedure JobAssignment_AddJob(Loc, Job, Score: Integer);
    4949    // add job for settlers with certain score
    5050    // jobs include founding cities!
    51     procedure JobAssignment_AddUnit(uix: integer);
     51    procedure JobAssignment_AddUnit(uix: Integer);
    5252    // add a settler unit to do jobs
    5353    procedure JobAssignment_Go;
     
    5757    // starting a job one turn earlier counts the same as 4 points of score
    5858    // function does not cancel jobs that are already started
    59     function JobAssignment_GotJob(uix: integer): boolean;
     59    function JobAssignment_GotJob(uix: Integer): Boolean;
    6060    // can be called after JobAssignment_Go to find out whether
    6161    // a certain settler has been assigned a job to
     
    6464    // calculates formations and districts
    6565
    66     function CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: integer;
    67       var TimeAfterStep, RecoverTurns: integer; FromTile, ToTile: integer;
    68       IsCapture: boolean): integer;
     66    function CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: Integer;
     67      var TimeAfterStep, RecoverTurns: Integer; FromTile, ToTile: Integer;
     68      IsCapture: Boolean): Integer;
    6969    // forecast single unit move between adjacent tiles
    7070    // format of TimeBeforeStep and TimeAfterStep: $1000*number of turns + $800-MP left
     
    7474    // CrossCorner=1 for long moves that cross the tile corner, =0 for short ones that don't
    7575
    76     function GetMyMoveStyle(mix, Health: integer): integer;
    77 
    78     function Unit_MoveEx(uix, ToLoc: integer; Options: integer = 0): integer;
     76    function GetMyMoveStyle(mix, Health: Integer): Integer;
     77
     78    function Unit_MoveEx(uix, ToLoc: Integer; Options: Integer = 0): Integer;
    7979
    8080    procedure SeaTransport_BeginInitialize;
     
    9090    // - all transports have same capacity
    9191    // - no transport is damaged
    92     procedure SeaTransport_AddLoad(uix: integer);
    93     procedure SeaTransport_AddTransport(uix: integer);
    94     procedure SeaTransport_AddDestination(Loc: integer);
    95     function SeaTransport_MakeGroupPlan(var TransportPlan: TGroupTransportPlan): boolean;
     92    procedure SeaTransport_AddLoad(uix: Integer);
     93    procedure SeaTransport_AddTransport(uix: Integer);
     94    procedure SeaTransport_AddDestination(Loc: Integer);
     95    function SeaTransport_MakeGroupPlan(var TransportPlan: TGroupTransportPlan): Boolean;
    9696    // make plan for group of units to transport from a single loading location by a single transport
    9797    // the plan optimizes:
     
    103103    // function returns false if no more transports are possible
    104104
    105     function CurrentMStrength(Domain: integer): integer;
    106   end;
    107 
     105    function CurrentMStrength(Domain: Integer): Integer;
     106  end;
    108107
    109108const
     
    132131  mxAdjacent = $00000001;
    133132
    134 
    135 var
    136   nContinent, nOcean, nDistrict: integer;
    137   Formation: array[0..lxmax * lymax - 1] of integer;
     133var
     134  nContinent, nOcean, nDistrict: Integer;
     135  Formation: array[0..lxmax * lymax - 1] of Integer;
    138136  // water: ocean index, land: continent index, sorted by size
    139137  // territory unpassable due to peace treaty divides a continent
    140   District: array[0..lxmax * lymax - 1] of integer;
     138  District: array[0..lxmax * lymax - 1] of Integer;
    141139  // index of coherent own territory, sorted by size
    142   CityResult: array[0..nCmax - 1] of integer;
    143 
    144   Advancedness: array[0..nAdv - 1] of integer;
     140  CityResult: array[0..nCmax - 1] of Integer;
     141
     142  Advancedness: array[0..nAdv - 1] of Integer;
    145143// total number of prerequisites for each advance
    146 
    147144
    148145implementation
     
    152149
    153150type
    154   pinteger = ^integer;
     151  pinteger = ^Integer;
    155152
    156153var
    157154  // for JobAssignment
    158   MaxScore: integer;
    159   TileJob, TileJobScore: array[0..lxmax * lymax - 1] of byte;
    160   JobLocOfSettler: array[0..nUmax - 1] of integer; // ToAssign = find job
     155  MaxScore: Integer;
     156  TileJob, TileJobScore: array[0..lxmax * lymax - 1] of Byte;
     157  JobLocOfSettler: array[0..nUmax - 1] of Integer; // ToAssign = find job
    161158
    162159  // for Transport
    163   TransportMoveStyle, TransportCapacity, nTransportLoad: integer;
    164   InitComplete, HaveDestinations: boolean;
    165   uixTransportLoad, TransportAvailable: array[0..nUmax - 1] of integer;
    166   TurnsAfterLoad: array[0..lxmax * lymax - 1] of shortint;
    167 
    168 
    169 procedure ReplaceD(Start, Stop: pinteger; Raider, Twix: integer);
     160  TransportMoveStyle, TransportCapacity, nTransportLoad: Integer;
     161  InitComplete, HaveDestinations: Boolean;
     162  uixTransportLoad, TransportAvailable: array[0..nUmax - 1] of Integer;
     163  TurnsAfterLoad: array[0..lxmax * lymax - 1] of ShortInt;
     164
     165procedure ReplaceD(Start, Stop: pinteger; Raider, Twix: Integer);
    170166begin
    171167  while Start <> Stop do
     
    177173end;
    178174
    179 function NextZero(Start, Stop: pinteger; Mask: cardinal): pinteger;
     175function NextZero(Start, Stop: pinteger; Mask: Cardinal): pinteger;
    180176begin
    181177  while (Start <> Stop) and (Start^ and Mask <> 0) do
     
    184180end;
    185181
    186 
    187 function TToolAI.CenterOfEmpire: integer;
    188 var
    189   cix, Loc, x, y, sy, n: integer;
    190   a, su, sv: double;
    191 begin
    192   n := 0;
     182function TToolAI.CenterOfEmpire: Integer;
     183var
     184  cix, Loc, X, Y, sy, N: Integer;
     185  A, su, sv: Double;
     186begin
     187  N := 0;
    193188  sy := 0;
    194189  su := 0;
     
    199194    if Loc >= 0 then
    200195    begin
    201       y := Loc div G.lx;
    202       x := Loc - y * G.lx;
    203       Inc(sy, y);
    204       a := 2 * pi * x / G.lx;
    205       su := su + cos(a);
    206       sv := sv + sin(a);
    207       Inc(n);
    208     end;
    209   end;
    210   a := arctan2(sv, su);
    211   x := round(G.lx * a / (2 * pi));
    212   while x >= G.lx do
    213     Dec(x, G.lx);
    214   while x < 0 do
    215     Inc(x, G.lx);
    216   Result := ((2 * sy + n) div (2 * n)) * G.lx + x;
    217 end;
    218 
    219 function TToolAI.CityTaxBalance(cix: integer; const CityReport: TCityReport): integer;
    220 var
    221   i: integer;
     196      Y := Loc div G.lx;
     197      X := Loc - Y * G.lx;
     198      Inc(sy, Y);
     199      A := 2 * pi * X / G.lx;
     200      su := su + cos(A);
     201      sv := sv + sin(A);
     202      Inc(N);
     203    end;
     204  end;
     205  A := arctan2(sv, su);
     206  X := round(G.lx * A / (2 * pi));
     207  while X >= G.lx do
     208    Dec(X, G.lx);
     209  while X < 0 do
     210    Inc(X, G.lx);
     211  Result := ((2 * sy + N) div (2 * N)) * G.lx + X;
     212end;
     213
     214function TToolAI.CityTaxBalance(cix: Integer; const CityReport: TCityReport): Integer;
     215var
     216  I: Integer;
    222217begin
    223218  Result := 0;
     
    234229      Inc(Result, CityReport.FoodRep - CityReport.Eaten);
    235230  end;
    236   for i := nWonder to nImp - 1 do
    237     if MyCity[cix].Built[i] > 0 then
    238       Dec(Result, Imp[i].Maint);
    239 end;
    240 
    241 procedure TToolAI.SumCities(TaxRate: integer; var TaxSum, ScienceSum: integer);
    242 var
    243   cix, p1: integer;
     231  for I := nWonder to nImp - 1 do
     232    if MyCity[cix].Built[I] > 0 then
     233      Dec(Result, Imp[I].Maint);
     234end;
     235
     236procedure TToolAI.SumCities(TaxRate: Integer; var TaxSum, ScienceSum: Integer);
     237var
     238  cix, p1: Integer;
    244239  CityReport: TCityReport;
    245240begin
     
    247242  ScienceSum := 0;
    248243  if RO.Government = gAnarchy then
    249     exit;
     244    Exit;
    250245  for p1 := 0 to nPl - 1 do
    251246    if RO.Tribute[p1] <= RO.TributePaid[p1] then
     
    263258end;
    264259
    265 
    266260//------------------------------------------------------------------------------
    267261// City Tiles Processing
     
    274268procedure TToolAI.OptimizeCityTiles;
    275269var
    276   cix: integer;
     270  cix: Integer;
    277271begin
    278272  for cix := 0 to RO.nCity - 1 do
     
    284278procedure TToolAI.GetCityProdPotential;
    285279var
    286   cix: integer;
     280  cix: Integer;
    287281  Advice: TCityTileAdviceData;
    288282begin
     
    292286      begin
    293287        Advice.ResourceWeights := rwMaxProd;
    294         Server(sGetCityTileAdvice, me, cix, Advice);
     288        Server(sGetCityTileAdvice, Me, cix, Advice);
    295289        CityResult[cix] := Advice.CityReport.ProdRep; // considers factory, but shouldn't
    296290      end;
     
    299293procedure TToolAI.GetCityTradePotential;
    300294var
    301   cix: integer;
     295  cix: Integer;
    302296  Advice: TCityTileAdviceData;
    303297begin
     
    307301      begin
    308302        Advice.ResourceWeights := rwMaxScience;
    309         Server(sGetCityTileAdvice, me, cix, Advice);
     303        Server(sGetCityTileAdvice, Me, cix, Advice);
    310304        CityResult[cix] := Advice.CityReport.Trade;
    311305      end;
    312306end;
    313 
    314307
    315308//------------------------------------------------------------------------------
     
    321314procedure TToolAI.JobAssignment_Initialize;
    322315begin
    323   fillchar(JobLocOfSettler, RO.nUn * sizeof(integer), $FF); // -1
    324   fillchar(TileJob, MapSize, jNone);
    325   fillchar(TileJobScore, MapSize, 0);
     316  FillChar(JobLocOfSettler, RO.nUn * SizeOf(Integer), $FF); // -1
     317  FillChar(TileJob, MapSize, jNone);
     318  FillChar(TileJobScore, MapSize, 0);
    326319  MaxScore := 0;
    327320end;
    328321
    329 procedure TToolAI.JobAssignment_AddJob(Loc, Job, Score: integer);
     322procedure TToolAI.JobAssignment_AddJob(Loc, Job, Score: Integer);
    330323begin
    331324  if Score > 255 then
     
    340333end;
    341334
    342 procedure TToolAI.JobAssignment_AddUnit(uix: integer);
    343 begin
    344   assert(MyModel[MyUnit[uix].mix].Kind in [mkSettler, mkSlaves]);
     335procedure TToolAI.JobAssignment_AddUnit(uix: Integer);
     336begin
     337  Assert(MyModel[MyUnit[uix].mix].Kind in [mkSettler, mkSlaves]);
    345338  JobLocOfSettler[uix] := ToAssign;
    346339end;
    347340
    348 function TToolAI.JobAssignment_GotJob(uix: integer): boolean;
     341function TToolAI.JobAssignment_GotJob(uix: Integer): Boolean;
    349342begin
    350343  Result := JobLocOfSettler[uix] >= 0;
     
    354347const
    355348  DistanceScore = 4;
    356   StepSizeByTerrain: array[0..11] of integer =
     349  StepSizeByTerrain: array[0..11] of Integer =
    357350    (0, 0, 1, 2, 1, 1, 0, 1, 0, 1, 1, 2);
    358351  //Oc-Sh-Gr-De-Pr-Tu-Ar-Sw-XX-Fo-Hi-Mo
    359352var
    360353  uix, BestScore, BestCount, BestLoc, BestJob, BestDistance, TestLoc,
    361   NextLoc, TestDistance, V8, TestScore, StepSize, MoveResult: integer;
    362   UnitsToAssign: boolean;
     354  NextLoc, TestDistance, V8, TestScore, StepSize, MoveResult: Integer;
     355  UnitsToAssign: Boolean;
    363356  Adjacent: TVicinity8Loc;
    364357  SettlerOfJobLoc, DistToLoc: array[0..lxmax * lymax - 1] of smallint;
    365358  // DistToLoc is only defined where SettlerOfJobLoc>=0
    366   TileChecked: array[0..lxmax * lymax - 1] of boolean;
    367 begin
    368   fillchar(SettlerOfJobLoc, MapSize * 2, $FF); // -1
     359  TileChecked: array[0..lxmax * lymax - 1] of Boolean;
     360begin
     361  FillChar(SettlerOfJobLoc, MapSize * 2, $FF); // -1
    369362
    370363  // keep up jobs that are already started
     
    387380        BestJob := jNone;
    388381        BestScore := -999999;
    389         FillChar(TileChecked, MapSize * sizeof(boolean), False);
     382        FillChar(TileChecked, MapSize * SizeOf(Boolean), False);
    390383        Pile.Create(MapSize);
    391384        Pile.Put(MyUnit[uix].Loc, 0); // start search for new job at current location
     
    406399                  and (Map[NextLoc] and (fUnit or fOwned) <> fUnit) // no foreign unit
    407400                  and ((RO.Territory[NextLoc] < 0) or
    408                   (RO.Territory[NextLoc] = me)) // no foreign territory
     401                  (RO.Territory[NextLoc] = Me)) // no foreign territory
    409402                  and (Map[TestLoc] and Map[NextLoc] and fInEnemyZoC = 0) then
    410403                  // move not prevented by ZoC
     
    421414            ((SettlerOfJobLoc[TestLoc] < 0) or (DistToLoc[TestLoc] > TestDistance)) then
    422415          begin
    423             TestScore := integer(TileJobScore[TestLoc]) - DistanceScore * TestDistance;
     416            TestScore := Integer(TileJobScore[TestLoc]) - DistanceScore * TestDistance;
    424417            if TestScore > BestScore then
    425418              BestCount := 0;
     
    469462          Unit_StartJob(uix, TileJob[JobLocOfSettler[uix]]);
    470463      end;
    471 end; // JobAssignment_Go
    472 
     464end;
    473465
    474466//------------------------------------------------------------------------------
     
    477469procedure TToolAI.AnalyzeMap;
    478470var
    479   i, j, Loc, Loc1, V8, Count, Kind, MostIndex: integer;
     471  I, J, Loc, Loc1, V8, Count, Kind, MostIndex: Integer;
    480472  Adjacent: TVicinity8Loc;
    481473  IndexOfID: array[0..lxmax * lymax - 1] of smallint;
    482474  IDOfIndex: array[0..lxmax * lymax div 2 - 1] of smallint;
    483475begin
    484   fillchar(District, MapSize * 4, $FF);
     476  FillChar(District, MapSize * 4, $FF);
    485477  for Loc := 0 to MapSize - 1 do
    486478    if Map[Loc] and fTerrain = fUNKNOWN then
     
    508500              Formation[Loc], Formation[Loc1]);
    509501      end;
    510       if (RO.Territory[Loc] = me) and (Map[Loc] and fTerrain >= fGrass) then
     502      if (RO.Territory[Loc] = Me) and (Map[Loc] and fTerrain >= fGrass) then
    511503      begin
    512504        District[Loc] := Loc;
     
    553545        Inc(Count);
    554546      end;
    555     for i := 0 to Count - 2 do
    556     begin
    557       MostIndex := i;
    558       for j := i + 1 to Count - 1 do
    559         if IndexOfID[IDOfIndex[j]] > IndexOfID[IDOfIndex[MostIndex]] then
    560           MostIndex := j;
    561       if MostIndex <> i then
    562       begin
    563         j := IDOfIndex[i];
    564         IDOfIndex[i] := IDOfIndex[MostIndex];
    565         IDOfIndex[MostIndex] := j;
    566       end;
    567     end;
    568     for i := 0 to Count - 1 do
    569       IndexOfID[IDOfIndex[i]] := i;
     547    for I := 0 to Count - 2 do
     548    begin
     549      MostIndex := I;
     550      for J := I + 1 to Count - 1 do
     551        if IndexOfID[IDOfIndex[J]] > IndexOfID[IDOfIndex[MostIndex]] then
     552          MostIndex := J;
     553      if MostIndex <> I then
     554      begin
     555        J := IDOfIndex[I];
     556        IDOfIndex[I] := IDOfIndex[MostIndex];
     557        IDOfIndex[MostIndex] := J;
     558      end;
     559    end;
     560    for I := 0 to Count - 1 do
     561      IndexOfID[IDOfIndex[I]] := I;
    570562
    571563    case Kind of
     
    594586  end;
    595587end;
    596 
    597588
    598589//------------------------------------------------------------------------------
     
    614605// other:  |   Basic   | 0| Speed  |              X X X             | MaxTerrType  |
    615606
    616 function TToolAI.GetMyMoveStyle(mix, Health: integer): integer;
     607function TToolAI.GetMyMoveStyle(mix, Health: Integer): Integer;
    617608begin
    618609  with MyModel[mix] do
     
    623614      begin
    624615        Inc(Result, (50 + (Speed - 150) * 13 shr 7) shl 8); //HeavyCost
    625         if RO.Wonder[woShinkansen].EffectiveOwner <> me then
     616        if RO.Wonder[woShinkansen].EffectiveOwner <> Me then
    626617          Inc(Result, Speed * (4 * 1311) shr 17); // RailCost
    627         if (RO.Wonder[woGardens].EffectiveOwner <> me) or
     618        if (RO.Wonder[woGardens].EffectiveOwner <> Me) or
    628619          (Kind = mkSettler) and (Speed >= 200) then
    629620          Inc(Result, msHostile);
     
    640631      begin
    641632        Result := Speed;
    642         if RO.Wonder[woMagellan].EffectiveOwner = me then
     633        if RO.Wonder[woMagellan].EffectiveOwner = Me then
    643634          Inc(Result, 200);
    644635        if Health < 100 then
     
    655646end;
    656647
    657 function TToolAI.CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: integer;
    658   var TimeAfterStep, RecoverTurns: integer; FromTile, ToTile: integer;
    659   IsCapture: boolean): integer;
    660 var
    661   MoveCost, RecoverCost: integer;
     648function TToolAI.CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: Integer;
     649  var TimeAfterStep, RecoverTurns: Integer; FromTile, ToTile: Integer;
     650  IsCapture: Boolean): Integer;
     651var
     652  MoveCost, RecoverCost: Integer;
    662653begin
    663654  //IsCapture:=true;
    664   assert(((FromTile and fTerrain <= fMountains) or (FromTile and
     655  Assert(((FromTile and fTerrain <= fMountains) or (FromTile and
    665656    fTerrain = fUNKNOWN)) and ((ToTile and fTerrain <= fMountains) or
    666657    (ToTile and fTerrain = fUNKNOWN)));
     
    710701                if ToTile and fPeace <> 0 then
    711702                  Result := csCheckTerritory;
    712                 exit;
     703                Exit;
    713704              end;
    714705            end;
     
    829820          begin
    830821            Result := csForbiddenTile;
    831             exit;
     822            Exit;
    832823          end;
    833824        end
     
    878869              // must wait for next turn
    879870              Result := csOk;
    880               exit;
     871              Exit;
    881872            end;
    882873          end;
     
    898889      Result := csForbiddenTile;
    899890  end;
    900 end; // CheckStep
     891end;
    901892
    902893(*
    903894-------- Pathfinding Reference Implementation --------
    904895var
    905 MoveStyle,V8,Loc,Time,NextLoc,NextTime,RecoverTurns: integer;
     896MoveStyle,V8,Loc,Time,NextLoc,NextTime,RecoverTurns: Integer;
    906897Adjacent: TVicinity8Loc;
    907 Reached: array[0..lxmax*lymax-1] of boolean;
    908 begin
    909 fillchar(Reached, MapSize, false);
     898Reached: array[0..lxmax*lymax-1] of Boolean;
     899begin
     900FillChar(Reached, MapSize, False);
    910901MoveStyle:=GetMyMoveStyle(MyUnit[uix].mix, MyUnit[uix].Health);
    911902Pile.Create(MapSize);
     
    915906  // todo: check exit condition, e.g. whether destination reached
    916907
    917   Reached[Loc]:=true;
     908  Reached[Loc]:=True;
    918909  V8_to_Loc(Loc, Adjacent);
    919910  for V8:=0 to 7 do
     
    925916          Pile.Put(NextLoc, NextTime+RecoverTurns*$1000);
    926917        csForbiddenTile:
    927           Reached[NextLoc]:=true; // don't check moving there again
     918          Reached[NextLoc]:=True; // don't check moving there again
    928919        csCheckTerritory:
    929920          if RO.Territory[NextLoc]=RO.Territory[Loc] then
     
    936927*)
    937928
    938 function TToolAI.Unit_MoveEx(uix, ToLoc: integer; Options: integer): integer;
     929function TToolAI.Unit_MoveEx(uix, ToLoc: Integer; Options: Integer): Integer;
    939930var
    940931  Loc, NextLoc, Temp, FromLoc, EndLoc, Time, V8, MoveResult, RecoverTurns,
    941   NextTime, MoveStyle: integer;
     932  NextTime, MoveStyle: Integer;
    942933  Adjacent: TVicinity8Loc;
    943   PreLoc: array[0..lxmax * lymax - 1] of integer;
    944   Reached: array[0..lxmax * lymax - 1] of boolean;
     934  PreLoc: array[0..lxmax * lymax - 1] of Integer;
     935  Reached: array[0..lxmax * lymax - 1] of Boolean;
    945936begin
    946937  Result := eOk;
    947938  FromLoc := MyUnit[uix].Loc;
    948939  if FromLoc = ToLoc then
    949     exit;
     940    Exit;
    950941
    951942  FillChar(Reached, MapSize, False);
     
    10121003      begin
    10131004        Result := MoveResult;
    1014         break;
     1005        Break;
    10151006      end;
    10161007    end;
     
    10201011end;
    10211012
    1022 
    10231013//------------------------------------------------------------------------------
    10241014// Oversea Transport
     
    10261016procedure TToolAI.SeaTransport_BeginInitialize;
    10271017begin
    1028   fillchar(TransportAvailable, RO.nUn * sizeof(integer), $FF); // -1
     1018  FillChar(TransportAvailable, RO.nUn * SizeOf(Integer), $FF); // -1
    10291019  InitComplete := False;
    10301020  HaveDestinations := False;
     
    10351025end;
    10361026
    1037 procedure TToolAI.SeaTransport_AddLoad(uix: integer);
    1038 var
    1039   i: integer;
    1040 begin
    1041   assert(not InitComplete); // call order violation!
     1027procedure TToolAI.SeaTransport_AddLoad(uix: Integer);
     1028var
     1029  I: Integer;
     1030begin
     1031  Assert(not InitComplete); // call order violation!
    10421032  if Map[MyUnit[uix].Loc] and fTerrain < fGrass then
    1043     exit;
    1044   for i := 0 to nTransportLoad - 1 do
    1045     if uix = uixTransportLoad[i] then
    1046       exit;
     1033    Exit;
     1034  for I := 0 to nTransportLoad - 1 do
     1035    if uix = uixTransportLoad[I] then
     1036      Exit;
    10471037  uixTransportLoad[nTransportLoad] := uix;
    10481038  Inc(nTransportLoad);
    10491039end;
    10501040
    1051 procedure TToolAI.SeaTransport_AddTransport(uix: integer);
    1052 var
    1053   MoveStyle: integer;
    1054 begin
    1055   assert(not InitComplete); // call order violation!
    1056   assert(MyModel[MyUnit[uix].mix].Cap[mcSeaTrans] > 0);
     1041procedure TToolAI.SeaTransport_AddTransport(uix: Integer);
     1042var
     1043  MoveStyle: Integer;
     1044begin
     1045  Assert(not InitComplete); // call order violation!
     1046  Assert(MyModel[MyUnit[uix].mix].Cap[mcSeaTrans] > 0);
    10571047  TransportAvailable[uix] := 1;
    10581048  with MyModel[MyUnit[uix].mix] do
     
    10681058end;
    10691059
    1070 procedure TToolAI.SeaTransport_AddDestination(Loc: integer);
    1071 begin
    1072   assert(not InitComplete); // call order violation!
     1060procedure TToolAI.SeaTransport_AddDestination(Loc: Integer);
     1061begin
     1062  Assert(not InitComplete); // call order violation!
    10731063  Pile.Put(Loc, $800);
    10741064  HaveDestinations := True;
     
    10771067procedure TToolAI.SeaTransport_EndInitialize;
    10781068var
    1079   Loc0, Time0, V8, Loc1, ArriveTime, RecoverTurns: integer;
     1069  Loc0, Time0, V8, Loc1, ArriveTime, RecoverTurns: Integer;
    10801070  Adjacent: TVicinity8Loc;
    10811071begin
    1082   assert(not InitComplete); // call order violation!
     1072  Assert(not InitComplete); // call order violation!
    10831073  InitComplete := True;
    10841074  if HaveDestinations then
    10851075  begin // calculate TurnsAfterLoad from destination locs
    1086     fillchar(TurnsAfterLoad, MapSize, $FF); // -1
     1076    FillChar(TurnsAfterLoad, MapSize, $FF); // -1
    10871077    while Pile.Get(Loc0, Time0) do
    10881078    begin // search backward
     
    11091099end;
    11101100
    1111 
    11121101function TToolAI.SeaTransport_MakeGroupPlan(
    1113   var TransportPlan: TGroupTransportPlan): boolean;
    1114 var
    1115   V8, i, j, iPicked, uix, Loc0, Time0, Loc1, RecoverTurns, MoveStyle,
     1102  var TransportPlan: TGroupTransportPlan): Boolean;
     1103var
     1104  V8, I, J, iPicked, uix, Loc0, Time0, Loc1, RecoverTurns, MoveStyle,
    11161105  TurnsLoaded, TurnCount, tuix, tuix1, ArriveTime, TotalDelay,
    11171106  BestTotalDelay, GroupCount, BestGroupCount, BestLoadLoc, FullMovementLoc,
    1118   nSelectedLoad, f, OriginContinent, a, b: integer;
    1119   CompleteFlag, NotReachedFlag, ContinueUnit: cardinal;
    1120   IsComplete, ok, IsFirstLoc: boolean;
     1107  nSelectedLoad, F, OriginContinent, A, B: Integer;
     1108  CompleteFlag, NotReachedFlag, ContinueUnit: Cardinal;
     1109  IsComplete, ok, IsFirstLoc: Boolean;
    11211110  StartLocPtr, ArrivedEnd: pinteger;
    11221111  Adjacent: TVicinity8Loc;
    1123   uixSelectedLoad: array[0..15] of integer;
    1124   tuixSelectedLoad: array[0..15] of integer;
    1125   Arrived: array[0..lxmax * lymax] of cardinal;
     1112  uixSelectedLoad: array[0..15] of Integer;
     1113  tuixSelectedLoad: array[0..15] of Integer;
     1114  Arrived: array[0..lxmax * lymax] of Cardinal;
    11261115  ResponsibleTransport: array[0..lxmax * lymax - 1] of smallint;
    1127   TurnsBeforeLoad: array[0..lxmax * lymax - 1] of shortint;
    1128   GroupComplete: array[0..lxmax * lymax - 1] of boolean;
    1129 begin
    1130   assert(InitComplete); // call order violation!
     1116  TurnsBeforeLoad: array[0..lxmax * lymax - 1] of ShortInt;
     1117  GroupComplete: array[0..lxmax * lymax - 1] of Boolean;
     1118begin
     1119  Assert(InitComplete); // call order violation!
    11311120
    11321121  if HaveDestinations and (nTransportLoad > 0) then
     
    11391128        for tuix := 0 to nTransportLoad - 1 do
    11401129        begin
    1141           Loc_to_ab(MyUnit[uix].Loc, MyUnit[uixTransportLoad[tuix]].Loc, a, b);
    1142           if (abs(a) <= 1) and (abs(b) <= 1) then
     1130          Loc_to_ab(MyUnit[uix].Loc, MyUnit[uixTransportLoad[tuix]].Loc, A, B);
     1131          if (abs(A) <= 1) and (abs(B) <= 1) then
    11431132          begin
    1144             assert((a <> 0) or (b <> 0));
     1133            Assert((A <> 0) or (B <> 0));
    11451134            Inc(GroupCount);
    11461135          end;
     
    11561145          for tuix := nTransportLoad - 1 downto 0 do
    11571146          begin
    1158             Loc_to_ab(TransportPlan.LoadLoc, MyUnit[uixTransportLoad[tuix]].Loc, a, b);
    1159             if (abs(a) <= 1) and (abs(b) <= 1) then
     1147            Loc_to_ab(TransportPlan.LoadLoc, MyUnit[uixTransportLoad[tuix]].Loc, A, B);
     1148            if (abs(A) <= 1) and (abs(B) <= 1) then
    11601149            begin
    11611150              TransportPlan.uixLoad[TransportPlan.nLoad] := uixTransportLoad[tuix];
     
    11641153              Inc(TransportPlan.nLoad);
    11651154              if TransportPlan.nLoad = TransportCapacity then
    1166                 break;
     1155                Break;
    11671156            end;
    11681157          end;
    11691158          Result := True;
    1170           exit;
     1159          Exit;
    11711160        end;
    11721161      end;
     
    11761165  begin
    11771166    // select units from same continent
    1178     fillchar(Arrived, 4 * nContinent, 0); // misuse Arrived as counter
     1167    FillChar(Arrived, 4 * nContinent, 0); // misuse Arrived as counter
    11791168    for tuix := 0 to nTransportLoad - 1 do
    11801169    begin
    1181       assert(Map[MyUnit[uixTransportLoad[tuix]].Loc] and fTerrain >= fGrass);
    1182       f := Formation[MyUnit[uixTransportLoad[tuix]].Loc];
    1183       if f >= 0 then
    1184         Inc(Arrived[f]);
     1170      Assert(Map[MyUnit[uixTransportLoad[tuix]].Loc] and fTerrain >= fGrass);
     1171      F := Formation[MyUnit[uixTransportLoad[tuix]].Loc];
     1172      if F >= 0 then
     1173        Inc(Arrived[F]);
    11851174    end;
    11861175    OriginContinent := 0;
    1187     for f := 1 to nContinent - 1 do
    1188       if Arrived[f] > Arrived[OriginContinent] then
    1189         OriginContinent := f;
     1176    for F := 1 to nContinent - 1 do
     1177      if Arrived[F] > Arrived[OriginContinent] then
     1178        OriginContinent := F;
    11901179    nSelectedLoad := 0;
    11911180    for tuix := 0 to nTransportLoad - 1 do
     
    11961185        Inc(nSelectedLoad);
    11971186        if nSelectedLoad = 16 then
    1198           break;
     1187          Break;
    11991188      end;
    12001189
    12011190    Pile.Create(MapSize);
    1202     fillchar(ResponsibleTransport, MapSize * 2, $FF); // -1
    1203     fillchar(TurnsBeforeLoad, MapSize, $FF); // -1
     1191    FillChar(ResponsibleTransport, MapSize * 2, $FF); // -1
     1192    FillChar(TurnsBeforeLoad, MapSize, $FF); // -1
    12041193    ok := False;
    12051194    for uix := 0 to RO.nUn - 1 do
     
    12141203      Result := False;
    12151204      Pile.Free;
    1216       exit;
     1205      Exit;
    12171206    end;
    12181207    while Pile.Get(Loc0, Time0) do
     
    12351224    end;
    12361225
    1237     fillchar(Arrived, MapSize * 4, $55); // set NotReachedFlag for all tiles
    1238     fillchar(GroupComplete, MapSize, False);
     1226    FillChar(Arrived, MapSize * 4, $55); // set NotReachedFlag for all tiles
     1227    FillChar(GroupComplete, MapSize, False);
    12391228    BestLoadLoc := -1;
    12401229
     
    12431232    begin
    12441233      uix := uixSelectedLoad[tuix];
    1245       if MyUnit[uix].Movement = integer(MyModel[MyUnit[uix].mix].Speed) then
     1234      if MyUnit[uix].Movement = Integer(MyModel[MyUnit[uix].mix].Speed) then
    12461235      begin
    12471236        NotReachedFlag := 1 shl (2 * tuix);
     
    12571246            if (TurnsBeforeLoad[Loc1] >= 0) and (TurnsAfterLoad[Loc1] >= 0) then
    12581247            begin
    1259               i := 1;
     1248              I := 1;
    12601249              GroupCount := 0;
    12611250              for tuix1 := 0 to nSelectedLoad - 1 do
    12621251              begin
    1263                 if Arrived[loc1] and i = 0 then
     1252                if Arrived[loc1] and I = 0 then
    12641253                  Inc(GroupCount);
    1265                 i := i shl 2;
     1254                I := I shl 2;
    12661255              end;
    1267               assert(GroupCount <= TransportCapacity);
     1256              Assert(GroupCount <= TransportCapacity);
    12681257              if (GroupCount = TransportCapacity) or (GroupCount = nSelectedLoad) then
    12691258                GroupComplete[loc1] := True;
     
    13031292          begin
    13041293            Pile.Put(MyUnit[uix].Loc, $1800 - MyUnit[uix].Movement);
    1305             if MyUnit[uix].Movement = integer(MyModel[MyUnit[uix].mix].Speed) then
     1294            if MyUnit[uix].Movement = Integer(MyModel[MyUnit[uix].mix].Speed) then
    13061295              FullMovementLoc := MyUnit[uix].Loc;
    13071296            // surrounding tiles can be loaded immediately
     
    13191308            if StartLocPtr <> ArrivedEnd then
    13201309            begin
    1321               Loc0 := (integer(StartLocPtr) - integer(@Arrived)) shr 2;
     1310              Loc0 := (Integer(StartLocPtr) - Integer(@Arrived)) shr 2;
    13221311              Inc(StartLocPtr);
    13231312              Time0 := $800;
     
    13271316              if IsFirstLoc then
    13281317                ContinueUnit := ContinueUnit and not (1 shl tuix);
    1329               break;
     1318              Break;
    13301319            end;
    13311320            IsFirstLoc := False;
     
    13341323            if not GroupComplete[Loc0] and (Map[Loc0] and fTerrain <> fMountains) then
    13351324            begin // check whether group complete -- no mountains because complete flag might be faked there
    1336               i := 1;
     1325              I := 1;
    13371326              GroupCount := 0;
    13381327              for tuix1 := 0 to nSelectedLoad - 1 do
    13391328              begin
    1340                 if Arrived[Loc0] and i = 0 then
     1329                if Arrived[Loc0] and I = 0 then
    13411330                  Inc(GroupCount);
    1342                 i := i shl 2;
     1331                I := I shl 2;
    13431332              end;
    1344               assert(GroupCount <= TransportCapacity);
     1333              Assert(GroupCount <= TransportCapacity);
    13451334              if (GroupCount = TransportCapacity) or (GroupCount = nSelectedLoad) then
    13461335                GroupComplete[Loc0] := True;
     
    13641353                if (TurnsBeforeLoad[Loc1] >= 0) and (TurnsAfterLoad[Loc1] >= 0) then
    13651354                begin
    1366                   i := 1;
     1355                  I := 1;
    13671356                  GroupCount := 0;
    13681357                  for tuix1 := 0 to nSelectedLoad - 1 do
    13691358                  begin
    1370                     if Arrived[loc1] and i = 0 then
     1359                    if Arrived[loc1] and I = 0 then
    13711360                      Inc(GroupCount);
    1372                     i := i shl 2;
     1361                    I := I shl 2;
    13731362                  end;
    1374                   assert(GroupCount <= TransportCapacity);
     1363                  Assert(GroupCount <= TransportCapacity);
    13751364                  if (GroupCount = TransportCapacity) or
    13761365                    (GroupCount = nSelectedLoad) then
     
    14471436        if 1 shl (2 * tuix) and Arrived[BestLoadLoc] = 0 then
    14481437        begin
    1449           assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);
     1438          Assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);
    14501439          TransportPlan.uixLoad[TransportPlan.nLoad] := uixSelectedLoad[tuix];
    14511440          uixTransportLoad[tuixSelectedLoad[tuix]] :=
     
    14551444        end;
    14561445      Result := True;
    1457       exit;
     1446      Exit;
    14581447    end;
    14591448
     
    14621451    for tuix := nSelectedLoad - 1 downto 0 do
    14631452    begin
    1464       assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);
     1453      Assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);
    14651454      uixTransportLoad[tuixSelectedLoad[tuix]] :=
    14661455        uixTransportLoad[nTransportLoad - 1];
     
    14721461end;
    14731462
    1474 
    14751463//------------------------------------------------------------------------------
    14761464// Misc
    14771465
    1478 function TToolAI.CurrentMStrength(Domain: integer): integer;
    1479 var
    1480   i: integer;
     1466function TToolAI.CurrentMStrength(Domain: Integer): Integer;
     1467var
     1468  I: Integer;
    14811469begin
    14821470  Result := 0;
    1483   for i := 0 to nUpgrade - 1 do
    1484     with upgrade[Domain, i] do
     1471  for I := 0 to nUpgrade - 1 do
     1472    with upgrade[Domain, I] do
    14851473      if (Preq = preNone) or (Preq >= 0) and
    14861474        ((RO.Tech[Preq] >= tsApplicable) or (Preq in FutureTech) and
     
    14941482end;
    14951483
    1496 
    14971484//------------------------------------------------------------------------------
    14981485
    14991486procedure SetAdvancedness;
    15001487var
    1501   ad, j, Reduction, AgeThreshold: integer;
    1502   known: array[0..nAdv - 1] of integer;
    1503 
    1504   procedure MarkPreqs(ad: integer);
     1488  ad, J, Reduction, AgeThreshold: Integer;
     1489  known: array[0..nAdv - 1] of Integer;
     1490
     1491  procedure MarkPreqs(ad: Integer);
    15051492  var
    1506     i: integer;
     1493    I: Integer;
    15071494  begin
    15081495    if known[ad] = 0 then
    15091496    begin
    15101497      known[ad] := 1;
    1511       for i := 0 to 2 do
    1512         if AdvPreq[ad, i] >= 0 then
    1513           MarkPreqs(AdvPreq[ad, i]);
     1498      for I := 0 to 2 do
     1499        if AdvPreq[ad, I] >= 0 then
     1500          MarkPreqs(AdvPreq[ad, I]);
    15141501    end;
    15151502  end;
     
    15211508    FillChar(known, SizeOf(known), 0);
    15221509    MarkPreqs(ad);
    1523     for j := 0 to nAdv - 1 do
    1524       if known[j] > 0 then
     1510    for J := 0 to nAdv - 1 do
     1511      if known[J] > 0 then
    15251512        Inc(Advancedness[ad]);
    15261513  end;
  • branches/highdpi/Back.lfm

    r246 r465  
    88  Caption = 'C-evo'
    99  Color = clBlack
     10  DesignTimePPI = 144
    1011  Font.Color = clWindowText
    11   Font.Height = -13
     12  Font.Height = -30
    1213  Font.Name = 'MS Sans Serif'
    1314  OnClose = FormClose
     
    1617  OnPaint = FormPaint
    1718  OnShow = FormShow
    18   LCLVersion = '1.6.2.0'
    19   WindowState = wsMaximized
    20   PixelsPerInch = 96
     19  ShowInTaskBar = stNever
     20  LCLVersion = '2.2.0.4'
    2121  Scaled = False
     22  WindowState = wsFullScreen
    2223end
  • branches/highdpi/Back.pas

    r349 r465  
    5151begin
    5252  if Assigned(Img) then
    53     DpiBitCanvas(Canvas, DpiScreen.Width - Img.Width - (DpiScreen.Width - 800) *
     53    DpiBitBltCanvas(Canvas, DpiScreen.Width - Img.Width - (DpiScreen.Width - 800) *
    5454      3 div 8, (DpiScreen.Height - 600) div 3, Img.Width, Img.Height,
    5555      Img.Canvas, 0, 0);
     
    7070      if FileExists(FileName) then begin
    7171        Img := TDpiBitmap.Create;
    72         LoadGraphicFile(img, FileName);
     72        LoadGraphicFile(Img, FileName);
     73        Repaint;
    7374      end;
    7475    end;
  • branches/highdpi/Brain.pas

    r464 r465  
    1 unit UBrain;
    2 
    3 {$mode delphi}
     1unit Brain;
    42
    53interface
    64
    75uses
    8   UDpiControls, Classes, SysUtils, fgl, Graphics, Protocol, LazFileUtils, dynlibs;
     6  UDpiControls, Classes, SysUtils, Generics.Collections, Graphics, Protocol, LazFileUtils,
     7  dynlibs, Types;
    98
    109const
     
    3534    Picture: TDpiBitmap;
    3635    Beginner: Boolean;
     36    procedure LoadPicture;
    3737    procedure LoadFromFile(AIFileName: string);
    3838    constructor Create;
     
    4242  { TBrains }
    4343
    44   TBrains = class(TFPGObjectList<TBrain>)
     44  TBrains = class(TObjectList<TBrain>)
    4545    function AddNew: TBrain;
    4646    function GetKindCount(Kind: TBrainType): Integer;
    4747    procedure GetByKind(Kind: TBrainType; Brains: TBrains);
    4848    function GetBeginner: TBrain;
     49    procedure LoadPictures;
    4950  end;
    5051
     
    5354
    5455uses
    55   ScreenTools;
     56  ScreenTools, Directories;
    5657
    5758{ TBrain }
     59
     60procedure TBrain.LoadPicture;
     61var
     62  TextSize: TSize;
     63begin
     64  if not LoadGraphicFile(Picture, GetAiDir + DirectorySeparator +
     65    FileName + DirectorySeparator + FileName + '.png', [gfNoError]) then begin
     66    with Picture.Canvas do begin
     67      Brush.Color := $904830;
     68      FillRect(Rect(0, 0, 64, 64));
     69      Font.Assign(UniFont[ftTiny]);
     70      Font.Style := [];
     71      Font.Color := $5FDBFF;
     72      TextSize := TextExtent(FileName);
     73      TextOut(32 - TextSize.Width div 2, 32 - TextSize.Height div 2, FileName);
     74    end;
     75  end;
     76end;
    5877
    5978procedure TBrain.LoadFromFile(AIFileName: string);
     
    106125      DLLName := BasePath + DirectorySeparator + Value
    107126    {$ENDIF}{$ENDIF}
    108     {$IFDEF LINUX}{$IFDEF CPU32}
    109     else if Key = '#PATH_LINUX32' then
    110       DLLName := BasePath + DirectorySeparator + Value
    111     {$ENDIF}{$ENDIF}
    112     {$IFDEF LINUX}{$IFDEF CPU64}
    113     else if Key = '#PATH_LINUX64' then
     127    {$IFDEF UNIX}{$IFDEF CPUI386}
     128    else if Key = '#PATH_LINUX_I386' then
     129      DLLName := BasePath + DirectorySeparator + Value
     130    {$ENDIF}{$ENDIF}
     131    {$IFDEF UNIX}{$IFDEF CPUAMD64}
     132    else if Key = '#PATH_LINUX_AMD64' then
     133      DLLName := BasePath + DirectorySeparator + Value
     134    {$ENDIF}{$ENDIF}
     135    {$IFDEF UNIX}{$IFDEF CPUARM}
     136    else if Key = '#PATH_LINUX_ARM32' then
     137      DLLName := BasePath + DirectorySeparator + Value
     138    {$ENDIF}{$ENDIF}
     139    {$IFDEF UNIX}{$IFDEF CPUAARCH64}
     140    else if Key = '#PATH_LINUX_ARM64' then
    114141      DLLName := BasePath + DirectorySeparator + Value
    115142    {$ENDIF}{$ENDIF}
     
    177204end;
    178205
     206procedure TBrains.LoadPictures;
     207var
     208  I: Integer;
     209begin
     210  for I := 0 to Count - 1 do
     211    with Items[I] do LoadPicture;
     212end;
     213
    179214end.
    180215
     216
     217
  • branches/highdpi/CityProcessing.pas

    r349 r465  
    88
    99// Reporting
    10 procedure GetCityAreaInfo(p, Loc: integer; var CityAreaInfo: TCityAreaInfo);
    11 function CanCityGrow(p, cix: integer): boolean;
    12 function GetCityReport(p, cix: integer; var CityReport: TCityReport): integer;
    13 function GetCityReportNew(p, cix: integer;
    14   var CityReportNew: TCityReportNew): integer;
     10procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo);
     11function CanCityGrow(P, cix: Integer): Boolean;
     12function GetCityReport(P, cix: Integer; var CityReport: TCityReport): Integer;
     13function GetCityReportNew(P, cix: Integer;
     14  var CityReportNew: TCityReportNew): Integer;
    1515
    1616// Internal Tile Picking
    17 function AddBestCityTile(p, cix: integer): boolean;
    18 procedure CityGrowth(p, cix: integer);
    19 procedure CityShrink(p, cix: integer);
    20 procedure Pollute(p, cix: integer);
     17function AddBestCityTile(P, cix: Integer): Boolean;
     18procedure CityGrowth(P, cix: Integer);
     19procedure CityShrink(P, cix: Integer);
     20procedure Pollute(P, cix: Integer);
    2121
    2222// Turn Processing
    23 procedure PayCityMaintenance(p, cix: integer);
    24 procedure CollectCityResources(p, cix: integer);
    25 function CityTurn(p, cix: integer): boolean;
     23procedure PayCityMaintenance(P, cix: Integer);
     24procedure CollectCityResources(P, cix: Integer);
     25function CityTurn(P, cix: Integer): Boolean;
    2626
    2727// Tile Access
    28 function SetCityTiles(p, cix, NewTiles: integer;
    29   TestOnly: boolean = false): integer;
    30 procedure GetCityTileAdvice(p, cix: integer; var Advice: TCityTileAdviceData);
     28function SetCityTiles(P, cix, NewTiles: Integer;
     29  TestOnly: Boolean = False): Integer;
     30procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData);
    3131
    3232// Start/End Game
     
    3434procedure ReleaseGame;
    3535
     36
    3637implementation
    3738
    3839type
    3940  TTradeProcessing = record
    40     TaxBonus, LuxBonus, ScienceBonus, FutResBonus, ScienceDoubling,
    41       HappyBase: integer;
    42     RelCorr: single;
    43     FlexibleLuxury: boolean;
     41    TaxBonus: Integer;
     42    LuxBonus: Integer;
     43    ScienceBonus: Integer;
     44    FutResBonus: Integer;
     45    ScienceDoubling: Integer;
     46    HappyBase: Integer;
     47    RelCorr: Single;
     48    FlexibleLuxury: Boolean;
    4449  end;
    4550
    4651  TProdProcessing = record
    47     ProdBonus, PollBonus, FutProdBonus, PollThreshold: integer;
     52    ProdBonus: Integer;
     53    PollBonus: Integer;
     54    FutProdBonus: Integer;
     55    PollThreshold: Integer;
    4856  end;
    4957
     
    5159
    5260  TCityReportEx = record
    53     BaseHappiness, BaseControl, Material: integer;
     61    BaseHappiness: Integer;
     62    BaseControl: Integer;
     63    Material: Integer;
    5464    ProdProcessing: TProdProcessing;
    5565    TradeProcessing: TTradeProcessing;
     
    5767
    5868var
    59   MaxDist: integer;
    60 
    61   {
    62     Reporting
    63     ____________________________________________________________________
    64   }
    65 procedure GetCityAreaInfo(p, Loc: integer; var CityAreaInfo: TCityAreaInfo);
    66 var
    67   V21, Loc1, p1: integer;
     69  MaxDist: Integer;
     70
     71{
     72  Reporting
     73  ____________________________________________________________________
     74}
     75procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo);
     76var
     77  V21, Loc1, p1: Integer;
    6878  Radius: TVicinity21Loc;
    6979begin
    70 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
     80{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
    7181  with CityAreaInfo do
    7282  begin
     
    8090      begin
    8191        p1 := RealMap[Loc1] shr 27;
    82         if (p1 < nPl) and (p1 <> p) and (RW[p].Treaty[p1] >= trPeace) then
     92        if (p1 < nPl) and (p1 <> P) and (RW[P].Treaty[p1] >= trPeace) then
    8393          Available[V21] := faTreaty
    84         else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> p) and
    85           (RW[p].Treaty[Occupant[Loc1]] < trAlliance) then
     94        else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> P) and
     95          (RW[P].Treaty[Occupant[Loc1]] < trAlliance) then
    8696          Available[V21] := faSiege
    8797        else if (UsedByCity[Loc1] <> -1) and (UsedByCity[Loc1] <> Loc) then
    8898          Available[V21] := faNotAvailable
    8999        else
    90           Available[V21] := faAvailable
    91       end
    92     end;
    93   end
    94 end;
    95 
    96 function CanCityGrow(p, cix: integer): boolean;
    97 begin
    98   with RW[p].City[cix] do
    99     result := (Size < MaxCitySize) and
     100          Available[V21] := faAvailable;
     101      end;
     102    end;
     103  end;
     104end;
     105
     106function CanCityGrow(P, cix: Integer): Boolean;
     107begin
     108  with RW[P].City[cix] do
     109    Result := (Size < MaxCitySize) and
    100110      ((Size < NeedAqueductSize) or (Built[imAqueduct] = 1) and
    101111      (Size < NeedSewerSize) or (Built[imSewer] = 1));
    102112end;
    103113
    104 procedure DetermineCityProdProcessing(p, cix: integer;
     114procedure DetermineCityProdProcessing(P, cix: Integer;
    105115  var ProdProcessing: TProdProcessing);
    106116begin
    107   with RW[p].City[cix], ProdProcessing do
     117  with RW[P].City[cix], ProdProcessing do
    108118  begin
    109119    ProdBonus := 0;
    110120    PollBonus := 0;
    111121    if Built[imFactory] = 1 then
    112       inc(ProdBonus);
     122      Inc(ProdBonus);
    113123    if Built[imMfgPlant] = 1 then
    114       inc(ProdBonus);
     124      Inc(ProdBonus);
    115125    if (Built[imPower] = 1) or (Built[imHydro] = 1) or (Built[imNuclear] = 1) or
    116       (GWonder[woHoover].EffectiveOwner = p) then
     126      (GWonder[woHoover].EffectiveOwner = P) then
    117127      ProdBonus := ProdBonus * 2;
    118128    if Built[imFactory] = 1 then
    119       inc(PollBonus);
     129      Inc(PollBonus);
    120130    if Built[imMfgPlant] = 1 then
    121       inc(PollBonus);
     131      Inc(PollBonus);
    122132    if (Built[imFactory] + Built[imMfgPlant] > 0) then
    123       if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = p) then
    124         dec(PollBonus)
     133      if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = P) then
     134        Dec(PollBonus)
    125135      else if (Built[imNuclear] = 0) and (Built[imPower] = 1) then
    126         inc(PollBonus);
    127     if (RW[p].Government <= gDespotism) or (Built[imRecycling] = 1) then
     136        Inc(PollBonus);
     137    if (RW[P].Government <= gDespotism) or (Built[imRecycling] = 1) then
    128138      PollBonus := -2; // no pollution
    129139    PollThreshold := Size;
    130140    FutProdBonus := 0;
    131     if RW[p].Tech[futProductionTechnology] > 0 then
     141    if RW[P].Tech[futProductionTechnology] > 0 then
    132142    begin // future tech benefits
    133143      if Built[imFactory] = 1 then
    134         inc(FutProdBonus, FactoryFutureBonus * RW[p].Tech
     144        Inc(FutProdBonus, FactoryFutureBonus * RW[P].Tech
    135145          [futProductionTechnology]);
    136146      if Built[imMfgPlant] = 1 then
    137         inc(FutProdBonus, MfgPlantFutureBonus * RW[p].Tech
     147        Inc(FutProdBonus, MfgPlantFutureBonus * RW[P].Tech
    138148          [futProductionTechnology]);
    139149    end;
     
    141151end;
    142152
    143 procedure BoostProd(BaseProd: integer; ProdProcessing: TProdProcessing;
    144   var Prod, Poll: integer);
     153procedure BoostProd(BaseProd: Integer; ProdProcessing: TProdProcessing;
     154  var Prod, Poll: Integer);
    145155begin
    146156  Poll := BaseProd * (2 + ProdProcessing.PollBonus) shr 1;
     
    148158    Poll := 0
    149159  else
    150     dec(Poll, ProdProcessing.PollThreshold);
     160    Dec(Poll, ProdProcessing.PollThreshold);
    151161  if ProdProcessing.FutProdBonus > 0 then
    152162    Prod := BaseProd * (100 + ProdProcessing.ProdBonus * 50 +
     
    156166end;
    157167
    158 procedure DetermineCityTradeProcessing(p, cix, HappinessBeforeLux: integer;
     168procedure DetermineCityTradeProcessing(P, cix, HappinessBeforeLux: Integer;
    159169  var TradeProcessing: TTradeProcessing);
    160170var
    161   i, Dist: integer;
    162 begin
    163   with RW[p].City[cix], TradeProcessing do
     171  I, Dist: Integer;
     172begin
     173  with RW[P].City[cix], TradeProcessing do
    164174  begin
    165175    TaxBonus := 0;
    166176    ScienceBonus := 0;
    167177    if Built[imMarket] = 1 then
    168       inc(TaxBonus, 2);
     178      Inc(TaxBonus, 2);
    169179    if Built[imBank] = 1 then
    170180    begin
    171       inc(TaxBonus, 3);
    172       if RW[p].NatBuilt[imStockEx] = 1 then
    173         inc(TaxBonus, 3);
     181      Inc(TaxBonus, 3);
     182      if RW[P].NatBuilt[imStockEx] = 1 then
     183        Inc(TaxBonus, 3);
    174184    end;
    175185    LuxBonus := TaxBonus;
    176186    if Built[imLibrary] = 1 then
    177       inc(ScienceBonus, 2);
     187      Inc(ScienceBonus, 2);
    178188    if Built[imUniversity] = 1 then
    179       inc(ScienceBonus, 3);
     189      Inc(ScienceBonus, 3);
    180190    if Built[imResLab] = 1 then
    181       inc(ScienceBonus, 3);
     191      Inc(ScienceBonus, 3);
    182192    ScienceDoubling := 0;
    183193    if Built[imNatObs] > 0 then
    184       inc(ScienceDoubling);
    185     if RW[p].Government = gFundamentalism then
    186       dec(ScienceDoubling)
    187     else if (GWonder[woNewton].EffectiveOwner = p) and
    188       (RW[p].Government = gMonarchy) then
    189       inc(ScienceDoubling);
    190     FlexibleLuxury := ((ServerVersion[p] >= $0100F1) and
    191       (GWonder[woLiberty].EffectiveOwner = p) or (ServerVersion[p] < $0100F1)
    192       and (GWonder[woMich].EffectiveOwner = p)) and
    193       (RW[p].Government <> gAnarchy);
     194      Inc(ScienceDoubling);
     195    if RW[P].Government = gFundamentalism then
     196      Dec(ScienceDoubling)
     197    else if (GWonder[woNewton].EffectiveOwner = P) and
     198      (RW[P].Government = gMonarchy) then
     199      Inc(ScienceDoubling);
     200    FlexibleLuxury := ((ServerVersion[P] >= $0100F1) and
     201      (GWonder[woLiberty].EffectiveOwner = P) or (ServerVersion[P] < $0100F1)
     202      and (GWonder[woMich].EffectiveOwner = P)) and
     203      (RW[P].Government <> gAnarchy);
    194204    FutResBonus := 0;
    195     if RW[p].Tech[futResearchTechnology] > 0 then
     205    if RW[P].Tech[futResearchTechnology] > 0 then
    196206    begin // future tech benefits
    197207      if Built[imUniversity] = 1 then
    198         inc(FutResBonus, UniversityFutureBonus * RW[p].Tech
     208        Inc(FutResBonus, UniversityFutureBonus * RW[P].Tech
    199209          [futResearchTechnology]);
    200210      if Built[imResLab] = 1 then
    201         inc(FutResBonus, ResLabFutureBonus * RW[p].Tech[futResearchTechnology]);
    202     end;
    203     if (RW[p].NatBuilt[imPalace] > 0) or (ServerVersion[p] < $010000) then
     211        Inc(FutResBonus, ResLabFutureBonus * RW[P].Tech[futResearchTechnology]);
     212    end;
     213    if (RW[P].NatBuilt[imPalace] > 0) or (ServerVersion[P] < $010000) then
    204214    begin // calculate corruption
    205215      Dist := MaxDist;
    206       for i := 0 to RW[p].nCity - 1 do
    207         if (RW[p].City[i].Loc >= 0) and (RW[p].City[i].Built[imPalace] = 1) then
    208           Dist := Distance(Loc, RW[p].City[i].Loc);
    209       if (Dist = 0) or (CorrLevel[RW[p].Government] = 0) then
     216      for I := 0 to RW[P].nCity - 1 do
     217        if (RW[P].City[I].Loc >= 0) and (RW[P].City[I].Built[imPalace] = 1) then
     218          Dist := Distance(Loc, RW[P].City[I].Loc);
     219      if (Dist = 0) or (CorrLevel[RW[P].Government] = 0) then
    210220        RelCorr := 0.0
    211221      else
    212222      begin
    213223        RelCorr := Dist / MaxDist;
    214         if CorrLevel[RW[p].Government] > 1 then
    215           RelCorr := Exp(ln(RelCorr) / CorrLevel[RW[p].Government]);
     224        if CorrLevel[RW[P].Government] > 1 then
     225          RelCorr := Exp(ln(RelCorr) / CorrLevel[RW[P].Government]);
    216226        if Built[imCourt] = 1 then
    217227          RelCorr := RelCorr / 2;
     
    224234      RelCorr := 1.0;
    225235    HappyBase := Size + HappinessBeforeLux;
    226   end
    227 end;
    228 
    229 procedure SplitTrade(Trade, TaxRate, LuxRate, Working: integer;
     236  end;
     237end;
     238
     239procedure SplitTrade(Trade, TaxRate, LuxRate, Working: Integer;
    230240  TradeProcessing: TTradeProcessing; var Corruption, Tax, Lux,
    231   Science: integer);
    232 var
    233   plus: integer;
     241  Science: Integer);
     242var
     243  plus: Integer;
    234244begin
    235245  Corruption := Trunc(Trade * TradeProcessing.RelCorr);
     
    266276end;
    267277
    268 function GetProjectCost(p, cix: integer): integer;
    269 var
    270   i: integer;
    271 begin
    272   with RW[p].City[cix] do
     278function GetProjectCost(P, cix: Integer): Integer;
     279var
     280  I: Integer;
     281begin
     282  with RW[P].City[cix] do
    273283  begin
    274284    if Project and cpImp = 0 then
    275285    begin
    276       result := RW[p].Model[Project and cpIndex].Cost; { unit project }
     286      Result := RW[P].Model[Project and cpIndex].Cost; { unit project }
    277287      if Project and cpConscripts <> 0 then
    278288      begin
    279         i := RW[p].Model[Project and cpIndex].MCost;
    280         result := result - 3 * i;
    281         if result <= 0 then
    282           result := i
     289        I := RW[P].Model[Project and cpIndex].MCost;
     290        Result := Result - 3 * I;
     291        if Result <= 0 then
     292          Result := I;
    283293      end
    284       else if RW[p].Model[Project and cpIndex].Cap[mcLine] > 0 then
     294      else if RW[P].Model[Project and cpIndex].Cap[mcLine] > 0 then
    285295        if Project0 and (not cpAuto or cpRepeat) = Project and not cpAuto or cpRepeat
    286296        then
    287           result := result shr 1
     297          Result := Result shr 1
    288298        else
    289           result := result * 2
     299          Result := Result * 2;
    290300    end
    291301    else
    292302    begin { improvement project }
    293       result := Imp[Project and cpIndex].Cost;
    294       if (Project and cpIndex < nWonder) and (GWonder[woColossus].EffectiveOwner = p)
     303      Result := Imp[Project and cpIndex].Cost;
     304      if (Project and cpIndex < nWonder) and (GWonder[woColossus].EffectiveOwner = P)
    295305      then
    296         result := result * ColossusEffect div 100;
    297     end;
    298     result := result * BuildCostMod[Difficulty[p]] div 12;
    299   end
    300 end;
    301 
    302 function GetSmallCityReport(p, cix: integer; var CityReport: TCityReport;
    303   PCityReportEx: PCityReportEx = nil): integer;
    304 var
    305   i, uix, V21, Loc1, ForcedSupport, BaseHappiness, Control: integer;
     306        Result := Result * ColossusEffect div 100;
     307    end;
     308    Result := Result * BuildCostMod[Difficulty[P]] div 12;
     309  end;
     310end;
     311
     312function GetSmallCityReport(P, cix: Integer; var CityReport: TCityReport;
     313  PCityReportEx: PCityReportEx = nil): Integer;
     314var
     315  I, uix, V21, Loc1, ForcedSupport, BaseHappiness, Control: Integer;
    306316  ProdProcessing: TProdProcessing;
    307317  TradeProcessing: TTradeProcessing;
    308318  Radius: TVicinity21Loc;
    309319  UnitReport: TUnitReport;
    310   RareOK: array [0 .. 3] of integer;
     320  RareOK: array [0 .. 3] of Integer;
    311321  TileInfo: TTileInfo;
    312322begin
    313   with RW[p].City[cix], CityReport do
     323  with RW[P].City[cix], CityReport do
    314324  begin
    315325    if HypoTiles <= 0 then
    316326      HypoTiles := Tiles;
    317327    if HypoTax < 0 then
    318       HypoTax := RW[p].TaxRate;
     328      HypoTax := RW[P].TaxRate;
    319329    if HypoLux < 0 then
    320       HypoLux := RW[p].LuxRate;
    321 
    322     if (Flags and chCaptured <> 0) or (RW[p].Government = gAnarchy) then
     330      HypoLux := RW[P].LuxRate;
     331
     332    if (Flags and chCaptured <> 0) or (RW[P].Government = gAnarchy) then
    323333    begin
    324334      Working := 0;
    325335      for V21 := 1 to 26 do
    326336        if HypoTiles and (1 shl V21) <> 0 then
    327           inc(Working); // for backward compatibility
    328 
    329       if RW[p].Government = gFundamentalism then
     337          Inc(Working); // for backward compatibility
     338
     339      if RW[P].Government = gFundamentalism then
    330340      begin
    331341        Happy := Size;
    332         Control := Size
     342        Control := Size;
    333343      end // !!! old bug, kept for compatibility
    334344      else
    335345      begin
    336346        Happy := 0;
    337         Control := 0
     347        Control := 0;
    338348      end;
    339349
     
    370380          BaseHappiness := Size;
    371381      end;
    372       for i := 0 to nWonder - 1 do
    373         if Built[i] = 1 then
     382      for I := 0 to nWonder - 1 do
     383        if Built[I] = 1 then
    374384        begin
    375           inc(Happy);
    376           inc(BaseHappiness, 2)
     385          Inc(Happy);
     386          Inc(BaseHappiness, 2);
    377387        end;
    378388      if Built[imTemple] = 1 then
    379389      begin
    380         inc(Happy);
    381         inc(BaseHappiness, 2)
     390        Inc(Happy);
     391        Inc(BaseHappiness, 2);
    382392      end;
    383393      if Built[imCathedral] = 1 then
    384394      begin
    385         inc(Happy, 2);
    386         inc(BaseHappiness, 4);
    387         if GWonder[woBach].EffectiveOwner = p then
     395        Inc(Happy, 2);
     396        Inc(BaseHappiness, 4);
     397        if GWonder[woBach].EffectiveOwner = P then
    388398        begin
    389           inc(Happy);
    390           inc(BaseHappiness, 2)
     399          Inc(Happy);
     400          Inc(BaseHappiness, 2);
    391401        end;
    392402      end;
    393403      if Built[imTheater] > 0 then
    394404      begin
    395         inc(Happy, 2);
    396         inc(BaseHappiness, 4)
     405        Inc(Happy, 2);
     406        Inc(BaseHappiness, 4);
    397407      end;
    398408
    399409      // calculate unit support
    400 {$IFOPT O-}assert(InvalidTreatyMap = 0); {$ENDIF}
     410{$IFOPT O-}Assert(InvalidTreatyMap = 0); {$ENDIF}
    401411      Support := 0;
    402412      ForcedSupport := 0;
    403413      Eaten := Size * 2;
    404414      Deployed := 0;
    405       for uix := 0 to RW[p].nUn - 1 do
    406         with RW[p].Un[uix] do
     415      for uix := 0 to RW[P].nUn - 1 do
     416        with RW[P].Un[uix] do
    407417          if (Loc >= 0) and (Home = cix) then
    408418          begin
    409             GetUnitReport(p, uix, UnitReport);
    410             inc(Eaten, UnitReport.FoodSupport);
     419            GetUnitReport(P, uix, UnitReport);
     420            Inc(Eaten, UnitReport.FoodSupport);
    411421            if UnitReport.ReportFlags and urfAlwaysSupport <> 0 then
    412               inc(ForcedSupport, UnitReport.ProdSupport)
     422              Inc(ForcedSupport, UnitReport.ProdSupport)
    413423            else
    414               inc(Support, UnitReport.ProdSupport);
     424              Inc(Support, UnitReport.ProdSupport);
    415425            if UnitReport.ReportFlags and urfDeployed <> 0 then
    416               inc(Deployed);
     426              Inc(Deployed);
    417427          end;
    418428      if Deployed >= Happy then
    419429        Happy := 0
    420430      else
    421         dec(Happy, Deployed);
    422       dec(Support, Size * SupportFree[RW[p].Government] shr 1);
     431        Dec(Happy, Deployed);
     432      Dec(Support, Size * SupportFree[RW[P].Government] shr 1);
    423433      if Support < 0 then
    424434        Support := 0;
    425       inc(Support, ForcedSupport);
     435      Inc(Support, ForcedSupport);
    426436
    427437      { control }
    428       case RW[p].Government of
     438      case RW[P].Government of
    429439        gDespotism:
    430           for uix := 0 to RW[p].nUn - 1 do
    431             if (RW[p].Un[uix].Loc = Loc) and
    432               (RW[p].Model[RW[p].Un[uix].mix].Kind = mkSpecial_TownGuard) then
     440          for uix := 0 to RW[P].nUn - 1 do
     441            if (RW[P].Un[uix].Loc = Loc) and
     442              (RW[P].Model[RW[P].Un[uix].mix].Kind = mkSpecial_TownGuard) then
    433443            begin
    434               inc(Happy);
    435               inc(Control, 2)
     444              Inc(Happy);
     445              Inc(Control, 2);
    436446            end;
    437447        gFundamentalism:
     
    439449            BaseHappiness := 0; // done by control
    440450            Happy := Size;
    441             Control := Size
     451            Control := Size;
    442452          end;
    443453      end;
    444454
    445455      // collect processing parameters
    446       DetermineCityProdProcessing(p, cix, ProdProcessing);
    447       DetermineCityTradeProcessing(p, cix, BaseHappiness + Control - 2 *
     456      DetermineCityProdProcessing(P, cix, ProdProcessing);
     457      DetermineCityTradeProcessing(P, cix, BaseHappiness + Control - 2 *
    448458        Deployed, TradeProcessing);
    449459
     
    462472          // HypoTiles go beyond map border!
    463473          begin
    464             result := eInvalid;
    465             exit
     474            Result := eInvalid;
     475            Exit;
    466476          end;
    467           GetTileInfo(p, cix, Loc1, TileInfo);
    468           inc(FoodRep, TileInfo.Food);
    469           inc(ProdRep, TileInfo.Prod);
    470           inc(Trade, TileInfo.Trade);
     477          GetTileInfo(P, cix, Loc1, TileInfo);
     478          Inc(FoodRep, TileInfo.Food);
     479          Inc(ProdRep, TileInfo.Prod);
     480          Inc(Trade, TileInfo.Trade);
    471481          if (RealMap[Loc1] and fModern <> 0) and
    472             (RW[p].Tech[adMassProduction] >= tsApplicable) then
    473             inc(RareOK[RealMap[Loc1] shr 25 and 3]);
    474           inc(Working)
     482            (RW[P].Tech[adMassProduction] >= tsApplicable) then
     483            Inc(RareOK[RealMap[Loc1] shr 25 and 3]);
     484          Inc(Working);
    475485        end;
    476486      if Built[imAlgae] = 1 then
    477         inc(FoodRep, 12);
     487        Inc(FoodRep, 12);
    478488
    479489      if PCityReportEx <> nil then
     
    500510    end;
    501511  end;
    502   result := eOk;
    503 end; { GetSmallCityReport }
    504 
    505 function GetCityReport(p, cix: integer; var CityReport: TCityReport): integer;
    506 begin
    507   result := GetSmallCityReport(p, cix, CityReport);
    508   CityReport.Storage := StorageSize[Difficulty[p]];
    509   CityReport.ProdCost := GetProjectCost(p, cix);
    510 end;
    511 
    512 function GetCityReportNew(p, cix: integer;
    513   var CityReportNew: TCityReportNew): integer;
     512  Result := eOk;
     513end;
     514
     515function GetCityReport(P, cix: Integer; var CityReport: TCityReport): Integer;
     516begin
     517  Result := GetSmallCityReport(P, cix, CityReport);
     518  CityReport.Storage := StorageSize[Difficulty[P]];
     519  CityReport.ProdCost := GetProjectCost(P, cix);
     520end;
     521
     522function GetCityReportNew(P, cix: Integer;
     523  var CityReportNew: TCityReportNew): Integer;
    514524var
    515525  CityReport: TCityReport;
     
    521531    CityReport.HypoTax := HypoTaxRate;
    522532    CityReport.HypoLux := HypoLuxuryRate;
    523     result := GetSmallCityReport(p, cix, CityReport, @CityReportEx);
    524     FoodSupport := CityReport.Eaten - 2 * RW[p].City[cix].Size;
     533    Result := GetSmallCityReport(P, cix, CityReport, @CityReportEx);
     534    FoodSupport := CityReport.Eaten - 2 * RW[P].City[cix].Size;
    525535    MaterialSupport := CityReport.Support;
    526     ProjectCost := GetProjectCost(p, cix);
    527     Storage := StorageSize[Difficulty[p]];
     536    ProjectCost := GetProjectCost(P, cix);
     537    Storage := StorageSize[Difficulty[P]];
    528538    Deployed := CityReport.Deployed;
    529539    Morale := CityReportEx.BaseHappiness;
    530540    CollectedControl := CityReportEx.BaseControl +
    531       (RW[p].City[cix].Size - CityReport.Working) * 2;
     541      (RW[P].City[cix].Size - CityReport.Working) * 2;
    532542    CollectedFood := CityReport.FoodRep;
    533543    CollectedMaterial := CityReportEx.Material;
     
    541551    Luxury := CityReport.Lux;
    542552    FoodSurplus := CityReport.FoodRep - CityReport.Eaten;
    543     HappinessBalance := Morale + Luxury + CollectedControl - RW[p].City[cix]
     553    HappinessBalance := Morale + Luxury + CollectedControl - RW[P].City[cix]
    544554      .Size - 2 * Deployed;
    545555  end;
     
    550560  ____________________________________________________________________
    551561}
    552 procedure NextBest(p, cix: integer; var SelectedLoc, SelectedV21: integer);
     562procedure NextBest(P, cix: Integer; var SelectedLoc, SelectedV21: Integer);
    553563{ best tile unused but available by city cix }
    554564var
    555   Resources, Most, Loc1, p1, V21: integer;
     565  Resources, Most, Loc1, p1, V21: Integer;
    556566  TileInfo: TTileInfo;
    557567  Radius: TVicinity21Loc;
    558568begin
    559 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
     569{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
    560570  Most := 0;
    561571  SelectedLoc := -1;
    562572  SelectedV21 := -1;
    563   with RW[p].City[cix] do
     573  with RW[P].City[cix] do
    564574  begin
    565575    V21_to_Loc(Loc, Radius);
     
    570580      begin
    571581        p1 := RealMap[Loc1] shr 27;
    572         if ((p1 = nPl) or (p1 = p) or (RW[p].Treaty[p1] < trPeace)) and
    573           ((ZoCMap[Loc1] = 0) or (Occupant[Loc1] = p) or
    574           (RW[p].Treaty[Occupant[Loc1]] = trAlliance)) then
     582        if ((p1 = nPl) or (p1 = P) or (RW[P].Treaty[p1] < trPeace)) and
     583          ((ZoCMap[Loc1] = 0) or (Occupant[Loc1] = P) or
     584          (RW[P].Treaty[Occupant[Loc1]] = trAlliance)) then
    575585        begin
    576           GetTileInfo(p, cix, Loc1, TileInfo);
     586          GetTileInfo(P, cix, Loc1, TileInfo);
    577587          Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 +
    578588            TileInfo.Trade;
     
    582592            SelectedLoc := Loc1;
    583593            SelectedV21 := V21;
    584             Most := Resources
    585           end
    586         end
    587       end
    588     end;
    589   end;
    590 end;
    591 
    592 procedure NextWorst(p, cix: integer; var SelectedLoc, SelectedV21: integer);
     594            Most := Resources;
     595          end;
     596        end;
     597      end;
     598    end;
     599  end;
     600end;
     601
     602procedure NextWorst(P, cix: Integer; var SelectedLoc, SelectedV21: Integer);
    593603{ worst tile used by city cix }
    594604var
    595   Resources, Least, Loc1, V21: integer;
     605  Resources, Least, Loc1, V21: Integer;
    596606  Radius: TVicinity21Loc;
    597607  TileInfo: TTileInfo;
     
    600610  SelectedLoc := -1;
    601611  SelectedV21 := -1;
    602   with RW[p].City[cix] do
     612  with RW[P].City[cix] do
    603613  begin
    604614    V21_to_Loc(Loc, Radius);
     
    609619        if (Loc1 >= 0) and (Loc1 < MapSize) and (1 shl V21 and Tiles <> 0) then
    610620        begin
    611           GetTileInfo(p, cix, Loc1, TileInfo);
     621          GetTileInfo(P, cix, Loc1, TileInfo);
    612622          Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 +
    613623            TileInfo.Trade;
     
    617627            SelectedLoc := Loc1;
    618628            SelectedV21 := V21;
    619             Least := Resources
    620           end
    621         end;
    622       end
    623   end
    624 end;
    625 
    626 function NextPoll(p, cix: integer): integer;
    627 var
    628   Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: integer;
     629            Least := Resources;
     630          end;
     631        end;
     632      end;
     633  end;
     634end;
     635
     636function NextPoll(P, cix: Integer): Integer;
     637var
     638  Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: Integer;
    629639  Radius: TVicinity21Loc;
    630640  TileInfo: TTileInfo;
    631641begin
    632642  BestDist := MaxInt;
    633 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
     643{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
    634644  Best := 0;
    635   result := -1;
    636   with RW[p].City[cix] do
     645  Result := -1;
     646  with RW[P].City[cix] do
    637647  begin
    638648    V21_to_Loc(Loc, Radius);
     
    646656        begin
    647657          pTerr := RealMap[Loc1] shr 27;
    648           if (pTerr = nPl) or (pTerr = p) or (RW[p].Treaty[pTerr] < trPeace)
     658          if (pTerr = nPl) or (pTerr = P) or (RW[P].Treaty[pTerr] < trPeace)
    649659          then
    650660          begin
    651             GetTileInfo(p, cix, Loc1, TileInfo);
     661            GetTileInfo(P, cix, Loc1, TileInfo);
    652662            Resources := TileInfo.Prod shl 16 + TileInfo.Trade shl 8 +
    653663              TileInfo.Food;
     
    659669            then
    660670            begin
    661               result := Loc1;
     671              Result := Loc1;
    662672              Best := Resources;
    663673              BestDist := Dist;
     
    669679end;
    670680
    671 function AddBestCityTile(p, cix: integer): boolean;
    672 var
    673   TileLoc, V21: integer;
    674 begin
    675   NextBest(p, cix, TileLoc, V21);
    676   result := TileLoc >= 0;
    677   if result then
    678     with RW[p].City[cix] do
    679     begin
    680       assert(1 shl V21 and Tiles = 0);
     681function AddBestCityTile(P, cix: Integer): Boolean;
     682var
     683  TileLoc, V21: Integer;
     684begin
     685  NextBest(P, cix, TileLoc, V21);
     686  Result := TileLoc >= 0;
     687  if Result then
     688    with RW[P].City[cix] do
     689    begin
     690      Assert(1 shl V21 and Tiles = 0);
    681691      Tiles := Tiles or (1 shl V21);
    682       UsedByCity[TileLoc] := Loc
    683     end
    684 end;
    685 
    686 procedure CityGrowth(p, cix: integer);
    687 var
    688   TileLoc, V21: integer;
     692      UsedByCity[TileLoc] := Loc;
     693    end;
     694end;
     695
     696procedure CityGrowth(P, cix: Integer);
     697var
     698  TileLoc, V21: Integer;
    689699  AltCityReport: TCityReport;
    690700begin
    691   with RW[p].City[cix] do
     701  with RW[P].City[cix] do
    692702  begin
    693     inc(Size);
    694     NextBest(p, cix, TileLoc, V21);
     703    Inc(Size);
     704    NextBest(P, cix, TileLoc, V21);
    695705    if TileLoc >= 0 then
    696706    begin { test whether exploitation of tile would lead to disorder }
     
    698708      AltCityReport.HypoTax := -1;
    699709      AltCityReport.HypoLux := -1;
    700       GetSmallCityReport(p, cix, AltCityReport);
     710      GetSmallCityReport(P, cix, AltCityReport);
    701711      if AltCityReport.Working - AltCityReport.Happy <= Size shr 1 then
    702712      // !!! change to new style disorder
    703713      begin { no disorder -- exploit tile }
    704         assert(1 shl V21 and Tiles = 0);
     714        Assert(1 shl V21 and Tiles = 0);
    705715        Tiles := Tiles or (1 shl V21);
    706         UsedByCity[TileLoc] := Loc
    707       end
    708     end;
    709   end
    710 end;
    711 
    712 procedure CityShrink(p, cix: integer);
    713 var
    714   TileLoc, V21, Working: integer;
     716        UsedByCity[TileLoc] := Loc;
     717      end;
     718    end;
     719  end;
     720end;
     721
     722procedure CityShrink(P, cix: Integer);
     723var
     724  TileLoc, V21, Working: Integer;
    715725  AltCityReport: TCityReport;
    716726begin
    717   with RW[p].City[cix] do
     727  with RW[P].City[cix] do
    718728  begin
    719729    Working := 0;
    720730    for V21 := 1 to 26 do
    721731      if Tiles and (1 shl V21) <> 0 then
    722         inc(Working);
    723     dec(Size);
    724     if Food > StorageSize[Difficulty[p]] then
    725       Food := StorageSize[Difficulty[p]];
    726     NextWorst(p, cix, TileLoc, V21);
     732        Inc(Working);
     733    Dec(Size);
     734    if Food > StorageSize[Difficulty[P]] then
     735      Food := StorageSize[Difficulty[P]];
     736    NextWorst(P, cix, TileLoc, V21);
    727737    if Working > Size then
    728738    begin { all citizens were working -- worst tile no longer exploited }
    729       assert(1 shl V21 and Tiles <> 0);
     739      Assert(1 shl V21 and Tiles <> 0);
    730740      Tiles := Tiles and not(1 shl V21);
    731       UsedByCity[TileLoc] := -1
     741      UsedByCity[TileLoc] := -1;
    732742    end
    733743    else { test whether exploitation of tile would lead to disorder }
     
    736746      AltCityReport.HypoTax := -1;
    737747      AltCityReport.HypoLux := -1;
    738       GetSmallCityReport(p, cix, AltCityReport);
     748      GetSmallCityReport(P, cix, AltCityReport);
    739749      if AltCityReport.Working - AltCityReport.Happy > Size shr 1 then
    740750      // !!! change to new style disorder
    741751      begin { disorder -- don't exploit tile }
    742         assert(1 shl V21 and Tiles <> 0);
     752        Assert(1 shl V21 and Tiles <> 0);
    743753        Tiles := Tiles and not(1 shl V21);
    744         UsedByCity[TileLoc] := -1
    745       end
    746     end;
    747   end
    748 end;
    749 
    750 procedure Pollute(p, cix: integer);
    751 var
    752   PollutionLoc: integer;
    753 begin
    754   with RW[p].City[cix] do
     754        UsedByCity[TileLoc] := -1;
     755      end;
     756    end;
     757  end;
     758end;
     759
     760procedure Pollute(P, cix: Integer);
     761var
     762  PollutionLoc: Integer;
     763begin
     764  with RW[P].City[cix] do
    755765  begin
    756766    Pollution := Pollution - MaxPollution;
    757     PollutionLoc := NextPoll(p, cix);
     767    PollutionLoc := NextPoll(P, cix);
    758768    if PollutionLoc >= 0 then
    759769    begin
    760       inc(Flags, chPollution);
     770      Inc(Flags, chPollution);
    761771      RealMap[PollutionLoc] := RealMap[PollutionLoc] or fPoll;
    762     end
     772    end;
    763773  end;
    764774end;
     
    768778  ____________________________________________________________________
    769779}
    770 procedure PayCityMaintenance(p, cix: integer);
    771 var
    772   i: integer;
    773 begin
    774   with RW[p], City[cix] do
    775     for i := nWonder to nImp - 1 do
    776       if (Built[i] > 0) and (Project0 and (cpImp or cpIndex) <> (cpImp or i))
     780procedure PayCityMaintenance(P, cix: Integer);
     781var
     782  I: Integer;
     783begin
     784  with RW[P], City[cix] do
     785    for I := nWonder to nImp - 1 do
     786      if (Built[I] > 0) and (Project0 and (cpImp or cpIndex) <> (cpImp or I))
    777787      then // don't pay maintenance when just completed
    778788      begin
    779         dec(Money, Imp[i].Maint);
     789        Dec(Money, Imp[I].Maint);
    780790        if Money < 0 then
    781791        begin { out of money - sell improvement }
    782           inc(Money, Imp[i].Cost * BuildCostMod[Difficulty[p]] div 12);
    783           Built[i] := 0;
    784           if Imp[i].Kind <> ikCommon then
     792          Inc(Money, Imp[I].Cost * BuildCostMod[Difficulty[P]] div 12);
     793          Built[I] := 0;
     794          if Imp[I].Kind <> ikCommon then
    785795          begin
    786             assert(i <> imSpacePort);
     796            Assert(I <> imSpacePort);
    787797            // never sell automatically! (solution: no maintenance)
    788             NatBuilt[i] := 0;
    789             if i = imGrWall then
    790               GrWallContinent[p] := -1;
     798            NatBuilt[I] := 0;
     799            if I = imGrWall then
     800              GrWallContinent[P] := -1;
    791801          end;
    792           inc(Flags, chImprovementLost)
    793         end
    794       end;
    795 end;
    796 
    797 procedure CollectCityResources(p, cix: integer);
    798 var
    799   CityStorage, CityProjectCost: integer;
     802          Inc(Flags, chImprovementLost);
     803        end;
     804      end;
     805end;
     806
     807procedure CollectCityResources(P, cix: Integer);
     808var
     809  CityStorage, CityProjectCost: Integer;
    800810  CityReport: TCityReportNew;
    801   Disorder: boolean;
    802 begin
    803   with RW[p], City[cix], CityReport do
     811  Disorder: Boolean;
     812begin
     813  with RW[P], City[cix], CityReport do
    804814    if Flags and chCaptured <> 0 then
    805815    begin
    806816      Flags := Flags and not chDisorder;
    807       dec(Flags, $10000);
     817      Dec(Flags, $10000);
    808818      if Flags and chCaptured = 0 then
    809819        Flags := Flags or chAfterCapture;
     
    816826      HypoTaxRate := -1;
    817827      HypoLuxuryRate := -1;
    818       GetCityReportNew(p, cix, CityReport);
    819       CityStorage := StorageSize[Difficulty[p]];
    820       CityProjectCost := GetProjectCost(p, cix);
     828      GetCityReportNew(P, cix, CityReport);
     829      CityStorage := StorageSize[Difficulty[P]];
     830      CityProjectCost := GetProjectCost(P, cix);
    821831
    822832      Disorder := (HappinessBalance < 0);
     
    830840      if not Disorder and ((Government = gFuture) or (Size >= NeedAqueductSize)
    831841        and (FoodSurplus < 2)) and (FoodSurplus > 0) then
    832         inc(Money, FoodSurplus)
     842        Inc(Money, FoodSurplus)
    833843      else if not(Disorder and (FoodSurplus > 0)) then
    834844      begin { calculate new food storage }
     
    839849          (Project and (cpImp + cpIndex) <> cpImp + imAqueduct) and
    840850          (Project and (cpImp + cpIndex) <> cpImp + imSewer) and
    841           not CanCityGrow(p, cix) then
    842           inc(Flags, chNoGrowthWarning);
     851          not CanCityGrow(P, cix) then
     852          Inc(Flags, chNoGrowthWarning);
    843853      end;
    844854
    845855      if Prod > CityProjectCost then
    846856      begin
    847         inc(Money, Prod - CityProjectCost);
    848         Prod := CityProjectCost
     857        Inc(Money, Prod - CityProjectCost);
     858        Prod := CityProjectCost;
    849859      end;
    850860      if Production < 0 then
     
    852862      else if not Disorder and (Flags and chProductionSabotaged = 0) then
    853863        if Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    854           inc(Money, Production)
     864          Inc(Money, Production)
    855865        else
    856           inc(Prod, Production);
     866          Inc(Prod, Production);
    857867
    858868      if not Disorder then
    859869      begin
    860870        { sum research points and taxes }
    861         inc(Research, Science);
    862         inc(Money, Tax);
     871        Inc(Research, Science);
     872        Inc(Money, Tax);
    863873        Pollution := Pollution + AddPollution;
    864874      end;
     
    866876end;
    867877
    868 function CityTurn(p, cix: integer): boolean;
     878function CityTurn(P, cix: Integer): Boolean;
    869879// return value: whether city keeps existing
    870880var
    871   i, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det,
    872     TestDet: integer;
    873   LackOfMaterial, CheckGrow, DoProd, IsActive: boolean;
    874 begin
    875   with RW[p], City[cix] do
     881  I, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det,
     882    TestDet: Integer;
     883  LackOfMaterial, CheckGrow, DoProd, IsActive: Boolean;
     884begin
     885  with RW[P], City[cix] do
    876886  begin
    877887    SizeMod := 0;
    878     CityStorage := StorageSize[Difficulty[p]];
    879     CityProjectCost := GetProjectCost(p, cix);
     888    CityStorage := StorageSize[Difficulty[P]];
     889    CityProjectCost := GetProjectCost(P, cix);
    880890
    881891    LackOfMaterial := Flags and chUnitLost <> 0;
     
    887897    if CheckGrow and (GTestFlags and tfImmGrow <> 0) then { fast growth }
    888898    begin
    889       if CanCityGrow(p, cix) then
    890         inc(SizeMod)
     899      if CanCityGrow(P, cix) then
     900        Inc(SizeMod);
    891901    end
    892902    else if CheckGrow and (Food >= CityStorage) then { normal growth }
    893903    begin
    894       if CanCityGrow(p, cix) then
     904      if CanCityGrow(P, cix) then
    895905      begin
    896906        if Built[imGranary] = 1 then
    897           dec(Food, CityStorage shr 1)
     907          Dec(Food, CityStorage shr 1)
    898908        else
    899           dec(Food, CityStorage);
    900         inc(SizeMod)
    901       end
     909          Dec(Food, CityStorage);
     910        Inc(SizeMod);
     911      end;
    902912    end
    903913    else if Food < 0 then { famine }
     
    906916      // check if settlers or conscripts there to disband
    907917      uix := -1;
    908       for i := 0 to nUn - 1 do
    909         if (Un[i].Loc >= 0) and (Un[i].Home = cix) and
    910           ((Model[Un[i].mix].Kind = mkSettler)
     918      for I := 0 to nUn - 1 do
     919        if (Un[I].Loc >= 0) and (Un[I].Home = cix) and
     920          ((Model[Un[I].mix].Kind = mkSettler)
    911921          { and (GWonder[woFreeSettlers].EffectiveOwner<>p) }
    912           or (Un[i].Flags and unConscripts <> 0)) and
    913           ((uix = -1) or (Model[Un[i].mix].Cost < Model[Un[uix].mix].Cost) or
    914           (Model[Un[i].mix].Cost = Model[Un[uix].mix].Cost) and
    915           (Un[i].Exp < Un[uix].Exp)) then
    916           uix := i;
     922          or (Un[I].Flags and unConscripts <> 0)) and
     923          ((uix = -1) or (Model[Un[I].mix].Cost < Model[Un[uix].mix].Cost) or
     924          (Model[Un[I].mix].Cost = Model[Un[uix].mix].Cost) and
     925          (Un[I].Exp < Un[uix].Exp)) then
     926          uix := I;
    917927
    918928      if uix >= 0 then
    919929      begin
    920         RemoveUnit_UpdateMap(p, uix);
    921         inc(Flags, chUnitLost);
     930        RemoveUnit_UpdateMap(P, uix);
     931        Inc(Flags, chUnitLost);
    922932      end
    923933      else
    924934      begin
    925         dec(SizeMod);
    926         inc(Flags, chPopDecrease)
     935        Dec(SizeMod);
     936        Inc(Flags, chPopDecrease);
    927937      end
    928938    end;
     
    936946        uix := -1;
    937947        Det := MaxInt;
    938         for i := 0 to nUn - 1 do
    939           if (Un[i].Loc >= 0) and (Un[i].Home = cix) then
    940             with Model[Un[i].mix] do
     948        for I := 0 to nUn - 1 do
     949          if (Un[I].Loc >= 0) and (Un[I].Home = cix) then
     950            with Model[Un[I].mix] do
    941951            begin
    942952              if Kind = mkSpecial_TownGuard then
    943                 TestDet := Un[i].Health + Un[i].Exp shl 8
     953                TestDet := Un[I].Health + Un[I].Exp shl 8
    944954                // disband townguards first
    945955              else
    946956              begin
    947                 TestDet := Un[i].Health + Un[i].Exp shl 8 + Cost shl 16;
     957                TestDet := Un[I].Health + Un[I].Exp shl 8 + Cost shl 16;
    948958                // value of unit
    949959                if Flags and mdDoubleSupport <> 0 then
     
    953963              if TestDet < Det then
    954964              begin
    955                 uix := i;
    956                 Det := TestDet
     965                uix := I;
     966                Det := TestDet;
    957967              end;
    958968            end;
    959969        if uix >= 0 then
    960970        begin
    961           RemoveUnit_UpdateMap(p, uix);
    962           inc(Flags, chUnitLost);
    963         end
    964       end
     971          RemoveUnit_UpdateMap(P, uix);
     972          Inc(Flags, chUnitLost);
     973        end;
     974      end;
    965975    end;
    966976
     
    974984      (GWonder[Project and cpIndex].CityID <> WonderNotBuiltYet) then
    975985    begin
    976       inc(Flags, chOldWonder);
    977       DoProd := false;
     986      Inc(Flags, chOldWonder);
     987      DoProd := False;
    978988    end;
    979989
     
    985995      (Project and cpConscripts <> 0))) then
    986996    begin
    987       inc(Flags, chNoSettlerProd);
    988       DoProd := false;
     997      Inc(Flags, chNoSettlerProd);
     998      DoProd := False;
    989999    end;
    9901000
    9911001    if DoProd then
    9921002    begin { project complete }
    993       dec(Prod, CityProjectCost);
     1003      Dec(Prod, CityProjectCost);
    9941004      if Project and cpImp = 0 then { produce unit }
    9951005      begin
    9961006        if nUn < numax then
    9971007        begin
    998           CreateUnit(p, Project and cpIndex);
     1008          CreateUnit(P, Project and cpIndex);
    9991009          Un[nUn - 1].Loc := Loc;
    10001010          with Un[nUn - 1] do
     
    10081018              Exp := ExpCost * 2; { vet }
    10091019            if Project and cpConscripts <> 0 then
    1010               Flags := Flags or unConscripts
     1020              Flags := Flags or unConscripts;
    10111021          end;
    1012           PlaceUnit(p, nUn - 1);
     1022          PlaceUnit(P, nUn - 1);
    10131023          UpdateUnitMap(Loc);
    10141024          if Model[Project and cpIndex].Kind = mkSettler then
    1015             dec(SizeMod, 2) { settler produced - city shrink }
     1025            Dec(SizeMod, 2) { settler produced - city shrink }
    10161026          else if (Model[Project and cpIndex].Kind = mkSlaves) or
    10171027            (Project and cpConscripts <> 0) then
    1018             dec(SizeMod); { slaves/conscripts produced - city shrink }
     1028            Dec(SizeMod); { slaves/conscripts produced - city shrink }
    10191029        end;
    10201030        Project0 := Project or cpRepeat or cpCompleted;
     
    10221032      else if Imp[Project and cpIndex].Kind = ikShipPart then
    10231033      begin { produce ship parts }
    1024         inc(GShip[p].Parts[Project and cpIndex - imShipComp]);
     1034        Inc(GShip[P].Parts[Project and cpIndex - imShipComp]);
    10251035        Project0 := Project or cpCompleted;
    10261036      end
     
    10281038      begin
    10291039        NewImp := Project and cpIndex;
    1030         inc(Money, Prod); { change rest to money }
     1040        Inc(Money, Prod); { change rest to money }
    10311041        Project0 := Project or cpCompleted;
    10321042        Project := cpImp + imTrGoods;
     
    10351045        if Imp[NewImp].Kind in [ikNatLocal, ikNatGlobal] then
    10361046        begin // nat. project
    1037           for i := 0 to nCity - 1 do
    1038             if (City[i].Loc >= 0) and (City[i].Built[NewImp] = 1) then
     1047          for I := 0 to nCity - 1 do
     1048            if (City[I].Loc >= 0) and (City[I].Built[NewImp] = 1) then
    10391049            begin { allowed only once }
    1040               inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[p]] div 12);
    1041               City[i].Built[NewImp] := 0;
     1050              Inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[P]] div 12);
     1051              City[I].Built[NewImp] := 0;
    10421052            end;
    10431053          NatBuilt[NewImp] := 1;
     
    10461056          case NewImp of
    10471057            imGrWall:
    1048               GrWallContinent[p] := Continent[Loc];
     1058              GrWallContinent[P] := Continent[Loc];
    10491059          end;
    10501060        end;
     
    10531063        begin // wonder
    10541064          GWonder[NewImp].CityID := ID;
    1055           GWonder[NewImp].EffectiveOwner := p;
     1065          GWonder[NewImp].EffectiveOwner := P;
    10561066          CheckExpiration(NewImp);
    10571067
     
    10601070            woEiffel:
    10611071              begin // reactivate wonders
    1062                 for i := 0 to nWonder - 1 do
    1063                   if Imp[i].Expiration >= 0 then
     1072                for I := 0 to nWonder - 1 do
     1073                  if Imp[I].Expiration >= 0 then
    10641074                    for cix2 := 0 to nCity - 1 do
    1065                       if (City[cix2].Loc >= 0) and (City[cix2].Built[i] = 1)
     1075                      if (City[cix2].Loc >= 0) and (City[cix2].Built[I] = 1)
    10661076                      then
    1067                         GWonder[i].EffectiveOwner := p
     1077                        GWonder[I].EffectiveOwner := P;
    10681078              end;
    10691079            woLighthouse:
    1070               CheckSpecialModels(p, preLighthouse);
     1080              CheckSpecialModels(P, preLighthouse);
    10711081            woLeo:
    10721082              begin
    1073                 inc(Research, TechBaseCost(nTech[p], Difficulty[p]) +
    1074                   TechBaseCost(nTech[p] + 2, Difficulty[p]));
    1075                 CheckSpecialModels(p, preLeo);
     1083                Inc(Research, TechBaseCost(nTech[P], Difficulty[P]) +
     1084                  TechBaseCost(nTech[P] + 2, Difficulty[P]));
     1085                CheckSpecialModels(P, preLeo);
    10761086              end;
    10771087            woPyramids:
    1078               CheckSpecialModels(p, preBuilder);
     1088              CheckSpecialModels(P, preBuilder);
    10791089            woMir:
    10801090              begin
    10811091                for p1 := 0 to nPl - 1 do
    1082                   if (p1 <> p) and (1 shl p1 and GAlive <> 0) then
     1092                  if (p1 <> P) and (1 shl p1 and GAlive <> 0) then
    10831093                  begin
    1084                     if RW[p].Treaty[p1] = trNoContact then
    1085                       IntroduceEnemy(p, p1);
    1086                     GiveCivilReport(p, p1);
    1087                     GiveMilReport(p, p1)
     1094                    if RW[P].Treaty[p1] = trNoContact then
     1095                      IntroduceEnemy(P, p1);
     1096                    GiveCivilReport(P, p1);
     1097                    GiveMilReport(P, p1);
    10881098                  end;
    1089               end
     1099              end;
    10901100          end;
    10911101        end;
    10921102
    1093         for i := 0 to nImpReplacement - 1 do // sell obsolete buildings
    1094           if (ImpReplacement[i].NewImp = NewImp) and
    1095             (Built[ImpReplacement[i].OldImp] > 0) then
     1103        for I := 0 to nImpReplacement - 1 do // sell obsolete buildings
     1104          if (ImpReplacement[I].NewImp = NewImp) and
     1105            (Built[ImpReplacement[I].OldImp] > 0) then
    10961106          begin
    1097             inc(RW[p].Money, Imp[ImpReplacement[i].OldImp].Cost * BuildCostMod
    1098               [Difficulty[p]] div 12);
    1099             Built[ImpReplacement[i].OldImp] := 0;
     1107            Inc(RW[P].Money, Imp[ImpReplacement[I].OldImp].Cost * BuildCostMod
     1108              [Difficulty[P]] div 12);
     1109            Built[ImpReplacement[I].OldImp] := 0;
    11001110          end;
    11011111
    11021112        if NewImp in [imPower, imHydro, imNuclear] then
    1103           for i := 0 to nImp - 1 do
    1104             if (i <> NewImp) and (i in [imPower, imHydro, imNuclear]) and
    1105               (Built[i] > 0) then
     1113          for I := 0 to nImp - 1 do
     1114            if (I <> NewImp) and (I in [imPower, imHydro, imNuclear]) and
     1115              (Built[I] > 0) then
    11061116            begin // sell obsolete power plant
    1107               inc(RW[p].Money, Imp[i].Cost * BuildCostMod[Difficulty[p]
     1117              Inc(RW[P].Money, Imp[I].Cost * BuildCostMod[Difficulty[P]
    11081118                ] div 12);
    1109               Built[i] := 0;
     1119              Built[I] := 0;
    11101120            end;
    11111121
     
    11131123      end;
    11141124      Prod0 := Prod;
    1115       inc(Flags, chProduction)
     1125      Inc(Flags, chProduction);
    11161126    end
    11171127    else
     
    11251135    if SizeMod > 0 then
    11261136    begin
    1127       CityGrowth(p, cix);
    1128       inc(Flags, chPopIncrease);
    1129     end;
    1130     result := Size + SizeMod >= 2;
    1131     if result then
     1137      CityGrowth(P, cix);
     1138      Inc(Flags, chPopIncrease);
     1139    end;
     1140    Result := Size + SizeMod >= 2;
     1141    if Result then
    11321142      while SizeMod < 0 do
    11331143      begin
    1134         CityShrink(p, cix);
    1135         inc(SizeMod)
    1136       end;
    1137   end
    1138 end; // CityTurn
     1144        CityShrink(P, cix);
     1145        Inc(SizeMod);
     1146      end;
     1147  end;
     1148end;
    11391149
    11401150{
     
    11421152  ____________________________________________________________________
    11431153}
    1144 function SetCityTiles(p, cix, NewTiles: integer;
    1145   TestOnly: boolean = false): integer;
    1146 var
    1147   V21, Working, ChangeTiles, AddTiles, Loc1: integer;
     1154function SetCityTiles(P, cix, NewTiles: Integer;
     1155  TestOnly: Boolean = False): Integer;
     1156var
     1157  V21, Working, ChangeTiles, AddTiles, Loc1: Integer;
    11481158  CityAreaInfo: TCityAreaInfo;
    11491159  Radius: TVicinity21Loc;
    11501160begin
    1151   with RW[p].City[cix] do
     1161  with RW[P].City[cix] do
    11521162  begin
    1153     ChangeTiles := NewTiles xor integer(Tiles);
     1163    ChangeTiles := NewTiles xor Integer(Tiles);
    11541164    AddTiles := NewTiles and not Tiles;
    11551165    if Mode = moPlaying then
     
    11571167      if NewTiles and not $67F7F76 <> 0 then
    11581168      begin
    1159         result := eInvalid;
    1160         exit
     1169        Result := eInvalid;
     1170        Exit
    11611171      end; // invalid tile index included
    11621172      if NewTiles and (1 shl 13) = 0 then
    11631173      begin
    1164         result := eViolation;
    1165         exit
     1174        Result := eViolation;
     1175        Exit
    11661176      end; // city tile must be exploited
    11671177      if ChangeTiles = 0 then
    11681178      begin
    1169         result := eNotChanged;
    1170         exit
     1179        Result := eNotChanged;
     1180        Exit
    11711181      end;
    11721182      if AddTiles <> 0 then
    11731183      begin
    11741184        // check if new tiles possible
    1175         GetCityAreaInfo(p, Loc, CityAreaInfo);
     1185        GetCityAreaInfo(P, Loc, CityAreaInfo);
    11761186        for V21 := 1 to 26 do
    11771187          if AddTiles and (1 shl V21) <> 0 then
    11781188            if CityAreaInfo.Available[V21] <> faAvailable then
    11791189            begin
    1180               result := eTileNotAvailable;
    1181               exit
     1190              Result := eTileNotAvailable;
     1191              Exit;
    11821192            end;
    11831193        // not more tiles than inhabitants
     
    11851195        for V21 := 1 to 26 do
    11861196          if NewTiles and (1 shl V21) <> 0 then
    1187             inc(Working);
     1197            Inc(Working);
    11881198        if Working > Size then
    11891199        begin
    1190           result := eNoWorkerAvailable;
    1191           exit
    1192         end;
    1193       end;
    1194     end;
    1195     result := eOk;
     1200          Result := eNoWorkerAvailable;
     1201          Exit;
     1202        end;
     1203      end;
     1204    end;
     1205    Result := eOk;
    11961206    if not TestOnly then
    11971207    begin
     
    12011211        begin
    12021212          Loc1 := Radius[V21];
    1203           assert((Loc1 >= 0) and (Loc1 < MapSize));
     1213          Assert((Loc1 >= 0) and (Loc1 < MapSize));
    12041214          if NewTiles and (1 shl V21) <> 0 then
    12051215            UsedByCity[Loc1] := Loc // employ tile
    12061216          else if UsedByCity[Loc1] <> Loc then
    1207             assert(Mode < moPlaying)
     1217            Assert(Mode < moPlaying)
    12081218            // should only happen during loading, because of wrong sSetCityTiles command order
    12091219          else
    1210             UsedByCity[Loc1] := -1 // unemploy tile
    1211         end;
    1212       Tiles := NewTiles
    1213     end
    1214   end;
    1215 end;
    1216 
    1217 procedure GetCityTileAdvice(p, cix: integer; var Advice: TCityTileAdviceData);
     1220            UsedByCity[Loc1] := -1; // unemploy tile
     1221        end;
     1222      Tiles := NewTiles;
     1223    end;
     1224  end;
     1225end;
     1226
     1227procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData);
    12181228const
    12191229  oFood = 0;
     
    12231233type
    12241234  TTileData = record
    1225     Food, Prod, Trade, SubValue, V21: integer;
    1226   end;
    1227 var
    1228   i, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking,
     1235    Food: Integer;
     1236    Prod: Integer;
     1237    Trade: Integer;
     1238    SubValue: Integer;
     1239    V21: Integer;
     1240  end;
     1241var
     1242  I, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking,
    12291243    WantedProd, MinFood, MinProd, count, Take, MaxTake, AreaSize, FormulaCode,
    12301244    NeedRare, RareTiles, cix1, dx, dy, BestTiles, ProdBeforeBoost, TestTiles,
    1231     SubPlus, SuperPlus: integer;
    1232   SuperValue, BestSuperValue, SubValue, BestSubValue: integer;
    1233   Value, BestValue, ValuePlus: extended;
    1234   ValueFormula_Weight: array [oFood .. oScience] of extended;
    1235   ValueFormula_Multiply: array [oFood .. oScience] of boolean;
    1236   Output: array [oFood .. oScience] of integer;
     1245    SubPlus, SuperPlus: Integer;
     1246  SuperValue, BestSuperValue, SubValue, BestSubValue: Integer;
     1247  Value, BestValue, ValuePlus: Extended;
     1248  ValueFormula_Weight: array [oFood .. oScience] of Extended;
     1249  ValueFormula_Multiply: array [oFood .. oScience] of Boolean;
     1250  Output: array [oFood .. oScience] of Integer;
    12371251  TileInfo, BaseTileInfo: TTileInfo;
    12381252  Radius, Radius1: TVicinity21Loc;
     
    12411255  CityAreaInfo: TCityAreaInfo;
    12421256  Hierarchy: array [0 .. 20, 0 .. 31] of TTileData;
    1243   nTile, nSelection: array [0 .. 20] of integer;
    1244   SubCriterion: array [0 .. 27] of integer;
    1245   FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: boolean;
    1246 begin
    1247   if (RW[p].Government = gAnarchy) or (RW[p].City[cix].Flags and chCaptured <> 0)
     1257  nTile, nSelection: array [0 .. 20] of Integer;
     1258  SubCriterion: array [0 .. 27] of Integer;
     1259  FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: Boolean;
     1260begin
     1261  if (RW[P].Government = gAnarchy) or (RW[P].City[cix].Flags and chCaptured <> 0)
    12481262  then
    12491263  begin
     
    12511265    Advice.Tiles := 1 shl CityOwnTile;
    12521266    Advice.CityReport.HypoTiles := 1 shl CityOwnTile;
    1253     exit;
    1254   end;
    1255 
    1256   for i := oFood to oScience do
     1267    Exit;
     1268  end;
     1269
     1270  for I := oFood to oScience do
    12571271  begin // decode evaluation formula from weights parameter
    1258     FormulaCode := Advice.ResourceWeights shr (24 - 8 * i) and $FF;
    1259     ValueFormula_Multiply[i] := FormulaCode and $80 <> 0;
     1272    FormulaCode := Advice.ResourceWeights shr (24 - 8 * I) and $FF;
     1273    ValueFormula_Multiply[I] := FormulaCode and $80 <> 0;
    12601274    if FormulaCode and $40 <> 0 then
    1261       ValueFormula_Weight[i] := (FormulaCode and $0F) *
     1275      ValueFormula_Weight[I] := (FormulaCode and $0F) *
    12621276        (1 shl (FormulaCode and $30 shr 4)) / 16
    12631277    else
    1264       ValueFormula_Weight[i] := (FormulaCode and $0F) *
     1278      ValueFormula_Weight[I] := (FormulaCode and $0F) *
    12651279        (1 shl (FormulaCode and $30 shr 4));
    12661280  end;
     
    12691283  TestReport.HypoTax := -1;
    12701284  TestReport.HypoLux := -1;
    1271   GetSmallCityReport(p, cix, TestReport, @CityReportEx);
    1272   with RW[p].City[cix] do
     1285  GetSmallCityReport(P, cix, TestReport, @CityReportEx);
     1286  with RW[P].City[cix] do
    12731287  begin
    12741288    V21_to_Loc(Loc, Radius);
    1275     FoodToTax := RW[p].Government = gFuture;
     1289    FoodToTax := RW[P].Government = gFuture;
    12761290    ProdToTax := Project and (cpImp + cpIndex) = cpImp + imTrGoods;
    1277     FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[p]]) and
    1278       not CanCityGrow(p, cix);
     1291    FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[P]]) and
     1292      not CanCityGrow(P, cix);
    12791293
    12801294    // sub criteria
     
    12861300          V21 xor $15;
    12871301    end;
    1288     for cix1 := 0 to RW[p].nCity - 1 do
     1302    for cix1 := 0 to RW[P].nCity - 1 do
    12891303      if cix1 <> cix then
    12901304      begin
    1291         Loc1 := RW[p].City[cix1].Loc;
     1305        Loc1 := RW[P].City[cix1].Loc;
    12921306        if Loc1 >= 0 then
    12931307        begin
     
    13021316              begin
    13031317                dxdy(Loc, Loc1, dx, dy);
    1304                 dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160);
     1318                Dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160);
    13051319              end;
    13061320            end;
     
    13091323      end;
    13101324
    1311     GetCityAreaInfo(p, Loc, CityAreaInfo);
     1325    GetCityAreaInfo(P, Loc, CityAreaInfo);
    13121326    AreaSize := 0;
    13131327    for V21 := 1 to 26 do
    13141328      if CityAreaInfo.Available[V21] = faAvailable then
    1315         inc(AreaSize);
    1316 
    1317     if RW[p].Government = gFundamentalism then
     1329        Inc(AreaSize);
     1330
     1331    if RW[P].Government = gFundamentalism then
    13181332    begin
    13191333      MinWorking := Size;
     
    13251339      if MinWorking > Size then
    13261340        MinWorking := Size;
    1327       if (RW[p].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury
     1341      if (RW[P].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury
    13281342      then
    13291343        MaxWorking := MinWorking
     
    13621376        Loc1 := Radius[V21];
    13631377        if (Loc1 >= 0) and (Loc1 < MapSize) and
    1364           (RealMap[Loc1] and fModern = cardinal(NeedRare)) then
     1378          (RealMap[Loc1] and fModern = Cardinal(NeedRare)) then
    13651379          RareTiles := RareTiles or (1 shl V21);
    1366       end
     1380      end;
    13671381    end;
    13681382
     
    13741388      begin
    13751389        Loc1 := Radius[V21];
    1376         assert((Loc1 >= 0) and (Loc1 < MapSize));
    1377         GetTileInfo(p, cix, Loc1, TileInfo);
     1390        Assert((Loc1 >= 0) and (Loc1 < MapSize));
     1391        GetTileInfo(P, cix, Loc1, TileInfo);
    13781392        if V21 = CityOwnTile then
    13791393          BaseTileInfo := TileInfo
     
    13911405              (TileInfo.Trade = Hierarchy[iH, iT].Trade) and
    13921406              (SubCriterion[V21] >= SubCriterion[Hierarchy[iH, iT].V21])) do
    1393               inc(iT);
     1407              Inc(iT);
    13941408            if (iT = nTile[iH]) // new worst tile in this hierarchy
    13951409              or ((TileInfo.Food >= Hierarchy[iH, iT].Food)
     
    13971411              and (TileInfo.Prod >= Hierarchy[iH, iT].Prod) and
    13981412              (TileInfo.Trade >= Hierarchy[iH, iT].Trade)) then
    1399               break; // insert position found!
    1400             inc(iH);
     1413              Break; // insert position found!
     1414            Inc(iH);
    14011415          end;
    14021416          if iH = nHierarchy then
    14031417          begin // need to start new hierarchy
    14041418            nTile[iH] := 0;
    1405             inc(nHierarchy);
     1419            Inc(nHierarchy);
    14061420            iT := 0;
    14071421          end;
    1408           move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1],
     1422          Move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1],
    14091423            (nTile[iH] - iT) * SizeOf(TTileData));
    1410           inc(nTile[iH]);
     1424          Inc(nTile[iH]);
    14111425          Hierarchy[iH, iT].V21 := V21;
    14121426          Hierarchy[iH, iT].Food := TileInfo.Food;
     
    14241438        begin
    14251439          Loc1 := Radius[V21];
    1426           assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize));
    1427           GetTileInfo(p, cix, Loc1, TileInfo);
     1440          Assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize));
     1441          GetTileInfo(P, cix, Loc1, TileInfo);
    14281442          if iH = nHierarchy then
    14291443          begin // need to start new hierarchy
    14301444            nTile[iH] := 0;
    1431             inc(nHierarchy);
     1445            Inc(nHierarchy);
    14321446            iT := 0;
    14331447          end
    14341448          else
    14351449            iT := nTile[iH];
    1436           inc(nTile[iH]);
     1450          Inc(nTile[iH]);
    14371451          Hierarchy[iH, iT].V21 := V21;
    14381452          Hierarchy[iH, iT].Food := TileInfo.Food; // = 0
     
    14431457    end;
    14441458    if Built[imAlgae] > 0 then
    1445       inc(BaseTileInfo.Food, 12);
     1459      Inc(BaseTileInfo.Food, 12);
    14461460
    14471461    // step 2: summarize resources
    14481462    for iH := 0 to nHierarchy - 1 do
    14491463    begin
    1450       move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData));
     1464      Move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData));
    14511465      Hierarchy[iH, 0].Food := 0;
    14521466      Hierarchy[iH, 0].Prod := 0;
     
    14561470      for iT := 1 to nTile[iH] do
    14571471      begin
    1458         inc(Hierarchy[iH, iT].Food, Hierarchy[iH, iT - 1].Food);
    1459         inc(Hierarchy[iH, iT].Prod, Hierarchy[iH, iT - 1].Prod);
    1460         inc(Hierarchy[iH, iT].Trade, Hierarchy[iH, iT - 1].Trade);
    1461         inc(Hierarchy[iH, iT].SubValue, Hierarchy[iH, iT - 1].SubValue);
     1472        Inc(Hierarchy[iH, iT].Food, Hierarchy[iH, iT - 1].Food);
     1473        Inc(Hierarchy[iH, iT].Prod, Hierarchy[iH, iT - 1].Prod);
     1474        Inc(Hierarchy[iH, iT].Trade, Hierarchy[iH, iT - 1].Trade);
     1475        Inc(Hierarchy[iH, iT].SubValue, Hierarchy[iH, iT - 1].SubValue);
    14621476        Hierarchy[iH, iT].V21 := 1 shl Hierarchy[iH, iT].V21 +
    14631477          Hierarchy[iH, iT - 1].V21;
     
    14871501        (ProdBeforeBoost < WantedProd)) do
    14881502      begin
    1489         assert(nSelection[iH] = 0);
     1503        Assert(nSelection[iH] = 0);
    14901504        Take := MinWorking - TestReport.Working;
    14911505        if Take > nTile[iH] then
     
    15001514          while (Take < MaxTake) and
    15011515            (TestReport.FoodRep + Hierarchy[iH, Take].Food < MinFood) do
    1502             inc(Take);
     1516            Inc(Take);
    15031517          while (Take < MaxTake) and
    15041518            (ProdBeforeBoost + Hierarchy[iH, Take].Prod < MinProd) do
    1505             inc(Take);
     1519            Inc(Take);
    15061520        end;
    15071521        nSelection[iH] := Take;
    1508         inc(TestReport.Working, Take);
     1522        Inc(TestReport.Working, Take);
    15091523        with Hierarchy[iH, Take] do
    15101524        begin
    1511           inc(TestReport.FoodRep, Food);
    1512           inc(ProdBeforeBoost, Prod);
    1513           inc(TestReport.Trade, Trade);
    1514         end;
    1515         inc(iH);
    1516       end;
    1517 
    1518       assert((TestReport.Working >= MinWorking) and
     1525          Inc(TestReport.FoodRep, Food);
     1526          Inc(ProdBeforeBoost, Prod);
     1527          Inc(TestReport.Trade, Trade);
     1528        end;
     1529        Inc(iH);
     1530      end;
     1531
     1532      Assert((TestReport.Working >= MinWorking) and
    15191533        (TestReport.Working <= MaxWorking));
    15201534      if (TestReport.FoodRep >= MinFood) and (ProdBeforeBoost >= MinProd) then
    15211535      begin
    1522         SplitTrade(TestReport.Trade, RW[p].TaxRate, RW[p].LuxRate,
     1536        SplitTrade(TestReport.Trade, RW[P].TaxRate, RW[P].LuxRate,
    15231537          TestReport.Working, CityReportEx.TradeProcessing,
    15241538          TestReport.Corruption, TestReport.Tax, TestReport.Lux,
     
    15291543          TestReport.Deployed >= Size then
    15301544        begin // city is not in disorder -- evaluate combination
    1531           inc(count);
     1545          Inc(count);
    15321546          if (MinProd < WantedProd) and (ProdBeforeBoost > MinProd) then
    15331547          begin // no combination reached wanted prod yet
     
    15771591              then
    15781592              begin
    1579                 inc(Output[oTax], Output[oFood]);
     1593                Inc(Output[oTax], Output[oFood]);
    15801594                Output[oFood] := 0;
    15811595              end;
     
    15891603              if NeedRare > 0 then
    15901604              begin
    1591                 RareOK := false;
     1605                RareOK := False;
    15921606                for iH := 0 to nHierarchy - 1 do
    15931607                  if Hierarchy[iH, nSelection[iH]].V21 and RareTiles <> 0 then
    1594                     RareOK := true;
     1608                    RareOK := True;
    15951609                if not RareOK then
    15961610                  TestReport.ProdRep := TestReport.Support;
     
    15991613              if ProdToTax then
    16001614              begin
    1601                 inc(Output[oTax], Output[oProd]);
     1615                Inc(Output[oTax], Output[oProd]);
    16021616                Output[oProd] := 0;
    16031617              end;
    16041618            end;
    16051619
    1606             NeedStep2 := false;
     1620            NeedStep2 := False;
    16071621            Value := 0;
    1608             for i := oFood to oScience do
    1609               if ValueFormula_Multiply[i] then
    1610                 NeedStep2 := true
     1622            for I := oFood to oScience do
     1623              if ValueFormula_Multiply[I] then
     1624                NeedStep2 := True
    16111625              else
    1612                 Value := Value + ValueFormula_Weight[i] * Output[i];
     1626                Value := Value + ValueFormula_Weight[I] * Output[I];
    16131627            if NeedStep2 then
    16141628            begin
    16151629              if Value > 0 then
    16161630                Value := ln(Value) + 123;
    1617               for i := oFood to oScience do
    1618                 if ValueFormula_Multiply[i] and (Output[i] > 0) then
    1619                   Value := Value + ValueFormula_Weight[i] *
    1620                     (ln(Output[i]) + 123);
     1631              for I := oFood to oScience do
     1632                if ValueFormula_Multiply[I] and (Output[I] > 0) then
     1633                  Value := Value + ValueFormula_Weight[I] *
     1634                    (ln(Output[I]) + 123);
    16211635            end;
    16221636
     
    16291643              for iH := 0 to nHierarchy - 1 do
    16301644              begin
    1631                 inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21);
    1632                 inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue);
     1645                Inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21);
     1646                Inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue);
    16331647              end;
    1634               IsBest := true;
     1648              IsBest := True;
    16351649              if (SuperPlus = 0) and (ValuePlus = 0.0) then
    16361650              begin
    16371651                SubPlus := SubValue - BestSubValue;
    16381652                if SubPlus < 0 then
    1639                   IsBest := false
     1653                  IsBest := False
    16401654                else if SubPlus = 0 then
    16411655                begin
    1642                   assert(TestTiles <> BestTiles);
     1656                  Assert(TestTiles <> BestTiles);
    16431657                  IsBest := TestTiles > BestTiles
    16441658                end
     
    16541668                  TestReport.Lux shr 1;
    16551669                Advice.CityReport := TestReport;
    1656               end
    1657             end // if (SuperPlus>0) or (ValuePlus>=0.0)
    1658           end // if SuperPlus>=0
    1659         end
     1670              end;
     1671            end; // if (SuperPlus>0) or (ValuePlus>=0.0)
     1672          end; // if SuperPlus>=0
     1673        end;
    16601674      end;
    16611675
     
    16651679        with Hierarchy[iH_Switch, nSelection[iH_Switch]] do
    16661680        begin
    1667           dec(TestReport.FoodRep, Food);
    1668           dec(ProdBeforeBoost, Prod);
    1669           dec(TestReport.Trade, Trade);
    1670         end;
    1671         inc(nSelection[iH_Switch]);
    1672         inc(TestReport.Working);
     1681          Dec(TestReport.FoodRep, Food);
     1682          Dec(ProdBeforeBoost, Prod);
     1683          Dec(TestReport.Trade, Trade);
     1684        end;
     1685        Inc(nSelection[iH_Switch]);
     1686        Inc(TestReport.Working);
    16731687        if (nSelection[iH_Switch] <= nTile[iH_Switch]) and
    16741688          (TestReport.Working <= MaxWorking) then
     
    16761690          with Hierarchy[iH_Switch, nSelection[iH_Switch]] do
    16771691          begin
    1678             inc(TestReport.FoodRep, Food);
    1679             inc(ProdBeforeBoost, Prod);
    1680             inc(TestReport.Trade, Trade);
     1692            Inc(TestReport.FoodRep, Food);
     1693            Inc(ProdBeforeBoost, Prod);
     1694            Inc(TestReport.Trade, Trade);
    16811695          end;
    1682           break;
    1683         end;
    1684         dec(TestReport.Working, nSelection[iH_Switch]);
     1696          Break;
     1697        end;
     1698        Dec(TestReport.Working, nSelection[iH_Switch]);
    16851699        nSelection[iH_Switch] := 0;
    1686         inc(iH_Switch);
     1700        Inc(iH_Switch);
    16871701      until iH_Switch = nHierarchy;
    16881702    until iH_Switch = nHierarchy; // everything tested -- done
    16891703  end;
    1690   assert(BestSuperValue > 0); // advice should always be possible
     1704  Assert(BestSuperValue > 0); // advice should always be possible
    16911705  Advice.Tiles := BestTiles;
    16921706  Advice.CityReport.HypoTiles := BestTiles;
    1693 end; // GetCityTileAdvice
     1707end;
    16941708
    16951709{
     
    16991713procedure InitGame;
    17001714var
    1701   p, i, mixTownGuard: integer;
     1715  P, I, mixTownGuard: Integer;
    17021716begin
    17031717  MaxDist := Distance(0, MapSize - lx shr 1);
    1704   for p := 0 to nPl - 1 do
    1705     if (1 shl p and GAlive <> 0) then
    1706       with RW[p] do
     1718  for P := 0 to nPl - 1 do
     1719    if (1 shl P and GAlive <> 0) then
     1720      with RW[P] do
    17071721      begin // initialize capital
    17081722        mixTownGuard := 0;
    17091723        while Model[mixTownGuard].Kind <> mkSpecial_TownGuard do
    1710           inc(mixTownGuard);
     1724          Inc(mixTownGuard);
    17111725        with City[0] do
    17121726        begin
    17131727          Built[imPalace] := 1;
    17141728          Size := 4;
    1715           for i := 2 to Size do
    1716             AddBestCityTile(p, 0);
     1729          for I := 2 to Size do
     1730            AddBestCityTile(P, 0);
    17171731          Project := mixTownGuard;
    17181732        end;
  • branches/highdpi/CmdList.pas

    r361 r465  
    55
    66uses
    7   Classes;
     7  Classes, SysUtils, Math;
    88
    99const
    1010  MaxDataSize = 1024;
     11  CommandDataElementSize = 4;
     12  CommandDataElementCountMask = $F;
     13  CommandDataMaxSize = CommandDataElementSize * CommandDataElementCountMask;
    1114
    1215type
     
    2427    constructor Create;
    2528    destructor Destroy; override;
    26     procedure Get(var Command, Player, Subject: integer; var Data: pointer);
    27     procedure GetDataChanges(Data: pointer; DataSize: integer);
    28     procedure Put(Command, Player, Subject: integer; Data: pointer);
    29     procedure PutDataChanges(Command, Player: integer;
    30       OldData, NewData: pointer; DataSize: integer);
    31     procedure LoadFromFile(const f: TFileStream);
    32     procedure SaveToFile(const f: TFileStream);
    33     procedure AppendToFile(const f: TFileStream; const OldState: TCmdListState);
     29    procedure Get(var Command, Player, Subject: Integer; var Data: Pointer);
     30    procedure GetDataChanges(Data: Pointer; DataSize: Integer);
     31    procedure Put(Command, Player, Subject: Integer; Data: Pointer);
     32    procedure PutDataChanges(Command, Player: Integer;
     33      OldData, NewData: Pointer; DataSize: Integer);
     34    procedure LoadFromFile(const F: TFileStream);
     35    procedure SaveToFile(const F: TFileStream);
     36    procedure AppendToFile(const F: TFileStream; const OldState: TCmdListState);
    3437    procedure Cut;
    35     function Progress: integer;
     38    function Progress: Integer;
    3639  private
    37     LogAlloc: integer; { allocated size of LogData in bytes }
     40    LogAlloc: Integer; { allocated size of LogData in bytes }
    3841    LogData: ^TLogData;
    3942    FState: TCmdListState;
    40     procedure PutData(Data: pointer; Length: integer);
     43    procedure PutData(Data: Pointer; Length: Integer);
    4144    procedure CompleteMoveCode;
    4245  public
     
    4447  end;
    4548
     49  function CommandWithData(Command: Integer; DataSize: Byte): Integer;
     50
     51resourcestring
     52  SCommandDataSizeError = 'Command data size %d out of range (0-%d).';
     53
     54
    4655implementation
    4756
     
    5362
    5463type
    55   TData = array [0 .. MaxDataSize - 1] of Cardinal;
     64  TData = array [0..MaxDataSize - 1] of Cardinal;
    5665  PData = ^TData;
     66
     67function CommandWithData(Command: Integer; DataSize: Byte): Integer;
     68var
     69  DataElementCount: Byte;
     70begin
     71  if DataSize > CommandDataMaxSize then
     72    raise Exception.Create(Format(SCommandDataSizeError, [DataSize, CommandDataMaxSize]));
     73  DataElementCount := Ceil(DataSize / CommandDataElementSize);
     74  Result := Command or (DataElementCount and CommandDataElementCountMask);
     75end;
    5776
    5877constructor TCmdList.Create;
     
    7392end;
    7493
    75 procedure TCmdList.Get(var Command, Player, Subject: integer; var Data: pointer);
     94procedure TCmdList.Get(var Command, Player, Subject: Integer; var Data: Pointer);
    7695var
    7796  DirCode: Cardinal;
     
    108127  else
    109128  begin
    110     code := Cardinal((@LogData[FState.LoadPos])^);
    111     if code and 3 = 0 then
     129    Code := Cardinal((@LogData[FState.LoadPos])^);
     130    if Code and 3 = 0 then
    112131    begin // non-clientex command
    113       Command := code shr 2 and $3FFF + sExecute;
    114       Player := code shr 16 and $F;
    115       Subject := code shr 20 and $FFF;
    116       inc(FState.LoadPos, 4);
    117     end
    118     else if code and 7 = 2 then
     132      Command := Code shr 2 and $3FFF + sExecute;
     133      Player := Code shr 16 and $F;
     134      Subject := Code shr 20 and $FFF;
     135      Inc(FState.LoadPos, 4);
     136    end
     137    else if Code and 7 = 2 then
    119138    begin // clientex command
    120       Command := code shr 3 and $FFFF;
    121       Player := code shr 19 and $F;
     139      Command := Code shr 3 and $FFFF;
     140      Player := Code shr 19 and $F;
    122141      Subject := 0;
    123       inc(FState.LoadPos, 3);
     142      Inc(FState.LoadPos, 3);
    124143    end
    125144    else
    126145    begin // move command shortcut
    127       if (code and 1 = 1) and (code and (7 shl 4) <> 6 shl 4) then
     146      if (Code and 1 = 1) and (Code and (7 shl 4) <> 6 shl 4) then
    128147      begin
    129         FState.LoadMoveCode := code and $FF;
    130         inc(FState.LoadPos);
     148        FState.LoadMoveCode := Code and $FF;
     149        Inc(FState.LoadPos);
    131150      end
    132151      else
    133152      begin
    134         FState.LoadMoveCode := code and $FFFFFF;
    135         inc(FState.LoadPos, 3);
     153        FState.LoadMoveCode := Code and $FFFFFF;
     154        Inc(FState.LoadPos, 3);
    136155      end;
    137156      Get(Command, Player, Subject, Data);
     
    139158    end;
    140159
    141     if Command and $F = 0 then
     160    if Command and CommandDataElementCountMask = 0 then
    142161      Data := nil
    143162    else
    144163    begin
    145164      Data := @LogData[FState.LoadPos];
    146       inc(FState.LoadPos, Command and $F * 4);
    147     end;
    148   end;
    149 end;
    150 
    151 procedure TCmdList.GetDataChanges(Data: pointer; DataSize: integer);
     165      Inc(FState.LoadPos, Command and CommandDataElementCountMask * CommandDataElementSize);
     166    end;
     167  end;
     168end;
     169
     170procedure TCmdList.GetDataChanges(Data: Pointer; DataSize: Integer);
    152171var
    153   b0, b1: integer;
     172  b0, b1: Integer;
    154173  Map0, Map1: Cardinal;
    155174begin
    156175  Map0 := Cardinal((@LogData[FState.LoadPos])^);
    157   inc(FState.LoadPos, 4);
     176  Inc(FState.LoadPos, 4);
    158177  b0 := 0;
    159178  while Map0 > 0 do begin
    160179    if Map0 and 1 <> 0 then begin
    161180      Map1 := Cardinal((@LogData[FState.LoadPos])^);
    162       inc(FState.LoadPos, 4);
     181      Inc(FState.LoadPos, 4);
    163182      for b1 := 0 to 31 do
    164183        if 1 shl b1 and Map1 <> 0 then begin
    165184          if b0 * 32 + b1 < DataSize then
    166185            PData(Data)[b0 * 32 + b1] := Cardinal((@LogData[FState.LoadPos])^);
    167           inc(FState.LoadPos, 4);
     186          Inc(FState.LoadPos, 4);
    168187        end;
    169188    end;
    170     inc(b0);
     189    Inc(b0);
    171190    Map0 := Map0 shr 1;
    172191  end;
    173192end;
    174193
    175 procedure TCmdList.Put(Command, Player, Subject: integer; Data: pointer);
     194procedure TCmdList.Put(Command, Player, Subject: Integer; Data: Pointer);
    176195var
    177   DirCode, code: Cardinal;
     196  DirCode, Code: Cardinal;
    178197begin
    179198  if Command and $FC00 = sMoveUnit then
     
    190209    end;
    191210    if Subject = FState.LastMovingUnit then
    192       code := 1 + DirCode shl 1
    193     else
    194       code := 6 + DirCode shl 3 + Cardinal(Subject) shl 6;
     211      Code := 1 + DirCode shl 1
     212    else
     213      Code := 6 + DirCode shl 3 + Cardinal(Subject) shl 6;
    195214    if FState.MoveCode = 0 then
    196       FState.MoveCode := code
     215      FState.MoveCode := Code
    197216    else if FState.MoveCode and 1 = 1 then
    198217    begin // FM + this
    199       FState.MoveCode := FState.MoveCode + code shl 4;
    200       if code and 1 = 1 then
     218      FState.MoveCode := FState.MoveCode + Code shl 4;
     219      if Code and 1 = 1 then
    201220        PutData(@FState.MoveCode, 1) // FM + FM
    202221      else
     
    204223      FState.MoveCode := 0;
    205224    end
    206     else if code and 1 = 1 then
     225    else if Code and 1 = 1 then
    207226    begin // M + FM
    208       FState.MoveCode := FState.MoveCode + code shl 18;
     227      FState.MoveCode := FState.MoveCode + Code shl 18;
    209228      PutData(@FState.MoveCode, 3);
    210229      FState.MoveCode := 0;
     
    213232    begin
    214233      PutData(@FState.MoveCode, 3);
    215       FState.MoveCode := code;
     234      FState.MoveCode := Code;
    216235    end;
    217236    FState.LastMovingUnit := Subject;
     
    222241    if Command >= cClientEx then
    223242    begin
    224       code := 2 + Command shl 3 + Player shl 19;
    225       PutData(@code, 3);
    226     end
    227     else
    228     begin
    229       code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16 +
     243      Code := 2 + Command shl 3 + Player shl 19;
     244      PutData(@Code, 3);
     245    end
     246    else
     247    begin
     248      Code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16 +
    230249        Cardinal(Subject) shl 20;
    231       PutData(@code, 4);
    232     end;
    233   end;
    234   if Command and $F <> 0 then
    235     PutData(Data, Command and $F * 4);
    236 end;
    237 
    238 procedure TCmdList.PutDataChanges(Command, Player: integer;
    239   OldData, NewData: pointer; DataSize: integer);
     250      PutData(@Code, 4);
     251    end;
     252  end;
     253  if Command and CommandDataElementCountMask <> 0 then
     254    PutData(Data, Command and CommandDataElementCountMask * CommandDataElementSize);
     255end;
     256
     257procedure TCmdList.PutDataChanges(Command, Player: Integer;
     258  OldData, NewData: Pointer; DataSize: Integer);
    240259var
    241   MapPos, LogPos, b0, b1, RowEnd: integer;
    242   Map0, Map1, code: Cardinal;
     260  MapPos, LogPos, b0, b1, RowEnd: Integer;
     261  Map0, Map1, Code: Cardinal;
    243262begin
    244263  if DataSize <= 0 then
    245     exit;
     264    Exit;
    246265  if DataSize > MaxDataSize then
    247266    DataSize := MaxDataSize;
     
    254273    if LogPos + 4 * 32 > LogAlloc then
    255274    begin
    256       inc(LogAlloc, LogGrow);
     275      Inc(LogAlloc, LogGrow);
    257276      ReallocMem(LogData, LogAlloc);
    258277    end;
     
    268287      begin
    269288        Cardinal((@LogData[LogPos])^) := PData(NewData)[b1];
    270         inc(LogPos, 4);
    271         inc(Map1, $80000000);
     289        Inc(LogPos, 4);
     290        Inc(Map1, $80000000);
    272291      end;
    273292    end;
     
    277296      Cardinal((@LogData[MapPos])^) := Map1;
    278297      MapPos := LogPos;
    279       inc(LogPos, 4);
    280       inc(Map0, $80000000);
     298      Inc(LogPos, 4);
     299      Inc(Map0, $80000000);
    281300    end;
    282301  end;
    283302  if Map0 = 0 then
    284     exit; // no changes
     303    Exit; // no changes
    285304
    286305  Map0 := Map0 shr (31 - (DataSize - 1) div 32);
    287306  Cardinal((@LogData[FState.nLog + 4])^) := Map0;
    288   code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16;
    289   Cardinal((@LogData[FState.nLog])^) := code;
     307  Code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16;
     308  Cardinal((@LogData[FState.nLog])^) := Code;
    290309  FState.nLog := MapPos;
    291310end;
    292311
    293 procedure TCmdList.PutData(Data: pointer; Length: integer);
     312procedure TCmdList.PutData(Data: Pointer; Length: Integer);
    294313begin
    295314  if FState.nLog + Length > LogAlloc then
    296315  begin
    297     inc(LogAlloc, LogGrow);
     316    Inc(LogAlloc, LogGrow);
    298317    ReallocMem(LogData, LogAlloc);
    299318  end;
    300   move(Data^, LogData[FState.nLog], Length);
    301   inc(FState.nLog, Length);
     319  Move(Data^, LogData[FState.nLog], Length);
     320  Inc(FState.nLog, Length);
    302321end;
    303322
     
    314333end;
    315334
    316 procedure TCmdList.LoadFromFile(const f: TFileStream);
    317 begin
    318   f.read(FState.nLog, 4);
     335procedure TCmdList.LoadFromFile(const F: TFileStream);
     336begin
     337  F.Read(FState.nLog, 4);
    319338  LogData := nil;
    320339  LogAlloc := ((FState.nLog + 2) div LogGrow + 1) * LogGrow;
    321340  ReallocMem(LogData, LogAlloc);
    322   f.read(LogData^, FState.nLog);
     341  F.Read(LogData^, FState.nLog);
    323342  FState.LoadPos := 0;
    324343end;
    325344
    326 procedure TCmdList.SaveToFile(const f: TFileStream);
     345procedure TCmdList.SaveToFile(const F: TFileStream);
    327346begin
    328347  CompleteMoveCode;
    329   f.write(FState.nLog, 4);
    330   f.write(LogData^, FState.nLog);
    331 end;
    332 
    333 procedure TCmdList.AppendToFile(const f: TFileStream;
     348  F.Write(FState.nLog, 4);
     349  F.Write(LogData^, FState.nLog);
     350end;
     351
     352procedure TCmdList.AppendToFile(const F: TFileStream;
    334353  const OldState: TCmdListState);
    335354begin
    336355  CompleteMoveCode;
    337   f.write(FState.nLog, 4);
    338   f.Position := f.Position + OldState.nLog;
    339   f.write(LogData[OldState.nLog], FState.nLog - OldState.nLog);
     356  F.Write(FState.nLog, 4);
     357  F.Position := F.Position + OldState.nLog;
     358  F.Write(LogData[OldState.nLog], FState.nLog - OldState.nLog);
    340359end;
    341360
     
    345364end;
    346365
    347 function TCmdList.Progress: integer;
     366function TCmdList.Progress: Integer;
    348367begin
    349368  if (FState.LoadPos = FState.nLog) and (FState.LoadMoveCode = 0) then
    350     result := 1000 // loading complete
     369    Result := 1000 // loading complete
    351370  else if FState.nLog > 1 shl 20 then
    352     result := (FState.LoadPos shr 8) * 999 div (FState.nLog shr 8)
     371    Result := (FState.LoadPos shr 8) * 999 div (FState.nLog shr 8)
    353372  else
    354     result := FState.LoadPos * 999 div FState.nLog;
     373    Result := FState.LoadPos * 999 div FState.nLog;
    355374end;
    356375
     
    360379  Byte3    Byte2    Byte1    Byte0
    361380  ssssssss sssspppp cccccccc cccccc00
    362   (c = Command-sExecute, p = Player, s = Subject)
     381  (C = Command-sExecute, P = Player, S = Subject)
    363382
    364383  ClientEx-Command:
    365384  Byte2    Byte1    Byte0
    366385  0ppppccc cccccccc ccccc010
    367   (c = Command, p = Player)
     386  (C = Command, P = Player)
    368387
    369388  Single Move:
    370389  Byte2    Byte1    Byte0
    371390  000000ss ssssssss ssaaa110
    372   (a = Direction, s = Subject)
     391  (A = Direction, S = Subject)
    373392
    374393  Move + Follow Move:
    375394  Byte2    Byte1    Byte0
    376395  00bbb1ss ssssssss ssaaa110
    377   (a = Direction 1, s = Subject 1, b = Direction 2)
     396  (A = Direction 1, S = Subject 1, B = Direction 2)
    378397
    379398  Follow Move + Move:
    380399  Byte2    Byte1    Byte0
    381400  00ssssss ssssssbb b110aaa1
    382   (a = Direction 1, b = Direction 2, s = Subject 2)
     401  (A = Direction 1, B = Direction 2, S = Subject 2)
    383402
    384403  Single Follow Move:
    385404  Byte0
    386405  0000aaa1
    387   (a = Direction)
     406  (A = Direction)
    388407
    389408  Double Follow Move:
    390409  Byte0
    391410  bbb1aaa1
    392   (a = Direction 1, b = Direction 2)
     411  (A = Direction 1, B = Direction 2)
    393412}
    394413
  • branches/highdpi/Database.pas

    r349 r465  
    2626
    2727  nStartUn = 1;
    28   StartUn: array [0 .. nStartUn - 1] of integer = (0); // mix of start units
     28  StartUn: array [0 .. nStartUn - 1] of Integer = (0); // mix of start units
    2929
    3030  CityOwnTile = 13;
     
    5050  Mode: TGameMode;
    5151  GWonder: array [0 .. nWonder - 1] of TWonderInfo;
    52   ServerVersion: array [0 .. nPl - 1] of integer;
    53   ProcessClientData: array [0 .. nPl - 1] of boolean;
     52  ServerVersion: array [0 .. nPl - 1] of Integer;
     53  ProcessClientData: array [0 .. nPl - 1] of Boolean;
    5454  CL: TCmdList;
    5555{$IFDEF TEXTLOG}CmdInfo: string;
     
    5858  // map data
    5959  RealMap: array [0 .. lxmax * lymax - 1] of Cardinal;
    60   Continent: array [0 .. lxmax * lymax - 1] of integer;
     60  Continent: array [0 .. lxmax * lymax - 1] of Integer;
    6161  { continent id for each tile }
    6262  Occupant: array [0 .. lxmax * lymax - 1] of ShortInt;
     
    6565  ObserveLevel: array [0 .. lxmax * lymax - 1] of Cardinal;
    6666  { Observe Level of player p in bits 2*p and 2*p+1 }
    67   UsedByCity: array [0 .. lxmax * lymax - 1] of integer;
     67  UsedByCity: array [0 .. lxmax * lymax - 1] of Integer;
    6868  { location of exploiting city for
    6969    each tile, =-1 if not exploited }
     
    7171  // player data
    7272  RW: array [0 .. nPl - 1] of TPlayerContext; { player data }
    73   Difficulty: array [0 .. nPl - 1] of integer;
     73  Difficulty: array [0 .. nPl - 1] of Integer;
    7474  GShip: array [0 .. nPl - 1] of TShipInfo;
    7575  ResourceMask: array [0 .. nPl - 1] of Cardinal;
    76   Founded: array [0 .. nPl - 1] of integer; { number of cities founded }
    77   TerritoryCount: array [0 .. nPl] of integer;
     76  Founded: array [0 .. nPl - 1] of Integer; { number of cities founded }
     77  TerritoryCount: array [0 .. nPl] of Integer;
    7878  LastValidStat, Researched, Discovered, // number of tiles discovered
    79   GrWallContinent: array [0 .. nPl - 1] of integer;
     79  GrWallContinent: array [0 .. nPl - 1] of Integer;
    8080  RWemix: array [0 .. nPl - 1, 0 .. nPl - 1, 0 .. nmmax - 1] of SmallInt;
    8181  // [p1,p2,mix] -> index of p2's model mix in p1's enemy model list
    8282  Destroyed: array [0 .. nPl - 1, 0 .. nPl - 1, 0 .. nmmax - 1] of SmallInt;
    8383  // [p1,p2,mix] -> number of p2's units with model mix that p1 has destroyed
    84   nTech: array [0 .. nPl - 1] of integer; { number of known techs }
     84  nTech: array [0 .. nPl - 1] of Integer; { number of known techs }
    8585  // NewContact: array[0..nPl-1,0..nPl-1] of boolean;
    8686
    8787type
    88   TVicinity8Loc = array [0 .. 7] of integer;
    89   TVicinity21Loc = array [0 .. 27] of integer;
    90 
    91 procedure MaskD(var x: array of Cardinal; Count, Mask: Cardinal);
    92 procedure IntServer(Command, Player, Subject: integer; var Data);
    93 procedure CompactLists(p: integer);
    94 procedure ClearTestFlags(ClearFlags: integer);
    95 procedure SetTestFlags(p, SetFlags: integer);
     88  TVicinity8Loc = array [0 .. 7] of Integer;
     89  TVicinity21Loc = array [0 .. 27] of Integer;
     90
     91procedure MaskD(var X: array of Cardinal; Count, Mask: Cardinal);
     92procedure IntServer(Command, Player, Subject: Integer; var Data);
     93procedure CompactLists(P: Integer);
     94procedure ClearTestFlags(ClearFlags: Integer);
     95procedure SetTestFlags(P, SetFlags: Integer);
    9696
    9797// Tech Related Functions
    98 function TechBaseCost(nTech, diff: integer): integer;
    99 function TechCost(p: integer): integer;
    100 procedure CalculateModel(var m: TModel);
    101 procedure CheckSpecialModels(p, pre: integer);
    102 procedure EnableDevModel(p: integer);
    103 procedure SeeTech(p, ad: integer);
    104 procedure DiscoverTech(p, ad: integer);
    105 procedure CheckExpiration(Wonder: integer);
     98function TechBaseCost(nTech, diff: Integer): Integer;
     99function TechCost(P: Integer): Integer;
     100procedure CalculateModel(var M: TModel);
     101procedure CheckSpecialModels(P, pre: Integer);
     102procedure EnableDevModel(P: Integer);
     103procedure SeeTech(P, ad: Integer);
     104procedure DiscoverTech(P, ad: Integer);
     105procedure CheckExpiration(Wonder: Integer);
    106106
    107107// Location Navigation
    108 function dLoc(Loc, dx, dy: integer): integer;
    109 procedure dxdy(Loc0, Loc1: integer; var dx, dy: integer);
    110 function Distance(Loc0, Loc1: integer): integer;
    111 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    112 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
     108function dLoc(Loc, dx, dy: Integer): Integer;
     109procedure dxdy(Loc0, Loc1: Integer; var dx, dy: Integer);
     110function Distance(Loc0, Loc1: Integer): Integer;
     111procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     112procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
    113113
    114114// Game Initialization
    115115procedure InitRandomGame;
    116 procedure InitMapGame(Human: integer);
     116procedure InitMapGame(Human: Integer);
    117117procedure ReleaseGame;
    118118
    119119// Map Editor
    120 function MapGeneratorAvailable: boolean;
     120function MapGeneratorAvailable: Boolean;
    121121procedure CreateElevation;
    122 procedure CreateMap(preview: boolean);
     122procedure CreateMap(preview: Boolean);
    123123procedure InitMapEditor;
    124124procedure ReleaseMapEditor;
    125 procedure EditTile(Loc, NewTile: integer);
     125procedure EditTile(Loc, NewTile: Integer);
    126126
    127127// Map Revealing
    128 function GetTileInfo(p, cix, Loc: integer; var Info: TTileInfo): integer;
    129 procedure Strongest(Loc: integer; var uix, Strength, Bonus, Cnt: integer);
    130 function UnitSpeed(p, mix, Health: integer): integer;
    131 procedure GetUnitReport(p, uix: integer; var UnitReport: TUnitReport);
    132 procedure SearchCity(Loc: integer; var p, cix: integer);
    133 procedure TellAboutModel(p, taOwner, tamix: integer);
    134 function emixSafe(p, taOwner, tamix: integer): integer;
    135 function Discover9(Loc, p, Level: integer;
    136   TellAllied, EnableContact: boolean): boolean;
    137 function Discover21(Loc, p, AdjacentLevel: integer;
    138   TellAllied, EnableContact: boolean): boolean;
    139 procedure DiscoverAll(p, Level: integer);
    140 procedure DiscoverViewAreas(p: integer);
    141 function GetUnitStack(p, Loc: integer): integer;
    142 procedure UpdateUnitMap(Loc: integer; CityChange: boolean = false);
    143 procedure RecalcV8ZoC(p, Loc: integer);
    144 procedure RecalcMapZoC(p: integer);
    145 procedure RecalcPeaceMap(p: integer);
     128function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer;
     129procedure Strongest(Loc: Integer; var uix, Strength, Bonus, Cnt: Integer);
     130function UnitSpeed(P, mix, Health: Integer): Integer;
     131procedure GetUnitReport(P, uix: Integer; var UnitReport: TUnitReport);
     132procedure SearchCity(Loc: Integer; var P, cix: Integer);
     133procedure TellAboutModel(P, taOwner, tamix: Integer);
     134function emixSafe(P, taOwner, tamix: Integer): Integer;
     135function Discover9(Loc, P, Level: Integer;
     136  TellAllied, EnableContact: Boolean): Boolean;
     137function Discover21(Loc, P, AdjacentLevel: Integer;
     138  TellAllied, EnableContact: Boolean): Boolean;
     139procedure DiscoverAll(P, Level: Integer);
     140procedure DiscoverViewAreas(P: Integer);
     141function GetUnitStack(P, Loc: Integer): Integer;
     142procedure UpdateUnitMap(Loc: Integer; CityChange: Boolean = False);
     143procedure RecalcV8ZoC(P, Loc: Integer);
     144procedure RecalcMapZoC(P: Integer);
     145procedure RecalcPeaceMap(P: Integer);
    146146
    147147// Territory Calculation
    148 procedure CheckBorders(OriginLoc: integer; PlayerLosingCity: integer = -1);
    149 procedure LogCheckBorders(p, cix: integer; PlayerLosingCity: integer = -1);
     148procedure CheckBorders(OriginLoc: Integer; PlayerLosingCity: Integer = -1);
     149procedure LogCheckBorders(P, cix: Integer; PlayerLosingCity: Integer = -1);
    150150
    151151// Map Processing
    152 procedure CreateUnit(p, mix: integer);
    153 procedure FreeUnit(p, uix: integer);
    154 procedure PlaceUnit(p, uix: integer);
    155 procedure RemoveUnit(p, uix: integer; Enemy: integer = -1);
    156 procedure RemoveUnit_UpdateMap(p, uix: integer);
    157 procedure RemoveAllUnits(p, Loc: integer; Enemy: integer = -1);
    158 procedure RemoveDomainUnits(d, p, Loc: integer);
    159 procedure FoundCity(p, FoundLoc: integer);
    160 procedure DestroyCity(p, cix: integer; SaveUnits: boolean);
    161 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);
    162 procedure CompleteJob(p, Loc, Job: integer);
     152procedure CreateUnit(P, mix: Integer);
     153procedure FreeUnit(P, uix: Integer);
     154procedure PlaceUnit(P, uix: Integer);
     155procedure RemoveUnit(P, uix: Integer; Enemy: Integer = -1);
     156procedure RemoveUnit_UpdateMap(P, uix: Integer);
     157procedure RemoveAllUnits(P, Loc: Integer; Enemy: Integer = -1);
     158procedure RemoveDomainUnits(D, P, Loc: Integer);
     159procedure FoundCity(P, FoundLoc: Integer);
     160procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean);
     161procedure ChangeCityOwner(pOld, cixOld, pNew: Integer);
     162procedure CompleteJob(P, Loc, Job: Integer);
    163163
    164164// Diplomacy
    165 procedure IntroduceEnemy(p1, p2: integer);
    166 procedure GiveCivilReport(p, pAbout: integer);
    167 procedure GiveMilReport(p, pAbout: integer);
    168 procedure ShowPrice(pSender, pTarget, Price: integer);
    169 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;
    170 procedure CancelTreaty(p, pWith: integer; DecreaseCredibility: boolean = true);
    171 function DoSpyMission(p, pCity, cix, Mission: integer): Cardinal;
     165procedure IntroduceEnemy(p1, p2: Integer);
     166procedure GiveCivilReport(P, pAbout: Integer);
     167procedure GiveMilReport(P, pAbout: Integer);
     168procedure ShowPrice(pSender, pTarget, Price: Integer);
     169function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean;
     170procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean = True);
     171function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal;
     172
    172173
    173174implementation
     
    179180
    180181var
    181   UnBuilt: array [0 .. nPl - 1] of integer; { number of units built }
    182 
    183 procedure MaskD(var x: array of Cardinal; Count, Mask: Cardinal);
     182  UnBuilt: array [0 .. nPl - 1] of Integer; { number of units built }
     183
     184procedure MaskD(var X: array of Cardinal; Count, Mask: Cardinal);
    184185var
    185186  I: Integer;
    186187begin
    187188  for I := 0 to Count - 1 do
    188     x[I] := x[I] and Mask;
    189 end;
    190 
    191 procedure CompactLists(p: integer);
    192 var
    193   uix, uix1, cix: integer;
    194 {$IFOPT O-}V21: integer;
     189    X[I] := X[I] and Mask;
     190end;
     191
     192procedure CompactLists(P: Integer);
     193var
     194  uix, uix1, cix: Integer;
     195{$IFOPT O-}V21: Integer;
    195196  Radius: TVicinity21Loc; {$ENDIF}
    196197begin
    197   with RW[p] do
     198  with RW[P] do
    198199  begin
    199200    // compact unit list
     
    202203      if Un[uix].Loc < 0 then
    203204      begin
    204         dec(nUn);
     205        Dec(nUn);
    205206        Un[uix] := Un[nUn]; { replace removed unit by last }
    206207        if (Un[uix].TroopLoad > 0) or (Un[uix].AirLoad > 0) then
     
    211212      end
    212213      else
    213         inc(uix);
     214        Inc(uix);
    214215
    215216    // compact city list
     
    218219      if City[cix].Loc < 0 then
    219220      begin
    220         dec(nCity);
     221        Dec(nCity);
    221222        City[cix] := City[nCity]; { replace city by last }
    222223        for uix1 := 0 to nUn - 1 do
     
    226227      end
    227228      else
    228         inc(cix);
     229        Inc(cix);
    229230
    230231    // compact enemy city list
     
    233234      if EnemyCity[cix].Loc < 0 then
    234235      begin
    235         dec(nEnemyCity);
     236        Dec(nEnemyCity);
    236237        EnemyCity[cix] := EnemyCity[nEnemyCity]; { replace city by last }
    237238      end
    238239      else
    239         inc(cix);
     240        Inc(cix);
    240241
    241242{$IFOPT O-}
     
    246247        for V21 := 1 to 26 do
    247248          if Tiles and (1 shl V21) <> 0 then
    248             assert(UsedByCity[Radius[V21]] = Loc);
    249       end
     249            Assert(UsedByCity[Radius[V21]] = Loc);
     250      end;
    250251{$ENDIF}
    251252  end;
    252 end; // CompactLists
     253end;
    253254
    254255{
     
    256257  ____________________________________________________________________
    257258}
    258 function TechBaseCost(nTech, diff: integer): integer;
    259 var
    260   c0: single;
     259function TechBaseCost(nTech, diff: Integer): Integer;
     260var
     261  c0: Single;
    261262begin
    262263  c0 := TechFormula_M[diff] * (nTech + 4) *
    263264    exp((nTech + 4) / TechFormula_D[diff]);
    264265  if c0 >= $10000000 then
    265     result := $10000000
     266    Result := $10000000
    266267  else
    267     result := trunc(c0)
    268 end;
    269 
    270 function TechCost(p: integer): integer;
    271 begin
    272   with RW[p] do
    273   begin
    274     result := TechBaseCost(nTech[p], Difficulty[p]);
     268    Result := trunc(c0);
     269end;
     270
     271function TechCost(P: Integer): Integer;
     272begin
     273  with RW[P] do
     274  begin
     275    Result := TechBaseCost(nTech[P], Difficulty[P]);
    275276    if ResearchTech >= 0 then
    276277      if (ResearchTech = adMilitary) or (Tech[ResearchTech] = tsSeen) then
    277         result := result shr 1
     278        Result := Result shr 1
    278279      else if ResearchTech in FutureTech then
    279280        if Government = gFuture then
    280           result := result * 2
     281          Result := Result * 2
    281282        else
    282           result := result * 4;
    283   end
    284 end;
    285 
    286 procedure SetModelFlags(var m: TModel);
    287 begin
    288   m.Flags := 0;
    289   if (m.Domain = dGround) and (m.Kind <> mkDiplomat) then
    290     m.Flags := m.Flags or mdZOC;
    291   if (m.Kind = mkDiplomat) or (m.Attack + m.Cap[mcBombs] = 0) then
    292     m.Flags := m.Flags or mdCivil;
    293   if (m.Cap[mcOver] > 0) or (m.Domain = dSea) and (m.Weight >= 6) then
    294     m.Flags := m.Flags or mdDoubleSupport;
    295 end;
    296 
    297 procedure CalculateModel(var m: TModel);
     283          Result := Result * 4;
     284  end;
     285end;
     286
     287procedure SetModelFlags(var M: TModel);
     288begin
     289  M.Flags := 0;
     290  if (M.Domain = dGround) and (M.Kind <> mkDiplomat) then
     291    M.Flags := M.Flags or mdZOC;
     292  if (M.Kind = mkDiplomat) or (M.Attack + M.Cap[mcBombs] = 0) then
     293    M.Flags := M.Flags or mdCivil;
     294  if (M.Cap[mcOver] > 0) or (M.Domain = dSea) and (M.Weight >= 6) then
     295    M.Flags := M.Flags or mdDoubleSupport;
     296end;
     297
     298procedure CalculateModel(var M: TModel);
    298299{ calculate attack, defense, cost... of a model by features }
    299300var
    300   i: integer;
    301 begin
    302   with m do
     301  I: Integer;
     302begin
     303  with M do
    303304  begin
    304305    Attack := (Cap[mcOffense] + Cap[mcOver]) * MStrength;
     
    311312          Speed := 350 + 200 * Cap[mcNP] + 200 * Cap[mcTurbines];
    312313          if Cap[mcNP] = 0 then
    313             inc(Speed, 100 * Cap[mcSE]);
     314            Inc(Speed, 100 * Cap[mcSE]);
    314315        end;
    315316      dAir:
     
    317318    end;
    318319    Cost := 0;
    319     for i := 0 to nFeature - 1 do
    320       if 1 shl Domain and Feature[i].Domains <> 0 then
    321         inc(Cost, Cap[i] * Feature[i].Cost);
     320    for I := 0 to nFeature - 1 do
     321      if 1 shl Domain and Feature[I].Domains <> 0 then
     322        Inc(Cost, Cap[I] * Feature[I].Cost);
    322323    Cost := Cost * MCost;
    323324    Weight := 0;
    324     for i := 0 to nFeature - 1 do
    325       if 1 shl Domain and Feature[i].Domains <> 0 then
    326         if (Domain = dGround) and (i = mcDefense) then
    327           inc(Weight, Cap[i] * 2)
     325    for I := 0 to nFeature - 1 do
     326      if 1 shl Domain and Feature[I].Domains <> 0 then
     327        if (Domain = dGround) and (I = mcDefense) then
     328          Inc(Weight, Cap[I] * 2)
    328329        else
    329           inc(Weight, Cap[i] * Feature[i].Weight);
    330   end;
    331   SetModelFlags(m);
    332 end;
    333 
    334 procedure CheckSpecialModels(p, pre: integer);
    335 var
    336   i, mix1: integer;
    337   HasAlready: boolean;
    338 begin
    339   for i := 0 to nSpecialModel -
     330          Inc(Weight, Cap[I] * Feature[I].Weight);
     331  end;
     332  SetModelFlags(M);
     333end;
     334
     335procedure CheckSpecialModels(P, pre: Integer);
     336var
     337  I, mix1: Integer;
     338  HasAlready: Boolean;
     339begin
     340  for I := 0 to nSpecialModel -
    340341    1 do { check whether new special model available }
    341     if (SpecialModelPreq[i] = pre) and (RW[p].nModel < nmmax) then
    342     begin
    343       HasAlready := false;
    344       for mix1 := 0 to RW[p].nModel - 1 do
    345         if (RW[p].Model[mix1].Kind = SpecialModel[i].Kind) and
    346           (RW[p].Model[mix1].Attack = SpecialModel[i].Attack) and
    347           (RW[p].Model[mix1].Speed = SpecialModel[i].Speed) then
    348           HasAlready := true;
     342    if (SpecialModelPreq[I] = pre) and (RW[P].nModel < nmmax) then
     343    begin
     344      HasAlready := False;
     345      for mix1 := 0 to RW[P].nModel - 1 do
     346        if (RW[P].Model[mix1].Kind = SpecialModel[I].Kind) and
     347          (RW[P].Model[mix1].Attack = SpecialModel[I].Attack) and
     348          (RW[P].Model[mix1].Speed = SpecialModel[I].Speed) then
     349          HasAlready := True;
    349350      if not HasAlready then
    350351      begin
    351         RW[p].Model[RW[p].nModel] := SpecialModel[i];
    352         SetModelFlags(RW[p].Model[RW[p].nModel]);
    353         with RW[p].Model[RW[p].nModel] do
     352        RW[P].Model[RW[P].nModel] := SpecialModel[I];
     353        SetModelFlags(RW[P].Model[RW[P].nModel]);
     354        with RW[P].Model[RW[P].nModel] do
    354355        begin
    355356          Status := 0;
     
    358359          Built := 0;
    359360          Lost := 0;
    360           ID := p shl 12 + RW[p].nModel;
    361           if (Kind = mkSpecial_Boat) and (ServerVersion[p] < $000EF0) then
     361          ID := P shl 12 + RW[P].nModel;
     362          if (Kind = mkSpecial_Boat) and (ServerVersion[P] < $000EF0) then
    362363            Speed := 350; // old longboat
    363364        end;
    364         inc(RW[p].nModel);
    365       end
    366     end;
    367 end;
    368 
    369 procedure EnableDevModel(p: integer);
    370 begin
    371   with RW[p] do
     365        Inc(RW[P].nModel);
     366      end;
     367    end;
     368end;
     369
     370procedure EnableDevModel(P: Integer);
     371begin
     372  with RW[P] do
    372373    if nModel < nmmax then
    373374    begin
     
    380381        Built := 0;
    381382        Lost := 0;
    382         ID := p shl 12 + nModel
    383       end;
    384       inc(nModel);
    385       inc(Researched[p])
    386     end
    387 end;
    388 
    389 procedure SeeTech(p, ad: integer);
    390 begin
    391 {$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [p, ad]); {$ENDIF}
    392   RW[p].Tech[ad] := tsSeen;
     383        ID := P shl 12 + nModel;
     384      end;
     385      Inc(nModel);
     386      Inc(Researched[P]);
     387    end;
     388end;
     389
     390procedure SeeTech(P, ad: Integer);
     391begin
     392{$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [P, ad]); {$ENDIF}
     393  RW[P].Tech[ad] := tsSeen;
    393394  // inc(nTech[p]);
    394   inc(Researched[p])
     395  Inc(Researched[P]);
    395396end;
    396397
    397398procedure FreeSlaves;
    398399var
    399   p1, uix: integer;
     400  p1, uix: Integer;
    400401begin
    401402  for p1 := 0 to nPl - 1 do
     
    403404      for uix := 0 to RW[p1].nUn - 1 do
    404405        if RW[p1].Model[RW[p1].Un[uix].mix].Kind = mkSlaves then
    405           RW[p1].Un[uix].Job := jNone
    406 end;
    407 
    408 procedure DiscoverTech(p, ad: integer);
    409 
    410   procedure TellAboutKeyTech(p, Source: integer);
     406          RW[p1].Un[uix].Job := jNone;
     407end;
     408
     409procedure DiscoverTech(P, ad: Integer);
     410
     411  procedure TellAboutKeyTech(P, Source: Integer);
    411412  var
    412     i, p1: integer;
    413   begin
    414     for i := 1 to 3 do
    415       if ad = AgePreq[i] then
     413    I, p1: Integer;
     414  begin
     415    for I := 1 to 3 do
     416      if ad = AgePreq[I] then
    416417        for p1 := 0 to nPl - 1 do
    417           if (p1 <> p) and ((GAlive or GWatching) and (1 shl p1) <> 0) then
    418             RW[p1].EnemyReport[p].Tech[ad] := Source;
    419   end;
    420 
    421 var
    422   i: integer;
     418          if (p1 <> P) and ((GAlive or GWatching) and (1 shl p1) <> 0) then
     419            RW[p1].EnemyReport[P].Tech[ad] := Source;
     420  end;
     421
     422var
     423  I: Integer;
    423424begin
    424425  if ad in FutureTech then
    425426  begin
    426     if RW[p].Tech[ad] < tsApplicable then
    427       RW[p].Tech[ad] := 1
     427    if RW[P].Tech[ad] < tsApplicable then
     428      RW[P].Tech[ad] := 1
    428429    else
    429       inc(RW[p].Tech[ad]);
     430      Inc(RW[P].Tech[ad]);
    430431    if ad <> futResearchTechnology then
    431       inc(nTech[p], 2);
    432     inc(Researched[p], 8);
    433     exit;
    434   end;
    435 
    436   if RW[p].Tech[ad] = tsSeen then
    437   begin
    438     inc(nTech[p]);
    439     inc(Researched[p]);
     432      Inc(nTech[P], 2);
     433    Inc(Researched[P], 8);
     434    Exit;
     435  end;
     436
     437  if RW[P].Tech[ad] = tsSeen then
     438  begin
     439    Inc(nTech[P]);
     440    Inc(Researched[P]);
    440441  end
    441442  else
    442443  begin
    443     inc(nTech[p], 2);
    444     inc(Researched[p], 2);
    445   end;
    446   RW[p].Tech[ad] := tsResearched;
    447   TellAboutKeyTech(p, tsResearched);
    448   CheckSpecialModels(p, ad);
     444    Inc(nTech[P], 2);
     445    Inc(Researched[P], 2);
     446  end;
     447  RW[P].Tech[ad] := tsResearched;
     448  TellAboutKeyTech(P, tsResearched);
     449  CheckSpecialModels(P, ad);
    449450  if ad = adScience then
    450     ResourceMask[p] := ResourceMask[p] or fSpecial2;
     451    ResourceMask[P] := ResourceMask[P] or fSpecial2;
    451452  if ad = adMassProduction then
    452     ResourceMask[p] := ResourceMask[p] or fModern;
    453 
    454   for i := 0 to nWonder - 1 do { check whether wonders expired }
    455     if (GWonder[i].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and
    456       (Imp[i].Expiration = ad) then
    457     begin
    458       GWonder[i].EffectiveOwner := -1;
    459       if i = woPyramids then
     453    ResourceMask[P] := ResourceMask[P] or fModern;
     454
     455  for I := 0 to nWonder - 1 do { check whether wonders expired }
     456    if (GWonder[I].EffectiveOwner <> GWonder[woEiffel].EffectiveOwner) and
     457      (Imp[I].Expiration = ad) then
     458    begin
     459      GWonder[I].EffectiveOwner := -1;
     460      if I = woPyramids then
    460461        FreeSlaves;
    461462    end;
    462463end;
    463464
    464 procedure CheckExpiration(Wonder: integer);
     465procedure CheckExpiration(Wonder: Integer);
    465466// GWonder[Wonder].EffectiveOwner must be set before!
    466467var
    467   p: integer;
     468  P: Integer;
    468469begin
    469470  if (Imp[Wonder].Expiration >= 0) and
    470471    (GWonder[woEiffel].EffectiveOwner <> GWonder[Wonder].EffectiveOwner) then
    471     for p := 0 to nPl - 1 do // check if already expired
    472       if (1 shl p and GAlive <> 0) and
    473         (RW[p].Tech[Imp[Wonder].Expiration] >= tsApplicable) then
     472    for P := 0 to nPl - 1 do // check if already expired
     473      if (1 shl P and GAlive <> 0) and
     474        (RW[P].Tech[Imp[Wonder].Expiration] >= tsApplicable) then
    474475      begin
    475476        GWonder[Wonder].EffectiveOwner := -1;
    476477        if Wonder = woPyramids then
    477           FreeSlaves
    478       end
     478          FreeSlaves;
     479      end;
    479480end;
    480481
     
    483484  ____________________________________________________________________
    484485}
    485 function dLoc(Loc, dx, dy: integer): integer;
     486function dLoc(Loc, dx, dy: Integer): Integer;
    486487{ relative location, dx in hor and dy in ver direction from Loc }
    487488var
    488   y0: integer;
     489  y0: Integer;
    489490begin
    490491  if not (Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0) then
    491492    raise Exception.Create('Relative location error');
    492   assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));
     493  Assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));
    493494  y0 := Loc div lx;
    494   result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy);
    495   if (result < 0) or (result >= MapSize) then
    496     result := -1;
    497 end;
    498 
    499 procedure dxdy(Loc0, Loc1: integer; var dx, dy: integer);
     495  Result := (Loc + (dx + y0 and 1 + lx + lx) shr 1) mod lx + lx * (y0 + dy);
     496  if (Result < 0) or (Result >= MapSize) then
     497    Result := -1;
     498end;
     499
     500procedure dxdy(Loc0, Loc1: Integer; var dx, dy: Integer);
    500501begin
    501502  dx := ((Loc1 mod lx * 2 + Loc1 div lx and 1) -
     
    504505end;
    505506
    506 function Distance(Loc0, Loc1: integer): integer;
    507 var
    508   dx, dy: integer;
     507function Distance(Loc0, Loc1: Integer): Integer;
     508var
     509  dx, dy: Integer;
    509510begin
    510511  dxdy(Loc0, Loc1, dx, dy);
    511512  dx := abs(dx);
    512513  dy := abs(dy);
    513   result := dx + dy + abs(dx - dy) shr 1;
    514 end;
    515 
    516 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    517 var
    518   x0, y0, lx0: integer;
     514  Result := dx + dy + abs(dx - dy) shr 1;
     515end;
     516
     517procedure V8_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity8Loc);
     518var
     519  x0, y0, lx0: Integer;
    519520begin
    520521  lx0 := lx; // put in register!
     
    526527  VicinityLoc[5] := Loc0 - lx0 * 2;
    527528  VicinityLoc[7] := Loc0 + 1;
    528   inc(Loc0, y0);
     529  Inc(Loc0, y0);
    529530  VicinityLoc[0] := Loc0 + lx0;
    530531  VicinityLoc[2] := Loc0 + lx0 - 1;
     
    537538    if x0 = 0 then
    538539    begin
    539       inc(VicinityLoc[3], lx0);
     540      Inc(VicinityLoc[3], lx0);
    540541      if y0 = 0 then
    541542      begin
    542         inc(VicinityLoc[2], lx0);
    543         inc(VicinityLoc[4], lx0);
    544       end
    545     end
     543        Inc(VicinityLoc[2], lx0);
     544        Inc(VicinityLoc[4], lx0);
     545      end;
     546    end;
    546547  end
    547548  else
    548549  begin
    549     dec(VicinityLoc[7], lx0);
     550    Dec(VicinityLoc[7], lx0);
    550551    if y0 = 1 then
    551552    begin
    552       dec(VicinityLoc[0], lx0);
    553       dec(VicinityLoc[6], lx0);
    554     end
    555   end;
    556 end;
    557 
    558 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    559 var
    560   dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;
    561   dst: ^integer;
     553      Dec(VicinityLoc[0], lx0);
     554      Dec(VicinityLoc[6], lx0);
     555    end;
     556  end;
     557end;
     558
     559procedure V21_to_Loc(Loc0: Integer; var VicinityLoc: TVicinity21Loc);
     560var
     561  dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: Integer;
     562  dst: ^Integer;
    562563begin
    563564  y0 := Loc0 div lx;
     
    565566  xCompSwitch := xComp0 - 1 + y0 and 1;
    566567  if xComp0 < 0 then
    567     inc(xComp0, lx);
     568    Inc(xComp0, lx);
    568569  if xCompSwitch < 0 then
    569     inc(xCompSwitch, lx);
     570    Inc(xCompSwitch, lx);
    570571  xCompSwitch := xCompSwitch xor xComp0;
    571572  yComp := lx * (y0 - 3);
     
    582583      else
    583584        dst^ := -1;
    584       inc(xComp);
     585      Inc(xComp);
    585586      if xComp >= lx then
    586         dec(xComp, lx);
    587       inc(dst);
     587        Dec(xComp, lx);
     588      Inc(dst);
    588589      bit := bit shl 1;
    589590    end;
    590     inc(yComp, lx);
     591    Inc(yComp, lx);
    591592  end;
    592593end;
     
    597598}
    598599var
    599   primitive: integer;
    600   StartLoc, StartLoc2: array [0 .. nPl - 1] of integer; { starting coordinates }
     600  primitive: Integer;
     601  StartLoc, StartLoc2: array [0 .. nPl - 1] of Integer; { starting coordinates }
    601602  Elevation: array [0 .. lxmax * lymax - 1] of Byte; { map elevation }
    602   ElCount: array [Byte] of integer; { count of elevation occurance }
     603  ElCount: array [Byte] of Integer; { count of elevation occurance }
    603604
    604605procedure CalculatePrimitive;
    605606var
    606   i, j: integer;
     607  I, J: Integer;
    607608begin
    608609  primitive := 1;
    609   i := 2;
    610   while i * i <= MapSize + 1 do // test whether prime
    611   begin
    612     if (MapSize + 1) mod i = 0 then
     610  I := 2;
     611  while I * I <= MapSize + 1 do // test whether prime
     612  begin
     613    if (MapSize + 1) mod I = 0 then
    613614      primitive := 0;
    614     inc(i)
     615    Inc(I);
    615616  end;
    616617
    617618  if primitive > 0 then
    618619    repeat
    619       inc(primitive);
    620       i := 1;
    621       j := 0;
     620      Inc(primitive);
     621      I := 1;
     622      J := 0;
    622623      repeat
    623         inc(j);
    624         i := i * primitive mod (MapSize + 1)
    625       until (i = 1) or (j = MapSize + 1);
    626     until j = MapSize;
    627 end;
    628 
    629 function MapGeneratorAvailable: boolean;
    630 begin
    631   result := (primitive > 0) and (lx >= 20) and (ly >= 40)
     624        Inc(J);
     625        I := I * primitive mod (MapSize + 1);
     626      until (I = 1) or (J = MapSize + 1);
     627    until J = MapSize;
     628end;
     629
     630function MapGeneratorAvailable: Boolean;
     631begin
     632  Result := (primitive > 0) and (lx >= 20) and (ly >= 40);
    632633end;
    633634
    634635procedure CreateElevation;
    635636const
    636   d = 64;
     637  D = 64;
    637638  Smooth = 0.049; { causes low amplitude of short waves }
    638639  Detail = 0.095; { causes short period of short waves }
     
    641642
    642643var
    643   sa, ca, f1, f2: array [1 .. d] of single;
    644   imerge, x, y: integer;
    645   v, maxv: single;
    646 
    647   function Value(x, y: integer): single; { elevation formula }
     644  sa, ca, f1, f2: array [1 .. D] of Single;
     645  imerge, X, Y: Integer;
     646  V, maxv: Single;
     647
     648  function Value(X, Y: Integer): Single; { elevation formula }
    648649  var
    649     i: integer;
    650   begin
    651     result := 0;
    652     for i := 1 to d do
    653       result := result + sin(f1[i] * ((x * 2 + y and 1) * sa[i] + y * 1.5 *
    654         ca[i])) * f2[i];
     650    I: Integer;
     651  begin
     652    Result := 0;
     653    for I := 1 to D do
     654      Result := Result + sin(f1[I] * ((X * 2 + Y and 1) * sa[I] + Y * 1.5 *
     655        ca[I])) * f2[I];
    655656    { x values effectively multiplied with 2 to get 2 horizantal periods
    656657      of the prime waves }
     
    658659
    659660begin
    660   for x := 1 to d do { prepare formula parameters }
    661   begin
    662 {$IFNDEF SCR} if x = 1 then
    663       v := pi / 2 { first wave goes horizontal }
    664     else {$ENDIF} v := DelphiRandom * 2 * pi;
    665     sa[x] := sin(v) / lx;
    666     ca[x] := cos(v) / ly;
    667     f1[x] := 2 * pi * exp(Detail * (x - 1));
    668     f2[x] := exp(-x * Smooth)
     661  for X := 1 to D do { prepare formula parameters }
     662  begin
     663{$IFNDEF SCR} if X = 1 then
     664      V := pi / 2 { first wave goes horizontal }
     665    else {$ENDIF} V := DelphiRandom * 2 * pi;
     666    sa[X] := sin(V) / lx;
     667    ca[X] := cos(V) / ly;
     668    f1[X] := 2 * pi * exp(Detail * (X - 1));
     669    f2[X] := exp(-X * Smooth);
    669670  end;
    670671
     
    672673  FillChar(ElCount, SizeOf(ElCount), 0);
    673674  maxv := 0;
    674   for x := 0 to lx - 1 do
    675     for y := 0 to ly - 1 do
    676     begin
    677       v := Value(x, y);
    678       if x * 2 < imerge then
    679         v := (x * 2 * v + (imerge - x * 2) * Value(x + lx, y)) / imerge;
    680       v := v - sqr(sqr(2 * y / ly - 1)); { soft cut at poles }
    681       if v > maxv then
    682         maxv := v;
    683 
    684       if v < -4 then
    685         Elevation[x + lx * y] := 0
    686       else if v > 8.75 then
    687         Elevation[x + lx * y] := 255
     675  for X := 0 to lx - 1 do
     676    for Y := 0 to ly - 1 do
     677    begin
     678      V := Value(X, Y);
     679      if X * 2 < imerge then
     680        V := (X * 2 * V + (imerge - X * 2) * Value(X + lx, Y)) / imerge;
     681      V := V - sqr(sqr(2 * Y / ly - 1)); { soft cut at poles }
     682      if V > maxv then
     683        maxv := V;
     684
     685      if V < -4 then
     686        Elevation[X + lx * Y] := 0
     687      else if V > 8.75 then
     688        Elevation[X + lx * Y] := 255
    688689      else
    689         Elevation[x + lx * y] := Round((v + 4) * 20);
    690       inc(ElCount[Elevation[x + lx * y]])
     690        Elevation[X + lx * Y] := Round((V + 4) * 20);
     691      Inc(ElCount[Elevation[X + lx * Y]]);
    691692    end;
    692693end;
     
    694695procedure FindContinents;
    695696
    696   procedure ReplaceCont(a, b, Stop: integer);
     697  procedure ReplaceCont(A, B, Stop: Integer);
    697698  { replace continent name a by b }
    698699  // make sure always continent[loc]<=loc
    699700  var
    700     i: integer;
    701   begin
    702     if a < b then
    703     begin
    704       i := a;
    705       a := b;
    706       b := i
    707     end;
    708     if a > b then
    709       for i := a to Stop do
    710         if Continent[i] = a then
    711           Continent[i] := b
    712   end;
    713 
    714 var
    715   x, y, Loc, Wrong: integer;
    716 begin
    717   for y := 1 to ly - 2 do
    718     for x := 0 to lx - 1 do
    719     begin
    720       Loc := x + lx * y;
     701    I: Integer;
     702  begin
     703    if A < B then
     704    begin
     705      I := A;
     706      A := B;
     707      B := I
     708    end;
     709    if A > B then
     710      for I := A to Stop do
     711        if Continent[I] = A then
     712          Continent[I] := B;
     713  end;
     714
     715var
     716  X, Y, Loc, Wrong: Integer;
     717begin
     718  for Y := 1 to ly - 2 do
     719    for X := 0 to lx - 1 do
     720    begin
     721      Loc := X + lx * Y;
    721722      Continent[Loc] := -1;
    722723      if RealMap[Loc] and fTerrain >= fGrass then
    723724      begin
    724         if (y - 2 >= 1) and (RealMap[Loc - 2 * lx] and fTerrain >= fGrass) then
     725        if (Y - 2 >= 1) and (RealMap[Loc - 2 * lx] and fTerrain >= fGrass) then
    725726          Continent[Loc] := Continent[Loc - 2 * lx];
    726         if (x - 1 + y and 1 >= 0) and (y - 1 >= 1) and
    727           (RealMap[Loc - 1 + y and 1 - lx] and fTerrain >= fGrass) then
    728           Continent[Loc] := Continent[Loc - 1 + y and 1 - lx];
    729         if (x + y and 1 < lx) and (y - 1 >= 1) and
    730           (RealMap[Loc + y and 1 - lx] and fTerrain >= fGrass) then
    731           Continent[Loc] := Continent[Loc + y and 1 - lx];
    732         if (x - 1 >= 0) and (RealMap[Loc - 1] and fTerrain >= fGrass) then
     727        if (X - 1 + Y and 1 >= 0) and (Y - 1 >= 1) and
     728          (RealMap[Loc - 1 + Y and 1 - lx] and fTerrain >= fGrass) then
     729          Continent[Loc] := Continent[Loc - 1 + Y and 1 - lx];
     730        if (X + Y and 1 < lx) and (Y - 1 >= 1) and
     731          (RealMap[Loc + Y and 1 - lx] and fTerrain >= fGrass) then
     732          Continent[Loc] := Continent[Loc + Y and 1 - lx];
     733        if (X - 1 >= 0) and (RealMap[Loc - 1] and fTerrain >= fGrass) then
    733734          if Continent[Loc] = -1 then
    734735            Continent[Loc] := Continent[Loc - 1]
     
    736737            ReplaceCont(Continent[Loc - 1], Continent[Loc], Loc);
    737738        if Continent[Loc] = -1 then
    738           Continent[Loc] := Loc
    739       end
     739          Continent[Loc] := Loc;
     740      end;
    740741    end;
    741742
    742743  { connect continents due to round earth }
    743   for y := 1 to ly - 2 do
    744     if RealMap[lx * y] and fTerrain >= fGrass then
     744  for Y := 1 to ly - 2 do
     745    if RealMap[lx * Y] and fTerrain >= fGrass then
    745746    begin
    746747      Wrong := -1;
    747       if RealMap[lx - 1 + lx * y] and fTerrain >= fGrass then
    748         Wrong := Continent[lx - 1 + lx * y];
    749       if (y and 1 = 0) and (y - 1 >= 1) and
    750         (RealMap[lx - 1 + lx * (y - 1)] and fTerrain >= fGrass) then
    751         Wrong := Continent[lx - 1 + lx * (y - 1)];
    752       if (y and 1 = 0) and (y + 1 < ly - 1) and
    753         (RealMap[lx - 1 + lx * (y + 1)] and fTerrain >= fGrass) then
    754         Wrong := Continent[lx - 1 + lx * (y + 1)];
     748      if RealMap[lx - 1 + lx * Y] and fTerrain >= fGrass then
     749        Wrong := Continent[lx - 1 + lx * Y];
     750      if (Y and 1 = 0) and (Y - 1 >= 1) and
     751        (RealMap[lx - 1 + lx * (Y - 1)] and fTerrain >= fGrass) then
     752        Wrong := Continent[lx - 1 + lx * (Y - 1)];
     753      if (Y and 1 = 0) and (Y + 1 < ly - 1) and
     754        (RealMap[lx - 1 + lx * (Y + 1)] and fTerrain >= fGrass) then
     755        Wrong := Continent[lx - 1 + lx * (Y + 1)];
    755756      if Wrong >= 0 then
    756         ReplaceCont(Wrong, Continent[lx * y], MapSize - 1)
     757        ReplaceCont(Wrong, Continent[lx * Y], MapSize - 1);
    757758    end;
    758759end;
     
    762763// must be done after FindContinents
    763764var
    764   i, j, Cnt, x, y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater,
    765     RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: integer;
    766   AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of integer;
    767   RareLoc: array [0 .. 11] of integer;
    768   Dist: array [0 .. 11, 0 .. 11] of integer;
     765  I, J, Cnt, X, Y, dx, dy, Loc0, Loc1, xworst, yworst, totalrare, RareMaxWater,
     766    RareType, iBest, jbest, MinDist, xBlock, yBlock, V8: Integer;
     767  AreaCount, RareByArea, RareAdjacent: array [0 .. 7, 0 .. 4] of Integer;
     768  RareLoc: array [0 .. 11] of Integer;
     769  Dist: array [0 .. 11, 0 .. 11] of Integer;
    769770  Adjacent: TVicinity8Loc;
    770771begin
     
    772773  repeat
    773774    FillChar(AreaCount, SizeOf(AreaCount), 0);
    774     for y := 1 to ly - 2 do
    775     begin
    776       yBlock := y * 5 div ly;
    777       if yBlock = (y + 1) * 5 div ly then
    778         for x := 0 to lx - 1 do
    779         begin
    780           xBlock := x * 8 div lx;
    781           if xBlock = (x + 1) * 8 div lx then
     775    for Y := 1 to ly - 2 do
     776    begin
     777      yBlock := Y * 5 div ly;
     778      if yBlock = (Y + 1) * 5 div ly then
     779        for X := 0 to lx - 1 do
     780        begin
     781          xBlock := X * 8 div lx;
     782          if xBlock = (X + 1) * 8 div lx then
    782783          begin
    783             Loc0 := x + lx * y;
     784            Loc0 := X + lx * Y;
    784785            if RealMap[Loc0] and fTerrain >= fGrass then
    785786            begin
     
    791792                if (Loc1 >= 0) and (Loc1 < MapSize) and
    792793                  (RealMap[Loc1] and fTerrain < fGrass) then
    793                   inc(Cnt); // count adjacent water
     794                  Inc(Cnt); // count adjacent water
    794795              end;
    795796              if Cnt <= RareMaxWater then // inner land
    796797              begin
    797                 inc(AreaCount[xBlock, yBlock]);
     798                Inc(AreaCount[xBlock, yBlock]);
    798799                if DelphiRandom(AreaCount[xBlock, yBlock]) = 0 then
    799                   RareByArea[xBlock, yBlock] := Loc0
    800               end
     800                  RareByArea[xBlock, yBlock] := Loc0;
     801              end;
    801802            end;
    802803          end;
    803         end
     804        end;
    804805    end;
    805806    totalrare := 0;
    806     for x := 0 to 7 do
    807       for y := 0 to 4 do
    808         if AreaCount[x, y] > 0 then
    809           inc(totalrare);
    810     inc(RareMaxWater);
     807    for X := 0 to 7 do
     808      for Y := 0 to 4 do
     809        if AreaCount[X, Y] > 0 then
     810          Inc(totalrare);
     811    Inc(RareMaxWater);
    811812  until totalrare >= 12;
    812813
     
    814815  begin // remove rarebyarea resources too close to each other
    815816    FillChar(RareAdjacent, SizeOf(RareAdjacent), 0);
    816     for x := 0 to 7 do
    817       for y := 0 to 4 do
    818         if AreaCount[x, y] > 0 then
    819         begin
    820           if (AreaCount[(x + 1) mod 8, y] > 0) and
    821             (Continent[RareByArea[x, y]] = Continent
    822             [RareByArea[(x + 1) mod 8, y]]) then
     817    for X := 0 to 7 do
     818      for Y := 0 to 4 do
     819        if AreaCount[X, Y] > 0 then
     820        begin
     821          if (AreaCount[(X + 1) mod 8, Y] > 0) and
     822            (Continent[RareByArea[X, Y]] = Continent
     823            [RareByArea[(X + 1) mod 8, Y]]) then
    823824          begin
    824             inc(RareAdjacent[x, y]);
    825             inc(RareAdjacent[(x + 1) mod 8, y]);
     825            Inc(RareAdjacent[X, Y]);
     826            Inc(RareAdjacent[(X + 1) mod 8, Y]);
    826827          end;
    827           if y < 4 then
     828          if Y < 4 then
    828829          begin
    829             if (AreaCount[x, y + 1] > 0) and
    830               (Continent[RareByArea[x, y]] = Continent[RareByArea[x, y + 1]])
     830            if (AreaCount[X, Y + 1] > 0) and
     831              (Continent[RareByArea[X, Y]] = Continent[RareByArea[X, Y + 1]])
    831832            then
    832833            begin
    833               inc(RareAdjacent[x, y]);
    834               inc(RareAdjacent[x, y + 1]);
     834              Inc(RareAdjacent[X, Y]);
     835              Inc(RareAdjacent[X, Y + 1]);
    835836            end;
    836             if (AreaCount[(x + 1) mod 8, y + 1] > 0) and
    837               (Continent[RareByArea[x, y]] = Continent[RareByArea[(x + 1) mod 8,
    838               y + 1]]) then
     837            if (AreaCount[(X + 1) mod 8, Y + 1] > 0) and
     838              (Continent[RareByArea[X, Y]] = Continent[RareByArea[(X + 1) mod 8,
     839              Y + 1]]) then
    839840            begin
    840               inc(RareAdjacent[x, y]);
    841               inc(RareAdjacent[(x + 1) mod 8, y + 1]);
     841              Inc(RareAdjacent[X, Y]);
     842              Inc(RareAdjacent[(X + 1) mod 8, Y + 1]);
    842843            end;
    843             if (AreaCount[(x + 7) mod 8, y + 1] > 0) and
    844               (Continent[RareByArea[x, y]] = Continent[RareByArea[(x + 7) mod 8,
    845               y + 1]]) then
     844            if (AreaCount[(X + 7) mod 8, Y + 1] > 0) and
     845              (Continent[RareByArea[X, Y]] = Continent[RareByArea[(X + 7) mod 8,
     846              Y + 1]]) then
    846847            begin
    847               inc(RareAdjacent[x, y]);
    848               inc(RareAdjacent[(x + 7) mod 8, y + 1]);
     848              Inc(RareAdjacent[X, Y]);
     849              Inc(RareAdjacent[(X + 7) mod 8, Y + 1]);
    849850            end;
    850           end
     851          end;
    851852        end;
    852853    xworst := 0;
    853854    yworst := 0;
    854855    Cnt := 0;
    855     for x := 0 to 7 do
    856       for y := 0 to 4 do
    857         if AreaCount[x, y] > 0 then
    858         begin
    859           if (Cnt = 0) or (RareAdjacent[x, y] > RareAdjacent[xworst, yworst])
     856    for X := 0 to 7 do
     857      for Y := 0 to 4 do
     858        if AreaCount[X, Y] > 0 then
     859        begin
     860          if (Cnt = 0) or (RareAdjacent[X, Y] > RareAdjacent[xworst, yworst])
    860861          then
    861862          begin
    862             xworst := x;
    863             yworst := y;
    864             Cnt := 1
     863            xworst := X;
     864            yworst := Y;
     865            Cnt := 1;
    865866          end
    866           else if (RareAdjacent[x, y] = RareAdjacent[xworst, yworst]) then
     867          else if (RareAdjacent[X, Y] = RareAdjacent[xworst, yworst]) then
    867868          begin
    868             inc(Cnt);
     869            Inc(Cnt);
    869870            if DelphiRandom(Cnt) = 0 then
    870871            begin
    871               xworst := x;
    872               yworst := y;
    873             end
     872              xworst := X;
     873              yworst := Y;
     874            end;
    874875          end;
    875876        end;
    876877    AreaCount[xworst, yworst] := 0;
    877     dec(totalrare)
     878    Dec(totalrare);
    878879  end;
    879880
    880881  Cnt := 0;
    881   for x := 0 to 7 do
    882     for y := 0 to 4 do
    883       if AreaCount[x, y] > 0 then
    884       begin
    885         RareLoc[Cnt] := RareByArea[x, y];
    886         inc(Cnt)
    887       end;
    888   for i := 0 to 11 do
    889   begin
    890     RealMap[RareLoc[i]] := RealMap[RareLoc[i]] and not(fTerrain or fSpecial) or
     882  for X := 0 to 7 do
     883    for Y := 0 to 4 do
     884      if AreaCount[X, Y] > 0 then
     885      begin
     886        RareLoc[Cnt] := RareByArea[X, Y];
     887        Inc(Cnt);
     888      end;
     889  for I := 0 to 11 do
     890  begin
     891    RealMap[RareLoc[I]] := RealMap[RareLoc[I]] and not(fTerrain or fSpecial) or
    891892      (fDesert or fDeadLands);
    892893    for dy := -1 to 1 do
     
    894895        if (dx + dy) and 1 = 0 then
    895896        begin
    896           Loc1 := dLoc(RareLoc[i], dx, dy);
     897          Loc1 := dLoc(RareLoc[I], dx, dy);
    897898          if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain = fMountains) then
    898899            RealMap[Loc1] := RealMap[Loc1] and not fTerrain or fHills;
    899         end
    900   end;
    901   for i := 0 to 11 do
    902     for j := 0 to 11 do
    903       Dist[i, j] := Distance(RareLoc[i], RareLoc[j]);
     900        end;
     901  end;
     902  for I := 0 to 11 do
     903    for J := 0 to 11 do
     904      Dist[I, J] := Distance(RareLoc[I], RareLoc[J]);
    904905
    905906  ibest := 0;
     
    909910  begin
    910911    Cnt := 0;
    911     for i := 0 to 11 do
    912       if RareLoc[i] >= 0 then
    913         for j := 0 to 11 do
    914           if RareLoc[j] >= 0 then
     912    for I := 0 to 11 do
     913      if RareLoc[I] >= 0 then
     914        for J := 0 to 11 do
     915          if RareLoc[J] >= 0 then
    915916            if (Cnt > 0) and (Dist[iBest, jbest] >= MinDist) then
    916917            begin
    917               if Dist[i, j] >= MinDist then
     918              if Dist[I, J] >= MinDist then
    918919              begin
    919                 inc(Cnt);
     920                Inc(Cnt);
    920921                if DelphiRandom(Cnt) = 0 then
    921922                begin
    922                   iBest := i;
    923                   jbest := j
    924                 end
    925               end
     923                  iBest := I;
     924                  jbest := J;
     925                end;
     926              end;
    926927            end
    927             else if (Cnt = 0) or (Dist[i, j] > Dist[iBest, jbest]) then
     928            else if (Cnt = 0) or (Dist[I, J] > Dist[iBest, jbest]) then
    928929            begin
    929               iBest := i;
    930               jbest := j;
     930              iBest := I;
     931              jbest := J;
    931932              Cnt := 1;
    932933            end;
     
    938939    RareLoc[jbest] := -1;
    939940  end;
    940 end; // RarePositions
    941 
    942 function CheckShore(Loc: integer): boolean;
    943 var
    944   Loc1, OldTile, V21: integer;
     941end;
     942
     943function CheckShore(Loc: Integer): Boolean;
     944var
     945  Loc1, OldTile, V21: Integer;
    945946  Radius: TVicinity21Loc;
    946947begin
    947   result := false;
     948  Result := False;
    948949  OldTile := RealMap[Loc];
    949950  if OldTile and fTerrain < fGrass then
     
    960961    end;
    961962    if (RealMap[Loc] xor Cardinal(OldTile)) and fTerrain <> 0 then
    962       result := true;
    963   end;
    964 end;
    965 
    966 function ActualSpecialTile(Loc: integer): Cardinal;
    967 begin
    968   result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx);
    969 end;
    970 
    971 procedure CreateMap(preview: boolean);
     963      Result := True;
     964  end;
     965end;
     966
     967function ActualSpecialTile(Loc: Integer): Cardinal;
     968begin
     969  Result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx);
     970end;
     971
     972procedure CreateMap(preview: Boolean);
    972973const
    973974  ShHiHills = 6; { of land }
     
    980981  hotunification = 50; // min. 25
    981982
    982   Zone: array [0 .. 3, 2 .. 9] of single = { terrain distribution }
     983  Zone: array [0 .. 3, 2 .. 9] of Single = { terrain distribution }
    983984    ((0.25, 0, 0, 0.4, 0, 0, 0, 0.35), (0.55, 0, 0.1, 0, 0, 0, 0, 0.35),
    984985    (0.4, 0, 0.35, 0, 0, 0, 0, 0.25), (0, 0.7, 0, 0, 0, 0, 0, 0.3));
    985986  { Grs  Dst  Pra  Tun  - - - For }
    986987
    987   function RndLow(y: integer): Cardinal;
     988  function RndLow(Y: Integer): Cardinal;
    988989  { random lowland appropriate to climate }
    989990  var
    990     z0, i: integer;
    991     p, p0, ZPlus: single;
    992   begin
    993     if ly - 1 - y > y then
    994     begin
    995       z0 := 6 * y div ly;
    996       ZPlus := 6 * y / ly - z0;
     991    z0, I: Integer;
     992    P, p0, ZPlus: Single;
     993  begin
     994    if ly - 1 - Y > Y then
     995    begin
     996      z0 := 6 * Y div ly;
     997      ZPlus := 6 * Y / ly - z0;
    997998    end
    998999    else
    9991000    begin
    1000       z0 := 6 * (ly - 1 - y) div ly;
    1001       ZPlus := 6 * (ly - 1 - y) / ly - z0;
     1001      z0 := 6 * (ly - 1 - Y) div ly;
     1002      ZPlus := 6 * (ly - 1 - Y) / ly - z0;
    10021003    end;
    10031004    p0 := 1;
    1004     for i := 2 to 9 do
    1005     begin
    1006       p := Zone[z0, i] * (1 - ZPlus) + Zone[z0 + 1, i] * ZPlus;
     1005    for I := 2 to 9 do
     1006    begin
     1007      P := Zone[z0, I] * (1 - ZPlus) + Zone[z0 + 1, I] * ZPlus;
    10071008      { weight between zones z0 and z0+1 }
    1008       if DelphiRandom * p0 < p then
    1009       begin
    1010         RndLow := i;
     1009      if DelphiRandom * p0 < P then
     1010      begin
     1011        RndLow := I;
    10111012        Break;
    10121013      end;
    1013       p0 := p0 - p;
    1014     end;
    1015   end;
    1016 
    1017   function RunRiver(Loc0: integer): integer;
     1014      p0 := p0 - P;
     1015    end;
     1016  end;
     1017
     1018  function RunRiver(Loc0: Integer): Integer;
    10181019  { runs river from start point Loc0; return value: length }
    10191020  var
    1020     Dir, T, Loc, Loc1, Cost: integer;
     1021    Dir, T, Loc, Loc1, Cost: Integer;
    10211022    Q: TIPQ;
    1022     From: array [0 .. lxmax * lymax - 1] of integer;
    1023     Time: array [0 .. lxmax * lymax - 1] of integer;
    1024     OneTileLake: boolean;
     1023    From: array [0 .. lxmax * lymax - 1] of Integer;
     1024    Time: array [0 .. lxmax * lymax - 1] of Integer;
     1025    OneTileLake: Boolean;
    10251026  begin
    10261027    FillChar(Time, SizeOf(Time), 255); { -1 }
     
    10311032      if (RealMap[Loc] and fTerrain < fGrass) then
    10321033      begin
    1033         OneTileLake := true;
     1034        OneTileLake := True;
    10341035        for Dir := 0 to 3 do
    10351036        begin
    10361037          Loc1 := dLoc(Loc, Dir and 1 * 2 - 1, Dir shr 1 * 2 - 1);
    10371038          if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain < fGrass) then
    1038             OneTileLake := false;
     1039            OneTileLake := False;
    10391040        end;
    10401041        if not OneTileLake then
     
    10611062    end;
    10621063    Loc1 := Loc;
    1063     result := 0;
     1064    Result := 0;
    10641065    while Loc <> Loc0 do
    10651066    begin
    10661067      Loc := From[Loc];
    1067       inc(result);
    1068     end;
    1069     if (result > 1) and ((result >= MinRivLen) or
     1068      Inc(Result);
     1069    end;
     1070    if (Result > 1) and ((Result >= MinRivLen) or
    10701071      (RealMap[Loc1] and fTerrain >= fGrass)) then
    10711072    begin
     
    10811082    end
    10821083    else
    1083       result := 0;
     1084      Result := 0;
    10841085    FreeAndNil(Q);
    10851086  end;
    10861087
    10871088var
    1088   x, y, n, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: integer;
    1089   CopyFrom: array [0 .. lxmax * lymax - 1] of integer;
     1089  X, Y, N, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: Integer;
     1090  CopyFrom: array [0 .. lxmax * lymax - 1] of Integer;
    10901091  Adjacent: TVicinity8Loc;
    10911092
     
    10961097  while plus < MapSize * LandMass * ShMountains div 10000 do
    10971098  begin
    1098     dec(bMountains);
    1099     inc(plus, ElCount[bMountains])
     1099    Dec(bMountains);
     1100    Inc(plus, ElCount[bMountains]);
    11001101  end;
    11011102  Count := plus;
     
    11041105  while plus < MapSize * LandMass * ShHiHills div 10000 do
    11051106  begin
    1106     dec(bHills);
    1107     inc(plus, ElCount[bHills])
    1108   end;
    1109   inc(Count, plus);
     1107    Dec(bHills);
     1108    Inc(plus, ElCount[bHills]);
     1109  end;
     1110  Inc(Count, plus);
    11101111  bLand := bHills;
    11111112  while Count < MapSize * LandMass div 100 do
    11121113  begin
    1113     dec(bLand);
    1114     inc(Count, ElCount[bLand])
     1114    Dec(bLand);
     1115    Inc(Count, ElCount[bLand]);
    11151116  end;
    11161117
     
    11351136          (RealMap[Loc1] and fTerrain < fGrass) or
    11361137          (RealMap[Loc1] and fTerrain = fArctic) then
    1137           inc(Count); // count adjacent water
     1138          Inc(Count); // count adjacent water
    11381139      end;
    11391140      if Count = 8 then
    1140         RealMap[Loc0] := fOcean
     1141        RealMap[Loc0] := fOcean;
    11411142    end;
    11421143
     
    11471148      plus := MapSize;
    11481149    Loc0 := DelphiRandom(MapSize);
    1149     for n := 0 to plus - 1 do
     1150    for N := 0 to plus - 1 do
    11501151    begin
    11511152      if (RealMap[Loc0] and fTerrain >= fGrass) and (Loc0 >= lx) and
     
    11641165    CopyFrom[Loc0] := Loc0;
    11651166
    1166   for n := 0 to unification * MapSize div 100 do
    1167   begin
    1168     y := DelphiRandom(ly);
    1169     if abs(y - (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then
    1170       if y < ly shr 1 then
    1171         y := ly shr 1 - y
     1167  for N := 0 to unification * MapSize div 100 do
     1168  begin
     1169    Y := DelphiRandom(ly);
     1170    if abs(Y - (ly shr 1)) > ly div 4 + DelphiRandom(ly * hotunification div 100) then
     1171      if Y < ly shr 1 then
     1172        Y := ly shr 1 - Y
    11721173      else
    1173         y := 3 * ly shr 1 - y;
    1174     Loc0 := lx * y + DelphiRandom(lx);
     1174        Y := 3 * ly shr 1 - Y;
     1175    Loc0 := lx * Y + DelphiRandom(lx);
    11751176    if RealMap[Loc0] and fTerrain = fGrass then
    11761177    begin
     
    12021203        Loc1 := CopyFrom[Loc1];
    12031204      RealMap[Loc0] := RealMap[Loc0] and not fTerrain or
    1204         RealMap[Loc1] and fTerrain
     1205        RealMap[Loc1] and fTerrain;
    12051206    end;
    12061207
     
    12251226          if Loc1 >= 0 then
    12261227            if RealMap[Loc1] and fTerrain < fGrass then
    1227               inc(Count, 2)
     1228              Inc(Count, 2);
    12281229        end;
    12291230      end;
    12301231      if Count >= 4 then
    1231         RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie
     1232        RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie;
    12321233    end;
    12331234
     
    12411242        if Loc1 >= 0 then
    12421243          if RealMap[Loc1] and fTerrain <> fDesert then
    1243             inc(Count)
     1244            Inc(Count);
    12441245      end;
    12451246      if Count >= 4 then
    1246         RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie
     1247        RealMap[Loc0] := RealMap[Loc0] and not fTerrain or fPrairie;
    12471248    end;
    12481249
    12491250  for Loc0 := 0 to MapSize - 1 do
    12501251    CheckShore(Loc0); // change ocean to shore
    1251   for x := 0 to lx - 1 do
    1252   begin
    1253     RealMap[x + lx * 0] := fArctic;
    1254     if RealMap[x + lx * 1] >= fGrass then
    1255       RealMap[x + lx * 1] := RealMap[x + lx * 1] and not fTerrain or fTundra;
    1256     if RealMap[x + lx * (ly - 2)] >= fGrass then
    1257       RealMap[x + lx * (ly - 2)] := RealMap[x + lx * (ly - 2)] and
     1252  for X := 0 to lx - 1 do
     1253  begin
     1254    RealMap[X + lx * 0] := fArctic;
     1255    if RealMap[X + lx * 1] >= fGrass then
     1256      RealMap[X + lx * 1] := RealMap[X + lx * 1] and not fTerrain or fTundra;
     1257    if RealMap[X + lx * (ly - 2)] >= fGrass then
     1258      RealMap[X + lx * (ly - 2)] := RealMap[X + lx * (ly - 2)] and
    12581259        not fTerrain or fTundra;
    1259     RealMap[x + lx * (ly - 1)] := fArctic
     1260    RealMap[X + lx * (ly - 1)] := fArctic;
    12601261  end;
    12611262
     
    12781279  CountGood: (cgBest, cgFlat, cgLand);
    12791280
    1280   function IsGoodTile(Loc: integer): boolean;
     1281  function IsGoodTile(Loc: Integer): Boolean;
    12811282  var
    1282     xLoc, yLoc: integer;
     1283    xLoc, yLoc: Integer;
    12831284  begin
    12841285    xLoc := Loc mod lx;
    12851286    yLoc := Loc div lx;
    12861287    if RealMap[Loc] and fDeadLands <> 0 then
    1287       result := false
     1288      Result := False
    12881289    else
    12891290      case CountGood of
    12901291        cgBest:
    1291           result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
     1292          Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
    12921293            fSwamp, fForest]) and Odd((lymax + xLoc - yLoc shr 1) shr 1 + xLoc +
    12931294            (yLoc + 1) shr 1);
    12941295        cgFlat:
    1295           result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
     1296          Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
    12961297            fSwamp, fForest]);
    12971298        cgLand:
    1298           result := RealMap[Loc] and fTerrain >= fGrass;
     1299          Result := RealMap[Loc] and fTerrain >= fGrass;
    12991300      end;
    13001301  end;
     
    13041305
    13051306var
    1306   p1, p2, nAlive, c, Loc, Loc1, CntGood, CntGoodGrass, MinDist, i, j, n,
     1307  p1, p2, nAlive, C, Loc, Loc1, CntGood, CntGoodGrass, MinDist, I, J, N,
    13071308    nsc, V21, V8, BestDist, TestDist, MinGood, nIrrLoc,
    1308     FineDistSQR, nRest: integer;
    1309   ccount: array [0 .. lxmax * lymax - 1] of word;
    1310   sc, StartLoc0, sccount: array [1 .. nPl] of integer;
    1311   TestStartLoc: array [0 .. nPl - 1] of integer;
    1312   CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of integer;
    1313   nCityLoc: array [1 .. nPl] of integer;
    1314   RestLoc: array [0 .. MaxCityLoc - 1] of integer;
    1315   IrrLoc: array [0 .. 20] of integer;
     1309    FineDistSQR, nRest: Integer;
     1310  ccount: array [0 .. lxmax * lymax - 1] of Word;
     1311  sc, StartLoc0, sccount: array [1 .. nPl] of Integer;
     1312  TestStartLoc: array [0 .. nPl - 1] of Integer;
     1313  CityLoc: array [1 .. nPl, 0 .. MaxCityLoc - 1] of Integer;
     1314  nCityLoc: array [1 .. nPl] of Integer;
     1315  RestLoc: array [0 .. MaxCityLoc - 1] of Integer;
     1316  IrrLoc: array [0 .. 20] of Integer;
    13161317  Radius: TVicinity21Loc;
    13171318  Adjacent: TVicinity8Loc;
    1318   ok: boolean;
     1319  ok: Boolean;
    13191320
    13201321begin
     
    13221323  for p1 := 0 to nPl - 1 do
    13231324    if 1 shl p1 and GAlive <> 0 then
    1324       inc(nAlive);
     1325      Inc(nAlive);
    13251326  if nAlive = 0 then
    1326     exit;
     1327    Exit;
    13271328
    13281329  { count good tiles }
     
    13311332    if RealMap[Loc] and fTerrain = fGrass then
    13321333      if ActualSpecialTile(Loc) = 1 then
    1333         inc(ccount[Continent[Loc]], 3)
     1334        Inc(ccount[Continent[Loc]], 3)
    13341335      else
    1335         inc(ccount[Continent[Loc]], 2)
     1336        Inc(ccount[Continent[Loc]], 2)
    13361337    else if RealMap[Loc] and fTerrain in [fPrairie, fSwamp, fForest, fHills]
    13371338    then
    1338       inc(ccount[Continent[Loc]]);
     1339      Inc(ccount[Continent[Loc]]);
    13391340
    13401341  Loc := 0;
    13411342  while ccount[Loc] > 0 do
    1342     inc(Loc);
    1343   for i := 1 to nAlive do
    1344   begin
    1345     sc[i] := Loc;
    1346     sccount[i] := 1
     1343    Inc(Loc);
     1344  for I := 1 to nAlive do
     1345  begin
     1346    sc[I] := Loc;
     1347    sccount[I] := 1
    13471348  end;
    13481349  { init with zero size start continents, then search bigger ones }
     
    13551356        if p1 < nAlive + 1 then
    13561357          sc[p1] := sc[p1 - 1];
    1357         dec(p1)
     1358        Dec(p1);
    13581359      end;
    13591360      if p1 < nAlive + 1 then
     
    13621363  nsc := nAlive;
    13631364  repeat
    1364     c := 1; // search least crowded continent after smallest
    1365     for i := 2 to nsc - 1 do
    1366       if ccount[sc[i]] * (2 * sccount[c] + 1) > ccount[sc[c]] *
    1367         (2 * sccount[i] + 1) then
    1368         c := i;
    1369     if ccount[sc[nsc]] * (2 * sccount[c] + 1) > ccount[sc[c]] then
     1365    C := 1; // search least crowded continent after smallest
     1366    for I := 2 to nsc - 1 do
     1367      if ccount[sc[I]] * (2 * sccount[C] + 1) > ccount[sc[C]] *
     1368        (2 * sccount[I] + 1) then
     1369        C := I;
     1370    if ccount[sc[nsc]] * (2 * sccount[C] + 1) > ccount[sc[C]] then
    13701371      Break; // even least crowded continent is more crowded than smallest
    1371     inc(sccount[c]);
    1372     dec(nsc)
     1372    Inc(sccount[C]);
     1373    Dec(nsc);
    13731374  until sccount[nsc] > 1;
    13741375
     
    13761377  CountGood := cgBest;
    13771378  repeat
    1378     dec(MinGood);
     1379    Dec(MinGood);
    13791380    if (MinGood = 3) and (CountGood < cgLand) then // too demanding!
    13801381    begin
    1381       inc(CountGood);
    1382       MinGood := 6
     1382      Inc(CountGood);
     1383      MinGood := 6;
    13831384    end;
    13841385    FillChar(nCityLoc, SizeOf(nCityLoc), 0);
    13851386    Loc := DelphiRandom(MapSize);
    1386     for i := 0 to MapSize - 1 do
     1387    for I := 0 to MapSize - 1 do
    13871388    begin
    13881389      if ((Loc >= 4 * lx) and (Loc < MapSize - 4 * lx) or (CountGood >= cgLand))
    13891390        and IsGoodTile(Loc) then
    13901391      begin
    1391         c := nsc;
    1392         while (c > 0) and (Continent[Loc] <> sc[c]) do
    1393           dec(c);
    1394         if (c > 0) and (nCityLoc[c] < MaxCityLoc) then
     1392        C := nsc;
     1393        while (C > 0) and (Continent[Loc] <> sc[C]) do
     1394          Dec(C);
     1395        if (C > 0) and (nCityLoc[C] < MaxCityLoc) then
    13951396        begin
    13961397          CntGood := 1;
     
    14011402              Loc1 := Radius[V21];
    14021403              if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then
    1403                 inc(CntGood)
     1404                Inc(CntGood);
    14041405            end;
    14051406          if CntGood >= MinGood then
    14061407          begin
    1407             CityLoc[c, nCityLoc[c]] := Loc;
    1408             inc(nCityLoc[c])
     1408            CityLoc[C, nCityLoc[C]] := Loc;
     1409            Inc(nCityLoc[C]);
    14091410          end;
    14101411        end;
     
    14131414    end;
    14141415
    1415     ok := true;
    1416     for c := 1 to nsc do
    1417       if nCityLoc[c] < sccount[c] * (8 - MinGood) div (7 - MinGood) then
    1418         ok := false;
     1416    ok := True;
     1417    for C := 1 to nsc do
     1418      if nCityLoc[C] < sccount[C] * (8 - MinGood) div (7 - MinGood) then
     1419        ok := False;
    14191420  until ok;
    14201421
    14211422  FineDistSQR := MapSize * LandMass * 9 div (nAlive * 100);
    14221423  p1 := 1;
    1423   for c := 1 to nsc do
     1424  for C := 1 to nsc do
    14241425  begin // for all start continents
    1425     if sccount[c] = 1 then
    1426       StartLoc0[p1] := CityLoc[c, DelphiRandom(nCityLoc[c])]
     1426    if sccount[C] = 1 then
     1427      StartLoc0[p1] := CityLoc[C, DelphiRandom(nCityLoc[C])]
    14271428    else
    14281429    begin
    14291430      BestDist := 0;
    1430       n := 1 shl sccount[c] * 32; // number of tries to find good distribution
    1431       if n > 1 shl 12 then
    1432         n := 1 shl 12;
    1433       while (n > 0) and (BestDist * BestDist < FineDistSQR) do
     1431      N := 1 shl sccount[C] * 32; // number of tries to find good distribution
     1432      if N > 1 shl 12 then
     1433        N := 1 shl 12;
     1434      while (N > 0) and (BestDist * BestDist < FineDistSQR) do
    14341435      begin
    14351436        MinDist := MaxInt;
    1436         nRest := nCityLoc[c];
    1437         for i := 0 to nRest - 1 do
    1438           RestLoc[i] := CityLoc[c, i];
    1439         for i := 0 to sccount[c] - 1 do
     1437        nRest := nCityLoc[C];
     1438        for I := 0 to nRest - 1 do
     1439          RestLoc[I] := CityLoc[C, I];
     1440        for I := 0 to sccount[C] - 1 do
    14401441        begin
    14411442          if nRest = 0 then
    14421443            Break;
    1443           j := DelphiRandom(nRest);
    1444           TestStartLoc[i] := RestLoc[j];
    1445           RestLoc[j] := RestLoc[nRest - 1];
    1446           dec(nRest);
    1447           for j := 0 to i - 1 do
     1444          J := DelphiRandom(nRest);
     1445          TestStartLoc[I] := RestLoc[J];
     1446          RestLoc[J] := RestLoc[nRest - 1];
     1447          Dec(nRest);
     1448          for J := 0 to I - 1 do
    14481449          begin
    1449             TestDist := Distance(TestStartLoc[i], TestStartLoc[j]);
     1450            TestDist := Distance(TestStartLoc[I], TestStartLoc[J]);
    14501451            if TestDist < MinDist then
    1451               MinDist := TestDist
     1452              MinDist := TestDist;
    14521453          end;
    1453           if i = sccount[c] - 1 then
     1454          if I = sccount[C] - 1 then
    14541455          begin
    1455             assert(MinDist > BestDist);
     1456            Assert(MinDist > BestDist);
    14561457            BestDist := MinDist;
    1457             for j := 0 to sccount[c] - 1 do
    1458               StartLoc0[p1 + j] := TestStartLoc[j];
     1458            for J := 0 to sccount[C] - 1 do
     1459              StartLoc0[p1 + J] := TestStartLoc[J];
    14591460          end
    14601461          else if BestDist > 0 then
    14611462          begin
    1462             j := 0;
    1463             while j < nRest do
     1463            J := 0;
     1464            while J < nRest do
    14641465            begin // remove all locs from rest which have too little distance to this one
    1465               TestDist := Distance(TestStartLoc[i], RestLoc[j]);
     1466              TestDist := Distance(TestStartLoc[I], RestLoc[J]);
    14661467              if TestDist <= BestDist then
    14671468              begin
    1468                 RestLoc[j] := RestLoc[nRest - 1];
    1469                 dec(nRest);
     1469                RestLoc[J] := RestLoc[nRest - 1];
     1470                Dec(nRest);
    14701471              end
    14711472              else
    1472                 inc(j);
     1473                Inc(J);
    14731474            end;
    14741475          end;
    14751476        end;
    1476         dec(n)
    1477       end;
    1478     end;
    1479     p1 := p1 + sccount[c]
     1477        Dec(N)
     1478      end;
     1479    end;
     1480    p1 := p1 + sccount[C]
    14801481  end;
    14811482
     
    14941495        if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then
    14951496          if RealMap[Loc1] and fTerrain = fGrass then
    1496             inc(CntGoodGrass)
     1497            Inc(CntGoodGrass)
    14971498          else
    1498             inc(CntGood);
     1499            Inc(CntGood);
    14991500      end;
    15001501    for V21 := 1 to 26 do
     
    15281529        begin
    15291530          IrrLoc[nIrrLoc] := Loc1;
    1530           inc(nIrrLoc);
    1531         end;
    1532       end;
    1533     i := 2;
    1534     if i > nIrrLoc then
    1535       i := nIrrLoc;
    1536     while i > 0 do
    1537     begin
    1538       j := DelphiRandom(nIrrLoc);
    1539       RealMap[IrrLoc[j]] := RealMap[IrrLoc[j]] or tiIrrigation;
    1540       IrrLoc[j] := IrrLoc[nIrrLoc - 1];
    1541       dec(nIrrLoc);
    1542       dec(i);
     1531          Inc(nIrrLoc);
     1532        end;
     1533      end;
     1534    I := 2;
     1535    if I > nIrrLoc then
     1536      I := nIrrLoc;
     1537    while I > 0 do
     1538    begin
     1539      J := DelphiRandom(nIrrLoc);
     1540      RealMap[IrrLoc[J]] := RealMap[IrrLoc[J]] or tiIrrigation;
     1541      IrrLoc[J] := IrrLoc[nIrrLoc - 1];
     1542      Dec(nIrrLoc);
     1543      Dec(I);
    15431544    end;
    15441545  end;
     
    15491550    begin
    15501551      repeat
    1551         i := DelphiRandom(nAlive) + 1
    1552       until StartLoc0[i] >= 0;
    1553       StartLoc[p1] := StartLoc0[i];
    1554       StartLoc0[i] := -1
     1552        I := DelphiRandom(nAlive) + 1
     1553      until StartLoc0[I] >= 0;
     1554      StartLoc[p1] := StartLoc0[I];
     1555      StartLoc0[I] := -1
    15551556    end;
    15561557  SaveMapCenterLoc := StartLoc[0];
     
    15851586          StartLoc2[p1] := Loc1;
    15861587          BestDist := TestDist;
    1587           n := 1;
     1588          N := 1;
    15881589        end
    15891590        else if TestDist = BestDist then
    15901591        begin
    1591           inc(n);
    1592           if DelphiRandom(n) = 0 then
     1592          Inc(N);
     1593          if DelphiRandom(N) = 0 then
    15931594            StartLoc2[p1] := Loc1;
    15941595        end;
    15951596      end;
    15961597    end;
    1597 end; { StartPositions }
    1598 
    1599 procedure PredefinedStartPositions(Human: integer);
     1598end;
     1599
     1600procedure PredefinedStartPositions(Human: Integer);
    16001601// use predefined nation start positions
    16011602var
    1602   i, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: integer;
    1603   StartLoc0: array [0 .. lxmax * lymax - 1] of integer;
    1604   ishuman: boolean;
     1603  I, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: Integer;
     1604  StartLoc0: array [0 .. lxmax * lymax - 1] of Integer;
     1605  ishuman: Boolean;
    16051606begin
    16061607  nAlive := 0;
    16071608  for p1 := 0 to nPl - 1 do
    16081609    if 1 shl p1 and GAlive <> 0 then
    1609       inc(nAlive);
     1610      Inc(nAlive);
    16101611  if nAlive = 0 then
    1611     exit;
     1612    Exit;
    16121613
    16131614  for I := 0 to Length(StartLoc0) - 1 do
     
    16221623      StartLoc0[nStartLoc0] := StartLoc0[nPrefStartLoc0];
    16231624      StartLoc0[nPrefStartLoc0] := Loc1;
    1624       inc(nPrefStartLoc0);
    1625       inc(nStartLoc0);
     1625      Inc(nPrefStartLoc0);
     1626      Inc(nStartLoc0);
    16261627      RealMap[Loc1] := RealMap[Loc1] and not fPrefStartPos;
    16271628    end
     
    16291630    begin
    16301631      StartLoc0[nStartLoc0] := Loc1;
    1631       inc(nStartLoc0);
     1632      Inc(nStartLoc0);
    16321633      RealMap[Loc1] := RealMap[Loc1] and not fStartPos;
    16331634    end;
    1634   assert(nStartLoc0 >= nAlive);
     1635  Assert(nStartLoc0 >= nAlive);
    16351636
    16361637  StartLoc[0] := 0;
    1637   for ishuman := true downto false do
     1638  for ishuman := True downto False do
    16381639    for p1 := 0 to nPl - 1 do
    16391640      if (1 shl p1 and GAlive <> 0) and ((1 shl p1 and Human <> 0) = ishuman)
    16401641      then
    16411642      begin
    1642         dec(nStartLoc0);
     1643        Dec(nStartLoc0);
    16431644        imax := nStartLoc0;
    16441645        if nPrefStartLoc0 > 0 then
    16451646        begin
    1646           dec(nPrefStartLoc0);
     1647          Dec(nPrefStartLoc0);
    16471648          imax := nPrefStartLoc0;
    16481649        end;
    1649         i := DelphiRandom(imax + 1);
    1650         StartLoc[p1] := StartLoc0[i];
    1651         StartLoc2[p1] := StartLoc0[i];
    1652         StartLoc0[i] := StartLoc0[imax];
     1650        I := DelphiRandom(imax + 1);
     1651        StartLoc[p1] := StartLoc0[I];
     1652        StartLoc2[p1] := StartLoc0[I];
     1653        StartLoc0[I] := StartLoc0[imax];
    16531654        StartLoc0[imax] := StartLoc0[nStartLoc0];
    16541655      end;
    16551656  SaveMapCenterLoc := StartLoc[0];
    1656 end; { PredefinedStartPositions }
     1657end;
    16571658
    16581659procedure InitGame;
    16591660var
    1660   i, p, p1, uix, Loc1: integer;
     1661  I, P, p1, uix, Loc1: Integer;
    16611662begin
    16621663  {$IFDEF FastContact}
     
    16701671    if RealMap[Loc1] and fterrain>=fGrass then
    16711672    if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRoad
    1672     else if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRR;
     1673    else if Delphirandom(3)=0 then RealMap[Loc1]:=RealMap[Loc1] or fRR;}
    16731674    {random Road and Railroad }
    16741675  { !!!for Loc1:=0 to MapSize-1 do
     
    16821683  GTestFlags := 0;
    16831684  GInitialized := GAlive or GWatching;
    1684   for p := 0 to nPl - 1 do
    1685     if 1 shl p and GInitialized <> 0 then
    1686       with RW[p] do
    1687       begin
    1688         Researched[p] := 0;
    1689         Discovered[p] := 0;
    1690         TerritoryCount[p] := 0;
    1691         nTech[p] := 0;
    1692         if Difficulty[p] = 0 then
    1693           ResourceMask[p] := $FFFFFFFF
     1685  for P := 0 to nPl - 1 do
     1686    if 1 shl P and GInitialized <> 0 then
     1687      with RW[P] do
     1688      begin
     1689        Researched[P] := 0;
     1690        Discovered[P] := 0;
     1691        TerritoryCount[P] := 0;
     1692        nTech[P] := 0;
     1693        if Difficulty[P] = 0 then
     1694          ResourceMask[P] := $FFFFFFFF
    16941695        else
    1695           ResourceMask[p] := $FFFFFFFF and not(fSpecial2 or fModern);
    1696         GrWallContinent[p] := -1;
     1696          ResourceMask[P] := $FFFFFFFF and not(fSpecial2 or fModern);
     1697        GrWallContinent[P] := -1;
    16971698
    16981699        GetMem(Map, 4 * MapSize);
     
    17121713          if 1 shl p1 and GInitialized <> 0 then
    17131714          begin
    1714             FillChar(RWemix[p, p1], SizeOf(RWemix[p, p1]), 255); { -1 }
    1715             FillChar(Destroyed[p, p1], SizeOf(Destroyed[p, p1]), 0);
     1715            FillChar(RWemix[P, p1], SizeOf(RWemix[P, p1]), 255); { -1 }
     1716            FillChar(Destroyed[P, p1], SizeOf(Destroyed[P, p1]), 0);
    17161717          end;
    17171718          Attitude[p1] := atNeutral;
     
    17211722          Tribute[p1] := 0;
    17221723          TributePaid[p1] := 0;
    1723           if (p1 <> p) and (1 shl p1 and GAlive <> 0) then
     1724          if (p1 <> P) and (1 shl p1 and GAlive <> 0) then
    17241725          begin // initialize enemy report
    17251726            GetMem(EnemyReport[p1], SizeOf(TEnemyReport) - 2 *
     
    17311732            EnemyReport[p1].Attitude := atNeutral;
    17321733            EnemyReport[p1].Government := gDespotism;
    1733             if 1 shl p and GAlive = 0 then
     1734            if 1 shl P and GAlive = 0 then
    17341735              Treaty[p1] := trNone // supervisor
    17351736          end
     
    17531754
    17541755  // create initial models and units
    1755   for p := 0 to nPl - 1 do
    1756     if (1 shl p and GAlive <> 0) then
    1757       with RW[p] do
     1756  for P := 0 to nPl - 1 do
     1757    if (1 shl P and GAlive <> 0) then
     1758      with RW[P] do
    17581759      begin
    17591760        nModel := 0;
    1760         for i := 0 to nSpecialModel - 1 do
    1761           if SpecialModelPreq[i] = preNone then
     1761        for I := 0 to nSpecialModel - 1 do
     1762          if SpecialModelPreq[I] = preNone then
    17621763          begin
    1763             Model[nModel] := SpecialModel[i];
     1764            Model[nModel] := SpecialModel[I];
    17641765            Model[nModel].Status := 0;
    17651766            Model[nModel].IntroTurn := 0;
    17661767            Model[nModel].Built := 0;
    17671768            Model[nModel].Lost := 0;
    1768             Model[nModel].ID := p shl 12 + nModel;
     1769            Model[nModel].ID := P shl 12 + nModel;
    17691770            SetModelFlags(Model[nModel]);
    1770             inc(nModel)
     1771            Inc(nModel);
    17711772          end;
    17721773        nUn := 0;
    1773         UnBuilt[p] := 0;
     1774        UnBuilt[P] := 0;
    17741775        for uix := 0 to nStartUn - 1 do
    17751776        begin
    1776           CreateUnit(p, StartUn[uix]);
    1777           dec(Model[StartUn[uix]].Built);
    1778           Un[uix].Loc := StartLoc2[p];
    1779           PlaceUnit(p, uix);
    1780         end;
    1781         FoundCity(p, StartLoc[p]); // capital
    1782         Founded[p] := 1;
     1777          CreateUnit(P, StartUn[uix]);
     1778          Dec(Model[StartUn[uix]].Built);
     1779          Un[uix].Loc := StartLoc2[P];
     1780          PlaceUnit(P, uix);
     1781        end;
     1782        FoundCity(P, StartLoc[P]); // capital
     1783        Founded[P] := 1;
    17831784        with City[0] do
    17841785        begin
    1785           ID := p shl 12;
     1786          ID := P shl 12;
    17861787          Flags := chFounded;
    17871788        end;
     
    17901791  TerritoryCount[nPl] := MapSize;
    17911792  // fillchar(NewContact, sizeof(NewContact), false);
    1792 end; // InitGame
     1793end;
    17931794
    17941795procedure InitRandomGame;
     
    17971798  CalculatePrimitive;
    17981799  CreateElevation;
    1799   CreateMap(false);
     1800  CreateMap(False);
    18001801  StartPositions;
    18011802  InitGame;
    18021803end;
    18031804
    1804 procedure InitMapGame(Human: integer);
     1805procedure InitMapGame(Human: Integer);
    18051806begin
    18061807  DelphiRandSeed := RND;
     
    18121813procedure ReleaseGame;
    18131814var
    1814   p1, p2: integer;
     1815  p1, p2: Integer;
    18151816begin
    18161817  for p1 := 0 to nPl - 1 do
     
    18341835procedure InitMapEditor;
    18351836var
    1836   p1: integer;
     1837  p1: Integer;
    18371838begin
    18381839  CalculatePrimitive;
     
    18711872end;
    18721873
    1873 procedure EditTile(Loc, NewTile: integer);
    1874 var
    1875   Loc1, V21: integer;
     1874procedure EditTile(Loc, NewTile: Integer);
     1875var
     1876  Loc1, V21: Integer;
    18761877  Radius: TVicinity21Loc;
    18771878begin
     
    18971898    if (NewTile and fTerImp = tiIrrigation) or (NewTile and fTerImp = tiFarm)
    18981899    then
    1899       NewTile := NewTile and not fTerImp
     1900      NewTile := NewTile and not fTerImp;
    19001901  end;
    19011902  if (Terrain[NewTile and fTerrain].MineEff = 0) and
     
    19211922      RealMap[Loc1] := RealMap[Loc1] or ($F shl 27);
    19221923      RW[0].Map[Loc1] := RealMap[Loc1] and $07FFFFFF or fObserved;
    1923     end
     1924    end;
    19241925  end;
    19251926  // RealMap[Loc]:=RealMap[Loc] and not fSpecial;
     
    19311932  ____________________________________________________________________
    19321933}
    1933 function GetTileInfo(p, cix, Loc: integer; var Info: TTileInfo): integer;
     1934function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer;
    19341935// cix>=0 - known city index of player p -- only core internal!
    19351936// cix=-1 - search city, player unknown, only if permission for p
    19361937// cix=-2 - don't search city, don't calculate city benefits, just government of player p
    19371938var
    1938   p0, Tile, special: integer;
     1939  p0, Tile, special: Integer;
    19391940begin
    19401941  with Info do
    19411942  begin
    1942     p0 := p;
     1943    p0 := P;
    19431944    if cix >= 0 then
    19441945      Tile := RealMap[Loc]
    19451946    else
    19461947    begin
    1947       Tile := RW[p].Map[Loc];
     1948      Tile := RW[P].Map[Loc];
    19481949      if Tile and fTerrain = fUNKNOWN then
    19491950      begin
    1950         result := eNoPreq;
    1951         exit;
     1951        Result := eNoPreq;
     1952        Exit;
    19521953      end;
    19531954    end;
     
    19551956    if (cix = -1) and (UsedByCity[Loc] >= 0) then
    19561957    begin // search exploiting player and city
    1957       SearchCity(UsedByCity[Loc], p, cix);
    1958       if not((p = p0) or (ObserveLevel[UsedByCity[Loc]] shr (2 * p0) and
     1958      SearchCity(UsedByCity[Loc], P, cix);
     1959      if not((P = p0) or (ObserveLevel[UsedByCity[Loc]] shr (2 * p0) and
    19591960        3 = lObserveSuper)) then
    19601961        cix := -1
     
    19621963    if cix = -1 then
    19631964    begin
    1964       result := eInvalid;
    1965       exit;
     1965      Result := eInvalid;
     1966      Exit;
    19661967    end; // no city found here
    19671968
    1968     special := Tile and fSpecial and ResourceMask[p] shr 5;
     1969    special := Tile and fSpecial and ResourceMask[P] shr 5;
    19691970    with Terrain[Tile and fTerrain] do
    19701971    begin
     
    19731974      Trade := TradeRes[special];
    19741975      if (special > 0) and (Tile and fTerrain <> fGrass) and
    1975         (RW[p].NatBuilt[imSpacePort] > 0) then
     1976        (RW[P].NatBuilt[imSpacePort] > 0) then
    19761977      begin // GeoSat effect
    19771978        Food := 2 * Food - FoodRes[0];
     
    19821983      if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) or
    19831984        (Tile and fCity <> 0) then
    1984         inc(Food, IrrEff); { irrigation effect }
     1985        Inc(Food, IrrEff); { irrigation effect }
    19851986      if Tile and fTerImp = tiMine then
    1986         inc(Prod, MineEff); { mining effect }
    1987       if (Tile and fRiver <> 0) and (RW[p].Tech[adMapMaking] >= tsApplicable)
     1987        Inc(Prod, MineEff); { mining effect }
     1988      if (Tile and fRiver <> 0) and (RW[P].Tech[adMapMaking] >= tsApplicable)
    19881989      then
    1989         inc(Trade); { river effect }
     1990        Inc(Trade); { river effect }
    19901991      if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and
    1991         (RW[p].Tech[adWheel] >= tsApplicable) then
    1992         inc(Trade); { road effect }
     1992        (RW[P].Tech[adWheel] >= tsApplicable) then
     1993        Inc(Trade); { road effect }
    19931994      if (Tile and (fRR or fCity) <> 0) and
    1994         (RW[p].Tech[adRailroad] >= tsApplicable) then
    1995         inc(Prod, Prod shr 1); { railroad effect }
     1995        (RW[P].Tech[adRailroad] >= tsApplicable) then
     1996        Inc(Prod, Prod shr 1); { railroad effect }
    19961997
    19971998      ExplCity := -1;
    1998       if (cix >= 0) and (p = p0) then
     1999      if (cix >= 0) and (P = p0) then
    19992000        ExplCity := cix;
    20002001      if cix >= 0 then
     
    20022003        begin
    20032004          if ((Tile and fTerImp = tiFarm) or (Tile and fCity <> 0)) and
    2004             (RW[p].City[cix].Built[imSupermarket] > 0) then
    2005             inc(Food, Food shr 1); { farmland effect }
     2005            (RW[P].City[cix].Built[imSupermarket] > 0) then
     2006            Inc(Food, Food shr 1); { farmland effect }
    20062007          if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and
    2007             (RW[p].City[cix].Built[imHighways] > 0) then
    2008             inc(Trade, 1); { superhighway effect }
     2008            (RW[P].City[cix].Built[imHighways] > 0) then
     2009            Inc(Trade, 1); { superhighway effect }
    20092010        end
    20102011        else
    20112012        begin
    2012           if RW[p].City[cix].Built[imHarbor] > 0 then
    2013             inc(Food); { harbour effect }
    2014           if RW[p].City[cix].Built[imPlatform] > 0 then
    2015             inc(Prod); { oil platform effect }
    2016           if GWonder[woLighthouse].EffectiveOwner = p then
    2017             inc(Prod);
     2013          if RW[P].City[cix].Built[imHarbor] > 0 then
     2014            Inc(Food); { harbour effect }
     2015          if RW[P].City[cix].Built[imPlatform] > 0 then
     2016            Inc(Prod); { oil platform effect }
     2017          if GWonder[woLighthouse].EffectiveOwner = P then
     2018            Inc(Prod);
    20182019        end;
    20192020    end;
    20202021
    20212022    { good government influence }
    2022     if (RW[p].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)
     2023    if (RW[P].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)
    20232024    then
    2024       inc(Trade);
    2025     if (RW[p].Government = gCommunism) and (Prod > 1) then
    2026       inc(Prod);
    2027 
    2028     if RW[p].Government in [gAnarchy, gDespotism] then
     2025      Inc(Trade);
     2026    if (RW[P].Government = gCommunism) and (Prod > 1) then
     2027      Inc(Prod);
     2028
     2029    if RW[P].Government in [gAnarchy, gDespotism] then
    20292030    begin { bad government influence }
    20302031      if Food > 3 then
     
    20382039    if Tile and (fTerrain or fPoll) > fPoll then
    20392040    begin { pollution - decrease ressources }
    2040       dec(Food, Food shr 1);
    2041       dec(Prod, Prod shr 1);
    2042       dec(Trade, Trade shr 1);
     2041      Dec(Food, Food shr 1);
     2042      Dec(Prod, Prod shr 1);
     2043      Dec(Trade, Trade shr 1);
    20432044    end;
    20442045
    20452046    if Tile and fCity <> 0 then
    20462047      Trade := 0
    2047     else if (cix >= 0) and (RW[p].City[cix].Built[imCourt] + RW[p].City[cix]
     2048    else if (cix >= 0) and (RW[P].City[cix].Built[imCourt] + RW[P].City[cix]
    20482049      .Built[imPalace] = 0) then
    2049       if RW[p].City[cix].Built[imTownHall] = 0 then
     2050      if RW[P].City[cix].Built[imTownHall] = 0 then
    20502051        Trade := 0
    20512052      else if Trade > 3 then
    20522053        Trade := 3;
    20532054  end;
    2054   result := eOK;
    2055 end; { GetTileInfo }
    2056 
    2057 procedure Strongest(Loc: integer; var uix, Strength, Bonus, Cnt: integer);
     2055  Result := eOK;
     2056end;
     2057
     2058procedure Strongest(Loc: Integer; var uix, Strength, Bonus, Cnt: Integer);
    20582059{ find strongest defender at Loc }
    20592060var
    20602061  Defender, uix1, Det, Cost, TestStrength, TestBonus, TestDet, TestCost,
    2061     Domain: integer;
     2062    Domain: Integer;
    20622063  PUn: ^TUn;
    20632064  PModel: ^TModel;
     
    20772078    if PUn.Loc = Loc then
    20782079    begin
    2079       inc(Cnt);
     2080      Inc(Cnt);
    20802081      if PUn.Master < 0 then
    20812082      begin
     
    20842085          TestBonus := Terrain[RealMap[Loc] and fTerrain].Defense;
    20852086          if RealMap[Loc] and fTerImp = tiFort then
    2086             inc(TestBonus, 4);
     2087            Inc(TestBonus, 4);
    20872088          if PUn.Flags and unFortified <> 0 then
    2088             inc(TestBonus, 2);
     2089            Inc(TestBonus, 2);
    20892090          if (PModel.Kind = mkSpecial_TownGuard) and
    20902091            (RealMap[Loc] and fCity <> 0) then
    2091             inc(TestBonus, 4);
     2092            Inc(TestBonus, 4);
    20922093        end
    20932094        else
    20942095          TestBonus := 4;
    2095         inc(TestBonus, PUn.exp div ExpCost);
     2096        Inc(TestBonus, PUn.exp div ExpCost);
    20962097        TestStrength := PModel.Defense * TestBonus * PUn.Health;
    20972098        if (Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or
     
    21032104        if PModel.Cap[mcStealth] > 0 then
    21042105        else if PModel.Cap[mcSub] > 0 then
    2105           inc(TestDet, 1 shl 28)
     2106          Inc(TestDet, 1 shl 28)
    21062107        else if (Domain = dGround) and (PModel.Cap[mcFanatic] > 0) and
    21072108          not(RW[Defender].Government in [gRepublic, gDemocracy, gFuture]) then
    2108           inc(TestDet, 4 shl 28) // fanatic ground units always defend
     2109          Inc(TestDet, 4 shl 28) // fanatic ground units always defend
    21092110        else if PModel.Flags and mdZOC <> 0 then
    2110           inc(TestDet, 3 shl 28)
     2111          Inc(TestDet, 3 shl 28)
    21112112        else
    2112           inc(TestDet, 2 shl 28);
     2113          Inc(TestDet, 2 shl 28);
    21132114        TestCost := RW[Defender].Model[PUn.mix].Cost;
    21142115        if (TestDet > Det) or (TestDet = Det) and (TestCost < Cost) then
     
    21252126end;
    21262127
    2127 function UnitSpeed(p, mix, Health: integer): integer;
    2128 begin
    2129   with RW[p].Model[mix] do
    2130   begin
    2131     result := Speed;
     2128function UnitSpeed(P, mix, Health: Integer): Integer;
     2129begin
     2130  with RW[P].Model[mix] do
     2131  begin
     2132    Result := Speed;
    21322133    if Domain = dSea then
    21332134    begin
    2134       if GWonder[woMagellan].EffectiveOwner = p then
    2135         inc(result, 200);
     2135      if GWonder[woMagellan].EffectiveOwner = P then
     2136        Inc(Result, 200);
    21362137      if Health < 100 then
    2137         result := ((result - 250) * Health div 5000) * 50 + 250;
    2138     end
    2139   end
    2140 end;
    2141 
    2142 procedure GetUnitReport(p, uix: integer; var UnitReport: TUnitReport);
    2143 var
    2144   TerrOwner: integer;
     2138        Result := ((Result - 250) * Health div 5000) * 50 + 250;
     2139    end;
     2140  end;
     2141end;
     2142
     2143procedure GetUnitReport(P, uix: Integer; var UnitReport: TUnitReport);
     2144var
     2145  TerrOwner: Integer;
    21452146  PModel: ^TModel;
    21462147begin
     
    21482149  UnitReport.ProdSupport := 0;
    21492150  UnitReport.ReportFlags := 0;
    2150   if RW[p].Government <> gAnarchy then
    2151     with RW[p].Un[uix] do
    2152     begin
    2153       PModel := @RW[p].Model[mix];
     2151  if RW[P].Government <> gAnarchy then
     2152    with RW[P].Un[uix] do
     2153    begin
     2154      PModel := @RW[P].Model[mix];
    21542155      if (PModel.Kind = mkSettler)
    21552156      { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } then
    2156         UnitReport.FoodSupport := SettlerFood[RW[p].Government]
     2157        UnitReport.FoodSupport := SettlerFood[RW[P].Government]
    21572158      else if Flags and unConscripts <> 0 then
    21582159        UnitReport.FoodSupport := 1;
    21592160
    2160       if RW[p].Government <> gFundamentalism then
     2161      if RW[P].Government <> gFundamentalism then
    21612162      begin
    21622163        if GTestFlags and tfImmImprove = 0 then
     
    21732174        begin
    21742175          TerrOwner := RealMap[Loc] shr 27;
    2175           case RW[p].Government of
     2176          case RW[P].Government of
    21762177            gRepublic, gFuture:
    2177               if (TerrOwner <> p) and (TerrOwner < nPl) and
    2178                 (RW[p].Treaty[TerrOwner] < trAlliance) then
     2178              if (TerrOwner <> P) and (TerrOwner < nPl) and
     2179                (RW[P].Treaty[TerrOwner] < trAlliance) then
    21792180                UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed;
    21802181            gDemocracy:
    2181               if (TerrOwner >= nPl) or (TerrOwner <> p) and
    2182                 (RW[p].Treaty[TerrOwner] < trAlliance) then
     2182              if (TerrOwner >= nPl) or (TerrOwner <> P) and
     2183                (RW[P].Treaty[TerrOwner] < trAlliance) then
    21832184                UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed;
    21842185          end;
     
    21882189end;
    21892190
    2190 procedure SearchCity(Loc: integer; var p, cix: integer);
     2191procedure SearchCity(Loc: Integer; var P, cix: Integer);
    21912192// set p to supposed owner before call
    21922193var
    2193   i: integer;
     2194  I: Integer;
    21942195begin
    21952196  if RealMap[Loc] < nPl shl 27 then
    2196     p := RealMap[Loc] shr 27;
    2197   for i := 0 to nPl - 1 do
    2198   begin
    2199     if 1 shl p and GAlive <> 0 then
    2200       with RW[p] do
     2197    P := RealMap[Loc] shr 27;
     2198  for I := 0 to nPl - 1 do
     2199  begin
     2200    if 1 shl P and GAlive <> 0 then
     2201      with RW[P] do
    22012202      begin
    22022203        cix := nCity - 1;
    22032204        while (cix >= 0) and (City[cix].Loc <> Loc) do
    2204           dec(cix);
     2205          Dec(cix);
    22052206        if cix >= 0 then
    2206           exit;
    2207       end;
    2208     assert(i < nPl - 1);
    2209     p := (p + 1) mod nPl;
    2210   end;
    2211 end;
    2212 
    2213 procedure MakeCityInfo(p, cix: integer; var ci: TCityInfo);
    2214 begin
    2215   assert((p >= 0) and (p < nPl));
    2216   assert((cix >= 0) and (cix < RW[p].nCity));
    2217   with RW[p].City[cix] do
     2207          Exit;
     2208      end;
     2209    Assert(I < nPl - 1);
     2210    P := (P + 1) mod nPl;
     2211  end;
     2212end;
     2213
     2214procedure MakeCityInfo(P, cix: Integer; var ci: TCityInfo);
     2215begin
     2216  Assert((P >= 0) and (P < nPl));
     2217  Assert((cix >= 0) and (cix < RW[P].nCity));
     2218  with RW[P].City[cix] do
    22182219  begin
    22192220    ci.Loc := Loc;
    22202221    ci.ID := ID;
    2221     ci.Owner := p;
     2222    ci.Owner := P;
    22222223    ci.Size := Size;
    22232224    ci.Flags := 0;
    22242225    if Built[imPalace] > 0 then
    2225       inc(ci.Flags, ciCapital);
    2226     if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[p]) then
    2227       inc(ci.Flags, ciWalled);
     2226      Inc(ci.Flags, ciCapital);
     2227    if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[P]) then
     2228      Inc(ci.Flags, ciWalled);
    22282229    if Built[imCoastalFort] > 0 then
    2229       inc(ci.Flags, ciCoastalFort);
     2230      Inc(ci.Flags, ciCoastalFort);
    22302231    if Built[imMissileBat] > 0 then
    2231       inc(ci.Flags, ciMissileBat);
     2232      Inc(ci.Flags, ciMissileBat);
    22322233    if Built[imBunker] > 0 then
    2233       inc(ci.Flags, ciBunker);
     2234      Inc(ci.Flags, ciBunker);
    22342235    if Built[imSpacePort] > 0 then
    2235       inc(ci.Flags, ciSpacePort);
    2236   end;
    2237 end;
    2238 
    2239 procedure TellAboutModel(p, taOwner, tamix: integer);
    2240 var
    2241   i: integer;
    2242 begin
    2243   if (p = taOwner) or (Mode < moPlaying) then
    2244     exit;
    2245   i := 0;
    2246   while (i < RW[p].nEnemyModel) and ((RW[p].EnemyModel[i].Owner <> taOwner) or
    2247     (RW[p].EnemyModel[i].mix <> tamix)) do
    2248     inc(i);
    2249   if i = RW[p].nEnemyModel then
    2250     IntServer(sIntTellAboutModel + p shl 4, taOwner, tamix, nil^);
    2251 end;
    2252 
    2253 function emixSafe(p, taOwner, tamix: integer): integer;
    2254 begin
    2255   result := RWemix[p, taOwner, tamix];
    2256   if result < 0 then
     2236      Inc(ci.Flags, ciSpacePort);
     2237  end;
     2238end;
     2239
     2240procedure TellAboutModel(P, taOwner, tamix: Integer);
     2241var
     2242  I: Integer;
     2243begin
     2244  if (P = taOwner) or (Mode < moPlaying) then
     2245    Exit;
     2246  I := 0;
     2247  while (I < RW[P].nEnemyModel) and ((RW[P].EnemyModel[I].Owner <> taOwner) or
     2248    (RW[P].EnemyModel[I].mix <> tamix)) do
     2249    Inc(I);
     2250  if I = RW[P].nEnemyModel then
     2251    IntServer(sIntTellAboutModel + P shl 4, taOwner, tamix, nil^);
     2252end;
     2253
     2254function emixSafe(P, taOwner, tamix: Integer): Integer;
     2255begin
     2256  Result := RWemix[P, taOwner, tamix];
     2257  if Result < 0 then
    22572258  begin // sIntTellAboutModel comes too late
    2258     assert(Mode = moMovie);
    2259     result := $FFFF;
    2260   end;
    2261 end;
    2262 
    2263 procedure IntroduceEnemy(p1, p2: integer);
     2259    Assert(Mode = moMovie);
     2260    Result := $FFFF;
     2261  end;
     2262end;
     2263
     2264procedure IntroduceEnemy(p1, p2: Integer);
    22642265begin
    22652266  RW[p1].Treaty[p2] := trNone;
     
    22672268end;
    22682269
    2269 function DiscoverTile(Loc, p, pTell, Level: integer; EnableContact: boolean;
    2270   euix: integer = -2): boolean;
     2270function DiscoverTile(Loc, P, pTell, Level: Integer; EnableContact: Boolean;
     2271  euix: Integer = -2): Boolean;
    22712272// euix = -2: full discover
    22722273// euix = -1: unit and city only, append units in EnemyUn
    22732274// euix >= 0: unit and city only, replace EnemyUn[euix]
    22742275
    2275   procedure SetContact(p1, p2: integer);
     2276  procedure SetContact(p1, p2: Integer);
    22762277  begin
    22772278    if (Mode < moPlaying) or (p1 = p2) or (RW[p1].Treaty[p2] > trNoContact) then
    2278       exit;
     2279      Exit;
    22792280    IntServer(sIntTellAboutNation, p1, p2, nil^);
    22802281    // NewContact[p1,p2]:=true
     
    22822283
    22832284var
    2284   i, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,
    2285     cixFoundCity, MinLevel, Loc1, V8: integer;
     2285  I, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,
     2286    cixFoundCity, MinLevel, Loc1, V8: Integer;
    22862287  Tile, AddFlags: Cardinal;
    22872288  Adjacent: TVicinity8Loc;
     
    22892290  mox: ^TModel;
    22902291begin
    2291   result := false;
     2292  Result := False;
    22922293  with RW[pTell] do
    22932294  begin
     
    23052306        AddFlags := AddFlags or fGrWall;
    23062307      if (Mode = moPlaying) and ((Tile and (nPl shl 27) <> nPl shl 27) and
    2307         (pTell = p)) then
     2308        (pTell = P)) then
    23082309      begin // set fPeace flag?
    23092310        TerrOwner := Tile shr 27;
     
    23142315            (1 shl trPeace or 1 shl TrFriendlyContact) <> 0 then
    23152316            AddFlags := AddFlags or fPeace;
    2316         end
     2317        end;
    23172318      end;
    23182319
     
    23322333          unx := @RW[Occupant[Loc]].Un[uix];
    23332334          mox := @RW[Occupant[Loc]].Model[unx.mix];
    2334           assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));
     2335          Assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));
    23352336          if (mox.Cap[mcStealth] > 0) and (Tile and fCity = 0) and
    23362337            (Tile and fTerImp <> tiBase) then
     
    23482349            begin
    23492350              uix := nEnemyUn;
    2350               inc(nEnemyUn);
    2351               assert(nEnemyUn < neumax);
     2351              Inc(nEnemyUn);
     2352              Assert(nEnemyUn < neumax);
    23522353            end;
    23532354            MakeUnitInfo(Occupant[Loc], unx^, EnemyUn[uix]);
    23542355            if Cnt > 1 then
    23552356              EnemyUn[uix].Flags := EnemyUn[uix].Flags or unMulti;
    2356             if (mox.Flags and mdZOC <> 0) and (pTell = p) and
     2357            if (mox.Flags and mdZOC <> 0) and (pTell = P) and
    23572358              (Treaty[Occupant[Loc]] < trAlliance) then
    23582359            begin // set fInEnemyZoC flags of surrounding tiles
     
    23632364                if (Loc1 >= 0) and (Loc1 < MapSize) then
    23642365                  Map[Loc1] := Map[Loc1] or fInEnemyZoC
    2365               end
     2366              end;
    23662367            end;
    23672368            if EnableContact and (mox.Domain = dGround) then
     
    23732374            end;
    23742375            // Level:=lObserveSuper; // don't discover unit twice
    2375             if (pTell = p) and
     2376            if (pTell = P) and
    23762377              ((Tile and fCity = 0) or (1 shl pTell and GAI <> 0)) then
    2377               result := true;
     2378              Result := True;
    23782379          end
    23792380          else
     
    23972398          while (cixFoundCity >= 0) and
    23982399            (RW[pFoundCity].City[cixFoundCity].Loc <> Loc) do
    2399             dec(cixFoundCity);
    2400           assert(cixFoundCity >= 0);
    2401           i := 0;
    2402           while (i < nEnemyCity) and (EnemyCity[i].Loc <> Loc) do
    2403             inc(i);
    2404           if i = nEnemyCity then
     2400            Dec(cixFoundCity);
     2401          Assert(cixFoundCity >= 0);
     2402          I := 0;
     2403          while (I < nEnemyCity) and (EnemyCity[I].Loc <> Loc) do
     2404            Inc(I);
     2405          if I = nEnemyCity then
    24052406          begin
    2406             inc(nEnemyCity);
    2407             assert(nEnemyCity < necmax);
    2408             EnemyCity[i].Status := 0;
    2409             EnemyCity[i].SavedStatus := 0;
    2410             if pTell = p then
    2411               result := true;
     2407            Inc(nEnemyCity);
     2408            Assert(nEnemyCity < necmax);
     2409            EnemyCity[I].Status := 0;
     2410            EnemyCity[I].SavedStatus := 0;
     2411            if pTell = P then
     2412              Result := True;
    24122413          end;
    2413           MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[i]);
     2414          MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[I]);
    24142415        end;
    24152416      end
     
    24202421
    24212422    if Map[Loc] and fTerrain = fUNKNOWN then
    2422       inc(Discovered[pTell]);
     2423      Inc(Discovered[pTell]);
    24232424    if euix >= -1 then
    24242425      Map[Loc] := Map[Loc] and not(fUnit or fCity or fOwned or fOwnZoCUnit) or
     
    24372438      Cardinal(Level) shl (2 * pTell);
    24382439  end;
    2439 end; // DiscoverTile
    2440 
    2441 function Discover9(Loc, p, Level: integer;
    2442   TellAllied, EnableContact: boolean): boolean;
    2443 var
    2444   V9, Loc1, pTell, OldLevel: integer;
     2440end;
     2441
     2442function Discover9(Loc, P, Level: Integer;
     2443  TellAllied, EnableContact: Boolean): Boolean;
     2444var
     2445  V9, Loc1, pTell, OldLevel: Integer;
    24452446  Radius: TVicinity8Loc;
    24462447begin
    2447   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
    2448   result := false;
     2448  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
     2449  Result := False;
    24492450  V8_to_Loc(Loc, Radius);
    24502451  for V9 := 0 to 8 do
     
    24582459      begin
    24592460        for pTell := 0 to nPl - 1 do
    2460           if (pTell = p) or (1 shl pTell and GAlive <> 0) and
    2461             (RW[p].Treaty[pTell] = trAlliance) then
     2461          if (pTell = P) or (1 shl pTell and GAlive <> 0) and
     2462            (RW[P].Treaty[pTell] = trAlliance) then
    24622463          begin
    24632464            OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3;
    24642465            if Level > OldLevel then
    2465               result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)
    2466                 or result;
     2466              Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact)
     2467                or Result;
    24672468          end;
    24682469      end
    24692470      else
    24702471      begin
    2471         OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;
     2472        OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3;
    24722473        if Level > OldLevel then
    2473           result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;
    2474       end;
    2475   end;
    2476 end;
    2477 
    2478 function Discover21(Loc, p, AdjacentLevel: integer;
    2479   TellAllied, EnableContact: boolean): boolean;
    2480 var
    2481   V21, Loc1, pTell, Level, OldLevel, AdjacentFlags: integer;
     2474          Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result;
     2475      end;
     2476  end;
     2477end;
     2478
     2479function Discover21(Loc, P, AdjacentLevel: Integer;
     2480  TellAllied, EnableContact: Boolean): Boolean;
     2481var
     2482  V21, Loc1, pTell, Level, OldLevel, AdjacentFlags: Integer;
    24822483  Radius: TVicinity21Loc;
    24832484begin
    2484   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
    2485   result := false;
     2485  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
     2486  Result := False;
    24862487  AdjacentFlags := $00267620 shr 1;
    24872488  V21_to_Loc(Loc, Radius);
     
    24982499      begin
    24992500        for pTell := 0 to nPl - 1 do
    2500           if (pTell = p) or (1 shl pTell and GAlive <> 0) and
    2501             (RW[p].Treaty[pTell] = trAlliance) then
     2501          if (pTell = P) or (1 shl pTell and GAlive <> 0) and
     2502            (RW[P].Treaty[pTell] = trAlliance) then
    25022503          begin
    25032504            OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3;
    25042505            if Level > OldLevel then
    2505               result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)
    2506                 or result;
     2506              Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact)
     2507                or Result;
    25072508          end;
    25082509      end
    25092510      else
    25102511      begin
    2511         OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;
     2512        OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3;
    25122513        if Level > OldLevel then
    2513           result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;
     2514          Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result;
    25142515      end;
    25152516    end;
     
    25182519end;
    25192520
    2520 procedure DiscoverAll(p, Level: integer);
     2521procedure DiscoverAll(P, Level: Integer);
    25212522{ player p discovers complete playground (for supervisor) }
    25222523var
    2523   Loc, OldLevel: integer;
    2524 begin
    2525   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
     2524  Loc, OldLevel: Integer;
     2525begin
     2526  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
    25262527  for Loc := 0 to MapSize - 1 do
    25272528  begin
    2528     OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;
     2529    OldLevel := ObserveLevel[Loc] shr (2 * P) and 3;
    25292530    if Level > OldLevel then
    2530       DiscoverTile(Loc, p, p, Level, false);
    2531   end;
    2532 end;
    2533 
    2534 procedure DiscoverViewAreas(p: integer);
    2535 var
    2536   pTell, uix, cix, ecix, Loc, RealOwner: integer;
     2531      DiscoverTile(Loc, P, P, Level, False);
     2532  end;
     2533end;
     2534
     2535procedure DiscoverViewAreas(P: Integer);
     2536var
     2537  pTell, uix, cix, ecix, Loc, RealOwner: Integer;
    25372538  PModel: ^TModel;
    25382539begin // discover unit and city view areas
    25392540  for pTell := 0 to nPl - 1 do
    2540     if (pTell = p) or (RW[p].Treaty[pTell] = trAlliance) then
     2541    if (pTell = P) or (RW[P].Treaty[pTell] = trAlliance) then
    25412542    begin
    25422543      for uix := 0 to RW[pTell].nUn - 1 do
     
    25462547            PModel := @RW[pTell].Model[mix];
    25472548            if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then
    2548               Discover21(Loc, p, lObserveSuper, false, true)
     2549              Discover21(Loc, P, lObserveSuper, False, True)
    25492550            else if (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) or
    25502551              (PModel.Domain = dAir) then
    2551               Discover21(Loc, p, lObserveAll, false, false)
     2552              Discover21(Loc, P, lObserveAll, False, False)
    25522553            else if (RealMap[Loc] and fTerrain = fMountains) or
    25532554              (RealMap[Loc] and fTerImp = tiFort) or
    25542555              (RealMap[Loc] and fTerImp = tiBase) or (PModel.Cap[mcAcademy] > 0)
    25552556            then
    2556               Discover21(Loc, p, lObserveUnhidden, false,
     2557              Discover21(Loc, P, lObserveUnhidden, False,
    25572558                PModel.Domain = dGround)
    25582559            else
    2559               Discover9(Loc, p, lObserveUnhidden, false,
     2560              Discover9(Loc, P, lObserveUnhidden, False,
    25602561                PModel.Domain = dGround);
    25612562          end;
    25622563      for cix := 0 to RW[pTell].nCity - 1 do
    25632564        if RW[pTell].City[cix].Loc >= 0 then
    2564           Discover21(RW[pTell].City[cix].Loc, p, lObserveUnhidden, false, true);
     2565          Discover21(RW[pTell].City[cix].Loc, P, lObserveUnhidden, False, True);
    25652566      for ecix := 0 to RW[pTell].nEnemyCity - 1 do
    25662567      begin // players know territory, so no use in hiding city owner
     
    25742575          begin
    25752576            RW[pTell].EnemyCity[ecix].Loc := -1;
    2576             RW[pTell].Map[Loc] := RW[pTell].Map[Loc] and not fCity
     2577            RW[pTell].Map[Loc] := RW[pTell].Map[Loc] and not fCity;
    25772578          end;
    25782579        end;
     
    25812582end;
    25822583
    2583 function GetUnitStack(p, Loc: integer): integer;
    2584 var
    2585   uix: integer;
     2584function GetUnitStack(P, Loc: Integer): Integer;
     2585var
     2586  uix: Integer;
    25862587  unx: ^TUn;
    25872588begin
    2588   result := 0;
     2589  Result := 0;
    25892590  if Occupant[Loc] < 0 then
    2590     exit;
     2591    Exit;
    25912592  for uix := 0 to RW[Occupant[Loc]].nUn - 1 do
    25922593  begin
     
    25942595    if unx.Loc = Loc then
    25952596    begin
    2596       MakeUnitInfo(Occupant[Loc], unx^, RW[p].EnemyUn[RW[p].nEnemyUn + result]);
    2597       TellAboutModel(p, Occupant[Loc], unx.mix);
    2598       RW[p].EnemyUn[RW[p].nEnemyUn + result].emix :=
    2599         RWemix[p, Occupant[Loc], unx.mix];
    2600       inc(result);
    2601     end;
    2602   end;
    2603 end;
    2604 
    2605 procedure UpdateUnitMap(Loc: integer; CityChange: boolean = false);
     2597      MakeUnitInfo(Occupant[Loc], unx^, RW[P].EnemyUn[RW[P].nEnemyUn + Result]);
     2598      TellAboutModel(P, Occupant[Loc], unx.mix);
     2599      RW[P].EnemyUn[RW[P].nEnemyUn + Result].emix :=
     2600        RWemix[P, Occupant[Loc], unx.mix];
     2601      Inc(Result);
     2602    end;
     2603  end;
     2604end;
     2605
     2606procedure UpdateUnitMap(Loc: Integer; CityChange: Boolean = False);
    26062607// update maps and enemy units of all players after unit change
    26072608var
    2608   p, euix, OldLevel: integer;
     2609  P, euix, OldLevel: Integer;
    26092610  AddFlags, ClearFlags: Cardinal;
    26102611begin
    26112612  if (Mode = moLoading_Fast) and not CityChange then
    2612     exit;
    2613   for p := 0 to nPl - 1 do
    2614     if 1 shl p and (GAlive or GWatching) <> 0 then
    2615     begin
    2616       OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;
     2613    Exit;
     2614  for P := 0 to nPl - 1 do
     2615    if 1 shl P and (GAlive or GWatching) <> 0 then
     2616    begin
     2617      OldLevel := ObserveLevel[Loc] shr (2 * P) and 3;
    26172618      if OldLevel > lNoObserve then
    26182619      begin
    2619         if RW[p].Map[Loc] and (fUnit or fOwned) = fUnit then
     2620        if RW[P].Map[Loc] and (fUnit or fOwned) = fUnit then
    26202621        begin
    26212622          // replace unit located here in EnemyUn
    26222623          // do not just set loc:=-1 because total number would be unlimited
    2623           euix := RW[p].nEnemyUn - 1;
     2624          euix := RW[P].nEnemyUn - 1;
    26242625          while euix >= 0 do
    26252626          begin
    2626             if RW[p].EnemyUn[euix].Loc = Loc then
     2627            if RW[P].EnemyUn[euix].Loc = Loc then
    26272628            begin
    2628               RW[p].EnemyUn[euix].Loc := -1;
     2629              RW[P].EnemyUn[euix].Loc := -1;
    26292630              Break;
    26302631            end;
    2631             dec(euix);
     2632            Dec(euix);
    26322633          end;
    2633           RW[p].Map[Loc] := RW[p].Map[Loc] and not fUnit
     2634          RW[P].Map[Loc] := RW[P].Map[Loc] and not fUnit
    26342635        end
    26352636        else
    26362637        begin // look for empty slot in EnemyUn
    2637           euix := RW[p].nEnemyUn - 1;
    2638           while (euix >= 0) and (RW[p].EnemyUn[euix].Loc >= 0) do
    2639             dec(euix);
     2638          euix := RW[P].nEnemyUn - 1;
     2639          while (euix >= 0) and (RW[P].EnemyUn[euix].Loc >= 0) do
     2640            Dec(euix);
    26402641        end;
    26412642        if (Occupant[Loc] < 0) and not CityChange then
     
    26442645          if RealMap[Loc] and fCity = 0 then
    26452646            ClearFlags := ClearFlags or fOwned;
    2646           RW[p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags;
     2647          RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags;
    26472648        end
    2648         else if (Occupant[Loc] <> p) or CityChange then
     2649        else if (Occupant[Loc] <> P) or CityChange then
    26492650        begin // city or enemy unit update necessary, call DiscoverTile
    2650           ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * p));
    2651           DiscoverTile(Loc, p, p, OldLevel, false, euix);
     2651          ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * P));
     2652          DiscoverTile(Loc, P, P, OldLevel, False, euix);
    26522653        end
    26532654        else { if (Occupant[Loc]=p) and not CityChange then }
     
    26592660          else
    26602661            ClearFlags := ClearFlags or fOwnZoCUnit;
    2661           RW[p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags or AddFlags;
    2662         end;
    2663       end;
    2664     end;
    2665 end;
    2666 
    2667 procedure RecalcV8ZoC(p, Loc: integer);
     2662          RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags or AddFlags;
     2663        end;
     2664      end;
     2665    end;
     2666end;
     2667
     2668procedure RecalcV8ZoC(P, Loc: Integer);
    26682669// recalculate fInEnemyZoC flags around single tile
    26692670var
    2670   V8, V8V8, Loc1, Loc2, p1, ObserveMask: integer;
     2671  V8, V8V8, Loc1, Loc2, p1, ObserveMask: Integer;
    26712672  Tile1: ^Cardinal;
    26722673  Adjacent, AdjacentAdjacent: TVicinity8Loc;
    26732674begin
    26742675  if Mode = moLoading_Fast then
    2675     exit;
    2676   ObserveMask := 3 shl (2 * p);
     2676    Exit;
     2677  ObserveMask := 3 shl (2 * P);
    26772678  V8_to_Loc(Loc, Adjacent);
    26782679  for V8 := 0 to 7 do
     
    26812682    if (Loc1 >= 0) and (Loc1 < MapSize) then
    26822683    begin
    2683       Tile1 := @RW[p].Map[Loc1];
     2684      Tile1 := @RW[P].Map[Loc1];
    26842685      Tile1^ := Tile1^ and not fInEnemyZoC;
    26852686      V8_to_Loc(Loc1, AdjacentAdjacent);
     
    26912692        begin
    26922693          p1 := Occupant[Loc2];
    2693           assert(p1 <> nPl);
    2694           if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then
     2694          Assert(p1 <> nPl);
     2695          if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then
    26952696          begin
    26962697            Tile1^ := Tile1^ or fInEnemyZoC;
    2697             Break
     2698            Break;
    26982699          end;
    26992700        end;
     
    27032704end;
    27042705
    2705 procedure RecalcMapZoC(p: integer);
     2706procedure RecalcMapZoC(P: Integer);
    27062707// recalculate fInEnemyZoC flags for the whole map
    27072708var
    2708   Loc, Loc1, V8, p1, ObserveMask: integer;
     2709  Loc, Loc1, V8, p1, ObserveMask: Integer;
    27092710  Adjacent: TVicinity8Loc;
    27102711begin
    27112712  if Mode = moLoading_Fast then
    2712     exit;
    2713   MaskD(RW[p].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));
    2714   ObserveMask := 3 shl (2 * p);
     2713    Exit;
     2714  MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));
     2715  ObserveMask := 3 shl (2 * P);
    27152716  for Loc := 0 to MapSize - 1 do
    27162717    if (ZoCMap[Loc] > 0) and (ObserveLevel[Loc] and ObserveMask <> 0) then
    27172718    begin
    27182719      p1 := Occupant[Loc];
    2719       assert(p1 <> nPl);
    2720       if (p1 <> p) and (RW[p].Treaty[p1] < trAlliance) then
     2720      Assert(p1 <> nPl);
     2721      if (p1 <> P) and (RW[P].Treaty[p1] < trAlliance) then
    27212722      begin // this non-allied enemy ZoC unit is known to this player -- set flags!
    27222723        V8_to_Loc(Loc, Adjacent);
     
    27252726          Loc1 := Adjacent[V8];
    27262727          if (Loc1 >= 0) and (Loc1 < MapSize) then
    2727             RW[p].Map[Loc1] := RW[p].Map[Loc1] or fInEnemyZoC
    2728         end;
    2729       end;
    2730     end;
    2731 end;
    2732 
    2733 procedure RecalcPeaceMap(p: integer);
     2728            RW[P].Map[Loc1] := RW[P].Map[Loc1] or fInEnemyZoC;
     2729        end;
     2730      end;
     2731    end;
     2732end;
     2733
     2734procedure RecalcPeaceMap(P: Integer);
    27342735// recalculate fPeace flags for the whole map
    27352736var
    2736   Loc, p1: integer;
    2737   PeacePlayer: array [-1 .. nPl - 1] of boolean;
     2737  Loc, p1: Integer;
     2738  PeacePlayer: array [-1 .. nPl - 1] of Boolean;
    27382739begin
    27392740  if Mode <> moPlaying then
    2740     exit;
    2741   MaskD(RW[p].Map^, MapSize, Cardinal(not Cardinal(fPeace)));
     2741    Exit;
     2742  MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fPeace)));
    27422743  for p1 := -1 to nPl - 1 do
    2743     PeacePlayer[p1] := (p1 >= 0) and (p1 <> p) and (1 shl p1 and GAlive <> 0)
    2744       and (RW[p].Treaty[p1] in [trPeace, TrFriendlyContact]);
     2744    PeacePlayer[p1] := (p1 >= 0) and (p1 <> P) and (1 shl p1 and GAlive <> 0)
     2745      and (RW[P].Treaty[p1] in [trPeace, TrFriendlyContact]);
    27452746  for Loc := 0 to MapSize - 1 do
    2746     if PeacePlayer[RW[p].Territory[Loc]] then
    2747       RW[p].Map[Loc] := RW[p].Map[Loc] or fPeace;
     2747    if PeacePlayer[RW[P].Territory[Loc]] then
     2748      RW[P].Map[Loc] := RW[P].Map[Loc] or fPeace;
    27482749end;
    27492750
     
    27552756  BorderChanges: array [0 .. sIntExpandTerritory and $F - 1] of Cardinal;
    27562757
    2757 procedure ChangeTerritory(Loc, p: integer);
    2758 var
    2759   p1: integer;
    2760 begin
    2761   Assert(p >= 0); // no player's territory indicated by p=nPl
     2758procedure ChangeTerritory(Loc, P: Integer);
     2759var
     2760  p1: Integer;
     2761begin
     2762  Assert(P >= 0); // no player's territory indicated by p=nPl
    27622763  Dec(TerritoryCount[RealMap[Loc] shr 27]);
    2763   Inc(TerritoryCount[p]);
    2764   RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal(p) shl 27;
    2765   if p = $F then
    2766     p := -1;
     2764  Inc(TerritoryCount[P]);
     2765  RealMap[Loc] := RealMap[Loc] and not($F shl 27) or Cardinal(P) shl 27;
     2766  if P = $F then
     2767    P := -1;
    27672768  for p1 := 0 to nPl - 1 do
    27682769    if 1 shl p1 and (GAlive or GWatching) <> 0 then
    27692770      if RW[p1].Map[Loc] and fTerrain <> fUNKNOWN then
    27702771      begin
    2771         RW[p1].Territory[Loc] := p;
    2772         if (p < nPl) and (p <> p1) and (1 shl p and GAlive <> 0) and
    2773           (RW[p1].Treaty[p] in [trPeace, TrFriendlyContact]) then
     2772        RW[p1].Territory[Loc] := P;
     2773        if (P < nPl) and (P <> p1) and (1 shl P and GAlive <> 0) and
     2774          (RW[p1].Treaty[P] in [trPeace, TrFriendlyContact]) then
    27742775          RW[p1].Map[Loc] := RW[p1].Map[Loc] or fPeace
    27752776        else
     
    27782779end;
    27792780
    2780 procedure ExpandTerritory(OriginLoc: integer);
    2781 var
    2782   i, dx, dy, dxMax, dyMax, Loc, NewOwner: integer;
     2781procedure ExpandTerritory(OriginLoc: Integer);
     2782var
     2783  I, dx, dy, dxMax, dyMax, Loc, NewOwner: Integer;
    27832784begin
    27842785  if OriginLoc = -1 then
    27852786    raise Exception.Create('Location error');
    2786   i := 0;
     2787  I := 0;
    27872788  dyMax := 0;
    27882789  while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do
    2789     inc(dyMax);
     2790    Inc(dyMax);
    27902791  for dy := -dyMax to dyMax do
    27912792  begin
     
    27932794    while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <=
    27942795      CountryRadius do
    2795       inc(dxMax, 2);
     2796      Inc(dxMax, 2);
    27962797    for dx := -dxMax to dxMax do
    27972798      if (dy + dx) and 1 = 0 then
    27982799      begin
    2799         NewOwner := BorderChanges[i div 8] shr (i mod 8 * 4) and $F;
     2800        NewOwner := BorderChanges[I div 8] shr (I mod 8 * 4) and $F;
    28002801        Loc := dLoc(OriginLoc, dx, dy);
    28012802        if (Loc >= 0) and (Cardinal(NewOwner) <> RealMap[Loc] shr 27) then
    28022803          ChangeTerritory(Loc, NewOwner);
    2803         inc(i);
    2804       end;
    2805   end;
    2806 end;
    2807 
    2808 procedure CheckBorders(OriginLoc, PlayerLosingCity: integer);
     2804        Inc(I);
     2805      end;
     2806  end;
     2807end;
     2808
     2809procedure CheckBorders(OriginLoc, PlayerLosingCity: Integer);
    28092810// OriginLoc: only changes in CountryRadius around this location possible,
    28102811// -1 for complete map, -2 for double-check (no more changes allowed)
     
    28122813// player's territory, -1 for full border recalculation
    28132814var
    2814   i, r, Loc, Loc1, dx, dy, p1, p2, cix, NewDist, dxMax, dyMax, OldOwner, V8: Integer;
     2815  I, R, Loc, Loc1, dx, dy, p1, p2, cix, NewDist, dxMax, dyMax, OldOwner, V8: Integer;
    28152816  NewOwner: Cardinal;
    28162817  Adjacent: TVicinity8Loc;
    2817   AtPeace: array [0 .. nPl, 0 .. nPl] of boolean;
     2818  AtPeace: array [0 .. nPl, 0 .. nPl] of Boolean;
    28182819  Country, FormerCountry, { to who's country a tile belongs }
    28192820  Dist, FormerDist, StolenDist: array [0 .. lxmax * lymax - 1] of ShortInt;
     
    28272828        StolenDist[RW[PlayerLosingCity].City[cix].Loc] := 0;
    28282829
    2829     for r := 1 to CountryRadius shr 1 do
    2830     begin
    2831       move(StolenDist, FormerDist, MapSize);
     2830    for R := 1 to CountryRadius shr 1 do
     2831    begin
     2832      Move(StolenDist, FormerDist, MapSize);
    28322833      for Loc := 0 to MapSize - 1 do
    28332834        if (FormerDist[Loc] <= CountryRadius - 2)
     
    28612862        end;
    28622863
    2863   for r := 1 to CountryRadius shr 1 do
    2864   begin
    2865     move(Country, FormerCountry, MapSize);
    2866     move(Dist, FormerDist, MapSize);
     2864  for R := 1 to CountryRadius shr 1 do
     2865  begin
     2866    Move(Country, FormerCountry, MapSize);
     2867    Move(Dist, FormerDist, MapSize);
    28672868    for Loc := 0 to MapSize - 1 do
    28682869      if (FormerDist[Loc] <= CountryRadius - 2) // use same conditions as above!
     
    28702871        (1 shl fShore + 1 shl fMountains + 1 shl fArctic) = 0) then
    28712872      begin
    2872         assert(FormerCountry[Loc] >= 0);
     2873        Assert(FormerCountry[Loc] >= 0);
    28732874        V8_to_Loc(Loc, Adjacent);
    28742875        for V8 := 0 to 7 do
     
    28852886  end;
    28862887
    2887   FillChar(AtPeace, SizeOf(AtPeace), false);
     2888  FillChar(AtPeace, SizeOf(AtPeace), False);
    28882889  for p1 := 0 to nPl - 1 do
    28892890    if 1 shl p1 and GAlive <> 0 then
     
    28912892        if (p2 <> p1) and (1 shl p2 and GAlive <> 0) and
    28922893          (RW[p1].Treaty[p2] >= trPeace) then
    2893           AtPeace[p1, p2] := true;
     2894          AtPeace[p1, p2] := True;
    28942895
    28952896  if OriginLoc >= 0 then
    28962897  begin // update area only
    2897     i := 0;
     2898    I := 0;
    28982899    FillChar(BorderChanges, SizeOf(BorderChanges), 0);
    28992900    dyMax := 0;
    29002901    while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do
    2901       inc(dyMax);
     2902      Inc(dyMax);
    29022903    for dy := -dyMax to dyMax do
    29032904    begin
     
    29052906      while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <=
    29062907        CountryRadius do
    2907         inc(dxMax, 2);
     2908        Inc(dxMax, 2);
    29082909      for dx := -dxMax to dxMax do
    29092910        if (dy + dx) and 1 = 0 then
     
    29212922              else
    29222923                ChangeTerritory(Loc, NewOwner);
    2923             BorderChanges[i shr 3] := BorderChanges[i shr 3] or
    2924               ((NewOwner shl ((i and 7) * 4)) and $ffffffff);
     2924            BorderChanges[I shr 3] := BorderChanges[I shr 3] or
     2925              ((NewOwner shl ((I and 7) * 4)) and $ffffffff);
    29252926          end;
    2926           inc(i);
     2927          Inc(I);
    29272928        end;
    29282929    end;
     
    29372938      then
    29382939      begin
    2939         assert(OriginLoc <> -2); // test if border saving works
     2940        Assert(OriginLoc <> -2); // test if border saving works
    29402941        ChangeTerritory(Loc, NewOwner);
    29412942      end;
     
    29442945{$IFOPT O-} if OriginLoc <> -2 then
    29452946    CheckBorders(-2); {$ENDIF} // check: single pass should do!
    2946 end; // CheckBorders
    2947 
    2948 procedure LogCheckBorders(p, cix, PlayerLosingCity: integer);
    2949 begin
    2950   CheckBorders(RW[p].City[cix].Loc, PlayerLosingCity);
    2951   IntServer(sIntExpandTerritory, p, cix, BorderChanges);
     2947end;
     2948
     2949procedure LogCheckBorders(P, cix, PlayerLosingCity: Integer);
     2950begin
     2951  CheckBorders(RW[P].City[cix].Loc, PlayerLosingCity);
     2952  IntServer(sIntExpandTerritory, P, cix, BorderChanges);
    29522953end;
    29532954
     
    29572958}
    29582959
    2959 procedure CreateUnit(p, mix: integer);
    2960 begin
    2961   with RW[p] do
     2960procedure CreateUnit(P, mix: Integer);
     2961begin
     2962  with RW[P] do
    29622963  begin
    29632964    Un[nUn].mix := mix;
    29642965    with Un[nUn] do
    29652966    begin
    2966       ID := UnBuilt[p];
    2967       inc(UnBuilt[p]);
     2967      ID := UnBuilt[P];
     2968      Inc(UnBuilt[P]);
    29682969      Status := 0;
    29692970      SavedStatus := 0;
    2970       inc(Model[mix].Built);
     2971      Inc(Model[mix].Built);
    29712972      Home := -1;
    29722973      Health := 100;
     
    29762977      begin
    29772978        Fuel := Model[mix].Cap[mcFuel];
    2978         Flags := Flags or unBombsLoaded
     2979        Flags := Flags or unBombsLoaded;
    29792980      end;
    29802981      Job := jNone;
     
    29842985      Master := -1;
    29852986    end;
    2986     inc(nUn);
     2987    Inc(nUn);
    29872988  end
    29882989end;
    29892990
    2990 procedure FreeUnit(p, uix: integer);
     2991procedure FreeUnit(P, uix: Integer);
    29912992// loc or master should be set after call
    29922993// implementation is critical for loading performance, change carefully
    29932994var
    2994   Loc0, uix1: integer;
    2995   Occ, ZoC: boolean;
    2996 begin
    2997   with RW[p].Un[uix] do
     2995  Loc0, uix1: Integer;
     2996  Occ, ZoC: Boolean;
     2997begin
     2998  with RW[P].Un[uix] do
    29982999  begin
    29993000    Job := jNone;
    30003001    Flags := Flags and not(unFortified or unMountainDelay);
    3001     Loc0 := Loc
     3002    Loc0 := Loc;
    30023003  end;
    30033004  if Occupant[Loc0] >= 0 then
    30043005  begin
    3005     assert(Occupant[Loc0] = p);
    3006     Occ := false;
    3007     ZoC := false;
    3008     for uix1 := 0 to RW[p].nUn - 1 do
    3009       with RW[p].Un[uix1] do
     3006    Assert(Occupant[Loc0] = P);
     3007    Occ := False;
     3008    ZoC := False;
     3009    for uix1 := 0 to RW[P].nUn - 1 do
     3010      with RW[P].Un[uix1] do
    30103011        if (Loc = Loc0) and (Master < 0) and (uix1 <> uix) then
    30113012        begin
    3012           Occ := true;
    3013           if RW[p].Model[mix].Flags and mdZOC <> 0 then
     3013          Occ := True;
     3014          if RW[P].Model[mix].Flags and mdZOC <> 0 then
    30143015          begin
    3015             ZoC := true;
    3016             Break
    3017           end
     3016            ZoC := True;
     3017            Break;
     3018          end;
    30183019        end;
    30193020    if not Occ then
     
    30243025end;
    30253026
    3026 procedure PlaceUnit(p, uix: integer);
    3027 begin
    3028   with RW[p].Un[uix] do
    3029   begin
    3030     Occupant[Loc] := p;
    3031     if RW[p].Model[mix].Flags and mdZOC <> 0 then
     3027procedure PlaceUnit(P, uix: Integer);
     3028begin
     3029  with RW[P].Un[uix] do
     3030  begin
     3031    Occupant[Loc] := P;
     3032    if RW[P].Model[mix].Flags and mdZOC <> 0 then
    30323033      ZoCMap[Loc] := 1;
    30333034  end;
    30343035end;
    30353036
    3036 procedure CountLost(p, mix, Enemy: integer);
    3037 begin
    3038   Inc(RW[p].Model[mix].Lost);
    3039   TellAboutModel(Enemy, p, mix);
    3040   Inc(Destroyed[Enemy, p, mix]);
    3041 end;
    3042 
    3043 procedure RemoveUnit(p, uix: integer; Enemy: integer = -1);
     3037procedure CountLost(P, mix, Enemy: Integer);
     3038begin
     3039  Inc(RW[P].Model[mix].Lost);
     3040  TellAboutModel(Enemy, P, mix);
     3041  Inc(Destroyed[Enemy, P, mix]);
     3042end;
     3043
     3044procedure RemoveUnit(P, uix: Integer; Enemy: Integer = -1);
    30443045// use enemy only from inside sMoveUnit if attack
    30453046var
    3046   uix1: integer;
    3047 begin
    3048   with RW[p].Un[uix] do
    3049   begin
    3050     assert((Loc >= 0) or (RW[p].Model[mix].Kind = mkDiplomat));
     3047  uix1: Integer;
     3048begin
     3049  with RW[P].Un[uix] do
     3050  begin
     3051    Assert((Loc >= 0) or (RW[P].Model[mix].Kind = mkDiplomat));
    30513052    // already freed when spy mission
    30523053    if Loc >= 0 then
    3053       FreeUnit(p, uix);
     3054      FreeUnit(P, uix);
    30543055    if Master >= 0 then
    3055       if RW[p].Model[mix].Domain = dAir then
    3056         dec(RW[p].Un[Master].AirLoad)
     3056      if RW[P].Model[mix].Domain = dAir then
     3057        Dec(RW[P].Un[Master].AirLoad)
    30573058      else
    3058         dec(RW[p].Un[Master].TroopLoad);
     3059        Dec(RW[P].Un[Master].TroopLoad);
    30593060    if (TroopLoad > 0) or (AirLoad > 0) then
    3060       for uix1 := 0 to RW[p].nUn - 1 do
    3061         if (RW[p].Un[uix1].Loc >= 0) and (RW[p].Un[uix1].Master = uix) then
     3061      for uix1 := 0 to RW[P].nUn - 1 do
     3062        if (RW[P].Un[uix1].Loc >= 0) and (RW[P].Un[uix1].Master = uix) then
    30623063        { unit mastered by removed unit -- remove too }
    30633064        begin
    3064           RW[p].Un[uix1].Loc := -1;
     3065          RW[P].Un[uix1].Loc := -1;
    30653066          if Enemy >= 0 then
    3066             CountLost(p, RW[p].Un[uix1].mix, Enemy);
     3067            CountLost(P, RW[P].Un[uix1].mix, Enemy);
    30673068        end;
    30683069    Loc := -1;
    30693070    if Enemy >= 0 then
    3070       CountLost(p, mix, Enemy);
    3071   end;
    3072 end;
    3073 
    3074 procedure RemoveUnit_UpdateMap(p, uix: integer);
     3071      CountLost(P, mix, Enemy);
     3072  end;
     3073end;
     3074
     3075procedure RemoveUnit_UpdateMap(P, uix: Integer);
    30753076var
    30763077  Loc0: Integer;
    30773078begin
    3078   Loc0 := RW[p].Un[uix].Loc;
    3079   RemoveUnit(p, uix);
     3079  Loc0 := RW[P].Un[uix].Loc;
     3080  RemoveUnit(P, uix);
    30803081  if Mode > moLoading_Fast then
    30813082    UpdateUnitMap(Loc0);
    30823083end;
    30833084
    3084 procedure RemoveAllUnits(p, Loc: integer; Enemy: integer = -1);
    3085 var
    3086   uix: integer;
    3087 begin
    3088   for uix := 0 to RW[p].nUn - 1 do
    3089     if RW[p].Un[uix].Loc = Loc then
     3085procedure RemoveAllUnits(P, Loc: Integer; Enemy: Integer = -1);
     3086var
     3087  uix: Integer;
     3088begin
     3089  for uix := 0 to RW[P].nUn - 1 do
     3090    if RW[P].Un[uix].Loc = Loc then
    30903091    begin
    30913092      if Enemy >= 0 then
    3092         CountLost(p, RW[p].Un[uix].mix, Enemy);
    3093       RW[p].Un[uix].Loc := -1
     3093        CountLost(P, RW[P].Un[uix].mix, Enemy);
     3094      RW[P].Un[uix].Loc := -1;
    30943095    end;
    30953096  Occupant[Loc] := -1;
     
    30973098end;
    30983099
    3099 procedure RemoveDomainUnits(d, p, Loc: integer);
    3100 var
    3101   uix: integer;
    3102 begin
    3103   for uix := 0 to RW[p].nUn - 1 do
    3104     if (RW[p].Model[RW[p].Un[uix].mix].Domain = d) and (RW[p].Un[uix].Loc = Loc)
     3100procedure RemoveDomainUnits(D, P, Loc: Integer);
     3101var
     3102  uix: Integer;
     3103begin
     3104  for uix := 0 to RW[P].nUn - 1 do
     3105    if (RW[P].Model[RW[P].Un[uix].mix].Domain = D) and (RW[P].Un[uix].Loc = Loc)
    31053106    then
    3106       RemoveUnit(p, uix);
    3107 end;
    3108 
    3109 procedure FoundCity(p, FoundLoc: integer);
    3110 var
    3111   p1, cix1, V21, dx, dy: integer;
    3112 begin
    3113   if RW[p].nCity = ncmax then
    3114     exit;
    3115   inc(RW[p].nCity);
    3116   with RW[p].City[RW[p].nCity - 1] do
     3107      RemoveUnit(P, uix);
     3108end;
     3109
     3110procedure FoundCity(P, FoundLoc: Integer);
     3111var
     3112  p1, cix1, V21, dx, dy: Integer;
     3113begin
     3114  if RW[P].nCity = ncmax then
     3115    Exit;
     3116  Inc(RW[P].nCity);
     3117  with RW[P].City[RW[P].nCity - 1] do
    31173118  begin
    31183119    Size := 2;
     
    31303131    if UsedByCity[FoundLoc] >= 0 then
    31313132    begin { central tile is exploited - toggle in exploiting city }
    3132       p1 := p;
     3133      p1 := P;
    31333134      SearchCity(UsedByCity[FoundLoc], p1, cix1);
    31343135      dxdy(UsedByCity[FoundLoc], FoundLoc, dx, dy);
     
    31413142      (fTerrain or fSpecial or fRiver or nPl shl 27) or fCity;
    31423143
    3143     ChangeTerritory(Loc, p)
    3144   end;
    3145 end;
    3146 
    3147 procedure StealCity(p, cix: integer; SaveUnits: boolean);
    3148 var
    3149   i, j, uix1, cix1, nearest: integer;
    3150 begin
    3151   for i := 0 to nWonder - 1 do
    3152     if RW[p].City[cix].Built[i] = 1 then
    3153     begin
    3154       GWonder[i].EffectiveOwner := -1;
    3155       if i = woPyramids then
     3144    ChangeTerritory(Loc, P);
     3145  end;
     3146end;
     3147
     3148procedure StealCity(P, cix: Integer; SaveUnits: Boolean);
     3149var
     3150  I, J, uix1, cix1, nearest: Integer;
     3151begin
     3152  for I := 0 to nWonder - 1 do
     3153    if RW[P].City[cix].Built[I] = 1 then
     3154    begin
     3155      GWonder[I].EffectiveOwner := -1;
     3156      if I = woPyramids then
    31563157        FreeSlaves;
    3157       if i = woEiffel then // deactivate expired wonders
    3158         for j := 0 to nWonder - 1 do
    3159           if GWonder[j].EffectiveOwner = p then
    3160             CheckExpiration(j);
    3161     end;
    3162   for i := nWonder to nImp - 1 do
    3163     if (Imp[i].Kind <> ikCommon) and (RW[p].City[cix].Built[i] > 0) then
     3158      if I = woEiffel then // deactivate expired wonders
     3159        for J := 0 to nWonder - 1 do
     3160          if GWonder[J].EffectiveOwner = P then
     3161            CheckExpiration(J);
     3162    end;
     3163  for I := nWonder to nImp - 1 do
     3164    if (Imp[I].Kind <> ikCommon) and (RW[P].City[cix].Built[I] > 0) then
    31643165    begin { destroy national projects }
    3165       RW[p].NatBuilt[i] := 0;
    3166       if i = imGrWall then
    3167         GrWallContinent[p] := -1;
    3168     end;
    3169 
    3170   for uix1 := 0 to RW[p].nUn - 1 do
    3171     with RW[p].Un[uix1] do
     3166      RW[P].NatBuilt[I] := 0;
     3167      if I = imGrWall then
     3168        GrWallContinent[P] := -1;
     3169    end;
     3170
     3171  for uix1 := 0 to RW[P].nUn - 1 do
     3172    with RW[P].Un[uix1] do
    31723173      if (Loc >= 0) and (Home = cix) then
    31733174        if SaveUnits then
    31743175        begin // support units by nearest other city
    31753176          nearest := -1;
    3176           for cix1 := 0 to RW[p].nCity - 1 do
    3177             if (cix1 <> cix) and (RW[p].City[cix1].Loc >= 0) and
    3178               ((nearest < 0) or (Distance(RW[p].City[cix1].Loc, Loc) <
    3179               Distance(RW[p].City[nearest].Loc, Loc))) then
     3177          for cix1 := 0 to RW[P].nCity - 1 do
     3178            if (cix1 <> cix) and (RW[P].City[cix1].Loc >= 0) and
     3179              ((nearest < 0) or (Distance(RW[P].City[cix1].Loc, Loc) <
     3180              Distance(RW[P].City[nearest].Loc, Loc))) then
    31803181              nearest := cix1;
    3181           Home := nearest
     3182          Home := nearest;
    31823183        end
    31833184        else
    3184           RemoveUnit(p, uix1); // destroy supported units
    3185 end;
    3186 
    3187 procedure DestroyCity(p, cix: integer; SaveUnits: boolean);
    3188 var
    3189   i, V21: integer;
     3185          RemoveUnit(P, uix1); // destroy supported units
     3186end;
     3187
     3188procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean);
     3189var
     3190  I, V21: Integer;
    31903191  Radius: TVicinity21Loc;
    31913192begin
    3192   StealCity(p, cix, SaveUnits);
    3193   with RW[p].City[cix] do begin
    3194     for i := 0 to nWonder - 1 do
    3195       if Built[i] > 0 then
    3196         GWonder[i].CityID := WonderDestroyed;
     3193  StealCity(P, cix, SaveUnits);
     3194  with RW[P].City[cix] do begin
     3195    for I := 0 to nWonder - 1 do
     3196      if Built[I] > 0 then
     3197        GWonder[I].CityID := WonderDestroyed;
    31973198    V21_to_Loc(Loc, Radius);
    31983199    for V21 := 1 to 26 do
     
    32003201        UsedByCity[Radius[V21]] := -1;
    32013202    RealMap[Loc] := RealMap[Loc] and not fCity;
    3202     Loc := -1
    3203   end;
    3204 end;
    3205 
    3206 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);
    3207 var
    3208   i, j, cix1, Loc1, V21: integer;
     3203    Loc := -1;
     3204  end;
     3205end;
     3206
     3207procedure ChangeCityOwner(pOld, cixOld, pNew: Integer);
     3208var
     3209  I, J, cix1, Loc1, V21: Integer;
    32093210  Radius: TVicinity21Loc;
    32103211begin
    3211   inc(RW[pNew].nCity);
     3212  Inc(RW[pNew].nCity);
    32123213  RW[pNew].City[RW[pNew].nCity - 1] := RW[pOld].City[cixOld];
    3213   StealCity(pOld, cixOld, false);
     3214  StealCity(pOld, cixOld, False);
    32143215  RW[pOld].City[cixOld].Loc := -1;
    32153216  with RW[pNew].City[(RW[pNew].nCity - 1)] do
     
    32303231      begin
    32313232        Loc1 := Radius[V21];
    3232         assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));
     3233        Assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));
    32333234        if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> pNew) and
    32343235          (RW[pNew].Treaty[Occupant[Loc1]] < trAlliance) then
     
    32423243    Built[imTownHall] := 0;
    32433244    Built[imCourt] := 0;
    3244     for i := nWonder to nImp - 1 do
    3245       if Imp[i].Kind <> ikCommon then
    3246         Built[i] := 0; { destroy national projects }
    3247     for i := 0 to nWonder - 1 do
    3248       if Built[i] = 1 then
     3245    for I := nWonder to nImp - 1 do
     3246      if Imp[I].Kind <> ikCommon then
     3247        Built[I] := 0; { destroy national projects }
     3248    for I := 0 to nWonder - 1 do
     3249      if Built[I] = 1 then
    32493250      begin // new wonder owner!
    3250         GWonder[i].EffectiveOwner := pNew;
    3251         if i = woEiffel then // reactivate expired wonders
    3252         begin
    3253           for j := 0 to nWonder - 1 do
    3254             if Imp[j].Expiration >= 0 then
     3251        GWonder[I].EffectiveOwner := pNew;
     3252        if I = woEiffel then // reactivate expired wonders
     3253        begin
     3254          for J := 0 to nWonder - 1 do
     3255            if Imp[J].Expiration >= 0 then
    32553256              for cix1 := 0 to (RW[pNew].nCity - 1) do
    3256                 if RW[pNew].City[cix1].Built[j] = 1 then
    3257                   GWonder[j].EffectiveOwner := pNew;
     3257                if RW[pNew].City[cix1].Built[J] = 1 then
     3258                  GWonder[J].EffectiveOwner := pNew;
    32583259        end
    32593260        else
    3260           CheckExpiration(i);
    3261         case i of
     3261          CheckExpiration(I);
     3262        case I of
    32623263          woLighthouse:
    32633264            CheckSpecialModels(pNew, preLighthouse);
     
    32733274    cix1 := RW[pNew].nEnemyCity - 1;
    32743275    while (cix1 >= 0) and (RW[pNew].EnemyCity[cix1].Loc <> Loc) do
    3275       dec(cix1);
    3276     assert(cix1 >= 0);
     3276      Dec(cix1);
     3277    Assert(cix1 >= 0);
    32773278    RW[pNew].EnemyCity[cix1].Loc := -1;
    32783279
     
    32813282end;
    32823283
    3283 procedure CompleteJob(p, Loc, Job: integer);
    3284 var
    3285   ChangedTerrain, p1: integer;
    3286 begin
    3287   assert(Job <> jCity);
     3284procedure CompleteJob(P, Loc, Job: Integer);
     3285var
     3286  ChangedTerrain, p1: Integer;
     3287begin
     3288  Assert(Job <> jCity);
    32883289  ChangedTerrain := -1;
    32893290  case Job of
     
    33273328        if not(RealMap[Loc] and fTerrain in TerrType_Canalable) then
    33283329        begin
    3329           RemoveDomainUnits(dSea, p, Loc);
     3330          RemoveDomainUnits(dSea, P, Loc);
    33303331          RealMap[Loc] := RealMap[Loc] and not fCanal;
    33313332        end;
     
    33393340      begin
    33403341        if RealMap[Loc] and fTerImp = tiBase then
    3341           RemoveDomainUnits(dAir, p, Loc);
     3342          RemoveDomainUnits(dAir, P, Loc);
    33423343        RealMap[Loc] := RealMap[Loc] and not fTerImp
    33433344      end
    33443345      else if RealMap[Loc] and fCanal <> 0 then
    33453346      begin
    3346         RemoveDomainUnits(dSea, p, Loc);
     3347        RemoveDomainUnits(dSea, P, Loc);
    33473348        RealMap[Loc] := RealMap[Loc] and not fCanal
    33483349      end
     
    33743375          fPoll) or RealMap[Loc] and (fTerrain or fSpecial or fTerImp or
    33753376          fRoad or fRR or fCanal or fPoll);
    3376 end; // CompleteJob
     3377end;
    33773378
    33783379{
     
    33803381  ____________________________________________________________________
    33813382}
    3382 procedure GiveCivilReport(p, pAbout: integer);
    3383 begin
    3384   with RW[p].EnemyReport[pAbout]^ do
     3383procedure GiveCivilReport(P, pAbout: Integer);
     3384begin
     3385  with RW[P].EnemyReport[pAbout]^ do
    33853386  begin
    33863387    // general info
    33873388    TurnOfCivilReport := LastValidStat[pAbout];
    3388     move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));
     3389    Move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));
    33893390    Government := RW[pAbout].Government;
    33903391    Money := RW[pAbout].Money;
     
    33953396    if ResearchDone > 100 then
    33963397      ResearchDone := 100;
    3397     move(RW[pAbout].Tech, Tech, nAdv);
    3398   end;
    3399 end;
    3400 
    3401 procedure GiveMilReport(p, pAbout: integer);
    3402 var
    3403   uix, mix: integer;
    3404 begin
    3405   with RW[p].EnemyReport[pAbout]^ do
     3398    Move(RW[pAbout].Tech, Tech, nAdv);
     3399  end;
     3400end;
     3401
     3402procedure GiveMilReport(P, pAbout: Integer);
     3403var
     3404  uix, mix: Integer;
     3405begin
     3406  with RW[P].EnemyReport[pAbout]^ do
    34063407  begin
    34073408    TurnOfMilReport := LastValidStat[pAbout];
     
    34093410    for mix := 0 to RW[pAbout].nModel - 1 do
    34103411    begin
    3411       TellAboutModel(p, pAbout, mix);
     3412      TellAboutModel(P, pAbout, mix);
    34123413      UnCount[mix] := 0
    34133414    end;
    34143415    for uix := 0 to RW[pAbout].nUn - 1 do
    34153416      if RW[pAbout].Un[uix].Loc >= 0 then
    3416         inc(UnCount[RW[pAbout].Un[uix].mix]);
    3417   end;
    3418 end;
    3419 
    3420 procedure ShowPrice(pSender, pTarget, Price: integer);
     3417        Inc(UnCount[RW[pAbout].Un[uix].mix]);
     3418  end;
     3419end;
     3420
     3421procedure ShowPrice(pSender, pTarget, Price: Integer);
    34213422begin
    34223423  case Price and opMask of
     
    34333434end;
    34343435
    3435 function CopyCivilReport(pSender, pTarget, pAbout: integer): boolean;
    3436 var
    3437   i: integer;
     3436function CopyCivilReport(pSender, pTarget, pAbout: Integer): Boolean;
     3437var
     3438  I: Integer;
    34383439  rSender, rTarget: ^TEnemyReport;
    34393440begin // copy third nation civil report
    3440   result := false;
     3441  Result := False;
    34413442  if RW[pTarget].Treaty[pAbout] = trNoContact then
    34423443    IntroduceEnemy(pTarget, pAbout);
    3443   rSender := pointer(RW[pSender].EnemyReport[pAbout]);
    3444   rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);
     3444  rSender := Pointer(RW[pSender].EnemyReport[pAbout]);
     3445  rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]);
    34453446  if rSender.TurnOfCivilReport > rTarget.TurnOfCivilReport then
    34463447  begin // only if newer than current information
     
    34513452    rTarget.ResearchTech := rSender.ResearchTech;
    34523453    rTarget.ResearchDone := rSender.ResearchDone;
    3453     result := true;
    3454   end;
    3455   for i := 0 to nAdv - 1 do
    3456     if rTarget.Tech[i] < rSender.Tech[i] then
    3457     begin
    3458       rTarget.Tech[i] := rSender.Tech[i];
    3459       result := true;
    3460     end;
    3461 end;
    3462 
    3463 function CopyMilReport(pSender, pTarget, pAbout: integer): boolean;
    3464 var
    3465   mix: integer;
     3454    Result := True;
     3455  end;
     3456  for I := 0 to nAdv - 1 do
     3457    if rTarget.Tech[I] < rSender.Tech[I] then
     3458    begin
     3459      rTarget.Tech[I] := rSender.Tech[I];
     3460      Result := True;
     3461    end;
     3462end;
     3463
     3464function CopyMilReport(pSender, pTarget, pAbout: Integer): Boolean;
     3465var
     3466  mix: Integer;
    34663467  rSender, rTarget: ^TEnemyReport;
    34673468begin // copy third nation military report
    3468   result := false;
     3469  Result := False;
    34693470  if RW[pTarget].Treaty[pAbout] = trNoContact then
    34703471    IntroduceEnemy(pTarget, pAbout);
    3471   rSender := pointer(RW[pSender].EnemyReport[pAbout]);
    3472   rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);
     3472  rSender := Pointer(RW[pSender].EnemyReport[pAbout]);
     3473  rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]);
    34733474  if rSender.TurnOfMilReport > rTarget.TurnOfMilReport then
    34743475  begin // only if newer than current information
    34753476    rTarget.TurnOfMilReport := rSender.TurnOfMilReport;
    34763477    rTarget.nModelCounted := rSender.nModelCounted;
    3477     move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);
     3478    Move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);
    34783479    for mix := 0 to rTarget.nModelCounted - 1 do
    34793480      TellAboutModel(pTarget, pAbout, mix);
    3480     result := true;
    3481   end;
    3482 end;
    3483 
    3484 procedure CopyModel(pSender, pTarget, mix: integer);
    3485 var
    3486   i: integer;
     3481    Result := True;
     3482  end;
     3483end;
     3484
     3485procedure CopyModel(pSender, pTarget, mix: Integer);
     3486var
     3487  I: Integer;
    34873488  miSender, miTarget: TModelInfo;
    3488   ok: boolean;
     3489  ok: Boolean;
    34893490begin
    34903491  // only if target doesn't already have a model like this
    34913492  ok := RW[pTarget].nModel < nmmax;
    34923493  MakeModelInfo(pSender, mix, RW[pSender].Model[mix], miSender);
    3493   for i := 0 to RW[pTarget].nModel - 1 do
    3494   begin
    3495     MakeModelInfo(pTarget, i, RW[pTarget].Model[i], miTarget);
     3494  for I := 0 to RW[pTarget].nModel - 1 do
     3495  begin
     3496    MakeModelInfo(pTarget, I, RW[pTarget].Model[I], miTarget);
    34963497    if IsSameModel(miSender, miTarget) then
    3497       ok := false;
     3498      ok := False;
    34983499  end;
    34993500  if ok then
     
    35103511      Lost := 0;
    35113512    end;
    3512     inc(RW[pTarget].nModel);
    3513     inc(Researched[pTarget]);
     3513    Inc(RW[pTarget].nModel);
     3514    Inc(Researched[pTarget]);
    35143515    TellAboutModel(pSender, pTarget, RW[pTarget].nModel - 1);
    35153516  end;
    35163517end;
    35173518
    3518 procedure CopyMap(pSender, pTarget: integer);
    3519 var
    3520   Loc, i, cix: integer;
     3519procedure CopyMap(pSender, pTarget: Integer);
     3520var
     3521  Loc, I, cix: Integer;
    35213522  Tile: Cardinal;
    35223523begin
     
    35283529      if Tile and fCity <> 0 then
    35293530      begin
    3530         i := 0;
    3531         while (i < RW[pTarget].nEnemyCity) and
    3532           (RW[pTarget].EnemyCity[i].Loc <> Loc) do
    3533           inc(i);
    3534         if i = RW[pTarget].nEnemyCity then
    3535         begin
    3536           inc(RW[pTarget].nEnemyCity);
    3537           assert(RW[pTarget].nEnemyCity < necmax);
    3538           RW[pTarget].EnemyCity[i].Status := 0;
    3539           RW[pTarget].EnemyCity[i].SavedStatus := 0;
     3531        I := 0;
     3532        while (I < RW[pTarget].nEnemyCity) and
     3533          (RW[pTarget].EnemyCity[I].Loc <> Loc) do
     3534          Inc(I);
     3535        if I = RW[pTarget].nEnemyCity then
     3536        begin
     3537          Inc(RW[pTarget].nEnemyCity);
     3538          Assert(RW[pTarget].nEnemyCity < necmax);
     3539          RW[pTarget].EnemyCity[I].Status := 0;
     3540          RW[pTarget].EnemyCity[I].SavedStatus := 0;
    35403541        end;
    35413542        if Tile and fOwned <> 0 then
     
    35433544          cix := RW[pSender].nCity - 1;
    35443545          while (cix >= 0) and (RW[pSender].City[cix].Loc <> Loc) do
    3545             dec(cix);
    3546           MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[i]);
     3546            Dec(cix);
     3547          MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[I]);
    35473548        end
    35483549        else // city not owned by sender -- copy old info
     
    35503551          cix := RW[pSender].nEnemyCity - 1;
    35513552          while (cix >= 0) and (RW[pSender].EnemyCity[cix].Loc <> Loc) do
    3552             dec(cix);
    3553           RW[pTarget].EnemyCity[i] := RW[pSender].EnemyCity[cix];
     3553            Dec(cix);
     3554          RW[pTarget].EnemyCity[I] := RW[pSender].EnemyCity[cix];
    35543555        end;
    35553556      end
     
    35653566
    35663567      if RW[pTarget].Map[Loc] and fTerrain = fUNKNOWN then
    3567         inc(Discovered[pTarget]);
     3568        Inc(Discovered[pTarget]);
    35683569      RW[pTarget].Map[Loc] := RW[pTarget].Map[Loc] and fInEnemyZoC
    35693570      // always preserve this flag!
     
    35813582end;
    35823583
    3583 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;
    3584 var
    3585   pSubject, i, n, NewTreaty: integer;
    3586 begin
    3587   result := true;
     3584function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean;
     3585var
     3586  pSubject, I, N, NewTreaty: Integer;
     3587begin
     3588  Result := True;
    35883589  case Price and opMask of
    35893590    opCivilReport: // + turn + concerned player shl 16
     
    35913592        pSubject := Price shr 16 and $F;
    35923593        if pTarget = pSubject then
    3593           result := false
     3594          Result := False
    35943595        else if pSender = pSubject then
    35953596        begin
    35963597          if execute then
    3597             GiveCivilReport(pTarget, pSender)
     3598            GiveCivilReport(pTarget, pSender);
    35983599        end
    35993600        else if RW[pSender].EnemyReport[pSubject].TurnOfCivilReport < 0 then
    3600           result := false
     3601          Result := False
    36013602        else if execute then
    36023603          CopyCivilReport(pSender, pTarget, pSubject);
     
    36063607        pSubject := Price shr 16 and $F;
    36073608        if pTarget = pSubject then
    3608           result := false
     3609          Result := False
    36093610        else if pSender = pSubject then
    36103611        begin
    36113612          if execute then
    3612             GiveMilReport(pTarget, pSender)
     3613            GiveMilReport(pTarget, pSender);
    36133614        end
    36143615        else if RW[pSender].EnemyReport[pSubject].TurnOfMilReport < 0 then
    3615           result := false
     3616          Result := False
    36163617        else if execute then
    3617           CopyMilReport(pSender, pTarget, pSubject)
     3618          CopyMilReport(pSender, pTarget, pSubject);
    36183619      end;
    36193620    opMap:
     
    36283629        begin // agreed treaty end
    36293630          if execute then
    3630             CancelTreaty(pSender, pTarget, false)
     3631            CancelTreaty(pSender, pTarget, False);
    36313632        end
    36323633        else
     
    36393640            NewTreaty := trPeace;
    36403641          if NewTreaty < 0 then
    3641             result := false
     3642            Result := False
    36423643          else if execute then
    36433644          begin
    3644             assert(NewTreaty > RW[pSender].Treaty[pTarget]);
     3645            Assert(NewTreaty > RW[pSender].Treaty[pTarget]);
    36453646            RW[pSender].Treaty[pTarget] := NewTreaty;
    36463647            RW[pTarget].Treaty[pSender] := NewTreaty;
     
    36713672    opShipParts: // + number + part type shl 16
    36723673      begin
    3673         n := Price and $FFFF; // number
    3674         i := Price shr 16 and $F; // type
    3675         if (i < nShipPart) and (GShip[pSender].Parts[i] >= n) then
     3674        N := Price and $FFFF; // number
     3675        I := Price shr 16 and $F; // type
     3676        if (I < nShipPart) and (GShip[pSender].Parts[I] >= N) then
    36763677        begin
    36773678          if execute then
    36783679          begin
    3679             dec(GShip[pSender].Parts[i], n);
    3680             RW[pSender].Ship[pSender].Parts[i] := GShip[pSender].Parts[i];
    3681             RW[pTarget].Ship[pSender].Parts[i] := GShip[pSender].Parts[i];
     3680            Dec(GShip[pSender].Parts[I], N);
     3681            RW[pSender].Ship[pSender].Parts[I] := GShip[pSender].Parts[I];
     3682            RW[pTarget].Ship[pSender].Parts[I] := GShip[pSender].Parts[I];
    36823683            if RW[pTarget].NatBuilt[imSpacePort] > 0 then
    36833684            begin // space ship control requires space port
    3684               inc(GShip[pTarget].Parts[i], n);
    3685               RW[pSender].Ship[pTarget].Parts[i] := GShip[pTarget].Parts[i];
    3686               RW[pTarget].Ship[pTarget].Parts[i] := GShip[pTarget].Parts[i];
     3685              Inc(GShip[pTarget].Parts[I], N);
     3686              RW[pSender].Ship[pTarget].Parts[I] := GShip[pTarget].Parts[I];
     3687              RW[pTarget].Ship[pTarget].Parts[I] := GShip[pTarget].Parts[I];
    36873688            end;
    36883689          end;
    36893690        end
    36903691        else
    3691           result := false;
     3692          Result := False;
    36923693      end;
    36933694    opMoney: // + value
     
    36973698        if execute then
    36983699        begin
    3699           dec(RW[pSender].Money, Price - opMoney);
    3700           inc(RW[pTarget].Money, Price - opMoney);
     3700          Dec(RW[pSender].Money, Price - opMoney);
     3701          Inc(RW[pTarget].Money, Price - opMoney);
    37013702        end;
    37023703      end
    37033704      else
    3704         result := false;
     3705        Result := False;
    37053706    opTribute: // + value
    37063707      if execute then
     
    37173718      end
    37183719      else
    3719         result := false;
     3720        Result := False;
    37203721    opAllTech:
    37213722      if execute then
    3722         for i := 0 to nAdv - 1 do
    3723           if (RW[pSender].Tech[i] >= tsApplicable) and
    3724             (RW[pTarget].Tech[i] = tsNA) then
     3723        for I := 0 to nAdv - 1 do
     3724          if (RW[pSender].Tech[I] >= tsApplicable) and
     3725            (RW[pTarget].Tech[I] = tsNA) then
    37253726          begin
    3726             SeeTech(pTarget, i);
    3727             RW[pSender].EnemyReport[pTarget].Tech[i] := tsSeen;
    3728             RW[pTarget].EnemyReport[pSender].Tech[i] := tsApplicable;
     3727            SeeTech(pTarget, I);
     3728            RW[pSender].EnemyReport[pTarget].Tech[I] := tsSeen;
     3729            RW[pTarget].EnemyReport[pSender].Tech[I] := tsApplicable;
    37293730          end;
    37303731    opModel: // + model index
     
    37323733      begin
    37333734        if execute then
    3734           CopyModel(pSender, pTarget, Price - opModel)
     3735          CopyModel(pSender, pTarget, Price - opModel);
    37353736      end
    37363737      else
    3737         result := false;
     3738        Result := False;
    37383739    opAllModel:
    37393740      if execute then
    3740         for i := 0 to RW[pSender].nModel - 1 do
    3741         begin
    3742           TellAboutModel(pTarget, pSender, i);
    3743           CopyModel(pSender, pTarget, i);
     3741        for I := 0 to RW[pSender].nModel - 1 do
     3742        begin
     3743          TellAboutModel(pTarget, pSender, I);
     3744          CopyModel(pSender, pTarget, I);
    37443745        end;
    37453746    { opCity: // + city ID
    37463747      begin
    3747       result:=false
     3748      Result:=False
    37483749      end; }
    3749   end
    3750 end;
    3751 
    3752 procedure CancelTreaty(p, pWith: integer; DecreaseCredibility: boolean);
     3750  end;
     3751end;
     3752
     3753procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean);
    37533754// side effect: PeaceEnded := bitarray of players with which peace treaty was canceled
    37543755var
    3755   p1, OldTreaty: integer;
    3756 begin
    3757   OldTreaty := RW[p].Treaty[pWith];
     3756  p1, OldTreaty: Integer;
     3757begin
     3758  OldTreaty := RW[P].Treaty[pWith];
    37583759  PeaceEnded := 0;
    37593760  if OldTreaty >= trPeace then
    3760     RW[p].LastCancelTreaty[pWith] := GTurn;
     3761    RW[P].LastCancelTreaty[pWith] := GTurn;
    37613762  if DecreaseCredibility then
    37623763  begin
     
    37643765      trPeace:
    37653766        begin
    3766           RW[p].Credibility := RW[p].Credibility shr 1;
    3767           if RW[p].MaxCredibility > 0 then
    3768             dec(RW[p].MaxCredibility, 10);
    3769           if RW[p].Credibility > RW[p].MaxCredibility then
    3770             RW[p].Credibility := RW[p].MaxCredibility;
     3767          RW[P].Credibility := RW[P].Credibility shr 1;
     3768          if RW[P].MaxCredibility > 0 then
     3769            Dec(RW[P].MaxCredibility, 10);
     3770          if RW[P].Credibility > RW[P].MaxCredibility then
     3771            RW[P].Credibility := RW[P].MaxCredibility;
    37713772        end;
    37723773      trAlliance:
    3773         RW[p].Credibility := RW[p].Credibility * 3 div 4;
    3774     end;
    3775     RW[pWith].EnemyReport[p].Credibility := RW[p].Credibility;
     3774        RW[P].Credibility := RW[P].Credibility * 3 div 4;
     3775    end;
     3776    RW[pWith].EnemyReport[P].Credibility := RW[P].Credibility;
    37763777  end;
    37773778
     
    37793780  begin
    37803781    for p1 := 0 to nPl - 1 do
    3781       if (p1 = pWith) or DecreaseCredibility and (p1 <> p) and
    3782         (RW[pWith].Treaty[p1] = trAlliance) and (RW[p].Treaty[p1] >= trPeace)
     3782      if (p1 = pWith) or DecreaseCredibility and (p1 <> P) and
     3783        (RW[pWith].Treaty[p1] = trAlliance) and (RW[P].Treaty[p1] >= trPeace)
    37833784      then
    37843785      begin
    3785         RW[p].Treaty[p1] := trNone;
    3786         RW[p1].Treaty[p] := trNone;
    3787         RW[p].EvaStart[p1] := -PeaceEvaTurns - 1;
    3788         RW[p1].EvaStart[p] := -PeaceEvaTurns - 1;
    3789         inc(PeaceEnded, 1 shl p1);
     3786        RW[P].Treaty[p1] := trNone;
     3787        RW[p1].Treaty[P] := trNone;
     3788        RW[P].EvaStart[p1] := -PeaceEvaTurns - 1;
     3789        RW[p1].EvaStart[P] := -PeaceEvaTurns - 1;
     3790        Inc(PeaceEnded, 1 shl p1);
    37903791      end;
    37913792    CheckBorders(-1);
    37923793    if (Mode > moLoading_Fast) and (PeaceEnded > 0) then
    3793       RecalcMapZoC(p);
     3794      RecalcMapZoC(P);
    37943795  end
    37953796  else
    37963797  begin
    3797     RW[p].Treaty[pWith] := OldTreaty - 1;
    3798     RW[pWith].Treaty[p] := OldTreaty - 1;
     3798    RW[P].Treaty[pWith] := OldTreaty - 1;
     3799    RW[pWith].Treaty[P] := OldTreaty - 1;
    37993800    if OldTreaty = TrFriendlyContact then
    38003801    begin // necessary for loading
    3801       GiveCivilReport(p, pWith);
    3802       GiveCivilReport(pWith, p);
     3802      GiveCivilReport(P, pWith);
     3803      GiveCivilReport(pWith, P);
    38033804    end
    38043805    else if OldTreaty = trAlliance then
    38053806    begin // necessary for loading
    3806       GiveMilReport(p, pWith);
    3807       GiveMilReport(pWith, p);
     3807      GiveMilReport(P, pWith);
     3808      GiveMilReport(pWith, P);
    38083809    end;
    38093810    if (Mode > moLoading_Fast) and (OldTreaty = trAlliance) then
    38103811    begin
    3811       RecalcMapZoC(p);
     3812      RecalcMapZoC(P);
    38123813      RecalcMapZoC(pWith);
    38133814    end;
     
    38153816  if OldTreaty in [trPeace, trAlliance] then
    38163817  begin
    3817     RecalcPeaceMap(p);
     3818    RecalcPeaceMap(P);
    38183819    RecalcPeaceMap(pWith);
    38193820  end;
    38203821end;
    38213822
    3822 function DoSpyMission(p, pCity, cix, Mission: integer): Cardinal;
    3823 var
    3824   p1: integer;
    3825 begin
    3826   result := 0;
     3823function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal;
     3824var
     3825  p1: Integer;
     3826begin
     3827  Result := 0;
    38273828  case Mission of
    38283829    smSabotageProd:
     
    38313832    smStealMap:
    38323833      begin
    3833         CopyMap(pCity, p);
    3834         RecalcPeaceMap(p);
     3834        CopyMap(pCity, P);
     3835        RecalcPeaceMap(P);
    38353836      end;
    38363837    smStealCivilReport:
    38373838      begin
    3838         if RW[p].Treaty[pCity] = trNoContact then
    3839           IntroduceEnemy(p, pCity);
    3840         GiveCivilReport(p, pCity);
     3839        if RW[P].Treaty[pCity] = trNoContact then
     3840          IntroduceEnemy(P, pCity);
     3841        GiveCivilReport(P, pCity);
    38413842      end;
    38423843    smStealMilReport:
    38433844      begin
    3844         if RW[p].Treaty[pCity] = trNoContact then
    3845           IntroduceEnemy(p, pCity);
    3846         GiveMilReport(p, pCity);
     3845        if RW[P].Treaty[pCity] = trNoContact then
     3846          IntroduceEnemy(P, pCity);
     3847        GiveMilReport(P, pCity);
    38473848      end;
    38483849    smStealForeignReports:
    38493850      begin
    38503851        for p1 := 0 to nPl - 1 do
    3851           if (p1 <> p) and (p1 <> pCity) and (RW[pCity].EnemyReport[p1] <> nil)
     3852          if (p1 <> P) and (p1 <> pCity) and (RW[pCity].EnemyReport[p1] <> nil)
    38523853          then
    38533854          begin
    38543855            if RW[pCity].EnemyReport[p1].TurnOfCivilReport >= 0 then
    3855               if CopyCivilReport(pCity, p, p1) then
    3856                 result := result or (1 shl (2 * p1));
     3856              if CopyCivilReport(pCity, P, p1) then
     3857                Result := Result or (1 shl (2 * p1));
    38573858            if RW[pCity].EnemyReport[p1].TurnOfMilReport >= 0 then
    3858               if CopyMilReport(pCity, p, p1) then
    3859                 result := result or (2 shl (2 * p1));
     3859              if CopyMilReport(pCity, P, p1) then
     3860                Result := Result or (2 shl (2 * p1));
    38603861          end;
    38613862      end;
     
    38673868  ____________________________________________________________________
    38683869}
    3869 procedure ClearTestFlags(ClearFlags: integer);
    3870 var
    3871   p1: integer;
     3870procedure ClearTestFlags(ClearFlags: Integer);
     3871var
     3872  p1: Integer;
    38723873begin
    38733874  GTestFlags := GTestFlags and (not ClearFlags or tfTested or tfAllTechs or
     
    38783879end;
    38793880
    3880 procedure SetTestFlags(p, SetFlags: integer);
    3881 var
    3882   i, p1, p2, MoreFlags: integer;
     3881procedure SetTestFlags(P, SetFlags: Integer);
     3882var
     3883  I, p1, p2, MoreFlags: Integer;
    38833884begin
    38843885  MoreFlags := SetFlags and not GTestFlags;
     
    38953896          begin // make p1 and p2 know each other
    38963897            if RW[p1].Treaty[p2] = trNoContact then
    3897               IntroduceEnemy(p1, p2)
     3898              IntroduceEnemy(p1, p2);
    38983899          end;
    38993900
     
    39043905      if 1 shl p1 and GAlive <> 0 then
    39053906      begin
    3906         for i := 0 to nAdv - 1 do // give all techs to player p1
    3907           if not(i in FutureTech) and (RW[p1].Tech[i] < tsApplicable) then
     3907        for I := 0 to nAdv - 1 do // give all techs to player p1
     3908          if not(I in FutureTech) and (RW[p1].Tech[I] < tsApplicable) then
    39083909          begin
    3909             RW[p1].Tech[i] := tsCheat;
    3910             CheckSpecialModels(p1, i);
     3910            RW[p1].Tech[I] := tsCheat;
     3911            CheckSpecialModels(p1, I);
    39113912          end;
    39123913        for p2 := 0 to nPl - 1 do
    39133914          if (p2 <> p1) and (1 shl p2 and (GAlive or GWatching) <> 0) then
    3914             for i := 1 to 3 do
    3915               if RW[p2].EnemyReport[p1].Tech[AgePreq[i]] < tsApplicable then
    3916                 RW[p2].EnemyReport[p1].Tech[AgePreq[i]] := tsCheat;
     3915            for I := 1 to 3 do
     3916              if RW[p2].EnemyReport[p1].Tech[AgePreq[I]] < tsApplicable then
     3917                RW[p2].EnemyReport[p1].Tech[AgePreq[I]] := tsCheat;
    39173918      end;
    39183919    end;
     
    39203921  if MoreFlags and tfUncover <> 0 then
    39213922  begin
    3922     DiscoverAll(p, lObserveSuper);
     3923    DiscoverAll(P, lObserveSuper);
    39233924    for p1 := 0 to nPl - 1 do
    39243925      if 1 shl p1 and GAlive <> 0 then
    39253926      begin
    39263927        ResourceMask[p1] := $FFFFFFFF;
    3927         if p1 <> p then
    3928         begin
    3929           GiveCivilReport(p, p1);
    3930           GiveMilReport(p, p1);
     3928        if p1 <> P then
     3929        begin
     3930          GiveCivilReport(P, p1);
     3931          GiveMilReport(P, p1);
    39313932        end;
    39323933      end;
     
    39383939  ____________________________________________________________________
    39393940}
    3940 procedure IntServer(Command, Player, Subject: integer; var Data);
    3941 var
    3942   i, p1: integer;
    3943 
     3941procedure IntServer(Command, Player, Subject: Integer; var Data);
     3942var
     3943  I, p1: Integer;
    39443944begin
    39453945  if Mode = moPlaying then
     
    39513951      begin
    39523952{$IFDEF TEXTLOG}CmdInfo := Format('IntTellAboutNation P%d+P%d', [Player, Subject]); {$ENDIF}
    3953         assert((Player >= 0) and (Player < nPl) and (Subject >= 0) and
     3953        Assert((Player >= 0) and (Player < nPl) and (Subject >= 0) and
    39543954          (Subject < nPl));
    39553955        IntroduceEnemy(Player, Subject);
     
    39593959      begin
    39603960{$IFDEF TEXTLOG}CmdInfo := Format('IntHaveContact P%d+P%d', [Player, Subject]); {$ENDIF}
    3961         assert(RW[Player].Treaty[Subject] > trNoContact);
     3961        Assert(RW[Player].Treaty[Subject] > trNoContact);
    39623962        RW[Player].EnemyReport[Subject].TurnOfContact := GTurn;
    39633963        RW[Subject].EnemyReport[Player].TurnOfContact := GTurn;
     
    39813981        p1 := (Command - sIntTellAboutModel) shr 4; // told player
    39823982{$IFDEF TEXTLOG}CmdInfo := Format('IntTellAboutModel P%d about P%d Mod%d', [p1, Player, Subject]); {$ENDIF}
    3983         assert((Player >= 0) and (Player < nPl));
    3984         assert((Subject >= 0) and (Subject < RW[Player].nModel));
     3983        Assert((Player >= 0) and (Player < nPl));
     3984        Assert((Subject >= 0) and (Subject < RW[Player].nModel));
    39853985        MakeModelInfo(Player, Subject, RW[Player].Model[Subject],
    39863986          RW[p1].EnemyModel[RW[p1].nEnemyModel]);
    39873987        RWemix[p1, Player, Subject] := RW[p1].nEnemyModel;
    3988         inc(RW[p1].nEnemyModel);
    3989         assert(RW[p1].nEnemyModel < nemmax);
     3988        Inc(RW[p1].nEnemyModel);
     3989        Assert(RW[p1].nEnemyModel < nemmax);
    39903990      end;
    39913991
    39923992    sIntDiscoverZOC:
    39933993      begin
    3994 {$IFDEF TEXTLOG}CmdInfo := Format('IntDiscoverZOC P%d Loc%d', [Player, integer(Data)]); {$ENDIF}
    3995         Discover9(integer(Data), Player, lObserveUnhidden, true, false);
     3994{$IFDEF TEXTLOG}CmdInfo := Format('IntDiscoverZOC P%d Loc%d', [Player, Integer(Data)]); {$ENDIF}
     3995        Discover9(Integer(Data), Player, lObserveUnhidden, True, False);
    39963996      end;
    39973997
     
    40004000      begin
    40014001{$IFDEF TEXTLOG}CmdInfo := Format('IntExpandTerritory P%d Loc%d', [Player, RW[Player].City[Subject].Loc]); {$ENDIF}
    4002         move(Data, BorderChanges, SizeOf(BorderChanges));
     4002        Move(Data, BorderChanges, SizeOf(BorderChanges));
    40034003        ExpandTerritory(RW[Player].City[Subject].Loc);
    40044004      end;
     
    40074007      with RW[Player].City[Subject] do
    40084008      begin
    4009 {$IFDEF TEXTLOG}CmdInfo := Format('IntBuyMaterial P%d Loc%d Cost%d', [Player, Loc, integer(Data)]); {$ENDIF}
    4010         dec(RW[Player].Money, integer(Data));
     4009{$IFDEF TEXTLOG}CmdInfo := Format('IntBuyMaterial P%d Loc%d Cost%d', [Player, Loc, Integer(Data)]); {$ENDIF}
     4010        Dec(RW[Player].Money, Integer(Data));
    40114011        if (GWonder[woMich].EffectiveOwner = Player) and (Project and cpImp <> 0)
    40124012        then
    4013           inc(Prod, integer(Data) div 2)
     4013          Inc(Prod, Integer(Data) div 2)
    40144014        else
    4015           inc(Prod, integer(Data) div 4);
     4015          Inc(Prod, Integer(Data) div 4);
    40164016        if Project0 and not cpAuto <> Project and not cpAuto then
    40174017          Project0 := Project;
     
    40224022      begin
    40234023{$IFDEF TEXTLOG}CmdInfo := Format('IntPayPrices P%d+P%d', [Player, Subject]); {$ENDIF}
    4024         for i := 0 to TOffer(Data).nDeliver - 1 do
    4025           PayPrice(Player, Subject, TOffer(Data).Price[i], true);
    4026         for i := 0 to TOffer(Data).nCost - 1 do
     4024        for I := 0 to TOffer(Data).nDeliver - 1 do
     4025          PayPrice(Player, Subject, TOffer(Data).Price[I], True);
     4026        for I := 0 to TOffer(Data).nCost - 1 do
    40274027          PayPrice(Subject, Player, TOffer(Data).Price[TOffer(Data).nDeliver
    4028             + i], true);
    4029         for i := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    4030           if TOffer(Data).Price[i] = opTreaty + trAlliance then
     4028            + I], True);
     4029        for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
     4030          if TOffer(Data).Price[I] = opTreaty + trAlliance then
    40314031          begin // add view area of allied player
    40324032            DiscoverViewAreas(Player);
    40334033            DiscoverViewAreas(Subject);
    4034             Break
    4035           end
     4034            Break;
     4035          end;
    40364036      end;
    40374037
    40384038    sIntSetDevModel:
    40394039      if Mode < moPlaying then
    4040         move(Data, RW[Player].DevModel.Kind, sIntSetDevModel and $F * 4);
     4040        Move(Data, RW[Player].DevModel.Kind, sIntSetDevModel and $F * 4);
    40414041
    40424042    sIntSetModelStatus:
     
    40454045{$IFDEF TEXTLOG}CmdInfo := Format('IntSetModelStatus P%d', [Player]);
    40464046        {$ENDIF}
    4047         RW[Player].Model[Subject].Status := integer(Data);
     4047        RW[Player].Model[Subject].Status := Integer(Data);
    40484048      end;
    40494049
     
    40534053{$IFDEF TEXTLOG}CmdInfo := Format('IntSetUnitStatus P%d', [Player]);
    40544054        {$ENDIF}
    4055         RW[Player].Un[Subject].Status := integer(Data);
     4055        RW[Player].Un[Subject].Status := Integer(Data);
    40564056      end;
    40574057
     
    40614061{$IFDEF TEXTLOG}CmdInfo := Format('IntSetCityStatus P%d', [Player]);
    40624062        {$ENDIF}
    4063         RW[Player].City[Subject].Status := integer(Data);
     4063        RW[Player].City[Subject].Status := Integer(Data);
    40644064      end;
    40654065
     
    40694069{$IFDEF TEXTLOG}CmdInfo := Format('IntSetECityStatus P%d', [Player]);
    40704070        {$ENDIF}
    4071         RW[Player].EnemyCity[Subject].Status := integer(Data);
    4072       end;
    4073 
    4074   end; { case command }
    4075 end; { IntServer }
     4071        RW[Player].EnemyCity[Subject].Status := Integer(Data);
     4072      end;
     4073  end;
     4074end;
    40764075
    40774076end.
  • branches/highdpi/Direct.lfm

    r246 r465  
    88  Caption = 'C-evo'
    99  Color = clBtnFace
    10   DesignTimePPI = 125
     10  DesignTimePPI = 144
    1111  Font.Color = clWindowText
    12   Font.Height = -13
     12  Font.Height = -20
    1313  Font.Name = 'MS Sans Serif'
    1414  FormStyle = fsStayOnTop
     
    1717  OnPaint = FormPaint
    1818  OnShow = FormShow
    19   LCLVersion = '1.8.0.6'
    20   PixelsPerInch = 96
     19  ShowInTaskBar = stNever
     20  LCLVersion = '2.2.6.0'
    2121  Scaled = False
    2222end
  • branches/highdpi/Direct.pas

    r405 r465  
    77  UDpiControls, Messg,
    88
    9   LCLIntf, LCLType, {$IFDEF Linux}LMessages, {$ENDIF}Messages, SysUtils, Classes,
     9  LCLIntf, LCLType, {$IFDEF UNIX}LMessages, {$ENDIF}Messages, SysUtils, Classes,
    1010  Graphics, Controls, Forms, DrawDlg, GameServer;
    1111
     
    2929    Gone: Boolean;
    3030    Quick: Boolean;
    31     procedure SetInfo(x: string);
    32     procedure SetState(x: integer);
     31    procedure SetInfo(X: string);
     32    procedure SetState(X: Integer);
    3333    procedure OnGo(var Msg: TMessage); message WM_GO;
    3434    procedure OnChangeClient(var Msg: TMessage); message WM_CHANGECLIENT;
     
    4040  DirectDlg: TDirectDlg;
    4141
     42
    4243implementation
    4344
    4445uses
    45   ScreenTools, Protocol, Start, LocalPlayer, NoTerm, Back, Global, UNetworkServer,
    46   UNetworkClient;
     46  ScreenTools, Protocol, Start, LocalPlayer, NoTerm, Back, Global, NetworkServer,
     47  NetworkClient;
    4748
    4849{$R *.lfm}
     
    5758//  hMem: Cardinal;
    5859//  p: pointer;
    59   s: string;
     60  S: string;
    6061Begin
    6162  case ID of
     
    7273      if visible then
    7374      begin
    74         s := Format(Phrases.Lookup('BUSY_MOD'), [Brains[Index].Name]);
    75         while BiColorTextWidth(Canvas, s) + 64 > ClientWidth do
    76           Delete(s, Length(s), 1);
    77         SetInfo(s);
     75        S := Format(Phrases.Lookup('BUSY_MOD'), [Brains[Index].Name]);
     76        while BiColorTextWidth(Canvas, S) + 64 > ClientWidth do
     77          Delete(S, Length(S), 1);
     78        SetInfo(S);
    7879      end;
    7980    ntCreateWorld:
     
    111112          hMem := GlobalAlloc(GMEM_MOVEABLE or GMEM_DDESHARE,
    112113            Length(NotifyMessage));
    113           p := GlobalLock(hMem);
    114           if p <> nil then
    115             move(NotifyMessage[1], p^, Length(NotifyMessage));
     114          P := GlobalLock(hMem);
     115          if P <> nil then
     116            Move(NotifyMessage[1], P^, Length(NotifyMessage));
    116117          GlobalUnlock(hMem);
    117118          SetClipboardData(CF_TEXT, hMem);
     
    153154        State := -1;
    154155        Show;
    155         {$IFDEF LINUX}
    156         // Force shown window repaint on Gtk2 widgetset
    157         Sleep(1);
    158         DpiApplication.ProcessMessages;
    159         {$ENDIF}
     156        Gtk2Fix;
    160157        Invalidate;
    161158        Update;
     
    183180  BrainTerm.Name := Phrases.Lookup('HUMAN');
    184181  if NetworkEnabled then begin
    185     BrainNetworkServer.Client := UNetworkServer.Client;
     182    BrainNetworkServer.Client := NetworkServer.Client;
    186183    BrainNetworkServer.Name := Phrases.Lookup('NETWORK_SERVER');
    187     BrainNetworkClient.Client := UNetworkClient.Client;
     184    BrainNetworkClient.Client := NetworkClient.Client;
    188185    BrainNetworkClient.Name := Phrases.Lookup('NETWORK_CLIENT');
    189186  end;
     
    198195  begin
    199196    PostMessage(Handle, WM_GO, 0, 0);
    200     Gone := true;
     197    Gone := True;
    201198  end;
    202199end;
     
    209206procedure TDirectDlg.OnGo(var Msg: TMessage);
    210207var
    211   i: integer;
    212   s: string;
     208  I: Integer;
     209  S: string;
    213210  FileName: string;
    214211begin
     
    220217    Exit;
    221218  end;
    222   Quick := false;
     219  Quick := False;
    223220  if ParamCount > 0 then
    224221  begin
    225     s := ParamStr(1);
    226     if (s[1] = '-') {$IFDEF WINDOWS}or (s[1] = '/'){$ENDIF} then
     222    S := ParamStr(1);
     223    if (S[1] = '-') {$IFDEF WINDOWS}or (S[1] = '/'){$ENDIF} then
    227224    begin // special mode
    228       Delete(s, 1, 1);
    229       for i := 1 to Length(s) do
    230         if s[i] in ['a' .. 'z'] then
    231           dec(s[i], 32);
    232       if s = 'MAN' then
     225      Delete(S, 1, 1);
     226      for I := 1 to Length(S) do
     227        if S[I] in ['a' .. 'z'] then
     228          Dec(S[I], 32);
     229      if S = 'MAN' then
    233230      begin
    234         Quick := true;
     231        Quick := True;
    235232        DirectHelp(cHelpOnly);
    236233        Close;
     
    242239        Quick := True;
    243240        if not LoadGame(ExtractFilePath(ParamStr(1)), ExtractFileName(ParamStr(1)
    244         ), -1, false) then begin
     241        ), -1, False) then begin
    245242          SimpleMessage(Phrases.Lookup('LOADERR'));
    246243          Close;
     
    280277procedure TDirectDlg.FormPaint(Sender: TObject);
    281278begin
    282   PaintBackground(self, 3, 3, ClientWidth - 6, ClientHeight - 6);
     279  PaintBackground(Self, 3, 3, ClientWidth - 6, ClientHeight - 6);
    283280  Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
    284281  Frame(Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
     
    297294end;
    298295
    299 procedure TDirectDlg.SetInfo(x: string);
    300 begin
    301   Info := x;
     296procedure TDirectDlg.SetInfo(X: string);
     297begin
     298  Info := X;
    302299  Invalidate;
    303300  Update;
    304   {$IFDEF LINUX}
     301  {$IFDEF UNIX}
    305302  DpiApplication.ProcessMessages;
    306303  {$ENDIF}
    307304end;
    308305
    309 procedure TDirectDlg.SetState(x: integer);
    310 begin
    311   if (x < 0) <> (State < 0) then begin
    312     State := x;
     306procedure TDirectDlg.SetState(X: Integer);
     307begin
     308  if (X < 0) <> (State < 0) then begin
     309    State := X;
    313310    Invalidate;
    314311    Update;
    315312  end
    316   else if x <> State then begin
    317     State := x;
     313  else if X <> State then begin
     314    State := X;
    318315    PaintProgressBar(Canvas, 6, ClientWidth div 2 - 64, 40, State, 128 - State,
    319316      128, MainTexture);
  • branches/highdpi/GameServer.pas

    r405 r465  
    77
    88uses
    9   Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils,
    10   Graphics, UBrain, Global;
     9  Protocol, Database, dynlibs, Platform, dateutils, LazFileUtils, Graphics,
     10  Brain, Global;
    1111
    1212const
     
    4949  // PARAMETERS
    5050  PlayersBrain: TBrains; { brain of the players view }
    51   Difficulty: array [0 .. nPl - 1] of integer absolute Database.Difficulty;
     51  Difficulty: array [0 .. nPl - 1] of Integer absolute Database.Difficulty;
    5252  { difficulty }
    5353
     
    7070
    7171procedure StartNewGame(const Path, FileName, Map: string;
    72   Newlx, Newly, NewLandMass, NewMaxTurn: integer);
    73 function LoadGame(const Path, FileName: string; Turn: integer;
    74   MovieMode: boolean): boolean;
    75 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: integer);
    76 procedure DirectHelp(Command: integer);
     72  Newlx, Newly, NewLandMass, NewMaxTurn: Integer);
     73function LoadGame(const Path, FileName: string; Turn: Integer;
     74  MovieMode: Boolean): Boolean;
     75procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer);
     76procedure DirectHelp(Command: Integer);
    7777
    7878procedure ChangeClient;
    7979procedure NextPlayer;
    80 function PreviewMap(lm: integer): pointer;
     80function PreviewMap(lm: Integer): Pointer;
    8181
    8282
     
    112112  MapField: ^Cardinal; // predefined map
    113113  LastOffer: TOffer;
    114   CCData: array [0 .. 14] of integer;
     114  CCData: array [0 .. 14] of Integer;
    115115  bix: TBrains; { brain of the players }
    116116  DevModelTurn: array [0 .. nPl - 1] of Integer; { turn of last call to sResetModel }
    117117  OriginalDataVersion: array [0 .. nPl - 1] of Integer;
    118118  SavedTiles { , SavedResourceWeights } : array [0 .. ncmax - 1] of Cardinal;
    119   SavedData: array [0 .. nPl - 1] of pointer;
     119  SavedData: array [0 .. nPl - 1] of Pointer;
    120120  LogFileName: string;
    121121  SavePath: string; { name of file for saving the current game }
     
    135135  PreviewRND = 41601260; { randseed for preview map }
    136136
    137 function Server(Command, Player, Subject: integer; var Data): integer;
     137function Server(Command, Player, Subject: Integer; var Data): Integer;
    138138  stdcall; forward;
    139139
    140 procedure CallPlayer(Command, p: integer; var Data);
     140procedure CallPlayer(Command, P: Integer; var Data);
    141141begin
    142   if ((Mode <> moMovie) or (p = 0)) then
     142  if ((Mode <> moMovie) or (P = 0)) then
    143143  begin
    144144{$IFOPT O-}
    145     HandoverStack[nHandoverStack] := p;
     145    HandoverStack[nHandoverStack] := P;
    146146    HandoverStack[nHandoverStack + 1] := Command;
    147     inc(nHandoverStack, 2);
    148     bix[p].Client(Command, p, Data);
    149     dec(nHandoverStack, 2);
     147    Inc(nHandoverStack, 2);
     148    bix[P].Client(Command, P, Data);
     149    Dec(nHandoverStack, 2);
    150150{$ELSE}
    151151    try
    152       bix[p].Client(Command, p, Data);
     152      bix[P].Client(Command, P, Data);
    153153    except
    154       Notify(ntException + bix[p]);
     154      Notify(ntException + bix[P]);
    155155    end;
    156156{$ENDIF}
    157   end
     157  end;
    158158end;
    159159
     
    167167end;
    168168
    169 procedure CallClient(bix, Command: integer; var Data);
     169procedure CallClient(bix, Command: Integer; var Data);
    170170begin
    171171  if ((Mode <> moMovie) or (bix = Brains.IndexOf(GameServer.bix[0]))) then
     
    174174    HandoverStack[nHandoverStack] := bix;
    175175    HandoverStack[nHandoverStack + 1] := Command;
    176     inc(nHandoverStack, 2);
     176    Inc(nHandoverStack, 2);
    177177    Brains[bix].Client(Command, -1, Data);
    178     dec(nHandoverStack, 2);
     178    Dec(nHandoverStack, 2);
    179179{$ELSE}
    180180    try
     
    189189procedure Init(NotifyFunction: TNotifyFunction);
    190190var
    191   f: TSearchRec;
     191  F: TSearchRec;
    192192  BasePath: string;
    193193  NewBrain: TBrain;
     
    195195begin
    196196  Notify := NotifyFunction;
    197   PreviewElevation := false;
     197  PreviewElevation := False;
    198198  PlayersBrain := TBrains.Create(False);
    199199  PlayersBrain.Count := nPl;
     
    246246  end;
    247247
    248   if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, f) = 0 then
     248  if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, F) = 0 then
    249249  repeat
    250     BasePath := GetAiDir + DirectorySeparator + f.Name;
    251     if (f.Name <> '.') and (f.Name <> '..') and DirectoryExists(BasePath) then begin
     250    BasePath := GetAiDir + DirectorySeparator + F.Name;
     251    if (F.Name <> '.') and (F.Name <> '..') and DirectoryExists(BasePath) then begin
    252252      NewBrain := Brains.AddNew;
    253253      NewBrain.Kind := btAI;
     
    258258        end else Brains.Delete(Brains.Count - 1);
    259259    end;
    260   until FindNext(f) <> 0;
     260  until FindNext(F) <> 0;
    261261  FindClose(F);
    262262
     
    281281end;
    282282
    283 function PreviewMap(lm: integer): pointer;
     283function PreviewMap(lm: Integer): Pointer;
    284284begin
    285285  lx := lxmax;
     
    291291  begin
    292292    CreateElevation;
    293     PreviewElevation := true;
     293    PreviewElevation := True;
    294294  end;
    295   CreateMap(true);
     295  CreateMap(True);
    296296  Result := @RealMap;
    297297end;
    298298
    299 procedure ChangeClientWhenDone(Command, Player: integer; var Data;
    300   DataSize: integer);
     299procedure ChangeClientWhenDone(Command, Player: Integer; var Data;
     300  DataSize: Integer);
    301301begin
    302302  CCCommand := Command;
    303303  CCPlayer := Player;
    304304  if DataSize > 0 then
    305     move(Data, CCData, DataSize);
     305    Move(Data, CCData, DataSize);
    306306  Notify(ntChangeClient);
    307307end;
    308308
    309 procedure PutMessage(Level: integer; Text: string);
     309procedure PutMessage(Level: Integer; Text: string);
    310310begin
    311   bix[0].Client(cDebugMessage, Level, pchar(Text)^);
     311  bix[0].Client(cDebugMessage, Level, PChar(Text)^);
    312312end;
    313313
     
    336336// hand over control to other client (as specified by CC...)
    337337var
    338   p: integer;
     338  P: Integer;
    339339  T: TDateTime;
    340340begin
     
    346346    [CCPlayer, bix[CCPlayer].Name]));
    347347  if CCCommand = cTurn then
    348     for p := 0 to nPl - 1 do
    349       if (p <> CCPlayer) and (1 shl p and GWatching <> 0) then
    350         CallPlayer(cShowTurnChange, p, CCPlayer);
    351 
    352   p := CCPlayer;
     348    for P := 0 to nPl - 1 do
     349      if (P <> CCPlayer) and (1 shl P and GWatching <> 0) then
     350        CallPlayer(cShowTurnChange, P, CCPlayer);
     351
     352  P := CCPlayer;
    353353  CCPlayer := -1;
    354   CallPlayer(CCCommand, p, CCData);
    355   if (Mode = moPlaying) and (bix[p].Flags and aiThreaded = 0) and
     354  CallPlayer(CCCommand, P, CCData);
     355  if (Mode = moPlaying) and (bix[P].Flags and aiThreaded = 0) and
    356356    (CCPlayer < 0) then
    357357  begin
    358     Notify(ntDeactivationMissing, p);
     358    Notify(ntDeactivationMissing, P);
    359359    ForceClientDeactivation;
    360360  end;
    361361end;
    362362
    363 procedure Inform(p: integer);
     363procedure Inform(P: Integer);
    364364var
    365   i, p1: integer;
     365  I, p1: Integer;
    366366begin
    367   RW[p].Turn := GTurn;
    368   if (GTurn = MaxTurn) and (p = pTurn) and (p = 0) then
    369     RW[p].Happened := RW[p].Happened or phTimeUp;
    370   if (GWinner > 0) and (p = pTurn) and (p = 0) then
    371     RW[p].Happened := RW[p].Happened or phShipComplete;
    372   RW[p].Alive := GAlive;
    373   move(GWonder, RW[p].Wonder, SizeOf(GWonder));
    374   move(GShip, RW[p].Ship, SizeOf(GShip));
     367  RW[P].Turn := GTurn;
     368  if (GTurn = MaxTurn) and (P = pTurn) and (P = 0) then
     369    RW[P].Happened := RW[P].Happened or phTimeUp;
     370  if (GWinner > 0) and (P = pTurn) and (P = 0) then
     371    RW[P].Happened := RW[P].Happened or phShipComplete;
     372  RW[P].Alive := GAlive;
     373  Move(GWonder, RW[P].Wonder, SizeOf(GWonder));
     374  Move(GShip, RW[P].Ship, SizeOf(GShip));
    375375  for p1 := 0 to nPl - 1 do
    376     if (p1 <> p) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then
    377       RW[p].EnemyReport[p1].Credibility := RW[p1].Credibility;
     376    if (p1 <> P) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then
     377      RW[P].EnemyReport[p1].Credibility := RW[p1].Credibility;
    378378  for p1 := 0 to nPl - 1 do
    379     if (p1 <> p) and (1 shl p1 and GAlive <> 0) then
     379    if (p1 <> P) and (1 shl p1 and GAlive <> 0) then
    380380    begin
    381       if (GTestFlags and tfUncover <> 0) or (Difficulty[p] = 0) or
    382         (RW[p].Treaty[p1] >= trFriendlyContact) then
    383         GiveCivilReport(p, p1);
    384       if (GTestFlags and tfUncover <> 0) or (Difficulty[p] = 0) or
    385         (RW[p].Treaty[p1] = trAlliance) then
    386         GiveMilReport(p, p1)
     381      if (GTestFlags and tfUncover <> 0) or (Difficulty[P] = 0) or
     382        (RW[P].Treaty[p1] >= trFriendlyContact) then
     383        GiveCivilReport(P, p1);
     384      if (GTestFlags and tfUncover <> 0) or (Difficulty[P] = 0) or
     385        (RW[P].Treaty[p1] = trAlliance) then
     386        GiveMilReport(P, p1)
    387387    end;
    388   for i := 0 to RW[p].nEnemyModel - 1 do
    389     with RW[p].EnemyModel[i] do
    390       Lost := Destroyed[p, Owner, mix];
     388  for I := 0 to RW[P].nEnemyModel - 1 do
     389    with RW[P].EnemyModel[I] do
     390      Lost := Destroyed[P, Owner, mix];
    391391end;
    392392
    393393procedure LogChanges;
    394394var
    395   p, ix: integer;
     395  P, ix: Integer;
    396396begin
    397   for p := 0 to nPl - 1 do
    398     if (1 shl p and GWatching <> 0) and ProcessClientData[p] then
     397  for P := 0 to nPl - 1 do
     398    if (1 shl P and GWatching <> 0) and ProcessClientData[P] then
    399399    begin
    400400      // log unit status changes
    401       for ix := 0 to RW[p].nUn - 1 do
    402         with RW[p].Un[ix] do
     401      for ix := 0 to RW[P].nUn - 1 do
     402        with RW[P].Un[ix] do
    403403          if (Loc >= 0) and (SavedStatus <> Status) then
    404404          begin
    405             CL.Put(sIntSetUnitStatus, p, ix, @Status);
     405            CL.Put(sIntSetUnitStatus, P, ix, @Status);
    406406            SavedStatus := Status;
    407407          end;
    408408      // log city status changes
    409       for ix := 0 to RW[p].nCity - 1 do
    410         with RW[p].City[ix] do
     409      for ix := 0 to RW[P].nCity - 1 do
     410        with RW[P].City[ix] do
    411411          if (Loc >= 0) and (SavedStatus <> Status) then
    412412          begin
    413             CL.Put(sIntSetCityStatus, p, ix, @Status);
     413            CL.Put(sIntSetCityStatus, P, ix, @Status);
    414414            SavedStatus := Status;
    415415          end;
    416416      // log model status changes
    417       for ix := 0 to RW[p].nModel - 1 do
    418         with RW[p].Model[ix] do
     417      for ix := 0 to RW[P].nModel - 1 do
     418        with RW[P].Model[ix] do
    419419          if SavedStatus <> Status then
    420420          begin
    421             CL.Put(sIntSetModelStatus, p, ix, @Status);
     421            CL.Put(sIntSetModelStatus, P, ix, @Status);
    422422            SavedStatus := Status;
    423423          end;
    424424      // log enemy city status changes
    425       for ix := 0 to RW[p].nEnemyCity - 1 do
    426         with RW[p].EnemyCity[ix] do
     425      for ix := 0 to RW[P].nEnemyCity - 1 do
     426        with RW[P].EnemyCity[ix] do
    427427          if (Loc >= 0) and (SavedStatus <> Status) then
    428428          begin
    429             CL.Put(sIntSetECityStatus, p, ix, @Status);
     429            CL.Put(sIntSetECityStatus, P, ix, @Status);
    430430            SavedStatus := Status;
    431431          end;
    432432      // log data changes
    433       if bix[p].DataSize > 0 then
    434       begin
    435         CL.PutDataChanges(sIntDataChange, p, SavedData[p], RW[p].Data,
    436           bix[p].DataSize);
    437         Move(RW[p].Data^, SavedData[p]^, bix[p].DataSize * 4);
     433      if bix[P].DataSize > 0 then
     434      begin
     435        CL.PutDataChanges(sIntDataChange, P, SavedData[P], RW[P].Data,
     436          bix[P].DataSize);
     437        Move(RW[P].Data^, SavedData[P]^, bix[P].DataSize * 4);
    438438      end;
    439439    end;
     
    442442procedure NoLogChanges;
    443443var
    444   p, ix: integer;
     444  P, ix: Integer;
    445445begin
    446   for p := 0 to nPl - 1 do
    447     if (1 shl p and GWatching <> 0) and ProcessClientData[p] then
     446  for P := 0 to nPl - 1 do
     447    if (1 shl P and GWatching <> 0) and ProcessClientData[P] then
    448448    begin
    449       for ix := 0 to RW[p].nUn - 1 do
    450         with RW[p].Un[ix] do
     449      for ix := 0 to RW[P].nUn - 1 do
     450        with RW[P].Un[ix] do
    451451          SavedStatus := Status;
    452       for ix := 0 to RW[p].nCity - 1 do
    453         with RW[p].City[ix] do
     452      for ix := 0 to RW[P].nCity - 1 do
     453        with RW[P].City[ix] do
    454454          SavedStatus := Status;
    455       for ix := 0 to RW[p].nModel - 1 do
    456         with RW[p].Model[ix] do
     455      for ix := 0 to RW[P].nModel - 1 do
     456        with RW[P].Model[ix] do
    457457          SavedStatus := Status;
    458       for ix := 0 to RW[p].nEnemyCity - 1 do
    459         with RW[p].EnemyCity[ix] do
     458      for ix := 0 to RW[P].nEnemyCity - 1 do
     459        with RW[P].EnemyCity[ix] do
    460460          SavedStatus := Status;
    461       if bix[p].DataSize > 0 then
    462         Move(RW[p].Data^, SavedData[p]^, bix[p].DataSize * 4);
     461      if bix[P].DataSize > 0 then
     462        Move(RW[P].Data^, SavedData[P]^, bix[P].DataSize * 4);
    463463    end;
    464464end;
    465465
    466 function HasChanges(p: integer): boolean;
     466function HasChanges(P: Integer): Boolean;
    467467type
    468468  TDWordList = array [0 .. INFIN] of Cardinal;
    469469  PDWortList = ^TDWordList;
    470470var
    471   ix: integer;
     471  ix: Integer;
    472472begin
    473473  Result := False;
    474   for ix := 0 to RW[p].nUn - 1 do
    475     with RW[p].Un[ix] do
     474  for ix := 0 to RW[P].nUn - 1 do
     475    with RW[P].Un[ix] do
    476476      if (Loc >= 0) and (SavedStatus <> Status) then
    477477        Result := True;
    478   for ix := 0 to RW[p].nCity - 1 do
    479     with RW[p].City[ix] do
     478  for ix := 0 to RW[P].nCity - 1 do
     479    with RW[P].City[ix] do
    480480      if (Loc >= 0) and (SavedStatus <> Status) then
    481481        Result := True;
    482   for ix := 0 to RW[p].nModel - 1 do
    483     with RW[p].Model[ix] do
     482  for ix := 0 to RW[P].nModel - 1 do
     483    with RW[P].Model[ix] do
    484484      if SavedStatus <> Status then
    485485        Result := True;
    486   for ix := 0 to RW[p].nEnemyCity - 1 do
    487     with RW[p].EnemyCity[ix] do
     486  for ix := 0 to RW[P].nEnemyCity - 1 do
     487    with RW[P].EnemyCity[ix] do
    488488      if (Loc >= 0) and (SavedStatus <> Status) then
    489489        Result := True;
    490   if RW[p].Data <> nil then
    491     for ix := 0 to bix[p].DataSize - 1 do
    492       if PDWortList(SavedData[p])[ix] <> PDWortList(RW[p].Data)[ix] then
     490  if RW[P].Data <> nil then
     491    for ix := 0 to bix[P].DataSize - 1 do
     492      if PDWortList(SavedData[P])[ix] <> PDWortList(RW[P].Data)[ix] then
    493493        Result := True;
    494494end;
     
    498498  InitModuleData: TInitModuleData;
    499499begin
    500   assert(bix.Kind <> btSuperVirtual);
     500  Assert(bix.Kind <> btSuperVirtual);
    501501  with bix do begin
    502502    if Initialized then
    503       exit;
     503      Exit;
    504504    if Kind = btAI then
    505505    begin { get client function }
     
    509509      else
    510510      begin
    511         hm := LoadLibrary(pchar(DLLName));
     511        hm := LoadLibrary(PChar(DLLName));
    512512        if hm = 0 then
    513513        begin
     
    525525    if @Client <> nil then
    526526    begin
    527       Initialized := true;
     527      Initialized := True;
    528528      InitModuleData.Server := @Server;
    529529      InitModuleData.DataVersion := 0;
     
    542542procedure SaveMap(FileName: string);
    543543var
    544   i: integer;
     544  I: Integer;
    545545  MapFile: TFileStream;
    546   s: string[255];
     546  S: string[255];
    547547begin
    548548  MapFile := TFileStream.Create(GetMapsDir + DirectorySeparator + FileName,
     
    550550  try
    551551    MapFile.Position := 0;
    552     s := 'cEvoMap'#0;
    553     MapFile.write(s[1], 8); { file id }
    554     i := 0;
    555     MapFile.write(i, 4); { format id }
    556     MapFile.write(MaxTurn, 4);
    557     MapFile.write(lx, 4);
    558     MapFile.write(ly, 4);
    559     MapFile.write(RealMap, MapSize * 4);
     552    S := 'cEvoMap'#0;
     553    MapFile.Write(S[1], 8); { file id }
     554    I := 0;
     555    MapFile.Write(I, 4); { format id }
     556    MapFile.Write(MaxTurn, 4);
     557    MapFile.Write(lx, 4);
     558    MapFile.Write(ly, 4);
     559    MapFile.Write(RealMap, MapSize * 4);
    560560  finally
    561561    FreeAndNil(MapFile);
     
    563563end;
    564564
    565 function LoadMap(FileName: string): boolean;
     565function LoadMap(FileName: string): Boolean;
    566566var
    567   i, Loc1: integer;
     567  I, Loc1: Integer;
    568568  MapFile: TFileStream;
    569   s: string[255];
     569  S: string[255];
    570570begin
    571   result := false;
     571  Result := False;
    572572  MapFile := nil;
    573573  try
    574574    MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive);
    575575    MapFile.Position := 0;
    576     MapFile.read(s[1], 8); { file id }
    577     MapFile.read(i, 4); { format id }
    578     if i = 0 then
     576    MapFile.Read(S[1], 8); { file id }
     577    MapFile.Read(I, 4); { format id }
     578    if I = 0 then
    579579    begin
    580       MapFile.read(i, 4); // MaxTurn
    581       MapFile.read(lx, 4);
    582       MapFile.read(ly, 4);
     580      MapFile.Read(I, 4); // MaxTurn
     581      MapFile.Read(lx, 4);
     582      MapFile.Read(ly, 4);
    583583      ly := ly and not 1;
    584584      if lx > lxmax then
     
    587587        ly := lymax;
    588588      MapSize := lx * ly;
    589       MapFile.read(RealMap, MapSize * 4);
     589      MapFile.Read(RealMap, MapSize * 4);
    590590      for Loc1 := 0 to MapSize - 1 do
    591591      begin
     
    600600            or fDesert;
    601601      end;
    602       result := true;
     602      Result := True;
    603603    end;
    604604    FreeAndNil(MapFile);
     
    609609end;
    610610
    611 procedure SaveGame(FileName: string; auto: boolean);
     611procedure SaveGame(FileName: string; Auto: Boolean);
    612612var
    613   x, y, i, zero, Tile, nLocal: integer;
     613  X, Y, I, zero, Tile, nLocal: Integer;
    614614  LogFile: TFileStream;
    615   s: string[255];
     615  S: string[255];
    616616  SaveMap: array [0 .. lxmax * lymax - 1] of Byte;
    617617begin
    618618  nLocal := 0;
    619   for i := 0 to nPl - 1 do
    620     if Assigned(bix[i]) and (bix[i].Kind = btTerm) then
    621       inc(nLocal);
     619  for I := 0 to nPl - 1 do
     620    if Assigned(bix[I]) and (bix[I].Kind = btTerm) then
     621      Inc(nLocal);
    622622  if Difficulty[0] = 0 then
    623623    nLocal := 0;
    624624  if nLocal <= 1 then
    625     for y := 0 to ly - 1 do
    626       for x := 0 to lx - 1 do
    627       begin
    628         Tile := RW[0].Map[(x + SaveMapCenterLoc + lx shr 1) mod lx + lx * y];
    629         SaveMap[x + lx * y] := Tile and fTerrain + Tile and
     625    for Y := 0 to ly - 1 do
     626      for X := 0 to lx - 1 do
     627      begin
     628        Tile := RW[0].Map[(X + SaveMapCenterLoc + lx shr 1) mod lx + lx * Y];
     629        SaveMap[X + lx * Y] := Tile and fTerrain + Tile and
    630630          (fCity or fUnit or fOwned) shr 16;
    631631      end;
    632632
    633   if auto and AutoSaveExists then // append to existing file
     633  if Auto and AutoSaveExists then // append to existing file
    634634    LogFile := TFileStream.Create(SavePath + FileName, fmOpenReadWrite or
    635635      fmShareExclusive)
     
    640640  zero := 0;
    641641  LogFile.Position := 0;
    642   s := 'cEvoBook';
    643   LogFile.write(s[1], 8); { file id }
    644   i := CevoVersion;
    645   LogFile.write(i, 4); { c-evo version }
    646   LogFile.write(ExeInfo.Time, 4);
    647   LogFile.write(lx, 4);
    648   LogFile.write(ly, 4);
    649   LogFile.write(LandMass, 4);
     642  S := 'cEvoBook';
     643  LogFile.Write(S[1], 8); { file id }
     644  I := CevoVersion;
     645  LogFile.Write(I, 4); { c-evo version }
     646  LogFile.Write(ExeInfo.Time, 4);
     647  LogFile.Write(lx, 4);
     648  LogFile.Write(ly, 4);
     649  LogFile.Write(LandMass, 4);
    650650  if LandMass = 0 then
    651     LogFile.write(MapField^, MapSize * 4);
    652 
    653   LogFile.write(MaxTurn, 4);
    654   LogFile.write(RND, 4);
    655   LogFile.write(GTurn, 4);
     651    LogFile.Write(MapField^, MapSize * 4);
     652
     653  LogFile.Write(MaxTurn, 4);
     654  LogFile.Write(RND, 4);
     655  LogFile.Write(GTurn, 4);
    656656  if nLocal > 1 then // multiplayer game -- no quick view
    657657  begin
    658     i := $80;
    659     LogFile.write(i, 4);
     658    I := $80;
     659    LogFile.Write(I, 4);
    660660  end
    661661  else
    662     LogFile.write(SaveMap, ((MapSize - 1) div 4 + 1) * 4);
    663   for i := 0 to nPl - 1 do
    664     if not Assigned(bix[i]) then
    665       LogFile.write(zero, 4)
     662    LogFile.Write(SaveMap, ((MapSize - 1) div 4 + 1) * 4);
     663  for I := 0 to nPl - 1 do
     664    if not Assigned(bix[I]) then
     665      LogFile.Write(zero, 4)
    666666    else
    667667    begin
    668       if PlayersBrain[i].Kind in [btRandom, btAI] then
    669         s := bix[i].FileName
    670       else
    671         s := PlayersBrain[i].FileName;
    672       move(zero, s[Length(s) + 1], 4);
    673       LogFile.write(s, (Length(s) div 4 + 1) * 4);
    674       LogFile.write(OriginalDataVersion[i], 4);
    675       s := ''; { behavior }
    676       move(zero, s[Length(s) + 1], 4);
    677       LogFile.write(s, (Length(s) div 4 + 1) * 4);
    678       LogFile.write(Difficulty[i], 4);
     668      if PlayersBrain[I].Kind in [btRandom, btAI] then
     669        S := bix[I].FileName
     670      else
     671        S := PlayersBrain[I].FileName;
     672      Move(zero, S[Length(S) + 1], 4);
     673      LogFile.Write(S, (Length(S) div 4 + 1) * 4);
     674      LogFile.Write(OriginalDataVersion[I], 4);
     675      S := ''; { behavior }
     676      Move(zero, S[Length(S) + 1], 4);
     677      LogFile.Write(S, (Length(S) div 4 + 1) * 4);
     678      LogFile.Write(Difficulty[I], 4);
    679679    end;
    680680
    681   if auto and AutoSaveExists then
     681  if Auto and AutoSaveExists then
    682682    CL.AppendToFile(LogFile, AutoSaveState)
    683683  else
    684684    CL.SaveToFile(LogFile);
    685685  FreeAndNil(LogFile);
    686   if auto then
     686  if Auto then
    687687  begin
    688688    AutoSaveState := CL.State;
    689     AutoSaveExists := true;
     689    AutoSaveExists := True;
    690690  end
    691691end;
     
    693693procedure StartGame;
    694694var
    695   i, p, p1, Human, nAlive, bixUni: integer;
     695  I, P, p1, Human, nAlive, bixUni: Integer;
    696696  Game: TNewGameData;
    697697  // GameEx: TNewGameExData;
     
    722722
    723723  BrainUsed := [];
    724   for p := 0 to nPl - 1 do
    725     if Assigned(bix[p]) and ((Mode <> moMovie) or (p = 0)) then
     724  for P := 0 to nPl - 1 do
     725    if Assigned(bix[P]) and ((Mode <> moMovie) or (P = 0)) then
    726726    begin { initiate selected control module }
    727       AIInfo[p] := bix[p].Name + #0;
    728       InitBrain(bix[p]);
     727      AIInfo[P] := bix[P].Name + #0;
     728      InitBrain(bix[P]);
    729729      if Mode = moPlaying then
    730730      begin // new game, this data version is original
    731         OriginalDataVersion[p] := bix[p].DataVersion;
    732         ProcessClientData[p] := true;
     731        OriginalDataVersion[P] := bix[P].DataVersion;
     732        ProcessClientData[P] := True;
    733733      end
    734734      else // loading game, compare with data version read from file
    735         ProcessClientData[p] := ProcessClientData[p] and
    736           (OriginalDataVersion[p] = bix[p].DataVersion);
    737       if @bix[p].Client = nil then // client function not found
     735        ProcessClientData[P] := ProcessClientData[P] and
     736          (OriginalDataVersion[P] = bix[P].DataVersion);
     737      if @bix[P].Client = nil then // client function not found
    738738        if bix[0].Kind = btNoTerm then
    739           bix[p] := nil
     739          bix[P] := nil
    740740        else
    741741        begin
    742           bix[p] := BrainTerm;
    743           OriginalDataVersion[p] := -1;
    744           ProcessClientData[p] := false;
     742          bix[P] := BrainTerm;
     743          OriginalDataVersion[P] := -1;
     744          ProcessClientData[P] := False;
    745745        end;
    746       if Assigned(bix[p]) then
    747         include(BrainUsed, Brains.IndexOf(bix[p]));
     746      if Assigned(bix[P]) then
     747        Include(BrainUsed, Brains.IndexOf(bix[P]));
    748748    end;
    749749
     
    760760    begin
    761761      if Mode <> moMovie then
    762         inc(GWatching, 1 shl p1);
     762        Inc(GWatching, 1 shl p1);
    763763      if bix[p1].Kind = btAI then
    764         inc(GAI, 1 shl p1);
     764        Inc(GAI, 1 shl p1);
    765765      if Difficulty[p1] > 0 then
    766766      begin
    767         inc(GAlive, 1 shl p1);
    768         inc(nAlive);
     767        Inc(GAlive, 1 shl p1);
     768        Inc(nAlive);
    769769      end;
    770770      ServerVersion[p1] := bix[p1].ServerVersion;
     
    779779
    780780  GTurn := 0;
    781   for i := 0 to nWonder - 1 do
    782     with GWonder[i] do
     781  for I := 0 to nWonder - 1 do
     782    with GWonder[I] do
    783783    begin
    784784      CityID := -1;
     
    787787  FillChar(GShip, SizeOf(GShip), 0);
    788788
    789   for p := 0 to nPl - 1 do
    790     if 1 shl p and (GAlive or GWatching) <> 0 then
    791       with RW[p] do
     789  for P := 0 to nPl - 1 do
     790    if 1 shl P and (GAlive or GWatching) <> 0 then
     791      with RW[P] do
    792792      begin
    793793        Government := gDespotism;
     
    799799        AnarchyStart := -AnarchyTurns - 1;
    800800        Happened := 0;
    801         LastValidStat[p] := -1;
    802         Worked[p] := 0;
    803         Founded[p] := 0;
    804         DevModelTurn[p] := -1;
     801        LastValidStat[P] := -1;
     802        Worked[P] := 0;
     803        Founded[P] := 0;
     804        DevModelTurn[P] := -1;
    805805        OracleIncome := 0;
    806806
    807         if bix[p].DataSize > 0 then
     807        if bix[P].DataSize > 0 then
    808808        begin
    809           GetMem(SavedData[p], bix[p].DataSize * 4);
    810           GetMem(Data, bix[p].DataSize * 4);
    811           FillChar(SavedData[p]^, bix[p].DataSize * 4, 0);
    812           FillChar(Data^, bix[p].DataSize * 4, 0);
     809          GetMem(SavedData[P], bix[P].DataSize * 4);
     810          GetMem(Data, bix[P].DataSize * 4);
     811          FillChar(SavedData[P]^, bix[P].DataSize * 4, 0);
     812          FillChar(Data^, bix[P].DataSize * 4, 0);
    813813        end
    814814        else
    815815        begin
    816816          Data := nil;
    817           SavedData[p] := nil
     817          SavedData[P] := nil;
    818818        end;
    819819        nBattleHistory := 0;
     
    825825          end
    826826          else } BorderHelper := nil;
    827         for i := 0 to nStat - 1 do
    828           GetMem(Stat[i, p], 4 * (MaxTurn + 1));
    829         if bix[p].Flags and fDotNet <> 0 then
     827        for I := 0 to nStat - 1 do
     828          GetMem(Stat[I, P], 4 * (MaxTurn + 1));
     829        if bix[P].Flags and fDotNet <> 0 then
    830830        begin
    831           GetMem(RW[p].DefaultDebugMap, MapSize * 4);
    832           FillChar(RW[p].DefaultDebugMap^, MapSize * 4, 0);
    833           DebugMap[p] := RW[p].DefaultDebugMap;
     831          GetMem(RW[P].DefaultDebugMap, MapSize * 4);
     832          FillChar(RW[P].DefaultDebugMap^, MapSize * 4, 0);
     833          DebugMap[P] := RW[P].DefaultDebugMap;
    834834        end
    835835        else
    836           RW[p].DefaultDebugMap := nil;
    837 
    838         { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2);{ }
     836          RW[P].DefaultDebugMap := nil;
     837
     838        { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); }
    839839      end;
    840840
     
    842842  begin // random map
    843843    InitRandomGame;
    844     PreviewElevation := false;
     844    PreviewElevation := False;
    845845    MapField := nil;
    846846  end
     
    850850      LoadMap(MapFileName); // new game -- load map from file
    851851    GetMem(MapField, MapSize * 4);
    852     move(RealMap, MapField^, MapSize * 4);
     852    Move(RealMap, MapField^, MapSize * 4);
    853853    Human := 0;
    854854    for p1 := 0 to nPl - 1 do
    855855      if Assigned(bix[p1]) and (bix[p1].Kind = btTerm) then
    856         inc(Human, 1 shl p1);
     856        Inc(Human, 1 shl p1);
    857857    InitMapGame(Human);
    858858  end;
    859859  CityProcessing.InitGame;
    860860  UnitProcessing.InitGame;
    861   for p := 0 to nPl - 1 do
    862     if 1 shl p and (GAlive or GWatching) <> 0 then
    863       Inform(p);
     861  for P := 0 to nPl - 1 do
     862    if 1 shl P and (GAlive or GWatching) <> 0 then
     863      Inform(P);
    864864
    865865  pTurn := -1;
     
    870870  Game.LandMass := LandMass;
    871871  Game.MaxTurn := MaxTurn;
    872   move(Difficulty, Game.Difficulty, SizeOf(Difficulty));
     872  Move(Difficulty, Game.Difficulty, SizeOf(Difficulty));
    873873  // GameEx.lx:=lx; GameEx.ly:=ly; GameEx.LandMass:=LandMass;
    874874  // GameEx.MaxTurn:=MaxTurn; GameEx.RND:=RND;
    875875  // move(Difficulty,GameEx.Difficulty,SizeOf(Difficulty));
    876876  AICredits := '';
    877   for i := 0 to Brains.Count - 1 do
     877  for I := 0 to Brains.Count - 1 do
    878878  with Brains[I] do begin
    879879    if Initialized then
    880       if i in BrainUsed then
     880      if I in BrainUsed then
    881881      begin
    882882        if Kind = btAI then
    883883          Notify(ntInitPlayers);
    884         for p := 0 to nPl - 1 do
     884        for P := 0 to nPl - 1 do
    885885        begin
    886           if Brains.IndexOf(bix[p]) = i then
    887             Game.RO[p] := @RW[p]
     886          if Brains.IndexOf(bix[P]) = I then
     887            Game.RO[P] := @RW[P]
    888888          else
    889             Game.RO[p] := nil;
    890           if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[p]) then
    891             Game.SuperVisorRO[p] := @RW[p]
     889            Game.RO[P] := nil;
     890          if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[P]) then
     891            Game.SuperVisorRO[P] := @RW[P]
    892892          else
    893             Game.SuperVisorRO[p] := nil;
     893            Game.SuperVisorRO[P] := nil;
    894894        end;
    895895        if Flags and fDotNet > 0 then
    896896        begin
    897897          Path := DLLName;
    898           move(Path[1], Game.AssemblyPath, Length(Path));
     898          Move(Path[1], Game.AssemblyPath, Length(Path));
    899899          Game.AssemblyPath[Length(Path)] := #0;
    900900        end
     
    903903        case Mode of
    904904          moLoading, moLoading_Fast:
    905             CallClient(i, cLoadGame, Game);
     905            CallClient(I, cLoadGame, Game);
    906906          moMovie:
    907             CallClient(i, cMovie, Game);
     907            CallClient(I, cMovie, Game);
    908908          moPlaying:
    909             CallClient(i, cNewGame, Game);
     909            CallClient(I, cNewGame, Game);
    910910        end;
    911911        if (Kind = btAI) and (Credits <> '') then
     
    917917      else
    918918      begin { module no longer used -- unload }
    919         CallClient(i, cReleaseModule, nil^);
     919        CallClient(I, cReleaseModule, nil^);
    920920        if Kind = btAI then
    921921        begin
     
    924924          Client := nil;
    925925        end;
    926         Initialized := false;
     926        Initialized := False;
    927927      end;
    928928  end;
     
    952952  CheckBorders(-1);
    953953{$IFOPT O-}InvalidTreatyMap := 0; {$ENDIF}
    954   AutoSaveExists := false;
     954  AutoSaveExists := False;
    955955  pDipActive := -1;
    956956  pTurn := 0;
     
    958958  if Mode >= moMovie then
    959959    Notify(ntEndInfo);
    960 end; { StartGame }
     960end;
    961961
    962962procedure EndGame;
    963963var
    964   i, p1: integer;
     964  I, p1: Integer;
    965965begin
    966966  if LandMass = 0 then
     
    969969    if Assigned(bix[p1]) then
    970970    begin
    971       for i := 0 to nStat - 1 do
    972         FreeMem(Stat[i, p1]);
     971      for I := 0 to nStat - 1 do
     972        FreeMem(Stat[I, p1]);
    973973      if RW[p1].BattleHistory <> nil then
    974974        FreeMem(RW[p1].BattleHistory);
     
    985985end;
    986986
    987 procedure GenerateStat(p: integer);
     987procedure GenerateStat(P: Integer);
    988988var
    989   cix, uix: integer;
     989  cix, uix: Integer;
    990990begin
    991   if Difficulty[p] > 0 then
    992     with RW[p] do
     991  if Difficulty[P] > 0 then
     992    with RW[P] do
    993993    begin
    994       Stat[stPop, p, GTurn] := 0;
     994      Stat[stPop, P, GTurn] := 0;
    995995      for cix := 0 to nCity - 1 do
    996996        if City[cix].Loc >= 0 then
    997           inc(Stat[stPop, p, GTurn], City[cix].Size);
    998       Stat[stScience, p, GTurn] := Researched[p] * 50;
    999       if (RW[p].ResearchTech >= 0) and (RW[p].ResearchTech <> adMilitary) then
    1000         inc(Stat[stScience, p, GTurn], Research * 100 div TechBaseCost(nTech[p],
    1001           Difficulty[p]));
    1002       Stat[stMil, p, GTurn] := 0;
     997          Inc(Stat[stPop, P, GTurn], City[cix].Size);
     998      Stat[stScience, P, GTurn] := Researched[P] * 50;
     999      if (RW[P].ResearchTech >= 0) and (RW[P].ResearchTech <> adMilitary) then
     1000        Inc(Stat[stScience, P, GTurn], Research * 100 div TechBaseCost(nTech[P],
     1001          Difficulty[P]));
     1002      Stat[stMil, P, GTurn] := 0;
    10031003      for uix := 0 to nUn - 1 do
    10041004        if Un[uix].Loc >= 0 then
     
    10061006          begin
    10071007            if (Kind <= mkEnemyDeveloped) and (Un[uix].mix <> 1) then
    1008               inc(Stat[stMil, p, GTurn], Weight * MStrength *
     1008              Inc(Stat[stMil, P, GTurn], Weight * MStrength *
    10091009                Un[uix].Health div 100)
    10101010            else if Domain = dGround then
    1011               inc(Stat[stMil, p, GTurn], (Attack + 2 * Defense) *
     1011              Inc(Stat[stMil, P, GTurn], (Attack + 2 * Defense) *
    10121012                Un[uix].Health div 100)
    10131013            else
    1014               inc(Stat[stMil, p, GTurn], (Attack + Defense) *
     1014              Inc(Stat[stMil, P, GTurn], (Attack + Defense) *
    10151015                Un[uix].Health div 100);
    10161016            case Kind of
    10171017              mkSlaves:
    1018                 inc(Stat[stPop, p, GTurn]);
     1018                Inc(Stat[stPop, P, GTurn]);
    10191019              mkSettler:
    1020                 inc(Stat[stPop, p, GTurn], 2);
     1020                Inc(Stat[stPop, P, GTurn], 2);
    10211021            end;
    10221022          end;
    1023       Stat[stMil, p, GTurn] := Stat[stMil, p, GTurn] div 16;
    1024       Stat[stExplore, p, GTurn] := Discovered[p];
    1025       Stat[stTerritory, p, GTurn] := TerritoryCount[p];
    1026       Stat[stWork, p, GTurn] := Worked[p];
    1027       LastValidStat[p] := GTurn;
     1023      Stat[stMil, P, GTurn] := Stat[stMil, P, GTurn] div 16;
     1024      Stat[stExplore, P, GTurn] := Discovered[P];
     1025      Stat[stTerritory, P, GTurn] := TerritoryCount[P];
     1026      Stat[stWork, P, GTurn] := Worked[P];
     1027      LastValidStat[P] := GTurn;
    10281028    end;
    10291029end;
     
    10311031procedure LogCityTileChanges;
    10321032var
    1033   cix: integer;
     1033  cix: Integer;
    10341034begin
    10351035  for cix := 0 to RW[pTurn].nCity - 1 do
     
    10521052procedure NoLogCityTileChanges;
    10531053var
    1054   cix: integer;
     1054  cix: Integer;
    10551055begin
    10561056  for cix := 0 to RW[pTurn].nCity - 1 do
     
    10631063end;
    10641064
    1065 function HasCityTileChanges: boolean;
     1065function HasCityTileChanges: Boolean;
    10661066var
    1067   cix: integer;
     1067  cix: Integer;
    10681068begin
    1069   result := false;
     1069  Result := False;
    10701070  for cix := 0 to RW[pTurn].nCity - 1 do
    10711071    with RW[pTurn].City[cix] do
     
    10741074        // if SavedResourceWeights[cix]<>ResourceWeights then result:=true;
    10751075        if SavedTiles[cix] <> Tiles then
    1076           result := true;
     1076          Result := True;
    10771077      end;
    10781078end;
     
    10801080procedure BeforeTurn0;
    10811081var
    1082   p1, uix: integer;
     1082  p1, uix: Integer;
    10831083begin
    10841084  for uix := 0 to RW[pTurn].nUn - 1 do { init movement points for first turn }
     
    11011101end;
    11021102
    1103 function LoadGame(const Path, FileName: string; Turn: integer;
    1104   MovieMode: boolean): boolean;
     1103function LoadGame(const Path, FileName: string; Turn: Integer;
     1104  MovieMode: Boolean): Boolean;
    11051105var
    11061106  J: TBrain;
    1107   i, ix, d, p1, Command, Subject: integer;
     1107  I, ix, D, p1, Command, Subject: Integer;
    11081108  K: Integer;
    1109 {$IFDEF TEXTLOG}LoadPos0: integer; {$ENDIF}
    1110   Data: pointer;
     1109{$IFDEF TEXTLOG}LoadPos0: Integer; {$ENDIF}
     1110  Data: Pointer;
    11111111  LogFile: TFileStream;
    11121112  FormerCLState: TCmdListState;
    1113   s: string[255];
     1113  S: string[255];
    11141114  SaveMap: array [0 .. lxmax * lymax - 1] of Byte;
    1115   Started, StatRequest: boolean;
     1115  Started, StatRequest: Boolean;
    11161116begin
    11171117  SavePath := Path;
     
    11211121    fmShareExclusive);
    11221122  LogFile.Position := 0;
    1123   LogFile.Read(s[1], 8); { file id }
    1124   LogFile.Read(i, 4); { c-evo version }
     1123  LogFile.Read(S[1], 8); { file id }
     1124  LogFile.Read(I, 4); { c-evo version }
    11251125  LogFile.Read(J, 4); { exe time }
    11261126
    1127   if (i >= FirstBookCompatibleVersion) and (i <= CevoVersion) then
     1127  if (I >= FirstBookCompatibleVersion) and (I <= CevoVersion) then
    11281128  begin
    1129     result := true;
     1129    Result := True;
    11301130    LogFile.Read(lx, 4);
    11311131    LogFile.Read(ly, 4);
     
    11391139    LogFile.Read(SaveMap, 4);
    11401140    if SaveMap[0] <> $80 then
    1141       LogFile.read(SaveMap[4], ((MapSize - 1) div 4 + 1) * 4 - 4);
     1141      LogFile.Read(SaveMap[4], ((MapSize - 1) div 4 + 1) * 4 - 4);
    11421142    for p1 := 0 to nPl - 1 do
    11431143    begin
    1144       LogFile.Read(s[0], 4);
    1145       if s[0] = #0 then
     1144      LogFile.Read(S[0], 4);
     1145      if S[0] = #0 then
    11461146        PlayersBrain[p1] := nil
    11471147      else
    11481148      begin
    1149         LogFile.Read(s[4], Byte(s[0]) div 4 * 4);
     1149        LogFile.Read(S[4], Byte(S[0]) div 4 * 4);
    11501150        LogFile.Read(OriginalDataVersion[p1], 4);
    1151         LogFile.Read(d, 4); { behavior }
     1151        LogFile.Read(D, 4); { behavior }
    11521152        LogFile.Read(Difficulty[p1], 4);
    11531153        J := Brains.Last;
    1154         while Assigned(J) and (AnsiCompareFileName(J.FileName, s) <> 0) do begin
     1154        while Assigned(J) and (AnsiCompareFileName(J.FileName, S) <> 0) do begin
    11551155          K := Brains.IndexOf(J) - 1;
    11561156          if K >= 0 then J := Brains[K]
     
    11591159        if not Assigned(J) then
    11601160        begin // ai not found -- replace by local player
    1161           ProcessClientData[p1] := false;
    1162           NotifyMessage := s;
     1161          ProcessClientData[p1] := False;
     1162          NotifyMessage := S;
    11631163          Notify(ntAIError);
    11641164          J := BrainTerm;
    11651165        end
    11661166        else
    1167           ProcessClientData[p1] := true;
    1168         if j.Kind = btNoTerm then
    1169           j := BrainSuperVirtual;
     1167          ProcessClientData[p1] := True;
     1168        if J.Kind = btNoTerm then
     1169          J := BrainSuperVirtual;
    11701170        // crashed tournament -- load as supervisor
    1171         PlayersBrain[p1] := j;
     1171        PlayersBrain[p1] := J;
    11721172      end;
    11731173    end;
    11741174  end
    11751175  else
    1176     Result := false;
     1176    Result := False;
    11771177
    11781178  if Result then begin
     
    11811181  end;
    11821182  FreeAndNil(LogFile);
    1183   if not result then
     1183  if not Result then
    11841184    Exit;
    11851185
     
    11951195{$IFDEF TEXTLOG}AssignFile(TextLog, SavePath + LogFileName + '.txt');
    11961196  Rewrite(TextLog); {$ENDIF}
    1197   LoadOK := true;
     1197  LoadOK := True;
    11981198  StartGame;
    11991199  if MovieMode then
     
    12051205    Notify(ntLoadBegin);
    12061206
    1207   started := false;
    1208   StatRequest := false;
    1209   MovieStopped := false;
     1207  started := False;
     1208  StatRequest := False;
     1209  MovieStopped := False;
    12101210{$IFDEF LOADPERF}QueryPerformanceCounter(time_total0);
    12111211  time_a := 0;
     
    12221222    begin
    12231223      GenerateStat(pTurn);
    1224       StatRequest := false;
     1224      StatRequest := False;
    12251225    end;
    12261226    // complete all internal commands following an sTurn before generating statistics
     
    12371237        CallPlayer(cMovieTurn, 0, nil^);
    12381238      end;
    1239       StatRequest := true;
    1240       started := true;
     1239      StatRequest := True;
     1240      started := True;
    12411241    end
    12421242    else if (Command = sTurn) and (pTurn = 0) and (GTurn = LoadTurn) then
    12431243    begin
    1244       assert(CL.State.LoadPos = FormerCLState.LoadPos + 4); // size of sTurn
     1244      Assert(CL.State.LoadPos = FormerCLState.LoadPos + 4); // size of sTurn
    12451245      CL.State := FormerCLState;
    12461246      CL.Cut;
     
    12781278    EndGame;
    12791279    Notify(ntStartGo);
    1280     result := false;
    1281     exit;
     1280    Result := False;
     1281    Exit;
    12821282  end;
    12831283
    12841284  if StatRequest then
    12851285    GenerateStat(pTurn);
    1286   assert(started);
     1286  Assert(started);
    12871287{$IFDEF TEXTLOG}CloseFile(TextLog); {$ENDIF}
    12881288{$IFDEF LOADPERF}QueryPerformanceCounter(time_total); { time in s is: (time_total-time_total0)/PerfFreq }{$ENDIF}
     
    13241324  Inform(pTurn);
    13251325  ChangeClientWhenDone(cResume, 0, nil^, 0);
    1326 end; // LoadGame
     1326end;
    13271327
    13281328procedure InsertTerritoryUpdateCommands;
    13291329var
    1330   p1, Command, Subject: integer;
    1331   Data: pointer;
     1330  p1, Command, Subject: Integer;
     1331  Data: Pointer;
    13321332  FormerCLState: TCmdListState;
    13331333begin
     
    13511351
    13521352procedure StartNewGame(const Path, FileName, Map: string;
    1353   Newlx, Newly, NewLandMass, NewMaxTurn: integer);
     1353  Newlx, Newly, NewLandMass, NewMaxTurn: Integer);
    13541354var
    13551355  I: Integer;
     
    13951395end;
    13961396
    1397 procedure DirectHelp(Command: integer);
     1397procedure DirectHelp(Command: Integer);
    13981398begin
    13991399  InitBrain(BrainTerm);
     
    14021402end;
    14031403
    1404 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: integer);
     1404procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer);
    14051405var
    1406   p1, Loc1: integer;
     1406  p1, Loc1: Integer;
    14071407  Game: TNewGameData;
    14081408begin
     
    14461446end;
    14471447
    1448 procedure DestroySpacePort_TellPlayers(p, pCapturer: integer);
     1448procedure DestroySpacePort_TellPlayers(P, pCapturer: Integer);
    14491449var
    1450   cix, i, p1: integer;
     1450  cix, I, p1: Integer;
    14511451  ShowShipChange: TShowShipChange;
    14521452begin
    14531453  // stop ship part production
    1454   for cix := 0 to RW[p].nCity - 1 do
    1455     with RW[p].City[cix] do
     1454  for cix := 0 to RW[P].nCity - 1 do
     1455    with RW[P].City[cix] do
    14561456      if (Loc >= 0) and (Project and cpImp <> 0) and
    14571457        ((Project and cpIndex = woMIR) or
    14581458        (Imp[Project and cpIndex].Kind = ikShipPart)) then
    14591459      begin
    1460         inc(RW[p].Money, Prod0);
     1460        Inc(RW[P].Money, Prod0);
    14611461        Prod := 0;
    14621462        Prod0 := 0;
     
    14661466
    14671467  // destroy ship
    1468   with GShip[p] do
     1468  with GShip[P] do
    14691469    if Parts[0] + Parts[1] + Parts[2] > 0 then
    14701470    begin
    1471       for i := 0 to nShipPart - 1 do
    1472       begin
    1473         ShowShipChange.Ship1Change[i] := -Parts[i];
     1471      for I := 0 to nShipPart - 1 do
     1472      begin
     1473        ShowShipChange.Ship1Change[I] := -Parts[I];
    14741474        if pCapturer >= 0 then
    14751475        begin
    1476           ShowShipChange.Ship2Change[i] := Parts[i];
    1477           inc(GShip[pCapturer].Parts[i], Parts[i]);
     1476          ShowShipChange.Ship2Change[I] := Parts[I];
     1477          Inc(GShip[pCapturer].Parts[I], Parts[I]);
    14781478        end;
    1479         Parts[i] := 0;
     1479        Parts[I] := 0;
    14801480      end;
    14811481      if Mode >= moMovie then
     
    14851485        else
    14861486          ShowShipChange.Reason := scrDestruction;
    1487         ShowShipChange.Ship1Owner := p;
     1487        ShowShipChange.Ship1Owner := P;
    14881488        ShowShipChange.Ship2Owner := pCapturer;
    14891489        for p1 := 0 to nPl - 1 do
    14901490          if 1 shl p1 and (GAlive or GWatching) <> 0 then
    14911491          begin
    1492             move(GShip, RW[p1].Ship, SizeOf(GShip));
     1492            Move(GShip, RW[p1].Ship, SizeOf(GShip));
    14931493            if 1 shl p1 and GWatching <> 0 then
    14941494              CallPlayer(cShowShipChange, p1, ShowShipChange);
     
    14981498end;
    14991499
    1500 procedure DestroyCity_TellPlayers(p, cix: integer; SaveUnits: boolean);
     1500procedure DestroyCity_TellPlayers(P, cix: Integer; SaveUnits: Boolean);
    15011501begin
    1502   if RW[p].City[cix].built[imSpacePort] > 0 then
    1503     DestroySpacePort_TellPlayers(p, -1);
    1504   DestroyCity(p, cix, SaveUnits);
     1502  if RW[P].City[cix].built[imSpacePort] > 0 then
     1503    DestroySpacePort_TellPlayers(P, -1);
     1504  DestroyCity(P, cix, SaveUnits);
    15051505end;
    15061506
    1507 procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: integer);
     1507procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: Integer);
    15081508begin
    15091509  if RW[pOld].City[cixOld].built[imSpacePort] > 0 then
     
    15151515end;
    15161516
    1517 procedure CheckWin(p: integer);
     1517procedure CheckWin(P: Integer);
    15181518var
    1519   i: integer;
    1520   ShipComplete: boolean;
     1519  I: Integer;
     1520  ShipComplete: Boolean;
    15211521begin
    1522   ShipComplete := true;
    1523   for i := 0 to nShipPart - 1 do
    1524     if GShip[p].Parts[i] < ShipNeed[i] then
    1525       ShipComplete := false;
     1522  ShipComplete := True;
     1523  for I := 0 to nShipPart - 1 do
     1524    if GShip[P].Parts[I] < ShipNeed[I] then
     1525      ShipComplete := False;
    15261526  if ShipComplete then
    1527     GWinner := GWinner or 1 shl p; // game won!
     1527    GWinner := GWinner or 1 shl P; // game won!
    15281528end;
    15291529
    15301530procedure BeforeTurn;
    15311531var
    1532   i, p1, uix, cix, V21, Loc1, Cost, Job0, nAlive, nAppliers, ad, OldLoc,
    1533     SiegedTiles, nUpdateLoc: integer;
    1534   UpdateLoc: array [0 .. numax - 1] of integer;
     1532  I, p1, uix, cix, V21, Loc1, Cost, Job0, nAlive, nAppliers, ad, OldLoc,
     1533    SiegedTiles, nUpdateLoc: Integer;
     1534  UpdateLoc: array [0 .. numax - 1] of Integer;
    15351535  Radius: TVicinity21Loc;
    15361536  ShowShipChange: TShowShipChange;
    1537   TribeExtinct, JobDone, MirBuilt: boolean;
     1537  TribeExtinct, JobDone, MirBuilt: Boolean;
    15381538begin
    1539 {$IFOPT O-}assert(1 shl pTurn and InvalidTreatyMap = 0); {$ENDIF}
    1540   assert(1 shl pTurn and (GAlive or GWatching) <> 0);
     1539{$IFOPT O-}Assert(1 shl pTurn and InvalidTreatyMap = 0); {$ENDIF}
     1540  Assert(1 shl pTurn and (GAlive or GWatching) <> 0);
    15411541  if (1 shl pTurn and GAlive = 0) and (Difficulty[pTurn] > 0) then
    1542     exit;
     1542    Exit;
    15431543
    15441544  if (GWonder[woGrLibrary].EffectiveOwner = pTurn) and (GWinner = 0) then
     
    15471547    for p1 := 0 to nPl - 1 do
    15481548      if 1 shl p1 and GAlive <> 0 then
    1549         inc(nAlive);
     1549        Inc(nAlive);
    15501550    ad := 0;
    15511551    while ad <= (nAdv - 5) do begin
     
    15561556          if (p1 <> pTurn) and (1 shl p1 and GAlive <> 0) and
    15571557            (RW[p1].Tech[ad] >= tsApplicable) then
    1558             inc(nAppliers);
     1558            Inc(nAppliers);
    15591559        if nAppliers * 2 > nAlive then
    15601560        begin
    15611561          SeeTech(pTurn, ad);
    1562           inc(nTech[pTurn]);
     1562          Inc(nTech[pTurn]);
    15631563          if Mode >= moMovie then
    15641564            CallPlayer(cShowGreatLibTech, pTurn, ad);
     
    15771577  RW[pTurn].nEnemyUn := 0;
    15781578
    1579   MirBuilt := false;
     1579  MirBuilt := False;
    15801580  if (Difficulty[pTurn] > 0) and (GWinner = 0) then
    15811581    with RW[pTurn] do
     
    16001600                  begin // transport unload
    16011601                    if Model[mix].Domain = dAir then
    1602                       dec(Un[Master].AirLoad)
     1602                      Dec(Un[Master].AirLoad)
    16031603                    else
    1604                       dec(Un[Master].TroopLoad);
     1604                      Dec(Un[Master].TroopLoad);
    16051605                    Master := -1;
    16061606                  end
     
    16221622      if Mode >= moMovie then
    16231623        FillChar(ShowShipChange, SizeOf(ShowShipChange), 0);
    1624       TribeExtinct := true;
     1624      TribeExtinct := True;
    16251625      nUpdateLoc := 0;
    16261626      for cix := 0 to nCity - 1 do
     
    16381638              begin
    16391639                Loc1 := Radius[V21];
    1640                 assert((Loc1 >= 0) and (Loc1 < MapSize) and
     1640                Assert((Loc1 >= 0) and (Loc1 < MapSize) and
    16411641                  (UsedByCity[Loc1] = Loc));
    16421642                p1 := RealMap[Loc1] shr 27;
     
    16491649                  UsedByCity[Loc1] := -1;
    16501650                  Flags := Flags or chSiege;
    1651                   inc(SiegedTiles);
     1651                  Inc(SiegedTiles);
    16521652                end;
    16531653              end;
     
    16561656              if not AddBestCityTile(pTurn, cix) then
    16571657                Break;
    1658               dec(SiegedTiles);
     1658              Dec(SiegedTiles);
    16591659            end;
    16601660
     
    16641664
    16651665              if CityTurn(pTurn, cix) then
    1666                 TribeExtinct := false
     1666                TribeExtinct := False
    16671667              else
    16681668              begin // city is erased
     
    16711671                Map[Loc] := Map[Loc] and not fCity; // !!! do this in inner core
    16721672                UpdateLoc[nUpdateLoc] := Loc;
    1673                 inc(nUpdateLoc);
    1674                 DestroyCity_TellPlayers(pTurn, cix, true);
     1673                Inc(nUpdateLoc);
     1674                DestroyCity_TellPlayers(pTurn, cix, True);
    16751675              end;
    16761676
     
    16791679              begin
    16801680                if Project0 and cpIndex = woMIR then // MIR completed
    1681                   MirBuilt := true
     1681                  MirBuilt := True
    16821682                else if Project0 and cpIndex = woManhattan then
    16831683                  GColdWarStart := GTurn
    16841684                else if Imp[Project0 and cpIndex].Kind = ikShipPart
    16851685                then { ship parts produced }
    1686                   inc(ShowShipChange.Ship1Change[Project0 and cpIndex -
     1686                  Inc(ShowShipChange.Ship1Change[Project0 and cpIndex -
    16871687                    imShipComp]);
    16881688              end;
     
    16921692      begin
    16931693        CheckBorders(-1, pTurn);
    1694         for i := 0 to nUpdateLoc - 1 do
    1695           UpdateUnitMap(UpdateLoc[i], true);
     1694        for I := 0 to nUpdateLoc - 1 do
     1695          UpdateUnitMap(UpdateLoc[I], True);
    16961696        if Mode >= moMovie then
    16971697          for p1 := 0 to nPl - 1 do
    16981698            if (1 shl p1 and GWatching <> 0) and (p1 <> pTurn) then
    1699               for i := 0 to nUpdateLoc - 1 do
    1700                 if ObserveLevel[UpdateLoc[i]] shr (2 * p1) and 3 >= lObserveUnhidden
     1699              for I := 0 to nUpdateLoc - 1 do
     1700                if ObserveLevel[UpdateLoc[I]] shr (2 * p1) and 3 >= lObserveUnhidden
    17011701                then
    1702                   CallPlayer(cShowCityChanged, p1, UpdateLoc[i]);
     1702                  CallPlayer(cShowCityChanged, p1, UpdateLoc[I]);
    17031703      end;
    17041704
     
    17181718              Movement := UnitSpeed(pTurn, mix, Health); { refresh movement }
    17191719
    1720             assert(Loc >= 0);
     1720            Assert(Loc >= 0);
    17211721            if Model[mix].Kind <> mkDiplomat then
    17221722            begin // check treaty violation
     
    17621762              begin
    17631763                AddBestCityTile(pTurn, RW[pTurn].nCity - 1);
    1764                 UpdateUnitMap(Loc1, true);
     1764                UpdateUnitMap(Loc1, True);
    17651765                if Mode >= moMovie then // tell enemies
    17661766                  for p1 := 0 to nPl - 1 do
     
    18101810            end;
    18111811          end;
    1812         exit
     1812        Exit;
    18131813      end;
    18141814
     
    18241824          DiscoverTech(pTurn, ResearchTech);
    18251825
    1826         dec(Research, Cost);
     1826        Dec(Research, Cost);
    18271827        Happened := Happened or phTech;
    1828         ResearchTech := -1
     1828        ResearchTech := -1;
    18291829      end
    18301830      else if (ResearchTech = -2) and (nCity > 0) then
     
    18391839            (Treaty[p1] >= trPeace) then
    18401840          begin
    1841             inc(Credibility);
     1841            Inc(Credibility);
    18421842            Break;
    18431843          end;
     
    18561856          if (p1 <> pTurn) and (1 shl p1 and (GAlive or GWatching) <> 0) then
    18571857          begin
    1858             move(GShip, RW[p1].Ship, SizeOf(GShip));
     1858            Move(GShip, RW[p1].Ship, SizeOf(GShip));
    18591859            if 1 shl p1 and GWatching <> 0 then
    18601860              CallPlayer(cShowShipChange, p1, ShowShipChange);
    1861           end
     1861          end;
    18621862      end;
    18631863      if WinOnAlone and (GAlive and not(1 shl pTurn or 1) = 0) then
     
    18711871          if (p1 <> pTurn) and ((GAlive or GWatching) and (1 shl p1) <> 0) then
    18721872            RW[p1].EnemyReport[pTurn].Government := gDespotism;
    1873         inc(Happened, phChangeGov)
     1873        Inc(Happened, phChangeGov);
    18741874      end;
    18751875    end; // if Difficulty[pTurn]>0
     
    19081908  end;
    19091909  // CheckContact;
    1910 end; { BeforeTurn }
     1910end;
    19111911
    19121912procedure AfterTurn;
    19131913var
    1914   cix, uix, p1, Loc1, Job0: integer;
    1915   JobDone: boolean;
     1914  cix, uix, p1, Loc1, Job0: Integer;
     1915  JobDone: Boolean;
    19161916begin
    19171917  with RW[pTurn] do
     
    19251925      end;
    19261926
    1927     inc(Money, OracleIncome);
     1927    Inc(Money, OracleIncome);
    19281928    OracleIncome := 0;
    19291929    if GWonder[woOracle].EffectiveOwner = pTurn then
     
    19351935            if (RW[p1].City[cix].Loc >= 0) and
    19361936              (RW[p1].City[cix].built[imTemple] > 0) then
    1937               inc(OracleIncome);
     1937              Inc(OracleIncome);
    19381938    end;
    19391939
     
    19621962            begin
    19631963              AddBestCityTile(pTurn, RW[pTurn].nCity - 1);
    1964               UpdateUnitMap(Loc1, true);
     1964              UpdateUnitMap(Loc1, True);
    19651965              if Mode >= moMovie then // tell enemies
    19661966                for p1 := 0 to nPl - 1 do
     
    19931993            else
    19941994            begin
    1995               dec(Fuel);
     1995              Dec(Fuel);
    19961996              if Fuel < 0 then
    19971997              begin
     
    20132013        Flags := Flags and not unWithdrawn;
    20142014        if (Loc >= 0) and (Model[mix].Domain = dGround) and (Master < 0) and
    2015           ((integer(Movement) = Model[mix].Speed) or
     2015          ((Integer(Movement) = Model[mix].Speed) or
    20162016          (Model[mix].Cap[mcAcademy] > 0) and (Movement * 2 >= Model[mix].Speed))
    20172017        then
     
    20352035          CheckWin(p1);
    20362036  end;
    2037 end; // Afterturn
     2037end;
    20382038
    20392039procedure NextPlayer;
     
    20492049end;
    20502050
    2051 function ExecuteMove(p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;
    2052   ShowMove: TShowMove): integer;
     2051function ExecuteMove(P, uix, ToLoc: Integer; var MoveInfo: TMoveInfo;
     2052  ShowMove: TShowMove): Integer;
    20532053var
    2054   i, p1, FromLoc, uix1, nUpdateLoc: integer;
     2054  I, p1, FromLoc, uix1, nUpdateLoc: Integer;
    20552055  MinLevel, MissionResult: Cardinal;
    20562056  PModel: ^TModel;
    2057   UpdateLoc: array [0 .. numax - 1] of integer;
    2058   SeeFrom, SeeTo, ExtDiscover: boolean;
     2057  UpdateLoc: array [0 .. numax - 1] of Integer;
     2058  SeeFrom, SeeTo, ExtDiscover: Boolean;
    20592059begin
    2060   result := 0;
    2061   with RW[p], Un[uix] do
     2060  Result := 0;
     2061  with RW[P], Un[uix] do
    20622062  begin
    20632063    PModel := @Model[mix];
     
    20652065
    20662066    if Master < 0 then
    2067       FreeUnit(p, uix);
     2067      FreeUnit(P, uix);
    20682068    if (MoveInfo.MoveType in [mtMove, mtCapture]) and MoveInfo.MountainDelay
    20692069    then
     
    20732073    Loc := -2;
    20742074    if TroopLoad + AirLoad > 0 then
    2075       for i := 0 to nUn - 1 do
    2076         if (Un[i].Loc >= 0) and (Un[i].Master = uix) then
    2077           Un[i].Loc := -2;
     2075      for I := 0 to nUn - 1 do
     2076        if (Un[I].Loc >= 0) and (Un[I].Master = uix) then
     2077          Un[I].Loc := -2;
    20782078    UpdateUnitMap(FromLoc);
    20792079
     
    20932093          ShowMove.Flags := ShowMove.Flags or umShipLoading;
    20942094      for p1 := 0 to nPl - 1 do
    2095         if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))
     2095        if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm))
    20962096        then
    20972097        begin
     
    21022102          else
    21032103            MinLevel := lObserveUnhidden;
    2104           SeeFrom := (p1 = p) or (ObserveLevel[FromLoc] shr (2 * p1) and
     2104          SeeFrom := (p1 = P) or (ObserveLevel[FromLoc] shr (2 * p1) and
    21052105            3 >= MinLevel);
    2106           SeeTo := (p1 = p) or (ObserveLevel[ToLoc] shr (2 * p1) and
     2106          SeeTo := (p1 = P) or (ObserveLevel[ToLoc] shr (2 * p1) and
    21072107            3 >= MinLevel);
    21082108          if SeeFrom and SeeTo then
    21092109          begin
    2110             TellAboutModel(p1, p, mix);
    2111             if p1 = p then
     2110            TellAboutModel(p1, P, mix);
     2111            if p1 = P then
    21122112              ShowMove.emix := -1
    21132113            else
    2114               ShowMove.emix := emixSafe(p1, p, mix);
     2114              ShowMove.emix := emixSafe(p1, P, mix);
    21152115            if MoveInfo.MoveType = mtCapture then
    21162116              CallPlayer(cShowCapturing, p1, ShowMove)
     
    21262126      Loc := ToLoc;
    21272127    if TroopLoad + AirLoad > 0 then
    2128       for i := 0 to nUn - 1 do
    2129         if Un[i].Loc = -2 then
    2130           Un[i].Loc := ToLoc;
    2131 
    2132     ExtDiscover := false;
     2128      for I := 0 to nUn - 1 do
     2129        if Un[I].Loc = -2 then
     2130          Un[I].Loc := ToLoc;
     2131
     2132    ExtDiscover := False;
    21332133    nUpdateLoc := 0;
    21342134    if MoveInfo.MoveType = mtCapture then
    21352135    begin
    2136       assert(Occupant[ToLoc] < 0);
     2136      Assert(Occupant[ToLoc] < 0);
    21372137      for uix1 := 0 to RW[MoveInfo.Defender].nUn - 1 do
    21382138        with RW[MoveInfo.Defender].Un[uix1] do
     
    21402140          begin
    21412141            UpdateLoc[nUpdateLoc] := Loc;
    2142             inc(nUpdateLoc);
     2142            Inc(nUpdateLoc);
    21432143          end;
    21442144      // unit will be removed -- remember position and update for all players
     
    21472147      then
    21482148      begin // city captured
    2149         ChangeCityOwner_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, p);
     2149        ChangeCityOwner_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, P);
    21502150        City[nCity - 1].Flags := CaptureTurns shl 16;
    2151         CityShrink(p, nCity - 1);
     2151        CityShrink(P, nCity - 1);
    21522152        if Mode = moPlaying then
    2153           with RW[p].City[nCity - 1] do
     2153          with RW[P].City[nCity - 1] do
    21542154          begin
    21552155            // SavedResourceWeights[nCity-1]:=ResourceWeights;
    21562156            SavedTiles[nCity - 1] := Tiles;
    21572157          end;
    2158         ExtDiscover := true;
     2158        ExtDiscover := True;
    21592159
    21602160        // Temple of Zeus effect
    2161         if GWonder[woZeus].EffectiveOwner = p then
     2161        if GWonder[woZeus].EffectiveOwner = P then
    21622162        begin
    2163           GiveCivilReport(p, MoveInfo.Defender);
    2164           for i := 0 to nAdv - 1 do
    2165             if not(i in FutureTech) and (RW[p].Tech[i] < tsSeen) and
    2166               (RW[MoveInfo.Defender].Tech[i] >= tsApplicable) then
     2163          GiveCivilReport(P, MoveInfo.Defender);
     2164          for I := 0 to nAdv - 1 do
     2165            if not(I in FutureTech) and (RW[P].Tech[I] < tsSeen) and
     2166              (RW[MoveInfo.Defender].Tech[I] >= tsApplicable) then
    21672167            begin
    21682168              Happened := Happened or phStealTech;
     
    21722172        end;
    21732173        if Mode = moPlaying then
    2174           LogCheckBorders(p, nCity - 1, MoveInfo.Defender);
     2174          LogCheckBorders(P, nCity - 1, MoveInfo.Defender);
    21752175{$IFOPT O-} if Mode < moPlaying then
    2176           InvalidTreatyMap := not(1 shl p); {$ENDIF}
     2176          InvalidTreatyMap := not(1 shl P); {$ENDIF}
    21772177        // territory should not be considered for the rest of the command
    21782178        // execution, because during loading a game it's incorrect before
     
    21812181      else // city destroyed
    21822182      begin
    2183         DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, false);
     2183        DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, False);
    21842184        CheckBorders(ToLoc, MoveInfo.Defender);
    21852185      end;
    2186       RecalcPeaceMap(p);
     2186      RecalcPeaceMap(P);
    21872187      if Mode >= moMovie then
    2188         move(GWonder, Wonder, SizeOf(GWonder));
     2188        Move(GWonder, Wonder, SizeOf(GWonder));
    21892189    end; { if MoveInfo.MoveType=mtCapture }
    21902190
    21912191    if MoveInfo.MoveType = mtSpyMission then
    21922192    begin
    2193       MissionResult := DoSpyMission(p, MoveInfo.Defender, MoveInfo.Dcix,
     2193      MissionResult := DoSpyMission(P, MoveInfo.Defender, MoveInfo.Dcix,
    21942194        SpyMission);
    21952195      if (Mode = moPlaying) and (SpyMission = smStealForeignReports) then
    2196         CallPlayer(cShowMissionResult, p, MissionResult);
     2196        CallPlayer(cShowMissionResult, P, MissionResult);
    21972197    end;
    21982198
    21992199    Health := MoveInfo.EndHealth;
    2200     dec(Movement, MoveInfo.Cost);
     2200    Dec(Movement, MoveInfo.Cost);
    22012201    // transport unload
    22022202    if Master >= 0 then
    22032203    begin
    22042204      if PModel.Domain = dAir then
    2205         dec(Un[Master].AirLoad)
    2206       else
    2207       begin
    2208         dec(Un[Master].TroopLoad);
    2209         assert(Movement <= 0);
     2205        Dec(Un[Master].AirLoad)
     2206      else
     2207      begin
     2208        Dec(Un[Master].TroopLoad);
     2209        Assert(Movement <= 0);
    22102210      end;
    22112211      Master := -1;
     
    22132213
    22142214    if (Health <= 0) or (MoveInfo.MoveType = mtSpyMission) then
    2215       RemoveUnit(p, uix) // spy mission or victim of HostileDamage
     2215      RemoveUnit(P, uix) // spy mission or victim of HostileDamage
    22162216    else
    22172217    begin // transport load
     
    22202220      begin
    22212221        if PModel.Domain = dAir then
    2222           inc(Un[MoveInfo.ToMaster].AirLoad)
     2222          Inc(Un[MoveInfo.ToMaster].AirLoad)
    22232223        else
    2224           inc(Un[MoveInfo.ToMaster].TroopLoad);
     2224          Inc(Un[MoveInfo.ToMaster].TroopLoad);
    22252225      end
    22262226      else
    2227         PlaceUnit(p, uix);
     2227        PlaceUnit(P, uix);
    22282228    end;
    22292229
    22302230    if (MoveInfo.MoveType = mtCapture) and (nUpdateLoc > 0) then
    2231       RecalcMapZoC(p);
     2231      RecalcMapZoC(P);
    22322232    UpdateUnitMap(ToLoc, MoveInfo.MoveType = mtCapture);
    2233     for i := 0 to nUpdateLoc - 1 do
    2234       UpdateUnitMap(UpdateLoc[i]);
     2233    for I := 0 to nUpdateLoc - 1 do
     2234      UpdateUnitMap(UpdateLoc[I]);
    22352235    // tell about lost units of defender
    22362236
     
    22422242        (RealMap[ToLoc] and fTerImp = tiFort) or
    22432243        (RealMap[ToLoc] and fTerImp = tiBase) then
    2244         ExtDiscover := true;
     2244        ExtDiscover := True;
    22452245      if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then
    2246         i := lObserveSuper
     2246        I := lObserveSuper
    22472247      else if (PModel.Domain = dAir) or
    22482248        (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) then
    2249         i := lObserveAll
    2250       else
    2251         i := lObserveUnhidden;
     2249        I := lObserveAll
     2250      else
     2251        I := lObserveUnhidden;
    22522252      if ExtDiscover then
    22532253      begin
    2254         if Discover21(ToLoc, p, i, true, PModel.Domain = dGround) then
    2255           result := result or rEnemySpotted;
     2254        if Discover21(ToLoc, P, I, True, PModel.Domain = dGround) then
     2255          Result := Result or rEnemySpotted;
    22562256      end
    22572257      else
    22582258      begin
    2259         if Discover9(ToLoc, p, i, true, PModel.Domain = dGround) then
    2260           result := result or rEnemySpotted;
     2259        if Discover9(ToLoc, P, I, True, PModel.Domain = dGround) then
     2260          Result := Result or rEnemySpotted;
    22612261      end;
    22622262    end;
     
    22642264    if Mode >= moMovie then { show after-move in interface modules }
    22652265      for p1 := 0 to nPl - 1 do
    2266         if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))
     2266        if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm))
    22672267        then
    22682268        begin
     
    22732273          else
    22742274            MinLevel := lObserveUnhidden;
    2275           SeeFrom := (p1 = p) or (ObserveLevel[FromLoc] shr (2 * p1) and
     2275          SeeFrom := (p1 = P) or (ObserveLevel[FromLoc] shr (2 * p1) and
    22762276            3 >= MinLevel);
    2277           SeeTo := (p1 = p) or (ObserveLevel[ToLoc] shr (2 * p1) and
     2277          SeeTo := (p1 = P) or (ObserveLevel[ToLoc] shr (2 * p1) and
    22782278            3 >= MinLevel);
    22792279          if SeeTo and (MoveInfo.MoveType = mtCapture) then
     
    22832283          else if (MoveInfo.MoveType <> mtSpyMission) and SeeTo then
    22842284            CallPlayer(cShowUnitChanged, p1, ToLoc);
    2285           for i := 0 to nUpdateLoc - 1 do
    2286             if ObserveLevel[UpdateLoc[i]] shr (2 * p1) and 3 >= lObserveUnhidden
     2285          for I := 0 to nUpdateLoc - 1 do
     2286            if ObserveLevel[UpdateLoc[I]] shr (2 * p1) and 3 >= lObserveUnhidden
    22872287            then
    2288               CallPlayer(cShowUnitChanged, p1, UpdateLoc[i]);
     2288              CallPlayer(cShowUnitChanged, p1, UpdateLoc[I]);
    22892289        end;
    22902290  end;
    2291 end; // ExecuteMove
    2292 
    2293 function ExecuteAttack(p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;
    2294   ShowMove: TShowMove): integer;
     2291end;
     2292
     2293function ExecuteAttack(P, uix, ToLoc: Integer; var MoveInfo: TMoveInfo;
     2294  ShowMove: TShowMove): Integer;
    22952295
    22962296  procedure WriteBattleHistory(ToLoc, FromLoc, Attacker, Defender, mixAttacker,
    2297     mixDefender: integer; AttackerLost, DefenderLost: boolean);
     2297    mixDefender: Integer; AttackerLost, DefenderLost: Boolean);
    22982298  var
    22992299    AttackerBattle, DefenderBattle: ^TBattle;
     
    23072307        ReallocMem(BattleHistory, nBattleHistory * (2 * SizeOf(TBattle)));
    23082308      AttackerBattle := @BattleHistory[nBattleHistory];
    2309       inc(nBattleHistory);
     2309      Inc(nBattleHistory);
    23102310    end;
    23112311    with RW[Defender] do
     
    23172317        ReallocMem(BattleHistory, nBattleHistory * (2 * SizeOf(TBattle)));
    23182318      DefenderBattle := @BattleHistory[nBattleHistory];
    2319       inc(nBattleHistory);
     2319      Inc(nBattleHistory);
    23202320    end;
    23212321    AttackerBattle.Enemy := Defender;
     
    23462346
    23472347var
    2348   i, p1, FromLoc, uix1, nUpdateLoc, ExpGain, ExpelToLoc, cix1: integer;
     2348  I, p1, FromLoc, uix1, nUpdateLoc, ExpGain, ExpelToLoc, cix1: Integer;
    23492349  PModel: ^TModel;
    2350   UpdateLoc: array [0 .. numax - 1] of integer;
    2351   LoseCityPop, CityDestroyed, SeeFrom, SeeTo, ZoCDefenderDestroyed: boolean;
     2350  UpdateLoc: array [0 .. numax - 1] of Integer;
     2351  LoseCityPop, CityDestroyed, SeeFrom, SeeTo, ZoCDefenderDestroyed: Boolean;
    23522352begin
    2353   result := 0;
    2354   with RW[p].Un[uix] do
     2353  Result := 0;
     2354  with RW[P].Un[uix] do
    23552355  begin
    2356     PModel := @RW[p].Model[mix];
     2356    PModel := @RW[P].Model[mix];
    23572357    FromLoc := Loc;
    23582358
     
    23602360    ShowMove.EndHealthDef := MoveInfo.EndHealthDef;
    23612361    if MoveInfo.MoveType = mtAttack then
    2362       WriteBattleHistory(ToLoc, FromLoc, p, MoveInfo.Defender, mix,
     2362      WriteBattleHistory(ToLoc, FromLoc, P, MoveInfo.Defender, mix,
    23632363        RW[MoveInfo.Defender].Un[MoveInfo.Duix].mix, MoveInfo.EndHealth <= 0,
    23642364        MoveInfo.EndHealthDef <= 0);
     
    23672367      begin
    23682368      if Mode>=moMovie then
    2369       CallPlayer(cShowCancelTreaty,MoveInfo.Defender,p);
    2370       CancelTreaty(p,MoveInfo.Defender)
     2369      CallPlayer(cShowCancelTreaty,MoveInfo.Defender,P);
     2370      CancelTreaty(P,MoveInfo.Defender)
    23712371      end; }
    23722372    if Mode >= moMovie then { show attack in interface modules }
    23732373      for p1 := 0 to nPl - 1 do
    2374         if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))
     2374        if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm))
    23752375        then
    23762376        begin
     
    23802380          if SeeFrom and SeeTo then
    23812381          begin
    2382             TellAboutModel(p1, p, mix);
    2383             if p1 = p then
     2382            TellAboutModel(p1, P, mix);
     2383            if p1 = P then
    23842384              ShowMove.emix := -1
    23852385            else
    2386               ShowMove.emix := emixSafe(p1, p, mix);
     2386              ShowMove.emix := emixSafe(p1, P, mix);
    23872387            CallPlayer(cShowAttacking, p1, ShowMove);
    23882388          end;
    23892389        end;
    23902390
    2391     LoseCityPop := false;
     2391    LoseCityPop := False;
    23922392    if (RealMap[ToLoc] and fCity <> 0) and
    23932393      ((MoveInfo.MoveType = mtAttack) and (MoveInfo.EndHealthDef <= 0) or
     
    24112411    if MoveInfo.MoveType = mtBombard then
    24122412    begin
    2413       assert(Movement >= 100);
     2413      Assert(Movement >= 100);
    24142414      if PModel.Attack = 0 then
    24152415        Flags := Flags and not unBombsLoaded;
    2416       dec(Movement, 100);
     2416      Dec(Movement, 100);
    24172417    end
    24182418    else if MoveInfo.MoveType = mtExpel then
    24192419    begin
    2420       assert(Movement >= 100);
     2420      Assert(Movement >= 100);
    24212421      Job := jNone;
    24222422      Flags := Flags and not unFortified;
    2423       dec(Movement, 100);
     2423      Dec(Movement, 100);
    24242424    end
    24252425    else
    24262426    begin
    2427       assert(MoveInfo.MoveType = mtAttack);
     2427      Assert(MoveInfo.MoveType = mtAttack);
    24282428      if MoveInfo.EndHealth = 0 then
    2429         RemoveUnit(p, uix, MoveInfo.Defender) // destroy attacker
     2429        RemoveUnit(P, uix, MoveInfo.Defender) // destroy attacker
    24302430      else
    24312431      begin // update attacker
     
    24342434          Exp := (nExp - 1) * ExpCost
    24352435        else
    2436           inc(Exp, ExpGain);
     2436          Inc(Exp, ExpGain);
    24372437        Health := MoveInfo.EndHealth;
    24382438        Job := jNone;
     
    24422442        Flags := Flags and not unFortified;
    24432443        if Movement > 100 then
    2444           dec(Movement, 100)
     2444          Dec(Movement, 100)
    24452445        else
    24462446          Movement := 0;
     
    24482448    end;
    24492449
    2450     ZoCDefenderDestroyed := false;
     2450    ZoCDefenderDestroyed := False;
    24512451    nUpdateLoc := 0;
    24522452    if MoveInfo.MoveType = mtExpel then
     
    24692469          PlaceUnit(MoveInfo.Defender, MoveInfo.Duix);
    24702470          UpdateLoc[nUpdateLoc] := Loc;
    2471           inc(nUpdateLoc);
     2471          Inc(nUpdateLoc);
    24722472          Flags := Flags or unWithdrawn;
    24732473        end;
     
    24802480          Exp := (nExp - 1) * ExpCost
    24812481        else
    2482           inc(Exp, ExpGain);
     2482          Inc(Exp, ExpGain);
    24832483        Health := MoveInfo.EndHealthDef;
    24842484      end
     
    24932493          (RealMap[ToLoc] and fTerImp <> tiFort)) or LoseCityPop and
    24942494          (RW[MoveInfo.Defender].City[MoveInfo.Dcix].Size = 2) then
    2495           RemoveAllUnits(MoveInfo.Defender, ToLoc, p)
     2495          RemoveAllUnits(MoveInfo.Defender, ToLoc, P)
    24962496          { no city, base or fortress }
    24972497        else
    2498           RemoveUnit(MoveInfo.Defender, MoveInfo.Duix, p);
     2498          RemoveUnit(MoveInfo.Defender, MoveInfo.Duix, P);
    24992499      end;
    25002500
     
    25092509              begin
    25102510                UpdateLoc[nUpdateLoc] := Loc;
    2511                 inc(nUpdateLoc);
     2511                Inc(nUpdateLoc);
    25122512              end;
    25132513          // unit will be removed -- remember position and update for all players
    2514           DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, false);
     2514          DestroyCity_TellPlayers(MoveInfo.Defender, MoveInfo.Dcix, False);
    25152515          CheckBorders(ToLoc, MoveInfo.Defender);
    2516           RecalcPeaceMap(p);
     2516          RecalcPeaceMap(P);
    25172517        end;
    25182518    end;
    25192519
    25202520    if CityDestroyed and (nUpdateLoc > 0) then
    2521       RecalcMapZoC(p)
     2521      RecalcMapZoC(P)
    25222522    else if ZoCDefenderDestroyed then
    2523       RecalcV8ZoC(p, ToLoc);
     2523      RecalcV8ZoC(P, ToLoc);
    25242524    UpdateUnitMap(FromLoc);
    25252525    UpdateUnitMap(ToLoc, LoseCityPop);
    2526     for i := 0 to nUpdateLoc - 1 do
    2527       UpdateUnitMap(UpdateLoc[i]);
     2526    for I := 0 to nUpdateLoc - 1 do
     2527      UpdateUnitMap(UpdateLoc[I]);
    25282528    // tell about lost units of defender
    25292529
    25302530    if Mode >= moMovie then
    25312531    begin
    2532       for i := 0 to RW[p].nEnemyModel - 1 do
    2533         with RW[p].EnemyModel[i] do
    2534           Lost := Destroyed[p, Owner, mix];
     2532      for I := 0 to RW[P].nEnemyModel - 1 do
     2533        with RW[P].EnemyModel[I] do
     2534          Lost := Destroyed[P, Owner, mix];
    25352535      for p1 := 0 to nPl - 1 do { show after-attack in interface modules }
    2536         if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm))
     2536        if (1 shl p1 and GWatching <> 0) and ((p1 <> P) or (bix[p1].Kind = btTerm))
    25372537        then
    25382538        begin
     
    25592559    end;
    25602560  end;
    2561 end; // ExecuteAttack
    2562 
    2563 function MoveUnit(p, uix, dx, dy: integer; TestOnly: boolean): integer;
     2561end;
     2562
     2563function MoveUnit(P, uix, dx, dy: Integer; TestOnly: Boolean): Integer;
    25642564var
    2565   ToLoc: integer;
     2565  ToLoc: Integer;
    25662566  MoveInfo: TMoveInfo;
    25672567  ShowMove: TShowMove;
    25682568begin
    2569 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
    2570   with RW[p].Un[uix] do
     2569{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
     2570  with RW[P].Un[uix] do
    25712571  begin
    25722572    ToLoc := dLoc(Loc, dx, dy);
    25732573    if (ToLoc < 0) or (ToLoc >= MapSize) then
    25742574    begin
    2575       result := eInvalid;
    2576       exit;
     2575      Result := eInvalid;
     2576      Exit;
    25772577    end;
    2578     result := CalculateMove(p, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo);
    2579     if result = eZOC_EnemySpotted then
     2578    Result := CalculateMove(P, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo);
     2579    if Result = eZOC_EnemySpotted then
    25802580      ZOCTile := ToLoc;
    2581     if (result >= rExecuted) and not TestOnly then
     2581    if (Result >= rExecuted) and not TestOnly then
    25822582    begin
    25832583      ShowMove.dx := dx;
     
    25892589      ShowMove.Exp := Exp;
    25902590      ShowMove.Load := TroopLoad + AirLoad;
    2591       ShowMove.Owner := p;
     2591      ShowMove.Owner := P;
    25922592      if (TroopLoad > 0) or (AirLoad > 0) then
    25932593        ShowMove.Flags := unMulti
     
    26062606      case MoveInfo.MoveType of
    26072607        mtMove, mtCapture, mtSpyMission:
    2608           result := ExecuteMove(p, uix, ToLoc, MoveInfo, ShowMove) or result;
     2608          Result := ExecuteMove(P, uix, ToLoc, MoveInfo, ShowMove) or Result;
    26092609        mtAttack, mtBombard, mtExpel:
    2610           result := ExecuteAttack(p, uix, ToLoc, MoveInfo, ShowMove) or result;
     2610          Result := ExecuteAttack(P, uix, ToLoc, MoveInfo, ShowMove) or Result;
    26112611      end;
    26122612    end;
    2613   end; // with
    2614 end; { MoveUnit }
    2615 
    2616 function Server(Command, Player, Subject: integer; var Data): integer; stdcall;
    2617 
    2618   function CountPrice(const Offer: TOffer; PriceType: integer): integer;
     2613  end;
     2614end;
     2615
     2616function Server(Command, Player, Subject: Integer; var Data): Integer; stdcall;
     2617
     2618  function CountPrice(const Offer: TOffer; PriceType: Integer): Integer;
    26192619  var
    2620     i: integer;
     2620    I: Integer;
    26212621  begin
    2622     result := 0;
    2623     for i := 0 to Offer.nDeliver + Offer.nCost - 1 do
    2624       if Offer.Price[i] and $FFFF0000 = Cardinal(PriceType) then
    2625         inc(result);
     2622    Result := 0;
     2623    for I := 0 to Offer.nDeliver + Offer.nCost - 1 do
     2624      if Offer.Price[I] and $FFFF0000 = Cardinal(PriceType) then
     2625        Inc(Result);
    26262626  end;
    26272627
    26282628{ procedure UpdateBorderHelper;
    26292629  var
    2630   x, y, Loc, Loc1, dx, dy, ObserveMask: integer;
     2630  X, Y, Loc, Loc1, dx, dy, ObserveMask: Integer;
    26312631  begin
    26322632  ObserveMask:=3 shl (2*pTurn);
    2633   for x:=0 to lx-1 do for y:=0 to ly shr 1-1 do
     2633  for X:=0 to lx-1 do for Y:=0 to ly shr 1-1 do
    26342634  begin
    2635   Loc:=lx*(y*2)+x;
     2635  Loc:=lx*(Y*2)+X;
    26362636  if ObserveLevel[Loc] and ObserveMask<>0 then
    26372637  begin
    26382638  for dy:=0 to 1 do for dx:=0 to 1 do
    26392639  begin
    2640   Loc1:=(Loc+dx-1+lx) mod lx +lx*((y+dy)*2-1);
     2640  Loc1:=(Loc+dx-1+lx) mod lx +lx*((Y+dy)*2-1);
    26412641  if (Loc1>=0) and (Loc1<MapSize)
    26422642  and (ObserveLevel[Loc1] and ObserveMask<>0) then
     
    26662666  ptInvalid = 8;
    26672667
    2668   function ProjectType(Project: integer): integer;
     2668  function ProjectType(Project: Integer): Integer;
    26692669  begin
    26702670    if Project and cpCompleted <> 0 then
    2671       result := ptSelect
     2671      Result := ptSelect
    26722672    else if Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    2673       result := ptTrGoods
     2673      Result := ptTrGoods
    26742674    else if Project and cpImp = 0 then
    26752675      if RW[Player].Model[Project and cpIndex].Kind = mkCaravan then
    2676         result := ptCaravan
    2677       else
    2678         result := ptUn
     2676        Result := ptCaravan
     2677      else
     2678        Result := ptUn
    26792679    else if Project and cpIndex >= nImp then
    2680       result := ptInvalid
     2680      Result := ptInvalid
    26812681    else if Imp[Project and cpIndex].Kind = ikWonder then
    2682       result := ptWonder
     2682      Result := ptWonder
    26832683    else if Imp[Project and cpIndex].Kind = ikShipPart then
    2684       result := ptShip
     2684      Result := ptShip
    26852685    else
    2686       result := ptImp;
     2686      Result := ptImp;
    26872687  end;
    26882688
    26892689var
    2690   d, i, j, p1, p2, pt0, pt1, uix1, cix1, Loc0, Loc1, dx, dy, NewCap, MinCap,
     2690  D, I, J, p1, p2, pt0, pt1, uix1, cix1, Loc0, Loc1, dx, dy, NewCap, MinCap,
    26912691    MaxCap, CapWeight, Cost, NextProd, Preq, TotalFood, TotalProd, CheckSum,
    26922692    StopTurn, FutureMCost, NewProject, OldImp, mix, V8, V21, AStr, DStr,
    2693     ABaseDamage, DBaseDamage: integer;
     2693    ABaseDamage, DBaseDamage: Integer;
    26942694  CityReport: TCityReport;
    26952695  FormerCLState: TCmdListState;
     
    26982698  ShowShipChange: TShowShipChange;
    26992699  ShowNegoData: TShowNegoData;
    2700   logged, ok, HasShipChanged, AllHumansDead, OfferFullySupported: boolean;
    2701 
    2702 begin { >>>server }
     2700  logged, ok, HasShipChanged, AllHumansDead, OfferFullySupported: Boolean;
     2701begin
    27032702  if Command = sTurn then
    27042703  begin
     
    27092708  end;
    27102709
    2711   assert(MapSize = lx * ly);
    2712   assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);
     2710  Assert(MapSize = lx * ly);
     2711  Assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);
    27132712  // not for internal commands
    27142713  if (Command < 0) or (Command >= $10000) then
    27152714  begin
    2716     result := eUnknown;
    2717     exit;
     2715    Result := eUnknown;
     2716    Exit;
    27182717  end;
    27192718
     
    27222721    ((Subject < 0) or (Subject >= $1000))) then
    27232722  begin
    2724     result := eInvalid;
    2725     exit;
     2723    Result := eInvalid;
     2724    Exit;
    27262725  end;
    27272726
     
    27322731  begin
    27332732    PutMessage(1 shl 16 + 1, Format('NOT Alive: %d', [Player]));
    2734     result := eNoTurn;
    2735     exit;
     2733    Result := eNoTurn;
     2734    Exit;
    27362735  end;
    27372736
    2738   result := eOK;
     2737  Result := eOK;
    27392738
    27402739  // check if command allowed now
     
    27592758    PutMessage(1 shl 16 + 1, Format('No Turn: %d calls %x',
    27602759      [Player, Command shr 4]));
    2761     result := eNoTurn;
    2762     exit;
     2760    Result := eNoTurn;
     2761    Exit;
    27632762  end;
    27642763
     
    27682767  HandoverStack[nHandoverStack] := Player + $1000;
    27692768  HandoverStack[nHandoverStack + 1] := Command;
    2770   inc(nHandoverStack, 2);
     2769  Inc(nHandoverStack, 2);
    27712770
    27722771  InvalidTreatyMap := 0;
     
    27812780    FormerCLState := CL.State;
    27822781    CL.Put(Command, Player, Subject, @Data);
    2783     logged := true;
     2782    logged := True;
    27842783  end
    27852784  else
    2786     logged := false;
     2785    logged := False;
    27872786
    27882787  case Command of
     
    27992798
    28002799    sGetDebugMap:
    2801       pointer(Data) := DebugMap[Subject];
     2800      Pointer(Data) := DebugMap[Subject];
    28022801
    28032802    { sChangeSuperView:
    28042803      if Difficulty[Player]=0 then
    28052804      begin
    2806       for i:=0 to nBrain-1 do if Brain[i].Initialized then
    2807       CallClient(i, cShowSuperView, Subject)
     2805      for I:=0 to nBrain-1 do if Brain[I].Initialized then
     2806      CallClient(I, cShowSuperView, Subject)
    28082807      end
    2809       else result:=eInvalid; }
     2808      else Result:=eInvalid; }
    28102809
    28112810    sRefreshDebugMap:
     
    28302829          else
    28312830            StopTurn := RW[Player].EnemyReport[Subject].TurnOfCivilReport + 1;
    2832         move(Stat[Command shr 4 and $F, Subject]^, Data,
    2833           StopTurn * SizeOf(integer));
     2831        Move(Stat[Command shr 4 and $F, Subject]^, Data,
     2832          StopTurn * SizeOf(Integer));
    28342833        FillChar(TChart(Data)[StopTurn], (GTurn - StopTurn) *
    2835           SizeOf(integer), 0);
     2834          SizeOf(Integer), 0);
    28362835      end
    28372836      else
    2838         result := eInvalid;
     2837        Result := eInvalid;
    28392838
    28402839    sGetTechCost:
    2841       integer(Data) := TechCost(Player);
     2840      Integer(Data) := TechCost(Player);
    28422841
    28432842    sGetAIInfo:
    28442843      if AIInfo[Subject] = '' then
    2845         pchar(Data) := nil
    2846       else
    2847         pchar(Data) := @AIInfo[Subject][1];
     2844        PChar(Data) := nil
     2845      else
     2846        PChar(Data) := @AIInfo[Subject][1];
    28482847
    28492848    sGetAICredits:
    28502849      if AICredits = '' then
    2851         pchar(Data) := nil
    2852       else
    2853         pchar(Data) := @AICredits[1];
     2850        PChar(Data) := nil
     2851      else
     2852        PChar(Data) := @AICredits[1];
    28542853
    28552854    sGetVersion:
    2856       integer(Data) := CevoVersion;
     2855      Integer(Data) := CevoVersion;
    28572856
    28582857    sGetGameChanged:
    28592858      if Player <> 0 then
    2860         result := eInvalid
     2859        Result := eInvalid
    28612860      else if (CL <> nil) and (CL.State.nLog = nLogOpened) and
    28622861        (CL.State.MoveCode = 0) and not HasCityTileChanges and
    28632862        not HasChanges(Player) then
    2864         result := eNotChanged;
     2863        Result := eNotChanged;
    28652864
    28662865    sGetTileInfo:
    28672866      if (Subject >= 0) and (Subject < MapSize) then
    2868         result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))
    2869       else
    2870         result := eInvalid;
     2867        Result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))
     2868      else
     2869        Result := eInvalid;
    28712870
    28722871    sGetCityTileInfo:
    28732872      if (Subject >= 0) and (Subject < MapSize) then
    2874         result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))
    2875       else
    2876         result := eInvalid;
     2873        Result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))
     2874      else
     2875        Result := eInvalid;
    28772876
    28782877    sGetHypoCityTileInfo:
     
    28812880        if (TTileInfo(Data).ExplCity < 0) or
    28822881          (TTileInfo(Data).ExplCity >= RW[Player].nCity) then
    2883           result := eInvalid
     2882          Result := eInvalid
    28842883        else if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then
    2885           result := eNoPreq
     2884          Result := eNoPreq
    28862885        else
    2887           result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,
     2886          Result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,
    28882887            TTileInfo(Data));
    28892888      end
    28902889      else
    2891         result := eInvalid;
     2890        Result := eInvalid;
    28922891
    28932892    sGetJobProgress:
     
    28952894      begin
    28962895        if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then
    2897           result := eNoPreq
     2896          Result := eNoPreq
    28982897        else
    2899           result := GetJobProgress(Player, Subject, TJobProgressData(Data));
     2898          Result := GetJobProgress(Player, Subject, TJobProgressData(Data));
    29002899      end
    29012900      else
    2902         result := eInvalid;
     2901        Result := eInvalid;
    29032902
    29042903    sGetModels:
     
    29122911      end
    29132912      else
    2914         result := eInvalid;
     2913        Result := eInvalid;
    29152914
    29162915    sGetUnits:
    29172916      if (Subject >= 0) and (Subject < MapSize) and
    29182917        (ObserveLevel[Subject] shr (Player * 2) and 3 = lObserveSuper) then
    2919         integer(Data) := GetUnitStack(Player, Subject)
    2920       else
    2921         result := eNoPreq;
     2918        Integer(Data) := GetUnitStack(Player, Subject)
     2919      else
     2920        Result := eNoPreq;
    29222921
    29232922    sGetDefender:
    29242923      if (Subject >= 0) and (Subject < MapSize) and (Occupant[Subject] = Player)
    29252924      then
    2926         Strongest(Subject, integer(Data), d, i, j)
    2927       else
    2928         result := eInvalid;
     2925        Strongest(Subject, Integer(Data), D, I, J)
     2926      else
     2927        Result := eInvalid;
    29292928
    29302929    sGetBattleForecast, sGetBattleForecastEx:
     
    29362935            ((pAtt = Player) or (RWemix[Player, pAtt, mixAtt] >= 0)) then
    29372936          begin
    2938             result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,
     2937            Result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,
    29392938              cix1, AStr, DStr, ABaseDamage, DBaseDamage);
    29402939            if Command = sGetBattleForecastEx then
     
    29452944              TBattleForecastEx(Data).DBaseDamage := DBaseDamage;
    29462945            end;
    2947             if result = eOK then
    2948               result := eInvalid; // no enemy unit there!
     2946            if Result = eOK then
     2947              Result := eInvalid; // no enemy unit there!
    29492948          end
    29502949          else
    2951             result := eInvalid
    2952       else
    2953         result := eInvalid;
     2950            Result := eInvalid
     2951      else
     2952        Result := eInvalid;
    29542953
    29552954    sGetUnitReport:
    29562955      if (Subject < 0) or (Subject >= RW[Player].nUn) or
    29572956        (RW[Player].Un[Subject].Loc < 0) then
    2958         result := eInvalid
     2957        Result := eInvalid
    29592958      else
    29602959        GetUnitReport(Player, Subject, TUnitReport(Data));
     
    29632962      if (Subject < 0) or (Subject >= RW[Player].nUn) or
    29642963        (RW[Player].Un[Subject].Loc < 0) then
    2965         result := eInvalid
    2966       else
    2967         result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));
     2964        Result := eInvalid
     2965      else
     2966        Result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));
    29682967
    29692968    sGetPlaneReturn:
     
    29712970        (RW[Player].Un[Subject].Loc < 0) or
    29722971        (RW[Player].Model[RW[Player].Un[Subject].mix].Domain <> dAir) then
    2973         result := eInvalid
     2972        Result := eInvalid
    29742973      else
    29752974      begin
    29762975        if CanPlaneReturn(Player, Subject, TPlaneReturnData(Data)) then
    2977           result := eOK
     2976          Result := eOK
    29782977        else
    2979           result := eNoWay;
     2978          Result := eNoWay;
    29802979      end;
    29812980
     
    29882987          Owner := Player;
    29892988          SearchCity(Subject, Owner, cix1);
    2990           c := RW[Owner].City[cix1];
    2991           if (Owner <> Player) and (c.Project and cpImp = 0) then
    2992             TellAboutModel(Player, Owner, c.Project and cpIndex);
     2989          C := RW[Owner].City[cix1];
     2990          if (Owner <> Player) and (C.Project and cpImp = 0) then
     2991            TellAboutModel(Player, Owner, C.Project and cpIndex);
    29932992        end
    29942993      else
    2995         result := eInvalid;
     2994        Result := eInvalid;
    29962995
    29972996    sGetCityReport:
    29982997      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    29992998        (RW[Player].City[Subject].Loc < 0) then
    3000         result := eInvalid
    3001       else
    3002         result := GetCityReport(Player, Subject, TCityReport(Data));
     2999        Result := eInvalid
     3000      else
     3001        Result := GetCityReport(Player, Subject, TCityReport(Data));
    30033002
    30043003    sGetCityReportNew:
    30053004      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30063005        (RW[Player].City[Subject].Loc < 0) then
    3007         result := eInvalid
     3006        Result := eInvalid
    30083007      else
    30093008        GetCityReportNew(Player, Subject, TCityReportNew(Data));
     
    30123011      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30133012        (RW[Player].City[Subject].Loc < 0) then
    3014         result := eInvalid
     3013        Result := eInvalid
    30153014      else
    30163015        GetCityAreaInfo(Player, RW[Player].City[Subject].Loc,
     
    30323031      end
    30333032      else
    3034         result := eInvalid;
     3033        Result := eInvalid;
    30353034
    30363035    sGetEnemyCityReportNew:
     
    30493048      end
    30503049      else
    3051         result := eInvalid;
     3050        Result := eInvalid;
    30523051
    30533052    sGetEnemyCityAreaInfo:
     
    30633062      end
    30643063      else
    3065         result := eInvalid;
     3064        Result := eInvalid;
    30663065
    30673066    sGetCityTileAdvice:
    30683067      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30693068        (RW[Player].City[Subject].Loc < 0) then
    3070         result := eInvalid
     3069        Result := eInvalid
    30713070      else
    30723071        GetCityTileAdvice(Player, Subject, TCityTileAdviceData(Data));
     
    30813080          EditTile(Loc, NewTile)
    30823081      else
    3083         result := eInvalid;
     3082        Result := eInvalid;
    30843083
    30853084    sRandomMap:
     
    30873086      begin
    30883087        CreateElevation;
    3089         PreviewElevation := false;
    3090         CreateMap(false);
     3088        PreviewElevation := False;
     3089        CreateMap(False);
    30913090        FillChar(ObserveLevel, MapSize * 4, 0);
    30923091        DiscoverAll(Player, lObserveSuper);
    30933092      end
    30943093      else
    3095         result := eInvalid;
     3094        Result := eInvalid;
    30963095
    30973096    sMapGeneratorRequest:
    30983097      if not MapGeneratorAvailable then
    3099         result := eInvalid;
     3098        Result := eInvalid;
    31003099
    31013100    {
     
    31053104    sTurn, sTurn - sExecute:
    31063105      begin
    3107         AllHumansDead := true;
     3106        AllHumansDead := True;
    31083107        for p1 := 0 to nPl - 1 do
    31093108          if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then
    3110             AllHumansDead := false;
     3109            AllHumansDead := False;
    31113110        if (pDipActive >= 0) // still in negotiation mode
    31123111          or (pTurn = 0) and ((GWinner > 0) or (GTurn = MaxTurn) or
    31133112          (Difficulty[0] > 0) and AllHumansDead) then // game end reached
    3114           result := eViolation
     3113          Result := eViolation
    31153114        else if Command >= sExecute then
    31163115        begin
     
    31233122            begin
    31243123              LogChanges;
    3125               SaveGame('~' + LogFileName, true);
     3124              SaveGame('~' + LogFileName, True);
    31263125            end;
    31273126{$ENDIF}
     
    31383137            TotalFood := 0;
    31393138            TotalProd := 0;
    3140             for i := 0 to RW[pTurn].nCity - 1 do
    3141               if RW[pTurn].City[i].Loc >= 0 then
     3139            for I := 0 to RW[pTurn].nCity - 1 do
     3140              if RW[pTurn].City[I].Loc >= 0 then
    31423141              begin
    3143                 inc(TotalFood, RW[pTurn].City[i].Food);
    3144                 inc(TotalProd, RW[pTurn].City[i].Prod);
     3142                Inc(TotalFood, RW[pTurn].City[I].Food);
     3143                Inc(TotalProd, RW[pTurn].City[I].Prod);
    31453144              end;
    31463145            CheckSum := TotalFood and 7 + TotalProd and 7 shl 3 +
     
    31533152          begin
    31543153            if CheckSum <> Subject then
    3155               LoadOK := false;
     3154              LoadOK := False;
    31563155          end
    31573156          else // save checksum
     
    31803179            pTurn := (pTurn + 1) mod nPl;
    31813180            if pTurn = 0 then
    3182               inc(GTurn);
     3181              Inc(GTurn);
    31833182            if Assigned(bix[pTurn]) and ((1 shl pTurn) and GAlive = 0) then
    31843183            begin // already made extinct -- continue statistics
     
    32193218    sBreak, sResign, sNextRound, sReload:
    32203219      if Mode = moMovie then
    3221         MovieStopped := true
     3220        MovieStopped := True
    32223221      else
    32233222      begin
     
    32253224        begin
    32263225          ok := (Difficulty[0] = 0) and (bix[0].Kind <> btNoTerm) and
    3227             (integer(Data) >= 0) and (integer(Data) < GTurn);
     3226            (Integer(Data) >= 0) and (Integer(Data) < GTurn);
    32283227          for p1 := 1 to nPl - 1 do
    32293228            if bix[p1].Kind = btTerm then
    3230               ok := false;
     3229              ok := False;
    32313230          // allow reload in AI-only games only
    32323231        end
     
    32373236          if (Command = sBreak) or (Command = sResign) then
    32383237            Notify(ntBackOn);
    3239           for i := 0 to Brains.Count - 1 do
    3240             if Brains[i].Initialized then
     3238          for I := 0 to Brains.Count - 1 do
     3239            if Brains[I].Initialized then
    32413240            begin
    3242               if Brains[i].Kind = btAI then
    3243                 Notify(ntDeinitModule, i);
    3244               CallClient(i, cBreakGame, nil^);
     3241              if Brains[I].Kind = btAI then
     3242                Notify(ntDeinitModule, I);
     3243              CallClient(I, cBreakGame, nil^);
    32453244            end;
    32463245          Notify(ntEndInfo);
     
    32493248            LogCityTileChanges;
    32503249            LogChanges;
    3251             SaveGame(LogFileName, false);
     3250            SaveGame(LogFileName, False);
    32523251          end;
    32533252          DeleteFile(SavePath + '~' + LogFileName);
     
    32623261                LandMass, MaxTurn);
    32633262            sReload:
    3264               LoadGame(SavePath, LogFileName, integer(Data), false);
     3263              LoadGame(SavePath, LogFileName, Integer(Data), False);
    32653264          end;
    32663265        end
    32673266        else
    3268           result := eInvalid;
     3267          Result := eInvalid;
    32693268      end;
    32703269
     
    32833282      end
    32843283      else
    3285         result := eInvalid;
     3284        Result := eInvalid;
    32863285
    32873286    scContact .. scContact + (nPl - 1) shl 4, scContact - sExecute .. scContact
    32883287      - sExecute + (nPl - 1) shl 4:
    32893288      if (pDipActive >= 0) or (1 shl (Command shr 4 and $F) and GAlive = 0) then
    3290         result := eInvalid
     3289        Result := eInvalid
    32913290      else if GWinner > 0 then
    3292         result := eViolation // game end reached
     3291        Result := eViolation // game end reached
    32933292      else if RW[Player].Treaty[Command shr 4 and $F] = trNoContact then
    3294         result := eNoPreq
     3293        Result := eNoPreq
    32953294      else if GTurn < GColdWarStart + ColdWarTurns then
    3296         result := eColdWar
     3295        Result := eColdWar
    32973296      else if RW[Player].Government = gAnarchy then
    3298         result := eAnarchy
     3297        Result := eAnarchy
    32993298      else if RW[Command shr 4 and $F].Government = gAnarchy then
    33003299      begin
    3301         result := eAnarchy;
     3300        Result := eAnarchy;
    33023301        LastEndClientCommand := scReject; // enable cancel treaty
    33033302        pContacted := Command shr 4 and $F;
     
    33073306        pContacted := Command shr 4 and $F;
    33083307        pDipActive := pContacted;
    3309         assert(Mode = moPlaying);
     3308        Assert(Mode = moPlaying);
    33103309        Inform(pDipActive);
    33113310        ChangeClientWhenDone(scContact, pDipActive, pTurn, 4);
     
    33183317        begin // contact requested and not accepted yet
    33193318          pDipActive := -1;
    3320           assert(Mode = moPlaying);
     3319          Assert(Mode = moPlaying);
    33213320          ChangeClientWhenDone(cContinue, pTurn, nil^, 0);
    33223321        end;
    33233322      end
    33243323      else
    3325         result := eInvalid;
     3324        Result := eInvalid;
    33263325
    33273326    scDipStart, scDipStart - sExecute:
     
    33343333            RW[pTurn].Credibility;
    33353334          pDipActive := pTurn;
    3336           assert(Mode = moPlaying);
     3335          Assert(Mode = moPlaying);
    33373336          IntServer(sIntHaveContact, pTurn, pContacted, nil^);
    33383337          ChangeClientWhenDone(scDipStart, pDipActive, nil^, 0);
     
    33403339      end
    33413340      else
    3342         result := eInvalid;
     3341        Result := eInvalid;
    33433342
    33443343    scDipNotice, scDipAccept, scDipCancelTreaty, scDipBreak,
     
    33473346      if pDipActive >= 0 then
    33483347      begin
    3349         assert(Mode = moPlaying);
     3348        Assert(Mode = moPlaying);
    33503349        if pDipActive = pTurn then
    33513350          p1 := pContacted
     
    33633362            // check if offer can be accepted
    33643363            if nDeliver + nCost = 0 then
    3365               result := eOfferNotAcceptable;
    3366             for i := 0 to nDeliver + nCost - 1 do
    3367               if Price[i] = opChoose then
    3368                 result := eOfferNotAcceptable;
    3369             for i := 0 to nCost - 1 do
    3370               if not PayPrice(pDipActive, p1, Price[nDeliver + i], false) then
    3371                 result := eOfferNotAcceptable;
    3372             if (Command >= sExecute) and (result >= rExecuted) then
     3364              Result := eOfferNotAcceptable;
     3365            for I := 0 to nDeliver + nCost - 1 do
     3366              if Price[I] = opChoose then
     3367                Result := eOfferNotAcceptable;
     3368            for I := 0 to nCost - 1 do
     3369              if not PayPrice(pDipActive, p1, Price[nDeliver + I], False) then
     3370                Result := eOfferNotAcceptable;
     3371            if (Command >= sExecute) and (Result >= rExecuted) then
    33733372            begin
    33743373              IntServer(sIntPayPrices + nDeliver + nCost, p1, pDipActive,
     
    33773376
    33783377              // tell other players about ship part trades
    3379               HasShipChanged := false;
     3378              HasShipChanged := False;
    33803379              FillChar(ShowShipChange, SizeOf(ShowShipChange), 0);
    3381               for i := 0 to nDeliver + nCost - 1 do
    3382                 if Price[i] and opMask = opShipParts then
     3380              for I := 0 to nDeliver + nCost - 1 do
     3381                if Price[I] and opMask = opShipParts then
    33833382                begin
    3384                   HasShipChanged := true;
    3385                   if i >= nDeliver then
     3383                  HasShipChanged := True;
     3384                  if I >= nDeliver then
    33863385                  begin // p1 has demanded from pDipActive
    3387                     ShowShipChange.Ship1Change[Price[i] shr 16 and 3] :=
    3388                       +integer(Price[i] and $FFFF);
    3389                     ShowShipChange.Ship2Change[Price[i] shr 16 and 3] :=
    3390                       -integer(Price[i] and $FFFF);
     3386                    ShowShipChange.Ship1Change[Price[I] shr 16 and 3] :=
     3387                      +Integer(Price[I] and $FFFF);
     3388                    ShowShipChange.Ship2Change[Price[I] shr 16 and 3] :=
     3389                      -Integer(Price[I] and $FFFF);
    33913390                  end
    33923391                  else
    33933392                  begin // p1 has delivered to pDipActive
    3394                     ShowShipChange.Ship1Change[Price[i] shr 16 and 3] :=
    3395                       -integer(Price[i] and $FFFF);
    3396                     ShowShipChange.Ship2Change[Price[i] shr 16 and 3] :=
    3397                       +integer(Price[i] and $FFFF);
     3393                    ShowShipChange.Ship1Change[Price[I] shr 16 and 3] :=
     3394                      -Integer(Price[I] and $FFFF);
     3395                    ShowShipChange.Ship2Change[Price[I] shr 16 and 3] :=
     3396                      +Integer(Price[I] and $FFFF);
    33983397                  end;
    33993398                end;
     
    34073406                    (1 shl p2 and (GAlive or GWatching) <> 0) then
    34083407                  begin
    3409                     move(GShip, RW[p2].Ship, SizeOf(GShip));
     3408                    Move(GShip, RW[p2].Ship, SizeOf(GShip));
    34103409                    if 1 shl p2 and GWatching <> 0 then
    34113410                      CallPlayer(cShowShipChange, p2, ShowShipChange);
     
    34203419            (GTurn < RW[pDipActive].LastCancelTreaty[p1] + CancelTreatyTurns)
    34213420          then
    3422             result := eCancelTreatyRush
     3421            Result := eCancelTreatyRush
    34233422          else if Command >= sExecute then
    34243423          begin
     
    34273426              if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then
    34283427              begin
    3429                 i := p1 shl 4 + pDipActive;
    3430                 CallPlayer(cShowSupportAllianceAgainst, p2, i);
     3428                I := p1 shl 4 + pDipActive;
     3429                CallPlayer(cShowSupportAllianceAgainst, p2, I);
    34313430              end;
    34323431            for p2 := 0 to nPl - 1 do
    34333432              if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then
    34343433              begin
    3435                 i := p2;
    3436                 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, i);
     3434                I := p2;
     3435                CallPlayer(cShowCancelTreatyByAlliance, pDipActive, I);
    34373436              end;
    34383437          end;
    34393438        end
    34403439        else
    3441           result := eInvalid;
    3442         if (Command >= sExecute) and (result >= rExecuted) then
     3440          Result := eInvalid;
     3441        if (Command >= sExecute) and (Result >= rExecuted) then
    34433442          if LastEndClientCommand = scDipBreak then
    34443443          begin // break negotiation
     
    34623461      end
    34633462      else
    3464         result := eInvalid;
     3463        Result := eInvalid;
    34653464
    34663465    scDipOffer, scDipOffer - sExecute:
     
    34753474            pDipActive := -1;
    34763475            CallPlayer(cShowEndContact, pContacted, nil^);
    3477             assert(Mode = moPlaying);
     3476            Assert(Mode = moPlaying);
    34783477            ChangeClientWhenDone(cContinue, pTurn, nil^, 0);
    34793478          end;
     
    34883487          if RW[pDipActive].Treaty[p1] < trPeace then
    34893488          begin // no tribute allowed!
    3490             for i := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    3491               if (TOffer(Data).Price[i] and opMask = opTribute) then
    3492                 result := eInvalidOffer;
    3493             for i := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    3494               if (TOffer(Data).Price[i] = opTreaty + trPeace) then
    3495                 result := eOK;
     3489            for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
     3490              if (TOffer(Data).Price[I] and opMask = opTribute) then
     3491                Result := eInvalidOffer;
     3492            for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
     3493              if (TOffer(Data).Price[I] = opTreaty + trPeace) then
     3494                Result := eOK;
    34963495          end;
    3497           for i := 0 to TOffer(Data).nDeliver - 1 do
    3498             if (TOffer(Data).Price[i] <> opChoose) and
    3499               not PayPrice(pDipActive, p1, TOffer(Data).Price[i], false) then
    3500               result := eInvalidOffer;
     3496          for I := 0 to TOffer(Data).nDeliver - 1 do
     3497            if (TOffer(Data).Price[I] <> opChoose) and
     3498              not PayPrice(pDipActive, p1, TOffer(Data).Price[I], False) then
     3499              Result := eInvalidOffer;
    35013500          if CountPrice(TOffer(Data), opTreaty) > 1 then
    3502             result := eInvalidOffer;
    3503           for i := 0 to nShipPart - 1 do
    3504             if CountPrice(TOffer(Data), opShipParts + i shl 16) > 1 then
    3505               result := eInvalidOffer;
     3501            Result := eInvalidOffer;
     3502          for I := 0 to nShipPart - 1 do
     3503            if CountPrice(TOffer(Data), opShipParts + I shl 16) > 1 then
     3504              Result := eInvalidOffer;
    35063505          if CountPrice(TOffer(Data), opMoney) > 1 then
    3507             result := eInvalidOffer;
     3506            Result := eInvalidOffer;
    35083507          if CountPrice(TOffer(Data), opTribute) > 1 then
    3509             result := eInvalidOffer;
     3508            Result := eInvalidOffer;
    35103509          case CountPrice(TOffer(Data), opChoose) of
    35113510            0:
     
    35133512            1:
    35143513              if (TOffer(Data).nCost = 0) or (TOffer(Data).nDeliver = 0) then
    3515                 result := eInvalidOffer;
     3514                Result := eInvalidOffer;
    35163515          else
    3517             result := eInvalidOffer;
     3516            Result := eInvalidOffer;
    35183517          end;
    35193518
    35203519          // !!! check here if cost can be demanded
    35213520
    3522           if (Command >= sExecute) and (result >= rExecuted) then
     3521          if (Command >= sExecute) and (Result >= rExecuted) then
    35233522          begin
    35243523            OfferFullySupported := (TOffer(Data).nDeliver <= 2) and
    35253524              (TOffer(Data).nCost <= 2); // >2 no more allowed
    3526             for i := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
     3525            for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    35273526            begin
    3528               if TOffer(Data).Price[i] and opMask = opTribute then
    3529                 OfferFullySupported := false;
     3527              if TOffer(Data).Price[I] and opMask = opTribute then
     3528                OfferFullySupported := False;
    35303529              // tribute no more part of the game
    3531               if (TOffer(Data).Price[i] and opMask = opTreaty) and
    3532                 (TOffer(Data).Price[i] - opTreaty <= RW[pDipActive].Treaty[p1])
     3530              if (TOffer(Data).Price[I] and opMask = opTreaty) and
     3531                (TOffer(Data).Price[I] - opTreaty <= RW[pDipActive].Treaty[p1])
    35333532              then
    3534                 OfferFullySupported := false;
     3533                OfferFullySupported := False;
    35353534              // agreed treaty end no more part of the game
    3536               if TOffer(Data).Price[i] = opTreaty + trCeaseFire then
    3537                 OfferFullySupported := false;
     3535              if TOffer(Data).Price[I] = opTreaty + trCeaseFire then
     3536                OfferFullySupported := False;
    35383537              // ceasefire no more part of the game
    35393538            end;
     
    35603559              LastOffer := TOffer(Data);
    35613560              // show offered things to receiver
    3562               for i := 0 to LastOffer.nDeliver - 1 do
    3563                 ShowPrice(pDipActive, p1, LastOffer.Price[i]);
     3561              for I := 0 to LastOffer.nDeliver - 1 do
     3562                ShowPrice(pDipActive, p1, LastOffer.Price[I]);
    35643563              pDipActive := p1;
    3565               assert(Mode = moPlaying);
     3564              Assert(Mode = moPlaying);
    35663565              ChangeClientWhenDone(scDipOffer, pDipActive, LastOffer,
    35673566                SizeOf(LastOffer));
    3568             end
    3569           end
     3567            end;
     3568          end;
    35703569        end
    35713570      else
    3572         result := eInvalid;
     3571        Result := eInvalid;
    35733572
    35743573    {
     
    35833582      end
    35843583      else
    3585         result := eInvalid;
     3584        Result := eInvalid;
    35863585
    35873586    sSetTestFlag:
     
    35933592      end
    35943593      else
    3595         result := eInvalid;
     3594        Result := eInvalid;
    35963595
    35973596    sSetGovernment, sSetGovernment - sExecute:
     
    35993598{$IFDEF TEXTLOG}CmdInfo := Format('SetGovernment P%d: %d', [Player, Subject]); {$ENDIF}
    36003599        if RW[Player].Happened and phChangeGov = 0 then
    3601           result := eViolation
     3600          Result := eViolation
    36023601        else if RW[Player].Government = Subject then
    3603           result := eNotChanged
     3602          Result := eNotChanged
    36043603        else if (Subject >= nGov) then
    3605           result := eInvalid
     3604          Result := eInvalid
    36063605        else if (Subject >= gMonarchy) and
    36073606          (RW[Player].Tech[GovPreq[Subject]] < tsApplicable) then
    3608           result := eNoPreq
     3607          Result := eNoPreq
    36093608        else if Command >= sExecute then
    36103609        begin
     
    36143613            then
    36153614              RW[p1].EnemyReport[Player].Government := Subject;
    3616         end
     3615        end;
    36173616      end;
    36183617
     
    36213620{$IFDEF TEXTLOG}CmdInfo := Format('SetRates P%d: %d/%d', [Player, Subject and $F * 10, Subject shr 4 * 10]); {$ENDIF}
    36223621        if Subject and $F + Subject shr 4 > 10 then
    3623           result := eInvalid
     3622          Result := eInvalid
    36243623        else if (RW[Player].TaxRate = Subject and $F * 10) and
    36253624          (RW[Player].LuxRate = Subject shr 4 * 10) then
    3626           result := eNotChanged
     3625          Result := eNotChanged
    36273626        else if Command >= sExecute then
    36283627        begin
    36293628          RW[Player].TaxRate := Subject and $F * 10;
    36303629          RW[Player].LuxRate := Subject shr 4 * 10;
    3631         end
     3630        end;
    36323631      end;
    36333632
     
    36363635{$IFDEF TEXTLOG}CmdInfo := Format('Revolution P%d', [Player]); {$ENDIF}
    36373636        if RW[Player].Government = gAnarchy then
    3638           result := eInvalid
     3637          Result := eInvalid
    36393638        else
    36403639        begin
     
    36583657          if (Mode = moPlaying) and (Subject = adMilitary) and
    36593658            (DevModelTurn[Player] <> GTurn) then
    3660             result := eNoModel
     3659            Result := eNoModel
    36613660          else if Subject <> adMilitary then
    36623661          begin
     
    36643663            begin
    36653664              if Tech[Subject] >= MaxFutureTech_Computing then
    3666                 result := eInvalid;
     3665                Result := eInvalid;
    36673666            end
    36683667            else if Subject in FutureTech then
    36693668            begin
    36703669              if Tech[Subject] >= MaxFutureTech then
    3671                 result := eInvalid;
     3670                Result := eInvalid;
    36723671            end
    36733672            else if Tech[Subject] >= tsApplicable then
    3674               result := eInvalid; // already discovered
     3673              Result := eInvalid; // already discovered
    36753674            if Tech[Subject] <> tsSeen then // look if preqs met
    36763675              if AdvPreq[Subject, 2] <> preNone then
    36773676              begin // 2 of 3 required
    3678                 i := 0;
    3679                 for j := 0 to 2 do
    3680                   if Tech[AdvPreq[Subject, j]] >= tsApplicable then
    3681                     inc(i);
    3682                 if i < 2 then
    3683                   result := eNoPreq;
     3677                I := 0;
     3678                for J := 0 to 2 do
     3679                  if Tech[AdvPreq[Subject, J]] >= tsApplicable then
     3680                    Inc(I);
     3681                if I < 2 then
     3682                  Result := eNoPreq;
    36843683              end
    36853684              else if (AdvPreq[Subject, 0] <> preNone) and
     
    36873686                (AdvPreq[Subject, 1] <> preNone) and
    36883687                (Tech[AdvPreq[Subject, 1]] < tsApplicable) then
    3689                 result := eNoPreq;
     3688                Result := eNoPreq;
    36903689          end;
    3691           if (result = eOK) and (Command >= sExecute) then
     3690          if (Result = eOK) and (Command >= sExecute) then
    36923691          begin
    36933692            if (Mode = moPlaying) and (Subject = adMilitary) then
     
    36983697        end
    36993698        else
    3700           result := eViolation;
     3699          Result := eViolation;
    37013700      end;
    37023701
     
    37063705        {$ENDIF}
    37073706        if RW[Player].Happened and phStealTech = 0 then
    3708           result := eInvalid
     3707          Result := eInvalid
    37093708        else if (Subject >= nAdv) or (Subject in FutureTech) or
    37103709          (RW[Player].Tech[Subject] >= tsSeen) or
    37113710          (RW[GStealFrom].Tech[Subject] < tsApplicable) then
    3712           result := eInvalid
     3711          Result := eInvalid
    37133712        else if Command >= sExecute then
    37143713        begin
    37153714          SeeTech(Player, Subject);
    3716           dec(RW[Player].Happened, phStealTech);
     3715          Dec(RW[Player].Happened, phStealTech);
    37173716        end;
    37183717      end;
     
    37253724        if (Subject >= nAttitude) or (p1 >= nPl) or
    37263725          (RW[Player].EnemyReport[p1] = nil) then
    3727           result := eInvalid
     3726          Result := eInvalid
    37283727        else if RW[Player].Treaty[p1] = trNoContact then
    3729           result := eNoPreq
     3728          Result := eNoPreq
    37303729        else if RW[Player].Attitude[p1] = Subject then
    3731           result := eNotChanged
     3730          Result := eNotChanged
    37323731        else if Command >= sExecute then
    37333732        begin
     
    37403739      if (LastEndClientCommand <> scReject) or
    37413740        (RW[Player].Treaty[pContacted] < trPeace) then
    3742         result := eInvalid
     3741        Result := eInvalid
    37433742      else if (ServerVersion[Player] >= $010100) and
    37443743        (GTurn < RW[Player].LastCancelTreaty[pContacted] + CancelTreatyTurns)
    37453744      then
    3746         result := eCancelTreatyRush
     3745        Result := eCancelTreatyRush
    37473746      else if Command >= sExecute then
    37483747      begin
     
    37523751          if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then
    37533752          begin
    3754             i := pContacted shl 4 + Player;
    3755             CallPlayer(cShowSupportAllianceAgainst, p2, i);
     3753            I := pContacted shl 4 + Player;
     3754            CallPlayer(cShowSupportAllianceAgainst, p2, I);
    37563755          end;
    37573756        for p2 := 0 to nPl - 1 do
    37583757          if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then
    37593758          begin
    3760             i := p2;
    3761             CallPlayer(cShowCancelTreatyByAlliance, Player, i);
     3759            I := p2;
     3760            CallPlayer(cShowCancelTreatyByAlliance, Player, I);
    37623761          end;
    37633762        LastEndClientCommand := sTurn;
     
    37723771{$IFDEF TEXTLOG}CmdInfo := Format('CreateDevModel P%d', [Player]); {$ENDIF}
    37733772        if Subject >= 4 then
    3774           result := eInvalid
     3773          Result := eInvalid
    37753774        else if (upgrade[Subject, 0].Preq <> preNone) and
    37763775          (RW[Player].Tech[upgrade[Subject, 0].Preq] < tsApplicable) then
    3777           result := eNoPreq
     3776          Result := eNoPreq
    37783777        else if Command >= sExecute then
    37793778        begin
     
    37863785            Upgrades := 0;
    37873786            FutureMCost := 0;
    3788             for i := 0 to nUpgrade - 1 do
    3789               with upgrade[Domain, i] do
     3787            for I := 0 to nUpgrade - 1 do
     3788              with upgrade[Domain, I] do
    37903789                if (Preq = preNone) or (Preq >= 0) and
    37913790                  ((RW[Player].Tech[Preq] >= tsApplicable) or
     
    37943793                  if Preq in FutureTech then
    37953794                  begin
    3796                     j := RW[Player].Tech[Preq];
    3797                     inc(FutureMCost, j * Cost);
     3795                    J := RW[Player].Tech[Preq];
     3796                    Inc(FutureMCost, J * Cost);
    37983797                  end
    37993798                  else
    38003799                  begin
    3801                     j := 1;
     3800                    J := 1;
    38023801                    if Cost > MCost then
    38033802                      MCost := Cost;
    38043803                  end;
    3805                   inc(Upgrades, 1 shl i);
    3806                   inc(MStrength, j * Strength);
    3807                   inc(MTrans, j * Trans);
     3804                  Inc(Upgrades, 1 shl I);
     3805                  Inc(MStrength, J * Strength);
     3806                  Inc(MTrans, J * Trans);
    38083807                end;
    3809             inc(MCost, FutureMCost);
     3808            Inc(MCost, FutureMCost);
    38103809            FillChar(Cap, SizeOf(Cap), 0);
    38113810            Cap[mcOffense] := 2;
    38123811            Cap[mcDefense] := 1;
    3813             for i := 0 to nFeature - 1 do
    3814               with Feature[i] do
     3812            for I := 0 to nFeature - 1 do
     3813              with Feature[I] do
    38153814                if (1 shl Domain and Domains <> 0) and
    38163815                  ((Preq = preNone) or (Preq = preSun) and
    38173816                  (GWonder[woSun].EffectiveOwner = Player) or (Preq >= 0) and
    3818                   (RW[Player].Tech[Preq] >= tsApplicable)) and (i in AutoFeature)
     3817                  (RW[Player].Tech[Preq] >= tsApplicable)) and (I in AutoFeature)
    38193818                then
    3820                   Cap[i] := 1;
     3819                  Cap[I] := 1;
    38213820            MaxWeight := 5;
    38223821            if (WeightPreq7[Domain] <> preNA) and
     
    38403839{$IFDEF TEXTLOG}CmdInfo := Format('SetDevModelCap P%d', [Player]); {$ENDIF}
    38413840        if Subject >= nFeature then
    3842           result := eInvalid
     3841          Result := eInvalid
    38433842        else if DevModelTurn[Player] = GTurn then
    38443843        begin
     
    38463845          with RW[Player].DevModel do
    38473846            if 1 shl Domain and Feature[Subject].Domains = 0 then
    3848               result := eDomainMismatch
     3847              Result := eDomainMismatch
    38493848            else if not((Feature[Subject].Preq = preNone) or
    38503849              (Feature[Subject].Preq = preSun) and
     
    38523851              (Feature[Subject].Preq >= 0) and
    38533852              (RW[Player].Tech[Feature[Subject].Preq] >= tsApplicable)) then
    3854               result := eNoPreq
     3853              Result := eNoPreq
    38553854            else
    38563855            begin
     
    38683867                  MaxCap := 3;
    38693868                if RW[Player].Tech[adSteel] >= tsApplicable then
    3870                   inc(MaxCap);
     3869                  Inc(MaxCap);
    38713870              end
    38723871              else
     
    38783877              if (NewCap < MinCap) or (NewCap > MaxCap) or
    38793878                (Weight + (NewCap - Cap[Subject]) * CapWeight > MaxWeight) then
    3880                 result := eViolation
     3879                Result := eViolation
    38813880              else if Command >= sExecute then
    38823881              begin
     
    39213920        end
    39223921        else
    3923           result := eNoModel;
     3922          Result := eNoModel;
    39243923      end;
    39253924
     
    39323931{$IFDEF TEXTLOG}CmdInfo := Format('RemoveUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    39333932        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    3934           result := eInvalid
     3933          Result := eInvalid
    39353934        else
    39363935        begin
    3937           result := eRemoved;
     3936          Result := eRemoved;
    39383937          Loc0 := RW[Player].Un[Subject].Loc;
    39393938          if RealMap[Loc0] and fCity <> 0 then { check utilize }
     
    39473946                (Project and cpImp = 0) and
    39483947                (RW[Player].Model[Project and cpIndex].Kind <> mkCaravan) then
    3949                 result := eUtilized;
     3948                Result := eUtilized;
    39503949              if Command >= sExecute then
    39513950              begin
    3952                 if result = eUtilized then
     3951                if Result = eUtilized then
    39533952                begin
    39543953                  with RW[Player].Un[Subject] do
    39553954                  begin
    3956                     Cost := integer(RW[Player].Model[mix].Cost) * Health *
     3955                    Cost := Integer(RW[Player].Model[mix].Cost) * Health *
    39573956                      BuildCostMod[Difficulty[Player]] div 1200;
    39583957                    if RW[Player].Model[mix].Cap[mcLine] > 0 then
     
    39603959                  end;
    39613960                  if Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    3962                     inc(RW[Player].Money, Cost)
     3961                    Inc(RW[Player].Money, Cost)
    39633962                  else
    39643963                  begin
    3965                     inc(Prod, Cost * 2 div 3);
     3964                    Inc(Prod, Cost * 2 div 3);
    39663965                    Project0 := Project0 and not cpCompleted;
    39673966                    if Project0 and not cpAuto <> Project and not cpAuto then
     
    39833982{$IFDEF TEXTLOG}CmdInfo := Format('SetUnitHome P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    39843983        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    3985           result := eInvalid
     3984          Result := eInvalid
    39863985        else
    39873986        begin
    39883987          Loc0 := RW[Player].Un[Subject].Loc;
    39893988          if RealMap[Loc0] and fCity = 0 then
    3990             result := eInvalid
     3989            Result := eInvalid
    39913990          else
    39923991          begin
    39933992            SearchCity(Loc0, Player, cix1);
    39943993            if RW[Player].City[cix1].Flags and chCaptured <> 0 then
    3995               result := eViolation
     3994              Result := eViolation
    39963995            else if Command >= sExecute then
    39973996              RW[Player].Un[Subject].Home := cix1;
     
    40104009{$IFDEF TEXTLOG}CmdInfo := Format('LoadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40114010        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4012           result := eInvalid
     4011          Result := eInvalid
    40134012        else
    4014           result := LoadUnit(Player, Subject, Command < sExecute);
     4013          Result := LoadUnit(Player, Subject, Command < sExecute);
    40154014      end;
    40164015
     
    40194018{$IFDEF TEXTLOG}CmdInfo := Format('UnloadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40204019        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4021           result := eInvalid
     4020          Result := eInvalid
    40224021        else
    4023           result := UnloadUnit(Player, Subject, Command < sExecute);
     4022          Result := UnloadUnit(Player, Subject, Command < sExecute);
    40244023      end;
    40254024
    40264025    sSelectTransport, sSelectTransport - sExecute:
    40274026      if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4028         result := eInvalid
     4027        Result := eInvalid
    40294028      else
    40304029        with RW[Player].Model[RW[Player].Un[Subject].mix] do
    40314030        begin
    40324031          if Cap[mcSeaTrans] + Cap[mcAirTrans] + Cap[mcCarrier] = 0 then
    4033             result := eInvalid
     4032            Result := eInvalid
    40344033          else if Command >= sExecute then
    40354034            uixSelectedTransport := Subject;
     
    40424041      begin
    40434042        p1 := Command shr 4 and $F;
    4044         Loc1 := integer(Data);
     4043        Loc1 := Integer(Data);
    40454044        if (Occupant[Loc1] >= 0) and (p1 <> Occupant[Loc1]) or
    40464045          (RealMap[Loc1] and fCity <> 0) and
    40474046          (RealMap[Loc1] shr 27 <> Cardinal(p1)) or
    40484047          (RW[p1].Model[Subject].Domain < dAir) and
    4049           ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[integer(Data)] and
     4048          ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[Integer(Data)] and
    40504049          fTerrain < fGrass)) then
    4051           result := eViolation
     4050          Result := eViolation
    40524051        else if Command >= sExecute then
    40534052        begin
    40544053          CreateUnit(p1, Subject);
    4055           RW[p1].Un[RW[p1].nUn - 1].Loc := integer(Data);
     4054          RW[p1].Un[RW[p1].nUn - 1].Loc := Integer(Data);
    40564055          PlaceUnit(p1, RW[p1].nUn - 1);
    4057           UpdateUnitMap(integer(Data));
     4056          UpdateUnitMap(Integer(Data));
    40584057        end;
    40594058      end
    40604059      else
    4061         result := eInvalid;
     4060        Result := eInvalid;
    40624061
    40634062    sMoveUnit + (0 + 6 * 8) * 16, sMoveUnit + (1 + 7 * 8) * 16,
     
    40764075{$IFDEF TEXTLOG}CmdInfo := Format('MoveUnit P%d I%d Mod%d Loc%d (%d,%d)', [Player, Subject, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc, dx, dy]); {$ENDIF}
    40774076        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4078           result := eInvalid
     4077          Result := eInvalid
    40794078        else
    4080           result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);
     4079          Result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);
    40814080      end;
    40824081
     
    40894088{$IFDEF TEXTLOG}CmdInfo := Format('AddToCity P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40904089        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4091           result := eInvalid
     4090          Result := eInvalid
    40924091        else if not(RW[Player].Model[RW[Player].Un[Subject].mix].Kind
    40934092          in [mkSettler, mkSlaves]) and
    40944093          (RW[Player].Un[Subject].Flags and unConscripts = 0) then
    4095           result := eViolation
     4094          Result := eViolation
    40964095        else
    40974096        begin
    40984097          Loc0 := RW[Player].Un[Subject].Loc;
    40994098          if RealMap[Loc0] and fCity = 0 then
    4100             result := eInvalid
     4099            Result := eInvalid
    41014100          else
    41024101          begin
     
    41044103            with RW[Player].City[cix1] do
    41054104              if not CanCityGrow(Player, cix1) then
    4106                 result := eMaxSize
     4105                Result := eMaxSize
    41074106              else if Command >= sExecute then
    41084107              begin { add to city }
     
    41244123      begin
    41254124        Loc0 := RW[Player].Un[Subject].Loc;
    4126         i := Command shr 4 and $3F; // new job
    4127 {$IFDEF TEXTLOG}CmdInfo := Format('StartJob P%d Mod%d Loc%d: %d', [Player, RW[Player].Un[Subject].mix, Loc0, i]); {$ENDIF}
     4125        I := Command shr 4 and $3F; // new job
     4126{$IFDEF TEXTLOG}CmdInfo := Format('StartJob P%d Mod%d Loc%d: %d', [Player, RW[Player].Un[Subject].mix, Loc0, I]); {$ENDIF}
    41284127        if (Subject >= RW[Player].nUn) or (Loc0 < 0) then
    4129           result := eInvalid
    4130         else if i >= nJob then
    4131           result := eInvalid
     4128          Result := eInvalid
     4129        else if I >= nJob then
     4130          Result := eInvalid
    41324131        else
    41334132        begin
    4134           result := StartJob(Player, Subject, i, Command < sExecute);
    4135           if result = eCity then
     4133          Result := StartJob(Player, Subject, I, Command < sExecute);
     4134          if Result = eCity then
    41364135          begin // new city
    41374136            cix1 := RW[Player].nCity - 1;
     
    41584157    sSetCityProject, sSetCityProject - sExecute:
    41594158      begin
    4160         NewProject := integer(Data) and not cpAuto;
     4159        NewProject := Integer(Data) and not cpAuto;
    41614160{$IFDEF TEXTLOG}CmdInfo := Format('SetCityProject P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, NewProject]); {$ENDIF}
    41624161        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    41634162        then
    4164           result := eInvalid
     4163          Result := eInvalid
    41654164        else
    41664165          with RW[Player].City[Subject] do
    41674166          begin
    41684167            if NewProject = Project then
    4169               result := eNotChanged
     4168              Result := eNotChanged
    41704169            else
    41714170            begin
     
    41754174              begin
    41764175                if NewProject and cpIndex >= RW[Player].nModel then
    4177                   result := eInvalid
     4176                  Result := eInvalid
    41784177                else if (NewProject and cpConscripts <> 0) and
    41794178                  not((RW[Player].Tech[adConscription] >= tsApplicable) and
     
    41814180                  and (RW[Player].Model[NewProject and cpIndex].Kind < mkScout))
    41824181                then
    4183                   result := eViolation
     4182                  Result := eViolation
    41844183                  // else if (RW[Player].Model[NewProject and cpIndex].Kind=mkSlaves)
    41854184                  // and (GWonder[woPyramids].EffectiveOwner<>Player) then
     
    41874186              end
    41884187              else if NewProject and cpIndex >= nImp then
    4189                 result := eInvalid
     4188                Result := eInvalid
    41904189              else
    41914190              begin
    41924191                Preq := Imp[NewProject and cpIndex].Preq;
    4193                 for i := 0 to nImpReplacement - 1 do
    4194                   if (ImpReplacement[i].OldImp = NewProject and cpIndex) and
    4195                     (built[ImpReplacement[i].NewImp] > 0) then
    4196                     result := eObsolete;
    4197                 if result = eObsolete then
     4192                for I := 0 to nImpReplacement - 1 do
     4193                  if (ImpReplacement[I].OldImp = NewProject and cpIndex) and
     4194                    (built[ImpReplacement[I].NewImp] > 0) then
     4195                    Result := eObsolete;
     4196                if Result = eObsolete then
    41984197                else if Preq = preNA then
    4199                   result := eInvalid
     4198                  Result := eInvalid
    42004199                else if (Preq >= 0) and (RW[Player].Tech[Preq] < tsApplicable)
    42014200                then
    4202                   result := eNoPreq
     4201                  Result := eNoPreq
    42034202                else if built[NewProject and cpIndex] > 0 then
    4204                   result := eInvalid
     4203                  Result := eInvalid
    42054204                else if (NewProject and cpIndex < nWonder) and
    42064205                  (GWonder[NewProject and cpIndex].CityID <> WonderNotBuiltYet) then
    4207                   result := eViolation // wonder already exists
     4206                  Result := eViolation // wonder already exists
    42084207                else if (NewProject and cpIndex = imSpacePort) and
    42094208                  (RW[Player].NatBuilt[imSpacePort] > 0) then
    4210                   result := eViolation // space port already exists
     4209                  Result := eViolation // space port already exists
    42114210                else if (NewProject = cpImp + imBank) and (built[imMarket] = 0)
    42124211                  or (NewProject = cpImp + imUniversity) and
     
    42144213                  (built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant)
    42154214                  and (built[imFactory] = 0) then
    4216                   result := eNoPreq;
     4215                  Result := eNoPreq;
    42174216                case NewProject - cpImp of
    42184217                  woLighthouse, woMagellan, imCoastalFort, imHarbor, imPlatform:
     
    42254224                        if (Loc1 >= 0) and (Loc1 < MapSize) and
    42264225                          (RealMap[Loc1] and fTerrain = fShore) then
    4227                           inc(Preq);
     4226                          Inc(Preq);
    42284227                      end;
    42294228                      if Preq = 0 then
    4230                         result := eNoPreq;
     4229                        Result := eNoPreq;
    42314230                    end;
    42324231                  woHoover, imHydro:
     
    42404239                          ((RealMap[Loc1] and fTerrain = fMountains) or
    42414240                          (RealMap[Loc1] and fRiver <> 0)) then
    4242                           inc(Preq);
     4241                          Inc(Preq);
    42434242                      end;
    42444243                      if Preq = 0 then
    4245                         result := eNoPreq;
     4244                        Result := eNoPreq;
    42464245                    end;
    42474246                  woMIR, imShipComp, imShipPow, imShipHab:
    42484247                    if RW[Player].NatBuilt[imSpacePort] = 0 then
    4249                       result := eNoPreq;
     4248                      Result := eNoPreq;
    42504249                end;
    42514250                if (GTestFlags and tfNoRareNeed = 0) and
    42524251                  (Imp[NewProject and cpIndex].Kind = ikShipPart) then
    42534252                  if RW[Player].Tech[adMassProduction] < tsApplicable then
    4254                     result := eNoPreq
     4253                    Result := eNoPreq
    42554254                  else
    42564255                  begin // check for rare resources
    42574256                    if NewProject and cpIndex = imShipComp then
    4258                       j := 1
     4257                      J := 1
    42594258                    else if NewProject and cpIndex = imShipPow then
    4260                       j := 2
     4259                      J := 2
    42614260                    else { if NewProject and cpIndex=imShipHab then }
    4262                       j := 3;
     4261                      J := 3;
    42634262                    // j = rare resource required
    42644263                    Preq := 0;
     
    42684267                      Loc1 := Radius[V21];
    42694268                      if (Loc1 >= 0) and (Loc1 < MapSize) and
    4270                         (RealMap[Loc1] shr 25 and 3 = Cardinal(j)) then
    4271                         inc(Preq);
     4269                        (RealMap[Loc1] shr 25 and 3 = Cardinal(J)) then
     4270                        Inc(Preq);
    42724271                    end;
    42734272                    if Preq = 0 then
    4274                       result := eNoPreq;
     4273                      Result := eNoPreq;
    42754274                  end;
    42764275              end;
    42774276
    4278               if (Command >= sExecute) and (result >= rExecuted) then
     4277              if (Command >= sExecute) and (Result >= rExecuted) then
    42794278              begin
    42804279                if pt0 <> ptSelect then
     
    42854284                    and (pt0 <> ptCaravan) then
    42864285                  begin
    4287                     inc(RW[Player].Money, Prod0);
     4286                    Inc(RW[Player].Money, Prod0);
    42884287                    Prod := 0;
    42894288                    Prod0 := 0;
     
    42924291                  else
    42934292                    Prod := Prod0 * 2 div 3;
    4294                 Project := NewProject
     4293                Project := NewProject;
    42954294              end;
    42964295            end;
     
    43034302        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43044303        then
    4305           result := eInvalid
     4304          Result := eInvalid
    43064305        else
    43074306          with RW[Player].City[Subject] do
    43084307            if (RW[Player].Government = gAnarchy) or (Flags and chCaptured <> 0)
    43094308            then
    4310               result := eOutOfControl
     4309              Result := eOutOfControl
    43114310            else if (Project and cpImp <> 0) and
    43124311              ((Project and cpIndex = imTrGoods) or
    43134312              (Imp[Project and cpIndex].Kind = ikShipPart)) then
    4314               result := eInvalid // don't buy colony ship
     4313              Result := eInvalid // don't buy colony ship
    43154314            else
    43164315            begin
     
    43314330                Cost := Cost * 4;
    43324331              if Cost <= 0 then
    4333                 result := eNotChanged
     4332                Result := eNotChanged
    43344333              else if Cost > RW[Player].Money then
    4335                 result := eViolation
     4334                Result := eViolation
    43364335              else if Command >= sExecute then
    43374336                IntServer(sIntBuyMaterial, Player, Subject, Cost);
     
    43464345        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43474346        then
    4348           result := eInvalid
     4347          Result := eInvalid
    43494348        else if Command >= sExecute then
    43504349          with RW[Player].City[Subject] do
    43514350          begin
    4352             inc(RW[Player].Money, Prod0);
     4351            Inc(RW[Player].Money, Prod0);
    43534352            Prod := 0;
    43544353            Prod0 := 0;
     
    43584357    sSellCityImprovement, sSellCityImprovement - sExecute:
    43594358      begin
    4360 {$IFDEF TEXTLOG}CmdInfo := Format('SellCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, integer(Data)]); {$ENDIF}
     4359{$IFDEF TEXTLOG}CmdInfo := Format('SellCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, Integer(Data)]); {$ENDIF}
    43614360        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43624361        then
    4363           result := eInvalid
     4362          Result := eInvalid
    43644363        else
    43654364          with RW[Player].City[Subject] do
    4366             if built[integer(Data)] = 0 then
    4367               result := eInvalid
     4365            if built[Integer(Data)] = 0 then
     4366              Result := eInvalid
    43684367            else if (RW[Player].Government = gAnarchy) or
    43694368              (Flags and chCaptured <> 0) then
    4370               result := eOutOfControl
     4369              Result := eOutOfControl
    43714370            else if Flags and chImprovementSold <> 0 then
    4372               result := eOnlyOnce
     4371              Result := eOnlyOnce
    43734372            else if Command >= sExecute then
    43744373            begin
    4375               inc(RW[Player].Money, Imp[integer(Data)].Cost * BuildCostMod
     4374              Inc(RW[Player].Money, Imp[Integer(Data)].Cost * BuildCostMod
    43764375                [Difficulty[Player]] div 12);
    4377               built[integer(Data)] := 0;
    4378               if Imp[integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
     4376              built[Integer(Data)] := 0;
     4377              if Imp[Integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
    43794378              begin
    4380                 RW[Player].NatBuilt[integer(Data)] := 0;
    4381                 case integer(Data) of
     4379                RW[Player].NatBuilt[Integer(Data)] := 0;
     4380                case Integer(Data) of
    43824381                  imGrWall:
    43834382                    GrWallContinent[Player] := -1;
     
    43864385                end;
    43874386              end;
    4388               inc(Flags, chImprovementSold);
     4387              Inc(Flags, chImprovementSold);
    43894388            end;
    43904389      end;
     
    43924391    sRebuildCityImprovement, sRebuildCityImprovement - sExecute:
    43934392      begin
    4394         OldImp := integer(Data);
     4393        OldImp := Integer(Data);
    43954394{$IFDEF TEXTLOG}CmdInfo := Format('RebuildCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, OldImp]); {$ENDIF}
    43964395        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43974396        then
    4398           result := eInvalid
     4397          Result := eInvalid
    43994398        else
    44004399        begin
    44014400          if (OldImp < 0) or (OldImp >= nImp) or
    44024401            not(Imp[OldImp].Kind in [ikCommon, ikNatLocal, ikNatGlobal]) then
    4403             result := eInvalid
     4402            Result := eInvalid
    44044403          else
    44054404            with RW[Player].City[Subject] do
     
    44074406                not(Imp[Project and cpIndex].Kind in [ikCommon, ikNatLocal,
    44084407                ikNatGlobal]) then
    4409                 result := eInvalid
     4408                Result := eInvalid
    44104409              else if (RW[Player].Government = gAnarchy) or
    44114410                (Flags and chCaptured <> 0) then
    4412                 result := eOutOfControl
     4411                Result := eOutOfControl
    44134412              else if Flags and chImprovementSold <> 0 then
    4414                 result := eOnlyOnce
     4413                Result := eOnlyOnce
    44154414              else if Command >= sExecute then
    44164415              begin
    4417                 inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]
     4416                Inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]
    44184417                  div 12 * 2 div 3);
    44194418                Project0 := Project0 and not cpCompleted;
     
    44324431                  end;
    44334432                end;
    4434                 inc(Flags, chImprovementSold);
     4433                Inc(Flags, chImprovementSold);
    44354434              end;
    44364435        end;
     
    44394438    sSetCityTiles, sSetCityTiles - sExecute:
    44404439      begin
    4441 {$IFDEF TEXTLOG}CmdInfo := Format('SetCityTiles P%d Loc%d: %x', [Player, RW[Player].City[Subject].Loc, integer(Data)]); {$ENDIF}
     4440{$IFDEF TEXTLOG}CmdInfo := Format('SetCityTiles P%d Loc%d: %x', [Player, RW[Player].City[Subject].Loc, Integer(Data)]); {$ENDIF}
    44424441        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    44434442        then
    4444           result := eInvalid
     4443          Result := eInvalid
    44454444        else
    4446           result := SetCityTiles(Player, Subject, integer(Data),
     4445          Result := SetCityTiles(Player, Subject, Integer(Data),
    44474446            Command < sExecute);
    44484447      end;
     
    44614460    end
    44624461    else
    4463       result := eUnknown;
     4462      Result := eUnknown;
    44644463  end; { case command }
    44654464
    44664465  // do not log invalid and non-relevant commands
    4467   if result = eZOC_EnemySpotted then
     4466  if Result = eZOC_EnemySpotted then
    44684467  begin
    4469     assert(Mode = moPlaying);
     4468    Assert(Mode = moPlaying);
    44704469    CL.State := FormerCLState;
    44714470    IntServer(sIntDiscoverZOC, Player, 0, ZOCTile);
    44724471  end
    4473   else if result and rEffective = 0 then
     4472  else if Result and rEffective = 0 then
    44744473    if Mode < moPlaying then
    44754474    begin
    4476 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [result]) + CmdInfo;
     4475{$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [Result]) + CmdInfo;
    44774476      {$ENDIF}
    4478       LoadOK := false;
     4477      LoadOK := False;
    44794478    end
    44804479    else
     
    44824481      if logged then
    44834482        CL.State := FormerCLState;
    4484       if (result < rExecuted) and (Command >= sExecute) then
     4483      if (Result < rExecuted) and (Command >= sExecute) then
    44854484        PutMessage(1 shl 16 + 1, Format('INVALID: %d calls %x (%d)',
    44864485          [Player, Command, Subject]));
     
    44884487
    44894488  if (Command and (cClientEx or sExecute or sctMask) = sExecute or sctEndClient)
    4490     and (result >= rExecuted) then
     4489    and (Result >= rExecuted) then
    44914490    LastEndClientCommand := Command;
    4492 {$IFOPT O-}dec(nHandoverStack, 2); {$ENDIF}
    4493 end; { <<<server }
     4491{$IFOPT O-}Dec(nHandoverStack, 2); {$ENDIF}
     4492end;
    44944493
    44954494
  • branches/highdpi/Global.pas

    r412 r465  
    2424    ((CevoVersionBugFix and $ff) shl 0);
    2525
    26 
    2726implementation
    2827
    2928end.
    3029
     30
  • branches/highdpi/Graphics/System2.grs

    r349 r465  
    99      <Height>26</Height>
    1010    </Item>
     11    <Item>
     12      <Name>BrainNoTerm</Name>
     13      <Left>1</Left>
     14      <Top>111</Top>
     15      <Width>64</Width>
     16      <Height>64</Height>
     17    </Item>
     18    <Item>
     19      <Name>BrainSuperVirtual</Name>
     20      <Left>66</Left>
     21      <Top>111</Top>
     22      <Width>64</Width>
     23      <Height>64</Height>
     24    </Item>
     25    <Item>
     26      <Name>BrainTerm</Name>
     27      <Left>131</Left>
     28      <Top>111</Top>
     29      <Width>64</Width>
     30      <Height>64</Height>
     31    </Item>
     32    <Item>
     33      <Name>BrainRandom</Name>
     34      <Left>131</Left>
     35      <Top>46</Top>
     36      <Width>64</Width>
     37      <Height>64</Height>
     38    </Item>
    1139  </Items>
    1240</GraphicSet>
  • branches/highdpi/IPQ.pas

    r303 r465  
    11{ binary heap priority queue
    2   code contributed by Rassim Eminli }
     2  Code contributed by Rassim Eminli }
    33
    44{$INCLUDE Switches.inc}
     
    88
    99type
    10 
    11   TIntegerArray = array [0 .. $40000000 div sizeof(integer)] of integer;
     10  TIntegerArray = array [0 .. $40000000 div SizeOf(Integer)] of Integer;
    1211  PIntegerArray = ^TIntegerArray;
    1312
    1413  TheapItem = record
    15     Item: integer;
    16     Value: integer;
     14    Item: Integer;
     15    Value: Integer;
    1716  end;
    1817
    19   TItemArray = array [0 .. $40000000 div sizeof(TheapItem)] of TheapItem;
     18  TItemArray = array [0 .. $40000000 div SizeOf(TheapItem)] of TheapItem;
    2019  PItemArray = ^TItemArray;
    2120
    2221  TIPQ = class
    23     constructor Create(max: integer);
     22    constructor Create(Max: Integer);
    2423    destructor Destroy; override;
    2524    procedure Empty;
    26     function Put(Item, Value: integer): boolean;
    27     function TestPut(Item, Value: integer): boolean;
    28     function Get(var Item, Value: integer): boolean;
     25    function Put(Item, Value: Integer): Boolean;
     26    function TestPut(Item, Value: Integer): Boolean;
     27    function Get(var Item, Value: Integer): Boolean;
    2928  private
    3029    // n - is the size of the heap.
    3130    // fmax - is the max size of the heap.
    32     n, fmax: integer;
     31    N, fmax: Integer;
    3332
    3433    // bh - stores (Value, Item) pairs of the heap.
     
    4039implementation
    4140
    42 constructor TIPQ.Create(max: integer);
     41constructor TIPQ.Create(Max: Integer);
    4342begin
    4443  inherited Create;
    45   fmax := max;
    46   GetMem(bh, fmax * sizeof(TheapItem));
    47   GetMem(Ix, fmax * sizeof(integer));
    48   n := -1;
     44  fmax := Max;
     45  GetMem(bh, fmax * SizeOf(TheapItem));
     46  GetMem(Ix, fmax * SizeOf(Integer));
     47  N := -1;
    4948  Empty;
    5049end;
     
    5958procedure TIPQ.Empty;
    6059begin
    61   if n <> 0 then
     60  if N <> 0 then
    6261  begin
    63     FillChar(Ix^, fmax * sizeof(integer), 255);
    64     n := 0;
     62    FillChar(Ix^, fmax * SizeOf(Integer), 255);
     63    N := 0;
    6564  end;
    6665end;
    6766
    6867// Parent(i) = (i-1)/2.
    69 function TIPQ.Put(Item, Value: integer): boolean; // O(lg(n))
     68function TIPQ.Put(Item, Value: Integer): Boolean; // O(lg(n))
    7069var
    71   i, j: integer;
     70  I, J: Integer;
    7271  lbh: PItemArray;
    7372  lIx: PIntegerArray;
     
    7574  lIx := Ix;
    7675  lbh := bh;
    77   i := lIx[Item];
    78   if i >= 0 then
     76  I := lIx[Item];
     77  if I >= 0 then
    7978  begin
    80     if lbh[i].Value <= Value then
     79    if lbh[I].Value <= Value then
    8180    begin
    82       result := False;
    83       exit;
     81      Result := False;
     82      Exit;
    8483    end;
    8584  end
    8685  else
    8786  begin
    88     i := n;
    89     Inc(n);
     87    I := N;
     88    Inc(N);
    9089  end;
    9190
    92   while i > 0 do
     91  while I > 0 do
    9392  begin
    94     j := (i - 1) shr 1; // Parent(i) = (i-1)/2
    95     if Value >= lbh[j].Value then
    96       break;
    97     lbh[i] := lbh[j];
    98     lIx[lbh[i].Item] := i;
    99     i := j;
     93    J := (I - 1) shr 1; // Parent(i) = (i-1)/2
     94    if Value >= lbh[J].Value then
     95      Break;
     96    lbh[I] := lbh[J];
     97    lIx[lbh[I].Item] := I;
     98    I := J;
    10099  end;
    101100  // Insert the new Item at the insertion point found.
    102   lbh[i].Value := Value;
    103   lbh[i].Item := Item;
    104   lIx[lbh[i].Item] := i;
    105   result := True;
     101  lbh[I].Value := Value;
     102  lbh[I].Item := Item;
     103  lIx[lbh[I].Item] := I;
     104  Result := True;
    106105end;
    107106
    108 function TIPQ.TestPut(Item, Value: integer): boolean;
     107function TIPQ.TestPut(Item, Value: Integer): Boolean;
    109108var
    110   i: integer;
     109  I: Integer;
    111110begin
    112   i := Ix[Item];
    113   result := (i < 0) or (bh[i].Value > Value);
     111  I := Ix[Item];
     112  Result := (I < 0) or (bh[I].Value > Value);
    114113end;
    115114
    116115// Left(i) = 2*i+1.
    117116// Right(i) = 2*i+2 => Left(i)+1
    118 function TIPQ.Get(var Item, Value: integer): boolean; // O(lg(n))
     117function TIPQ.Get(var Item, Value: Integer): Boolean; // O(lg(n))
    119118var
    120   i, j: integer;
    121   last: TheapItem;
     119  I, J: Integer;
     120  Last: TheapItem;
    122121  lbh: PItemArray;
    123122begin
    124   if n = 0 then
     123  if N = 0 then
    125124  begin
    126     result := False;
    127     exit;
     125    Result := False;
     126    Exit;
    128127  end;
    129128
     
    134133  Ix[Item] := -1;
    135134
    136   dec(n);
    137   if n > 0 then
     135  Dec(N);
     136  if N > 0 then
    138137  begin
    139     last := lbh[n];
    140     i := 0;
    141     j := 1;
    142     while j < n do
     138    Last := lbh[N];
     139    I := 0;
     140    J := 1;
     141    while J < N do
    143142    begin
    144143      // Right(i) = Left(i)+1
    145       if (j < n - 1) and (lbh[j].Value > lbh[j + 1].Value) then
    146         Inc(j);
    147       if last.Value <= lbh[j].Value then
    148         break;
     144      if (J < N - 1) and (lbh[J].Value > lbh[J + 1].Value) then
     145        Inc(J);
     146      if Last.Value <= lbh[J].Value then
     147        Break;
    149148
    150       lbh[i] := lbh[j];
    151       Ix[lbh[i].Item] := i;
    152       i := j;
    153       j := j shl 1 + 1; // Left(j) = 2*j+1
     149      lbh[I] := lbh[J];
     150      Ix[lbh[I].Item] := I;
     151      I := J;
     152      J := J shl 1 + 1; // Left(j) = 2*j+1
    154153    end;
    155154
    156155    // Insert the root in the correct place in the heap.
    157     lbh[i] := last;
    158     Ix[last.Item] := i;
     156    lbh[I] := Last;
     157    Ix[Last.Item] := I;
    159158  end;
    160   result := True
     159  Result := True;
    161160end;
    162161
  • branches/highdpi/Inp.pas

    r412 r465  
    2121    procedure CenterToRect(Rect: TRect);
    2222  private
    23     Center: boolean;
     23    Center: Boolean;
    2424  end;
    2525
    2626var
    2727  InputDlg: TInputDlg;
     28
    2829
    2930implementation
     
    5354    9, Caption);
    5455  { Corner(canvas,1,1,0,MainTexture);
    55     Corner(canvas,ClientWidth-9,1,1,MainTexture);
    56     Corner(canvas,1,ClientHeight-9,2,MainTexture);
    57     Corner(canvas,ClientWidth-9,ClientHeight-9,3,MainTexture); }
     56    Corner(Canvas,ClientWidth-9,1,1,MainTexture);
     57    Corner(Canvas,1,ClientHeight-9,2,MainTexture);
     58    Corner(Canvas,ClientWidth-9,ClientHeight-9,3,MainTexture); }
    5859end;
    5960
  • branches/highdpi/Install/rpm/c-evo.spec

    r405 r465  
    1111Requires:       sox
    1212
    13 #BuildRequires:  lazarus
     13BuildRequires:  lazarus >= 2.0.12
    1414
    1515%description
    16 Turn-based empire building game inspired by Civilization.
     16A turn-based empire building game inspired by Civilization.
    1717
    1818%global debug_package %{nil}
     
    7272/usr/bin/c-evo
    7373/usr/share/applications/c-evo.desktop
    74 /usr/share/c-evo/*
     74/usr/share/c-evo/
    7575/usr/share/pixmaps/c-evo.png
    7676
  • branches/highdpi/Install/snap/local/build.sh

    r405 r465  
    44
    55pushd ../../..
    6 snapcraft --debug --use-lxd
     6snapcraft --debug --use-lxd $@
    77popd
    88
  • branches/highdpi/Install/snap/snapcraft.yaml

    r405 r465  
    55description: |
    66  This is a fork and Lazarus/FPC port of the original C-evo 1.2.0 game.
    7   Now it is finally possible to play C-evo natively on Linux. 
     7  Now it is finally possible to play C-evo natively on Linux.
    88  * Zoomable map by mouse wheel with three tile sizes
    99  * Many sample maps included
    10   * All available localizations include
     10  * Multiple localizations included
     11  * Support for user defined key mapping
    1112  * Many other small improvements
    12 confinement: strict
    13 base: core20
     13confinement: devmode
     14base: core22
    1415grade: stable
    1516icon: Graphics/c-evo_64x64.png
    1617license: NLPL
    1718
    18 environment:
    19   LD_LIBRARY_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio
     19environment: 
     20  LD_LIBRARY_PATH: $SNAP_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/usr/lib/x86_64-linux-gnu:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio
    2021  PULSE_SERVER: unix:/run/user/1000/pulse/native
    2122
    2223layout:
    2324  /usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox:
    24     bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox   
     25    bind: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/sox
    2526 
    2627parts:
     
    2930    source: .
    3031    source-type: local
    31     build-packages:
    32     - fpc
    33     - lazarus
    34     - lcl
    35     - lcl-utils
    36     stage-packages:   
     32    after: [lazarus]
     33    stage-packages:
    3734    - sox
    3835    - libsox-fmt-mp3
     
    7269    override-build: |
    7370      snapcraftctl build
    74       (cd AI/StdAI &&lazbuild --build-mode=Release StdAI.lpi)
     71      (cd AI/StdAI &&lazbuild --build-mode=Debug StdAI.lpi)
    7572      mv AI/StdAI/libstdai.so AI/StdAI/libstdai-amd64.so
    76       lazbuild --build-mode=Release Integrated.lpi
    77       ROOT=/root/parts/c-evo/install
    78       install -d -m 755 $ROOT/usr/share/c-evo
    79       install -s -m 755 c-evo $ROOT/usr/share/c-evo
    80       install -m 644 Language.txt $ROOT/usr/share/c-evo
    81       install -m 644 Language2.txt $ROOT/usr/share/c-evo
    82       install -m 644 Fonts.txt $ROOT/usr/share/c-evo
    83       install -d -m 755 $ROOT/usr/share/applications
    84       install -m 755 Install/deb/c-evo.desktop $ROOT/usr/share/applications
    85       install -d -m 755 $ROOT/usr/share/mime/packages
    86       install -m 755 Install/deb/c-evo.xml $ROOT/usr/share/mime/packages
    87       install -d -m 755 $ROOT/usr/share/pixmaps
    88       install -m 644 Graphics/c-evo_64x64.png $ROOT/usr/share/pixmaps/c-evo.png
    89       install -m 644 Graphics/c-evo_64x64.png $ROOT/usr/share/pixmaps/application-cevo.png
    90       install -m 644 Graphics/c-evo_64x64.png $ROOT/usr/share/pixmaps/application-cevomap.png
    91       install -d -m 755 $ROOT/usr/share/c-evo/AI/StdAI
    92       install -m 644 AI/StdAI/libstdai-amd64.so $ROOT/usr/share/c-evo/AI/StdAI
    93       install -m 644 AI/StdAI/StdAI.ai.txt $ROOT/usr/share/c-evo/AI/StdAI
    94       install -m 644 AI/StdAI/StdAI.png $ROOT/usr/share/c-evo/AI/StdAI
    95       cp -r Graphics $ROOT/usr/share/c-evo
    96       cp -r Help $ROOT/usr/share/c-evo
    97       cp -r Sounds $ROOT/usr/share/c-evo
    98       cp -r Tribes $ROOT/usr/share/c-evo
    99       cp -r Localization $ROOT/usr/share/c-evo
    100       cp -r Maps $ROOT/usr/share/c-evo
    101       cp -r Saved $ROOT/usr/share/c-evo
    102       cp -r "AI Template" $ROOT/usr/share/c-evo
     73      lazbuild --build-mode=Debug Integrated.lpi
     74      install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     75      install -s -m 755 c-evo $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     76      install -m 644 Language.txt $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     77      install -m 644 Language2.txt $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     78      install -m 644 Fonts.txt $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     79      install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/applications
     80      install -m 755 Install/deb/c-evo.desktop $SNAPCRAFT_PART_INSTALL/usr/share/applications
     81      install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/mime/packages
     82      install -m 644 Install/deb/c-evo.xml $SNAPCRAFT_PART_INSTALL/usr/share/mime/packages
     83      install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/pixmaps
     84      install -m 644 Graphics/c-evo_64x64.png $SNAPCRAFT_PART_INSTALL/usr/share/pixmaps/c-evo.png
     85      install -m 644 Graphics/c-evo_64x64.png $SNAPCRAFT_PART_INSTALL/usr/share/pixmaps/application-cevo.png
     86      install -m 644 Graphics/c-evo_64x64.png $SNAPCRAFT_PART_INSTALL/usr/share/pixmaps/application-cevomap.png
     87      install -d -m 755 $SNAPCRAFT_PART_INSTALL/usr/share/c-evo/AI/StdAI
     88      install -m 644 AI/StdAI/libstdai-amd64.so $SNAPCRAFT_PART_INSTALL/usr/share/c-evo/AI/StdAI
     89      install -m 644 AI/StdAI/StdAI.ai.txt $SNAPCRAFT_PART_INSTALL/usr/share/c-evo/AI/StdAI
     90      install -m 644 AI/StdAI/StdAI.png $SNAPCRAFT_PART_INSTALL/usr/share/c-evo/AI/StdAI
     91      cp -r Graphics $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     92      cp -r Help $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     93      cp -r Sounds $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     94      cp -r Tribes $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     95      cp -r Localization $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     96      cp -r Maps $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     97      cp -r Saved $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
     98      cp -r "AI Template" $SNAPCRAFT_PART_INSTALL/usr/share/c-evo
    10399    stage:
    104100      - etc
     
    107103      - usr/share/applications/c-evo.desktop
    108104      - usr/share/mime/packages/c-evo.xml
    109 
     105  lazarus:
     106    plugin: nil
     107    source: .
     108    source-type: local
     109    build-packages:
     110    - wget
     111    - libgtk2.0-dev
     112    override-build: |
     113      wget -nc https://downloads.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.2/lazarus-project_2.2.2-0_amd64.deb
     114      wget -nc https://downloads.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.2/fpc-laz_3.2.2-210709_amd64.deb
     115      wget -nc https://downloads.sourceforge.net/project/lazarus/Lazarus%20Linux%20amd64%20DEB/Lazarus%202.2.2/fpc-src_3.2.2-210709_amd64.deb
     116      apt install ./lazarus-project_2.2.2-0_amd64.deb ./fpc-laz_3.2.2-210709_amd64.deb ./fpc-src_3.2.2-210709_amd64.deb
     117    stage: [-*]
     118    prime: [-*]
     119   
    110120apps:
    111121  c-evo:
    112122    command: usr/share/c-evo/c-evo
    113     desktop: usr/share/applications/c-evo.desktop   
     123    desktop: usr/share/applications/c-evo.desktop
    114124    plugs:
    115125      - home
  • branches/highdpi/Integrated.lpi

    r405 r465  
    22<CONFIG>
    33  <ProjectOptions>
    4     <Version Value="11"/>
     4    <Version Value="12"/>
    55    <PathDelim Value="\"/>
    66    <General>
     
    99        <MainUnitHasCreateFormStatements Value="False"/>
    1010        <MainUnitHasTitleStatement Value="False"/>
     11        <CompatibilityMode Value="True"/>
    1112      </Flags>
    1213      <SessionStorage Value="InProjectDir"/>
    13       <MainUnit Value="0"/>
    1414      <Title Value="Integrated"/>
    1515      <UseAppBundle Value="False"/>
     
    5959            <Debugging>
    6060              <GenerateDebugInfo Value="False"/>
     61              <DebugInfoType Value="dsDwarf2Set"/>
    6162            </Debugging>
    6263            <LinkSmart Value="True"/>
     
    106107      </Item4>
    107108    </RequiredPackages>
    108     <Units Count="48">
     109    <Units Count="47">
    109110      <Unit0>
    110111        <Filename Value="Integrated.lpr"/>
     
    344345      </Unit40>
    345346      <Unit41>
    346         <Filename Value="LocalPlayer\UKeyBindings.pas"/>
     347        <Filename Value="LocalPlayer\KeyBindings.pas"/>
    347348        <IsPartOfProject Value="True"/>
    348349      </Unit41>
    349350      <Unit42>
    350         <Filename Value="UMiniMap.pas"/>
     351        <Filename Value="MiniMap.pas"/>
    351352        <IsPartOfProject Value="True"/>
    352353      </Unit42>
    353354      <Unit43>
    354         <Filename Value="UBrain.pas"/>
     355        <Filename Value="Brain.pas"/>
    355356        <IsPartOfProject Value="True"/>
    356357      </Unit43>
    357358      <Unit44>
    358         <Filename Value="Network\UNetworkServer.pas"/>
     359        <Filename Value="Network\NetworkServer.pas"/>
    359360        <IsPartOfProject Value="True"/>
    360361      </Unit44>
    361362      <Unit45>
    362         <Filename Value="Network\UNetworkClient.pas"/>
     363        <Filename Value="Network\NetworkClient.pas"/>
    363364        <IsPartOfProject Value="True"/>
    364365      </Unit45>
    365366      <Unit46>
    366         <Filename Value="Network\UNetworkCommon.pas"/>
     367        <Filename Value="Network\NetworkCommon.pas"/>
    367368        <IsPartOfProject Value="True"/>
    368369      </Unit46>
    369       <Unit47>
    370         <Filename Value="ULanguages.pas"/>
    371         <IsPartOfProject Value="True"/>
    372       </Unit47>
    373370    </Units>
    374371  </ProjectOptions>
     
    404401    <Linking>
    405402      <Debugging>
     403        <DebugInfoType Value="dsDwarf2Set"/>
     404        <UseHeaptrc Value="True"/>
    406405        <UseExternalDbgSyms Value="True"/>
    407406      </Debugging>
  • branches/highdpi/Integrated.lpr

    r405 r465  
    66  cthreads, clocale,
    77  {$ENDIF}
    8   UDpiControls, Forms, Interfaces, SysUtils, Protocol, GameServer, Direct, Start, Messg, Inp,
     8  Forms, Interfaces, SysUtils, Protocol, GameServer, Direct, Start, Messg, Inp,
    99  Back, Log, LocalPlayer, ClientTools, Tribes, IsoEngine, Term, CityScreen, Nego,
    10   NoTerm, ScreenTools, Directories;
     10  NoTerm, ScreenTools, Directories, UDpiControls;
    1111
    1212{$if declared(UseHeapTrace)}
     
    2626  DotNetClient := nil;
    2727  DpiApplication.Initialize;
    28   DpiApplication.Title := 'c-evo';
     28  DpiApplication.Title := 'C-evo';
     29  DpiApplication.TaskBarBehavior := tbMultiButton;
    2930  Directories.UnitInit;
    3031  ScreenTools.UnitInit;
  • branches/highdpi/Language.txt

    r405 r465  
    140140#TITLE_SPYMISSION Covert Operation
    141141#TITLE_SUICIDE Suicide Mission
     142#TITLE_MESSAGE Message
    142143#FRMILREP Military Report
    143144
  • branches/highdpi/LocalPlayer/Battle.pas

    r361 r465  
    3232    uix, ToLoc: Integer;
    3333    Forecast: TBattleForecastEx;
    34     IsSuicideQuery: boolean;
    35   end;
    36 
    37 var
    38   BattleDlg: TBattleDlg;
     34    IsSuicideQuery: Boolean;
     35  end;
     36
    3937
    4038implementation
     
    6260  TextSize: TSize;
    6361  LabelText: string;
    64   FirstStrike: boolean;
     62  FirstStrike: Boolean;
    6563begin
    6664  MaxBar := 65;
     
    112110    VLightGradient(ca, xm - 8, ym + 8 + LABaseDamage, LADamage - LABaseDamage,
    113111      FanaticColor);
    114   DpiBitCanvas(ca, xm - 12, ym - 12, 24, 24,
     112  DpiBitBltCanvas(ca, xm - 12, ym - 12, 24, 24,
    115113    HGrSystem.Mask.Canvas, 26, 146, SRCAND);
    116   DpiBitCanvas(ca, xm - 12, ym - 12, 24, 24,
     114  DpiBitBltCanvas(ca, xm - 12, ym - 12, 24, 24,
    117115    HGrSystem.Data.Canvas, 26, 146, SRCPAINT);
    118116
     
    137135  if Forecast.EndHealthDef <= 0 then
    138136  begin
    139     DpiBitCanvas(ca, xm + 9 + LDDamage - 7, ym - 6, 14, 17,
     137    DpiBitBltCanvas(ca, xm + 9 + LDDamage - 7, ym - 6, 14, 17,
    140138      HGrSystem.Mask.Canvas, 51, 153, SRCAND);
    141     DpiBitCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
     139    DpiBitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
    142140      HGrSystem.Mask.Canvas, 51, 153, SRCAND);
    143     DpiBitCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
     141    DpiBitBltCanvas(ca, xm + 8 + LDDamage - 7, ym - 7, 14, 17,
    144142      HGrSystem.Data.Canvas, 51, 153, SRCPAINT);
    145143  end;
     
    149147  begin
    150148    if Forecast.EndHealthDef > 0 then
    151       RisedTextOut(ca, xm + 10, ym - (TextSize.cy + 1) div 2, LabelText)
     149      RisedTextOut(ca, xm + 10, ym - (TextSize.cy + 1) div 2, LabelText);
    152150  end
    153151  else
     
    157155  if Forecast.EndHealthAtt <= 0 then
    158156  begin
    159     DpiBitCanvas(ca, xm - 6, ym + 9 + LADamage - 7, 14, 17,
     157    DpiBitBltCanvas(ca, xm - 6, ym + 9 + LADamage - 7, 14, 17,
    160158      HGrSystem.Mask.Canvas, 51, 153, SRCAND);
    161     DpiBitCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
     159    DpiBitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
    162160      HGrSystem.Mask.Canvas, 51, 153, SRCAND);
    163     DpiBitCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
     161    DpiBitBltCanvas(ca, xm - 7, ym + 8 + LADamage - 7, 14, 17,
    164162      HGrSystem.Data.Canvas, 51, 153, SRCPAINT);
    165163  end;
     
    171169    if Forecast.EndHealthAtt > 0 then
    172170      RisedTextOut(ca, xm - (TextSize.cx + 1) div 2, ym + 8 + LAAvoidedDamage,
    173         LabelText)
     171        LabelText);
    174172  end
    175173  else
     
    178176
    179177  IsoMap.SetOutput(Buffer);
    180   DpiBitCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm + 8 + 4,
     178  DpiBitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm + 8 + 4,
    181179    ym - 8 - 12 - 48);
    182180  { if TerrType<fForest then
     
    190188    end; }
    191189  IsoMap.PaintUnit(1, 0, UnitInfo, 0);
    192   DpiBitCanvas(ca, xm + 8 + 4, ym - 8 - 12 - 48, 66, 48, Buffer.Canvas,
     190  DpiBitBltCanvas(ca, xm + 8 + 4, ym - 8 - 12 - 48, 66, 48, Buffer.Canvas,
    193191    0, 0);
    194192
    195   DpiBitCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66,
     193  DpiBitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66,
    196194    ym + 8 + 12);
    197   MakeUnitInfo(me, MyUn[uix], UnitInfo);
     195  MakeUnitInfo(Me, MyUn[uix], UnitInfo);
    198196  UnitInfo.Flags := UnitInfo.Flags and not unFortified;
    199197  IsoMap.PaintUnit(1, 0, UnitInfo, 0);
    200   DpiBitCanvas(ca, xm - 8 - 4 - 66, ym + 8 + 12, 66, 48, Buffer.Canvas, 0, 0);
    201 end; { PaintBattleOutcome }
     198  DpiBitBltCanvas(ca, xm - 8 - 4 - 66, ym + 8 + 12, 66, 48, Buffer.Canvas, 0, 0);
     199end;
    202200
    203201procedure TBattleDlg.FormCreate(Sender: TObject);
     
    215213    ClientWidth := 300;
    216214    ClientHeight := 288;
    217     OKBtn.Visible := true;
    218     CancelBtn.Visible := true;
     215    OKBtn.Visible := True;
     216    CancelBtn.Visible := True;
    219217    Left := (DpiScreen.Width - ClientWidth) div 2; // center on screen
    220218    Top := (DpiScreen.Height - ClientHeight) div 2;
     
    224222    ClientWidth := 178;
    225223    ClientHeight := 178;
    226     OKBtn.Visible := false;
    227     CancelBtn.Visible := false;
     224    OKBtn.Visible := False;
     225    CancelBtn.Visible := False;
    228226  end;
    229227end;
     
    231229procedure TBattleDlg.FormPaint(Sender: TObject);
    232230var
    233   ym, cix, p: Integer;
    234   s, s1: string;
     231  ym, cix, P: Integer;
     232  S, s1: string;
    235233begin
    236234  with Canvas do
     
    240238    Brush.Style := bsClear;
    241239    PaintBackground(self, 3 + Border, 3 + Border,
    242       ClientWidth - (6 + 2 * Border), ClientHeight - (6 + 2 * Border))
     240      ClientWidth - (6 + 2 * Border), ClientHeight - (6 + 2 * Border));
    243241  end;
    244242  Frame(Canvas, Border + 1, Border + 1, ClientWidth - (2 + Border),
     
    252250  begin
    253251    Canvas.Font.Assign(UniFont[ftCaption]);
    254     s := Phrases.Lookup('TITLE_SUICIDE');
    255     RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
    256       7 + Border, s);
     252    S := Phrases.Lookup('TITLE_SUICIDE');
     253    RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
     254      7 + Border, S);
    257255    Canvas.Font.Assign(UniFont[ftNormal]);
    258     s := Phrases.Lookup('SUICIDE');
    259     p := pos('\', s);
    260     if p = 0 then
    261       RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))
    262         div 2, 205, s)
     256    S := Phrases.Lookup('SUICIDE');
     257    P := Pos('\', S);
     258    if P = 0 then
     259      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S))
     260        div 2, 205, S)
    263261    else
    264262    begin
    265       s1 := copy(s, 1, p - 1);
     263      s1 := Copy(S, 1, P - 1);
    266264      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
    267265        205 - MessageLineSpacing div 2, s1);
    268       s1 := copy(s, p + 1, 255);
     266      s1 := Copy(S, P + 1, 255);
    269267      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
    270268        205 + (MessageLineSpacing - MessageLineSpacing div 2), s1);
    271269    end;
    272     ym := 110
     270    ym := 110;
    273271  end
    274272  else
     
    297295begin
    298296  if not IsSuicideQuery then
    299     Close
     297    Close;
    300298end;
    301299
     
    309307    if Key <> VK_ESCAPE then
    310308      MainScreen.FormKeyDown(Sender, Key, Shift);
    311   end
     309  end;
    312310end;
    313311
  • branches/highdpi/LocalPlayer/CityScreen.pas

    r405 r465  
    55
    66uses
    7   UDpiControls, {$IFDEF LINUX}LMessages,{$ENDIF}
    8   Protocol, ClientTools, Term, ScreenTools, IsoEngine, BaseWin,
    9   LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
    10   ButtonA, ButtonC, Area, GraphType, UTexture;
     7  UDpiControls, {$IFDEF UNIX}LMessages,{$ENDIF}
     8  Protocol, ClientTools, ScreenTools, IsoEngine, BaseWin, LCLIntf, LCLType,
     9  Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls, ButtonA,
     10  ButtonC, Area, GraphType, Texture;
    1111
    1212const
     
    3939    procedure FormDestroy(Sender: TObject);
    4040    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    41       Shift: TShiftState; x, y: integer);
     41      Shift: TShiftState; X, Y: Integer);
    4242    procedure BuyClick(Sender: TObject);
    4343    procedure CloseBtnClick(Sender: TObject);
     
    4949    procedure PrevCityBtnClick(Sender: TObject);
    5050    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    51     // procedure AdviceBtnClick(Sender: TObject);
    5251    procedure PageUpBtnClick(Sender: TObject);
    5352    procedure PageDownBtnClick(Sender: TObject);
    5453  private
    55     c: TCity;
     54    C: TCity;
    5655    Report: TCityReportNew;
    5756    cOwner: Integer;
     
    7069    Optimize_cixTileChange: Integer;
    7170    Optimize_TilesBeforeChange: Integer;
    72     Happened: cardinal;
    73     imix: array [0 .. 15] of integer;
     71    Happened: Cardinal;
     72    imix: array [0 .. 15] of Integer;
    7473    CityAreaInfo: TCityAreaInfo;
    7574    AreaMap: TIsoMap;
     
    8988    procedure InitZoomCityMap;
    9089    procedure ChooseProject;
    91     procedure ChangeCity(d: integer);
    92     procedure ChangeResourceWeights(iResourceWeights: integer);
     90    procedure ChangeCity(D: Integer);
     91    procedure ChangeResourceWeights(iResourceWeights: Integer);
    9392    procedure OnPlaySound(var Msg: TMessage); message WM_PLAYSOUND;
    9493  public
    95     RestoreUnFocus: integer;
     94    RestoreUnFocus: Integer;
    9695    CloseAction: TCityCloseAction;
    9796    procedure OffscreenPaint; override;
    98     procedure ShowNewContent(NewMode, Loc: integer; ShowEvent: cardinal);
     97    procedure ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal);
    9998    procedure Reset;
    10099    procedure CheckAge;
    101100  end;
    102101
    103 var
    104   CityDlg: TCityDlg;
    105 
    106102
    107103implementation
    108104
    109105uses
    110   Select, Messg, MessgEx, Help, Tribes, Directories, Math, Sound;
     106  Select, Messg, MessgEx, Help, Tribes, Directories, Math, Sound, Term;
    111107
    112108{$R *.lfm}
     
    148144  wZoomEnvironment = 68;
    149145
    150   ImpPosition: array [28 .. nImp - 1] of integer = (-1, // imTrGoods
     146  ImpPosition: array [28 .. nImp - 1] of Integer = (
     147    -1, // imTrGoods
    151148    21, // imBarracks
    152149    6, // imGranary
     
    192189
    193190var
    194   ImpSorted: array [0 .. nImp - 1] of integer;
     191  ImpSorted: array [0 .. nImp - 1] of Integer;
    195192
    196193procedure TCityDlg.FormCreate(Sender: TObject);
     
    201198  NoMap := TIsoMap.Create;
    202199  AreaMap := TIsoMap.Create;
    203   AreaMap.SetOutput(offscreen);
     200  AreaMap.SetOutput(Offscreen);
    204201  AreaMap.SetPaintBounds(xmArea - 192, ymArea - 96 - 32, xmArea + 192,
    205202    ymArea + 96);
    206   SmallMapMode := smImprovements;
    207   ZoomArea := 1;
    208   ProdHint := false;
     203  Reset;
     204  ProdHint := False;
    209205  RestoreUnFocus := -1;
    210206  OpenSoundEvent := -1;
     
    279275
    280276    UnshareBitmap(Back);
    281     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
     277    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
    282278      MainTexture.Image.Canvas, 0, 0);
    283279    ImageOp_B(Back, Template, 0, 0, 0, 0, ClientWidth, ClientHeight);
     
    292288procedure TCityDlg.InitSmallCityMap;
    293289var
    294   i, iix, cli1, Color0, Color1, Color2: integer;
     290  I, iix, cli1, Color0, Color1, Color2: Integer;
    295291begin
    296292  if cix >= 0 then
    297     c := MyCity[cix];
     293    C := MyCity[cix];
    298294  case MyMap[cLoc] and fTerrain of
    299295    fPrairie: cli1 := cliPrairie;
     
    307303  Color2 := Colors.Canvas.Pixels[clkAge0 + Age, cliHouse];
    308304  SmallCityMap.Canvas.FillRect(0, 0, SmallCityMap.Width, SmallCityMap.Height);
    309   DpiBitCanvas(SmallCityMap.Canvas, 0, 0, 83, hSmallMap,
     305  DpiBitBltCanvas(SmallCityMap.Canvas, 0, 0, 83, hSmallMap,
    310306    SmallCityMapTemplate.Canvas, 83 * SizeClass, 0);
    311307  if IsPort then
    312308  begin
    313     DpiBitCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,
     309    DpiBitBltCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,
    314310      SmallCityMapTemplate.Canvas, 332 + 15, 0);
    315311    ImageOp_CCC(SmallCityMap, 0, 0, 83, hSmallMap, Color0, Color1, Color2);
     
    319315  else
    320316  begin
    321     DpiBitCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,
     317    DpiBitBltCanvas(SmallCityMap.Canvas, 83, 0, 15, hSmallMap,
    322318      SmallCityMapTemplate.Canvas, 332, 0);
    323319    ImageOp_CCC(SmallCityMap, 0, 0, wSmallMap, hSmallMap, Color0,
     
    328324  begin
    329325    Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImp];
    330     for i := 0 to 29 do
     326    for I := 0 to 29 do
    331327    begin
    332328      for iix := nWonder to nImp - 1 do
    333         if (ImpPosition[iix] = i) and (c.Built[iix] > 0) then
     329        if (ImpPosition[iix] = I) and (C.Built[iix] > 0) then
    334330        begin
    335           FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    336             3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    337             11 + 12 * (i mod 18 div 3)));
    338           break;
     331          FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     332            3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     333            11 + 12 * (I mod 18 div 3)));
     334          Break;
    339335        end;
    340336    end;
    341     i := 30;
     337    I := 30;
    342338    for iix := 0 to nImp do
    343       if (c.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then
     339      if (C.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then
    344340      begin
    345         FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    346           3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    347           11 + 12 * (i mod 18 div 3)));
    348         inc(i);
    349         if i = 36 then
    350           break; // area is full
     341        FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     342          3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     343          11 + 12 * (I mod 18 div 3)));
     344        Inc(I);
     345        if I = 36 then
     346          Break; // area is full
    351347      end;
    352     if c.Project and cpImp <> 0 then
    353     begin
    354       iix := c.Project and cpIndex;
     348    if C.Project and cpImp <> 0 then
     349    begin
     350      iix := C.Project and cpIndex;
    355351      if iix <> imTrGoods then
    356352      begin
    357353        if (iix >= nWonder) and (ImpPosition[iix] >= 0) then
    358           i := ImpPosition[iix];
    359         if i < 36 then
     354          I := ImpPosition[iix];
     355        if I < 36 then
    360356        begin
    361           brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject];
    362           FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    363             3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    364             11 + 12 * (i mod 18 div 3)));
     357          Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject];
     358          FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     359            3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     360            11 + 12 * (I mod 18 div 3)));
    365361        end;
    366362      end;
    367363    end;
    368     brush.style := bsClear;
     364    Brush.style := bsClear;
    369365  end;
    370366end;
     
    373369begin
    374370  UnshareBitmap(ZoomCityMap);
    375   DpiBitCanvas(ZoomCityMap.Canvas, 0, 0, wZoomMap, hZoomMap,
     371  DpiBitBltCanvas(ZoomCityMap.Canvas, 0, 0, wZoomMap, hZoomMap,
    376372    Back.Canvas, xZoomMap, yZoomMap);
    377373  if SmallMapMode = smImprovements then begin
     
    383379        112 * (ZoomArea - 3), wZoomMap - wZoomEnvironment, hZoomMap);
    384380      ImageOp_B(ZoomCityMap, CityMapTemplate, wZoomMap - wZoomEnvironment, 0,
    385         1504 + wZoomEnvironment * byte(IsPort), 112 * (ZoomArea - 3),
     381        1504 + wZoomEnvironment * Byte(IsPort), 112 * (ZoomArea - 3),
    386382        wZoomEnvironment, hZoomMap);
    387383    end;
     
    391387procedure TCityDlg.OffscreenPaint;
    392388
    393   procedure FillBar(x, y, pos, Growth, max, Kind: integer;
    394     IndicateComplete: boolean);
     389  procedure FillBar(X, Y, Pos, Growth, Max, Kind: Integer;
     390    IndicateComplete: Boolean);
    395391  begin
    396392    BarTex.Assign(MainTexture);
     
    399395      BarTex.ColorBevelShade := BarTex.ColorBevelLight;
    400396    end;
    401     PaintRelativeProgressBar(offscreen.Canvas, Kind, x - 3, y, wBar - 4, pos,
    402       Growth, max, IndicateComplete, BarTex);
    403   end;
    404 
    405   procedure PaintResources(x, y, Loc: integer; Add4Happy: boolean);
     397    PaintRelativeProgressBar(Offscreen.Canvas, Kind, X - 3, Y, wBar - 4, Pos,
     398      Growth, Max, IndicateComplete, BarTex);
     399  end;
     400
     401  procedure PaintResources(X, Y, Loc: Integer; Add4Happy: Boolean);
    406402  var
    407     d, i, Total, xGr, yGr: integer;
     403    D, I, Total, xGr, yGr: Integer;
    408404    TileInfo: TTileInfo;
    409     rare: boolean;
     405    rare: Boolean;
    410406  begin
    411407    with AreaMap do begin
    412     if Server(sGetCityTileInfo, me, Loc, TileInfo) <> eOk then
    413     begin
    414       assert(cix < 0);
    415       exit
     408    if Server(sGetCityTileInfo, Me, Loc, TileInfo) <> eOk then
     409    begin
     410      Assert(cix < 0);
     411      Exit
    416412    end;
    417413    Total := TileInfo.Food + TileInfo.Prod + TileInfo.Trade;
    418414    rare := MyMap[Loc] and $06000000 > 0;
    419415    if rare then
    420       inc(Total);
     416      Inc(Total);
    421417    if Add4Happy then
    422       inc(Total, 4);
     418      Inc(Total, 4);
    423419    if Total > 1 then
    424       d := (xxt - 11) div (Total - 1);
    425     if d < 1 then
    426       d := 1;
    427     if d > 4 then
    428       d := 4;
    429     for i := 0 to Total - 1 do
     420      D := (xxt - 11) div (Total - 1);
     421    if D < 1 then
     422      D := 1;
     423    if D > 4 then
     424      D := 4;
     425    for I := 0 to Total - 1 do
    430426    begin
    431427      yGr := 115;
    432       if Add4Happy and (i >= Total - 4) then
     428      if Add4Happy and (I >= Total - 4) then
    433429      begin
    434430        xGr := 132;
    435431        yGr := 126
    436432      end
    437       else if rare and (i = Total - 1) then
     433      else if rare and (I = Total - 1) then
    438434        xGr := 66 + 110
    439       else if i >= TileInfo.Food + TileInfo.Prod then
     435      else if I >= TileInfo.Food + TileInfo.Prod then
    440436        xGr := 66 + 44
    441       else if i >= TileInfo.Prod then
     437      else if I >= TileInfo.Prod then
    442438        xGr := 66
    443439      else
    444440        xGr := 66 + 22;
    445       Sprite(offscreen, HGrSystem, x + xxt - 5 + d * (2 * i + 1 - Total),
    446         y + yyt - 5, 10, 10, xGr, yGr);
     441      Sprite(Offscreen, HGrSystem, X + xxt - 5 + D * (2 * I + 1 - Total),
     442        Y + yyt - 5, 10, 10, xGr, yGr);
    447443    end;
    448444    end;
    449445  end;
    450446var
    451   line, MessageCount: integer;
    452 
    453   procedure CheckMessage(Flag: integer);
     447  Line, MessageCount: Integer;
     448
     449  procedure CheckMessage(Flag: Integer);
    454450  var
    455     i, test: integer;
    456     s: string;
     451    I, Test: Integer;
     452    S: string;
    457453  begin
    458454    if Happened and Flag <> 0 then
    459455    begin
    460       i := 0;
    461       test := 1;
    462       while test < Flag do
     456      I := 0;
     457      Test := 1;
     458      while Test < Flag do
    463459      begin
    464         inc(i);
    465         inc(test, test)
     460        Inc(I);
     461        Inc(Test, Test);
    466462      end;
    467463
    468464      if AllowChange and (Sounds <> nil) and (OpenSoundEvent = -1) then
    469465      begin
    470         s := CityEventSoundItem[i];
    471         if s <> '' then
    472           s := Sounds.Lookup(s);
    473         if (Flag = chProduction) or (s <> '') and (s[1] <> '*') and (s[1] <> '[')
     466        S := CityEventSoundItem[I];
     467        if S <> '' then
     468          S := Sounds.Lookup(S);
     469        if (Flag = chProduction) or (S <> '') and (S[1] <> '*') and (S[1] <> '[')
    474470        then
    475           OpenSoundEvent := i
     471          OpenSoundEvent := I;
    476472      end;
    477473
    478       s := CityEventName(i);
     474      S := CityEventName(I);
    479475      { if Flag=chNoGrowthWarning then
    480         if c.Built[imAqueduct]=0 then
    481         s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
    482         else s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); }
    483       RisedTextOut(offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount +
    484         16 * line, s);
    485       inc(line)
     476        if C.Built[imAqueduct]=0 then
     477        S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
     478        else S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); }
     479      RisedTextOut(Offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount +
     480        16 * Line, S);
     481      Inc(Line);
    486482    end;
    487483  end;
    488484
    489485var
    490   x, y, xGr, i, j, iix, d, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix,
    491     HappyGain, OptiType, rx, ry, TrueFood, TrueProd, TruePoll: integer;
    492   av: integer;
    493   PrName, s: string;
     486  X, Y, xGr, I, J, iix, D, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix,
     487    HappyGain, OptiType, rx, ry, TrueFood, TrueProd, TruePoll: Integer;
     488  av: Integer;
     489  PrName, S: string;
    494490  UnitInfo: TUnitInfo;
    495491  UnitReport: TUnitReport;
    496   IsCityAlive, CanGrow: boolean;
     492  IsCityAlive, CanGrow: Boolean;
    497493begin
    498494  inherited;
    499495  if cix >= 0 then
    500     c := MyCity[cix];
     496    C := MyCity[cix];
    501497  Report.HypoTiles := -1;
    502498  Report.HypoTaxRate := -1;
    503499  Report.HypoLuxuryRate := -1;
    504500  if cix >= 0 then
    505     Server(sGetCityReportNew, me, cix, Report) // own city
     501    Server(sGetCityReportNew, Me, cix, Report) // own city
    506502  else
    507     Server(sGetEnemyCityReportNew, me, cLoc, Report); // enemy city
    508   TrueFood := c.Food;
    509   TrueProd := c.Prod;
    510   TruePoll := c.Pollution;
    511   if supervising or (cix < 0) then
     503    Server(sGetEnemyCityReportNew, Me, cLoc, Report); // enemy city
     504  TrueFood := C.Food;
     505  TrueProd := C.Prod;
     506  TruePoll := C.Pollution;
     507  if Supervising or (cix < 0) then
    512508  begin // normalize city from after-turn state
    513     dec(TrueFood, Report.FoodSurplus);
     509    Dec(TrueFood, Report.FoodSurplus);
    514510    if TrueFood < 0 then
    515511      TrueFood := 0; // shouldn't happen
    516     dec(TrueProd, Report.Production);
     512    Dec(TrueProd, Report.Production);
    517513    if TrueProd < 0 then
    518514      TrueProd := 0; // shouldn't happen
    519     dec(TruePoll, Report.AddPollution);
     515    Dec(TruePoll, Report.AddPollution);
    520516    if TruePoll < 0 then
    521517      TruePoll := 0; // shouldn't happen
    522518  end;
    523   IsCityAlive := (cGov <> gAnarchy) and (c.Flags and chCaptured = 0);
     519  IsCityAlive := (cGov <> gAnarchy) and (C.Flags and chCaptured = 0);
    524520  if not IsCityAlive then
    525     Report.Working := c.Size;
     521    Report.Working := C.Size;
    526522
    527523  RedTex.Assign(MainTexture);
     
    531527  RedTex.ColorTextShade := $0000FF;
    532528
    533   DpiBitCanvas(offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0);
     529  DpiBitBltCanvas(Offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0);
    534530
    535531  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    536   RisedTextOut(offscreen.Canvas, 42, 7, Caption);
    537   with offscreen.Canvas do
     532  RisedTextOut(Offscreen.Canvas, 42, 7, Caption);
     533  with Offscreen.Canvas do
    538534  begin // city size
    539     brush.Color := $000000;
     535    Brush.Color := $000000;
    540536    FillRect(Rect(8 + 1, 7 + 1, 36 + 1, 32 + 1));
    541     brush.Color := $FFFFFF;
     537    Brush.Color := $FFFFFF;
    542538    FillRect(Rect(8, 7, 36, 32));
    543     brush.style := bsClear;
     539    Brush.style := bsClear;
    544540    Font.Color := $000000;
    545     s := inttostr(c.Size);
    546     TextOut(8 + 14 - textwidth(s) div 2, 7, s);
     541    S := IntToStr(C.Size);
     542    TextOut(8 + 14 - TextWidth(S) div 2, 7, S);
    547543  end;
    548544  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     
    552548    MakeRed(Offscreen, 18, 280, 298, 40);
    553549    if cGov = gAnarchy then
    554       s := Phrases.Lookup('GOVERNMENT', gAnarchy)
     550      S := Phrases.Lookup('GOVERNMENT', gAnarchy)
    555551    else { if c.Flags and chCaptured<>0 then }
    556       s := Phrases.Lookup('CITYEVENTS', 14);
    557     RisedTextOut(offscreen.Canvas, 167 - BiColorTextWidth(offscreen.Canvas, s)
    558       div 2, ymOpt - 9, s);
     552      S := Phrases.Lookup('CITYEVENTS', 14);
     553    RisedTextOut(Offscreen.Canvas, 167 - BiColorTextWidth(Offscreen.Canvas, S)
     554      div 2, ymOpt - 9, S);
    559555  end
    560556  else if AllowChange then
    561557  begin
    562     OptiType := c.Status shr 4 and $0F;
    563     Sprite(offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64,
     558    OptiType := C.Status shr 4 and $0F;
     559    Sprite(Offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64,
    564560      1 + OptiType mod 3 * 64, 217 + OptiType div 3 * 64);
    565561
    566562    { display messages now }
    567563    MessageCount := 0;
    568     for i := 0 to 31 do
    569       if Happened and ($FFFFFFFF - chCaptured) and (1 shl i) <> 0 then
    570         inc(MessageCount);
     564    for I := 0 to 31 do
     565      if Happened and ($FFFFFFFF - chCaptured) and (1 shl I) <> 0 then
     566        Inc(MessageCount);
    571567    if MessageCount > 3 then
    572568      MessageCount := 3;
    573569    if MessageCount > 0 then
    574570    begin
    575       MakeBlue(offscreen, 74, 280, 242, 40);
    576       line := 0;
    577       for i := 0 to nCityEventPriority - 1 do
    578         if line < MessageCount then
    579           CheckMessage(CityEventPriority[i]);
     571      MakeBlue(Offscreen, 74, 280, 242, 40);
     572      Line := 0;
     573      for I := 0 to nCityEventPriority - 1 do
     574        if Line < MessageCount then
     575          CheckMessage(CityEventPriority[I]);
    580576    end
    581577    else
    582578    begin
    583       s := Phrases.Lookup('CITYMANAGETYPE', OptiType);
    584       j := pos('\', s);
    585       if j = 0 then
    586         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40,
    587           ymOpt - 9, s)
     579      S := Phrases.Lookup('CITYMANAGETYPE', OptiType);
     580      J := Pos('\', S);
     581      if J = 0 then
     582        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40,
     583          ymOpt - 9, S)
    588584      else
    589585      begin
    590         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40,
    591           ymOpt - 17, copy(s, 1, j - 1));
    592         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1,
    593           copy(s, j + 1, 255));
     586        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40,
     587          ymOpt - 17, Copy(S, 1, J - 1));
     588        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1,
     589          Copy(S, J + 1, 255));
    594590      end;
    595591    end;
     
    601597    AreaMap.Paint(xmArea - xxt * 2 * rx, ymArea - yyt * 2 * ry - 3 * yyt,
    602598      dLoc(cLoc, -2 * rx + 1, -2 * ry - 1), 4 * rx - 1, 4 * ry + 1, cLoc, cOwner,
    603       false, AllowChange and IsCityAlive and
    604       (c.Status and csResourceWeightsMask = 0));
    605     DpiBitCanvas(offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas,
     599      False, AllowChange and IsCityAlive and
     600      (C.Status and csResourceWeightsMask = 0));
     601    DpiBitBltCanvas(Offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas,
    606602      xmArea + 102, 42);
    607603
     
    615611              ((Loc1 < 0) or (Loc1 >= G.lx * G.ly) or (MyMap[Loc1] and fCity = 0))
    616612            then
    617               Sprite(offscreen, HGrTerrain, xmArea - xxt + xxt * dx,
     613              Sprite(Offscreen, HGrTerrain, xmArea - xxt + xxt * dx,
    618614                ymArea - yyt + yyt * dy, xxt * 2, yyt * 2, 1 + 5 * (xxt * 2 + 1),
    619615                1 + yyt + 15 * (yyt * 3 + 1));
    620             if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and c.Tiles <> 0) then
     616            if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and C.Tiles <> 0) then
    621617              PaintResources(xmArea - xxt + xxt * dx, ymArea - yyt + yyt * dy,
    622618                Loc1, (dx = 0) and (dy = 0));
     
    625621
    626622  if Report.Working > 1 then
    627     d := (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1);
    628   if d > 28 then
    629     d := 28;
    630   for i := Report.Working - 1 downto 0 do
     623    D := (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1);
     624  if D > 28 then
     625    D := 28;
     626  for I := Report.Working - 1 downto 0 do
    631627  begin
    632628    if IsCityAlive then
     
    634630    else
    635631      xGr := 141;
    636     DpiBitCanvas(offscreen.Canvas, xmArea - 192 + 5 + i * d, ymArea - 96 - 29,
     632    DpiBitBltCanvas(Offscreen.Canvas, xmArea - 192 + 5 + I * D, ymArea - 96 - 29,
    637633      27, 30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow }
    638     Sprite(offscreen, HGrSystem, xmArea - 192 + 4 + i * d, ymArea - 96 - 30, 27,
     634    Sprite(Offscreen, HGrSystem, xmArea - 192 + 4 + I * D, ymArea - 96 - 30, 27,
    639635      30, xGr, 171);
    640636  end;
    641   if c.Size - Report.Working > 1 then
    642     d := (xmArea + 192 - xService - 32) div (c.Size - Report.Working - 1);
    643   if d > 28 then
    644     d := 28;
    645   for i := 0 to c.Size - Report.Working - 1 do
     637  if C.Size - Report.Working > 1 then
     638    D := (xmArea + 192 - xService - 32) div (C.Size - Report.Working - 1);
     639  if D > 28 then
     640    D := 28;
     641  for I := 0 to C.Size - Report.Working - 1 do
    646642  begin
    647643    xGr := 1 + 112;
    648     DpiBitCanvas(offscreen.Canvas, xmArea + 192 - 27 + 1 - i * d, 29 + 1, 27,
     644    DpiBitBltCanvas(Offscreen.Canvas, xmArea + 192 - 27 + 1 - I * D, 29 + 1, 27,
    649645      30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow }
    650     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 - i * d, 29, 27, 30,
     646    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 - I * D, 29, 27, 30,
    651647      xGr, 171);
    652     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 + 4 - i * d, 29 + 32, 10,
     648    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 4 - I * D, 29 + 32, 10,
    653649      10, 121, 126);
    654     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 + 13 - i * d, 29 + 32, 10,
     650    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 13 - I * D, 29 + 32, 10,
    655651      10, 121, 126);
    656652    // Sprite(offscreen,HGrSystem,xmArea+192-31+18-i*d,ymArea-96-80+32,10,10,88,115);
    657653  end;
    658654
    659   if c.Project and cpImp = 0 then
    660     PrName := Tribe[cOwner].ModelName[c.Project and cpIndex]
     655  if C.Project and cpImp = 0 then
     656    PrName := Tribe[cOwner].ModelName[C.Project and cpIndex]
    661657  else
    662     PrName := Phrases.Lookup('IMPROVEMENTS', c.Project and cpIndex);
     658    PrName := Phrases.Lookup('IMPROVEMENTS', C.Project and cpIndex);
    663659  PrCost := Report.ProjectCost;
    664660
     
    667663  begin
    668664    if cGov = gFundamentalism then
    669       CountBar(offscreen, xHapp, yHapp + dyBar, wBar, 17,
     665      CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17,
    670666        Phrases.Lookup('FAITH'), Report.CollectedControl, MainTexture)
    671667    else
    672668    begin
    673       CountBar(offscreen, xHapp, yHapp + dyBar, wBar, 17,
     669      CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17,
    674670        Phrases.Lookup('HAPPINESS'), Report.Morale, MainTexture);
    675       CountBar(offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16,
     671      CountBar(Offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16,
    676672        Phrases.Lookup('CONTROL'), Report.CollectedControl, MainTexture);
    677673    end;
    678     CountBar(offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'),
     674    CountBar(Offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'),
    679675      Report.Luxury, MainTexture);
    680     CountBar(offscreen, xHapp + dxBar, yHapp, wBar, 19,
     676    CountBar(Offscreen, xHapp + dxBar, yHapp, wBar, 19,
    681677      Phrases.Lookup('UNREST'), 2 * Report.Deployed, MainTexture);
    682     CountBar(offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17,
    683       Phrases.Lookup('HAPPINESSDEMAND'), c.Size, MainTexture);
     678    CountBar(Offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17,
     679      Phrases.Lookup('HAPPINESSDEMAND'), C.Size, MainTexture);
    684680    if Report.HappinessBalance >= 0 then
    685       CountBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17,
     681      CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17,
    686682        Phrases.Lookup('HAPPINESSPLUS'), Report.HappinessBalance, MainTexture)
    687683    else
    688684    begin
    689685      MakeRed(Offscreen, xHapp + dxBar - 6, yHapp + 2 * dyBar, wBar + 10, 38);
    690       CountBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18,
     686      CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18,
    691687        Phrases.Lookup('LACK'), -Report.HappinessBalance, RedTex);
    692688    end;
     
    696692  if IsCityAlive then
    697693  begin
    698     CountBar(offscreen, xFood, yFood + dyBar div 2, wBar, 0,
     694    CountBar(Offscreen, xFood, yFood + dyBar div 2, wBar, 0,
    699695      Phrases.Lookup('FOOD'), Report.CollectedFood, MainTexture);
    700     CountBar(offscreen, xFood + dxBar, yFood + dyBar, wBar, 0,
    701       Phrases.Lookup('DEMAND'), 2 * c.Size, MainTexture);
    702     CountBar(offscreen, xFood + dxBar, yFood, wBar, 0,
     696    CountBar(Offscreen, xFood + dxBar, yFood + dyBar, wBar, 0,
     697      Phrases.Lookup('DEMAND'), 2 * C.Size, MainTexture);
     698    CountBar(Offscreen, xFood + dxBar, yFood, wBar, 0,
    703699      Phrases.Lookup('SUPPORT'), Report.FoodSupport, MainTexture);
    704700    if Report.FoodSurplus >= 0 then
    705       if (cGov = gFuture) or (c.Size >= NeedAqueductSize) and
     701      if (cGov = gFuture) or (C.Size >= NeedAqueductSize) and
    706702        (Report.FoodSurplus < 2) then
    707         CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6,
     703        CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6,
    708704          Phrases.Lookup('PROFIT'), Report.FoodSurplus, MainTexture)
    709705      else
    710         CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0,
     706        CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0,
    711707          Phrases.Lookup('SURPLUS'), Report.FoodSurplus, MainTexture)
    712708    else
    713709    begin
    714710      MakeRed(Offscreen, xFood + dxBar - 6, yFood + 2 * dyBar, wBar + 10, 38);
    715       CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1,
     711      CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1,
    716712        Phrases.Lookup('LACK'), -Report.FoodSurplus, RedTex);
    717713    end;
    718714  end;
    719   CanGrow := (c.Size < MaxCitySize) and (cGov <> gFuture) and
    720     (Report.FoodSurplus > 0) and ((c.Size < NeedAqueductSize) or
    721     (c.Built[imAqueduct] = 1) and (c.Size < NeedSewerSize) or
    722     (c.Built[imSewer] = 1));
     715  CanGrow := (C.Size < MaxCitySize) and (cGov <> gFuture) and
     716    (Report.FoodSurplus > 0) and ((C.Size < NeedAqueductSize) or
     717    (C.Built[imAqueduct] = 1) and (C.Size < NeedSewerSize) or
     718    (C.Built[imSewer] = 1));
    723719  FillBar(xFood + 3, yFood + 102, TrueFood,
    724     CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, c.Size),
     720    CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, C.Size),
    725721    Report.Storage, 1, CanGrow);
    726   LoweredTextout(offscreen.Canvas, -1, MainTexture, xFood + 3 - 5,
     722  LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood + 3 - 5,
    727723    yFood + 102 - 20, Format('%d/%d', [TrueFood, Report.Storage]));
    728   LoweredTextout(offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66,
     724  LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66,
    729725    Phrases.Lookup('STORAGE'));
    730726
     
    732728  if IsCityAlive then
    733729  begin
    734     CountBar(offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'),
     730    CountBar(Offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'),
    735731      Report.CollectedMaterial, MainTexture);
    736     CountBar(offscreen, xProd + dxBar, yProd, wBar, 2,
     732    CountBar(Offscreen, xProd + dxBar, yProd, wBar, 2,
    737733      Phrases.Lookup('SUPPORT'), Report.MaterialSupport, MainTexture);
    738734    if Report.Production >= 0 then
    739       if c.Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    740         CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6,
     735      if C.Project and (cpImp + cpIndex) = cpImp + imTrGoods then
     736        CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6,
    741737          Phrases.Lookup('PROFIT'), Report.Production, MainTexture)
    742738      else
    743         CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2,
     739        CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2,
    744740          Phrases.Lookup('PROD'), Report.Production, MainTexture)
    745741    else
    746742    begin
    747743      MakeRed(Offscreen, xProd + dxBar - 6, yProd + dyBar + 17, wBar + 10, 38);
    748       CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3,
     744      CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3,
    749745        Phrases.Lookup('LACK'), -Report.Production, RedTex);
    750746    end;
    751747  end;
    752   if c.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then
    753     with offscreen.Canvas do
    754     begin
    755       i := Report.Production;
    756       if (i < 0) or not IsCityAlive then
    757         i := 0;
    758       FillBar(xProd + 3, yProd + 16 + 63, TrueProd, i, PrCost, 4, true);
    759       LoweredTextout(offscreen.Canvas, -1, MainTexture, xProd + 3 - 5,
     748  if C.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then
     749    with Offscreen.Canvas do
     750    begin
     751      I := Report.Production;
     752      if (I < 0) or not IsCityAlive then
     753        I := 0;
     754      FillBar(xProd + 3, yProd + 16 + 63, TrueProd, I, PrCost, 4, True);
     755      LoweredTextout(Offscreen.Canvas, -1, MainTexture, xProd + 3 - 5,
    760756        yProd + 16 + 43, Format('%d/%d', [TrueProd, PrCost]));
    761       if BiColorTextWidth(offscreen.Canvas, PrName) > wBar + dxBar then
     757      if BiColorTextWidth(Offscreen.Canvas, PrName) > wBar + dxBar then
    762758      begin
    763759        repeat
    764           Delete(PrName, length(PrName), 1)
    765         until BiColorTextWidth(offscreen.Canvas, PrName) <= wBar + dxBar;
     760          Delete(PrName, Length(PrName), 1)
     761        until BiColorTextWidth(Offscreen.Canvas, PrName) <= wBar + dxBar;
    766762        PrName := PrName + '.'
    767763      end;
    768764    end;
    769   RisedTextOut(offscreen.Canvas, xProd - 2, yProd + 36, PrName);
     765  RisedTextOut(Offscreen.Canvas, xProd - 2, yProd + 36, PrName);
    770766
    771767  // pollution section
     
    773769  begin
    774770    FillBar(xPoll + 3, yPoll + 20, TruePoll, Report.AddPollution,
    775       MaxPollution, 3, true);
    776     RisedTextOut(offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20,
     771      MaxPollution, 3, True);
     772    RisedTextOut(Offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20,
    777773      Phrases.Lookup('POLL'));
    778774  end;
     
    781777  if IsCityAlive and (Report.CollectedTrade > 0) then
    782778  begin
    783     CountBar(offscreen, xTrade, yTrade + dyBar div 2, wBar, 4,
     779    CountBar(Offscreen, xTrade, yTrade + dyBar div 2, wBar, 4,
    784780      Phrases.Lookup('TRADE'), Report.CollectedTrade, MainTexture);
    785     CountBar(offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5,
     781    CountBar(Offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5,
    786782      Phrases.Lookup('CORR'), Report.Corruption, MainTexture);
    787     CountBar(offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'),
     783    CountBar(Offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'),
    788784      Report.Tax, MainTexture);
    789     CountBar(offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12,
     785    CountBar(Offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12,
    790786      Phrases.Lookup('SCIENCE'), Report.Science, MainTexture);
    791787  end;
    792788
    793789  // small map
    794   DpiBitCanvas(offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap,
     790  DpiBitBltCanvas(Offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap,
    795791    SmallCityMap.Canvas, 0, 0);
    796792  if SmallMapMode = smImprovements then
    797     Frame(offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3),
     793    Frame(Offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3),
    798794      ySmallMap + 24 * (ZoomArea mod 3), xSmallMap + 48 * (ZoomArea div 3) + 49,
    799795      ySmallMap + 24 * (ZoomArea mod 3) + 25, MainTexture.ColorMark,
    800796      MainTexture.ColorMark);
    801   Frame(offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap,
     797  Frame(Offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap,
    802798    ySmallMap + hSmallMap, $B0B0B0, $FFFFFF);
    803   RFrame(offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap +
     799  RFrame(Offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap +
    804800    1, ySmallMap + hSmallMap + 1, $FFFFFF, $B0B0B0);
    805801
    806   Frame(offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport,
     802  Frame(Offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport,
    807803    ySupport + hSupport, $B0B0B0, $FFFFFF);
    808   RFrame(offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1,
     804  RFrame(Offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1,
    809805    ySupport + hSupport + 1, $FFFFFF, $B0B0B0);
    810   x := xSupport + wSupport div 2;
    811   y := ySupport + hSupport div 2;
     806  X := xSupport + wSupport div 2;
     807  Y := ySupport + hSupport div 2;
    812808  if SmallMapMode = smSupportedUnits then
    813809  begin
    814     offscreen.Canvas.brush.Color := MainTexture.ColorMark;
    815     offscreen.Canvas.FillRect(Rect(x - 27, y - 6, x + 27, y + 6));
    816     offscreen.Canvas.brush.style := bsClear;
    817   end;
    818   Sprite(offscreen, HGrSystem, x - 16, y - 5, 10, 10, 88, 115);
    819   Sprite(offscreen, HGrSystem, x - 5, y - 5, 10, 10, 66, 115);
    820   Sprite(offscreen, HGrSystem, x + 6, y - 5, 10, 10, 154, 126);
    821 
    822   DpiBitCanvas(offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap,
     810    Offscreen.Canvas.Brush.Color := MainTexture.ColorMark;
     811    Offscreen.Canvas.FillRect(Rect(X - 27, Y - 6, X + 27, Y + 6));
     812    Offscreen.Canvas.Brush.style := bsClear;
     813  end;
     814  Sprite(Offscreen, HGrSystem, X - 16, Y - 5, 10, 10, 88, 115);
     815  Sprite(Offscreen, HGrSystem, X - 5, Y - 5, 10, 10, 66, 115);
     816  Sprite(Offscreen, HGrSystem, X + 6, Y - 5, 10, 10, 154, 126);
     817
     818  DpiBitBltCanvas(Offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap,
    823819    ZoomCityMap.Canvas, 0, 0);
    824820
    825   for i := 0 to 5 do
    826     imix[i] := -1;
     821  for I := 0 to 5 do
     822    imix[I] := -1;
    827823  if SmallMapMode = smImprovements then
    828824  begin
     
    831827      Cnt := 0;
    832828      for iix := 0 to nImp - 1 do
    833         if ((iix < nWonder) or (ImpPosition[iix] < 0)) and (c.Built[iix] > 0) then
     829        if ((iix < nWonder) or (ImpPosition[iix] < 0)) and (C.Built[iix] > 0) then
    834830        begin
    835           i := Cnt - Page * 6;
    836           if (i >= 0) and (i < 6) then
    837             imix[i] := iix;
    838           inc(Cnt);
     831          I := Cnt - Page * 6;
     832          if (I >= 0) and (I < 6) then
     833            imix[I] := iix;
     834          Inc(Cnt);
    839835        end;
    840836      PageCount := (Cnt + 5) div 6;
     
    844840      for iix := nWonder to nImp - 1 do
    845841      begin
    846         i := ImpPosition[iix] - 6 * ZoomArea;
    847         if (i >= 0) and (i < 6) and (c.Built[iix] > 0) then
    848           imix[i] := iix;
     842        I := ImpPosition[iix] - 6 * ZoomArea;
     843        if (I >= 0) and (I < 6) and (C.Built[iix] > 0) then
     844          imix[I] := iix;
    849845      end;
    850846      PageCount := 0;
    851847    end;
    852     for i := 0 to 5 do
    853       if imix[i] >= 0 then
     848    for I := 0 to 5 do
     849      if imix[I] >= 0 then
    854850      begin
    855         iix := imix[i];
    856         x := xZoomMap + 14 + 72 * (i mod 3);
    857         y := yZoomMap + 14 + 56 * (i div 3);
    858         ImpImage(offscreen.Canvas, x, y, iix, cGov, AllowChange and
     851        iix := imix[I];
     852        X := xZoomMap + 14 + 72 * (I mod 3);
     853        Y := yZoomMap + 14 + 56 * (I div 3);
     854        ImpImage(Offscreen.Canvas, X, Y, iix, cGov, AllowChange and
    859855          (ClientMode < scContact));
    860856        if IsCityAlive then
     
    862858          if iix = imColosseum then
    863859          begin
    864             Sprite(offscreen, HGrSystem, x + 46, y, 14, 14, 82, 100);
     860            Sprite(Offscreen, HGrSystem, X + 46, Y, 14, 14, 82, 100);
    865861          end
    866862          else
     
    880876            if HappyGain > 1 then
    881877            begin
    882               d := 30 div (HappyGain - 1);
    883               if d > 10 then
    884                 d := 10
     878              D := 30 div (HappyGain - 1);
     879              if D > 10 then
     880                D := 10
    885881            end;
    886             for j := 0 to HappyGain - 1 do
    887               Sprite(offscreen, HGrSystem, x + 50, y + d * j, 10, 10, 132, 126);
     882            for J := 0 to HappyGain - 1 do
     883              Sprite(Offscreen, HGrSystem, X + 50, Y + D * J, 10, 10, 132, 126);
    888884          end;
    889           for j := 0 to Imp[iix].Maint - 1 do
    890             Sprite(offscreen, HGrSystem, x - 4, y + 29 - 3 * j, 10, 10,
     885          for J := 0 to Imp[iix].Maint - 1 do
     886            Sprite(Offscreen, HGrSystem, X - 4, Y + 29 - 3 * J, 10, 10,
    891887              132, 115);
    892888        end
     
    919915  else { if SmallMapMode = smSupportedUnits then }
    920916  begin
    921     LoweredTextout(offscreen.Canvas, -1, MainTexture, xZoomMap + 6,
     917    LoweredTextout(Offscreen.Canvas, -1, MainTexture, xZoomMap + 6,
    922918      yZoomMap + 2, Phrases.Lookup('SUPUNITS'));
    923     FreeSupp := c.Size * SupportFree[cGov] shr 1;
     919    FreeSupp := C.Size * SupportFree[cGov] shr 1;
    924920    Cnt := 0;
    925     for i := 0 to MyRO.nUn - 1 do
    926       if (MyUn[i].Loc >= 0) and (MyUn[i].Home = cix) then
    927         with MyModel[MyUn[i].mix] do
     921    for I := 0 to MyRO.nUn - 1 do
     922      if (MyUn[I].Loc >= 0) and (MyUn[I].Home = cix) then
     923        with MyModel[MyUn[I].mix] do
    928924        begin
    929           Server(sGetUnitReport, me, i, UnitReport);
     925          Server(sGetUnitReport, Me, I, UnitReport);
    930926          if (Cnt >= 6 * Page) and (Cnt < 6 * (Page + 1)) then
    931927          begin // unit visible in display
    932             imix[Cnt - 6 * Page] := i;
    933             x := ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap;
    934             y := ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20;
    935             MakeUnitInfo(me, MyUn[i], UnitInfo);
    936             NoMap.SetOutput(offscreen);
    937             NoMap.PaintUnit(x, y, UnitInfo, MyUn[i].Status);
    938 
    939             for j := 0 to UnitReport.FoodSupport - 1 do
    940               Sprite(offscreen, HGrSystem, x + 38 + 11 * j, y + 40, 10,
     928            imix[Cnt - 6 * Page] := I;
     929            X := ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap;
     930            Y := ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20;
     931            MakeUnitInfo(Me, MyUn[I], UnitInfo);
     932            NoMap.SetOutput(Offscreen);
     933            NoMap.PaintUnit(X, Y, UnitInfo, MyUn[I].Status);
     934
     935            for J := 0 to UnitReport.FoodSupport - 1 do
     936              Sprite(Offscreen, HGrSystem, X + 38 + 11 * J, Y + 40, 10,
    941937                10, 66, 115);
    942             for j := 0 to UnitReport.ProdSupport - 1 do
     938            for J := 0 to UnitReport.ProdSupport - 1 do
    943939            begin
    944940              if (FreeSupp > 0) and
    945941                (UnitReport.ReportFlags and urfAlwaysSupport = 0) then
    946942              begin
    947                 Sprite(offscreen, HGrSystem, x + 16 - 11 * j, y + 40, 10,
     943                Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10,
    948944                  10, 143, 115);
    949                 dec(FreeSupp);
     945                Dec(FreeSupp);
    950946              end
    951947              else
    952                 Sprite(offscreen, HGrSystem, x + 16 - 11 * j, y + 40, 10,
     948                Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10,
    953949                  10, 88, 115);
    954950            end;
    955951            if UnitReport.ReportFlags and urfDeployed <> 0 then
    956               for j := 0 to 1 do
    957                 Sprite(offscreen, HGrSystem, x + 27 + 11 * j, y + 40, 10,
     952              for J := 0 to 1 do
     953                Sprite(Offscreen, HGrSystem, X + 27 + 11 * J, Y + 40, 10,
    958954                  10, 154, 126)
    959955          end // unit visible in display
    960956          else
    961             dec(FreeSupp, UnitReport.ProdSupport);
    962           inc(Cnt);
     957            Dec(FreeSupp, UnitReport.ProdSupport);
     958          Inc(Cnt);
    963959        end;
    964960    PageCount := (Cnt + 5) div 6;
     
    973969  PageDownBtn.Visible := PageCount > 1;
    974970
    975   with offscreen.Canvas do
     971  with Offscreen.Canvas do
    976972  begin
    977973    { display project now }
    978     DLine(offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10,
     974    DLine(Offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10,
    979975      yProd + dyBar + 16, $FFFFFF, $B0B0B0);
    980976    if ProdHint then
    981977    begin
    982       ScreenTools.Frame(offscreen.Canvas, xView + 9 - 1, yView + 5 - 1,
     978      ScreenTools.Frame(Offscreen.Canvas, xView + 9 - 1, yView + 5 - 1,
    983979        xView + 9 + xSizeBig, yView + 5 + ySizeBig, $B0B0B0, $FFFFFF);
    984       RFrame(offscreen.Canvas, xView + 9 - 2, yView + 5 - 2,
     980      RFrame(Offscreen.Canvas, xView + 9 - 2, yView + 5 - 2,
    985981        xView + 9 + xSizeBig + 1, yView + 5 + ySizeBig + 1, $FFFFFF, $B0B0B0);
    986       with offscreen.Canvas do
     982      with Offscreen.Canvas do
    987983      begin
    988         brush.Color := $000000;
     984        Brush.Color := $000000;
    989985        FillRect(Rect(xView + 9, yView + 5, xView + 1 + 72 - 8,
    990986          yView + 5 + 40));
    991         brush.style := bsClear;
     987        Brush.style := bsClear;
    992988      end;
    993989    end
    994     else if AllowChange and (c.Status and 7 <> 0) then
     990    else if AllowChange and (C.Status and 7 <> 0) then
    995991    begin // city type autobuild
    996       FrameImage(offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
    997         ySizeBig, (c.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and
     992      FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
     993        ySizeBig, (C.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and
    998994        (ClientMode < scContact));
    999995    end
    1000     else if c.Project and cpImp = 0 then
     996    else if C.Project and cpImp = 0 then
    1001997    begin // project is unit
    1002       FrameImage(offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
     998      FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
    1003999        ySizeBig, 0, 0, AllowChange and (ClientMode < scContact));
    1004       with Tribe[cOwner].ModelPicture[c.Project and cpIndex] do
    1005         Sprite(offscreen, HGr, xView + 5, yView + 1, 64, 44,
     1000      with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do
     1001        Sprite(Offscreen, HGr, xView + 5, yView + 1, 64, 44,
    10061002          pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
    10071003    end
     
    10091005    begin // project is building
    10101006      if ProdHint then
    1011         Paintiix := c.Project0 and cpIndex
     1007        Paintiix := C.Project0 and cpIndex
    10121008      else
    1013         Paintiix := c.Project and cpIndex;
    1014       ImpImage(offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov,
     1009        Paintiix := C.Project and cpIndex;
     1010      ImpImage(Offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov,
    10151011        AllowChange and (ClientMode < scContact));
    10161012    end;
     
    10191015  if AllowChange and (ClientMode < scContact) then
    10201016  begin
    1021     i := Server(sBuyCityProject - sExecute, me, cix, nil^);
    1022     BuyBtn.Visible := (i = eOk) or (i = eViolation);
     1017    I := Server(sBuyCityProject - sExecute, Me, cix, nil^);
     1018    BuyBtn.Visible := (I = eOk) or (I = eViolation);
    10231019  end
    10241020  else
    1025     BuyBtn.Visible := false;
     1021    BuyBtn.Visible := False;
    10261022
    10271023  MarkUsedOffscreen(ClientWidth, ClientHeight);
    1028 end; { OffscreenPaint }
     1024end;
    10291025
    10301026procedure TCityDlg.FormShow(Sender: TObject);
    10311027var
    1032   dx, dy, Loc1: integer;
     1028  dx, dy, Loc1: Integer;
    10331029  GetCityData: TGetCityData;
    10341030begin
     
    10361032  if cix >= 0 then
    10371033  begin { own city }
    1038     c := MyCity[cix];
    1039     cOwner := me;
     1034    C := MyCity[cix];
     1035    cOwner := Me;
    10401036    cGov := MyRO.Government;
    10411037    ProdHint := (cGov <> gAnarchy) and
    10421038      (Happened and (chProduction or chFounded or chCaptured or
    10431039      chAllImpsMade) <> 0);
    1044     Server(sGetCityAreaInfo, me, cix, CityAreaInfo);
     1040    Server(sGetCityAreaInfo, Me, cix, CityAreaInfo);
    10451041    NextCityBtn.Visible := WindowMode = wmPersistent;
    10461042    PrevCityBtn.Visible := WindowMode = wmPersistent;
     
    10491045  begin
    10501046    SmallMapMode := smImprovements;
    1051     Server(sGetCity, me, cLoc, GetCityData);
    1052     c := GetCityData.c;
     1047    Server(sGetCity, Me, cLoc, GetCityData);
     1048    C := GetCityData.C;
    10531049    cOwner := GetCityData.Owner;
    10541050    cGov := MyRO.EnemyReport[cOwner].Government;
    1055     Happened := c.Flags and $7FFFFFFF;
    1056     ProdHint := false;
    1057     Server(sGetEnemyCityAreaInfo, me, cLoc, CityAreaInfo);
    1058 
    1059     if c.Project and cpImp = 0 then
     1051    Happened := C.Flags and $7FFFFFFF;
     1052    ProdHint := False;
     1053    Server(sGetEnemyCityAreaInfo, Me, cLoc, CityAreaInfo);
     1054
     1055    if C.Project and cpImp = 0 then
    10601056    begin
    10611057      emix := MyRO.nEnemyModel - 1;
    10621058      while (emix > 0) and ((MyRO.EnemyModel[emix].Owner <> cOwner) or
    1063         (integer(MyRO.EnemyModel[emix].mix) <> c.Project and cpIndex)) do
    1064         dec(emix);
    1065       if not Assigned(Tribe[cOwner].ModelPicture[c.Project and cpIndex].HGr) then
     1059        (Integer(MyRO.EnemyModel[emix].mix) <> C.Project and cpIndex)) do
     1060        Dec(emix);
     1061      if not Assigned(Tribe[cOwner].ModelPicture[C.Project and cpIndex].HGr) then
    10661062        InitEnemyModel(emix);
    10671063    end;
    10681064
    1069     NextCityBtn.Visible := false;
    1070     PrevCityBtn.Visible := false;
     1065    NextCityBtn.Visible := False;
     1066    PrevCityBtn.Visible := False;
    10711067  end;
    10721068  Page := 0;
    10731069
    1074   if c.Size < 5 then
     1070  if C.Size < 5 then
    10751071    SizeClass := 0
    1076   else if c.Size < 9 then
     1072  else if C.Size < 9 then
    10771073    SizeClass := 1
    1078   else if c.Size < 13 then
     1074  else if C.Size < 13 then
    10791075    SizeClass := 2
    10801076  else
     
    10821078
    10831079  // check if port
    1084   IsPort := false;
     1080  IsPort := False;
    10851081  for dx := -2 to 2 do
    10861082    for dy := -2 to 2 do
    1087       if abs(dx) + abs(dy) = 2 then
     1083      if Abs(dx) + Abs(dy) = 2 then
    10881084      begin
    10891085        Loc1 := dLoc(cLoc, dx, dy);
    10901086        if (Loc1 >= 0) and (Loc1 < G.lx * G.ly) and
    10911087          (MyMap[Loc1] and fTerrain < fGrass) then
    1092           IsPort := true;
     1088          IsPort := True;
    10931089      end;
    10941090
     
    10991095  end;
    11001096
    1101   Caption := CityName(c.ID);
     1097  Caption := CityName(C.ID);
    11021098
    11031099  InitSmallCityMap;
     
    11051101  OpenSoundEvent := -1;
    11061102  OffscreenPaint;
    1107   Timer1.Enabled := true;
    1108 end;
    1109 
    1110 procedure TCityDlg.ShowNewContent(NewMode, Loc: integer; ShowEvent: cardinal);
     1103  Timer1.Enabled := True;
     1104end;
     1105
     1106procedure TCityDlg.ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal);
    11111107begin
    11121108  if MyMap[Loc] and fOwned <> 0 then
     
    11141110    cix := MyRO.nCity - 1;
    11151111    while (cix >= 0) and (MyCity[cix].Loc <> Loc) do
    1116       dec(cix);
    1117     assert(cix >= 0);
     1112      Dec(cix);
     1113    Assert(cix >= 0);
    11181114    if (Optimize_cixTileChange >= 0) and
    11191115      (Optimize_TilesBeforeChange and not MyCity[Optimize_cixTileChange].Tiles
     
    11311127  else
    11321128    cix := -1;
    1133   AllowChange := not supervising and (cix >= 0);
     1129  AllowChange := not Supervising and (cix >= 0);
    11341130  cLoc := Loc;
    11351131  Happened := ShowEvent;
     
    11381134
    11391135procedure TCityDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
    1140   Shift: TShiftState; x, y: integer);
     1136  Shift: TShiftState; X, Y: Integer);
    11411137var
    1142   i, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: integer;
    1143   Rebuild: boolean;
    1144 begin
    1145   if (ssLeft in Shift) and (x >= xSmallMap) and (x < xSmallMap + wSmallMap) and
    1146     (y >= ySmallMap) and (y < ySmallMap + hSmallMap) then
     1138  I, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: Integer;
     1139  Rebuild: Boolean;
     1140begin
     1141  if (ssLeft in Shift) and (X >= xSmallMap) and (X < xSmallMap + wSmallMap) and
     1142    (Y >= ySmallMap) and (Y < ySmallMap + hSmallMap) then
    11471143  begin
    11481144    SmallMapMode := smImprovements;
    1149     ZoomArea := (y - ySmallMap) * 3 div hSmallMap + 3 *
    1150       ((x - xSmallMap) * 2 div wSmallMap);
     1145    ZoomArea := (Y - ySmallMap) * 3 div hSmallMap + 3 *
     1146      ((X - xSmallMap) * 2 div wSmallMap);
    11511147    Page := 0;
    11521148    InitZoomCityMap;
    11531149    SmartUpdateContent;
    1154     exit;
    1155   end;
    1156   if (ssLeft in Shift) and (x >= xSupport) and (x < xSupport + wSupport) and
    1157     (y >= ySupport) and (y < ySupport + hSupport) then
     1150    Exit;
     1151  end;
     1152  if (ssLeft in Shift) and (X >= xSupport) and (X < xSupport + wSupport) and
     1153    (Y >= ySupport) and (Y < ySupport + hSupport) then
    11581154  begin
    11591155    SmallMapMode := smSupportedUnits;
     
    11611157    InitZoomCityMap;
    11621158    SmartUpdateContent;
    1163     exit;
     1159    Exit;
    11641160  end;
    11651161  if not AllowChange then
    1166     exit; // not an own city
     1162    Exit; // Not an own city
    11671163
    11681164  if (ssLeft in Shift) then
    1169     if (ClientMode < scContact) and (x >= xView) and (y >= yView) and
    1170       (x < xView + 73) and (y < yView + 50) then
     1165    if (ClientMode < scContact) and (X >= xView) and (Y >= yView) and
     1166      (X < xView + 73) and (Y < yView + 50) then
    11711167      if cGov = gAnarchy then
    1172         with MessgExDlg do
     1168        with MainScreen.MessgExDlg do
    11731169        begin
    11741170          { MessgText:=Phrases.Lookup('OUTOFCONTROL');
    1175             if c.Project and cpImp=0 then
    1176             MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[c.Project and cpIndex]])
    1177             else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',c.Project and cpIndex)]); }
     1171            if C.Project and cpImp=0 then
     1172            MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[C.Project and cpIndex]])
     1173            else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',C.Project and cpIndex)]); }
    11781174          MessgText := Phrases.Lookup('NOCHANGEINANARCHY');
    11791175          Kind := mkOk;
     
    11841180        if ProdHint then
    11851181        begin
    1186           ProdHint := false;
     1182          ProdHint := False;
    11871183          SmartUpdateContent
    11881184        end;
    11891185        ChooseProject;
    11901186      end
    1191     else if (SmallMapMode = smImprovements) and (x >= xZoomMap) and (x < xZoomMap + wZoomMap) and
    1192       (y >= yZoomMap) and (y < yZoomMap + hZoomMap) then
    1193     begin
    1194       i := 5;
    1195       while (i >= 0) and not((x >= xZoomMap + 14 + 72 * (i mod 3)) and
    1196         (x < xZoomMap + 14 + 56 + 72 * (i mod 3)) and
    1197         (y >= yZoomMap + 14 + 56 * (i div 3)) and
    1198         (y < yZoomMap + 14 + 40 + 56 * (i div 3))) do
    1199         dec(i);
    1200       if i >= 0 then
     1187    else if (SmallMapMode = smImprovements) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and
     1188      (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then
     1189    begin
     1190      I := 5;
     1191      while (I >= 0) and not((X >= xZoomMap + 14 + 72 * (I mod 3)) and
     1192        (X < xZoomMap + 14 + 56 + 72 * (I mod 3)) and
     1193        (Y >= yZoomMap + 14 + 56 * (I div 3)) and
     1194        (Y < yZoomMap + 14 + 40 + 56 * (I div 3))) do
     1195        Dec(I);
     1196      if I >= 0 then
    12011197      begin
    1202         iix := imix[i];
     1198        iix := imix[I];
    12031199        if iix >= 0 then
    12041200          if ssShift in Shift then
    1205             HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, iix)
     1201            MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, iix)
    12061202          else if (ClientMode < scContact) then
    1207             with MessgExDlg do
     1203            with MainScreen.MessgExDlg do
    12081204            begin
    12091205              IconKind := mikImp;
     
    12201216              else
    12211217              begin
    1222                 SellResult := Server(sSellCityImprovement - sExecute, me,
     1218                SellResult := Server(sSellCityImprovement - sExecute, Me,
    12231219                  cix, iix);
    12241220                if SellResult < rExecuted then
     
    12351231                else
    12361232                begin
    1237                   if Server(sRebuildCityImprovement - sExecute, me, cix, iix) < rExecuted
     1233                  if Server(sRebuildCityImprovement - sExecute, Me, cix, iix) < rExecuted
    12381234                  then
    12391235                  begin // no rebuild possible, ask for sell only
    1240                     Rebuild := false;
     1236                    Rebuild := False;
    12411237                    MessgText := Phrases.Lookup('IMPROVEMENTS', iix);
    12421238                    if not Phrases2FallenBackToEnglish then
    12431239                      MessgText := Format(Phrases2.Lookup('SELL2'),
    12441240                        [MessgText, Imp[iix].Cost * BuildCostMod
    1245                         [G.Difficulty[me]] div 12])
     1241                        [G.Difficulty[Me]] div 12])
    12461242                    else
    12471243                      MessgText := Format(Phrases.Lookup('SELL'), [MessgText]);
    12481244                    if iix = imSpacePort then
    1249                       with MyRO.Ship[me] do
     1245                      with MyRO.Ship[Me] do
    12501246                        if Parts[0] + Parts[1] + Parts[2] > 0 then
    12511247                          MessgText := MessgText + ' ' +
     
    12581254                  else
    12591255                  begin
    1260                     Rebuild := true;
     1256                    Rebuild := True;
    12611257                    MessgText := Phrases.Lookup('IMPROVEMENTS', iix);
    12621258                    if not Phrases2FallenBackToEnglish then
    12631259                      MessgText := Format(Phrases2.Lookup('DISPOSE2'),
    12641260                        [MessgText, Imp[iix].Cost * BuildCostMod
    1265                         [G.Difficulty[me]] div 12 * 2 div 3])
     1261                        [G.Difficulty[Me]] div 12 * 2 div 3])
    12661262                    else
    12671263                      MessgText := Format(Phrases.Lookup('DISPOSE'),
    12681264                        [MessgText]);
    12691265                    if iix = imSpacePort then
    1270                       with MyRO.Ship[me] do
     1266                      with MyRO.Ship[Me] do
    12711267                        if Parts[0] + Parts[1] + Parts[2] > 0 then
    12721268                          MessgText := MessgText + ' ' +
     
    12821278                    begin
    12831279                      Play('CITY_REBUILDIMP');
    1284                       Server(sRebuildCityImprovement, me, cix, iix);
     1280                      Server(sRebuildCityImprovement, Me, cix, iix);
    12851281                    end
    12861282                    else
    12871283                    begin
    12881284                      Play('CITY_SELLIMP');
    1289                       Server(sSellCityImprovement, me, cix, iix);
     1285                      Server(sSellCityImprovement, Me, cix, iix);
    12901286                    end;
    12911287                    CityOptimizer_CityChange(cix);
     
    13001296      end;
    13011297    end
    1302     else if (SmallMapMode = smSupportedUnits) and (x >= xZoomMap) and (x < xZoomMap + wZoomMap) and
    1303       (y >= yZoomMap) and (y < yZoomMap + hZoomMap) then
    1304     begin
    1305       i := 5;
    1306       while (i >= 0) and not((x >= xZoomMap + 64 * (i mod 3)) and
    1307         (x < xZoomMap + 64 + 64 * (i mod 3)) and
    1308         (y >= yZoomMap + 20 + 48 * (i div 3)) and
    1309         (y < yZoomMap + 20 + 52 + 48 * (i div 3))) do
    1310         dec(i);
    1311       if (i >= 0) and (imix[i] >= 0) then
     1298    else if (SmallMapMode = smSupportedUnits) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and
     1299      (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then
     1300    begin
     1301      I := 5;
     1302      while (I >= 0) and not((X >= xZoomMap + 64 * (I mod 3)) and
     1303        (X < xZoomMap + 64 + 64 * (I mod 3)) and
     1304        (Y >= yZoomMap + 20 + 48 * (I div 3)) and
     1305        (Y < yZoomMap + 20 + 52 + 48 * (I div 3))) do
     1306        Dec(I);
     1307      if (I >= 0) and (imix[I] >= 0) then
    13121308        if ssShift in Shift then
    13131309        else if (cix >= 0) and (ClientMode < scContact) and
     
    13161312          CloseAction := None;
    13171313          Close;
    1318           MainScreen.CityClosed(imix[i], false, true);
     1314          MainScreen.CityClosed(imix[I], False, True);
    13191315        end;
    13201316    end
    1321     else if (x >= xmArea - 192) and (x < xmArea + 192) and (y >= ymArea - 96)
    1322       and (y < ymArea + 96) then
     1317    else if (X >= xmArea - 192) and (X < xmArea + 192) and (Y >= ymArea - 96)
     1318      and (Y < ymArea + 96) then
    13231319    with AreaMap do begin
    1324       qx := ((4000 * xxt * yyt) + (x - xmArea) * (yyt * 2) + (y - ymArea + yyt)
     1320      qx := ((4000 * xxt * yyt) + (X - xmArea) * (yyt * 2) + (Y - ymArea + yyt)
    13251321        * (xxt * 2)) div (xxt * yyt * 4) - 1000;
    1326       qy := ((4000 * xxt * yyt) + (y - ymArea + yyt) * (xxt * 2) - (x - xmArea)
     1322      qy := ((4000 * xxt * yyt) + (Y - ymArea + yyt) * (xxt * 2) - (X - xmArea)
    13271323        * (yyt * 2)) div (xxt * yyt * 4) - 1000;
    13281324      dx := qx - qy;
     
    13341330          Loc1 := dLoc(cLoc, dx, dy);
    13351331          if (Loc1 >= 0) and (Loc1 < G.lx * G.ly) then
    1336             HelpOnTerrain(Loc1, FWindowMode or wmPersistent)
     1332            HelpOnTerrain(Loc1, WindowModeMakePersistent(FWindowMode))
    13371333        end
    13381334        else if (ClientMode < scContact) and (cGov <> gAnarchy) and
    1339           (c.Flags and chCaptured = 0) then
     1335          (C.Flags and chCaptured = 0) then
    13401336        begin // toggle exploitation
    1341           assert(not supervising);
    1342           if c.Status and csResourceWeightsMask <> 0 then
     1337          Assert(not Supervising);
     1338          if C.Status and csResourceWeightsMask <> 0 then
    13431339          begin
    1344             with MessgExDlg do
     1340            with MainScreen.MessgExDlg do
    13451341            begin
    13461342              MessgText := Phrases.Lookup('CITYMANAGEOFF');
     
    13501346              ShowModal;
    13511347            end;
    1352             if MessgExDlg.ModalResult = mrOK then
     1348            if MainScreen.MessgExDlg.ModalResult = mrOK then
    13531349            begin
    13541350              MyCity[cix].Status := MyCity[cix].Status and
    13551351                not csResourceWeightsMask; // off
    1356               c.Status := MyCity[cix].Status;
     1352              C.Status := MyCity[cix].Status;
    13571353              SmartUpdateContent;
    13581354            end;
    1359             exit;
     1355            Exit;
    13601356          end;
    13611357          fix := (dy + 3) shl 2 + (dx + 3) shr 1;
    13621358          NewTiles := MyCity[cix].Tiles xor (1 shl fix);
    1363           if Server(sSetCityTiles, me, cix, NewTiles) >= rExecuted then
     1359          if Server(sSetCityTiles, Me, cix, NewTiles) >= rExecuted then
    13641360          begin
    13651361            SmartUpdateContent;
     
    13701366    end
    13711367    else if (ClientMode < scContact) and (cGov <> gAnarchy) and
    1372       (c.Flags and chCaptured = 0) and (x >= xmOpt - 32) and (x < xmOpt + 32)
    1373       and (y >= ymOpt - 32) and (y < ymOpt + 32) then
    1374     begin
    1375       i := sqr(x - xmOpt) + sqr(y - ymOpt); // click radius
    1376       if i <= 32 * 32 then
     1368      (C.Flags and chCaptured = 0) and (X >= xmOpt - 32) and (X < xmOpt + 32)
     1369      and (Y >= ymOpt - 32) and (Y < ymOpt + 32) then
     1370    begin
     1371      I := sqr(X - xmOpt) + sqr(Y - ymOpt); // click radius
     1372      if I <= 32 * 32 then
    13771373      begin
    1378         if i < 16 * 16 then // inner area clicked
    1379           if c.Status and csResourceWeightsMask <> 0 then
    1380             i := (c.Status shr 4 and $0F) mod 5 + 1 // rotate except off
     1374        if I < 16 * 16 then // inner area clicked
     1375          if C.Status and csResourceWeightsMask <> 0 then
     1376            I := (C.Status shr 4 and $0F) mod 5 + 1 // rotate except off
    13811377          else
    1382             i := 3 // rwGrowth
     1378            I := 3 // rwGrowth
    13831379        else
    1384           case trunc(arctan2(x - xmOpt, ymOpt - y) * 180 / pi) of
     1380          case trunc(arctan2(X - xmOpt, ymOpt - Y) * 180 / pi) of
    13851381            - 25 - 52 * 2 .. -26 - 52:
    1386               i := 1;
     1382              I := 1;
    13871383            -25 - 52 .. -26:
    1388               i := 2;
     1384              I := 2;
    13891385            -25 .. 25:
    1390               i := 3;
     1386              I := 3;
    13911387            26 .. 25 + 52:
    1392               i := 4;
     1388              I := 4;
    13931389            26 + 52 .. 25 + 52 * 2:
    1394               i := 5;
     1390              I := 5;
    13951391            180 - 26 .. 180, -180 .. -180 + 26:
    1396               i := 0;
     1392              I := 0;
    13971393          else
    1398             i := -1;
     1394            I := -1;
    13991395          end;
    1400         if i >= 0 then
     1396        if I >= 0 then
    14011397        begin
    1402           ChangeResourceWeights(i);
     1398          ChangeResourceWeights(I);
    14031399          SmartUpdateContent;
    14041400          if WindowMode <> wmModal then
     
    14071403      end;
    14081404    end;
    1409 end; { FormMouseDown }
     1405end;
    14101406
    14111407procedure TCityDlg.ChooseProject;
     
    14221418  );
    14231419
    1424   function ProjectType(Project: integer): TProjectType;
     1420  function ProjectType(Project: Integer): TProjectType;
    14251421  begin
    14261422    if Project and cpCompleted <> 0 then
     
    14441440
    14451441var
    1446   NewProject, OldMoney, cix1: integer;
     1442  NewProject, OldMoney, cix1: Integer;
    14471443  pt0, pt1: TProjectType;
    1448   QueryOk: boolean;
    1449 begin
    1450   Assert(not supervising);
    1451   ModalSelectDlg.ShowNewContent_CityProject(wmModal, cix);
    1452   if ModalSelectDlg.result <> -1 then
    1453   begin
    1454     if ModalSelectDlg.result and cpType <> 0 then
     1444  QueryOk: Boolean;
     1445begin
     1446  Assert(not Supervising);
     1447  MainScreen.ModalSelectDlg.ShowNewContent_CityProject(wmModal, cix);
     1448  if MainScreen.ModalSelectDlg.Result <> -1 then
     1449  begin
     1450    if MainScreen.ModalSelectDlg.Result and cpType <> 0 then
    14551451    begin
    14561452      MyCity[cix].Status := MyCity[cix].Status and not 7 or
    1457         (1 + ModalSelectDlg.result and cpIndex);
    1458       AutoBuild(cix, MyData.ImpOrder[ModalSelectDlg.result and cpIndex]);
     1453        (1 + MainScreen.ModalSelectDlg.Result and cpIndex);
     1454      AutoBuild(cix, MyData.ImpOrder[MainScreen.ModalSelectDlg.Result and cpIndex]);
    14591455    end
    14601456    else
    14611457    begin
    1462       NewProject := ModalSelectDlg.Result;
     1458      NewProject := MainScreen.ModalSelectDlg.Result;
    14631459      QueryOk := True;
    14641460      if (NewProject and cpImp <> 0) and (NewProject and cpIndex >= 28) and
    14651461        (MyRO.NatBuilt[NewProject and cpIndex] > 0) then
    1466         with MessgExDlg do
     1462        with MainScreen.MessgExDlg do
    14671463        begin
    14681464          cix1 := MyRO.nCity - 1;
     
    15211517        then
    15221518          NewProject := NewProject or cpDisbandCity;
    1523       Server(sSetCityProject, me, cix, NewProject);
    1524       c.Project := MyCity[cix].Project;
     1519      Server(sSetCityProject, Me, cix, NewProject);
     1520      C.Project := MyCity[cix].Project;
    15251521      if MyRO.Money > OldMoney then
    15261522        Play('CITY_SELLIMP');
     
    15371533procedure TCityDlg.BuyClick(Sender: TObject);
    15381534var
    1539   NextProd, Cost: integer;
     1535  NextProd, Cost: Integer;
    15401536begin
    15411537  if (cix < 0) or (ClientMode >= scContact) then
    1542     exit;
    1543   with MyCity[cix], MessgExDlg do
     1538    Exit;
     1539  with MyCity[cix], MainScreen.MessgExDlg do
    15441540  begin
    15451541    Cost := Report.ProjectCost;
     
    15481544      NextProd := 0;
    15491545    Cost := Cost - Prod - NextProd;
    1550     if (MyRO.Wonder[woMich].EffectiveOwner = me) and (Project and cpImp <> 0)
     1546    if (MyRO.Wonder[woMich].EffectiveOwner = Me) and (Project and cpImp <> 0)
    15511547    then
    15521548      Cost := Cost * 2
     
    15721568    if (Kind = mkYesNo) and (ModalResult = mrOK) then
    15731569    begin
    1574       if Server(sBuyCityProject, me, cix, nil^) >= rExecuted then
     1570      if Server(sBuyCityProject, Me, cix, nil^) >= rExecuted then
    15751571      begin
    15761572        Play('CITY_BUYPROJECT');
     
    15851581procedure TCityDlg.FormClose(Sender: TObject; var Action: TCloseAction);
    15861582begin
    1587   Timer1.Enabled := false;
    1588   ProdHint := false;
     1583  Timer1.Enabled := False;
     1584  ProdHint := False;
    15891585  MarkCityLoc := -1;
    15901586  if Optimize_cixTileChange >= 0 then
     
    16151611      with Canvas do
    16161612      begin
    1617         DpiBitCanvas(Canvas, xView + 5, yView + 1, 64, 2, Back.Canvas,
     1613        DpiBitBltCanvas(Canvas, xView + 5, yView + 1, 64, 2, Back.Canvas,
    16181614          xView + 5, yView + 1);
    1619         DpiBitCanvas(Canvas, xView + 5, yView + 3, 2, 42, Back.Canvas,
     1615        DpiBitBltCanvas(Canvas, xView + 5, yView + 3, 2, 42, Back.Canvas,
    16201616          xView + 5, yView + 3);
    1621         DpiBitCanvas(Canvas, xView + 5 + 62, yView + 3, 2, 42,
     1617        DpiBitBltCanvas(Canvas, xView + 5 + 62, yView + 3, 2, 42,
    16221618          Back.Canvas, xView + 5 + 62, yView + 3);
    16231619        ScreenTools.Frame(Canvas, xView + 9 - 1, yView + 5 - 1, xView + 9 + xSizeBig,
     
    16321628    else if BlinkTime = 6 then
    16331629    begin
    1634       if AllowChange and (c.Status and 7 <> 0) then
     1630      if AllowChange and (C.Status and 7 <> 0) then
    16351631      begin // city type autobuild
    16361632        FrameImage(Canvas, bigimp, xView + 9, yView + 5, xSizeBig, ySizeBig,
    1637           (c.Status and 7 - 1 + 3) * xSizeBig, 0, true);
     1633          (C.Status and 7 - 1 + 3) * xSizeBig, 0, True);
    16381634      end
    1639       else if c.Project and cpImp = 0 then
     1635      else if C.Project and cpImp = 0 then
    16401636      begin // project is unit
    1641         DpiBitCanvas(Canvas, xView + 9, yView + 5, xSizeBig, ySizeBig,
     1637        DpiBitBltCanvas(Canvas, xView + 9, yView + 5, xSizeBig, ySizeBig,
    16421638          Bigimp.Canvas, 0, 0);
    1643         with Tribe[cOwner].ModelPicture[c.Project and cpIndex] do
     1639        with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do
    16441640          Sprite(Canvas, HGr, xView + 5, yView + 1, 64, 44, pix mod 10 * 65 + 1,
    16451641            pix div 10 * 49 + 1);
    16461642      end
    16471643      else
    1648         ImpImage(Canvas, xView + 9, yView + 5, c.Project0 and cpIndex,
    1649           cGov, true);
     1644        ImpImage(Canvas, xView + 9, yView + 5, C.Project0 and cpIndex,
     1645          cGov, True);
    16501646    end;
    16511647  end;
     
    16631659  if 1 shl OpenSoundEvent = chProduction then
    16641660  begin
    1665     if c.Project0 and cpImp <> 0 then
    1666     begin
    1667       if c.Project0 and cpIndex >= 28 then
     1661    if C.Project0 and cpImp <> 0 then
     1662    begin
     1663      if C.Project0 and cpIndex >= 28 then
    16681664      // wonders have already extra message with sound
    1669         if Imp[c.Project0 and cpIndex].Kind = ikShipPart then
     1665        if Imp[C.Project0 and cpIndex].Kind = ikShipPart then
    16701666          Play('SHIP_BUILT')
    16711667        else
     
    16811677end;
    16821678
    1683 function Prio(iix: integer): integer;
     1679function Prio(iix: Integer): Integer;
    16841680begin
    16851681  case Imp[iix].Kind of
    16861682    ikWonder:
    1687       result := iix + 10000;
     1683      Result := iix + 10000;
    16881684    ikNatLocal, ikNatGlobal:
    16891685      case iix of
    16901686        imPalace:
    1691           result := 0;
     1687          Result := 0;
    16921688      else
    1693         result := iix + 20000;
     1689        Result := iix + 20000;
    16941690      end;
    16951691  else
    16961692    case iix of
    16971693      imTownHall, imCourt:
    1698         result := iix + 30000;
     1694        Result := iix + 30000;
    16991695      imAqueduct, imSewer:
    1700         result := iix + 40000;
     1696        Result := iix + 40000;
    17011697      imTemple, imTheater, imCathedral:
    1702         result := iix + 50000;
    1703     else
    1704       result := iix + 90000;
     1698        Result := iix + 50000;
     1699    else
     1700      Result := iix + 90000;
    17051701    end;
    17061702  end;
     
    17171713end;
    17181714
    1719 procedure TCityDlg.ChangeCity(d: integer);
     1715procedure TCityDlg.ChangeCity(D: Integer);
    17201716var
    1721   cixNew: integer;
     1717  cixNew: Integer;
    17221718begin
    17231719  cixNew := cix;
    17241720  repeat
    1725     cixNew := (cixNew + MyRO.nCity + d) mod MyRO.nCity;
     1721    cixNew := (cixNew + MyRO.nCity + D) mod MyRO.nCity;
    17261722  until (MyCity[cixNew].Loc >= 0) or (cixNew = cix);
    17271723  if cixNew <> cix then
     
    17421738end;
    17431739
    1744 { procedure TCityDlg.AdviceBtnClick(Sender: TObject);
    1745   begin
    1746   AdvisorDlg.GiveCityAdvice(cix);
    1747   end; }
    1748 
    17491740procedure TCityDlg.PageUpBtnClick(Sender: TObject);
    17501741begin
    17511742  if Page > 0 then
    17521743  begin
    1753     dec(Page);
     1744    Dec(Page);
    17541745    SmartUpdateContent;
    17551746  end;
     
    17601751  if Page < PageCount - 1 then
    17611752  begin
    1762     inc(Page);
     1753    Inc(Page);
    17631754    SmartUpdateContent;
    17641755  end;
    17651756end;
    17661757
    1767 procedure TCityDlg.ChangeResourceWeights(iResourceWeights: integer);
     1758procedure TCityDlg.ChangeResourceWeights(iResourceWeights: Integer);
    17681759var
    17691760  Advice: TCityTileAdviceData;
    17701761begin
    1771   assert(not supervising);
    1772   assert(cix >= 0);
     1762  Assert(not Supervising);
     1763  Assert(cix >= 0);
    17731764  MyCity[cix].Status := MyCity[cix].Status and not csResourceWeightsMask or
    17741765    (iResourceWeights shl 4);
    1775   c.Status := MyCity[cix].Status;
     1766  C.Status := MyCity[cix].Status;
    17761767  if iResourceWeights > 0 then
    17771768  begin
    17781769    Advice.ResourceWeights := OfferedResourceWeights[iResourceWeights];
    1779     Server(sGetCityTileAdvice, me, cix, Advice);
     1770    Server(sGetCityTileAdvice, Me, cix, Advice);
    17801771    if Advice.Tiles <> MyCity[cix].Tiles then
    1781       Server(sSetCityTiles, me, cix, Advice.Tiles);
     1772      Server(sSetCityTiles, Me, cix, Advice.Tiles);
    17821773  end;
    17831774end;
     
    17851776procedure SortImprovements;
    17861777var
    1787   i, j, k: integer;
    1788 begin
    1789   for i := 0 to nImp - 1 do
    1790     ImpSorted[i] := i;
    1791   for i := 0 to nImp - 2 do
    1792     for j := i + 1 to nImp - 1 do
    1793       if Prio(ImpSorted[i]) > Prio(ImpSorted[j]) then begin
    1794         k := ImpSorted[i];
    1795         ImpSorted[i] := ImpSorted[j];
    1796         ImpSorted[j] := k;
     1778  I, J, K: Integer;
     1779begin
     1780  for I := 0 to nImp - 1 do
     1781    ImpSorted[I] := I;
     1782  for I := 0 to nImp - 2 do
     1783    for J := I + 1 to nImp - 1 do
     1784      if Prio(ImpSorted[I]) > Prio(ImpSorted[J]) then begin
     1785        K := ImpSorted[I];
     1786        ImpSorted[I] := ImpSorted[J];
     1787        ImpSorted[J] := K;
    17971788      end;
    17981789end;
  • branches/highdpi/LocalPlayer/CityType.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin, LCLIntf, LCLType,
    8   SysUtils, Classes, Graphics, Controls, Forms,
    9   ButtonB, ExtCtrls;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType,
     8  SysUtils, Classes, Graphics, Controls, Forms, ButtonB, ExtCtrls;
    109
    1110type
     
    1817    procedure FormShow(Sender: TObject);
    1918    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    20       Shift: TShiftState; x, y: integer);
     19      Shift: TShiftState; X, Y: Integer);
    2120    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    22       Shift: TShiftState; x, y: integer);
     21      Shift: TShiftState; X, Y: Integer);
    2322    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    2423    procedure DeleteBtnClick(Sender: TObject);
    2524  public
    26     procedure ShowNewContent(NewMode: integer);
     25    procedure ShowNewContent(NewMode: TWindowMode);
    2726  protected
    2827    procedure OffscreenPaint; override;
    2928  private
    30     nPool, dragiix, ctype: integer;
    31     Pooliix: array [0 .. nImp - 1] of integer;
     29    nPool, dragiix, ctype: Integer;
     30    Pooliix: array [0 .. nImp - 1] of Integer;
    3231    listed: Set of 0 .. nImp;
    33     Changed: boolean;
    34     procedure LoadType(NewType: integer);
     32    Changed: Boolean;
     33    procedure LoadType(NewType: Integer);
    3534    procedure SaveType;
    3635  end;
    3736
    38 var
    39   CityTypeDlg: TCityTypeDlg;
    4037
    4138implementation
    4239
    43 uses Help;
     40uses
     41  Help, Term;
    4442
    4543{$R *.lfm}
     
    8280procedure TCityTypeDlg.OffscreenPaint;
    8381var
    84   i, iix: integer;
    85   s: string;
     82  I, iix: Integer;
     83  S: string;
    8684begin
    8785  inherited;
    88   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     86  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    8987  FillOffscreen(xList - 7, yList, 42 * nListCol + 14, 32 * nListRow);
    9088  FillOffscreen(xPool - 7, yPool, 42 * nPoolCol + 14, 32 * nPoolRow);
     
    9290    yPool - yList - 32 * nListRow);
    9391
    94   Frame(offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,
     92  Frame(Offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,
    9593    yPool - 23, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    96   Frame(offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,
     94  Frame(Offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,
    9795    InnerWidth - 89, yPool - 23, MainTexture.ColorBevelLight,
    9896    MainTexture.ColorBevelShade);
    99   Frame(offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,
     97  Frame(Offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,
    10098    InnerWidth - 1, yPool - 23, MainTexture.ColorBevelLight,
    10199    MainTexture.ColorBevelShade);
    102   Frame(offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,
     100  Frame(Offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,
    103101    MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    104   for i := 0 to nCityType - 1 do
    105   begin
    106     RFrame(offscreen.Canvas, xSwitch + i * 42, ySwitch, xSwitch + 39 + i * 42,
     102  for I := 0 to nCityType - 1 do
     103  begin
     104    RFrame(Offscreen.Canvas, xSwitch + I * 42, ySwitch, xSwitch + 39 + I * 42,
    107105      ySwitch + 23, MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    108     if i = ctype then
    109       Frame(offscreen.Canvas, xSwitch + 1 + i * 42, ySwitch + 1,
    110         xSwitch + 38 + i * 42, ySwitch + 22, MainTexture.ColorBevelShade,
     106    if I = ctype then
     107      Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1,
     108        xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelShade,
    111109        MainTexture.ColorBevelLight)
    112110    else
    113       Frame(offscreen.Canvas, xSwitch + 1 + i * 42, ySwitch + 1,
    114         xSwitch + 38 + i * 42, ySwitch + 22, MainTexture.ColorBevelLight,
     111      Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1,
     112        xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelLight,
    115113        MainTexture.ColorBevelShade);
    116     DpiBitCanvas(offscreen.Canvas, xSwitch + 2 + i * 42, ySwitch + 2,
    117       xSizeSmall, ySizeSmall, SmallImp.Canvas, (i + 3) * xSizeSmall, 0);
    118   end;
    119   RisedTextOut(offscreen.Canvas, 8, yList + 32 * nListRow + 2,
     114    DpiBitBltCanvas(Offscreen.Canvas, xSwitch + 2 + I * 42, ySwitch + 2,
     115      xSizeSmall, ySizeSmall, SmallImp.Canvas, (I + 3) * xSizeSmall, 0);
     116  end;
     117  RisedTextOut(Offscreen.Canvas, 8, yList + 32 * nListRow + 2,
    120118    Phrases.Lookup('BUILDORDER'));
    121   RisedTextOut(offscreen.Canvas, 8, ySwitch + 26,
     119  RisedTextOut(Offscreen.Canvas, 8, ySwitch + 26,
    122120    Phrases.Lookup('CITYTYPE', ctype));
    123   s := Phrases.Lookup('BUILDREST');
    124   RisedTextOut(offscreen.Canvas,
    125     (InnerWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2,
    126     yList + 72 + 32 * nListRow, s);
    127 
    128   with offscreen.Canvas do
    129   begin
    130     for i := 1 to nListRow - 1 do
    131       DLine(offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol,
    132         yList - 1 + 32 * i, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    133     for i := 0 to nListCol * nListRow - 1 do
    134     begin
    135       s := IntToStr(i + 1);
     121  S := Phrases.Lookup('BUILDREST');
     122  RisedTextOut(Offscreen.Canvas,
     123    (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2,
     124    yList + 72 + 32 * nListRow, S);
     125
     126  with Offscreen.Canvas do
     127  begin
     128    for I := 1 to nListRow - 1 do
     129      DLine(Offscreen.Canvas, xList - 5, xList + 4 + 42 * nListCol,
     130        yList - 1 + 32 * I, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
     131    for I := 0 to nListCol * nListRow - 1 do
     132    begin
     133      S := IntToStr(I + 1);
    136134      Font.Color := MainTexture.ColorTextLight;
    137       Textout(xList + 20 + i mod nListCol * 42 - TextWidth(s) div 2,
    138         yList + 15 + i div nListCol * 32 - TextHeight(s) div 2, s);
    139     end;
    140   end;
    141 
    142   i := 0;
    143   while MyData.ImpOrder[ctype, i] >= 0 do
    144   begin
    145     RFrame(offscreen.Canvas, xList + 20 - xSizeSmall div 2 + i mod nListCol *
    146       42, yList + 15 - ySizeSmall div 2 + i div nListCol * 32,
    147       xList + 21 + xSizeSmall div 2 + i mod nListCol * 42,
    148       yList + 16 + ySizeSmall div 2 + i div nListCol * 32,
     135      Textout(xList + 20 + I mod nListCol * 42 - TextWidth(S) div 2,
     136        yList + 15 + I div nListCol * 32 - TextHeight(S) div 2, S);
     137    end;
     138  end;
     139
     140  I := 0;
     141  while MyData.ImpOrder[ctype, I] >= 0 do
     142  begin
     143    RFrame(Offscreen.Canvas, xList + 20 - xSizeSmall div 2 + I mod nListCol *
     144      42, yList + 15 - ySizeSmall div 2 + I div nListCol * 32,
     145      xList + 21 + xSizeSmall div 2 + I mod nListCol * 42,
     146      yList + 16 + ySizeSmall div 2 + I div nListCol * 32,
    149147      MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    150     DpiBitCanvas(offscreen.Canvas, xList + 21 - xSizeSmall div 2 +
    151       i mod nListCol * 42, yList + 16 - ySizeSmall div 2 + i div nListCol * 32,
     148    DpiBitBltCanvas(Offscreen.Canvas, xList + 21 - xSizeSmall div 2 +
     149      I mod nListCol * 42, yList + 16 - ySizeSmall div 2 + I div nListCol * 32,
    152150      xSizeSmall, ySizeSmall, SmallImp.Canvas,
    153       MyData.ImpOrder[ctype, i] mod 7 * xSizeSmall,
    154       (MyData.ImpOrder[ctype, i] + SystemIconLines * 7) div 7 *
     151      MyData.ImpOrder[ctype, I] mod 7 * xSizeSmall,
     152      (MyData.ImpOrder[ctype, I] + SystemIconLines * 7) div 7 *
    155153      ySizeSmall);
    156     inc(i);
     154    Inc(I);
    157155  end;
    158156
     
    165163    begin
    166164      Pooliix[nPool] := iix;
    167       RFrame(offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +
     165      RFrame(Offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +
    168166        nPool mod nPoolCol * 42, yPool + 15 - ySizeSmall div 2 +
    169167        nPool div nPoolCol * 32, xPool + 21 + xSizeSmall div 2 +
     
    171169        nPool div nPoolCol * 32, MainTexture.ColorBevelLight,
    172170        MainTexture.ColorBevelShade);
    173       DpiBitCanvas(offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +
     171      DpiBitBltCanvas(Offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +
    174172        nPool mod nPoolCol * 42, yPool + 16 - ySizeSmall div 2 +
    175173        nPool div nPoolCol * 32, xSizeSmall, ySizeSmall, SmallImp.Canvas,
    176174        iix mod 7 * xSizeSmall, (iix + SystemIconLines * 7) div 7 *
    177175        ySizeSmall);
    178       inc(nPool);
     176      Inc(nPool);
    179177    end;
    180178  DeleteBtn.Visible := MyData.ImpOrder[ctype, 0] >= 0;
     
    182180  if dragiix >= 0 then
    183181  begin
    184     ImpImage(offscreen.Canvas, xView + 9, yView + 5, dragiix);
    185     s := Phrases.Lookup('IMPROVEMENTS', dragiix);
    186     RisedTextOut(offscreen.Canvas,
    187       xView + 36 - BiColorTextWidth(offscreen.Canvas, s) div 2,
    188       ySwitch + 26, s);
     182    ImpImage(Offscreen.Canvas, xView + 9, yView + 5, dragiix);
     183    S := Phrases.Lookup('IMPROVEMENTS', dragiix);
     184    RisedTextOut(Offscreen.Canvas,
     185      xView + 36 - BiColorTextWidth(Offscreen.Canvas, S) div 2,
     186      ySwitch + 26, S);
    189187  end;
    190188  MarkUsedOffscreen(InnerWidth, InnerHeight);
    191 end; { MainPaint }
    192 
    193 procedure TCityTypeDlg.LoadType(NewType: integer);
    194 var
    195   i: integer;
     189end;
     190
     191procedure TCityTypeDlg.LoadType(NewType: Integer);
     192var
     193  I: Integer;
    196194begin
    197195  ctype := NewType;
    198196  listed := [];
    199   i := 0;
    200   while MyData.ImpOrder[ctype, i] >= 0 do
    201   begin
    202     include(listed, MyData.ImpOrder[ctype, i]);
    203     inc(i);
    204   end;
    205   Changed := false;
     197  I := 0;
     198  while MyData.ImpOrder[ctype, I] >= 0 do
     199  begin
     200    Include(listed, MyData.ImpOrder[ctype, I]);
     201    Inc(I);
     202  end;
     203  Changed := False;
    206204end;
    207205
    208206procedure TCityTypeDlg.SaveType;
    209207var
    210   cix: integer;
     208  cix: Integer;
    211209begin
    212210  if Changed then
     
    215213      if (MyCity[cix].Loc >= 0) and (MyCity[cix].Status and 7 = ctype + 1) then
    216214        AutoBuild(cix, MyData.ImpOrder[ctype]);
    217     Changed := false;
     215    Changed := False;
    218216  end;
    219217end;
     
    226224end;
    227225
    228 procedure TCityTypeDlg.ShowNewContent(NewMode: integer);
     226procedure TCityTypeDlg.ShowNewContent(NewMode: TWindowMode);
    229227begin
    230228  inherited ShowNewContent(NewMode);
     
    232230
    233231procedure TCityTypeDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    234   Shift: TShiftState; x, y: integer);
    235 var
    236   i: integer;
    237 begin
    238   x := x - SideFrame;
    239   y := y - WideFrame;
    240   i := (x - xList) div 42 + (y - yList) div 32 * nListCol;
    241   if (i < nImp) and (MyData.ImpOrder[ctype, i] >= 0) and
    242     (x > xList + 2 + i mod nListCol * 42) and
    243     (y > yList + 5 + i div nListCol * 32) and
    244     (x < xList + 3 + 36 + i mod nListCol * 42) and
    245     (y < yList + 6 + 20 + i div nListCol * 32) then
     232  Shift: TShiftState; X, Y: Integer);
     233var
     234  I: Integer;
     235begin
     236  X := X - SideFrame;
     237  Y := Y - WideFrame;
     238  I := (X - xList) div 42 + (Y - yList) div 32 * nListCol;
     239  if (I < nImp) and (MyData.ImpOrder[ctype, I] >= 0) and
     240    (X > xList + 2 + I mod nListCol * 42) and
     241    (Y > yList + 5 + I div nListCol * 32) and
     242    (X < xList + 3 + 36 + I mod nListCol * 42) and
     243    (Y < yList + 6 + 20 + I div nListCol * 32) then
    246244  begin
    247245    if ssShift in Shift then
    248       HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp,
    249         MyData.ImpOrder[ctype, i])
     246      MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp,
     247        MyData.ImpOrder[ctype, I])
    250248    else
    251249    begin
    252       dragiix := MyData.ImpOrder[ctype, i];
     250      dragiix := MyData.ImpOrder[ctype, I];
    253251      DpiScreen.Cursor := crImpDrag;
    254252      SmartUpdateContent;
    255253    end;
    256     exit;
    257   end;
    258   i := (x - xPool) div 42 + (y - yPool) div 32 * nPoolCol;
    259   if (i < nPool) and (x > xPool + 2 + i mod nPoolCol * 42) and
    260     (y > yPool + 5 + i div nPoolCol * 32) and
    261     (x < xPool + 3 + 36 + i mod nPoolCol * 42) and
    262     (y < yPool + 6 + 20 + i div nPoolCol * 32) then
     254    Exit;
     255  end;
     256  I := (X - xPool) div 42 + (Y - yPool) div 32 * nPoolCol;
     257  if (I < nPool) and (X > xPool + 2 + I mod nPoolCol * 42) and
     258    (Y > yPool + 5 + I div nPoolCol * 32) and
     259    (X < xPool + 3 + 36 + I mod nPoolCol * 42) and
     260    (Y < yPool + 6 + 20 + I div nPoolCol * 32) then
    263261  begin
    264262    if ssShift in Shift then
    265       HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkImp, Pooliix[i])
     263      MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[I])
    266264    else
    267265    begin
    268       dragiix := Pooliix[i];
     266      dragiix := Pooliix[I];
    269267      DpiScreen.Cursor := crImpDrag;
    270268      SmartUpdateContent;
    271269    end;
    272     exit;
    273   end;
    274   i := (x - xSwitch) div 42;
    275   if (i < nCityType) and (x > xSwitch + 2 + i * 42) and
    276     (x < xSwitch + 3 + 36 + i * 42) and (y >= ySwitch + 2) and (y < ySwitch + 22)
     270    Exit;
     271  end;
     272  I := (X - xSwitch) div 42;
     273  if (I < nCityType) and (X > xSwitch + 2 + I * 42) and
     274    (X < xSwitch + 3 + 36 + I * 42) and (Y >= ySwitch + 2) and (Y < ySwitch + 22)
    277275  then
    278276  begin
    279277    SaveType;
    280     LoadType(i);
     278    LoadType(I);
    281279    SmartUpdateContent;
    282280  end;
     
    284282
    285283procedure TCityTypeDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    286   Shift: TShiftState; x, y: integer);
    287 
    288   procedure UnList(iix: integer);
     284  Shift: TShiftState; X, Y: Integer);
     285
     286  procedure UnList(iix: Integer);
    289287  var
    290     i: integer;
    291   begin
    292     i := 0;
    293     while (MyData.ImpOrder[ctype, i] >= 0) and
    294       (MyData.ImpOrder[ctype, i] <> iix) do
    295       inc(i);
    296     assert(MyData.ImpOrder[ctype, i] = iix);
    297     move(MyData.ImpOrder[ctype, i + 1], MyData.ImpOrder[ctype, i], nImp - i);
     288    I: Integer;
     289  begin
     290    I := 0;
     291    while (MyData.ImpOrder[ctype, I] >= 0) and
     292      (MyData.ImpOrder[ctype, I] <> iix) do
     293      Inc(I);
     294    Assert(MyData.ImpOrder[ctype, I] = iix);
     295    Move(MyData.ImpOrder[ctype, I + 1], MyData.ImpOrder[ctype, I], nImp - I);
    298296    Exclude(listed, iix);
    299297  end;
    300298
    301299var
    302   i: integer;
    303 begin
    304   x := x - SideFrame;
    305   y := y - WideFrame;
     300  I: Integer;
     301begin
     302  X := X - SideFrame;
     303  Y := Y - WideFrame;
    306304  if dragiix >= 0 then
    307305  begin
    308     if (x >= xList) and (x < xList + nListCol * 42) and (y >= yList) and
    309       (y < yList + nListRow * 32) then
     306    if (X >= xList) and (X < xList + nListCol * 42) and (Y >= yList) and
     307      (Y < yList + nListRow * 32) then
    310308    begin
    311309      if dragiix in listed then
    312310        UnList(dragiix);
    313       i := (x - xList) div 42 + (y - yList) div 32 * nListCol;
    314       while (i > 0) and (MyData.ImpOrder[ctype, i - 1] < 0) do
    315         dec(i);
    316       move(MyData.ImpOrder[ctype, i], MyData.ImpOrder[ctype, i + 1],
    317         nImp - i - 1);
    318       MyData.ImpOrder[ctype, i] := dragiix;
    319       include(listed, dragiix);
    320       Changed := true;
     311      I := (X - xList) div 42 + (Y - yList) div 32 * nListCol;
     312      while (I > 0) and (MyData.ImpOrder[ctype, I - 1] < 0) do
     313        Dec(I);
     314      Move(MyData.ImpOrder[ctype, I], MyData.ImpOrder[ctype, I + 1],
     315        nImp - I - 1);
     316      MyData.ImpOrder[ctype, I] := dragiix;
     317      Include(listed, dragiix);
     318      Changed := True;
    321319    end
    322     else if (dragiix in listed) and (x >= xPool) and (x < xPool + nPoolCol * 42)
    323       and (y >= yPool) and (y < yPool + nPoolRow * 32) then
     320    else if (dragiix in listed) and (X >= xPool) and (X < xPool + nPoolCol * 42)
     321      and (Y >= yPool) and (Y < yPool + nPoolRow * 32) then
    324322    begin
    325323      UnList(dragiix);
    326       Changed := true;
     324      Changed := True;
    327325    end;
    328326    dragiix := -1;
     
    340338procedure TCityTypeDlg.DeleteBtnClick(Sender: TObject);
    341339begin
    342   fillchar(MyData.ImpOrder[ctype], sizeof(MyData.ImpOrder[ctype]), Byte(-1));
     340  FillChar(MyData.ImpOrder[ctype], SizeOf(MyData.ImpOrder[ctype]), Byte(-1));
    343341  listed := [];
    344   Changed := true;
     342  Changed := True;
    345343  SmartUpdateContent;
    346344end;
  • branches/highdpi/LocalPlayer/ClientTools.pas

    r405 r465  
    99const
    1010  nOfferedResourceWeights = 6;
    11   OfferedResourceWeights: array [0 .. nOfferedResourceWeights - 1] of cardinal =
     11  OfferedResourceWeights: array [0 .. nOfferedResourceWeights - 1] of Cardinal =
    1212    (rwOff, rwMaxScience, rwForceScience, rwMaxGrowth, rwForceProd, rwMaxProd);
    1313
    1414type
    15   TImpOrder = array [0 .. (nImp + 4) div 4 * 4 - 1] of shortint;
    16   TEnhancementJobs = array [0 .. 11, 0 .. 7] of byte;
     15  TImpOrder = array [0 .. (nImp + 4) div 4 * 4 - 1] of ShortInt;
     16  TEnhancementJobs = array [0 .. 11, 0 .. 7] of Byte;
    1717  JobResultSet = set of 0 .. 39;
    1818
     
    3636  Server: TServerCall;
    3737  G: TNewGameData;
    38   me: integer;
     38  Me: Integer;
    3939  MyRO: ^TPlayerContext;
    4040  MyMap: ^TTileList;
     
    4343  MyModel: ^TModelList;
    4444
    45   AdvValue: array [0 .. nAdv - 1] of integer;
    46 
    47 function dLoc(Loc, dx, dy: integer): integer;
    48 function Distance(Loc0, Loc1: integer): integer;
    49 function UnrestAtLoc(uix, Loc: integer): boolean;
    50 function GetMoveAdvice(uix, ToLoc: integer;
    51   var MoveAdviceData: TMoveAdviceData): integer;
    52 function ColorOfHealth(Health: integer): integer;
    53 function IsMultiPlayerGame: boolean;
    54 procedure ItsMeAgain(p: integer);
    55 function GetAge(p: integer): integer;
    56 function IsCivilReportNew(Enemy: integer): boolean;
    57 function IsMilReportNew(Enemy: integer): boolean;
    58 function CutCityFoodSurplus(FoodSurplus: integer; IsCityAlive: boolean;
    59   gov, size: integer): integer;
    60 function CityTaxBalance(cix: integer; const CityReport: TCityReportNew): integer;
    61 procedure SumCities(var TaxSum, ScienceSum: integer);
    62 function JobTest(uix, Job: integer; IgnoreResults: JobResultSet = []): boolean;
    63 procedure GetUnitInfo(Loc: integer; var uix: integer; var UnitInfo: TUnitInfo);
    64 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);
    65 function UnitExhausted(uix: integer): boolean;
    66 function ModelHash(const ModelInfo: TModelInfo): integer;
    67 function ProcessEnhancement(uix: integer; const Jobs: TEnhancementJobs): integer;
    68 function AutoBuild(cix: integer; const ImpOrder: TImpOrder): boolean;
    69 procedure DebugMessage(Level: integer; Text: string);
     45  AdvValue: array [0 .. nAdv - 1] of Integer;
     46
     47function dLoc(Loc, dx, dy: Integer): Integer;
     48function Distance(Loc0, Loc1: Integer): Integer;
     49function UnrestAtLoc(uix, Loc: Integer): Boolean;
     50function GetMoveAdvice(uix, ToLoc: Integer;
     51  var MoveAdviceData: TMoveAdviceData): Integer;
     52function ColorOfHealth(Health: Integer): Integer;
     53function IsMultiPlayerGame: Boolean;
     54procedure ItsMeAgain(P: Integer);
     55function GetAge(P: Integer): Integer;
     56function IsCivilReportNew(Enemy: Integer): Boolean;
     57function IsMilReportNew(Enemy: Integer): Boolean;
     58function CutCityFoodSurplus(FoodSurplus: Integer; IsCityAlive: Boolean;
     59  gov, size: Integer): Integer;
     60function CityTaxBalance(cix: Integer; const CityReport: TCityReportNew): Integer;
     61procedure SumCities(var TaxSum, ScienceSum: Integer);
     62function JobTest(uix, Job: Integer; IgnoreResults: JobResultSet = []): Boolean;
     63procedure GetUnitInfo(Loc: Integer; var uix: Integer; var UnitInfo: TUnitInfo);
     64procedure GetCityInfo(Loc: Integer; var cix: Integer; var CityInfo: TCityInfo);
     65function UnitExhausted(uix: Integer): Boolean;
     66function ModelHash(const ModelInfo: TModelInfo): Integer;
     67function ProcessEnhancement(uix: Integer; const Jobs: TEnhancementJobs): Integer;
     68function AutoBuild(cix: Integer; const ImpOrder: TImpOrder): Boolean;
     69procedure DebugMessage(Level: Integer; Text: string);
    7070procedure CityOptimizer_BeginOfTurn;
    71 procedure CityOptimizer_CityChange(cix: integer);
    72 procedure CityOptimizer_TileBecomesAvailable(Loc: integer);
    73 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: integer);
    74 procedure CityOptimizer_BeforeRemoveUnit(uix: integer);
     71procedure CityOptimizer_CityChange(cix: Integer);
     72procedure CityOptimizer_TileBecomesAvailable(Loc: Integer);
     73procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: Integer);
     74procedure CityOptimizer_BeforeRemoveUnit(uix: Integer);
    7575procedure CityOptimizer_AfterRemoveUnit;
    7676procedure CityOptimizer_EndOfTurn;
     
    8484
    8585var
    86   CityNeedsOptimize: array [0 .. ncmax - 1] of boolean;
    87 
    88 function dLoc(Loc, dx, dy: integer): integer;
    89 var
    90   y0: integer;
     86  CityNeedsOptimize: array [0 .. ncmax - 1] of Boolean;
     87
     88function dLoc(Loc, dx, dy: Integer): Integer;
     89var
     90  y0: Integer;
    9191begin
    9292  y0 := (Loc + G.lx * 1024) div G.lx - 1024;
     
    9494end;
    9595
    96 function Distance(Loc0, Loc1: integer): integer;
    97 var
    98   dx, dy: integer;
     96function Distance(Loc0, Loc1: Integer): Integer;
     97var
     98  dx, dy: Integer;
    9999begin
    100100  Inc(Loc0, G.lx * 1024);
     
    106106end;
    107107
    108 function UnrestAtLoc(uix, Loc: integer): boolean;
    109 var
    110   uix1: integer;
     108function UnrestAtLoc(uix, Loc: Integer): Boolean;
     109var
     110  uix1: Integer;
    111111begin
    112112  Result := False;
     
    114114    case MyRO.Government of
    115115      gRepublic, gFuture:
    116         Result := (MyRO.Territory[Loc] >= 0) and (MyRO.Territory[Loc] <> me) and
     116        Result := (MyRO.Territory[Loc] >= 0) and (MyRO.Territory[Loc] <> Me) and
    117117          (MyRO.Treaty[MyRO.Territory[Loc]] < trAlliance);
    118118      gDemocracy:
    119         Result := (MyRO.Territory[Loc] < 0) or (MyRO.Territory[Loc] <> me) and
     119        Result := (MyRO.Territory[Loc] < 0) or (MyRO.Territory[Loc] <> Me) and
    120120          (MyRO.Treaty[MyRO.Territory[Loc]] < trAlliance);
    121121    end;
     
    127127end;
    128128
    129 function GetMoveAdvice(uix, ToLoc: integer;
    130   var MoveAdviceData: TMoveAdviceData): integer;
    131 var
    132   MinEndHealth: integer;
     129function GetMoveAdvice(uix, ToLoc: Integer;
     130  var MoveAdviceData: TMoveAdviceData): Integer;
     131var
     132  MinEndHealth: Integer;
    133133begin
    134134  if MyModel[MyUn[uix].mix].Domain = dGround then
     
    142142      MoveAdviceData.MoreTurns := 999;
    143143      MoveAdviceData.MaxHostile_MovementLeft := MyUn[uix].Health - MinEndHealth;
    144       Result := Server(sGetMoveAdvice, me, uix, MoveAdviceData);
     144      Result := Server(sGetMoveAdvice, Me, uix, MoveAdviceData);
    145145      if (MinEndHealth <= 1) or (Result <> eNoWay) then
    146         exit;
     146        Exit;
    147147    end;
    148148    case MinEndHealth of
     
    159159end;
    160160
    161 function ColorOfHealth(Health: integer): integer;
    162 var
    163   red, green: integer;
    164 begin
    165   green := 400 * Health div 100;
    166   if green > 200 then
    167     green := 200;
    168   red := 510 * (100 - Health) div 100;
    169   if red > 255 then
    170     red := 255;
    171   Result := green shl 8 + red;
    172 end;
    173 
    174 function IsMultiPlayerGame: boolean;
    175 var
    176   p1: integer;
     161function ColorOfHealth(Health: Integer): Integer;
     162var
     163  Red, Green: Integer;
     164begin
     165  Green := 400 * Health div 100;
     166  if Green > 200 then
     167    Green := 200;
     168  Red := 510 * (100 - Health) div 100;
     169  if Red > 255 then
     170    Red := 255;
     171  Result := Green shl 8 + Red;
     172end;
     173
     174function IsMultiPlayerGame: Boolean;
     175var
     176  p1: Integer;
    177177begin
    178178  Result := False;
     
    182182end;
    183183
    184 procedure ItsMeAgain(p: integer);
    185 begin
    186   if G.RO[p] <> nil then
    187     MyRO := pointer(G.RO[p])
    188   else if G.SuperVisorRO[p] <> nil then
    189     MyRO := pointer(G.SuperVisorRO[p])
     184procedure ItsMeAgain(P: Integer);
     185begin
     186  if G.RO[P] <> nil then
     187    MyRO := Pointer(G.RO[P])
     188  else if G.SuperVisorRO[P] <> nil then
     189    MyRO := Pointer(G.SuperVisorRO[P])
    190190  else
    191     exit;
    192   me := p;
    193   MyMap := pointer(MyRO.Map);
    194   MyUn := pointer(MyRO.Un);
    195   MyCity := pointer(MyRO.City);
    196   MyModel := pointer(MyRO.Model);
    197 end;
    198 
    199 function GetAge(p: integer): integer;
    200 var
    201   i: integer;
    202 begin
    203   if p = me then begin
     191    Exit;
     192  Me := P;
     193  MyMap := Pointer(MyRO.Map);
     194  MyUn := Pointer(MyRO.Un);
     195  MyCity := Pointer(MyRO.City);
     196  MyModel := Pointer(MyRO.Model);
     197end;
     198
     199function GetAge(P: Integer): Integer;
     200var
     201  I: Integer;
     202begin
     203  if P = Me then begin
    204204    Result := 0;
    205     for i := 1 to 3 do
    206       if MyRO.Tech[AgePreq[i]] >= tsApplicable then
    207         Result := i;
     205    for I := 1 to 3 do
     206      if MyRO.Tech[AgePreq[I]] >= tsApplicable then
     207        Result := I;
    208208  end else begin
    209209    Result := 0;
    210     for i := 1 to 3 do
    211       if MyRO.EnemyReport[p].Tech[AgePreq[i]] >= tsApplicable then
    212         Result := i;
    213   end;
    214 end;
    215 
    216 function IsCivilReportNew(Enemy: integer): boolean;
    217 var
    218   i: integer;
    219 begin
    220   assert(Enemy <> me);
    221   i := MyRO.EnemyReport[Enemy].TurnOfCivilReport;
    222   Result := (i = MyRO.Turn) or (i = MyRO.Turn - 1) and (Enemy > me);
    223 end;
    224 
    225 function IsMilReportNew(Enemy: integer): boolean;
    226 var
    227   i: integer;
    228 begin
    229   assert(Enemy <> me);
    230   i := MyRO.EnemyReport[Enemy].TurnOfMilReport;
    231   Result := (i = MyRO.Turn) or (i = MyRO.Turn - 1) and (Enemy > me);
    232 end;
    233 
    234 function CutCityFoodSurplus(FoodSurplus: integer; IsCityAlive: boolean;
    235   gov, size: integer): integer;
     210    for I := 1 to 3 do
     211      if MyRO.EnemyReport[P].Tech[AgePreq[I]] >= tsApplicable then
     212        Result := I;
     213  end;
     214end;
     215
     216function IsCivilReportNew(Enemy: Integer): Boolean;
     217var
     218  I: Integer;
     219begin
     220  Assert(Enemy <> Me);
     221  I := MyRO.EnemyReport[Enemy].TurnOfCivilReport;
     222  Result := (I = MyRO.Turn) or (I = MyRO.Turn - 1) and (Enemy > Me);
     223end;
     224
     225function IsMilReportNew(Enemy: Integer): Boolean;
     226var
     227  I: Integer;
     228begin
     229  Assert(Enemy <> Me);
     230  I := MyRO.EnemyReport[Enemy].TurnOfMilReport;
     231  Result := (I = MyRO.Turn) or (I = MyRO.Turn - 1) and (Enemy > Me);
     232end;
     233
     234function CutCityFoodSurplus(FoodSurplus: Integer; IsCityAlive: Boolean;
     235  gov, size: Integer): Integer;
    236236begin
    237237  Result := FoodSurplus;
     
    241241end;
    242242
    243 function CityTaxBalance(cix: integer; const CityReport: TCityReportNew): integer;
    244 var
    245   i: integer;
     243function CityTaxBalance(cix: Integer; const CityReport: TCityReportNew): Integer;
     244var
     245  I: Integer;
    246246begin
    247247  Result := 0;
     
    258258      Inc(Result, CityReport.FoodSurplus);
    259259  end;
    260   for i := nWonder to nImp - 1 do
    261     if MyCity[cix].Built[i] > 0 then
    262       Dec(Result, Imp[i].Maint);
    263 end;
    264 
    265 procedure SumCities(var TaxSum, ScienceSum: integer);
    266 var
    267   cix: integer;
     260  for I := nWonder to nImp - 1 do
     261    if MyCity[cix].Built[I] > 0 then
     262      Dec(Result, Imp[I].Maint);
     263end;
     264
     265procedure SumCities(var TaxSum, ScienceSum: Integer);
     266var
     267  cix: Integer;
    268268  CityReport: TCityReportNew;
    269269begin
     
    271271  ScienceSum := 0;
    272272  if MyRO.Government = gAnarchy then
    273     exit;
     273    Exit;
    274274  for cix := 0 to MyRO.nCity - 1 do
    275275    if MyCity[cix].Loc >= 0 then
     
    278278      CityReport.HypoTaxRate := -1;
    279279      CityReport.HypoLuxuryRate := -1;
    280       Server(sGetCityReportNew, me, cix, CityReport);
     280      Server(sGetCityReportNew, Me, cix, CityReport);
    281281      if (CityReport.HappinessBalance >= 0) { no disorder } and
    282282        (MyCity[cix].Flags and chCaptured = 0) then // not captured
     
    286286end;
    287287
    288 function JobTest(uix, Job: integer; IgnoreResults: JobResultSet): boolean;
    289 var
    290   Test: integer;
    291 begin
    292   Test := Server(sStartJob + Job shl 4 - sExecute, me, uix, nil^);
     288function JobTest(uix, Job: Integer; IgnoreResults: JobResultSet): Boolean;
     289var
     290  Test: Integer;
     291begin
     292  Test := Server(sStartJob + Job shl 4 - sExecute, Me, uix, nil^);
    293293  Result := (Test >= rExecuted) or (Test in IgnoreResults);
    294294end;
    295295
    296 procedure GetUnitInfo(Loc: integer; var uix: integer; var UnitInfo: TUnitInfo);
    297 var
    298   i, Cnt: integer;
     296procedure GetUnitInfo(Loc: Integer; var uix: Integer; var UnitInfo: TUnitInfo);
     297var
     298  I, Cnt: Integer;
    299299begin
    300300  if MyMap[Loc] and fOwned <> 0 then
    301301  begin
    302     Server(sGetDefender, me, Loc, uix);
     302    Server(sGetDefender, Me, Loc, uix);
    303303    Cnt := 0;
    304     for i := 0 to MyRO.nUn - 1 do
    305       if MyUn[i].Loc = Loc then
     304    for I := 0 to MyRO.nUn - 1 do
     305      if MyUn[I].Loc = Loc then
    306306        Inc(Cnt);
    307     MakeUnitInfo(me, MyUn[uix], UnitInfo);
     307    MakeUnitInfo(Me, MyUn[uix], UnitInfo);
    308308    if Cnt > 1 then
    309309      UnitInfo.Flags := UnitInfo.Flags or unMulti;
     
    316316    UnitInfo := MyRO.EnemyUn[uix];
    317317  end;
    318 end; { GetUnitInfo }
    319 
    320 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);
     318end;
     319
     320procedure GetCityInfo(Loc: Integer; var cix: Integer; var CityInfo: TCityInfo);
    321321begin
    322322  if MyMap[Loc] and fOwned <> 0 then
     
    328328    with CityInfo do
    329329    begin
    330       Owner := me;
     330      Owner := Me;
    331331      ID := MyCity[cix].ID;
    332332      size := MyCity[cix].size;
     
    356356end;
    357357
    358 function UnitExhausted(uix: integer): boolean;
     358function UnitExhausted(uix: Integer): Boolean;
    359359  // check if another move of this unit is still possible
    360360var
    361   dx, dy: integer;
     361  dx, dy: Integer;
    362362begin
    363363  Result := True;
    364364  if (MyUn[uix].Movement > 0) or
    365     (MyRO.Wonder[woShinkansen].EffectiveOwner = me) then
     365    (MyRO.Wonder[woShinkansen].EffectiveOwner = Me) then
    366366    if (MyUn[uix].Movement >= 100) or
    367367      ((MyModel[MyUn[uix].mix].Kind = mkCaravan) and
     
    373373          if abs(dx) + abs(dy) = 2 then
    374374            if Server(sMoveUnit - sExecute + dx and 7 shl 4 + dy and
    375               7 shl 7, me, uix, nil^) >= rExecuted then
     375              7 shl 7, Me, uix, nil^) >= rExecuted then
    376376              Result := False;
    377377end;
    378378
    379 function ModelHash(const ModelInfo: TModelInfo): integer;
    380 var
    381   i, FeatureCode, Hash1, Hash2, Hash2r, d: cardinal;
     379function ModelHash(const ModelInfo: TModelInfo): Integer;
     380var
     381  I, FeatureCode, Hash1, Hash2, Hash2r, D: Cardinal;
    382382begin
    383383  with ModelInfo do
    384384    if Kind > mkEnemyDeveloped then
    385       Result := integer($C0000000 + Speed div 50 + Kind shl 8)
     385      Result := Integer($C0000000 + Speed div 50 + Kind shl 8)
    386386    else
    387387    begin
    388388      FeatureCode := 0;
    389       for i := mcFirstNonCap to nFeature - 1 do
    390         if 1 shl Domain and Feature[i].Domains <> 0 then
     389      for I := mcFirstNonCap to nFeature - 1 do
     390        if 1 shl Domain and Feature[I].Domains <> 0 then
    391391        begin
    392392          FeatureCode := FeatureCode * 2;
    393           if 1 shl (i - mcFirstNonCap) <> 0 then
     393          if 1 shl (I - mcFirstNonCap) <> 0 then
    394394            Inc(FeatureCode);
    395395        end;
     
    397397        dGround:
    398398        begin
    399           assert(FeatureCode < 1 shl 8);
    400           assert(Attack < 5113);
    401           assert(Defense < 2273);
    402           assert(Cost < 1611);
     399          Assert(FeatureCode < 1 shl 8);
     400          Assert(Attack < 5113);
     401          Assert(Defense < 2273);
     402          Assert(Cost < 1611);
    403403          Hash1 := (Attack * 2273 + Defense) * 9 + (Speed - 150) div 50;
    404404          Hash2 := FeatureCode * 1611 + Cost;
     
    406406        dSea:
    407407        begin
    408           assert(FeatureCode < 1 shl 9);
    409           assert(Attack < 12193);
    410           assert(Defense < 6097);
    411           assert(Cost < 4381);
     408          Assert(FeatureCode < 1 shl 9);
     409          Assert(Attack < 12193);
     410          Assert(Defense < 6097);
     411          Assert(Cost < 4381);
    412412          Hash1 := ((Attack * 6097 + Defense) * 5 +
    413413            (Speed - 350) div 100) * 2;
     
    419419        dAir:
    420420        begin
    421           assert(FeatureCode < 1 shl 5);
    422           assert(Attack < 2407);
    423           assert(Defense < 1605);
    424           assert(Bombs < 4813);
    425           assert(Cost < 2089);
     421          Assert(FeatureCode < 1 shl 5);
     422          Assert(Attack < 2407);
     423          Assert(Defense < 1605);
     424          Assert(Bombs < 4813);
     425          Assert(Cost < 2089);
    426426          Hash1 := (Attack * 1605 + Defense) shl 5 + FeatureCode;
    427427          Hash2 := ((Bombs * 7 + ATrans_Fuel) * 4 + TTrans) * 2089 + Cost;
     
    429429      end;
    430430      Hash2r := 0;
    431       for i := 0 to 7 do
     431      for I := 0 to 7 do
    432432      begin
    433433        Hash2r := Hash2r * 13;
    434         d := Hash2 div 13;
    435         Inc(Hash2r, Hash2 - d * 13);
    436         Hash2 := d;
     434        D := Hash2 div 13;
     435        Inc(Hash2r, Hash2 - D * 13);
     436        Hash2 := D;
    437437      end;
    438       Result := integer(Domain shl 30 + Hash1 xor Hash2r);
     438      Result := Integer(Domain shl 30 + Hash1 xor Hash2r);
    439439    end;
    440440end;
    441441
    442 function ProcessEnhancement(uix: integer; const Jobs: TEnhancementJobs): integer;
     442function ProcessEnhancement(uix: Integer; const Jobs: TEnhancementJobs): Integer;
    443443  { return values:
    444444    eJobDone - all applicable jobs done
     
    446446    eDied - job done and died (thurst) }
    447447var
    448   stage, NextJob, Tile: integer;
     448  stage, NextJob, Tile: Integer;
    449449  Done: set of jNone .. jPoll;
    450450begin
     
    452452  Tile := MyMap[MyUn[uix].Loc];
    453453  if Tile and fRoad <> 0 then
    454     include(Done, jRoad);
     454    Include(Done, jRoad);
    455455  if Tile and fRR <> 0 then
    456     include(Done, jRR);
     456    Include(Done, jRR);
    457457  if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) then
    458     include(Done, jIrr);
     458    Include(Done, jIrr);
    459459  if Tile and fTerImp = tiFarm then
    460     include(Done, jFarm);
     460    Include(Done, jFarm);
    461461  if Tile and fTerImp = tiMine then
    462     include(Done, jMine);
     462    Include(Done, jMine);
    463463  if Tile and fPoll = 0 then
    464     include(Done, jPoll);
     464    Include(Done, jPoll);
    465465
    466466  if MyUn[uix].Job = jNone then
     
    485485      Break;
    486486    end; // tile enhancement complete
    487     Result := Server(sStartJob + NextJob shl 4, me, uix, nil^);
    488     include(Done, NextJob);
    489   end;
    490 end;
    491 
    492 function AutoBuild(cix: integer; const ImpOrder: TImpOrder): boolean;
    493 var
    494   i, NewProject: integer;
     487    Result := Server(sStartJob + NextJob shl 4, Me, uix, nil^);
     488    Include(Done, NextJob);
     489  end;
     490end;
     491
     492function AutoBuild(cix: Integer; const ImpOrder: TImpOrder): Boolean;
     493var
     494  I, NewProject: Integer;
    495495begin
    496496  Result := False;
     
    498498    (MyCity[cix].Flags and chProduction <> 0) then
    499499  begin
    500     i := 0;
     500    I := 0;
    501501    repeat
    502       while (ImpOrder[i] >= 0) and (MyCity[cix].Built[ImpOrder[i]] > 0) do
    503         Inc(i);
    504       if ImpOrder[i] < 0 then
     502      while (ImpOrder[I] >= 0) and (MyCity[cix].Built[ImpOrder[I]] > 0) do
     503        Inc(I);
     504      if ImpOrder[I] < 0 then
    505505        Break;
    506       assert(i < nImp);
    507       NewProject := cpImp + ImpOrder[i];
    508       if Server(sSetCityProject, me, cix, NewProject) >= rExecuted then
     506      Assert(I < nImp);
     507      NewProject := cpImp + ImpOrder[I];
     508      if Server(sSetCityProject, Me, cix, NewProject) >= rExecuted then
    509509      begin
    510510        Result := True;
     
    512512        Break;
    513513      end;
    514       Inc(i);
     514      Inc(I);
    515515    until False;
    516516  end;
     
    519519procedure CalculateAdvValues;
    520520var
    521   i, j: integer;
    522   known: array [0 .. nAdv - 1] of integer;
    523 
    524   procedure MarkPreqs(i: integer);
    525   begin
    526     if known[i] = 0 then
     521  I, J: Integer;
     522  known: array [0 .. nAdv - 1] of Integer;
     523
     524  procedure MarkPreqs(I: Integer);
     525  begin
     526    if known[I] = 0 then
    527527    begin
    528       known[i] := 1;
    529       if (i <> adScience) and (i <> adMassProduction) then
     528      known[I] := 1;
     529      if (I <> adScience) and (I <> adMassProduction) then
    530530      begin
    531         if (AdvPreq[i, 0] >= 0) then
    532           MarkPreqs(AdvPreq[i, 0]);
    533         if (AdvPreq[i, 1] >= 0) then
    534           MarkPreqs(AdvPreq[i, 1]);
     531        if (AdvPreq[I, 0] >= 0) then
     532          MarkPreqs(AdvPreq[I, 0]);
     533        if (AdvPreq[I, 1] >= 0) then
     534          MarkPreqs(AdvPreq[I, 1]);
    535535      end;
    536536    end;
     
    539539begin
    540540  FillChar(AdvValue, SizeOf(AdvValue), 0);
    541   for i := 0 to nAdv - 1 do
     541  for I := 0 to nAdv - 1 do
    542542  begin
    543543    FillChar(known, SizeOf(known), 0);
    544     MarkPreqs(i);
    545     for j := 0 to nAdv - 1 do
    546       if known[j] > 0 then
    547         Inc(AdvValue[i]);
    548     if i in FutureTech then
    549       Inc(AdvValue[i], 3000)
     544    MarkPreqs(I);
     545    for J := 0 to nAdv - 1 do
     546      if known[J] > 0 then
     547        Inc(AdvValue[I]);
     548    if I in FutureTech then
     549      Inc(AdvValue[I], 3000)
    550550    else if known[adMassProduction] > 0 then
    551       Inc(AdvValue[i], 2000)
     551      Inc(AdvValue[I], 2000)
    552552    else if known[adScience] > 0 then
    553       Inc(AdvValue[i], 1000);
    554   end;
    555 end;
    556 
    557 procedure DebugMessage(Level: integer; Text: string);
    558 begin
    559   Server(sMessage, me, Level, PChar(Text)^);
    560 end;
    561 
    562 function MarkCitiesAround(Loc, cixExcept: integer): boolean;
     553      Inc(AdvValue[I], 1000);
     554  end;
     555end;
     556
     557procedure DebugMessage(Level: Integer; Text: string);
     558begin
     559  Server(sMessage, Me, Level, PChar(Text)^);
     560end;
     561
     562function MarkCitiesAround(Loc, cixExcept: Integer): Boolean;
    563563  // return whether a city was marked
    564564var
    565   cix: integer;
     565  cix: Integer;
    566566begin
    567567  Result := False;
     
    576576end;
    577577
    578 procedure OptimizeCities(CheckOnly: boolean);
    579 var
    580   cix, fix, dx, dy, Loc1, OptiType: integer;
    581   Done: boolean;
     578procedure OptimizeCities(CheckOnly: Boolean);
     579var
     580  cix, fix, dx, dy, Loc1, OptiType: Integer;
     581  Done: Boolean;
    582582  Advice: TCityTileAdviceData;
    583583begin
     
    591591        begin
    592592          Advice.ResourceWeights := OfferedResourceWeights[OptiType];
    593           Server(sGetCityTileAdvice, me, cix, Advice);
     593          Server(sGetCityTileAdvice, Me, cix, Advice);
    594594          if Advice.Tiles <> MyCity[cix].Tiles then
    595595            if CheckOnly then
     
    611611                    Done := False;
    612612                end;
    613               Server(sSetCityTiles, me, cix, Advice.Tiles);
     613              Server(sSetCityTiles, Me, cix, Advice.Tiles);
    614614            end;
    615615        end;
     
    621621procedure CityOptimizer_BeginOfTurn;
    622622var
    623   cix: integer;
     623  cix: Integer;
    624624begin
    625625  FillChar(CityNeedsOptimize, MyRO.nCity - 1, 0); // false
     
    634634end;
    635635
    636 procedure CityOptimizer_CityChange(cix: integer);
     636procedure CityOptimizer_CityChange(cix: Integer);
    637637begin
    638638  if (MyRO.Government <> gAnarchy) and (cix <> -1) and (MyCity[cix].Flags and
     
    644644end;
    645645
    646 procedure CityOptimizer_TileBecomesAvailable(Loc: integer);
     646procedure CityOptimizer_TileBecomesAvailable(Loc: Integer);
    647647begin
    648648  if (MyRO.Government <> gAnarchy) and MarkCitiesAround(Loc, -1) then
     
    650650end;
    651651
    652 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: integer);
    653 var
    654   fix, dx, dy, Loc1: integer;
    655   Done: boolean;
     652procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: Integer);
     653var
     654  fix, dx, dy, Loc1: Integer;
     655  Done: Boolean;
    656656begin
    657657  if (MyRO.Government <> gAnarchy) and (ReleasedTiles <> 0) then
     
    672672end;
    673673
    674 procedure CityOptimizer_BeforeRemoveUnit(uix: integer);
    675 var
    676   uix1: integer;
     674procedure CityOptimizer_BeforeRemoveUnit(uix: Integer);
     675var
     676  uix1: Integer;
    677677begin
    678678  if MyRO.Government <> gAnarchy then
     
    698698// all cities should already be optimized here -- only check this
    699699var
    700   cix: integer;
     700  cix: Integer;
    701701begin
    702702{$IFOPT O-}
  • branches/highdpi/LocalPlayer/Diagram.pas

    r361 r465  
    99
    1010type
     11  TDiagramKind = (dkChart, dkShip);
     12
    1113  TDiaDlg = class(TFramedDlg)
    1214    CloseBtn: TButtonB;
     
    1921    procedure ToggleBtnClick(Sender: TObject);
    2022    procedure PlayerClick(Sender: TObject);
    21     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
    22 
     23    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    2324  public
    2425    procedure OffscreenPaint; override;
    25     procedure ShowNewContent_Charts(NewMode: integer);
    26     procedure ShowNewContent_Ship(NewMode: integer; p: integer = -1);
    27 
     26    procedure ShowNewContent_Charts(NewMode: TWindowMode);
     27    procedure ShowNewContent_Ship(NewMode: TWindowMode; P: Integer = -1);
    2828  private
    29     Kind: (dkChart, dkShip);
    30     Player, Mode: integer;
    31   end;
    32 
    33 var
    34   DiaDlg: TDiaDlg;
    35 
    36 procedure PaintColonyShip(canvas: TDpiCanvas; Player, Left, Width, Top: integer);
     29    Kind: TDiagramKind;
     30    Player: Integer;
     31    Mode: Integer;
     32  end;
     33
     34procedure PaintColonyShip(Canvas: TDpiCanvas; Player, Left, Width, Top: Integer);
     35
    3736
    3837implementation
     
    4544const
    4645  Border = 24;
    47   RoundPixels: array [0 .. nStat - 1] of integer = (0, 0, 0, 5, 5, 5);
     46  RoundPixels: array [0 .. nStat - 1] of Integer = (0, 0, 0, 5, 5, 5);
    4847
    4948  yArea = 48;
    50   xComp: array [0 .. 5] of integer = (-60, -28, 4, 4, 36, 68);
    51   yComp: array [0 .. 5] of integer = (-40, -40, -79, -1, -40, -40);
    52   xPow: array [0 .. 3] of integer = (-116, -116, -116, -116);
    53   yPow: array [0 .. 3] of integer = (-28, 0, -44, 16);
    54   xHab: array [0 .. 1] of integer = (23, 23);
    55   yHab: array [0 .. 1] of integer = (-81, 1);
    56 
    57 procedure PaintColonyShip(canvas: TDpiCanvas; Player, Left, Width, Top: integer);
     49  xComp: array [0 .. 5] of Integer = (-60, -28, 4, 4, 36, 68);
     50  yComp: array [0 .. 5] of Integer = (-40, -40, -79, -1, -40, -40);
     51  xPow: array [0 .. 3] of Integer = (-116, -116, -116, -116);
     52  yPow: array [0 .. 3] of Integer = (-28, 0, -44, 16);
     53  xHab: array [0 .. 1] of Integer = (23, 23);
     54  yHab: array [0 .. 1] of Integer = (-81, 1);
     55
     56procedure PaintColonyShip(Canvas: TDpiCanvas; Player, Left, Width, Top: Integer);
    5857var
    59   i, x, r, nComp, nPow, nHab: integer;
     58  I, X, R, nComp, nPow, nHab: Integer;
    6059begin
    6160  Canvas.Brush.Color := $000000;
    6261  Canvas.FillRect(Rect(Left, Top, Left + Width, Top + 200));
    6362  Canvas.Brush.Style := bsClear;
    64     ScreenTools.Frame(canvas, Left - 1, Top - 1, Left + Width, Top + 200,
     63    ScreenTools.Frame(Canvas, Left - 1, Top - 1, Left + Width, Top + 200,
    6564      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    66     RFrame(canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1,
     65    RFrame(Canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1,
    6766      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    6867
    6968    // stars
    7069    DelphiRandSeed := Player * 11111;
    71     for i := 1 to Width - 16 do
     70    for I := 1 to Width - 16 do
    7271    begin
    73       x := DelphiRandom((Width - 16) * 200);
    74       r := DelphiRandom(13) + 28;
    75       Canvas.Pixels[x div 200 + 8, x mod 200 + Top] :=
    76         (r * r * r * r div 10001) * $10101;
     72      X := DelphiRandom((Width - 16) * 200);
     73      R := DelphiRandom(13) + 28;
     74      Canvas.Pixels[X div 200 + 8, X mod 200 + Top] :=
     75        (R * R * R * R div 10001) * $10101;
    7776    end;
    7877
     
    8685    if nHab > 2 then
    8786      nHab := 2;
    88     for i := 0 to nHab - 1 do
    89       Sprite(canvas, HGrSystem2, Left + Width div 2 + xHab[i],
    90         Top + 100 + yHab[i], 80, 80, 34, 1);
    91     for i := 0 to nComp - 1 do
    92       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[i],
    93         Top + 100 + yComp[i], 32, 80, 1, 1);
     87    for I := 0 to nHab - 1 do
     88      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xHab[I],
     89        Top + 100 + yHab[I], 80, 80, 34, 1);
     90    for I := 0 to nComp - 1 do
     91      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[I],
     92        Top + 100 + yComp[I], 32, 80, 1, 1);
    9493    if nComp > 0 then
    95       for i := 3 downto nPow do
    96         Sprite(canvas, HGrSystem2, Left + Width div 2 + xPow[i] + 40,
    97           Top + 100 + yPow[i], 16, 27, 1, 82);
    98     for i := nPow - 1 downto 0 do
    99       Sprite(canvas, HGrSystem2, Left + Width div 2 + xPow[i],
    100         Top + 100 + yPow[i], 56, 28, 58, 82);
     94      for I := 3 downto nPow do
     95        Sprite(Canvas, HGrSystem2, Left + Width div 2 + xPow[I] + 40,
     96          Top + 100 + yPow[I], 16, 27, 1, 82);
     97    for I := nPow - 1 downto 0 do
     98      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xPow[I],
     99        Top + 100 + yPow[I], 56, 28, 58, 82);
    101100    if (nComp < 3) and (nHab >= 1) then
    102       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16,
     101      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16,
    103102        Top + 100 + 7 + yComp[2], 16, 27, 1, 82);
    104103    if (nComp >= 3) and (nHab < 1) then
    105       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32,
     104      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32,
    106105        Top + 100 + 7 + yComp[2], 16, 27, 18, 82);
    107106    if (nComp < 4) and (nHab >= 2) then
    108       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16,
     107      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16,
    109108        Top + 100 + 46 + yComp[3], 16, 27, 1, 82);
    110109    if (nComp >= 4) and (nHab < 2) then
    111       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32,
     110      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32,
    112111        Top + 100 + 46 + yComp[3], 16, 27, 18, 82);
    113112    if (nComp <> 6) and (nComp <> 2) and not((nComp = 0) and (nPow < 1)) then
    114       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
     113      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
    115114        Top + 100 + 7 + yComp[nComp], 16, 27, 18, 82);
    116115    if (nComp <> 6) and (nComp <> 3) and not((nComp = 0) and (nPow < 2)) then
    117       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
     116      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
    118117        Top + 100 + 46 + yComp[nComp], 16, 27, 18, 82);
    119118    if nComp = 2 then
    120       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3],
     119      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3],
    121120        Top + 100 + 7 + yComp[3], 16, 27, 18, 82);
    122121    if nComp = 3 then
    123       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[4],
     122      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[4],
    124123        Top + 100 + 7 + yComp[4], 16, 27, 18, 82);
    125124end;
     
    142141procedure TDiaDlg.OffscreenPaint;
    143142var
    144   p, T, max, x, y, y0, Stop, r, RoundRange, LineStep: integer;
    145   s: string;
     143  P, T, Max, X, Y, y0, Stop, R, RoundRange, LineStep: Integer;
     144  S: string;
    146145  List: ^TChart;
    147146
    148   function Round(T: integer): integer;
     147  function Round(T: Integer): Integer;
    149148  var
    150     n, i: integer;
     149    N, I: Integer;
    151150  begin
    152151    if T < RoundRange then
    153       n := T
     152      N := T
    154153    else
    155       n := RoundRange;
    156     result := 0;
    157     for i := T - n to T do
    158       inc(result, List[i]);
    159     result := result div (n + 1);
    160   end;
    161 
    162   procedure ShareBar(x, y: integer; Cap: string; val0, val1: integer);
    163   begin
    164     LoweredTextOut(offscreen.canvas, -1, MainTexture, x - 2, y, Cap);
    165     DLine(offscreen.canvas, x - 2, x + 169, y + 16, MainTexture.ColorTextShade,
     154      N := RoundRange;
     155    Result := 0;
     156    for I := T - N to T do
     157      Inc(Result, List[I]);
     158    Result := Result div (N + 1);
     159  end;
     160
     161  procedure ShareBar(X, Y: Integer; Cap: string; val0, val1: Integer);
     162  begin
     163    LoweredTextOut(Offscreen.Canvas, -1, MainTexture, X - 2, Y, Cap);
     164    DLine(Offscreen.Canvas, X - 2, X + 169, Y + 16, MainTexture.ColorTextShade,
    166165      MainTexture.ColorTextLight);
    167166    if val0 > 0 then
    168       s := Format(Phrases.Lookup('SHARE'), [val0, val1])
     167      S := Format(Phrases.Lookup('SHARE'), [val0, val1])
    169168    else
    170       s := '0';
    171     RisedTextOut(offscreen.canvas,
    172       x + 170 - BiColorTextWidth(offscreen.canvas, s), y, s);
     169      S := '0';
     170    RisedTextOut(Offscreen.Canvas,
     171      X + 170 - BiColorTextWidth(Offscreen.Canvas, S), Y, S);
    173172  end;
    174173
     
    176175  inherited;
    177176  if Kind = dkChart then
    178     with offscreen.canvas do
     177    with Offscreen.Canvas do
    179178    begin
    180179      Font.Assign(UniFont[ftTiny]);
     
    186185      GetMem(List, 4 * (MyRO.Turn + 2));
    187186      if Mode = stExplore then
    188         max := G.lx * G.ly
     187        Max := G.lx * G.ly
    189188      else
    190189      begin
    191         max := -1;
    192         for p := 0 to nPl - 1 do
    193           if (G.Difficulty[p] > 0) and
    194             (Server(sGetChart + Mode shl 4, me, p, List^) >= rExecuted) then
     190        Max := -1;
     191        for P := 0 to nPl - 1 do
     192          if (G.Difficulty[P] > 0) and
     193            (Server(sGetChart + Mode shl 4, Me, P, List^) >= rExecuted) then
    195194            for T := 0 to MyRO.Turn - 1 do
    196195            begin
    197               r := Round(T);
    198               if r > max then
    199                 max := r;
     196              R := Round(T);
     197              if R > Max then
     198                Max := R;
    200199            end;
    201200      end;
     
    215214      for T := 0 to (MyRO.Turn - 1) div LineStep do
    216215      begin
    217         x := Border + (InnerWidth - 2 * Border) * T *
     216        X := Border + (InnerWidth - 2 * Border) * T *
    218217          LineStep div (MyRO.Turn - 1);
    219         MoveTo(x, Border);
    220         LineTo(x, InnerHeight - Border);
    221         s := IntToStr(abs(TurnToYear(T * LineStep)));
    222         Textout(x - TextWidth(s) div 2, Border - 16, s);
     218        MoveTo(X, Border);
     219        LineTo(X, InnerHeight - Border);
     220        S := IntToStr(abs(TurnToYear(T * LineStep)));
     221        Textout(X - TextWidth(S) div 2, Border - 16, S);
    223222      end;
    224223
    225224      y0 := 0;
    226       if max > 0 then
     225      if Max > 0 then
    227226      begin
    228         for p := 0 to nPl - 1 do
    229           if (G.Difficulty[p] > 0) and
    230             (Server(sGetChart + Mode shl 4, me, p, List^) >= rExecuted) then
     227        for P := 0 to nPl - 1 do
     228          if (G.Difficulty[P] > 0) and
     229            (Server(sGetChart + Mode shl 4, Me, P, List^) >= rExecuted) then
    231230          begin
    232             Pen.Color := Tribe[p].Color;
     231            Pen.Color := Tribe[P].Color;
    233232            Stop := MyRO.Turn - 1;
    234233            while (Stop > 0) and (List[Stop] = 0) do
    235               dec(Stop);
     234              Dec(Stop);
    236235            for T := 0 to Stop do
    237236            begin
    238               r := Round(T);
    239               x := Border + (InnerWidth - 2 * Border) * T div (MyRO.Turn - 1);
    240               y := InnerHeight - Border - (InnerHeight - 2 * Border) *
    241                 r div max;
     237              R := Round(T);
     238              X := Border + (InnerWidth - 2 * Border) * T div (MyRO.Turn - 1);
     239              Y := InnerHeight - Border - (InnerHeight - 2 * Border) *
     240                R div Max;
    242241              if T = 0 then
    243                 MoveTo(x, y)
     242                MoveTo(X, Y)
    244243                // else if Mode=stTerritory then
    245244                // begin LineTo(x,y0); LineTo(x,y) end
    246245              else if RoundPixels[Mode] = 0 then
    247246              begin
    248                 if (y <> y0) or (T = Stop) then
    249                   LineTo(x, y)
     247                if (Y <> y0) or (T = Stop) then
     248                  LineTo(X, Y)
    250249              end
    251250              else
    252                 LineTo(x, y);
    253               y0 := y;
     251                LineTo(X, Y);
     252              y0 := Y;
    254253            end;
    255254          end;
     
    258257    end
    259258  else
    260     with offscreen.canvas do
     259    with Offscreen.Canvas do
    261260    begin
    262261      Font.Assign(UniFont[ftSmall]);
    263262      FillOffscreen(0, 0, InnerWidth, InnerHeight);
    264263
    265       PaintColonyShip(offscreen.canvas, Player, 8, InnerWidth - 16, yArea);
     264      PaintColonyShip(Offscreen.Canvas, Player, 8, InnerWidth - 16, yArea);
    266265
    267266      ShareBar(InnerWidth div 2 - 85, InnerHeight - 62,
     
    273272    end;
    274273  MarkUsedOffscreen(InnerWidth, InnerHeight);
    275 end; // OffscreenPaint
     274end;
    276275
    277276procedure TDiaDlg.FormPaint(Sender: TObject);
    278277var
    279   s: string;
     278  S: string;
    280279begin
    281280  inherited;
    282   canvas.Font.Assign(UniFont[ftNormal]);
     281  Canvas.Font.Assign(UniFont[ftNormal]);
    283282  if Kind = dkChart then
    284     s := Phrases.Lookup('DIAGRAM', Mode)
    285   else
    286     s := Tribe[Player].TPhrase('SHORTNAME');
    287   LoweredTextOut(canvas, -1, MainTexture,
    288     (ClientWidth - BiColorTextWidth(canvas, s)) div 2, 31, s);
     283    S := Phrases.Lookup('DIAGRAM', Mode)
     284  else
     285    S := Tribe[Player].TPhrase('SHORTNAME');
     286  LoweredTextOut(Canvas, -1, MainTexture,
     287    (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 31, S);
    289288end;
    290289
     
    299298end;
    300299
    301 procedure TDiaDlg.ShowNewContent_Charts(NewMode: integer);
     300procedure TDiaDlg.ShowNewContent_Charts(NewMode: TWindowMode);
    302301begin
    303302  Kind := dkChart;
     
    309308end;
    310309
    311 procedure TDiaDlg.ShowNewContent_Ship(NewMode, p: integer);
     310procedure TDiaDlg.ShowNewContent_Ship(NewMode: TWindowMode; P: Integer);
    312311begin
    313312  Kind := dkShip;
    314   if p < 0 then
    315   begin
    316     Player := me;
     313  if P < 0 then
     314  begin
     315    Player := Me;
    317316    while MyRO.Ship[Player].Parts[spComp] + MyRO.Ship[Player].Parts[spPow] +
    318317      MyRO.Ship[Player].Parts[spHab] = 0 do
     
    320319  end
    321320  else
    322     Player := p;
     321    Player := P;
    323322  ToggleBtn.ButtonIndex := 28;
    324323  ToggleBtn.Hint := Phrases.Lookup('BTN_SELECT');
     
    329328procedure TDiaDlg.ToggleBtnClick(Sender: TObject);
    330329var
    331   p1: integer;
    332   m: TDpiMenuItem;
     330  p1: Integer;
     331  M: TDpiMenuItem;
    333332begin
    334333  if Kind = dkChart then
     
    345344        MyRO.Ship[p1].Parts[spHab] > 0 then
    346345      begin
    347         m := TDpiMenuItem.Create(Popup);
    348         m.RadioItem := true;
    349         m.Caption := Tribe[p1].TPhrase('SHORTNAME');
    350         m.Tag := p1;
    351         m.OnClick := PlayerClick;
     346        M := TDpiMenuItem.Create(Popup);
     347        M.RadioItem := True;
     348        M.Caption := Tribe[p1].TPhrase('SHORTNAME');
     349        M.Tag := p1;
     350        M.OnClick := PlayerClick;
    352351        if p1 = Player then
    353           m.Checked := true;
    354         Popup.Items.Add(m);
     352          M.Checked := True;
     353        Popup.Items.Add(M);
    355354      end;
    356355    Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
     
    363362end;
    364363
    365 procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: word;
     364procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: Word;
    366365  Shift: TShiftState);
    367366begin
  • branches/highdpi/LocalPlayer/Diplomacy.pas

    r210 r465  
    77
    88function DipCommandToString(pSender, pTarget, Treaty, OppCommand,
    9   Command: integer; const OppOffer, Offer: TOffer): string;
     9  Command: Integer; const OppOffer, Offer: TOffer): string;
    1010
    1111implementation
     
    1616function DipCommandToString;
    1717
    18   function PriceToString(p, Price: integer): string;
     18  function PriceToString(P, Price: Integer): string;
    1919  begin
    2020    case Price and opMask of
    2121      opChoose:
    22         result := Phrases.Lookup('PRICE_CHOOSE');
     22        Result := Phrases.Lookup('PRICE_CHOOSE');
    2323      opCivilReport:
    24         result := Tribe[p].TPhrase('PRICE_CIVIL');
     24        Result := Tribe[P].TPhrase('PRICE_CIVIL');
    2525      opMilReport:
    26         result := Tribe[p].TPhrase('PRICE_MIL');
     26        Result := Tribe[P].TPhrase('PRICE_MIL');
    2727      opMap:
    28         result := Tribe[p].TPhrase('PRICE_MAP');
     28        Result := Tribe[P].TPhrase('PRICE_MAP');
    2929      opTreaty:
    3030        { if Price-opTreaty<Treaty then
    3131          case Treaty of
    32           trPeace: result:=Phrases.Lookup('FRENDTREATY_PEACE');
    33           trFriendlyContact: result:=Phrases.Lookup('FRENDTREATY_FRIENDLY');
    34           trAlliance: result:=Phrases.Lookup('FRENDTREATY_ALLIANCE');
    35           end
    36           else } result := Phrases.Lookup('TREATY', Price - opTreaty);
     32          trPeace: Result:=Phrases.Lookup('FRENDTREATY_PEACE');
     33          trFriendlyContact: Result:=Phrases.Lookup('FRENDTREATY_FRIENDLY');
     34          trAlliance: Result:=Phrases.Lookup('FRENDTREATY_ALLIANCE');
     35          end
     36          else } Result := Phrases.Lookup('TREATY', Price - opTreaty);
    3737      opShipParts:
    3838        case Price shr 16 and $F of
    3939          0:
    40             result := Format(Phrases.Lookup('PRICE_SHIPCOMP'),
     40            Result := Format(Phrases.Lookup('PRICE_SHIPCOMP'),
    4141              [Price and $FFFF]);
    4242          1:
    43             result := Format(Phrases.Lookup('PRICE_SHIPPOW'),
     43            Result := Format(Phrases.Lookup('PRICE_SHIPPOW'),
    4444              [Price and $FFFF]);
    4545          2:
    46             result := Format(Phrases.Lookup('PRICE_SHIPHAB'),
     46            Result := Format(Phrases.Lookup('PRICE_SHIPHAB'),
    4747              [Price and $FFFF]);
    4848        end;
    4949      opMoney:
    50         result := Format('%d%%c', [Price - opMoney]);
     50        Result := Format('%d%%c', [Price - opMoney]);
    5151      opTribute:
    52         result := Format(Phrases.Lookup('PRICE_TRIBUTE'), [Price - opTribute]);
     52        Result := Format(Phrases.Lookup('PRICE_TRIBUTE'), [Price - opTribute]);
    5353      opTech:
    54         result := Phrases.Lookup('ADVANCES', Price - opTech);
     54        Result := Phrases.Lookup('ADVANCES', Price - opTech);
    5555      opAllTech:
    56         result := Tribe[p].TPhrase('PRICE_ALLTECH');
     56        Result := Tribe[P].TPhrase('PRICE_ALLTECH');
    5757      opModel:
    58         result := Tribe[p].ModelName[Price - opModel];
     58        Result := Tribe[P].ModelName[Price - opModel];
    5959      opAllModel:
    60         result := Tribe[p].TPhrase('PRICE_ALLMODEL');
     60        Result := Tribe[P].TPhrase('PRICE_ALLMODEL');
    6161      { opCity:
    62         result:=Format(TPhrase('PRICE_CITY',p),[CityName(Price-opCity)]); }
     62        Result:=Format(TPhrase('PRICE_CITY',P),[CityName(Price-opCity)]); }
    6363    end
    6464  end;
    6565
    6666var
    67   i: integer;
     67  I: Integer;
    6868  sAdd, sDeliver, sCost: string;
    69   DoIntro: boolean;
     69  DoIntro: Boolean;
    7070begin
    7171  DoIntro := OppCommand = scDipStart;
     
    7575        case Treaty of
    7676          trPeace:
    77             result := Phrases.Lookup('FRCANCELTREATY_PEACE');
     77            Result := Phrases.Lookup('FRCANCELTREATY_PEACE');
    7878          trFriendlyContact:
    79             result := Phrases.Lookup('FRCANCELTREATY_FRIENDLY');
     79            Result := Phrases.Lookup('FRCANCELTREATY_FRIENDLY');
    8080          trAlliance:
    81             result := Phrases.Lookup('FRCANCELTREATY_ALLIANCE');
    82         end;
    83         DoIntro := false;
     81            Result := Phrases.Lookup('FRCANCELTREATY_ALLIANCE');
     82        end;
     83        DoIntro := False;
    8484      end;
    8585    scDipNotice:
    86       result := Phrases.Lookup('FRNOTICE');
     86      Result := Phrases.Lookup('FRNOTICE');
    8787    scDipAccept:
    8888      begin
    8989        if (OppOffer.nDeliver + OppOffer.nCost = 1) and
    9090          (OppOffer.Price[0] and opMask = opTreaty) and
    91           (integer(OppOffer.Price[0] - opTreaty) > Treaty) then
     91          (Integer(OppOffer.Price[0] - opTreaty) > Treaty) then
    9292        // simple treaty offer
    9393          { if OppOffer.Price[0]-opTreaty=trCeaseFire then
    94             result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE')
    95             else } result := Tribe[pTarget].TPhrase('FRACCEPTTREATY')
     94            Result:=Tribe[pTarget].TPhrase('FRACCEPTCEASEFIRE')
     95            else } Result := Tribe[pTarget].TPhrase('FRACCEPTTREATY')
    9696        else if OppOffer.nDeliver = 0 then
    97           result := Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG')
     97          Result := Tribe[pSender].TPhrase('FRACCEPTDEMAND_STRONG')
    9898        else if OppOffer.nCost = 0 then
    99           result := Tribe[pSender].TPhrase('FRACCEPTPRESENT')
     99          Result := Tribe[pSender].TPhrase('FRACCEPTPRESENT')
    100100        else
    101           result := Tribe[pSender].TPhrase('FRACCEPTOFFER');
     101          Result := Tribe[pSender].TPhrase('FRACCEPTOFFER');
    102102      end;
    103103    scDipBreak:
    104104      begin
    105         result := Tribe[pTarget].TPhrase('FRBREAK');
    106         DoIntro := false;
     105        Result := Tribe[pTarget].TPhrase('FRBREAK');
     106        DoIntro := False;
    107107      end;
    108108    scDipOffer:
    109109      begin
    110         result := '';
     110        Result := '';
    111111        if (OppCommand = scDipOffer) and
    112112          ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) and
     
    115115          if (OppOffer.nDeliver + OppOffer.nCost = 1) and
    116116            (OppOffer.Price[0] and opMask = opTreaty) and
    117             (integer(OppOffer.Price[0] - opTreaty) > Treaty) then
     117            (Integer(OppOffer.Price[0] - opTreaty) > Treaty) then
    118118          // simple treaty offer
    119             result := Tribe[pSender].TPhrase('FRNOTACCEPTTREATY') + '\'
     119            Result := Tribe[pSender].TPhrase('FRNOTACCEPTTREATY') + '\'
    120120          else if OppOffer.nDeliver = 0 then
    121             result := Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG') + '\'
     121            Result := Tribe[pSender].TPhrase('FRNOTACCEPTDEMAND_STRONG') + '\'
    122122          else if OppOffer.nCost = 0 then
    123             result := Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT') + '\';
     123            Result := Tribe[pSender].TPhrase('FRNOTACCEPTPRESENT') + '\';
    124124        end;
    125125
    126126        sDeliver := '';
    127         for i := 0 to Offer.nDeliver - 1 do
    128         begin
    129           sAdd := PriceToString(pSender, Offer.Price[i]);
    130           if i = 0 then
     127        for I := 0 to Offer.nDeliver - 1 do
     128        begin
     129          sAdd := PriceToString(pSender, Offer.Price[I]);
     130          if I = 0 then
    131131            sDeliver := sAdd
    132132          else
     
    134134        end;
    135135        sCost := '';
    136         for i := 0 to Offer.nCost - 1 do
    137         begin
    138           sAdd := PriceToString(pTarget, Offer.Price[Offer.nDeliver + i]);
    139           if i = 0 then
     136        for I := 0 to Offer.nCost - 1 do
     137        begin
     138          sAdd := PriceToString(pTarget, Offer.Price[Offer.nDeliver + I]);
     139          if I = 0 then
    140140            sCost := sAdd
    141141          else
     
    147147          if (OppCommand = scDipOffer) and
    148148            ((OppOffer.nDeliver = 0) and (OppOffer.nCost = 0)) then
    149             result := Tribe[pTarget].TPhrase('FRBYE')
     149            Result := Tribe[pTarget].TPhrase('FRBYE')
    150150          else
    151151          begin
    152             if (result = '') and (OppCommand = scDipOffer) and
     152            if (Result = '') and (OppCommand = scDipOffer) and
    153153              ((OppOffer.nDeliver > 0) or (OppOffer.nCost > 0)) then
    154154            begin
    155155              if (OppOffer.nDeliver = 1) and (OppOffer.Price[0] = opChoose) and
    156156                not Phrases2FallenBackToEnglish then
    157                 result := Tribe[pSender].TString
     157                Result := Tribe[pSender].TString
    158158                  (Phrases2.Lookup('FRNOTACCEPTANYOFFER')) + ' '
    159159              else if (OppOffer.nCost = 1) and
    160160                (OppOffer.Price[OppOffer.nDeliver] = opChoose) and not Phrases2FallenBackToEnglish
    161161              then
    162                 result := Tribe[pSender].TString
     162                Result := Tribe[pSender].TString
    163163                  (Phrases2.Lookup('FRNOTACCEPTANYWANT')) + ' '
    164164              else
    165                 result := Tribe[pSender].TPhrase('FRNOTACCEPTOFFER') + ' ';
     165                Result := Tribe[pSender].TPhrase('FRNOTACCEPTOFFER') + ' ';
    166166            end;
    167             result := result + Phrases.Lookup('FRDONE');
    168             DoIntro := false
     167            Result := Result + Phrases.Lookup('FRDONE');
     168            DoIntro := False
    169169          end
    170170        end
    171171        else if (Offer.nDeliver + Offer.nCost = 1) and
    172172          (Offer.Price[0] and opMask = opTreaty) and
    173           (integer(Offer.Price[0] - opTreaty) > Treaty) then
     173          (Integer(Offer.Price[0] - opTreaty) > Treaty) then
    174174        // simple treaty offer
    175175        begin
     
    177177            // trCeaseFire: result:=result+Tribe[pTarget].TPhrase('FRCEASEFIRE');
    178178            trPeace:
    179               result := result + Tribe[pTarget].TPhrase('FRPEACE');
     179              Result := Result + Tribe[pTarget].TPhrase('FRPEACE');
    180180            trFriendlyContact:
    181               result := result + Tribe[pTarget].TPhrase('FRFRIENDLY');
     181              Result := Result + Tribe[pTarget].TPhrase('FRFRIENDLY');
    182182            trAlliance:
    183               result := result + Tribe[pTarget].TPhrase('FRALLIANCE');
     183              Result := Result + Tribe[pTarget].TPhrase('FRALLIANCE');
    184184          end
    185185        end
     
    188188          if (Treaty >= trFriendlyContact) and not Phrases2FallenBackToEnglish
    189189          then
    190             result := result +
     190            Result := Result +
    191191              Format(Tribe[pTarget].TString(Phrases2.Lookup('FRDEMAND_SOFT')
    192192              ), [sCost])
    193193          else
    194194          begin
    195             result := result +
     195            Result := Result +
    196196              Format(Tribe[pTarget].TPhrase('FRDEMAND_STRONG'), [sCost]);
    197             DoIntro := false
     197            DoIntro := False
    198198          end
    199199        end
    200200        else if Offer.nCost = 0 then // present
    201           result := result + Format(Tribe[pTarget].TPhrase('FRPRESENT'),
     201          Result := Result + Format(Tribe[pTarget].TPhrase('FRPRESENT'),
    202202            [sDeliver])
    203203        else if (Offer.nDeliver = 1) and (Offer.Price[0] = opChoose) then
    204           result := result + Format(Phrases.Lookup('FRDELCHOICE'), [sCost])
     204          Result := Result + Format(Phrases.Lookup('FRDELCHOICE'), [sCost])
    205205        else if (Offer.nCost = 1) and (Offer.Price[Offer.nDeliver] = opChoose)
    206206        then
    207           result := result + Format(Phrases.Lookup('FRCOSTCHOICE'), [sDeliver])
     207          Result := Result + Format(Phrases.Lookup('FRCOSTCHOICE'), [sDeliver])
    208208        else
    209           result := result + Format(Phrases.Lookup('FROFFER'),
     209          Result := Result + Format(Phrases.Lookup('FROFFER'),
    210210            [sDeliver, sCost]);
    211211      end;
     
    213213  if DoIntro then
    214214    if Treaty < trPeace then
    215       result := Tribe[pSender].TPhrase('FRSTART_NOTREATY') + ' ' + result
     215      Result := Tribe[pSender].TPhrase('FRSTART_NOTREATY') + ' ' + Result
    216216    else
    217       result := Tribe[pSender].TPhrase('FRSTART_PEACE') + ' ' + result
     217      Result := Tribe[pSender].TPhrase('FRSTART_PEACE') + ' ' + Result
    218218end;
    219219
  • branches/highdpi/LocalPlayer/Draft.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin,
    8 
    9   LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
    10   ButtonA,
    11   ButtonB, Area;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, ExtCtrls, ButtonA, ButtonB, Area;
    129
    1310type
     
    2320    procedure CloseBtnClick(Sender: TObject);
    2421    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    25       Shift: TShiftState; x, y: integer);
     22      Shift: TShiftState; X, Y: Integer);
    2623    procedure OKBtnClick(Sender: TObject);
    2724    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    28       Shift: TShiftState; x, y: integer);
     25      Shift: TShiftState; X, Y: Integer);
    2926  public
    30     procedure ShowNewContent(NewMode: integer);
     27    procedure ShowNewContent(NewMode: TWindowMode);
    3128  protected
    3229    procedure OffscreenPaint; override;
    3330  private
    3431    Domain, MaxLines, Lines, Cut, yDomain, yFeature, yWeight, yTotal, yView,
    35       IncCap, DecCap: integer;
    36     code: array [0 .. nFeature - 1] of integer;
     32      IncCap, DecCap: Integer;
     33    Code: array [0 .. nFeature - 1] of Integer;
    3734    Template, Back: TDpiBitmap;
    38     function IsFeatureInList(d, i: integer): boolean;
    39     procedure SetDomain(d: integer);
    40   end;
    41 
    42 var
    43   DraftDlg: TDraftDlg;
     35    function IsFeatureInList(D, I: Integer): Boolean;
     36    procedure SetDomain(D: Integer);
     37  end;
     38
    4439
    4540implementation
    4641
    47 uses Help, Tribes, Directories;
     42uses
     43  Term, Help, Tribes, Directories;
    4844
    4945{$R *.lfm}
     
    109105procedure TDraftDlg.OffscreenPaint;
    110106
    111   function DomainAvailable(d: integer): boolean;
    112   begin
    113     result := (upgrade[d, 0].Preq = preNone) or
    114       (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable);
     107  function DomainAvailable(D: Integer): Boolean;
     108  begin
     109    Result := (upgrade[D, 0].Preq = preNone) or
     110      (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable);
    115111  end;
    116112
    117113  procedure PaintTotalBars;
    118114  var
    119     i, y, dx, num, w: integer;
    120     s: string;
    121   begin
    122     with offscreen.Canvas do
     115    I, Y, dx, num, W: Integer;
     116    S: string;
     117  begin
     118    with Offscreen.Canvas do
    123119    begin
    124120      // strength bar
    125       y := yTotal;
    126       DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 2);
    127       DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 2);
    128       RisedTextOut(offscreen.Canvas, xTotal - 2, y,
     121      Y := yTotal;
     122      DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 2);
     123      DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 2);
     124      RisedTextOut(Offscreen.Canvas, xTotal - 2, Y,
    129125        Phrases.Lookup('UNITSTRENGTH'));
    130       RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
     126      RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y,
    131127        'x' + IntToStr(MyRO.DevModel.MStrength));
    132       RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
    133       s := IntToStr(MyRO.DevModel.Attack) + '/' +
     128      RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '=');
     129      S := IntToStr(MyRO.DevModel.Attack) + '/' +
    134130        IntToStr(MyRO.DevModel.Defense);
    135       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
    136         BiColorTextWidth(offscreen.Canvas, s), y, s);
     131      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
     132        BiColorTextWidth(Offscreen.Canvas, S), Y, S);
    137133
    138134      // transport bar
    139135      if MyRO.DevModel.MTrans > 0 then
    140136      begin
    141         y := yTotal + 19;
    142         DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 1);
    143         DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 1);
    144         RisedTextOut(offscreen.Canvas, xTotal - 2, y,
     137        Y := yTotal + 19;
     138        DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 1);
     139        DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 1);
     140        RisedTextOut(Offscreen.Canvas, xTotal - 2, Y,
    145141          Phrases.Lookup('UNITTRANSPORT'));
    146         RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
     142        RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y,
    147143          'x' + IntToStr(MyRO.DevModel.MTrans));
    148         RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
     144        RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '=');
    149145
    150146        Font.Color := $000000;
    151147        dx := -237 - 30;
    152         for i := mcFirstNonCap - 1 downto 3 do
    153           if i in [mcSeaTrans, mcCarrier, mcAirTrans] then
     148        for I := mcFirstNonCap - 1 downto 3 do
     149          if I in [mcSeaTrans, mcCarrier, mcAirTrans] then
    154150          begin
    155             num := MyRO.DevModel.Cap[i] * MyRO.DevModel.MTrans;
     151            num := MyRO.DevModel.Cap[I] * MyRO.DevModel.MTrans;
    156152            if num > 0 then
    157153            begin
    158               inc(dx, 15);
     154              Inc(dx, 15);
    159155              Brush.Color := $C0C0C0;
    160               FrameRect(Rect(xTotal2 - 3 - dx, y + 2,
    161                 xTotal2 + 11 - dx, y + 16));
     156              FrameRect(Rect(xTotal2 - 3 - dx, Y + 2,
     157                xTotal2 + 11 - dx, Y + 16));
    162158              Brush.Style := bsClear;
    163               Sprite(offscreen, HGrSystem, xTotal2 - 1 - dx, y + 4, 10, 10,
    164                 66 + i mod 11 * 11, 137 + i div 11 * 11);
     159              Sprite(Offscreen, HGrSystem, xTotal2 - 1 - dx, Y + 4, 10, 10,
     160                66 + I mod 11 * 11, 137 + I div 11 * 11);
    165161              if num > 1 then
    166162              begin
    167                 s := IntToStr(num);
    168                 w := TextWidth(s);
    169                 inc(dx, w + 1);
     163                S := IntToStr(num);
     164                W := TextWidth(S);
     165                Inc(dx, W + 1);
    170166                Brush.Color := $FFFFFF;
    171                 FillRect(Rect(xTotal2 - 3 - dx, y + 2,
    172                   xTotal2 + w - 1 - dx, y + 16));
     167                FillRect(Rect(xTotal2 - 3 - dx, Y + 2,
     168                  xTotal2 + W - 1 - dx, Y + 16));
    173169                Brush.Style := bsClear;
    174                 Textout(xTotal2 - 3 - dx + 1, y, s);
     170                Textout(xTotal2 - 3 - dx + 1, Y, S);
    175171              end;
    176172            end;
    177           end
     173          end;
    178174      end;
    179175
    180176      // speed bar
    181       y := yTotal + 38;
    182       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
     177      Y := yTotal + 38;
     178      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
    183179        Phrases.Lookup('UNITSPEED'));
    184       DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     180      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    185181        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    186       DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     182      DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    187183        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    188       s := MovementToString(MyRO.DevModel.Speed);
    189       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
    190         TextWidth(s), y, s);
     184      S := MovementToString(MyRO.DevModel.Speed);
     185      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
     186        TextWidth(S), Y, S);
    191187
    192188      // cost bar
    193       y := yTotal + 57;
    194       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
     189      Y := yTotal + 57;
     190      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
    195191        Phrases.Lookup('UNITCOST'));
    196       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, y,
     192      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, Y,
    197193        'x' + IntToStr(MyRO.DevModel.MCost));
    198       LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    199         xTotal2 + 148 + 30, y, '=');
    200       DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     194      LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     195        xTotal2 + 148 + 30, Y, '=');
     196      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    201197        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    202       DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     198      DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    203199        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    204       s := IntToStr(MyRO.DevModel.Cost);
    205       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
    206         TextWidth(s), y, s);
    207       Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
     200      S := IntToStr(MyRO.DevModel.Cost);
     201      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
     202        TextWidth(S), Y, S);
     203      Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10,
    208204        10, 88, 115);
    209205
    210       if G.Difficulty[me] <> 2 then
     206      if G.Difficulty[Me] <> 2 then
    211207      begin // corrected cost bar
    212         y := yTotal + 76;
    213         LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
    214           Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[me])));
    215         LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    216           xTotal2 + 148 + 30, y, '=');
    217         DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     208        Y := yTotal + 76;
     209        LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
     210          Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[Me])));
     211        LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     212          xTotal2 + 148 + 30, Y, '=');
     213        DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    218214          MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    219         DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     215        DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    220216          MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    221         s := IntToStr(MyRO.DevModel.Cost * BuildCostMod
    222           [G.Difficulty[me]] div 12);
    223         RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
    224           TextWidth(s), y, s);
    225         Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
     217        S := IntToStr(MyRO.DevModel.Cost * BuildCostMod
     218          [G.Difficulty[Me]] div 12);
     219        RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
     220          TextWidth(S), Y, S);
     221        Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10,
    226222          10, 88, 115);
    227223      end;
     
    230226
    231227var
    232   i, j, x, d, n, TextColor, CapWeight, DomainCount: integer;
     228  I, J, X, D, N, TextColor, CapWeight, DomainCount: Integer;
    233229begin
    234230  inherited;
     
    239235  // assemble background from 2 texture tiles
    240236  begin
    241     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, 64,
     237    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, 64,
    242238      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    243239      MainTexture.Height - 64);
    244     DpiBitCanvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64,
     240    DpiBitBltCanvas(Back.Canvas, 0, 64, ClientWidth, ClientHeight - 64,
    245241      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    246242      0);
    247243  end
    248244  else
    249     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
     245    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
    250246      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    251247      (MainTexture.Height - ClientHeight) div 2);
     
    254250    Template.Height - 64 - Cut);
    255251
    256   DpiBitCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
     252  DpiBitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
    257253    Back.Canvas, 0, 0);
    258254
    259   offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    260   RisedTextOut(offscreen.Canvas, 10, 7, Caption);
    261   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     255  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
     256  RisedTextOut(Offscreen.Canvas, 10, 7, Caption);
     257  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    262258
    263259  with MyRO.DevModel do
    264260  begin
    265261    DomainCount := 0;
    266     for d := 0 to nDomains - 1 do
    267       if DomainAvailable(d) then
    268         inc(DomainCount);
     262    for D := 0 to nDomains - 1 do
     263      if DomainAvailable(D) then
     264        Inc(DomainCount);
    269265    if DomainCount > 1 then
    270266    begin
    271       for d := 0 to nDomains - 1 do
    272         if DomainAvailable(d) then
     267      for D := 0 to nDomains - 1 do
     268        if DomainAvailable(D) then
    273269        begin
    274           x := xDomain + d * DomainPitch;
    275           if d = Domain then
    276             ImageOp_BCC(offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,
     270          X := xDomain + D * DomainPitch;
     271          if D = Domain then
     272            ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36,
    277273              36, 0, $00C0FF)
    278274          else
    279             ImageOp_BCC(offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,
     275            ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36,
    280276              36, 0, $606060);
    281277        end;
    282       Frame(offscreen.Canvas, xDomain - 11, yDomain - 3,
     278      Frame(Offscreen.Canvas, xDomain - 11, yDomain - 3,
    283279        xDomain + 2 * DomainPitch + 46, yDomain + 38, $B0B0B0, $FFFFFF);
    284       RFrame(offscreen.Canvas, xDomain - 12, yDomain - 4,
     280      RFrame(Offscreen.Canvas, xDomain - 12, yDomain - 4,
    285281        xDomain + 2 * DomainPitch + 47, yDomain + 39, $FFFFFF, $B0B0B0);
    286282    end;
     
    295291
    296292    // display weight
    297     with offscreen.Canvas do
    298     begin
    299       for i := 0 to MaxWeight - 1 do
    300         if i < Weight then
    301           ImageOp_BCC(offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),
     293    with Offscreen.Canvas do
     294    begin
     295      for I := 0 to MaxWeight - 1 do
     296        if I < Weight then
     297          ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight),
    302298            WeightOn.BoundsRect, 0, $949494)
    303299        else
    304           ImageOp_BCC(offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),
     300          ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight),
    305301            WeightOff.BoundsRect, 0, $949494);
    306302    end;
    307303
    308     with offscreen.Canvas do
    309       for i := 0 to Lines - 1 do
     304    with Offscreen.Canvas do
     305      for I := 0 to Lines - 1 do
    310306      begin
    311         if not(code[i] in AutoFeature) then
     307        if not(Code[I] in AutoFeature) then
    312308        begin
    313309          // paint +/- butttons
    314           if code[i] < mcFirstNonCap then
     310          if Code[I] < mcFirstNonCap then
    315311          begin
    316             Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
    317               i, 12, 12, 169, 172);
    318             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    319               i, 12, 12, 169, 159);
    320             RFrame(offscreen.Canvas, xFeature - (21 + 1),
    321               yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
    322               yFeature + 2 + LinePitch * i + 12, MainTexture.ColorBevelShade,
     312            Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
     313              I, 12, 12, 169, 172);
     314            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     315              I, 12, 12, 169, 159);
     316            RFrame(Offscreen.Canvas, xFeature - (21 + 1),
     317              yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24),
     318              yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade,
    323319              MainTexture.ColorBevelLight);
    324320          end
    325321          else
    326322          begin
    327             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    328               i, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
    329             RFrame(offscreen.Canvas, xFeature - (9 + 1),
    330               yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
    331               yFeature + 2 + LinePitch * i + 12, MainTexture.ColorBevelShade,
     323            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     324              I, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[Code[I]]);
     325            RFrame(Offscreen.Canvas, xFeature - (9 + 1),
     326              yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24),
     327              yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade,
    332328              MainTexture.ColorBevelLight);
    333329          end;
    334330
    335331          // paint cost
    336           LightGradient(offscreen.Canvas, xFeature + 34,
    337             yFeature + LinePitch * i, 50, HGrSystem.Data.Canvas.Pixels
     332          LightGradient(Offscreen.Canvas, xFeature + 34,
     333            yFeature + LinePitch * I, 50, HGrSystem.Data.Canvas.Pixels
    338334            [187, 137]);
    339           if (Domain = dGround) and (code[i] = mcDefense) then
     335          if (Domain = dGround) and (Code[I] = mcDefense) then
    340336            CapWeight := 2
    341337          else
    342             CapWeight := Feature[code[i]].Weight;
    343           n := CapWeight + Feature[code[i]].Cost;
    344           d := 6;
    345           while (n - 1) * d * 2 > 48 - 10 do
    346             dec(d);
    347           for j := 0 to n - 1 do
    348             if j < CapWeight then
    349               Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
    350                 yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 126)
     338            CapWeight := Feature[Code[I]].Weight;
     339          N := CapWeight + Feature[Code[I]].Cost;
     340          D := 6;
     341          while (N - 1) * D * 2 > 48 - 10 do
     342            Dec(D);
     343          for J := 0 to N - 1 do
     344            if J < CapWeight then
     345              Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D,
     346                yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 126)
    351347            else
    352               Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
    353                 yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 115);
     348              Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D,
     349                yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 115);
    354350        end; // if not (code[i] in AutoFeature)
    355         DarkGradient(offscreen.Canvas, xFeature + 17,
    356           yFeature + LinePitch * i, 16, 1);
    357         ScreenTools.Frame(offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * i,
    358           xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * i,
     351        DarkGradient(Offscreen.Canvas, xFeature + 17,
     352          yFeature + LinePitch * I, 16, 1);
     353        ScreenTools.Frame(Offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * I,
     354          xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * I,
    359355          $C0C0C0, $C0C0C0);
    360         Sprite(offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
    361           * i, 10, 10, 66 + code[i] mod 11 * 11, 137 + code[i] div 11 * 11);
    362 
    363         if MyRO.DevModel.Cap[code[i]] > 0 then
     356        Sprite(Offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
     357          * I, 10, 10, 66 + Code[I] mod 11 * 11, 137 + Code[I] div 11 * 11);
     358
     359        if MyRO.DevModel.Cap[Code[I]] > 0 then
    364360          TextColor := MainTexture.ColorLitText
    365361        else
    366362          TextColor := -1;
    367363
    368         if code[i] < mcFirstNonCap then
    369           LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
    370             yFeature + LinePitch * i - 1, IntToStr(MyRO.DevModel.Cap[code[i]]));
    371         LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
    372           yFeature + LinePitch * i - 1, Phrases.Lookup('FEATURES', code[i]));
     364        if Code[I] < mcFirstNonCap then
     365          LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
     366            yFeature + LinePitch * I - 1, IntToStr(MyRO.DevModel.Cap[Code[I]]));
     367        LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
     368          yFeature + LinePitch * I - 1, Phrases.Lookup('FEATURES', Code[I]));
    373369      end;
    374370  end;
    375371
    376372  // free features
    377   j := 0;
    378   for i := 0 to nFeature - 1 do
    379     if (i in AutoFeature) and (1 shl Domain and Feature[i].Domains <> 0) and
    380       (Feature[i].Preq <> preNA) and
    381       ((Feature[i].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = me)
    382       or (Feature[i].Preq >= 0) and (MyRO.Tech[Feature[i].Preq] >= tsApplicable)
    383       ) and not((Feature[i].Preq = adSteamEngine) and
     373  J := 0;
     374  for I := 0 to nFeature - 1 do
     375    if (I in AutoFeature) and (1 shl Domain and Feature[I].Domains <> 0) and
     376      (Feature[I].Preq <> preNA) and
     377      ((Feature[I].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = Me)
     378      or (Feature[I].Preq >= 0) and (MyRO.Tech[Feature[I].Preq] >= tsApplicable)
     379      ) and not((Feature[I].Preq = adSteamEngine) and
    384380      (MyRO.Tech[adNuclearPower] >= tsApplicable)) then
    385381    begin
    386       DarkGradient(offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
    387         * j, 16, 1);
    388       Frame(offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * j,
    389         xWeight + 18, yWeight + 47 + LinePitch * j, $C0C0C0, $C0C0C0);
    390       Sprite(offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * j,
    391         10, 10, 66 + i mod 11 * 11, 137 + i div 11 * 11);
    392       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xWeight + 26,
    393         yWeight + 31 + LinePitch * j, Phrases.Lookup('FEATURES', i));
    394       inc(j);
    395     end;
    396 
    397   with Tribe[me].ModelPicture[MyRO.nModel] do
    398   begin
    399     FrameImage(offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
     382      DarkGradient(Offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
     383        * J, 16, 1);
     384      Frame(Offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * J,
     385        xWeight + 18, yWeight + 47 + LinePitch * J, $C0C0C0, $C0C0C0);
     386      Sprite(Offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * J,
     387        10, 10, 66 + I mod 11 * 11, 137 + I div 11 * 11);
     388      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xWeight + 26,
     389        yWeight + 31 + LinePitch * J, Phrases.Lookup('FEATURES', I));
     390      Inc(J);
     391    end;
     392
     393  with Tribe[Me].ModelPicture[MyRO.nModel] do
     394  begin
     395    FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
    400396      ySizeBig, 0, 0);
    401     Sprite(offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
     397    Sprite(Offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
    402398      pix div 10 * 49 + 1);
    403399  end;
    404400  MarkUsedOffscreen(ClientWidth, ClientHeight);
    405 end; { MainPaint }
    406 
    407 procedure TDraftDlg.SetDomain(d: integer);
    408 
    409   function Prio(fix: integer): integer;
     401end;
     402
     403procedure TDraftDlg.SetDomain(D: Integer);
     404
     405  function Prio(fix: Integer): Integer;
    410406  var
    411     FeaturePreq: integer;
     407    FeaturePreq: Integer;
    412408  begin
    413409    FeaturePreq := Feature[fix].Preq;
    414     assert(FeaturePreq <> preNA);
     410    Assert(FeaturePreq <> preNA);
    415411    if fix < mcFirstNonCap then
    416       result := 10000 + fix
     412      Result := 10000 + fix
    417413    else if FeaturePreq = preNone then
    418       result := 20000
     414      Result := 20000
    419415    else if FeaturePreq < 0 then
    420       result := 40000
     416      Result := 40000
    421417    else
    422       result := 30000 + AdvValue[FeaturePreq];
     418      Result := 30000 + AdvValue[FeaturePreq];
    423419    if not(fix in AutoFeature) then
    424       inc(result, 90000);
     420      Inc(Result, 90000);
    425421  end;
    426422
    427423var
    428   i, j, x: integer;
    429 begin
    430   Domain := d;
     424  I, J, X: Integer;
     425begin
     426  Domain := D;
    431427  Lines := 0;
    432   for i := 0 to nFeature - 1 do
    433     if IsFeatureInList(Domain, i) then
    434     begin
    435       code[Lines] := i;
    436       inc(Lines)
     428  for I := 0 to nFeature - 1 do
     429    if IsFeatureInList(Domain, I) then
     430    begin
     431      Code[Lines] := I;
     432      Inc(Lines);
    437433    end;
    438434  yFeature := yFeature0 + (MaxLines - Lines) * LinePitch div 2;
    439435
    440436  // sort features
    441   for i := 0 to Lines - 2 do
    442     for j := i + 1 to Lines - 1 do
    443       if Prio(code[i]) > Prio(code[j]) then
     437  for I := 0 to Lines - 2 do
     438    for J := I + 1 to Lines - 1 do
     439      if Prio(Code[I]) > Prio(Code[J]) then
    444440      begin // exchange
    445         x := code[i];
    446         code[i] := code[j];
    447         code[j] := x
     441        X := Code[I];
     442        Code[I] := Code[J];
     443        Code[J] := X;
    448444      end;
    449445end;
    450446
    451 function TDraftDlg.IsFeatureInList(d, i: integer): boolean;
    452 begin
    453   result := not(i in AutoFeature) and (1 shl d and Feature[i].Domains <> 0) and
    454     (Feature[i].Preq <> preNA) and
    455     ((Feature[i].Preq = preNone) or (Feature[i].Preq = preSun) and
    456     (MyRO.Wonder[woSun].EffectiveOwner = me) or (Feature[i].Preq >= 0) and
    457     (MyRO.Tech[Feature[i].Preq] >= tsApplicable));
     447function TDraftDlg.IsFeatureInList(D, I: Integer): Boolean;
     448begin
     449  Result := not(I in AutoFeature) and (1 shl D and Feature[I].Domains <> 0) and
     450    (Feature[I].Preq <> preNA) and
     451    ((Feature[I].Preq = preNone) or (Feature[I].Preq = preSun) and
     452    (MyRO.Wonder[woSun].EffectiveOwner = Me) or (Feature[I].Preq >= 0) and
     453    (MyRO.Tech[Feature[I].Preq] >= tsApplicable));
    458454end;
    459455
    460456procedure TDraftDlg.FormShow(Sender: TObject);
    461457var
    462   count, d, i: integer;
     458  count, D, I: Integer;
    463459begin
    464460  Domain := dGround;
    465461  while (Domain < dAir) and (upgrade[Domain, 0].Preq <> preNone) and
    466462    (MyRO.Tech[upgrade[Domain, 0].Preq] < tsApplicable) do
    467     inc(Domain);
     463    Inc(Domain);
    468464
    469465  // count max number of features in any domain
    470466  MaxLines := 0;
    471   for d := 0 to nDomains - 1 do
    472     if (upgrade[d, 0].Preq = preNone) or
    473       (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable) then
     467  for D := 0 to nDomains - 1 do
     468    if (upgrade[D, 0].Preq = preNone) or
     469      (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable) then
    474470    begin
    475471      count := 0;
    476       for i := 0 to nFeature - 1 do
    477         if IsFeatureInList(d, i) then
    478           inc(count);
     472      for I := 0 to nFeature - 1 do
     473        if IsFeatureInList(D, I) then
     474          Inc(count);
    479475      if count > MaxLines then
    480476        MaxLines := count;
     
    494490
    495491  SetDomain(Domain);
    496   Server(sCreateDevModel, me, Domain, nil^);
     492  Server(sCreateDevModel, Me, Domain, nil^);
    497493  MyModel[MyRO.nModel] := MyRO.DevModel;
    498   InitMyModel(MyRO.nModel, false);
     494  InitMyModel(MyRO.nModel, False);
    499495  OffscreenPaint;
    500496  IncCap := -1;
     
    502498end;
    503499
    504 procedure TDraftDlg.ShowNewContent(NewMode: integer);
     500procedure TDraftDlg.ShowNewContent(NewMode: TWindowMode);
    505501begin
    506502  inherited ShowNewContent(NewMode);
     
    508504
    509505procedure TDraftDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    510   Shift: TShiftState; x, y: integer);
     506  Shift: TShiftState; X, Y: Integer);
    511507var
    512   i, d: integer;
     508  I, D: Integer;
    513509begin
    514510  if Button = mbLeft then
    515511  begin
    516     for d := 0 to nDomains - 1 do
    517       if (d <> Domain) and ((upgrade[d, 0].Preq = preNone) or
    518         (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable)) and
    519         (x >= xDomain + d * DomainPitch) and
    520         (x < xDomain + d * DomainPitch + 36) and (y >= yDomain) and
    521         (y < yDomain + 36) then
     512    for D := 0 to nDomains - 1 do
     513      if (D <> Domain) and ((upgrade[D, 0].Preq = preNone) or
     514        (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable)) and
     515        (X >= xDomain + D * DomainPitch) and
     516        (X < xDomain + D * DomainPitch + 36) and (Y >= yDomain) and
     517        (Y < yDomain + 36) then
    522518      begin
    523         SetDomain(d);
    524         Server(sCreateDevModel, me, Domain, nil^);
     519        SetDomain(D);
     520        Server(sCreateDevModel, Me, Domain, nil^);
    525521        MyModel[MyRO.nModel] := MyRO.DevModel;
    526         InitMyModel(MyRO.nModel, false);
     522        InitMyModel(MyRO.nModel, False);
    527523        SmartUpdateContent;
    528524      end;
    529525
    530     if (y >= yFeature) and (y < yFeature + LinePitch * Lines) then
    531     begin
    532       i := (y - yFeature) div LinePitch;
    533       if (x >= xFeature - 21) and (x < ClientWidth) and (ssShift in Shift) then
    534         HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkFeature, code[i])
    535       else if not(code[i] in AutoFeature) then
     526    if (Y >= yFeature) and (Y < yFeature + LinePitch * Lines) then
     527    begin
     528      I := (Y - yFeature) div LinePitch;
     529      if (X >= xFeature - 21) and (X < ClientWidth) and (ssShift in Shift) then
     530        MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkFeature, Code[I])
     531      else if not(Code[I] in AutoFeature) then
    536532      begin
    537         if (code[i] < mcFirstNonCap) and (x >= xFeature - 21) and
    538           (x < xFeature - 21 + 12) then
     533        if (Code[I] < mcFirstNonCap) and (X >= xFeature - 21) and
     534          (X < xFeature - 21 + 12) then
    539535        begin
    540           IncCap := code[i];
    541           Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
    542             i, 12, 12, 182, 172);
     536          IncCap := Code[I];
     537          Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
     538            I, 12, 12, 182, 172);
    543539          SmartInvalidate;
    544540        end
    545         else if (x >= xFeature - 9) and (x < xFeature - 9 + 12) then
     541        else if (X >= xFeature - 9) and (X < xFeature - 9 + 12) then
    546542        begin
    547           DecCap := code[i];
    548           if code[i] < mcFirstNonCap then
    549             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    550               i, 12, 12, 182, 159)
     543          DecCap := Code[I];
     544          if Code[I] < mcFirstNonCap then
     545            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     546              I, 12, 12, 182, 159)
    551547          else
    552             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    553               i, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
     548            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     549              I, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[Code[I]]);
    554550          SmartInvalidate;
    555551        end;
    556       end
    557     end
    558   end
     552      end;
     553    end;
     554  end;
    559555end;
    560556
    561557procedure TDraftDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    562   Shift: TShiftState; x, y: integer);
     558  Shift: TShiftState; X, Y: Integer);
    563559var
    564   NewValue: integer;
     560  NewValue: Integer;
    565561begin
    566562  if IncCap >= 0 then
    567563  begin
    568564    NewValue := MyRO.DevModel.Cap[IncCap] + 1;
    569     Server(sSetDevModelCap + NewValue shl 4, me, IncCap, nil^);
     565    Server(sSetDevModelCap + NewValue shl 4, Me, IncCap, nil^);
    570566    MyModel[MyRO.nModel] := MyRO.DevModel;
    571     InitMyModel(MyRO.nModel, false);
     567    InitMyModel(MyRO.nModel, False);
    572568    SmartUpdateContent;
    573569    IncCap := -1;
     
    580576      if DecCap >= mcFirstNonCap then
    581577        NewValue := -NewValue;
    582       Server(sSetDevModelCap + NewValue shl 4, me, DecCap, nil^);
     578      Server(sSetDevModelCap + NewValue shl 4, Me, DecCap, nil^);
    583579      MyModel[MyRO.nModel] := MyRO.DevModel;
    584       InitMyModel(MyRO.nModel, false);
     580      InitMyModel(MyRO.nModel, False);
    585581    end;
    586582    SmartUpdateContent;
  • branches/highdpi/LocalPlayer/Enhance.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, ScreenTools, BaseWin, Protocol, ClientTools, Term, LCLIntf, LCLType,
    8 
    9   SysUtils, Classes, Graphics, Controls, Forms, IsoEngine,
    10   ButtonB, ButtonC, Menus;
     7  UDpiControls, ScreenTools, BaseWin, Protocol, ClientTools, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, IsoEngine, ButtonB, ButtonC, Menus;
    119
    1210type
     
    3937    NoMap: TIsoMap;
    4038  public
    41     procedure ShowNewContent(NewMode: integer; TerrType: integer = -1);
     39    procedure ShowNewContent(NewMode: TWindowMode; TerrType: Integer = -1);
    4240  protected
    43     Page: integer;
     41    Page: Integer;
    4442    procedure OffscreenPaint; override;
    4543  end;
    4644
    47 var
    48   EnhanceDlg: TEnhanceDlg;
    49 
    5045
    5146implementation
    5247
    5348uses
    54   Help, UKeyBindings;
     49  Help, KeyBindings, Term;
    5550
    5651{$R *.lfm}
     
    5853procedure TEnhanceDlg.FormCreate(Sender: TObject);
    5954var
    60   TerrType: integer;
    61   m: TDpiMenuItem;
     55  TerrType: Integer;
     56  M: TDpiMenuItem;
    6257begin
    6358  inherited;
     
    7368    if TerrType <> fJungle then
    7469    begin
    75       m := TDpiMenuItem.Create(Popup);
    76       m.RadioItem := true;
     70      M := TDpiMenuItem.Create(Popup);
     71      M.RadioItem := True;
    7772      if TerrType = fGrass then
    78         m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
     73        M.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
    7974          [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN',
    8075          fGrass + 12)])
    8176      else if TerrType = fForest then
    82         m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
     77        M.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
    8378          [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN',
    8479          fJungle)])
    8580      else
    86         m.Caption := Phrases.Lookup('TERRAIN', TerrType);
    87       m.Tag := TerrType;
    88       m.OnClick := TerrClick;
    89       Popup.Items.Add(m);
     81        M.Caption := Phrases.Lookup('TERRAIN', TerrType);
     82      M.Tag := TerrType;
     83      M.OnClick := TerrClick;
     84      Popup.Items.Add(M);
    9085    end;
    9186end;
     
    9893procedure TEnhanceDlg.FormPaint(Sender: TObject);
    9994var
    100   i: integer;
     95  I: Integer;
    10196begin
    10297  inherited;
     
    105100  BtnFrame(Canvas, Rect(job3.Left, job3.Top, job9.Left + job9.Width,
    106101    job3.Top + job3.Height), MainTexture);
    107   for i := 0 to ControlCount - 1 do
    108     if Controls[i] is TButtonC then
    109       DpiBitCanvas(Canvas, Controls[i].Left + 2, Controls[i].Top - 11, 8, 8,
    110         HGrSystem.Data.Canvas, 121 + Controls[i].Tag mod 7 * 9,
    111         1 + Controls[i].Tag div 7 * 9);
     102  for I := 0 to ControlCount - 1 do
     103    if Controls[I] is TButtonC then
     104      DpiBitBltCanvas(Canvas, Controls[I].Left + 2, Controls[I].Top - 11, 8, 8,
     105        HGrSystem.Data.Canvas, 121 + Controls[I].Tag mod 7 * 9,
     106        1 + Controls[I].Tag div 7 * 9);
    112107end;
    113108
     
    117112end;
    118113
    119 procedure TEnhanceDlg.ShowNewContent(NewMode, TerrType: integer);
     114procedure TEnhanceDlg.ShowNewContent(NewMode: TWindowMode; TerrType: Integer);
    120115begin
    121116  if (TerrType < fGrass) or (TerrType > fMountains) then
     
    128123procedure TEnhanceDlg.OffscreenPaint;
    129124var
    130   i, stage, TerrType, TileImp, x, EndStage, Cost, LastJob: integer;
    131   s: string;
    132   Done: Set of jNone .. jTrans;
    133   TypeChanged: boolean;
     125  I, stage, TerrType, TileImp, X, EndStage, Cost, LastJob: Integer;
     126  S: string;
     127  Done: set of jNone .. jTrans;
     128  TypeChanged: Boolean;
    134129begin
    135130  OffscreenUser := self;
    136   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     131  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    137132  FillOffscreen(0, 0, InnerWidth, InnerHeight);
    138133
    139134  EndStage := 0;
    140135  while (EndStage < 5) and (MyData.EnhancementJobs[Page, EndStage] <> jNone) do
    141     inc(EndStage);
     136    Inc(EndStage);
    142137  with NoMap do
    143     x := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
     138    X := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
    144139
    145140  TerrType := Page;
     
    151146    if stage > 0 then
    152147    begin
    153       Sprite(offscreen, HGrSystem, x - 10, 66, 14, 14, 80, 1);
     148      Sprite(Offscreen, HGrSystem, X - 10, 66, 14, 14, 80, 1);
    154149      case MyData.EnhancementJobs[Page, stage - 1] of
    155150        jRoad:
    156151          begin
    157             inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
     152            Inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
    158153            TileImp := TileImp or fRoad;
    159154          end;
    160155        jRR:
    161156          begin
    162             inc(Cost, Terrain[TerrType].MoveCost * RRWork);
     157            Inc(Cost, Terrain[TerrType].MoveCost * RRWork);
    163158            TileImp := TileImp or fRR;
    164159          end;
    165160        jIrr:
    166161          begin
    167             inc(Cost, Terrain[TerrType].IrrClearWork);
     162            Inc(Cost, Terrain[TerrType].IrrClearWork);
    168163            TileImp := TileImp and not fTerImp or tiIrrigation;
    169164          end;
    170165        jFarm:
    171166          begin
    172             inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
     167            Inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
    173168            TileImp := TileImp and not fTerImp or tiFarm;
    174169          end;
    175170        jMine:
    176171          begin
    177             inc(Cost, Terrain[TerrType].MineAfforestWork);
     172            Inc(Cost, Terrain[TerrType].MineAfforestWork);
    178173            TileImp := TileImp and not fTerImp or tiMine;
    179174          end;
    180175        jClear:
    181176          begin
    182             inc(Cost, Terrain[TerrType].IrrClearWork);
     177            Inc(Cost, Terrain[TerrType].IrrClearWork);
    183178            TerrType := Terrain[TerrType].ClearTerrain;
    184179          end;
    185180        jAfforest:
    186181          begin
    187             inc(Cost, Terrain[TerrType].MineAfforestWork);
     182            Inc(Cost, Terrain[TerrType].MineAfforestWork);
    188183            TerrType := Terrain[TerrType].AfforestTerrain;
    189184          end;
    190185        jTrans:
    191186          begin
    192             inc(Cost, Terrain[TerrType].TransWork);
     187            Inc(Cost, Terrain[TerrType].TransWork);
    193188            TerrType := Terrain[TerrType].TransTerrain;
    194189          end;
    195190      end;
    196       include(Done, MyData.EnhancementJobs[Page, stage - 1]);
     191      Include(Done, MyData.EnhancementJobs[Page, stage - 1]);
    197192    end;
    198193
    199194    with NoMap do begin
    200195      if TerrType < fForest then
    201         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     196        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    202197          1 + TerrType * (xxt * 2 + 1), 1 + yyt)
    203198      else
    204199      begin
    205         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     200        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    206201          1 + 2 * (xxt * 2 + 1), 1 + yyt + 2 * (yyt * 3 + 1));
    207         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     202        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    208203          1 + 7 * (xxt * 2 + 1), 1 + yyt + 2 * (2 + TerrType - fForest) *
    209204          (yyt * 3 + 1));
    210205      end;
    211206      if TileImp and fTerImp = tiFarm then
    212         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     207        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    213208          1 + (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1))
    214209      else if TileImp and fTerImp = tiIrrigation then
    215         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2, 1,
     210        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 1,
    216211          1 + yyt + 12 * (yyt * 3 + 1));
    217212      if TileImp and fRR <> 0 then
    218213      begin
    219         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     214        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    220215          1 + 6 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
    221         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     216        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    222217          1 + 2 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
    223218      end
    224219      else if TileImp and fRoad <> 0 then
    225220      begin
    226         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     221        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    227222          1 + 6 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
    228         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     223        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    229224          1 + 2 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
    230225      end;
    231226      if TileImp and fTerImp = tiMine then
    232         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     227        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    233228          1 + 2 * (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1));
    234       inc(x, xxt * 2 + 6);
    235     end;
    236   end;
    237 
    238   for i := 0 to Popup.Items.Count - 1 do
    239     if Popup.Items[i].Tag = Page then
    240       s := Popup.Items[i].Caption;
     229      Inc(X, xxt * 2 + 6);
     230    end;
     231  end;
     232
     233  for I := 0 to Popup.Items.Count - 1 do
     234    if Popup.Items[I].Tag = Page then
     235      S := Popup.Items[I].Caption;
    241236  if Cost > 0 then
    242     s := Format(Phrases.Lookup('ENHANCE'), [s, MovementToString(Cost)]);
    243   LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    244     (InnerWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 12, s);
     237    S := Format(Phrases.Lookup('ENHANCE'), [S, MovementToString(Cost)]);
     238  LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     239    (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 12, S);
    245240
    246241  if EndStage > 0 then
     
    291286    (Terrain[TerrType].MineEff > 0);
    292287  job3.Visible := not TypeChanged and (Terrain[TerrType].ClearTerrain >= 0) and
    293     ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = me)) or
     288    ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = Me)) or
    294289    (LastJob = jClear);
    295290  job6.Visible := not TypeChanged and (Terrain[TerrType].AfforestTerrain >= 0)
     
    299294
    300295  MarkUsedOffscreen(InnerWidth, InnerHeight);
    301 end; { OffscreenPaint }
     296end;
    302297
    303298procedure TEnhanceDlg.CloseBtnClick(Sender: TObject);
     
    308303procedure TEnhanceDlg.ToggleBtnClick(Sender: TObject);
    309304var
    310   i: integer;
    311 begin
    312   for i := 0 to Popup.Items.Count - 1 do
    313     Popup.Items[i].Checked := Popup.Items[i].Tag = Page;
     305  I: Integer;
     306begin
     307  for I := 0 to Popup.Items.Count - 1 do
     308    Popup.Items[I].Checked := Popup.Items[I].Tag = Page;
    314309  Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
    315310end;
     
    323318procedure TEnhanceDlg.JobClick(Sender: TObject);
    324319var
    325   stage, NewJob: integer;
     320  Stage, NewJob: Integer;
    326321  Done: Set of jNone .. jTrans;
    327322
    328   procedure RemoveJob(j: integer);
     323  procedure RemoveJob(J: Integer);
    329324  begin // remove job
    330     stage := 0;
    331     while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
    332     begin
    333       if (MyData.EnhancementJobs[Page, stage] = j) or (j = jRoad) and
    334         (MyData.EnhancementJobs[Page, stage] = jRR) or (j = jIrr) and
    335         (MyData.EnhancementJobs[Page, stage] = jFarm) then
     325    Stage := 0;
     326    while (Stage < 5) and (MyData.EnhancementJobs[Page, Stage] <> jNone) do
     327    begin
     328      if (MyData.EnhancementJobs[Page, Stage] = J) or (J = jRoad) and
     329        (MyData.EnhancementJobs[Page, Stage] = jRR) or (J = jIrr) and
     330        (MyData.EnhancementJobs[Page, Stage] = jFarm) then
    336331      begin
    337         if stage < 4 then
    338           move(MyData.EnhancementJobs[Page, stage + 1],
    339             MyData.EnhancementJobs[Page, stage], 4 - stage);
     332        if Stage < 4 then
     333          Move(MyData.EnhancementJobs[Page, Stage + 1],
     334            MyData.EnhancementJobs[Page, Stage], 4 - Stage);
    340335        MyData.EnhancementJobs[Page, 4] := jNone;
    341336      end
    342337      else
    343         inc(stage);
     338        Inc(Stage);
    344339    end;
    345340  end;
     
    348343  NewJob := TButtonC(Sender).Tag;
    349344  Done := [];
    350   stage := 0;
    351   while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
     345  Stage := 0;
     346  while (Stage < 5) and (MyData.EnhancementJobs[Page, Stage] <> jNone) do
    352347  begin
    353     include(Done, MyData.EnhancementJobs[Page, stage]);
    354     inc(stage);
     348    Include(Done, MyData.EnhancementJobs[Page, Stage]);
     349    Inc(Stage);
    355350  end;
    356351  if NewJob in Done then
     
    364359    if (NewJob = jRR) and not(jRoad in Done) then
    365360    begin
    366       MyData.EnhancementJobs[Page, stage] := jRoad;
    367       inc(stage);
     361      MyData.EnhancementJobs[Page, Stage] := jRoad;
     362      Inc(Stage);
    368363    end;
    369364    if (NewJob = jFarm) and not(jIrr in Done) then
    370365    begin
    371       MyData.EnhancementJobs[Page, stage] := jIrr;
    372       inc(stage);
    373     end;
    374     MyData.EnhancementJobs[Page, stage] := NewJob;
     366      MyData.EnhancementJobs[Page, Stage] := jIrr;
     367      Inc(Stage);
     368    end;
     369    MyData.EnhancementJobs[Page, Stage] := NewJob;
    375370  end;
    376371  SmartUpdateContent;
     
    384379  ShortCut := KeyToShortCut(Key, Shift);
    385380  if BHelp.Test(ShortCut) then
    386     HelpDlg.ShowNewContent(FWindowMode or wmPersistent, hkText,
    387       HelpDlg.TextIndex('MACRO'))
     381    MainScreen.HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkText,
     382      MainScreen.HelpDlg.TextIndex('MACRO'))
    388383end;
    389384
  • branches/highdpi/LocalPlayer/Help.pas

    r412 r465  
    77  UDpiControls, Protocol, ScreenTools, BaseWin, StringTables, Math, LCLIntf, LCLType,
    88  Messages, SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
    9   ButtonB, PVSB, Types, fgl, IsoEngine;
     9  ButtonB, PVSB, Types, Generics.Collections, IsoEngine;
    1010
    1111const
    1212  MaxHist = 16;
    1313
    14   { link categories }
    15   hkNoLink = 0;
    16   hkAdv = 1;
    17   hkImp = 2;
    18   hkTer = 3;
    19   hkFeature = 4;
    20   hkInternet = 5;
    21   hkModel = 6;
    22   hkMisc = 7;
    23   hkCrossLink = $40;
    24   hkText = $80;
    25 
    26   liInvalid = $3FFF; // link index indicates invalid link
    27 
    28   { link indices for category hkMisc }
    29   miscMain = 0;
    30   miscCredits = 1;
    31   miscGovList = 2;
    32   miscJobList = 3;
    33   miscSearchResult = 7;
    34 
    35   fJungle = 8; // pseudo terrain
     14  fJungle = 8; // Pseudo terrain
    3615
    3716type
     17  { Link categories }
     18  TLinkCategory = (
     19    hkNoLink,
     20    hkAdv,
     21    hkImp,
     22    hkTer,
     23    hkFeature ,
     24    hkInternet,
     25    hkModel,
     26    hkMisc,
     27    hkText);
     28
     29  { Link indices for category hkMisc }
     30  TMiscLinkIndex = (
     31    miscMain,
     32    miscCredits,
     33    miscGovList,
     34    miscJobList,
     35    miscSearchResult);
     36
     37  TTextFormat = (
     38    pkNormal,
     39    pkCaption,
     40    pkSmallIcon,
     41    pkBigIcon,
     42    pkAdvIcon,
     43    pkTer,
     44    pkBigTer,
     45    pkFeature,
     46    pkDot,
     47    pkNormal_Dot,
     48    pkDomain,
     49    pkSection,
     50    pkBigFeature,
     51    pkExp,
     52    pkAITStat,
     53    pkExternal,
     54    pkModel,
     55    pkNormal_64,
     56    pkIllu,
     57    pkLogo,
     58    pkTerImp,
     59    pkRightIcon,
     60    pkAdvIcon_AsPreq,
     61    pkSmallIcon_AsPreq,
     62    pkSpecialIcon,
     63    pkGov);
    3864
    3965  { THyperText }
     
    4167  THyperText = class(TStringList)
    4268  public
    43     procedure AddLine(s: String = ''; Format: integer = 0; Picpix: Integer = 0;
    44       LinkCategory: integer = 0; LinkIndex: integer = 0);
     69    procedure AddLine(S: String = ''; Format: TTextFormat = pkNormal; Picpix: Integer = 0;
     70      LinkCategory: TLinkCategory = hkNoLink; LinkIndex: Integer = 0; CrossLink: Boolean = False);
    4571    procedure LineFeed;
    4672    procedure AppendList(Source: THyperText);
    47     destructor Destroy; override;
    4873  end;
    4974
     
    5176
    5277  THistItem = class
    53     Kind: Integer;
     78    Kind: TLinkCategory;
    5479    No: Integer;
    5580    Pos: Integer;
     
    6085  { THistItems }
    6186
    62   THistItems = class(TFPGObjectList<THistItem>)
    63     function AddNew(Kind, No, Pos: Integer; SearchContent: string): THistItem;
     87  THistItems = class(TObjectList<THistItem>)
     88    function AddNew(Kind: TLinkCategory; No, Pos: Integer; SearchContent: string): THistItem;
    6489  end;
    6590
     
    78103    procedure CloseBtnClick(Sender: TObject);
    79104    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    80       x, y: integer);
     105      X, Y: Integer);
    81106    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    82       Shift: TShiftState; x, y: integer);
     107      Shift: TShiftState; X, Y: Integer);
    83108    procedure BackBtnClick(Sender: TObject);
    84109    procedure TopBtnClick(Sender: TObject);
     
    89114    procedure OffscreenPaint; override;
    90115  private
    91     Kind: Integer;
    92     no: Integer;
     116    Kind: TLinkCategory;
     117    No: Integer;
    93118    Sel: Integer;
    94119    CaptionColor: Integer;
     
    100125    SearchResult: THyperText;
    101126    HelpText: TStringTable;
    102     ExtPic, TerrIcon: TDpiBitmap;
     127    ExtPic: TDpiBitmap;
     128    TerrIcon: TDpiBitmap;
    103129    ScrollBar: TPVScrollbar;
    104130    NoMap: TIsoMap;
    105131    x0: array [-2..180] of Integer;
    106     procedure PaintTerrIcon(x, y, xSrc, ySrc: Integer);
     132    procedure PaintTerrIcon(X, Y, xSrc, ySrc: Integer);
    107133    procedure ScrollBarUpdate(Sender: TObject);
    108     procedure Line(ca: TDpiCanvas; i: Integer; lit: Boolean);
     134    procedure Line(ACanvas: TDpiCanvas; I: Integer; Lit: Boolean);
    109135    procedure Prepare(sbPos: Integer = 0);
    110     procedure ShowNewContentProcExecute(NewMode: Integer; HelpContext: string);
     136    procedure ShowNewContentProcExecute(NewMode: TWindowMode; HelpContext: string);
    111137    procedure WaterSign(x0, y0, iix: Integer);
    112138    procedure Search(SearchString: string);
     
    117143    Difficulty: Integer;
    118144    procedure ClearHistory;
    119     procedure ShowNewContent(NewMode, Category, Index: Integer);
     145    procedure ShowNewContent(NewMode: TWindowMode; Category: TLinkCategory; Index: Integer);
    120146    function TextIndex(Item: string): Integer;
    121147  end;
    122148
    123 var
    124   HelpDlg: THelpDlg;
    125 
    126149
    127150implementation
    128151
    129152uses
    130   Directories, ClientTools, Term, Tribes, Inp, Messg, UPixelPointer, Global,
    131   UKeyBindings;
     153  Directories, ClientTools, Term, Tribes, Inp, Messg, PixelPointer, Global,
     154  KeyBindings;
    132155
    133156{$R *.lfm}
     
    138161
    139162  THelpLineInfo = class
    140     Format: Byte;
     163    Format: TTextFormat;
    141164    Picpix: Byte;
    142     Link: Word;
     165    Category: TLinkCategory;
     166    Index: Integer;
     167    CrossLink: Boolean;
    143168    procedure Assign(Source: THelpLineInfo);
    144169  end;
    145170
    146 { THelpLineInfo }
    147 
    148 procedure THelpLineInfo.Assign(Source: THelpLineInfo);
    149 begin
    150   Format := Source.Format;
    151   PicPix := Source.PicPix;
    152   Link := Source.Link;
    153 end;
    154 
    155 { THistItem }
    156 
    157 procedure THistItem.Assign(Source: THistItem);
    158 begin
    159   Kind := Source.Kind;
    160   No := Source.No;
    161   Pos := Source.Pos;
    162   SearchContent := Source.SearchContent;
    163 end;
    164 
    165 { THistItems }
    166 
    167 function THistItems.AddNew(Kind, No, Pos: Integer; SearchContent: string
    168   ): THistItem;
    169 begin
    170   Result := THistItem.Create;
    171   Result.Kind := Kind;
    172   Result.No := No;
    173   Result.Pos := Pos;
    174   Result.SearchContent := SearchContent;
    175   Add(Result);
    176 end;
    177 
    178 procedure THyperText.AddLine(s: String; Format: integer; Picpix: integer;
    179   LinkCategory: integer; LinkIndex: integer);
    180 var
    181   HelpLineInfo: THelpLineInfo;
    182 begin
    183   HelpLineInfo := THelpLineInfo.Create;
    184   if LinkIndex < 0 then
    185     LinkIndex := liInvalid;
    186   HelpLineInfo.Format := Format;
    187   HelpLineInfo.Picpix := Picpix;
    188   HelpLineInfo.Link := LinkCategory shl 8 + LinkIndex;
    189   AddObject(s, TObject(HelpLineInfo));
    190 end;
    191 
    192 procedure THyperText.LineFeed;
    193 begin
    194   AddLine;
    195 end;
    196 
    197 procedure THyperText.AppendList(Source: THyperText);
    198 var
    199   I: Integer;
    200   HelpLineInfo: THelpLineInfo;
    201 begin
    202   for I := 0 to Source.Count - 1 do begin
    203     HelpLineInfo := THelpLineInfo.Create;
    204     HelpLineInfo.Assign(THelpLineInfo(Source.Objects[I]));
    205     AddObject(Source.Strings[I], HelpLineInfo);
    206   end;
    207 end;
    208 
    209 destructor THyperText.Destroy;
    210 begin
    211   inherited;
    212 end;
     171  TSeeAlso = record
     172    Kind: TLinkCategory;
     173    No: Integer;
     174    SeeKind: TLinkCategory;
     175    SeeNo: Integer;
     176  end;
    213177
    214178const
    215   { text formats }
    216   pkNormal = 0;
    217   pkCaption = 1;
    218   pkSmallIcon = 2;
    219   pkBigIcon = 3;
    220   pkAdvIcon = 4;
    221   pkTer = 5;
    222   pkBigTer = 6;
    223   pkFeature = 7;
    224   pkDot = 8;
    225   pkNormal_Dot = 9;
    226   pkDomain = 10;
    227   pkSection = 11;
    228   pkBigFeature = 12;
    229   pkExp = 13;
    230   pkAITStat = 14;
    231   pkExternal = 15;
    232   pkModel = 16;
    233   pkNormal_64 = 17;
    234   pkIllu = 18;
    235   pkLogo = 19;
    236   pkTerImp = 20;
    237   pkRightIcon = 21;
    238   pkAdvIcon_AsPreq = 22;
    239   pkSmallIcon_AsPreq = 23;
    240   pkSpecialIcon = 24;
    241   pkGov = 25;
    242 
    243   nSeeAlso = 14;
    244   SeeAlso: array [0 .. nSeeAlso - 1] of record
    245     Kind: Integer;
    246     no: Integer;
    247     SeeKind: Integer;
    248     SeeNo: Integer;
    249   end = ((Kind: hkImp; no: imWalls; SeeKind: hkFeature;
     179  SeeAlso: array[0..13] of TSeeAlso = ((Kind: hkImp; no: imWalls; SeeKind: hkFeature;
    250180    SeeNo: mcArtillery), (Kind: hkImp; no: imHydro; SeeKind: hkImp;
    251181    SeeNo: woHoover), (Kind: hkImp; no: imWalls; SeeKind: hkImp;
     
    262192    SeeKind: hkFeature; SeeNo: mcDefense));
    263193
    264   nTerrainHelp = 14;
    265   TerrainHelp: array [0 .. nTerrainHelp - 1] of integer = (fGrass, fGrass + 12,
     194  TerrainHelp: array[0..13] of Integer = (fGrass, fGrass + 12,
    266195    fPrairie, fForest, fJungle, fHills, fMountains, fSwamp, fTundra, fArctic,
    267     fDesert, 3 * 12 { DeadLands } , fShore, fOcean);
    268 
    269   nJobHelp = 8;
    270   JobHelp: array [0 .. nJobHelp - 1] of integer = (jRoad, jRR, jCanal, jIrr,
     196    fDesert, 3 * 12 { DeadLands }, fShore, fOcean);
     197
     198  JobHelp: array[0..7] of Integer = (jRoad, jRR, jCanal, jIrr,
    271199    jFarm, jMine, jFort, jBase);
    272200
     201{ THelpLineInfo }
     202
     203procedure THelpLineInfo.Assign(Source: THelpLineInfo);
     204begin
     205  Format := Source.Format;
     206  PicPix := Source.PicPix;
     207  Category := Source.Category;
     208  Index := Source.Index;
     209end;
     210
     211{ THistItem }
     212
     213procedure THistItem.Assign(Source: THistItem);
     214begin
     215  Kind := Source.Kind;
     216  No := Source.No;
     217  Pos := Source.Pos;
     218  SearchContent := Source.SearchContent;
     219end;
     220
     221{ THistItems }
     222
     223function THistItems.AddNew(Kind: TLinkCategory; No, Pos: Integer; SearchContent: string
     224  ): THistItem;
     225begin
     226  Result := THistItem.Create;
     227  Result.Kind := Kind;
     228  Result.No := No;
     229  Result.Pos := Pos;
     230  Result.SearchContent := SearchContent;
     231  Add(Result);
     232end;
     233
     234procedure THyperText.AddLine(S: String; Format: TTextFormat; Picpix: Integer;
     235  LinkCategory: TLinkCategory = hkNoLink; LinkIndex: Integer = 0;
     236  CrossLink: Boolean = False);
     237var
     238  HelpLineInfo: THelpLineInfo;
     239begin
     240  HelpLineInfo := THelpLineInfo.Create;
     241  HelpLineInfo.Format := Format;
     242  HelpLineInfo.Picpix := Picpix;
     243  HelpLineInfo.Category := LinkCategory;
     244  HelpLineInfo.Index := LinkIndex;
     245  HelpLineInfo.CrossLink := CrossLink;
     246  AddObject(S, HelpLineInfo);
     247end;
     248
     249procedure THyperText.LineFeed;
     250begin
     251  AddLine;
     252end;
     253
     254procedure THyperText.AppendList(Source: THyperText);
     255var
     256  I: Integer;
     257  HelpLineInfo: THelpLineInfo;
     258begin
     259  for I := 0 to Source.Count - 1 do begin
     260    HelpLineInfo := THelpLineInfo.Create;
     261    HelpLineInfo.Assign(THelpLineInfo(Source.Objects[I]));
     262    AddObject(Source.Strings[I], HelpLineInfo);
     263  end;
     264end;
     265
    273266procedure THelpDlg.FormCreate(Sender: TObject);
    274267begin
    275   inherited;
    276268  NoMap := TIsoMap.Create;
    277269
     
    280272  CaptionLeft := BackBtn.Left + BackBtn.Width;
    281273  CaptionRight := SearchBtn.Left;
    282   inc(ModalFrameIndent, 29);
     274  Inc(ModalFrameIndent, 29);
    283275  MainText := THyperText.Create;
    284276  MainText.OwnsObjects := True;
     
    290282
    291283  HelpText := TStringTable.Create;
    292   HelpText.LoadFromFile(LocalizedFilePath('Help' + DirectorySeparator + 'help.txt'));
     284  HelpText.LoadFromFile(LocalizedFilePath('Help' + DirectorySeparator + 'Help.txt'));
    293285  hADVHELP := HelpText.Gethandle('ADVHELP');
    294286  hIMPHELP := HelpText.Gethandle('IMPHELP');
     
    316308end;
    317309
    318 procedure THelpDlg.ShowNewContentProcExecute(NewMode: Integer;
     310procedure THelpDlg.ShowNewContentProcExecute(NewMode: TWindowMode;
    319311  HelpContext: string);
    320312begin
    321   HelpDlg.ShowNewContent(NewMode, hkText,
    322     HelpDlg.TextIndex(HelpContext))
     313  ShowNewContent(NewMode, hkText, TextIndex(HelpContext));
    323314end;
    324315
     
    356347  if ScrollBar.Process(Msg) then begin
    357348    Sel := -1;
    358     SmartUpdateContent(true)
     349    SmartUpdateContent(True)
    359350  end;
    360351  }
     
    364355begin
    365356  if Sel <> -1 then begin
    366     Line(Canvas, Sel, false);
    367     Sel := -1
     357    Line(Canvas, Sel, False);
     358    Sel := -1;
    368359  end;
    369360end;
     
    380371end;
    381372
    382 procedure THelpDlg.Line(ca: TDpiCanvas; i: Integer; lit: Boolean);
     373procedure THelpDlg.Line(ACanvas: TDpiCanvas; I: Integer; Lit: Boolean);
    383374var
    384   TextColor, x, y: Integer;
     375  TextColor: TColor;
     376  X, Y: Integer;
    385377  TextSize: TSize;
    386   s: string;
    387 begin
    388   s := MainText[ScrollBar.Position + i];
    389   if s = '' then
     378  S: string;
     379begin
     380  S := MainText[ScrollBar.Position + I];
     381  if S = '' then
    390382    Exit;
    391   x := x0[i];
    392   y := 2 + i * 24;
    393   if ca = Canvas then
    394   begin
    395     x := x + SideFrame;
    396     y := y + WideFrame
    397   end;
    398   if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format
     383  X := x0[I];
     384  Y := 2 + I * 24;
     385  if ACanvas = Canvas then
     386  begin
     387    X := X + SideFrame;
     388    Y := Y + WideFrame;
     389  end;
     390  if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format
    399391    in [pkCaption, pkBigTer, pkRightIcon, pkBigFeature] then
    400392  begin
    401     ca.Font.Assign(CaptionFont);
    402     { ca.brush.color:=CaptionColor;
    403       ca.FillRect(rect(x,i*24,x+24,i*24+24));
    404       ca.brush.color:=$FFFFFF;
    405       ca.FrameRect(rect(x+1,i*24+1,x+24-1,i*24+24-1));
    406       ca.Brush.Style:=bsClear; }
    407     DpiBitCanvas(ca, x, y - 4, 24, 24, HGrSystem.Data.Canvas, 1,
     393    ACanvas.Font.Assign(CaptionFont);
     394    { ACanvas.brush.color:=CaptionColor;
     395      ACanvas.FillRect(rect(X,I*24,X+24,I*24+24));
     396      ACanvas.Brush.Color:=$FFFFFF;
     397      ACanvas.FrameRect(rect(X+1,I*24+1,X+24-1,I*24+24-1));
     398      ACanvas.Brush.Style:=bsClear; }
     399    DpiBitBltCanvas(ACanvas, X, Y - 4, 24, 24, HGrSystem.Data.Canvas, 1,
    408400      146);
    409     BiColorTextOut(ca, $FFFFFF, $7F007F, x + 10 - ca.Textwidth(s[1]) div 2,
    410       y - 3, s[1]);
    411     BiColorTextOut(ca, CaptionColor, $7F007F, x + 24, y - 3, copy(s, 2, 255));
    412     ca.Font.Assign(UniFont[ftNormal]);
     401    BiColorTextOut(ACanvas, $FFFFFF, $7F007F, X + 10 - ACanvas.Textwidth(S[1]) div 2,
     402      Y - 3, S[1]);
     403    BiColorTextOut(ACanvas, CaptionColor, $7F007F, X + 24, Y - 3, Copy(S, 2, 255));
     404    ACanvas.Font.Assign(UniFont[ftNormal]);
    413405  end
    414   else if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format = pkSection
    415   then
    416   begin
    417     ca.Font.Assign(CaptionFont);
    418     BiColorTextOut(ca, CaptionColor, $7F007F, x, y - 3, s);
    419     ca.Font.Assign(UniFont[ftNormal]);
     406  else if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format = pkSection then
     407  begin
     408    ACanvas.Font.Assign(CaptionFont);
     409    BiColorTextOut(ACanvas, CaptionColor, $7F007F, X, Y - 3, S);
     410    ACanvas.Font.Assign(UniFont[ftNormal]);
    420411  end
    421412  else
    422413  begin
    423     if (Kind = hkMisc) and (no = miscMain) then
    424       ca.Font.Assign(CaptionFont);
     414    if (Kind = hkMisc) and (No = Integer(miscMain)) then
     415      ACanvas.Font.Assign(CaptionFont);
    425416    TextColor := Colors.Canvas.Pixels[clkMisc, cliPaperText];
    426     if ca = Canvas then
     417    if ACanvas = Canvas then
    427418    begin
    428       TextSize.cx := BiColorTextWidth(ca, s);
    429       TextSize.cy := ca.TextHeight(s);
    430       if y + TextSize.cy >= WideFrame + InnerHeight then
    431         TextSize.cy := WideFrame + InnerHeight - y;
    432       FillSeamless(ca, x, y, TextSize.cx, TextSize.cy, -SideFrame,
     419      TextSize.cx := BiColorTextWidth(ACanvas, S);
     420      TextSize.cy := ACanvas.TextHeight(S);
     421      if Y + TextSize.cy >= WideFrame + InnerHeight then
     422        TextSize.cy := WideFrame + InnerHeight - Y;
     423      FillSeamless(ACanvas, X, Y, TextSize.cx, TextSize.cy, -SideFrame,
    433424        ScrollBar.Position * 24 - WideFrame, Paper);
    434425    end;
    435     BiColorTextOut(ca, TextColor, $7F007F, x, y, s);
     426    BiColorTextOut(ACanvas, TextColor, $7F007F, X, Y, S);
    436427    if lit then
    437       with ca do
     428      with ACanvas do
    438429      begin
    439         Assert(ca = Canvas);
     430        Assert(ACanvas = Canvas);
    440431        Pen.Color := TextColor;
    441         MoveTo(x + 1, y + TextSize.cy - 2);
    442         LineTo(x + TextSize.cx, y + TextSize.cy - 2);
     432        MoveTo(X + 1, Y + TextSize.cy - 2);
     433        LineTo(X + TextSize.cx, Y + TextSize.cy - 2);
    443434      end;
    444     if (Kind = hkMisc) and (no = miscMain) then
    445       ca.Font.Assign(UniFont[ftNormal]);
    446   end;
    447 end;
    448 
    449 procedure THelpDlg.WaterSign(x0, y0, iix: integer);
     435    if (Kind = hkMisc) and (No = Integer(miscMain)) then
     436      ACanvas.Font.Assign(UniFont[ftNormal]);
     437  end;
     438end;
     439
     440procedure THelpDlg.WaterSign(x0, y0, iix: Integer);
    450441const
    451442  nHeaven = 28;
    452443  MaxSum = 9 * 9 * 255 * 75 div 100;
    453444var
    454   x, y, dx, dy, xSrc, ySrc, Sum, xx: integer;
    455   Heaven: array [0..nHeaven] of integer;
     445  X, Y, dx, dy, xSrc, ySrc, Sum, xx: Integer;
     446  Heaven: array [0..nHeaven] of Integer;
    456447  PaintPtr: TPixelPointer;
    457448  CoalPtr: TPixelPointer;
     
    467458  xSrc := iix mod 7 * xSizeBig;
    468459  ySrc := (iix div 7 + 1) * ySizeBig;
    469   PaintPtr := PixelPointer(OffScreen, ScaleToNative(x0), ScaleToNative(y0));
    470   CoalPtr := PixelPointer(Templates.Data, ScaleToNative(xCoal), ScaleToNative(yCoal));
     460  PaintPtr := TPixelPointer.Create(OffScreen, ScaleToNative(x0), ScaleToNative(y0));
     461  CoalPtr := TPixelPointer.Create(Templates.Data, ScaleToNative(xCoal), ScaleToNative(yCoal));
    471462  for dy := -1 to 1 do
    472     ImpPtr[dy] := PixelPointer(BigImp, ScaleToNative(xSrc), ScaleToNative(ySrc));
    473   for y := 0 to ScaleToNative(ySizeBig) * 2 - 1 do begin
    474     if ((ScaleToNative(y0) + y) >= 0) and ((ScaleToNative(y0) + y) < ScaleToNative(InnerHeight)) then begin
     463    ImpPtr[dy] := TPixelPointer.Create(BigImp, ScaleToNative(xSrc), ScaleToNative(ySrc));
     464  for Y := 0 to ScaleToNative(ySizeBig) * 2 - 1 do begin
     465    if ((ScaleToNative(y0) + Y) >= 0) and ((ScaleToNative(y0) + Y) < ScaleToNative(InnerHeight)) then begin
    475466      for dy := -1 to 1 do
    476         if ((Max(y + ScaleToNative(dy), 0) shr 1) >= 0) and ((Max(y + ScaleToNative(dy), 0) shr 1) < ScaleToNative(ySizeBig)) then
    477           ImpPtr[dy].SetXY(0, Max(y + ScaleToNative(dy), 0) shr 1);
    478       for x := 0 to ScaleToNative(xSizeBig * 2) - 1 do begin
     467        if ((Max(Y + ScaleToNative(dy), 0) shr 1) >= 0) and ((Max(Y + ScaleToNative(dy), 0) shr 1) < ScaleToNative(ySizeBig)) then
     468          ImpPtr[dy].SetXY(0, Max(Y + ScaleToNative(dy), 0) shr 1);
     469      for X := 0 to ScaleToNative(xSizeBig * 2) - 1 do begin
    479470        Sum := 0;
    480471        for dx := -1 to 1 do begin
    481           xx := Max((x + ScaleToNative(dx)), 0) shr 1;
     472          xx := Max((X + ScaleToNative(dx)), 0) shr 1;
    482473          for dy := -1 to 1 do begin
    483474            ImpPtr[dy].SetX(xx);
    484             if ((y + ScaleToNative(dy)) shr 1 < 0) or ((y + ScaleToNative(dy)) shr 1 >= ScaleToNative(ySizeBig)) or
    485               ((x + ScaleToNative(dx)) shr 1 < 0) or ((x + ScaleToNative(dx)) shr 1 >= ScaleToNative(xSizeBig)) or
    486               ((y + ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and
     475            if ((Y + ScaleToNative(dy)) shr 1 < 0) or ((Y + ScaleToNative(dy)) shr 1 >= ScaleToNative(ySizeBig)) or
     476              ((X + ScaleToNative(dx)) shr 1 < 0) or ((X + ScaleToNative(dx)) shr 1 >= ScaleToNative(xSizeBig)) or
     477              ((Y + ScaleToNative(dy)) shr 1 < ScaleToNative(nHeaven)) and
    487478              (ImpPtr[dy].Pixel^.B shl 16 + ImpPtr[dy].Pixel^.G shl 8 +
    488               ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(y + ScaleToNative(dy))) shr 1]) then
     479              ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(Y + ScaleToNative(dy))) shr 1]) then
    489480              Sum := Sum + 9 * 255
    490481            else
     
    493484          end;
    494485        end;
    495         if Sum < MaxSum then begin // no saturation
     486        if Sum < MaxSum then begin // No saturation
    496487          Sum := 1 shl 22 - (MaxSum - Sum) * (256 - CoalPtr.Pixel^.B * 2);
    497488          PaintPtr.Pixel^.B := Min(PaintPtr.Pixel^.B * Sum shr 22, 255);
     
    510501end;
    511502
    512 procedure THelpDlg.PaintTerrIcon(x, y, xSrc, ySrc: integer);
     503procedure THelpDlg.PaintTerrIcon(X, Y, xSrc, ySrc: Integer);
    513504begin
    514505  with NoMap do begin
    515     Frame(OffScreen.Canvas, x - 1, y - 1, x + xSizeBig, y + ySizeBig,
     506    Frame(OffScreen.Canvas, X - 1, Y - 1, X + xSizeBig, Y + ySizeBig,
    516507      $000000, $000000);
    517508    if 2 * yyt < 40 then begin
    518       Sprite(OffScreen, HGrTerrain, x, y, 56, 2 * yyt, xSrc, ySrc);
    519       Sprite(OffScreen, HGrTerrain, x, y + 2 * yyt, 56, 40 - 2 * yyt,
     509      Sprite(OffScreen, HGrTerrain, X, Y, 56, 2 * yyt, xSrc, ySrc);
     510      Sprite(OffScreen, HGrTerrain, X, Y + 2 * yyt, 56, 40 - 2 * yyt,
    520511        xSrc, ySrc);
    521512    end else
    522       Sprite(OffScreen, HGrTerrain, x, y, 56, 40, xSrc, ySrc);
    523     Sprite(OffScreen, HGrTerrain, x, y, xxt, yyt, xSrc + xxt, ySrc + yyt);
    524     Sprite(OffScreen, HGrTerrain, x, y + yyt, xxt, 40 - yyt, xSrc + xxt, ySrc);
    525     Sprite(OffScreen, HGrTerrain, x + xxt, y, 56 - xxt, yyt, xSrc, ySrc + yyt);
    526     Sprite(OffScreen, HGrTerrain, x + xxt, y + yyt, 56 - xxt, 40 - yyt,
     513      Sprite(OffScreen, HGrTerrain, X, Y, 56, 40, xSrc, ySrc);
     514    Sprite(OffScreen, HGrTerrain, X, Y, xxt, yyt, xSrc + xxt, ySrc + yyt);
     515    Sprite(OffScreen, HGrTerrain, X, Y + yyt, xxt, 40 - yyt, xSrc + xxt, ySrc);
     516    Sprite(OffScreen, HGrTerrain, X + xxt, Y, 56 - xxt, yyt, xSrc, ySrc + yyt);
     517    Sprite(OffScreen, HGrTerrain, X + xxt, Y + yyt, 56 - xxt, 40 - yyt,
    527518      xSrc, ySrc);
    528519  end;
     
    531522procedure THelpDlg.OffscreenPaint;
    532523var
    533   i, j, yl, srcno, ofs, cnt, y: Integer;
    534   s: string;
     524  I, J, yl, srcno, ofs, cnt, Y: Integer;
     525  S: string;
    535526  HelpLineInfo: THelpLineInfo;
    536527begin
     
    542533  begin
    543534    Font.Assign(UniFont[ftNormal]);
    544     for i := -ScrollBar.Position to InnerHeight div 24 do
    545       if ScrollBar.Position + i < MainText.Count then
     535    for I := -ScrollBar.Position to InnerHeight div 24 do
     536      if ScrollBar.Position + I < MainText.Count then
    546537      begin
    547         HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);
     538        HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]);
    548539        if HelpLineInfo.Format = pkExternal then
    549540        begin
    550541          yl := ExtPic.Height;
    551           if 4 + i * 24 + yl > InnerHeight then
    552             yl := InnerHeight - (4 + i * 24);
    553           DpiBitCanvas(OffScreen.Canvas, 8, 4 + i * 24, ExtPic.Width, yl, ExtPic.Canvas,
     542          if 4 + I * 24 + yl > InnerHeight then
     543            yl := InnerHeight - (4 + I * 24);
     544          DpiBitBltCanvas(OffScreen.Canvas, 8, 4 + I * 24, ExtPic.Width, yl, ExtPic.Canvas,
    554545            0, 0);
    555546        end;
    556547      end;
    557     for i := -2 to InnerHeight div 24 do
    558       if (ScrollBar.Position + i >= 0) and (ScrollBar.Position + i < MainText.Count) then
     548    for I := -2 to InnerHeight div 24 do
     549      if (ScrollBar.Position + I >= 0) and (ScrollBar.Position + I < MainText.Count) then
    559550      begin
    560         HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);
    561         if HelpLineInfo.Link <> 0 then
     551        HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]);
     552        if (HelpLineInfo.Category <> hkNoLink) or (HelpLineInfo.Index <> 0) then
    562553        begin
    563           if (Kind = hkMisc) and (no = miscSearchResult) then
    564             Sprite(OffScreen, HGrSystem, 18, 9 + i * 24, 8, 8, 90, 16)
     554          if (Kind = hkMisc) and (No = Integer(miscSearchResult)) then
     555            Sprite(OffScreen, HGrSystem, 18, 9 + I * 24, 8, 8, 90, 16)
    565556          else if HelpLineInfo.Format in [pkSmallIcon_AsPreq, pkAdvIcon_AsPreq]
    566557          then
    567             Sprite(OffScreen, HGrSystem, 12, i * 24 + 5, 14, 14, 65, 20)
    568           else if HelpLineInfo.Link and (hkCrossLink shl 8) <> 0 then
    569             Sprite(OffScreen, HGrSystem, 12, i * 24 + 5, 14, 14, 80, 1)
    570           else if not((Kind = hkMisc) and (no = miscMain)) then
    571             Sprite(OffScreen, HGrSystem, 10, i * 24 + 6, 14, 14, 65, 1);
    572           x0[i] := 24;
     558            Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 65, 20)
     559          else if HelpLineInfo.CrossLink then
     560            Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 80, 1)
     561          else if not((Kind = hkMisc) and (No = Integer(miscMain))) then
     562            Sprite(OffScreen, HGrSystem, 10, I * 24 + 6, 14, 14, 65, 1);
     563          x0[I] := 24;
    573564        end
    574565        else
    575           x0[i] := 0;
     566          x0[I] := 0;
    576567        case HelpLineInfo.Format of
    577568          pkLogo:
    578569            begin
    579               Server(sGetVersion, 0, 0, j);
    580               s := Format('%d.%d.%d', [j shr 16 and $FF, j shr 8 and $FF,
    581                 j and $FF]);
    582               PaintLogo(OffScreen.Canvas, (InnerWidth - 122) div 2, i * 24 + 1,
     570              Server(sGetVersion, 0, 0, J);
     571              S := Format('%d.%d.%d', [J shr 16 and $FF, J shr 8 and $FF,
     572                J and $FF]);
     573              PaintLogo(OffScreen.Canvas, (InnerWidth - 122) div 2, I * 24 + 1,
    583574                HGrSystem.Data.Canvas.Pixels[95, 1], $000000);
    584575              Font.Assign(UniFont[ftSmall]);
    585576              BiColorTextOut(OffScreen.Canvas, $000000, $7F007F,
    586                 (InnerWidth - Textwidth(s)) div 2, i * 24 + 26, s);
     577                (InnerWidth - Textwidth(S)) div 2, I * 24 + 26, S);
    587578              Font.Assign(UniFont[ftNormal]);
    588579            end;
    589580          pkSmallIcon, pkSmallIcon_AsPreq:
    590581            begin
    591               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    592                 8 + xSizeSmall + x0[i], 2 + 20 + i * 24, $000000, $000000);
     582              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     583                8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000);
    593584              if HelpLineInfo.Picpix = imPalace then
    594                 DpiBitCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     585                DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    595586                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    596587                  0 * xSizeSmall, 1 * ySizeSmall)
    597588              else
    598                 DpiBitCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     589                DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    599590                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    600591                  HelpLineInfo.Picpix mod 7 * xSizeSmall,
    601592                  (HelpLineInfo.Picpix + SystemIconLines * 7) div 7 *
    602593                  ySizeSmall);
    603               x0[i] := x0[i] + (8 + 8 + 36);
     594              x0[I] := x0[I] + (8 + 8 + 36);
    604595            end;
    605596          pkBigIcon:
    606597            begin
    607               FrameImage(OffScreen.Canvas, BigImp, x0[i] + 12, i * 24 - 7, 56,
     598              FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7, 56,
    608599                40, HelpLineInfo.Picpix mod 7 * xSizeBig,
    609600                HelpLineInfo.Picpix div 7 * ySizeBig);
    610               x0[i] := 64 + 8 + 8 + x0[i];
     601              x0[I] := 64 + 8 + 8 + x0[I];
    611602            end;
    612603          pkSpecialIcon:
     
    615606                0:
    616607                  FrameImage(OffScreen.Canvas, HGrSystem2.Data,
    617                     12 + x0[i], -7 + i * 24, 56, 40, 137, 127);
     608                    12 + x0[I], -7 + I * 24, 56, 40, 137, 127);
    618609                1:
    619610                  with NoMap do begin
    620                     PaintTerrIcon(12 + x0[i], -7 + i * 24,
     611                    PaintTerrIcon(12 + x0[I], -7 + I * 24,
    621612                      1 + 3 * (xxt * 2 + 1), 1 + yyt);
    622613                    if 2 * yyt < 40 then
    623                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     614                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    624615                        56, 2 * yyt, 1 + 3 * (xxt * 2 + 1) + xxt - 28,
    625616                        1 + yyt + 1 * (yyt * 3 + 1))
    626617                    else
    627                       Sprite(OffScreen, HGrTerrain, 12 + x0[i],
    628                         -7 + 4 + i * 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt
     618                      Sprite(OffScreen, HGrTerrain, 12 + x0[I],
     619                        -7 + 4 + I * 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt
    629620                        - 28, 1 + yyt + 1 * (yyt * 3 + 1) + yyt - 20);
    630621                  end;
    631622                2:
    632623                  with NoMap do begin
    633                     PaintTerrIcon(12 + x0[i], -7 + i * 24,
     624                    PaintTerrIcon(12 + x0[I], -7 + I * 24,
    634625                      1 + 7 * (xxt * 2 + 1), 1 + yyt + 4 * (yyt * 3 + 1));
    635626                    if 2 * yyt < 40 then
    636                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     627                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    637628                        56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28,
    638629                        1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16)
    639630                    else
    640                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     631                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    641632                        56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28,
    642633                        1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16)
    643634                  end;
    644635              end;
    645               x0[i] := 64 + 8 + 8 + x0[i];
     636              x0[I] := 64 + 8 + 8 + x0[I];
    646637            end;
    647638          pkDomain:
    648639            begin
    649               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    650                 8 + 36 + x0[i], 2 + 20 + i * 24, $000000, $000000);
    651               Dump(OffScreen, HGrSystem, 8 + x0[i], 2 + i * 24, 36, 20,
     640              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     641                8 + 36 + x0[I], 2 + 20 + I * 24, $000000, $000000);
     642              Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20,
    652643                75 + HelpLineInfo.Picpix * 37, 295);
    653               x0[i] := x0[i] + (8 + 8 + 36);
     644              x0[I] := x0[I] + (8 + 8 + 36);
    654645            end;
    655646          pkAdvIcon, pkAdvIcon_AsPreq:
    656647            begin
    657               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    658                 8 + xSizeSmall + x0[i], 2 + ySizeSmall + i * 24,
     648              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     649                8 + xSizeSmall + x0[I], 2 + ySizeSmall + I * 24,
    659650                $000000, $000000);
    660651              if AdvIcon[HelpLineInfo.Picpix] < 84 then
    661                 DpiBitCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     652                DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    662653                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    663654                  (AdvIcon[HelpLineInfo.Picpix] + SystemIconLines * 7) mod 7 *
     
    665656                  7) div 7 * ySizeSmall)
    666657              else
    667                 Dump(OffScreen, HGrSystem, 8 + x0[i], 2 + i * 24, 36, 20,
     658                Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20,
    668659                  1 + (AdvIcon[HelpLineInfo.Picpix] - 84) mod 8 * 37,
    669660                  295 + (AdvIcon[HelpLineInfo.Picpix] - 84) div 8 * 21);
    670               j := AdvValue[HelpLineInfo.Picpix] div 1000;
    671               DpiBitCanvas(OffScreen.Canvas, x0[i] + 4, 4 + i * 24, 14, 14,
    672                 HGrSystem.Mask.Canvas, 127 + j * 15, 85, SRCAND);
    673               Sprite(OffScreen, HGrSystem, x0[i] + 3, 3 + i * 24, 14, 14,
    674                 127 + j * 15, 85);
    675               x0[i] := x0[i] + (8 + 8 + 36);
     661              J := AdvValue[HelpLineInfo.Picpix] div 1000;
     662              DpiBitBltCanvas(OffScreen.Canvas, x0[I] + 4, 4 + I * 24, 14, 14,
     663                HGrSystem.Mask.Canvas, 127 + J * 15, 85, SRCAND);
     664              Sprite(OffScreen, HGrSystem, x0[I] + 3, 3 + I * 24, 14, 14,
     665                127 + J * 15, 85);
     666              x0[I] := x0[I] + (8 + 8 + 36);
    676667            end;
    677668          pkRightIcon:
    678669            begin
    679670              if Imp[HelpLineInfo.Picpix].Kind <> ikWonder then
    680                 ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), i * 24,
     671                ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), I * 24,
    681672                  HelpLineInfo.Picpix, gDespotism)
    682673              else
    683                 WaterSign(InnerWidth - (40 + 2 * xSizeBig), i * 24 - 8,
     674                WaterSign(InnerWidth - (40 + 2 * xSizeBig), I * 24 - 8,
    684675                  HelpLineInfo.Picpix + 7);
    685               x0[i] := x0[i] + 8;
     676              x0[I] := x0[I] + 8;
    686677            end;
    687678          pkIllu:
    688             WaterSign(8, i * 24 - 8, HelpLineInfo.Picpix);
     679            WaterSign(8, I * 24 - 8, HelpLineInfo.Picpix);
    689680          pkBigFeature:
    690681            begin
    691682              cnt := 0;
    692               for j := nDomains - 1 downto 0 do
    693                 if 1 shl j and Feature[HelpLineInfo.Picpix].Domains <> 0 then
     683              for J := nDomains - 1 downto 0 do
     684                if 1 shl J and Feature[HelpLineInfo.Picpix].Domains <> 0 then
    694685                begin
    695                   inc(cnt);
     686                  Inc(cnt);
    696687                  Dump(OffScreen, HGrSystem, InnerWidth - 38 - 38 * cnt,
    697                     i * 24 + 1, 36, 20, 75 + j * 37, 295);
    698                   ScreenTools.Frame(OffScreen.Canvas, InnerWidth - 39 - 38 * cnt, i * 24,
    699                     InnerWidth - 2 - 38 * cnt, i * 24 + 21, $000000, $000000);
     688                    I * 24 + 1, 36, 20, 75 + J * 37, 295);
     689                  ScreenTools.Frame(OffScreen.Canvas, InnerWidth - 39 - 38 * cnt, I * 24,
     690                    InnerWidth - 2 - 38 * cnt, I * 24 + 21, $000000, $000000);
    700691                end;
    701692              DarkGradient(OffScreen.Canvas, InnerWidth - 38 - 38 * cnt,
    702                 i * 24 + 23, cnt * 38 - 2, 1);
     693                I * 24 + 23, cnt * 38 - 2, 1);
    703694              ofs := InnerWidth - (39 + 7) - 19 * cnt;
    704695              with OffScreen.Canvas do
    705696              begin
    706                 Brush.color := $C0C0C0;
    707                 FrameRect(Rect(ofs, 1 + 23 + i * 24, ofs + 14,
    708                   15 + 23 + i * 24));
     697                Brush.Color := $C0C0C0;
     698                FrameRect(Rect(ofs, 1 + 23 + I * 24, ofs + 14,
     699                  15 + 23 + I * 24));
    709700                Brush.Style := bsClear;
    710                 Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + i * 24, 10, 10,
     701                Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + I * 24, 10, 10,
    711702                  66 + HelpLineInfo.Picpix mod 11 * 11,
    712703                  137 + HelpLineInfo.Picpix div 11 * 11);
    713704              end;
    714               x0[i] := x0[i] + 8;
     705              x0[I] := x0[I] + 8;
    715706            end;
    716707          pkTer, pkBigTer:
    717708            with NoMap do begin
    718709              if HelpLineInfo.Format = pkBigTer then
    719                 y := i * 24 - 3 + yyt
     710                Y := I * 24 - 3 + yyt
    720711              else
    721                 y := i * 24 + 13;
     712                Y := I * 24 + 13;
    722713              if HelpLineInfo.Picpix >= 3 * 12 then
    723714                srcno := 2 * 9 + 6
     
    730721              if HelpLineInfo.Format = pkTer then
    731722              begin
    732                 ofs := x0[i] + 8;
    733                 x0[i] := 2 * xxt + 8 + ofs;
     723                ofs := x0[I] + 8;
     724                x0[I] := 2 * xxt + 8 + ofs;
    734725              end
    735726              else
    736727              begin
    737728                ofs := InnerWidth - (2 * xxt + 38);
    738                 x0[i] := x0[i] + 8;
     729                x0[I] := x0[I] + 8;
    739730              end;
    740731              if srcno >= fJungle then
    741732              begin
    742                 Sprite(OffScreen, HGrTerrain, ofs + 4, y - yyt + 2, xxt * 2 - 8,
     733                Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8,
    743734                  yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1),
    744735                  3 + yyt + 2 * (yyt * 3 + 1));
    745                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     736                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    746737                  yyt * 3 - 2, 1 + srcno mod 9 * (xxt * 2 + 1),
    747738                  1 + srcno div 9 * (yyt * 3 + 1));
    748739              end
    749740              else
    750                 Sprite(OffScreen, HGrTerrain, ofs + 4, y - yyt + 2, xxt * 2 - 8,
     741                Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8,
    751742                  yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1),
    752743                  3 + yyt + srcno div 9 * (yyt * 3 + 1));
    753744              if HelpLineInfo.Picpix >= 3 * 12 then { rare resource }
    754                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     745                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    755746                  yyt * 3, 1 + 8 * (xxt * 2 + 1),
    756747                  1 + (HelpLineInfo.Picpix - 2 * 12) * (yyt * 3 + 1))
     
    764755                  srcno := 18 + 8 + (HelpLineInfo.Picpix mod 12 - 9) * 18;
    765756                srcno := srcno + HelpLineInfo.Picpix div 12 * 9;
    766                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     757                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    767758                  yyt * 3, 1 + srcno mod 9 * (xxt * 2 + 1),
    768759                  1 + srcno div 9 * (yyt * 3 + 1));
     
    774765              if HelpLineInfo.Picpix = 5 then
    775766              begin // display mine on hills
    776                 Sprite(OffScreen, HGrTerrain, ofs + 4, i * 24 + 13 - yyt,
     767                Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt,
    777768                  xxt * 2 - 8, yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1),
    778769                  3 + yyt + 2 * (yyt * 3 + 1));
     
    781772              else
    782773                srcno := fPrairie; // display on prairie
    783               Sprite(OffScreen, HGrTerrain, ofs + 4, i * 24 + 13 - yyt,
     774              Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt,
    784775                xxt * 2 - 8, yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1),
    785776                3 + yyt + srcno div 9 * (yyt * 3 + 1));
    786777              if HelpLineInfo.Picpix = 12 then { river }
    787                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - yyt, xxt * 2,
     778                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - yyt, xxt * 2,
    788779                  yyt * 2, 1 + 5 * (xxt * 2 + 1), 1 + yyt + 13 * (yyt * 3 + 1))
    789780              else if HelpLineInfo.Picpix >= 3 then { improvement 2 }
    790781              begin
    791782                if HelpLineInfo.Picpix = 6 then
    792                   Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     783                  Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    793784                    xxt * 2, yyt * 3, 1 + 7 * (xxt * 2 + 1),
    794785                    1 + 12 * (yyt * 3 + 1));
    795                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     786                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    796787                  xxt * 2, yyt * 3, 1 + (HelpLineInfo.Picpix - 3) *
    797788                  (xxt * 2 + 1), 1 + 12 * (yyt * 3 + 1))
     
    799790              else { improvement 1 }
    800791              begin
    801                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     792                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    802793                  xxt * 2, yyt * 3, 1 + 2 * (xxt * 2 + 1),
    803794                  1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1));
    804                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     795                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    805796                  xxt * 2, yyt * 3, 1 + 5 * (xxt * 2 + 1),
    806797                  1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1))
    807798              end;
    808               x0[i] := x0[i] + 8;
     799              x0[I] := x0[I] + 8;
    809800            end;
    810801          pkModel:
    811802            begin
    812               FrameImage(OffScreen.Canvas, BigImp, x0[i] + 12, i * 24 - 7,
     803              FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7,
    813804                56, 40, 0, 0);
    814               Sprite(OffScreen, HGrStdUnits, x0[i] + 8, i * 24 - 11, 64, 44,
     805              Sprite(OffScreen, HGrStdUnits, x0[I] + 8, I * 24 - 11, 64, 44,
    815806                1 + HelpLineInfo.Picpix mod 10 * 65,
    816807                1 + HelpLineInfo.Picpix div 10 * 49);
    817               x0[i] := 64 + 8 + 8 + x0[i];
     808              x0[I] := 64 + 8 + 8 + x0[I];
    818809            end;
    819810          pkFeature:
    820811            begin
    821               DarkGradient(OffScreen.Canvas, x0[i] + 8 - 1,
    822                 7 + i * 24 - 3, 16, 1);
    823               ScreenTools.Frame(OffScreen.Canvas, x0[i] + 8, 7 + i * 24 - 2, x0[i] + 8 + 13,
    824                 7 + i * 24 - 2 + 13, $C0C0C0, $C0C0C0);
    825               Sprite(OffScreen, HGrSystem, x0[i] + 8 + 2, 7 + i * 24, 10, 10,
     812              DarkGradient(OffScreen.Canvas, x0[I] + 8 - 1,
     813                7 + I * 24 - 3, 16, 1);
     814              ScreenTools.Frame(OffScreen.Canvas, x0[I] + 8, 7 + I * 24 - 2, x0[I] + 8 + 13,
     815                7 + I * 24 - 2 + 13, $C0C0C0, $C0C0C0);
     816              Sprite(OffScreen, HGrSystem, x0[I] + 8 + 2, 7 + I * 24, 10, 10,
    826817                66 + HelpLineInfo.Picpix mod 11 * 11,
    827818                137 + HelpLineInfo.Picpix div 11 * 11);
    828               x0[i] := x0[i] + 8 + 8 + 2 + 13;
     819              x0[I] := x0[I] + 8 + 8 + 2 + 13;
    829820            end;
    830821          pkExp:
    831822            begin
    832               ScreenTools.Frame(OffScreen.Canvas, 20 - 1, 8 - 4 + i * 24, 20 + 12,
    833                 8 + 11 + i * 24, $000000, $000000);
    834               Dump(OffScreen, HGrSystem, 20, 8 - 3 + i * 24, 12, 14,
     823              ScreenTools.Frame(OffScreen.Canvas, 20 - 1, 8 - 4 + I * 24, 20 + 12,
     824                8 + 11 + I * 24, $000000, $000000);
     825              Dump(OffScreen, HGrSystem, 20, 8 - 3 + I * 24, 12, 14,
    835826                121 + HelpLineInfo.Picpix * 13, 28);
    836               x0[i] := 20 + 8 + 11;
     827              x0[I] := 20 + 8 + 11;
    837828            end;
    838829          pkAITStat:
    839830            begin
    840               Sprite(OffScreen, HGrSystem, 20, 6 + i * 24, 14, 14,
     831              Sprite(OffScreen, HGrSystem, 20, 6 + I * 24, 14, 14,
    841832                1 + HelpLineInfo.Picpix * 15, 316);
    842               x0[i] := 20 + 8 + 11;
     833              x0[I] := 20 + 8 + 11;
    843834            end;
    844835          pkGov:
    845836            begin
    846               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    847                 8 + xSizeSmall + x0[i], 2 + 20 + i * 24, $000000, $000000);
    848               DpiBitCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24, xSizeSmall,
     837              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     838                8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000);
     839              DpiBitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, xSizeSmall,
    849840                ySizeSmall, SmallImp.Canvas, (HelpLineInfo.Picpix - 1) *
    850841                xSizeSmall, ySizeSmall);
    851               x0[i] := x0[i] + (8 + 8 + 36);
     842              x0[I] := x0[I] + (8 + 8 + 36);
    852843            end;
    853844          pkDot:
    854845            begin
    855               Sprite(OffScreen, HGrSystem, x0[i] + 18, 9 + i * 24, 8,
     846              Sprite(OffScreen, HGrSystem, x0[I] + 18, 9 + I * 24, 8,
    856847                8, 81, 16);
    857               x0[i] := 20 + 8 + 4;
     848              x0[I] := 20 + 8 + 4;
    858849            end;
    859850          pkNormal_Dot:
    860             x0[i] := 20 + 8 + 4;
     851            x0[I] := 20 + 8 + 4;
    861852          pkNormal_64:
    862             x0[i] := 64 + 8 + 8;
     853            x0[I] := 64 + 8 + 8;
    863854        else
    864           x0[i] := x0[i] + 8;
     855          x0[I] := x0[I] + 8;
    865856        end;
    866         Self.Line(OffScreen.Canvas, i, False)
     857        Self.Line(OffScreen.Canvas, I, False)
    867858      end;
    868859  end;
     
    873864begin
    874865  Sel := -1;
    875   SmartUpdateContent(true)
    876 end;
    877 
    878 procedure THelpDlg.Prepare(sbPos: integer = 0);
     866  SmartUpdateContent(True);
     867end;
     868
     869procedure THelpDlg.Prepare(sbPos: Integer = 0);
    879870var
    880   i, j, Special, Domain, Headline, TerrType, TerrSubType: integer;
    881   s: string;
    882   ps: pchar;
     871  I, J, Special, Domain, Headline, TerrType, TerrSubType: Integer;
     872  S: string;
     873  ps: PChar;
    883874  List: THyperText;
    884875  CheckSeeAlso: Boolean;
    885876
    886   procedure AddAdvance(i: integer);
    887   begin
    888     MainText.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon, i,
    889       hkAdv + hkCrossLink, i);
    890   end;
    891 
    892   procedure AddPreqAdv(i: integer);
    893   begin
    894     MainText.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon_AsPreq, i,
    895       hkAdv + hkCrossLink, i);
    896   end;
    897 
    898   procedure AddImprovement(i: integer);
    899   begin
    900     MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,
    901       hkImp + hkCrossLink, i);
    902   end;
    903 
    904   procedure AddPreqImp(i: integer);
    905   begin
    906     MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon_AsPreq, i,
    907       hkImp + hkCrossLink, i);
    908   end;
    909 
    910   procedure AddTerrain(i: integer);
     877  procedure AddAdvance(I: Integer);
     878  begin
     879    MainText.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon, I,
     880      hkAdv, I, True);
     881  end;
     882
     883  procedure AddPreqAdv(I: Integer);
     884  begin
     885    MainText.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon_AsPreq, I,
     886      hkAdv, I, True);
     887  end;
     888
     889  procedure AddImprovement(I: Integer);
     890  begin
     891    MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I,
     892      hkImp, I, True);
     893  end;
     894
     895  procedure AddPreqImp(I: Integer);
     896  begin
     897    MainText.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon_AsPreq, I,
     898      hkImp, I, True);
     899  end;
     900
     901  procedure AddTerrain(I: Integer);
    911902  begin
    912903    if MainText.Count > 1 then
     
    914905      MainText.LineFeed;
    915906    end;
    916     MainText.AddLine(Phrases.Lookup('TERRAIN', i), pkTer, i, hkTer, i);
    917   end;
    918 
    919   procedure AddFeature(i: integer);
    920   begin
    921     MainText.AddLine(Phrases.Lookup('FEATURES', i), pkFeature, i,
    922       hkFeature + hkCrossLink, i);
    923   end;
    924 
    925   procedure AddModel(i: integer);
     907    MainText.AddLine(Phrases.Lookup('TERRAIN', I), pkTer, I, hkTer, I);
     908  end;
     909
     910  procedure AddFeature(I: Integer);
     911  begin
     912    MainText.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I,
     913      hkFeature, I, True);
     914  end;
     915
     916  procedure AddModel(I: Integer);
    926917  var
    927     pix: integer;
     918    pix: Integer;
    928919    Name: string;
    929920  begin
    930921    if MainText.Count > 1 then
    931922      MainText.LineFeed;
    932     FindStdModelPicture(SpecialModelPictureCode[i], pix, Name);
    933     MainText.AddLine(Name, pkModel, pix, hkModel + hkCrossLink, i)
     923    FindStdModelPicture(SpecialModelPictureCode[I], pix, Name);
     924    MainText.AddLine(Name, pkModel, pix, hkModel, I, True);
    934925  end;
    935926
    936927  procedure AddStandardBlock(Item: string);
    937928  var
    938     i: integer;
     929    I: Integer;
    939930  begin
    940931    with MainText do
     
    947938      else if Item = 'TECHFORMULA' then
    948939      begin
    949         i := Difficulty;
    950         if i = 0 then
    951           i := 2;
    952         AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[i],
    953           TechFormula_D[i]]))
     940        I := Difficulty;
     941        if I = 0 then
     942          I := 2;
     943        AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[I],
     944          TechFormula_D[I]]));
    954945      end
    955946      else if Item = 'EXPERIENCE' then
    956         for i := 0 to nExp - 1 do
    957           AddLine(Phrases.Lookup('EXPERIENCE', i), pkExp, i)
     947        for I := 0 to nExp - 1 do
     948          AddLine(Phrases.Lookup('EXPERIENCE', I), pkExp, I)
    958949      else if Item = 'MODERN' then
    959         for i := 1 to 3 do
     950        for I := 1 to 3 do
    960951        begin
    961952          LineFeed;
    962           AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + i), pkTer, 3 * 12 + i);
     953          AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + I), pkTer, 3 * 12 + I);
    963954        end
    964955      else if Item = 'SAVED' then
    965956        AddLine(DataDir + 'Saved', pkNormal)
    966957      else if Item = 'AITSTAT' then
    967         for i := 0 to 3 do
    968           AddLine(Phrases2.Lookup('AITSTAT', i), pkAITStat, i)
    969     end
    970   end;
    971 
    972   procedure DecodeItem(s: string; var Category, Index: Integer);
     958        for I := 0 to 3 do
     959          AddLine(Phrases2.Lookup('AITSTAT', I), pkAITStat, I)
     960    end;
     961  end;
     962
     963  procedure DecodeItem(S: string; var Category: TLinkCategory; var Index: Integer);
    973964  var
    974     i: Integer;
    975   begin
    976     if (Length(s) > 0) and (s[1] = ':') then begin
     965    I: Integer;
     966  begin
     967    if (Length(S) > 0) and (S[1] = ':') then begin
    977968      Category := hkMisc;
    978969      Index := 0;
    979       for i := 3 to length(s) do
    980         Index := Index * 10 + Ord(s[i]) - 48;
    981       case s[2] of
     970      for I := 3 to Length(S) do
     971        Index := Index * 10 + Ord(S[I]) - 48;
     972      case S[2] of
    982973        'A': Category := hkAdv;
    983974        'B': Category := hkImp;
     
    986977        'E': Category := hkInternet;
    987978        'S': Category := hkModel;
    988         'C': Index := miscCredits;
    989         'J': Index := miscJobList;
    990         'G': Index := miscGovList;
     979        'C': Index := Integer(miscCredits);
     980        'J': Index := Integer(miscJobList);
     981        'G': Index := Integer(miscGovList);
    991982      end;
    992983      if (Category <> hkMisc) and (Index = 0) then
     
    994985    end else begin
    995986      Category := hkText;
    996       Index := HelpText.Gethandle(Copy(s, 1, 255));
     987      Index := HelpText.GetHandle(Copy(S, 1, 255));
    997988    end;
    998989  end;
    999990
    1000   procedure AddTextual(s: string);
     991  procedure AddTextual(S: string);
    1001992  var
    1002     i: Integer;
    1003     p: Integer;
    1004     l: Integer;
     993    I: Integer;
     994    P: Integer;
     995    L: Integer;
    1005996    ofs: Integer;
    1006     CurrentFormat: Integer;
    1007     FollowFormat: Integer;
     997    CurrentFormat: TTextFormat;
     998    FollowFormat: TTextFormat;
    1008999    Picpix: Integer;
    1009     LinkCategory: Integer;
     1000    LinkCategory: TLinkCategory;
     1001    CrossLink: Boolean;
    10101002    LinkIndex: Integer;
    10111003    RightMargin: Integer;
     
    10131005    Text: string;
    10141006  begin
     1007    CrossLink := False;
    10151008    RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL);
    10161009    FollowFormat := pkNormal;
    1017     while s <> '' do
     1010    while S <> '' do
    10181011    begin
    10191012      Picpix := 0;
    1020       LinkCategory := 0;
     1013      LinkCategory := hkNoLink;
    10211014      LinkIndex := 0;
    1022       if s[1] = '$' then
    1023       begin // window caption
    1024         p := 1;
     1015      if S[1] = '$' then
     1016      begin // Window caption
     1017        P := 1;
    10251018        repeat
    1026           inc(p)
    1027         until (p > Length(s)) or (s[p] = '\');
    1028         Caption := Copy(s, 2, p - 2);
    1029         Delete(s, 1, p);
     1019          Inc(P);
     1020        until (P > Length(S)) or (S[P] = '\');
     1021        Caption := Copy(S, 2, P - 2);
     1022        Delete(S, 1, P);
    10301023      end
    1031       else if s[1] = '&' then
    1032       begin // standard block
    1033         p := 1;
     1024      else if S[1] = '&' then
     1025      begin // Standard block
     1026        P := 1;
    10341027        repeat
    1035           inc(p)
    1036         until (p > Length(s)) or (s[p] = '\');
    1037         AddStandardBlock(Copy(s, 2, p - 2));
    1038         Delete(s, 1, p);
     1028          Inc(P);
     1029        until (P > Length(S)) or (S[P] = '\');
     1030        AddStandardBlock(Copy(S, 2, P - 2));
     1031        Delete(S, 1, P);
    10391032      end
    1040       else if s[1] = '@' then
    1041       begin // image
    1042         if (Length(s) >= 2) and (s[2] = '@') then
    1043         begin // generate from icon
     1033      else if S[1] = '@' then
     1034      begin // Image
     1035        if (Length(S) >= 2) and (S[2] = '@') then
     1036        begin // Generate from icon
    10441037          Picpix := 0;
    1045           p := 3;
    1046           while (p <= Length(s)) and (s[p] <> '\') do
     1038          P := 3;
     1039          while (P <= Length(S)) and (S[P] <> '\') do
    10471040          begin
    1048             Picpix := Picpix * 10 + Ord(s[p]) - 48;
    1049             inc(p)
     1041            Picpix := Picpix * 10 + Ord(S[P]) - 48;
     1042            Inc(P);
    10501043          end;
    10511044          if (Picpix < 0) or (Picpix >= nImp) then
     
    10571050        else
    10581051        begin // external image
    1059           p := 1;
     1052          P := 1;
    10601053          repeat
    1061             Inc(p)
    1062           until (p > Length(s)) or (s[p] = '\');
     1054            Inc(P);
     1055          until (P > Length(S)) or (S[P] = '\');
    10631056          if LoadGraphicFile(ExtPic, LocalizedFilePath('Help' +
    1064             DirectorySeparator + Copy(s, 2, p - 2)) + '.png') then
     1057            DirectorySeparator + Copy(S, 2, P - 2)) + '.png') then
    10651058          begin
    10661059            MainText.AddLine('', pkExternal);
    1067             for i := 0 to (ExtPic.Height - 12) div 24 do
     1060            for I := 0 to (ExtPic.Height - 12) div 24 do
    10681061              MainText.LineFeed;
    10691062          end;
    10701063        end;
    1071         Delete(s, 1, p);
     1064        Delete(S, 1, P);
    10721065      end
    10731066      else
    10741067      begin
    1075         case s[1] of
     1068        case S[1] of
    10761069          ':', ';':
    10771070            begin // link
    1078               p := 1;
     1071              P := 1;
    10791072              repeat
    1080                 inc(p)
    1081               until (p > Length(s)) or (s[p] = '\') or (s[p] = ' ');
    1082               DecodeItem(Copy(s, 2, p - 2), LinkCategory, LinkIndex);
    1083               CurrentFormat := 0;
     1073                Inc(P);
     1074              until (P > Length(S)) or (S[P] = '\') or (S[P] = ' ');
     1075              DecodeItem(Copy(S, 2, P - 2), LinkCategory, LinkIndex);
     1076              CurrentFormat := pkNormal;
    10841077              if (LinkCategory <> hkText) and (LinkIndex < 200) then
    10851078              // show icon
     
    10881081                    begin
    10891082                      CurrentFormat := pkAdvIcon;
    1090                       Picpix := LinkIndex
     1083                      Picpix := LinkIndex;
    10911084                    end;
    10921085                  hkImp:
    10931086                    begin
    10941087                      CurrentFormat := pkSmallIcon;
    1095                       Picpix := LinkIndex
     1088                      Picpix := LinkIndex;
    10961089                    end;
    10971090                  hkTer:
     
    11031096                    begin
    11041097                      CurrentFormat := pkFeature;
    1105                       Picpix := LinkIndex
     1098                      Picpix := LinkIndex;
    11061099                    end;
    11071100                  hkModel:
     
    11121105                    end;
    11131106                end;
    1114               if s[1] = ':' then
    1115                 LinkCategory := LinkCategory + hkCrossLink;
    1116               if (p > Length(s)) or (s[p] = ' ') then
    1117                 Delete(s, 1, p)
     1107              if S[1] = ':' then
     1108                CrossLink := True;
     1109              if (P > Length(S)) or (S[P] = ' ') then
     1110                Delete(S, 1, P)
    11181111              else
    1119                 Delete(s, 1, p - 1)
    1120             end;
    1121           '!': // highlited
    1122             if (Length(s) >= 2) and (s[2] = '!') then
     1112                Delete(S, 1, P - 1)
     1113            end;
     1114          '!': // highlighted
     1115            if (Length(S) >= 2) and (S[2] = '!') then
    11231116            begin
    11241117              if MainText.Count > 1 then
     
    11261119              FollowFormat := pkCaption;
    11271120              CurrentFormat := pkCaption;
    1128               Delete(s, 1, 2);
     1121              Delete(S, 1, 2);
    11291122            end
    11301123            else
     
    11321125              FollowFormat := pkSection;
    11331126              CurrentFormat := pkSection;
    1134               Delete(s, 1, 1);
     1127              Delete(S, 1, 1);
    11351128            end;
    11361129          '-':
     
    11381131              FollowFormat := pkNormal_Dot;
    11391132              CurrentFormat := pkDot;
    1140               Delete(s, 1, 1);
     1133              Delete(S, 1, 1);
    11411134            end;
    11421135        else
     
    11471140        else
    11481141          ofs := 8;
    1149         p := 0;
     1142        P := 0;
    11501143        repeat
    11511144          repeat
    1152             Inc(p)
    1153           until (p > Length(s)) or (s[p] = ' ') or (s[p] = '\');
    1154           if (BiColorTextWidth(OffScreen.Canvas, Copy(s, 1, p - 1)) <=
     1145            Inc(P)
     1146          until (P > Length(S)) or (S[P] = ' ') or (S[P] = '\');
     1147          if (BiColorTextWidth(OffScreen.Canvas, Copy(S, 1, P - 1)) <=
    11551148            RightMargin - ofs) then
    1156             l := p - 1
     1149            L := P - 1
    11571150          else
    11581151            Break;
    1159         until (p >= Length(s)) or (s[l + 1] = '\');
    1160         Text := Copy(s, 1, l);
    1161         if LinkCategory and $3f = hkInternet then begin
     1152        until (P >= Length(S)) or (S[L + 1] = '\');
     1153        Text := Copy(S, 1, L);
     1154        if LinkCategory = hkInternet then begin
    11621155          if LinkIndex = 1 then Text := AITemplateManual
    11631156          else if LinkIndex = 2 then Text := CevoHomepageShort
     
    11651158        end;
    11661159        MainText.AddLine(Text, CurrentFormat, Picpix, LinkCategory,
    1167           LinkIndex);
    1168         if (l < Length(s)) and (s[l + 1] = '\') then
     1160          LinkIndex, CrossLink);
     1161        if (L < Length(S)) and (S[L + 1] = '\') then
    11691162          FollowFormat := pkNormal;
    1170         Delete(s, 1, l + 1);
    1171       end
    1172     end
     1163        Delete(S, 1, L + 1);
     1164      end;
     1165    end;
    11731166  end;
    11741167
     
    11781171  end;
    11791172
    1180   procedure AddModelText(i: Integer);
     1173  procedure AddModelText(I: Integer);
    11811174  var
    11821175    pix: Integer;
    1183     s: string;
     1176    S: string;
    11841177  begin
    11851178    with MainText do begin
     
    11881181        LineFeed;
    11891182      end;
    1190       FindStdModelPicture(SpecialModelPictureCode[i], pix, s);
    1191       AddLine(s, pkSection);
    1192       AddLine(Format(HelpText.Lookup('STRENGTH'), [SpecialModel[i].Attack,
    1193         SpecialModel[i].Defense]), pkNormal_64);
     1183      FindStdModelPicture(SpecialModelPictureCode[I], pix, S);
     1184      AddLine(S, pkSection);
     1185      AddLine(Format(HelpText.Lookup('STRENGTH'), [SpecialModel[I].Attack,
     1186        SpecialModel[I].Defense]), pkNormal_64);
    11941187      AddLine(Format(HelpText.Lookup('SPEED'),
    1195         [MovementToString(SpecialModel[i].Speed)]), pkModel, pix);
     1188        [MovementToString(SpecialModel[I].Speed)]), pkModel, pix);
    11961189      if Difficulty = 0 then
    1197         AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[i].Cost]),
     1190        AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[I].Cost]),
    11981191          pkNormal_64)
    11991192      else
    12001193        AddLine(Format(HelpText.Lookup('BUILDCOST'),
    1201           [SpecialModel[i].Cost * BuildCostMod[Difficulty] div 12]),
     1194          [SpecialModel[I].Cost * BuildCostMod[Difficulty] div 12]),
    12021195          pkNormal_64);
    1203       s := HelpText.LookupByHandle(hSPECIALMODEL, i);
    1204       if (s <> '') and (s <> '*') then
    1205         AddTextual(s);
    1206       if SpecialModelPreq[i] >= 0 then
    1207         AddPreqAdv(SpecialModelPreq[i])
    1208       else if SpecialModelPreq[i] = preLighthouse then
     1196      S := HelpText.LookupByHandle(hSPECIALMODEL, I);
     1197      if (S <> '') and (S <> '*') then
     1198        AddTextual(S);
     1199      if SpecialModelPreq[I] >= 0 then
     1200        AddPreqAdv(SpecialModelPreq[I])
     1201      else if SpecialModelPreq[I] = preLighthouse then
    12091202        AddPreqImp(woLighthouse)
    1210       else if SpecialModelPreq[i] = preBuilder then
     1203      else if SpecialModelPreq[I] = preBuilder then
    12111204        AddPreqImp(woPyramids)
    1212       else if SpecialModelPreq[i] = preLeo then
     1205      else if SpecialModelPreq[I] = preLeo then
    12131206        AddPreqImp(woLeo);
    1214       if SpecialModelPreq[i] <> preNone then
     1207      if SpecialModelPreq[I] <> preNone then
    12151208        MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    12161209          [MainText[Count - 1]]);
     
    12201213  procedure AddJobList;
    12211214  var
    1222     i, JobCost: Integer;
     1215    I, JobCost: Integer;
    12231216  begin
    12241217    with MainText do begin
    1225       for i := 0 to nJobHelp - 1 do begin
    1226         if i > 0 then begin
     1218      for I := 0 to Length(JobHelp) - 1 do begin
     1219        if I > 0 then begin
    12271220          LineFeed;
    12281221          LineFeed;
    12291222        end;
    1230         AddLine(Phrases.Lookup('JOBRESULT', JobHelp[i]), pkSection);
     1223        AddLine(Phrases.Lookup('JOBRESULT', JobHelp[I]), pkSection);
    12311224        AddLine;
    1232         AddLine('', pkTerImp, i);
     1225        AddLine('', pkTerImp, I);
    12331226        AddLine;
    1234         AddTextual(HelpText.LookupByHandle(hJOBHELP, i));
     1227        AddTextual(HelpText.LookupByHandle(hJOBHELP, I));
    12351228        JobCost := -1;
    1236         case JobHelp[i] of
     1229        case JobHelp[I] of
    12371230          jCanal: JobCost := CanalWork;
    12381231          jFort: JobCost := FortWork;
     
    12441237        else
    12451238          AddTextual(HelpText.Lookup('JOBCOSTVAR'));
    1246         if JobPreq[JobHelp[i]] <> preNone then begin
    1247           AddPreqAdv(JobPreq[JobHelp[i]]);
     1239        if JobPreq[JobHelp[I]] <> preNone then begin
     1240          AddPreqAdv(JobPreq[JobHelp[I]]);
    12481241          MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    12491242            [MainText[Count - 1]]);
     
    12551248  procedure AddGraphicCredits;
    12561249  var
    1257     i: Integer;
    1258     s: string;
     1250    I: Integer;
     1251    S: string;
    12591252    sr: TSearchRec;
    12601253    List, Plus: TStringList;
     
    12711264
    12721265    List.Sort;
    1273     i := 1;
    1274     while i < List.Count do
    1275       if List[i] = List[i - 1] then
    1276         List.Delete(i)
     1266    I := 1;
     1267    while I < List.Count do
     1268      if List[I] = List[I - 1] then
     1269        List.Delete(I)
    12771270      else
    1278         Inc(i);
    1279 
    1280     for i := 0 to List.Count - 1 do begin
    1281       s := List[i];
    1282       while BiColorTextWidth(OffScreen.Canvas, s) > InnerWidth - 16 -
     1271        Inc(I);
     1272
     1273    for I := 0 to List.Count - 1 do begin
     1274      S := List[I];
     1275      while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 -
    12831276        DpiGetSystemMetrics(SM_CXVSCROLL) do
    1284         Delete(s, length(s), 1);
    1285       MainText.AddLine(s);
     1277        Delete(S, Length(S), 1);
     1278      MainText.AddLine(S);
    12861279    end;
    12871280    FreeAndNil(List);
     
    12901283  procedure AddSoundCredits;
    12911284  var
    1292     i: Integer;
    1293     s: string;
     1285    I: Integer;
     1286    S: string;
    12941287    List: TStringList;
    12951288  begin
    12961289    List := TStringList.Create;
    12971290    List.LoadFromFile(GetSoundsDir + DirectorySeparator + 'sound.credits.txt');
    1298     for i := 0 to List.Count - 1 do begin
    1299       s := List[i];
    1300       while BiColorTextWidth(OffScreen.Canvas, s) > InnerWidth - 16 -
     1291    for I := 0 to List.Count - 1 do begin
     1292      S := List[I];
     1293      while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 -
    13011294        DpiGetSystemMetrics(SM_CXVSCROLL) do
    1302         Delete(s, length(s), 1);
    1303       MainText.AddLine(s);
     1295        Delete(S, Length(S), 1);
     1296      MainText.AddLine(S);
    13041297    end;
    13051298    FreeAndNil(List);
     
    13231316    Clear;
    13241317    Headline := -1;
    1325     if (no >= 200) or not(Kind in [hkAdv, hkImp, hkTer, hkFeature]) then
     1318    if (No >= 200) or not (Kind in [hkAdv, hkImp, hkTer, hkFeature]) then
    13261319      LineFeed;
    13271320    case Kind of
    13281321      hkText:
    1329         AddTextual(HelpText.LookupByHandle(no));
     1322        AddTextual(HelpText.LookupByHandle(No));
    13301323      hkMisc:
    13311324        begin
    1332           case no of
    1333             miscMain:
     1325          case No of
     1326            Integer(miscMain):
    13341327              begin
    13351328                Caption := HelpText.Lookup('HELPTITLE_MAIN');
    13361329                AddLine(HelpText.Lookup('HELPTITLE_QUICKSTART'), pkSpecialIcon,
    1337                   0, { pkBigIcon,22, } hkText, HelpText.Gethandle('QUICK'));
     1330                  0, { pkBigIcon,22, } hkText, HelpText.GetHandle('QUICK'));
    13381331                LineFeed;
    13391332                AddLine(HelpText.Lookup('HELPTITLE_CONCEPTS'), pkBigIcon, 6,
     
    13441337                LineFeed;
    13451338                AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkSpecialIcon, 2,
    1346                   hkMisc, miscJobList);
     1339                  hkMisc, Integer(miscJobList));
    13471340                LineFeed;
    13481341                AddLine(HelpText.Lookup('HELPTITLE_TECHLIST'), pkBigIcon, 39,
    13491342                  hkAdv, 200);
    13501343                LineFeed;
    1351                 FindStdModelPicture(SpecialModelPictureCode[6], i, s);
    1352                 AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, i,
     1344                FindStdModelPicture(SpecialModelPictureCode[6], I, S);
     1345                AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, I,
    13531346                  hkModel, 0);
    13541347                LineFeed;
     
    13661359                LineFeed;
    13671360                AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkBigIcon,
    1368                   gDemocracy + 6, hkMisc, miscGovList);
     1361                  gDemocracy + 6, hkMisc, Integer(miscGovList));
    13691362                LineFeed;
    13701363                AddLine(HelpText.Lookup('HELPTITLE_KEYS'), pkBigIcon, 2, hkText,
     
    13751368                LineFeed;
    13761369                AddLine(HelpText.Lookup('HELPTITLE_CREDITS'), pkBigIcon, 22,
    1377                   hkMisc, miscCredits);
     1370                  hkMisc, Integer(miscCredits));
    13781371              end;
    1379             miscCredits:
     1372            Integer(miscCredits):
    13801373              begin
    13811374                AddItem('CREDITS');
     
    13901383                AddItem('AUTHOR');
    13911384              end;
    1392             miscJobList:
     1385            Integer(miscJobList):
    13931386              begin
    13941387                Caption := HelpText.Lookup('HELPTITLE_JOBLIST');
     
    13991392                AddItem('TERIMPCITY');
    14001393              end;
    1401             miscGovList:
     1394            Integer(miscGovList):
    14021395              begin
    14031396                Caption := HelpText.Lookup('HELPTITLE_GOVLIST');
    1404                 for i := 1 to nGov do
     1397                for I := 1 to nGov do
    14051398                begin
    1406                   AddLine(Phrases.Lookup('GOVERNMENT', i mod nGov), pkSection);
     1399                  AddLine(Phrases.Lookup('GOVERNMENT', I mod nGov), pkSection);
    14071400                  LineFeed;
    1408                   if i = nGov then
     1401                  if I = nGov then
    14091402                    AddLine('', pkBigIcon, 7 * SystemIconLines + imPalace)
    14101403                  else
    1411                     AddLine('', pkBigIcon, i + 6);
     1404                    AddLine('', pkBigIcon, I + 6);
    14121405                  LineFeed;
    1413                   AddTextual(HelpText.LookupByHandle(hGOVHELP, i mod nGov));
    1414                   if i mod nGov >= 2 then
     1406                  AddTextual(HelpText.LookupByHandle(hGOVHELP, I mod nGov));
     1407                  if I mod nGov >= 2 then
    14151408                  begin
    1416                     AddPreqAdv(GovPreq[i mod nGov]);
     1409                    AddPreqAdv(GovPreq[I mod nGov]);
    14171410                    MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    14181411                      [MainText[Count - 1]]);
    14191412                  end;
    1420                   if i < nGov then
     1413                  if I < nGov then
    14211414                  begin
    14221415                    LineFeed;
     
    14251418                end;
    14261419              end;
    1427             miscSearchResult:
     1420            Integer(miscSearchResult):
    14281421              begin
    14291422                Caption := HelpText.Lookup('HELPTITLE_SEARCHRESULTS');
     
    14311424                MainText.AppendList(SearchResult);
    14321425              end;
    1433           end; // case no
     1426          end; // case No
    14341427        end;
    14351428
    14361429      hkAdv:
    1437         if no = 200 then
     1430        if No = 200 then
    14381431        begin // complete advance list
    14391432          Caption := HelpText.Lookup('HELPTITLE_TECHLIST');
    14401433          List := THyperText.Create;
    14411434          List.OwnsObjects := True;
    1442           for j := 0 to 3 do
     1435          for J := 0 to 3 do
    14431436          begin
    1444             if j > 0 then
     1437            if J > 0 then
    14451438            begin
    14461439              LineFeed;
    14471440              LineFeed;
    14481441            end;
    1449             AddLine(HelpText.Lookup('TECHAGE', j), pkSection);
    1450             if j = 1 then
     1442            AddLine(HelpText.Lookup('TECHAGE', J), pkSection);
     1443            if J = 1 then
    14511444              AddLine(Phrases.Lookup('ADVANCES', adScience) + ' ' +
    14521445                HelpText.Lookup('BASETECH'), pkAdvIcon, adScience, hkAdv,
    14531446                adScience);
    1454             if j = 2 then
     1447            if J = 2 then
    14551448              AddLine(Phrases.Lookup('ADVANCES', adMassProduction) + ' ' +
    14561449                HelpText.Lookup('BASETECH'), pkAdvIcon, adMassProduction, hkAdv,
    14571450                adMassProduction);
    14581451            List.Clear;
    1459             for i := 0 to nAdv - 1 do
    1460               if (i <> adScience) and (i <> adMassProduction) and
    1461                 (AdvValue[i] div 1000 = j) then
    1462                 List.AddLine(Phrases.Lookup('ADVANCES', i), pkAdvIcon, i,
    1463                   hkAdv, i);
     1452            for I := 0 to nAdv - 1 do
     1453              if (I <> adScience) and (I <> adMassProduction) and
     1454                (AdvValue[I] div 1000 = J) then
     1455                List.AddLine(Phrases.Lookup('ADVANCES', I), pkAdvIcon, I,
     1456                  hkAdv, I);
    14641457            List.Sort;
    14651458            AppendList(List);
     
    14691462        else // single advance
    14701463        begin
    1471           Caption := Phrases.Lookup('ADVANCES', no);
     1464          Caption := Phrases.Lookup('ADVANCES', No);
    14721465          LineFeed;
    1473           AddLine(Phrases.Lookup('ADVANCES', no), pkCaption);
    1474           if no in FutureTech then
     1466          AddLine(Phrases.Lookup('ADVANCES', No), pkCaption);
     1467          if No in FutureTech then
    14751468          begin
    14761469            AddLine(HelpText.Lookup('HELPSPEC_FUTURE'));
    14771470            LineFeed;
    1478             if no = futResearchTechnology then
     1471            if No = futResearchTechnology then
    14791472              AddItem('FUTURETECHHELP100')
    14801473            else
     
    14831476          else
    14841477            AddLine(HelpText.Lookup('HELPSPEC_ADV'));
    1485           if AdvPreq[no, 2] <> preNone then
     1478          if AdvPreq[No, 2] <> preNone then
    14861479            NextSection('PREREQALT')
    14871480          else
    14881481            NextSection('PREREQ');
    1489           for i := 0 to 2 do
    1490             if AdvPreq[no, i] <> preNone then
    1491               AddPreqAdv(AdvPreq[no, i]);
     1482          for I := 0 to 2 do
     1483            if AdvPreq[No, I] <> preNone then
     1484              AddPreqAdv(AdvPreq[No, I]);
    14921485          NextSection('GOVALLOW');
    1493           for i := 2 to nGov - 1 do
    1494             if GovPreq[i] = no then
    1495               AddLine(Phrases.Lookup('GOVERNMENT', i), pkGov, i,
    1496                 hkMisc + hkCrossLink, miscGovList);
     1486          for I := 2 to nGov - 1 do
     1487            if GovPreq[I] = No then
     1488              AddLine(Phrases.Lookup('GOVERNMENT', I), pkGov, I,
     1489                hkMisc, Integer(miscGovList), True);
    14971490          NextSection('BUILDALLOW');
    1498           for i := 0 to nWonder - 1 do
    1499             if Imp[i].Preq = no then
    1500               AddImprovement(i);
    1501           for i := nWonder to nImp - 1 do
    1502             if (Imp[i].Preq = no) and (Imp[i].Kind <> ikCommon) then
    1503               AddImprovement(i);
    1504           for i := nWonder to nImp - 1 do
    1505             if (Imp[i].Preq = no) and (Imp[i].Kind = ikCommon) then
    1506               AddImprovement(i);
     1491          for I := 0 to nWonder - 1 do
     1492            if Imp[I].Preq = No then
     1493              AddImprovement(I);
     1494          for I := nWonder to nImp - 1 do
     1495            if (Imp[I].Preq = No) and (Imp[I].Kind <> ikCommon) then
     1496              AddImprovement(I);
     1497          for I := nWonder to nImp - 1 do
     1498            if (Imp[I].Preq = No) and (Imp[I].Kind = ikCommon) then
     1499              AddImprovement(I);
    15071500          NextSection('MODELALLOW');
    1508           for i := 0 to nSpecialModel - 1 do
    1509             if SpecialModelPreq[i] = no then
    1510               AddModel(i);
     1501          for I := 0 to nSpecialModel - 1 do
     1502            if SpecialModelPreq[I] = No then
     1503              AddModel(I);
    15111504          NextSection('FEATALLOW');
    1512           for i := 0 to nFeature - 1 do
    1513             if Feature[i].Preq = no then
    1514               AddFeature(i);
     1505          for I := 0 to nFeature - 1 do
     1506            if Feature[I].Preq = No then
     1507              AddFeature(I);
    15151508          NextSection('FOLLOWADV');
    1516           for i := 0 to nAdv - 1 do
    1517             if (AdvPreq[i, 0] = no) or (AdvPreq[i, 1] = no) or
    1518               (AdvPreq[i, 2] = no) then
    1519               AddAdvance(i);
     1509          for I := 0 to nAdv - 1 do
     1510            if (AdvPreq[I, 0] = No) or (AdvPreq[I, 1] = No) or
     1511              (AdvPreq[I, 2] = No) then
     1512              AddAdvance(I);
    15201513          NextSection('UPGRADEALLOW');
    15211514          for Domain := 0 to nDomains - 1 do
    1522             for i := 1 to nUpgrade - 1 do
    1523               if upgrade[Domain, i].Preq = no then
     1515            for I := 1 to nUpgrade - 1 do
     1516              if upgrade[Domain, I].Preq = No then
    15241517              begin
    1525                 if upgrade[Domain, i].Strength > 0 then
     1518                if upgrade[Domain, I].Strength > 0 then
    15261519                  AddLine(Format(HelpText.Lookup('STRENGTHUP'),
    15271520                    [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain,
    1528                     i].Strength]), pkDomain, Domain);
    1529                 if upgrade[Domain, i].Trans > 0 then
     1521                    I].Strength]), pkDomain, Domain);
     1522                if upgrade[Domain, I].Trans > 0 then
    15301523                  AddLine(Format(HelpText.Lookup('TRANSUP'),
    1531                     [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, i].Trans]
     1524                    [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, I].Trans]
    15321525                    ), pkDomain, Domain);
    1533                 if no in FutureTech then
     1526                if No in FutureTech then
    15341527                  AddLine(Format(HelpText.Lookup('COSTUP'),
    1535                     [upgrade[Domain, i].Cost]), pkNormal_Dot)
     1528                    [upgrade[Domain, I].Cost]), pkNormal_Dot)
    15361529                else
    15371530                  AddLine(Format(HelpText.Lookup('COSTMIN'),
    1538                     [upgrade[Domain, i].Cost]), pkNormal_Dot)
     1531                    [upgrade[Domain, I].Cost]), pkNormal_Dot)
    15391532              end;
    15401533          NextSection('EXPIRATION');
    1541           for i := 0 to nWonder - 1 do
    1542             if (Imp[i].Preq <> preNA) and (Imp[i].Expiration = no) then
    1543               AddImprovement(i);
     1534          for I := 0 to nWonder - 1 do
     1535            if (Imp[I].Preq <> preNA) and (Imp[I].Expiration = No) then
     1536              AddImprovement(I);
    15441537          NextSection('ADVEFFECT');
    1545           s := HelpText.LookupByHandle(hADVHELP, no);
    1546           if s <> '*' then
    1547             AddTextual(s);
     1538          S := HelpText.LookupByHandle(hADVHELP, No);
     1539          if S <> '*' then
     1540            AddTextual(S);
    15481541          NextSection('SEEALSO');
    1549           CheckSeeAlso := true
     1542          CheckSeeAlso := True;
    15501543        end;
    15511544
    15521545      hkImp:
    1553         if no = 200 then
     1546        if No = 200 then
    15541547        begin // complete city improvement list
    15551548          Caption := HelpText.Lookup('HELPTITLE_IMPLIST');
     
    15571550          List := THyperText.Create;
    15581551          List.OwnsObjects := True;
    1559           for i := nWonder to nImp - 1 do
    1560             if (i <> imTrGoods) and (Imp[i].Preq <> preNA) and
    1561               (Imp[i].Kind = ikCommon) then
    1562               List.AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon,
    1563                 i, hkImp, i);
     1552          for I := nWonder to nImp - 1 do
     1553            if (I <> imTrGoods) and (Imp[I].Preq <> preNA) and
     1554              (Imp[I].Kind = ikCommon) then
     1555              List.AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon,
     1556                I, hkImp, I);
    15641557          List.Sort;
    15651558          AppendList(List);
    15661559          FreeAndNil(List);
    15671560        end
    1568         else if no = 201 then
     1561        else if No = 201 then
    15691562        begin // complete nat. project list
    15701563          Caption := HelpText.Lookup('HELPTITLE_UNIQUELIST');
    15711564          // AddLine(HelpText.Lookup('HELPTITLE_UNIQUELIST'),pkSection);
    1572           for i := nWonder to nImp - 1 do
    1573             if (Imp[i].Preq <> preNA) and
    1574               ((Imp[i].Kind = ikNatLocal) or (Imp[i].Kind = ikNatGlobal)) then
    1575               AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,
    1576                 hkImp, i);
     1565          for I := nWonder to nImp - 1 do
     1566            if (Imp[I].Preq <> preNA) and
     1567              ((Imp[I].Kind = ikNatLocal) or (Imp[I].Kind = ikNatGlobal)) then
     1568              AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I,
     1569                hkImp, I);
    15771570          { LineFeed;
    15781571            LineFeed;
    15791572            AddLine(HelpText.Lookup('HELPTITLE_SHIPPARTLIST'),pkSection);
    1580             for i:= nWonder to nImp-1 do
    1581             if (Imp[i].Preq<>preNA) and (Imp[i].Kind=ikShipPart) then
    1582             AddLine(Phrases.Lookup('IMPROVEMENTS',i),pkSmallIcon,i,hkImp,i); }
     1573            for I:= nWonder to nImp-1 do
     1574            if (Imp[I].Preq<>preNA) and (Imp[I].Kind=ikShipPart) then
     1575            AddLine(Phrases.Lookup('IMPROVEMENTS',I),pkSmallIcon,I,hkImp,I); }
    15831576        end
    1584         else if no = 202 then
     1577        else if No = 202 then
    15851578        begin // complete wonder list
    15861579          Caption := HelpText.Lookup('HELPTITLE_WONDERLIST');
    15871580          // AddLine(HelpText.Lookup('HELPTITLE_WONDERLIST'),pkSection);
    1588           for i := 0 to nWonder - 1 do
    1589             if Imp[i].Preq <> preNA then
    1590               AddLine(Phrases.Lookup('IMPROVEMENTS', i), pkSmallIcon, i,
    1591                 hkImp, i);
     1581          for I := 0 to nWonder - 1 do
     1582            if Imp[I].Preq <> preNA then
     1583              AddLine(Phrases.Lookup('IMPROVEMENTS', I), pkSmallIcon, I,
     1584                hkImp, I);
    15921585        end
    15931586        else
    15941587        begin // single building
    1595           Caption := Phrases.Lookup('IMPROVEMENTS', no);
     1588          Caption := Phrases.Lookup('IMPROVEMENTS', No);
    15961589          LineFeed;
    1597           AddLine(Phrases.Lookup('IMPROVEMENTS', no), pkRightIcon, no);
    1598           case Imp[no].Kind of
     1590          AddLine(Phrases.Lookup('IMPROVEMENTS', No), pkRightIcon, No);
     1591          case Imp[No].Kind of
    15991592            ikWonder: AddLine(HelpText.Lookup('HELPSPEC_WONDER'));
    16001593            ikCommon: AddLine(HelpText.Lookup('HELPSPEC_IMP'));
     
    16031596            AddLine(HelpText.Lookup('HELPSPEC_NAT'))
    16041597          end;
    1605           if Imp[no].Kind <> ikShipPart then begin
     1598          if Imp[No].Kind <> ikShipPart then begin
    16061599            NextSection('EFFECT');
    1607             AddTextual(HelpText.LookupByHandle(hIMPHELP, no));
     1600            AddTextual(HelpText.LookupByHandle(hIMPHELP, No));
    16081601          end;
    1609           if no = woSun then begin
     1602          if No = woSun then begin
    16101603            AddFeature(mcFirst);
    16111604            AddFeature(mcWill);
    16121605            AddFeature(mcAcademy);
    16131606          end;
    1614           if (no < nWonder) and not Phrases2FallenBackToEnglish then
     1607          if (No < nWonder) and not Phrases2FallenBackToEnglish then
    16151608          begin
    16161609            LineFeed;
    1617             if Imp[no].Expiration >= 0 then
     1610            if Imp[No].Expiration >= 0 then
    16181611              AddTextual(Phrases2.Lookup('HELP_WONDERMORALE1'))
    16191612            else
    16201613              AddTextual(Phrases2.Lookup('HELP_WONDERMORALE2'));
    16211614          end;
    1622           if Imp[no].Preq <> preNone then
     1615          if Imp[No].Preq <> preNone then
    16231616          begin
    16241617            NextSection('PREREQ');
    1625             AddPreqAdv(Imp[no].Preq);
     1618            AddPreqAdv(Imp[No].Preq);
    16261619          end;
    16271620          NextSection('COSTS');
    16281621          if Difficulty = 0 then
    1629             s := Format(HelpText.Lookup('BUILDCOST'), [Imp[no].Cost])
     1622            S := Format(HelpText.Lookup('BUILDCOST'), [Imp[No].Cost])
    16301623          else
    1631             s := Format(HelpText.Lookup('BUILDCOST'),
    1632               [Imp[no].Cost * BuildCostMod[Difficulty] div 12]);
    1633           AddLine(s);
    1634           if Imp[no].Maint > 0 then
    1635             AddLine(Format(HelpText.Lookup('MAINTCOST'), [Imp[no].Maint]));
    1636           j := 0;
    1637           for i := 0 to nImpReplacement - 1 do
    1638             if ImpReplacement[i].NewImp = no then
    1639             begin
    1640               if j = 0 then
     1624            S := Format(HelpText.Lookup('BUILDCOST'),
     1625              [Imp[No].Cost * BuildCostMod[Difficulty] div 12]);
     1626          AddLine(S);
     1627          if Imp[No].Maint > 0 then
     1628            AddLine(Format(HelpText.Lookup('MAINTCOST'), [Imp[No].Maint]));
     1629          J := 0;
     1630          for I := 0 to nImpReplacement - 1 do
     1631            if ImpReplacement[I].NewImp = No then
     1632            begin
     1633              if J = 0 then
    16411634              begin
    16421635                NextSection('REPLACE');
    16431636                AddItem('REPLACETEXT');
    1644                 j := 1;
     1637                J := 1;
    16451638              end;
    1646               AddImprovement(ImpReplacement[i].OldImp);
    1647             end;
    1648           if Imp[no].Kind = ikShipPart then
     1639              AddImprovement(ImpReplacement[I].OldImp);
     1640            end;
     1641          if Imp[No].Kind = ikShipPart then
    16491642          begin
    16501643            LineFeed;
    1651             if no = imShipComp then
    1652               i := 1
    1653             else if no = imShipPow then
    1654               i := 2
    1655             else { if no=imShipHab then }
    1656               i := 3;
     1644            if No = imShipComp then
     1645              I := 1
     1646            else if No = imShipPow then
     1647              I := 2
     1648            else { if No=imShipHab then }
     1649              I := 3;
    16571650            AddLine(Format(HelpText.Lookup('RAREREQUIRED'),
    1658               [Phrases.Lookup('TERRAIN', 3 * 12 + i)]), pkTer, 3 * 12 + i);
     1651              [Phrases.Lookup('TERRAIN', 3 * 12 + I)]), pkTer, 3 * 12 + I);
    16591652          end;
    1660           if (no < nWonder) and (Imp[no].Expiration >= 0) then
     1653          if (No < nWonder) and (Imp[No].Expiration >= 0) then
    16611654          begin
    16621655            NextSection('EXPIRATION');
    1663             s := Format(HelpText.Lookup('EXPWITH'),
    1664               [Phrases.Lookup('ADVANCES', Imp[no].Expiration)]);
    1665             if no = woPyramids then
    1666               s := s + ' ' + HelpText.Lookup('EXPSLAVE');
    1667             AddTextual(s);
     1656            S := Format(HelpText.Lookup('EXPWITH'),
     1657              [Phrases.Lookup('ADVANCES', Imp[No].Expiration)]);
     1658            if No = woPyramids then
     1659              S := S + ' ' + HelpText.Lookup('EXPSLAVE');
     1660            AddTextual(S);
    16681661          end;
    16691662          NextSection('SEEALSO');
    1670           if (no < nWonder) and (Imp[no].Expiration >= 0) then
     1663          if (No < nWonder) and (Imp[No].Expiration >= 0) then
    16711664            AddImprovement(woEiffel);
    1672           for i := 0 to nImpReplacement - 1 do
    1673             if ImpReplacement[i].OldImp = no then
    1674               AddImprovement(ImpReplacement[i].NewImp);
    1675           if no = imSupermarket then
     1665          for I := 0 to nImpReplacement - 1 do
     1666            if ImpReplacement[I].OldImp = No then
     1667              AddImprovement(ImpReplacement[I].NewImp);
     1668          if No = imSupermarket then
    16761669            AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0,
    1677               hkMisc + hkCrossLink, miscJobList);
    1678           CheckSeeAlso := true;
     1670              hkMisc, Integer(miscJobList), True);
     1671          CheckSeeAlso := True;
    16791672        end;
    16801673
    16811674      hkTer:
    1682         if no = 200 then
     1675        if No = 200 then
    16831676        begin // complete terrain type list
    16841677          Caption := HelpText.Lookup('HELPTITLE_TERLIST');
    16851678          // AddLine(HelpText.Lookup('HELPTITLE_TERLIST'),pkSection);
    1686           for i := 0 to nTerrainHelp - 1 do
    1687             AddTerrain(TerrainHelp[i]);
     1679          for I := 0 to Length(TerrainHelp) - 1 do
     1680            AddTerrain(TerrainHelp[I]);
    16881681        end
    16891682        else
    16901683        begin // sigle terrain type
    1691           TerrType := no mod 12;
     1684          TerrType := No mod 12;
    16921685          if TerrType = fJungle then
    16931686            TerrType := fForest;
    1694           TerrSubType := no div 12;
    1695           if no = 3 * 12 then
     1687          TerrSubType := No div 12;
     1688          if No = 3 * 12 then
    16961689          begin
    16971690            TerrType := fDesert;
     
    17001693          with Terrain[TerrType] do
    17011694          begin
    1702             Caption := Phrases.Lookup('TERRAIN', no);
     1695            Caption := Phrases.Lookup('TERRAIN', No);
    17031696            LineFeed;
    1704             AddLine(Phrases.Lookup('TERRAIN', no), pkBigTer, no);
     1697            AddLine(Phrases.Lookup('TERRAIN', No), pkBigTer, No);
    17051698            AddLine(HelpText.Lookup('HELPSPEC_TER'));
    17061699            LineFeed;
     
    17081701              AddLine(Format(HelpText.Lookup('RESPROD'),
    17091702                [ProdRes[TerrSubType]]));
    1710             if (no < 3 * 12) and (MineEff > 0) then
     1703            if (No < 3 * 12) and (MineEff > 0) then
    17111704              MainText[Count - 1] := MainText[Count - 1] + ' ' +
    17121705                Format(HelpText.Lookup('MOREMINE'), [MineEff]);
     
    17141707              AddLine(Format(HelpText.Lookup('RESFOOD'),
    17151708                [FoodRes[TerrSubType]]));
    1716             if (no < 3 * 12) and (IrrEff > 0) then
     1709            if (No < 3 * 12) and (IrrEff > 0) then
    17171710              MainText[Count - 1] := MainText[Count - 1] + ' ' +
    17181711                Format(HelpText.Lookup('MOREIRR'), [IrrEff]);
     
    17281721              else
    17291722                AddLine(HelpText.Lookup('MOVEPLAIN'));
    1730             if no = 3 * 12 then
     1723            if No = 3 * 12 then
    17311724            begin
    17321725              LineFeed;
    17331726              AddTextual(HelpText.Lookup('DEADLANDS'));
    17341727            end;
    1735             if (TerrType = fDesert) and (no <> fDesert + 12) then
     1728            if (TerrType = fDesert) and (No <> fDesert + 12) then
    17361729            begin
    17371730              LineFeed;
     
    17431736              AddTextual(Format(HelpText.Lookup('HOSTILE'), [ArcticThurst]));
    17441737            end;
    1745             if (no < 3 * 12) and (TransTerrain >= 0) then
     1738            if (No < 3 * 12) and (TransTerrain >= 0) then
    17461739            begin
    17471740              LineFeed;
    1748               i := TransTerrain;
    1749               if (TerrType <> fGrass) and (i <> fGrass) then
    1750                 i := i + TerrSubType * 12;
     1741              I := TransTerrain;
     1742              if (TerrType <> fGrass) and (I <> fGrass) then
     1743                I := I + TerrSubType * 12;
    17511744              // trafo to same Special resource group
    17521745              AddLine(Format(HelpText.Lookup('TRAFO'),
    1753                 [Phrases.Lookup('TERRAIN', i)]), pkTer, i,
    1754                 hkTer + hkCrossLink, i);
    1755               if no = fSwamp + 12 then
     1746                [Phrases.Lookup('TERRAIN', I)]), pkTer, I,
     1747                hkTer, I, True);
     1748              if No = fSwamp + 12 then
    17561749              begin
    17571750                LineFeed;
    17581751                AddLine(Format(HelpText.Lookup('TRAFO'),
    17591752                  [Phrases.Lookup('TERRAIN', TransTerrain + 24)]), pkTer,
    1760                   TransTerrain + 24, hkTer + hkCrossLink, TransTerrain + 24);
     1753                  TransTerrain + 24, hkTer, TransTerrain + 24, True);
    17611754              end
    1762               else if i = fGrass then
     1755              else if I = fGrass then
    17631756              begin
    17641757                LineFeed;
    17651758                AddLine(Format(HelpText.Lookup('TRAFO'),
    17661759                  [Phrases.Lookup('TERRAIN', fGrass + 12)]), pkTer, fGrass + 12,
    1767                   hkTer + hkCrossLink, fGrass + 12);
     1760                  hkTer, fGrass + 12, True);
    17681761              end;
    17691762            end;
    17701763            NextSection('SPECIAL');
    1771             if no = 3 * 12 then
     1764            if No = 3 * 12 then
    17721765            begin
    17731766              LineFeed;
     
    17801773              end;
    17811774            end
    1782             else if (no < 12) and (no <> fGrass) and (no <> fOcean) then
     1775            else if (No < 12) and (No <> fGrass) and (No <> fOcean) then
    17831776            begin
    17841777              LineFeed;
    17851778              for Special := 1 to 2 do
    1786                 if (no <> fArctic) and (no <> fSwamp) or (Special < 2) then
     1779                if (No <> fArctic) and (No <> fSwamp) or (Special < 2) then
    17871780                begin
    17881781                  if Special > 1 then
    17891782                    LineFeed;
    1790                   AddLine(Phrases.Lookup('TERRAIN', no + Special * 12), pkTer,
    1791                     no + Special * 12);
    1792                   i := FoodRes[Special] - FoodRes[0];
    1793                   if i <> 0 then
     1783                  AddLine(Phrases.Lookup('TERRAIN', No + Special * 12), pkTer,
     1784                    No + Special * 12);
     1785                  I := FoodRes[Special] - FoodRes[0];
     1786                  if I <> 0 then
    17941787                    MainText[Count - 1] := MainText[Count - 1] +
    1795                       Format(HelpText.Lookup('SPECIALFOOD'), [i]);
    1796                   i := ProdRes[Special] - ProdRes[0];
    1797                   if i <> 0 then
     1788                      Format(HelpText.Lookup('SPECIALFOOD'), [I]);
     1789                  I := ProdRes[Special] - ProdRes[0];
     1790                  if I <> 0 then
    17981791                    MainText[Count - 1] := MainText[Count - 1] +
    1799                       Format(HelpText.Lookup('SPECIALPROD'), [i]);
    1800                   i := TradeRes[Special] - TradeRes[0];
    1801                   if i <> 0 then
     1792                      Format(HelpText.Lookup('SPECIALPROD'), [I]);
     1793                  I := TradeRes[Special] - TradeRes[0];
     1794                  if I <> 0 then
    18021795                    MainText[Count - 1] := MainText[Count - 1] +
    1803                       Format(HelpText.Lookup('SPECIALTRADE'), [i]);
     1796                      Format(HelpText.Lookup('SPECIALTRADE'), [I]);
    18041797                end;
    18051798            end;
    1806             if no = 3 * 12 then
     1799            if No = 3 * 12 then
    18071800            begin
    18081801              LineFeed;
    18091802              AddTextual(HelpText.Lookup('RARE'));
    18101803            end;
    1811             if (no < 3 * 12) and (TerrType in [fDesert, fArctic]) then
     1804            if (No < 3 * 12) and (TerrType in [fDesert, fArctic]) then
    18121805            begin
    18131806              NextSection('SEEALSO');
    18141807              AddImprovement(woGardens);
    1815               CheckSeeAlso := true
     1808              CheckSeeAlso := True;
    18161809            end;
    18171810          end;
     
    18191812
    18201813      hkFeature:
    1821         if no = 200 then
     1814        if No = 200 then
    18221815        begin // complete feature list
    18231816          Caption := HelpText.Lookup('HELPTITLE_FEATURELIST');
     
    18371830            end;
    18381831            List.Clear;
    1839             for i := 0 to nFeature - 1 do
    1840               if Feature[i].Preq <> preNA then
     1832            for I := 0 to nFeature - 1 do
     1833              if Feature[I].Preq <> preNA then
    18411834              begin
    1842                 if i < mcFirstNonCap then
    1843                   j := 0
    1844                 else if i in AutoFeature then
    1845                   j := 2
     1835                if I < mcFirstNonCap then
     1836                  J := 0
     1837                else if I in AutoFeature then
     1838                  J := 2
    18461839                else
    1847                   j := 1;
    1848                 if j = Special then
    1849                   List.AddLine(Phrases.Lookup('FEATURES', i), pkFeature, i,
    1850                     hkFeature, i);
     1840                  J := 1;
     1841                if J = Special then
     1842                  List.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I,
     1843                    hkFeature, I);
    18511844              end;
    18521845            List.Sort;
     
    18571850        else
    18581851        begin // single feature
    1859           Caption := Phrases.Lookup('FEATURES', no);
     1852          Caption := Phrases.Lookup('FEATURES', No);
    18601853          LineFeed;
    1861           AddLine(Phrases.Lookup('FEATURES', no), pkBigFeature, no);
    1862           if no < mcFirstNonCap then
     1854          AddLine(Phrases.Lookup('FEATURES', No), pkBigFeature, No);
     1855          if No < mcFirstNonCap then
    18631856            AddLine(HelpText.Lookup('HELPSPEC_CAP'))
    1864           else if no in AutoFeature then
     1857          else if No in AutoFeature then
    18651858            AddLine(HelpText.Lookup('HELPSPEC_STANDARD'))
    18661859          else
    18671860            AddLine(HelpText.Lookup('HELPSPEC_FEATURE'));
    18681861          NextSection('EFFECT');
    1869           AddTextual(HelpText.LookupByHandle(hFEATUREHELP, no));
    1870           if (Feature[no].Weight <> 0) or (Feature[no].Cost <> 0) then
     1862          AddTextual(HelpText.LookupByHandle(hFEATUREHELP, No));
     1863          if (Feature[No].Weight <> 0) or (Feature[No].Cost <> 0) then
    18711864          begin
    18721865            NextSection('COSTS');
    1873             s := IntToStr(Feature[no].Cost);
    1874             if Feature[no].Cost >= 0 then
    1875               s := '+' + s;
    1876             AddLine(Format(HelpText.Lookup('COSTBASE'), [s]));
    1877             if Feature[no].Weight > 0 then
     1866            S := IntToStr(Feature[No].Cost);
     1867            if Feature[No].Cost >= 0 then
     1868              S := '+' + S;
     1869            AddLine(Format(HelpText.Lookup('COSTBASE'), [S]));
     1870            if Feature[No].Weight > 0 then
    18781871            begin
    18791872              AddLine(Format(HelpText.Lookup('WEIGHT'),
    1880                 ['+' + IntToStr(Feature[no].Weight)]));
    1881               if no = mcDefense then
     1873                ['+' + IntToStr(Feature[No].Weight)]));
     1874              if No = mcDefense then
    18821875                AddLine(Format(HelpText.Lookup('WEIGHT'), ['+2']),
    18831876                  pkDomain, dGround);
    18841877            end;
    18851878          end;
    1886           if Feature[no].Preq <> preNone then
     1879          if Feature[No].Preq <> preNone then
    18871880          begin
    18881881            LineFeed;
    1889             if Feature[no].Preq = preSun then
     1882            if Feature[No].Preq = preSun then
    18901883              AddPreqImp(woSun) // sun tsu feature
    18911884            else
    1892               AddPreqAdv(Feature[no].Preq);
     1885              AddPreqAdv(Feature[No].Preq);
    18931886            MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    18941887              [MainText[Count - 1]]);
     
    19011894        begin
    19021895          Caption := HelpText.Lookup('HELPTITLE_MODELLIST');
    1903           for i := 0 to nSpecialModel - 1 do
    1904             if i <> 2 then
    1905               AddModelText(i);
     1896          for I := 0 to nSpecialModel - 1 do
     1897            if I <> 2 then
     1898              AddModelText(I);
    19061899          LineFeed;
    19071900          AddItem('MODELNOTE');
     
    19101903    end;
    19111904    if CheckSeeAlso then
    1912       for i := 0 to nSeeAlso - 1 do
    1913         if (SeeAlso[i].Kind = Kind) and (SeeAlso[i].no = no) then
    1914           case SeeAlso[i].SeeKind of
    1915             hkImp: AddImprovement(SeeAlso[i].SeeNo);
    1916             hkAdv: AddAdvance(SeeAlso[i].SeeNo);
    1917             hkFeature: AddFeature(SeeAlso[i].SeeNo);
     1905      for I := 0 to Length(SeeAlso) - 1 do
     1906        if (SeeAlso[I].Kind = Kind) and (SeeAlso[I].No = No) then
     1907          case SeeAlso[I].SeeKind of
     1908            hkImp: AddImprovement(SeeAlso[I].SeeNo);
     1909            hkAdv: AddAdvance(SeeAlso[I].SeeNo);
     1910            hkFeature: AddFeature(SeeAlso[I].SeeNo);
    19181911          end;
    19191912    if (Headline >= 0) and (Count = Headline + 1) then
     
    19261919    ScrollBar.SetPos(sbPos);
    19271920    BackBtn.Visible := HistItems.Count > 1;
    1928     TopBtn.Visible := (HistItems.Count > 1) or (Kind <> hkMisc) or (no <> miscMain);
     1921    TopBtn.Visible := (HistItems.Count > 1) or (Kind <> hkMisc) or (No <> Integer(miscMain));
    19291922    Sel := -1;
    19301923  end; // with MainText
    19311924end;
    19321925
    1933 procedure THelpDlg.ShowNewContent(NewMode, Category, Index: Integer);
    1934 begin
    1935   if (Category <> Kind) or (Index <> no) or (Category = hkMisc) and
    1936     (Index = miscSearchResult) then begin
     1926procedure THelpDlg.ShowNewContent(NewMode: TWindowMode; Category: TLinkCategory;
     1927  Index: Integer);
     1928begin
     1929  if (Category <> Kind) or (Index <> No) or (Category = hkMisc) and
     1930    (Index = Integer(miscSearchResult)) then begin
    19371931    if HistItems.Count = MaxHist then HistItems.Delete(0);
    19381932    if HistItems.Count = 0 then
     
    19411935  end;
    19421936  Kind := Category;
    1943   no := Index;
     1937  No := Index;
    19441938  SearchContent := NewSearchContent;
    19451939  Prepare;
     
    19491943
    19501944procedure THelpDlg.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    1951   x, y: integer);
     1945  X, Y: Integer);
    19521946var
    19531947  i0, Sel0: Integer;
    19541948begin
    1955   y := y - WideFrame;
     1949  Y := Y - WideFrame;
    19561950  i0 := ScrollBar.Position;
    19571951  Sel0 := Sel;
    1958   if (x >= SideFrame) and (x < SideFrame + InnerWidth) and (y >= 0) and
    1959     (y < InnerHeight) and (y mod 24 >= 8) then
    1960     Sel := y div 24
     1952  if (X >= SideFrame) and (X < SideFrame + InnerWidth) and (Y >= 0) and
     1953    (Y < InnerHeight) and (Y mod 24 >= 8) then
     1954    Sel := Y div 24
    19611955  else
    19621956    Sel := -1;
    19631957  if (Sel + i0 >= MainText.Count) or (Sel >= 0) and
    1964     (THelpLineInfo(MainText.Objects[Sel + i0]).Link = 0) then
     1958    (THelpLineInfo(MainText.Objects[Sel + i0]).Category = hkNoLink) and
     1959    (THelpLineInfo(MainText.Objects[Sel + i0]).Index = 0)then
    19651960    Sel := -1;
    19661961  if Sel <> Sel0 then
     
    19741969
    19751970procedure THelpDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    1976   Shift: TShiftState; x, y: integer);
     1971  Shift: TShiftState; X, Y: Integer);
    19771972begin
    19781973  if Sel >= 0 then
    19791974    with THelpLineInfo(MainText.Objects[Sel + ScrollBar.Position]) do
    1980       if Link shr 8 and $3F = hkInternet then
    1981         case Link and $FF of
     1975      if Category = hkInternet then
     1976        case Index of
    19821977          1: OpenDocument(HomeDir + AITemplateFileName);
    19831978          2: OpenURL(CevoHomepage);
     
    19861981      else
    19871982      begin
    1988         if (Link >= $8000) and (Link and $3FFF = liInvalid) then
    1989           exit; // invalid link;
    1990         if Link >= $8000 then
    1991           ShowNewContent(FWindowMode, hkText, Link and $3FFF)
    1992         else
    1993           ShowNewContent(FWindowMode, Link shr 8 and $3F, Link and $FF);
     1983        if Index < 0 then Exit; // invalid link;
     1984        ShowNewContent(FWindowMode, Category, Index);
    19941985      end;
    19951986end;
     
    20031994    HistItem.Assign(HistItems.Last);
    20041995    HistItems.Delete(HistItems.Count - 1);
    2005     if (HistItem.Kind = hkMisc) and (HistItem.No = miscSearchResult) and
     1996    if (HistItem.Kind = hkMisc) and (HistItem.No = Integer(miscSearchResult)) and
    20061997      (HistItem.SearchContent <> SearchContent) then
    20071998    begin
     
    20102001    end;
    20112002    Kind := HistItem.Kind;
    2012     no := HistItem.No;
     2003    No := HistItem.No;
    20132004    Prepare(HistItem.Pos);
    20142005    OffscreenPaint;
     
    20222013  while HistItems.Count > 1 do HistItems.Delete(HistItems.Count - 1);
    20232014  Kind := hkMisc;
    2024   no := miscMain;
     2015  No := Integer(miscMain);
    20252016  Prepare;
    20262017  OffscreenPaint;
     
    20362027function THelpDlg.TextIndex(Item: string): Integer;
    20372028begin
    2038   Result := HelpText.Gethandle(Item);
     2029  Result := HelpText.GetHandle(Item);
    20392030end;
    20402031
     
    20642055      1:
    20652056        with THelpLineInfo(SearchResult.Objects[0]) do
    2066           if Link >= $8000 then
    2067             ShowNewContent(FWindowMode, hkText, Link and $3FFF)
    2068           else
    2069             ShowNewContent(FWindowMode, Link shr 8 and $3F, Link and $FF);
    2070     else
    2071       begin
     2057          ShowNewContent(FWindowMode, Category, Index);
     2058      else begin
    20722059        NewSearchContent := InputDlg.EInput.Text;
    2073         ShowNewContent(FWindowMode, hkMisc, miscSearchResult);
     2060        ShowNewContent(FWindowMode, hkMisc, Integer(miscSearchResult));
    20742061      end;
    20752062    end;
     
    20792066procedure THelpDlg.Search(SearchString: string);
    20802067var
    2081   h, i, PrevHandle, PrevIndex, p, RightMargin: Integer;
    2082   s: string;
    2083   mADVHELP, mIMPHELP, mFEATUREHELP: set of 0 .. 255;
     2068  H, I, PrevHandle, PrevIndex, P, RightMargin: Integer;
     2069  S: string;
     2070  mADVHELP, mIMPHELP, mFEATUREHELP: set of 0..255;
    20842071  bGOVHELP, bSPECIALMODEL, bJOBHELP: Boolean;
    20852072begin
     
    20922079  bJOBHELP := False;
    20932080
    2094   // search in generic reference
     2081  // Search in generic reference
    20952082  SearchString := UpperCase(SearchString);
    2096   for i := 0 to 35 + 4 do begin
    2097     s := Phrases.Lookup('TERRAIN', i);
    2098     if pos(SearchString, UpperCase(s)) > 0 then
    2099       if i < 36 then
    2100         SearchResult.AddLine(s + ' ' + HelpText.Lookup('HELPSPEC_TER'),
    2101           pkNormal, 0, hkTer + hkCrossLink, i)
     2083  for I := 0 to 35 + 4 do begin
     2084    S := Phrases.Lookup('TERRAIN', I);
     2085    if Pos(SearchString, UpperCase(S)) > 0 then
     2086      if I < 36 then
     2087        SearchResult.AddLine(S + ' ' + HelpText.Lookup('HELPSPEC_TER'),
     2088          pkNormal, 0, hkTer, I, True)
    21022089      else
    21032090      begin
    21042091        SearchResult.AddLine(Phrases.Lookup('TERRAIN', 36) + ' ' +
    21052092          HelpText.Lookup('HELPSPEC_TER'), pkNormal, 0,
    2106           hkTer + hkCrossLink, 36);
    2107         if i > 36 then
     2093          hkTer, 36, True);
     2094        if I > 36 then
    21082095          SearchResult.AddLine(Phrases.Lookup('IMPROVEMENTS',
    2109             imShipComp + i - 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'),
    2110             pkNormal, 0, hkImp + hkCrossLink, imShipComp + i - 37);
     2096            imShipComp + I - 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'),
     2097            pkNormal, 0, hkImp, imShipComp + I - 37, True);
    21112098        Break;
    21122099      end;
    21132100  end;
    2114   for i := 0 to nJobHelp - 1 do
    2115     if pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[i]))) > 0
     2101  for I := 0 to Length(JobHelp) - 1 do
     2102    if Pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[I]))) > 0
    21162103    then
    21172104    begin
    21182105      SearchResult.AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0,
    2119         hkMisc + hkCrossLink, miscJobList);
     2106        hkMisc, Integer(miscJobList), True);
    21202107      bJOBHELP := True;
    21212108      Break;
    21222109    end;
    2123   for i := 0 to nAdv - 1 do
    2124   begin
    2125     s := Phrases.Lookup('ADVANCES', i);
    2126     if pos(SearchString, UpperCase(s)) > 0 then
     2110  for I := 0 to nAdv - 1 do
     2111  begin
     2112    S := Phrases.Lookup('ADVANCES', I);
     2113    if Pos(SearchString, UpperCase(S)) > 0 then
    21272114    begin
    2128       if i in FutureTech then
    2129         s := s + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
     2115      if I in FutureTech then
     2116        S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
    21302117      else
    2131         s := s + ' ' + HelpText.Lookup('HELPSPEC_ADV');
    2132       SearchResult.AddLine(s, pkNormal, 0, hkAdv + hkCrossLink, i);
    2133       include(mADVHELP, i);
     2118        S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV');
     2119      SearchResult.AddLine(S, pkNormal, 0, hkAdv, I, True);
     2120      Include(mADVHELP, I);
    21342121    end;
    21352122  end;
    2136   for i := 0 to nSpecialModel - 1 do
    2137   begin
    2138     FindStdModelPicture(SpecialModelPictureCode[i], h, s);
    2139     if pos(SearchString, UpperCase(s)) > 0 then
     2123  for I := 0 to nSpecialModel - 1 do
     2124  begin
     2125    FindStdModelPicture(SpecialModelPictureCode[I], H, S);
     2126    if Pos(SearchString, UpperCase(S)) > 0 then
    21402127    begin
    21412128      SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal, 0,
    2142         hkModel + hkCrossLink, 0);
     2129        hkModel, 0, True);
    21432130      bSPECIALMODEL := True;
    21442131      Break;
    21452132    end;
    21462133  end;
    2147   for i := 0 to nFeature - 1 do
    2148   begin
    2149     s := Phrases.Lookup('FEATURES', i);
    2150     if Pos(SearchString, UpperCase(s)) > 0 then
     2134  for I := 0 to nFeature - 1 do
     2135  begin
     2136    S := Phrases.Lookup('FEATURES', I);
     2137    if Pos(SearchString, UpperCase(S)) > 0 then
    21512138    begin
    2152       if i < mcFirstNonCap then
    2153         s := s + ' ' + HelpText.Lookup('HELPSPEC_CAP')
    2154       else if i in AutoFeature then
    2155         s := s + ' ' + HelpText.Lookup('HELPSPEC_STANDARD')
     2139      if I < mcFirstNonCap then
     2140        S := S + ' ' + HelpText.Lookup('HELPSPEC_CAP')
     2141      else if I in AutoFeature then
     2142        S := S + ' ' + HelpText.Lookup('HELPSPEC_STANDARD')
    21562143      else
    2157         s := s + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
    2158       SearchResult.AddLine(s, pkNormal, 0, hkFeature + hkCrossLink, i);
    2159       Include(mFEATUREHELP, i);
     2144        S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
     2145      SearchResult.AddLine(S, pkNormal, 0, hkFeature, I, True);
     2146      Include(mFEATUREHELP, I);
    21602147    end;
    21612148  end;
    2162   for i := 0 to nImp - 1 do
    2163   begin
    2164     s := Phrases.Lookup('IMPROVEMENTS', i);
    2165     if Pos(SearchString, UpperCase(s)) > 0 then
     2149  for I := 0 to nImp - 1 do
     2150  begin
     2151    S := Phrases.Lookup('IMPROVEMENTS', I);
     2152    if Pos(SearchString, UpperCase(S)) > 0 then
    21662153    begin
    2167       case Imp[i].Kind of
     2154      case Imp[I].Kind of
    21682155        ikWonder:
    2169           s := s + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
     2156          S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
    21702157        ikCommon:
    2171           s := s + ' ' + HelpText.Lookup('HELPSPEC_IMP');
     2158          S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP');
    21722159        ikShipPart:
    2173           s := s + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
     2160          S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
    21742161      else
    2175         s := s + ' ' + HelpText.Lookup('HELPSPEC_NAT')
     2162        S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT')
    21762163      end;
    2177       SearchResult.AddLine(s, pkNormal, 0, hkImp + hkCrossLink, i);
    2178       Include(mIMPHELP, i);
     2164      SearchResult.AddLine(S, pkNormal, 0, hkImp, I, True);
     2165      Include(mIMPHELP, I);
    21792166    end
    21802167  end;
    2181   for i := 0 to nGov - 1 do
    2182     if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', i))) > 0 then
     2168  for I := 0 to nGov - 1 do
     2169    if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', I))) > 0 then
    21832170    begin
    21842171      SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0,
    2185         hkMisc + hkCrossLink, miscGovList);
     2172        hkMisc, Integer(miscGovList), True);
    21862173      bGOVHELP := True;
    21872174      Break;
    21882175    end;
    21892176
    2190   // full text search
    2191   h := -1;
     2177  // Full text search
     2178  H := -1;
    21922179  repeat
    2193     PrevHandle := h;
    2194     PrevIndex := i;
    2195     if not HelpText.Search(SearchString, h, i) then
     2180    PrevHandle := H;
     2181    PrevIndex := I;
     2182    if not HelpText.Search(SearchString, H, I) then
    21962183      Break;
    2197     if h = hADVHELP then
     2184    if H = hADVHELP then
    21982185    begin
    2199       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2200         not(i in mADVHELP) then
     2186      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2187        not(I in mADVHELP) then
    22012188      begin
    2202         s := Phrases.Lookup('ADVANCES', i);
    2203         if i in FutureTech then
    2204           s := s + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
     2189        S := Phrases.Lookup('ADVANCES', I);
     2190        if I in FutureTech then
     2191          S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
    22052192        else
    2206           s := s + ' ' + HelpText.Lookup('HELPSPEC_ADV');
    2207         SearchResult.AddLine(s, pkNormal, 0, hkAdv + hkCrossLink, i)
     2193          S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV');
     2194        SearchResult.AddLine(S, pkNormal, 0, hkAdv, I, True);
    22082195      end;
    22092196    end
    2210     else if h = hIMPHELP then
     2197    else if H = hIMPHELP then
    22112198    begin
    2212       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2213         not(i in mIMPHELP) then
     2199      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2200        not(I in mIMPHELP) then
    22142201      begin
    2215         s := Phrases.Lookup('IMPROVEMENTS', i);
    2216         case Imp[i].Kind of
     2202        S := Phrases.Lookup('IMPROVEMENTS', I);
     2203        case Imp[I].Kind of
    22172204          ikWonder:
    2218             s := s + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
     2205            S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
    22192206          ikCommon:
    2220             s := s + ' ' + HelpText.Lookup('HELPSPEC_IMP');
     2207            S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP');
    22212208          ikShipPart:
    2222             s := s + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
     2209            S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
    22232210        else
    2224           s := s + ' ' + HelpText.Lookup('HELPSPEC_NAT')
     2211          S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT')
    22252212        end;
    2226         SearchResult.AddLine(s, pkNormal, 0, hkImp + hkCrossLink, i)
     2213        SearchResult.AddLine(S, pkNormal, 0, hkImp, I, True);
    22272214      end;
    22282215    end
    2229     else if h = hFEATUREHELP then
     2216    else if H = hFEATUREHELP then
    22302217    begin
    2231       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2232         not(i in mFEATUREHELP) then
     2218      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2219        not(I in mFEATUREHELP) then
    22332220      begin
    2234         s := Phrases.Lookup('FEATURES', i);
    2235         if i < mcFirstNonCap then
    2236           s := s + ' ' + HelpText.Lookup('HELPSPEC_CAP')
    2237         else if i in AutoFeature then
    2238           s := s + ' ' + HelpText.Lookup('HELPSPEC_STANDARD')
     2221        S := Phrases.Lookup('FEATURES', I);
     2222        if I < mcFirstNonCap then
     2223          S := S + ' ' + HelpText.Lookup('HELPSPEC_CAP')
     2224        else if I in AutoFeature then
     2225          S := S + ' ' + HelpText.Lookup('HELPSPEC_STANDARD')
    22392226        else
    2240           s := s + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
    2241         SearchResult.AddLine(s, pkNormal, 0, hkFeature + hkCrossLink, i);
     2227          S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
     2228        SearchResult.AddLine(S, pkNormal, 0, hkFeature, I, True);
    22422229      end;
    22432230    end
    2244     else if h = hGOVHELP then
     2231    else if H = hGOVHELP then
    22452232    begin
    2246       if (i >= 0) and (h <> PrevHandle) and not bGOVHELP then
     2233      if (I >= 0) and (H <> PrevHandle) and not bGOVHELP then
    22472234        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0,
    2248           hkMisc + hkCrossLink, miscGovList)
     2235          hkMisc, Integer(miscGovList), True);
    22492236    end
    2250     else if h = hSPECIALMODEL then
     2237    else if H = hSPECIALMODEL then
    22512238    begin
    2252       if (i >= 0) and (h <> PrevHandle) and not bSPECIALMODEL then
     2239      if (I >= 0) and (H <> PrevHandle) and not bSPECIALMODEL then
    22532240        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal,
    2254           0, hkModel + hkCrossLink, 0)
     2241          0, hkModel, 0, True);
    22552242    end
    2256     else if h = hJOBHELP then
     2243    else if H = hJOBHELP then
    22572244    begin
    2258       if (i >= 0) and (h <> PrevHandle) and not bJOBHELP then
     2245      if (I >= 0) and (H <> PrevHandle) and not bJOBHELP then
    22592246        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0,
    2260           hkMisc + hkCrossLink, miscJobList)
     2247          hkMisc, Integer(miscJobList), True);
    22612248    end
    2262     else if { (h<>hMAIN) and } (h <> PrevHandle) then
     2249    else if { (h<>hMAIN) and } (H <> PrevHandle) then
    22632250    begin
    2264       s := HelpText.LookupByHandle(h);
    2265       p := Pos('$', s);
    2266       if p > 0 then
     2251      S := HelpText.LookupByHandle(H);
     2252      P := Pos('$', S);
     2253      if P > 0 then
    22672254      begin
    2268         s := Copy(s, p + 1, maxint);
    2269         p := Pos('\', s);
    2270         if p > 0 then
    2271           s := Copy(s, 1, p - 1);
    2272         SearchResult.AddLine(s, pkNormal, 0, hkText + hkCrossLink, h);
     2255        S := Copy(S, P + 1, MaxInt);
     2256        P := Pos('\', S);
     2257        if P > 0 then
     2258          S := Copy(S, 1, P - 1);
     2259        SearchResult.AddLine(S, pkNormal, 0, hkText, H, True);
    22732260      end;
    22742261    end;
    2275     until False;
    2276 
    2277     // cut lines to fit to window
    2278     RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL);
    2279     OffScreen.Canvas.Font.Assign(UniFont[ftNormal]);
    2280     for i := 0 to SearchResult.Count - 1 do
    2281     begin
    2282       while BiColorTextWidth(OffScreen.Canvas, SearchResult[i]) >
    2283         RightMargin - 32 do
    2284         SearchResult[i] := copy(SearchResult[i], 1, length(SearchResult[i]) - 1)
    2285     end;
    2286   end;
     2262  until False;
     2263
     2264  // Cut lines to fit to window
     2265  RightMargin := InnerWidth - 16 - DpiGetSystemMetrics(SM_CXVSCROLL);
     2266  OffScreen.Canvas.Font.Assign(UniFont[ftNormal]);
     2267  for I := 0 to SearchResult.Count - 1 do
     2268  begin
     2269    while BiColorTextWidth(OffScreen.Canvas, SearchResult[I]) >
     2270      RightMargin - 32 do
     2271      SearchResult[I] := Copy(SearchResult[I], 1, Length(SearchResult[I]) - 1)
     2272  end;
     2273end;
    22872274
    22882275end.
  • branches/highdpi/LocalPlayer/IsoEngine.pas

    r405 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, ScreenTools, Tribes,
    8   LCLIntf, LCLType, SysUtils, Classes, Graphics, UPixelPointer, UGraphicSet;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, Tribes, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, PixelPointer, GraphicSet;
    99
    1010const
     
    1313
    1414type
    15   TInitEnemyModelEvent = function(emix: integer): boolean;
     15  TInitEnemyModelEvent = function(emix: Integer): Boolean;
    1616  TTileSize = (tsSmall, tsMedium, tsBig);
    1717
     
    3333      Dirx: array [0..7] of Integer = (1, 2, 1, 0, -1, -2, -1, 0);
    3434      Diry: array [0..7] of Integer = (-1, 0, 1, 2, 1, 0, -1, -2);
    35     procedure CityGrid(xm, ym: integer; CityAllowClick: Boolean);
    36     function IsShoreTile(Loc: integer): boolean;
     35    procedure CityGrid(xm, ym: Integer; CityAllowClick: Boolean);
     36    function IsShoreTile(Loc: Integer): Boolean;
    3737    procedure MakeDark(Line: PPixelPointer; Length: Integer);
    3838    procedure SetTileSize(AValue: TTileSize);
    39     procedure ShadeOutside(x0, y0, Width, Height, xm, ym: integer);
     39    procedure ShadeOutside(x0, y0, Width, Height, xm, ym: Integer);
    4040  protected
    4141    FOutput: TDpiBitmap;
     
    6565    ShowDebug: Boolean;
    6666    FoW: Boolean;
    67     function Connection4(Loc, Mask, Value: integer): integer;
    68     function Connection8(Loc, Mask: integer): integer;
    69     function OceanConnection(Loc: integer): integer;
    70     procedure PaintShore(x, y, Loc: integer);
    71     procedure PaintTileExtraTerrain(x, y, Loc: integer);
    72     procedure PaintTileObjects(x, y, Loc, CityLoc, CityOwner: integer;
    73       UseBlink: boolean);
    74     procedure PaintGrid(x, y, nx, ny: integer);
    75     procedure FillRect(x, y, Width, Height, Color: integer);
    76     procedure Textout(x, y, Color: integer; const s: string);
    77     procedure Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
    78     procedure TSprite(xDst, yDst, grix: integer; PureBlack: boolean = false);
     67    function Connection4(Loc, Mask, Value: Integer): Integer;
     68    function Connection8(Loc, Mask: Integer): Integer;
     69    function OceanConnection(Loc: Integer): Integer;
     70    procedure PaintShore(X, Y, Loc: Integer);
     71    procedure PaintTileExtraTerrain(X, Y, Loc: Integer);
     72    procedure PaintTileObjects(X, Y, Loc, CityLoc, CityOwner: Integer;
     73      UseBlink: Boolean);
     74    procedure PaintGrid(X, Y, nx, ny: Integer);
     75    procedure FillRect(X, Y, Width, Height, Color: Integer);
     76    procedure Textout(X, Y, Color: Integer; const S: string);
     77    procedure Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
     78    procedure TSprite(xDst, yDst, grix: Integer; PureBlack: Boolean = False);
    7979    procedure ApplyTileSize(ATileSize: TTileSize);
    8080  public
     
    8989    procedure Reset;
    9090    procedure SetOutput(Output: TDpiBitmap);
    91     procedure SetPaintBounds(Left, Top, Right, Bottom: integer);
    92     procedure Paint(x, y, Loc, nx, ny, CityLoc, CityOwner: integer;
    93       UseBlink: boolean = false; CityAllowClick: boolean = false);
    94     procedure PaintUnit(x, y: integer; const UnitInfo: TUnitInfo;
    95       Status: integer);
    96     procedure PaintCity(x, y: integer; const CityInfo: TCityInfo;
    97       accessory: boolean = true);
    98     procedure BitBltBitmap(Src: TDpiBitmap; x, y, Width, Height, xSrc, ySrc,
    99       Rop: integer);
     91    procedure SetPaintBounds(Left, Top, Right, Bottom: Integer);
     92    procedure Paint(X, Y, Loc, nx, ny, CityLoc, CityOwner: Integer;
     93      UseBlink: Boolean = False; CityAllowClick: Boolean = False);
     94    procedure PaintUnit(X, Y: Integer; const UnitInfo: TUnitInfo;
     95      Status: Integer);
     96    procedure PaintCity(X, Y: Integer; const CityInfo: TCityInfo;
     97      accessory: Boolean = True);
     98    procedure BitBltBitmap(Src: TDpiBitmap; X, Y, Width, Height, xSrc, ySrc,
     99      Rop: Integer);
    100100    procedure AttackBegin(const ShowMove: TShowMove);
    101101    procedure AttackEffect(const ShowMove: TShowMove);
    102102    procedure AttackEnd;
    103103    procedure ReduceTerrainIconsSize;
    104     property AdviceLoc: integer read FAdviceLoc write FAdviceLoc;
     104    property AdviceLoc: Integer read FAdviceLoc write FAdviceLoc;
    105105    property TileSize: TTileSize read FTileSize write SetTileSize;
    106106  end;
     
    127127    (X: 72; Y: 36));
    128128
    129 function IsJungle(y: integer): boolean;
     129function IsJungle(Y: Integer): Boolean;
    130130procedure Init(InitEnemyModelHandler: TInitEnemyModelEvent);
    131131
     
    173173  IsoMapCache: array[TTileSize] of TIsoMapCache;
    174174
    175 function IsJungle(y: integer): boolean;
    176 begin
    177   result := (y > (G.ly - 2) div 4) and (G.ly - 1 - y > (G.ly - 2) div 4)
     175function IsJungle(Y: Integer): Boolean;
     176begin
     177  Result := (Y > (G.ly - 2) div 4) and (G.ly - 1 - Y > (G.ly - 2) div 4)
    178178end;
    179179
     
    254254  Mask24.BeginUpdate;
    255255  for ySrc := 0 to TerrainIconLines - 1 do begin
    256     for i := 0 to yyt * 3 - 1 do
    257       MaskLine[i] := PixelPointer(Mask24, ScaleToNative(0),
    258         ScaleToNative(1 + ySrc * (yyt * 3 + 1) + i));
     256    for I := 0 to yyt * 3 - 1 do
     257      MaskLine[I] := TPixelPointer.Create(Mask24, ScaleToNative(0),
     258        ScaleToNative(1 + ySrc * (yyt * 3 + 1) + I));
    259259    for xSrc := 0 to TerrainIconCols - 1 do begin
    260       i := ySrc * 9 + xSrc;
    261       TSpriteSize[i].Left := 0;
     260      I := ySrc * 9 + xSrc;
     261      TSpriteSize[I].Left := 0;
    262262      repeat
    263         Border := true;
    264         for y := 0 to yyt * 3 - 1 do begin
    265           MaskLine[y].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + TSpriteSize[i].Left));
    266           if MaskLine[y].Pixel^.B = 0 then Border := false;
     263        Border := True;
     264        for Y := 0 to yyt * 3 - 1 do begin
     265          MaskLine[Y].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + TSpriteSize[I].Left));
     266          if MaskLine[Y].Pixel^.B = 0 then Border := False;
    267267        end;
    268         if Border then Inc(TSpriteSize[i].Left);
    269       until not Border or (TSpriteSize[i].Left = xxt * 2 - 1);
    270       TSpriteSize[i].Top := 0;
     268        if Border then Inc(TSpriteSize[I].Left);
     269      until not Border or (TSpriteSize[I].Left = xxt * 2 - 1);
     270      TSpriteSize[I].Top := 0;
    271271      repeat
    272         Border := true;
    273         for x := 0 to xxt * 2 - 1 do begin
    274           MaskLine[TSpriteSize[i].Top].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + x));
    275           if MaskLine[TSpriteSize[i].Top].Pixel^.B = 0 then Border := false;
     272        Border := True;
     273        for X := 0 to xxt * 2 - 1 do begin
     274          MaskLine[TSpriteSize[I].Top].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + X));
     275          if MaskLine[TSpriteSize[I].Top].Pixel^.B = 0 then Border := False;
    276276        end;
    277         if Border then inc(TSpriteSize[i].Top);
    278       until not Border or (TSpriteSize[i].Top = yyt * 3 - 1);
    279       TSpriteSize[i].Right := xxt * 2;
     277        if Border then Inc(TSpriteSize[I].Top);
     278      until not Border or (TSpriteSize[I].Top = yyt * 3 - 1);
     279      TSpriteSize[I].Right := xxt * 2;
    280280      repeat
    281         Border := true;
    282         for y := 0 to yyt * 3 - 1 do begin
    283           MaskLine[y].SetX(ScaleToNative(xSrc * (xxt * 2 + 1) + TSpriteSize[i].Right));
    284           if MaskLine[y].Pixel^.B = 0 then Border := false;
     281        Border := True;
     282        for Y := 0 to yyt * 3 - 1 do begin
     283          MaskLine[Y].SetX(ScaleToNative(xSrc * (xxt * 2 + 1) + TSpriteSize[I].Right));
     284          if MaskLine[Y].Pixel^.B = 0 then Border := False;
    285285        end;
    286         if Border then Dec(TSpriteSize[i].Right);
    287       until not Border or (TSpriteSize[i].Right = TSpriteSize[i].Left);
    288       TSpriteSize[i].Bottom := yyt * 3;
     286        if Border then Dec(TSpriteSize[I].Right);
     287      until not Border or (TSpriteSize[I].Right = TSpriteSize[I].Left);
     288      TSpriteSize[I].Bottom := yyt * 3;
    289289      repeat
    290         Border := true;
    291         for x := 0 to xxt * 2 - 1 do begin
    292           MaskLine[TSpriteSize[i].Bottom - 1].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + x));
    293           if MaskLine[TSpriteSize[i].Bottom - 1].Pixel^.B = 0 then Border := false;
     290        Border := True;
     291        for X := 0 to xxt * 2 - 1 do begin
     292          MaskLine[TSpriteSize[I].Bottom - 1].SetX(ScaleToNative(1 + xSrc * (xxt * 2 + 1) + X));
     293          if MaskLine[TSpriteSize[I].Bottom - 1].Pixel^.B = 0 then Border := False;
    294294        end;
    295         if Border then Dec(TSpriteSize[i].Bottom);
    296       until not Border or (TSpriteSize[i].Bottom = TSpriteSize[i].Top);
     295        if Border then Dec(TSpriteSize[I].Bottom);
     296      until not Border or (TSpriteSize[I].Bottom = TSpriteSize[I].Top);
    297297    end;
    298298  end;
     
    303303procedure TIsoMap.ApplyTileSize(ATileSize: TTileSize);
    304304var
    305   x: Integer;
    306   y: Integer;
     305  X: Integer;
     306  Y: Integer;
    307307  xSrc: Integer;
    308308  ySrc: Integer;
     
    357357  DitherMask.SetSize(xxt * 2, yyt * 2);
    358358  DitherMask.Canvas.FillRect(0, 0, DitherMask.Width, DitherMask.Height);
    359   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
     359  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
    360360    HGrTerrain.Mask.Canvas, 1 + 7 * (xxt * 2 + 1),
    361361    1 + yyt + 15 * (yyt * 3 + 1), SRCAND);
    362362
    363   for x := -1 to 6 do begin
    364     if x = -1 then begin
     363  for X := -1 to 6 do begin
     364    if X = -1 then begin
    365365      xSrc := ShoreDither * (xxt * 2 + 1) + 1;
    366366      ySrc := 1 + yyt;
    367367    end
    368     else if x = 6 then begin
     368    else if X = 6 then begin
    369369      xSrc := 1 + (xxt * 2 + 1) * 2;
    370370      ySrc := 1 + yyt + (yyt * 3 + 1) * 2;
    371371    end else begin
    372       xSrc := (x + 2) * (xxt * 2 + 1) + 1;
     372      xSrc := (X + 2) * (xxt * 2 + 1) + 1;
    373373      ySrc := 1 + yyt;
    374374    end;
    375     for y := -1 to 6 do
    376       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     375    for Y := -1 to 6 do
     376      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    377377        xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc);
    378     for y := -2 to 6 do
    379       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt,
     378    for Y := -2 to 6 do
     379      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, xxt,
    380380        yyt, HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt,
    381381        SRCPAINT);
    382     for y := -2 to 6 do
    383       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2) + xxt, (y + 2) * yyt,
     382    for Y := -2 to 6 do
     383      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2) + xxt, (Y + 2) * yyt,
    384384        xxt, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc + yyt,
    385385        SRCPAINT);
    386     for y := -2 to 6 do
    387       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt,
     386    for Y := -2 to 6 do
     387      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt, xxt,
    388388        yyt, DitherMask.Canvas, xxt, yyt, SRCAND);
    389     for y := -2 to 6 do
    390       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2) + xxt, (y + 2) * yyt,
     389    for Y := -2 to 6 do
     390      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2) + xxt, (Y + 2) * yyt,
    391391        xxt, yyt, DitherMask.Canvas, 0, yyt, SRCAND);
    392392  end;
    393393
    394   for y := -1 to 6 do begin
    395     if y = -1 then begin
     394  for Y := -1 to 6 do begin
     395    if Y = -1 then begin
    396396      xSrc := ShoreDither * (xxt * 2 + 1) + 1;
    397397      ySrc := 1 + yyt;
    398398    end
    399     else if y = 6 then begin
     399    else if Y = 6 then begin
    400400      xSrc := 1 + 2 * (xxt * 2 + 1);
    401401      ySrc := 1 + yyt + 2 * (yyt * 3 + 1);
    402402    end else begin
    403       xSrc := (y + 2) * (xxt * 2 + 1) + 1;
     403      xSrc := (Y + 2) * (xxt * 2 + 1) + 1;
    404404      ySrc := 1 + yyt;
    405405    end;
    406     for x := -2 to 6 do
    407       DpiBitCanvas(LandMore.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     406    for X := -2 to 6 do
     407      DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    408408        xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc);
    409     DpiBitCanvas(LandMore.Canvas, xxt * 2, (y + 2) * yyt, xxt, yyt,
     409    DpiBitBltCanvas(LandMore.Canvas, xxt * 2, (Y + 2) * yyt, xxt, yyt,
    410410      HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt, SRCPAINT);
    411     for x := 0 to 7 do
    412       DpiBitCanvas(LandMore.Canvas, (x + 2) * (xxt * 2) - xxt, (y + 2) * yyt,
     411    for X := 0 to 7 do
     412      DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2) - xxt, (Y + 2) * yyt,
    413413        xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc + yyt,
    414414        SRCPAINT);
    415     for x := -2 to 6 do
    416       DpiBitCanvas(LandMore.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     415    for X := -2 to 6 do
     416      DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    417417        xxt * 2, yyt, DitherMask.Canvas, 0, 0, SRCAND);
    418418  end;
    419419
    420   for x := 0 to 3 do begin
    421     for y := 0 to 3 do begin
    422       if (x = 1) and (y = 1) then xSrc := 1
     420  for X := 0 to 3 do begin
     421    for Y := 0 to 3 do begin
     422      if (X = 1) and (Y = 1) then xSrc := 1
    423423      else
    424         xSrc := (x mod 2) * (xxt * 2 + 1) + 1;
     424        xSrc := (X mod 2) * (xxt * 2 + 1) + 1;
    425425      ySrc := 1 + yyt;
    426       if (x >= 1) = (y >= 2) then
    427         DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     426      if (X >= 1) = (Y >= 2) then
     427        DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    428428          HGrTerrain.Data.Canvas, xSrc, ySrc);
    429       if (x >= 1) and ((y < 2) or (x >= 2)) then
     429      if (X >= 1) and ((Y < 2) or (X >= 2)) then
    430430      begin
    431         DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     431        DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    432432          HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt,
    433433          SRCPAINT);
    434         DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     434        DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt,
    435435          HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT);
    436436      end;
    437       DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     437      DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    438438        DitherMask.Canvas, xxt, yyt, SRCAND);
    439       DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     439      DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt,
    440440        DitherMask.Canvas, 0, yyt, SRCAND);
    441441    end;
    442442  end;
    443443
    444   for y := 0 to 3 do begin
    445     for x := 0 to 3 do begin
    446       if (x = 1) and (y = 1) then xSrc := 1
     444  for Y := 0 to 3 do begin
     445    for X := 0 to 3 do begin
     446      if (X = 1) and (Y = 1) then xSrc := 1
    447447      else
    448         xSrc := (y mod 2) * (xxt * 2 + 1) + 1;
     448        xSrc := (Y mod 2) * (xxt * 2 + 1) + 1;
    449449      ySrc := 1 + yyt;
    450       if (x < 1) or (y >= 2) then
    451         DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     450      if (X < 1) or (Y >= 2) then
     451        DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    452452          HGrTerrain.Data.Canvas, xSrc, ySrc);
    453       if (x = 1) and (y < 2) or (x >= 2) and (y >= 1) then
     453      if (X = 1) and (Y < 2) or (X >= 2) and (Y >= 1) then
    454454      begin
    455         DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     455        DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    456456          HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt,
    457457          SRCPAINT);
    458         DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     458        DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt,
    459459          HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT);
    460460      end;
    461       DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     461      DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    462462        DitherMask.Canvas, 0, 0, SRCAND);
    463463    end;
    464464  end;
    465465
    466   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
     466  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
    467467    DitherMask.Canvas, 0, 0, DSTINVERT); { invert dither mask }
    468   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
     468  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt * 2,
    469469    HGrTerrain.Mask.Canvas, 1, 1 + yyt, SRCPAINT);
    470470
    471   for x := -1 to 6 do
    472     for y := -2 to 6 do
    473       DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     471  for X := -1 to 6 do
     472    for Y := -2 to 6 do
     473      DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    474474        xxt * 2, yyt, DitherMask.Canvas, 0, 0, SRCAND);
    475475
    476   for y := -1 to 6 do
    477     for x := -2 to 7 do
    478       DpiBitCanvas(LandMore.Canvas, (x + 2) * (xxt * 2) - xxt, (y + 2) * yyt,
     476  for Y := -1 to 6 do
     477    for X := -2 to 7 do
     478      DpiBitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2) - xxt, (Y + 2) * yyt,
    479479        xxt * 2, yyt, DitherMask.Canvas, 0, yyt, SRCAND);
    480480
    481   DpiBitCanvas(LandPatch.Canvas, 0, 0, (xxt * 2) * 9, yyt * 9,
     481  DpiBitBltCanvas(LandPatch.Canvas, 0, 0, (xxt * 2) * 9, yyt * 9,
    482482    LandMore.Canvas, 0, 0, SRCPAINT);
    483483
    484   for x := 0 to 3 do
    485     for y := 0 to 3 do
    486       DpiBitCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     484  for X := 0 to 3 do
     485    for Y := 0 to 3 do
     486      DpiBitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    487487        DitherMask.Canvas, 0, 0, SRCAND);
    488488
    489   for y := 0 to 3 do
    490     for x := 0 to 4 do
    491       DpiBitCanvas(OceanMore.Canvas, x * (xxt * 2) - xxt, y * yyt, xxt * 2,
     489  for Y := 0 to 3 do
     490    for X := 0 to 4 do
     491      DpiBitBltCanvas(OceanMore.Canvas, X * (xxt * 2) - xxt, Y * yyt, xxt * 2,
    492492        yyt, DitherMask.Canvas, 0, yyt, SRCAND);
    493493
    494   DpiBitCanvas(OceanPatch.Canvas, 0, 0, (xxt * 2) * 4, yyt * 4,
     494  DpiBitBltCanvas(OceanPatch.Canvas, 0, 0, (xxt * 2) * 4, yyt * 4,
    495495    OceanMore.Canvas, 0, 0, SRCPAINT);
    496496
     
    499499    FillRect(Rect(0, 0, xxt * 2, yyt));
    500500  end;
    501   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt,
     501  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt,
    502502    HGrTerrain.Mask.Canvas, 1, 1 + yyt);
    503503
    504   for x := 0 to 6 do
    505     DpiBitCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), yyt, xxt * 2, yyt,
     504  for X := 0 to 6 do
     505    DpiBitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), yyt, xxt * 2, yyt,
    506506      DitherMask.Canvas, 0, 0, SRCAND);
    507   DpiBitCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, DitherMask.Canvas,
     507  DpiBitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, DitherMask.Canvas,
    508508    0, 0, DSTINVERT);
    509509
    510   for y := 0 to 6 do
    511     DpiBitCanvas(LandPatch.Canvas, xxt * 2, (y + 2) * yyt, xxt * 2, yyt,
     510  for Y := 0 to 6 do
     511    DpiBitBltCanvas(LandPatch.Canvas, xxt * 2, (Y + 2) * yyt, xxt * 2, yyt,
    512512      DitherMask.Canvas, 0, 0, SRCAND);
    513513
     
    555555end;
    556556
    557 procedure TIsoMap.SetPaintBounds(Left, Top, Right, Bottom: integer);
     557procedure TIsoMap.SetPaintBounds(Left, Top, Right, Bottom: Integer);
    558558begin
    559559  FLeft := Left;
     
    563563end;
    564564
    565 procedure TIsoMap.FillRect(x, y, Width, Height, Color: integer);
    566 begin
    567   if x < FLeft then
    568   begin
    569     Width := Width - (FLeft - x);
    570     x := FLeft;
    571   end;
    572   if y < FTop then
    573   begin
    574     Height := Height - (FTop - y);
    575     y := FTop;
    576   end;
    577   if x + Width >= FRight then
    578     Width := FRight - x;
    579   if y + Height >= FBottom then
    580     Height := FBottom - y;
     565procedure TIsoMap.FillRect(X, Y, Width, Height, Color: Integer);
     566begin
     567  if X < FLeft then
     568  begin
     569    Width := Width - (FLeft - X);
     570    X := FLeft;
     571  end;
     572  if Y < FTop then
     573  begin
     574    Height := Height - (FTop - Y);
     575    Y := FTop;
     576  end;
     577  if X + Width >= FRight then
     578    Width := FRight - X;
     579  if Y + Height >= FBottom then
     580    Height := FBottom - Y;
    581581  if (Width <= 0) or (Height <= 0) then
    582     exit;
     582    Exit;
    583583
    584584  FOutput.Canvas.Brush.Color := Color;
    585   FOutput.Canvas.FillRect(Rect(x, y, x + Width, y + Height));
     585  FOutput.Canvas.FillRect(Rect(X, Y, X + Width, Y + Height));
    586586  FOutput.Canvas.Brush.Style := bsClear;
    587587end;
    588588
    589 procedure TIsoMap.Textout(x, y, Color: integer; const s: string);
     589procedure TIsoMap.Textout(X, Y, Color: Integer; const S: string);
    590590begin
    591591  FOutput.Canvas.Font.Color := Color;
    592   FOutput.Canvas.TextRect(Rect(FLeft, FTop, FRight, FBottom), x, y, s)
    593 end;
    594 
    595 procedure TIsoMap.BitBltBitmap(Src: TDpiBitmap; x, y, Width, Height, xSrc, ySrc,
    596   Rop: integer);
    597 begin
    598   if x < FLeft then
    599   begin
    600     Width := Width - (FLeft - x);
    601     xSrc := xSrc + (FLeft - x);
    602     x := FLeft;
    603   end;
    604   if y < FTop then
    605   begin
    606     Height := Height - (FTop - y);
    607     ySrc := ySrc + (FTop - y);
    608     y := FTop;
    609   end;
    610   if x + Width >= FRight then
    611     Width := FRight - x;
    612   if y + Height >= FBottom then
    613     Height := FBottom - y;
     592  FOutput.Canvas.TextRect(Rect(FLeft, FTop, FRight, FBottom), X, Y, S)
     593end;
     594
     595procedure TIsoMap.BitBltBitmap(Src: TDpiBitmap; X, Y, Width, Height, xSrc, ySrc,
     596  Rop: Integer);
     597begin
     598  if X < FLeft then
     599  begin
     600    Width := Width - (FLeft - X);
     601    xSrc := xSrc + (FLeft - X);
     602    X := FLeft;
     603  end;
     604  if Y < FTop then
     605  begin
     606    Height := Height - (FTop - Y);
     607    ySrc := ySrc + (FTop - Y);
     608    Y := FTop;
     609  end;
     610  if X + Width >= FRight then
     611    Width := FRight - X;
     612  if Y + Height >= FBottom then
     613    Height := FBottom - Y;
    614614  if (Width <= 0) or (Height <= 0) then
    615     exit;
    616 
    617   DpiBitCanvas(FOutput.Canvas, x, y, Width, Height, Src.Canvas, xSrc, ySrc, Rop);
    618 end;
    619 
    620 procedure TIsoMap.Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     615    Exit;
     616
     617  DpiBitBltCanvas(FOutput.Canvas, X, Y, Width, Height, Src.Canvas, xSrc, ySrc, Rop);
     618end;
     619
     620procedure TIsoMap.Sprite(HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
    621621begin
    622622  BitBltBitmap(HGr.Mask, xDst, yDst, Width, Height, xGr, yGr, SRCAND);
     
    624624end;
    625625
    626 procedure TIsoMap.TSprite(xDst, yDst, grix: integer;
    627   PureBlack: boolean = false);
     626procedure TIsoMap.TSprite(xDst, yDst, grix: Integer;
     627  PureBlack: Boolean = False);
    628628var
    629629  Width: Integer;
    630630  Height: Integer;
    631631  xSrc: Integer;
    632   ySrc: integer;
     632  ySrc: Integer;
    633633begin
    634634  Width := TSpriteSize[grix].Right - TSpriteSize[grix].Left;
     
    653653    Height := FBottom - yDst;
    654654  if (Width <= 0) or (Height <= 0) then
    655     exit;
    656 
    657   DpiBitCanvas(FOutput.Canvas, xDst, yDst, Width, Height, MaskCanvas, xSrc, ySrc, SRCAND);
     655    Exit;
     656
     657  DpiBitBltCanvas(FOutput.Canvas, xDst, yDst, Width, Height, MaskCanvas, xSrc, ySrc, SRCAND);
    658658  if not PureBlack then
    659     DpiBitCanvas(FOutput.Canvas, xDst, yDst, Width, Height, DataCanvas, xSrc, ySrc, SRCPAINT);
    660 end;
    661 
    662 procedure TIsoMap.PaintUnit(x, y: integer; const UnitInfo: TUnitInfo;
    663   Status: integer);
    664 var
    665   xsh, ysh, xGr, yGr, j, mixShow: integer;
     659    DpiBitBltCanvas(FOutput.Canvas, xDst, yDst, Width, Height, DataCanvas, xSrc, ySrc, SRCPAINT);
     660end;
     661
     662procedure TIsoMap.PaintUnit(X, Y: Integer; const UnitInfo: TUnitInfo;
     663  Status: Integer);
     664var
     665  xsh, ysh, xGr, yGr, J, mixShow: Integer;
    666666begin
    667667  with UnitInfo do
    668     if (Owner = me) or (emix <> $FFFF) then
     668    if (Owner = Me) or (emix <> $FFFF) then
    669669    begin
    670670      if Job = jCity then
     
    675675        (@OnInitEnemyModel <> nil) then
    676676        if not OnInitEnemyModel(emix) then
    677           exit;
     677          Exit;
    678678      xsh := Tribe[Owner].ModelPicture[mixShow].xShield;
    679679      ysh := Tribe[Owner].ModelPicture[mixShow].yShield;
    680680{$IFNDEF SCR} if Status and usStay <> 0 then
    681         j := 19
     681        J := 19
    682682      else if Status and usRecover <> 0 then
    683         j := 16
     683        J := 16
    684684      else if Status and (usGoto or usEnhance) = usGoto or usEnhance then
    685         j := 18
     685        J := 18
    686686      else if Status and usEnhance <> 0 then
    687         j := 17
     687        J := 17
    688688      else if Status and usGoto <> 0 then
    689         j := 20
     689        J := 20
    690690      else {$ENDIF} if Job = jCity then
    691           j := jNone
     691          J := jNone
    692692        else
    693           j := Job;
     693          J := Job;
    694694      if Flags and unMulti <> 0 then
    695         Sprite(Tribe[Owner].symHGr, x + xsh - 1 + 4, y + ysh - 2, 14, 12,
     695        Sprite(Tribe[Owner].symHGr, X + xsh - 1 + 4, Y + ysh - 2, 14, 12,
    696696          33 + Tribe[Owner].sympix mod 10 * 65,
    697697          1 + Tribe[Owner].sympix div 10 * 49);
    698       Sprite(Tribe[Owner].symHGr, x + xsh - 1, y + ysh - 2, 14, 12,
     698      Sprite(Tribe[Owner].symHGr, X + xsh - 1, Y + ysh - 2, 14, 12,
    699699        18 + Tribe[Owner].sympix mod 10 * 65,
    700700        1 + Tribe[Owner].sympix div 10 * 49);
    701       FillRect(x + xsh, y + ysh + 5, 1 + Health * 11 div 100, 3,
     701      FillRect(X + xsh, Y + ysh + 5, 1 + Health * 11 div 100, 3,
    702702        ColorOfHealth(Health));
    703       if j > 0 then
     703      if J > 0 then
    704704      begin
    705         xGr := 121 + j mod 7 * 9;
    706         yGr := 1 + j div 7 * 9;
    707         BitBltBitmap(HGrSystem.Mask, x + xsh + 3, y + ysh + 9, 8, 8, xGr,
     705        xGr := 121 + J mod 7 * 9;
     706        yGr := 1 + J div 7 * 9;
     707        BitBltBitmap(HGrSystem.Mask, X + xsh + 3, Y + ysh + 9, 8, 8, xGr,
    708708          yGr, SRCAND);
    709         Sprite(HGrSystem, x + xsh + 2, y + ysh + 8, 8, 8, xGr, yGr);
     709        Sprite(HGrSystem, X + xsh + 2, Y + ysh + 8, 8, 8, xGr, yGr);
    710710      end;
    711711      with Tribe[Owner].ModelPicture[mixShow] do
    712         Sprite(HGr, x, y, 64, 48, pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
     712        Sprite(HGr, X, Y, 64, 48, pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
    713713      if Flags and unFortified <> 0 then
    714714      begin
    715715        { DataCanvas:=HGrTerrain.Data.Canvas;
    716716          MaskCanvas:=HGrTerrain.Mask.Canvas;
    717           TSprite(x,y+16,12*9+7); }
    718         Sprite(HGrStdUnits, x, y, xxu * 2, yyu * 2, 1 + 6 * (xxu * 2 + 1), 1);
     717          TSprite(X,Y+16,12*9+7); }
     718        Sprite(HGrStdUnits, X, Y, xxu * 2, yyu * 2, 1 + 6 * (xxu * 2 + 1), 1);
    719719      end;
    720720    end;
    721 end; { PaintUnit }
    722 
    723 procedure TIsoMap.PaintCity(x, y: integer; const CityInfo: TCityInfo;
    724   accessory: boolean);
     721end;
     722
     723procedure TIsoMap.PaintCity(X, Y: Integer; const CityInfo: TCityInfo;
     724  accessory: Boolean);
    725725var
    726726  age: Integer;
     
    733733  LabelLength: Integer;
    734734  cpic: TCityPicture;
    735   s: string;
     735  S: string;
    736736begin
    737737  age := GetAge(CityInfo.Owner);
     
    752752      (cHGr.Data.Canvas.Pixels[(xGr + 4) * 65, cpix * 49 + 48] = $00FFFF)
    753753    then
    754       Sprite(cHGr, x - xxc, y - 2 * yyc, xxc * 2, yyc * 3,
     754      Sprite(cHGr, X - xxc, Y - 2 * yyc, xxc * 2, yyc * 3,
    755755        xGr * (xxc * 2 + 1) + 1, 1 + cpix * (yyc * 3 + 1));
    756756    if ciWalled and CityInfo.Flags <> 0 then
    757       Sprite(cHGr, x - xxc, y - 2 * yyc, xxc * 2, yyc * 3,
     757      Sprite(cHGr, X - xxc, Y - 2 * yyc, xxc * 2, yyc * 3,
    758758        (xGr + 4) * (xxc * 2 + 1) + 1, 1 + cpix * (yyc * 3 + 1));
    759759  end
     
    761761  begin
    762762    if ciWalled and CityInfo.Flags <> 0 then
    763       Sprite(HGrCities, x - xxt, y - 2 * yyt, 2 * xxt, 3 * yyt,
     763      Sprite(HGrCities, X - xxt, Y - 2 * yyt, 2 * xxt, 3 * yyt,
    764764        (xGr + 4) * (2 * xxt + 1) + 1, 1 + (age - 2) * (3 * yyt + 1))
    765765    else
    766       Sprite(HGrCities, x - xxt, y - 2 * yyt, 2 * xxt, 3 * yyt,
     766      Sprite(HGrCities, X - xxt, Y - 2 * yyt, 2 * xxt, 3 * yyt,
    767767        xGr * (2 * xxt + 1) + 1, 1 + (age - 2) * (3 * yyt + 1));
    768768  end;
    769769
    770770  if not accessory then
    771     exit;
     771    Exit;
    772772
    773773  { if ciCapital and CityInfo.Flags<>0 then
    774     Sprite(Tribe[CityInfo.Owner].symHGr,x+cpic.xf,y-13+cpic.yf,13,14,
     774    Sprite(Tribe[CityInfo.Owner].symHGr,X+cpic.xf,Y-13+cpic.yf,13,14,
    775775    1+Tribe[CityInfo.Owner].sympix mod 10 *65,
    776776    1+Tribe[CityInfo.Owner].sympix div 10 *49); {capital -- paint flag }
     
    781781    begin
    782782      cpic := Tribe[CityInfo.Owner].CityPicture[xGr];
    783       xShield := x - xxc + cpic.xShield;
    784       yShield := y - 2 * yyc + cpic.yShield;
     783      xShield := X - xxc + cpic.xShield;
     784      yShield := Y - 2 * yyc + cpic.yShield;
    785785    end
    786786    else
    787787    begin
    788788      cpic := CitiesPictures.Pictures[age, xGr];
    789       xShield := x - xxt + cpic.xShield;
    790       yShield := y - 2 * yyt + cpic.yShield;
     789      xShield := X - xxt + cpic.xShield;
     790      yShield := Y - 2 * yyt + cpic.yShield;
    791791    end;
    792     s := IntToStr(CityInfo.size);
    793     LabelLength := FOutput.Canvas.TextWidth(s);
     792    S := IntToStr(CityInfo.size);
     793    LabelLength := FOutput.Canvas.TextWidth(S);
    794794    FillRect(xShield, yShield, LabelLength + 4, 16, $000000);
    795795    if MyMap[CityInfo.Loc] and (fUnit or fObserved) = fObserved then
     
    802802      LabelTextColor := $000000;
    803803    end;
    804     Textout(xShield + 2, yShield - 1, LabelTextColor, s);
    805   end;
    806 end; { PaintCity }
    807 
    808 function PoleTile(Loc: integer): integer;
     804    Textout(xShield + 2, yShield - 1, LabelTextColor, S);
     805  end;
     806end;
     807
     808function PoleTile(Loc: Integer): Integer;
    809809begin { virtual pole tile }
    810   result := fUNKNOWN;
     810  Result := fUNKNOWN;
    811811  if Loc < -2 * G.lx then
    812812  else if Loc < -G.lx then
     
    815815      (MyMap[dLoc(Loc, -2, 2)] and fTerrain <> fUNKNOWN) and
    816816      (MyMap[dLoc(Loc, 2, 2)] and fTerrain <> fUNKNOWN) then
    817       result := fArctic;
     817      Result := fArctic;
    818818    if (MyMap[dLoc(Loc, 0, 2)] and fObserved <> 0) and
    819819      (MyMap[dLoc(Loc, -2, 2)] and fObserved <> 0) and
    820820      (MyMap[dLoc(Loc, 2, 2)] and fObserved <> 0) then
    821       result := result or fObserved;
     821      Result := Result or fObserved;
    822822  end
    823823  else if Loc < 0 then
     
    825825    if (MyMap[dLoc(Loc, -1, 1)] and fTerrain <> fUNKNOWN) and
    826826      (MyMap[dLoc(Loc, 1, 1)] and fTerrain <> fUNKNOWN) then
    827       result := fArctic;
     827      Result := fArctic;
    828828    if (MyMap[dLoc(Loc, -1, 1)] and fObserved <> 0) and
    829829      (MyMap[dLoc(Loc, 1, 1)] and fObserved <> 0) then
    830       result := result or fObserved;
     830      Result := Result or fObserved;
    831831  end
    832832  else if Loc < G.lx * (G.ly + 1) then
     
    834834    if (MyMap[dLoc(Loc, -1, -1)] and fTerrain <> fUNKNOWN) and
    835835      (MyMap[dLoc(Loc, 1, -1)] and fTerrain <> fUNKNOWN) then
    836       result := fArctic;
     836      Result := fArctic;
    837837    if (MyMap[dLoc(Loc, -1, -1)] and fObserved <> 0) and
    838838      (MyMap[dLoc(Loc, 1, -1)] and fObserved <> 0) then
    839       result := result or fObserved;
     839      Result := Result or fObserved;
    840840  end
    841841  else if Loc < G.lx * (G.ly + 2) then
     
    844844      (MyMap[dLoc(Loc, -2, -2)] and fTerrain <> fUNKNOWN) and
    845845      (MyMap[dLoc(Loc, 2, -2)] and fTerrain <> fUNKNOWN) then
    846       result := fArctic;
     846      Result := fArctic;
    847847    if (MyMap[dLoc(Loc, 0, -2)] and fObserved <> 0) and
    848848      (MyMap[dLoc(Loc, -2, -2)] and fObserved <> 0) and
    849849      (MyMap[dLoc(Loc, 2, -2)] and fObserved <> 0) then
    850       result := result or fObserved;
    851   end;
    852 end;
    853 
    854 function TIsoMap.Connection4(Loc, Mask, Value: integer): integer;
    855 begin
    856   result := 0;
     850      Result := Result or fObserved;
     851  end;
     852end;
     853
     854function TIsoMap.Connection4(Loc, Mask, Value: Integer): Integer;
     855begin
     856  Result := 0;
    857857  if dLoc(Loc, 1, -1) >= 0 then
    858858  begin
    859859    if MyMap[dLoc(Loc, 1, -1)] and Mask = Cardinal(Value) then
    860       inc(result, 1);
     860      Inc(Result, 1);
    861861    if MyMap[dLoc(Loc, -1, -1)] and Mask = Cardinal(Value) then
    862       inc(result, 8);
     862      Inc(Result, 8);
    863863  end;
    864864  if dLoc(Loc, 1, 1) < G.lx * G.ly then
    865865  begin
    866866    if MyMap[dLoc(Loc, 1, 1)] and Mask = Cardinal(Value) then
    867       inc(result, 2);
     867      Inc(Result, 2);
    868868    if MyMap[dLoc(Loc, -1, 1)] and Mask = Cardinal(Value) then
    869       inc(result, 4);
    870   end;
    871 end;
    872 
    873 function TIsoMap.Connection8(Loc, Mask: integer): integer;
     869      Inc(Result, 4);
     870  end;
     871end;
     872
     873function TIsoMap.Connection8(Loc, Mask: Integer): Integer;
    874874var
    875875  Dir: Integer;
    876876  ConnLoc: Integer;
    877877begin
    878   result := 0;
     878  Result := 0;
    879879  for Dir := 0 to 7 do
    880880  begin
     
    882882    if (ConnLoc >= 0) and (ConnLoc < G.lx * G.ly) and
    883883      (MyMap[ConnLoc] and Mask <> 0) then
    884       inc(result, 1 shl Dir);
    885   end;
    886 end;
    887 
    888 function TIsoMap.OceanConnection(Loc: integer): integer;
     884      Inc(Result, 1 shl Dir);
     885  end;
     886end;
     887
     888function TIsoMap.OceanConnection(Loc: Integer): Integer;
    889889var
    890890  Dir: Integer;
    891891  ConnLoc: Integer;
    892892begin
    893   result := 0;
     893  Result := 0;
    894894  for Dir := 0 to 7 do
    895895  begin
     
    897897    if (ConnLoc < 0) or (ConnLoc >= G.lx * G.ly) or
    898898      ((MyMap[ConnLoc] - 2) and fTerrain < 13) then
    899       inc(result, 1 shl Dir);
    900   end;
    901 end;
    902 
    903 procedure TIsoMap.PaintShore(x, y, Loc: integer);
     899      Inc(Result, 1 shl Dir);
     900  end;
     901end;
     902
     903procedure TIsoMap.PaintShore(X, Y, Loc: Integer);
    904904var
    905905  Conn: Integer;
    906906  Tile: Integer;
    907907begin
    908   if (y <= FTop - yyt * 2) or (y > FBottom) or (x <= FLeft - xxt * 2) or
    909     (x > FRight) then
    910     exit;
     908  if (Y <= FTop - yyt * 2) or (Y > FBottom) or (X <= FLeft - xxt * 2) or
     909    (X > FRight) then
     910    Exit;
    911911  if (Loc < 0) or (Loc >= G.lx * G.ly) then
    912     exit;
     912    Exit;
    913913  Tile := MyMap[Loc];
    914914  if Tile and fTerrain >= fGrass then
    915     exit;
     915    Exit;
    916916  Conn := OceanConnection(Loc);
    917917  if Conn = 0 then
    918     exit;
    919 
    920   BitBltBitmap(HGrTerrain.Data, x + xxt div 2, y, xxt, yyt,
     918    Exit;
     919
     920  BitBltBitmap(HGrTerrain.Data, X + xxt div 2, Y, xxt, yyt,
    921921    1 + (Conn shr 6 + Conn and 1 shl 2) * (xxt * 2 + 1),
    922922    1 + yyt + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT);
    923   BitBltBitmap(HGrTerrain.Data, x + xxt, y + yyt div 2, xxt, yyt,
     923  BitBltBitmap(HGrTerrain.Data, X + xxt, Y + yyt div 2, xxt, yyt,
    924924    1 + (Conn and 7) * (xxt * 2 + 1) + xxt,
    925925    1 + yyt * 2 + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT);
    926   BitBltBitmap(HGrTerrain.Data, x + xxt div 2, y + yyt, xxt, yyt,
     926  BitBltBitmap(HGrTerrain.Data, X + xxt div 2, Y + yyt, xxt, yyt,
    927927    1 + (Conn shr 2 and 7) * (xxt * 2 + 1) + xxt,
    928928    1 + yyt + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT);
    929   BitBltBitmap(HGrTerrain.Data, x, y + yyt div 2, xxt, yyt,
     929  BitBltBitmap(HGrTerrain.Data, X, Y + yyt div 2, xxt, yyt,
    930930    1 + (Conn shr 4 and 7) * (xxt * 2 + 1),
    931931    1 + yyt * 2 + (16 + Tile and fTerrain) * (yyt * 3 + 1), SRCPAINT);
    932932  Conn := Connection4(Loc, fTerrain, fUNKNOWN); { dither to black }
    933933  if Conn and 1 <> 0 then
    934     BitBltBitmap(HGrTerrain.Mask, x + xxt, y, xxt, yyt, 1 + 7 * (xxt * 2 + 1) +
     934    BitBltBitmap(HGrTerrain.Mask, X + xxt, Y, xxt, yyt, 1 + 7 * (xxt * 2 + 1) +
    935935      xxt, 1 + yyt + 15 * (yyt * 3 + 1), SRCAND);
    936936  if Conn and 2 <> 0 then
    937     BitBltBitmap(HGrTerrain.Mask, x + xxt, y + yyt, xxt, yyt,
     937    BitBltBitmap(HGrTerrain.Mask, X + xxt, Y + yyt, xxt, yyt,
    938938      1 + 7 * (xxt * 2 + 1) + xxt, 1 + yyt * 2 + 15 * (yyt * 3 + 1), SRCAND);
    939939  if Conn and 4 <> 0 then
    940     BitBltBitmap(HGrTerrain.Mask, x, y + yyt, xxt, yyt, 1 + 7 * (xxt * 2 + 1),
     940    BitBltBitmap(HGrTerrain.Mask, X, Y + yyt, xxt, yyt, 1 + 7 * (xxt * 2 + 1),
    941941      1 + yyt * 2 + 15 * (yyt * 3 + 1), SRCAND);
    942942  if Conn and 8 <> 0 then
    943     BitBltBitmap(HGrTerrain.Mask, x, y, xxt, yyt, 1 + 7 * (xxt * 2 + 1),
     943    BitBltBitmap(HGrTerrain.Mask, X, Y, xxt, yyt, 1 + 7 * (xxt * 2 + 1),
    944944      1 + yyt + 15 * (yyt * 3 + 1), SRCAND);
    945945end;
    946946
    947 procedure TIsoMap.PaintTileExtraTerrain(x, y, Loc: integer);
    948 var
    949   Dir, Conn, RRConn, yGr, Tile, yLoc: integer;
    950 begin
    951   if (Loc < 0) or (Loc >= G.lx * G.ly) or (y <= -yyt * 2) or
    952     (y > FOutput.Height) or (x <= -xxt * 2) or (x > FOutput.Width) then
    953     exit;
     947procedure TIsoMap.PaintTileExtraTerrain(X, Y, Loc: Integer);
     948var
     949  Dir, Conn, RRConn, yGr, Tile, yLoc: Integer;
     950begin
     951  if (Loc < 0) or (Loc >= G.lx * G.ly) or (Y <= -yyt * 2) or
     952    (Y > FOutput.Height) or (X <= -xxt * 2) or (X > FOutput.Width) then
     953    Exit;
    954954  Tile := MyMap[Loc];
    955955  if Tile and fTerrain = fForest then
     
    966966    then
    967967      Conn := Conn and not 9; // no connection to north
    968     TSprite(x, y, yGr + Conn mod 8 + (Conn div 8) * TerrainIconCols);
     968    TSprite(X, Y, yGr + Conn mod 8 + (Conn div 8) * TerrainIconCols);
    969969  end
    970970  else if Tile and fTerrain in [fHills, fMountains, fForest] then
     
    972972    yGr := 3 + 2 * (Tile and fTerrain - fForest);
    973973    Conn := Connection4(Loc, fTerrain, Tile and fTerrain);
    974     TSprite(x, y, Conn mod 8 + (yGr + Conn div 8) * TerrainIconCols);
     974    TSprite(X, Y, Conn mod 8 + (yGr + Conn div 8) * TerrainIconCols);
    975975  end
    976976  else if Tile and fDeadLands <> 0 then
    977     TSprite(x, y, spRow2);
     977    TSprite(X, Y, spRow2);
    978978
    979979  if ShowObjects then
    980980  begin
    981981    if Tile and fTerImp = tiFarm then
    982       TSprite(x, y, spFarmLand)
     982      TSprite(X, Y, spFarmLand)
    983983    else if Tile and fTerImp = tiIrrigation then
    984       TSprite(x, y, spIrrigation);
     984      TSprite(X, Y, spIrrigation);
    985985  end;
    986986  if Tile and fRiver <> 0 then
     
    989989      Connection4(Loc, fTerrain, fShore) or Connection4(Loc, fTerrain,
    990990      fUNKNOWN);
    991     TSprite(x, y, spRiver + Conn mod 8 + (Conn div 8) * TerrainIconCols);
     991    TSprite(X, Y, spRiver + Conn mod 8 + (Conn div 8) * TerrainIconCols);
    992992  end;
    993993
     
    997997    for Dir := 0 to 3 do
    998998      if Conn and (1 shl Dir) <> 0 then { river mouths }
    999         TSprite(x, y, spRiverMouths + Dir);
     999        TSprite(X, Y, spRiverMouths + Dir);
    10001000    if ShowObjects then
    10011001    begin
     
    10031003      for Dir := 0 to 7 do
    10041004        if Conn and (1 shl Dir) <> 0 then { canal mouths }
    1005           TSprite(x, y, spCanalMouths + 1 + Dir);
     1005          TSprite(X, Y, spCanalMouths + 1 + Dir);
    10061006    end;
    10071007  end;
     
    10151015      if Conn = 0 then begin
    10161016        if Tile and fCanal <> 0 then
    1017           TSprite(x, y, spCanal);
     1017          TSprite(X, Y, spCanal);
    10181018      end
    10191019      else
    10201020        for Dir := 0 to 7 do
    10211021          if (1 shl Dir) and Conn <> 0 then
    1022             TSprite(x, y, spCanal + 1 + Dir);
     1022            TSprite(X, Y, spCanal + 1 + Dir);
    10231023    end;
    10241024
     
    10321032      Conn := Connection8(Loc, fRoad or fRR or fCity) and not RRConn;
    10331033      if (Conn = 0) and (Tile and (fRR or fCity) = 0) then
    1034         TSprite(x, y, spRoad)
     1034        TSprite(X, Y, spRoad)
    10351035      else if Conn > 0 then
    10361036        for Dir := 0 to 7 do
    10371037          if (1 shl Dir) and Conn <> 0 then
    1038             TSprite(x, y, spRoad + 1 + Dir);
     1038            TSprite(X, Y, spRoad + 1 + Dir);
    10391039    end;
    10401040
    10411041    // Paint railroad connections
    10421042    if (Tile and fRR <> 0) and (RRConn = 0) then
    1043       TSprite(x, y, spRailRoad)
     1043      TSprite(X, Y, spRailRoad)
    10441044    else if RRConn > 0 then begin
    10451045      for Dir := 0 to 7 do
    10461046        if (1 shl Dir) and RRConn <> 0 then
    1047           TSprite(x, y, spRailRoad + 1 + Dir);
     1047          TSprite(X, Y, spRailRoad + 1 + Dir);
    10481048    end;
    10491049  end;
     
    10511051
    10521052// (x,y) is top left pixel of (2*xxt,3*yyt) rectangle
    1053 procedure TIsoMap.PaintTileObjects(x, y, Loc, CityLoc, CityOwner: integer;
    1054   UseBlink: boolean);
    1055 var
    1056   p1, p2, uix, cix, dy, Loc1, Tile, Multi, Destination: integer;
     1053procedure TIsoMap.PaintTileObjects(X, Y, Loc, CityLoc, CityOwner: Integer;
     1054  UseBlink: Boolean);
     1055var
     1056  p1, p2, uix, cix, dy, Loc1, Tile, Multi, Destination: Integer;
    10571057  CityInfo: TCityInfo;
    10581058  UnitInfo: TUnitInfo;
    1059   fog: boolean;
     1059  fog: Boolean;
    10601060  SpecialRow: Integer;
    10611061  SpecialCol: Integer;
     
    10631063  procedure NameCity;
    10641064  var
    1065     cix, xs, w: integer;
     1065    cix, xs, W: Integer;
    10661066    BehindCityInfo: TCityInfo;
    1067     s: string;
    1068     IsCapital: boolean;
     1067    S: string;
     1068    IsCapital: Boolean;
    10691069  begin
    10701070    BehindCityInfo.Loc := Loc - 2 * G.lx;
     
    10761076      IsCapital := BehindCityInfo.Flags and ciCapital <> 0;
    10771077      { if Showuix and (cix>=0) then s:=IntToStr(cix)
    1078         else } s := CityName(BehindCityInfo.ID);
    1079       w := FOutput.Canvas.TextWidth(s);
    1080       xs := x + xxt - (w + 1) div 2;
     1078        else } S := CityName(BehindCityInfo.ID);
     1079      W := FOutput.Canvas.TextWidth(S);
     1080      xs := X + xxt - (W + 1) div 2;
    10811081      if IsCapital then
    10821082        FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style + [fsUnderline];
    1083       Textout(xs + 1, y - 9, $000000, s);
    1084       Textout(xs, y - 10, $FFFFFF, s);
     1083      Textout(xs + 1, Y - 9, $000000, S);
     1084      Textout(xs, Y - 10, $FFFFFF, S);
    10851085      if IsCapital then
    10861086        FOutput.Canvas.Font.Style := FOutput.Canvas.Font.Style - [fsUnderline];
     
    10921092    if ShowObjects and not (moEditMode in MapOptions) and
    10931093      (Tile and fCity <> 0) and (CityInfo.Flags and ciSpacePort <> 0) then
    1094       TSprite(x + xxt, y - 6, spSpacePort);
     1094      TSprite(X + xxt, Y - 6, spSpacePort);
    10951095  end;
    10961096
    10971097  procedure PaintBorder;
    10981098  var
    1099     dx, dy: integer;
     1099    dx, dy: Integer;
    11001100  begin
    11011101    if ShowBorder and (Loc >= 0) and (Loc < G.lx * G.ly) and
    11021102      (Tile and fTerrain <> fUNKNOWN) then begin
    11031103      p1 := MyRO.Territory[Loc];
    1104       if (p1 >= 0) and (ShowMyBorder or (p1 <> me)) then begin
     1104      if (p1 >= 0) and (ShowMyBorder or (p1 <> Me)) then begin
    11051105        if BordersOK^ and (1 shl p1) = 0 then begin
    11061106          UnshareBitmap(Borders);
    1107           DpiBitCanvas(Borders.Canvas, 0, p1 * (yyt * 2), xxt * 2,
     1107          DpiBitBltCanvas(Borders.Canvas, 0, p1 * (yyt * 2), xxt * 2,
    11081108            yyt * 2, HGrTerrain.Data.Canvas,
    11091109            1 + 8 * (xxt * 2 + 1), 1 + yyt + 16 * (yyt * 3 + 1));
     
    11231123              if p2 <> p1 then
    11241124              begin
    1125                 BitBltBitmap(HGrTerrain.Mask, x + dx * xxt, y + dy * yyt, xxt,
     1125                BitBltBitmap(HGrTerrain.Mask, X + dx * xxt, Y + dy * yyt, xxt,
    11261126                  yyt, 1 + 8 * (xxt * 2 + 1) + dx * xxt,
    11271127                  1 + yyt + 16 * (yyt * 3 + 1) + dy * yyt, SRCAND);
    1128                 BitBltBitmap(Borders, x + dx * xxt, y + dy * yyt, xxt, yyt, dx * xxt,
     1128                BitBltBitmap(Borders, X + dx * xxt, Y + dy * yyt, xxt, yyt, dx * xxt,
    11291129                  p1 * (yyt * 2) + dy * yyt, SRCPAINT);
    11301130              end;
     
    11431143    (Tile and fCity <> 0) then
    11441144    GetCityInfo(Loc, cix, CityInfo);
    1145   if (y <= FTop - yyt * 2) or (y > FBottom) or (x <= FLeft - xxt * 2) or
    1146     (x > FRight) then
     1145  if (Y <= FTop - yyt * 2) or (Y > FBottom) or (X <= FLeft - xxt * 2) or
     1146    (X > FRight) then
    11471147  begin
    11481148    NameCity;
    11491149    ShowSpacePort;
    1150     exit;
     1150    Exit;
    11511151  end;
    11521152  if Tile and fTerrain = fUNKNOWN then
     
    11541154    NameCity;
    11551155    ShowSpacePort;
    1156     exit;
     1156    Exit;
    11571157  end; { square not discovered }
    11581158
     
    11611161
    11621162  if (Loc >= 0) and (Loc < G.lx * G.ly) and (Loc = FAdviceLoc) then
    1163     TSprite(x, y, spPlain);
     1163    TSprite(X, Y, spPlain);
    11641164
    11651165  if (Loc >= 0) and (Loc < G.lx * G.ly) and (Tile and fSpecial <> 0)
     
    11701170    SpecialRow := Tile and fSpecial shr 5;
    11711171    if SpecialCol < fForest then
    1172       TSprite(x, y, SpecialCol + SpecialRow * TerrainIconCols)
     1172      TSprite(X, Y, SpecialCol + SpecialRow * TerrainIconCols)
    11731173    else if (SpecialCol = fForest) and IsJungle(dy) then
    1174       TSprite(x, y, spJungle - 1 + SpecialRow * TerrainIconCols)
     1174      TSprite(X, Y, spJungle - 1 + SpecialRow * TerrainIconCols)
    11751175    else
    1176       TSprite(x, y, spForest - 1 + ((SpecialCol - fForest) * 2 + SpecialRow) * TerrainIconCols);
     1176      TSprite(X, Y, spForest - 1 + ((SpecialCol - fForest) * 2 + SpecialRow) * TerrainIconCols);
    11771177  end;
    11781178
     
    11801180  begin
    11811181    if Tile and fTerImp = tiMine then
    1182       TSprite(x, y, spMine);
     1182      TSprite(X, Y, spMine);
    11831183    if Tile and fTerImp = tiBase then
    1184       TSprite(x, y, spBase);
     1184      TSprite(X, Y, spBase);
    11851185    if Tile and fPoll <> 0 then
    1186       TSprite(x, y, spPollution);
     1186      TSprite(X, Y, spPollution);
    11871187    if Tile and fTerImp = tiFort then
    11881188    begin
    1189       TSprite(x, y, spFortBack);
     1189      TSprite(X, Y, spFortBack);
    11901190      if Tile and fObserved = 0 then
    1191         TSprite(x, y, spFortFront);
     1191        TSprite(X, Y, spFortFront);
    11921192    end;
    11931193  end;
    11941194  if (Tile and fDeadLands) <> 0 then
    1195     TSprite(x, y, spMinerals + (Tile shr 25 and 3) * TerrainIconCols);
     1195    TSprite(X, Y, spMinerals + (Tile shr 25 and 3) * TerrainIconCols);
    11961196
    11971197  if moEditMode in MapOptions then
     
    12051205  if fog and ShowObjects then
    12061206    if Loc < -G.lx then
    1207       Sprite(HGrTerrain, x, y + yyt, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),
     1207      Sprite(HGrTerrain, X, Y + yyt, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),
    12081208        1 + yyt * 2 + 15 * (yyt * 3 + 1))
    12091209    else if Loc >= G.lx * (G.ly + 1) then
    1210       Sprite(HGrTerrain, x, y, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),
     1210      Sprite(HGrTerrain, X, Y, xxt * 2, yyt, 1 + 6 * (xxt * 2 + 1),
    12111211        1 + yyt + 15 * (yyt * 3 + 1))
    12121212    else
    1213       TSprite(x, y, spGrid, xxt <> 33);
     1213      TSprite(X, Y, spGrid, xxt <> 33);
    12141214
    12151215  if FoW and (Tile and fObserved = 0) then
     
    12241224    if (Destination = Loc) and (Destination <> MyUn[UnFocus].Loc) then
    12251225      if not UseBlink or BlinkOn then
    1226         TSprite(x, y, spBlink1)
     1226        TSprite(X, Y, spBlink1)
    12271227      else
    1228         TSprite(x, y, spBlink2)
     1228        TSprite(X, Y, spBlink2)
    12291229  end;
    12301230{$ENDIF}
     
    12321232  begin
    12331233    if Tile and fPrefStartPos <> 0 then
    1234       TSprite(x, y, spPrefStartPos)
     1234      TSprite(X, Y, spPrefStartPos)
    12351235    else if Tile and fStartPos <> 0 then
    1236       TSprite(x, y, spStartPos);
     1236      TSprite(X, Y, spStartPos);
    12371237  end
    12381238  else if ShowObjects then
    12391239  begin
    12401240    { if (CityLoc<0) and (UnFocus>=0) and (Loc=MyUn[UnFocus].Loc) then
    1241       if BlinkOn then TSprite(x,y,8+9*0)
    1242       else TSprite(x,y,8+9*1); }
     1241      if BlinkOn then TSprite(X,Y,8+9*0)
     1242      else TSprite(X,Y,8+9*1); }
    12431243
    12441244    NameCity;
    12451245    ShowSpacePort;
    12461246    if Tile and fCity <> 0 then
    1247       PaintCity(x + xxt, y + yyt, CityInfo, CityOwner < 0);
     1247      PaintCity(X + xxt, Y + yyt, CityInfo, CityOwner < 0);
    12481248
    12491249    if (Tile and fUnit <> 0) and (Loc <> AttLoc) and
     
    12591259        UnitInfo.Health := DefHealth;
    12601260      if (UnitInfo.Owner <> CityOwner) and
    1261         not((CityOwner = me) and (MyRO.Treaty[UnitInfo.Owner] = trAlliance))
     1261        not((CityOwner = Me) and (MyRO.Treaty[UnitInfo.Owner] = trAlliance))
    12621262      then
    12631263{$IFNDEF SCR} if (UnFocus >= 0) and (Loc = MyUn[UnFocus].Loc) then { active unit }
    12641264        begin
    12651265          Multi := UnitInfo.Flags and unMulti;
    1266           MakeUnitInfo(me, MyUn[UnFocus], UnitInfo);
     1266          MakeUnitInfo(Me, MyUn[UnFocus], UnitInfo);
    12671267          UnitInfo.Flags := UnitInfo.Flags or Multi;
    1268           PaintUnit(x + (xxt - xxu), y + (yyt - yyu_anchor), UnitInfo,
     1268          PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo,
    12691269            MyUn[UnFocus].Status);
    12701270        end
    1271         else if UnitInfo.Owner = me then
     1271        else if UnitInfo.Owner = Me then
    12721272        begin
    12731273          if ClientMode = cMovieTurn then
    1274             PaintUnit(x + (xxt - xxu), y + (yyt - yyu_anchor), UnitInfo, 0)
     1274            PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo, 0)
    12751275            // status is not set with precise timing during loading
    12761276          else
    1277             PaintUnit(x + (xxt - xxu), y + (yyt - yyu_anchor), UnitInfo,
     1277            PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo,
    12781278              MyUn[uix].Status);
    12791279          // if Showuix then Textout(x+16,y+5,$80FF00,IntToStr(uix));
    12801280        end
    1281         else {$ENDIF} PaintUnit(x + (xxt - xxu), y + (yyt - yyu_anchor), UnitInfo, 0);
     1281        else {$ENDIF} PaintUnit(X + (xxt - xxu), Y + (yyt - yyu_anchor), UnitInfo, 0);
    12821282    end
    12831283    else if Tile and fHiddenUnit <> 0 then
    1284       Sprite(HGrStdUnits, x + (xxt - xxu), y + (yyt - yyu_anchor), xxu * 2,
     1284      Sprite(HGrStdUnits, X + (xxt - xxu), Y + (yyt - yyu_anchor), xxu * 2,
    12851285        yyu * 2, 1 + 5 * (xxu * 2 + 1), 1)
    12861286    else if Tile and fStealthUnit <> 0 then
    1287       Sprite(HGrStdUnits, x + (xxt - xxu), y + (yyt - yyu_anchor), xxu * 2,
     1287      Sprite(HGrStdUnits, X + (xxt - xxu), Y + (yyt - yyu_anchor), xxu * 2,
    12881288        yyu * 2, 1 + 5 * (xxu * 2 + 1), 1 + 1 * (yyu * 2 + 1))
    12891289  end;
     
    12911291  if ShowObjects and (Tile and fTerImp = tiFort) and (Tile and fObserved <> 0)
    12921292  then
    1293     TSprite(x, y, spFortFront);
     1293    TSprite(X, Y, spFortFront);
    12941294
    12951295  if (Loc >= 0) and (Loc < G.lx * G.ly) then
    12961296    if ShowLoc then
    1297       Textout(x + xxt - 16, y + yyt - 9, $FFFF00, IntToStr(Loc))
     1297      Textout(X + xxt - 16, Y + yyt - 9, $FFFF00, IntToStr(Loc))
    12981298    else if ShowDebug and (DebugMap <> nil) and (Loc >= 0) and
    12991299      (Loc < G.lx * G.ly) and (DebugMap[Loc] <> 0) then
    1300       Textout(x + xxt - 16, y + yyt - 9, $00E0FF,
    1301         IntToStr(integer(DebugMap[Loc])))
    1302 end; { PaintTileObjects }
    1303 
    1304 procedure TIsoMap.PaintGrid(x, y, nx, ny: integer);
    1305 
    1306   procedure ClippedLine(dx0, dy0: integer; mirror: boolean);
     1300      Textout(X + xxt - 16, Y + yyt - 9, $00E0FF,
     1301        IntToStr(Integer(DebugMap[Loc])))
     1302end;
     1303
     1304procedure TIsoMap.PaintGrid(X, Y, nx, ny: Integer);
     1305
     1306  procedure ClippedLine(dx0, dy0: Integer; mirror: Boolean);
    13071307  var
    1308     x0, x1, dxmin, dymin, dxmax, dymax, n: integer;
     1308    x0, x1, dxmin, dymin, dxmax, dymax, N: Integer;
    13091309  begin
    13101310    with FOutput.Canvas do
    13111311    begin
    1312       dxmin := (FLeft - x) div xxt;
    1313       dymin := (RealTop - y) div yyt;
    1314       dxmax := (FRight - x - 1) div xxt + 1;
    1315       dymax := (RealBottom - y - 1) div yyt + 1;
    1316       n := dymax - dy0;
     1312      dxmin := (FLeft - X) div xxt;
     1313      dymin := (RealTop - Y) div yyt;
     1314      dxmax := (FRight - X - 1) div xxt + 1;
     1315      dymax := (RealBottom - Y - 1) div yyt + 1;
     1316      N := dymax - dy0;
    13171317      if mirror then
    13181318      begin
    1319         if dx0 - dxmin < n then
    1320           n := dx0 - dxmin;
     1319        if dx0 - dxmin < N then
     1320          N := dx0 - dxmin;
    13211321        if dx0 > dxmax then
    13221322        begin
    1323           n := n - (dx0 - dxmax);
     1323          N := N - (dx0 - dxmax);
    13241324          dy0 := dy0 + (dx0 - dxmax);
    13251325          dx0 := dxmax
     
    13271327        if dy0 < dymin then
    13281328        begin
    1329           n := n - (dymin - dy0);
     1329          N := N - (dymin - dy0);
    13301330          dx0 := dx0 - (dymin - dy0);
    13311331          dy0 := dymin
     
    13341334      else
    13351335      begin
    1336         if dxmax - dx0 < n then
    1337           n := dxmax - dx0;
     1336        if dxmax - dx0 < N then
     1337          N := dxmax - dx0;
    13381338        if dx0 < dxmin then
    13391339        begin
    1340           n := n - (dxmin - dx0);
     1340          N := N - (dxmin - dx0);
    13411341          dy0 := dy0 + (dxmin - dx0);
    13421342          dx0 := dxmin
     
    13441344        if dy0 < dymin then
    13451345        begin
    1346           n := n - (dymin - dy0);
     1346          N := N - (dymin - dy0);
    13471347          dx0 := dx0 + (dymin - dy0);
    13481348          dy0 := dymin
    13491349        end;
    13501350      end;
    1351       if n <= 0 then
    1352         exit;
     1351      if N <= 0 then
     1352        Exit;
    13531353      if mirror then
    13541354      begin
    1355         x0 := x + dx0 * xxt - 1;
    1356         x1 := x + (dx0 - n) * xxt - 1;
     1355        x0 := X + dx0 * xxt - 1;
     1356        x1 := X + (dx0 - N) * xxt - 1;
    13571357      end
    13581358      else
    13591359      begin
    1360         x0 := x + dx0 * xxt;
    1361         x1 := x + (dx0 + n) * xxt;
     1360        x0 := X + dx0 * xxt;
     1361        x1 := X + (dx0 + N) * xxt;
    13621362      end;
    1363       moveto(x0, y + dy0 * yyt);
    1364       lineto(x1, y + (dy0 + n) * yyt);
     1363      moveto(x0, Y + dy0 * yyt);
     1364      lineto(x1, Y + (dy0 + N) * yyt);
    13651365    end;
    13661366  end;
    13671367
    13681368var
    1369   i: integer;
     1369  I: Integer;
    13701370begin
    13711371  FOutput.Canvas.pen.Color := $000000; // $FF shl (8*random(3));
    1372   for i := 0 to nx div 2 do
    1373     ClippedLine(i * 2, 0, false);
    1374   for i := 1 to (nx + 1) div 2 do
    1375     ClippedLine(i * 2, 0, true);
    1376   for i := 0 to ny div 2 do
    1377   begin
    1378     ClippedLine(0, 2 * i + 2, false);
    1379     ClippedLine(nx + 1, 2 * i + 1 + nx and 1, true);
    1380   end;
    1381 end;
    1382 
    1383 function TIsoMap.IsShoreTile(Loc: integer): boolean;
     1372  for I := 0 to nx div 2 do
     1373    ClippedLine(I * 2, 0, False);
     1374  for I := 1 to (nx + 1) div 2 do
     1375    ClippedLine(I * 2, 0, True);
     1376  for I := 0 to ny div 2 do
     1377  begin
     1378    ClippedLine(0, 2 * I + 2, False);
     1379    ClippedLine(nx + 1, 2 * I + 1 + nx and 1, True);
     1380  end;
     1381end;
     1382
     1383function TIsoMap.IsShoreTile(Loc: Integer): Boolean;
    13841384var
    13851385  Dir: Integer;
    1386   ConnLoc: integer;
    1387 begin
    1388   result := false;
     1386  ConnLoc: Integer;
     1387begin
     1388  Result := False;
    13891389  for Dir := 0 to 7 do
    13901390  begin
     
    13921392    if (ConnLoc < 0) or (ConnLoc >= G.lx * G.ly) or
    13931393      ((MyMap[ConnLoc] - 2) and fTerrain < 13) then
    1394       result := true;
     1394      Result := True;
    13951395  end;
    13961396end;
     
    14011401begin
    14021402  for I := 0 to Length - 1 do begin
    1403     Line^.Pixel^.B := (Line^.Pixel^.B shr 1) and $7f;
    1404     Line^.Pixel^.G := (Line^.Pixel^.G shr 1) and $7f;
    1405     Line^.Pixel^.R := (Line^.Pixel^.R shr 1) and $7f;
     1403    Line^.Pixel^.B := (Line^.Pixel^.B shr 1) and $7F;
     1404    Line^.Pixel^.G := (Line^.Pixel^.G shr 1) and $7F;
     1405    Line^.Pixel^.R := (Line^.Pixel^.R shr 1) and $7F;
    14061406    Line^.NextPixel;
    14071407  end;
     
    14151415end;
    14161416
    1417 procedure TIsoMap.ShadeOutside(x0, y0, Width, Height, xm, ym: integer);
     1417procedure TIsoMap.ShadeOutside(x0, y0, Width, Height, xm, ym: Integer);
    14181418const
    14191419  rShade = 3.75;
    14201420var
    1421   y, wBright: integer;
    1422   y_n, w_n: single;
     1421  Y, wBright: Integer;
     1422  y_n, w_n: Single;
    14231423  Line: TPixelPointer;
    14241424begin
    14251425  FOutput.BeginUpdate;
    1426   Line := PixelPointer(FOutput, ScaleToNative(x0), ScaleToNative(y0));
    1427   for y := 0 to ScaleToNative(Height) - 1 do begin
    1428     y_n := (ScaleFromNative(y) + y0 - ym) / yyt;
     1426  Line := TPixelPointer.Create(FOutput, ScaleToNative(x0), ScaleToNative(y0));
     1427  for Y := 0 to ScaleToNative(Height) - 1 do begin
     1428    y_n := (ScaleFromNative(Y) + y0 - ym) / yyt;
    14291429    if abs(y_n) < rShade then begin
    14301430      // Darken left and right parts of elipsis
     
    14451445end;
    14461446
    1447 procedure TIsoMap.CityGrid(xm, ym: integer; CityAllowClick: Boolean);
    1448 var
    1449   i: integer;
     1447procedure TIsoMap.CityGrid(xm, ym: Integer; CityAllowClick: Boolean);
     1448var
     1449  I: Integer;
    14501450begin
    14511451  with FOutput.Canvas do
     
    14561456      pen.Color := $000000;
    14571457    pen.Width := 1;
    1458     for i := 0 to 3 do
     1458    for I := 0 to 3 do
    14591459    begin
    1460       moveto(xm - xxt * (4 - i), ym + yyt * (1 + i));
    1461       lineto(xm + xxt * (1 + i), ym - yyt * (4 - i));
    1462       moveto(xm - xxt * (4 - i), ym - yyt * (1 + i));
    1463       lineto(xm + xxt * (1 + i), ym + yyt * (4 - i));
     1460      moveto(xm - xxt * (4 - I), ym + yyt * (1 + I));
     1461      lineto(xm + xxt * (1 + I), ym - yyt * (4 - I));
     1462      moveto(xm - xxt * (4 - I), ym - yyt * (1 + I));
     1463      lineto(xm + xxt * (1 + I), ym + yyt * (4 - I));
    14641464    end;
    14651465    moveto(xm - xxt * 4, ym + yyt * 1);
     
    14751475end;
    14761476
    1477 procedure TIsoMap.Paint(x, y, Loc, nx, ny, CityLoc, CityOwner: integer;
    1478   UseBlink: boolean; CityAllowClick: boolean);
    1479 var
    1480   dx, dy, xm, ym, ALoc, BLoc, ATer, BTer, Aix, bix: integer;
    1481 begin
    1482   FoW := true;
     1477procedure TIsoMap.Paint(X, Y, Loc, nx, ny, CityLoc, CityOwner: Integer;
     1478  UseBlink: Boolean; CityAllowClick: Boolean);
     1479var
     1480  dx, dy, xm, ym, ALoc, BLoc, ATer, BTer, Aix, bix: Integer;
     1481begin
     1482  FoW := True;
    14831483  ShowLoc := moLocCodes in MapOptions;
    14841484  ShowDebug := pDebugMap >= 0;
     
    14861486  ShowCityNames := ShowObjects and (CityOwner < 0) and
    14871487    (moCityNames in MapOptions);
    1488   ShowBorder := true;
     1488  ShowBorder := True;
    14891489  ShowMyBorder := CityOwner < 0;
    14901490  ShowGrWall := (CityOwner < 0) and (moGreatWall in MapOptions);
    14911491  if ShowDebug then
    1492     Server(sGetDebugMap, me, pDebugMap, DebugMap)
     1492    Server(sGetDebugMap, Me, pDebugMap, DebugMap)
    14931493  else
    14941494    DebugMap := nil;
    14951495  with FOutput.Canvas do
    14961496  begin
    1497     RealTop := y - ((Loc + 12345 * G.lx) div G.lx - 12345) * yyt;
    1498     RealBottom := y + (G.ly - ((Loc + 12345 * G.lx) div G.lx - 12345) +
     1497    RealTop := Y - ((Loc + 12345 * G.lx) div G.lx - 12345) * yyt;
     1498    RealBottom := Y + (G.ly - ((Loc + 12345 * G.lx) div G.lx - 12345) +
    14991499      3) * yyt;
    15001500    Brush.Color := EmptySpaceColor;
     
    15731573                  bix := 0;
    15741574                end;
    1575               BitBltBitmap(OceanPatch, x + dx * xxt, y + dy * yyt, xxt, yyt,
     1575              BitBltBitmap(OceanPatch, X + dx * xxt, Y + dy * yyt, xxt, yyt,
    15761576                Aix * (xxt * 2) + (dx + dy + 1) and 1 * xxt, bix * yyt, SRCCOPY)
    15771577            end
     
    16211621                bix := Aix;
    16221622            if Aix = -1 then
    1623               BitBltBitmap(HGrTerrain.Data, x + dx * xxt, y + dy * yyt, xxt,
     1623              BitBltBitmap(HGrTerrain.Data, X + dx * xxt, Y + dy * yyt, xxt,
    16241624                yyt, 1 + 6 * (xxt * 2 + 1) + (dx + dy + 1) and 1 * xxt, 1 + yyt,
    16251625                SRCCOPY) // arctic <-> ocean
    16261626            else if bix = -1 then
    1627               BitBltBitmap(HGrTerrain.Data, x + dx * xxt, y + dy * yyt, xxt,
     1627              BitBltBitmap(HGrTerrain.Data, X + dx * xxt, Y + dy * yyt, xxt,
    16281628                yyt, 1 + 6 * (xxt * 2 + 1) + xxt - (dx + dy + 1) and 1 * xxt,
    16291629                1 + yyt * 2, SRCCOPY) // arctic <-> ocean
    16301630            else
    1631               BitBltBitmap(LandPatch, x + dx * xxt, y + dy * yyt, xxt, yyt,
     1631              BitBltBitmap(LandPatch, X + dx * xxt, Y + dy * yyt, xxt, yyt,
    16321632                Aix * (xxt * 2) + (dx + dy + 1) and 1 * xxt, bix * yyt, SRCCOPY)
    16331633          end;
     
    16391639    for dx := -1 to nx do
    16401640      if (dx + dy) and 1 = 0 then
    1641         PaintShore(x + xxt * dx, y + yyt + yyt * dy, dLoc(Loc, dx, dy));
     1641        PaintShore(X + xxt * dx, Y + yyt + yyt * dy, dLoc(Loc, dx, dy));
    16421642  for dy := -2 to ny + 1 do
    16431643    for dx := -1 to nx do
    16441644      if (dx + dy) and 1 = 0 then
    1645         PaintTileExtraTerrain(x + xxt * dx, y + yyt + yyt * dy,
     1645        PaintTileExtraTerrain(X + xxt * dx, Y + yyt + yyt * dy,
    16461646          dLoc(Loc, dx, dy));
    16471647  if CityOwner >= 0 then
     
    16531653          ALoc := dLoc(Loc, dx, dy);
    16541654          if Distance(ALoc, CityLoc) > 5 then
    1655             PaintTileObjects(x + xxt * dx, y + yyt + yyt * dy, ALoc, CityLoc,
     1655            PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, ALoc, CityLoc,
    16561656              CityOwner, UseBlink);
    16571657        end;
     
    16601660      * G.lx) mod (2 * G.lx) - G.lx;
    16611661    dy := CityLoc div G.lx - (Loc + 666 * G.lx) div G.lx + 666;
    1662     xm := x + (dx + 1) * xxt;
    1663     ym := y + (dy + 1) * yyt + yyt;
     1662    xm := X + (dx + 1) * xxt;
     1663    ym := Y + (dy + 1) * yyt + yyt;
    16641664    ShadeOutside(FLeft, FTop, FRight - FLeft, FBottom - FTop, xm, ym);
    16651665    CityGrid(xm, ym, CityAllowClick);
     
    16701670          ALoc := dLoc(Loc, dx, dy);
    16711671          if Distance(ALoc, CityLoc) <= 5 then
    1672             PaintTileObjects(x + xxt * dx, y + yyt + yyt * dy, ALoc, CityLoc,
     1672            PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, ALoc, CityLoc,
    16731673              CityOwner, UseBlink);
    16741674        end;
     
    16781678    if ShowLoc or (moEditMode in MapOptions) or
    16791679      (moGrid in MapOptions) then
    1680       PaintGrid(x, y, nx, ny);
     1680      PaintGrid(X, Y, nx, ny);
    16811681    for dy := -2 to ny + 1 do
    16821682      for dx := -2 to nx + 1 do
    16831683        if (dx + dy) and 1 = 0 then
    1684           PaintTileObjects(x + xxt * dx, y + yyt + yyt * dy, dLoc(Loc, dx, dy),
     1684          PaintTileObjects(X + xxt * dx, Y + yyt + yyt * dy, dLoc(Loc, dx, dy),
    16851685            CityLoc, CityOwner, UseBlink);
    16861686  end;
    16871687
    16881688  // frame(FOutput.Canvas,x+1,y+1,x+nx*33+33-2,y+ny*16+32-2,$FFFF,$FFFF);
    1689 end; { Paint }
     1689end;
    16901690
    16911691procedure TIsoMap.AttackBegin(const ShowMove: TShowMove);
  • branches/highdpi/LocalPlayer/KeyBindings.pas

    r464 r465  
    1 unit UKeyBindings;
    2 
    3 {$mode delphi}
     1unit KeyBindings;
    42
    53interface
    64
    75uses
    8   Classes, SysUtils, fgl, LCLProc, LCLType, Menus, Registry;
     6  Classes, SysUtils, Generics.Collections, Generics.Defaults, LCLProc, LCLType,
     7  Menus, Registry;
    98
    109type
     
    2625  { TKeyBindings }
    2726
    28   TKeyBindings = class(TFPGObjectList<TKeyBinding>)
     27  TKeyBindings = class(TObjectList<TKeyBinding>)
    2928  private
    3029  public
     
    3837    procedure ResetToDefault;
    3938    procedure RemoveShortCut(ShortCut: TShortCut);
     39    procedure SortAlpha;
    4040  end;
    4141
     
    241241  Text: string;
    242242begin
    243   Strings.Clear;
    244   for I := 0 to Count - 1 do begin
    245     Text:= '';
    246     if Items[I].ShortCut <> 0 then
    247       Text:= Text + ShortCutToText(Items[I].ShortCut);
    248     if Items[I].ShortCut2 <> 0 then begin
    249       if Text <> '' then Text := Text + ', ';
    250       Text:= Text + ShortCutToText(Items[I].ShortCut2);
     243  Strings.BeginUpdate;
     244  try
     245    Strings.Clear;
     246    for I := 0 to Count - 1 do begin
     247      Text := '';
     248      if Items[I].ShortCut <> 0 then
     249        Text := Text + ShortCutToText(Items[I].ShortCut);
     250      if Items[I].ShortCut2 <> 0 then begin
     251        if Text <> '' then Text := Text + ', ';
     252        Text := Text + ShortCutToText(Items[I].ShortCut2);
     253      end;
     254      if Text <> '' then Text := Items[I].FullName + ' (' + Text + ')'
     255        else Text := Items[I].FullName;
     256      Strings.Add(Text);
    251257    end;
    252     if Text <> '' then Text := Items[I].FullName + ' (' + Text + ')'
    253       else Text := Items[I].FullName;
    254     Strings.Add(Text);
     258  finally
     259    Strings.EndUpdate;
    255260  end;
    256261end;
     
    284289    if Items[I].ShortCut2 = ShortCut then Items[I].ShortCut2 := 0;
    285290  end;
     291end;
     292
     293function CompareAlpha(constref Item1, Item2: TKeyBinding): Integer;
     294begin
     295  Result := CompareStr(Item1.FullName, Item2.FullName);
     296end;
     297
     298procedure TKeyBindings.SortAlpha;
     299begin
     300  Sort(TComparer<TKeyBinding>.Construct(CompareAlpha));
    286301end;
    287302
     
    372387  BMoveLeftUp := AddItem('MoveLeftUp', 'Move unit left-up', 'Num7', 'Home');
    373388  BMoveLeft := AddItem('MoveLeft', 'Move unit left', 'Num4', 'Left');
     389  SortAlpha;
    374390end;
    375391
     
    381397end.
    382398
     399
  • branches/highdpi/LocalPlayer/LocalPlayer.pas

    r378 r465  
    44interface
    55
    6 procedure Client(Command, Player: integer; var Data); stdcall;
    7 procedure SetAIName(p: integer; Name: string);
     6procedure Client(Command, Player: Integer; var Data); stdcall;
     7procedure SetAIName(P: Integer; Name: string);
    88
    99implementation
    1010
    1111uses
    12   UDpiControls, Term, CityScreen, Draft, MessgEx, Select, CityType, Help, UnitStat, Diagram,
    13   NatStat, Wonders, Nego, Enhance, BaseWin, Battle, Rates, TechTree, Forms;
     12  UDpiControls, Term, CityScreen, Nego, BaseWin, Forms;
    1413
    1514var
    16   FormsCreated: boolean;
     15  FormsCreated: Boolean;
    1716
    18 procedure Client(Command, Player: integer; var Data);
     17procedure Client(Command, Player: Integer; var Data);
    1918begin
    2019  if not FormsCreated then
    2120  begin
    22     FormsCreated := true;
     21    FormsCreated := True;
    2322    // TODO: Changing application name in runtime will cause change of Linux XML registry file path
    24 //    DpiApplication.MainForm := MainScreen;
     23//    Application.MainForm := MainScreen;
    2524    DpiApplication.CreateForm(TMainScreen, MainScreen);
    26     DpiApplication.CreateForm(TCityDlg, CityDlg);
    27     DpiApplication.CreateForm(TModalSelectDlg, ModalSelectDlg);
    28     DpiApplication.CreateForm(TListDlg, ListDlg);
    29     DpiApplication.CreateForm(TMessgExDlg, MessgExDlg);
    30     DpiApplication.CreateForm(TDraftDlg, DraftDlg);
    31     DpiApplication.CreateForm(TCityTypeDlg, CityTypeDlg);
    32     DpiApplication.CreateForm(THelpDlg, HelpDlg);
    33     DpiApplication.CreateForm(TUnitStatDlg, UnitStatDlg);
    34     DpiApplication.CreateForm(TDiaDlg, DiaDlg);
    35     DpiApplication.CreateForm(TNatStatDlg, NatStatDlg);
    36     DpiApplication.CreateForm(TWondersDlg, WondersDlg);
    37     DpiApplication.CreateForm(TNegoDlg, NegoDlg);
    38     DpiApplication.CreateForm(TEnhanceDlg, EnhanceDlg);
    39     DpiApplication.CreateForm(TBattleDlg, BattleDlg);
    40     // DpiApplication.CreateForm(TAdvisorDlg, AdvisorDlg);
    41     DpiApplication.CreateForm(TRatesDlg, RatesDlg);
    42     DpiApplication.CreateForm(TTechTreeDlg, TechTreeDlg);
    4325  end;
    4426  MainScreen.Client(Command, Player, Data);
    4527end;
    4628
    47 procedure SetAIName(p: integer; Name: string);
     29procedure SetAIName(P: Integer; Name: string);
    4830begin
    49   MainScreen.SetAIName(p, Name);
     31  MainScreen.SetAIName(P, Name);
    5032end;
    5133
    5234initialization
    5335
    54 FormsCreated := false;
     36FormsCreated := False;
    5537
    5638end.
  • branches/highdpi/LocalPlayer/MessgEx.lfm

    r349 r465  
    66  BorderIcons = []
    77  BorderStyle = bsNone
    8   Caption = 'C-evo'
     8  Caption = 'Message'
    99  ClientHeight = 134
    1010  ClientWidth = 418
     
    1212  DesignTimePPI = 144
    1313  Font.Color = clWindowText
    14   Font.Height = -13
     14  Font.Height = -20
    1515  Font.Name = 'MS Sans Serif'
    1616  FormStyle = fsStayOnTop
     
    2020  OnPaint = FormPaint
    2121  OnShow = FormShow
    22   LCLVersion = '2.0.12.0'
     22  LCLVersion = '2.2.2.0'
    2323  Scaled = False
    2424  object Button1: TButtonA
     
    6161  object EInput: TDpiEdit
    6262    Left = 125
    63     Height = 26
     63    Height = 27
    6464    Top = 64
    6565    Width = 168
  • branches/highdpi/LocalPlayer/MessgEx.pas

    r412 r465  
    55
    66uses
    7   UDpiControls, Messg, Protocol, ScreenTools, Platform, DateUtils,
    8   LCLIntf, LCLType, Messages, SysUtils, Classes, Graphics, Controls, Forms, ButtonA,
    9   ButtonB, StdCtrls, DrawDlg;
     7  UDpiControls, Messg, Protocol, ScreenTools, Platform, DateUtils, LCLIntf, LCLType, Messages,
     8  SysUtils, Classes, Graphics, Controls, Forms, ButtonA, ButtonB, StdCtrls,
     9  DrawDlg, Help;
    1010
    1111type
     
    1313    mikPureIcon, mikMyArmy, mikEnemyArmy, mikFullControl, mikShip, mikBigIcon,
    1414    mikEnemyShipComplete);
     15
     16  { TMessgExDlg }
    1517
    1618  TMessgExDlg = class(TBaseMessgDlg)
     
    3234    Kind: TMessageKind;
    3335    IconIndex: Integer;
    34     HelpKind: Integer;
     36    HelpKind: TLinkCategory;
    3537    HelpNo: Integer;
    3638    CenterTo: Integer;
    3739    IconKind: TMessageIconKind;
    3840    OpenSound: string;
    39     function ShowModal: integer; override;
     41    function ShowModal: Integer; override;
    4042    procedure CancelMovie;
    4143  private
    42     MovieCancelled: boolean;
    43     procedure PaintBook(ca: TDpiCanvas; x, y, clPage, clCover: integer);
     44    MovieCancelled: Boolean;
     45    procedure PaintBook(ca: TDpiCanvas; X, Y, clPage, clCover: Integer);
    4446    procedure PaintMyArmy;
    4547    procedure PaintEnemyArmy;
     
    4749  end;
    4850
    49 var
    50   MessgExDlg: TMessgExDlg;
    5151
    5252procedure SoundMessageEx(SimpleText, SoundItem: string);
    53 procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
     53procedure TribeMessage(P: Integer; SimpleText, SoundItem: string);
    5454function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string)
    55   : integer;
     55  : Integer;
    5656procedure ContextMessage(SimpleText, SoundItem: string;
    57   ContextKind, ContextNo: integer);
     57  ContextKind: TLinkCategory; ContextNo: Integer);
     58
    5859
    5960implementation
    6061
    6162uses
    62   ClientTools, BaseWin, Term, Help, UnitStat, Tribes, UPixelPointer,
    63   IsoEngine, Diagram, Sound;
     63  ClientTools, BaseWin, Term, UnitStat, Tribes, PixelPointer,
     64  Diagram, Sound;
    6465
    6566{$R *.lfm}
     
    7879procedure TMessgExDlg.FormShow(Sender: TObject);
    7980var
    80   i: integer;
     81  I: Integer;
    8182begin
    8283  if IconKind = mikEnemyArmy then
     
    147148  end;
    148149
    149   SplitText(true);
     150  SplitText(True);
    150151  ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing;
    151152  if GameMode = cMovie then
     
    178179      end;
    179180  end;
    180   for i := 0 to ControlCount - 1 do
    181     Controls[i].Top := ClientHeight - (34 + Border);
     181  for I := 0 to ControlCount - 1 do
     182    Controls[I].Top := ClientHeight - (34 + Border);
    182183  if Kind = mkModel then
    183184    EInput.Top := ClientHeight - (76 + Border);
    184185end;
    185186
    186 function TMessgExDlg.ShowModal: integer;
     187function TMessgExDlg.ShowModal: Integer;
    187188var
    188189  Ticks0: TDateTime;
    189190  Ticks: TDateTime;
    190191begin
     192  Caption := Phrases.Lookup('TITLE_MESSAGE');
    191193  if GameMode = cMovie then
    192194  begin
    193195    if not((GameMode = cMovie) and (MovieSpeed = 4)) then
    194196    begin
    195       MovieCancelled := false;
     197      MovieCancelled := False;
    196198      Show;
    197199      Ticks0 := NowPrecise;
     
    203205      Hide;
    204206    end;
    205     result := mrOk;
     207    Result := mrOk;
    206208  end
    207209  else
    208     result := inherited;
     210    Result := inherited;
     211  //Gtk2Fix;
    209212end;
    210213
    211214procedure TMessgExDlg.CancelMovie;
    212215begin
    213   MovieCancelled := true;
    214 end;
    215 
    216 procedure TMessgExDlg.PaintBook(ca: TDpiCanvas; x, y, clPage, clCover: integer);
     216  MovieCancelled := True;
     217end;
     218
     219procedure TMessgExDlg.PaintBook(ca: TDpiCanvas; X, Y, clPage, clCover: Integer);
    217220const
    218221  xScrewed = 77;
     
    220223  wScrewed = 43;
    221224  hScrewed = 27;
     225type
     226  TScrewed = array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of Single;
    222227var
    223   ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: integer;
     228  ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: Integer;
    224229  BookRect: TRect;
    225   x1, xR, yR, share: single;
    226   Screwed: array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of single;
     230  x1, xR, yR, share: Single;
     231  Screwed: TScrewed;
    227232  SrcPtr: TPixelPointer;
    228233  Width: Integer;
     
    235240    yIcon := (IconIndex + SystemIconLines * 7) div 7 * ySizeBig;
    236241    // prepare screwed icon
    237     FillChar(Screwed, sizeof(Screwed), 0);
     242    Screwed := Default(TScrewed);
    238243    BigImp.BeginUpdate;
    239     SrcPtr := PixelPointer(BigImp, ScaleToNative(xIcon), ScaleToNative(yIcon));
     244    SrcPtr := TPixelPointer.Create(BigImp, ScaleToNative(xIcon), ScaleToNative(yIcon));
    240245    for iy := 0 to ScaleToNative(Height) - 1 do begin
    241246      for ix := 0 to ScaleToNative(Width) - 1 do begin
     
    277282    BookRect := SmallBook.BoundsRect;
    278283  end;
    279   x := x - BookRect.Width div 2;
     284  X := X - BookRect.Width div 2;
    280285
    281286  // paint
    282287  UnshareBitmap(LogoBuffer);
    283   DpiBitCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, x, y);
     288  DpiBitBltCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, X, Y);
    284289
    285290  if IconIndex >= 0 then
     
    294299  ImageOp_BCC(LogoBuffer, Templates.Data, Point(0, 0), BookRect, clCover, clPage);
    295300
    296   DpiBitCanvas(ca, x, y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0);
     301  DpiBitBltCanvas(ca, X, Y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0);
    297302end;
    298303
     
    303308procedure TMessgExDlg.PaintEnemyArmy;
    304309var
    305   emix, ix, iy, x, y, count, UnitsInLine: integer;
     310  emix, ix, iy, X, Y, count, UnitsInLine: Integer;
    306311begin
    307312  ix := 0;
     
    314319    for count := 0 to LostArmy[emix] - 1 do
    315320    begin
    316       x := ClientWidth div 2 + ix * 64 - UnitsInLine * 32;
    317       y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;
     321      X := ClientWidth div 2 + ix * 64 - UnitsInLine * 32;
     322      Y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;
    318323      with MyRO.EnemyModel[emix], Tribe[Owner].ModelPicture[mix] do
    319324      begin
    320         DpiBitCanvas(Canvas, x, y, 64, 48, HGr.Mask.Canvas,
     325        DpiBitBltCanvas(Canvas, X, Y, 64, 48, HGr.Mask.Canvas,
    321326          pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCAND);
    322         DpiBitCanvas(Canvas, x, y, 64, 48, HGr.Data.Canvas,
     327        DpiBitBltCanvas(Canvas, X, Y, 64, 48, HGr.Data.Canvas,
    323328          pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCPAINT);
    324329      end;
    325330
    326331      // next position
    327       inc(ix);
     332      Inc(ix);
    328333      if ix = LostUnitsPerLine then
    329334      begin // next line
    330335        ix := 0;
    331         inc(iy);
     336        Inc(iy);
    332337        if iy = 6 then
    333           exit;
     338          Exit;
    334339        UnitsInLine := nLostArmy - LostUnitsPerLine * iy;
    335340        if UnitsInLine > LostUnitsPerLine then
     
    341346procedure TMessgExDlg.FormPaint(Sender: TObject);
    342347var
    343   p1, clSaveTextLight, clSaveTextShade: integer;
     348  p1, clSaveTextLight, clSaveTextShade: Integer;
    344349begin
    345350  if (IconKind = mikImp) and (IconIndex = 27) then
     
    362367        p1 := MyRO.Wonder[IconIndex].EffectiveOwner;
    363368        UnshareBitmap(Buffer);
    364         DpiBitCanvas(Buffer.Canvas, 0, 0, xSizeBig + 2 * GlowRange,
     369        DpiBitBltCanvas(Buffer.Canvas, 0, 0, xSizeBig + 2 * GlowRange,
    365370          ySizeBig + 2 * GlowRange, Canvas,
    366371          ClientWidth div 2 - (28 + GlowRange), 24 - GlowRange);
    367         DpiBitCanvas(Buffer.Canvas, GlowRange, GlowRange, xSizeBig, ySizeBig,
     372        DpiBitBltCanvas(Buffer.Canvas, GlowRange, GlowRange, xSizeBig, ySizeBig,
    368373          BigImp.Canvas, IconIndex mod 7 * xSizeBig,
    369374          (IconIndex + SystemIconLines * 7) div 7 * ySizeBig);
     
    373378          GlowFrame(Buffer, GlowRange, GlowRange, xSizeBig, ySizeBig,
    374379            Tribe[p1].Color);
    375         DpiBitCanvas(Canvas, ClientWidth div 2 - (28 + GlowRange),
     380        DpiBitBltCanvas(Canvas, ClientWidth div 2 - (28 + GlowRange),
    376381          24 - GlowRange, xSizeBig + 2 * GlowRange, ySizeBig + 2 * GlowRange,
    377382          Buffer.Canvas, 0, 0);
     
    387392      end;
    388393    mikModel:
    389       with Tribe[me].ModelPicture[IconIndex] do
     394      with Tribe[Me].ModelPicture[IconIndex] do
    390395      begin
    391396        FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig,
    392397          ySizeBig, 0, 0);
    393         DpiBitCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
     398        DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
    394399          HGr.Mask.Canvas, pix mod 10 * 65 + 1,
    395400          pix div 10 * 49 + 1, SRCAND);
    396         DpiBitCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
     401        DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 20, 64, 44,
    397402          HGr.Data.Canvas, pix mod 10 * 65 + 1,
    398403          pix div 10 * 49 + 1, SRCPAINT);
     
    406411        Frame(Canvas, ClientWidth div 2 - 32 - 1, 24 - 1,
    407412          ClientWidth div 2 + 32, 24 + 48, $000000, $000000);
    408         DpiBitCanvas(Canvas, ClientWidth div 2 - 32, 24, 64, 48,
     413        DpiBitBltCanvas(Canvas, ClientWidth div 2 - 32, 24, 64, 48,
    409414          Tribe[IconIndex].faceHGr.Data.Canvas,
    410415          1 + Tribe[IconIndex].facepix mod 10 * 65,
     
    420425    mikEnemyShipComplete:
    421426      begin
    422         DpiBitCanvas(Buffer.Canvas, 0, 0, 140, 120, Canvas,
     427        DpiBitBltCanvas(Buffer.Canvas, 0, 0, 140, 120, Canvas,
    423428          (ClientWidth - 140) div 2, 24);
    424429        ImageOp_BCC(Buffer, Templates.Data, Point(0, 0), StarshipDeparted.BoundsRect, 0, $FFFFFF);
    425         DpiBitCanvas(Canvas, (ClientWidth - 140) div 2, 24, 140, 120,
     430        DpiBitBltCanvas(Canvas, (ClientWidth - 140) div 2, 24, 140, 120,
    426431          Buffer.Canvas, 0, 0);
    427432      end;
     
    451456begin
    452457  if Kind = mkOkHelp then
    453     HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo)
     458    MainScreen.HelpDlg.ShowNewContent(wmSubmodal, HelpKind, HelpNo)
    454459  else if Kind = mkModel then
    455     UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex)
     460    MainScreen.UnitStatDlg.ShowNewContent_OwnModel(wmSubmodal, IconIndex)
    456461  else
    457462    ModalResult := mrIgnore;
     
    482487// because Messg.SoundMessage not capable of movie mode
    483488begin
    484   with MessgExDlg do
     489  with MainScreen.MessgExDlg do
    485490  begin
    486491    MessgText := SimpleText;
     
    491496end;
    492497
    493 procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
    494 begin
    495   with MessgExDlg do
     498procedure TribeMessage(P: Integer; SimpleText, SoundItem: string);
     499begin
     500  with MainScreen.MessgExDlg do
    496501  begin
    497502    OpenSound := SoundItem;
     
    499504    Kind := mkOk;
    500505    IconKind := mikTribe;
    501     IconIndex := p;
     506    IconIndex := P;
    502507    ShowModal;
    503508  end;
     
    505510
    506511function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string)
    507   : integer;
    508 begin
    509   with MessgExDlg do
     512  : Integer;
     513begin
     514  with MainScreen.MessgExDlg do
    510515  begin
    511516    MessgText := SimpleText;
     
    513518    Kind := QueryKind;
    514519    ShowModal;
    515     result := ModalResult;
     520    Result := ModalResult;
    516521  end;
    517522end;
    518523
    519524procedure ContextMessage(SimpleText, SoundItem: string;
    520   ContextKind, ContextNo: integer);
    521 begin
    522   with MessgExDlg do
     525  ContextKind: TLinkCategory; ContextNo: Integer);
     526begin
     527  with MainScreen.MessgExDlg do
    523528  begin
    524529    MessgText := SimpleText;
     
    543548end;
    544549
    545 
    546 initialization
    547 
    548550end.
  • branches/highdpi/LocalPlayer/NatStat.pas

    r361 r465  
    55
    66uses
    7   UDpiControls, Protocol, ClientTools, Term, ScreenTools, BaseWin,
    8 
    9   LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
    10   ButtonB, ButtonC, Menus, EOTButton;
     7  UDpiControls, Protocol, ClientTools, ScreenTools, BaseWin, LCLIntf, LCLType, SysUtils,
     8  Classes, Graphics, Controls, Forms, ButtonB, ButtonC, Menus, EOTButton;
    119
    1210type
     
    2725    procedure ToggleBtnClick(Sender: TObject);
    2826    procedure PlayerClick(Sender: TObject);
    29     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     27    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    3028    procedure FormDestroy(Sender: TObject);
    3129    procedure ScrollUpBtnClick(Sender: TObject);
    3230    procedure ScrollDownBtnClick(Sender: TObject);
    3331    procedure TellAIBtnClick(Sender: TObject);
    34 
    3532  public
    3633    procedure CheckAge;
    37     procedure ShowNewContent(NewMode: integer; p: integer = -1);
     34    procedure ShowNewContent(NewMode: TWindowMode; P: Integer = -1);
    3835    procedure EcoChange;
    39 
    4036  protected
    4137    procedure OffscreenPaint; override;
    42 
    4338  private
    44     pView, AgePrepared, LinesDown: integer;
    45     SelfReport, CurrentReport: PEnemyReport;
    46     ShowContact, ContactEnabled: boolean;
    47     Back, Template: TDpiBitmap;
     39    pView: Integer;
     40    AgePrepared: Integer;
     41    LinesDown: Integer;
     42    SelfReport: PEnemyReport;
     43    CurrentReport: PEnemyReport;
     44    ShowContact: Boolean;
     45    ContactEnabled: Boolean;
     46    Back: TDpiBitmap;
     47    Template: TDpiBitmap;
    4848    ReportText: TStringList;
    4949    procedure GenerateReportText;
    5050  end;
    5151
    52 var
    53   NatStatDlg: TNatStatDlg;
    5452
    5553implementation
     
    5856
    5957uses
    60   Messg, Tribes, Directories;
     58  Term, Messg, Tribes, Directories;
    6159
    6260const
     
    109107  if MainTexture.Age <> AgePrepared then begin
    110108    AgePrepared := MainTexture.Age;
    111     DpiBitCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
     109    DpiBitBltCanvas(Back.Canvas, 0, 0, ClientWidth, ClientHeight,
    112110      MainTexture.Image.Canvas, (MainTexture.Width - ClientWidth) div 2,
    113111      (MainTexture.Height - ClientHeight) div 2);
     
    118116procedure TNatStatDlg.FormShow(Sender: TObject);
    119117begin
    120   if pView = me then
     118  if pView = Me then
    121119  begin
    122120    SelfReport.TurnOfCivilReport := MyRO.Turn;
    123121    SelfReport.TurnOfMilReport := MyRO.Turn;
    124     move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
     122    Move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
    125123    SelfReport.Government := MyRO.Government;
    126124    SelfReport.Money := MyRO.Money;
    127     CurrentReport := pointer(SelfReport);
     125    CurrentReport := Pointer(SelfReport);
    128126  end
    129127  else
    130     CurrentReport := pointer(MyRO.EnemyReport[pView]);
     128    CurrentReport := Pointer(MyRO.EnemyReport[pView]);
    131129  if CurrentReport.TurnOfCivilReport >= 0 then
    132130    GenerateReportText;
    133   ShowContact := (pView <> me) and (not supervising or (me <> 0));
    134   ContactEnabled := ShowContact and not supervising and
     131  ShowContact := (pView <> Me) and (not Supervising or (Me <> 0));
     132  ContactEnabled := ShowContact and not Supervising and
    135133    (1 shl pView and MyRO.Alive <> 0);
    136134  ContactBtn.Visible := ContactEnabled and (MyRO.Happened and phGameEnd = 0) and
     
    150148end;
    151149
    152 procedure TNatStatDlg.ShowNewContent(NewMode, p: integer);
    153 begin
    154   if p < 0 then
     150procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; P: Integer);
     151begin
     152  if P < 0 then
    155153    if ClientMode >= scContact then
    156       pView := DipMem[me].pContact
     154      pView := DipMem[Me].pContact
    157155    else
    158156    begin
     
    160158      while (pView < nPl) and ((MyRO.Treaty[pView] < trNone) or
    161159        (1 shl pView and MyRO.Alive = 0)) do
    162         inc(pView);
     160        Inc(pView);
    163161      if pView >= nPl then
    164         pView := me;
     162        pView := Me;
    165163    end
    166164  else
    167     pView := p;
     165    pView := P;
    168166  inherited ShowNewContent(NewMode);
    169167end;
     
    178176  List: ^TChart;
    179177
    180   function StatText(no: integer): string;
     178  function StatText(no: Integer): string;
    181179  var
    182     i: integer;
     180    I: Integer;
    183181  begin
    184182    if (CurrentReport.TurnOfCivilReport >= 0) and
    185       (Server(sGetChart + no shl 4, me, pView, List^) >= rExecuted) then
     183      (Server(sGetChart + no shl 4, Me, pView, List^) >= rExecuted) then
    186184    begin
    187       i := List[CurrentReport.TurnOfCivilReport];
     185      I := List[CurrentReport.TurnOfCivilReport];
    188186      case no of
    189187        stPop:
    190           result := Format(Phrases.Lookup('FRSTATPOP'), [i]);
     188          Result := Format(Phrases.Lookup('FRSTATPOP'), [I]);
    191189        stTerritory:
    192           result := Format(Phrases.Lookup('FRSTATTER'), [i]);
     190          Result := Format(Phrases.Lookup('FRSTATTER'), [I]);