Changeset 447


Ignore:
Timestamp:
May 19, 2022, 10:39:34 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Use first capital letter in identifiers.
Location:
trunk
Files:
82 edited

Legend:

Unmodified
Added
Removed
  • trunk/AI/StdAI/AI.pas

    r442 r447  
    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 constructor TAI.Create(Nation: integer);
     176  LeaveOutValue: array[0..nAdv - 1] of Integer;
     177
     178constructor TAI.Create(Nation: Integer);
    179179begin
    180180  inherited;
    181   Data := pointer(RO.Data);
     181  Data := Pointer(RO.Data);
    182182{$IFDEF DEBUG}
    183183  if Nation = 1 then
     
    192192  begin
    193193    LastResearchTech := -1;
    194     if PlayerHash[me] > 7 then
     194    if PlayerHash[Me] > 7 then
    195195      BehaviorFlags := bFemale
    196196    else
     
    198198    DebugMessage(1, 'Gender:=' + char(48 + BehaviorFlags and bGender));
    199199    TheologyPartner := -1;
    200     fillchar(RejectTurn, sizeof(RejectTurn), $FF);
    201     Fillchar(RequestedTechs, sizeof(RequestedTechs), $FF);
     200    FillChar(RejectTurn, SizeOf(RejectTurn), $FF);
     201    Fillchar(RequestedTechs, SizeOf(RequestedTechs), $FF);
    202202  end;
    203203end;
    204204
    205 function TAI.OnNegoRejected_CancelTreaty: boolean;
     205function TAI.OnNegoRejected_CancelTreaty: Boolean;
    206206begin
    207207  Data.RejectTurn[suContact, Opponent] := RO.Turn;
     
    213213//-------------------------------
    214214
    215 procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: integer);
     215procedure TAI.RateModel(const mi: TModelInfo; var Category, Quality: Integer);
    216216var
    217   EffectiveTransport: integer;
     217  EffectiveTransport: Integer;
    218218begin
    219219  if mi.Kind >= mkScout then
    220220  begin
    221221    Category := mctNone;
    222     exit;
     222    Exit;
    223223  end;
    224224  case mi.Domain of
     
    292292end;
    293293
    294 procedure TAI.RateMyModel(mix: integer; var Category, Quality: integer);
     294procedure TAI.RateMyModel(mix: Integer; var Category, Quality: Integer);
    295295var
    296296  mi: TModelInfo;
    297297begin
    298   MakeModelInfo(me, mix, MyModel[mix], mi);
     298  MakeModelInfo(Me, mix, MyModel[mix], mi);
    299299  RateModel(mi, Category, Quality);
    300300end;
    301301
    302 function TAI.IsBetterModel(const mi: TModelInfo): boolean;
     302function TAI.IsBetterModel(const mi: TModelInfo): Boolean;
    303303var
    304   mix, Cat, Quality, Cat1, Quality1: integer;
     304  mix, Cat, Quality, Cat1, Quality1: Integer;
    305305begin
    306306  RateModel(mi, Cat, Quality);
     
    312312      begin
    313313        Result := False;
    314         exit;
     314        Exit;
    315315      end;
    316316    end;
     
    318318end;
    319319
    320 function TAI.ChooseResearchAdvance: integer;
     320function TAI.ChooseResearchAdvance: Integer;
    321321var
    322   adNext, iad, i, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut,
    323   NewResearch, StateOfArt, mix: integer;
     322  adNext, iad, I, ad, Count, EarliestNeeded, EarliestNeeded_NoLeaveOut,
     323  NewResearch, StateOfArt, mix: Integer;
    324324  mi: TModelInfo;
    325   Entry: array[0..nAdv - 1] of boolean;
    326   ok: boolean;
    327 
    328   function MarkEntry(ad: integer): boolean;
     325  Entry: array[0..nAdv - 1] of Boolean;
     326  ok: Boolean;
     327
     328  function MarkEntry(ad: Integer): Boolean;
    329329  begin
    330330    if RO.Tech[ad] >= tsApplicable then
     
    373373  end;
    374374
    375   procedure OptimizeDevModel(OptimizeCaps: integer);
     375  procedure OptimizeDevModel(OptimizeCaps: Integer);
    376376  var
    377     f, Cat, OriginalCat, Quality, BestQuality, Best: integer;
     377    F, Cat, OriginalCat, Quality, BestQuality, Best: Integer;
    378378    mi: TModelInfo;
    379379  begin
    380     MakeModelInfo(me, 0, RO.DevModel, mi);
     380    MakeModelInfo(Me, 0, RO.DevModel, mi);
    381381    RateModel(mi, OriginalCat, BestQuality);
    382382    repeat
    383383      Best := -1;
    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
     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
    391391          begin
    392             MakeModelInfo(me, 0, RO.DevModel, mi);
     392            MakeModelInfo(Me, 0, RO.DevModel, mi);
    393393            RateModel(mi, Cat, Quality);
    394             assert(Cat = OriginalCat);
     394            Assert(Cat = OriginalCat);
    395395            if Quality > BestQuality then
    396396            begin
    397               Best := f;
     397              Best := F;
    398398              BestQuality := Quality;
    399399            end;
    400             SetNewModelFeature(f, RO.DevModel.Cap[f] - 1);
     400            SetNewModelFeature(F, RO.DevModel.Cap[F] - 1);
    401401          end;
    402402        end;
     
    406406  end;
    407407
    408   function LeaveOutsMissing(ad: integer): boolean;
     408  function LeaveOutsMissing(ad: Integer): Boolean;
    409409  var
    410     i: integer;
     410    I: Integer;
    411411  begin
    412412    Result := False;
     
    422422        Result := True
    423423      else
    424         for i := 0 to 1 do
    425           if AdvPreq[ad, i] >= 0 then
    426             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]);
    427427  end;
    428428
     
    432432    Result := Barbarina_ChooseResearchAdvance;
    433433    if Result >= 0 then
    434       exit;
     434      Exit;
    435435  end;
    436436
     
    444444      Result := ad;
    445445  if Result >= 0 then
    446     exit;
     446    Exit;
    447447
    448448  if Data.BehaviorFlags and bBarbarina = 0 then
     
    460460      OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl
    461461        mcMob + 1 shl mcLongRange + 1 shl mcFanatic);
    462       MakeModelInfo(me, 0, RO.DevModel, mi);
     462      MakeModelInfo(Me, 0, RO.DevModel, mi);
    463463      if IsBetterModel(mi) then
    464464      begin
    465465        Result := adMilitary;
    466         exit;
     466        Exit;
    467467      end;
    468468
     
    471471      SetNewModelFeature(mcOffense, 1);
    472472      OptimizeDevModel(1 shl mcOffense + 1 shl mcDefense + 1 shl mcFanatic);
    473       MakeModelInfo(me, 0, RO.DevModel, mi);
     473      MakeModelInfo(Me, 0, RO.DevModel, mi);
    474474      if IsBetterModel(mi) then
    475475      begin
    476476        Result := adMilitary;
    477         exit;
     477        Exit;
    478478      end;
    479479    end;
     
    491491        SetNewModelFeature(mcWeapons, 0);
    492492        SetNewModelFeature(mcDefense, 3);
    493         exit;
     493        Exit;
    494494      end;
    495495    end;
     
    506506      OptimizeDevModel(1 shl mcDefense+1 shl mcSeaTrans+1 shl mcTurbines
    507507        +1 shl mcAirDef);
    508       MakeModelInfo(me,0,RO.DevModel,mi);
     508      MakeModelInfo(Me,0,RO.DevModel,mi);
    509509      if IsBetterModel(mi) then
    510         begin result:=adMilitary; exit end;
     510        begin Result:=adMilitary; Exit end;
    511511      end;
    512512
     
    519519      OptimizeDevModel(1 shl mcOffense+1 shl mcDefense
    520520        +1 shl mcLongRange+1 shl mcAirDef+1 shl mcRadar);
    521       MakeModelInfo(me,0,RO.DevModel,mi);
     521      MakeModelInfo(Me,0,RO.DevModel,mi);
    522522      if IsBetterModel(mi) then
    523         begin result:=adMilitary; exit end;
     523        begin Result:=adMilitary; Exit end;
    524524      end
    525525    end;
     
    545545        begin
    546546          ok := True;
    547           break;
     547          Break;
    548548        end;
    549549      if not ok then
     
    588588        begin // 2 of 3 required
    589589          Count := 0;
    590           for i := 0 to 2 do
    591             if RO.Tech[AdvPreq[ad, i]] >= tsApplicable then
     590          for I := 0 to 2 do
     591            if RO.Tech[AdvPreq[ad, I]] >= tsApplicable then
    592592              Inc(Count);
    593593          if Count >= 2 then
    594594          begin
    595595            Result := ad;
    596             exit;
     596            Exit;
    597597          end;
    598598        end
     
    602602        begin
    603603          Result := ad;
    604           exit;
     604          Exit;
    605605        end;
    606606      end;
     
    618618    begin // go for future techs
    619619      Result := -1;
    620       i := 0;
     620      I := 0;
    621621      for ad := nAdv - 4 to nAdv - 1 do
    622622        if (RO.Tech[ad] < MaxFutureTech) and (RO.Tech[AdvPreq[ad, 0]] >=
    623623          tsApplicable) then
    624624        begin
    625           Inc(i);
    626           if random(i) = 0 then
     625          Inc(I);
     626          if random(I) = 0 then
    627627            Result := ad;
    628628        end;
    629       assert((Result < 0) or AdvanceResearchable(Result));
    630       exit;
    631     end;
    632 
    633   assert(NewResearch >= 0);
    634   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);
    635635  MarkEntry(NewResearch);
    636636  Result := -1;
     
    638638    if Entry[ad] and ((Result < 0) or (Advancedness[ad] > Advancedness[Result])) then
    639639      Result := ad;
    640   assert(Result >= 0);
     640  Assert(Result >= 0);
    641641end;
    642642
    643 function TAI.ChooseStealAdvance: integer;
     643function TAI.ChooseStealAdvance: Integer;
    644644var
    645   ad: integer;
     645  ad: Integer;
    646646begin
    647647  Result := -1;
     
    659659  twpAllowFarmland = $0001;
    660660
    661 procedure TAI.TileWorkPlan(Loc, cix: integer; var Value, NextJob, TotalWork: integer);
     661procedure TAI.TileWorkPlan(Loc, cix: Integer; var Value, NextJob, TotalWork: Integer);
    662662var
    663   OldTile, TerrType: cardinal;
     663  OldTile, TerrType: Cardinal;
    664664  TileInfo: TTileInfo;
    665665begin
     
    669669  begin
    670670    Value := 3 * 8 - 1;
    671     exit;
     671    Exit;
    672672  end; // better than any tile with 2 food
    673673
     
    690690      Map[Loc] := Map[Loc] and not fTerrain or fGrass;
    691691      TerrType := fGrass;
    692       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);
    693693    end
    694694    else if IsResearched(adExplosives) and
     
    701701      Map[Loc] := Map[Loc] and not fTerrain or fGrass;
    702702      TerrType := fGrass;
    703       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);
    704704    end;
    705705    if (Terrain[TerrType].MineEff > 0) and (RO.Government <> gDespotism) then
     
    764764    end;
    765765  end;
    766   Server(sGetTileInfo, me, Loc, TileInfo);
     766  Server(sGetTileInfo, Me, Loc, TileInfo);
    767767  Value := TileInfo.Food * 8 + TileInfo.Prod * 2 + TileInfo.Trade;
    768768  Map[Loc] := OldTile;
     
    772772procedure TAI.ProcessSettlers;
    773773var
    774   i, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade,
     774  I, uix, cix, ecix, dtr, Loc, RadiusLoc, Special, Food, Prod, Trade,
    775775  CityFood, Happy, TestScore, BestNearCityScore, BestUnusedValue,
    776   BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: integer;
    777   Tile: cardinal;
    778   FoodOk, Started: boolean;
     776  BestUnusedLoc, Value, NextJob, TotalWork, V21, part, Loc1: Integer;
     777  Tile: Cardinal;
     778  FoodOk, Started: Boolean;
    779779  Radius: TVicinity21Loc;
    780780  CityAreaInfo: TCityAreaInfo;
    781   TileFood, ResourceScore, CityScore: array[0..lxmax * lymax - 1] of integer;
    782 
    783   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);
    784784  // set Score=1 for low-priority jobs
    785785  begin
     
    789789  end;
    790790
    791   procedure ReserveCityRadius(Loc: integer);
     791  procedure ReserveCityRadius(Loc: Integer);
    792792  var
    793     V21, RadiusLoc: integer;
     793    V21, RadiusLoc: Integer;
    794794    Radius: TVicinity21Loc;
    795795  begin
     
    808808  procedure ScoreRoadConnections;
    809809  var
    810     V8, nFragments, Loc, Loc1, History, RoadScore, a, b, FullyDeveloped,
    811     ConnectMask: integer;
    812     BridgeOk: boolean;
     810    V8, nFragments, Loc, Loc1, History, RoadScore, A, B, FullyDeveloped,
     811    ConnectMask: Integer;
     812    BridgeOk: Boolean;
    813813    Adjacent: TVicinity8Loc;
    814814  begin
     
    821821      if ((1 shl (Map[Loc] and fTerrain)) and (1 shl fOcean or 1 shl
    822822        fShore or 1 shl fDesert or 1 shl fArctic or 1 shl fUNKNOWN) = 0) and
    823         (RO.Territory[Loc] = me) and (Map[Loc] and FullyDeveloped = 0) and
     823        (RO.Territory[Loc] = Me) and (Map[Loc] and FullyDeveloped = 0) and
    824824        (BridgeOk or (Map[Loc] and fRiver = 0)) then
    825825      begin
     
    835835          Loc1 := Adjacent[V8 and 7];
    836836          History := History shl 1;
    837           if (Loc1 >= 0) and (RO.Territory[Loc1] = me) and
     837          if (Loc1 >= 0) and (RO.Territory[Loc1] = Me) and
    838838            (Map[Loc1] and ConnectMask <> 0) then
    839839          begin
     
    851851                  else if History and 4 <> 0 then
    852852                  begin
    853                     V8_to_ab((V8 - 1) and 7, a, b);
    854                     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);
    855855                    if (Loc1 >= 0) and (Map[Loc1] and ConnectMask <> 0) then
    856856                      Dec(nFragments);
     
    876876
    877877begin
    878   fillchar(SettlerSurplus, sizeof(SettlerSurplus), 0);
     878  FillChar(SettlerSurplus, SizeOf(SettlerSurplus), 0);
    879879  JobAssignment_Initialize;
    880880
    881881  if (Data.BehaviorFlags and bBarbarina = 0) or (RO.nCity < 3) then
    882882  begin
    883     fillchar(TileFood, sizeof(TileFood), 0);
    884     fillchar(ResourceScore, sizeof(ResourceScore), 0);
     883    FillChar(TileFood, SizeOf(TileFood), 0);
     884    FillChar(ResourceScore, SizeOf(ResourceScore), 0);
    885885    for Loc := 0 to MapSize - 1 do
    886886      if Map[Loc] and fTerrain <> fUNKNOWN then
     
    923923
    924924    // rate possible new cities
    925     fillchar(CityScore, MapSize * sizeof(integer), 0);
     925    FillChar(CityScore, MapSize * SizeOf(Integer), 0);
    926926    for Loc := 0 to MapSize - 1 do
    927927    begin
     
    930930        ((RO.Government <> gDespotism) or (Map[Loc] and fSpecial = fSpecial1)) or
    931931        (Map[Loc] and (fTerrain or fSpecial) = fPrairie or fSpecial1));
    932       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
    933933      begin
    934934        TestScore := 0;
     
    950950        if CityFood >= MinCityFood then // city is worth founding
    951951        begin
    952           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;
    953953          // some unexactness, random but always the same for this tile
    954954          if TestScore > BestNearCityScore then
     
    988988              if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then
    989989              begin
    990                 assert(RadiusLoc >= 0);
     990                Assert(RadiusLoc >= 0);
    991991                TileWorkPlan(RadiusLoc, cix, Value, NextJob, TotalWork);
    992992                if (NextJob = jRoad) and (Built[imPalace] +
     
    10001000            begin // tile could be exploited
    10011001              RadiusLoc := Radius[V21];
    1002               assert(RadiusLoc >= 0);
     1002              Assert(RadiusLoc >= 0);
    10031003              if not (Map[RadiusLoc] and fTerrain in [fDesert, fArctic]) then
    10041004              begin
     
    10241024  if Data.BehaviorFlags and bBarbarina = 0 then // low priority jobs
    10251025    for Loc := 0 to MapSize - 1 do
    1026       if RO.Territory[Loc] = me then
     1026      if RO.Territory[Loc] = Me then
    10271027      begin
    10281028        Tile := Map[Loc];
     
    10481048  begin
    10491049    for part := 0 to nShipPart - 1 do
    1050       for i := 0 to ColonyShipPlan[part].nLocFoundCity - 1 do
    1051       begin
    1052         Loc := ColonyShipPlan[part].LocFoundCity[i];
     1050      for I := 0 to ColonyShipPlan[part].nLocFoundCity - 1 do
     1051      begin
     1052        Loc := ColonyShipPlan[part].LocFoundCity[I];
    10531053        Started := False;
    10541054        for uix := 0 to RO.nUn - 1 do
     
    10561056          begin
    10571057            Started := True;
    1058             break;
     1058            Break;
    10591059          end;
    10601060        if not Started then
     
    11191119            begin // settlers could be added to this city
    11201120              Happy := BasicHappy;
    1121               for i := 0 to nWonder - 1 do
    1122                 if Built[i] > 0 then
     1121              for I := 0 to nWonder - 1 do
     1122                if Built[I] > 0 then
    11231123                  Inc(Happy);
    11241124              if Built[imTemple] > 0 then
     
    11271127              begin
    11281128                Inc(Happy, 2);
    1129                 if RO.Wonder[woBach].EffectiveOwner = me then
     1129                if RO.Wonder[woBach].EffectiveOwner = Me then
    11301130                  Inc(Happy, 1);
    11311131              end;
     
    11501150procedure TAI.DoTurn;
    11511151var
    1152   emix, i, p1, TaxSum, ScienceSum, NewTaxRate: integer;
    1153   AllHateMe: boolean;
     1152  emix, I, p1, TaxSum, ScienceSum, NewTaxRate: Integer;
     1153  AllHateMe: Boolean;
    11541154{$IFDEF PERF}
    11551155  PF, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9: int64;
     
    11571157begin
    11581158{$IFDEF DEBUG}
    1159   fillchar(DebugMap, sizeof(DebugMap), 0);
     1159  FillChar(DebugMap, SizeOf(DebugMap), 0);
    11601160{$ENDIF}
    11611161
     
    11691169  WarNations := PresenceUnknown;
    11701170  for p1 := 0 to nPl - 1 do
    1171     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
    11721172      Inc(WarNations, 1 shl p1);
    11731173  BombardingNations := 0;
     
    11851185    CheckGender;
    11861186
    1187   if G.Difficulty[me] < MaxDiff then // not on beginner level
     1187  if G.Difficulty[Me] < MaxDiff then // not on beginner level
    11881188  begin
    11891189    if (Data.LastResearchTech = adHorsebackRiding) and (RO.ResearchTech < 0) and
    11901190      (random(6) = 0) and (HavePort or (ContinentPresence[0] and not
    1191       (1 shl me or PresenceUnknown) <> 0)) then
     1191      (1 shl Me or PresenceUnknown) <> 0)) then
    11921192    begin
    11931193      Data.BehaviorFlags := Data.BehaviorFlags or bBarbarina_Hide;
     
    12061206          begin
    12071207            AllHateMe := False;
    1208             break;
     1208            Break;
    12091209          end;
    12101210      if AllHateMe then
     
    13021302  else
    13031303  begin
    1304     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
    13051305      NewTaxRate := RO.TaxRate // don't check decreasing tax
    13061306    else
     
    13091309    begin
    13101310      SumCities(NewTaxRate, TaxSum, ScienceSum);
    1311       if RO.Money + TaxSum >= (TotalPopulation[me] - 4) then
    1312         break; // enough
     1311      if RO.Money + TaxSum >= (TotalPopulation[Me] - 4) then
     1312        Break; // enough
    13131313      Inc(NewTaxRate, 10);
    13141314    end;
     
    13241324    // research completed
    13251325    for p1 := 0 to nPl - 1 do
    1326       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
    13271327        (RO.EnemyReport[p1].TurnOfCivilReport + TechReportOutdated > RO.Turn) and
    13281328        (RO.EnemyReport[p1].Tech[Data.LastResearchTech] < tsSeen) then
    13291329      begin // latest researched advance might be of interest to this nation
    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;
     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;
    13341334      end;
    13351335  if RO.ResearchTech = adMilitary then
     
    13371337  else
    13381338    Data.LastResearchTech := RO.ResearchTech;
    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;
     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;
    13431343
    13441344  // prepare negotiation
     
    13481348{$IFDEF DEBUG}
    13491349(*for p1:=0 to nPl-1 do
    1350   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)
    13511351    and (RO.EnemyReport[p1].TurnOfCivilReport>=0) then
    13521352    TraceAdvanceValues(p1);*)
     
    13631363
    13641364{$IFDEF DEBUG}
    1365 procedure TAI.TraceAdvanceValues(Nation: integer);
     1365procedure TAI.TraceAdvanceValues(Nation: Integer);
    13661366var
    1367   ad: integer;
     1367  ad: Integer;
    13681368begin
    13691369  for ad := 0 to nAdv - 1 do
     
    13791379procedure TAI.CheckGender;
    13801380var
    1381   p1, NewGender: integer;
     1381  p1, NewGender: Integer;
    13821382begin
    13831383  NewGender := -1;
    13841384  for p1 := 0 to nPl - 1 do
    1385     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
    13861386      (RO.Treaty[p1] >= trFriendlyContact) then
    1387       if PlayerHash[me] > PlayerHash[p1] then
     1387      if PlayerHash[Me] > PlayerHash[p1] then
    13881388      begin
    13891389        if NewGender = bMale then
    13901390        begin
    13911391          NewGender := -2;
    1392           break;
     1392          Break;
    13931393        end; // ambiguous, don't change gender
    13941394        NewGender := bFemale;
     
    13991399        begin
    14001400          NewGender := -2;
    1401           break;
     1401          Break;
    14021402        end; // ambiguous, don't change gender
    14031403        NewGender := bMale;
     
    14121412procedure TAI.SetAdvanceValues;
    14131413
    1414   procedure RateResearchAdv(ad, Time: integer);
     1414  procedure RateResearchAdv(ad, Time: Integer);
    14151415  var
    1416     Value: integer;
     1416    Value: Integer;
    14171417  begin
    14181418    if Time = 0 then
     
    14241424  end;
    14251425
    1426   procedure SetPreqValues(ad, Value: integer);
     1426  procedure SetPreqValues(ad, Value: Integer);
    14271427  begin
    14281428    if (RO.Tech[ad] < tsSeen) and (ad <> RO.ResearchTech) then
     
    14471447  end;
    14481448
    1449   procedure RateImpPreq(iix, Value: integer);
     1449  procedure RateImpPreq(iix, Value: Integer);
    14501450  begin
    14511451    if (Value > 0) and (Imp[iix].Preq >= 0) then
     
    14541454
    14551455var
    1456   emix, cix, adMissing, iad, ad, Count, i, Time, d, CurrentCost,
    1457   CurrentStrength, MaxSize, MaxTrade: integer;
    1458   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;
    14591459begin
    14601460  if AdvanceValuesSet then
    1461     exit;
     1461    Exit;
    14621462  AdvanceValuesSet := True;
    14631463
    1464   fillchar(AdvanceValue, sizeof(AdvanceValue), 0);
     1464  FillChar(AdvanceValue, SizeOf(AdvanceValue), 0);
    14651465
    14661466  // rate techs to ensure research progress
     
    14821482      begin // 2 of 3 required
    14831483        Count := 0;
    1484         for i := 0 to 2 do
    1485           if (AdvPreq[ad, i] = RO.ResearchTech) or
    1486             (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
    14871487            Inc(Count);
    14881488        if Count >= 2 then
     
    14921492          if ad <> adMassProduction then // don't score third preq for MP
    14931493          begin
    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);
     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);
    14981498          end;
    14991499          Inc(Time, 2 - Count);
     
    15031503      begin
    15041504        Count := 0;
    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
     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
    15081508          begin
    1509             RateResearchAdv(AdvPreq[ad, i], Time);
     1509            RateResearchAdv(AdvPreq[ad, I], Time);
    15101510            Inc(Count);
    15111511          end;
     
    15361536
    15371537  // rate military techs
    1538   for d := 0 to nDomains - 1 do
     1538  for D := 0 to nDomains - 1 do
    15391539  begin
    15401540    CurrentCost := 0;
    15411541    CurrentStrength := 0;
    15421542    for PreView := True downto False do
    1543       for i := 0 to nUpgrade - 1 do
    1544         with Upgrade[d, i] do
     1543      for I := 0 to nUpgrade - 1 do
     1544        with Upgrade[D, I] do
    15451545          if (Preq >= 0) and not (Preq in FutureTech) then
    15461546            if ((Ro.ResearchTech = Preq) or (RO.Tech[Preq] >= tsSeen)) = PreView then
     
    15531553              else
    15541554              begin // rate
    1555                 if (i > 0) and (Trans > 0) then
     1555                if (I > 0) and (Trans > 0) then
    15561556                  Inc(AdvanceValue[Preq], $400);
    15571557                if Cost <= CurrentCost then
    1558                   Inc(AdvanceValue[Preq], (4 - d) * Strength * $400 div
    1559                     (CurrentStrength + Upgrade[d, 0].Strength))
     1558                  Inc(AdvanceValue[Preq], (4 - D) * Strength * $400 div
     1559                    (CurrentStrength + Upgrade[D, 0].Strength))
    15601560                else
    1561                   Inc(AdvanceValue[Preq], (4 - d) * Strength * $200 div
    1562                     (CurrentStrength + Upgrade[d, 0].Strength));
     1561                  Inc(AdvanceValue[Preq], (4 - D) * Strength * $200 div
     1562                    (CurrentStrength + Upgrade[D, 0].Strength));
    15631563              end;
    15641564  end;
     
    16401640procedure TAI.AnalyzeMap;
    16411641var
    1642   cix, Loc, Loc1, V8, f1, p1: integer;
     1642  cix, Loc, Loc1, V8, f1, p1: Integer;
    16431643  Adjacent: TVicinity8Loc;
    16441644begin
     
    16461646
    16471647  // collect nation presence information for continents and oceans
    1648   fillchar(ContinentPresence, sizeof(ContinentPresence), 0);
    1649   fillchar(OceanPresence, sizeof(OceanPresence), 0);
     1648  FillChar(ContinentPresence, SizeOf(ContinentPresence), 0);
     1649  FillChar(OceanPresence, SizeOf(OceanPresence), 0);
    16501650  for Loc := 0 to MapSize - 1 do
    16511651  begin
     
    16991699  end;
    17001700
    1701   fillchar(TotalPopulation, sizeof(TotalPopulation), 0);
    1702   fillchar(ContinentPopulation, sizeof(ContinentPopulation), 0);
    1703   fillchar(DistrictPopulation, 4 * nDistrict, 0);
     1701  FillChar(TotalPopulation, SizeOf(TotalPopulation), 0);
     1702  FillChar(ContinentPopulation, SizeOf(ContinentPopulation), 0);
     1703  FillChar(DistrictPopulation, 4 * nDistrict, 0);
    17041704
    17051705  // count population
     
    17161716      if Loc >= 0 then
    17171717      begin
    1718         Inc(TotalPopulation[me], Size);
    1719         assert(District[Loc] >= 0);
     1718        Inc(TotalPopulation[Me], Size);
     1719        Assert(District[Loc] >= 0);
    17201720        if District[Loc] < maxCOD then
    17211721          Inc(DistrictPopulation[District[Loc]], Size);
     
    17251725procedure TAI.CollectModelCatStat;
    17261726var
    1727   i, uix, Cat, mix, Quality: integer;
     1727  I, uix, Cat, mix, Quality: Integer;
    17281728begin
    17291729  // categorize models
     
    17711771        if (Loc >= 0) and (mix = mixCruiser) and (Map[Loc] and fTerrain < fGrass) then
    17721772        begin
    1773           i := Formation[Loc];
    1774           if (i >= 0) and (i < maxCOD) then
    1775             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);
    17761776        end;
    17771777end;
     
    17801780const
    17811781  PatrolDestination = lxmax * lymax;
    1782   FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of integer = (2, 1);
     1782  FirstSurplusLoop: array[mctGroundDefender..mctGroundAttacker] of Integer = (2, 1);
    17831783var
    1784   Cat, i, mix, cix, uix, Loop, nModelOrder: integer;
     1784  Cat, I, mix, cix, uix, Loop, nModelOrder: Integer;
    17851785  Adjacent: TVicinity8Loc;
    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;
     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;
    17931793  var
    1794     Loc1, V8: integer;
     1794    Loc1, V8: Integer;
    17951795    Adjacent: TVicinity8Loc;
    17961796  begin
     
    18091809          begin
    18101810            Result := True;
    1811             exit;
     1811            Exit;
    18121812          end;
    18131813        end;
     
    18151815  end;
    18161816
    1817   procedure TryUtilize(uix: integer);
     1817  procedure TryUtilize(uix: Integer);
    18181818  var
    1819     cix, ProdCost, UtilizeCost: integer;
     1819    cix, ProdCost, UtilizeCost: Integer;
    18201820  begin
    18211821    if (MyUnit[uix].Health = 100) and (Map[MyUnit[uix].Loc] and
     
    18291829          UtilizeCost := MyModel[MyUnit[uix].mix].Cost;
    18301830          if Prod < (ProdCost - UtilizeCost * 2 div 3) *
    1831             BuildCostMod[G.Difficulty[me]] div 12 then
     1831            BuildCostMod[G.Difficulty[Me]] div 12 then
    18321832            Unit_Disband(uix);
    18331833        end;
     
    18351835  end;
    18361836
    1837   procedure FindDestination(uix: integer);
     1837  procedure FindDestination(uix: Integer);
    18381838  var
    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);
     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);
    18431843    Pile.Create(MapSize);
    18441844    with MyUnit[uix] do
     
    18541854        if (District[Loc1] >= 0) and (District[Loc1] < maxCOD) then
    18551855        begin
    1856           assert(DistrictNeed[District[Loc1]] > 0);
     1856          Assert(DistrictNeed[District[Loc1]] > 0);
    18571857          Dec(DistrictNeed[District[Loc1]]);
    18581858        end;
    18591859        Destination[uix] := Loc1;
    1860         break;
     1860        Break;
    18611861      end;
    18621862      Reached[Loc1] := True;
     
    18651865      begin
    18661866        NextLoc := Adjacent[V8];
    1867         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
    18681868          case CheckStep(MoveStyle, Time, V8 and 1, NextTime, RecoverTurns,
    18691869              Map[Loc1], Map[NextLoc], False) of
     
    18731873              Reached[NextLoc] := True; // don't check moving there again
    18741874            csCheckTerritory:
    1875               assert(False);
     1875              Assert(False);
    18761876          end;
    18771877      end;
     
    18871887          Unit_Disband(uix);
    18881888
    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;
     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;
    18941894  for uix := 0 to RO.nUn - 1 do
    18951895    if (MyUnit[uix].mix = mixMilitia) or (MyUnit[uix].mix = mixCruiser) then
     
    19031903      if ModelCat[mix] = Cat then
    19041904      begin
    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;
     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;
    19121912        Inc(nModelOrder);
    19131913      end;
     
    19221922              TryUtilize(uix);
    19231923
    1924       fillchar(LocNeed, MapSize, 0);
    1925       fillchar(DistrictNeed, sizeof(DistrictNeed), 0);
     1924      FillChar(LocNeed, MapSize, 0);
     1925      FillChar(DistrictNeed, SizeOf(DistrictNeed), 0);
    19261926
    19271927      for cix := 0 to RO.nCity - 1 do
     
    19461946        for uix := 0 to RO.nUn - 1 do
    19471947          with MyUnit[uix] do
    1948             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
    19491949            begin
    19501950              LocNeed[Loc] := 1;
     
    19541954
    19551955      complete := Loop >= FirstSurplusLoop[Cat];
    1956       for i := nModelOrder - 1 downto 0 do
     1956      for I := nModelOrder - 1 downto 0 do
    19571957      begin
    19581958        for Fortified := True downto False do
    19591959          for uix := 0 to RO.nUn - 1 do
    19601960            with MyUnit[uix] do
    1961               if (mix = ModelOrder[i]) and (Loc >= 0) and
     1961              if (mix = ModelOrder[I]) and (Loc >= 0) and
    19621962                (Destination[uix] < 0) and (Master < 0) and
    19631963                ((Flags and unFortified <> 0) = Fortified) and (LocNeed[Loc] > 0) then
     
    19721972        for uix := 0 to RO.nUn - 1 do
    19731973          with MyUnit[uix] do
    1974             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
    19751975              (Master < 0) then
    19761976              if (District[Loc] >= 0) and (District[Loc] < maxCOD) and
     
    19891989  // distribute obsolete settlers
    19901990  repeat
    1991     fillchar(LocNeed, MapSize, 0);
    1992     fillchar(DistrictNeed, sizeof(DistrictNeed), 0);
     1991    FillChar(LocNeed, MapSize, 0);
     1992    FillChar(DistrictNeed, SizeOf(DistrictNeed), 0);
    19931993
    19941994    for cix := 0 to RO.nCity - 1 do
     
    20402040  for uix := 0 to RO.nUn - 1 do
    20412041    with MyUnit[uix] do
    2042       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
    20432043        (District[Loc] < maxCOD) and (ModelQuality[mix] > 0) then
    20442044        case ModelCat[mix] of
     
    20482048end;
    20492049
    2050 procedure TAI.CheckAttack(uix: integer);
     2050procedure TAI.CheckAttack(uix: Integer);
    20512051var
    20522052  AttackScore, BestCount, AttackLoc, TestLoc, NextLoc, TestTime, V8,
    20532053  TestScore, euix, MyDamage, EnemyDamage, OldLoc, AttackForecast,
    2054   MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: integer;
    2055   Tile: cardinal;
    2056   Exhausted: boolean;
     2054  MoveResult, AttackResult, MoveStyle, NextTime, RecoverTurns: Integer;
     2055  Tile: Cardinal;
     2056  Exhausted: Boolean;
    20572057  Adjacent: TVicinity8Loc;
    2058   Reached: array[0..lxmax * lymax - 1] of boolean;
     2058  Reached: array[0..lxmax * lymax - 1] of Boolean;
    20592059
    20602060begin
     
    20652065      AttackScore := -999999;
    20662066      AttackLoc := -1;
    2067       fillchar(Reached, MapSize, False);
     2067      FillChar(Reached, MapSize, False);
    20682068      Pile.Create(MapSize);
    20692069      Pile.Put(Loc, $800 - Movement);
     
    20772077        if ((Tile and fUnit) <> 0) and ((Tile and fOwned) = 0) then
    20782078        begin // enemy unit
    2079           assert(TestTime < $1000);
     2079          Assert(TestTime < $1000);
    20802080          Unit_FindEnemyDefender(TestLoc, euix);
    20812081          if RO.Treaty[RO.EnemyUn[euix].Owner] < trPeace then
     
    21682168end;
    21692169
    2170 procedure TAI.Patrol(uix: integer);
     2170procedure TAI.Patrol(uix: Integer);
    21712171const
    21722172  DistanceScore = 4;
    21732173var
    21742174  PatrolScore, BestCount, PatrolLoc, TestLoc, NextLoc, TestTime, V8,
    2175   TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: integer;
    2176   Tile: cardinal;
    2177   Exhausted, CaptureOnly: boolean;
     2175  TestScore, OldLoc, MoveResult, MoveStyle, NextTime, RecoverTurns: Integer;
     2176  Tile: Cardinal;
     2177  Exhausted, CaptureOnly: Boolean;
    21782178  Adjacent: TVicinity8Loc;
    2179   AdjacentUnknown: array[0..lxmax * lymax - 1] of shortint;
     2179  AdjacentUnknown: array[0..lxmax * lymax - 1] of ShortInt;
    21802180
    21812181begin
     
    21962196          // assume a score of 50 is the best achievable
    21972197          or CaptureOnly and (TestTime >= $1000) then
    2198           break;
     2198          Break;
    21992199
    22002200        TestScore := 0;
     
    22762276const
    22772277  nAttackCatOrder = 3;
    2278   AttackCatOrder: array[0..nAttackCatOrder - 1] of integer =
     2278  AttackCatOrder: array[0..nAttackCatOrder - 1] of Integer =
    22792279    (mctGroundAttacker, mctCruiser, mctGroundDefender);
    22802280var
    2281   iCat, uix, uix1: integer;
    2282   IsPatrolUnit, Fortified: boolean;
     2281  iCat, uix, uix1: Integer;
     2282  IsPatrolUnit, Fortified: Boolean;
    22832283begin
    22842284  for uix := 0 to RO.nUn - 1 do
     
    22992299              CheckAttack(uix);
    23002300
    2301   fillchar(uixPatrol, sizeof(uixPatrol), $FF);
     2301  FillChar(uixPatrol, SizeOf(uixPatrol), $FF);
    23022302  for uix := 0 to RO.nUn - 1 do
    23032303    with MyUnit[uix], MyModel[mix] do
     
    23332333end;
    23342334
    2335 function TAI.HavePort: boolean;
     2335function TAI.HavePort: Boolean;
    23362336var
    2337   V8, cix, AdjacentLoc, f: integer;
     2337  V8, cix, AdjacentLoc, F: Integer;
    23382338  Adjacent: TVicinity8Loc;
    23392339begin
     
    23492349          if (AdjacentLoc >= 0) and ((Map[AdjacentLoc] and fTerrain) < fGrass) then
    23502350          begin
    2351             f := Formation[AdjacentLoc];
    2352             if (f >= 0) and (f < maxCOD) and (OceanPresence[f] and
    2353               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
    23542354              Result := True;
    23552355          end;
     
    23612361var
    23622362  uix, cix, iix, dtr, V8, V21, NewImprovement, AdjacentLoc, MaxSettlers,
    2363   maxcount, cixMilAcademy: integer;
    2364   TerrType: cardinal;
     2363  maxcount, cixMilAcademy: Integer;
     2364  TerrType: Cardinal;
    23652365  IsPort, IsNavalBase, NeedCruiser, CheckProd, Destructed, ProduceSettlers,
    2366   ProduceMil: boolean;
     2366  ProduceMil: Boolean;
    23672367  Adjacent: TVicinity8Loc;
    23682368  Radius: TVicinity21Loc;
    23692369  Report: TCityReport;
    2370   HomeCount, CityProdRep: array[0..nCmax - 1] of integer;
    2371   MilProdCity: array[0..nCmax - 1] of boolean;
    2372 
    2373   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);
    23742374  begin
    23752375    if (NewImprovement = imTrGoods) // not already improvement of higher priority found
     
    23812381  end;
    23822382
    2383   procedure TryDestruct(Improvement: integer);
     2383  procedure TryDestruct(Improvement: Integer);
    23842384  begin
    23852385    if Destructed or (MyCity[cix].Built[Improvement] = 0) then
    2386       exit;
     2386      Exit;
    23872387    if City_CurrentImprovementProject(cix) >= 0 then
    23882388      City_RebuildImprovement(cix, Improvement)
     
    23922392      and (Imp[CurrentImprovementProject].Kind in [ikCommon,ikNatGlobal,ikNatLocal])
    23932393      and ((Imp[CurrentImprovementProject].Cost*3-Imp[Improvement].Cost*2)
    2394       *BuildCostMod[G.Difficulty[me]]>MyCity[cix].Prod*(12*3)) then}
     2394      *BuildCostMod[G.Difficulty[Me]]>MyCity[cix].Prod*(12*3)) then}
    23952395    Destructed := True;
    23962396  end;
    23972397
    2398   function ChooseBuildModel(Cat: integer): integer;
     2398  function ChooseBuildModel(Cat: Integer): Integer;
    23992399  var
    2400     Count, mix: integer;
     2400    Count, mix: Integer;
    24012401  begin
    24022402    Count := 0;
     
    24092409          Result := mix;
    24102410      end;
    2411     assert(Count > 0);
     2411    Assert(Count > 0);
    24122412  end;
    24132413
     
    24152415  // find military production cities
    24162416  var
    2417     cix, Total, d, Threshold, NewThreshold, Share, SharePlus, cixWorst: integer;
    2418   begin
    2419     fillchar(MilProdCity, RO.nCity, 0);
     2417    cix, Total, D, Threshold, NewThreshold, Share, SharePlus, cixWorst: Integer;
     2418  begin
     2419    FillChar(MilProdCity, RO.nCity, 0);
    24202420    GetCityProdPotential;
    2421     for d := 0 to maxCOD - 1 do
     2421    for D := 0 to maxCOD - 1 do
    24222422    begin
    24232423      Total := 0;
    24242424      for cix := 0 to RO.nCity - 1 do
    24252425        with MyCity[cix] do
    2426           if (Loc >= 0) and (District[Loc] = d) then
     2426          if (Loc >= 0) and (District[Loc] = D) then
    24272427            Total := Total + CityResult[cix];
    24282428      if Total = 0 then
     
    24332433      for cix := 0 to RO.nCity - 1 do
    24342434        with MyCity[cix] do
    2435           if (Loc >= 0) and (District[Loc] = d) and
     2435          if (Loc >= 0) and (District[Loc] = D) and
    24362436            (Built[imBarracks] + Built[imMilAcademy] > 0) then
    24372437          begin
     
    24482448        for cix := 0 to RO.nCity - 1 do
    24492449          with MyCity[cix] do
    2450             if (Loc >= 0) and (District[Loc] = d) and
     2450            if (Loc >= 0) and (District[Loc] = D) and
    24512451              (Built[imBarracks] + Built[imMilAcademy] = 0) and
    24522452              (Built[imObservatory] = 0) and (CityResult[cix] < Threshold) and
     
    24652465      for cix := 0 to RO.nCity - 1 do
    24662466        with MyCity[cix] do
    2467           if (Loc >= 0) and (District[Loc] = d) and
     2467          if (Loc >= 0) and (District[Loc] = D) and
    24682468            (Built[imBarracks] + Built[imMilAcademy] = 0) and
    24692469            (CityResult[cix] >= Threshold) then
     
    24712471{    if (cixWorst>=0)
    24722472      and (Share-CityResult[cixWorst]*2>=Total*MilProdShare div 100) then
    2473       MilProdCity[cixWorst]:=false;}
     2473      MilProdCity[cixWorst]:=False;}
    24742474    end;
    24752475
     
    24782478    if cixStateImp[imPalace] >= 0 then
    24792479    begin
    2480       d := District[MyCity[cixStateImp[imPalace]].Loc];
    2481       if (d >= 0) and (d < maxCOD) then
     2480      D := District[MyCity[cixStateImp[imPalace]].Loc];
     2481      if (D >= 0) and (D < maxCOD) then
    24822482      begin
    24832483        cixMilAcademy := -1;
    24842484        for cix := 0 to RO.nCity - 1 do
    24852485          with MyCity[cix] do
    2486             if (Loc >= 0) and (District[Loc] = d) and
     2486            if (Loc >= 0) and (District[Loc] = D) and
    24872487              (Built[imObservatory] + Built[imPalace] = 0) and
    24882488              ((cixMilAcademy < 0) or (CityResult[cix] > CityResult[cixMilAcademy])) then
     
    25002500  procedure ChangeHomeCities;
    25012501  var
    2502     uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: integer;
     2502    uix, NewHome, HomeSupport, NewHomeSupport, SingleSupport: Integer;
    25032503  begin
    25042504    if RO.Government in [gAnarchy, gFundamentalism] then
    2505       exit;
     2505      Exit;
    25062506    for uix := 0 to RO.nUn - 1 do
    25072507      with MyUnit[uix] do
     
    25512551
    25522552begin
    2553   fillchar(HomeCount, 4 * RO.nCity, 0);
     2553  FillChar(HomeCount, 4 * RO.nCity, 0);
    25542554  for uix := 0 to RO.nUn - 1 do
    25552555    with MyUnit[uix] do
     
    27442744                    begin
    27452745                      TryBuild(imHarbor);
    2746                       break;
     2746                      Break;
    27472747                    end;
    27482748                  end;
     
    27622762              TryBuild(imRecycling);
    27632763            if (Report.Trade - Report.Corruption >= 11) and
    2764               (RO.Money < TotalPopulation[me] * 2) then
     2764              (RO.Money < TotalPopulation[Me] * 2) then
    27652765              TryBuild(imBank);
    27662766            if (RO.NatBuilt[imStockEx] = 0) and
     
    27992799
    28002800          // rebuild imps no longer needed
    2801           if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[me] * 4) then
     2801          if (RO.TaxRate = 0) and (RO.Money >= TotalPopulation[Me] * 4) then
    28022802            TryDestruct(imBank)
    28032803          else if Report.Happy * 2 >= Size + 6 then
     
    28252825end;
    28262826
    2827 function TAI.ChooseGovernment: integer;
     2827function TAI.ChooseGovernment: Integer;
    28282828begin
    28292829  if Data.BehaviorFlags and bBarbarina <> 0 then
     
    28462846//-------------------------------
    28472847
    2848 function TAI.MostWanted(Nation, adGiveAway: integer): integer;
     2848function TAI.MostWanted(Nation, adGiveAway: Integer): Integer;
    28492849var
    2850   ad: integer;
     2850  ad: Integer;
    28512851begin
    28522852  Result := -1;
     
    28762876end;
    28772877
    2878 procedure TAI.FindBestTrade(Nation: integer; var adWanted, adGiveAway: integer);
     2878procedure TAI.FindBestTrade(Nation: Integer; var adWanted, adGiveAway: Integer);
    28792879var
    2880   i, ad, ead, adTestGiveAway: integer;
     2880  I, ad, ead, adTestGiveAway: Integer;
    28812881begin
    28822882  adWanted := -1;
     
    28882888    begin
    28892889      adTestGiveAway := -1;
    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
     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
    28932893          adTestGiveAway := -2; // already requested before
    28942894      if adTestGiveAway = -1 then
     
    29132913end;
    29142914
    2915 function TAI.WantNegotiation(Nation: integer; NegoTime: TNegoTime): boolean;
     2915function TAI.WantNegotiation(Nation: Integer; NegoTime: TNegoTime): Boolean;
    29162916var
    2917   p1, Count, adWanted, adGiveAway: integer;
     2917  p1, Count, adWanted, adGiveAway: Integer;
    29182918begin
    29192919  if Data.BehaviorFlags and bBarbarina = bBarbarina then
    29202920  begin
    29212921    Result := Barbarina_WantNegotiation(Nation, NegoTime);
    2922     exit;
     2922    Exit;
    29232923  end;
    29242924
     
    29282928    begin
    29292929      Result := False;
    2930       exit;
     2930      Exit;
    29312931    end;
    29322932    Count := 0;
    29332933    for p1 := 0 to nPl - 1 do
    2934       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
    29352935        Inc(Count);
    29362936    if Count >= 3 then // enough peace made
    29372937    begin
    29382938      Result := False;
    2939       exit;
     2939      Exit;
    29402940    end;
    29412941  end;
     
    29782978procedure TAI.DoNegotiation;
    29792979var
    2980   i, adWanted, adGiveAway, adToGet, Slot: integer;
    2981   BuildFreeOffer: boolean;
     2980  I, adWanted, adGiveAway, adToGet, Slot: Integer;
     2981  BuildFreeOffer: Boolean;
    29822982begin
    29832983  if MyLastAction = scDipOffer then
     
    30103010  begin
    30113011    Barbarina_DoNegotiation;
    3012     exit;
     3012    Exit;
    30133013  end;
    30143014
     
    30163016  begin
    30173017    Barbarina_DoCheckNegotiation;
    3018     exit;
     3018    Exit;
    30193019  end;
    30203020
     
    30313031      (OppoOffer.nDeliver + OppoOffer.nCost = 1) and
    30323032      (OppoOffer.Price[0] and opMask = opTreaty) and
    3033       (integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and
     3033      (Integer(OppoOffer.Price[0] - opTreaty) > RO.Treaty[Opponent]) and
    30343034      ((OppoOffer.Price[0] - opTreaty < trAlliance) or
    30353035      (RO.Tech[adScience] >= tsSeen)) then
    30363036      MyAction := scDipAccept // accept all treaties
    30373037    else if (RO.Treaty[Opponent] >= trPeace) and (OppoOffer.nDeliver = 1) and
    3038       (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + cardinal(Opponent) shl 16) and
     3038      (OppoOffer.Price[0] and $FFFF0000 = opCivilReport + Cardinal(Opponent) shl 16) and
    30393039      (OppoOffer.nCost = 1) and (OppoOffer.Price[1] and $FFFF0000 =
    3040       opCivilReport + cardinal(me) shl 16) then
     3040      opCivilReport + Cardinal(Me) shl 16) then
    30413041      MyAction := scDipAccept // accept exchange of civil reports
    30423042    else if (OppoOffer.nDeliver = 1) and (OppoOffer.nCost = 1) and
     
    30683068        adWanted := MostWanted(Opponent, OppoOffer.Price[1] - opTech);
    30693069        if (OppoOffer.Price[0] and opMask = opTech) and
    3070           (cardinal(adWanted) = OppoOffer.Price[0] - opTech) then
     3070          (Cardinal(adWanted) = OppoOffer.Price[0] - opTech) then
    30713071          MyAction := scDipAccept // opponent's offer is already perfect
    30723072        else if adWanted >= 0 then
     
    31243124        MyOffer.Price[1] := opTech + adWanted;
    31253125        MyAction := scDipOffer;
    3126         for i := 0 to nRequestedTechs - 1 do
    3127           if Data.RequestedTechs[i] < 0 then
     3126        for I := 0 to nRequestedTechs - 1 do
     3127          if Data.RequestedTechs[I] < 0 then
    31283128          begin
    3129             Slot := i;
    3130             break;
     3129            Slot := I;
     3130            Break;
    31313131          end
    3132           else if (i = 0) or (Data.RequestedTechs[i] shr 16 <
     3132          else if (I = 0) or (Data.RequestedTechs[I] shr 16 <
    31333133            Data.RequestedTechs[Slot] shr 16) then // find most outdated entry
    3134             Slot := i;
     3134            Slot := I;
    31353135        Data.RequestedTechs[Slot] := RO.Turn shl 16 + Opponent shl 8 + adWanted;
    31363136      end;
     
    31413141procedure SetLeaveOutValue;
    31423142
    3143   procedure Process(ad: integer);
     3143  procedure Process(ad: Integer);
    31443144  var
    3145     i: integer;
     3145    I: Integer;
    31463146  begin
    31473147    if LeaveOutValue[ad] < 0 then
    31483148    begin
    31493149      LeaveOutValue[ad] := 0;
    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);
     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);
    31563156        end;
    31573157    end;
     
    31593159
    31603160var
    3161   ad: integer;
     3161  ad: Integer;
    31623162begin
    31633163  FillChar(LeaveOutValue, SizeOf(LeaveOutValue), $FF);
     
    31683168
    31693169initialization
    3170   RWDataSize := sizeof(TPersistentData);
     3170  RWDataSize := SizeOf(TPersistentData);
    31713171  SetLeaveOutValue;
    31723172
  • trunk/AI/StdAI/Barbarina.pas

    r442 r447  
    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
     
    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;
     
    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;
  • trunk/AI/StdAI/CustomAI.pas

    r289 r447  
    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
  • trunk/AI/StdAI/CustomAI_Reload.pas

    r160 r447  
    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
  • trunk/AI/StdAI/Pile.pas

    r289 r447  
    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}
  • trunk/AI/StdAI/Protocol.pas

    r328 r447  
    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;
  • trunk/AI/StdAI/StdAI.lpr

    r289 r447  
    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:
  • trunk/AI/StdAI/ToolAI.pas

    r442 r447  
    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;
     105    function CurrentMStrength(Domain: Integer): Integer;
    106106  end;
    107107
     
    132132
    133133var
    134   nContinent, nOcean, nDistrict: integer;
    135   Formation: array[0..lxmax * lymax - 1] of integer;
     134  nContinent, nOcean, nDistrict: Integer;
     135  Formation: array[0..lxmax * lymax - 1] of Integer;
    136136  // water: ocean index, land: continent index, sorted by size
    137137  // territory unpassable due to peace treaty divides a continent
    138   District: array[0..lxmax * lymax - 1] of integer;
     138  District: array[0..lxmax * lymax - 1] of Integer;
    139139  // index of coherent own territory, sorted by size
    140   CityResult: array[0..nCmax - 1] of integer;
    141 
    142   Advancedness: array[0..nAdv - 1] of integer;
     140  CityResult: array[0..nCmax - 1] of Integer;
     141
     142  Advancedness: array[0..nAdv - 1] of Integer;
    143143// total number of prerequisites for each advance
    144144
     
    149149
    150150type
    151   pinteger = ^integer;
     151  pinteger = ^Integer;
    152152
    153153var
    154154  // for JobAssignment
    155   MaxScore: integer;
    156   TileJob, TileJobScore: array[0..lxmax * lymax - 1] of byte;
    157   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
    158158
    159159  // for Transport
    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 
    165 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);
    166166begin
    167167  while Start <> Stop do
     
    173173end;
    174174
    175 function NextZero(Start, Stop: pinteger; Mask: cardinal): pinteger;
     175function NextZero(Start, Stop: pinteger; Mask: Cardinal): pinteger;
    176176begin
    177177  while (Start <> Stop) and (Start^ and Mask <> 0) do
     
    180180end;
    181181
    182 function TToolAI.CenterOfEmpire: integer;
    183 var
    184   cix, Loc, x, y, sy, n: integer;
    185   a, su, sv: double;
    186 begin
    187   n := 0;
     182function TToolAI.CenterOfEmpire: Integer;
     183var
     184  cix, Loc, X, Y, sy, N: Integer;
     185  A, su, sv: Double;
     186begin
     187  N := 0;
    188188  sy := 0;
    189189  su := 0;
     
    194194    if Loc >= 0 then
    195195    begin
    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;
    212 end;
    213 
    214 function TToolAI.CityTaxBalance(cix: integer; const CityReport: TCityReport): integer;
    215 var
    216   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;
    217217begin
    218218  Result := 0;
     
    229229      Inc(Result, CityReport.FoodRep - CityReport.Eaten);
    230230  end;
    231   for i := nWonder to nImp - 1 do
    232     if MyCity[cix].Built[i] > 0 then
    233       Dec(Result, Imp[i].Maint);
    234 end;
    235 
    236 procedure TToolAI.SumCities(TaxRate: integer; var TaxSum, ScienceSum: integer);
    237 var
    238   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;
    239239  CityReport: TCityReport;
    240240begin
     
    242242  ScienceSum := 0;
    243243  if RO.Government = gAnarchy then
    244     exit;
     244    Exit;
    245245  for p1 := 0 to nPl - 1 do
    246246    if RO.Tribute[p1] <= RO.TributePaid[p1] then
     
    268268procedure TToolAI.OptimizeCityTiles;
    269269var
    270   cix: integer;
     270  cix: Integer;
    271271begin
    272272  for cix := 0 to RO.nCity - 1 do
     
    278278procedure TToolAI.GetCityProdPotential;
    279279var
    280   cix: integer;
     280  cix: Integer;
    281281  Advice: TCityTileAdviceData;
    282282begin
     
    286286      begin
    287287        Advice.ResourceWeights := rwMaxProd;
    288         Server(sGetCityTileAdvice, me, cix, Advice);
     288        Server(sGetCityTileAdvice, Me, cix, Advice);
    289289        CityResult[cix] := Advice.CityReport.ProdRep; // considers factory, but shouldn't
    290290      end;
     
    293293procedure TToolAI.GetCityTradePotential;
    294294var
    295   cix: integer;
     295  cix: Integer;
    296296  Advice: TCityTileAdviceData;
    297297begin
     
    301301      begin
    302302        Advice.ResourceWeights := rwMaxScience;
    303         Server(sGetCityTileAdvice, me, cix, Advice);
     303        Server(sGetCityTileAdvice, Me, cix, Advice);
    304304        CityResult[cix] := Advice.CityReport.Trade;
    305305      end;
     
    314314procedure TToolAI.JobAssignment_Initialize;
    315315begin
    316   fillchar(JobLocOfSettler, RO.nUn * sizeof(integer), $FF); // -1
    317   fillchar(TileJob, MapSize, jNone);
    318   fillchar(TileJobScore, MapSize, 0);
     316  FillChar(JobLocOfSettler, RO.nUn * SizeOf(Integer), $FF); // -1
     317  FillChar(TileJob, MapSize, jNone);
     318  FillChar(TileJobScore, MapSize, 0);
    319319  MaxScore := 0;
    320320end;
    321321
    322 procedure TToolAI.JobAssignment_AddJob(Loc, Job, Score: integer);
     322procedure TToolAI.JobAssignment_AddJob(Loc, Job, Score: Integer);
    323323begin
    324324  if Score > 255 then
     
    333333end;
    334334
    335 procedure TToolAI.JobAssignment_AddUnit(uix: integer);
    336 begin
    337   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]);
    338338  JobLocOfSettler[uix] := ToAssign;
    339339end;
    340340
    341 function TToolAI.JobAssignment_GotJob(uix: integer): boolean;
     341function TToolAI.JobAssignment_GotJob(uix: Integer): Boolean;
    342342begin
    343343  Result := JobLocOfSettler[uix] >= 0;
     
    347347const
    348348  DistanceScore = 4;
    349   StepSizeByTerrain: array[0..11] of integer =
     349  StepSizeByTerrain: array[0..11] of Integer =
    350350    (0, 0, 1, 2, 1, 1, 0, 1, 0, 1, 1, 2);
    351351  //Oc-Sh-Gr-De-Pr-Tu-Ar-Sw-XX-Fo-Hi-Mo
    352352var
    353353  uix, BestScore, BestCount, BestLoc, BestJob, BestDistance, TestLoc,
    354   NextLoc, TestDistance, V8, TestScore, StepSize, MoveResult: integer;
    355   UnitsToAssign: boolean;
     354  NextLoc, TestDistance, V8, TestScore, StepSize, MoveResult: Integer;
     355  UnitsToAssign: Boolean;
    356356  Adjacent: TVicinity8Loc;
    357357  SettlerOfJobLoc, DistToLoc: array[0..lxmax * lymax - 1] of smallint;
    358358  // DistToLoc is only defined where SettlerOfJobLoc>=0
    359   TileChecked: array[0..lxmax * lymax - 1] of boolean;
    360 begin
    361   fillchar(SettlerOfJobLoc, MapSize * 2, $FF); // -1
     359  TileChecked: array[0..lxmax * lymax - 1] of Boolean;
     360begin
     361  FillChar(SettlerOfJobLoc, MapSize * 2, $FF); // -1
    362362
    363363  // keep up jobs that are already started
     
    380380        BestJob := jNone;
    381381        BestScore := -999999;
    382         FillChar(TileChecked, MapSize * sizeof(boolean), False);
     382        FillChar(TileChecked, MapSize * SizeOf(Boolean), False);
    383383        Pile.Create(MapSize);
    384384        Pile.Put(MyUnit[uix].Loc, 0); // start search for new job at current location
     
    399399                  and (Map[NextLoc] and (fUnit or fOwned) <> fUnit) // no foreign unit
    400400                  and ((RO.Territory[NextLoc] < 0) or
    401                   (RO.Territory[NextLoc] = me)) // no foreign territory
     401                  (RO.Territory[NextLoc] = Me)) // no foreign territory
    402402                  and (Map[TestLoc] and Map[NextLoc] and fInEnemyZoC = 0) then
    403403                  // move not prevented by ZoC
     
    414414            ((SettlerOfJobLoc[TestLoc] < 0) or (DistToLoc[TestLoc] > TestDistance)) then
    415415          begin
    416             TestScore := integer(TileJobScore[TestLoc]) - DistanceScore * TestDistance;
     416            TestScore := Integer(TileJobScore[TestLoc]) - DistanceScore * TestDistance;
    417417            if TestScore > BestScore then
    418418              BestCount := 0;
     
    469469procedure TToolAI.AnalyzeMap;
    470470var
    471   i, j, Loc, Loc1, V8, Count, Kind, MostIndex: integer;
     471  I, J, Loc, Loc1, V8, Count, Kind, MostIndex: Integer;
    472472  Adjacent: TVicinity8Loc;
    473473  IndexOfID: array[0..lxmax * lymax - 1] of smallint;
    474474  IDOfIndex: array[0..lxmax * lymax div 2 - 1] of smallint;
    475475begin
    476   fillchar(District, MapSize * 4, $FF);
     476  FillChar(District, MapSize * 4, $FF);
    477477  for Loc := 0 to MapSize - 1 do
    478478    if Map[Loc] and fTerrain = fUNKNOWN then
     
    500500              Formation[Loc], Formation[Loc1]);
    501501      end;
    502       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
    503503      begin
    504504        District[Loc] := Loc;
     
    545545        Inc(Count);
    546546      end;
    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;
     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;
    562562
    563563    case Kind of
     
    605605// other:  |   Basic   | 0| Speed  |              X X X             | MaxTerrType  |
    606606
    607 function TToolAI.GetMyMoveStyle(mix, Health: integer): integer;
     607function TToolAI.GetMyMoveStyle(mix, Health: Integer): Integer;
    608608begin
    609609  with MyModel[mix] do
     
    614614      begin
    615615        Inc(Result, (50 + (Speed - 150) * 13 shr 7) shl 8); //HeavyCost
    616         if RO.Wonder[woShinkansen].EffectiveOwner <> me then
     616        if RO.Wonder[woShinkansen].EffectiveOwner <> Me then
    617617          Inc(Result, Speed * (4 * 1311) shr 17); // RailCost
    618         if (RO.Wonder[woGardens].EffectiveOwner <> me) or
     618        if (RO.Wonder[woGardens].EffectiveOwner <> Me) or
    619619          (Kind = mkSettler) and (Speed >= 200) then
    620620          Inc(Result, msHostile);
     
    631631      begin
    632632        Result := Speed;
    633         if RO.Wonder[woMagellan].EffectiveOwner = me then
     633        if RO.Wonder[woMagellan].EffectiveOwner = Me then
    634634          Inc(Result, 200);
    635635        if Health < 100 then
     
    646646end;
    647647
    648 function TToolAI.CheckStep(MoveStyle, TimeBeforeStep, CrossCorner: integer;
    649   var TimeAfterStep, RecoverTurns: integer; FromTile, ToTile: integer;
    650   IsCapture: boolean): integer;
    651 var
    652   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;
    653653begin
    654654  //IsCapture:=true;
    655   assert(((FromTile and fTerrain <= fMountains) or (FromTile and
     655  Assert(((FromTile and fTerrain <= fMountains) or (FromTile and
    656656    fTerrain = fUNKNOWN)) and ((ToTile and fTerrain <= fMountains) or
    657657    (ToTile and fTerrain = fUNKNOWN)));
     
    701701                if ToTile and fPeace <> 0 then
    702702                  Result := csCheckTerritory;
    703                 exit;
     703                Exit;
    704704              end;
    705705            end;
     
    820820          begin
    821821            Result := csForbiddenTile;
    822             exit;
     822            Exit;
    823823          end;
    824824        end
     
    869869              // must wait for next turn
    870870              Result := csOk;
    871               exit;
     871              Exit;
    872872            end;
    873873          end;
     
    894894-------- Pathfinding Reference Implementation --------
    895895var
    896 MoveStyle,V8,Loc,Time,NextLoc,NextTime,RecoverTurns: integer;
     896MoveStyle,V8,Loc,Time,NextLoc,NextTime,RecoverTurns: Integer;
    897897Adjacent: TVicinity8Loc;
    898 Reached: array[0..lxmax*lymax-1] of boolean;
    899 begin
    900 fillchar(Reached, MapSize, false);
     898Reached: array[0..lxmax*lymax-1] of Boolean;
     899begin
     900FillChar(Reached, MapSize, False);
    901901MoveStyle:=GetMyMoveStyle(MyUnit[uix].mix, MyUnit[uix].Health);
    902902Pile.Create(MapSize);
     
    906906  // todo: check exit condition, e.g. whether destination reached
    907907
    908   Reached[Loc]:=true;
     908  Reached[Loc]:=True;
    909909  V8_to_Loc(Loc, Adjacent);
    910910  for V8:=0 to 7 do
     
    916916          Pile.Put(NextLoc, NextTime+RecoverTurns*$1000);
    917917        csForbiddenTile:
    918           Reached[NextLoc]:=true; // don't check moving there again
     918          Reached[NextLoc]:=True; // don't check moving there again
    919919        csCheckTerritory:
    920920          if RO.Territory[NextLoc]=RO.Territory[Loc] then
     
    927927*)
    928928
    929 function TToolAI.Unit_MoveEx(uix, ToLoc: integer; Options: integer): integer;
     929function TToolAI.Unit_MoveEx(uix, ToLoc: Integer; Options: Integer): Integer;
    930930var
    931931  Loc, NextLoc, Temp, FromLoc, EndLoc, Time, V8, MoveResult, RecoverTurns,
    932   NextTime, MoveStyle: integer;
     932  NextTime, MoveStyle: Integer;
    933933  Adjacent: TVicinity8Loc;
    934   PreLoc: array[0..lxmax * lymax - 1] of integer;
    935   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;
    936936begin
    937937  Result := eOk;
    938938  FromLoc := MyUnit[uix].Loc;
    939939  if FromLoc = ToLoc then
    940     exit;
     940    Exit;
    941941
    942942  FillChar(Reached, MapSize, False);
     
    10031003      begin
    10041004        Result := MoveResult;
    1005         break;
     1005        Break;
    10061006      end;
    10071007    end;
     
    10161016procedure TToolAI.SeaTransport_BeginInitialize;
    10171017begin
    1018   fillchar(TransportAvailable, RO.nUn * sizeof(integer), $FF); // -1
     1018  FillChar(TransportAvailable, RO.nUn * SizeOf(Integer), $FF); // -1
    10191019  InitComplete := False;
    10201020  HaveDestinations := False;
     
    10251025end;
    10261026
    1027 procedure TToolAI.SeaTransport_AddLoad(uix: integer);
    1028 var
    1029   i: integer;
    1030 begin
    1031   assert(not InitComplete); // call order violation!
     1027procedure TToolAI.SeaTransport_AddLoad(uix: Integer);
     1028var
     1029  I: Integer;
     1030begin
     1031  Assert(not InitComplete); // call order violation!
    10321032  if Map[MyUnit[uix].Loc] and fTerrain < fGrass then
    1033     exit;
    1034   for i := 0 to nTransportLoad - 1 do
    1035     if uix = uixTransportLoad[i] then
    1036       exit;
     1033    Exit;
     1034  for I := 0 to nTransportLoad - 1 do
     1035    if uix = uixTransportLoad[I] then
     1036      Exit;
    10371037  uixTransportLoad[nTransportLoad] := uix;
    10381038  Inc(nTransportLoad);
    10391039end;
    10401040
    1041 procedure TToolAI.SeaTransport_AddTransport(uix: integer);
    1042 var
    1043   MoveStyle: integer;
    1044 begin
    1045   assert(not InitComplete); // call order violation!
    1046   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);
    10471047  TransportAvailable[uix] := 1;
    10481048  with MyModel[MyUnit[uix].mix] do
     
    10581058end;
    10591059
    1060 procedure TToolAI.SeaTransport_AddDestination(Loc: integer);
    1061 begin
    1062   assert(not InitComplete); // call order violation!
     1060procedure TToolAI.SeaTransport_AddDestination(Loc: Integer);
     1061begin
     1062  Assert(not InitComplete); // call order violation!
    10631063  Pile.Put(Loc, $800);
    10641064  HaveDestinations := True;
     
    10671067procedure TToolAI.SeaTransport_EndInitialize;
    10681068var
    1069   Loc0, Time0, V8, Loc1, ArriveTime, RecoverTurns: integer;
     1069  Loc0, Time0, V8, Loc1, ArriveTime, RecoverTurns: Integer;
    10701070  Adjacent: TVicinity8Loc;
    10711071begin
    1072   assert(not InitComplete); // call order violation!
     1072  Assert(not InitComplete); // call order violation!
    10731073  InitComplete := True;
    10741074  if HaveDestinations then
    10751075  begin // calculate TurnsAfterLoad from destination locs
    1076     fillchar(TurnsAfterLoad, MapSize, $FF); // -1
     1076    FillChar(TurnsAfterLoad, MapSize, $FF); // -1
    10771077    while Pile.Get(Loc0, Time0) do
    10781078    begin // search backward
     
    11001100
    11011101function TToolAI.SeaTransport_MakeGroupPlan(
    1102   var TransportPlan: TGroupTransportPlan): boolean;
    1103 var
    1104   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,
    11051105  TurnsLoaded, TurnCount, tuix, tuix1, ArriveTime, TotalDelay,
    11061106  BestTotalDelay, GroupCount, BestGroupCount, BestLoadLoc, FullMovementLoc,
    1107   nSelectedLoad, f, OriginContinent, a, b: integer;
    1108   CompleteFlag, NotReachedFlag, ContinueUnit: cardinal;
    1109   IsComplete, ok, IsFirstLoc: boolean;
     1107  nSelectedLoad, F, OriginContinent, A, B: Integer;
     1108  CompleteFlag, NotReachedFlag, ContinueUnit: Cardinal;
     1109  IsComplete, ok, IsFirstLoc: Boolean;
    11101110  StartLocPtr, ArrivedEnd: pinteger;
    11111111  Adjacent: TVicinity8Loc;
    1112   uixSelectedLoad: array[0..15] of integer;
    1113   tuixSelectedLoad: array[0..15] of integer;
    1114   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;
    11151115  ResponsibleTransport: array[0..lxmax * lymax - 1] of smallint;
    1116   TurnsBeforeLoad: array[0..lxmax * lymax - 1] of shortint;
    1117   GroupComplete: array[0..lxmax * lymax - 1] of boolean;
    1118 begin
    1119   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!
    11201120
    11211121  if HaveDestinations and (nTransportLoad > 0) then
     
    11281128        for tuix := 0 to nTransportLoad - 1 do
    11291129        begin
    1130           Loc_to_ab(MyUnit[uix].Loc, MyUnit[uixTransportLoad[tuix]].Loc, a, b);
    1131           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
    11321132          begin
    1133             assert((a <> 0) or (b <> 0));
     1133            Assert((A <> 0) or (B <> 0));
    11341134            Inc(GroupCount);
    11351135          end;
     
    11451145          for tuix := nTransportLoad - 1 downto 0 do
    11461146          begin
    1147             Loc_to_ab(TransportPlan.LoadLoc, MyUnit[uixTransportLoad[tuix]].Loc, a, b);
    1148             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
    11491149            begin
    11501150              TransportPlan.uixLoad[TransportPlan.nLoad] := uixTransportLoad[tuix];
     
    11531153              Inc(TransportPlan.nLoad);
    11541154              if TransportPlan.nLoad = TransportCapacity then
    1155                 break;
     1155                Break;
    11561156            end;
    11571157          end;
    11581158          Result := True;
    1159           exit;
     1159          Exit;
    11601160        end;
    11611161      end;
     
    11651165  begin
    11661166    // select units from same continent
    1167     fillchar(Arrived, 4 * nContinent, 0); // misuse Arrived as counter
     1167    FillChar(Arrived, 4 * nContinent, 0); // misuse Arrived as counter
    11681168    for tuix := 0 to nTransportLoad - 1 do
    11691169    begin
    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]);
     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]);
    11741174    end;
    11751175    OriginContinent := 0;
    1176     for f := 1 to nContinent - 1 do
    1177       if Arrived[f] > Arrived[OriginContinent] then
    1178         OriginContinent := f;
     1176    for F := 1 to nContinent - 1 do
     1177      if Arrived[F] > Arrived[OriginContinent] then
     1178        OriginContinent := F;
    11791179    nSelectedLoad := 0;
    11801180    for tuix := 0 to nTransportLoad - 1 do
     
    11851185        Inc(nSelectedLoad);
    11861186        if nSelectedLoad = 16 then
    1187           break;
     1187          Break;
    11881188      end;
    11891189
    11901190    Pile.Create(MapSize);
    1191     fillchar(ResponsibleTransport, MapSize * 2, $FF); // -1
    1192     fillchar(TurnsBeforeLoad, MapSize, $FF); // -1
     1191    FillChar(ResponsibleTransport, MapSize * 2, $FF); // -1
     1192    FillChar(TurnsBeforeLoad, MapSize, $FF); // -1
    11931193    ok := False;
    11941194    for uix := 0 to RO.nUn - 1 do
     
    12031203      Result := False;
    12041204      Pile.Free;
    1205       exit;
     1205      Exit;
    12061206    end;
    12071207    while Pile.Get(Loc0, Time0) do
     
    12241224    end;
    12251225
    1226     fillchar(Arrived, MapSize * 4, $55); // set NotReachedFlag for all tiles
    1227     fillchar(GroupComplete, MapSize, False);
     1226    FillChar(Arrived, MapSize * 4, $55); // set NotReachedFlag for all tiles
     1227    FillChar(GroupComplete, MapSize, False);
    12281228    BestLoadLoc := -1;
    12291229
     
    12321232    begin
    12331233      uix := uixSelectedLoad[tuix];
    1234       if MyUnit[uix].Movement = integer(MyModel[MyUnit[uix].mix].Speed) then
     1234      if MyUnit[uix].Movement = Integer(MyModel[MyUnit[uix].mix].Speed) then
    12351235      begin
    12361236        NotReachedFlag := 1 shl (2 * tuix);
     
    12461246            if (TurnsBeforeLoad[Loc1] >= 0) and (TurnsAfterLoad[Loc1] >= 0) then
    12471247            begin
    1248               i := 1;
     1248              I := 1;
    12491249              GroupCount := 0;
    12501250              for tuix1 := 0 to nSelectedLoad - 1 do
    12511251              begin
    1252                 if Arrived[loc1] and i = 0 then
     1252                if Arrived[loc1] and I = 0 then
    12531253                  Inc(GroupCount);
    1254                 i := i shl 2;
     1254                I := I shl 2;
    12551255              end;
    1256               assert(GroupCount <= TransportCapacity);
     1256              Assert(GroupCount <= TransportCapacity);
    12571257              if (GroupCount = TransportCapacity) or (GroupCount = nSelectedLoad) then
    12581258                GroupComplete[loc1] := True;
     
    12921292          begin
    12931293            Pile.Put(MyUnit[uix].Loc, $1800 - MyUnit[uix].Movement);
    1294             if MyUnit[uix].Movement = integer(MyModel[MyUnit[uix].mix].Speed) then
     1294            if MyUnit[uix].Movement = Integer(MyModel[MyUnit[uix].mix].Speed) then
    12951295              FullMovementLoc := MyUnit[uix].Loc;
    12961296            // surrounding tiles can be loaded immediately
     
    13081308            if StartLocPtr <> ArrivedEnd then
    13091309            begin
    1310               Loc0 := (integer(StartLocPtr) - integer(@Arrived)) shr 2;
     1310              Loc0 := (Integer(StartLocPtr) - Integer(@Arrived)) shr 2;
    13111311              Inc(StartLocPtr);
    13121312              Time0 := $800;
     
    13161316              if IsFirstLoc then
    13171317                ContinueUnit := ContinueUnit and not (1 shl tuix);
    1318               break;
     1318              Break;
    13191319            end;
    13201320            IsFirstLoc := False;
     
    13231323            if not GroupComplete[Loc0] and (Map[Loc0] and fTerrain <> fMountains) then
    13241324            begin // check whether group complete -- no mountains because complete flag might be faked there
    1325               i := 1;
     1325              I := 1;
    13261326              GroupCount := 0;
    13271327              for tuix1 := 0 to nSelectedLoad - 1 do
    13281328              begin
    1329                 if Arrived[Loc0] and i = 0 then
     1329                if Arrived[Loc0] and I = 0 then
    13301330                  Inc(GroupCount);
    1331                 i := i shl 2;
     1331                I := I shl 2;
    13321332              end;
    1333               assert(GroupCount <= TransportCapacity);
     1333              Assert(GroupCount <= TransportCapacity);
    13341334              if (GroupCount = TransportCapacity) or (GroupCount = nSelectedLoad) then
    13351335                GroupComplete[Loc0] := True;
     
    13531353                if (TurnsBeforeLoad[Loc1] >= 0) and (TurnsAfterLoad[Loc1] >= 0) then
    13541354                begin
    1355                   i := 1;
     1355                  I := 1;
    13561356                  GroupCount := 0;
    13571357                  for tuix1 := 0 to nSelectedLoad - 1 do
    13581358                  begin
    1359                     if Arrived[loc1] and i = 0 then
     1359                    if Arrived[loc1] and I = 0 then
    13601360                      Inc(GroupCount);
    1361                     i := i shl 2;
     1361                    I := I shl 2;
    13621362                  end;
    1363                   assert(GroupCount <= TransportCapacity);
     1363                  Assert(GroupCount <= TransportCapacity);
    13641364                  if (GroupCount = TransportCapacity) or
    13651365                    (GroupCount = nSelectedLoad) then
     
    14361436        if 1 shl (2 * tuix) and Arrived[BestLoadLoc] = 0 then
    14371437        begin
    1438           assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);
     1438          Assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);
    14391439          TransportPlan.uixLoad[TransportPlan.nLoad] := uixSelectedLoad[tuix];
    14401440          uixTransportLoad[tuixSelectedLoad[tuix]] :=
     
    14441444        end;
    14451445      Result := True;
    1446       exit;
     1446      Exit;
    14471447    end;
    14481448
     
    14511451    for tuix := nSelectedLoad - 1 downto 0 do
    14521452    begin
    1453       assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);
     1453      Assert(uixTransportLoad[tuixSelectedLoad[tuix]] = uixSelectedLoad[tuix]);
    14541454      uixTransportLoad[tuixSelectedLoad[tuix]] :=
    14551455        uixTransportLoad[nTransportLoad - 1];
     
    14641464// Misc
    14651465
    1466 function TToolAI.CurrentMStrength(Domain: integer): integer;
    1467 var
    1468   i: integer;
     1466function TToolAI.CurrentMStrength(Domain: Integer): Integer;
     1467var
     1468  I: Integer;
    14691469begin
    14701470  Result := 0;
    1471   for i := 0 to nUpgrade - 1 do
    1472     with upgrade[Domain, i] do
     1471  for I := 0 to nUpgrade - 1 do
     1472    with upgrade[Domain, I] do
    14731473      if (Preq = preNone) or (Preq >= 0) and
    14741474        ((RO.Tech[Preq] >= tsApplicable) or (Preq in FutureTech) and
     
    14861486procedure SetAdvancedness;
    14871487var
    1488   ad, j, Reduction, AgeThreshold: integer;
    1489   known: array[0..nAdv - 1] of integer;
    1490 
    1491   procedure MarkPreqs(ad: integer);
     1488  ad, J, Reduction, AgeThreshold: Integer;
     1489  known: array[0..nAdv - 1] of Integer;
     1490
     1491  procedure MarkPreqs(ad: Integer);
    14921492  var
    1493     i: integer;
     1493    I: Integer;
    14941494  begin
    14951495    if known[ad] = 0 then
    14961496    begin
    14971497      known[ad] := 1;
    1498       for i := 0 to 2 do
    1499         if AdvPreq[ad, i] >= 0 then
    1500           MarkPreqs(AdvPreq[ad, i]);
     1498      for I := 0 to 2 do
     1499        if AdvPreq[ad, I] >= 0 then
     1500          MarkPreqs(AdvPreq[ad, I]);
    15011501    end;
    15021502  end;
     
    15081508    FillChar(known, SizeOf(known), 0);
    15091509    MarkPreqs(ad);
    1510     for j := 0 to nAdv - 1 do
    1511       if known[j] > 0 then
     1510    for J := 0 to nAdv - 1 do
     1511      if known[J] > 0 then
    15121512        Inc(Advancedness[ad]);
    15131513  end;
  • trunk/CityProcessing.pas

    r425 r447  
    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
     
    6767
    6868var
    69   MaxDist: integer;
     69  MaxDist: Integer;
    7070
    7171{
     
    7373  ____________________________________________________________________
    7474}
    75 procedure GetCityAreaInfo(p, Loc: integer; var CityAreaInfo: TCityAreaInfo);
    76 var
    77   V21, Loc1, p1: integer;
     75procedure GetCityAreaInfo(P, Loc: Integer; var CityAreaInfo: TCityAreaInfo);
     76var
     77  V21, Loc1, p1: Integer;
    7878  Radius: TVicinity21Loc;
    7979begin
    80 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
     80{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
    8181  with CityAreaInfo do
    8282  begin
     
    9090      begin
    9191        p1 := RealMap[Loc1] shr 27;
    92         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
    9393          Available[V21] := faTreaty
    94         else if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> p) and
    95           (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
    9696          Available[V21] := faSiege
    9797        else if (UsedByCity[Loc1] <> -1) and (UsedByCity[Loc1] <> Loc) then
     
    104104end;
    105105
    106 function CanCityGrow(p, cix: integer): boolean;
    107 begin
    108   with RW[p].City[cix] do
    109     result := (Size < MaxCitySize) and
     106function CanCityGrow(P, cix: Integer): Boolean;
     107begin
     108  with RW[P].City[cix] do
     109    Result := (Size < MaxCitySize) and
    110110      ((Size < NeedAqueductSize) or (Built[imAqueduct] = 1) and
    111111      (Size < NeedSewerSize) or (Built[imSewer] = 1));
    112112end;
    113113
    114 procedure DetermineCityProdProcessing(p, cix: integer;
     114procedure DetermineCityProdProcessing(P, cix: Integer;
    115115  var ProdProcessing: TProdProcessing);
    116116begin
    117   with RW[p].City[cix], ProdProcessing do
     117  with RW[P].City[cix], ProdProcessing do
    118118  begin
    119119    ProdBonus := 0;
    120120    PollBonus := 0;
    121121    if Built[imFactory] = 1 then
    122       inc(ProdBonus);
     122      Inc(ProdBonus);
    123123    if Built[imMfgPlant] = 1 then
    124       inc(ProdBonus);
     124      Inc(ProdBonus);
    125125    if (Built[imPower] = 1) or (Built[imHydro] = 1) or (Built[imNuclear] = 1) or
    126       (GWonder[woHoover].EffectiveOwner = p) then
     126      (GWonder[woHoover].EffectiveOwner = P) then
    127127      ProdBonus := ProdBonus * 2;
    128128    if Built[imFactory] = 1 then
    129       inc(PollBonus);
     129      Inc(PollBonus);
    130130    if Built[imMfgPlant] = 1 then
    131       inc(PollBonus);
     131      Inc(PollBonus);
    132132    if (Built[imFactory] + Built[imMfgPlant] > 0) then
    133       if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = p) then
    134         dec(PollBonus)
     133      if (Built[imHydro] > 0) or (GWonder[woHoover].EffectiveOwner = P) then
     134        Dec(PollBonus)
    135135      else if (Built[imNuclear] = 0) and (Built[imPower] = 1) then
    136         inc(PollBonus);
    137     if (RW[p].Government <= gDespotism) or (Built[imRecycling] = 1) then
     136        Inc(PollBonus);
     137    if (RW[P].Government <= gDespotism) or (Built[imRecycling] = 1) then
    138138      PollBonus := -2; // no pollution
    139139    PollThreshold := Size;
    140140    FutProdBonus := 0;
    141     if RW[p].Tech[futProductionTechnology] > 0 then
     141    if RW[P].Tech[futProductionTechnology] > 0 then
    142142    begin // future tech benefits
    143143      if Built[imFactory] = 1 then
    144         inc(FutProdBonus, FactoryFutureBonus * RW[p].Tech
     144        Inc(FutProdBonus, FactoryFutureBonus * RW[P].Tech
    145145          [futProductionTechnology]);
    146146      if Built[imMfgPlant] = 1 then
    147         inc(FutProdBonus, MfgPlantFutureBonus * RW[p].Tech
     147        Inc(FutProdBonus, MfgPlantFutureBonus * RW[P].Tech
    148148          [futProductionTechnology]);
    149149    end;
     
    151151end;
    152152
    153 procedure BoostProd(BaseProd: integer; ProdProcessing: TProdProcessing;
    154   var Prod, Poll: integer);
     153procedure BoostProd(BaseProd: Integer; ProdProcessing: TProdProcessing;
     154  var Prod, Poll: Integer);
    155155begin
    156156  Poll := BaseProd * (2 + ProdProcessing.PollBonus) shr 1;
     
    158158    Poll := 0
    159159  else
    160     dec(Poll, ProdProcessing.PollThreshold);
     160    Dec(Poll, ProdProcessing.PollThreshold);
    161161  if ProdProcessing.FutProdBonus > 0 then
    162162    Prod := BaseProd * (100 + ProdProcessing.ProdBonus * 50 +
     
    166166end;
    167167
    168 procedure DetermineCityTradeProcessing(p, cix, HappinessBeforeLux: integer;
     168procedure DetermineCityTradeProcessing(P, cix, HappinessBeforeLux: Integer;
    169169  var TradeProcessing: TTradeProcessing);
    170170var
    171   i, Dist: integer;
    172 begin
    173   with RW[p].City[cix], TradeProcessing do
     171  I, Dist: Integer;
     172begin
     173  with RW[P].City[cix], TradeProcessing do
    174174  begin
    175175    TaxBonus := 0;
    176176    ScienceBonus := 0;
    177177    if Built[imMarket] = 1 then
    178       inc(TaxBonus, 2);
     178      Inc(TaxBonus, 2);
    179179    if Built[imBank] = 1 then
    180180    begin
    181       inc(TaxBonus, 3);
    182       if RW[p].NatBuilt[imStockEx] = 1 then
    183         inc(TaxBonus, 3);
     181      Inc(TaxBonus, 3);
     182      if RW[P].NatBuilt[imStockEx] = 1 then
     183        Inc(TaxBonus, 3);
    184184    end;
    185185    LuxBonus := TaxBonus;
    186186    if Built[imLibrary] = 1 then
    187       inc(ScienceBonus, 2);
     187      Inc(ScienceBonus, 2);
    188188    if Built[imUniversity] = 1 then
    189       inc(ScienceBonus, 3);
     189      Inc(ScienceBonus, 3);
    190190    if Built[imResLab] = 1 then
    191       inc(ScienceBonus, 3);
     191      Inc(ScienceBonus, 3);
    192192    ScienceDoubling := 0;
    193193    if Built[imNatObs] > 0 then
    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);
     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);
    204204    FutResBonus := 0;
    205     if RW[p].Tech[futResearchTechnology] > 0 then
     205    if RW[P].Tech[futResearchTechnology] > 0 then
    206206    begin // future tech benefits
    207207      if Built[imUniversity] = 1 then
    208         inc(FutResBonus, UniversityFutureBonus * RW[p].Tech
     208        Inc(FutResBonus, UniversityFutureBonus * RW[P].Tech
    209209          [futResearchTechnology]);
    210210      if Built[imResLab] = 1 then
    211         inc(FutResBonus, ResLabFutureBonus * RW[p].Tech[futResearchTechnology]);
    212     end;
    213     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
    214214    begin // calculate corruption
    215215      Dist := MaxDist;
    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
     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
    220220        RelCorr := 0.0
    221221      else
    222222      begin
    223223        RelCorr := Dist / MaxDist;
    224         if CorrLevel[RW[p].Government] > 1 then
    225           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]);
    226226        if Built[imCourt] = 1 then
    227227          RelCorr := RelCorr / 2;
     
    237237end;
    238238
    239 procedure SplitTrade(Trade, TaxRate, LuxRate, Working: integer;
     239procedure SplitTrade(Trade, TaxRate, LuxRate, Working: Integer;
    240240  TradeProcessing: TTradeProcessing; var Corruption, Tax, Lux,
    241   Science: integer);
    242 var
    243   plus: integer;
     241  Science: Integer);
     242var
     243  plus: Integer;
    244244begin
    245245  Corruption := Trunc(Trade * TradeProcessing.RelCorr);
     
    276276end;
    277277
    278 function GetProjectCost(p, cix: integer): integer;
    279 var
    280   i: integer;
    281 begin
    282   with RW[p].City[cix] do
     278function GetProjectCost(P, cix: Integer): Integer;
     279var
     280  I: Integer;
     281begin
     282  with RW[P].City[cix] do
    283283  begin
    284284    if Project and cpImp = 0 then
    285285    begin
    286       result := RW[p].Model[Project and cpIndex].Cost; { unit project }
     286      Result := RW[P].Model[Project and cpIndex].Cost; { unit project }
    287287      if Project and cpConscripts <> 0 then
    288288      begin
    289         i := RW[p].Model[Project and cpIndex].MCost;
    290         result := result - 3 * i;
    291         if result <= 0 then
    292           result := i;
     289        I := RW[P].Model[Project and cpIndex].MCost;
     290        Result := Result - 3 * I;
     291        if Result <= 0 then
     292          Result := I;
    293293      end
    294       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
    295295        if Project0 and (not cpAuto or cpRepeat) = Project and not cpAuto or cpRepeat
    296296        then
    297           result := result shr 1
     297          Result := Result shr 1
    298298        else
    299           result := result * 2;
     299          Result := Result * 2;
    300300    end
    301301    else
    302302    begin { improvement project }
    303       result := Imp[Project and cpIndex].Cost;
    304       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)
    305305      then
    306         result := result * ColossusEffect div 100;
    307     end;
    308     result := result * BuildCostMod[Difficulty[p]] div 12;
    309   end;
    310 end;
    311 
    312 function GetSmallCityReport(p, cix: integer; var CityReport: TCityReport;
    313   PCityReportEx: PCityReportEx = nil): integer;
    314 var
    315   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;
    316316  ProdProcessing: TProdProcessing;
    317317  TradeProcessing: TTradeProcessing;
    318318  Radius: TVicinity21Loc;
    319319  UnitReport: TUnitReport;
    320   RareOK: array [0 .. 3] of integer;
     320  RareOK: array [0 .. 3] of Integer;
    321321  TileInfo: TTileInfo;
    322322begin
    323   with RW[p].City[cix], CityReport do
     323  with RW[P].City[cix], CityReport do
    324324  begin
    325325    if HypoTiles <= 0 then
    326326      HypoTiles := Tiles;
    327327    if HypoTax < 0 then
    328       HypoTax := RW[p].TaxRate;
     328      HypoTax := RW[P].TaxRate;
    329329    if HypoLux < 0 then
    330       HypoLux := RW[p].LuxRate;
    331 
    332     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
    333333    begin
    334334      Working := 0;
    335335      for V21 := 1 to 26 do
    336336        if HypoTiles and (1 shl V21) <> 0 then
    337           inc(Working); // for backward compatibility
    338 
    339       if RW[p].Government = gFundamentalism then
     337          Inc(Working); // for backward compatibility
     338
     339      if RW[P].Government = gFundamentalism then
    340340      begin
    341341        Happy := Size;
     
    380380          BaseHappiness := Size;
    381381      end;
    382       for i := 0 to nWonder - 1 do
    383         if Built[i] = 1 then
     382      for I := 0 to nWonder - 1 do
     383        if Built[I] = 1 then
    384384        begin
    385           inc(Happy);
    386           inc(BaseHappiness, 2);
     385          Inc(Happy);
     386          Inc(BaseHappiness, 2);
    387387        end;
    388388      if Built[imTemple] = 1 then
    389389      begin
    390         inc(Happy);
    391         inc(BaseHappiness, 2);
     390        Inc(Happy);
     391        Inc(BaseHappiness, 2);
    392392      end;
    393393      if Built[imCathedral] = 1 then
    394394      begin
    395         inc(Happy, 2);
    396         inc(BaseHappiness, 4);
    397         if GWonder[woBach].EffectiveOwner = p then
     395        Inc(Happy, 2);
     396        Inc(BaseHappiness, 4);
     397        if GWonder[woBach].EffectiveOwner = P then
    398398        begin
    399           inc(Happy);
    400           inc(BaseHappiness, 2);
     399          Inc(Happy);
     400          Inc(BaseHappiness, 2);
    401401        end;
    402402      end;
    403403      if Built[imTheater] > 0 then
    404404      begin
    405         inc(Happy, 2);
    406         inc(BaseHappiness, 4);
     405        Inc(Happy, 2);
     406        Inc(BaseHappiness, 4);
    407407      end;
    408408
    409409      // calculate unit support
    410 {$IFOPT O-}assert(InvalidTreatyMap = 0); {$ENDIF}
     410{$IFOPT O-}Assert(InvalidTreatyMap = 0); {$ENDIF}
    411411      Support := 0;
    412412      ForcedSupport := 0;
    413413      Eaten := Size * 2;
    414414      Deployed := 0;
    415       for uix := 0 to RW[p].nUn - 1 do
    416         with RW[p].Un[uix] do
     415      for uix := 0 to RW[P].nUn - 1 do
     416        with RW[P].Un[uix] do
    417417          if (Loc >= 0) and (Home = cix) then
    418418          begin
    419             GetUnitReport(p, uix, UnitReport);
    420             inc(Eaten, UnitReport.FoodSupport);
     419            GetUnitReport(P, uix, UnitReport);
     420            Inc(Eaten, UnitReport.FoodSupport);
    421421            if UnitReport.ReportFlags and urfAlwaysSupport <> 0 then
    422               inc(ForcedSupport, UnitReport.ProdSupport)
     422              Inc(ForcedSupport, UnitReport.ProdSupport)
    423423            else
    424               inc(Support, UnitReport.ProdSupport);
     424              Inc(Support, UnitReport.ProdSupport);
    425425            if UnitReport.ReportFlags and urfDeployed <> 0 then
    426               inc(Deployed);
     426              Inc(Deployed);
    427427          end;
    428428      if Deployed >= Happy then
    429429        Happy := 0
    430430      else
    431         dec(Happy, Deployed);
    432       dec(Support, Size * SupportFree[RW[p].Government] shr 1);
     431        Dec(Happy, Deployed);
     432      Dec(Support, Size * SupportFree[RW[P].Government] shr 1);
    433433      if Support < 0 then
    434434        Support := 0;
    435       inc(Support, ForcedSupport);
     435      Inc(Support, ForcedSupport);
    436436
    437437      { control }
    438       case RW[p].Government of
     438      case RW[P].Government of
    439439        gDespotism:
    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
     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
    443443            begin
    444               inc(Happy);
    445               inc(Control, 2);
     444              Inc(Happy);
     445              Inc(Control, 2);
    446446            end;
    447447        gFundamentalism:
     
    454454
    455455      // collect processing parameters
    456       DetermineCityProdProcessing(p, cix, ProdProcessing);
    457       DetermineCityTradeProcessing(p, cix, BaseHappiness + Control - 2 *
     456      DetermineCityProdProcessing(P, cix, ProdProcessing);
     457      DetermineCityTradeProcessing(P, cix, BaseHappiness + Control - 2 *
    458458        Deployed, TradeProcessing);
    459459
     
    472472          // HypoTiles go beyond map border!
    473473          begin
    474             result := eInvalid;
    475             exit;
     474            Result := eInvalid;
     475            Exit;
    476476          end;
    477           GetTileInfo(p, cix, Loc1, TileInfo);
    478           inc(FoodRep, TileInfo.Food);
    479           inc(ProdRep, TileInfo.Prod);
    480           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);
    481481          if (RealMap[Loc1] and fModern <> 0) and
    482             (RW[p].Tech[adMassProduction] >= tsApplicable) then
    483             inc(RareOK[RealMap[Loc1] shr 25 and 3]);
    484           inc(Working);
     482            (RW[P].Tech[adMassProduction] >= tsApplicable) then
     483            Inc(RareOK[RealMap[Loc1] shr 25 and 3]);
     484          Inc(Working);
    485485        end;
    486486      if Built[imAlgae] = 1 then
    487         inc(FoodRep, 12);
     487        Inc(FoodRep, 12);
    488488
    489489      if PCityReportEx <> nil then
     
    510510    end;
    511511  end;
    512   result := eOk;
    513 end;
    514 
    515 function GetCityReport(p, cix: integer; var CityReport: TCityReport): integer;
    516 begin
    517   result := GetSmallCityReport(p, cix, CityReport);
    518   CityReport.Storage := StorageSize[Difficulty[p]];
    519   CityReport.ProdCost := GetProjectCost(p, cix);
    520 end;
    521 
    522 function GetCityReportNew(p, cix: integer;
    523   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;
    524524var
    525525  CityReport: TCityReport;
     
    531531    CityReport.HypoTax := HypoTaxRate;
    532532    CityReport.HypoLux := HypoLuxuryRate;
    533     result := GetSmallCityReport(p, cix, CityReport, @CityReportEx);
    534     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;
    535535    MaterialSupport := CityReport.Support;
    536     ProjectCost := GetProjectCost(p, cix);
    537     Storage := StorageSize[Difficulty[p]];
     536    ProjectCost := GetProjectCost(P, cix);
     537    Storage := StorageSize[Difficulty[P]];
    538538    Deployed := CityReport.Deployed;
    539539    Morale := CityReportEx.BaseHappiness;
    540540    CollectedControl := CityReportEx.BaseControl +
    541       (RW[p].City[cix].Size - CityReport.Working) * 2;
     541      (RW[P].City[cix].Size - CityReport.Working) * 2;
    542542    CollectedFood := CityReport.FoodRep;
    543543    CollectedMaterial := CityReportEx.Material;
     
    551551    Luxury := CityReport.Lux;
    552552    FoodSurplus := CityReport.FoodRep - CityReport.Eaten;
    553     HappinessBalance := Morale + Luxury + CollectedControl - RW[p].City[cix]
     553    HappinessBalance := Morale + Luxury + CollectedControl - RW[P].City[cix]
    554554      .Size - 2 * Deployed;
    555555  end;
     
    560560  ____________________________________________________________________
    561561}
    562 procedure NextBest(p, cix: integer; var SelectedLoc, SelectedV21: integer);
     562procedure NextBest(P, cix: Integer; var SelectedLoc, SelectedV21: Integer);
    563563{ best tile unused but available by city cix }
    564564var
    565   Resources, Most, Loc1, p1, V21: integer;
     565  Resources, Most, Loc1, p1, V21: Integer;
    566566  TileInfo: TTileInfo;
    567567  Radius: TVicinity21Loc;
    568568begin
    569 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
     569{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
    570570  Most := 0;
    571571  SelectedLoc := -1;
    572572  SelectedV21 := -1;
    573   with RW[p].City[cix] do
     573  with RW[P].City[cix] do
    574574  begin
    575575    V21_to_Loc(Loc, Radius);
     
    580580      begin
    581581        p1 := RealMap[Loc1] shr 27;
    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
     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
    585585        begin
    586           GetTileInfo(p, cix, Loc1, TileInfo);
     586          GetTileInfo(P, cix, Loc1, TileInfo);
    587587          Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 +
    588588            TileInfo.Trade;
     
    600600end;
    601601
    602 procedure NextWorst(p, cix: integer; var SelectedLoc, SelectedV21: integer);
     602procedure NextWorst(P, cix: Integer; var SelectedLoc, SelectedV21: Integer);
    603603{ worst tile used by city cix }
    604604var
    605   Resources, Least, Loc1, V21: integer;
     605  Resources, Least, Loc1, V21: Integer;
    606606  Radius: TVicinity21Loc;
    607607  TileInfo: TTileInfo;
     
    610610  SelectedLoc := -1;
    611611  SelectedV21 := -1;
    612   with RW[p].City[cix] do
     612  with RW[P].City[cix] do
    613613  begin
    614614    V21_to_Loc(Loc, Radius);
     
    619619        if (Loc1 >= 0) and (Loc1 < MapSize) and (1 shl V21 and Tiles <> 0) then
    620620        begin
    621           GetTileInfo(p, cix, Loc1, TileInfo);
     621          GetTileInfo(P, cix, Loc1, TileInfo);
    622622          Resources := TileInfo.Food shl 16 + TileInfo.Prod shl 8 +
    623623            TileInfo.Trade;
     
    634634end;
    635635
    636 function NextPoll(p, cix: integer): integer;
    637 var
    638   Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: integer;
     636function NextPoll(P, cix: Integer): Integer;
     637var
     638  Resources, Best, dx, dy, Loc1, Dist, BestDist, V21, pTerr: Integer;
    639639  Radius: TVicinity21Loc;
    640640  TileInfo: TTileInfo;
    641641begin
    642642  BestDist := MaxInt;
    643 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
     643{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
    644644  Best := 0;
    645   result := -1;
    646   with RW[p].City[cix] do
     645  Result := -1;
     646  with RW[P].City[cix] do
    647647  begin
    648648    V21_to_Loc(Loc, Radius);
     
    656656        begin
    657657          pTerr := RealMap[Loc1] shr 27;
    658           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)
    659659          then
    660660          begin
    661             GetTileInfo(p, cix, Loc1, TileInfo);
     661            GetTileInfo(P, cix, Loc1, TileInfo);
    662662            Resources := TileInfo.Prod shl 16 + TileInfo.Trade shl 8 +
    663663              TileInfo.Food;
     
    669669            then
    670670            begin
    671               result := Loc1;
     671              Result := Loc1;
    672672              Best := Resources;
    673673              BestDist := Dist;
     
    679679end;
    680680
    681 function AddBestCityTile(p, cix: integer): boolean;
    682 var
    683   TileLoc, V21: integer;
    684 begin
    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);
     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);
    691691      Tiles := Tiles or (1 shl V21);
    692692      UsedByCity[TileLoc] := Loc;
     
    694694end;
    695695
    696 procedure CityGrowth(p, cix: integer);
    697 var
    698   TileLoc, V21: integer;
     696procedure CityGrowth(P, cix: Integer);
     697var
     698  TileLoc, V21: Integer;
    699699  AltCityReport: TCityReport;
    700700begin
    701   with RW[p].City[cix] do
     701  with RW[P].City[cix] do
    702702  begin
    703     inc(Size);
    704     NextBest(p, cix, TileLoc, V21);
     703    Inc(Size);
     704    NextBest(P, cix, TileLoc, V21);
    705705    if TileLoc >= 0 then
    706706    begin { test whether exploitation of tile would lead to disorder }
     
    708708      AltCityReport.HypoTax := -1;
    709709      AltCityReport.HypoLux := -1;
    710       GetSmallCityReport(p, cix, AltCityReport);
     710      GetSmallCityReport(P, cix, AltCityReport);
    711711      if AltCityReport.Working - AltCityReport.Happy <= Size shr 1 then
    712712      // !!! change to new style disorder
    713713      begin { no disorder -- exploit tile }
    714         assert(1 shl V21 and Tiles = 0);
     714        Assert(1 shl V21 and Tiles = 0);
    715715        Tiles := Tiles or (1 shl V21);
    716716        UsedByCity[TileLoc] := Loc;
     
    720720end;
    721721
    722 procedure CityShrink(p, cix: integer);
    723 var
    724   TileLoc, V21, Working: integer;
     722procedure CityShrink(P, cix: Integer);
     723var
     724  TileLoc, V21, Working: Integer;
    725725  AltCityReport: TCityReport;
    726726begin
    727   with RW[p].City[cix] do
     727  with RW[P].City[cix] do
    728728  begin
    729729    Working := 0;
    730730    for V21 := 1 to 26 do
    731731      if Tiles and (1 shl V21) <> 0 then
    732         inc(Working);
    733     dec(Size);
    734     if Food > StorageSize[Difficulty[p]] then
    735       Food := StorageSize[Difficulty[p]];
    736     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);
    737737    if Working > Size then
    738738    begin { all citizens were working -- worst tile no longer exploited }
    739       assert(1 shl V21 and Tiles <> 0);
     739      Assert(1 shl V21 and Tiles <> 0);
    740740      Tiles := Tiles and not(1 shl V21);
    741741      UsedByCity[TileLoc] := -1;
     
    746746      AltCityReport.HypoTax := -1;
    747747      AltCityReport.HypoLux := -1;
    748       GetSmallCityReport(p, cix, AltCityReport);
     748      GetSmallCityReport(P, cix, AltCityReport);
    749749      if AltCityReport.Working - AltCityReport.Happy > Size shr 1 then
    750750      // !!! change to new style disorder
    751751      begin { disorder -- don't exploit tile }
    752         assert(1 shl V21 and Tiles <> 0);
     752        Assert(1 shl V21 and Tiles <> 0);
    753753        Tiles := Tiles and not(1 shl V21);
    754754        UsedByCity[TileLoc] := -1;
     
    758758end;
    759759
    760 procedure Pollute(p, cix: integer);
    761 var
    762   PollutionLoc: integer;
    763 begin
    764   with RW[p].City[cix] do
     760procedure Pollute(P, cix: Integer);
     761var
     762  PollutionLoc: Integer;
     763begin
     764  with RW[P].City[cix] do
    765765  begin
    766766    Pollution := Pollution - MaxPollution;
    767     PollutionLoc := NextPoll(p, cix);
     767    PollutionLoc := NextPoll(P, cix);
    768768    if PollutionLoc >= 0 then
    769769    begin
    770       inc(Flags, chPollution);
     770      Inc(Flags, chPollution);
    771771      RealMap[PollutionLoc] := RealMap[PollutionLoc] or fPoll;
    772772    end;
     
    778778  ____________________________________________________________________
    779779}
    780 procedure PayCityMaintenance(p, cix: integer);
    781 var
    782   i: integer;
    783 begin
    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))
     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))
    787787      then // don't pay maintenance when just completed
    788788      begin
    789         dec(Money, Imp[i].Maint);
     789        Dec(Money, Imp[I].Maint);
    790790        if Money < 0 then
    791791        begin { out of money - sell improvement }
    792           inc(Money, Imp[i].Cost * BuildCostMod[Difficulty[p]] div 12);
    793           Built[i] := 0;
    794           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
    795795          begin
    796             assert(i <> imSpacePort);
     796            Assert(I <> imSpacePort);
    797797            // never sell automatically! (solution: no maintenance)
    798             NatBuilt[i] := 0;
    799             if i = imGrWall then
    800               GrWallContinent[p] := -1;
     798            NatBuilt[I] := 0;
     799            if I = imGrWall then
     800              GrWallContinent[P] := -1;
    801801          end;
    802           inc(Flags, chImprovementLost);
    803         end;
    804       end;
    805 end;
    806 
    807 procedure CollectCityResources(p, cix: integer);
    808 var
    809   CityStorage, CityProjectCost: integer;
     802          Inc(Flags, chImprovementLost);
     803        end;
     804      end;
     805end;
     806
     807procedure CollectCityResources(P, cix: Integer);
     808var
     809  CityStorage, CityProjectCost: Integer;
    810810  CityReport: TCityReportNew;
    811   Disorder: boolean;
    812 begin
    813   with RW[p], City[cix], CityReport do
     811  Disorder: Boolean;
     812begin
     813  with RW[P], City[cix], CityReport do
    814814    if Flags and chCaptured <> 0 then
    815815    begin
    816816      Flags := Flags and not chDisorder;
    817       dec(Flags, $10000);
     817      Dec(Flags, $10000);
    818818      if Flags and chCaptured = 0 then
    819819        Flags := Flags or chAfterCapture;
     
    826826      HypoTaxRate := -1;
    827827      HypoLuxuryRate := -1;
    828       GetCityReportNew(p, cix, CityReport);
    829       CityStorage := StorageSize[Difficulty[p]];
    830       CityProjectCost := GetProjectCost(p, cix);
     828      GetCityReportNew(P, cix, CityReport);
     829      CityStorage := StorageSize[Difficulty[P]];
     830      CityProjectCost := GetProjectCost(P, cix);
    831831
    832832      Disorder := (HappinessBalance < 0);
     
    840840      if not Disorder and ((Government = gFuture) or (Size >= NeedAqueductSize)
    841841        and (FoodSurplus < 2)) and (FoodSurplus > 0) then
    842         inc(Money, FoodSurplus)
     842        Inc(Money, FoodSurplus)
    843843      else if not(Disorder and (FoodSurplus > 0)) then
    844844      begin { calculate new food storage }
     
    849849          (Project and (cpImp + cpIndex) <> cpImp + imAqueduct) and
    850850          (Project and (cpImp + cpIndex) <> cpImp + imSewer) and
    851           not CanCityGrow(p, cix) then
    852           inc(Flags, chNoGrowthWarning);
     851          not CanCityGrow(P, cix) then
     852          Inc(Flags, chNoGrowthWarning);
    853853      end;
    854854
    855855      if Prod > CityProjectCost then
    856856      begin
    857         inc(Money, Prod - CityProjectCost);
     857        Inc(Money, Prod - CityProjectCost);
    858858        Prod := CityProjectCost;
    859859      end;
     
    862862      else if not Disorder and (Flags and chProductionSabotaged = 0) then
    863863        if Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    864           inc(Money, Production)
     864          Inc(Money, Production)
    865865        else
    866           inc(Prod, Production);
     866          Inc(Prod, Production);
    867867
    868868      if not Disorder then
    869869      begin
    870870        { sum research points and taxes }
    871         inc(Research, Science);
    872         inc(Money, Tax);
     871        Inc(Research, Science);
     872        Inc(Money, Tax);
    873873        Pollution := Pollution + AddPollution;
    874874      end;
     
    876876end;
    877877
    878 function CityTurn(p, cix: integer): boolean;
     878function CityTurn(P, cix: Integer): Boolean;
    879879// return value: whether city keeps existing
    880880var
    881   i, uix, cix2, p1, SizeMod, CityStorage, CityProjectCost, NewImp, Det,
    882     TestDet: integer;
    883   LackOfMaterial, CheckGrow, DoProd, IsActive: boolean;
    884 begin
    885   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
    886886  begin
    887887    SizeMod := 0;
    888     CityStorage := StorageSize[Difficulty[p]];
    889     CityProjectCost := GetProjectCost(p, cix);
     888    CityStorage := StorageSize[Difficulty[P]];
     889    CityProjectCost := GetProjectCost(P, cix);
    890890
    891891    LackOfMaterial := Flags and chUnitLost <> 0;
     
    897897    if CheckGrow and (GTestFlags and tfImmGrow <> 0) then { fast growth }
    898898    begin
    899       if CanCityGrow(p, cix) then
    900         inc(SizeMod);
     899      if CanCityGrow(P, cix) then
     900        Inc(SizeMod);
    901901    end
    902902    else if CheckGrow and (Food >= CityStorage) then { normal growth }
    903903    begin
    904       if CanCityGrow(p, cix) then
     904      if CanCityGrow(P, cix) then
    905905      begin
    906906        if Built[imGranary] = 1 then
    907           dec(Food, CityStorage shr 1)
     907          Dec(Food, CityStorage shr 1)
    908908        else
    909           dec(Food, CityStorage);
    910         inc(SizeMod);
     909          Dec(Food, CityStorage);
     910        Inc(SizeMod);
    911911      end;
    912912    end
     
    916916      // check if settlers or conscripts there to disband
    917917      uix := -1;
    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)
     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)
    921921          { and (GWonder[woFreeSettlers].EffectiveOwner<>p) }
    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;
     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;
    927927
    928928      if uix >= 0 then
    929929      begin
    930         RemoveUnit_UpdateMap(p, uix);
    931         inc(Flags, chUnitLost);
     930        RemoveUnit_UpdateMap(P, uix);
     931        Inc(Flags, chUnitLost);
    932932      end
    933933      else
    934934      begin
    935         dec(SizeMod);
    936         inc(Flags, chPopDecrease);
     935        Dec(SizeMod);
     936        Inc(Flags, chPopDecrease);
    937937      end
    938938    end;
     
    946946        uix := -1;
    947947        Det := MaxInt;
    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
     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
    951951            begin
    952952              if Kind = mkSpecial_TownGuard then
    953                 TestDet := Un[i].Health + Un[i].Exp shl 8
     953                TestDet := Un[I].Health + Un[I].Exp shl 8
    954954                // disband townguards first
    955955              else
    956956              begin
    957                 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;
    958958                // value of unit
    959959                if Flags and mdDoubleSupport <> 0 then
     
    963963              if TestDet < Det then
    964964              begin
    965                 uix := i;
     965                uix := I;
    966966                Det := TestDet;
    967967              end;
     
    969969        if uix >= 0 then
    970970        begin
    971           RemoveUnit_UpdateMap(p, uix);
    972           inc(Flags, chUnitLost);
     971          RemoveUnit_UpdateMap(P, uix);
     972          Inc(Flags, chUnitLost);
    973973        end;
    974974      end;
     
    984984      (GWonder[Project and cpIndex].CityID <> WonderNotBuiltYet) then
    985985    begin
    986       inc(Flags, chOldWonder);
    987       DoProd := false;
     986      Inc(Flags, chOldWonder);
     987      DoProd := False;
    988988    end;
    989989
     
    995995      (Project and cpConscripts <> 0))) then
    996996    begin
    997       inc(Flags, chNoSettlerProd);
    998       DoProd := false;
     997      Inc(Flags, chNoSettlerProd);
     998      DoProd := False;
    999999    end;
    10001000
    10011001    if DoProd then
    10021002    begin { project complete }
    1003       dec(Prod, CityProjectCost);
     1003      Dec(Prod, CityProjectCost);
    10041004      if Project and cpImp = 0 then { produce unit }
    10051005      begin
    10061006        if nUn < numax then
    10071007        begin
    1008           CreateUnit(p, Project and cpIndex);
     1008          CreateUnit(P, Project and cpIndex);
    10091009          Un[nUn - 1].Loc := Loc;
    10101010          with Un[nUn - 1] do
     
    10201020              Flags := Flags or unConscripts;
    10211021          end;
    1022           PlaceUnit(p, nUn - 1);
     1022          PlaceUnit(P, nUn - 1);
    10231023          UpdateUnitMap(Loc);
    10241024          if Model[Project and cpIndex].Kind = mkSettler then
    1025             dec(SizeMod, 2) { settler produced - city shrink }
     1025            Dec(SizeMod, 2) { settler produced - city shrink }
    10261026          else if (Model[Project and cpIndex].Kind = mkSlaves) or
    10271027            (Project and cpConscripts <> 0) then
    1028             dec(SizeMod); { slaves/conscripts produced - city shrink }
     1028            Dec(SizeMod); { slaves/conscripts produced - city shrink }
    10291029        end;
    10301030        Project0 := Project or cpRepeat or cpCompleted;
     
    10321032      else if Imp[Project and cpIndex].Kind = ikShipPart then
    10331033      begin { produce ship parts }
    1034         inc(GShip[p].Parts[Project and cpIndex - imShipComp]);
     1034        Inc(GShip[P].Parts[Project and cpIndex - imShipComp]);
    10351035        Project0 := Project or cpCompleted;
    10361036      end
     
    10381038      begin
    10391039        NewImp := Project and cpIndex;
    1040         inc(Money, Prod); { change rest to money }
     1040        Inc(Money, Prod); { change rest to money }
    10411041        Project0 := Project or cpCompleted;
    10421042        Project := cpImp + imTrGoods;
     
    10451045        if Imp[NewImp].Kind in [ikNatLocal, ikNatGlobal] then
    10461046        begin // nat. project
    1047           for i := 0 to nCity - 1 do
    1048             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
    10491049            begin { allowed only once }
    1050               inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[p]] div 12);
    1051               City[i].Built[NewImp] := 0;
     1050              Inc(Money, Imp[NewImp].Cost * BuildCostMod[Difficulty[P]] div 12);
     1051              City[I].Built[NewImp] := 0;
    10521052            end;
    10531053          NatBuilt[NewImp] := 1;
     
    10561056          case NewImp of
    10571057            imGrWall:
    1058               GrWallContinent[p] := Continent[Loc];
     1058              GrWallContinent[P] := Continent[Loc];
    10591059          end;
    10601060        end;
     
    10631063        begin // wonder
    10641064          GWonder[NewImp].CityID := ID;
    1065           GWonder[NewImp].EffectiveOwner := p;
     1065          GWonder[NewImp].EffectiveOwner := P;
    10661066          CheckExpiration(NewImp);
    10671067
     
    10701070            woEiffel:
    10711071              begin // reactivate wonders
    1072                 for i := 0 to nWonder - 1 do
    1073                   if Imp[i].Expiration >= 0 then
     1072                for I := 0 to nWonder - 1 do
     1073                  if Imp[I].Expiration >= 0 then
    10741074                    for cix2 := 0 to nCity - 1 do
    1075                       if (City[cix2].Loc >= 0) and (City[cix2].Built[i] = 1)
     1075                      if (City[cix2].Loc >= 0) and (City[cix2].Built[I] = 1)
    10761076                      then
    1077                         GWonder[i].EffectiveOwner := p;
     1077                        GWonder[I].EffectiveOwner := P;
    10781078              end;
    10791079            woLighthouse:
    1080               CheckSpecialModels(p, preLighthouse);
     1080              CheckSpecialModels(P, preLighthouse);
    10811081            woLeo:
    10821082              begin
    1083                 inc(Research, TechBaseCost(nTech[p], Difficulty[p]) +
    1084                   TechBaseCost(nTech[p] + 2, Difficulty[p]));
    1085                 CheckSpecialModels(p, preLeo);
     1083                Inc(Research, TechBaseCost(nTech[P], Difficulty[P]) +
     1084                  TechBaseCost(nTech[P] + 2, Difficulty[P]));
     1085                CheckSpecialModels(P, preLeo);
    10861086              end;
    10871087            woPyramids:
    1088               CheckSpecialModels(p, preBuilder);
     1088              CheckSpecialModels(P, preBuilder);
    10891089            woMir:
    10901090              begin
    10911091                for p1 := 0 to nPl - 1 do
    1092                   if (p1 <> p) and (1 shl p1 and GAlive <> 0) then
     1092                  if (p1 <> P) and (1 shl p1 and GAlive <> 0) then
    10931093                  begin
    1094                     if RW[p].Treaty[p1] = trNoContact then
    1095                       IntroduceEnemy(p, p1);
    1096                     GiveCivilReport(p, p1);
    1097                     GiveMilReport(p, p1);
     1094                    if RW[P].Treaty[p1] = trNoContact then
     1095                      IntroduceEnemy(P, p1);
     1096                    GiveCivilReport(P, p1);
     1097                    GiveMilReport(P, p1);
    10981098                  end;
    10991099              end;
     
    11011101        end;
    11021102
    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
     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
    11061106          begin
    1107             inc(RW[p].Money, Imp[ImpReplacement[i].OldImp].Cost * BuildCostMod
    1108               [Difficulty[p]] div 12);
    1109             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;
    11101110          end;
    11111111
    11121112        if NewImp in [imPower, imHydro, imNuclear] 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
     1113          for I := 0 to nImp - 1 do
     1114            if (I <> NewImp) and (I in [imPower, imHydro, imNuclear]) and
     1115              (Built[I] > 0) then
    11161116            begin // sell obsolete power plant
    1117               inc(RW[p].Money, Imp[i].Cost * BuildCostMod[Difficulty[p]
     1117              Inc(RW[P].Money, Imp[I].Cost * BuildCostMod[Difficulty[P]
    11181118                ] div 12);
    1119               Built[i] := 0;
     1119              Built[I] := 0;
    11201120            end;
    11211121
     
    11231123      end;
    11241124      Prod0 := Prod;
    1125       inc(Flags, chProduction);
     1125      Inc(Flags, chProduction);
    11261126    end
    11271127    else
     
    11351135    if SizeMod > 0 then
    11361136    begin
    1137       CityGrowth(p, cix);
    1138       inc(Flags, chPopIncrease);
    1139     end;
    1140     result := Size + SizeMod >= 2;
    1141     if result then
     1137      CityGrowth(P, cix);
     1138      Inc(Flags, chPopIncrease);
     1139    end;
     1140    Result := Size + SizeMod >= 2;
     1141    if Result then
    11421142      while SizeMod < 0 do
    11431143      begin
    1144         CityShrink(p, cix);
    1145         inc(SizeMod);
     1144        CityShrink(P, cix);
     1145        Inc(SizeMod);
    11461146      end;
    11471147  end;
     
    11521152  ____________________________________________________________________
    11531153}
    1154 function SetCityTiles(p, cix, NewTiles: integer;
    1155   TestOnly: boolean = false): integer;
    1156 var
    1157   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;
    11581158  CityAreaInfo: TCityAreaInfo;
    11591159  Radius: TVicinity21Loc;
    11601160begin
    1161   with RW[p].City[cix] do
     1161  with RW[P].City[cix] do
    11621162  begin
    1163     ChangeTiles := NewTiles xor integer(Tiles);
     1163    ChangeTiles := NewTiles xor Integer(Tiles);
    11641164    AddTiles := NewTiles and not Tiles;
    11651165    if Mode = moPlaying then
     
    11671167      if NewTiles and not $67F7F76 <> 0 then
    11681168      begin
    1169         result := eInvalid;
    1170         exit
     1169        Result := eInvalid;
     1170        Exit
    11711171      end; // invalid tile index included
    11721172      if NewTiles and (1 shl 13) = 0 then
    11731173      begin
    1174         result := eViolation;
    1175         exit
     1174        Result := eViolation;
     1175        Exit
    11761176      end; // city tile must be exploited
    11771177      if ChangeTiles = 0 then
    11781178      begin
    1179         result := eNotChanged;
    1180         exit
     1179        Result := eNotChanged;
     1180        Exit
    11811181      end;
    11821182      if AddTiles <> 0 then
    11831183      begin
    11841184        // check if new tiles possible
    1185         GetCityAreaInfo(p, Loc, CityAreaInfo);
     1185        GetCityAreaInfo(P, Loc, CityAreaInfo);
    11861186        for V21 := 1 to 26 do
    11871187          if AddTiles and (1 shl V21) <> 0 then
    11881188            if CityAreaInfo.Available[V21] <> faAvailable then
    11891189            begin
    1190               result := eTileNotAvailable;
    1191               exit;
     1190              Result := eTileNotAvailable;
     1191              Exit;
    11921192            end;
    11931193        // not more tiles than inhabitants
     
    11951195        for V21 := 1 to 26 do
    11961196          if NewTiles and (1 shl V21) <> 0 then
    1197             inc(Working);
     1197            Inc(Working);
    11981198        if Working > Size then
    11991199        begin
    1200           result := eNoWorkerAvailable;
    1201           exit;
    1202         end;
    1203       end;
    1204     end;
    1205     result := eOk;
     1200          Result := eNoWorkerAvailable;
     1201          Exit;
     1202        end;
     1203      end;
     1204    end;
     1205    Result := eOk;
    12061206    if not TestOnly then
    12071207    begin
     
    12111211        begin
    12121212          Loc1 := Radius[V21];
    1213           assert((Loc1 >= 0) and (Loc1 < MapSize));
     1213          Assert((Loc1 >= 0) and (Loc1 < MapSize));
    12141214          if NewTiles and (1 shl V21) <> 0 then
    12151215            UsedByCity[Loc1] := Loc // employ tile
    12161216          else if UsedByCity[Loc1] <> Loc then
    1217             assert(Mode < moPlaying)
     1217            Assert(Mode < moPlaying)
    12181218            // should only happen during loading, because of wrong sSetCityTiles command order
    12191219          else
     
    12251225end;
    12261226
    1227 procedure GetCityTileAdvice(p, cix: integer; var Advice: TCityTileAdviceData);
     1227procedure GetCityTileAdvice(P, cix: Integer; var Advice: TCityTileAdviceData);
    12281228const
    12291229  oFood = 0;
     
    12401240  end;
    12411241var
    1242   i, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking,
     1242  I, V21, Loc1, nHierarchy, iH, iT, iH_Switch, MinWorking, MaxWorking,
    12431243    WantedProd, MinFood, MinProd, count, Take, MaxTake, AreaSize, FormulaCode,
    12441244    NeedRare, RareTiles, cix1, dx, dy, BestTiles, ProdBeforeBoost, TestTiles,
    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;
     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;
    12511251  TileInfo, BaseTileInfo: TTileInfo;
    12521252  Radius, Radius1: TVicinity21Loc;
     
    12551255  CityAreaInfo: TCityAreaInfo;
    12561256  Hierarchy: array [0 .. 20, 0 .. 31] of TTileData;
    1257   nTile, nSelection: array [0 .. 20] of integer;
    1258   SubCriterion: array [0 .. 27] of integer;
    1259   FoodWasted, FoodToTax, ProdToTax, RareOK, NeedStep2, IsBest: boolean;
    1260 begin
    1261   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)
    12621262  then
    12631263  begin
     
    12651265    Advice.Tiles := 1 shl CityOwnTile;
    12661266    Advice.CityReport.HypoTiles := 1 shl CityOwnTile;
    1267     exit;
    1268   end;
    1269 
    1270   for i := oFood to oScience do
     1267    Exit;
     1268  end;
     1269
     1270  for I := oFood to oScience do
    12711271  begin // decode evaluation formula from weights parameter
    1272     FormulaCode := Advice.ResourceWeights shr (24 - 8 * i) and $FF;
    1273     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;
    12741274    if FormulaCode and $40 <> 0 then
    1275       ValueFormula_Weight[i] := (FormulaCode and $0F) *
     1275      ValueFormula_Weight[I] := (FormulaCode and $0F) *
    12761276        (1 shl (FormulaCode and $30 shr 4)) / 16
    12771277    else
    1278       ValueFormula_Weight[i] := (FormulaCode and $0F) *
     1278      ValueFormula_Weight[I] := (FormulaCode and $0F) *
    12791279        (1 shl (FormulaCode and $30 shr 4));
    12801280  end;
     
    12831283  TestReport.HypoTax := -1;
    12841284  TestReport.HypoLux := -1;
    1285   GetSmallCityReport(p, cix, TestReport, @CityReportEx);
    1286   with RW[p].City[cix] do
     1285  GetSmallCityReport(P, cix, TestReport, @CityReportEx);
     1286  with RW[P].City[cix] do
    12871287  begin
    12881288    V21_to_Loc(Loc, Radius);
    1289     FoodToTax := RW[p].Government = gFuture;
     1289    FoodToTax := RW[P].Government = gFuture;
    12901290    ProdToTax := Project and (cpImp + cpIndex) = cpImp + imTrGoods;
    1291     FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[p]]) and
    1292       not CanCityGrow(p, cix);
     1291    FoodWasted := not FoodToTax and (Food = StorageSize[Difficulty[P]]) and
     1292      not CanCityGrow(P, cix);
    12931293
    12941294    // sub criteria
     
    13001300          V21 xor $15;
    13011301    end;
    1302     for cix1 := 0 to RW[p].nCity - 1 do
     1302    for cix1 := 0 to RW[P].nCity - 1 do
    13031303      if cix1 <> cix then
    13041304      begin
    1305         Loc1 := RW[p].City[cix1].Loc;
     1305        Loc1 := RW[P].City[cix1].Loc;
    13061306        if Loc1 >= 0 then
    13071307        begin
     
    13161316              begin
    13171317                dxdy(Loc, Loc1, dx, dy);
    1318                 dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160);
     1318                Dec(SubCriterion[(dy + 3) shl 2 + (dx + 3) shr 1], 160);
    13191319              end;
    13201320            end;
     
    13231323      end;
    13241324
    1325     GetCityAreaInfo(p, Loc, CityAreaInfo);
     1325    GetCityAreaInfo(P, Loc, CityAreaInfo);
    13261326    AreaSize := 0;
    13271327    for V21 := 1 to 26 do
    13281328      if CityAreaInfo.Available[V21] = faAvailable then
    1329         inc(AreaSize);
    1330 
    1331     if RW[p].Government = gFundamentalism then
     1329        Inc(AreaSize);
     1330
     1331    if RW[P].Government = gFundamentalism then
    13321332    begin
    13331333      MinWorking := Size;
     
    13391339      if MinWorking > Size then
    13401340        MinWorking := Size;
    1341       if (RW[p].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury
     1341      if (RW[P].LuxRate = 0) and not CityReportEx.TradeProcessing.FlexibleLuxury
    13421342      then
    13431343        MaxWorking := MinWorking
     
    13761376        Loc1 := Radius[V21];
    13771377        if (Loc1 >= 0) and (Loc1 < MapSize) and
    1378           (RealMap[Loc1] and fModern = cardinal(NeedRare)) then
     1378          (RealMap[Loc1] and fModern = Cardinal(NeedRare)) then
    13791379          RareTiles := RareTiles or (1 shl V21);
    13801380      end;
     
    13881388      begin
    13891389        Loc1 := Radius[V21];
    1390         assert((Loc1 >= 0) and (Loc1 < MapSize));
    1391         GetTileInfo(p, cix, Loc1, TileInfo);
     1390        Assert((Loc1 >= 0) and (Loc1 < MapSize));
     1391        GetTileInfo(P, cix, Loc1, TileInfo);
    13921392        if V21 = CityOwnTile then
    13931393          BaseTileInfo := TileInfo
     
    14051405              (TileInfo.Trade = Hierarchy[iH, iT].Trade) and
    14061406              (SubCriterion[V21] >= SubCriterion[Hierarchy[iH, iT].V21])) do
    1407               inc(iT);
     1407              Inc(iT);
    14081408            if (iT = nTile[iH]) // new worst tile in this hierarchy
    14091409              or ((TileInfo.Food >= Hierarchy[iH, iT].Food)
     
    14111411              and (TileInfo.Prod >= Hierarchy[iH, iT].Prod) and
    14121412              (TileInfo.Trade >= Hierarchy[iH, iT].Trade)) then
    1413               break; // insert position found!
    1414             inc(iH);
     1413              Break; // insert position found!
     1414            Inc(iH);
    14151415          end;
    14161416          if iH = nHierarchy then
    14171417          begin // need to start new hierarchy
    14181418            nTile[iH] := 0;
    1419             inc(nHierarchy);
     1419            Inc(nHierarchy);
    14201420            iT := 0;
    14211421          end;
    1422           move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1],
     1422          Move(Hierarchy[iH, iT], Hierarchy[iH, iT + 1],
    14231423            (nTile[iH] - iT) * SizeOf(TTileData));
    1424           inc(nTile[iH]);
     1424          Inc(nTile[iH]);
    14251425          Hierarchy[iH, iT].V21 := V21;
    14261426          Hierarchy[iH, iT].Food := TileInfo.Food;
     
    14381438        begin
    14391439          Loc1 := Radius[V21];
    1440           assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize));
    1441           GetTileInfo(p, cix, Loc1, TileInfo);
     1440          Assert((V21 <> CityOwnTile) and (Loc1 >= 0) and (Loc1 < MapSize));
     1441          GetTileInfo(P, cix, Loc1, TileInfo);
    14421442          if iH = nHierarchy then
    14431443          begin // need to start new hierarchy
    14441444            nTile[iH] := 0;
    1445             inc(nHierarchy);
     1445            Inc(nHierarchy);
    14461446            iT := 0;
    14471447          end
    14481448          else
    14491449            iT := nTile[iH];
    1450           inc(nTile[iH]);
     1450          Inc(nTile[iH]);
    14511451          Hierarchy[iH, iT].V21 := V21;
    14521452          Hierarchy[iH, iT].Food := TileInfo.Food; // = 0
     
    14571457    end;
    14581458    if Built[imAlgae] > 0 then
    1459       inc(BaseTileInfo.Food, 12);
     1459      Inc(BaseTileInfo.Food, 12);
    14601460
    14611461    // step 2: summarize resources
    14621462    for iH := 0 to nHierarchy - 1 do
    14631463    begin
    1464       move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData));
     1464      Move(Hierarchy[iH, 0], Hierarchy[iH, 1], nTile[iH] * SizeOf(TTileData));
    14651465      Hierarchy[iH, 0].Food := 0;
    14661466      Hierarchy[iH, 0].Prod := 0;
     
    14701470      for iT := 1 to nTile[iH] do
    14711471      begin
    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);
     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);
    14761476        Hierarchy[iH, iT].V21 := 1 shl Hierarchy[iH, iT].V21 +
    14771477          Hierarchy[iH, iT - 1].V21;
     
    15011501        (ProdBeforeBoost < WantedProd)) do
    15021502      begin
    1503         assert(nSelection[iH] = 0);
     1503        Assert(nSelection[iH] = 0);
    15041504        Take := MinWorking - TestReport.Working;
    15051505        if Take > nTile[iH] then
     
    15141514          while (Take < MaxTake) and
    15151515            (TestReport.FoodRep + Hierarchy[iH, Take].Food < MinFood) do
    1516             inc(Take);
     1516            Inc(Take);
    15171517          while (Take < MaxTake) and
    15181518            (ProdBeforeBoost + Hierarchy[iH, Take].Prod < MinProd) do
    1519             inc(Take);
     1519            Inc(Take);
    15201520        end;
    15211521        nSelection[iH] := Take;
    1522         inc(TestReport.Working, Take);
     1522        Inc(TestReport.Working, Take);
    15231523        with Hierarchy[iH, Take] do
    15241524        begin
    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
     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
    15331533        (TestReport.Working <= MaxWorking));
    15341534      if (TestReport.FoodRep >= MinFood) and (ProdBeforeBoost >= MinProd) then
    15351535      begin
    1536         SplitTrade(TestReport.Trade, RW[p].TaxRate, RW[p].LuxRate,
     1536        SplitTrade(TestReport.Trade, RW[P].TaxRate, RW[P].LuxRate,
    15371537          TestReport.Working, CityReportEx.TradeProcessing,
    15381538          TestReport.Corruption, TestReport.Tax, TestReport.Lux,
     
    15431543          TestReport.Deployed >= Size then
    15441544        begin // city is not in disorder -- evaluate combination
    1545           inc(count);
     1545          Inc(count);
    15461546          if (MinProd < WantedProd) and (ProdBeforeBoost > MinProd) then
    15471547          begin // no combination reached wanted prod yet
     
    15911591              then
    15921592              begin
    1593                 inc(Output[oTax], Output[oFood]);
     1593                Inc(Output[oTax], Output[oFood]);
    15941594                Output[oFood] := 0;
    15951595              end;
     
    16031603              if NeedRare > 0 then
    16041604              begin
    1605                 RareOK := false;
     1605                RareOK := False;
    16061606                for iH := 0 to nHierarchy - 1 do
    16071607                  if Hierarchy[iH, nSelection[iH]].V21 and RareTiles <> 0 then
    1608                     RareOK := true;
     1608                    RareOK := True;
    16091609                if not RareOK then
    16101610                  TestReport.ProdRep := TestReport.Support;
     
    16131613              if ProdToTax then
    16141614              begin
    1615                 inc(Output[oTax], Output[oProd]);
     1615                Inc(Output[oTax], Output[oProd]);
    16161616                Output[oProd] := 0;
    16171617              end;
    16181618            end;
    16191619
    1620             NeedStep2 := false;
     1620            NeedStep2 := False;
    16211621            Value := 0;
    1622             for i := oFood to oScience do
    1623               if ValueFormula_Multiply[i] then
    1624                 NeedStep2 := true
     1622            for I := oFood to oScience do
     1623              if ValueFormula_Multiply[I] then
     1624                NeedStep2 := True
    16251625              else
    1626                 Value := Value + ValueFormula_Weight[i] * Output[i];
     1626                Value := Value + ValueFormula_Weight[I] * Output[I];
    16271627            if NeedStep2 then
    16281628            begin
    16291629              if Value > 0 then
    16301630                Value := ln(Value) + 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);
     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);
    16351635            end;
    16361636
     
    16431643              for iH := 0 to nHierarchy - 1 do
    16441644              begin
    1645                 inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21);
    1646                 inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue);
     1645                Inc(TestTiles, Hierarchy[iH, nSelection[iH]].V21);
     1646                Inc(SubValue, Hierarchy[iH, nSelection[iH]].SubValue);
    16471647              end;
    1648               IsBest := true;
     1648              IsBest := True;
    16491649              if (SuperPlus = 0) and (ValuePlus = 0.0) then
    16501650              begin
    16511651                SubPlus := SubValue - BestSubValue;
    16521652                if SubPlus < 0 then
    1653                   IsBest := false
     1653                  IsBest := False
    16541654                else if SubPlus = 0 then
    16551655                begin
    1656                   assert(TestTiles <> BestTiles);
     1656                  Assert(TestTiles <> BestTiles);
    16571657                  IsBest := TestTiles > BestTiles
    16581658                end
     
    16791679        with Hierarchy[iH_Switch, nSelection[iH_Switch]] do
    16801680        begin
    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);
     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);
    16871687        if (nSelection[iH_Switch] <= nTile[iH_Switch]) and
    16881688          (TestReport.Working <= MaxWorking) then
     
    16901690          with Hierarchy[iH_Switch, nSelection[iH_Switch]] do
    16911691          begin
    1692             inc(TestReport.FoodRep, Food);
    1693             inc(ProdBeforeBoost, Prod);
    1694             inc(TestReport.Trade, Trade);
     1692            Inc(TestReport.FoodRep, Food);
     1693            Inc(ProdBeforeBoost, Prod);
     1694            Inc(TestReport.Trade, Trade);
    16951695          end;
    1696           break;
    1697         end;
    1698         dec(TestReport.Working, nSelection[iH_Switch]);
     1696          Break;
     1697        end;
     1698        Dec(TestReport.Working, nSelection[iH_Switch]);
    16991699        nSelection[iH_Switch] := 0;
    1700         inc(iH_Switch);
     1700        Inc(iH_Switch);
    17011701      until iH_Switch = nHierarchy;
    17021702    until iH_Switch = nHierarchy; // everything tested -- done
    17031703  end;
    1704   assert(BestSuperValue > 0); // advice should always be possible
     1704  Assert(BestSuperValue > 0); // advice should always be possible
    17051705  Advice.Tiles := BestTiles;
    17061706  Advice.CityReport.HypoTiles := BestTiles;
     
    17131713procedure InitGame;
    17141714var
    1715   p, i, mixTownGuard: integer;
     1715  P, I, mixTownGuard: Integer;
    17161716begin
    17171717  MaxDist := Distance(0, MapSize - lx shr 1);
    1718   for p := 0 to nPl - 1 do
    1719     if (1 shl p and GAlive <> 0) then
    1720       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
    17211721      begin // initialize capital
    17221722        mixTownGuard := 0;
    17231723        while Model[mixTownGuard].Kind <> mkSpecial_TownGuard do
    1724           inc(mixTownGuard);
     1724          Inc(mixTownGuard);
    17251725        with City[0] do
    17261726        begin
    17271727          Built[imPalace] := 1;
    17281728          Size := 4;
    1729           for i := 2 to Size do
    1730             AddBestCityTile(p, 0);
     1729          for I := 2 to Size do
     1730            AddBestCityTile(P, 0);
    17311731          Project := mixTownGuard;
    17321732        end;
  • trunk/CmdList.pas

    r438 r447  
    1010  MaxDataSize = 1024;
    1111  CommandDataElementSize = 4;
    12   CommandDataElementCountMask = $f;
     12  CommandDataElementCountMask = $F;
    1313  CommandDataMaxSize = CommandDataElementSize * CommandDataElementCountMask;
    1414
     
    2727    constructor Create;
    2828    destructor Destroy; override;
    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);
     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);
    3737    procedure Cut;
    38     function Progress: integer;
     38    function Progress: Integer;
    3939  private
    40     LogAlloc: integer; { allocated size of LogData in bytes }
     40    LogAlloc: Integer; { allocated size of LogData in bytes }
    4141    LogData: ^TLogData;
    4242    FState: TCmdListState;
    43     procedure PutData(Data: pointer; Length: integer);
     43    procedure PutData(Data: Pointer; Length: Integer);
    4444    procedure CompleteMoveCode;
    4545  public
     
    9292end;
    9393
    94 procedure TCmdList.Get(var Command, Player, Subject: integer; var Data: pointer);
     94procedure TCmdList.Get(var Command, Player, Subject: Integer; var Data: Pointer);
    9595var
    9696  DirCode: Cardinal;
     
    127127  else
    128128  begin
    129     code := Cardinal((@LogData[FState.LoadPos])^);
    130     if code and 3 = 0 then
     129    Code := Cardinal((@LogData[FState.LoadPos])^);
     130    if Code and 3 = 0 then
    131131    begin // non-clientex command
    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
     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
    138138    begin // clientex command
    139       Command := code shr 3 and $FFFF;
    140       Player := code shr 19 and $F;
     139      Command := Code shr 3 and $FFFF;
     140      Player := Code shr 19 and $F;
    141141      Subject := 0;
    142       inc(FState.LoadPos, 3);
     142      Inc(FState.LoadPos, 3);
    143143    end
    144144    else
    145145    begin // move command shortcut
    146       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
    147147      begin
    148         FState.LoadMoveCode := code and $FF;
    149         inc(FState.LoadPos);
     148        FState.LoadMoveCode := Code and $FF;
     149        Inc(FState.LoadPos);
    150150      end
    151151      else
    152152      begin
    153         FState.LoadMoveCode := code and $FFFFFF;
    154         inc(FState.LoadPos, 3);
     153        FState.LoadMoveCode := Code and $FFFFFF;
     154        Inc(FState.LoadPos, 3);
    155155      end;
    156156      Get(Command, Player, Subject, Data);
     
    163163    begin
    164164      Data := @LogData[FState.LoadPos];
    165       inc(FState.LoadPos, Command and CommandDataElementCountMask * CommandDataElementSize);
    166     end;
    167   end;
    168 end;
    169 
    170 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);
    171171var
    172   b0, b1: integer;
     172  b0, b1: Integer;
    173173  Map0, Map1: Cardinal;
    174174begin
    175175  Map0 := Cardinal((@LogData[FState.LoadPos])^);
    176   inc(FState.LoadPos, 4);
     176  Inc(FState.LoadPos, 4);
    177177  b0 := 0;
    178178  while Map0 > 0 do begin
    179179    if Map0 and 1 <> 0 then begin
    180180      Map1 := Cardinal((@LogData[FState.LoadPos])^);
    181       inc(FState.LoadPos, 4);
     181      Inc(FState.LoadPos, 4);
    182182      for b1 := 0 to 31 do
    183183        if 1 shl b1 and Map1 <> 0 then begin
    184184          if b0 * 32 + b1 < DataSize then
    185185            PData(Data)[b0 * 32 + b1] := Cardinal((@LogData[FState.LoadPos])^);
    186           inc(FState.LoadPos, 4);
     186          Inc(FState.LoadPos, 4);
    187187        end;
    188188    end;
    189     inc(b0);
     189    Inc(b0);
    190190    Map0 := Map0 shr 1;
    191191  end;
    192192end;
    193193
    194 procedure TCmdList.Put(Command, Player, Subject: integer; Data: pointer);
     194procedure TCmdList.Put(Command, Player, Subject: Integer; Data: Pointer);
    195195var
    196   DirCode, code: Cardinal;
     196  DirCode, Code: Cardinal;
    197197begin
    198198  if Command and $FC00 = sMoveUnit then
     
    209209    end;
    210210    if Subject = FState.LastMovingUnit then
    211       code := 1 + DirCode shl 1
    212     else
    213       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;
    214214    if FState.MoveCode = 0 then
    215       FState.MoveCode := code
     215      FState.MoveCode := Code
    216216    else if FState.MoveCode and 1 = 1 then
    217217    begin // FM + this
    218       FState.MoveCode := FState.MoveCode + code shl 4;
    219       if code and 1 = 1 then
     218      FState.MoveCode := FState.MoveCode + Code shl 4;
     219      if Code and 1 = 1 then
    220220        PutData(@FState.MoveCode, 1) // FM + FM
    221221      else
     
    223223      FState.MoveCode := 0;
    224224    end
    225     else if code and 1 = 1 then
     225    else if Code and 1 = 1 then
    226226    begin // M + FM
    227       FState.MoveCode := FState.MoveCode + code shl 18;
     227      FState.MoveCode := FState.MoveCode + Code shl 18;
    228228      PutData(@FState.MoveCode, 3);
    229229      FState.MoveCode := 0;
     
    232232    begin
    233233      PutData(@FState.MoveCode, 3);
    234       FState.MoveCode := code;
     234      FState.MoveCode := Code;
    235235    end;
    236236    FState.LastMovingUnit := Subject;
     
    241241    if Command >= cClientEx then
    242242    begin
    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 +
     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 +
    249249        Cardinal(Subject) shl 20;
    250       PutData(@code, 4);
     250      PutData(@Code, 4);
    251251    end;
    252252  end;
     
    255255end;
    256256
    257 procedure TCmdList.PutDataChanges(Command, Player: integer;
    258   OldData, NewData: pointer; DataSize: integer);
     257procedure TCmdList.PutDataChanges(Command, Player: Integer;
     258  OldData, NewData: Pointer; DataSize: Integer);
    259259var
    260   MapPos, LogPos, b0, b1, RowEnd: integer;
    261   Map0, Map1, code: Cardinal;
     260  MapPos, LogPos, b0, b1, RowEnd: Integer;
     261  Map0, Map1, Code: Cardinal;
    262262begin
    263263  if DataSize <= 0 then
    264     exit;
     264    Exit;
    265265  if DataSize > MaxDataSize then
    266266    DataSize := MaxDataSize;
     
    273273    if LogPos + 4 * 32 > LogAlloc then
    274274    begin
    275       inc(LogAlloc, LogGrow);
     275      Inc(LogAlloc, LogGrow);
    276276      ReallocMem(LogData, LogAlloc);
    277277    end;
     
    287287      begin
    288288        Cardinal((@LogData[LogPos])^) := PData(NewData)[b1];
    289         inc(LogPos, 4);
    290         inc(Map1, $80000000);
     289        Inc(LogPos, 4);
     290        Inc(Map1, $80000000);
    291291      end;
    292292    end;
     
    296296      Cardinal((@LogData[MapPos])^) := Map1;
    297297      MapPos := LogPos;
    298       inc(LogPos, 4);
    299       inc(Map0, $80000000);
     298      Inc(LogPos, 4);
     299      Inc(Map0, $80000000);
    300300    end;
    301301  end;
    302302  if Map0 = 0 then
    303     exit; // no changes
     303    Exit; // no changes
    304304
    305305  Map0 := Map0 shr (31 - (DataSize - 1) div 32);
    306306  Cardinal((@LogData[FState.nLog + 4])^) := Map0;
    307   code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16;
    308   Cardinal((@LogData[FState.nLog])^) := code;
     307  Code := Cardinal(Command - sExecute) shl 2 + Cardinal(Player) shl 16;
     308  Cardinal((@LogData[FState.nLog])^) := Code;
    309309  FState.nLog := MapPos;
    310310end;
    311311
    312 procedure TCmdList.PutData(Data: pointer; Length: integer);
     312procedure TCmdList.PutData(Data: Pointer; Length: Integer);
    313313begin
    314314  if FState.nLog + Length > LogAlloc then
    315315  begin
    316     inc(LogAlloc, LogGrow);
     316    Inc(LogAlloc, LogGrow);
    317317    ReallocMem(LogData, LogAlloc);
    318318  end;
    319   move(Data^, LogData[FState.nLog], Length);
    320   inc(FState.nLog, Length);
     319  Move(Data^, LogData[FState.nLog], Length);
     320  Inc(FState.nLog, Length);
    321321end;
    322322
     
    333333end;
    334334
    335 procedure TCmdList.LoadFromFile(const f: TFileStream);
    336 begin
    337   f.read(FState.nLog, 4);
     335procedure TCmdList.LoadFromFile(const F: TFileStream);
     336begin
     337  F.read(FState.nLog, 4);
    338338  LogData := nil;
    339339  LogAlloc := ((FState.nLog + 2) div LogGrow + 1) * LogGrow;
    340340  ReallocMem(LogData, LogAlloc);
    341   f.read(LogData^, FState.nLog);
     341  F.read(LogData^, FState.nLog);
    342342  FState.LoadPos := 0;
    343343end;
    344344
    345 procedure TCmdList.SaveToFile(const f: TFileStream);
     345procedure TCmdList.SaveToFile(const F: TFileStream);
    346346begin
    347347  CompleteMoveCode;
    348   f.write(FState.nLog, 4);
    349   f.write(LogData^, FState.nLog);
    350 end;
    351 
    352 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;
    353353  const OldState: TCmdListState);
    354354begin
    355355  CompleteMoveCode;
    356   f.write(FState.nLog, 4);
    357   f.Position := f.Position + OldState.nLog;
    358   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);
    359359end;
    360360
     
    364364end;
    365365
    366 function TCmdList.Progress: integer;
     366function TCmdList.Progress: Integer;
    367367begin
    368368  if (FState.LoadPos = FState.nLog) and (FState.LoadMoveCode = 0) then
    369     result := 1000 // loading complete
     369    Result := 1000 // loading complete
    370370  else if FState.nLog > 1 shl 20 then
    371     result := (FState.LoadPos shr 8) * 999 div (FState.nLog shr 8)
     371    Result := (FState.LoadPos shr 8) * 999 div (FState.nLog shr 8)
    372372  else
    373     result := FState.LoadPos * 999 div FState.nLog;
     373    Result := FState.LoadPos * 999 div FState.nLog;
    374374end;
    375375
     
    379379  Byte3    Byte2    Byte1    Byte0
    380380  ssssssss sssspppp cccccccc cccccc00
    381   (c = Command-sExecute, p = Player, s = Subject)
     381  (C = Command-sExecute, P = Player, S = Subject)
    382382
    383383  ClientEx-Command:
    384384  Byte2    Byte1    Byte0
    385385  0ppppccc cccccccc ccccc010
    386   (c = Command, p = Player)
     386  (C = Command, P = Player)
    387387
    388388  Single Move:
    389389  Byte2    Byte1    Byte0
    390390  000000ss ssssssss ssaaa110
    391   (a = Direction, s = Subject)
     391  (A = Direction, S = Subject)
    392392
    393393  Move + Follow Move:
    394394  Byte2    Byte1    Byte0
    395395  00bbb1ss ssssssss ssaaa110
    396   (a = Direction 1, s = Subject 1, b = Direction 2)
     396  (A = Direction 1, S = Subject 1, B = Direction 2)
    397397
    398398  Follow Move + Move:
    399399  Byte2    Byte1    Byte0
    400400  00ssssss ssssssbb b110aaa1
    401   (a = Direction 1, b = Direction 2, s = Subject 2)
     401  (A = Direction 1, B = Direction 2, S = Subject 2)
    402402
    403403  Single Follow Move:
    404404  Byte0
    405405  0000aaa1
    406   (a = Direction)
     406  (A = Direction)
    407407
    408408  Double Follow Move:
    409409  Byte0
    410410  bbb1aaa1
    411   (a = Direction 1, b = Direction 2)
     411  (A = Direction 1, B = Direction 2)
    412412}
    413413
  • trunk/Database.pas

    r442 r447  
    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;
    172172
    173173
     
    180180
    181181var
    182   UnBuilt: array [0 .. nPl - 1] of integer; { number of units built }
    183 
    184 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);
    185185var
    186186  I: Integer;
    187187begin
    188188  for I := 0 to Count - 1 do
    189     x[I] := x[I] and Mask;
    190 end;
    191 
    192 procedure CompactLists(p: integer);
    193 var
    194   uix, uix1, cix: integer;
    195 {$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;
    196196  Radius: TVicinity21Loc; {$ENDIF}
    197197begin
    198   with RW[p] do
     198  with RW[P] do
    199199  begin
    200200    // compact unit list
     
    203203      if Un[uix].Loc < 0 then
    204204      begin
    205         dec(nUn);
     205        Dec(nUn);
    206206        Un[uix] := Un[nUn]; { replace removed unit by last }
    207207        if (Un[uix].TroopLoad > 0) or (Un[uix].AirLoad > 0) then
     
    212212      end
    213213      else
    214         inc(uix);
     214        Inc(uix);
    215215
    216216    // compact city list
     
    219219      if City[cix].Loc < 0 then
    220220      begin
    221         dec(nCity);
     221        Dec(nCity);
    222222        City[cix] := City[nCity]; { replace city by last }
    223223        for uix1 := 0 to nUn - 1 do
     
    227227      end
    228228      else
    229         inc(cix);
     229        Inc(cix);
    230230
    231231    // compact enemy city list
     
    234234      if EnemyCity[cix].Loc < 0 then
    235235      begin
    236         dec(nEnemyCity);
     236        Dec(nEnemyCity);
    237237        EnemyCity[cix] := EnemyCity[nEnemyCity]; { replace city by last }
    238238      end
    239239      else
    240         inc(cix);
     240        Inc(cix);
    241241
    242242{$IFOPT O-}
     
    247247        for V21 := 1 to 26 do
    248248          if Tiles and (1 shl V21) <> 0 then
    249             assert(UsedByCity[Radius[V21]] = Loc);
     249            Assert(UsedByCity[Radius[V21]] = Loc);
    250250      end;
    251251{$ENDIF}
     
    257257  ____________________________________________________________________
    258258}
    259 function TechBaseCost(nTech, diff: integer): integer;
    260 var
    261   c0: single;
     259function TechBaseCost(nTech, diff: Integer): Integer;
     260var
     261  c0: Single;
    262262begin
    263263  c0 := TechFormula_M[diff] * (nTech + 4) *
    264264    exp((nTech + 4) / TechFormula_D[diff]);
    265265  if c0 >= $10000000 then
    266     result := $10000000
     266    Result := $10000000
    267267  else
    268     result := trunc(c0);
    269 end;
    270 
    271 function TechCost(p: integer): integer;
    272 begin
    273   with RW[p] do
    274   begin
    275     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]);
    276276    if ResearchTech >= 0 then
    277277      if (ResearchTech = adMilitary) or (Tech[ResearchTech] = tsSeen) then
    278         result := result shr 1
     278        Result := Result shr 1
    279279      else if ResearchTech in FutureTech then
    280280        if Government = gFuture then
    281           result := result * 2
     281          Result := Result * 2
    282282        else
    283           result := result * 4;
    284   end;
    285 end;
    286 
    287 procedure SetModelFlags(var m: TModel);
    288 begin
    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;
    296 end;
    297 
    298 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);
    299299{ calculate attack, defense, cost... of a model by features }
    300300var
    301   i: integer;
    302 begin
    303   with m do
     301  I: Integer;
     302begin
     303  with M do
    304304  begin
    305305    Attack := (Cap[mcOffense] + Cap[mcOver]) * MStrength;
     
    312312          Speed := 350 + 200 * Cap[mcNP] + 200 * Cap[mcTurbines];
    313313          if Cap[mcNP] = 0 then
    314             inc(Speed, 100 * Cap[mcSE]);
     314            Inc(Speed, 100 * Cap[mcSE]);
    315315        end;
    316316      dAir:
     
    318318    end;
    319319    Cost := 0;
    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);
     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);
    323323    Cost := Cost * MCost;
    324324    Weight := 0;
    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)
     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)
    329329        else
    330           inc(Weight, Cap[i] * Feature[i].Weight);
    331   end;
    332   SetModelFlags(m);
    333 end;
    334 
    335 procedure CheckSpecialModels(p, pre: integer);
    336 var
    337   i, mix1: integer;
    338   HasAlready: boolean;
    339 begin
    340   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 -
    341341    1 do { check whether new special model available }
    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;
     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;
    350350      if not HasAlready then
    351351      begin
    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
     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
    355355        begin
    356356          Status := 0;
     
    359359          Built := 0;
    360360          Lost := 0;
    361           ID := p shl 12 + RW[p].nModel;
    362           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
    363363            Speed := 350; // old longboat
    364364        end;
    365         inc(RW[p].nModel);
    366       end;
    367     end;
    368 end;
    369 
    370 procedure EnableDevModel(p: integer);
    371 begin
    372   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
    373373    if nModel < nmmax then
    374374    begin
     
    381381        Built := 0;
    382382        Lost := 0;
    383         ID := p shl 12 + nModel;
    384       end;
    385       inc(nModel);
    386       inc(Researched[p]);
    387     end;
    388 end;
    389 
    390 procedure SeeTech(p, ad: integer);
    391 begin
    392 {$IFDEF TEXTLOG}CmdInfo := CmdInfo + Format(' P%d:A%d', [p, ad]); {$ENDIF}
    393   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;
    394394  // inc(nTech[p]);
    395   inc(Researched[p]);
     395  Inc(Researched[P]);
    396396end;
    397397
    398398procedure FreeSlaves;
    399399var
    400   p1, uix: integer;
     400  p1, uix: Integer;
    401401begin
    402402  for p1 := 0 to nPl - 1 do
     
    407407end;
    408408
    409 procedure DiscoverTech(p, ad: integer);
    410 
    411   procedure TellAboutKeyTech(p, Source: integer);
     409procedure DiscoverTech(P, ad: Integer);
     410
     411  procedure TellAboutKeyTech(P, Source: Integer);
    412412  var
    413     i, p1: integer;
    414   begin
    415     for i := 1 to 3 do
    416       if ad = AgePreq[i] then
     413    I, p1: Integer;
     414  begin
     415    for I := 1 to 3 do
     416      if ad = AgePreq[I] then
    417417        for p1 := 0 to nPl - 1 do
    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 
    422 var
    423   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;
    424424begin
    425425  if ad in FutureTech then
    426426  begin
    427     if RW[p].Tech[ad] < tsApplicable then
    428       RW[p].Tech[ad] := 1
     427    if RW[P].Tech[ad] < tsApplicable then
     428      RW[P].Tech[ad] := 1
    429429    else
    430       inc(RW[p].Tech[ad]);
     430      Inc(RW[P].Tech[ad]);
    431431    if ad <> futResearchTechnology then
    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]);
     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]);
    441441  end
    442442  else
    443443  begin
    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);
     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);
    450450  if ad = adScience then
    451     ResourceMask[p] := ResourceMask[p] or fSpecial2;
     451    ResourceMask[P] := ResourceMask[P] or fSpecial2;
    452452  if ad = adMassProduction 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
     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
    461461        FreeSlaves;
    462462    end;
    463463end;
    464464
    465 procedure CheckExpiration(Wonder: integer);
     465procedure CheckExpiration(Wonder: Integer);
    466466// GWonder[Wonder].EffectiveOwner must be set before!
    467467var
    468   p: integer;
     468  P: Integer;
    469469begin
    470470  if (Imp[Wonder].Expiration >= 0) and
    471471    (GWonder[woEiffel].EffectiveOwner <> GWonder[Wonder].EffectiveOwner) 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
     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
    475475      begin
    476476        GWonder[Wonder].EffectiveOwner := -1;
     
    484484  ____________________________________________________________________
    485485}
    486 function dLoc(Loc, dx, dy: integer): integer;
     486function dLoc(Loc, dx, dy: Integer): Integer;
    487487{ relative location, dx in hor and dy in ver direction from Loc }
    488488var
    489   y0: integer;
     489  y0: Integer;
    490490begin
    491491  if not (Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0) then
    492492    raise Exception.Create('Relative location error');
    493   assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));
     493  Assert((Loc >= 0) and (Loc < MapSize) and (dx + lx >= 0));
    494494  y0 := Loc div lx;
    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;
    498 end;
    499 
    500 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);
    501501begin
    502502  dx := ((Loc1 mod lx * 2 + Loc1 div lx and 1) -
     
    505505end;
    506506
    507 function Distance(Loc0, Loc1: integer): integer;
    508 var
    509   dx, dy: integer;
     507function Distance(Loc0, Loc1: Integer): Integer;
     508var
     509  dx, dy: Integer;
    510510begin
    511511  dxdy(Loc0, Loc1, dx, dy);
    512512  dx := abs(dx);
    513513  dy := abs(dy);
    514   result := dx + dy + abs(dx - dy) shr 1;
    515 end;
    516 
    517 procedure V8_to_Loc(Loc0: integer; var VicinityLoc: TVicinity8Loc);
    518 var
    519   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;
    520520begin
    521521  lx0 := lx; // put in register!
     
    527527  VicinityLoc[5] := Loc0 - lx0 * 2;
    528528  VicinityLoc[7] := Loc0 + 1;
    529   inc(Loc0, y0);
     529  Inc(Loc0, y0);
    530530  VicinityLoc[0] := Loc0 + lx0;
    531531  VicinityLoc[2] := Loc0 + lx0 - 1;
     
    538538    if x0 = 0 then
    539539    begin
    540       inc(VicinityLoc[3], lx0);
     540      Inc(VicinityLoc[3], lx0);
    541541      if y0 = 0 then
    542542      begin
    543         inc(VicinityLoc[2], lx0);
    544         inc(VicinityLoc[4], lx0);
     543        Inc(VicinityLoc[2], lx0);
     544        Inc(VicinityLoc[4], lx0);
    545545      end;
    546546    end;
     
    548548  else
    549549  begin
    550     dec(VicinityLoc[7], lx0);
     550    Dec(VicinityLoc[7], lx0);
    551551    if y0 = 1 then
    552552    begin
    553       dec(VicinityLoc[0], lx0);
    554       dec(VicinityLoc[6], lx0);
    555     end;
    556   end;
    557 end;
    558 
    559 procedure V21_to_Loc(Loc0: integer; var VicinityLoc: TVicinity21Loc);
    560 var
    561   dx, dy, bit, y0, xComp, yComp, xComp0, xCompSwitch: integer;
    562   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;
    563563begin
    564564  y0 := Loc0 div lx;
     
    566566  xCompSwitch := xComp0 - 1 + y0 and 1;
    567567  if xComp0 < 0 then
    568     inc(xComp0, lx);
     568    Inc(xComp0, lx);
    569569  if xCompSwitch < 0 then
    570     inc(xCompSwitch, lx);
     570    Inc(xCompSwitch, lx);
    571571  xCompSwitch := xCompSwitch xor xComp0;
    572572  yComp := lx * (y0 - 3);
     
    583583      else
    584584        dst^ := -1;
    585       inc(xComp);
     585      Inc(xComp);
    586586      if xComp >= lx then
    587         dec(xComp, lx);
    588       inc(dst);
     587        Dec(xComp, lx);
     588      Inc(dst);
    589589      bit := bit shl 1;
    590590    end;
    591     inc(yComp, lx);
     591    Inc(yComp, lx);
    592592  end;
    593593end;
     
    598598}
    599599var
    600   primitive: integer;
    601   StartLoc, StartLoc2: array [0 .. nPl - 1] of integer; { starting coordinates }
     600  primitive: Integer;
     601  StartLoc, StartLoc2: array [0 .. nPl - 1] of Integer; { starting coordinates }
    602602  Elevation: array [0 .. lxmax * lymax - 1] of Byte; { map elevation }
    603   ElCount: array [Byte] of integer; { count of elevation occurance }
     603  ElCount: array [Byte] of Integer; { count of elevation occurance }
    604604
    605605procedure CalculatePrimitive;
    606606var
    607   i, j: integer;
     607  I, J: Integer;
    608608begin
    609609  primitive := 1;
    610   i := 2;
    611   while i * i <= MapSize + 1 do // test whether prime
    612   begin
    613     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
    614614      primitive := 0;
    615     inc(i);
     615    Inc(I);
    616616  end;
    617617
    618618  if primitive > 0 then
    619619    repeat
    620       inc(primitive);
    621       i := 1;
    622       j := 0;
     620      Inc(primitive);
     621      I := 1;
     622      J := 0;
    623623      repeat
    624         inc(j);
    625         i := i * primitive mod (MapSize + 1);
    626       until (i = 1) or (j = MapSize + 1);
    627     until j = MapSize;
    628 end;
    629 
    630 function MapGeneratorAvailable: boolean;
    631 begin
    632   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);
    633633end;
    634634
    635635procedure CreateElevation;
    636636const
    637   d = 64;
     637  D = 64;
    638638  Smooth = 0.049; { causes low amplitude of short waves }
    639639  Detail = 0.095; { causes short period of short waves }
     
    642642
    643643var
    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 }
     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 }
    649649  var
    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];
     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];
    656656    { x values effectively multiplied with 2 to get 2 horizantal periods
    657657      of the prime waves }
     
    659659
    660660begin
    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);
     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);
    670670  end;
    671671
     
    673673  FillChar(ElCount, SizeOf(ElCount), 0);
    674674  maxv := 0;
    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
     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
    689689      else
    690         Elevation[x + lx * y] := Round((v + 4) * 20);
    691       inc(ElCount[Elevation[x + lx * y]]);
     690        Elevation[X + lx * Y] := Round((V + 4) * 20);
     691      Inc(ElCount[Elevation[X + lx * Y]]);
    692692    end;
    693693end;
     
    695695procedure FindContinents;
    696696
    697   procedure ReplaceCont(a, b, Stop: integer);
     697  procedure ReplaceCont(A, B, Stop: Integer);
    698698  { replace continent name a by b }
    699699  // make sure always continent[loc]<=loc
    700700  var
    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 
    715 var
    716   x, y, Loc, Wrong: integer;
    717 begin
    718   for y := 1 to ly - 2 do
    719     for x := 0 to lx - 1 do
    720     begin
    721       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;
    722722      Continent[Loc] := -1;
    723723      if RealMap[Loc] and fTerrain >= fGrass then
    724724      begin
    725         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
    726726          Continent[Loc] := Continent[Loc - 2 * lx];
    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
     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
    734734          if Continent[Loc] = -1 then
    735735            Continent[Loc] := Continent[Loc - 1]
     
    742742
    743743  { connect continents due to round earth }
    744   for y := 1 to ly - 2 do
    745     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
    746746    begin
    747747      Wrong := -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)];
     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)];
    756756      if Wrong >= 0 then
    757         ReplaceCont(Wrong, Continent[lx * y], MapSize - 1);
     757        ReplaceCont(Wrong, Continent[lx * Y], MapSize - 1);
    758758    end;
    759759end;
     
    763763// must be done after FindContinents
    764764var
    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;
     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;
    770770  Adjacent: TVicinity8Loc;
    771771begin
     
    773773  repeat
    774774    FillChar(AreaCount, SizeOf(AreaCount), 0);
    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
     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
    783783          begin
    784             Loc0 := x + lx * y;
     784            Loc0 := X + lx * Y;
    785785            if RealMap[Loc0] and fTerrain >= fGrass then
    786786            begin
     
    792792                if (Loc1 >= 0) and (Loc1 < MapSize) and
    793793                  (RealMap[Loc1] and fTerrain < fGrass) then
    794                   inc(Cnt); // count adjacent water
     794                  Inc(Cnt); // count adjacent water
    795795              end;
    796796              if Cnt <= RareMaxWater then // inner land
    797797              begin
    798                 inc(AreaCount[xBlock, yBlock]);
     798                Inc(AreaCount[xBlock, yBlock]);
    799799                if DelphiRandom(AreaCount[xBlock, yBlock]) = 0 then
    800800                  RareByArea[xBlock, yBlock] := Loc0;
     
    805805    end;
    806806    totalrare := 0;
    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);
     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);
    812812  until totalrare >= 12;
    813813
     
    815815  begin // remove rarebyarea resources too close to each other
    816816    FillChar(RareAdjacent, SizeOf(RareAdjacent), 0);
    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
     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
    824824          begin
    825             inc(RareAdjacent[x, y]);
    826             inc(RareAdjacent[(x + 1) mod 8, y]);
     825            Inc(RareAdjacent[X, Y]);
     826            Inc(RareAdjacent[(X + 1) mod 8, Y]);
    827827          end;
    828           if y < 4 then
     828          if Y < 4 then
    829829          begin
    830             if (AreaCount[x, y + 1] > 0) and
    831               (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]])
    832832            then
    833833            begin
    834               inc(RareAdjacent[x, y]);
    835               inc(RareAdjacent[x, y + 1]);
     834              Inc(RareAdjacent[X, Y]);
     835              Inc(RareAdjacent[X, Y + 1]);
    836836            end;
    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
     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
    840840            begin
    841               inc(RareAdjacent[x, y]);
    842               inc(RareAdjacent[(x + 1) mod 8, y + 1]);
     841              Inc(RareAdjacent[X, Y]);
     842              Inc(RareAdjacent[(X + 1) mod 8, Y + 1]);
    843843            end;
    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
     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
    847847            begin
    848               inc(RareAdjacent[x, y]);
    849               inc(RareAdjacent[(x + 7) mod 8, y + 1]);
     848              Inc(RareAdjacent[X, Y]);
     849              Inc(RareAdjacent[(X + 7) mod 8, Y + 1]);
    850850            end;
    851851          end;
     
    854854    yworst := 0;
    855855    Cnt := 0;
    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])
     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])
    861861          then
    862862          begin
    863             xworst := x;
    864             yworst := y;
     863            xworst := X;
     864            yworst := Y;
    865865            Cnt := 1;
    866866          end
    867           else if (RareAdjacent[x, y] = RareAdjacent[xworst, yworst]) then
     867          else if (RareAdjacent[X, Y] = RareAdjacent[xworst, yworst]) then
    868868          begin
    869             inc(Cnt);
     869            Inc(Cnt);
    870870            if DelphiRandom(Cnt) = 0 then
    871871            begin
    872               xworst := x;
    873               yworst := y;
     872              xworst := X;
     873              yworst := Y;
    874874            end;
    875875          end;
    876876        end;
    877877    AreaCount[xworst, yworst] := 0;
    878     dec(totalrare);
     878    Dec(totalrare);
    879879  end;
    880880
    881881  Cnt := 0;
    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
     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
    892892      (fDesert or fDeadLands);
    893893    for dy := -1 to 1 do
     
    895895        if (dx + dy) and 1 = 0 then
    896896        begin
    897           Loc1 := dLoc(RareLoc[i], dx, dy);
     897          Loc1 := dLoc(RareLoc[I], dx, dy);
    898898          if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain = fMountains) then
    899899            RealMap[Loc1] := RealMap[Loc1] and not fTerrain or fHills;
    900900        end;
    901901  end;
    902   for i := 0 to 11 do
    903     for j := 0 to 11 do
    904       Dist[i, j] := Distance(RareLoc[i], RareLoc[j]);
     902  for I := 0 to 11 do
     903    for J := 0 to 11 do
     904      Dist[I, J] := Distance(RareLoc[I], RareLoc[J]);
    905905
    906906  ibest := 0;
     
    910910  begin
    911911    Cnt := 0;
    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
     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
    916916            if (Cnt > 0) and (Dist[iBest, jbest] >= MinDist) then
    917917            begin
    918               if Dist[i, j] >= MinDist then
     918              if Dist[I, J] >= MinDist then
    919919              begin
    920                 inc(Cnt);
     920                Inc(Cnt);
    921921                if DelphiRandom(Cnt) = 0 then
    922922                begin
    923                   iBest := i;
    924                   jbest := j;
     923                  iBest := I;
     924                  jbest := J;
    925925                end;
    926926              end;
    927927            end
    928             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
    929929            begin
    930               iBest := i;
    931               jbest := j;
     930              iBest := I;
     931              jbest := J;
    932932              Cnt := 1;
    933933            end;
     
    941941end;
    942942
    943 function CheckShore(Loc: integer): boolean;
    944 var
    945   Loc1, OldTile, V21: integer;
     943function CheckShore(Loc: Integer): Boolean;
     944var
     945  Loc1, OldTile, V21: Integer;
    946946  Radius: TVicinity21Loc;
    947947begin
    948   result := false;
     948  Result := False;
    949949  OldTile := RealMap[Loc];
    950950  if OldTile and fTerrain < fGrass then
     
    961961    end;
    962962    if (RealMap[Loc] xor Cardinal(OldTile)) and fTerrain <> 0 then
    963       result := true;
    964   end;
    965 end;
    966 
    967 function ActualSpecialTile(Loc: integer): Cardinal;
    968 begin
    969   result := SpecialTile(Loc, RealMap[Loc] and fTerrain, lx);
    970 end;
    971 
    972 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);
    973973const
    974974  ShHiHills = 6; { of land }
     
    981981  hotunification = 50; // min. 25
    982982
    983   Zone: array [0 .. 3, 2 .. 9] of single = { terrain distribution }
     983  Zone: array [0 .. 3, 2 .. 9] of Single = { terrain distribution }
    984984    ((0.25, 0, 0, 0.4, 0, 0, 0, 0.35), (0.55, 0, 0.1, 0, 0, 0, 0, 0.35),
    985985    (0.4, 0, 0.35, 0, 0, 0, 0, 0.25), (0, 0.7, 0, 0, 0, 0, 0, 0.3));
    986986  { Grs  Dst  Pra  Tun  - - - For }
    987987
    988   function RndLow(y: integer): Cardinal;
     988  function RndLow(Y: Integer): Cardinal;
    989989  { random lowland appropriate to climate }
    990990  var
    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;
     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;
    998998    end
    999999    else
    10001000    begin
    1001       z0 := 6 * (ly - 1 - y) div ly;
    1002       ZPlus := 6 * (ly - 1 - y) / ly - z0;
     1001      z0 := 6 * (ly - 1 - Y) div ly;
     1002      ZPlus := 6 * (ly - 1 - Y) / ly - z0;
    10031003    end;
    10041004    p0 := 1;
    1005     for i := 2 to 9 do
    1006     begin
    1007       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;
    10081008      { weight between zones z0 and z0+1 }
    1009       if DelphiRandom * p0 < p then
    1010       begin
    1011         RndLow := i;
     1009      if DelphiRandom * p0 < P then
     1010      begin
     1011        RndLow := I;
    10121012        Break;
    10131013      end;
    1014       p0 := p0 - p;
    1015     end;
    1016   end;
    1017 
    1018   function RunRiver(Loc0: integer): integer;
     1014      p0 := p0 - P;
     1015    end;
     1016  end;
     1017
     1018  function RunRiver(Loc0: Integer): Integer;
    10191019  { runs river from start point Loc0; return value: length }
    10201020  var
    1021     Dir, T, Loc, Loc1, Cost: integer;
     1021    Dir, T, Loc, Loc1, Cost: Integer;
    10221022    Q: TIPQ;
    1023     From: array [0 .. lxmax * lymax - 1] of integer;
    1024     Time: array [0 .. lxmax * lymax - 1] of integer;
    1025     OneTileLake: boolean;
     1023    From: array [0 .. lxmax * lymax - 1] of Integer;
     1024    Time: array [0 .. lxmax * lymax - 1] of Integer;
     1025    OneTileLake: Boolean;
    10261026  begin
    10271027    FillChar(Time, SizeOf(Time), 255); { -1 }
     
    10321032      if (RealMap[Loc] and fTerrain < fGrass) then
    10331033      begin
    1034         OneTileLake := true;
     1034        OneTileLake := True;
    10351035        for Dir := 0 to 3 do
    10361036        begin
    10371037          Loc1 := dLoc(Loc, Dir and 1 * 2 - 1, Dir shr 1 * 2 - 1);
    10381038          if (Loc1 >= 0) and (RealMap[Loc1] and fTerrain < fGrass) then
    1039             OneTileLake := false;
     1039            OneTileLake := False;
    10401040        end;
    10411041        if not OneTileLake then
     
    10621062    end;
    10631063    Loc1 := Loc;
    1064     result := 0;
     1064    Result := 0;
    10651065    while Loc <> Loc0 do
    10661066    begin
    10671067      Loc := From[Loc];
    1068       inc(result);
    1069     end;
    1070     if (result > 1) and ((result >= MinRivLen) or
     1068      Inc(Result);
     1069    end;
     1070    if (Result > 1) and ((Result >= MinRivLen) or
    10711071      (RealMap[Loc1] and fTerrain >= fGrass)) then
    10721072    begin
     
    10821082    end
    10831083    else
    1084       result := 0;
     1084      Result := 0;
    10851085    FreeAndNil(Q);
    10861086  end;
    10871087
    10881088var
    1089   x, y, n, Dir, plus, Count, Loc0, Loc1, bLand, bHills, bMountains, V8: integer;
    1090   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;
    10911091  Adjacent: TVicinity8Loc;
    10921092
     
    10971097  while plus < MapSize * LandMass * ShMountains div 10000 do
    10981098  begin
    1099     dec(bMountains);
    1100     inc(plus, ElCount[bMountains]);
     1099    Dec(bMountains);
     1100    Inc(plus, ElCount[bMountains]);
    11011101  end;
    11021102  Count := plus;
     
    11051105  while plus < MapSize * LandMass * ShHiHills div 10000 do
    11061106  begin
    1107     dec(bHills);
    1108     inc(plus, ElCount[bHills]);
    1109   end;
    1110   inc(Count, plus);
     1107    Dec(bHills);
     1108    Inc(plus, ElCount[bHills]);
     1109  end;
     1110  Inc(Count, plus);
    11111111  bLand := bHills;
    11121112  while Count < MapSize * LandMass div 100 do
    11131113  begin
    1114     dec(bLand);
    1115     inc(Count, ElCount[bLand]);
     1114    Dec(bLand);
     1115    Inc(Count, ElCount[bLand]);
    11161116  end;
    11171117
     
    11361136          (RealMap[Loc1] and fTerrain < fGrass) or
    11371137          (RealMap[Loc1] and fTerrain = fArctic) then
    1138           inc(Count); // count adjacent water
     1138          Inc(Count); // count adjacent water
    11391139      end;
    11401140      if Count = 8 then
     
    11481148      plus := MapSize;
    11491149    Loc0 := DelphiRandom(MapSize);
    1150     for n := 0 to plus - 1 do
     1150    for N := 0 to plus - 1 do
    11511151    begin
    11521152      if (RealMap[Loc0] and fTerrain >= fGrass) and (Loc0 >= lx) and
     
    11651165    CopyFrom[Loc0] := Loc0;
    11661166
    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
     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
    11731173      else
    1174         y := 3 * ly shr 1 - y;
    1175     Loc0 := lx * y + DelphiRandom(lx);
     1174        Y := 3 * ly shr 1 - Y;
     1175    Loc0 := lx * Y + DelphiRandom(lx);
    11761176    if RealMap[Loc0] and fTerrain = fGrass then
    11771177    begin
     
    12261226          if Loc1 >= 0 then
    12271227            if RealMap[Loc1] and fTerrain < fGrass then
    1228               inc(Count, 2);
     1228              Inc(Count, 2);
    12291229        end;
    12301230      end;
     
    12421242        if Loc1 >= 0 then
    12431243          if RealMap[Loc1] and fTerrain <> fDesert then
    1244             inc(Count);
     1244            Inc(Count);
    12451245      end;
    12461246      if Count >= 4 then
     
    12501250  for Loc0 := 0 to MapSize - 1 do
    12511251    CheckShore(Loc0); // change ocean to shore
    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
     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
    12591259        not fTerrain or fTundra;
    1260     RealMap[x + lx * (ly - 1)] := fArctic;
     1260    RealMap[X + lx * (ly - 1)] := fArctic;
    12611261  end;
    12621262
     
    12791279  CountGood: (cgBest, cgFlat, cgLand);
    12801280
    1281   function IsGoodTile(Loc: integer): boolean;
     1281  function IsGoodTile(Loc: Integer): Boolean;
    12821282  var
    1283     xLoc, yLoc: integer;
     1283    xLoc, yLoc: Integer;
    12841284  begin
    12851285    xLoc := Loc mod lx;
    12861286    yLoc := Loc div lx;
    12871287    if RealMap[Loc] and fDeadLands <> 0 then
    1288       result := false
     1288      Result := False
    12891289    else
    12901290      case CountGood of
    12911291        cgBest:
    1292           result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
     1292          Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
    12931293            fSwamp, fForest]) and Odd((lymax + xLoc - yLoc shr 1) shr 1 + xLoc +
    12941294            (yLoc + 1) shr 1);
    12951295        cgFlat:
    1296           result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
     1296          Result := (RealMap[Loc] and fTerrain in [fGrass, fPrairie, fTundra,
    12971297            fSwamp, fForest]);
    12981298        cgLand:
    1299           result := RealMap[Loc] and fTerrain >= fGrass;
     1299          Result := RealMap[Loc] and fTerrain >= fGrass;
    13001300      end;
    13011301  end;
     
    13051305
    13061306var
    1307   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,
    13081308    nsc, V21, V8, BestDist, TestDist, MinGood, nIrrLoc,
    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;
     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;
    13171317  Radius: TVicinity21Loc;
    13181318  Adjacent: TVicinity8Loc;
    1319   ok: boolean;
     1319  ok: Boolean;
    13201320
    13211321begin
     
    13231323  for p1 := 0 to nPl - 1 do
    13241324    if 1 shl p1 and GAlive <> 0 then
    1325       inc(nAlive);
     1325      Inc(nAlive);
    13261326  if nAlive = 0 then
    1327     exit;
     1327    Exit;
    13281328
    13291329  { count good tiles }
     
    13321332    if RealMap[Loc] and fTerrain = fGrass then
    13331333      if ActualSpecialTile(Loc) = 1 then
    1334         inc(ccount[Continent[Loc]], 3)
     1334        Inc(ccount[Continent[Loc]], 3)
    13351335      else
    1336         inc(ccount[Continent[Loc]], 2)
     1336        Inc(ccount[Continent[Loc]], 2)
    13371337    else if RealMap[Loc] and fTerrain in [fPrairie, fSwamp, fForest, fHills]
    13381338    then
    1339       inc(ccount[Continent[Loc]]);
     1339      Inc(ccount[Continent[Loc]]);
    13401340
    13411341  Loc := 0;
    13421342  while ccount[Loc] > 0 do
    1343     inc(Loc);
    1344   for i := 1 to nAlive do
    1345   begin
    1346     sc[i] := Loc;
    1347     sccount[i] := 1
     1343    Inc(Loc);
     1344  for I := 1 to nAlive do
     1345  begin
     1346    sc[I] := Loc;
     1347    sccount[I] := 1
    13481348  end;
    13491349  { init with zero size start continents, then search bigger ones }
     
    13561356        if p1 < nAlive + 1 then
    13571357          sc[p1] := sc[p1 - 1];
    1358         dec(p1);
     1358        Dec(p1);
    13591359      end;
    13601360      if p1 < nAlive + 1 then
     
    13631363  nsc := nAlive;
    13641364  repeat
    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
     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
    13711371      Break; // even least crowded continent is more crowded than smallest
    1372     inc(sccount[c]);
    1373     dec(nsc);
     1372    Inc(sccount[C]);
     1373    Dec(nsc);
    13741374  until sccount[nsc] > 1;
    13751375
     
    13771377  CountGood := cgBest;
    13781378  repeat
    1379     dec(MinGood);
     1379    Dec(MinGood);
    13801380    if (MinGood = 3) and (CountGood < cgLand) then // too demanding!
    13811381    begin
    1382       inc(CountGood);
     1382      Inc(CountGood);
    13831383      MinGood := 6;
    13841384    end;
    13851385    FillChar(nCityLoc, SizeOf(nCityLoc), 0);
    13861386    Loc := DelphiRandom(MapSize);
    1387     for i := 0 to MapSize - 1 do
     1387    for I := 0 to MapSize - 1 do
    13881388    begin
    13891389      if ((Loc >= 4 * lx) and (Loc < MapSize - 4 * lx) or (CountGood >= cgLand))
    13901390        and IsGoodTile(Loc) then
    13911391      begin
    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
     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
    13961396        begin
    13971397          CntGood := 1;
     
    14021402              Loc1 := Radius[V21];
    14031403              if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then
    1404                 inc(CntGood);
     1404                Inc(CntGood);
    14051405            end;
    14061406          if CntGood >= MinGood then
    14071407          begin
    1408             CityLoc[c, nCityLoc[c]] := Loc;
    1409             inc(nCityLoc[c]);
     1408            CityLoc[C, nCityLoc[C]] := Loc;
     1409            Inc(nCityLoc[C]);
    14101410          end;
    14111411        end;
     
    14141414    end;
    14151415
    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;
     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;
    14201420  until ok;
    14211421
    14221422  FineDistSQR := MapSize * LandMass * 9 div (nAlive * 100);
    14231423  p1 := 1;
    1424   for c := 1 to nsc do
     1424  for C := 1 to nsc do
    14251425  begin // for all start continents
    1426     if sccount[c] = 1 then
    1427       StartLoc0[p1] := CityLoc[c, DelphiRandom(nCityLoc[c])]
     1426    if sccount[C] = 1 then
     1427      StartLoc0[p1] := CityLoc[C, DelphiRandom(nCityLoc[C])]
    14281428    else
    14291429    begin
    14301430      BestDist := 0;
    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
     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
    14351435      begin
    14361436        MinDist := MaxInt;
    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
     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
    14411441        begin
    14421442          if nRest = 0 then
    14431443            Break;
    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
     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
    14491449          begin
    1450             TestDist := Distance(TestStartLoc[i], TestStartLoc[j]);
     1450            TestDist := Distance(TestStartLoc[I], TestStartLoc[J]);
    14511451            if TestDist < MinDist then
    14521452              MinDist := TestDist;
    14531453          end;
    1454           if i = sccount[c] - 1 then
     1454          if I = sccount[C] - 1 then
    14551455          begin
    1456             assert(MinDist > BestDist);
     1456            Assert(MinDist > BestDist);
    14571457            BestDist := MinDist;
    1458             for j := 0 to sccount[c] - 1 do
    1459               StartLoc0[p1 + j] := TestStartLoc[j];
     1458            for J := 0 to sccount[C] - 1 do
     1459              StartLoc0[p1 + J] := TestStartLoc[J];
    14601460          end
    14611461          else if BestDist > 0 then
    14621462          begin
    1463             j := 0;
    1464             while j < nRest do
     1463            J := 0;
     1464            while J < nRest do
    14651465            begin // remove all locs from rest which have too little distance to this one
    1466               TestDist := Distance(TestStartLoc[i], RestLoc[j]);
     1466              TestDist := Distance(TestStartLoc[I], RestLoc[J]);
    14671467              if TestDist <= BestDist then
    14681468              begin
    1469                 RestLoc[j] := RestLoc[nRest - 1];
    1470                 dec(nRest);
     1469                RestLoc[J] := RestLoc[nRest - 1];
     1470                Dec(nRest);
    14711471              end
    14721472              else
    1473                 inc(j);
     1473                Inc(J);
    14741474            end;
    14751475          end;
    14761476        end;
    1477         dec(n)
    1478       end;
    1479     end;
    1480     p1 := p1 + sccount[c]
     1477        Dec(N)
     1478      end;
     1479    end;
     1480    p1 := p1 + sccount[C]
    14811481  end;
    14821482
     
    14951495        if (Loc1 >= 0) and (Loc1 < MapSize) and IsGoodTile(Loc1) then
    14961496          if RealMap[Loc1] and fTerrain = fGrass then
    1497             inc(CntGoodGrass)
     1497            Inc(CntGoodGrass)
    14981498          else
    1499             inc(CntGood);
     1499            Inc(CntGood);
    15001500      end;
    15011501    for V21 := 1 to 26 do
     
    15291529        begin
    15301530          IrrLoc[nIrrLoc] := Loc1;
    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);
     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);
    15441544    end;
    15451545  end;
     
    15501550    begin
    15511551      repeat
    1552         i := DelphiRandom(nAlive) + 1
    1553       until StartLoc0[i] >= 0;
    1554       StartLoc[p1] := StartLoc0[i];
    1555       StartLoc0[i] := -1
     1552        I := DelphiRandom(nAlive) + 1
     1553      until StartLoc0[I] >= 0;
     1554      StartLoc[p1] := StartLoc0[I];
     1555      StartLoc0[I] := -1
    15561556    end;
    15571557  SaveMapCenterLoc := StartLoc[0];
     
    15861586          StartLoc2[p1] := Loc1;
    15871587          BestDist := TestDist;
    1588           n := 1;
     1588          N := 1;
    15891589        end
    15901590        else if TestDist = BestDist then
    15911591        begin
    1592           inc(n);
    1593           if DelphiRandom(n) = 0 then
     1592          Inc(N);
     1593          if DelphiRandom(N) = 0 then
    15941594            StartLoc2[p1] := Loc1;
    15951595        end;
     
    15981598end;
    15991599
    1600 procedure PredefinedStartPositions(Human: integer);
     1600procedure PredefinedStartPositions(Human: Integer);
    16011601// use predefined nation start positions
    16021602var
    1603   i, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: integer;
    1604   StartLoc0: array [0 .. lxmax * lymax - 1] of integer;
    1605   ishuman: boolean;
     1603  I, p1, Loc1, nAlive, nStartLoc0, nPrefStartLoc0, imax: Integer;
     1604  StartLoc0: array [0 .. lxmax * lymax - 1] of Integer;
     1605  ishuman: Boolean;
    16061606begin
    16071607  nAlive := 0;
    16081608  for p1 := 0 to nPl - 1 do
    16091609    if 1 shl p1 and GAlive <> 0 then
    1610       inc(nAlive);
     1610      Inc(nAlive);
    16111611  if nAlive = 0 then
    1612     exit;
     1612    Exit;
    16131613
    16141614  for I := 0 to Length(StartLoc0) - 1 do
     
    16231623      StartLoc0[nStartLoc0] := StartLoc0[nPrefStartLoc0];
    16241624      StartLoc0[nPrefStartLoc0] := Loc1;
    1625       inc(nPrefStartLoc0);
    1626       inc(nStartLoc0);
     1625      Inc(nPrefStartLoc0);
     1626      Inc(nStartLoc0);
    16271627      RealMap[Loc1] := RealMap[Loc1] and not fPrefStartPos;
    16281628    end
     
    16301630    begin
    16311631      StartLoc0[nStartLoc0] := Loc1;
    1632       inc(nStartLoc0);
     1632      Inc(nStartLoc0);
    16331633      RealMap[Loc1] := RealMap[Loc1] and not fStartPos;
    16341634    end;
    1635   assert(nStartLoc0 >= nAlive);
     1635  Assert(nStartLoc0 >= nAlive);
    16361636
    16371637  StartLoc[0] := 0;
    1638   for ishuman := true downto false do
     1638  for ishuman := True downto False do
    16391639    for p1 := 0 to nPl - 1 do
    16401640      if (1 shl p1 and GAlive <> 0) and ((1 shl p1 and Human <> 0) = ishuman)
    16411641      then
    16421642      begin
    1643         dec(nStartLoc0);
     1643        Dec(nStartLoc0);
    16441644        imax := nStartLoc0;
    16451645        if nPrefStartLoc0 > 0 then
    16461646        begin
    1647           dec(nPrefStartLoc0);
     1647          Dec(nPrefStartLoc0);
    16481648          imax := nPrefStartLoc0;
    16491649        end;
    1650         i := DelphiRandom(imax + 1);
    1651         StartLoc[p1] := StartLoc0[i];
    1652         StartLoc2[p1] := StartLoc0[i];
    1653         StartLoc0[i] := StartLoc0[imax];
     1650        I := DelphiRandom(imax + 1);
     1651        StartLoc[p1] := StartLoc0[I];
     1652        StartLoc2[p1] := StartLoc0[I];
     1653        StartLoc0[I] := StartLoc0[imax];
    16541654        StartLoc0[imax] := StartLoc0[nStartLoc0];
    16551655      end;
     
    16591659procedure InitGame;
    16601660var
    1661   i, p, p1, uix, Loc1: integer;
     1661  I, P, p1, uix, Loc1: Integer;
    16621662begin
    16631663  {$IFDEF FastContact}
     
    16831683  GTestFlags := 0;
    16841684  GInitialized := GAlive or GWatching;
    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
     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
    16951695        else
    1696           ResourceMask[p] := $FFFFFFFF and not(fSpecial2 or fModern);
    1697         GrWallContinent[p] := -1;
     1696          ResourceMask[P] := $FFFFFFFF and not(fSpecial2 or fModern);
     1697        GrWallContinent[P] := -1;
    16981698
    16991699        GetMem(Map, 4 * MapSize);
     
    17131713          if 1 shl p1 and GInitialized <> 0 then
    17141714          begin
    1715             FillChar(RWemix[p, p1], SizeOf(RWemix[p, p1]), 255); { -1 }
    1716             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);
    17171717          end;
    17181718          Attitude[p1] := atNeutral;
     
    17221722          Tribute[p1] := 0;
    17231723          TributePaid[p1] := 0;
    1724           if (p1 <> p) and (1 shl p1 and GAlive <> 0) then
     1724          if (p1 <> P) and (1 shl p1 and GAlive <> 0) then
    17251725          begin // initialize enemy report
    17261726            GetMem(EnemyReport[p1], SizeOf(TEnemyReport) - 2 *
     
    17321732            EnemyReport[p1].Attitude := atNeutral;
    17331733            EnemyReport[p1].Government := gDespotism;
    1734             if 1 shl p and GAlive = 0 then
     1734            if 1 shl P and GAlive = 0 then
    17351735              Treaty[p1] := trNone // supervisor
    17361736          end
     
    17541754
    17551755  // create initial models and units
    1756   for p := 0 to nPl - 1 do
    1757     if (1 shl p and GAlive <> 0) then
    1758       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
    17591759      begin
    17601760        nModel := 0;
    1761         for i := 0 to nSpecialModel - 1 do
    1762           if SpecialModelPreq[i] = preNone then
     1761        for I := 0 to nSpecialModel - 1 do
     1762          if SpecialModelPreq[I] = preNone then
    17631763          begin
    1764             Model[nModel] := SpecialModel[i];
     1764            Model[nModel] := SpecialModel[I];
    17651765            Model[nModel].Status := 0;
    17661766            Model[nModel].IntroTurn := 0;
    17671767            Model[nModel].Built := 0;
    17681768            Model[nModel].Lost := 0;
    1769             Model[nModel].ID := p shl 12 + nModel;
     1769            Model[nModel].ID := P shl 12 + nModel;
    17701770            SetModelFlags(Model[nModel]);
    1771             inc(nModel);
     1771            Inc(nModel);
    17721772          end;
    17731773        nUn := 0;
    1774         UnBuilt[p] := 0;
     1774        UnBuilt[P] := 0;
    17751775        for uix := 0 to nStartUn - 1 do
    17761776        begin
    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;
     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;
    17841784        with City[0] do
    17851785        begin
    1786           ID := p shl 12;
     1786          ID := P shl 12;
    17871787          Flags := chFounded;
    17881788        end;
     
    17981798  CalculatePrimitive;
    17991799  CreateElevation;
    1800   CreateMap(false);
     1800  CreateMap(False);
    18011801  StartPositions;
    18021802  InitGame;
    18031803end;
    18041804
    1805 procedure InitMapGame(Human: integer);
     1805procedure InitMapGame(Human: Integer);
    18061806begin
    18071807  DelphiRandSeed := RND;
     
    18131813procedure ReleaseGame;
    18141814var
    1815   p1, p2: integer;
     1815  p1, p2: Integer;
    18161816begin
    18171817  for p1 := 0 to nPl - 1 do
     
    18351835procedure InitMapEditor;
    18361836var
    1837   p1: integer;
     1837  p1: Integer;
    18381838begin
    18391839  CalculatePrimitive;
     
    18721872end;
    18731873
    1874 procedure EditTile(Loc, NewTile: integer);
    1875 var
    1876   Loc1, V21: integer;
     1874procedure EditTile(Loc, NewTile: Integer);
     1875var
     1876  Loc1, V21: Integer;
    18771877  Radius: TVicinity21Loc;
    18781878begin
     
    19321932  ____________________________________________________________________
    19331933}
    1934 function GetTileInfo(p, cix, Loc: integer; var Info: TTileInfo): integer;
     1934function GetTileInfo(P, cix, Loc: Integer; var Info: TTileInfo): Integer;
    19351935// cix>=0 - known city index of player p -- only core internal!
    19361936// cix=-1 - search city, player unknown, only if permission for p
    19371937// cix=-2 - don't search city, don't calculate city benefits, just government of player p
    19381938var
    1939   p0, Tile, special: integer;
     1939  p0, Tile, special: Integer;
    19401940begin
    19411941  with Info do
    19421942  begin
    1943     p0 := p;
     1943    p0 := P;
    19441944    if cix >= 0 then
    19451945      Tile := RealMap[Loc]
    19461946    else
    19471947    begin
    1948       Tile := RW[p].Map[Loc];
     1948      Tile := RW[P].Map[Loc];
    19491949      if Tile and fTerrain = fUNKNOWN then
    19501950      begin
    1951         result := eNoPreq;
    1952         exit;
     1951        Result := eNoPreq;
     1952        Exit;
    19531953      end;
    19541954    end;
     
    19561956    if (cix = -1) and (UsedByCity[Loc] >= 0) then
    19571957    begin // search exploiting player and city
    1958       SearchCity(UsedByCity[Loc], p, cix);
    1959       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
    19601960        3 = lObserveSuper)) then
    19611961        cix := -1
     
    19631963    if cix = -1 then
    19641964    begin
    1965       result := eInvalid;
    1966       exit;
     1965      Result := eInvalid;
     1966      Exit;
    19671967    end; // no city found here
    19681968
    1969     special := Tile and fSpecial and ResourceMask[p] shr 5;
     1969    special := Tile and fSpecial and ResourceMask[P] shr 5;
    19701970    with Terrain[Tile and fTerrain] do
    19711971    begin
     
    19741974      Trade := TradeRes[special];
    19751975      if (special > 0) and (Tile and fTerrain <> fGrass) and
    1976         (RW[p].NatBuilt[imSpacePort] > 0) then
     1976        (RW[P].NatBuilt[imSpacePort] > 0) then
    19771977      begin // GeoSat effect
    19781978        Food := 2 * Food - FoodRes[0];
     
    19831983      if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) or
    19841984        (Tile and fCity <> 0) then
    1985         inc(Food, IrrEff); { irrigation effect }
     1985        Inc(Food, IrrEff); { irrigation effect }
    19861986      if Tile and fTerImp = tiMine then
    1987         inc(Prod, MineEff); { mining effect }
    1988       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)
    19891989      then
    1990         inc(Trade); { river effect }
     1990        Inc(Trade); { river effect }
    19911991      if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and
    1992         (RW[p].Tech[adWheel] >= tsApplicable) then
    1993         inc(Trade); { road effect }
     1992        (RW[P].Tech[adWheel] >= tsApplicable) then
     1993        Inc(Trade); { road effect }
    19941994      if (Tile and (fRR or fCity) <> 0) and
    1995         (RW[p].Tech[adRailroad] >= tsApplicable) then
    1996         inc(Prod, Prod shr 1); { railroad effect }
     1995        (RW[P].Tech[adRailroad] >= tsApplicable) then
     1996        Inc(Prod, Prod shr 1); { railroad effect }
    19971997
    19981998      ExplCity := -1;
    1999       if (cix >= 0) and (p = p0) then
     1999      if (cix >= 0) and (P = p0) then
    20002000        ExplCity := cix;
    20012001      if cix >= 0 then
     
    20032003        begin
    20042004          if ((Tile and fTerImp = tiFarm) or (Tile and fCity <> 0)) and
    2005             (RW[p].City[cix].Built[imSupermarket] > 0) then
    2006             inc(Food, Food shr 1); { farmland effect }
     2005            (RW[P].City[cix].Built[imSupermarket] > 0) then
     2006            Inc(Food, Food shr 1); { farmland effect }
    20072007          if (Tile and (fRoad or fRR) <> 0) and (MoveCost = 1) and
    2008             (RW[p].City[cix].Built[imHighways] > 0) then
    2009             inc(Trade, 1); { superhighway effect }
     2008            (RW[P].City[cix].Built[imHighways] > 0) then
     2009            Inc(Trade, 1); { superhighway effect }
    20102010        end
    20112011        else
    20122012        begin
    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);
     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);
    20192019        end;
    20202020    end;
    20212021
    20222022    { good government influence }
    2023     if (RW[p].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)
     2023    if (RW[P].Government in [gRepublic, gDemocracy, gFuture]) and (Trade > 0)
    20242024    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
     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
    20302030    begin { bad government influence }
    20312031      if Food > 3 then
     
    20392039    if Tile and (fTerrain or fPoll) > fPoll then
    20402040    begin { pollution - decrease ressources }
    2041       dec(Food, Food shr 1);
    2042       dec(Prod, Prod shr 1);
    2043       dec(Trade, Trade shr 1);
     2041      Dec(Food, Food shr 1);
     2042      Dec(Prod, Prod shr 1);
     2043      Dec(Trade, Trade shr 1);
    20442044    end;
    20452045
    20462046    if Tile and fCity <> 0 then
    20472047      Trade := 0
    2048     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]
    20492049      .Built[imPalace] = 0) then
    2050       if RW[p].City[cix].Built[imTownHall] = 0 then
     2050      if RW[P].City[cix].Built[imTownHall] = 0 then
    20512051        Trade := 0
    20522052      else if Trade > 3 then
    20532053        Trade := 3;
    20542054  end;
    2055   result := eOK;
    2056 end;
    2057 
    2058 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);
    20592059{ find strongest defender at Loc }
    20602060var
    20612061  Defender, uix1, Det, Cost, TestStrength, TestBonus, TestDet, TestCost,
    2062     Domain: integer;
     2062    Domain: Integer;
    20632063  PUn: ^TUn;
    20642064  PModel: ^TModel;
     
    20782078    if PUn.Loc = Loc then
    20792079    begin
    2080       inc(Cnt);
     2080      Inc(Cnt);
    20812081      if PUn.Master < 0 then
    20822082      begin
     
    20852085          TestBonus := Terrain[RealMap[Loc] and fTerrain].Defense;
    20862086          if RealMap[Loc] and fTerImp = tiFort then
    2087             inc(TestBonus, 4);
     2087            Inc(TestBonus, 4);
    20882088          if PUn.Flags and unFortified <> 0 then
    2089             inc(TestBonus, 2);
     2089            Inc(TestBonus, 2);
    20902090          if (PModel.Kind = mkSpecial_TownGuard) and
    20912091            (RealMap[Loc] and fCity <> 0) then
    2092             inc(TestBonus, 4);
     2092            Inc(TestBonus, 4);
    20932093        end
    20942094        else
    20952095          TestBonus := 4;
    2096         inc(TestBonus, PUn.exp div ExpCost);
     2096        Inc(TestBonus, PUn.exp div ExpCost);
    20972097        TestStrength := PModel.Defense * TestBonus * PUn.Health;
    20982098        if (Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or
     
    21042104        if PModel.Cap[mcStealth] > 0 then
    21052105        else if PModel.Cap[mcSub] > 0 then
    2106           inc(TestDet, 1 shl 28)
     2106          Inc(TestDet, 1 shl 28)
    21072107        else if (Domain = dGround) and (PModel.Cap[mcFanatic] > 0) and
    21082108          not(RW[Defender].Government in [gRepublic, gDemocracy, gFuture]) then
    2109           inc(TestDet, 4 shl 28) // fanatic ground units always defend
     2109          Inc(TestDet, 4 shl 28) // fanatic ground units always defend
    21102110        else if PModel.Flags and mdZOC <> 0 then
    2111           inc(TestDet, 3 shl 28)
     2111          Inc(TestDet, 3 shl 28)
    21122112        else
    2113           inc(TestDet, 2 shl 28);
     2113          Inc(TestDet, 2 shl 28);
    21142114        TestCost := RW[Defender].Model[PUn.mix].Cost;
    21152115        if (TestDet > Det) or (TestDet = Det) and (TestCost < Cost) then
     
    21262126end;
    21272127
    2128 function UnitSpeed(p, mix, Health: integer): integer;
    2129 begin
    2130   with RW[p].Model[mix] do
    2131   begin
    2132     result := Speed;
     2128function UnitSpeed(P, mix, Health: Integer): Integer;
     2129begin
     2130  with RW[P].Model[mix] do
     2131  begin
     2132    Result := Speed;
    21332133    if Domain = dSea then
    21342134    begin
    2135       if GWonder[woMagellan].EffectiveOwner = p then
    2136         inc(result, 200);
     2135      if GWonder[woMagellan].EffectiveOwner = P then
     2136        Inc(Result, 200);
    21372137      if Health < 100 then
    2138         result := ((result - 250) * Health div 5000) * 50 + 250;
    2139     end;
    2140   end;
    2141 end;
    2142 
    2143 procedure GetUnitReport(p, uix: integer; var UnitReport: TUnitReport);
    2144 var
    2145   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;
    21462146  PModel: ^TModel;
    21472147begin
     
    21492149  UnitReport.ProdSupport := 0;
    21502150  UnitReport.ReportFlags := 0;
    2151   if RW[p].Government <> gAnarchy then
    2152     with RW[p].Un[uix] do
    2153     begin
    2154       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];
    21552155      if (PModel.Kind = mkSettler)
    21562156      { and (GWonder[woFreeSettlers].EffectiveOwner<>p) } then
    2157         UnitReport.FoodSupport := SettlerFood[RW[p].Government]
     2157        UnitReport.FoodSupport := SettlerFood[RW[P].Government]
    21582158      else if Flags and unConscripts <> 0 then
    21592159        UnitReport.FoodSupport := 1;
    21602160
    2161       if RW[p].Government <> gFundamentalism then
     2161      if RW[P].Government <> gFundamentalism then
    21622162      begin
    21632163        if GTestFlags and tfImmImprove = 0 then
     
    21742174        begin
    21752175          TerrOwner := RealMap[Loc] shr 27;
    2176           case RW[p].Government of
     2176          case RW[P].Government of
    21772177            gRepublic, gFuture:
    2178               if (TerrOwner <> p) and (TerrOwner < nPl) and
    2179                 (RW[p].Treaty[TerrOwner] < trAlliance) then
     2178              if (TerrOwner <> P) and (TerrOwner < nPl) and
     2179                (RW[P].Treaty[TerrOwner] < trAlliance) then
    21802180                UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed;
    21812181            gDemocracy:
    2182               if (TerrOwner >= nPl) or (TerrOwner <> p) and
    2183                 (RW[p].Treaty[TerrOwner] < trAlliance) then
     2182              if (TerrOwner >= nPl) or (TerrOwner <> P) and
     2183                (RW[P].Treaty[TerrOwner] < trAlliance) then
    21842184                UnitReport.ReportFlags := UnitReport.ReportFlags or urfDeployed;
    21852185          end;
     
    21892189end;
    21902190
    2191 procedure SearchCity(Loc: integer; var p, cix: integer);
     2191procedure SearchCity(Loc: Integer; var P, cix: Integer);
    21922192// set p to supposed owner before call
    21932193var
    2194   i: integer;
     2194  I: Integer;
    21952195begin
    21962196  if RealMap[Loc] < nPl shl 27 then
    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
     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
    22022202      begin
    22032203        cix := nCity - 1;
    22042204        while (cix >= 0) and (City[cix].Loc <> Loc) do
    2205           dec(cix);
     2205          Dec(cix);
    22062206        if cix >= 0 then
    2207           exit;
    2208       end;
    2209     assert(i < nPl - 1);
    2210     p := (p + 1) mod nPl;
    2211   end;
    2212 end;
    2213 
    2214 procedure MakeCityInfo(p, cix: integer; var ci: TCityInfo);
    2215 begin
    2216   assert((p >= 0) and (p < nPl));
    2217   assert((cix >= 0) and (cix < RW[p].nCity));
    2218   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
    22192219  begin
    22202220    ci.Loc := Loc;
    22212221    ci.ID := ID;
    2222     ci.Owner := p;
     2222    ci.Owner := P;
    22232223    ci.Size := Size;
    22242224    ci.Flags := 0;
    22252225    if Built[imPalace] > 0 then
    2226       inc(ci.Flags, ciCapital);
    2227     if (Built[imWalls] > 0) or (Continent[Loc] = GrWallContinent[p]) then
    2228       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);
    22292229    if Built[imCoastalFort] > 0 then
    2230       inc(ci.Flags, ciCoastalFort);
     2230      Inc(ci.Flags, ciCoastalFort);
    22312231    if Built[imMissileBat] > 0 then
    2232       inc(ci.Flags, ciMissileBat);
     2232      Inc(ci.Flags, ciMissileBat);
    22332233    if Built[imBunker] > 0 then
    2234       inc(ci.Flags, ciBunker);
     2234      Inc(ci.Flags, ciBunker);
    22352235    if Built[imSpacePort] > 0 then
    2236       inc(ci.Flags, ciSpacePort);
    2237   end;
    2238 end;
    2239 
    2240 procedure TellAboutModel(p, taOwner, tamix: integer);
    2241 var
    2242   i: integer;
    2243 begin
    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^);
    2252 end;
    2253 
    2254 function emixSafe(p, taOwner, tamix: integer): integer;
    2255 begin
    2256   result := RWemix[p, taOwner, tamix];
    2257   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
    22582258  begin // sIntTellAboutModel comes too late
    2259     assert(Mode = moMovie);
    2260     result := $FFFF;
    2261   end;
    2262 end;
    2263 
    2264 procedure IntroduceEnemy(p1, p2: integer);
     2259    Assert(Mode = moMovie);
     2260    Result := $FFFF;
     2261  end;
     2262end;
     2263
     2264procedure IntroduceEnemy(p1, p2: Integer);
    22652265begin
    22662266  RW[p1].Treaty[p2] := trNone;
     
    22682268end;
    22692269
    2270 function DiscoverTile(Loc, p, pTell, Level: integer; EnableContact: boolean;
    2271   euix: integer = -2): boolean;
     2270function DiscoverTile(Loc, P, pTell, Level: Integer; EnableContact: Boolean;
     2271  euix: Integer = -2): Boolean;
    22722272// euix = -2: full discover
    22732273// euix = -1: unit and city only, append units in EnemyUn
    22742274// euix >= 0: unit and city only, replace EnemyUn[euix]
    22752275
    2276   procedure SetContact(p1, p2: integer);
     2276  procedure SetContact(p1, p2: Integer);
    22772277  begin
    22782278    if (Mode < moPlaying) or (p1 = p2) or (RW[p1].Treaty[p2] > trNoContact) then
    2279       exit;
     2279      Exit;
    22802280    IntServer(sIntTellAboutNation, p1, p2, nil^);
    22812281    // NewContact[p1,p2]:=true
     
    22832283
    22842284var
    2285   i, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,
    2286     cixFoundCity, MinLevel, Loc1, V8: integer;
     2285  I, uix, cix, TerrOwner, TerrOwnerTreaty, Strength, Bonus, Cnt, pFoundCity,
     2286    cixFoundCity, MinLevel, Loc1, V8: Integer;
    22872287  Tile, AddFlags: Cardinal;
    22882288  Adjacent: TVicinity8Loc;
     
    22902290  mox: ^TModel;
    22912291begin
    2292   result := false;
     2292  Result := False;
    22932293  with RW[pTell] do
    22942294  begin
     
    23062306        AddFlags := AddFlags or fGrWall;
    23072307      if (Mode = moPlaying) and ((Tile and (nPl shl 27) <> nPl shl 27) and
    2308         (pTell = p)) then
     2308        (pTell = P)) then
    23092309      begin // set fPeace flag?
    23102310        TerrOwner := Tile shr 27;
     
    23332333          unx := @RW[Occupant[Loc]].Un[uix];
    23342334          mox := @RW[Occupant[Loc]].Model[unx.mix];
    2335           assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));
     2335          Assert((ZoCMap[Loc] <> 0) = (mox.Flags and mdZOC <> 0));
    23362336          if (mox.Cap[mcStealth] > 0) and (Tile and fCity = 0) and
    23372337            (Tile and fTerImp <> tiBase) then
     
    23492349            begin
    23502350              uix := nEnemyUn;
    2351               inc(nEnemyUn);
    2352               assert(nEnemyUn < neumax);
     2351              Inc(nEnemyUn);
     2352              Assert(nEnemyUn < neumax);
    23532353            end;
    23542354            MakeUnitInfo(Occupant[Loc], unx^, EnemyUn[uix]);
    23552355            if Cnt > 1 then
    23562356              EnemyUn[uix].Flags := EnemyUn[uix].Flags or unMulti;
    2357             if (mox.Flags and mdZOC <> 0) and (pTell = p) and
     2357            if (mox.Flags and mdZOC <> 0) and (pTell = P) and
    23582358              (Treaty[Occupant[Loc]] < trAlliance) then
    23592359            begin // set fInEnemyZoC flags of surrounding tiles
     
    23742374            end;
    23752375            // Level:=lObserveSuper; // don't discover unit twice
    2376             if (pTell = p) and
     2376            if (pTell = P) and
    23772377              ((Tile and fCity = 0) or (1 shl pTell and GAI <> 0)) then
    2378               result := true;
     2378              Result := True;
    23792379          end
    23802380          else
     
    23982398          while (cixFoundCity >= 0) and
    23992399            (RW[pFoundCity].City[cixFoundCity].Loc <> Loc) do
    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
     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
    24062406          begin
    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;
     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;
    24132413          end;
    2414           MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[i]);
     2414          MakeCityInfo(pFoundCity, cixFoundCity, EnemyCity[I]);
    24152415        end;
    24162416      end
     
    24212421
    24222422    if Map[Loc] and fTerrain = fUNKNOWN then
    2423       inc(Discovered[pTell]);
     2423      Inc(Discovered[pTell]);
    24242424    if euix >= -1 then
    24252425      Map[Loc] := Map[Loc] and not(fUnit or fCity or fOwned or fOwnZoCUnit) or
     
    24402440end;
    24412441
    2442 function Discover9(Loc, p, Level: integer;
    2443   TellAllied, EnableContact: boolean): boolean;
    2444 var
    2445   V9, Loc1, pTell, OldLevel: integer;
     2442function Discover9(Loc, P, Level: Integer;
     2443  TellAllied, EnableContact: Boolean): Boolean;
     2444var
     2445  V9, Loc1, pTell, OldLevel: Integer;
    24462446  Radius: TVicinity8Loc;
    24472447begin
    2448   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
    2449   result := false;
     2448  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
     2449  Result := False;
    24502450  V8_to_Loc(Loc, Radius);
    24512451  for V9 := 0 to 8 do
     
    24592459      begin
    24602460        for pTell := 0 to nPl - 1 do
    2461           if (pTell = p) or (1 shl pTell and GAlive <> 0) and
    2462             (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
    24632463          begin
    24642464            OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3;
    24652465            if Level > OldLevel then
    2466               result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)
    2467                 or result;
     2466              Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact)
     2467                or Result;
    24682468          end;
    24692469      end
    24702470      else
    24712471      begin
    2472         OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;
     2472        OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3;
    24732473        if Level > OldLevel then
    2474           result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;
    2475       end;
    2476   end;
    2477 end;
    2478 
    2479 function Discover21(Loc, p, AdjacentLevel: integer;
    2480   TellAllied, EnableContact: boolean): boolean;
    2481 var
    2482   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;
    24832483  Radius: TVicinity21Loc;
    24842484begin
    2485   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
    2486   result := false;
     2485  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
     2486  Result := False;
    24872487  AdjacentFlags := $00267620 shr 1;
    24882488  V21_to_Loc(Loc, Radius);
     
    24992499      begin
    25002500        for pTell := 0 to nPl - 1 do
    2501           if (pTell = p) or (1 shl pTell and GAlive <> 0) and
    2502             (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
    25032503          begin
    25042504            OldLevel := ObserveLevel[Loc1] shr (2 * pTell) and 3;
    25052505            if Level > OldLevel then
    2506               result := DiscoverTile(Loc1, p, pTell, Level, EnableContact)
    2507                 or result;
     2506              Result := DiscoverTile(Loc1, P, pTell, Level, EnableContact)
     2507                or Result;
    25082508          end;
    25092509      end
    25102510      else
    25112511      begin
    2512         OldLevel := ObserveLevel[Loc1] shr (2 * p) and 3;
     2512        OldLevel := ObserveLevel[Loc1] shr (2 * P) and 3;
    25132513        if Level > OldLevel then
    2514           result := DiscoverTile(Loc1, p, p, Level, EnableContact) or result;
     2514          Result := DiscoverTile(Loc1, P, P, Level, EnableContact) or Result;
    25152515      end;
    25162516    end;
     
    25192519end;
    25202520
    2521 procedure DiscoverAll(p, Level: integer);
     2521procedure DiscoverAll(P, Level: Integer);
    25222522{ player p discovers complete playground (for supervisor) }
    25232523var
    2524   Loc, OldLevel: integer;
    2525 begin
    2526   assert((Mode > moLoading_Fast) or (RW[p].nEnemyUn = 0));
     2524  Loc, OldLevel: Integer;
     2525begin
     2526  Assert((Mode > moLoading_Fast) or (RW[P].nEnemyUn = 0));
    25272527  for Loc := 0 to MapSize - 1 do
    25282528  begin
    2529     OldLevel := ObserveLevel[Loc] shr (2 * p) and 3;
     2529    OldLevel := ObserveLevel[Loc] shr (2 * P) and 3;
    25302530    if Level > OldLevel then
    2531       DiscoverTile(Loc, p, p, Level, false);
    2532   end;
    2533 end;
    2534 
    2535 procedure DiscoverViewAreas(p: integer);
    2536 var
    2537   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;
    25382538  PModel: ^TModel;
    25392539begin // discover unit and city view areas
    25402540  for pTell := 0 to nPl - 1 do
    2541     if (pTell = p) or (RW[p].Treaty[pTell] = trAlliance) then
     2541    if (pTell = P) or (RW[P].Treaty[pTell] = trAlliance) then
    25422542    begin
    25432543      for uix := 0 to RW[pTell].nUn - 1 do
     
    25472547            PModel := @RW[pTell].Model[mix];
    25482548            if (PModel.Kind = mkDiplomat) or (PModel.Cap[mcSpy] > 0) then
    2549               Discover21(Loc, p, lObserveSuper, false, true)
     2549              Discover21(Loc, P, lObserveSuper, False, True)
    25502550            else if (PModel.Cap[mcRadar] + PModel.Cap[mcCarrier] > 0) or
    25512551              (PModel.Domain = dAir) then
    2552               Discover21(Loc, p, lObserveAll, false, false)
     2552              Discover21(Loc, P, lObserveAll, False, False)
    25532553            else if (RealMap[Loc] and fTerrain = fMountains) or
    25542554              (RealMap[Loc] and fTerImp = tiFort) or
    25552555              (RealMap[Loc] and fTerImp = tiBase) or (PModel.Cap[mcAcademy] > 0)
    25562556            then
    2557               Discover21(Loc, p, lObserveUnhidden, false,
     2557              Discover21(Loc, P, lObserveUnhidden, False,
    25582558                PModel.Domain = dGround)
    25592559            else
    2560               Discover9(Loc, p, lObserveUnhidden, false,
     2560              Discover9(Loc, P, lObserveUnhidden, False,
    25612561                PModel.Domain = dGround);
    25622562          end;
    25632563      for cix := 0 to RW[pTell].nCity - 1 do
    25642564        if RW[pTell].City[cix].Loc >= 0 then
    2565           Discover21(RW[pTell].City[cix].Loc, p, lObserveUnhidden, false, true);
     2565          Discover21(RW[pTell].City[cix].Loc, P, lObserveUnhidden, False, True);
    25662566      for ecix := 0 to RW[pTell].nEnemyCity - 1 do
    25672567      begin // players know territory, so no use in hiding city owner
     
    25822582end;
    25832583
    2584 function GetUnitStack(p, Loc: integer): integer;
    2585 var
    2586   uix: integer;
     2584function GetUnitStack(P, Loc: Integer): Integer;
     2585var
     2586  uix: Integer;
    25872587  unx: ^TUn;
    25882588begin
    2589   result := 0;
     2589  Result := 0;
    25902590  if Occupant[Loc] < 0 then
    2591     exit;
     2591    Exit;
    25922592  for uix := 0 to RW[Occupant[Loc]].nUn - 1 do
    25932593  begin
     
    25952595    if unx.Loc = Loc then
    25962596    begin
    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;
    2604 end;
    2605 
    2606 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);
    26072607// update maps and enemy units of all players after unit change
    26082608var
    2609   p, euix, OldLevel: integer;
     2609  P, euix, OldLevel: Integer;
    26102610  AddFlags, ClearFlags: Cardinal;
    26112611begin
    26122612  if (Mode = moLoading_Fast) and not CityChange then
    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;
     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;
    26182618      if OldLevel > lNoObserve then
    26192619      begin
    2620         if RW[p].Map[Loc] and (fUnit or fOwned) = fUnit then
     2620        if RW[P].Map[Loc] and (fUnit or fOwned) = fUnit then
    26212621        begin
    26222622          // replace unit located here in EnemyUn
    26232623          // do not just set loc:=-1 because total number would be unlimited
    2624           euix := RW[p].nEnemyUn - 1;
     2624          euix := RW[P].nEnemyUn - 1;
    26252625          while euix >= 0 do
    26262626          begin
    2627             if RW[p].EnemyUn[euix].Loc = Loc then
     2627            if RW[P].EnemyUn[euix].Loc = Loc then
    26282628            begin
    2629               RW[p].EnemyUn[euix].Loc := -1;
     2629              RW[P].EnemyUn[euix].Loc := -1;
    26302630              Break;
    26312631            end;
    2632             dec(euix);
     2632            Dec(euix);
    26332633          end;
    2634           RW[p].Map[Loc] := RW[p].Map[Loc] and not fUnit
     2634          RW[P].Map[Loc] := RW[P].Map[Loc] and not fUnit
    26352635        end
    26362636        else
    26372637        begin // look for empty slot in EnemyUn
    2638           euix := RW[p].nEnemyUn - 1;
    2639           while (euix >= 0) and (RW[p].EnemyUn[euix].Loc >= 0) do
    2640             dec(euix);
     2638          euix := RW[P].nEnemyUn - 1;
     2639          while (euix >= 0) and (RW[P].EnemyUn[euix].Loc >= 0) do
     2640            Dec(euix);
    26412641        end;
    26422642        if (Occupant[Loc] < 0) and not CityChange then
     
    26452645          if RealMap[Loc] and fCity = 0 then
    26462646            ClearFlags := ClearFlags or fOwned;
    2647           RW[p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags;
     2647          RW[P].Map[Loc] := RW[P].Map[Loc] and not ClearFlags;
    26482648        end
    2649         else if (Occupant[Loc] <> p) or CityChange then
     2649        else if (Occupant[Loc] <> P) or CityChange then
    26502650        begin // city or enemy unit update necessary, call DiscoverTile
    2651           ObserveLevel[Loc] := ObserveLevel[Loc] and not(3 shl (2 * p));
    2652           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);
    26532653        end
    26542654        else { if (Occupant[Loc]=p) and not CityChange then }
     
    26602660          else
    26612661            ClearFlags := ClearFlags or fOwnZoCUnit;
    2662           RW[p].Map[Loc] := RW[p].Map[Loc] and not ClearFlags or AddFlags;
    2663         end;
    2664       end;
    2665     end;
    2666 end;
    2667 
    2668 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);
    26692669// recalculate fInEnemyZoC flags around single tile
    26702670var
    2671   V8, V8V8, Loc1, Loc2, p1, ObserveMask: integer;
     2671  V8, V8V8, Loc1, Loc2, p1, ObserveMask: Integer;
    26722672  Tile1: ^Cardinal;
    26732673  Adjacent, AdjacentAdjacent: TVicinity8Loc;
    26742674begin
    26752675  if Mode = moLoading_Fast then
    2676     exit;
    2677   ObserveMask := 3 shl (2 * p);
     2676    Exit;
     2677  ObserveMask := 3 shl (2 * P);
    26782678  V8_to_Loc(Loc, Adjacent);
    26792679  for V8 := 0 to 7 do
     
    26822682    if (Loc1 >= 0) and (Loc1 < MapSize) then
    26832683    begin
    2684       Tile1 := @RW[p].Map[Loc1];
     2684      Tile1 := @RW[P].Map[Loc1];
    26852685      Tile1^ := Tile1^ and not fInEnemyZoC;
    26862686      V8_to_Loc(Loc1, AdjacentAdjacent);
     
    26922692        begin
    26932693          p1 := Occupant[Loc2];
    2694           assert(p1 <> nPl);
    2695           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
    26962696          begin
    26972697            Tile1^ := Tile1^ or fInEnemyZoC;
     
    27042704end;
    27052705
    2706 procedure RecalcMapZoC(p: integer);
     2706procedure RecalcMapZoC(P: Integer);
    27072707// recalculate fInEnemyZoC flags for the whole map
    27082708var
    2709   Loc, Loc1, V8, p1, ObserveMask: integer;
     2709  Loc, Loc1, V8, p1, ObserveMask: Integer;
    27102710  Adjacent: TVicinity8Loc;
    27112711begin
    27122712  if Mode = moLoading_Fast then
    2713     exit;
    2714   MaskD(RW[p].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));
    2715   ObserveMask := 3 shl (2 * p);
     2713    Exit;
     2714  MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fInEnemyZoC)));
     2715  ObserveMask := 3 shl (2 * P);
    27162716  for Loc := 0 to MapSize - 1 do
    27172717    if (ZoCMap[Loc] > 0) and (ObserveLevel[Loc] and ObserveMask <> 0) then
    27182718    begin
    27192719      p1 := Occupant[Loc];
    2720       assert(p1 <> nPl);
    2721       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
    27222722      begin // this non-allied enemy ZoC unit is known to this player -- set flags!
    27232723        V8_to_Loc(Loc, Adjacent);
     
    27262726          Loc1 := Adjacent[V8];
    27272727          if (Loc1 >= 0) and (Loc1 < MapSize) then
    2728             RW[p].Map[Loc1] := RW[p].Map[Loc1] or fInEnemyZoC;
    2729         end;
    2730       end;
    2731     end;
    2732 end;
    2733 
    2734 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);
    27352735// recalculate fPeace flags for the whole map
    27362736var
    2737   Loc, p1: integer;
    2738   PeacePlayer: array [-1 .. nPl - 1] of boolean;
     2737  Loc, p1: Integer;
     2738  PeacePlayer: array [-1 .. nPl - 1] of Boolean;
    27392739begin
    27402740  if Mode <> moPlaying then
    2741     exit;
    2742   MaskD(RW[p].Map^, MapSize, Cardinal(not Cardinal(fPeace)));
     2741    Exit;
     2742  MaskD(RW[P].Map^, MapSize, Cardinal(not Cardinal(fPeace)));
    27432743  for p1 := -1 to nPl - 1 do
    2744     PeacePlayer[p1] := (p1 >= 0) and (p1 <> p) and (1 shl p1 and GAlive <> 0)
    2745       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]);
    27462746  for Loc := 0 to MapSize - 1 do
    2747     if PeacePlayer[RW[p].Territory[Loc]] then
    2748       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;
    27492749end;
    27502750
     
    27562756  BorderChanges: array [0 .. sIntExpandTerritory and $F - 1] of Cardinal;
    27572757
    2758 procedure ChangeTerritory(Loc, p: integer);
    2759 var
    2760   p1: integer;
    2761 begin
    2762   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
    27632763  Dec(TerritoryCount[RealMap[Loc] shr 27]);
    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;
     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;
    27682768  for p1 := 0 to nPl - 1 do
    27692769    if 1 shl p1 and (GAlive or GWatching) <> 0 then
    27702770      if RW[p1].Map[Loc] and fTerrain <> fUNKNOWN then
    27712771      begin
    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
     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
    27752775          RW[p1].Map[Loc] := RW[p1].Map[Loc] or fPeace
    27762776        else
     
    27792779end;
    27802780
    2781 procedure ExpandTerritory(OriginLoc: integer);
    2782 var
    2783   i, dx, dy, dxMax, dyMax, Loc, NewOwner: integer;
     2781procedure ExpandTerritory(OriginLoc: Integer);
     2782var
     2783  I, dx, dy, dxMax, dyMax, Loc, NewOwner: Integer;
    27842784begin
    27852785  if OriginLoc = -1 then
    27862786    raise Exception.Create('Location error');
    2787   i := 0;
     2787  I := 0;
    27882788  dyMax := 0;
    27892789  while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do
    2790     inc(dyMax);
     2790    Inc(dyMax);
    27912791  for dy := -dyMax to dyMax do
    27922792  begin
     
    27942794    while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <=
    27952795      CountryRadius do
    2796       inc(dxMax, 2);
     2796      Inc(dxMax, 2);
    27972797    for dx := -dxMax to dxMax do
    27982798      if (dy + dx) and 1 = 0 then
    27992799      begin
    2800         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;
    28012801        Loc := dLoc(OriginLoc, dx, dy);
    28022802        if (Loc >= 0) and (Cardinal(NewOwner) <> RealMap[Loc] shr 27) then
    28032803          ChangeTerritory(Loc, NewOwner);
    2804         inc(i);
    2805       end;
    2806   end;
    2807 end;
    2808 
    2809 procedure CheckBorders(OriginLoc, PlayerLosingCity: integer);
     2804        Inc(I);
     2805      end;
     2806  end;
     2807end;
     2808
     2809procedure CheckBorders(OriginLoc, PlayerLosingCity: Integer);
    28102810// OriginLoc: only changes in CountryRadius around this location possible,
    28112811// -1 for complete map, -2 for double-check (no more changes allowed)
     
    28132813// player's territory, -1 for full border recalculation
    28142814var
    2815   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;
    28162816  NewOwner: Cardinal;
    28172817  Adjacent: TVicinity8Loc;
    2818   AtPeace: array [0 .. nPl, 0 .. nPl] of boolean;
     2818  AtPeace: array [0 .. nPl, 0 .. nPl] of Boolean;
    28192819  Country, FormerCountry, { to who's country a tile belongs }
    28202820  Dist, FormerDist, StolenDist: array [0 .. lxmax * lymax - 1] of ShortInt;
     
    28282828        StolenDist[RW[PlayerLosingCity].City[cix].Loc] := 0;
    28292829
    2830     for r := 1 to CountryRadius shr 1 do
    2831     begin
    2832       move(StolenDist, FormerDist, MapSize);
     2830    for R := 1 to CountryRadius shr 1 do
     2831    begin
     2832      Move(StolenDist, FormerDist, MapSize);
    28332833      for Loc := 0 to MapSize - 1 do
    28342834        if (FormerDist[Loc] <= CountryRadius - 2)
     
    28622862        end;
    28632863
    2864   for r := 1 to CountryRadius shr 1 do
    2865   begin
    2866     move(Country, FormerCountry, MapSize);
    2867     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);
    28682868    for Loc := 0 to MapSize - 1 do
    28692869      if (FormerDist[Loc] <= CountryRadius - 2) // use same conditions as above!
     
    28712871        (1 shl fShore + 1 shl fMountains + 1 shl fArctic) = 0) then
    28722872      begin
    2873         assert(FormerCountry[Loc] >= 0);
     2873        Assert(FormerCountry[Loc] >= 0);
    28742874        V8_to_Loc(Loc, Adjacent);
    28752875        for V8 := 0 to 7 do
     
    28862886  end;
    28872887
    2888   FillChar(AtPeace, SizeOf(AtPeace), false);
     2888  FillChar(AtPeace, SizeOf(AtPeace), False);
    28892889  for p1 := 0 to nPl - 1 do
    28902890    if 1 shl p1 and GAlive <> 0 then
     
    28922892        if (p2 <> p1) and (1 shl p2 and GAlive <> 0) and
    28932893          (RW[p1].Treaty[p2] >= trPeace) then
    2894           AtPeace[p1, p2] := true;
     2894          AtPeace[p1, p2] := True;
    28952895
    28962896  if OriginLoc >= 0 then
    28972897  begin // update area only
    2898     i := 0;
     2898    I := 0;
    28992899    FillChar(BorderChanges, SizeOf(BorderChanges), 0);
    29002900    dyMax := 0;
    29012901    while (dyMax + 1) + (dyMax + 1) shr 1 <= CountryRadius do
    2902       inc(dyMax);
     2902      Inc(dyMax);
    29032903    for dy := -dyMax to dyMax do
    29042904    begin
     
    29062906      while abs(dy) + (dxMax + 2) + abs(abs(dy) - (dxMax + 2)) shr 1 <=
    29072907        CountryRadius do
    2908         inc(dxMax, 2);
     2908        Inc(dxMax, 2);
    29092909      for dx := -dxMax to dxMax do
    29102910        if (dy + dx) and 1 = 0 then
     
    29222922              else
    29232923                ChangeTerritory(Loc, NewOwner);
    2924             BorderChanges[i shr 3] := BorderChanges[i shr 3] or
    2925               ((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);
    29262926          end;
    2927           inc(i);
     2927          Inc(I);
    29282928        end;
    29292929    end;
     
    29382938      then
    29392939      begin
    2940         assert(OriginLoc <> -2); // test if border saving works
     2940        Assert(OriginLoc <> -2); // test if border saving works
    29412941        ChangeTerritory(Loc, NewOwner);
    29422942      end;
     
    29472947end;
    29482948
    2949 procedure LogCheckBorders(p, cix, PlayerLosingCity: integer);
    2950 begin
    2951   CheckBorders(RW[p].City[cix].Loc, PlayerLosingCity);
    2952   IntServer(sIntExpandTerritory, p, cix, BorderChanges);
     2949procedure LogCheckBorders(P, cix, PlayerLosingCity: Integer);
     2950begin
     2951  CheckBorders(RW[P].City[cix].Loc, PlayerLosingCity);
     2952  IntServer(sIntExpandTerritory, P, cix, BorderChanges);
    29532953end;
    29542954
     
    29582958}
    29592959
    2960 procedure CreateUnit(p, mix: integer);
    2961 begin
    2962   with RW[p] do
     2960procedure CreateUnit(P, mix: Integer);
     2961begin
     2962  with RW[P] do
    29632963  begin
    29642964    Un[nUn].mix := mix;
    29652965    with Un[nUn] do
    29662966    begin
    2967       ID := UnBuilt[p];
    2968       inc(UnBuilt[p]);
     2967      ID := UnBuilt[P];
     2968      Inc(UnBuilt[P]);
    29692969      Status := 0;
    29702970      SavedStatus := 0;
    2971       inc(Model[mix].Built);
     2971      Inc(Model[mix].Built);
    29722972      Home := -1;
    29732973      Health := 100;
     
    29852985      Master := -1;
    29862986    end;
    2987     inc(nUn);
     2987    Inc(nUn);
    29882988  end
    29892989end;
    29902990
    2991 procedure FreeUnit(p, uix: integer);
     2991procedure FreeUnit(P, uix: Integer);
    29922992// loc or master should be set after call
    29932993// implementation is critical for loading performance, change carefully
    29942994var
    2995   Loc0, uix1: integer;
    2996   Occ, ZoC: boolean;
    2997 begin
    2998   with RW[p].Un[uix] do
     2995  Loc0, uix1: Integer;
     2996  Occ, ZoC: Boolean;
     2997begin
     2998  with RW[P].Un[uix] do
    29992999  begin
    30003000    Job := jNone;
     
    30043004  if Occupant[Loc0] >= 0 then
    30053005  begin
    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
     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
    30113011        if (Loc = Loc0) and (Master < 0) and (uix1 <> uix) then
    30123012        begin
    3013           Occ := true;
    3014           if RW[p].Model[mix].Flags and mdZOC <> 0 then
     3013          Occ := True;
     3014          if RW[P].Model[mix].Flags and mdZOC <> 0 then
    30153015          begin
    3016             ZoC := true;
     3016            ZoC := True;
    30173017            Break;
    30183018          end;
     
    30253025end;
    30263026
    3027 procedure PlaceUnit(p, uix: integer);
    3028 begin
    3029   with RW[p].Un[uix] do
    3030   begin
    3031     Occupant[Loc] := p;
    3032     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
    30333033      ZoCMap[Loc] := 1;
    30343034  end;
    30353035end;
    30363036
    3037 procedure CountLost(p, mix, Enemy: integer);
    3038 begin
    3039   Inc(RW[p].Model[mix].Lost);
    3040   TellAboutModel(Enemy, p, mix);
    3041   Inc(Destroyed[Enemy, p, mix]);
    3042 end;
    3043 
    3044 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);
    30453045// use enemy only from inside sMoveUnit if attack
    30463046var
    3047   uix1: integer;
    3048 begin
    3049   with RW[p].Un[uix] do
    3050   begin
    3051     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));
    30523052    // already freed when spy mission
    30533053    if Loc >= 0 then
    3054       FreeUnit(p, uix);
     3054      FreeUnit(P, uix);
    30553055    if Master >= 0 then
    3056       if RW[p].Model[mix].Domain = dAir then
    3057         dec(RW[p].Un[Master].AirLoad)
     3056      if RW[P].Model[mix].Domain = dAir then
     3057        Dec(RW[P].Un[Master].AirLoad)
    30583058      else
    3059         dec(RW[p].Un[Master].TroopLoad);
     3059        Dec(RW[P].Un[Master].TroopLoad);
    30603060    if (TroopLoad > 0) or (AirLoad > 0) 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
     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
    30633063        { unit mastered by removed unit -- remove too }
    30643064        begin
    3065           RW[p].Un[uix1].Loc := -1;
     3065          RW[P].Un[uix1].Loc := -1;
    30663066          if Enemy >= 0 then
    3067             CountLost(p, RW[p].Un[uix1].mix, Enemy);
     3067            CountLost(P, RW[P].Un[uix1].mix, Enemy);
    30683068        end;
    30693069    Loc := -1;
    30703070    if Enemy >= 0 then
    3071       CountLost(p, mix, Enemy);
    3072   end;
    3073 end;
    3074 
    3075 procedure RemoveUnit_UpdateMap(p, uix: integer);
     3071      CountLost(P, mix, Enemy);
     3072  end;
     3073end;
     3074
     3075procedure RemoveUnit_UpdateMap(P, uix: Integer);
    30763076var
    30773077  Loc0: Integer;
    30783078begin
    3079   Loc0 := RW[p].Un[uix].Loc;
    3080   RemoveUnit(p, uix);
     3079  Loc0 := RW[P].Un[uix].Loc;
     3080  RemoveUnit(P, uix);
    30813081  if Mode > moLoading_Fast then
    30823082    UpdateUnitMap(Loc0);
    30833083end;
    30843084
    3085 procedure RemoveAllUnits(p, Loc: integer; Enemy: integer = -1);
    3086 var
    3087   uix: integer;
    3088 begin
    3089   for uix := 0 to RW[p].nUn - 1 do
    3090     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
    30913091    begin
    30923092      if Enemy >= 0 then
    3093         CountLost(p, RW[p].Un[uix].mix, Enemy);
    3094       RW[p].Un[uix].Loc := -1;
     3093        CountLost(P, RW[P].Un[uix].mix, Enemy);
     3094      RW[P].Un[uix].Loc := -1;
    30953095    end;
    30963096  Occupant[Loc] := -1;
     
    30983098end;
    30993099
    3100 procedure RemoveDomainUnits(d, p, Loc: integer);
    3101 var
    3102   uix: integer;
    3103 begin
    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)
     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)
    31063106    then
    3107       RemoveUnit(p, uix);
    3108 end;
    3109 
    3110 procedure FoundCity(p, FoundLoc: integer);
    3111 var
    3112   p1, cix1, V21, dx, dy: integer;
    3113 begin
    3114   if RW[p].nCity = ncmax then
    3115     exit;
    3116   inc(RW[p].nCity);
    3117   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
    31183118  begin
    31193119    Size := 2;
     
    31313131    if UsedByCity[FoundLoc] >= 0 then
    31323132    begin { central tile is exploited - toggle in exploiting city }
    3133       p1 := p;
     3133      p1 := P;
    31343134      SearchCity(UsedByCity[FoundLoc], p1, cix1);
    31353135      dxdy(UsedByCity[FoundLoc], FoundLoc, dx, dy);
     
    31423142      (fTerrain or fSpecial or fRiver or nPl shl 27) or fCity;
    31433143
    3144     ChangeTerritory(Loc, p);
    3145   end;
    3146 end;
    3147 
    3148 procedure StealCity(p, cix: integer; SaveUnits: boolean);
    3149 var
    3150   i, j, uix1, cix1, nearest: integer;
    3151 begin
    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
     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
    31573157        FreeSlaves;
    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
     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
    31653165    begin { destroy national projects }
    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
     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
    31733173      if (Loc >= 0) and (Home = cix) then
    31743174        if SaveUnits then
    31753175        begin // support units by nearest other city
    31763176          nearest := -1;
    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
     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
    31813181              nearest := cix1;
    31823182          Home := nearest;
    31833183        end
    31843184        else
    3185           RemoveUnit(p, uix1); // destroy supported units
    3186 end;
    3187 
    3188 procedure DestroyCity(p, cix: integer; SaveUnits: boolean);
    3189 var
    3190   i, V21: integer;
     3185          RemoveUnit(P, uix1); // destroy supported units
     3186end;
     3187
     3188procedure DestroyCity(P, cix: Integer; SaveUnits: Boolean);
     3189var
     3190  I, V21: Integer;
    31913191  Radius: TVicinity21Loc;
    31923192begin
    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;
     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;
    31983198    V21_to_Loc(Loc, Radius);
    31993199    for V21 := 1 to 26 do
     
    32013201        UsedByCity[Radius[V21]] := -1;
    32023202    RealMap[Loc] := RealMap[Loc] and not fCity;
    3203     Loc := -1
    3204   end;
    3205 end;
    3206 
    3207 procedure ChangeCityOwner(pOld, cixOld, pNew: integer);
    3208 var
    3209   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;
    32103210  Radius: TVicinity21Loc;
    32113211begin
    3212   inc(RW[pNew].nCity);
     3212  Inc(RW[pNew].nCity);
    32133213  RW[pNew].City[RW[pNew].nCity - 1] := RW[pOld].City[cixOld];
    3214   StealCity(pOld, cixOld, false);
     3214  StealCity(pOld, cixOld, False);
    32153215  RW[pOld].City[cixOld].Loc := -1;
    32163216  with RW[pNew].City[(RW[pNew].nCity - 1)] do
     
    32313231      begin
    32323232        Loc1 := Radius[V21];
    3233         assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));
     3233        Assert((Loc1 >= 0) and (Loc1 < MapSize) and (UsedByCity[Loc1] = Loc));
    32343234        if (ZoCMap[Loc1] > 0) and (Occupant[Loc1] <> pNew) and
    32353235          (RW[pNew].Treaty[Occupant[Loc1]] < trAlliance) then
     
    32433243    Built[imTownHall] := 0;
    32443244    Built[imCourt] := 0;
    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
     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
    32503250      begin // new wonder owner!
    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
     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
    32563256              for cix1 := 0 to (RW[pNew].nCity - 1) do
    3257                 if RW[pNew].City[cix1].Built[j] = 1 then
    3258                   GWonder[j].EffectiveOwner := pNew;
     3257                if RW[pNew].City[cix1].Built[J] = 1 then
     3258                  GWonder[J].EffectiveOwner := pNew;
    32593259        end
    32603260        else
    3261           CheckExpiration(i);
    3262         case i of
     3261          CheckExpiration(I);
     3262        case I of
    32633263          woLighthouse:
    32643264            CheckSpecialModels(pNew, preLighthouse);
     
    32743274    cix1 := RW[pNew].nEnemyCity - 1;
    32753275    while (cix1 >= 0) and (RW[pNew].EnemyCity[cix1].Loc <> Loc) do
    3276       dec(cix1);
    3277     assert(cix1 >= 0);
     3276      Dec(cix1);
     3277    Assert(cix1 >= 0);
    32783278    RW[pNew].EnemyCity[cix1].Loc := -1;
    32793279
     
    32823282end;
    32833283
    3284 procedure CompleteJob(p, Loc, Job: integer);
    3285 var
    3286   ChangedTerrain, p1: integer;
    3287 begin
    3288   assert(Job <> jCity);
     3284procedure CompleteJob(P, Loc, Job: Integer);
     3285var
     3286  ChangedTerrain, p1: Integer;
     3287begin
     3288  Assert(Job <> jCity);
    32893289  ChangedTerrain := -1;
    32903290  case Job of
     
    33283328        if not(RealMap[Loc] and fTerrain in TerrType_Canalable) then
    33293329        begin
    3330           RemoveDomainUnits(dSea, p, Loc);
     3330          RemoveDomainUnits(dSea, P, Loc);
    33313331          RealMap[Loc] := RealMap[Loc] and not fCanal;
    33323332        end;
     
    33403340      begin
    33413341        if RealMap[Loc] and fTerImp = tiBase then
    3342           RemoveDomainUnits(dAir, p, Loc);
     3342          RemoveDomainUnits(dAir, P, Loc);
    33433343        RealMap[Loc] := RealMap[Loc] and not fTerImp
    33443344      end
    33453345      else if RealMap[Loc] and fCanal <> 0 then
    33463346      begin
    3347         RemoveDomainUnits(dSea, p, Loc);
     3347        RemoveDomainUnits(dSea, P, Loc);
    33483348        RealMap[Loc] := RealMap[Loc] and not fCanal
    33493349      end
     
    33813381  ____________________________________________________________________
    33823382}
    3383 procedure GiveCivilReport(p, pAbout: integer);
    3384 begin
    3385   with RW[p].EnemyReport[pAbout]^ do
     3383procedure GiveCivilReport(P, pAbout: Integer);
     3384begin
     3385  with RW[P].EnemyReport[pAbout]^ do
    33863386  begin
    33873387    // general info
    33883388    TurnOfCivilReport := LastValidStat[pAbout];
    3389     move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));
     3389    Move(RW[pAbout].Treaty, Treaty, SizeOf(Treaty));
    33903390    Government := RW[pAbout].Government;
    33913391    Money := RW[pAbout].Money;
     
    33963396    if ResearchDone > 100 then
    33973397      ResearchDone := 100;
    3398     move(RW[pAbout].Tech, Tech, nAdv);
    3399   end;
    3400 end;
    3401 
    3402 procedure GiveMilReport(p, pAbout: integer);
    3403 var
    3404   uix, mix: integer;
    3405 begin
    3406   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
    34073407  begin
    34083408    TurnOfMilReport := LastValidStat[pAbout];
     
    34103410    for mix := 0 to RW[pAbout].nModel - 1 do
    34113411    begin
    3412       TellAboutModel(p, pAbout, mix);
     3412      TellAboutModel(P, pAbout, mix);
    34133413      UnCount[mix] := 0
    34143414    end;
    34153415    for uix := 0 to RW[pAbout].nUn - 1 do
    34163416      if RW[pAbout].Un[uix].Loc >= 0 then
    3417         inc(UnCount[RW[pAbout].Un[uix].mix]);
    3418   end;
    3419 end;
    3420 
    3421 procedure ShowPrice(pSender, pTarget, Price: integer);
     3417        Inc(UnCount[RW[pAbout].Un[uix].mix]);
     3418  end;
     3419end;
     3420
     3421procedure ShowPrice(pSender, pTarget, Price: Integer);
    34223422begin
    34233423  case Price and opMask of
     
    34343434end;
    34353435
    3436 function CopyCivilReport(pSender, pTarget, pAbout: integer): boolean;
    3437 var
    3438   i: integer;
     3436function CopyCivilReport(pSender, pTarget, pAbout: Integer): Boolean;
     3437var
     3438  I: Integer;
    34393439  rSender, rTarget: ^TEnemyReport;
    34403440begin // copy third nation civil report
    3441   result := false;
     3441  Result := False;
    34423442  if RW[pTarget].Treaty[pAbout] = trNoContact then
    34433443    IntroduceEnemy(pTarget, pAbout);
    3444   rSender := pointer(RW[pSender].EnemyReport[pAbout]);
    3445   rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);
     3444  rSender := Pointer(RW[pSender].EnemyReport[pAbout]);
     3445  rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]);
    34463446  if rSender.TurnOfCivilReport > rTarget.TurnOfCivilReport then
    34473447  begin // only if newer than current information
     
    34523452    rTarget.ResearchTech := rSender.ResearchTech;
    34533453    rTarget.ResearchDone := rSender.ResearchDone;
    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;
    3462 end;
    3463 
    3464 function CopyMilReport(pSender, pTarget, pAbout: integer): boolean;
    3465 var
    3466   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;
    34673467  rSender, rTarget: ^TEnemyReport;
    34683468begin // copy third nation military report
    3469   result := false;
     3469  Result := False;
    34703470  if RW[pTarget].Treaty[pAbout] = trNoContact then
    34713471    IntroduceEnemy(pTarget, pAbout);
    3472   rSender := pointer(RW[pSender].EnemyReport[pAbout]);
    3473   rTarget := pointer(RW[pTarget].EnemyReport[pAbout]);
     3472  rSender := Pointer(RW[pSender].EnemyReport[pAbout]);
     3473  rTarget := Pointer(RW[pTarget].EnemyReport[pAbout]);
    34743474  if rSender.TurnOfMilReport > rTarget.TurnOfMilReport then
    34753475  begin // only if newer than current information
    34763476    rTarget.TurnOfMilReport := rSender.TurnOfMilReport;
    34773477    rTarget.nModelCounted := rSender.nModelCounted;
    3478     move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);
     3478    Move(rSender.UnCount, rTarget.UnCount, 2 * rSender.nModelCounted);
    34793479    for mix := 0 to rTarget.nModelCounted - 1 do
    34803480      TellAboutModel(pTarget, pAbout, mix);
    3481     result := true;
    3482   end;
    3483 end;
    3484 
    3485 procedure CopyModel(pSender, pTarget, mix: integer);
    3486 var
    3487   i: integer;
     3481    Result := True;
     3482  end;
     3483end;
     3484
     3485procedure CopyModel(pSender, pTarget, mix: Integer);
     3486var
     3487  I: Integer;
    34883488  miSender, miTarget: TModelInfo;
    3489   ok: boolean;
     3489  ok: Boolean;
    34903490begin
    34913491  // only if target doesn't already have a model like this
    34923492  ok := RW[pTarget].nModel < nmmax;
    34933493  MakeModelInfo(pSender, mix, RW[pSender].Model[mix], miSender);
    3494   for i := 0 to RW[pTarget].nModel - 1 do
    3495   begin
    3496     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);
    34973497    if IsSameModel(miSender, miTarget) then
    3498       ok := false;
     3498      ok := False;
    34993499  end;
    35003500  if ok then
     
    35113511      Lost := 0;
    35123512    end;
    3513     inc(RW[pTarget].nModel);
    3514     inc(Researched[pTarget]);
     3513    Inc(RW[pTarget].nModel);
     3514    Inc(Researched[pTarget]);
    35153515    TellAboutModel(pSender, pTarget, RW[pTarget].nModel - 1);
    35163516  end;
    35173517end;
    35183518
    3519 procedure CopyMap(pSender, pTarget: integer);
    3520 var
    3521   Loc, i, cix: integer;
     3519procedure CopyMap(pSender, pTarget: Integer);
     3520var
     3521  Loc, I, cix: Integer;
    35223522  Tile: Cardinal;
    35233523begin
     
    35293529      if Tile and fCity <> 0 then
    35303530      begin
    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;
     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;
    35413541        end;
    35423542        if Tile and fOwned <> 0 then
     
    35443544          cix := RW[pSender].nCity - 1;
    35453545          while (cix >= 0) and (RW[pSender].City[cix].Loc <> Loc) do
    3546             dec(cix);
    3547           MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[i]);
     3546            Dec(cix);
     3547          MakeCityInfo(pSender, cix, RW[pTarget].EnemyCity[I]);
    35483548        end
    35493549        else // city not owned by sender -- copy old info
     
    35513551          cix := RW[pSender].nEnemyCity - 1;
    35523552          while (cix >= 0) and (RW[pSender].EnemyCity[cix].Loc <> Loc) do
    3553             dec(cix);
    3554           RW[pTarget].EnemyCity[i] := RW[pSender].EnemyCity[cix];
     3553            Dec(cix);
     3554          RW[pTarget].EnemyCity[I] := RW[pSender].EnemyCity[cix];
    35553555        end;
    35563556      end
     
    35663566
    35673567      if RW[pTarget].Map[Loc] and fTerrain = fUNKNOWN then
    3568         inc(Discovered[pTarget]);
     3568        Inc(Discovered[pTarget]);
    35693569      RW[pTarget].Map[Loc] := RW[pTarget].Map[Loc] and fInEnemyZoC
    35703570      // always preserve this flag!
     
    35823582end;
    35833583
    3584 function PayPrice(pSender, pTarget, Price: integer; execute: boolean): boolean;
    3585 var
    3586   pSubject, i, n, NewTreaty: integer;
    3587 begin
    3588   result := true;
     3584function PayPrice(pSender, pTarget, Price: Integer; execute: Boolean): Boolean;
     3585var
     3586  pSubject, I, N, NewTreaty: Integer;
     3587begin
     3588  Result := True;
    35893589  case Price and opMask of
    35903590    opCivilReport: // + turn + concerned player shl 16
     
    35923592        pSubject := Price shr 16 and $F;
    35933593        if pTarget = pSubject then
    3594           result := false
     3594          Result := False
    35953595        else if pSender = pSubject then
    35963596        begin
     
    35993599        end
    36003600        else if RW[pSender].EnemyReport[pSubject].TurnOfCivilReport < 0 then
    3601           result := false
     3601          Result := False
    36023602        else if execute then
    36033603          CopyCivilReport(pSender, pTarget, pSubject);
     
    36073607        pSubject := Price shr 16 and $F;
    36083608        if pTarget = pSubject then
    3609           result := false
     3609          Result := False
    36103610        else if pSender = pSubject then
    36113611        begin
     
    36143614        end
    36153615        else if RW[pSender].EnemyReport[pSubject].TurnOfMilReport < 0 then
    3616           result := false
     3616          Result := False
    36173617        else if execute then
    36183618          CopyMilReport(pSender, pTarget, pSubject);
     
    36293629        begin // agreed treaty end
    36303630          if execute then
    3631             CancelTreaty(pSender, pTarget, false);
     3631            CancelTreaty(pSender, pTarget, False);
    36323632        end
    36333633        else
     
    36403640            NewTreaty := trPeace;
    36413641          if NewTreaty < 0 then
    3642             result := false
     3642            Result := False
    36433643          else if execute then
    36443644          begin
    3645             assert(NewTreaty > RW[pSender].Treaty[pTarget]);
     3645            Assert(NewTreaty > RW[pSender].Treaty[pTarget]);
    36463646            RW[pSender].Treaty[pTarget] := NewTreaty;
    36473647            RW[pTarget].Treaty[pSender] := NewTreaty;
     
    36723672    opShipParts: // + number + part type shl 16
    36733673      begin
    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
     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
    36773677        begin
    36783678          if execute then
    36793679          begin
    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];
     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];
    36833683            if RW[pTarget].NatBuilt[imSpacePort] > 0 then
    36843684            begin // space ship control requires space port
    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];
     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];
    36883688            end;
    36893689          end;
    36903690        end
    36913691        else
    3692           result := false;
     3692          Result := False;
    36933693      end;
    36943694    opMoney: // + value
     
    36983698        if execute then
    36993699        begin
    3700           dec(RW[pSender].Money, Price - opMoney);
    3701           inc(RW[pTarget].Money, Price - opMoney);
     3700          Dec(RW[pSender].Money, Price - opMoney);
     3701          Inc(RW[pTarget].Money, Price - opMoney);
    37023702        end;
    37033703      end
    37043704      else
    3705         result := false;
     3705        Result := False;
    37063706    opTribute: // + value
    37073707      if execute then
     
    37183718      end
    37193719      else
    3720         result := false;
     3720        Result := False;
    37213721    opAllTech:
    37223722      if execute then
    3723         for i := 0 to nAdv - 1 do
    3724           if (RW[pSender].Tech[i] >= tsApplicable) and
    3725             (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
    37263726          begin
    3727             SeeTech(pTarget, i);
    3728             RW[pSender].EnemyReport[pTarget].Tech[i] := tsSeen;
    3729             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;
    37303730          end;
    37313731    opModel: // + model index
     
    37363736      end
    37373737      else
    3738         result := false;
     3738        Result := False;
    37393739    opAllModel:
    37403740      if execute then
    3741         for i := 0 to RW[pSender].nModel - 1 do
    3742         begin
    3743           TellAboutModel(pTarget, pSender, i);
    3744           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);
    37453745        end;
    37463746    { opCity: // + city ID
    37473747      begin
    3748       result:=false
     3748      Result:=False
    37493749      end; }
    37503750  end;
    37513751end;
    37523752
    3753 procedure CancelTreaty(p, pWith: integer; DecreaseCredibility: boolean);
     3753procedure CancelTreaty(P, pWith: Integer; DecreaseCredibility: Boolean);
    37543754// side effect: PeaceEnded := bitarray of players with which peace treaty was canceled
    37553755var
    3756   p1, OldTreaty: integer;
    3757 begin
    3758   OldTreaty := RW[p].Treaty[pWith];
     3756  p1, OldTreaty: Integer;
     3757begin
     3758  OldTreaty := RW[P].Treaty[pWith];
    37593759  PeaceEnded := 0;
    37603760  if OldTreaty >= trPeace then
    3761     RW[p].LastCancelTreaty[pWith] := GTurn;
     3761    RW[P].LastCancelTreaty[pWith] := GTurn;
    37623762  if DecreaseCredibility then
    37633763  begin
     
    37653765      trPeace:
    37663766        begin
    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;
     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;
    37723772        end;
    37733773      trAlliance:
    3774         RW[p].Credibility := RW[p].Credibility * 3 div 4;
    3775     end;
    3776     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;
    37773777  end;
    37783778
     
    37803780  begin
    37813781    for p1 := 0 to nPl - 1 do
    3782       if (p1 = pWith) or DecreaseCredibility and (p1 <> p) and
    3783         (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)
    37843784      then
    37853785      begin
    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);
     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);
    37913791      end;
    37923792    CheckBorders(-1);
    37933793    if (Mode > moLoading_Fast) and (PeaceEnded > 0) then
    3794       RecalcMapZoC(p);
     3794      RecalcMapZoC(P);
    37953795  end
    37963796  else
    37973797  begin
    3798     RW[p].Treaty[pWith] := OldTreaty - 1;
    3799     RW[pWith].Treaty[p] := OldTreaty - 1;
     3798    RW[P].Treaty[pWith] := OldTreaty - 1;
     3799    RW[pWith].Treaty[P] := OldTreaty - 1;
    38003800    if OldTreaty = TrFriendlyContact then
    38013801    begin // necessary for loading
    3802       GiveCivilReport(p, pWith);
    3803       GiveCivilReport(pWith, p);
     3802      GiveCivilReport(P, pWith);
     3803      GiveCivilReport(pWith, P);
    38043804    end
    38053805    else if OldTreaty = trAlliance then
    38063806    begin // necessary for loading
    3807       GiveMilReport(p, pWith);
    3808       GiveMilReport(pWith, p);
     3807      GiveMilReport(P, pWith);
     3808      GiveMilReport(pWith, P);
    38093809    end;
    38103810    if (Mode > moLoading_Fast) and (OldTreaty = trAlliance) then
    38113811    begin
    3812       RecalcMapZoC(p);
     3812      RecalcMapZoC(P);
    38133813      RecalcMapZoC(pWith);
    38143814    end;
     
    38163816  if OldTreaty in [trPeace, trAlliance] then
    38173817  begin
    3818     RecalcPeaceMap(p);
     3818    RecalcPeaceMap(P);
    38193819    RecalcPeaceMap(pWith);
    38203820  end;
    38213821end;
    38223822
    3823 function DoSpyMission(p, pCity, cix, Mission: integer): Cardinal;
    3824 var
    3825   p1: integer;
    3826 begin
    3827   result := 0;
     3823function DoSpyMission(P, pCity, cix, Mission: Integer): Cardinal;
     3824var
     3825  p1: Integer;
     3826begin
     3827  Result := 0;
    38283828  case Mission of
    38293829    smSabotageProd:
     
    38323832    smStealMap:
    38333833      begin
    3834         CopyMap(pCity, p);
    3835         RecalcPeaceMap(p);
     3834        CopyMap(pCity, P);
     3835        RecalcPeaceMap(P);
    38363836      end;
    38373837    smStealCivilReport:
    38383838      begin
    3839         if RW[p].Treaty[pCity] = trNoContact then
    3840           IntroduceEnemy(p, pCity);
    3841         GiveCivilReport(p, pCity);
     3839        if RW[P].Treaty[pCity] = trNoContact then
     3840          IntroduceEnemy(P, pCity);
     3841        GiveCivilReport(P, pCity);
    38423842      end;
    38433843    smStealMilReport:
    38443844      begin
    3845         if RW[p].Treaty[pCity] = trNoContact then
    3846           IntroduceEnemy(p, pCity);
    3847         GiveMilReport(p, pCity);
     3845        if RW[P].Treaty[pCity] = trNoContact then
     3846          IntroduceEnemy(P, pCity);
     3847        GiveMilReport(P, pCity);
    38483848      end;
    38493849    smStealForeignReports:
    38503850      begin
    38513851        for p1 := 0 to nPl - 1 do
    3852           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)
    38533853          then
    38543854          begin
    38553855            if RW[pCity].EnemyReport[p1].TurnOfCivilReport >= 0 then
    3856               if CopyCivilReport(pCity, p, p1) then
    3857                 result := result or (1 shl (2 * p1));
     3856              if CopyCivilReport(pCity, P, p1) then
     3857                Result := Result or (1 shl (2 * p1));
    38583858            if RW[pCity].EnemyReport[p1].TurnOfMilReport >= 0 then
    3859               if CopyMilReport(pCity, p, p1) then
    3860                 result := result or (2 shl (2 * p1));
     3859              if CopyMilReport(pCity, P, p1) then
     3860                Result := Result or (2 shl (2 * p1));
    38613861          end;
    38623862      end;
     
    38683868  ____________________________________________________________________
    38693869}
    3870 procedure ClearTestFlags(ClearFlags: integer);
    3871 var
    3872   p1: integer;
     3870procedure ClearTestFlags(ClearFlags: Integer);
     3871var
     3872  p1: Integer;
    38733873begin
    38743874  GTestFlags := GTestFlags and (not ClearFlags or tfTested or tfAllTechs or
     
    38793879end;
    38803880
    3881 procedure SetTestFlags(p, SetFlags: integer);
    3882 var
    3883   i, p1, p2, MoreFlags: integer;
     3881procedure SetTestFlags(P, SetFlags: Integer);
     3882var
     3883  I, p1, p2, MoreFlags: Integer;
    38843884begin
    38853885  MoreFlags := SetFlags and not GTestFlags;
     
    39053905      if 1 shl p1 and GAlive <> 0 then
    39063906      begin
    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
     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
    39093909          begin
    3910             RW[p1].Tech[i] := tsCheat;
    3911             CheckSpecialModels(p1, i);
     3910            RW[p1].Tech[I] := tsCheat;
     3911            CheckSpecialModels(p1, I);
    39123912          end;
    39133913        for p2 := 0 to nPl - 1 do
    39143914          if (p2 <> p1) and (1 shl p2 and (GAlive or GWatching) <> 0) then
    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;
     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;
    39183918      end;
    39193919    end;
     
    39213921  if MoreFlags and tfUncover <> 0 then
    39223922  begin
    3923     DiscoverAll(p, lObserveSuper);
     3923    DiscoverAll(P, lObserveSuper);
    39243924    for p1 := 0 to nPl - 1 do
    39253925      if 1 shl p1 and GAlive <> 0 then
    39263926      begin
    39273927        ResourceMask[p1] := $FFFFFFFF;
    3928         if p1 <> p then
    3929         begin
    3930           GiveCivilReport(p, p1);
    3931           GiveMilReport(p, p1);
     3928        if p1 <> P then
     3929        begin
     3930          GiveCivilReport(P, p1);
     3931          GiveMilReport(P, p1);
    39323932        end;
    39333933      end;
     
    39393939  ____________________________________________________________________
    39403940}
    3941 procedure IntServer(Command, Player, Subject: integer; var Data);
    3942 var
    3943   i, p1: integer;
     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);
     
    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);
     4071        RW[Player].EnemyCity[Subject].Status := Integer(Data);
    40724072      end;
    40734073  end;
  • trunk/Direct.pas

    r423 r447  
    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;
     
    5757//  hMem: Cardinal;
    5858//  p: pointer;
    59   s: string;
     59  S: string;
    6060Begin
    6161  case ID of
     
    7272      if visible then
    7373      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);
     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);
    7878      end;
    7979    ntCreateWorld:
     
    111111          hMem := GlobalAlloc(GMEM_MOVEABLE or GMEM_DDESHARE,
    112112            Length(NotifyMessage));
    113           p := GlobalLock(hMem);
    114           if p <> nil then
    115             move(NotifyMessage[1], p^, Length(NotifyMessage));
     113          P := GlobalLock(hMem);
     114          if P <> nil then
     115            Move(NotifyMessage[1], P^, Length(NotifyMessage));
    116116          GlobalUnlock(hMem);
    117117          SetClipboardData(CF_TEXT, hMem);
     
    198198  begin
    199199    PostMessage(Handle, WM_GO, 0, 0);
    200     Gone := true;
     200    Gone := True;
    201201  end;
    202202end;
     
    209209procedure TDirectDlg.OnGo(var Msg: TMessage);
    210210var
    211   i: integer;
    212   s: string;
     211  I: Integer;
     212  S: string;
    213213  FileName: string;
    214214begin
     
    220220    Exit;
    221221  end;
    222   Quick := false;
     222  Quick := False;
    223223  if ParamCount > 0 then
    224224  begin
    225     s := ParamStr(1);
    226     if (s[1] = '-') {$IFDEF WINDOWS}or (s[1] = '/'){$ENDIF} then
     225    S := ParamStr(1);
     226    if (S[1] = '-') {$IFDEF WINDOWS}or (S[1] = '/'){$ENDIF} then
    227227    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
     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
    233233      begin
    234         Quick := true;
     234        Quick := True;
    235235        DirectHelp(cHelpOnly);
    236236        Close;
     
    242242        Quick := True;
    243243        if not LoadGame(ExtractFilePath(ParamStr(1)), ExtractFileName(ParamStr(1)
    244         ), -1, false) then begin
     244        ), -1, False) then begin
    245245          SimpleMessage(Phrases.Lookup('LOADERR'));
    246246          Close;
     
    297297end;
    298298
    299 procedure TDirectDlg.SetInfo(x: string);
    300 begin
    301   Info := x;
     299procedure TDirectDlg.SetInfo(X: string);
     300begin
     301  Info := X;
    302302  Invalidate;
    303303  Update;
     
    307307end;
    308308
    309 procedure TDirectDlg.SetState(x: integer);
    310 begin
    311   if (x < 0) <> (State < 0) then begin
    312     State := x;
     309procedure TDirectDlg.SetState(X: Integer);
     310begin
     311  if (X < 0) <> (State < 0) then begin
     312    State := X;
    313313    Invalidate;
    314314    Update;
    315315  end
    316   else if x <> State then begin
    317     State := x;
     316  else if X <> State then begin
     317    State := X;
    318318    PaintProgressBar(Canvas, 6, ClientWidth div 2 - 64, 40, State, 128 - State,
    319319      128, MainTexture);
  • trunk/GameServer.pas

    r442 r447  
    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}
     
    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 }
     552    S := 'cEvoMap'#0;
     553    MapFile.write(S[1], 8); { file id }
     554    I := 0;
     555    MapFile.write(I, 4); { format id }
    556556    MapFile.write(MaxTurn, 4);
    557557    MapFile.write(lx, 4);
     
    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
     580      MapFile.read(I, 4); // MaxTurn
    581581      MapFile.read(lx, 4);
    582582      MapFile.read(ly, 4);
     
    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;
     
    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 }
     642  S := 'cEvoBook';
     643  LogFile.write(S[1], 8); { file id }
     644  I := CevoVersion;
     645  LogFile.write(I, 4); { c-evo version }
    646646  LogFile.write(ExeInfo.Time, 4);
    647647  LogFile.write(lx, 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
    662662    LogFile.write(SaveMap, ((MapSize - 1) div 4 + 1) * 4);
    663   for i := 0 to nPl - 1 do
    664     if not Assigned(bix[i]) then
     663  for I := 0 to nPl - 1 do
     664    if not Assigned(bix[I]) then
    665665      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
     
    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;
     836          RW[P].DefaultDebugMap := nil;
    837837
    838838        { !!!for i:=0 to nShipPart-1 do GShip[p].Parts[i]:=Delphirandom((3-i)*2); }
     
    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;
     
    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);
     
    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}
     
    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
     
    18241824          DiscoverTech(pTurn, ResearchTech);
    18251825
    1826         dec(Research, Cost);
     1826        Dec(Research, Cost);
    18271827        Happened := Happened or phTech;
    18281828        ResearchTech := -1;
     
    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);
     
    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
     
    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
     
    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;
    22912291end;
    22922292
    2293 function ExecuteAttack(p, uix, ToLoc: integer; var MoveInfo: TMoveInfo;
    2294   ShowMove: TShowMove): integer;
     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
     
    25612561end;
    25622562
    2563 function MoveUnit(p, uix, dx, dy: integer; TestOnly: boolean): integer;
     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;
     
    26142614end;
    26152615
    2616 function Server(Command, Player, Subject: integer; var Data): integer; stdcall;
    2617 
    2618   function CountPrice(const Offer: TOffer; PriceType: integer): integer;
     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;
     
    27082708  end;
    27092709
    2710   assert(MapSize = lx * ly);
    2711   assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);
     2710  Assert(MapSize = lx * ly);
     2711  Assert(Command and (sctMask or sExecute) <> sctInternal or sExecute);
    27122712  // not for internal commands
    27132713  if (Command < 0) or (Command >= $10000) then
    27142714  begin
    2715     result := eUnknown;
    2716     exit;
     2715    Result := eUnknown;
     2716    Exit;
    27172717  end;
    27182718
     
    27212721    ((Subject < 0) or (Subject >= $1000))) then
    27222722  begin
    2723     result := eInvalid;
    2724     exit;
     2723    Result := eInvalid;
     2724    Exit;
    27252725  end;
    27262726
     
    27312731  begin
    27322732    PutMessage(1 shl 16 + 1, Format('NOT Alive: %d', [Player]));
    2733     result := eNoTurn;
    2734     exit;
     2733    Result := eNoTurn;
     2734    Exit;
    27352735  end;
    27362736
    2737   result := eOK;
     2737  Result := eOK;
    27382738
    27392739  // check if command allowed now
     
    27582758    PutMessage(1 shl 16 + 1, Format('No Turn: %d calls %x',
    27592759      [Player, Command shr 4]));
    2760     result := eNoTurn;
    2761     exit;
     2760    Result := eNoTurn;
     2761    Exit;
    27622762  end;
    27632763
     
    27672767  HandoverStack[nHandoverStack] := Player + $1000;
    27682768  HandoverStack[nHandoverStack + 1] := Command;
    2769   inc(nHandoverStack, 2);
     2769  Inc(nHandoverStack, 2);
    27702770
    27712771  InvalidTreatyMap := 0;
     
    27802780    FormerCLState := CL.State;
    27812781    CL.Put(Command, Player, Subject, @Data);
    2782     logged := true;
     2782    logged := True;
    27832783  end
    27842784  else
    2785     logged := false;
     2785    logged := False;
    27862786
    27872787  case Command of
     
    27982798
    27992799    sGetDebugMap:
    2800       pointer(Data) := DebugMap[Subject];
     2800      Pointer(Data) := DebugMap[Subject];
    28012801
    28022802    { sChangeSuperView:
    28032803      if Difficulty[Player]=0 then
    28042804      begin
    2805       for i:=0 to nBrain-1 do if Brain[i].Initialized then
    2806       CallClient(i, cShowSuperView, Subject)
     2805      for I:=0 to nBrain-1 do if Brain[I].Initialized then
     2806      CallClient(I, cShowSuperView, Subject)
    28072807      end
    2808       else result:=eInvalid; }
     2808      else Result:=eInvalid; }
    28092809
    28102810    sRefreshDebugMap:
     
    28292829          else
    28302830            StopTurn := RW[Player].EnemyReport[Subject].TurnOfCivilReport + 1;
    2831         move(Stat[Command shr 4 and $F, Subject]^, Data,
    2832           StopTurn * SizeOf(integer));
     2831        Move(Stat[Command shr 4 and $F, Subject]^, Data,
     2832          StopTurn * SizeOf(Integer));
    28332833        FillChar(TChart(Data)[StopTurn], (GTurn - StopTurn) *
    2834           SizeOf(integer), 0);
     2834          SizeOf(Integer), 0);
    28352835      end
    28362836      else
    2837         result := eInvalid;
     2837        Result := eInvalid;
    28382838
    28392839    sGetTechCost:
    2840       integer(Data) := TechCost(Player);
     2840      Integer(Data) := TechCost(Player);
    28412841
    28422842    sGetAIInfo:
    28432843      if AIInfo[Subject] = '' then
    2844         pchar(Data) := nil
    2845       else
    2846         pchar(Data) := @AIInfo[Subject][1];
     2844        PChar(Data) := nil
     2845      else
     2846        PChar(Data) := @AIInfo[Subject][1];
    28472847
    28482848    sGetAICredits:
    28492849      if AICredits = '' then
    2850         pchar(Data) := nil
    2851       else
    2852         pchar(Data) := @AICredits[1];
     2850        PChar(Data) := nil
     2851      else
     2852        PChar(Data) := @AICredits[1];
    28532853
    28542854    sGetVersion:
    2855       integer(Data) := CevoVersion;
     2855      Integer(Data) := CevoVersion;
    28562856
    28572857    sGetGameChanged:
    28582858      if Player <> 0 then
    2859         result := eInvalid
     2859        Result := eInvalid
    28602860      else if (CL <> nil) and (CL.State.nLog = nLogOpened) and
    28612861        (CL.State.MoveCode = 0) and not HasCityTileChanges and
    28622862        not HasChanges(Player) then
    2863         result := eNotChanged;
     2863        Result := eNotChanged;
    28642864
    28652865    sGetTileInfo:
    28662866      if (Subject >= 0) and (Subject < MapSize) then
    2867         result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))
    2868       else
    2869         result := eInvalid;
     2867        Result := GetTileInfo(Player, -2, Subject, TTileInfo(Data))
     2868      else
     2869        Result := eInvalid;
    28702870
    28712871    sGetCityTileInfo:
    28722872      if (Subject >= 0) and (Subject < MapSize) then
    2873         result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))
    2874       else
    2875         result := eInvalid;
     2873        Result := GetTileInfo(Player, -1, Subject, TTileInfo(Data))
     2874      else
     2875        Result := eInvalid;
    28762876
    28772877    sGetHypoCityTileInfo:
     
    28802880        if (TTileInfo(Data).ExplCity < 0) or
    28812881          (TTileInfo(Data).ExplCity >= RW[Player].nCity) then
    2882           result := eInvalid
     2882          Result := eInvalid
    28832883        else if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then
    2884           result := eNoPreq
     2884          Result := eNoPreq
    28852885        else
    2886           result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,
     2886          Result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject,
    28872887            TTileInfo(Data));
    28882888      end
    28892889      else
    2890         result := eInvalid;
     2890        Result := eInvalid;
    28912891
    28922892    sGetJobProgress:
     
    28942894      begin
    28952895        if ObserveLevel[Subject] shr (Player * 2) and 3 = 0 then
    2896           result := eNoPreq
     2896          Result := eNoPreq
    28972897        else
    2898           result := GetJobProgress(Player, Subject, TJobProgressData(Data));
     2898          Result := GetJobProgress(Player, Subject, TJobProgressData(Data));
    28992899      end
    29002900      else
    2901         result := eInvalid;
     2901        Result := eInvalid;
    29022902
    29032903    sGetModels:
     
    29112911      end
    29122912      else
    2913         result := eInvalid;
     2913        Result := eInvalid;
    29142914
    29152915    sGetUnits:
    29162916      if (Subject >= 0) and (Subject < MapSize) and
    29172917        (ObserveLevel[Subject] shr (Player * 2) and 3 = lObserveSuper) then
    2918         integer(Data) := GetUnitStack(Player, Subject)
    2919       else
    2920         result := eNoPreq;
     2918        Integer(Data) := GetUnitStack(Player, Subject)
     2919      else
     2920        Result := eNoPreq;
    29212921
    29222922    sGetDefender:
    29232923      if (Subject >= 0) and (Subject < MapSize) and (Occupant[Subject] = Player)
    29242924      then
    2925         Strongest(Subject, integer(Data), d, i, j)
    2926       else
    2927         result := eInvalid;
     2925        Strongest(Subject, Integer(Data), D, I, J)
     2926      else
     2927        Result := eInvalid;
    29282928
    29292929    sGetBattleForecast, sGetBattleForecastEx:
     
    29352935            ((pAtt = Player) or (RWemix[Player, pAtt, mixAtt] >= 0)) then
    29362936          begin
    2937             result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,
     2937            Result := GetBattleForecast(Subject, TBattleForecast(Data), uix1,
    29382938              cix1, AStr, DStr, ABaseDamage, DBaseDamage);
    29392939            if Command = sGetBattleForecastEx then
     
    29442944              TBattleForecastEx(Data).DBaseDamage := DBaseDamage;
    29452945            end;
    2946             if result = eOK then
    2947               result := eInvalid; // no enemy unit there!
     2946            if Result = eOK then
     2947              Result := eInvalid; // no enemy unit there!
    29482948          end
    29492949          else
    2950             result := eInvalid
    2951       else
    2952         result := eInvalid;
     2950            Result := eInvalid
     2951      else
     2952        Result := eInvalid;
    29532953
    29542954    sGetUnitReport:
    29552955      if (Subject < 0) or (Subject >= RW[Player].nUn) or
    29562956        (RW[Player].Un[Subject].Loc < 0) then
    2957         result := eInvalid
     2957        Result := eInvalid
    29582958      else
    29592959        GetUnitReport(Player, Subject, TUnitReport(Data));
     
    29622962      if (Subject < 0) or (Subject >= RW[Player].nUn) or
    29632963        (RW[Player].Un[Subject].Loc < 0) then
    2964         result := eInvalid
    2965       else
    2966         result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));
     2964        Result := eInvalid
     2965      else
     2966        Result := GetMoveAdvice(Player, Subject, TMoveAdviceData(Data));
    29672967
    29682968    sGetPlaneReturn:
     
    29702970        (RW[Player].Un[Subject].Loc < 0) or
    29712971        (RW[Player].Model[RW[Player].Un[Subject].mix].Domain <> dAir) then
    2972         result := eInvalid
     2972        Result := eInvalid
    29732973      else
    29742974      begin
    29752975        if CanPlaneReturn(Player, Subject, TPlaneReturnData(Data)) then
    2976           result := eOK
     2976          Result := eOK
    29772977        else
    2978           result := eNoWay;
     2978          Result := eNoWay;
    29792979      end;
    29802980
     
    29872987          Owner := Player;
    29882988          SearchCity(Subject, Owner, cix1);
    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);
     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);
    29922992        end
    29932993      else
    2994         result := eInvalid;
     2994        Result := eInvalid;
    29952995
    29962996    sGetCityReport:
    29972997      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    29982998        (RW[Player].City[Subject].Loc < 0) then
    2999         result := eInvalid
    3000       else
    3001         result := GetCityReport(Player, Subject, TCityReport(Data));
     2999        Result := eInvalid
     3000      else
     3001        Result := GetCityReport(Player, Subject, TCityReport(Data));
    30023002
    30033003    sGetCityReportNew:
    30043004      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30053005        (RW[Player].City[Subject].Loc < 0) then
    3006         result := eInvalid
     3006        Result := eInvalid
    30073007      else
    30083008        GetCityReportNew(Player, Subject, TCityReportNew(Data));
     
    30113011      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30123012        (RW[Player].City[Subject].Loc < 0) then
    3013         result := eInvalid
     3013        Result := eInvalid
    30143014      else
    30153015        GetCityAreaInfo(Player, RW[Player].City[Subject].Loc,
     
    30313031      end
    30323032      else
    3033         result := eInvalid;
     3033        Result := eInvalid;
    30343034
    30353035    sGetEnemyCityReportNew:
     
    30483048      end
    30493049      else
    3050         result := eInvalid;
     3050        Result := eInvalid;
    30513051
    30523052    sGetEnemyCityAreaInfo:
     
    30623062      end
    30633063      else
    3064         result := eInvalid;
     3064        Result := eInvalid;
    30653065
    30663066    sGetCityTileAdvice:
    30673067      if (Subject < 0) or (Subject >= RW[Player].nCity) or
    30683068        (RW[Player].City[Subject].Loc < 0) then
    3069         result := eInvalid
     3069        Result := eInvalid
    30703070      else
    30713071        GetCityTileAdvice(Player, Subject, TCityTileAdviceData(Data));
     
    30803080          EditTile(Loc, NewTile)
    30813081      else
    3082         result := eInvalid;
     3082        Result := eInvalid;
    30833083
    30843084    sRandomMap:
     
    30863086      begin
    30873087        CreateElevation;
    3088         PreviewElevation := false;
    3089         CreateMap(false);
     3088        PreviewElevation := False;
     3089        CreateMap(False);
    30903090        FillChar(ObserveLevel, MapSize * 4, 0);
    30913091        DiscoverAll(Player, lObserveSuper);
    30923092      end
    30933093      else
    3094         result := eInvalid;
     3094        Result := eInvalid;
    30953095
    30963096    sMapGeneratorRequest:
    30973097      if not MapGeneratorAvailable then
    3098         result := eInvalid;
     3098        Result := eInvalid;
    30993099
    31003100    {
     
    31043104    sTurn, sTurn - sExecute:
    31053105      begin
    3106         AllHumansDead := true;
     3106        AllHumansDead := True;
    31073107        for p1 := 0 to nPl - 1 do
    31083108          if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then
    3109             AllHumansDead := false;
     3109            AllHumansDead := False;
    31103110        if (pDipActive >= 0) // still in negotiation mode
    31113111          or (pTurn = 0) and ((GWinner > 0) or (GTurn = MaxTurn) or
    31123112          (Difficulty[0] > 0) and AllHumansDead) then // game end reached
    3113           result := eViolation
     3113          Result := eViolation
    31143114        else if Command >= sExecute then
    31153115        begin
     
    31223122            begin
    31233123              LogChanges;
    3124               SaveGame('~' + LogFileName, true);
     3124              SaveGame('~' + LogFileName, True);
    31253125            end;
    31263126{$ENDIF}
     
    31373137            TotalFood := 0;
    31383138            TotalProd := 0;
    3139             for i := 0 to RW[pTurn].nCity - 1 do
    3140               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
    31413141              begin
    3142                 inc(TotalFood, RW[pTurn].City[i].Food);
    3143                 inc(TotalProd, RW[pTurn].City[i].Prod);
     3142                Inc(TotalFood, RW[pTurn].City[I].Food);
     3143                Inc(TotalProd, RW[pTurn].City[I].Prod);
    31443144              end;
    31453145            CheckSum := TotalFood and 7 + TotalProd and 7 shl 3 +
     
    31523152          begin
    31533153            if CheckSum <> Subject then
    3154               LoadOK := false;
     3154              LoadOK := False;
    31553155          end
    31563156          else // save checksum
     
    31793179            pTurn := (pTurn + 1) mod nPl;
    31803180            if pTurn = 0 then
    3181               inc(GTurn);
     3181              Inc(GTurn);
    31823182            if Assigned(bix[pTurn]) and ((1 shl pTurn) and GAlive = 0) then
    31833183            begin // already made extinct -- continue statistics
     
    32183218    sBreak, sResign, sNextRound, sReload:
    32193219      if Mode = moMovie then
    3220         MovieStopped := true
     3220        MovieStopped := True
    32213221      else
    32223222      begin
     
    32243224        begin
    32253225          ok := (Difficulty[0] = 0) and (bix[0].Kind <> btNoTerm) and
    3226             (integer(Data) >= 0) and (integer(Data) < GTurn);
     3226            (Integer(Data) >= 0) and (Integer(Data) < GTurn);
    32273227          for p1 := 1 to nPl - 1 do
    32283228            if bix[p1].Kind = btTerm then
    3229               ok := false;
     3229              ok := False;
    32303230          // allow reload in AI-only games only
    32313231        end
     
    32363236          if (Command = sBreak) or (Command = sResign) then
    32373237            Notify(ntBackOn);
    3238           for i := 0 to Brains.Count - 1 do
    3239             if Brains[i].Initialized then
     3238          for I := 0 to Brains.Count - 1 do
     3239            if Brains[I].Initialized then
    32403240            begin
    3241               if Brains[i].Kind = btAI then
    3242                 Notify(ntDeinitModule, i);
    3243               CallClient(i, cBreakGame, nil^);
     3241              if Brains[I].Kind = btAI then
     3242                Notify(ntDeinitModule, I);
     3243              CallClient(I, cBreakGame, nil^);
    32443244            end;
    32453245          Notify(ntEndInfo);
     
    32483248            LogCityTileChanges;
    32493249            LogChanges;
    3250             SaveGame(LogFileName, false);
     3250            SaveGame(LogFileName, False);
    32513251          end;
    32523252          DeleteFile(SavePath + '~' + LogFileName);
     
    32613261                LandMass, MaxTurn);
    32623262            sReload:
    3263               LoadGame(SavePath, LogFileName, integer(Data), false);
     3263              LoadGame(SavePath, LogFileName, Integer(Data), False);
    32643264          end;
    32653265        end
    32663266        else
    3267           result := eInvalid;
     3267          Result := eInvalid;
    32683268      end;
    32693269
     
    32823282      end
    32833283      else
    3284         result := eInvalid;
     3284        Result := eInvalid;
    32853285
    32863286    scContact .. scContact + (nPl - 1) shl 4, scContact - sExecute .. scContact
    32873287      - sExecute + (nPl - 1) shl 4:
    32883288      if (pDipActive >= 0) or (1 shl (Command shr 4 and $F) and GAlive = 0) then
    3289         result := eInvalid
     3289        Result := eInvalid
    32903290      else if GWinner > 0 then
    3291         result := eViolation // game end reached
     3291        Result := eViolation // game end reached
    32923292      else if RW[Player].Treaty[Command shr 4 and $F] = trNoContact then
    3293         result := eNoPreq
     3293        Result := eNoPreq
    32943294      else if GTurn < GColdWarStart + ColdWarTurns then
    3295         result := eColdWar
     3295        Result := eColdWar
    32963296      else if RW[Player].Government = gAnarchy then
    3297         result := eAnarchy
     3297        Result := eAnarchy
    32983298      else if RW[Command shr 4 and $F].Government = gAnarchy then
    32993299      begin
    3300         result := eAnarchy;
     3300        Result := eAnarchy;
    33013301        LastEndClientCommand := scReject; // enable cancel treaty
    33023302        pContacted := Command shr 4 and $F;
     
    33063306        pContacted := Command shr 4 and $F;
    33073307        pDipActive := pContacted;
    3308         assert(Mode = moPlaying);
     3308        Assert(Mode = moPlaying);
    33093309        Inform(pDipActive);
    33103310        ChangeClientWhenDone(scContact, pDipActive, pTurn, 4);
     
    33173317        begin // contact requested and not accepted yet
    33183318          pDipActive := -1;
    3319           assert(Mode = moPlaying);
     3319          Assert(Mode = moPlaying);
    33203320          ChangeClientWhenDone(cContinue, pTurn, nil^, 0);
    33213321        end;
    33223322      end
    33233323      else
    3324         result := eInvalid;
     3324        Result := eInvalid;
    33253325
    33263326    scDipStart, scDipStart - sExecute:
     
    33333333            RW[pTurn].Credibility;
    33343334          pDipActive := pTurn;
    3335           assert(Mode = moPlaying);
     3335          Assert(Mode = moPlaying);
    33363336          IntServer(sIntHaveContact, pTurn, pContacted, nil^);
    33373337          ChangeClientWhenDone(scDipStart, pDipActive, nil^, 0);
     
    33393339      end
    33403340      else
    3341         result := eInvalid;
     3341        Result := eInvalid;
    33423342
    33433343    scDipNotice, scDipAccept, scDipCancelTreaty, scDipBreak,
     
    33463346      if pDipActive >= 0 then
    33473347      begin
    3348         assert(Mode = moPlaying);
     3348        Assert(Mode = moPlaying);
    33493349        if pDipActive = pTurn then
    33503350          p1 := pContacted
     
    33623362            // check if offer can be accepted
    33633363            if nDeliver + nCost = 0 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
     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
    33723372            begin
    33733373              IntServer(sIntPayPrices + nDeliver + nCost, p1, pDipActive,
     
    33763376
    33773377              // tell other players about ship part trades
    3378               HasShipChanged := false;
     3378              HasShipChanged := False;
    33793379              FillChar(ShowShipChange, SizeOf(ShowShipChange), 0);
    3380               for i := 0 to nDeliver + nCost - 1 do
    3381                 if Price[i] and opMask = opShipParts then
     3380              for I := 0 to nDeliver + nCost - 1 do
     3381                if Price[I] and opMask = opShipParts then
    33823382                begin
    3383                   HasShipChanged := true;
    3384                   if i >= nDeliver then
     3383                  HasShipChanged := True;
     3384                  if I >= nDeliver then
    33853385                  begin // p1 has demanded from pDipActive
    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);
     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);
    33903390                  end
    33913391                  else
    33923392                  begin // p1 has delivered to pDipActive
    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);
     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);
    33973397                  end;
    33983398                end;
     
    34063406                    (1 shl p2 and (GAlive or GWatching) <> 0) then
    34073407                  begin
    3408                     move(GShip, RW[p2].Ship, SizeOf(GShip));
     3408                    Move(GShip, RW[p2].Ship, SizeOf(GShip));
    34093409                    if 1 shl p2 and GWatching <> 0 then
    34103410                      CallPlayer(cShowShipChange, p2, ShowShipChange);
     
    34193419            (GTurn < RW[pDipActive].LastCancelTreaty[p1] + CancelTreatyTurns)
    34203420          then
    3421             result := eCancelTreatyRush
     3421            Result := eCancelTreatyRush
    34223422          else if Command >= sExecute then
    34233423          begin
     
    34263426              if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then
    34273427              begin
    3428                 i := p1 shl 4 + pDipActive;
    3429                 CallPlayer(cShowSupportAllianceAgainst, p2, i);
     3428                I := p1 shl 4 + pDipActive;
     3429                CallPlayer(cShowSupportAllianceAgainst, p2, I);
    34303430              end;
    34313431            for p2 := 0 to nPl - 1 do
    34323432              if (p2 <> p1) and (1 shl p2 and PeaceEnded <> 0) then
    34333433              begin
    3434                 i := p2;
    3435                 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, i);
     3434                I := p2;
     3435                CallPlayer(cShowCancelTreatyByAlliance, pDipActive, I);
    34363436              end;
    34373437          end;
    34383438        end
    34393439        else
    3440           result := eInvalid;
    3441         if (Command >= sExecute) and (result >= rExecuted) then
     3440          Result := eInvalid;
     3441        if (Command >= sExecute) and (Result >= rExecuted) then
    34423442          if LastEndClientCommand = scDipBreak then
    34433443          begin // break negotiation
     
    34613461      end
    34623462      else
    3463         result := eInvalid;
     3463        Result := eInvalid;
    34643464
    34653465    scDipOffer, scDipOffer - sExecute:
     
    34743474            pDipActive := -1;
    34753475            CallPlayer(cShowEndContact, pContacted, nil^);
    3476             assert(Mode = moPlaying);
     3476            Assert(Mode = moPlaying);
    34773477            ChangeClientWhenDone(cContinue, pTurn, nil^, 0);
    34783478          end;
     
    34873487          if RW[pDipActive].Treaty[p1] < trPeace then
    34883488          begin // no tribute allowed!
    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;
     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;
    34953495          end;
    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;
     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;
    35003500          if CountPrice(TOffer(Data), opTreaty) > 1 then
    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;
     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;
    35053505          if CountPrice(TOffer(Data), opMoney) > 1 then
    3506             result := eInvalidOffer;
     3506            Result := eInvalidOffer;
    35073507          if CountPrice(TOffer(Data), opTribute) > 1 then
    3508             result := eInvalidOffer;
     3508            Result := eInvalidOffer;
    35093509          case CountPrice(TOffer(Data), opChoose) of
    35103510            0:
     
    35123512            1:
    35133513              if (TOffer(Data).nCost = 0) or (TOffer(Data).nDeliver = 0) then
    3514                 result := eInvalidOffer;
     3514                Result := eInvalidOffer;
    35153515          else
    3516             result := eInvalidOffer;
     3516            Result := eInvalidOffer;
    35173517          end;
    35183518
    35193519          // !!! check here if cost can be demanded
    35203520
    3521           if (Command >= sExecute) and (result >= rExecuted) then
     3521          if (Command >= sExecute) and (Result >= rExecuted) then
    35223522          begin
    35233523            OfferFullySupported := (TOffer(Data).nDeliver <= 2) and
    35243524              (TOffer(Data).nCost <= 2); // >2 no more allowed
    3525             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
    35263526            begin
    3527               if TOffer(Data).Price[i] and opMask = opTribute then
    3528                 OfferFullySupported := false;
     3527              if TOffer(Data).Price[I] and opMask = opTribute then
     3528                OfferFullySupported := False;
    35293529              // tribute no more part of the game
    3530               if (TOffer(Data).Price[i] and opMask = opTreaty) and
    3531                 (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])
    35323532              then
    3533                 OfferFullySupported := false;
     3533                OfferFullySupported := False;
    35343534              // agreed treaty end no more part of the game
    3535               if TOffer(Data).Price[i] = opTreaty + trCeaseFire then
    3536                 OfferFullySupported := false;
     3535              if TOffer(Data).Price[I] = opTreaty + trCeaseFire then
     3536                OfferFullySupported := False;
    35373537              // ceasefire no more part of the game
    35383538            end;
     
    35593559              LastOffer := TOffer(Data);
    35603560              // show offered things to receiver
    3561               for i := 0 to LastOffer.nDeliver - 1 do
    3562                 ShowPrice(pDipActive, p1, LastOffer.Price[i]);
     3561              for I := 0 to LastOffer.nDeliver - 1 do
     3562                ShowPrice(pDipActive, p1, LastOffer.Price[I]);
    35633563              pDipActive := p1;
    3564               assert(Mode = moPlaying);
     3564              Assert(Mode = moPlaying);
    35653565              ChangeClientWhenDone(scDipOffer, pDipActive, LastOffer,
    35663566                SizeOf(LastOffer));
     
    35693569        end
    35703570      else
    3571         result := eInvalid;
     3571        Result := eInvalid;
    35723572
    35733573    {
     
    35823582      end
    35833583      else
    3584         result := eInvalid;
     3584        Result := eInvalid;
    35853585
    35863586    sSetTestFlag:
     
    35923592      end
    35933593      else
    3594         result := eInvalid;
     3594        Result := eInvalid;
    35953595
    35963596    sSetGovernment, sSetGovernment - sExecute:
     
    35983598{$IFDEF TEXTLOG}CmdInfo := Format('SetGovernment P%d: %d', [Player, Subject]); {$ENDIF}
    35993599        if RW[Player].Happened and phChangeGov = 0 then
    3600           result := eViolation
     3600          Result := eViolation
    36013601        else if RW[Player].Government = Subject then
    3602           result := eNotChanged
     3602          Result := eNotChanged
    36033603        else if (Subject >= nGov) then
    3604           result := eInvalid
     3604          Result := eInvalid
    36053605        else if (Subject >= gMonarchy) and
    36063606          (RW[Player].Tech[GovPreq[Subject]] < tsApplicable) then
    3607           result := eNoPreq
     3607          Result := eNoPreq
    36083608        else if Command >= sExecute then
    36093609        begin
     
    36203620{$IFDEF TEXTLOG}CmdInfo := Format('SetRates P%d: %d/%d', [Player, Subject and $F * 10, Subject shr 4 * 10]); {$ENDIF}
    36213621        if Subject and $F + Subject shr 4 > 10 then
    3622           result := eInvalid
     3622          Result := eInvalid
    36233623        else if (RW[Player].TaxRate = Subject and $F * 10) and
    36243624          (RW[Player].LuxRate = Subject shr 4 * 10) then
    3625           result := eNotChanged
     3625          Result := eNotChanged
    36263626        else if Command >= sExecute then
    36273627        begin
     
    36353635{$IFDEF TEXTLOG}CmdInfo := Format('Revolution P%d', [Player]); {$ENDIF}
    36363636        if RW[Player].Government = gAnarchy then
    3637           result := eInvalid
     3637          Result := eInvalid
    36383638        else
    36393639        begin
     
    36573657          if (Mode = moPlaying) and (Subject = adMilitary) and
    36583658            (DevModelTurn[Player] <> GTurn) then
    3659             result := eNoModel
     3659            Result := eNoModel
    36603660          else if Subject <> adMilitary then
    36613661          begin
     
    36633663            begin
    36643664              if Tech[Subject] >= MaxFutureTech_Computing then
    3665                 result := eInvalid;
     3665                Result := eInvalid;
    36663666            end
    36673667            else if Subject in FutureTech then
    36683668            begin
    36693669              if Tech[Subject] >= MaxFutureTech then
    3670                 result := eInvalid;
     3670                Result := eInvalid;
    36713671            end
    36723672            else if Tech[Subject] >= tsApplicable then
    3673               result := eInvalid; // already discovered
     3673              Result := eInvalid; // already discovered
    36743674            if Tech[Subject] <> tsSeen then // look if preqs met
    36753675              if AdvPreq[Subject, 2] <> preNone then
    36763676              begin // 2 of 3 required
    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;
     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;
    36833683              end
    36843684              else if (AdvPreq[Subject, 0] <> preNone) and
     
    36863686                (AdvPreq[Subject, 1] <> preNone) and
    36873687                (Tech[AdvPreq[Subject, 1]] < tsApplicable) then
    3688                 result := eNoPreq;
     3688                Result := eNoPreq;
    36893689          end;
    3690           if (result = eOK) and (Command >= sExecute) then
     3690          if (Result = eOK) and (Command >= sExecute) then
    36913691          begin
    36923692            if (Mode = moPlaying) and (Subject = adMilitary) then
     
    36973697        end
    36983698        else
    3699           result := eViolation;
     3699          Result := eViolation;
    37003700      end;
    37013701
     
    37053705        {$ENDIF}
    37063706        if RW[Player].Happened and phStealTech = 0 then
    3707           result := eInvalid
     3707          Result := eInvalid
    37083708        else if (Subject >= nAdv) or (Subject in FutureTech) or
    37093709          (RW[Player].Tech[Subject] >= tsSeen) or
    37103710          (RW[GStealFrom].Tech[Subject] < tsApplicable) then
    3711           result := eInvalid
     3711          Result := eInvalid
    37123712        else if Command >= sExecute then
    37133713        begin
    37143714          SeeTech(Player, Subject);
    3715           dec(RW[Player].Happened, phStealTech);
     3715          Dec(RW[Player].Happened, phStealTech);
    37163716        end;
    37173717      end;
     
    37243724        if (Subject >= nAttitude) or (p1 >= nPl) or
    37253725          (RW[Player].EnemyReport[p1] = nil) then
    3726           result := eInvalid
     3726          Result := eInvalid
    37273727        else if RW[Player].Treaty[p1] = trNoContact then
    3728           result := eNoPreq
     3728          Result := eNoPreq
    37293729        else if RW[Player].Attitude[p1] = Subject then
    3730           result := eNotChanged
     3730          Result := eNotChanged
    37313731        else if Command >= sExecute then
    37323732        begin
     
    37393739      if (LastEndClientCommand <> scReject) or
    37403740        (RW[Player].Treaty[pContacted] < trPeace) then
    3741         result := eInvalid
     3741        Result := eInvalid
    37423742      else if (ServerVersion[Player] >= $010100) and
    37433743        (GTurn < RW[Player].LastCancelTreaty[pContacted] + CancelTreatyTurns)
    37443744      then
    3745         result := eCancelTreatyRush
     3745        Result := eCancelTreatyRush
    37463746      else if Command >= sExecute then
    37473747      begin
     
    37513751          if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then
    37523752          begin
    3753             i := pContacted shl 4 + Player;
    3754             CallPlayer(cShowSupportAllianceAgainst, p2, i);
     3753            I := pContacted shl 4 + Player;
     3754            CallPlayer(cShowSupportAllianceAgainst, p2, I);
    37553755          end;
    37563756        for p2 := 0 to nPl - 1 do
    37573757          if (p2 <> pContacted) and (1 shl p2 and PeaceEnded <> 0) then
    37583758          begin
    3759             i := p2;
    3760             CallPlayer(cShowCancelTreatyByAlliance, Player, i);
     3759            I := p2;
     3760            CallPlayer(cShowCancelTreatyByAlliance, Player, I);
    37613761          end;
    37623762        LastEndClientCommand := sTurn;
     
    37713771{$IFDEF TEXTLOG}CmdInfo := Format('CreateDevModel P%d', [Player]); {$ENDIF}
    37723772        if Subject >= 4 then
    3773           result := eInvalid
     3773          Result := eInvalid
    37743774        else if (upgrade[Subject, 0].Preq <> preNone) and
    37753775          (RW[Player].Tech[upgrade[Subject, 0].Preq] < tsApplicable) then
    3776           result := eNoPreq
     3776          Result := eNoPreq
    37773777        else if Command >= sExecute then
    37783778        begin
     
    37853785            Upgrades := 0;
    37863786            FutureMCost := 0;
    3787             for i := 0 to nUpgrade - 1 do
    3788               with upgrade[Domain, i] do
     3787            for I := 0 to nUpgrade - 1 do
     3788              with upgrade[Domain, I] do
    37893789                if (Preq = preNone) or (Preq >= 0) and
    37903790                  ((RW[Player].Tech[Preq] >= tsApplicable) or
     
    37933793                  if Preq in FutureTech then
    37943794                  begin
    3795                     j := RW[Player].Tech[Preq];
    3796                     inc(FutureMCost, j * Cost);
     3795                    J := RW[Player].Tech[Preq];
     3796                    Inc(FutureMCost, J * Cost);
    37973797                  end
    37983798                  else
    37993799                  begin
    3800                     j := 1;
     3800                    J := 1;
    38013801                    if Cost > MCost then
    38023802                      MCost := Cost;
    38033803                  end;
    3804                   inc(Upgrades, 1 shl i);
    3805                   inc(MStrength, j * Strength);
    3806                   inc(MTrans, j * Trans);
     3804                  Inc(Upgrades, 1 shl I);
     3805                  Inc(MStrength, J * Strength);
     3806                  Inc(MTrans, J * Trans);
    38073807                end;
    3808             inc(MCost, FutureMCost);
     3808            Inc(MCost, FutureMCost);
    38093809            FillChar(Cap, SizeOf(Cap), 0);
    38103810            Cap[mcOffense] := 2;
    38113811            Cap[mcDefense] := 1;
    3812             for i := 0 to nFeature - 1 do
    3813               with Feature[i] do
     3812            for I := 0 to nFeature - 1 do
     3813              with Feature[I] do
    38143814                if (1 shl Domain and Domains <> 0) and
    38153815                  ((Preq = preNone) or (Preq = preSun) and
    38163816                  (GWonder[woSun].EffectiveOwner = Player) or (Preq >= 0) and
    3817                   (RW[Player].Tech[Preq] >= tsApplicable)) and (i in AutoFeature)
     3817                  (RW[Player].Tech[Preq] >= tsApplicable)) and (I in AutoFeature)
    38183818                then
    3819                   Cap[i] := 1;
     3819                  Cap[I] := 1;
    38203820            MaxWeight := 5;
    38213821            if (WeightPreq7[Domain] <> preNA) and
     
    38393839{$IFDEF TEXTLOG}CmdInfo := Format('SetDevModelCap P%d', [Player]); {$ENDIF}
    38403840        if Subject >= nFeature then
    3841           result := eInvalid
     3841          Result := eInvalid
    38423842        else if DevModelTurn[Player] = GTurn then
    38433843        begin
     
    38453845          with RW[Player].DevModel do
    38463846            if 1 shl Domain and Feature[Subject].Domains = 0 then
    3847               result := eDomainMismatch
     3847              Result := eDomainMismatch
    38483848            else if not((Feature[Subject].Preq = preNone) or
    38493849              (Feature[Subject].Preq = preSun) and
     
    38513851              (Feature[Subject].Preq >= 0) and
    38523852              (RW[Player].Tech[Feature[Subject].Preq] >= tsApplicable)) then
    3853               result := eNoPreq
     3853              Result := eNoPreq
    38543854            else
    38553855            begin
     
    38673867                  MaxCap := 3;
    38683868                if RW[Player].Tech[adSteel] >= tsApplicable then
    3869                   inc(MaxCap);
     3869                  Inc(MaxCap);
    38703870              end
    38713871              else
     
    38773877              if (NewCap < MinCap) or (NewCap > MaxCap) or
    38783878                (Weight + (NewCap - Cap[Subject]) * CapWeight > MaxWeight) then
    3879                 result := eViolation
     3879                Result := eViolation
    38803880              else if Command >= sExecute then
    38813881              begin
     
    39203920        end
    39213921        else
    3922           result := eNoModel;
     3922          Result := eNoModel;
    39233923      end;
    39243924
     
    39313931{$IFDEF TEXTLOG}CmdInfo := Format('RemoveUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    39323932        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    3933           result := eInvalid
     3933          Result := eInvalid
    39343934        else
    39353935        begin
    3936           result := eRemoved;
     3936          Result := eRemoved;
    39373937          Loc0 := RW[Player].Un[Subject].Loc;
    39383938          if RealMap[Loc0] and fCity <> 0 then { check utilize }
     
    39463946                (Project and cpImp = 0) and
    39473947                (RW[Player].Model[Project and cpIndex].Kind <> mkCaravan) then
    3948                 result := eUtilized;
     3948                Result := eUtilized;
    39493949              if Command >= sExecute then
    39503950              begin
    3951                 if result = eUtilized then
     3951                if Result = eUtilized then
    39523952                begin
    39533953                  with RW[Player].Un[Subject] do
    39543954                  begin
    3955                     Cost := integer(RW[Player].Model[mix].Cost) * Health *
     3955                    Cost := Integer(RW[Player].Model[mix].Cost) * Health *
    39563956                      BuildCostMod[Difficulty[Player]] div 1200;
    39573957                    if RW[Player].Model[mix].Cap[mcLine] > 0 then
     
    39593959                  end;
    39603960                  if Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    3961                     inc(RW[Player].Money, Cost)
     3961                    Inc(RW[Player].Money, Cost)
    39623962                  else
    39633963                  begin
    3964                     inc(Prod, Cost * 2 div 3);
     3964                    Inc(Prod, Cost * 2 div 3);
    39653965                    Project0 := Project0 and not cpCompleted;
    39663966                    if Project0 and not cpAuto <> Project and not cpAuto then
     
    39823982{$IFDEF TEXTLOG}CmdInfo := Format('SetUnitHome P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    39833983        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    3984           result := eInvalid
     3984          Result := eInvalid
    39853985        else
    39863986        begin
    39873987          Loc0 := RW[Player].Un[Subject].Loc;
    39883988          if RealMap[Loc0] and fCity = 0 then
    3989             result := eInvalid
     3989            Result := eInvalid
    39903990          else
    39913991          begin
    39923992            SearchCity(Loc0, Player, cix1);
    39933993            if RW[Player].City[cix1].Flags and chCaptured <> 0 then
    3994               result := eViolation
     3994              Result := eViolation
    39953995            else if Command >= sExecute then
    39963996              RW[Player].Un[Subject].Home := cix1;
     
    40094009{$IFDEF TEXTLOG}CmdInfo := Format('LoadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40104010        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4011           result := eInvalid
     4011          Result := eInvalid
    40124012        else
    4013           result := LoadUnit(Player, Subject, Command < sExecute);
     4013          Result := LoadUnit(Player, Subject, Command < sExecute);
    40144014      end;
    40154015
     
    40184018{$IFDEF TEXTLOG}CmdInfo := Format('UnloadUnit P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40194019        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4020           result := eInvalid
     4020          Result := eInvalid
    40214021        else
    4022           result := UnloadUnit(Player, Subject, Command < sExecute);
     4022          Result := UnloadUnit(Player, Subject, Command < sExecute);
    40234023      end;
    40244024
    40254025    sSelectTransport, sSelectTransport - sExecute:
    40264026      if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4027         result := eInvalid
     4027        Result := eInvalid
    40284028      else
    40294029        with RW[Player].Model[RW[Player].Un[Subject].mix] do
    40304030        begin
    40314031          if Cap[mcSeaTrans] + Cap[mcAirTrans] + Cap[mcCarrier] = 0 then
    4032             result := eInvalid
     4032            Result := eInvalid
    40334033          else if Command >= sExecute then
    40344034            uixSelectedTransport := Subject;
     
    40414041      begin
    40424042        p1 := Command shr 4 and $F;
    4043         Loc1 := integer(Data);
     4043        Loc1 := Integer(Data);
    40444044        if (Occupant[Loc1] >= 0) and (p1 <> Occupant[Loc1]) or
    40454045          (RealMap[Loc1] and fCity <> 0) and
    40464046          (RealMap[Loc1] shr 27 <> Cardinal(p1)) or
    40474047          (RW[p1].Model[Subject].Domain < dAir) and
    4048           ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[integer(Data)] and
     4048          ((RW[p1].Model[Subject].Domain = dSea) <> (RealMap[Integer(Data)] and
    40494049          fTerrain < fGrass)) then
    4050           result := eViolation
     4050          Result := eViolation
    40514051        else if Command >= sExecute then
    40524052        begin
    40534053          CreateUnit(p1, Subject);
    4054           RW[p1].Un[RW[p1].nUn - 1].Loc := integer(Data);
     4054          RW[p1].Un[RW[p1].nUn - 1].Loc := Integer(Data);
    40554055          PlaceUnit(p1, RW[p1].nUn - 1);
    4056           UpdateUnitMap(integer(Data));
     4056          UpdateUnitMap(Integer(Data));
    40574057        end;
    40584058      end
    40594059      else
    4060         result := eInvalid;
     4060        Result := eInvalid;
    40614061
    40624062    sMoveUnit + (0 + 6 * 8) * 16, sMoveUnit + (1 + 7 * 8) * 16,
     
    40754075{$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}
    40764076        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4077           result := eInvalid
     4077          Result := eInvalid
    40784078        else
    4079           result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);
     4079          Result := MoveUnit(Player, Subject, dx, dy, Command < sExecute);
    40804080      end;
    40814081
     
    40884088{$IFDEF TEXTLOG}CmdInfo := Format('AddToCity P%d Mod%d Loc%d', [Player, RW[Player].Un[Subject].mix, RW[Player].Un[Subject].Loc]); {$ENDIF}
    40894089        if (Subject >= RW[Player].nUn) or (RW[Player].Un[Subject].Loc < 0) then
    4090           result := eInvalid
     4090          Result := eInvalid
    40914091        else if not(RW[Player].Model[RW[Player].Un[Subject].mix].Kind
    40924092          in [mkSettler, mkSlaves]) and
    40934093          (RW[Player].Un[Subject].Flags and unConscripts = 0) then
    4094           result := eViolation
     4094          Result := eViolation
    40954095        else
    40964096        begin
    40974097          Loc0 := RW[Player].Un[Subject].Loc;
    40984098          if RealMap[Loc0] and fCity = 0 then
    4099             result := eInvalid
     4099            Result := eInvalid
    41004100          else
    41014101          begin
     
    41034103            with RW[Player].City[cix1] do
    41044104              if not CanCityGrow(Player, cix1) then
    4105                 result := eMaxSize
     4105                Result := eMaxSize
    41064106              else if Command >= sExecute then
    41074107              begin { add to city }
     
    41234123      begin
    41244124        Loc0 := RW[Player].Un[Subject].Loc;
    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}
     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}
    41274127        if (Subject >= RW[Player].nUn) or (Loc0 < 0) then
    4128           result := eInvalid
    4129         else if i >= nJob then
    4130           result := eInvalid
     4128          Result := eInvalid
     4129        else if I >= nJob then
     4130          Result := eInvalid
    41314131        else
    41324132        begin
    4133           result := StartJob(Player, Subject, i, Command < sExecute);
    4134           if result = eCity then
     4133          Result := StartJob(Player, Subject, I, Command < sExecute);
     4134          if Result = eCity then
    41354135          begin // new city
    41364136            cix1 := RW[Player].nCity - 1;
     
    41574157    sSetCityProject, sSetCityProject - sExecute:
    41584158      begin
    4159         NewProject := integer(Data) and not cpAuto;
     4159        NewProject := Integer(Data) and not cpAuto;
    41604160{$IFDEF TEXTLOG}CmdInfo := Format('SetCityProject P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, NewProject]); {$ENDIF}
    41614161        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    41624162        then
    4163           result := eInvalid
     4163          Result := eInvalid
    41644164        else
    41654165          with RW[Player].City[Subject] do
    41664166          begin
    41674167            if NewProject = Project then
    4168               result := eNotChanged
     4168              Result := eNotChanged
    41694169            else
    41704170            begin
     
    41744174              begin
    41754175                if NewProject and cpIndex >= RW[Player].nModel then
    4176                   result := eInvalid
     4176                  Result := eInvalid
    41774177                else if (NewProject and cpConscripts <> 0) and
    41784178                  not((RW[Player].Tech[adConscription] >= tsApplicable) and
     
    41804180                  and (RW[Player].Model[NewProject and cpIndex].Kind < mkScout))
    41814181                then
    4182                   result := eViolation
     4182                  Result := eViolation
    41834183                  // else if (RW[Player].Model[NewProject and cpIndex].Kind=mkSlaves)
    41844184                  // and (GWonder[woPyramids].EffectiveOwner<>Player) then
     
    41864186              end
    41874187              else if NewProject and cpIndex >= nImp then
    4188                 result := eInvalid
     4188                Result := eInvalid
    41894189              else
    41904190              begin
    41914191                Preq := Imp[NewProject and cpIndex].Preq;
    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
     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
    41974197                else if Preq = preNA then
    4198                   result := eInvalid
     4198                  Result := eInvalid
    41994199                else if (Preq >= 0) and (RW[Player].Tech[Preq] < tsApplicable)
    42004200                then
    4201                   result := eNoPreq
     4201                  Result := eNoPreq
    42024202                else if built[NewProject and cpIndex] > 0 then
    4203                   result := eInvalid
     4203                  Result := eInvalid
    42044204                else if (NewProject and cpIndex < nWonder) and
    42054205                  (GWonder[NewProject and cpIndex].CityID <> WonderNotBuiltYet) then
    4206                   result := eViolation // wonder already exists
     4206                  Result := eViolation // wonder already exists
    42074207                else if (NewProject and cpIndex = imSpacePort) and
    42084208                  (RW[Player].NatBuilt[imSpacePort] > 0) then
    4209                   result := eViolation // space port already exists
     4209                  Result := eViolation // space port already exists
    42104210                else if (NewProject = cpImp + imBank) and (built[imMarket] = 0)
    42114211                  or (NewProject = cpImp + imUniversity) and
     
    42134213                  (built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant)
    42144214                  and (built[imFactory] = 0) then
    4215                   result := eNoPreq;
     4215                  Result := eNoPreq;
    42164216                case NewProject - cpImp of
    42174217                  woLighthouse, woMagellan, imCoastalFort, imHarbor, imPlatform:
     
    42244224                        if (Loc1 >= 0) and (Loc1 < MapSize) and
    42254225                          (RealMap[Loc1] and fTerrain = fShore) then
    4226                           inc(Preq);
     4226                          Inc(Preq);
    42274227                      end;
    42284228                      if Preq = 0 then
    4229                         result := eNoPreq;
     4229                        Result := eNoPreq;
    42304230                    end;
    42314231                  woHoover, imHydro:
     
    42394239                          ((RealMap[Loc1] and fTerrain = fMountains) or
    42404240                          (RealMap[Loc1] and fRiver <> 0)) then
    4241                           inc(Preq);
     4241                          Inc(Preq);
    42424242                      end;
    42434243                      if Preq = 0 then
    4244                         result := eNoPreq;
     4244                        Result := eNoPreq;
    42454245                    end;
    42464246                  woMIR, imShipComp, imShipPow, imShipHab:
    42474247                    if RW[Player].NatBuilt[imSpacePort] = 0 then
    4248                       result := eNoPreq;
     4248                      Result := eNoPreq;
    42494249                end;
    42504250                if (GTestFlags and tfNoRareNeed = 0) and
    42514251                  (Imp[NewProject and cpIndex].Kind = ikShipPart) then
    42524252                  if RW[Player].Tech[adMassProduction] < tsApplicable then
    4253                     result := eNoPreq
     4253                    Result := eNoPreq
    42544254                  else
    42554255                  begin // check for rare resources
    42564256                    if NewProject and cpIndex = imShipComp then
    4257                       j := 1
     4257                      J := 1
    42584258                    else if NewProject and cpIndex = imShipPow then
    4259                       j := 2
     4259                      J := 2
    42604260                    else { if NewProject and cpIndex=imShipHab then }
    4261                       j := 3;
     4261                      J := 3;
    42624262                    // j = rare resource required
    42634263                    Preq := 0;
     
    42674267                      Loc1 := Radius[V21];
    42684268                      if (Loc1 >= 0) and (Loc1 < MapSize) and
    4269                         (RealMap[Loc1] shr 25 and 3 = Cardinal(j)) then
    4270                         inc(Preq);
     4269                        (RealMap[Loc1] shr 25 and 3 = Cardinal(J)) then
     4270                        Inc(Preq);
    42714271                    end;
    42724272                    if Preq = 0 then
    4273                       result := eNoPreq;
     4273                      Result := eNoPreq;
    42744274                  end;
    42754275              end;
    42764276
    4277               if (Command >= sExecute) and (result >= rExecuted) then
     4277              if (Command >= sExecute) and (Result >= rExecuted) then
    42784278              begin
    42794279                if pt0 <> ptSelect then
     
    42844284                    and (pt0 <> ptCaravan) then
    42854285                  begin
    4286                     inc(RW[Player].Money, Prod0);
     4286                    Inc(RW[Player].Money, Prod0);
    42874287                    Prod := 0;
    42884288                    Prod0 := 0;
     
    42914291                  else
    42924292                    Prod := Prod0 * 2 div 3;
    4293                 Project := NewProject
     4293                Project := NewProject;
    42944294              end;
    42954295            end;
     
    43024302        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43034303        then
    4304           result := eInvalid
     4304          Result := eInvalid
    43054305        else
    43064306          with RW[Player].City[Subject] do
    43074307            if (RW[Player].Government = gAnarchy) or (Flags and chCaptured <> 0)
    43084308            then
    4309               result := eOutOfControl
     4309              Result := eOutOfControl
    43104310            else if (Project and cpImp <> 0) and
    43114311              ((Project and cpIndex = imTrGoods) or
    43124312              (Imp[Project and cpIndex].Kind = ikShipPart)) then
    4313               result := eInvalid // don't buy colony ship
     4313              Result := eInvalid // don't buy colony ship
    43144314            else
    43154315            begin
     
    43304330                Cost := Cost * 4;
    43314331              if Cost <= 0 then
    4332                 result := eNotChanged
     4332                Result := eNotChanged
    43334333              else if Cost > RW[Player].Money then
    4334                 result := eViolation
     4334                Result := eViolation
    43354335              else if Command >= sExecute then
    43364336                IntServer(sIntBuyMaterial, Player, Subject, Cost);
     
    43454345        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43464346        then
    4347           result := eInvalid
     4347          Result := eInvalid
    43484348        else if Command >= sExecute then
    43494349          with RW[Player].City[Subject] do
    43504350          begin
    4351             inc(RW[Player].Money, Prod0);
     4351            Inc(RW[Player].Money, Prod0);
    43524352            Prod := 0;
    43534353            Prod0 := 0;
     
    43574357    sSellCityImprovement, sSellCityImprovement - sExecute:
    43584358      begin
    4359 {$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}
    43604360        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43614361        then
    4362           result := eInvalid
     4362          Result := eInvalid
    43634363        else
    43644364          with RW[Player].City[Subject] do
    4365             if built[integer(Data)] = 0 then
    4366               result := eInvalid
     4365            if built[Integer(Data)] = 0 then
     4366              Result := eInvalid
    43674367            else if (RW[Player].Government = gAnarchy) or
    43684368              (Flags and chCaptured <> 0) then
    4369               result := eOutOfControl
     4369              Result := eOutOfControl
    43704370            else if Flags and chImprovementSold <> 0 then
    4371               result := eOnlyOnce
     4371              Result := eOnlyOnce
    43724372            else if Command >= sExecute then
    43734373            begin
    4374               inc(RW[Player].Money, Imp[integer(Data)].Cost * BuildCostMod
     4374              Inc(RW[Player].Money, Imp[Integer(Data)].Cost * BuildCostMod
    43754375                [Difficulty[Player]] div 12);
    4376               built[integer(Data)] := 0;
    4377               if Imp[integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
     4376              built[Integer(Data)] := 0;
     4377              if Imp[Integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
    43784378              begin
    4379                 RW[Player].NatBuilt[integer(Data)] := 0;
    4380                 case integer(Data) of
     4379                RW[Player].NatBuilt[Integer(Data)] := 0;
     4380                case Integer(Data) of
    43814381                  imGrWall:
    43824382                    GrWallContinent[Player] := -1;
     
    43854385                end;
    43864386              end;
    4387               inc(Flags, chImprovementSold);
     4387              Inc(Flags, chImprovementSold);
    43884388            end;
    43894389      end;
     
    43914391    sRebuildCityImprovement, sRebuildCityImprovement - sExecute:
    43924392      begin
    4393         OldImp := integer(Data);
     4393        OldImp := Integer(Data);
    43944394{$IFDEF TEXTLOG}CmdInfo := Format('RebuildCityImprovement P%d Loc%d: %d', [Player, RW[Player].City[Subject].Loc, OldImp]); {$ENDIF}
    43954395        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    43964396        then
    4397           result := eInvalid
     4397          Result := eInvalid
    43984398        else
    43994399        begin
    44004400          if (OldImp < 0) or (OldImp >= nImp) or
    44014401            not(Imp[OldImp].Kind in [ikCommon, ikNatLocal, ikNatGlobal]) then
    4402             result := eInvalid
     4402            Result := eInvalid
    44034403          else
    44044404            with RW[Player].City[Subject] do
     
    44064406                not(Imp[Project and cpIndex].Kind in [ikCommon, ikNatLocal,
    44074407                ikNatGlobal]) then
    4408                 result := eInvalid
     4408                Result := eInvalid
    44094409              else if (RW[Player].Government = gAnarchy) or
    44104410                (Flags and chCaptured <> 0) then
    4411                 result := eOutOfControl
     4411                Result := eOutOfControl
    44124412              else if Flags and chImprovementSold <> 0 then
    4413                 result := eOnlyOnce
     4413                Result := eOnlyOnce
    44144414              else if Command >= sExecute then
    44154415              begin
    4416                 inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]
     4416                Inc(Prod, Imp[OldImp].Cost * BuildCostMod[Difficulty[Player]]
    44174417                  div 12 * 2 div 3);
    44184418                Project0 := Project0 and not cpCompleted;
     
    44314431                  end;
    44324432                end;
    4433                 inc(Flags, chImprovementSold);
     4433                Inc(Flags, chImprovementSold);
    44344434              end;
    44354435        end;
     
    44384438    sSetCityTiles, sSetCityTiles - sExecute:
    44394439      begin
    4440 {$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}
    44414441        if (Subject >= RW[Player].nCity) or (RW[Player].City[Subject].Loc < 0)
    44424442        then
    4443           result := eInvalid
     4443          Result := eInvalid
    44444444        else
    4445           result := SetCityTiles(Player, Subject, integer(Data),
     4445          Result := SetCityTiles(Player, Subject, Integer(Data),
    44464446            Command < sExecute);
    44474447      end;
     
    44604460    end
    44614461    else
    4462       result := eUnknown;
     4462      Result := eUnknown;
    44634463  end; { case command }
    44644464
    44654465  // do not log invalid and non-relevant commands
    4466   if result = eZOC_EnemySpotted then
     4466  if Result = eZOC_EnemySpotted then
    44674467  begin
    4468     assert(Mode = moPlaying);
     4468    Assert(Mode = moPlaying);
    44694469    CL.State := FormerCLState;
    44704470    IntServer(sIntDiscoverZOC, Player, 0, ZOCTile);
    44714471  end
    4472   else if result and rEffective = 0 then
     4472  else if Result and rEffective = 0 then
    44734473    if Mode < moPlaying then
    44744474    begin
    4475 {$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [result]) + CmdInfo;
     4475{$IFDEF TEXTLOG}CmdInfo := Format('***ERROR (%x) ', [Result]) + CmdInfo;
    44764476      {$ENDIF}
    4477       LoadOK := false;
     4477      LoadOK := False;
    44784478    end
    44794479    else
     
    44814481      if logged then
    44824482        CL.State := FormerCLState;
    4483       if (result < rExecuted) and (Command >= sExecute) then
     4483      if (Result < rExecuted) and (Command >= sExecute) then
    44844484        PutMessage(1 shl 16 + 1, Format('INVALID: %d calls %x (%d)',
    44854485          [Player, Command, Subject]));
     
    44874487
    44884488  if (Command and (cClientEx or sExecute or sctMask) = sExecute or sctEndClient)
    4489     and (result >= rExecuted) then
     4489    and (Result >= rExecuted) then
    44904490    LastEndClientCommand := Command;
    4491 {$IFOPT O-}dec(nHandoverStack, 2); {$ENDIF}
     4491{$IFOPT O-}Dec(nHandoverStack, 2); {$ENDIF}
    44924492end;
    44934493
  • trunk/Global.pas

    r417 r447  
    2828end.
    2929
     30
  • trunk/IPQ.pas

    r442 r447  
    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   TIntegerArray = array [0 .. $40000000 div sizeof(integer)] of integer;
     10  TIntegerArray = array [0 .. $40000000 div SizeOf(Integer)] of Integer;
    1111  PIntegerArray = ^TIntegerArray;
    1212
    1313  TheapItem = record
    14     Item: integer;
    15     Value: integer;
     14    Item: Integer;
     15    Value: Integer;
    1616  end;
    1717
    18   TItemArray = array [0 .. $40000000 div sizeof(TheapItem)] of TheapItem;
     18  TItemArray = array [0 .. $40000000 div SizeOf(TheapItem)] of TheapItem;
    1919  PItemArray = ^TItemArray;
    2020
    2121  TIPQ = class
    22     constructor Create(max: integer);
     22    constructor Create(Max: Integer);
    2323    destructor Destroy; override;
    2424    procedure Empty;
    25     function Put(Item, Value: integer): boolean;
    26     function TestPut(Item, Value: integer): boolean;
    27     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;
    2828  private
    2929    // n - is the size of the heap.
    3030    // fmax - is the max size of the heap.
    31     n, fmax: integer;
     31    N, fmax: Integer;
    3232
    3333    // bh - stores (Value, Item) pairs of the heap.
     
    3939implementation
    4040
    41 constructor TIPQ.Create(max: integer);
     41constructor TIPQ.Create(Max: Integer);
    4242begin
    4343  inherited Create;
    44   fmax := max;
    45   GetMem(bh, fmax * sizeof(TheapItem));
    46   GetMem(Ix, fmax * sizeof(integer));
    47   n := -1;
     44  fmax := Max;
     45  GetMem(bh, fmax * SizeOf(TheapItem));
     46  GetMem(Ix, fmax * SizeOf(Integer));
     47  N := -1;
    4848  Empty;
    4949end;
     
    5858procedure TIPQ.Empty;
    5959begin
    60   if n <> 0 then
     60  if N <> 0 then
    6161  begin
    62     FillChar(Ix^, fmax * sizeof(integer), 255);
    63     n := 0;
     62    FillChar(Ix^, fmax * SizeOf(Integer), 255);
     63    N := 0;
    6464  end;
    6565end;
    6666
    6767// Parent(i) = (i-1)/2.
    68 function TIPQ.Put(Item, Value: integer): boolean; // O(lg(n))
     68function TIPQ.Put(Item, Value: Integer): Boolean; // O(lg(n))
    6969var
    70   i, j: integer;
     70  I, J: Integer;
    7171  lbh: PItemArray;
    7272  lIx: PIntegerArray;
     
    7474  lIx := Ix;
    7575  lbh := bh;
    76   i := lIx[Item];
    77   if i >= 0 then
     76  I := lIx[Item];
     77  if I >= 0 then
    7878  begin
    79     if lbh[i].Value <= Value then
     79    if lbh[I].Value <= Value then
    8080    begin
    81       result := False;
    82       exit;
     81      Result := False;
     82      Exit;
    8383    end;
    8484  end
    8585  else
    8686  begin
    87     i := n;
    88     Inc(n);
     87    I := N;
     88    Inc(N);
    8989  end;
    9090
    91   while i > 0 do
     91  while I > 0 do
    9292  begin
    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;
     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;
    9999  end;
    100100  // Insert the new Item at the insertion point found.
    101   lbh[i].Value := Value;
    102   lbh[i].Item := Item;
    103   lIx[lbh[i].Item] := i;
    104   result := True;
     101  lbh[I].Value := Value;
     102  lbh[I].Item := Item;
     103  lIx[lbh[I].Item] := I;
     104  Result := True;
    105105end;
    106106
    107 function TIPQ.TestPut(Item, Value: integer): boolean;
     107function TIPQ.TestPut(Item, Value: Integer): Boolean;
    108108var
    109   i: integer;
     109  I: Integer;
    110110begin
    111   i := Ix[Item];
    112   result := (i < 0) or (bh[i].Value > Value);
     111  I := Ix[Item];
     112  Result := (I < 0) or (bh[I].Value > Value);
    113113end;
    114114
    115115// Left(i) = 2*i+1.
    116116// Right(i) = 2*i+2 => Left(i)+1
    117 function TIPQ.Get(var Item, Value: integer): boolean; // O(lg(n))
     117function TIPQ.Get(var Item, Value: Integer): Boolean; // O(lg(n))
    118118var
    119   i, j: integer;
    120   last: TheapItem;
     119  I, J: Integer;
     120  Last: TheapItem;
    121121  lbh: PItemArray;
    122122begin
    123   if n = 0 then
     123  if N = 0 then
    124124  begin
    125     result := False;
    126     exit;
     125    Result := False;
     126    Exit;
    127127  end;
    128128
     
    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 := lbh[n];
    139     i := 0;
    140     j := 1;
    141     while j < n do
     138    Last := lbh[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 (lbh[j].Value > lbh[j + 1].Value) then
    145         Inc(j);
    146       if last.Value <= lbh[j].Value then
    147         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;
    148148
    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
     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
    153153    end;
    154154
    155155    // Insert the root in the correct place in the heap.
    156     lbh[i] := last;
    157     Ix[last.Item] := i;
     156    lbh[I] := Last;
     157    Ix[Last.Item] := I;
    158158  end;
    159   result := True;
     159  Result := True;
    160160end;
    161161
  • trunk/Inp.pas

    r442 r447  
    2121    procedure CenterToRect(Rect: TRect);
    2222  private
    23     Center: boolean;
     23    Center: Boolean;
    2424  end;
    2525
     
    5454    9, Caption);
    5555  { Corner(canvas,1,1,0,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); }
     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); }
    5959end;
    6060
  • trunk/LocalPlayer/Battle.pas

    r442 r447  
    3232    uix, ToLoc: Integer;
    3333    Forecast: TBattleForecastEx;
    34     IsSuicideQuery: boolean;
     34    IsSuicideQuery: Boolean;
    3535  end;
    3636
     
    6363  TextSize: TSize;
    6464  LabelText: string;
    65   FirstStrike: boolean;
     65  FirstStrike: Boolean;
    6666begin
    6767  MaxBar := 65;
     
    196196  BitBltCanvas(Buffer.Canvas, 0, 0, 66, 48, ca, xm - 8 - 4 - 66,
    197197    ym + 8 + 12);
    198   MakeUnitInfo(me, MyUn[uix], UnitInfo);
     198  MakeUnitInfo(Me, MyUn[uix], UnitInfo);
    199199  UnitInfo.Flags := UnitInfo.Flags and not unFortified;
    200200  IsoMap.PaintUnit(1, 0, UnitInfo, 0);
     
    216216    ClientWidth := 300;
    217217    ClientHeight := 288;
    218     OKBtn.Visible := true;
    219     CancelBtn.Visible := true;
     218    OKBtn.Visible := True;
     219    CancelBtn.Visible := True;
    220220    Left := (Screen.Width - ClientWidth) div 2; // center on screen
    221221    Top := (Screen.Height - ClientHeight) div 2;
     
    225225    ClientWidth := 178;
    226226    ClientHeight := 178;
    227     OKBtn.Visible := false;
    228     CancelBtn.Visible := false;
     227    OKBtn.Visible := False;
     228    CancelBtn.Visible := False;
    229229  end;
    230230end;
     
    232232procedure TBattleDlg.FormPaint(Sender: TObject);
    233233var
    234   ym, cix, p: Integer;
    235   s, s1: string;
     234  ym, cix, P: Integer;
     235  S, s1: string;
    236236begin
    237237  with Canvas do
     
    253253  begin
    254254    Canvas.Font.Assign(UniFont[ftCaption]);
    255     s := Phrases.Lookup('TITLE_SUICIDE');
    256     RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
    257       7 + Border, s);
     255    S := Phrases.Lookup('TITLE_SUICIDE');
     256    RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
     257      7 + Border, S);
    258258    Canvas.Font.Assign(UniFont[ftNormal]);
    259     s := Phrases.Lookup('SUICIDE');
    260     p := pos('\', s);
    261     if p = 0 then
    262       RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))
    263         div 2, 205, s)
     259    S := Phrases.Lookup('SUICIDE');
     260    P := Pos('\', S);
     261    if P = 0 then
     262      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S))
     263        div 2, 205, S)
    264264    else
    265265    begin
    266       s1 := copy(s, 1, p - 1);
     266      s1 := Copy(S, 1, P - 1);
    267267      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
    268268        205 - MessageLineSpacing div 2, s1);
    269       s1 := copy(s, p + 1, 255);
     269      s1 := Copy(S, P + 1, 255);
    270270      RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s1)) div 2,
    271271        205 + (MessageLineSpacing - MessageLineSpacing div 2), s1);
  • trunk/LocalPlayer/CityScreen.pas

    r442 r447  
    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);
     
    5353    procedure PageDownBtnClick(Sender: TObject);
    5454  private
    55     c: TCity;
     55    C: TCity;
    5656    Report: TCityReportNew;
    5757    cOwner: Integer;
     
    7070    Optimize_cixTileChange: Integer;
    7171    Optimize_TilesBeforeChange: Integer;
    72     Happened: cardinal;
    73     imix: array [0 .. 15] of integer;
     72    Happened: Cardinal;
     73    imix: array [0 .. 15] of Integer;
    7474    CityAreaInfo: TCityAreaInfo;
    7575    AreaMap: TIsoMap;
     
    8989    procedure InitZoomCityMap;
    9090    procedure ChooseProject;
    91     procedure ChangeCity(d: integer);
    92     procedure ChangeResourceWeights(iResourceWeights: integer);
     91    procedure ChangeCity(D: Integer);
     92    procedure ChangeResourceWeights(iResourceWeights: Integer);
    9393    procedure OnPlaySound(var Msg: TMessage); message WM_PLAYSOUND;
    9494  public
     
    9696    CloseAction: TCityCloseAction;
    9797    procedure OffscreenPaint; override;
    98     procedure ShowNewContent(NewMode: TWindowMode; Loc: integer; ShowEvent: cardinal);
     98    procedure ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal);
    9999    procedure Reset;
    100100    procedure CheckAge;
     
    202202  NoMap := TIsoMap.Create;
    203203  AreaMap := TIsoMap.Create;
    204   AreaMap.SetOutput(offscreen);
     204  AreaMap.SetOutput(Offscreen);
    205205  AreaMap.SetPaintBounds(xmArea - 192, ymArea - 96 - 32, xmArea + 192,
    206206    ymArea + 96);
     
    293293procedure TCityDlg.InitSmallCityMap;
    294294var
    295   i, iix, cli1, Color0, Color1, Color2: integer;
     295  I, iix, cli1, Color0, Color1, Color2: Integer;
    296296begin
    297297  if cix >= 0 then
    298     c := MyCity[cix];
     298    C := MyCity[cix];
    299299  case MyMap[cLoc] and fTerrain of
    300300    fPrairie: cli1 := cliPrairie;
     
    329329  begin
    330330    Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImp];
    331     for i := 0 to 29 do
     331    for I := 0 to 29 do
    332332    begin
    333333      for iix := nWonder to nImp - 1 do
    334         if (ImpPosition[iix] = i) and (c.Built[iix] > 0) then
     334        if (ImpPosition[iix] = I) and (C.Built[iix] > 0) then
    335335        begin
    336           FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    337             3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    338             11 + 12 * (i mod 18 div 3)));
    339           break;
     336          FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     337            3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     338            11 + 12 * (I mod 18 div 3)));
     339          Break;
    340340        end;
    341341    end;
    342     i := 30;
     342    I := 30;
    343343    for iix := 0 to nImp do
    344       if (c.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then
     344      if (C.Built[iix] > 0) and ((iix < nWonder) or (ImpPosition[iix] < 0)) then
    345345      begin
    346         FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    347           3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    348           11 + 12 * (i mod 18 div 3)));
    349         inc(i);
    350         if i = 36 then
    351           break; // area is full
     346        FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     347          3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     348          11 + 12 * (I mod 18 div 3)));
     349        Inc(I);
     350        if I = 36 then
     351          Break; // area is full
    352352      end;
    353     if c.Project and cpImp <> 0 then
    354     begin
    355       iix := c.Project and cpIndex;
     353    if C.Project and cpImp <> 0 then
     354    begin
     355      iix := C.Project and cpIndex;
    356356      if iix <> imTrGoods then
    357357      begin
    358358        if (iix >= nWonder) and (ImpPosition[iix] >= 0) then
    359           i := ImpPosition[iix];
    360         if i < 36 then
     359          I := ImpPosition[iix];
     360        if I < 36 then
    361361        begin
    362           brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject];
    363           FillRect(Rect(5 + 16 * (i mod 3) + 48 * (i div 18),
    364             3 + 12 * (i mod 18 div 3), 13 + 16 * (i mod 3) + 48 * (i div 18),
    365             11 + 12 * (i mod 18 div 3)));
     362          Brush.Color := ScreenTools.Colors.Canvas.Pixels[clkAge0 + Age, cliImpProject];
     363          FillRect(Rect(5 + 16 * (I mod 3) + 48 * (I div 18),
     364            3 + 12 * (I mod 18 div 3), 13 + 16 * (I mod 3) + 48 * (I div 18),
     365            11 + 12 * (I mod 18 div 3)));
    366366        end;
    367367      end;
    368368    end;
    369     brush.style := bsClear;
     369    Brush.style := bsClear;
    370370  end;
    371371end;
     
    384384        112 * (ZoomArea - 3), wZoomMap - wZoomEnvironment, hZoomMap);
    385385      ImageOp_B(ZoomCityMap, CityMapTemplate, wZoomMap - wZoomEnvironment, 0,
    386         1504 + wZoomEnvironment * byte(IsPort), 112 * (ZoomArea - 3),
     386        1504 + wZoomEnvironment * Byte(IsPort), 112 * (ZoomArea - 3),
    387387        wZoomEnvironment, hZoomMap);
    388388    end;
     
    392392procedure TCityDlg.OffscreenPaint;
    393393
    394   procedure FillBar(x, y, pos, Growth, max, Kind: integer;
    395     IndicateComplete: boolean);
     394  procedure FillBar(X, Y, Pos, Growth, Max, Kind: Integer;
     395    IndicateComplete: Boolean);
    396396  begin
    397397    BarTex.Assign(MainTexture);
     
    400400      BarTex.ColorBevelShade := BarTex.ColorBevelLight;
    401401    end;
    402     PaintRelativeProgressBar(offscreen.Canvas, Kind, x - 3, y, wBar - 4, pos,
    403       Growth, max, IndicateComplete, BarTex);
    404   end;
    405 
    406   procedure PaintResources(x, y, Loc: integer; Add4Happy: boolean);
     402    PaintRelativeProgressBar(Offscreen.Canvas, Kind, X - 3, Y, wBar - 4, Pos,
     403      Growth, Max, IndicateComplete, BarTex);
     404  end;
     405
     406  procedure PaintResources(X, Y, Loc: Integer; Add4Happy: Boolean);
    407407  var
    408     d, i, Total, xGr, yGr: integer;
     408    D, I, Total, xGr, yGr: Integer;
    409409    TileInfo: TTileInfo;
    410     rare: boolean;
     410    rare: Boolean;
    411411  begin
    412412    with AreaMap do begin
    413     if Server(sGetCityTileInfo, me, Loc, TileInfo) <> eOk then
    414     begin
    415       assert(cix < 0);
    416       exit
     413    if Server(sGetCityTileInfo, Me, Loc, TileInfo) <> eOk then
     414    begin
     415      Assert(cix < 0);
     416      Exit
    417417    end;
    418418    Total := TileInfo.Food + TileInfo.Prod + TileInfo.Trade;
    419419    rare := MyMap[Loc] and $06000000 > 0;
    420420    if rare then
    421       inc(Total);
     421      Inc(Total);
    422422    if Add4Happy then
    423       inc(Total, 4);
     423      Inc(Total, 4);
    424424    if Total > 1 then
    425       d := (xxt - 11) div (Total - 1);
    426     if d < 1 then
    427       d := 1;
    428     if d > 4 then
    429       d := 4;
    430     for i := 0 to Total - 1 do
     425      D := (xxt - 11) div (Total - 1);
     426    if D < 1 then
     427      D := 1;
     428    if D > 4 then
     429      D := 4;
     430    for I := 0 to Total - 1 do
    431431    begin
    432432      yGr := 115;
    433       if Add4Happy and (i >= Total - 4) then
     433      if Add4Happy and (I >= Total - 4) then
    434434      begin
    435435        xGr := 132;
    436436        yGr := 126
    437437      end
    438       else if rare and (i = Total - 1) then
     438      else if rare and (I = Total - 1) then
    439439        xGr := 66 + 110
    440       else if i >= TileInfo.Food + TileInfo.Prod then
     440      else if I >= TileInfo.Food + TileInfo.Prod then
    441441        xGr := 66 + 44
    442       else if i >= TileInfo.Prod then
     442      else if I >= TileInfo.Prod then
    443443        xGr := 66
    444444      else
    445445        xGr := 66 + 22;
    446       Sprite(offscreen, HGrSystem, x + xxt - 5 + d * (2 * i + 1 - Total),
    447         y + yyt - 5, 10, 10, xGr, yGr);
     446      Sprite(Offscreen, HGrSystem, X + xxt - 5 + D * (2 * I + 1 - Total),
     447        Y + yyt - 5, 10, 10, xGr, yGr);
    448448    end;
    449449    end;
    450450  end;
    451451var
    452   line, MessageCount: integer;
    453 
    454   procedure CheckMessage(Flag: integer);
     452  Line, MessageCount: Integer;
     453
     454  procedure CheckMessage(Flag: Integer);
    455455  var
    456     i, test: integer;
    457     s: string;
     456    I, Test: Integer;
     457    S: string;
    458458  begin
    459459    if Happened and Flag <> 0 then
    460460    begin
    461       i := 0;
    462       test := 1;
    463       while test < Flag do
     461      I := 0;
     462      Test := 1;
     463      while Test < Flag do
    464464      begin
    465         inc(i);
    466         inc(test, test)
     465        Inc(I);
     466        Inc(Test, Test);
    467467      end;
    468468
    469469      if AllowChange and (Sounds <> nil) and (OpenSoundEvent = -1) then
    470470      begin
    471         s := CityEventSoundItem[i];
    472         if s <> '' then
    473           s := Sounds.Lookup(s);
    474         if (Flag = chProduction) or (s <> '') and (s[1] <> '*') and (s[1] <> '[')
     471        S := CityEventSoundItem[I];
     472        if S <> '' then
     473          S := Sounds.Lookup(S);
     474        if (Flag = chProduction) or (S <> '') and (S[1] <> '*') and (S[1] <> '[')
    475475        then
    476           OpenSoundEvent := i
     476          OpenSoundEvent := I;
    477477      end;
    478478
    479       s := CityEventName(i);
     479      S := CityEventName(I);
    480480      { if Flag=chNoGrowthWarning then
    481         if c.Built[imAqueduct]=0 then
    482         s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
    483         else s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); }
    484       RisedTextOut(offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount +
    485         16 * line, s);
    486       inc(line)
     481        if C.Built[imAqueduct]=0 then
     482        S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
     483        else S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); }
     484      RisedTextOut(Offscreen.Canvas, xmOpt + 40, ymOpt - 1 - 8 * MessageCount +
     485        16 * Line, S);
     486      Inc(Line);
    487487    end;
    488488  end;
    489489
    490490var
    491   x, y, xGr, i, j, iix, d, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix,
     491  X, Y, xGr, I, J, iix, D, dx, dy, PrCost, Cnt, Loc1, FreeSupp, Paintiix,
    492492    HappyGain, OptiType, rx, ry, TrueFood, TrueProd, TruePoll: Integer;
    493493  av: Integer;
    494   PrName, s: string;
     494  PrName, S: string;
    495495  UnitInfo: TUnitInfo;
    496496  UnitReport: TUnitReport;
     
    499499  inherited;
    500500  if cix >= 0 then
    501     c := MyCity[cix];
     501    C := MyCity[cix];
    502502  Report.HypoTiles := -1;
    503503  Report.HypoTaxRate := -1;
    504504  Report.HypoLuxuryRate := -1;
    505505  if cix >= 0 then
    506     Server(sGetCityReportNew, me, cix, Report) // own city
     506    Server(sGetCityReportNew, Me, cix, Report) // own city
    507507  else
    508     Server(sGetEnemyCityReportNew, me, cLoc, Report); // enemy city
    509   TrueFood := c.Food;
    510   TrueProd := c.Prod;
    511   TruePoll := c.Pollution;
     508    Server(sGetEnemyCityReportNew, Me, cLoc, Report); // enemy city
     509  TrueFood := C.Food;
     510  TrueProd := C.Prod;
     511  TruePoll := C.Pollution;
    512512  if Supervising or (cix < 0) then
    513513  begin // normalize city from after-turn state
     
    522522      TruePoll := 0; // shouldn't happen
    523523  end;
    524   IsCityAlive := (cGov <> gAnarchy) and (c.Flags and chCaptured = 0);
     524  IsCityAlive := (cGov <> gAnarchy) and (C.Flags and chCaptured = 0);
    525525  if not IsCityAlive then
    526     Report.Working := c.Size;
     526    Report.Working := C.Size;
    527527
    528528  RedTex.Assign(MainTexture);
     
    532532  RedTex.ColorTextShade := $0000FF;
    533533
    534   BitBltCanvas(offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0);
     534  BitBltCanvas(Offscreen.Canvas, 0, 0, 640, 480, Back.Canvas, 0, 0);
    535535
    536536  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
     
    544544    Brush.style := bsClear;
    545545    Font.Color := $000000;
    546     s := IntToStr(c.Size);
    547     TextOut(8 + 14 - TextWidth(s) div 2, 7, s);
     546    S := IntToStr(C.Size);
     547    TextOut(8 + 14 - TextWidth(S) div 2, 7, S);
    548548  end;
    549549  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     
    553553    MakeRed(Offscreen, 18, 280, 298, 40);
    554554    if cGov = gAnarchy then
    555       s := Phrases.Lookup('GOVERNMENT', gAnarchy)
     555      S := Phrases.Lookup('GOVERNMENT', gAnarchy)
    556556    else { if c.Flags and chCaptured<>0 then }
    557       s := Phrases.Lookup('CITYEVENTS', 14);
    558     RisedTextOut(offscreen.Canvas, 167 - BiColorTextWidth(offscreen.Canvas, s)
    559       div 2, ymOpt - 9, s);
     557      S := Phrases.Lookup('CITYEVENTS', 14);
     558    RisedTextOut(Offscreen.Canvas, 167 - BiColorTextWidth(Offscreen.Canvas, S)
     559      div 2, ymOpt - 9, S);
    560560  end
    561561  else if AllowChange then
    562562  begin
    563     OptiType := c.Status shr 4 and $0F;
    564     Sprite(offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64,
     563    OptiType := C.Status shr 4 and $0F;
     564    Sprite(Offscreen, HGrSystem2, xmOpt - 32, ymOpt - 32, 64, 64,
    565565      1 + OptiType mod 3 * 64, 217 + OptiType div 3 * 64);
    566566
    567567    { display messages now }
    568568    MessageCount := 0;
    569     for i := 0 to 31 do
    570       if Happened and ($FFFFFFFF - chCaptured) and (1 shl i) <> 0 then
    571         inc(MessageCount);
     569    for I := 0 to 31 do
     570      if Happened and ($FFFFFFFF - chCaptured) and (1 shl I) <> 0 then
     571        Inc(MessageCount);
    572572    if MessageCount > 3 then
    573573      MessageCount := 3;
    574574    if MessageCount > 0 then
    575575    begin
    576       MakeBlue(offscreen, 74, 280, 242, 40);
    577       line := 0;
    578       for i := 0 to nCityEventPriority - 1 do
    579         if line < MessageCount then
    580           CheckMessage(CityEventPriority[i]);
     576      MakeBlue(Offscreen, 74, 280, 242, 40);
     577      Line := 0;
     578      for I := 0 to nCityEventPriority - 1 do
     579        if Line < MessageCount then
     580          CheckMessage(CityEventPriority[I]);
    581581    end
    582582    else
    583583    begin
    584       s := Phrases.Lookup('CITYMANAGETYPE', OptiType);
    585       j := pos('\', s);
    586       if j = 0 then
    587         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40,
    588           ymOpt - 9, s)
     584      S := Phrases.Lookup('CITYMANAGETYPE', OptiType);
     585      J := Pos('\', S);
     586      if J = 0 then
     587        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40,
     588          ymOpt - 9, S)
    589589      else
    590590      begin
    591         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40,
    592           ymOpt - 17, copy(s, 1, j - 1));
    593         LoweredTextout(offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1,
    594           copy(s, j + 1, 255));
     591        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40,
     592          ymOpt - 17, Copy(S, 1, J - 1));
     593        LoweredTextout(Offscreen.Canvas, -1, MainTexture, xmOpt + 40, ymOpt - 1,
     594          Copy(S, J + 1, 255));
    595595      end;
    596596    end;
     
    602602    AreaMap.Paint(xmArea - xxt * 2 * rx, ymArea - yyt * 2 * ry - 3 * yyt,
    603603      dLoc(cLoc, -2 * rx + 1, -2 * ry - 1), 4 * rx - 1, 4 * ry + 1, cLoc, cOwner,
    604       false, AllowChange and IsCityAlive and
    605       (c.Status and csResourceWeightsMask = 0));
    606     BitBltCanvas(offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas,
     604      False, AllowChange and IsCityAlive and
     605      (C.Status and csResourceWeightsMask = 0));
     606    BitBltCanvas(Offscreen.Canvas, xmArea + 102, 42, 90, 33, Back.Canvas,
    607607      xmArea + 102, 42);
    608608
     
    616616              ((Loc1 < 0) or (Loc1 >= G.lx * G.ly) or (MyMap[Loc1] and fCity = 0))
    617617            then
    618               Sprite(offscreen, HGrTerrain, xmArea - xxt + xxt * dx,
     618              Sprite(Offscreen, HGrTerrain, xmArea - xxt + xxt * dx,
    619619                ymArea - yyt + yyt * dy, xxt * 2, yyt * 2, 1 + 5 * (xxt * 2 + 1),
    620620                1 + yyt + 15 * (yyt * 3 + 1));
    621             if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and c.Tiles <> 0) then
     621            if (1 shl ((dy + 3) shl 2 + (dx + 3) shr 1) and C.Tiles <> 0) then
    622622              PaintResources(xmArea - xxt + xxt * dx, ymArea - yyt + yyt * dy,
    623623                Loc1, (dx = 0) and (dy = 0));
     
    626626
    627627  if Report.Working > 1 then
    628     d := (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1);
    629   if d > 28 then
    630     d := 28;
    631   for i := Report.Working - 1 downto 0 do
     628    D := (xService - (xmArea - 192) - 8 - 32) div (Report.Working - 1);
     629  if D > 28 then
     630    D := 28;
     631  for I := Report.Working - 1 downto 0 do
    632632  begin
    633633    if IsCityAlive then
     
    635635    else
    636636      xGr := 141;
    637     BitBltCanvas(offscreen.Canvas, xmArea - 192 + 5 + i * d, ymArea - 96 - 29,
     637    BitBltCanvas(Offscreen.Canvas, xmArea - 192 + 5 + I * D, ymArea - 96 - 29,
    638638      27, 30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow }
    639     Sprite(offscreen, HGrSystem, xmArea - 192 + 4 + i * d, ymArea - 96 - 30, 27,
     639    Sprite(Offscreen, HGrSystem, xmArea - 192 + 4 + I * D, ymArea - 96 - 30, 27,
    640640      30, xGr, 171);
    641641  end;
    642   if c.Size - Report.Working > 1 then
    643     d := (xmArea + 192 - xService - 32) div (c.Size - Report.Working - 1);
    644   if d > 28 then
    645     d := 28;
    646   for i := 0 to c.Size - Report.Working - 1 do
     642  if C.Size - Report.Working > 1 then
     643    D := (xmArea + 192 - xService - 32) div (C.Size - Report.Working - 1);
     644  if D > 28 then
     645    D := 28;
     646  for I := 0 to C.Size - Report.Working - 1 do
    647647  begin
    648648    xGr := 1 + 112;
    649     BitBltCanvas(offscreen.Canvas, xmArea + 192 - 27 + 1 - i * d, 29 + 1, 27,
     649    BitBltCanvas(Offscreen.Canvas, xmArea + 192 - 27 + 1 - I * D, 29 + 1, 27,
    650650      30, HGrSystem.Mask.Canvas, xGr, 171, SRCAND); { shadow }
    651     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 - i * d, 29, 27, 30,
     651    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 - I * D, 29, 27, 30,
    652652      xGr, 171);
    653     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 + 4 - i * d, 29 + 32, 10,
     653    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 4 - I * D, 29 + 32, 10,
    654654      10, 121, 126);
    655     Sprite(offscreen, HGrSystem, xmArea + 192 - 27 + 13 - i * d, 29 + 32, 10,
     655    Sprite(Offscreen, HGrSystem, xmArea + 192 - 27 + 13 - I * D, 29 + 32, 10,
    656656      10, 121, 126);
    657657    // Sprite(offscreen,HGrSystem,xmArea+192-31+18-i*d,ymArea-96-80+32,10,10,88,115);
    658658  end;
    659659
    660   if c.Project and cpImp = 0 then
    661     PrName := Tribe[cOwner].ModelName[c.Project and cpIndex]
     660  if C.Project and cpImp = 0 then
     661    PrName := Tribe[cOwner].ModelName[C.Project and cpIndex]
    662662  else
    663     PrName := Phrases.Lookup('IMPROVEMENTS', c.Project and cpIndex);
     663    PrName := Phrases.Lookup('IMPROVEMENTS', C.Project and cpIndex);
    664664  PrCost := Report.ProjectCost;
    665665
     
    668668  begin
    669669    if cGov = gFundamentalism then
    670       CountBar(offscreen, xHapp, yHapp + dyBar, wBar, 17,
     670      CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17,
    671671        Phrases.Lookup('FAITH'), Report.CollectedControl, MainTexture)
    672672    else
    673673    begin
    674       CountBar(offscreen, xHapp, yHapp + dyBar, wBar, 17,
     674      CountBar(Offscreen, xHapp, yHapp + dyBar, wBar, 17,
    675675        Phrases.Lookup('HAPPINESS'), Report.Morale, MainTexture);
    676       CountBar(offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16,
     676      CountBar(Offscreen, xHapp, yHapp + 2 * dyBar, wBar, 16,
    677677        Phrases.Lookup('CONTROL'), Report.CollectedControl, MainTexture);
    678678    end;
    679     CountBar(offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'),
     679    CountBar(Offscreen, xHapp, yHapp, wBar, 8, Phrases.Lookup('LUX'),
    680680      Report.Luxury, MainTexture);
    681     CountBar(offscreen, xHapp + dxBar, yHapp, wBar, 19,
     681    CountBar(Offscreen, xHapp + dxBar, yHapp, wBar, 19,
    682682      Phrases.Lookup('UNREST'), 2 * Report.Deployed, MainTexture);
    683     CountBar(offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17,
    684       Phrases.Lookup('HAPPINESSDEMAND'), c.Size, MainTexture);
     683    CountBar(Offscreen, xHapp + dxBar, yHapp + dyBar, wBar, 17,
     684      Phrases.Lookup('HAPPINESSDEMAND'), C.Size, MainTexture);
    685685    if Report.HappinessBalance >= 0 then
    686       CountBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17,
     686      CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 17,
    687687        Phrases.Lookup('HAPPINESSPLUS'), Report.HappinessBalance, MainTexture)
    688688    else
    689689    begin
    690690      MakeRed(Offscreen, xHapp + dxBar - 6, yHapp + 2 * dyBar, wBar + 10, 38);
    691       CountBar(offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18,
     691      CountBar(Offscreen, xHapp + dxBar, yHapp + 2 * dyBar, wBar, 18,
    692692        Phrases.Lookup('LACK'), -Report.HappinessBalance, RedTex);
    693693    end;
     
    697697  if IsCityAlive then
    698698  begin
    699     CountBar(offscreen, xFood, yFood + dyBar div 2, wBar, 0,
     699    CountBar(Offscreen, xFood, yFood + dyBar div 2, wBar, 0,
    700700      Phrases.Lookup('FOOD'), Report.CollectedFood, MainTexture);
    701     CountBar(offscreen, xFood + dxBar, yFood + dyBar, wBar, 0,
    702       Phrases.Lookup('DEMAND'), 2 * c.Size, MainTexture);
    703     CountBar(offscreen, xFood + dxBar, yFood, wBar, 0,
     701    CountBar(Offscreen, xFood + dxBar, yFood + dyBar, wBar, 0,
     702      Phrases.Lookup('DEMAND'), 2 * C.Size, MainTexture);
     703    CountBar(Offscreen, xFood + dxBar, yFood, wBar, 0,
    704704      Phrases.Lookup('SUPPORT'), Report.FoodSupport, MainTexture);
    705705    if Report.FoodSurplus >= 0 then
    706       if (cGov = gFuture) or (c.Size >= NeedAqueductSize) and
     706      if (cGov = gFuture) or (C.Size >= NeedAqueductSize) and
    707707        (Report.FoodSurplus < 2) then
    708         CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6,
     708        CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 6,
    709709          Phrases.Lookup('PROFIT'), Report.FoodSurplus, MainTexture)
    710710      else
    711         CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0,
     711        CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 0,
    712712          Phrases.Lookup('SURPLUS'), Report.FoodSurplus, MainTexture)
    713713    else
    714714    begin
    715715      MakeRed(Offscreen, xFood + dxBar - 6, yFood + 2 * dyBar, wBar + 10, 38);
    716       CountBar(offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1,
     716      CountBar(Offscreen, xFood + dxBar, yFood + 2 * dyBar, wBar, 1,
    717717        Phrases.Lookup('LACK'), -Report.FoodSurplus, RedTex);
    718718    end;
    719719  end;
    720   CanGrow := (c.Size < MaxCitySize) and (cGov <> gFuture) and
    721     (Report.FoodSurplus > 0) and ((c.Size < NeedAqueductSize) or
    722     (c.Built[imAqueduct] = 1) and (c.Size < NeedSewerSize) or
    723     (c.Built[imSewer] = 1));
     720  CanGrow := (C.Size < MaxCitySize) and (cGov <> gFuture) and
     721    (Report.FoodSurplus > 0) and ((C.Size < NeedAqueductSize) or
     722    (C.Built[imAqueduct] = 1) and (C.Size < NeedSewerSize) or
     723    (C.Built[imSewer] = 1));
    724724  FillBar(xFood + 3, yFood + 102, TrueFood,
    725     CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, c.Size),
     725    CutCityFoodSurplus(Report.FoodSurplus, IsCityAlive, cGov, C.Size),
    726726    Report.Storage, 1, CanGrow);
    727   LoweredTextout(offscreen.Canvas, -1, MainTexture, xFood + 3 - 5,
     727  LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood + 3 - 5,
    728728    yFood + 102 - 20, Format('%d/%d', [TrueFood, Report.Storage]));
    729   LoweredTextout(offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66,
     729  LoweredTextout(Offscreen.Canvas, -1, MainTexture, xFood - 2, yFood + 66,
    730730    Phrases.Lookup('STORAGE'));
    731731
     
    733733  if IsCityAlive then
    734734  begin
    735     CountBar(offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'),
     735    CountBar(Offscreen, xProd, yProd, wBar, 2, Phrases.Lookup('MATERIAL'),
    736736      Report.CollectedMaterial, MainTexture);
    737     CountBar(offscreen, xProd + dxBar, yProd, wBar, 2,
     737    CountBar(Offscreen, xProd + dxBar, yProd, wBar, 2,
    738738      Phrases.Lookup('SUPPORT'), Report.MaterialSupport, MainTexture);
    739739    if Report.Production >= 0 then
    740       if c.Project and (cpImp + cpIndex) = cpImp + imTrGoods then
    741         CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6,
     740      if C.Project and (cpImp + cpIndex) = cpImp + imTrGoods then
     741        CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 6,
    742742          Phrases.Lookup('PROFIT'), Report.Production, MainTexture)
    743743      else
    744         CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2,
     744        CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 2,
    745745          Phrases.Lookup('PROD'), Report.Production, MainTexture)
    746746    else
    747747    begin
    748748      MakeRed(Offscreen, xProd + dxBar - 6, yProd + dyBar + 17, wBar + 10, 38);
    749       CountBar(offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3,
     749      CountBar(Offscreen, xProd + dxBar, yProd + dyBar + 16, wBar, 3,
    750750        Phrases.Lookup('LACK'), -Report.Production, RedTex);
    751751    end;
    752752  end;
    753   if c.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then
    754     with offscreen.Canvas do
    755     begin
    756       i := Report.Production;
    757       if (i < 0) or not IsCityAlive then
    758         i := 0;
    759       FillBar(xProd + 3, yProd + 16 + 63, TrueProd, i, PrCost, 4, true);
    760       LoweredTextout(offscreen.Canvas, -1, MainTexture, xProd + 3 - 5,
     753  if C.Project and (cpImp + cpIndex) <> cpImp + imTrGoods then
     754    with Offscreen.Canvas do
     755    begin
     756      I := Report.Production;
     757      if (I < 0) or not IsCityAlive then
     758        I := 0;
     759      FillBar(xProd + 3, yProd + 16 + 63, TrueProd, I, PrCost, 4, True);
     760      LoweredTextout(Offscreen.Canvas, -1, MainTexture, xProd + 3 - 5,
    761761        yProd + 16 + 43, Format('%d/%d', [TrueProd, PrCost]));
    762       if BiColorTextWidth(offscreen.Canvas, PrName) > wBar + dxBar then
     762      if BiColorTextWidth(Offscreen.Canvas, PrName) > wBar + dxBar then
    763763      begin
    764764        repeat
    765           Delete(PrName, length(PrName), 1)
    766         until BiColorTextWidth(offscreen.Canvas, PrName) <= wBar + dxBar;
     765          Delete(PrName, Length(PrName), 1)
     766        until BiColorTextWidth(Offscreen.Canvas, PrName) <= wBar + dxBar;
    767767        PrName := PrName + '.'
    768768      end;
    769769    end;
    770   RisedTextOut(offscreen.Canvas, xProd - 2, yProd + 36, PrName);
     770  RisedTextOut(Offscreen.Canvas, xProd - 2, yProd + 36, PrName);
    771771
    772772  // pollution section
     
    774774  begin
    775775    FillBar(xPoll + 3, yPoll + 20, TruePoll, Report.AddPollution,
    776       MaxPollution, 3, true);
    777     RisedTextOut(offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20,
     776      MaxPollution, 3, True);
     777    RisedTextOut(Offscreen.Canvas, xPoll + 3 - 5, yPoll + 20 - 20,
    778778      Phrases.Lookup('POLL'));
    779779  end;
     
    782782  if IsCityAlive and (Report.CollectedTrade > 0) then
    783783  begin
    784     CountBar(offscreen, xTrade, yTrade + dyBar div 2, wBar, 4,
     784    CountBar(Offscreen, xTrade, yTrade + dyBar div 2, wBar, 4,
    785785      Phrases.Lookup('TRADE'), Report.CollectedTrade, MainTexture);
    786     CountBar(offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5,
     786    CountBar(Offscreen, xTrade + dxBar, yTrade + 2 * dyBar, wBar, 5,
    787787      Phrases.Lookup('CORR'), Report.Corruption, MainTexture);
    788     CountBar(offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'),
     788    CountBar(Offscreen, xTrade + dxBar, yTrade, wBar, 6, Phrases.Lookup('TAX'),
    789789      Report.Tax, MainTexture);
    790     CountBar(offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12,
     790    CountBar(Offscreen, xTrade + dxBar, yTrade + dyBar, wBar, 12,
    791791      Phrases.Lookup('SCIENCE'), Report.Science, MainTexture);
    792792  end;
    793793
    794794  // small map
    795   BitBltCanvas(offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap,
     795  BitBltCanvas(Offscreen.Canvas, xSmallMap, ySmallMap, wSmallMap, hSmallMap,
    796796    SmallCityMap.Canvas, 0, 0);
    797797  if SmallMapMode = smImprovements then
    798     Frame(offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3),
     798    Frame(Offscreen.Canvas, xSmallMap + 48 * (ZoomArea div 3),
    799799      ySmallMap + 24 * (ZoomArea mod 3), xSmallMap + 48 * (ZoomArea div 3) + 49,
    800800      ySmallMap + 24 * (ZoomArea mod 3) + 25, MainTexture.ColorMark,
    801801      MainTexture.ColorMark);
    802   Frame(offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap,
     802  Frame(Offscreen.Canvas, xSmallMap - 1, ySmallMap - 1, xSmallMap + wSmallMap,
    803803    ySmallMap + hSmallMap, $B0B0B0, $FFFFFF);
    804   RFrame(offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap +
     804  RFrame(Offscreen.Canvas, xSmallMap - 2, ySmallMap - 2, xSmallMap + wSmallMap +
    805805    1, ySmallMap + hSmallMap + 1, $FFFFFF, $B0B0B0);
    806806
    807   Frame(offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport,
     807  Frame(Offscreen.Canvas, xSupport - 1, ySupport - 1, xSupport + wSupport,
    808808    ySupport + hSupport, $B0B0B0, $FFFFFF);
    809   RFrame(offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1,
     809  RFrame(Offscreen.Canvas, xSupport - 2, ySupport - 2, xSupport + wSupport + 1,
    810810    ySupport + hSupport + 1, $FFFFFF, $B0B0B0);
    811   x := xSupport + wSupport div 2;
    812   y := ySupport + hSupport div 2;
     811  X := xSupport + wSupport div 2;
     812  Y := ySupport + hSupport div 2;
    813813  if SmallMapMode = smSupportedUnits then
    814814  begin
    815     offscreen.Canvas.brush.Color := MainTexture.ColorMark;
    816     offscreen.Canvas.FillRect(Rect(x - 27, y - 6, x + 27, y + 6));
    817     offscreen.Canvas.brush.style := bsClear;
    818   end;
    819   Sprite(offscreen, HGrSystem, x - 16, y - 5, 10, 10, 88, 115);
    820   Sprite(offscreen, HGrSystem, x - 5, y - 5, 10, 10, 66, 115);
    821   Sprite(offscreen, HGrSystem, x + 6, y - 5, 10, 10, 154, 126);
    822 
    823   BitBltCanvas(offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap,
     815    Offscreen.Canvas.Brush.Color := MainTexture.ColorMark;
     816    Offscreen.Canvas.FillRect(Rect(X - 27, Y - 6, X + 27, Y + 6));
     817    Offscreen.Canvas.Brush.style := bsClear;
     818  end;
     819  Sprite(Offscreen, HGrSystem, X - 16, Y - 5, 10, 10, 88, 115);
     820  Sprite(Offscreen, HGrSystem, X - 5, Y - 5, 10, 10, 66, 115);
     821  Sprite(Offscreen, HGrSystem, X + 6, Y - 5, 10, 10, 154, 126);
     822
     823  BitBltCanvas(Offscreen.Canvas, xZoomMap, yZoomMap, wZoomMap, hZoomMap,
    824824    ZoomCityMap.Canvas, 0, 0);
    825825
    826   for i := 0 to 5 do
    827     imix[i] := -1;
     826  for I := 0 to 5 do
     827    imix[I] := -1;
    828828  if SmallMapMode = smImprovements then
    829829  begin
     
    832832      Cnt := 0;
    833833      for iix := 0 to nImp - 1 do
    834         if ((iix < nWonder) or (ImpPosition[iix] < 0)) and (c.Built[iix] > 0) then
     834        if ((iix < nWonder) or (ImpPosition[iix] < 0)) and (C.Built[iix] > 0) then
    835835        begin
    836           i := Cnt - Page * 6;
    837           if (i >= 0) and (i < 6) then
    838             imix[i] := iix;
    839           inc(Cnt);
     836          I := Cnt - Page * 6;
     837          if (I >= 0) and (I < 6) then
     838            imix[I] := iix;
     839          Inc(Cnt);
    840840        end;
    841841      PageCount := (Cnt + 5) div 6;
     
    845845      for iix := nWonder to nImp - 1 do
    846846      begin
    847         i := ImpPosition[iix] - 6 * ZoomArea;
    848         if (i >= 0) and (i < 6) and (c.Built[iix] > 0) then
    849           imix[i] := iix;
     847        I := ImpPosition[iix] - 6 * ZoomArea;
     848        if (I >= 0) and (I < 6) and (C.Built[iix] > 0) then
     849          imix[I] := iix;
    850850      end;
    851851      PageCount := 0;
    852852    end;
    853     for i := 0 to 5 do
    854       if imix[i] >= 0 then
     853    for I := 0 to 5 do
     854      if imix[I] >= 0 then
    855855      begin
    856         iix := imix[i];
    857         x := xZoomMap + 14 + 72 * (i mod 3);
    858         y := yZoomMap + 14 + 56 * (i div 3);
    859         ImpImage(offscreen.Canvas, x, y, iix, cGov, AllowChange and
     856        iix := imix[I];
     857        X := xZoomMap + 14 + 72 * (I mod 3);
     858        Y := yZoomMap + 14 + 56 * (I div 3);
     859        ImpImage(Offscreen.Canvas, X, Y, iix, cGov, AllowChange and
    860860          (ClientMode < scContact));
    861861        if IsCityAlive then
     
    863863          if iix = imColosseum then
    864864          begin
    865             Sprite(offscreen, HGrSystem, x + 46, y, 14, 14, 82, 100);
     865            Sprite(Offscreen, HGrSystem, X + 46, Y, 14, 14, 82, 100);
    866866          end
    867867          else
     
    881881            if HappyGain > 1 then
    882882            begin
    883               d := 30 div (HappyGain - 1);
    884               if d > 10 then
    885                 d := 10
     883              D := 30 div (HappyGain - 1);
     884              if D > 10 then
     885                D := 10
    886886            end;
    887             for j := 0 to HappyGain - 1 do
    888               Sprite(offscreen, HGrSystem, x + 50, y + d * j, 10, 10, 132, 126);
     887            for J := 0 to HappyGain - 1 do
     888              Sprite(Offscreen, HGrSystem, X + 50, Y + D * J, 10, 10, 132, 126);
    889889          end;
    890           for j := 0 to Imp[iix].Maint - 1 do
    891             Sprite(offscreen, HGrSystem, x - 4, y + 29 - 3 * j, 10, 10,
     890          for J := 0 to Imp[iix].Maint - 1 do
     891            Sprite(Offscreen, HGrSystem, X - 4, Y + 29 - 3 * J, 10, 10,
    892892              132, 115);
    893893        end
     
    920920  else { if SmallMapMode = smSupportedUnits then }
    921921  begin
    922     LoweredTextout(offscreen.Canvas, -1, MainTexture, xZoomMap + 6,
     922    LoweredTextout(Offscreen.Canvas, -1, MainTexture, xZoomMap + 6,
    923923      yZoomMap + 2, Phrases.Lookup('SUPUNITS'));
    924     FreeSupp := c.Size * SupportFree[cGov] shr 1;
     924    FreeSupp := C.Size * SupportFree[cGov] shr 1;
    925925    Cnt := 0;
    926     for i := 0 to MyRO.nUn - 1 do
    927       if (MyUn[i].Loc >= 0) and (MyUn[i].Home = cix) then
    928         with MyModel[MyUn[i].mix] do
     926    for I := 0 to MyRO.nUn - 1 do
     927      if (MyUn[I].Loc >= 0) and (MyUn[I].Home = cix) then
     928        with MyModel[MyUn[I].mix] do
    929929        begin
    930           Server(sGetUnitReport, me, i, UnitReport);
     930          Server(sGetUnitReport, Me, I, UnitReport);
    931931          if (Cnt >= 6 * Page) and (Cnt < 6 * (Page + 1)) then
    932932          begin // unit visible in display
    933             imix[Cnt - 6 * Page] := i;
    934             x := ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap;
    935             y := ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20;
    936             MakeUnitInfo(me, MyUn[i], UnitInfo);
    937             NoMap.SetOutput(offscreen);
    938             NoMap.PaintUnit(x, y, UnitInfo, MyUn[i].Status);
    939 
    940             for j := 0 to UnitReport.FoodSupport - 1 do
    941               Sprite(offscreen, HGrSystem, x + 38 + 11 * j, y + 40, 10,
     933            imix[Cnt - 6 * Page] := I;
     934            X := ((Cnt - 6 * Page) mod 3) * 64 + xZoomMap;
     935            Y := ((Cnt - 6 * Page) div 3) * 52 + yZoomMap + 20;
     936            MakeUnitInfo(Me, MyUn[I], UnitInfo);
     937            NoMap.SetOutput(Offscreen);
     938            NoMap.PaintUnit(X, Y, UnitInfo, MyUn[I].Status);
     939
     940            for J := 0 to UnitReport.FoodSupport - 1 do
     941              Sprite(Offscreen, HGrSystem, X + 38 + 11 * J, Y + 40, 10,
    942942                10, 66, 115);
    943             for j := 0 to UnitReport.ProdSupport - 1 do
     943            for J := 0 to UnitReport.ProdSupport - 1 do
    944944            begin
    945945              if (FreeSupp > 0) and
    946946                (UnitReport.ReportFlags and urfAlwaysSupport = 0) then
    947947              begin
    948                 Sprite(offscreen, HGrSystem, x + 16 - 11 * j, y + 40, 10,
     948                Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10,
    949949                  10, 143, 115);
    950                 dec(FreeSupp);
     950                Dec(FreeSupp);
    951951              end
    952952              else
    953                 Sprite(offscreen, HGrSystem, x + 16 - 11 * j, y + 40, 10,
     953                Sprite(Offscreen, HGrSystem, X + 16 - 11 * J, Y + 40, 10,
    954954                  10, 88, 115);
    955955            end;
    956956            if UnitReport.ReportFlags and urfDeployed <> 0 then
    957               for j := 0 to 1 do
    958                 Sprite(offscreen, HGrSystem, x + 27 + 11 * j, y + 40, 10,
     957              for J := 0 to 1 do
     958                Sprite(Offscreen, HGrSystem, X + 27 + 11 * J, Y + 40, 10,
    959959                  10, 154, 126)
    960960          end // unit visible in display
     
    977977  begin
    978978    { display project now }
    979     DLine(offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10,
     979    DLine(Offscreen.Canvas, xView + 9 + xSizeBig, xProd + 2 * wBar + 10,
    980980      yProd + dyBar + 16, $FFFFFF, $B0B0B0);
    981981    if ProdHint then
    982982    begin
    983       ScreenTools.Frame(offscreen.Canvas, xView + 9 - 1, yView + 5 - 1,
     983      ScreenTools.Frame(Offscreen.Canvas, xView + 9 - 1, yView + 5 - 1,
    984984        xView + 9 + xSizeBig, yView + 5 + ySizeBig, $B0B0B0, $FFFFFF);
    985       RFrame(offscreen.Canvas, xView + 9 - 2, yView + 5 - 2,
     985      RFrame(Offscreen.Canvas, xView + 9 - 2, yView + 5 - 2,
    986986        xView + 9 + xSizeBig + 1, yView + 5 + ySizeBig + 1, $FFFFFF, $B0B0B0);
    987       with offscreen.Canvas do
     987      with Offscreen.Canvas do
    988988      begin
    989         brush.Color := $000000;
     989        Brush.Color := $000000;
    990990        FillRect(Rect(xView + 9, yView + 5, xView + 1 + 72 - 8,
    991991          yView + 5 + 40));
    992         brush.style := bsClear;
     992        Brush.style := bsClear;
    993993      end;
    994994    end
    995     else if AllowChange and (c.Status and 7 <> 0) then
     995    else if AllowChange and (C.Status and 7 <> 0) then
    996996    begin // city type autobuild
    997       FrameImage(offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
    998         ySizeBig, (c.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and
     997      FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
     998        ySizeBig, (C.Status and 7 - 1 + 3) * xSizeBig, 0, (cix >= 0) and
    999999        (ClientMode < scContact));
    10001000    end
    1001     else if c.Project and cpImp = 0 then
     1001    else if C.Project and cpImp = 0 then
    10021002    begin // project is unit
    1003       FrameImage(offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
     1003      FrameImage(Offscreen.Canvas, bigimp, xView + 9, yView + 5, xSizeBig,
    10041004        ySizeBig, 0, 0, AllowChange and (ClientMode < scContact));
    1005       with Tribe[cOwner].ModelPicture[c.Project and cpIndex] do
    1006         Sprite(offscreen, HGr, xView + 5, yView + 1, 64, 44,
     1005      with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do
     1006        Sprite(Offscreen, HGr, xView + 5, yView + 1, 64, 44,
    10071007          pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
    10081008    end
     
    10101010    begin // project is building
    10111011      if ProdHint then
    1012         Paintiix := c.Project0 and cpIndex
     1012        Paintiix := C.Project0 and cpIndex
    10131013      else
    1014         Paintiix := c.Project and cpIndex;
    1015       ImpImage(offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov,
     1014        Paintiix := C.Project and cpIndex;
     1015      ImpImage(Offscreen.Canvas, xView + 9, yView + 5, Paintiix, cGov,
    10161016        AllowChange and (ClientMode < scContact));
    10171017    end;
     
    10201020  if AllowChange and (ClientMode < scContact) then
    10211021  begin
    1022     i := Server(sBuyCityProject - sExecute, me, cix, nil^);
    1023     BuyBtn.Visible := (i = eOk) or (i = eViolation);
     1022    I := Server(sBuyCityProject - sExecute, Me, cix, nil^);
     1023    BuyBtn.Visible := (I = eOk) or (I = eViolation);
    10241024  end
    10251025  else
    1026     BuyBtn.Visible := false;
     1026    BuyBtn.Visible := False;
    10271027
    10281028  MarkUsedOffscreen(ClientWidth, ClientHeight);
     
    10311031procedure TCityDlg.FormShow(Sender: TObject);
    10321032var
    1033   dx, dy, Loc1: integer;
     1033  dx, dy, Loc1: Integer;
    10341034  GetCityData: TGetCityData;
    10351035begin
     
    10371037  if cix >= 0 then
    10381038  begin { own city }
    1039     c := MyCity[cix];
    1040     cOwner := me;
     1039    C := MyCity[cix];
     1040    cOwner := Me;
    10411041    cGov := MyRO.Government;
    10421042    ProdHint := (cGov <> gAnarchy) and
    10431043      (Happened and (chProduction or chFounded or chCaptured or
    10441044      chAllImpsMade) <> 0);
    1045     Server(sGetCityAreaInfo, me, cix, CityAreaInfo);
     1045    Server(sGetCityAreaInfo, Me, cix, CityAreaInfo);
    10461046    NextCityBtn.Visible := WindowMode = wmPersistent;
    10471047    PrevCityBtn.Visible := WindowMode = wmPersistent;
     
    10501050  begin
    10511051    SmallMapMode := smImprovements;
    1052     Server(sGetCity, me, cLoc, GetCityData);
    1053     c := GetCityData.c;
     1052    Server(sGetCity, Me, cLoc, GetCityData);
     1053    C := GetCityData.C;
    10541054    cOwner := GetCityData.Owner;
    10551055    cGov := MyRO.EnemyReport[cOwner].Government;
    1056     Happened := c.Flags and $7FFFFFFF;
    1057     ProdHint := false;
    1058     Server(sGetEnemyCityAreaInfo, me, cLoc, CityAreaInfo);
    1059 
    1060     if c.Project and cpImp = 0 then
     1056    Happened := C.Flags and $7FFFFFFF;
     1057    ProdHint := False;
     1058    Server(sGetEnemyCityAreaInfo, Me, cLoc, CityAreaInfo);
     1059
     1060    if C.Project and cpImp = 0 then
    10611061    begin
    10621062      emix := MyRO.nEnemyModel - 1;
    10631063      while (emix > 0) and ((MyRO.EnemyModel[emix].Owner <> cOwner) or
    1064         (integer(MyRO.EnemyModel[emix].mix) <> c.Project and cpIndex)) do
    1065         dec(emix);
    1066       if not Assigned(Tribe[cOwner].ModelPicture[c.Project and cpIndex].HGr) then
     1064        (Integer(MyRO.EnemyModel[emix].mix) <> C.Project and cpIndex)) do
     1065        Dec(emix);
     1066      if not Assigned(Tribe[cOwner].ModelPicture[C.Project and cpIndex].HGr) then
    10671067        InitEnemyModel(emix);
    10681068    end;
     
    10731073  Page := 0;
    10741074
    1075   if c.Size < 5 then
     1075  if C.Size < 5 then
    10761076    SizeClass := 0
    1077   else if c.Size < 9 then
     1077  else if C.Size < 9 then
    10781078    SizeClass := 1
    1079   else if c.Size < 13 then
     1079  else if C.Size < 13 then
    10801080    SizeClass := 2
    10811081  else
     
    11001100  end;
    11011101
    1102   Caption := CityName(c.ID);
     1102  Caption := CityName(C.ID);
    11031103
    11041104  InitSmallCityMap;
     
    11091109end;
    11101110
    1111 procedure TCityDlg.ShowNewContent(NewMode: TWindowMode; Loc: integer; ShowEvent: cardinal);
     1111procedure TCityDlg.ShowNewContent(NewMode: TWindowMode; Loc: Integer; ShowEvent: Cardinal);
    11121112begin
    11131113  if MyMap[Loc] and fOwned <> 0 then
     
    11151115    cix := MyRO.nCity - 1;
    11161116    while (cix >= 0) and (MyCity[cix].Loc <> Loc) do
    1117       dec(cix);
    1118     assert(cix >= 0);
     1117      Dec(cix);
     1118    Assert(cix >= 0);
    11191119    if (Optimize_cixTileChange >= 0) and
    11201120      (Optimize_TilesBeforeChange and not MyCity[Optimize_cixTileChange].Tiles
     
    11321132  else
    11331133    cix := -1;
    1134   AllowChange := not supervising and (cix >= 0);
     1134  AllowChange := not Supervising and (cix >= 0);
    11351135  cLoc := Loc;
    11361136  Happened := ShowEvent;
     
    11391139
    11401140procedure TCityDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
    1141   Shift: TShiftState; x, y: integer);
     1141  Shift: TShiftState; X, Y: Integer);
    11421142var
    1143   i, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: integer;
    1144   Rebuild: boolean;
    1145 begin
    1146   if (ssLeft in Shift) and (x >= xSmallMap) and (x < xSmallMap + wSmallMap) and
    1147     (y >= ySmallMap) and (y < ySmallMap + hSmallMap) then
     1143  I, qx, qy, dx, dy, fix, NewTiles, Loc1, iix, SellResult: Integer;
     1144  Rebuild: Boolean;
     1145begin
     1146  if (ssLeft in Shift) and (X >= xSmallMap) and (X < xSmallMap + wSmallMap) and
     1147    (Y >= ySmallMap) and (Y < ySmallMap + hSmallMap) then
    11481148  begin
    11491149    SmallMapMode := smImprovements;
    1150     ZoomArea := (y - ySmallMap) * 3 div hSmallMap + 3 *
    1151       ((x - xSmallMap) * 2 div wSmallMap);
     1150    ZoomArea := (Y - ySmallMap) * 3 div hSmallMap + 3 *
     1151      ((X - xSmallMap) * 2 div wSmallMap);
    11521152    Page := 0;
    11531153    InitZoomCityMap;
     
    11551155    Exit;
    11561156  end;
    1157   if (ssLeft in Shift) and (x >= xSupport) and (x < xSupport + wSupport) and
    1158     (y >= ySupport) and (y < ySupport + hSupport) then
     1157  if (ssLeft in Shift) and (X >= xSupport) and (X < xSupport + wSupport) and
     1158    (Y >= ySupport) and (Y < ySupport + hSupport) then
    11591159  begin
    11601160    SmallMapMode := smSupportedUnits;
     
    11681168
    11691169  if (ssLeft in Shift) then
    1170     if (ClientMode < scContact) and (x >= xView) and (y >= yView) and
    1171       (x < xView + 73) and (y < yView + 50) then
     1170    if (ClientMode < scContact) and (X >= xView) and (Y >= yView) and
     1171      (X < xView + 73) and (Y < yView + 50) then
    11721172      if cGov = gAnarchy then
    11731173        with MessgExDlg do
    11741174        begin
    11751175          { MessgText:=Phrases.Lookup('OUTOFCONTROL');
    1176             if c.Project and cpImp=0 then
    1177             MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[c.Project and cpIndex]])
    1178             else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',c.Project and cpIndex)]); }
     1176            if C.Project and cpImp=0 then
     1177            MessgText:=Format(MessgText,[Tribe[cOwner].ModelName[C.Project and cpIndex]])
     1178            else MessgText:=Format(MessgText,[Phrases.Lookup('IMPROVEMENTS',C.Project and cpIndex)]); }
    11791179          MessgText := Phrases.Lookup('NOCHANGEINANARCHY');
    11801180          Kind := mkOk;
     
    11851185        if ProdHint then
    11861186        begin
    1187           ProdHint := false;
     1187          ProdHint := False;
    11881188          SmartUpdateContent
    11891189        end;
    11901190        ChooseProject;
    11911191      end
    1192     else if (SmallMapMode = smImprovements) and (x >= xZoomMap) and (x < xZoomMap + wZoomMap) and
    1193       (y >= yZoomMap) and (y < yZoomMap + hZoomMap) then
    1194     begin
    1195       i := 5;
    1196       while (i >= 0) and not((x >= xZoomMap + 14 + 72 * (i mod 3)) and
    1197         (x < xZoomMap + 14 + 56 + 72 * (i mod 3)) and
    1198         (y >= yZoomMap + 14 + 56 * (i div 3)) and
    1199         (y < yZoomMap + 14 + 40 + 56 * (i div 3))) do
    1200         dec(i);
    1201       if i >= 0 then
     1192    else if (SmallMapMode = smImprovements) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and
     1193      (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then
     1194    begin
     1195      I := 5;
     1196      while (I >= 0) and not((X >= xZoomMap + 14 + 72 * (I mod 3)) and
     1197        (X < xZoomMap + 14 + 56 + 72 * (I mod 3)) and
     1198        (Y >= yZoomMap + 14 + 56 * (I div 3)) and
     1199        (Y < yZoomMap + 14 + 40 + 56 * (I div 3))) do
     1200        Dec(I);
     1201      if I >= 0 then
    12021202      begin
    1203         iix := imix[i];
     1203        iix := imix[I];
    12041204        if iix >= 0 then
    12051205          if ssShift in Shift then
     
    12211221              else
    12221222              begin
    1223                 SellResult := Server(sSellCityImprovement - sExecute, me,
     1223                SellResult := Server(sSellCityImprovement - sExecute, Me,
    12241224                  cix, iix);
    12251225                if SellResult < rExecuted then
     
    12361236                else
    12371237                begin
    1238                   if Server(sRebuildCityImprovement - sExecute, me, cix, iix) < rExecuted
     1238                  if Server(sRebuildCityImprovement - sExecute, Me, cix, iix) < rExecuted
    12391239                  then
    12401240                  begin // no rebuild possible, ask for sell only
    1241                     Rebuild := false;
     1241                    Rebuild := False;
    12421242                    MessgText := Phrases.Lookup('IMPROVEMENTS', iix);
    12431243                    if not Phrases2FallenBackToEnglish then
    12441244                      MessgText := Format(Phrases2.Lookup('SELL2'),
    12451245                        [MessgText, Imp[iix].Cost * BuildCostMod
    1246                         [G.Difficulty[me]] div 12])
     1246                        [G.Difficulty[Me]] div 12])
    12471247                    else
    12481248                      MessgText := Format(Phrases.Lookup('SELL'), [MessgText]);
    12491249                    if iix = imSpacePort then
    1250                       with MyRO.Ship[me] do
     1250                      with MyRO.Ship[Me] do
    12511251                        if Parts[0] + Parts[1] + Parts[2] > 0 then
    12521252                          MessgText := MessgText + ' ' +
     
    12591259                  else
    12601260                  begin
    1261                     Rebuild := true;
     1261                    Rebuild := True;
    12621262                    MessgText := Phrases.Lookup('IMPROVEMENTS', iix);
    12631263                    if not Phrases2FallenBackToEnglish then
    12641264                      MessgText := Format(Phrases2.Lookup('DISPOSE2'),
    12651265                        [MessgText, Imp[iix].Cost * BuildCostMod
    1266                         [G.Difficulty[me]] div 12 * 2 div 3])
     1266                        [G.Difficulty[Me]] div 12 * 2 div 3])
    12671267                    else
    12681268                      MessgText := Format(Phrases.Lookup('DISPOSE'),
    12691269                        [MessgText]);
    12701270                    if iix = imSpacePort then
    1271                       with MyRO.Ship[me] do
     1271                      with MyRO.Ship[Me] do
    12721272                        if Parts[0] + Parts[1] + Parts[2] > 0 then
    12731273                          MessgText := MessgText + ' ' +
     
    12831283                    begin
    12841284                      Play('CITY_REBUILDIMP');
    1285                       Server(sRebuildCityImprovement, me, cix, iix);
     1285                      Server(sRebuildCityImprovement, Me, cix, iix);
    12861286                    end
    12871287                    else
    12881288                    begin
    12891289                      Play('CITY_SELLIMP');
    1290                       Server(sSellCityImprovement, me, cix, iix);
     1290                      Server(sSellCityImprovement, Me, cix, iix);
    12911291                    end;
    12921292                    CityOptimizer_CityChange(cix);
     
    13011301      end;
    13021302    end
    1303     else if (SmallMapMode = smSupportedUnits) and (x >= xZoomMap) and (x < xZoomMap + wZoomMap) and
    1304       (y >= yZoomMap) and (y < yZoomMap + hZoomMap) then
    1305     begin
    1306       i := 5;
    1307       while (i >= 0) and not((x >= xZoomMap + 64 * (i mod 3)) and
    1308         (x < xZoomMap + 64 + 64 * (i mod 3)) and
    1309         (y >= yZoomMap + 20 + 48 * (i div 3)) and
    1310         (y < yZoomMap + 20 + 52 + 48 * (i div 3))) do
    1311         dec(i);
    1312       if (i >= 0) and (imix[i] >= 0) then
     1303    else if (SmallMapMode = smSupportedUnits) and (X >= xZoomMap) and (X < xZoomMap + wZoomMap) and
     1304      (Y >= yZoomMap) and (Y < yZoomMap + hZoomMap) then
     1305    begin
     1306      I := 5;
     1307      while (I >= 0) and not((X >= xZoomMap + 64 * (I mod 3)) and
     1308        (X < xZoomMap + 64 + 64 * (I mod 3)) and
     1309        (Y >= yZoomMap + 20 + 48 * (I div 3)) and
     1310        (Y < yZoomMap + 20 + 52 + 48 * (I div 3))) do
     1311        Dec(I);
     1312      if (I >= 0) and (imix[I] >= 0) then
    13131313        if ssShift in Shift then
    13141314        else if (cix >= 0) and (ClientMode < scContact) and
     
    13171317          CloseAction := None;
    13181318          Close;
    1319           MainScreen.CityClosed(imix[i], false, true);
     1319          MainScreen.CityClosed(imix[I], False, True);
    13201320        end;
    13211321    end
    1322     else if (x >= xmArea - 192) and (x < xmArea + 192) and (y >= ymArea - 96)
    1323       and (y < ymArea + 96) then
     1322    else if (X >= xmArea - 192) and (X < xmArea + 192) and (Y >= ymArea - 96)
     1323      and (Y < ymArea + 96) then
    13241324    with AreaMap do begin
    1325       qx := ((4000 * xxt * yyt) + (x - xmArea) * (yyt * 2) + (y - ymArea + yyt)
     1325      qx := ((4000 * xxt * yyt) + (X - xmArea) * (yyt * 2) + (Y - ymArea + yyt)
    13261326        * (xxt * 2)) div (xxt * yyt * 4) - 1000;
    1327       qy := ((4000 * xxt * yyt) + (y - ymArea + yyt) * (xxt * 2) - (x - xmArea)
     1327      qy := ((4000 * xxt * yyt) + (Y - ymArea + yyt) * (xxt * 2) - (X - xmArea)
    13281328        * (yyt * 2)) div (xxt * yyt * 4) - 1000;
    13291329      dx := qx - qy;
     
    13381338        end
    13391339        else if (ClientMode < scContact) and (cGov <> gAnarchy) and
    1340           (c.Flags and chCaptured = 0) then
     1340          (C.Flags and chCaptured = 0) then
    13411341        begin // toggle exploitation
    1342           assert(not supervising);
    1343           if c.Status and csResourceWeightsMask <> 0 then
     1342          Assert(not Supervising);
     1343          if C.Status and csResourceWeightsMask <> 0 then
    13441344          begin
    13451345            with MessgExDlg do
     
    13551355              MyCity[cix].Status := MyCity[cix].Status and
    13561356                not csResourceWeightsMask; // off
    1357               c.Status := MyCity[cix].Status;
     1357              C.Status := MyCity[cix].Status;
    13581358              SmartUpdateContent;
    13591359            end;
    1360             exit;
     1360            Exit;
    13611361          end;
    13621362          fix := (dy + 3) shl 2 + (dx + 3) shr 1;
    13631363          NewTiles := MyCity[cix].Tiles xor (1 shl fix);
    1364           if Server(sSetCityTiles, me, cix, NewTiles) >= rExecuted then
     1364          if Server(sSetCityTiles, Me, cix, NewTiles) >= rExecuted then
    13651365          begin
    13661366            SmartUpdateContent;
     
    13711371    end
    13721372    else if (ClientMode < scContact) and (cGov <> gAnarchy) and
    1373       (c.Flags and chCaptured = 0) and (x >= xmOpt - 32) and (x < xmOpt + 32)
    1374       and (y >= ymOpt - 32) and (y < ymOpt + 32) then
    1375     begin
    1376       i := sqr(x - xmOpt) + sqr(y - ymOpt); // click radius
    1377       if i <= 32 * 32 then
     1373      (C.Flags and chCaptured = 0) and (X >= xmOpt - 32) and (X < xmOpt + 32)
     1374      and (Y >= ymOpt - 32) and (Y < ymOpt + 32) then
     1375    begin
     1376      I := sqr(X - xmOpt) + sqr(Y - ymOpt); // click radius
     1377      if I <= 32 * 32 then
    13781378      begin
    1379         if i < 16 * 16 then // inner area clicked
    1380           if c.Status and csResourceWeightsMask <> 0 then
    1381             i := (c.Status shr 4 and $0F) mod 5 + 1 // rotate except off
     1379        if I < 16 * 16 then // inner area clicked
     1380          if C.Status and csResourceWeightsMask <> 0 then
     1381            I := (C.Status shr 4 and $0F) mod 5 + 1 // rotate except off
    13821382          else
    1383             i := 3 // rwGrowth
     1383            I := 3 // rwGrowth
    13841384        else
    1385           case trunc(arctan2(x - xmOpt, ymOpt - y) * 180 / pi) of
     1385          case trunc(arctan2(X - xmOpt, ymOpt - Y) * 180 / pi) of
    13861386            - 25 - 52 * 2 .. -26 - 52:
    1387               i := 1;
     1387              I := 1;
    13881388            -25 - 52 .. -26:
    1389               i := 2;
     1389              I := 2;
    13901390            -25 .. 25:
    1391               i := 3;
     1391              I := 3;
    13921392            26 .. 25 + 52:
    1393               i := 4;
     1393              I := 4;
    13941394            26 + 52 .. 25 + 52 * 2:
    1395               i := 5;
     1395              I := 5;
    13961396            180 - 26 .. 180, -180 .. -180 + 26:
    1397               i := 0;
     1397              I := 0;
    13981398          else
    1399             i := -1;
     1399            I := -1;
    14001400          end;
    1401         if i >= 0 then
     1401        if I >= 0 then
    14021402        begin
    1403           ChangeResourceWeights(i);
     1403          ChangeResourceWeights(I);
    14041404          SmartUpdateContent;
    14051405          if WindowMode <> wmModal then
     
    14231423  );
    14241424
    1425   function ProjectType(Project: integer): TProjectType;
     1425  function ProjectType(Project: Integer): TProjectType;
    14261426  begin
    14271427    if Project and cpCompleted <> 0 then
     
    14451445
    14461446var
    1447   NewProject, OldMoney, cix1: integer;
     1447  NewProject, OldMoney, cix1: Integer;
    14481448  pt0, pt1: TProjectType;
    1449   QueryOk: boolean;
    1450 begin
    1451   Assert(not supervising);
     1449  QueryOk: Boolean;
     1450begin
     1451  Assert(not Supervising);
    14521452  ModalSelectDlg.ShowNewContent_CityProject(wmModal, cix);
    1453   if ModalSelectDlg.result <> -1 then
    1454   begin
    1455     if ModalSelectDlg.result and cpType <> 0 then
     1453  if ModalSelectDlg.Result <> -1 then
     1454  begin
     1455    if ModalSelectDlg.Result and cpType <> 0 then
    14561456    begin
    14571457      MyCity[cix].Status := MyCity[cix].Status and not 7 or
    1458         (1 + ModalSelectDlg.result and cpIndex);
    1459       AutoBuild(cix, MyData.ImpOrder[ModalSelectDlg.result and cpIndex]);
     1458        (1 + ModalSelectDlg.Result and cpIndex);
     1459      AutoBuild(cix, MyData.ImpOrder[ModalSelectDlg.Result and cpIndex]);
    14601460    end
    14611461    else
     
    15221522        then
    15231523          NewProject := NewProject or cpDisbandCity;
    1524       Server(sSetCityProject, me, cix, NewProject);
    1525       c.Project := MyCity[cix].Project;
     1524      Server(sSetCityProject, Me, cix, NewProject);
     1525      C.Project := MyCity[cix].Project;
    15261526      if MyRO.Money > OldMoney then
    15271527        Play('CITY_SELLIMP');
     
    15381538procedure TCityDlg.BuyClick(Sender: TObject);
    15391539var
    1540   NextProd, Cost: integer;
     1540  NextProd, Cost: Integer;
    15411541begin
    15421542  if (cix < 0) or (ClientMode >= scContact) then
    1543     exit;
     1543    Exit;
    15441544  with MyCity[cix], MessgExDlg do
    15451545  begin
     
    15491549      NextProd := 0;
    15501550    Cost := Cost - Prod - NextProd;
    1551     if (MyRO.Wonder[woMich].EffectiveOwner = me) and (Project and cpImp <> 0)
     1551    if (MyRO.Wonder[woMich].EffectiveOwner = Me) and (Project and cpImp <> 0)
    15521552    then
    15531553      Cost := Cost * 2
     
    15731573    if (Kind = mkYesNo) and (ModalResult = mrOK) then
    15741574    begin
    1575       if Server(sBuyCityProject, me, cix, nil^) >= rExecuted then
     1575      if Server(sBuyCityProject, Me, cix, nil^) >= rExecuted then
    15761576      begin
    15771577        Play('CITY_BUYPROJECT');
     
    16331633    else if BlinkTime = 6 then
    16341634    begin
    1635       if AllowChange and (c.Status and 7 <> 0) then
     1635      if AllowChange and (C.Status and 7 <> 0) then
    16361636      begin // city type autobuild
    16371637        FrameImage(Canvas, bigimp, xView + 9, yView + 5, xSizeBig, ySizeBig,
    1638           (c.Status and 7 - 1 + 3) * xSizeBig, 0, true);
     1638          (C.Status and 7 - 1 + 3) * xSizeBig, 0, True);
    16391639      end
    1640       else if c.Project and cpImp = 0 then
     1640      else if C.Project and cpImp = 0 then
    16411641      begin // project is unit
    16421642        BitBltCanvas(Canvas, xView + 9, yView + 5, xSizeBig, ySizeBig,
    16431643          Bigimp.Canvas, 0, 0);
    1644         with Tribe[cOwner].ModelPicture[c.Project and cpIndex] do
     1644        with Tribe[cOwner].ModelPicture[C.Project and cpIndex] do
    16451645          Sprite(Canvas, HGr, xView + 5, yView + 1, 64, 44, pix mod 10 * 65 + 1,
    16461646            pix div 10 * 49 + 1);
    16471647      end
    16481648      else
    1649         ImpImage(Canvas, xView + 9, yView + 5, c.Project0 and cpIndex,
    1650           cGov, true);
     1649        ImpImage(Canvas, xView + 9, yView + 5, C.Project0 and cpIndex,
     1650          cGov, True);
    16511651    end;
    16521652  end;
     
    16641664  if 1 shl OpenSoundEvent = chProduction then
    16651665  begin
    1666     if c.Project0 and cpImp <> 0 then
    1667     begin
    1668       if c.Project0 and cpIndex >= 28 then
     1666    if C.Project0 and cpImp <> 0 then
     1667    begin
     1668      if C.Project0 and cpIndex >= 28 then
    16691669      // wonders have already extra message with sound
    1670         if Imp[c.Project0 and cpIndex].Kind = ikShipPart then
     1670        if Imp[C.Project0 and cpIndex].Kind = ikShipPart then
    16711671          Play('SHIP_BUILT')
    16721672        else
     
    16821682end;
    16831683
    1684 function Prio(iix: integer): integer;
     1684function Prio(iix: Integer): Integer;
    16851685begin
    16861686  case Imp[iix].Kind of
    16871687    ikWonder:
    1688       result := iix + 10000;
     1688      Result := iix + 10000;
    16891689    ikNatLocal, ikNatGlobal:
    16901690      case iix of
    16911691        imPalace:
    1692           result := 0;
     1692          Result := 0;
    16931693      else
    1694         result := iix + 20000;
     1694        Result := iix + 20000;
    16951695      end;
    16961696  else
    16971697    case iix of
    16981698      imTownHall, imCourt:
    1699         result := iix + 30000;
     1699        Result := iix + 30000;
    17001700      imAqueduct, imSewer:
    1701         result := iix + 40000;
     1701        Result := iix + 40000;
    17021702      imTemple, imTheater, imCathedral:
    1703         result := iix + 50000;
    1704     else
    1705       result := iix + 90000;
     1703        Result := iix + 50000;
     1704    else
     1705      Result := iix + 90000;
    17061706    end;
    17071707  end;
     
    17181718end;
    17191719
    1720 procedure TCityDlg.ChangeCity(d: integer);
     1720procedure TCityDlg.ChangeCity(D: Integer);
    17211721var
    1722   cixNew: integer;
     1722  cixNew: Integer;
    17231723begin
    17241724  cixNew := cix;
    17251725  repeat
    1726     cixNew := (cixNew + MyRO.nCity + d) mod MyRO.nCity;
     1726    cixNew := (cixNew + MyRO.nCity + D) mod MyRO.nCity;
    17271727  until (MyCity[cixNew].Loc >= 0) or (cixNew = cix);
    17281728  if cixNew <> cix then
     
    17661766end;
    17671767
    1768 procedure TCityDlg.ChangeResourceWeights(iResourceWeights: integer);
     1768procedure TCityDlg.ChangeResourceWeights(iResourceWeights: Integer);
    17691769var
    17701770  Advice: TCityTileAdviceData;
    17711771begin
    1772   assert(not supervising);
    1773   assert(cix >= 0);
     1772  Assert(not Supervising);
     1773  Assert(cix >= 0);
    17741774  MyCity[cix].Status := MyCity[cix].Status and not csResourceWeightsMask or
    17751775    (iResourceWeights shl 4);
    1776   c.Status := MyCity[cix].Status;
     1776  C.Status := MyCity[cix].Status;
    17771777  if iResourceWeights > 0 then
    17781778  begin
    17791779    Advice.ResourceWeights := OfferedResourceWeights[iResourceWeights];
    1780     Server(sGetCityTileAdvice, me, cix, Advice);
     1780    Server(sGetCityTileAdvice, Me, cix, Advice);
    17811781    if Advice.Tiles <> MyCity[cix].Tiles then
    1782       Server(sSetCityTiles, me, cix, Advice.Tiles);
     1782      Server(sSetCityTiles, Me, cix, Advice.Tiles);
    17831783  end;
    17841784end;
     
    17861786procedure SortImprovements;
    17871787var
    1788   i, j, k: integer;
    1789 begin
    1790   for i := 0 to nImp - 1 do
    1791     ImpSorted[i] := i;
    1792   for i := 0 to nImp - 2 do
    1793     for j := i + 1 to nImp - 1 do
    1794       if Prio(ImpSorted[i]) > Prio(ImpSorted[j]) then begin
    1795         k := ImpSorted[i];
    1796         ImpSorted[i] := ImpSorted[j];
    1797         ImpSorted[j] := k;
     1788  I, J, K: Integer;
     1789begin
     1790  for I := 0 to nImp - 1 do
     1791    ImpSorted[I] := I;
     1792  for I := 0 to nImp - 2 do
     1793    for J := I + 1 to nImp - 1 do
     1794      if Prio(ImpSorted[I]) > Prio(ImpSorted[J]) then begin
     1795        K := ImpSorted[I];
     1796        ImpSorted[I] := ImpSorted[J];
     1797        ImpSorted[J] := K;
    17981798      end;
    17991799end;
  • trunk/LocalPlayer/CityType.pas

    r442 r447  
    1818    procedure FormShow(Sender: TObject);
    1919    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    20       Shift: TShiftState; x, y: integer);
     20      Shift: TShiftState; X, Y: Integer);
    2121    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    22       Shift: TShiftState; x, y: integer);
     22      Shift: TShiftState; X, Y: Integer);
    2323    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    2424    procedure DeleteBtnClick(Sender: TObject);
     
    2828    procedure OffscreenPaint; override;
    2929  private
    30     nPool, dragiix, ctype: integer;
    31     Pooliix: array [0 .. nImp - 1] of integer;
     30    nPool, dragiix, ctype: Integer;
     31    Pooliix: array [0 .. nImp - 1] of Integer;
    3232    listed: Set of 0 .. nImp;
    33     Changed: boolean;
    34     procedure LoadType(NewType: integer);
     33    Changed: Boolean;
     34    procedure LoadType(NewType: Integer);
    3535    procedure SaveType;
    3636  end;
     
    8282procedure TCityTypeDlg.OffscreenPaint;
    8383var
    84   i, iix: integer;
    85   s: string;
     84  I, iix: Integer;
     85  S: string;
    8686begin
    8787  inherited;
    88   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     88  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    8989  FillOffscreen(xList - 7, yList, 42 * nListCol + 14, 32 * nListRow);
    9090  FillOffscreen(xPool - 7, yPool, 42 * nPoolCol + 14, 32 * nPoolRow);
     
    9292    yPool - yList - 32 * nListRow);
    9393
    94   Frame(offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,
     94  Frame(Offscreen.Canvas, 0, yList + 32 * nListRow, InnerWidth - 255,
    9595    yPool - 23, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    96   Frame(offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,
     96  Frame(Offscreen.Canvas, InnerWidth - 254, yList + 32 * nListRow,
    9797    InnerWidth - 89, yPool - 23, MainTexture.ColorBevelLight,
    9898    MainTexture.ColorBevelShade);
    99   Frame(offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,
     99  Frame(Offscreen.Canvas, InnerWidth - 88, yList + 32 * nListRow,
    100100    InnerWidth - 1, yPool - 23, MainTexture.ColorBevelLight,
    101101    MainTexture.ColorBevelShade);
    102   Frame(offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,
     102  Frame(Offscreen.Canvas, 0, yPool - 22, InnerWidth - 1, yPool - 1,
    103103    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,
     104  for I := 0 to nCityType - 1 do
     105  begin
     106    RFrame(Offscreen.Canvas, xSwitch + I * 42, ySwitch, xSwitch + 39 + I * 42,
    107107      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,
     108    if I = ctype then
     109      Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1,
     110        xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelShade,
    111111        MainTexture.ColorBevelLight)
    112112    else
    113       Frame(offscreen.Canvas, xSwitch + 1 + i * 42, ySwitch + 1,
    114         xSwitch + 38 + i * 42, ySwitch + 22, MainTexture.ColorBevelLight,
     113      Frame(Offscreen.Canvas, xSwitch + 1 + I * 42, ySwitch + 1,
     114        xSwitch + 38 + I * 42, ySwitch + 22, MainTexture.ColorBevelLight,
    115115        MainTexture.ColorBevelShade);
    116     BitBltCanvas(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,
     116    BitBltCanvas(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,
    120120    Phrases.Lookup('BUILDORDER'));
    121   RisedTextOut(offscreen.Canvas, 8, ySwitch + 26,
     121  RisedTextOut(Offscreen.Canvas, 8, ySwitch + 26,
    122122    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);
     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);
    136136      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,
     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,
    149149      MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    150     BitBltCanvas(offscreen.Canvas, xList + 21 - xSizeSmall div 2 +
    151       i mod nListCol * 42, yList + 16 - ySizeSmall div 2 + i div nListCol * 32,
     150    BitBltCanvas(Offscreen.Canvas, xList + 21 - xSizeSmall div 2 +
     151      I mod nListCol * 42, yList + 16 - ySizeSmall div 2 + I div nListCol * 32,
    152152      xSizeSmall, ySizeSmall, SmallImp.Canvas,
    153       MyData.ImpOrder[ctype, i] mod 7 * xSizeSmall,
    154       (MyData.ImpOrder[ctype, i] + SystemIconLines * 7) div 7 *
     153      MyData.ImpOrder[ctype, I] mod 7 * xSizeSmall,
     154      (MyData.ImpOrder[ctype, I] + SystemIconLines * 7) div 7 *
    155155      ySizeSmall);
    156     inc(i);
     156    Inc(I);
    157157  end;
    158158
     
    165165    begin
    166166      Pooliix[nPool] := iix;
    167       RFrame(offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +
     167      RFrame(Offscreen.Canvas, xPool + 20 - xSizeSmall div 2 +
    168168        nPool mod nPoolCol * 42, yPool + 15 - ySizeSmall div 2 +
    169169        nPool div nPoolCol * 32, xPool + 21 + xSizeSmall div 2 +
     
    171171        nPool div nPoolCol * 32, MainTexture.ColorBevelLight,
    172172        MainTexture.ColorBevelShade);
    173       BitBltCanvas(offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +
     173      BitBltCanvas(Offscreen.Canvas, xPool + 21 - xSizeSmall div 2 +
    174174        nPool mod nPoolCol * 42, yPool + 16 - ySizeSmall div 2 +
    175175        nPool div nPoolCol * 32, xSizeSmall, ySizeSmall, SmallImp.Canvas,
    176176        iix mod 7 * xSizeSmall, (iix + SystemIconLines * 7) div 7 *
    177177        ySizeSmall);
    178       inc(nPool);
     178      Inc(nPool);
    179179    end;
    180180  DeleteBtn.Visible := MyData.ImpOrder[ctype, 0] >= 0;
     
    182182  if dragiix >= 0 then
    183183  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);
     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);
    189189  end;
    190190  MarkUsedOffscreen(InnerWidth, InnerHeight);
    191191end;
    192192
    193 procedure TCityTypeDlg.LoadType(NewType: integer);
    194 var
    195   i: integer;
     193procedure TCityTypeDlg.LoadType(NewType: Integer);
     194var
     195  I: Integer;
    196196begin
    197197  ctype := NewType;
    198198  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;
     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;
    206206end;
    207207
    208208procedure TCityTypeDlg.SaveType;
    209209var
    210   cix: integer;
     210  cix: Integer;
    211211begin
    212212  if Changed then
     
    215215      if (MyCity[cix].Loc >= 0) and (MyCity[cix].Status and 7 = ctype + 1) then
    216216        AutoBuild(cix, MyData.ImpOrder[ctype]);
    217     Changed := false;
     217    Changed := False;
    218218  end;
    219219end;
     
    232232
    233233procedure 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
     234  Shift: TShiftState; X, Y: Integer);
     235var
     236  I: Integer;
     237begin
     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
    246246  begin
    247247    if ssShift in Shift then
    248248      HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp,
    249         MyData.ImpOrder[ctype, i])
     249        MyData.ImpOrder[ctype, I])
    250250    else
    251251    begin
    252       dragiix := MyData.ImpOrder[ctype, i];
     252      dragiix := MyData.ImpOrder[ctype, I];
    253253      Screen.Cursor := crImpDrag;
    254254      SmartUpdateContent;
    255255    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
     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
    263263  begin
    264264    if ssShift in Shift then
    265       HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[i])
     265      HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkImp, Pooliix[I])
    266266    else
    267267    begin
    268       dragiix := Pooliix[i];
     268      dragiix := Pooliix[I];
    269269      Screen.Cursor := crImpDrag;
    270270      SmartUpdateContent;
    271271    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)
     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)
    277277  then
    278278  begin
    279279    SaveType;
    280     LoadType(i);
     280    LoadType(I);
    281281    SmartUpdateContent;
    282282  end;
     
    284284
    285285procedure TCityTypeDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    286   Shift: TShiftState; x, y: integer);
    287 
    288   procedure UnList(iix: integer);
     286  Shift: TShiftState; X, Y: Integer);
     287
     288  procedure UnList(iix: Integer);
    289289  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);
     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);
    298298    Exclude(listed, iix);
    299299  end;
    300300
    301301var
    302   i: integer;
    303 begin
    304   x := x - SideFrame;
    305   y := y - WideFrame;
     302  I: Integer;
     303begin
     304  X := X - SideFrame;
     305  Y := Y - WideFrame;
    306306  if dragiix >= 0 then
    307307  begin
    308     if (x >= xList) and (x < xList + nListCol * 42) and (y >= yList) and
    309       (y < yList + nListRow * 32) then
     308    if (X >= xList) and (X < xList + nListCol * 42) and (Y >= yList) and
     309      (Y < yList + nListRow * 32) then
    310310    begin
    311311      if dragiix in listed then
    312312        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;
     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;
    321321    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
     322    else if (dragiix in listed) and (X >= xPool) and (X < xPool + nPoolCol * 42)
     323      and (Y >= yPool) and (Y < yPool + nPoolRow * 32) then
    324324    begin
    325325      UnList(dragiix);
    326       Changed := true;
     326      Changed := True;
    327327    end;
    328328    dragiix := -1;
     
    340340procedure TCityTypeDlg.DeleteBtnClick(Sender: TObject);
    341341begin
    342   fillchar(MyData.ImpOrder[ctype], sizeof(MyData.ImpOrder[ctype]), Byte(-1));
     342  FillChar(MyData.ImpOrder[ctype], SizeOf(MyData.ImpOrder[ctype]), Byte(-1));
    343343  listed := [];
    344   Changed := true;
     344  Changed := True;
    345345  SmartUpdateContent;
    346346end;
  • trunk/LocalPlayer/ClientTools.pas

    r442 r447  
    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;
     
    318318end;
    319319
    320 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);
     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-}
  • trunk/LocalPlayer/Diagram.pas

    r442 r447  
    1919    procedure ToggleBtnClick(Sender: TObject);
    2020    procedure PlayerClick(Sender: TObject);
    21     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     21    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    2222
    2323  public
    2424    procedure OffscreenPaint; override;
    2525    procedure ShowNewContent_Charts(NewMode: TWindowMode);
    26     procedure ShowNewContent_Ship(NewMode: TWindowMode; p: integer = -1);
     26    procedure ShowNewContent_Ship(NewMode: TWindowMode; P: Integer = -1);
    2727
    2828  private
    2929    Kind: (dkChart, dkShip);
    30     Player, Mode: integer;
     30    Player, Mode: Integer;
    3131  end;
    3232
     
    3434  DiaDlg: TDiaDlg;
    3535
    36 procedure PaintColonyShip(canvas: TCanvas; Player, Left, Width, Top: integer);
     36procedure PaintColonyShip(Canvas: TCanvas; Player, Left, Width, Top: Integer);
    3737
    3838implementation
     
    4545const
    4646  Border = 24;
    47   RoundPixels: array [0 .. nStat - 1] of integer = (0, 0, 0, 5, 5, 5);
     47  RoundPixels: array [0 .. nStat - 1] of Integer = (0, 0, 0, 5, 5, 5);
    4848
    4949  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: TCanvas; Player, Left, Width, Top: integer);
    58 var
    59   i, x, r, nComp, nPow, nHab: integer;
     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
     57procedure PaintColonyShip(Canvas: TCanvas; Player, Left, Width, Top: Integer);
     58var
     59  I, X, R, nComp, nPow, nHab: Integer;
    6060begin
    6161  Canvas.Brush.Color := $000000;
    6262  Canvas.FillRect(Rect(Left, Top, Left + Width, Top + 200));
    6363  Canvas.Brush.Style := bsClear;
    64     ScreenTools.Frame(canvas, Left - 1, Top - 1, Left + Width, Top + 200,
     64    ScreenTools.Frame(Canvas, Left - 1, Top - 1, Left + Width, Top + 200,
    6565      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    66     RFrame(canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1,
     66    RFrame(Canvas, Left - 2, Top - 2, Left + Width + 1, Top + 200 + 1,
    6767      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    6868
    6969    // stars
    7070    DelphiRandSeed := Player * 11111;
    71     for i := 1 to Width - 16 do
     71    for I := 1 to Width - 16 do
    7272    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;
     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;
    7777    end;
    7878
     
    8686    if nHab > 2 then
    8787      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);
     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);
    9494    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);
     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);
    101101    if (nComp < 3) and (nHab >= 1) then
    102       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16,
     102      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32 - 16,
    103103        Top + 100 + 7 + yComp[2], 16, 27, 1, 82);
    104104    if (nComp >= 3) and (nHab < 1) then
    105       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32,
     105      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[2] + 32,
    106106        Top + 100 + 7 + yComp[2], 16, 27, 18, 82);
    107107    if (nComp < 4) and (nHab >= 2) then
    108       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16,
     108      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32 - 16,
    109109        Top + 100 + 46 + yComp[3], 16, 27, 1, 82);
    110110    if (nComp >= 4) and (nHab < 2) then
    111       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32,
     111      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3] + 32,
    112112        Top + 100 + 46 + yComp[3], 16, 27, 18, 82);
    113113    if (nComp <> 6) and (nComp <> 2) and not((nComp = 0) and (nPow < 1)) then
    114       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
     114      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
    115115        Top + 100 + 7 + yComp[nComp], 16, 27, 18, 82);
    116116    if (nComp <> 6) and (nComp <> 3) and not((nComp = 0) and (nPow < 2)) then
    117       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
     117      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[nComp],
    118118        Top + 100 + 46 + yComp[nComp], 16, 27, 18, 82);
    119119    if nComp = 2 then
    120       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[3],
     120      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[3],
    121121        Top + 100 + 7 + yComp[3], 16, 27, 18, 82);
    122122    if nComp = 3 then
    123       Sprite(canvas, HGrSystem2, Left + Width div 2 + xComp[4],
     123      Sprite(Canvas, HGrSystem2, Left + Width div 2 + xComp[4],
    124124        Top + 100 + 7 + yComp[4], 16, 27, 18, 82);
    125125end;
     
    142142procedure TDiaDlg.OffscreenPaint;
    143143var
    144   p, T, max, x, y, y0, Stop, r, RoundRange, LineStep: integer;
    145   s: string;
     144  P, T, Max, X, Y, y0, Stop, R, RoundRange, LineStep: Integer;
     145  S: string;
    146146  List: ^TChart;
    147147
    148   function Round(T: integer): integer;
     148  function Round(T: Integer): Integer;
    149149  var
    150     n, i: integer;
     150    N, I: Integer;
    151151  begin
    152152    if T < RoundRange then
    153       n := T
     153      N := T
    154154    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,
     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,
    166166      MainTexture.ColorTextLight);
    167167    if val0 > 0 then
    168       s := Format(Phrases.Lookup('SHARE'), [val0, val1])
     168      S := Format(Phrases.Lookup('SHARE'), [val0, val1])
    169169    else
    170       s := '0';
    171     RisedTextOut(offscreen.canvas,
    172       x + 170 - BiColorTextWidth(offscreen.canvas, s), y, s);
     170      S := '0';
     171    RisedTextOut(Offscreen.Canvas,
     172      X + 170 - BiColorTextWidth(Offscreen.Canvas, S), Y, S);
    173173  end;
    174174
     
    176176  inherited;
    177177  if Kind = dkChart then
    178     with offscreen.canvas do
     178    with Offscreen.Canvas do
    179179    begin
    180180      Font.Assign(UniFont[ftTiny]);
     
    186186      GetMem(List, 4 * (MyRO.Turn + 2));
    187187      if Mode = stExplore then
    188         max := G.lx * G.ly
     188        Max := G.lx * G.ly
    189189      else
    190190      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
     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
    195195            for T := 0 to MyRO.Turn - 1 do
    196196            begin
    197               r := Round(T);
    198               if r > max then
    199                 max := r;
     197              R := Round(T);
     198              if R > Max then
     199                Max := R;
    200200            end;
    201201      end;
     
    215215      for T := 0 to (MyRO.Turn - 1) div LineStep do
    216216      begin
    217         x := Border + (InnerWidth - 2 * Border) * T *
     217        X := Border + (InnerWidth - 2 * Border) * T *
    218218          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);
     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);
    223223      end;
    224224
    225225      y0 := 0;
    226       if max > 0 then
     226      if Max > 0 then
    227227      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
     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
    231231          begin
    232             Pen.Color := Tribe[p].Color;
     232            Pen.Color := Tribe[P].Color;
    233233            Stop := MyRO.Turn - 1;
    234234            while (Stop > 0) and (List[Stop] = 0) do
    235               dec(Stop);
     235              Dec(Stop);
    236236            for T := 0 to Stop do
    237237            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;
     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;
    242242              if T = 0 then
    243                 MoveTo(x, y)
     243                MoveTo(X, Y)
    244244                // else if Mode=stTerritory then
    245245                // begin LineTo(x,y0); LineTo(x,y) end
    246246              else if RoundPixels[Mode] = 0 then
    247247              begin
    248                 if (y <> y0) or (T = Stop) then
    249                   LineTo(x, y)
     248                if (Y <> y0) or (T = Stop) then
     249                  LineTo(X, Y)
    250250              end
    251251              else
    252                 LineTo(x, y);
    253               y0 := y;
     252                LineTo(X, Y);
     253              y0 := Y;
    254254            end;
    255255          end;
     
    258258    end
    259259  else
    260     with offscreen.canvas do
     260    with Offscreen.Canvas do
    261261    begin
    262262      Font.Assign(UniFont[ftSmall]);
    263263      FillOffscreen(0, 0, InnerWidth, InnerHeight);
    264264
    265       PaintColonyShip(offscreen.canvas, Player, 8, InnerWidth - 16, yArea);
     265      PaintColonyShip(Offscreen.Canvas, Player, 8, InnerWidth - 16, yArea);
    266266
    267267      ShareBar(InnerWidth div 2 - 85, InnerHeight - 62,
     
    277277procedure TDiaDlg.FormPaint(Sender: TObject);
    278278var
    279   s: string;
     279  S: string;
    280280begin
    281281  inherited;
    282   canvas.Font.Assign(UniFont[ftNormal]);
     282  Canvas.Font.Assign(UniFont[ftNormal]);
    283283  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);
     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);
    289289end;
    290290
     
    309309end;
    310310
    311 procedure TDiaDlg.ShowNewContent_Ship(NewMode: TWindowMode; p: integer);
     311procedure TDiaDlg.ShowNewContent_Ship(NewMode: TWindowMode; P: Integer);
    312312begin
    313313  Kind := dkShip;
    314   if p < 0 then
    315   begin
    316     Player := me;
     314  if P < 0 then
     315  begin
     316    Player := Me;
    317317    while MyRO.Ship[Player].Parts[spComp] + MyRO.Ship[Player].Parts[spPow] +
    318318      MyRO.Ship[Player].Parts[spHab] = 0 do
     
    320320  end
    321321  else
    322     Player := p;
     322    Player := P;
    323323  ToggleBtn.ButtonIndex := 28;
    324324  ToggleBtn.Hint := Phrases.Lookup('BTN_SELECT');
     
    329329procedure TDiaDlg.ToggleBtnClick(Sender: TObject);
    330330var
    331   p1: integer;
    332   m: TMenuItem;
     331  p1: Integer;
     332  M: TMenuItem;
    333333begin
    334334  if Kind = dkChart then
     
    345345        MyRO.Ship[p1].Parts[spHab] > 0 then
    346346      begin
    347         m := TMenuItem.Create(Popup);
    348         m.RadioItem := true;
    349         m.Caption := Tribe[p1].TPhrase('SHORTNAME');
    350         m.Tag := p1;
    351         m.OnClick := PlayerClick;
     347        M := TMenuItem.Create(Popup);
     348        M.RadioItem := True;
     349        M.Caption := Tribe[p1].TPhrase('SHORTNAME');
     350        M.Tag := p1;
     351        M.OnClick := PlayerClick;
    352352        if p1 = Player then
    353           m.Checked := true;
    354         Popup.Items.Add(m);
     353          M.Checked := True;
     354        Popup.Items.Add(M);
    355355      end;
    356356    Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
     
    363363end;
    364364
    365 procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: word;
     365procedure TDiaDlg.FormKeyDown(Sender: TObject; var Key: Word;
    366366  Shift: TShiftState);
    367367begin
  • trunk/LocalPlayer/Diplomacy.pas

    r38 r447  
    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
  • trunk/LocalPlayer/Draft.pas

    r442 r447  
    2020    procedure CloseBtnClick(Sender: TObject);
    2121    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    22       Shift: TShiftState; x, y: integer);
     22      Shift: TShiftState; X, Y: Integer);
    2323    procedure OKBtnClick(Sender: TObject);
    2424    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    25       Shift: TShiftState; x, y: integer);
     25      Shift: TShiftState; X, Y: Integer);
    2626  public
    2727    procedure ShowNewContent(NewMode: TWindowMode);
     
    3030  private
    3131    Domain, MaxLines, Lines, Cut, yDomain, yFeature, yWeight, yTotal, yView,
    32       IncCap, DecCap: integer;
    33     code: array [0 .. nFeature - 1] of integer;
     32      IncCap, DecCap: Integer;
     33    Code: array [0 .. nFeature - 1] of Integer;
    3434    Template, Back: TBitmap;
    35     function IsFeatureInList(d, i: integer): boolean;
    36     procedure SetDomain(d: integer);
     35    function IsFeatureInList(D, I: Integer): Boolean;
     36    procedure SetDomain(D: Integer);
    3737  end;
    3838
     
    108108procedure TDraftDlg.OffscreenPaint;
    109109
    110   function DomainAvailable(d: integer): boolean;
    111   begin
    112     result := (upgrade[d, 0].Preq = preNone) or
    113       (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable);
     110  function DomainAvailable(D: Integer): Boolean;
     111  begin
     112    Result := (upgrade[D, 0].Preq = preNone) or
     113      (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable);
    114114  end;
    115115
    116116  procedure PaintTotalBars;
    117117  var
    118     i, y, dx, num, w: integer;
    119     s: string;
    120   begin
    121     with offscreen.Canvas do
     118    I, Y, dx, num, W: Integer;
     119    S: string;
     120  begin
     121    with Offscreen.Canvas do
    122122    begin
    123123      // strength bar
    124       y := yTotal;
    125       DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 2);
    126       DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 2);
    127       RisedTextOut(offscreen.Canvas, xTotal - 2, y,
     124      Y := yTotal;
     125      DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 2);
     126      DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 2);
     127      RisedTextOut(Offscreen.Canvas, xTotal - 2, Y,
    128128        Phrases.Lookup('UNITSTRENGTH'));
    129       RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
     129      RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y,
    130130        'x' + IntToStr(MyRO.DevModel.MStrength));
    131       RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
    132       s := IntToStr(MyRO.DevModel.Attack) + '/' +
     131      RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '=');
     132      S := IntToStr(MyRO.DevModel.Attack) + '/' +
    133133        IntToStr(MyRO.DevModel.Defense);
    134       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
    135         BiColorTextWidth(offscreen.Canvas, s), y, s);
     134      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
     135        BiColorTextWidth(Offscreen.Canvas, S), Y, S);
    136136
    137137      // transport bar
    138138      if MyRO.DevModel.MTrans > 0 then
    139139      begin
    140         y := yTotal + 19;
    141         DarkGradient(offscreen.Canvas, xTotal - 6, y + 1, 184, 1);
    142         DarkGradient(offscreen.Canvas, xTotal2 + 172, y + 1, 95, 1);
    143         RisedTextOut(offscreen.Canvas, xTotal - 2, y,
     140        Y := yTotal + 19;
     141        DarkGradient(Offscreen.Canvas, xTotal - 6, Y + 1, 184, 1);
     142        DarkGradient(Offscreen.Canvas, xTotal2 + 172, Y + 1, 95, 1);
     143        RisedTextOut(Offscreen.Canvas, xTotal - 2, Y,
    144144          Phrases.Lookup('UNITTRANSPORT'));
    145         RisedTextOut(offscreen.Canvas, xTotal + 112 + 30, y,
     145        RisedTextOut(Offscreen.Canvas, xTotal + 112 + 30, Y,
    146146          'x' + IntToStr(MyRO.DevModel.MTrans));
    147         RisedTextOut(offscreen.Canvas, xTotal2 + 148 + 30, y, '=');
     147        RisedTextOut(Offscreen.Canvas, xTotal2 + 148 + 30, Y, '=');
    148148
    149149        Font.Color := $000000;
    150150        dx := -237 - 30;
    151         for i := mcFirstNonCap - 1 downto 3 do
    152           if i in [mcSeaTrans, mcCarrier, mcAirTrans] then
     151        for I := mcFirstNonCap - 1 downto 3 do
     152          if I in [mcSeaTrans, mcCarrier, mcAirTrans] then
    153153          begin
    154             num := MyRO.DevModel.Cap[i] * MyRO.DevModel.MTrans;
     154            num := MyRO.DevModel.Cap[I] * MyRO.DevModel.MTrans;
    155155            if num > 0 then
    156156            begin
    157               inc(dx, 15);
     157              Inc(dx, 15);
    158158              Brush.Color := $C0C0C0;
    159               FrameRect(Rect(xTotal2 - 3 - dx, y + 2,
    160                 xTotal2 + 11 - dx, y + 16));
     159              FrameRect(Rect(xTotal2 - 3 - dx, Y + 2,
     160                xTotal2 + 11 - dx, Y + 16));
    161161              Brush.Style := bsClear;
    162               Sprite(offscreen, HGrSystem, xTotal2 - 1 - dx, y + 4, 10, 10,
    163                 66 + i mod 11 * 11, 137 + i div 11 * 11);
     162              Sprite(Offscreen, HGrSystem, xTotal2 - 1 - dx, Y + 4, 10, 10,
     163                66 + I mod 11 * 11, 137 + I div 11 * 11);
    164164              if num > 1 then
    165165              begin
    166                 s := IntToStr(num);
    167                 w := TextWidth(s);
    168                 inc(dx, w + 1);
     166                S := IntToStr(num);
     167                W := TextWidth(S);
     168                Inc(dx, W + 1);
    169169                Brush.Color := $FFFFFF;
    170                 FillRect(Rect(xTotal2 - 3 - dx, y + 2,
    171                   xTotal2 + w - 1 - dx, y + 16));
     170                FillRect(Rect(xTotal2 - 3 - dx, Y + 2,
     171                  xTotal2 + W - 1 - dx, Y + 16));
    172172                Brush.Style := bsClear;
    173                 Textout(xTotal2 - 3 - dx + 1, y, s);
     173                Textout(xTotal2 - 3 - dx + 1, Y, S);
    174174              end;
    175175            end;
     
    178178
    179179      // speed bar
    180       y := yTotal + 38;
    181       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
     180      Y := yTotal + 38;
     181      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
    182182        Phrases.Lookup('UNITSPEED'));
    183       DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     183      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    184184        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    185       DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     185      DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    186186        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    187       s := MovementToString(MyRO.DevModel.Speed);
    188       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
    189         TextWidth(s), y, s);
     187      S := MovementToString(MyRO.DevModel.Speed);
     188      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 -
     189        TextWidth(S), Y, S);
    190190
    191191      // cost bar
    192       y := yTotal + 57;
    193       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
     192      Y := yTotal + 57;
     193      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
    194194        Phrases.Lookup('UNITCOST'));
    195       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, y,
     195      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal + 112 + 30, Y,
    196196        'x' + IntToStr(MyRO.DevModel.MCost));
    197       LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    198         xTotal2 + 148 + 30, y, '=');
    199       DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     197      LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     198        xTotal2 + 148 + 30, Y, '=');
     199      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    200200        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    201       DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     201      DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    202202        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    203       s := IntToStr(MyRO.DevModel.Cost);
    204       RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
    205         TextWidth(s), y, s);
    206       Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
     203      S := IntToStr(MyRO.DevModel.Cost);
     204      RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
     205        TextWidth(S), Y, S);
     206      Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10,
    207207        10, 88, 115);
    208208
    209       if G.Difficulty[me] <> 2 then
     209      if G.Difficulty[Me] <> 2 then
    210210      begin // corrected cost bar
    211         y := yTotal + 76;
    212         LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, y,
    213           Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[me])));
    214         LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    215           xTotal2 + 148 + 30, y, '=');
    216         DLine(offscreen.Canvas, xTotal - 2, xTotal + 174, y + 16,
     211        Y := yTotal + 76;
     212        LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, Y,
     213          Phrases.Lookup('COSTDIFF' + char(48 + G.Difficulty[Me])));
     214        LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     215          xTotal2 + 148 + 30, Y, '=');
     216        DLine(Offscreen.Canvas, xTotal - 2, xTotal + 174, Y + 16,
    217217          MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    218         DLine(offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, y + 16,
     218        DLine(Offscreen.Canvas, xTotal2 + 176, xTotal2 + 263, Y + 16,
    219219          MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    220         s := IntToStr(MyRO.DevModel.Cost * BuildCostMod
    221           [G.Difficulty[me]] div 12);
    222         RisedTextOut(offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
    223           TextWidth(s), y, s);
    224         Sprite(offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, y + 4, 10,
     220        S := IntToStr(MyRO.DevModel.Cost * BuildCostMod
     221          [G.Difficulty[Me]] div 12);
     222        RisedTextOut(Offscreen.Canvas, xTotal2 + 170 + 64 + 30 - 12 -
     223          TextWidth(S), Y, S);
     224        Sprite(Offscreen, HGrSystem, xTotal2 + 170 + 54 + 30, Y + 4, 10,
    225225          10, 88, 115);
    226226      end;
     
    229229
    230230var
    231   i, j, x, d, n, TextColor, CapWeight, DomainCount: integer;
     231  I, J, X, D, N, TextColor, CapWeight, DomainCount: Integer;
    232232begin
    233233  inherited;
     
    253253    Template.Height - 64 - Cut);
    254254
    255   BitBltCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
     255  BitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
    256256    Back.Canvas, 0, 0);
    257257
    258   offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    259   RisedTextOut(offscreen.Canvas, 10, 7, Caption);
    260   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     258  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
     259  RisedTextOut(Offscreen.Canvas, 10, 7, Caption);
     260  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    261261
    262262  with MyRO.DevModel do
    263263  begin
    264264    DomainCount := 0;
    265     for d := 0 to nDomains - 1 do
    266       if DomainAvailable(d) then
    267         inc(DomainCount);
     265    for D := 0 to nDomains - 1 do
     266      if DomainAvailable(D) then
     267        Inc(DomainCount);
    268268    if DomainCount > 1 then
    269269    begin
    270       for d := 0 to nDomains - 1 do
    271         if DomainAvailable(d) then
     270      for D := 0 to nDomains - 1 do
     271        if DomainAvailable(D) then
    272272        begin
    273           x := xDomain + d * DomainPitch;
    274           if d = Domain then
    275             ImageOp_BCC(offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,
     273          X := xDomain + D * DomainPitch;
     274          if D = Domain then
     275            ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36,
    276276              36, 0, $00C0FF)
    277277          else
    278             ImageOp_BCC(offscreen, Templates.Data, x, yDomain, 142, 246 + 37 * d, 36,
     278            ImageOp_BCC(Offscreen, Templates.Data, X, yDomain, 142, 246 + 37 * D, 36,
    279279              36, 0, $606060);
    280280        end;
    281       Frame(offscreen.Canvas, xDomain - 11, yDomain - 3,
     281      Frame(Offscreen.Canvas, xDomain - 11, yDomain - 3,
    282282        xDomain + 2 * DomainPitch + 46, yDomain + 38, $B0B0B0, $FFFFFF);
    283       RFrame(offscreen.Canvas, xDomain - 12, yDomain - 4,
     283      RFrame(Offscreen.Canvas, xDomain - 12, yDomain - 4,
    284284        xDomain + 2 * DomainPitch + 47, yDomain + 39, $FFFFFF, $B0B0B0);
    285285    end;
     
    294294
    295295    // display weight
    296     with offscreen.Canvas do
    297     begin
    298       for i := 0 to MaxWeight - 1 do
    299         if i < Weight then
    300           ImageOp_BCC(offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),
     296    with Offscreen.Canvas do
     297    begin
     298      for I := 0 to MaxWeight - 1 do
     299        if I < Weight then
     300          ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight),
    301301            WeightOn.BoundsRect, 0, $949494)
    302302        else
    303           ImageOp_BCC(offscreen, Templates.Data, Point(xWeight + 20 * i, yWeight),
     303          ImageOp_BCC(Offscreen, Templates.Data, Point(xWeight + 20 * I, yWeight),
    304304            WeightOff.BoundsRect, 0, $949494);
    305305    end;
    306306
    307     with offscreen.Canvas do
    308       for i := 0 to Lines - 1 do
     307    with Offscreen.Canvas do
     308      for I := 0 to Lines - 1 do
    309309      begin
    310         if not(code[i] in AutoFeature) then
     310        if not(Code[I] in AutoFeature) then
    311311        begin
    312312          // paint +/- butttons
    313           if code[i] < mcFirstNonCap then
     313          if Code[I] < mcFirstNonCap then
    314314          begin
    315             Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
    316               i, 12, 12, 169, 172);
    317             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    318               i, 12, 12, 169, 159);
    319             RFrame(offscreen.Canvas, xFeature - (21 + 1),
    320               yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
    321               yFeature + 2 + LinePitch * i + 12, MainTexture.ColorBevelShade,
     315            Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
     316              I, 12, 12, 169, 172);
     317            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     318              I, 12, 12, 169, 159);
     319            RFrame(Offscreen.Canvas, xFeature - (21 + 1),
     320              yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24),
     321              yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade,
    322322              MainTexture.ColorBevelLight);
    323323          end
    324324          else
    325325          begin
    326             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    327               i, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
    328             RFrame(offscreen.Canvas, xFeature - (9 + 1),
    329               yFeature + 2 + LinePitch * i - 1, xFeature - (21 - 24),
    330               yFeature + 2 + LinePitch * i + 12, MainTexture.ColorBevelShade,
     326            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     327              I, 12, 12, 169, 185 + 13 * MyRO.DevModel.Cap[Code[I]]);
     328            RFrame(Offscreen.Canvas, xFeature - (9 + 1),
     329              yFeature + 2 + LinePitch * I - 1, xFeature - (21 - 24),
     330              yFeature + 2 + LinePitch * I + 12, MainTexture.ColorBevelShade,
    331331              MainTexture.ColorBevelLight);
    332332          end;
    333333
    334334          // paint cost
    335           LightGradient(offscreen.Canvas, xFeature + 34,
    336             yFeature + LinePitch * i, 50, HGrSystem.Data.Canvas.Pixels
     335          LightGradient(Offscreen.Canvas, xFeature + 34,
     336            yFeature + LinePitch * I, 50, HGrSystem.Data.Canvas.Pixels
    337337            [187, 137]);
    338           if (Domain = dGround) and (code[i] = mcDefense) then
     338          if (Domain = dGround) and (Code[I] = mcDefense) then
    339339            CapWeight := 2
    340340          else
    341             CapWeight := Feature[code[i]].Weight;
    342           n := CapWeight + Feature[code[i]].Cost;
    343           d := 6;
    344           while (n - 1) * d * 2 > 48 - 10 do
    345             dec(d);
    346           for j := 0 to n - 1 do
    347             if j < CapWeight then
    348               Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
    349                 yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 126)
     341            CapWeight := Feature[Code[I]].Weight;
     342          N := CapWeight + Feature[Code[I]].Cost;
     343          D := 6;
     344          while (N - 1) * D * 2 > 48 - 10 do
     345            Dec(D);
     346          for J := 0 to N - 1 do
     347            if J < CapWeight then
     348              Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D,
     349                yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 126)
    350350            else
    351               Sprite(offscreen, HGrSystem, xFeature + 54 + (j * 2 + 1 - n) * d,
    352                 yFeature + 2 + LinePitch * i + 1, 10, 10, 88, 115);
     351              Sprite(Offscreen, HGrSystem, xFeature + 54 + (J * 2 + 1 - N) * D,
     352                yFeature + 2 + LinePitch * I + 1, 10, 10, 88, 115);
    353353        end; // if not (code[i] in AutoFeature)
    354         DarkGradient(offscreen.Canvas, xFeature + 17,
    355           yFeature + LinePitch * i, 16, 1);
    356         ScreenTools.Frame(offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * i,
    357           xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * i,
     354        DarkGradient(Offscreen.Canvas, xFeature + 17,
     355          yFeature + LinePitch * I, 16, 1);
     356        ScreenTools.Frame(Offscreen.Canvas, xFeature + 18, yFeature + 1 + LinePitch * I,
     357          xFeature + 20 - 2 + 13, yFeature + 2 + 1 - 2 + 13 + LinePitch * I,
    358358          $C0C0C0, $C0C0C0);
    359         Sprite(offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
    360           * i, 10, 10, 66 + code[i] mod 11 * 11, 137 + code[i] div 11 * 11);
    361 
    362         if MyRO.DevModel.Cap[code[i]] > 0 then
     359        Sprite(Offscreen, HGrSystem, xFeature + 20, yFeature + 2 + 1 + LinePitch
     360          * I, 10, 10, 66 + Code[I] mod 11 * 11, 137 + Code[I] div 11 * 11);
     361
     362        if MyRO.DevModel.Cap[Code[I]] > 0 then
    363363          TextColor := MainTexture.ColorLitText
    364364        else
    365365          TextColor := -1;
    366366
    367         if code[i] < mcFirstNonCap then
    368           LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
    369             yFeature + LinePitch * i - 1, IntToStr(MyRO.DevModel.Cap[code[i]]));
    370         LoweredTextOut(offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
    371           yFeature + LinePitch * i - 1, Phrases.Lookup('FEATURES', code[i]));
     367        if Code[I] < mcFirstNonCap then
     368          LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 7,
     369            yFeature + LinePitch * I - 1, IntToStr(MyRO.DevModel.Cap[Code[I]]));
     370        LoweredTextOut(Offscreen.Canvas, TextColor, MainTexture, xFeature + 88,
     371          yFeature + LinePitch * I - 1, Phrases.Lookup('FEATURES', Code[I]));
    372372      end;
    373373  end;
    374374
    375375  // free features
    376   j := 0;
    377   for i := 0 to nFeature - 1 do
    378     if (i in AutoFeature) and (1 shl Domain and Feature[i].Domains <> 0) and
    379       (Feature[i].Preq <> preNA) and
    380       ((Feature[i].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = me)
    381       or (Feature[i].Preq >= 0) and (MyRO.Tech[Feature[i].Preq] >= tsApplicable)
    382       ) and not((Feature[i].Preq = adSteamEngine) and
     376  J := 0;
     377  for I := 0 to nFeature - 1 do
     378    if (I in AutoFeature) and (1 shl Domain and Feature[I].Domains <> 0) and
     379      (Feature[I].Preq <> preNA) and
     380      ((Feature[I].Preq = preSun) and (MyRO.Wonder[woSun].EffectiveOwner = Me)
     381      or (Feature[I].Preq >= 0) and (MyRO.Tech[Feature[I].Preq] >= tsApplicable)
     382      ) and not((Feature[I].Preq = adSteamEngine) and
    383383      (MyRO.Tech[adNuclearPower] >= tsApplicable)) then
    384384    begin
    385       DarkGradient(offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
    386         * j, 16, 1);
    387       Frame(offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * j,
    388         xWeight + 18, yWeight + 47 + LinePitch * j, $C0C0C0, $C0C0C0);
    389       Sprite(offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * j,
    390         10, 10, 66 + i mod 11 * 11, 137 + i div 11 * 11);
    391       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xWeight + 26,
    392         yWeight + 31 + LinePitch * j, Phrases.Lookup('FEATURES', i));
    393       inc(j);
    394     end;
    395 
    396   with Tribe[me].ModelPicture[MyRO.nModel] do
    397   begin
    398     FrameImage(offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
     385      DarkGradient(Offscreen.Canvas, xWeight + 4, yWeight + 32 + LinePitch
     386        * J, 16, 1);
     387      Frame(Offscreen.Canvas, xWeight + 5, yWeight + 33 + LinePitch * J,
     388        xWeight + 18, yWeight + 47 + LinePitch * J, $C0C0C0, $C0C0C0);
     389      Sprite(Offscreen, HGrSystem, xWeight + 7, yWeight + 36 + LinePitch * J,
     390        10, 10, 66 + I mod 11 * 11, 137 + I div 11 * 11);
     391      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xWeight + 26,
     392        yWeight + 31 + LinePitch * J, Phrases.Lookup('FEATURES', I));
     393      Inc(J);
     394    end;
     395
     396  with Tribe[Me].ModelPicture[MyRO.nModel] do
     397  begin
     398    FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView + 4, xSizeBig,
    399399      ySizeBig, 0, 0);
    400     Sprite(offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
     400    Sprite(Offscreen, HGr, xView, yView, 64, 44, pix mod 10 * 65 + 1,
    401401      pix div 10 * 49 + 1);
    402402  end;
     
    404404end;
    405405
    406 procedure TDraftDlg.SetDomain(d: integer);
    407 
    408   function Prio(fix: integer): integer;
     406procedure TDraftDlg.SetDomain(D: Integer);
     407
     408  function Prio(fix: Integer): Integer;
    409409  var
    410     FeaturePreq: integer;
     410    FeaturePreq: Integer;
    411411  begin
    412412    FeaturePreq := Feature[fix].Preq;
    413     assert(FeaturePreq <> preNA);
     413    Assert(FeaturePreq <> preNA);
    414414    if fix < mcFirstNonCap then
    415       result := 10000 + fix
     415      Result := 10000 + fix
    416416    else if FeaturePreq = preNone then
    417       result := 20000
     417      Result := 20000
    418418    else if FeaturePreq < 0 then
    419       result := 40000
     419      Result := 40000
    420420    else
    421       result := 30000 + AdvValue[FeaturePreq];
     421      Result := 30000 + AdvValue[FeaturePreq];
    422422    if not(fix in AutoFeature) then
    423       inc(result, 90000);
     423      Inc(Result, 90000);
    424424  end;
    425425
    426426var
    427   i, j, x: integer;
    428 begin
    429   Domain := d;
     427  I, J, X: Integer;
     428begin
     429  Domain := D;
    430430  Lines := 0;
    431   for i := 0 to nFeature - 1 do
    432     if IsFeatureInList(Domain, i) then
    433     begin
    434       code[Lines] := i;
    435       inc(Lines);
     431  for I := 0 to nFeature - 1 do
     432    if IsFeatureInList(Domain, I) then
     433    begin
     434      Code[Lines] := I;
     435      Inc(Lines);
    436436    end;
    437437  yFeature := yFeature0 + (MaxLines - Lines) * LinePitch div 2;
    438438
    439439  // sort features
    440   for i := 0 to Lines - 2 do
    441     for j := i + 1 to Lines - 1 do
    442       if Prio(code[i]) > Prio(code[j]) then
     440  for I := 0 to Lines - 2 do
     441    for J := I + 1 to Lines - 1 do
     442      if Prio(Code[I]) > Prio(Code[J]) then
    443443      begin // exchange
    444         x := code[i];
    445         code[i] := code[j];
    446         code[j] := x;
     444        X := Code[I];
     445        Code[I] := Code[J];
     446        Code[J] := X;
    447447      end;
    448448end;
    449449
    450 function TDraftDlg.IsFeatureInList(d, i: integer): boolean;
    451 begin
    452   result := not(i in AutoFeature) and (1 shl d and Feature[i].Domains <> 0) and
    453     (Feature[i].Preq <> preNA) and
    454     ((Feature[i].Preq = preNone) or (Feature[i].Preq = preSun) and
    455     (MyRO.Wonder[woSun].EffectiveOwner = me) or (Feature[i].Preq >= 0) and
    456     (MyRO.Tech[Feature[i].Preq] >= tsApplicable));
     450function TDraftDlg.IsFeatureInList(D, I: Integer): Boolean;
     451begin
     452  Result := not(I in AutoFeature) and (1 shl D and Feature[I].Domains <> 0) and
     453    (Feature[I].Preq <> preNA) and
     454    ((Feature[I].Preq = preNone) or (Feature[I].Preq = preSun) and
     455    (MyRO.Wonder[woSun].EffectiveOwner = Me) or (Feature[I].Preq >= 0) and
     456    (MyRO.Tech[Feature[I].Preq] >= tsApplicable));
    457457end;
    458458
    459459procedure TDraftDlg.FormShow(Sender: TObject);
    460460var
    461   count, d, i: integer;
     461  count, D, I: Integer;
    462462begin
    463463  Domain := dGround;
    464464  while (Domain < dAir) and (upgrade[Domain, 0].Preq <> preNone) and
    465465    (MyRO.Tech[upgrade[Domain, 0].Preq] < tsApplicable) do
    466     inc(Domain);
     466    Inc(Domain);
    467467
    468468  // count max number of features in any domain
    469469  MaxLines := 0;
    470   for d := 0 to nDomains - 1 do
    471     if (upgrade[d, 0].Preq = preNone) or
    472       (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable) then
     470  for D := 0 to nDomains - 1 do
     471    if (upgrade[D, 0].Preq = preNone) or
     472      (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable) then
    473473    begin
    474474      count := 0;
    475       for i := 0 to nFeature - 1 do
    476         if IsFeatureInList(d, i) then
    477           inc(count);
     475      for I := 0 to nFeature - 1 do
     476        if IsFeatureInList(D, I) then
     477          Inc(count);
    478478      if count > MaxLines then
    479479        MaxLines := count;
     
    493493
    494494  SetDomain(Domain);
    495   Server(sCreateDevModel, me, Domain, nil^);
     495  Server(sCreateDevModel, Me, Domain, nil^);
    496496  MyModel[MyRO.nModel] := MyRO.DevModel;
    497   InitMyModel(MyRO.nModel, false);
     497  InitMyModel(MyRO.nModel, False);
    498498  OffscreenPaint;
    499499  IncCap := -1;
     
    507507
    508508procedure TDraftDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    509   Shift: TShiftState; x, y: integer);
     509  Shift: TShiftState; X, Y: Integer);
    510510var
    511   i, d: integer;
     511  I, D: Integer;
    512512begin
    513513  if Button = mbLeft then
    514514  begin
    515     for d := 0 to nDomains - 1 do
    516       if (d <> Domain) and ((upgrade[d, 0].Preq = preNone) or
    517         (MyRO.Tech[upgrade[d, 0].Preq] >= tsApplicable)) and
    518         (x >= xDomain + d * DomainPitch) and
    519         (x < xDomain + d * DomainPitch + 36) and (y >= yDomain) and
    520         (y < yDomain + 36) then
     515    for D := 0 to nDomains - 1 do
     516      if (D <> Domain) and ((upgrade[D, 0].Preq = preNone) or
     517        (MyRO.Tech[upgrade[D, 0].Preq] >= tsApplicable)) and
     518        (X >= xDomain + D * DomainPitch) and
     519        (X < xDomain + D * DomainPitch + 36) and (Y >= yDomain) and
     520        (Y < yDomain + 36) then
    521521      begin
    522         SetDomain(d);
    523         Server(sCreateDevModel, me, Domain, nil^);
     522        SetDomain(D);
     523        Server(sCreateDevModel, Me, Domain, nil^);
    524524        MyModel[MyRO.nModel] := MyRO.DevModel;
    525         InitMyModel(MyRO.nModel, false);
     525        InitMyModel(MyRO.nModel, False);
    526526        SmartUpdateContent;
    527527      end;
    528528
    529     if (y >= yFeature) and (y < yFeature + LinePitch * Lines) then
    530     begin
    531       i := (y - yFeature) div LinePitch;
    532       if (x >= xFeature - 21) and (x < ClientWidth) and (ssShift in Shift) then
    533         HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkFeature, code[i])
    534       else if not(code[i] in AutoFeature) then
     529    if (Y >= yFeature) and (Y < yFeature + LinePitch * Lines) then
     530    begin
     531      I := (Y - yFeature) div LinePitch;
     532      if (X >= xFeature - 21) and (X < ClientWidth) and (ssShift in Shift) then
     533        HelpDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), hkFeature, Code[I])
     534      else if not(Code[I] in AutoFeature) then
    535535      begin
    536         if (code[i] < mcFirstNonCap) and (x >= xFeature - 21) and
    537           (x < xFeature - 21 + 12) then
     536        if (Code[I] < mcFirstNonCap) and (X >= xFeature - 21) and
     537          (X < xFeature - 21 + 12) then
    538538        begin
    539           IncCap := code[i];
    540           Dump(offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
    541             i, 12, 12, 182, 172);
     539          IncCap := Code[I];
     540          Dump(Offscreen, HGrSystem, xFeature - 21, yFeature + 2 + LinePitch *
     541            I, 12, 12, 182, 172);
    542542          SmartInvalidate;
    543543        end
    544         else if (x >= xFeature - 9) and (x < xFeature - 9 + 12) then
     544        else if (X >= xFeature - 9) and (X < xFeature - 9 + 12) then
    545545        begin
    546           DecCap := code[i];
    547           if code[i] < mcFirstNonCap then
    548             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    549               i, 12, 12, 182, 159)
     546          DecCap := Code[I];
     547          if Code[I] < mcFirstNonCap then
     548            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     549              I, 12, 12, 182, 159)
    550550          else
    551             Dump(offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
    552               i, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[code[i]]);
     551            Dump(Offscreen, HGrSystem, xFeature - 9, yFeature + 2 + LinePitch *
     552              I, 12, 12, 182, 185 + 13 * MyRO.DevModel.Cap[Code[I]]);
    553553          SmartInvalidate;
    554554        end;
     
    559559
    560560procedure TDraftDlg.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
    561   Shift: TShiftState; x, y: integer);
     561  Shift: TShiftState; X, Y: Integer);
    562562var
    563   NewValue: integer;
     563  NewValue: Integer;
    564564begin
    565565  if IncCap >= 0 then
    566566  begin
    567567    NewValue := MyRO.DevModel.Cap[IncCap] + 1;
    568     Server(sSetDevModelCap + NewValue shl 4, me, IncCap, nil^);
     568    Server(sSetDevModelCap + NewValue shl 4, Me, IncCap, nil^);
    569569    MyModel[MyRO.nModel] := MyRO.DevModel;
    570     InitMyModel(MyRO.nModel, false);
     570    InitMyModel(MyRO.nModel, False);
    571571    SmartUpdateContent;
    572572    IncCap := -1;
     
    579579      if DecCap >= mcFirstNonCap then
    580580        NewValue := -NewValue;
    581       Server(sSetDevModelCap + NewValue shl 4, me, DecCap, nil^);
     581      Server(sSetDevModelCap + NewValue shl 4, Me, DecCap, nil^);
    582582      MyModel[MyRO.nModel] := MyRO.DevModel;
    583       InitMyModel(MyRO.nModel, false);
     583      InitMyModel(MyRO.nModel, False);
    584584    end;
    585585    SmartUpdateContent;
  • trunk/LocalPlayer/Enhance.pas

    r442 r447  
    3737    NoMap: TIsoMap;
    3838  public
    39     procedure ShowNewContent(NewMode: TWindowMode; TerrType: integer = -1);
     39    procedure ShowNewContent(NewMode: TWindowMode; TerrType: Integer = -1);
    4040  protected
    41     Page: integer;
     41    Page: Integer;
    4242    procedure OffscreenPaint; override;
    4343  end;
     
    5656procedure TEnhanceDlg.FormCreate(Sender: TObject);
    5757var
    58   TerrType: integer;
    59   m: TMenuItem;
     58  TerrType: Integer;
     59  M: TMenuItem;
    6060begin
    6161  inherited;
     
    7171    if TerrType <> fJungle then
    7272    begin
    73       m := TMenuItem.Create(Popup);
    74       m.RadioItem := true;
     73      M := TMenuItem.Create(Popup);
     74      M.RadioItem := True;
    7575      if TerrType = fGrass then
    76         m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
     76        M.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
    7777          [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN',
    7878          fGrass + 12)])
    7979      else if TerrType = fForest then
    80         m.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
     80        M.Caption := Format(Phrases.Lookup('TWOTERRAINS'),
    8181          [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN',
    8282          fJungle)])
    8383      else
    84         m.Caption := Phrases.Lookup('TERRAIN', TerrType);
    85       m.Tag := TerrType;
    86       m.OnClick := TerrClick;
    87       Popup.Items.Add(m);
     84        M.Caption := Phrases.Lookup('TERRAIN', TerrType);
     85      M.Tag := TerrType;
     86      M.OnClick := TerrClick;
     87      Popup.Items.Add(M);
    8888    end;
    8989end;
     
    9696procedure TEnhanceDlg.FormPaint(Sender: TObject);
    9797var
    98   i: integer;
     98  I: Integer;
    9999begin
    100100  inherited;
     
    103103  BtnFrame(Canvas, Rect(job3.Left, job3.Top, job9.Left + job9.Width,
    104104    job3.Top + job3.Height), MainTexture);
    105   for i := 0 to ControlCount - 1 do
    106     if Controls[i] is TButtonC then
    107       BitBltCanvas(Canvas, Controls[i].Left + 2, Controls[i].Top - 11, 8, 8,
    108         HGrSystem.Data.Canvas, 121 + Controls[i].Tag mod 7 * 9,
    109         1 + Controls[i].Tag div 7 * 9);
     105  for I := 0 to ControlCount - 1 do
     106    if Controls[I] is TButtonC then
     107      BitBltCanvas(Canvas, Controls[I].Left + 2, Controls[I].Top - 11, 8, 8,
     108        HGrSystem.Data.Canvas, 121 + Controls[I].Tag mod 7 * 9,
     109        1 + Controls[I].Tag div 7 * 9);
    110110end;
    111111
     
    115115end;
    116116
    117 procedure TEnhanceDlg.ShowNewContent(NewMode: TWindowMode; TerrType: integer);
     117procedure TEnhanceDlg.ShowNewContent(NewMode: TWindowMode; TerrType: Integer);
    118118begin
    119119  if (TerrType < fGrass) or (TerrType > fMountains) then
     
    126126procedure TEnhanceDlg.OffscreenPaint;
    127127var
    128   i, stage, TerrType, TileImp, x, EndStage, Cost, LastJob: integer;
    129   s: string;
     128  I, stage, TerrType, TileImp, X, EndStage, Cost, LastJob: Integer;
     129  S: string;
    130130  Done: Set of jNone .. jTrans;
    131   TypeChanged: boolean;
     131  TypeChanged: Boolean;
    132132begin
    133133  OffscreenUser := self;
    134   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     134  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    135135  FillOffscreen(0, 0, InnerWidth, InnerHeight);
    136136
    137137  EndStage := 0;
    138138  while (EndStage < 5) and (MyData.EnhancementJobs[Page, EndStage] <> jNone) do
    139     inc(EndStage);
     139    Inc(EndStage);
    140140  with NoMap do
    141     x := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
     141    X := InnerWidth div 2 - xxt - (xxt + 3) * EndStage;
    142142
    143143  TerrType := Page;
     
    149149    if stage > 0 then
    150150    begin
    151       Sprite(offscreen, HGrSystem, x - 10, 66, 14, 14, 80, 1);
     151      Sprite(Offscreen, HGrSystem, X - 10, 66, 14, 14, 80, 1);
    152152      case MyData.EnhancementJobs[Page, stage - 1] of
    153153        jRoad:
    154154          begin
    155             inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
     155            Inc(Cost, Terrain[TerrType].MoveCost * RoadWork);
    156156            TileImp := TileImp or fRoad;
    157157          end;
    158158        jRR:
    159159          begin
    160             inc(Cost, Terrain[TerrType].MoveCost * RRWork);
     160            Inc(Cost, Terrain[TerrType].MoveCost * RRWork);
    161161            TileImp := TileImp or fRR;
    162162          end;
    163163        jIrr:
    164164          begin
    165             inc(Cost, Terrain[TerrType].IrrClearWork);
     165            Inc(Cost, Terrain[TerrType].IrrClearWork);
    166166            TileImp := TileImp and not fTerImp or tiIrrigation;
    167167          end;
    168168        jFarm:
    169169          begin
    170             inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
     170            Inc(Cost, Terrain[TerrType].IrrClearWork * FarmWork);
    171171            TileImp := TileImp and not fTerImp or tiFarm;
    172172          end;
    173173        jMine:
    174174          begin
    175             inc(Cost, Terrain[TerrType].MineAfforestWork);
     175            Inc(Cost, Terrain[TerrType].MineAfforestWork);
    176176            TileImp := TileImp and not fTerImp or tiMine;
    177177          end;
    178178        jClear:
    179179          begin
    180             inc(Cost, Terrain[TerrType].IrrClearWork);
     180            Inc(Cost, Terrain[TerrType].IrrClearWork);
    181181            TerrType := Terrain[TerrType].ClearTerrain;
    182182          end;
    183183        jAfforest:
    184184          begin
    185             inc(Cost, Terrain[TerrType].MineAfforestWork);
     185            Inc(Cost, Terrain[TerrType].MineAfforestWork);
    186186            TerrType := Terrain[TerrType].AfforestTerrain;
    187187          end;
    188188        jTrans:
    189189          begin
    190             inc(Cost, Terrain[TerrType].TransWork);
     190            Inc(Cost, Terrain[TerrType].TransWork);
    191191            TerrType := Terrain[TerrType].TransTerrain;
    192192          end;
    193193      end;
    194       include(Done, MyData.EnhancementJobs[Page, stage - 1]);
     194      Include(Done, MyData.EnhancementJobs[Page, stage - 1]);
    195195    end;
    196196
    197197    with NoMap do begin
    198198      if TerrType < fForest then
    199         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     199        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    200200          1 + TerrType * (xxt * 2 + 1), 1 + yyt)
    201201      else
    202202      begin
    203         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     203        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    204204          1 + 2 * (xxt * 2 + 1), 1 + yyt + 2 * (yyt * 3 + 1));
    205         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     205        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    206206          1 + 7 * (xxt * 2 + 1), 1 + yyt + 2 * (2 + TerrType - fForest) *
    207207          (yyt * 3 + 1));
    208208      end;
    209209      if TileImp and fTerImp = tiFarm then
    210         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     210        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    211211          1 + (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1))
    212212      else if TileImp and fTerImp = tiIrrigation then
    213         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2, 1,
     213        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2, 1,
    214214          1 + yyt + 12 * (yyt * 3 + 1));
    215215      if TileImp and fRR <> 0 then
    216216      begin
    217         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     217        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    218218          1 + 6 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
    219         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     219        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    220220          1 + 2 * (xxt * 2 + 1), 1 + yyt + 10 * (yyt * 3 + 1));
    221221      end
    222222      else if TileImp and fRoad <> 0 then
    223223      begin
    224         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     224        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    225225          1 + 6 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
    226         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     226        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    227227          1 + 2 * (xxt * 2 + 1), 1 + yyt + 9 * (yyt * 3 + 1));
    228228      end;
    229229      if TileImp and fTerImp = tiMine then
    230         Sprite(offscreen, HGrTerrain, x, 64 - yyt, xxt * 2, yyt * 2,
     230        Sprite(Offscreen, HGrTerrain, X, 64 - yyt, xxt * 2, yyt * 2,
    231231          1 + 2 * (xxt * 2 + 1), 1 + yyt + 12 * (yyt * 3 + 1));
    232       inc(x, xxt * 2 + 6);
    233     end;
    234   end;
    235 
    236   for i := 0 to Popup.Items.Count - 1 do
    237     if Popup.Items[i].Tag = Page then
    238       s := Popup.Items[i].Caption;
     232      Inc(X, xxt * 2 + 6);
     233    end;
     234  end;
     235
     236  for I := 0 to Popup.Items.Count - 1 do
     237    if Popup.Items[I].Tag = Page then
     238      S := Popup.Items[I].Caption;
    239239  if Cost > 0 then
    240     s := Format(Phrases.Lookup('ENHANCE'), [s, MovementToString(Cost)]);
    241   LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    242     (InnerWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 12, s);
     240    S := Format(Phrases.Lookup('ENHANCE'), [S, MovementToString(Cost)]);
     241  LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     242    (InnerWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 12, S);
    243243
    244244  if EndStage > 0 then
     
    289289    (Terrain[TerrType].MineEff > 0);
    290290  job3.Visible := not TypeChanged and (Terrain[TerrType].ClearTerrain >= 0) and
    291     ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = me)) or
     291    ((TerrType <> fDesert) or (MyRO.Wonder[woGardens].EffectiveOwner = Me)) or
    292292    (LastJob = jClear);
    293293  job6.Visible := not TypeChanged and (Terrain[TerrType].AfforestTerrain >= 0)
     
    306306procedure TEnhanceDlg.ToggleBtnClick(Sender: TObject);
    307307var
    308   i: integer;
    309 begin
    310   for i := 0 to Popup.Items.Count - 1 do
    311     Popup.Items[i].Checked := Popup.Items[i].Tag = Page;
     308  I: Integer;
     309begin
     310  for I := 0 to Popup.Items.Count - 1 do
     311    Popup.Items[I].Checked := Popup.Items[I].Tag = Page;
    312312  Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top + ToggleBtn.Height);
    313313end;
     
    321321procedure TEnhanceDlg.JobClick(Sender: TObject);
    322322var
    323   stage, NewJob: integer;
     323  stage, NewJob: Integer;
    324324  Done: Set of jNone .. jTrans;
    325325
    326   procedure RemoveJob(j: integer);
     326  procedure RemoveJob(J: Integer);
    327327  begin // remove job
    328328    stage := 0;
    329329    while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
    330330    begin
    331       if (MyData.EnhancementJobs[Page, stage] = j) or (j = jRoad) and
    332         (MyData.EnhancementJobs[Page, stage] = jRR) or (j = jIrr) and
     331      if (MyData.EnhancementJobs[Page, stage] = J) or (J = jRoad) and
     332        (MyData.EnhancementJobs[Page, stage] = jRR) or (J = jIrr) and
    333333        (MyData.EnhancementJobs[Page, stage] = jFarm) then
    334334      begin
    335335        if stage < 4 then
    336           move(MyData.EnhancementJobs[Page, stage + 1],
     336          Move(MyData.EnhancementJobs[Page, stage + 1],
    337337            MyData.EnhancementJobs[Page, stage], 4 - stage);
    338338        MyData.EnhancementJobs[Page, 4] := jNone;
    339339      end
    340340      else
    341         inc(stage);
     341        Inc(stage);
    342342    end;
    343343  end;
     
    349349  while (stage < 5) and (MyData.EnhancementJobs[Page, stage] <> jNone) do
    350350  begin
    351     include(Done, MyData.EnhancementJobs[Page, stage]);
    352     inc(stage);
     351    Include(Done, MyData.EnhancementJobs[Page, stage]);
     352    Inc(stage);
    353353  end;
    354354  if NewJob in Done then
     
    363363    begin
    364364      MyData.EnhancementJobs[Page, stage] := jRoad;
    365       inc(stage);
     365      Inc(stage);
    366366    end;
    367367    if (NewJob = jFarm) and not(jIrr in Done) then
    368368    begin
    369369      MyData.EnhancementJobs[Page, stage] := jIrr;
    370       inc(stage);
     370      Inc(stage);
    371371    end;
    372372    MyData.EnhancementJobs[Page, stage] := NewJob;
  • trunk/LocalPlayer/Help.pas

    r431 r447  
    4141  THyperText = class(TStringList)
    4242  public
    43     procedure AddLine(s: String = ''; Format: integer = 0; Picpix: Integer = 0;
    44       LinkCategory: integer = 0; LinkIndex: integer = 0);
     43    procedure AddLine(S: String = ''; Format: Integer = 0; Picpix: Integer = 0;
     44      LinkCategory: Integer = 0; LinkIndex: Integer = 0);
    4545    procedure LineFeed;
    4646    procedure AppendList(Source: THyperText);
     
    7878    procedure CloseBtnClick(Sender: TObject);
    7979    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    80       x, y: integer);
     80      X, Y: Integer);
    8181    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    82       Shift: TShiftState; x, y: integer);
     82      Shift: TShiftState; X, Y: Integer);
    8383    procedure BackBtnClick(Sender: TObject);
    8484    procedure TopBtnClick(Sender: TObject);
     
    104104    NoMap: TIsoMap;
    105105    x0: array [-2..180] of Integer;
    106     procedure PaintTerrIcon(x, y, xSrc, ySrc: Integer);
     106    procedure PaintTerrIcon(X, Y, xSrc, ySrc: Integer);
    107107    procedure ScrollBarUpdate(Sender: TObject);
    108     procedure Line(ca: TCanvas; i: Integer; lit: Boolean);
     108    procedure Line(ca: TCanvas; I: Integer; lit: Boolean);
    109109    procedure Prepare(sbPos: Integer = 0);
    110110    procedure ShowNewContentProcExecute(NewMode: TWindowMode; HelpContext: string);
     
    176176end;
    177177
    178 procedure THyperText.AddLine(s: String; Format: integer; Picpix: integer;
    179   LinkCategory: integer; LinkIndex: integer);
     178procedure THyperText.AddLine(S: String; Format: Integer; Picpix: Integer;
     179  LinkCategory: Integer; LinkIndex: Integer);
    180180var
    181181  HelpLineInfo: THelpLineInfo;
     
    187187  HelpLineInfo.Picpix := Picpix;
    188188  HelpLineInfo.Link := LinkCategory shl 8 + LinkIndex;
    189   AddObject(s, TObject(HelpLineInfo));
     189  AddObject(S, TObject(HelpLineInfo));
    190190end;
    191191
     
    263263
    264264  nTerrainHelp = 14;
    265   TerrainHelp: array [0 .. nTerrainHelp - 1] of integer = (fGrass, fGrass + 12,
     265  TerrainHelp: array [0 .. nTerrainHelp - 1] of Integer = (fGrass, fGrass + 12,
    266266    fPrairie, fForest, fJungle, fHills, fMountains, fSwamp, fTundra, fArctic,
    267267    fDesert, 3 * 12 { DeadLands } , fShore, fOcean);
    268268
    269269  nJobHelp = 8;
    270   JobHelp: array [0 .. nJobHelp - 1] of integer = (jRoad, jRR, jCanal, jIrr,
     270  JobHelp: array [0 .. nJobHelp - 1] of Integer = (jRoad, jRR, jCanal, jIrr,
    271271    jFarm, jMine, jFort, jBase);
    272272
     
    280280  CaptionLeft := BackBtn.Left + BackBtn.Width;
    281281  CaptionRight := SearchBtn.Left;
    282   inc(ModalFrameIndent, 29);
     282  Inc(ModalFrameIndent, 29);
    283283  MainText := THyperText.Create;
    284284  MainText.OwnsObjects := True;
     
    356356  if ScrollBar.Process(Msg) then begin
    357357    Sel := -1;
    358     SmartUpdateContent(true)
     358    SmartUpdateContent(True)
    359359  end;
    360360  }
     
    364364begin
    365365  if Sel <> -1 then begin
    366     Line(Canvas, Sel, false);
     366    Line(Canvas, Sel, False);
    367367    Sel := -1
    368368  end;
     
    380380end;
    381381
    382 procedure THelpDlg.Line(ca: TCanvas; i: Integer; lit: Boolean);
     382procedure THelpDlg.Line(ca: TCanvas; I: Integer; lit: Boolean);
    383383var
    384   TextColor, x, y: Integer;
     384  TextColor, X, Y: Integer;
    385385  TextSize: TSize;
    386   s: string;
    387 begin
    388   s := MainText[ScrollBar.Position + i];
    389   if s = '' then
     386  S: string;
     387begin
     388  S := MainText[ScrollBar.Position + I];
     389  if S = '' then
    390390    Exit;
    391   x := x0[i];
    392   y := 2 + i * 24;
     391  X := x0[I];
     392  Y := 2 + I * 24;
    393393  if ca = Canvas then
    394394  begin
    395     x := x + SideFrame;
    396     y := y + WideFrame
    397   end;
    398   if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format
     395    X := X + SideFrame;
     396    Y := Y + WideFrame
     397  end;
     398  if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format
    399399    in [pkCaption, pkBigTer, pkRightIcon, pkBigFeature] then
    400400  begin
    401401    ca.Font.Assign(CaptionFont);
    402402    { 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));
     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));
    406406      ca.Brush.Style:=bsClear; }
    407     BitBltCanvas(ca, x, y - 4, 24, 24, HGrSystem.Data.Canvas, 1,
     407    BitBltCanvas(ca, X, Y - 4, 24, 24, HGrSystem.Data.Canvas, 1,
    408408      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));
     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));
    412412    ca.Font.Assign(UniFont[ftNormal]);
    413413  end
    414   else if THelpLineInfo(MainText.Objects[ScrollBar.Position + i]).Format = pkSection
     414  else if THelpLineInfo(MainText.Objects[ScrollBar.Position + I]).Format = pkSection
    415415  then
    416416  begin
    417417    ca.Font.Assign(CaptionFont);
    418     BiColorTextOut(ca, CaptionColor, $7F007F, x, y - 3, s);
     418    BiColorTextOut(ca, CaptionColor, $7F007F, X, Y - 3, S);
    419419    ca.Font.Assign(UniFont[ftNormal]);
    420420  end
     
    426426    if ca = Canvas then
    427427    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,
     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,
    433433        ScrollBar.Position * 24 - WideFrame, Paper);
    434434    end;
    435     BiColorTextOut(ca, TextColor, $7F007F, x, y, s);
     435    BiColorTextOut(ca, TextColor, $7F007F, X, Y, S);
    436436    if lit then
    437437      with ca do
     
    439439        Assert(ca = Canvas);
    440440        Pen.Color := TextColor;
    441         MoveTo(x + 1, y + TextSize.cy - 2);
    442         LineTo(x + TextSize.cx, y + TextSize.cy - 2);
     441        MoveTo(X + 1, Y + TextSize.cy - 2);
     442        LineTo(X + TextSize.cx, Y + TextSize.cy - 2);
    443443      end;
    444444    if (Kind = hkMisc) and (no = miscMain) then
     
    447447end;
    448448
    449 procedure THelpDlg.WaterSign(x0, y0, iix: integer);
     449procedure THelpDlg.WaterSign(x0, y0, iix: Integer);
    450450const
    451451  nHeaven = 28;
    452452  MaxSum = 9 * 9 * 255 * 75 div 100;
    453453var
    454   x, y, dx, dy, xSrc, ySrc, Sum, xx: integer;
    455   Heaven: array [0..nHeaven] of integer;
     454  X, Y, dx, dy, xSrc, ySrc, Sum, xx: Integer;
     455  Heaven: array [0..nHeaven] of Integer;
    456456  PaintPtr: TPixelPointer;
    457457  CoalPtr: TPixelPointer;
     
    471471  for dy := -1 to 1 do
    472472    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
     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
    475475      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
     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
    479479        Sum := 0;
    480480        for dx := -1 to 1 do begin
    481           xx := Max((x + ScaleToNative(dx)), 0) shr 1;
     481          xx := Max((X + ScaleToNative(dx)), 0) shr 1;
    482482          for dy := -1 to 1 do begin
    483483            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
     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
    487487              (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
     488              ImpPtr[dy].Pixel^.R = Heaven[(ScaleFromNative(Y + ScaleToNative(dy))) shr 1]) then
    489489              Sum := Sum + 9 * 255
    490490            else
     
    510510end;
    511511
    512 procedure THelpDlg.PaintTerrIcon(x, y, xSrc, ySrc: integer);
     512procedure THelpDlg.PaintTerrIcon(X, Y, xSrc, ySrc: Integer);
    513513begin
    514514  with NoMap do begin
    515     Frame(OffScreen.Canvas, x - 1, y - 1, x + xSizeBig, y + ySizeBig,
     515    Frame(OffScreen.Canvas, X - 1, Y - 1, X + xSizeBig, Y + ySizeBig,
    516516      $000000, $000000);
    517517    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,
     518      Sprite(OffScreen, HGrTerrain, X, Y, 56, 2 * yyt, xSrc, ySrc);
     519      Sprite(OffScreen, HGrTerrain, X, Y + 2 * yyt, 56, 40 - 2 * yyt,
    520520        xSrc, ySrc);
    521521    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,
     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,
    527527      xSrc, ySrc);
    528528  end;
     
    531531procedure THelpDlg.OffscreenPaint;
    532532var
    533   i, j, yl, srcno, ofs, cnt, y: Integer;
    534   s: string;
     533  I, J, yl, srcno, ofs, cnt, Y: Integer;
     534  S: string;
    535535  HelpLineInfo: THelpLineInfo;
    536536begin
     
    542542  begin
    543543    Font.Assign(UniFont[ftNormal]);
    544     for i := -ScrollBar.Position to InnerHeight div 24 do
    545       if ScrollBar.Position + i < MainText.Count then
     544    for I := -ScrollBar.Position to InnerHeight div 24 do
     545      if ScrollBar.Position + I < MainText.Count then
    546546      begin
    547         HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);
     547        HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]);
    548548        if HelpLineInfo.Format = pkExternal then
    549549        begin
    550550          yl := ExtPic.Height;
    551           if 4 + i * 24 + yl > InnerHeight then
    552             yl := InnerHeight - (4 + i * 24);
    553           BitBltCanvas(OffScreen.Canvas, 8, 4 + i * 24, ExtPic.Width, yl, ExtPic.Canvas,
     551          if 4 + I * 24 + yl > InnerHeight then
     552            yl := InnerHeight - (4 + I * 24);
     553          BitBltCanvas(OffScreen.Canvas, 8, 4 + I * 24, ExtPic.Width, yl, ExtPic.Canvas,
    554554            0, 0);
    555555        end;
    556556      end;
    557     for i := -2 to InnerHeight div 24 do
    558       if (ScrollBar.Position + i >= 0) and (ScrollBar.Position + i < MainText.Count) then
     557    for I := -2 to InnerHeight div 24 do
     558      if (ScrollBar.Position + I >= 0) and (ScrollBar.Position + I < MainText.Count) then
    559559      begin
    560         HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + i]);
     560        HelpLineInfo := THelpLineInfo(MainText.Objects[ScrollBar.Position + I]);
    561561        if HelpLineInfo.Link <> 0 then
    562562        begin
    563563          if (Kind = hkMisc) and (no = miscSearchResult) then
    564             Sprite(OffScreen, HGrSystem, 18, 9 + i * 24, 8, 8, 90, 16)
     564            Sprite(OffScreen, HGrSystem, 18, 9 + I * 24, 8, 8, 90, 16)
    565565          else if HelpLineInfo.Format in [pkSmallIcon_AsPreq, pkAdvIcon_AsPreq]
    566566          then
    567             Sprite(OffScreen, HGrSystem, 12, i * 24 + 5, 14, 14, 65, 20)
     567            Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 65, 20)
    568568          else if HelpLineInfo.Link and (hkCrossLink shl 8) <> 0 then
    569             Sprite(OffScreen, HGrSystem, 12, i * 24 + 5, 14, 14, 80, 1)
     569            Sprite(OffScreen, HGrSystem, 12, I * 24 + 5, 14, 14, 80, 1)
    570570          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;
     571            Sprite(OffScreen, HGrSystem, 10, I * 24 + 6, 14, 14, 65, 1);
     572          x0[I] := 24;
    573573        end
    574574        else
    575           x0[i] := 0;
     575          x0[I] := 0;
    576576        case HelpLineInfo.Format of
    577577          pkLogo:
    578578            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,
     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,
    583583                HGrSystem.Data.Canvas.Pixels[95, 1], $000000);
    584584              Font.Assign(UniFont[ftSmall]);
    585585              BiColorTextOut(OffScreen.Canvas, $000000, $7F007F,
    586                 (InnerWidth - Textwidth(s)) div 2, i * 24 + 26, s);
     586                (InnerWidth - Textwidth(S)) div 2, I * 24 + 26, S);
    587587              Font.Assign(UniFont[ftNormal]);
    588588            end;
    589589          pkSmallIcon, pkSmallIcon_AsPreq:
    590590            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);
     591              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     592                8 + xSizeSmall + x0[I], 2 + 20 + I * 24, $000000, $000000);
    593593              if HelpLineInfo.Picpix = imPalace then
    594                 BitBltCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     594                BitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    595595                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    596596                  0 * xSizeSmall, 1 * ySizeSmall)
    597597              else
    598                 BitBltCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     598                BitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    599599                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    600600                  HelpLineInfo.Picpix mod 7 * xSizeSmall,
    601601                  (HelpLineInfo.Picpix + SystemIconLines * 7) div 7 *
    602602                  ySizeSmall);
    603               x0[i] := x0[i] + (8 + 8 + 36);
     603              x0[I] := x0[I] + (8 + 8 + 36);
    604604            end;
    605605          pkBigIcon:
    606606            begin
    607               FrameImage(OffScreen.Canvas, BigImp, x0[i] + 12, i * 24 - 7, 56,
     607              FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7, 56,
    608608                40, HelpLineInfo.Picpix mod 7 * xSizeBig,
    609609                HelpLineInfo.Picpix div 7 * ySizeBig);
    610               x0[i] := 64 + 8 + 8 + x0[i];
     610              x0[I] := 64 + 8 + 8 + x0[I];
    611611            end;
    612612          pkSpecialIcon:
     
    615615                0:
    616616                  FrameImage(OffScreen.Canvas, HGrSystem2.Data,
    617                     12 + x0[i], -7 + i * 24, 56, 40, 137, 127);
     617                    12 + x0[I], -7 + I * 24, 56, 40, 137, 127);
    618618                1:
    619619                  with NoMap do begin
    620                     PaintTerrIcon(12 + x0[i], -7 + i * 24,
     620                    PaintTerrIcon(12 + x0[I], -7 + I * 24,
    621621                      1 + 3 * (xxt * 2 + 1), 1 + yyt);
    622622                    if 2 * yyt < 40 then
    623                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     623                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    624624                        56, 2 * yyt, 1 + 3 * (xxt * 2 + 1) + xxt - 28,
    625625                        1 + yyt + 1 * (yyt * 3 + 1))
    626626                    else
    627                       Sprite(OffScreen, HGrTerrain, 12 + x0[i],
    628                         -7 + 4 + i * 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt
     627                      Sprite(OffScreen, HGrTerrain, 12 + x0[I],
     628                        -7 + 4 + I * 24 - 4, 56, 40, 1 + 3 * (xxt * 2 + 1) + xxt
    629629                        - 28, 1 + yyt + 1 * (yyt * 3 + 1) + yyt - 20);
    630630                  end;
    631631                2:
    632632                  with NoMap do begin
    633                     PaintTerrIcon(12 + x0[i], -7 + i * 24,
     633                    PaintTerrIcon(12 + x0[I], -7 + I * 24,
    634634                      1 + 7 * (xxt * 2 + 1), 1 + yyt + 4 * (yyt * 3 + 1));
    635635                    if 2 * yyt < 40 then
    636                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     636                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    637637                        56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28,
    638638                        1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16)
    639639                    else
    640                       Sprite(OffScreen, HGrTerrain, 12 + x0[i], -7 + 4 + i * 24,
     640                      Sprite(OffScreen, HGrTerrain, 12 + x0[I], -7 + 4 + I * 24,
    641641                        56, 32, 1 + 4 * (xxt * 2 + 1) + xxt - 28,
    642642                        1 + yyt + 12 * (yyt * 3 + 1) + yyt - 16)
    643643                  end;
    644644              end;
    645               x0[i] := 64 + 8 + 8 + x0[i];
     645              x0[I] := 64 + 8 + 8 + x0[I];
    646646            end;
    647647          pkDomain:
    648648            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,
     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,
    652652                75 + HelpLineInfo.Picpix * 37, 295);
    653               x0[i] := x0[i] + (8 + 8 + 36);
     653              x0[I] := x0[I] + (8 + 8 + 36);
    654654            end;
    655655          pkAdvIcon, pkAdvIcon_AsPreq:
    656656            begin
    657               ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[i], 2 - 1 + i * 24,
    658                 8 + xSizeSmall + x0[i], 2 + ySizeSmall + i * 24,
     657              ScreenTools.Frame(OffScreen.Canvas, 8 - 1 + x0[I], 2 - 1 + I * 24,
     658                8 + xSizeSmall + x0[I], 2 + ySizeSmall + I * 24,
    659659                $000000, $000000);
    660660              if AdvIcon[HelpLineInfo.Picpix] < 84 then
    661                 BitBltCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24,
     661                BitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24,
    662662                  xSizeSmall, ySizeSmall, SmallImp.Canvas,
    663663                  (AdvIcon[HelpLineInfo.Picpix] + SystemIconLines * 7) mod 7 *
     
    665665                  7) div 7 * ySizeSmall)
    666666              else
    667                 Dump(OffScreen, HGrSystem, 8 + x0[i], 2 + i * 24, 36, 20,
     667                Dump(OffScreen, HGrSystem, 8 + x0[I], 2 + I * 24, 36, 20,
    668668                  1 + (AdvIcon[HelpLineInfo.Picpix] - 84) mod 8 * 37,
    669669                  295 + (AdvIcon[HelpLineInfo.Picpix] - 84) div 8 * 21);
    670               j := AdvValue[HelpLineInfo.Picpix] div 1000;
    671               BitBltCanvas(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);
     670              J := AdvValue[HelpLineInfo.Picpix] div 1000;
     671              BitBltCanvas(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);
    676676            end;
    677677          pkRightIcon:
    678678            begin
    679679              if Imp[HelpLineInfo.Picpix].Kind <> ikWonder then
    680                 ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), i * 24,
     680                ImpImage(OffScreen.Canvas, InnerWidth - (40 + xSizeBig), I * 24,
    681681                  HelpLineInfo.Picpix, gDespotism)
    682682              else
    683                 WaterSign(InnerWidth - (40 + 2 * xSizeBig), i * 24 - 8,
     683                WaterSign(InnerWidth - (40 + 2 * xSizeBig), I * 24 - 8,
    684684                  HelpLineInfo.Picpix + 7);
    685               x0[i] := x0[i] + 8;
     685              x0[I] := x0[I] + 8;
    686686            end;
    687687          pkIllu:
    688             WaterSign(8, i * 24 - 8, HelpLineInfo.Picpix);
     688            WaterSign(8, I * 24 - 8, HelpLineInfo.Picpix);
    689689          pkBigFeature:
    690690            begin
    691691              cnt := 0;
    692               for j := nDomains - 1 downto 0 do
    693                 if 1 shl j and Feature[HelpLineInfo.Picpix].Domains <> 0 then
     692              for J := nDomains - 1 downto 0 do
     693                if 1 shl J and Feature[HelpLineInfo.Picpix].Domains <> 0 then
    694694                begin
    695                   inc(cnt);
     695                  Inc(cnt);
    696696                  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);
     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);
    700700                end;
    701701              DarkGradient(OffScreen.Canvas, InnerWidth - 38 - 38 * cnt,
    702                 i * 24 + 23, cnt * 38 - 2, 1);
     702                I * 24 + 23, cnt * 38 - 2, 1);
    703703              ofs := InnerWidth - (39 + 7) - 19 * cnt;
    704704              with OffScreen.Canvas do
    705705              begin
    706                 Brush.color := $C0C0C0;
    707                 FrameRect(Rect(ofs, 1 + 23 + i * 24, ofs + 14,
    708                   15 + 23 + i * 24));
     706                Brush.Color := $C0C0C0;
     707                FrameRect(Rect(ofs, 1 + 23 + I * 24, ofs + 14,
     708                  15 + 23 + I * 24));
    709709                Brush.Style := bsClear;
    710                 Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + i * 24, 10, 10,
     710                Sprite(OffScreen, HGrSystem, ofs + 2, 3 + 23 + I * 24, 10, 10,
    711711                  66 + HelpLineInfo.Picpix mod 11 * 11,
    712712                  137 + HelpLineInfo.Picpix div 11 * 11);
    713713              end;
    714               x0[i] := x0[i] + 8;
     714              x0[I] := x0[I] + 8;
    715715            end;
    716716          pkTer, pkBigTer:
    717717            with NoMap do begin
    718718              if HelpLineInfo.Format = pkBigTer then
    719                 y := i * 24 - 3 + yyt
     719                Y := I * 24 - 3 + yyt
    720720              else
    721                 y := i * 24 + 13;
     721                Y := I * 24 + 13;
    722722              if HelpLineInfo.Picpix >= 3 * 12 then
    723723                srcno := 2 * 9 + 6
     
    730730              if HelpLineInfo.Format = pkTer then
    731731              begin
    732                 ofs := x0[i] + 8;
    733                 x0[i] := 2 * xxt + 8 + ofs;
     732                ofs := x0[I] + 8;
     733                x0[I] := 2 * xxt + 8 + ofs;
    734734              end
    735735              else
    736736              begin
    737737                ofs := InnerWidth - (2 * xxt + 38);
    738                 x0[i] := x0[i] + 8;
     738                x0[I] := x0[I] + 8;
    739739              end;
    740740              if srcno >= fJungle then
    741741              begin
    742                 Sprite(OffScreen, HGrTerrain, ofs + 4, y - yyt + 2, xxt * 2 - 8,
     742                Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8,
    743743                  yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1),
    744744                  3 + yyt + 2 * (yyt * 3 + 1));
    745                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     745                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    746746                  yyt * 3 - 2, 1 + srcno mod 9 * (xxt * 2 + 1),
    747747                  1 + srcno div 9 * (yyt * 3 + 1));
    748748              end
    749749              else
    750                 Sprite(OffScreen, HGrTerrain, ofs + 4, y - yyt + 2, xxt * 2 - 8,
     750                Sprite(OffScreen, HGrTerrain, ofs + 4, Y - yyt + 2, xxt * 2 - 8,
    751751                  yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1),
    752752                  3 + yyt + srcno div 9 * (yyt * 3 + 1));
    753753              if HelpLineInfo.Picpix >= 3 * 12 then { rare resource }
    754                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     754                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    755755                  yyt * 3, 1 + 8 * (xxt * 2 + 1),
    756756                  1 + (HelpLineInfo.Picpix - 2 * 12) * (yyt * 3 + 1))
     
    764764                  srcno := 18 + 8 + (HelpLineInfo.Picpix mod 12 - 9) * 18;
    765765                srcno := srcno + HelpLineInfo.Picpix div 12 * 9;
    766                 Sprite(OffScreen, HGrTerrain, ofs, y - 2 * yyt, xxt * 2,
     766                Sprite(OffScreen, HGrTerrain, ofs, Y - 2 * yyt, xxt * 2,
    767767                  yyt * 3, 1 + srcno mod 9 * (xxt * 2 + 1),
    768768                  1 + srcno div 9 * (yyt * 3 + 1));
     
    774774              if HelpLineInfo.Picpix = 5 then
    775775              begin // display mine on hills
    776                 Sprite(OffScreen, HGrTerrain, ofs + 4, i * 24 + 13 - yyt,
     776                Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt,
    777777                  xxt * 2 - 8, yyt * 2 - 4, 5 + 2 * (xxt * 2 + 1),
    778778                  3 + yyt + 2 * (yyt * 3 + 1));
     
    781781              else
    782782                srcno := fPrairie; // display on prairie
    783               Sprite(OffScreen, HGrTerrain, ofs + 4, i * 24 + 13 - yyt,
     783              Sprite(OffScreen, HGrTerrain, ofs + 4, I * 24 + 13 - yyt,
    784784                xxt * 2 - 8, yyt * 2 - 4, 5 + srcno mod 9 * (xxt * 2 + 1),
    785785                3 + yyt + srcno div 9 * (yyt * 3 + 1));
    786786              if HelpLineInfo.Picpix = 12 then { river }
    787                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - yyt, xxt * 2,
     787                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - yyt, xxt * 2,
    788788                  yyt * 2, 1 + 5 * (xxt * 2 + 1), 1 + yyt + 13 * (yyt * 3 + 1))
    789789              else if HelpLineInfo.Picpix >= 3 then { improvement 2 }
    790790              begin
    791791                if HelpLineInfo.Picpix = 6 then
    792                   Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     792                  Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    793793                    xxt * 2, yyt * 3, 1 + 7 * (xxt * 2 + 1),
    794794                    1 + 12 * (yyt * 3 + 1));
    795                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     795                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    796796                  xxt * 2, yyt * 3, 1 + (HelpLineInfo.Picpix - 3) *
    797797                  (xxt * 2 + 1), 1 + 12 * (yyt * 3 + 1))
     
    799799              else { improvement 1 }
    800800              begin
    801                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     801                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    802802                  xxt * 2, yyt * 3, 1 + 2 * (xxt * 2 + 1),
    803803                  1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1));
    804                 Sprite(OffScreen, HGrTerrain, ofs, i * 24 + 11 - 2 * yyt,
     804                Sprite(OffScreen, HGrTerrain, ofs, I * 24 + 11 - 2 * yyt,
    805805                  xxt * 2, yyt * 3, 1 + 5 * (xxt * 2 + 1),
    806806                  1 + (9 + HelpLineInfo.Picpix) * (yyt * 3 + 1))
    807807              end;
    808               x0[i] := x0[i] + 8;
     808              x0[I] := x0[I] + 8;
    809809            end;
    810810          pkModel:
    811811            begin
    812               FrameImage(OffScreen.Canvas, BigImp, x0[i] + 12, i * 24 - 7,
     812              FrameImage(OffScreen.Canvas, BigImp, x0[I] + 12, I * 24 - 7,
    813813                56, 40, 0, 0);
    814               Sprite(OffScreen, HGrStdUnits, x0[i] + 8, i * 24 - 11, 64, 44,
     814              Sprite(OffScreen, HGrStdUnits, x0[I] + 8, I * 24 - 11, 64, 44,
    815815                1 + HelpLineInfo.Picpix mod 10 * 65,
    816816                1 + HelpLineInfo.Picpix div 10 * 49);
    817               x0[i] := 64 + 8 + 8 + x0[i];
     817              x0[I] := 64 + 8 + 8 + x0[I];
    818818            end;
    819819          pkFeature:
    820820            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,
     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,
    826826                66 + HelpLineInfo.Picpix mod 11 * 11,
    827827                137 + HelpLineInfo.Picpix div 11 * 11);
    828               x0[i] := x0[i] + 8 + 8 + 2 + 13;
     828              x0[I] := x0[I] + 8 + 8 + 2 + 13;
    829829            end;
    830830          pkExp:
    831831            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,
     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,
    835835                121 + HelpLineInfo.Picpix * 13, 28);
    836               x0[i] := 20 + 8 + 11;
     836              x0[I] := 20 + 8 + 11;
    837837            end;
    838838          pkAITStat:
    839839            begin
    840               Sprite(OffScreen, HGrSystem, 20, 6 + i * 24, 14, 14,
     840              Sprite(OffScreen, HGrSystem, 20, 6 + I * 24, 14, 14,
    841841                1 + HelpLineInfo.Picpix * 15, 316);
    842               x0[i] := 20 + 8 + 11;
     842              x0[I] := 20 + 8 + 11;
    843843            end;
    844844          pkGov:
    845845            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               BitBltCanvas(OffScreen.Canvas, 8 + x0[i], 2 + i * 24, xSizeSmall,
     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              BitBltCanvas(OffScreen.Canvas, 8 + x0[I], 2 + I * 24, xSizeSmall,
    849849                ySizeSmall, SmallImp.Canvas, (HelpLineInfo.Picpix - 1) *
    850850                xSizeSmall, ySizeSmall);
    851               x0[i] := x0[i] + (8 + 8 + 36);
     851              x0[I] := x0[I] + (8 + 8 + 36);
    852852            end;
    853853          pkDot:
    854854            begin
    855               Sprite(OffScreen, HGrSystem, x0[i] + 18, 9 + i * 24, 8,
     855              Sprite(OffScreen, HGrSystem, x0[I] + 18, 9 + I * 24, 8,
    856856                8, 81, 16);
    857               x0[i] := 20 + 8 + 4;
     857              x0[I] := 20 + 8 + 4;
    858858            end;
    859859          pkNormal_Dot:
    860             x0[i] := 20 + 8 + 4;
     860            x0[I] := 20 + 8 + 4;
    861861          pkNormal_64:
    862             x0[i] := 64 + 8 + 8;
     862            x0[I] := 64 + 8 + 8;
    863863        else
    864           x0[i] := x0[i] + 8;
     864          x0[I] := x0[I] + 8;
    865865        end;
    866         Self.Line(OffScreen.Canvas, i, False)
     866        Self.Line(OffScreen.Canvas, I, False)
    867867      end;
    868868  end;
     
    873873begin
    874874  Sel := -1;
    875   SmartUpdateContent(true)
    876 end;
    877 
    878 procedure THelpDlg.Prepare(sbPos: integer = 0);
     875  SmartUpdateContent(True)
     876end;
     877
     878procedure THelpDlg.Prepare(sbPos: Integer = 0);
    879879var
    880   i, j, Special, Domain, Headline, TerrType, TerrSubType: integer;
    881   s: string;
    882   ps: pchar;
     880  I, J, Special, Domain, Headline, TerrType, TerrSubType: Integer;
     881  S: string;
     882  ps: PChar;
    883883  List: THyperText;
    884884  CheckSeeAlso: Boolean;
    885885
    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);
     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);
    911911  begin
    912912    if MainText.Count > 1 then
     
    914914      MainText.LineFeed;
    915915    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);
     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);
    926926  var
    927     pix: integer;
     927    pix: Integer;
    928928    Name: string;
    929929  begin
    930930    if MainText.Count > 1 then
    931931      MainText.LineFeed;
    932     FindStdModelPicture(SpecialModelPictureCode[i], pix, Name);
    933     MainText.AddLine(Name, pkModel, pix, hkModel + hkCrossLink, i)
     932    FindStdModelPicture(SpecialModelPictureCode[I], pix, Name);
     933    MainText.AddLine(Name, pkModel, pix, hkModel + hkCrossLink, I)
    934934  end;
    935935
    936936  procedure AddStandardBlock(Item: string);
    937937  var
    938     i: integer;
     938    I: Integer;
    939939  begin
    940940    with MainText do
     
    947947      else if Item = 'TECHFORMULA' then
    948948      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]]))
     949        I := Difficulty;
     950        if I = 0 then
     951          I := 2;
     952        AddLine(Format(HelpText.Lookup('TECHFORMULA'), [TechFormula_M[I],
     953          TechFormula_D[I]]))
    954954      end
    955955      else if Item = 'EXPERIENCE' then
    956         for i := 0 to nExp - 1 do
    957           AddLine(Phrases.Lookup('EXPERIENCE', i), pkExp, i)
     956        for I := 0 to nExp - 1 do
     957          AddLine(Phrases.Lookup('EXPERIENCE', I), pkExp, I)
    958958      else if Item = 'MODERN' then
    959         for i := 1 to 3 do
     959        for I := 1 to 3 do
    960960        begin
    961961          LineFeed;
    962           AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + i), pkTer, 3 * 12 + i);
     962          AddLine(Phrases.Lookup('TERRAIN', 3 * 12 + I), pkTer, 3 * 12 + I);
    963963        end
    964964      else if Item = 'SAVED' then
    965965        AddLine(DataDir + 'Saved', pkNormal)
    966966      else if Item = 'AITSTAT' then
    967         for i := 0 to 3 do
    968           AddLine(Phrases2.Lookup('AITSTAT', i), pkAITStat, i)
     967        for I := 0 to 3 do
     968          AddLine(Phrases2.Lookup('AITSTAT', I), pkAITStat, I)
    969969    end
    970970  end;
    971971
    972   procedure DecodeItem(s: string; var Category, Index: Integer);
     972  procedure DecodeItem(S: string; var Category, Index: Integer);
    973973  var
    974     i: Integer;
    975   begin
    976     if (Length(s) > 0) and (s[1] = ':') then begin
     974    I: Integer;
     975  begin
     976    if (Length(S) > 0) and (S[1] = ':') then begin
    977977      Category := hkMisc;
    978978      Index := 0;
    979       for i := 3 to length(s) do
    980         Index := Index * 10 + Ord(s[i]) - 48;
    981       case s[2] of
     979      for I := 3 to Length(S) do
     980        Index := Index * 10 + Ord(S[I]) - 48;
     981      case S[2] of
    982982        'A': Category := hkAdv;
    983983        'B': Category := hkImp;
     
    994994    end else begin
    995995      Category := hkText;
    996       Index := HelpText.Gethandle(Copy(s, 1, 255));
     996      Index := HelpText.Gethandle(Copy(S, 1, 255));
    997997    end;
    998998  end;
    999999
    1000   procedure AddTextual(s: string);
     1000  procedure AddTextual(S: string);
    10011001  var
    1002     i: Integer;
    1003     p: Integer;
    1004     l: Integer;
     1002    I: Integer;
     1003    P: Integer;
     1004    L: Integer;
    10051005    ofs: Integer;
    10061006    CurrentFormat: Integer;
     
    10151015    RightMargin := InnerWidth - 16 - GetSystemMetrics(SM_CXVSCROLL);
    10161016    FollowFormat := pkNormal;
    1017     while s <> '' do
     1017    while S <> '' do
    10181018    begin
    10191019      Picpix := 0;
    10201020      LinkCategory := 0;
    10211021      LinkIndex := 0;
    1022       if s[1] = '$' then
     1022      if S[1] = '$' then
    10231023      begin // window caption
    1024         p := 1;
     1024        P := 1;
    10251025        repeat
    1026           inc(p)
    1027         until (p > Length(s)) or (s[p] = '\');
    1028         Caption := Copy(s, 2, p - 2);
    1029         Delete(s, 1, p);
     1026          Inc(P);
     1027        until (P > Length(S)) or (S[P] = '\');
     1028        Caption := Copy(S, 2, P - 2);
     1029        Delete(S, 1, P);
    10301030      end
    1031       else if s[1] = '&' then
     1031      else if S[1] = '&' then
    10321032      begin // standard block
    1033         p := 1;
     1033        P := 1;
    10341034        repeat
    1035           inc(p)
    1036         until (p > Length(s)) or (s[p] = '\');
    1037         AddStandardBlock(Copy(s, 2, p - 2));
    1038         Delete(s, 1, p);
     1035          Inc(P);
     1036        until (P > Length(S)) or (S[P] = '\');
     1037        AddStandardBlock(Copy(S, 2, P - 2));
     1038        Delete(S, 1, P);
    10391039      end
    1040       else if s[1] = '@' then
     1040      else if S[1] = '@' then
    10411041      begin // image
    1042         if (Length(s) >= 2) and (s[2] = '@') then
     1042        if (Length(S) >= 2) and (S[2] = '@') then
    10431043        begin // generate from icon
    10441044          Picpix := 0;
    1045           p := 3;
    1046           while (p <= Length(s)) and (s[p] <> '\') do
     1045          P := 3;
     1046          while (P <= Length(S)) and (S[P] <> '\') do
    10471047          begin
    1048             Picpix := Picpix * 10 + Ord(s[p]) - 48;
    1049             inc(p)
     1048            Picpix := Picpix * 10 + Ord(S[P]) - 48;
     1049            Inc(P);
    10501050          end;
    10511051          if (Picpix < 0) or (Picpix >= nImp) then
     
    10571057        else
    10581058        begin // external image
    1059           p := 1;
     1059          P := 1;
    10601060          repeat
    1061             Inc(p)
    1062           until (p > Length(s)) or (s[p] = '\');
     1061            Inc(P);
     1062          until (P > Length(S)) or (S[P] = '\');
    10631063          if LoadGraphicFile(ExtPic, LocalizedFilePath('Help' +
    1064             DirectorySeparator + Copy(s, 2, p - 2)) + '.png') then
     1064            DirectorySeparator + Copy(S, 2, P - 2)) + '.png') then
    10651065          begin
    10661066            MainText.AddLine('', pkExternal);
    1067             for i := 0 to (ExtPic.Height - 12) div 24 do
     1067            for I := 0 to (ExtPic.Height - 12) div 24 do
    10681068              MainText.LineFeed;
    10691069          end;
    10701070        end;
    1071         Delete(s, 1, p);
     1071        Delete(S, 1, P);
    10721072      end
    10731073      else
    10741074      begin
    1075         case s[1] of
     1075        case S[1] of
    10761076          ':', ';':
    10771077            begin // link
    1078               p := 1;
     1078              P := 1;
    10791079              repeat
    1080                 inc(p)
    1081               until (p > Length(s)) or (s[p] = '\') or (s[p] = ' ');
    1082               DecodeItem(Copy(s, 2, p - 2), LinkCategory, LinkIndex);
     1080                Inc(P)
     1081              until (P > Length(S)) or (S[P] = '\') or (S[P] = ' ');
     1082              DecodeItem(Copy(S, 2, P - 2), LinkCategory, LinkIndex);
    10831083              CurrentFormat := 0;
    10841084              if (LinkCategory <> hkText) and (LinkIndex < 200) then
     
    11121112                    end;
    11131113                end;
    1114               if s[1] = ':' then
     1114              if S[1] = ':' then
    11151115                LinkCategory := LinkCategory + hkCrossLink;
    1116               if (p > Length(s)) or (s[p] = ' ') then
    1117                 Delete(s, 1, p)
     1116              if (P > Length(S)) or (S[P] = ' ') then
     1117                Delete(S, 1, P)
    11181118              else
    1119                 Delete(s, 1, p - 1)
     1119                Delete(S, 1, P - 1)
    11201120            end;
    11211121          '!': // highlited
    1122             if (Length(s) >= 2) and (s[2] = '!') then
     1122            if (Length(S) >= 2) and (S[2] = '!') then
    11231123            begin
    11241124              if MainText.Count > 1 then
     
    11261126              FollowFormat := pkCaption;
    11271127              CurrentFormat := pkCaption;
    1128               Delete(s, 1, 2);
     1128              Delete(S, 1, 2);
    11291129            end
    11301130            else
     
    11321132              FollowFormat := pkSection;
    11331133              CurrentFormat := pkSection;
    1134               Delete(s, 1, 1);
     1134              Delete(S, 1, 1);
    11351135            end;
    11361136          '-':
     
    11381138              FollowFormat := pkNormal_Dot;
    11391139              CurrentFormat := pkDot;
    1140               Delete(s, 1, 1);
     1140              Delete(S, 1, 1);
    11411141            end;
    11421142        else
     
    11471147        else
    11481148          ofs := 8;
    1149         p := 0;
     1149        P := 0;
    11501150        repeat
    11511151          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)) <=
     1152            Inc(P)
     1153          until (P > Length(S)) or (S[P] = ' ') or (S[P] = '\');
     1154          if (BiColorTextWidth(OffScreen.Canvas, Copy(S, 1, P - 1)) <=
    11551155            RightMargin - ofs) then
    1156             l := p - 1
     1156            L := P - 1
    11571157          else
    11581158            Break;
    1159         until (p >= Length(s)) or (s[l + 1] = '\');
    1160         Text := Copy(s, 1, l);
    1161         if LinkCategory and $3f = hkInternet then begin
     1159        until (P >= Length(S)) or (S[L + 1] = '\');
     1160        Text := Copy(S, 1, L);
     1161        if LinkCategory and $3F = hkInternet then begin
    11621162          if LinkIndex = 1 then Text := AITemplateManual
    11631163          else if LinkIndex = 2 then Text := CevoHomepageShort
     
    11661166        MainText.AddLine(Text, CurrentFormat, Picpix, LinkCategory,
    11671167          LinkIndex);
    1168         if (l < Length(s)) and (s[l + 1] = '\') then
     1168        if (L < Length(S)) and (S[L + 1] = '\') then
    11691169          FollowFormat := pkNormal;
    1170         Delete(s, 1, l + 1);
     1170        Delete(S, 1, L + 1);
    11711171      end
    11721172    end
     
    11781178  end;
    11791179
    1180   procedure AddModelText(i: Integer);
     1180  procedure AddModelText(I: Integer);
    11811181  var
    11821182    pix: Integer;
    1183     s: string;
     1183    S: string;
    11841184  begin
    11851185    with MainText do begin
     
    11881188        LineFeed;
    11891189      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);
     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);
    11941194      AddLine(Format(HelpText.Lookup('SPEED'),
    1195         [MovementToString(SpecialModel[i].Speed)]), pkModel, pix);
     1195        [MovementToString(SpecialModel[I].Speed)]), pkModel, pix);
    11961196      if Difficulty = 0 then
    1197         AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[i].Cost]),
     1197        AddLine(Format(HelpText.Lookup('BUILDCOST'), [SpecialModel[I].Cost]),
    11981198          pkNormal_64)
    11991199      else
    12001200        AddLine(Format(HelpText.Lookup('BUILDCOST'),
    1201           [SpecialModel[i].Cost * BuildCostMod[Difficulty] div 12]),
     1201          [SpecialModel[I].Cost * BuildCostMod[Difficulty] div 12]),
    12021202          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
     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
    12091209        AddPreqImp(woLighthouse)
    1210       else if SpecialModelPreq[i] = preBuilder then
     1210      else if SpecialModelPreq[I] = preBuilder then
    12111211        AddPreqImp(woPyramids)
    1212       else if SpecialModelPreq[i] = preLeo then
     1212      else if SpecialModelPreq[I] = preLeo then
    12131213        AddPreqImp(woLeo);
    1214       if SpecialModelPreq[i] <> preNone then
     1214      if SpecialModelPreq[I] <> preNone then
    12151215        MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    12161216          [MainText[Count - 1]]);
     
    12201220  procedure AddJobList;
    12211221  var
    1222     i, JobCost: Integer;
     1222    I, JobCost: Integer;
    12231223  begin
    12241224    with MainText do begin
    1225       for i := 0 to nJobHelp - 1 do begin
    1226         if i > 0 then begin
     1225      for I := 0 to nJobHelp - 1 do begin
     1226        if I > 0 then begin
    12271227          LineFeed;
    12281228          LineFeed;
    12291229        end;
    1230         AddLine(Phrases.Lookup('JOBRESULT', JobHelp[i]), pkSection);
     1230        AddLine(Phrases.Lookup('JOBRESULT', JobHelp[I]), pkSection);
    12311231        AddLine;
    1232         AddLine('', pkTerImp, i);
     1232        AddLine('', pkTerImp, I);
    12331233        AddLine;
    1234         AddTextual(HelpText.LookupByHandle(hJOBHELP, i));
     1234        AddTextual(HelpText.LookupByHandle(hJOBHELP, I));
    12351235        JobCost := -1;
    1236         case JobHelp[i] of
     1236        case JobHelp[I] of
    12371237          jCanal: JobCost := CanalWork;
    12381238          jFort: JobCost := FortWork;
     
    12441244        else
    12451245          AddTextual(HelpText.Lookup('JOBCOSTVAR'));
    1246         if JobPreq[JobHelp[i]] <> preNone then begin
    1247           AddPreqAdv(JobPreq[JobHelp[i]]);
     1246        if JobPreq[JobHelp[I]] <> preNone then begin
     1247          AddPreqAdv(JobPreq[JobHelp[I]]);
    12481248          MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    12491249            [MainText[Count - 1]]);
     
    12551255  procedure AddGraphicCredits;
    12561256  var
    1257     i: Integer;
    1258     s: string;
     1257    I: Integer;
     1258    S: string;
    12591259    sr: TSearchRec;
    12601260    List, Plus: TStringList;
     
    12711271
    12721272    List.Sort;
    1273     i := 1;
    1274     while i < List.Count do
    1275       if List[i] = List[i - 1] then
    1276         List.Delete(i)
     1273    I := 1;
     1274    while I < List.Count do
     1275      if List[I] = List[I - 1] then
     1276        List.Delete(I)
    12771277      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 -
     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 -
    12831283        GetSystemMetrics(SM_CXVSCROLL) do
    1284         Delete(s, length(s), 1);
    1285       MainText.AddLine(s);
     1284        Delete(S, Length(S), 1);
     1285      MainText.AddLine(S);
    12861286    end;
    12871287    FreeAndNil(List);
     
    12901290  procedure AddSoundCredits;
    12911291  var
    1292     i: Integer;
    1293     s: string;
     1292    I: Integer;
     1293    S: string;
    12941294    List: TStringList;
    12951295  begin
    12961296    List := TStringList.Create;
    12971297    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 -
     1298    for I := 0 to List.Count - 1 do begin
     1299      S := List[I];
     1300      while BiColorTextWidth(OffScreen.Canvas, S) > InnerWidth - 16 -
    13011301        GetSystemMetrics(SM_CXVSCROLL) do
    1302         Delete(s, length(s), 1);
    1303       MainText.AddLine(s);
     1302        Delete(S, Length(S), 1);
     1303      MainText.AddLine(S);
    13041304    end;
    13051305    FreeAndNil(List);
     
    13491349                  hkAdv, 200);
    13501350                LineFeed;
    1351                 FindStdModelPicture(SpecialModelPictureCode[6], i, s);
    1352                 AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, i,
     1351                FindStdModelPicture(SpecialModelPictureCode[6], I, S);
     1352                AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkModel, I,
    13531353                  hkModel, 0);
    13541354                LineFeed;
     
    14021402              begin
    14031403                Caption := HelpText.Lookup('HELPTITLE_GOVLIST');
    1404                 for i := 1 to nGov do
     1404                for I := 1 to nGov do
    14051405                begin
    1406                   AddLine(Phrases.Lookup('GOVERNMENT', i mod nGov), pkSection);
     1406                  AddLine(Phrases.Lookup('GOVERNMENT', I mod nGov), pkSection);
    14071407                  LineFeed;
    1408                   if i = nGov then
     1408                  if I = nGov then
    14091409                    AddLine('', pkBigIcon, 7 * SystemIconLines + imPalace)
    14101410                  else
    1411                     AddLine('', pkBigIcon, i + 6);
     1411                    AddLine('', pkBigIcon, I + 6);
    14121412                  LineFeed;
    1413                   AddTextual(HelpText.LookupByHandle(hGOVHELP, i mod nGov));
    1414                   if i mod nGov >= 2 then
     1413                  AddTextual(HelpText.LookupByHandle(hGOVHELP, I mod nGov));
     1414                  if I mod nGov >= 2 then
    14151415                  begin
    1416                     AddPreqAdv(GovPreq[i mod nGov]);
     1416                    AddPreqAdv(GovPreq[I mod nGov]);
    14171417                    MainText[Count - 1] := Format(HelpText.Lookup('REQUIRED'),
    14181418                      [MainText[Count - 1]]);
    14191419                  end;
    1420                   if i < nGov then
     1420                  if I < nGov then
    14211421                  begin
    14221422                    LineFeed;
     
    14401440          List := THyperText.Create;
    14411441          List.OwnsObjects := True;
    1442           for j := 0 to 3 do
     1442          for J := 0 to 3 do
    14431443          begin
    1444             if j > 0 then
     1444            if J > 0 then
    14451445            begin
    14461446              LineFeed;
    14471447              LineFeed;
    14481448            end;
    1449             AddLine(HelpText.Lookup('TECHAGE', j), pkSection);
    1450             if j = 1 then
     1449            AddLine(HelpText.Lookup('TECHAGE', J), pkSection);
     1450            if J = 1 then
    14511451              AddLine(Phrases.Lookup('ADVANCES', adScience) + ' ' +
    14521452                HelpText.Lookup('BASETECH'), pkAdvIcon, adScience, hkAdv,
    14531453                adScience);
    1454             if j = 2 then
     1454            if J = 2 then
    14551455              AddLine(Phrases.Lookup('ADVANCES', adMassProduction) + ' ' +
    14561456                HelpText.Lookup('BASETECH'), pkAdvIcon, adMassProduction, hkAdv,
    14571457                adMassProduction);
    14581458            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);
     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);
    14641464            List.Sort;
    14651465            AppendList(List);
     
    14871487          else
    14881488            NextSection('PREREQ');
    1489           for i := 0 to 2 do
    1490             if AdvPreq[no, i] <> preNone then
    1491               AddPreqAdv(AdvPreq[no, i]);
     1489          for I := 0 to 2 do
     1490            if AdvPreq[no, I] <> preNone then
     1491              AddPreqAdv(AdvPreq[no, I]);
    14921492          NextSection('GOVALLOW');
    1493           for i := 2 to nGov - 1 do
    1494             if GovPreq[i] = no then
    1495               AddLine(Phrases.Lookup('GOVERNMENT', i), pkGov, i,
     1493          for I := 2 to nGov - 1 do
     1494            if GovPreq[I] = no then
     1495              AddLine(Phrases.Lookup('GOVERNMENT', I), pkGov, I,
    14961496                hkMisc + hkCrossLink, miscGovList);
    14971497          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);
     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);
    15071507          NextSection('MODELALLOW');
    1508           for i := 0 to nSpecialModel - 1 do
    1509             if SpecialModelPreq[i] = no then
    1510               AddModel(i);
     1508          for I := 0 to nSpecialModel - 1 do
     1509            if SpecialModelPreq[I] = no then
     1510              AddModel(I);
    15111511          NextSection('FEATALLOW');
    1512           for i := 0 to nFeature - 1 do
    1513             if Feature[i].Preq = no then
    1514               AddFeature(i);
     1512          for I := 0 to nFeature - 1 do
     1513            if Feature[I].Preq = no then
     1514              AddFeature(I);
    15151515          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);
     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);
    15201520          NextSection('UPGRADEALLOW');
    15211521          for Domain := 0 to nDomains - 1 do
    1522             for i := 1 to nUpgrade - 1 do
    1523               if upgrade[Domain, i].Preq = no then
     1522            for I := 1 to nUpgrade - 1 do
     1523              if upgrade[Domain, I].Preq = no then
    15241524              begin
    1525                 if upgrade[Domain, i].Strength > 0 then
     1525                if upgrade[Domain, I].Strength > 0 then
    15261526                  AddLine(Format(HelpText.Lookup('STRENGTHUP'),
    15271527                    [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain,
    1528                     i].Strength]), pkDomain, Domain);
    1529                 if upgrade[Domain, i].Trans > 0 then
     1528                    I].Strength]), pkDomain, Domain);
     1529                if upgrade[Domain, I].Trans > 0 then
    15301530                  AddLine(Format(HelpText.Lookup('TRANSUP'),
    1531                     [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, i].Trans]
     1531                    [Phrases.Lookup('DOMAIN', Domain), upgrade[Domain, I].Trans]
    15321532                    ), pkDomain, Domain);
    15331533                if no in FutureTech then
    15341534                  AddLine(Format(HelpText.Lookup('COSTUP'),
    1535                     [upgrade[Domain, i].Cost]), pkNormal_Dot)
     1535                    [upgrade[Domain, I].Cost]), pkNormal_Dot)
    15361536                else
    15371537                  AddLine(Format(HelpText.Lookup('COSTMIN'),
    1538                     [upgrade[Domain, i].Cost]), pkNormal_Dot)
     1538                    [upgrade[Domain, I].Cost]), pkNormal_Dot)
    15391539              end;
    15401540          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);
     1541          for I := 0 to nWonder - 1 do
     1542            if (Imp[I].Preq <> preNA) and (Imp[I].Expiration = no) then
     1543              AddImprovement(I);
    15441544          NextSection('ADVEFFECT');
    1545           s := HelpText.LookupByHandle(hADVHELP, no);
    1546           if s <> '*' then
    1547             AddTextual(s);
     1545          S := HelpText.LookupByHandle(hADVHELP, no);
     1546          if S <> '*' then
     1547            AddTextual(S);
    15481548          NextSection('SEEALSO');
    1549           CheckSeeAlso := true
     1549          CheckSeeAlso := True
    15501550        end;
    15511551
     
    15571557          List := THyperText.Create;
    15581558          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);
     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);
    15641564          List.Sort;
    15651565          AppendList(List);
     
    15701570          Caption := HelpText.Lookup('HELPTITLE_UNIQUELIST');
    15711571          // 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);
     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);
    15771577          { LineFeed;
    15781578            LineFeed;
    15791579            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); }
     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); }
    15831583        end
    15841584        else if no = 202 then
     
    15861586          Caption := HelpText.Lookup('HELPTITLE_WONDERLIST');
    15871587          // 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);
     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);
    15921592        end
    15931593        else
     
    16271627          NextSection('COSTS');
    16281628          if Difficulty = 0 then
    1629             s := Format(HelpText.Lookup('BUILDCOST'), [Imp[no].Cost])
     1629            S := Format(HelpText.Lookup('BUILDCOST'), [Imp[no].Cost])
    16301630          else
    1631             s := Format(HelpText.Lookup('BUILDCOST'),
     1631            S := Format(HelpText.Lookup('BUILDCOST'),
    16321632              [Imp[no].Cost * BuildCostMod[Difficulty] div 12]);
    1633           AddLine(s);
     1633          AddLine(S);
    16341634          if Imp[no].Maint > 0 then
    16351635            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
     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
    16411641              begin
    16421642                NextSection('REPLACE');
    16431643                AddItem('REPLACETEXT');
    1644                 j := 1;
     1644                J := 1;
    16451645              end;
    1646               AddImprovement(ImpReplacement[i].OldImp);
     1646              AddImprovement(ImpReplacement[I].OldImp);
    16471647            end;
    16481648          if Imp[no].Kind = ikShipPart then
     
    16501650            LineFeed;
    16511651            if no = imShipComp then
    1652               i := 1
     1652              I := 1
    16531653            else if no = imShipPow then
    1654               i := 2
     1654              I := 2
    16551655            else { if no=imShipHab then }
    1656               i := 3;
     1656              I := 3;
    16571657            AddLine(Format(HelpText.Lookup('RAREREQUIRED'),
    1658               [Phrases.Lookup('TERRAIN', 3 * 12 + i)]), pkTer, 3 * 12 + i);
     1658              [Phrases.Lookup('TERRAIN', 3 * 12 + I)]), pkTer, 3 * 12 + I);
    16591659          end;
    16601660          if (no < nWonder) and (Imp[no].Expiration >= 0) then
    16611661          begin
    16621662            NextSection('EXPIRATION');
    1663             s := Format(HelpText.Lookup('EXPWITH'),
     1663            S := Format(HelpText.Lookup('EXPWITH'),
    16641664              [Phrases.Lookup('ADVANCES', Imp[no].Expiration)]);
    16651665            if no = woPyramids then
    1666               s := s + ' ' + HelpText.Lookup('EXPSLAVE');
    1667             AddTextual(s);
     1666              S := S + ' ' + HelpText.Lookup('EXPSLAVE');
     1667            AddTextual(S);
    16681668          end;
    16691669          NextSection('SEEALSO');
    16701670          if (no < nWonder) and (Imp[no].Expiration >= 0) then
    16711671            AddImprovement(woEiffel);
    1672           for i := 0 to nImpReplacement - 1 do
    1673             if ImpReplacement[i].OldImp = no then
    1674               AddImprovement(ImpReplacement[i].NewImp);
     1672          for I := 0 to nImpReplacement - 1 do
     1673            if ImpReplacement[I].OldImp = no then
     1674              AddImprovement(ImpReplacement[I].NewImp);
    16751675          if no = imSupermarket then
    16761676            AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0,
    16771677              hkMisc + hkCrossLink, miscJobList);
    1678           CheckSeeAlso := true;
     1678          CheckSeeAlso := True;
    16791679        end;
    16801680
     
    16841684          Caption := HelpText.Lookup('HELPTITLE_TERLIST');
    16851685          // AddLine(HelpText.Lookup('HELPTITLE_TERLIST'),pkSection);
    1686           for i := 0 to nTerrainHelp - 1 do
    1687             AddTerrain(TerrainHelp[i]);
     1686          for I := 0 to nTerrainHelp - 1 do
     1687            AddTerrain(TerrainHelp[I]);
    16881688        end
    16891689        else
     
    17461746            begin
    17471747              LineFeed;
    1748               i := TransTerrain;
    1749               if (TerrType <> fGrass) and (i <> fGrass) then
    1750                 i := i + TerrSubType * 12;
     1748              I := TransTerrain;
     1749              if (TerrType <> fGrass) and (I <> fGrass) then
     1750                I := I + TerrSubType * 12;
    17511751              // trafo to same Special resource group
    17521752              AddLine(Format(HelpText.Lookup('TRAFO'),
    1753                 [Phrases.Lookup('TERRAIN', i)]), pkTer, i,
    1754                 hkTer + hkCrossLink, i);
     1753                [Phrases.Lookup('TERRAIN', I)]), pkTer, I,
     1754                hkTer + hkCrossLink, I);
    17551755              if no = fSwamp + 12 then
    17561756              begin
     
    17601760                  TransTerrain + 24, hkTer + hkCrossLink, TransTerrain + 24);
    17611761              end
    1762               else if i = fGrass then
     1762              else if I = fGrass then
    17631763              begin
    17641764                LineFeed;
     
    17901790                  AddLine(Phrases.Lookup('TERRAIN', no + Special * 12), pkTer,
    17911791                    no + Special * 12);
    1792                   i := FoodRes[Special] - FoodRes[0];
    1793                   if i <> 0 then
     1792                  I := FoodRes[Special] - FoodRes[0];
     1793                  if I <> 0 then
    17941794                    MainText[Count - 1] := MainText[Count - 1] +
    1795                       Format(HelpText.Lookup('SPECIALFOOD'), [i]);
    1796                   i := ProdRes[Special] - ProdRes[0];
    1797                   if i <> 0 then
     1795                      Format(HelpText.Lookup('SPECIALFOOD'), [I]);
     1796                  I := ProdRes[Special] - ProdRes[0];
     1797                  if I <> 0 then
    17981798                    MainText[Count - 1] := MainText[Count - 1] +
    1799                       Format(HelpText.Lookup('SPECIALPROD'), [i]);
    1800                   i := TradeRes[Special] - TradeRes[0];
    1801                   if i <> 0 then
     1799                      Format(HelpText.Lookup('SPECIALPROD'), [I]);
     1800                  I := TradeRes[Special] - TradeRes[0];
     1801                  if I <> 0 then
    18021802                    MainText[Count - 1] := MainText[Count - 1] +
    1803                       Format(HelpText.Lookup('SPECIALTRADE'), [i]);
     1803                      Format(HelpText.Lookup('SPECIALTRADE'), [I]);
    18041804                end;
    18051805            end;
     
    18131813              NextSection('SEEALSO');
    18141814              AddImprovement(woGardens);
    1815               CheckSeeAlso := true
     1815              CheckSeeAlso := True
    18161816            end;
    18171817          end;
     
    18371837            end;
    18381838            List.Clear;
    1839             for i := 0 to nFeature - 1 do
    1840               if Feature[i].Preq <> preNA then
     1839            for I := 0 to nFeature - 1 do
     1840              if Feature[I].Preq <> preNA then
    18411841              begin
    1842                 if i < mcFirstNonCap then
    1843                   j := 0
    1844                 else if i in AutoFeature then
    1845                   j := 2
     1842                if I < mcFirstNonCap then
     1843                  J := 0
     1844                else if I in AutoFeature then
     1845                  J := 2
    18461846                else
    1847                   j := 1;
    1848                 if j = Special then
    1849                   List.AddLine(Phrases.Lookup('FEATURES', i), pkFeature, i,
    1850                     hkFeature, i);
     1847                  J := 1;
     1848                if J = Special then
     1849                  List.AddLine(Phrases.Lookup('FEATURES', I), pkFeature, I,
     1850                    hkFeature, I);
    18511851              end;
    18521852            List.Sort;
     
    18711871          begin
    18721872            NextSection('COSTS');
    1873             s := IntToStr(Feature[no].Cost);
     1873            S := IntToStr(Feature[no].Cost);
    18741874            if Feature[no].Cost >= 0 then
    1875               s := '+' + s;
    1876             AddLine(Format(HelpText.Lookup('COSTBASE'), [s]));
     1875              S := '+' + S;
     1876            AddLine(Format(HelpText.Lookup('COSTBASE'), [S]));
    18771877            if Feature[no].Weight > 0 then
    18781878            begin
     
    19011901        begin
    19021902          Caption := HelpText.Lookup('HELPTITLE_MODELLIST');
    1903           for i := 0 to nSpecialModel - 1 do
    1904             if i <> 2 then
    1905               AddModelText(i);
     1903          for I := 0 to nSpecialModel - 1 do
     1904            if I <> 2 then
     1905              AddModelText(I);
    19061906          LineFeed;
    19071907          AddItem('MODELNOTE');
     
    19101910    end;
    19111911    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);
     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);
    19181918          end;
    19191919    if (Headline >= 0) and (Count = Headline + 1) then
     
    19491949
    19501950procedure THelpDlg.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    1951   x, y: integer);
     1951  X, Y: Integer);
    19521952var
    19531953  i0, Sel0: Integer;
    19541954begin
    1955   y := y - WideFrame;
     1955  Y := Y - WideFrame;
    19561956  i0 := ScrollBar.Position;
    19571957  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
     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
    19611961  else
    19621962    Sel := -1;
     
    19741974
    19751975procedure THelpDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    1976   Shift: TShiftState; x, y: integer);
     1976  Shift: TShiftState; X, Y: Integer);
    19771977begin
    19781978  if Sel >= 0 then
     
    19871987      begin
    19881988        if (Link >= $8000) and (Link and $3FFF = liInvalid) then
    1989           exit; // invalid link;
     1989          Exit; // invalid link;
    19901990        if Link >= $8000 then
    19911991          ShowNewContent(FWindowMode, hkText, Link and $3FFF)
     
    20792079procedure THelpDlg.Search(SearchString: string);
    20802080var
    2081   h, i, PrevHandle, PrevIndex, p, RightMargin: Integer;
    2082   s: string;
     2081  H, I, PrevHandle, PrevIndex, P, RightMargin: Integer;
     2082  S: string;
    20832083  mADVHELP, mIMPHELP, mFEATUREHELP: set of 0 .. 255;
    20842084  bGOVHELP, bSPECIALMODEL, bJOBHELP: Boolean;
     
    20942094  // search in generic reference
    20952095  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)
     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)
    21022102      else
    21032103      begin
     
    21052105          HelpText.Lookup('HELPSPEC_TER'), pkNormal, 0,
    21062106          hkTer + hkCrossLink, 36);
    2107         if i > 36 then
     2107        if I > 36 then
    21082108          SearchResult.AddLine(Phrases.Lookup('IMPROVEMENTS',
    2109             imShipComp + i - 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'),
    2110             pkNormal, 0, hkImp + hkCrossLink, imShipComp + i - 37);
     2109            imShipComp + I - 37) + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART'),
     2110            pkNormal, 0, hkImp + hkCrossLink, imShipComp + I - 37);
    21112111        Break;
    21122112      end;
    21132113  end;
    2114   for i := 0 to nJobHelp - 1 do
    2115     if pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[i]))) > 0
     2114  for I := 0 to nJobHelp - 1 do
     2115    if Pos(SearchString, UpperCase(Phrases.Lookup('JOBRESULT', JobHelp[I]))) > 0
    21162116    then
    21172117    begin
     
    21212121      Break;
    21222122    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
     2123  for I := 0 to nAdv - 1 do
     2124  begin
     2125    S := Phrases.Lookup('ADVANCES', I);
     2126    if Pos(SearchString, UpperCase(S)) > 0 then
    21272127    begin
    2128       if i in FutureTech then
    2129         s := s + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
     2128      if I in FutureTech then
     2129        S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
    21302130      else
    2131         s := s + ' ' + HelpText.Lookup('HELPSPEC_ADV');
    2132       SearchResult.AddLine(s, pkNormal, 0, hkAdv + hkCrossLink, i);
    2133       include(mADVHELP, i);
     2131        S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV');
     2132      SearchResult.AddLine(S, pkNormal, 0, hkAdv + hkCrossLink, I);
     2133      Include(mADVHELP, I);
    21342134    end;
    21352135  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
     2136  for I := 0 to nSpecialModel - 1 do
     2137  begin
     2138    FindStdModelPicture(SpecialModelPictureCode[I], H, S);
     2139    if Pos(SearchString, UpperCase(S)) > 0 then
    21402140    begin
    21412141      SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal, 0,
     
    21452145    end;
    21462146  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
     2147  for I := 0 to nFeature - 1 do
     2148  begin
     2149    S := Phrases.Lookup('FEATURES', I);
     2150    if Pos(SearchString, UpperCase(S)) > 0 then
    21512151    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')
     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')
    21562156      else
    2157         s := s + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
    2158       SearchResult.AddLine(s, pkNormal, 0, hkFeature + hkCrossLink, i);
    2159       Include(mFEATUREHELP, i);
     2157        S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
     2158      SearchResult.AddLine(S, pkNormal, 0, hkFeature + hkCrossLink, I);
     2159      Include(mFEATUREHELP, I);
    21602160    end;
    21612161  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
     2162  for I := 0 to nImp - 1 do
     2163  begin
     2164    S := Phrases.Lookup('IMPROVEMENTS', I);
     2165    if Pos(SearchString, UpperCase(S)) > 0 then
    21662166    begin
    2167       case Imp[i].Kind of
     2167      case Imp[I].Kind of
    21682168        ikWonder:
    2169           s := s + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
     2169          S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
    21702170        ikCommon:
    2171           s := s + ' ' + HelpText.Lookup('HELPSPEC_IMP');
     2171          S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP');
    21722172        ikShipPart:
    2173           s := s + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
     2173          S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
    21742174      else
    2175         s := s + ' ' + HelpText.Lookup('HELPSPEC_NAT')
     2175        S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT')
    21762176      end;
    2177       SearchResult.AddLine(s, pkNormal, 0, hkImp + hkCrossLink, i);
    2178       Include(mIMPHELP, i);
     2177      SearchResult.AddLine(S, pkNormal, 0, hkImp + hkCrossLink, I);
     2178      Include(mIMPHELP, I);
    21792179    end
    21802180  end;
    2181   for i := 0 to nGov - 1 do
    2182     if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', i))) > 0 then
     2181  for I := 0 to nGov - 1 do
     2182    if Pos(SearchString, UpperCase(Phrases.Lookup('GOVERNMENT', I))) > 0 then
    21832183    begin
    21842184      SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0,
     
    21892189
    21902190  // full text search
    2191   h := -1;
     2191  H := -1;
    21922192  repeat
    2193     PrevHandle := h;
    2194     PrevIndex := i;
    2195     if not HelpText.Search(SearchString, h, i) then
     2193    PrevHandle := H;
     2194    PrevIndex := I;
     2195    if not HelpText.Search(SearchString, H, I) then
    21962196      Break;
    2197     if h = hADVHELP then
     2197    if H = hADVHELP then
    21982198    begin
    2199       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2200         not(i in mADVHELP) then
     2199      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2200        not(I in mADVHELP) then
    22012201      begin
    2202         s := Phrases.Lookup('ADVANCES', i);
    2203         if i in FutureTech then
    2204           s := s + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
     2202        S := Phrases.Lookup('ADVANCES', I);
     2203        if I in FutureTech then
     2204          S := S + ' ' + HelpText.Lookup('HELPSPEC_FUTURE')
    22052205        else
    2206           s := s + ' ' + HelpText.Lookup('HELPSPEC_ADV');
    2207         SearchResult.AddLine(s, pkNormal, 0, hkAdv + hkCrossLink, i)
     2206          S := S + ' ' + HelpText.Lookup('HELPSPEC_ADV');
     2207        SearchResult.AddLine(S, pkNormal, 0, hkAdv + hkCrossLink, I)
    22082208      end;
    22092209    end
    2210     else if h = hIMPHELP then
     2210    else if H = hIMPHELP then
    22112211    begin
    2212       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2213         not(i in mIMPHELP) then
     2212      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2213        not(I in mIMPHELP) then
    22142214      begin
    2215         s := Phrases.Lookup('IMPROVEMENTS', i);
    2216         case Imp[i].Kind of
     2215        S := Phrases.Lookup('IMPROVEMENTS', I);
     2216        case Imp[I].Kind of
    22172217          ikWonder:
    2218             s := s + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
     2218            S := S + ' ' + HelpText.Lookup('HELPSPEC_WONDER');
    22192219          ikCommon:
    2220             s := s + ' ' + HelpText.Lookup('HELPSPEC_IMP');
     2220            S := S + ' ' + HelpText.Lookup('HELPSPEC_IMP');
    22212221          ikShipPart:
    2222             s := s + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
     2222            S := S + ' ' + HelpText.Lookup('HELPSPEC_SHIPPART');
    22232223        else
    2224           s := s + ' ' + HelpText.Lookup('HELPSPEC_NAT')
     2224          S := S + ' ' + HelpText.Lookup('HELPSPEC_NAT')
    22252225        end;
    2226         SearchResult.AddLine(s, pkNormal, 0, hkImp + hkCrossLink, i)
     2226        SearchResult.AddLine(S, pkNormal, 0, hkImp + hkCrossLink, I)
    22272227      end;
    22282228    end
    2229     else if h = hFEATUREHELP then
     2229    else if H = hFEATUREHELP then
    22302230    begin
    2231       if (i >= 0) and ((i <> PrevIndex) or (h <> PrevHandle)) and
    2232         not(i in mFEATUREHELP) then
     2231      if (I >= 0) and ((I <> PrevIndex) or (H <> PrevHandle)) and
     2232        not(I in mFEATUREHELP) then
    22332233      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')
     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')
    22392239        else
    2240           s := s + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
    2241         SearchResult.AddLine(s, pkNormal, 0, hkFeature + hkCrossLink, i);
     2240          S := S + ' ' + HelpText.Lookup('HELPSPEC_FEATURE');
     2241        SearchResult.AddLine(S, pkNormal, 0, hkFeature + hkCrossLink, I);
    22422242      end;
    22432243    end
    2244     else if h = hGOVHELP then
     2244    else if H = hGOVHELP then
    22452245    begin
    2246       if (i >= 0) and (h <> PrevHandle) and not bGOVHELP then
     2246      if (I >= 0) and (H <> PrevHandle) and not bGOVHELP then
    22472247        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_GOVLIST'), pkNormal, 0,
    22482248          hkMisc + hkCrossLink, miscGovList)
    22492249    end
    2250     else if h = hSPECIALMODEL then
     2250    else if H = hSPECIALMODEL then
    22512251    begin
    2252       if (i >= 0) and (h <> PrevHandle) and not bSPECIALMODEL then
     2252      if (I >= 0) and (H <> PrevHandle) and not bSPECIALMODEL then
    22532253        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_MODELLIST'), pkNormal,
    22542254          0, hkModel + hkCrossLink, 0)
    22552255    end
    2256     else if h = hJOBHELP then
     2256    else if H = hJOBHELP then
    22572257    begin
    2258       if (i >= 0) and (h <> PrevHandle) and not bJOBHELP then
     2258      if (I >= 0) and (H <> PrevHandle) and not bJOBHELP then
    22592259        SearchResult.AddLine(HelpText.Lookup('HELPTITLE_JOBLIST'), pkNormal, 0,
    22602260          hkMisc + hkCrossLink, miscJobList)
    22612261    end
    2262     else if { (h<>hMAIN) and } (h <> PrevHandle) then
     2262    else if { (h<>hMAIN) and } (H <> PrevHandle) then
    22632263    begin
    2264       s := HelpText.LookupByHandle(h);
    2265       p := Pos('$', s);
    2266       if p > 0 then
     2264      S := HelpText.LookupByHandle(H);
     2265      P := Pos('$', S);
     2266      if P > 0 then
    22672267      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);
     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);
    22732273      end;
    22742274    end;
     
    22782278    RightMargin := InnerWidth - 16 - GetSystemMetrics(SM_CXVSCROLL);
    22792279    OffScreen.Canvas.Font.Assign(UniFont[ftNormal]);
    2280     for i := 0 to SearchResult.Count - 1 do
     2280    for I := 0 to SearchResult.Count - 1 do
    22812281    begin
    2282       while BiColorTextWidth(OffScreen.Canvas, SearchResult[i]) >
     2282      while BiColorTextWidth(OffScreen.Canvas, SearchResult[I]) >
    22832283        RightMargin - 32 do
    2284         SearchResult[i] := copy(SearchResult[i], 1, length(SearchResult[i]) - 1)
     2284        SearchResult[I] := Copy(SearchResult[I], 1, Length(SearchResult[I]) - 1)
    22852285    end;
    22862286  end;
  • trunk/LocalPlayer/IsoEngine.pas

    r442 r447  
    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: TBitmap;
     
    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: TBitmap);
    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: TBitmap; 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: TBitmap; 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] := PixelPointer(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;
     
    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       BitBltCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     375    for Y := -1 to 6 do
     376      BitBltCanvas(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       BitBltCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt,
     378    for Y := -2 to 6 do
     379      BitBltCanvas(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       BitBltCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2) + xxt, (y + 2) * yyt,
     382    for Y := -2 to 6 do
     383      BitBltCanvas(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       BitBltCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt, xxt,
     386    for Y := -2 to 6 do
     387      BitBltCanvas(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       BitBltCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2) + xxt, (y + 2) * yyt,
     389    for Y := -2 to 6 do
     390      BitBltCanvas(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       BitBltCanvas(LandMore.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     406    for X := -2 to 6 do
     407      BitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2), (Y + 2) * yyt,
    408408        xxt * 2, yyt, HGrTerrain.Data.Canvas, xSrc, ySrc);
    409     BitBltCanvas(LandMore.Canvas, xxt * 2, (y + 2) * yyt, xxt, yyt,
     409    BitBltCanvas(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       BitBltCanvas(LandMore.Canvas, (x + 2) * (xxt * 2) - xxt, (y + 2) * yyt,
     411    for X := 0 to 7 do
     412      BitBltCanvas(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       BitBltCanvas(LandMore.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     415    for X := -2 to 6 do
     416      BitBltCanvas(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         BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     426      if (X >= 1) = (Y >= 2) then
     427        BitBltCanvas(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         BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     431        BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    432432          HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt,
    433433          SRCPAINT);
    434         BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     434        BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt,
    435435          HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT);
    436436      end;
    437       BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     437      BitBltCanvas(OceanPatch.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    438438        DitherMask.Canvas, xxt, yyt, SRCAND);
    439       BitBltCanvas(OceanPatch.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     439      BitBltCanvas(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         BitBltCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     450      if (X < 1) or (Y >= 2) then
     451        BitBltCanvas(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         BitBltCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt, yyt,
     455        BitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt, yyt,
    456456          HGrTerrain.Data.Canvas, xSrc + xxt, ySrc + yyt,
    457457          SRCPAINT);
    458         BitBltCanvas(OceanMore.Canvas, x * (xxt * 2) + xxt, y * yyt, xxt, yyt,
     458        BitBltCanvas(OceanMore.Canvas, X * (xxt * 2) + xxt, Y * yyt, xxt, yyt,
    459459          HGrTerrain.Data.Canvas, xSrc, ySrc + yyt, SRCPAINT);
    460460      end;
    461       BitBltCanvas(OceanMore.Canvas, x * (xxt * 2), y * yyt, xxt * 2, yyt,
     461      BitBltCanvas(OceanMore.Canvas, X * (xxt * 2), Y * yyt, xxt * 2, yyt,
    462462        DitherMask.Canvas, 0, 0, SRCAND);
    463463    end;
     
    469469    HGrTerrain.Mask.Canvas, 1, 1 + yyt, SRCPAINT);
    470470
    471   for x := -1 to 6 do
    472     for y := -2 to 6 do
    473       BitBltCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), (y + 2) * yyt,
     471  for X := -1 to 6 do
     472    for Y := -2 to 6 do
     473      BitBltCanvas(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       BitBltCanvas(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      BitBltCanvas(LandMore.Canvas, (X + 2) * (xxt * 2) - xxt, (Y + 2) * yyt,
    479479        xxt * 2, yyt, DitherMask.Canvas, 0, yyt, SRCAND);
    480480
     
    482482    LandMore.Canvas, 0, 0, SRCPAINT);
    483483
    484   for x := 0 to 3 do
    485     for y := 0 to 3 do
    486       BitBltCanvas(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      BitBltCanvas(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       BitBltCanvas(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      BitBltCanvas(OceanMore.Canvas, X * (xxt * 2) - xxt, Y * yyt, xxt * 2,
    492492        yyt, DitherMask.Canvas, 0, yyt, SRCAND);
    493493
     
    502502    HGrTerrain.Mask.Canvas, 1, 1 + yyt);
    503503
    504   for x := 0 to 6 do
    505     BitBltCanvas(LandPatch.Canvas, (x + 2) * (xxt * 2), yyt, xxt * 2, yyt,
     504  for X := 0 to 6 do
     505    BitBltCanvas(LandPatch.Canvas, (X + 2) * (xxt * 2), yyt, xxt * 2, yyt,
    506506      DitherMask.Canvas, 0, 0, SRCAND);
    507507  BitBltCanvas(DitherMask.Canvas, 0, 0, xxt * 2, yyt, DitherMask.Canvas,
    508508    0, 0, DSTINVERT);
    509509
    510   for y := 0 to 6 do
    511     BitBltCanvas(LandPatch.Canvas, xxt * 2, (y + 2) * yyt, xxt * 2, yyt,
     510  for Y := 0 to 6 do
     511    BitBltCanvas(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: TBitmap; 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: TBitmap; 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   BitBltCanvas(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  BitBltCanvas(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;
     655    Exit;
    656656
    657657  BitBltCanvas(FOutput.Canvas, xDst, yDst, Width, Height, MaskCanvas, xSrc, ySrc, SRCAND);
     
    660660end;
    661661
    662 procedure TIsoMap.PaintUnit(x, y: integer; const UnitInfo: TUnitInfo;
    663   Status: integer);
    664 var
    665   xsh, ysh, xGr, yGr, j, mixShow: integer;
     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;
    721721end;
    722722
    723 procedure TIsoMap.PaintCity(x, y: integer; const CityInfo: TCityInfo;
    724   accessory: boolean);
     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;
    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);
     
    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;
    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;
    14261426  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;
     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;
  • trunk/LocalPlayer/LocalPlayer.pas

    r364 r447  
    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
     
    1414
    1515var
    16   FormsCreated: boolean;
     16  FormsCreated: Boolean;
    1717
    18 procedure Client(Command, Player: integer; var Data);
     18procedure Client(Command, Player: Integer; var Data);
    1919begin
    2020  if not FormsCreated then
    2121  begin
    22     FormsCreated := true;
     22    FormsCreated := True;
    2323    // TODO: Changing application name in runtime will cause change of Linux XML registry file path
    2424//    Application.MainForm := MainScreen;
     
    4545end;
    4646
    47 procedure SetAIName(p: integer; Name: string);
     47procedure SetAIName(P: Integer; Name: string);
    4848begin
    49   MainScreen.SetAIName(p, Name);
     49  MainScreen.SetAIName(P, Name);
    5050end;
    5151
    5252initialization
    5353
    54 FormsCreated := false;
     54FormsCreated := False;
    5555
    5656end.
  • trunk/LocalPlayer/MessgEx.pas

    r442 r447  
    3939    IconKind: TMessageIconKind;
    4040    OpenSound: string;
    41     function ShowModal: integer; override;
     41    function ShowModal: Integer; override;
    4242    procedure CancelMovie;
    4343  private
    44     MovieCancelled: boolean;
    45     procedure PaintBook(ca: TCanvas; x, y, clPage, clCover: integer);
     44    MovieCancelled: Boolean;
     45    procedure PaintBook(ca: TCanvas; X, Y, clPage, clCover: Integer);
    4646    procedure PaintMyArmy;
    4747    procedure PaintEnemyArmy;
     
    5353
    5454procedure SoundMessageEx(SimpleText, SoundItem: string);
    55 procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
     55procedure TribeMessage(P: Integer; SimpleText, SoundItem: string);
    5656function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string)
    57   : integer;
     57  : Integer;
    5858procedure ContextMessage(SimpleText, SoundItem: string;
    59   ContextKind, ContextNo: integer);
     59  ContextKind, ContextNo: Integer);
    6060
    6161
     
    8181procedure TMessgExDlg.FormShow(Sender: TObject);
    8282var
    83   i: integer;
     83  I: Integer;
    8484begin
    8585  if IconKind = mikEnemyArmy then
     
    150150  end;
    151151
    152   SplitText(true);
     152  SplitText(True);
    153153  ClientHeight := 72 + Border + TopSpace + Lines * MessageLineSpacing;
    154154  if GameMode = cMovie then
     
    181181      end;
    182182  end;
    183   for i := 0 to ControlCount - 1 do
    184     Controls[i].Top := ClientHeight - (34 + Border);
     183  for I := 0 to ControlCount - 1 do
     184    Controls[I].Top := ClientHeight - (34 + Border);
    185185  if Kind = mkModel then
    186186    EInput.Top := ClientHeight - (76 + Border);
    187187end;
    188188
    189 function TMessgExDlg.ShowModal: integer;
     189function TMessgExDlg.ShowModal: Integer;
    190190var
    191191  Ticks0: TDateTime;
     
    197197    if not((GameMode = cMovie) and (MovieSpeed = 4)) then
    198198    begin
    199       MovieCancelled := false;
     199      MovieCancelled := False;
    200200      Show;
    201201      Ticks0 := NowPrecise;
     
    207207      Hide;
    208208    end;
    209     result := mrOk;
     209    Result := mrOk;
    210210  end
    211211  else
    212     result := inherited;
     212    Result := inherited;
    213213  Gtk2Fix;
    214214end;
     
    216216procedure TMessgExDlg.CancelMovie;
    217217begin
    218   MovieCancelled := true;
    219 end;
    220 
    221 procedure TMessgExDlg.PaintBook(ca: TCanvas; x, y, clPage, clCover: integer);
     218  MovieCancelled := True;
     219end;
     220
     221procedure TMessgExDlg.PaintBook(ca: TCanvas; X, Y, clPage, clCover: Integer);
    222222const
    223223  xScrewed = 77;
     
    228228  TScrewed = array [0 .. wScrewed - 1, 0 .. hScrewed - 1, 0 .. 3] of Single;
    229229var
    230   ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: integer;
     230  ix, iy, xDst, yDst, dx, dy, xIcon, yIcon: Integer;
    231231  BookRect: TRect;
    232   x1, xR, yR, share: single;
     232  x1, xR, yR, share: Single;
    233233  Screwed: TScrewed;
    234234  SrcPtr: TPixelPointer;
     
    284284    BookRect := SmallBook.BoundsRect;
    285285  end;
    286   x := x - BookRect.Width div 2;
     286  X := X - BookRect.Width div 2;
    287287
    288288  // paint
    289289  UnshareBitmap(LogoBuffer);
    290   BitBltCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, x, y);
     290  BitBltCanvas(LogoBuffer.Canvas, 0, 0, BookRect.Width, BookRect.Height, ca, X, Y);
    291291
    292292  if IconIndex >= 0 then
     
    301301  ImageOp_BCC(LogoBuffer, Templates.Data, Point(0, 0), BookRect, clCover, clPage);
    302302
    303   BitBltCanvas(ca, x, y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0);
     303  BitBltCanvas(ca, X, Y, BookRect.Width, BookRect.Height, LogoBuffer.Canvas, 0, 0);
    304304end;
    305305
     
    310310procedure TMessgExDlg.PaintEnemyArmy;
    311311var
    312   emix, ix, iy, x, y, count, UnitsInLine: integer;
     312  emix, ix, iy, X, Y, count, UnitsInLine: Integer;
    313313begin
    314314  ix := 0;
     
    321321    for count := 0 to LostArmy[emix] - 1 do
    322322    begin
    323       x := ClientWidth div 2 + ix * 64 - UnitsInLine * 32;
    324       y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;
     323      X := ClientWidth div 2 + ix * 64 - UnitsInLine * 32;
     324      Y := 26 + Border + TopSpace + Lines * MessageLineSpacing + iy * 48;
    325325      with MyRO.EnemyModel[emix], Tribe[Owner].ModelPicture[mix] do
    326326      begin
    327         BitBltCanvas(Canvas, x, y, 64, 48, HGr.Mask.Canvas,
     327        BitBltCanvas(Canvas, X, Y, 64, 48, HGr.Mask.Canvas,
    328328          pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCAND);
    329         BitBltCanvas(Canvas, x, y, 64, 48, HGr.Data.Canvas,
     329        BitBltCanvas(Canvas, X, Y, 64, 48, HGr.Data.Canvas,
    330330          pix mod 10 * 65 + 1, pix div 10 * 49 + 1, SRCPAINT);
    331331      end;
    332332
    333333      // next position
    334       inc(ix);
     334      Inc(ix);
    335335      if ix = LostUnitsPerLine then
    336336      begin // next line
    337337        ix := 0;
    338         inc(iy);
     338        Inc(iy);
    339339        if iy = 6 then
    340           exit;
     340          Exit;
    341341        UnitsInLine := nLostArmy - LostUnitsPerLine * iy;
    342342        if UnitsInLine > LostUnitsPerLine then
     
    348348procedure TMessgExDlg.FormPaint(Sender: TObject);
    349349var
    350   p1, clSaveTextLight, clSaveTextShade: integer;
     350  p1, clSaveTextLight, clSaveTextShade: Integer;
    351351begin
    352352  if (IconKind = mikImp) and (IconIndex = 27) then
     
    394394      end;
    395395    mikModel:
    396       with Tribe[me].ModelPicture[IconIndex] do
     396      with Tribe[Me].ModelPicture[IconIndex] do
    397397      begin
    398398        FrameImage(Canvas, BigImp, ClientWidth div 2 - 28, 24, xSizeBig,
     
    498498end;
    499499
    500 procedure TribeMessage(p: integer; SimpleText, SoundItem: string);
     500procedure TribeMessage(P: Integer; SimpleText, SoundItem: string);
    501501begin
    502502  with MessgExDlg do
     
    506506    Kind := mkOk;
    507507    IconKind := mikTribe;
    508     IconIndex := p;
     508    IconIndex := P;
    509509    ShowModal;
    510510  end;
     
    512512
    513513function SimpleQuery(QueryKind: TMessageKind; SimpleText, SoundItem: string)
    514   : integer;
     514  : Integer;
    515515begin
    516516  with MessgExDlg do
     
    520520    Kind := QueryKind;
    521521    ShowModal;
    522     result := ModalResult;
     522    Result := ModalResult;
    523523  end;
    524524end;
    525525
    526526procedure ContextMessage(SimpleText, SoundItem: string;
    527   ContextKind, ContextNo: integer);
     527  ContextKind, ContextNo: Integer);
    528528begin
    529529  with MessgExDlg do
  • trunk/LocalPlayer/NatStat.pas

    r442 r447  
    2525    procedure ToggleBtnClick(Sender: TObject);
    2626    procedure PlayerClick(Sender: TObject);
    27     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     27    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    2828    procedure FormDestroy(Sender: TObject);
    2929    procedure ScrollUpBtnClick(Sender: TObject);
     
    3232  public
    3333    procedure CheckAge;
    34     procedure ShowNewContent(NewMode: TWindowMode; p: integer = -1);
     34    procedure ShowNewContent(NewMode: TWindowMode; P: Integer = -1);
    3535    procedure EcoChange;
    3636  protected
    3737    procedure OffscreenPaint; override;
    3838  private
    39     pView, AgePrepared, LinesDown: integer;
     39    pView, AgePrepared, LinesDown: Integer;
    4040    SelfReport, CurrentReport: PEnemyReport;
    41     ShowContact, ContactEnabled: boolean;
     41    ShowContact, ContactEnabled: Boolean;
    4242    Back, Template: TBitmap;
    4343    ReportText: TStringList;
     
    114114procedure TNatStatDlg.FormShow(Sender: TObject);
    115115begin
    116   if pView = me then
     116  if pView = Me then
    117117  begin
    118118    SelfReport.TurnOfCivilReport := MyRO.Turn;
    119119    SelfReport.TurnOfMilReport := MyRO.Turn;
    120     move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
     120    Move(MyRO.Treaty, SelfReport.Treaty, SizeOf(SelfReport.Treaty));
    121121    SelfReport.Government := MyRO.Government;
    122122    SelfReport.Money := MyRO.Money;
    123     CurrentReport := pointer(SelfReport);
     123    CurrentReport := Pointer(SelfReport);
    124124  end
    125125  else
    126     CurrentReport := pointer(MyRO.EnemyReport[pView]);
     126    CurrentReport := Pointer(MyRO.EnemyReport[pView]);
    127127  if CurrentReport.TurnOfCivilReport >= 0 then
    128128    GenerateReportText;
    129   ShowContact := (pView <> me) and (not supervising or (me <> 0));
    130   ContactEnabled := ShowContact and not supervising and
     129  ShowContact := (pView <> Me) and (not Supervising or (Me <> 0));
     130  ContactEnabled := ShowContact and not Supervising and
    131131    (1 shl pView and MyRO.Alive <> 0);
    132132  ContactBtn.Visible := ContactEnabled and (MyRO.Happened and phGameEnd = 0) and
     
    146146end;
    147147
    148 procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; p: integer);
    149 begin
    150   if p < 0 then
     148procedure TNatStatDlg.ShowNewContent(NewMode: TWindowMode; P: Integer);
     149begin
     150  if P < 0 then
    151151    if ClientMode >= scContact then
    152       pView := DipMem[me].pContact
     152      pView := DipMem[Me].pContact
    153153    else
    154154    begin
     
    156156      while (pView < nPl) and ((MyRO.Treaty[pView] < trNone) or
    157157        (1 shl pView and MyRO.Alive = 0)) do
    158         inc(pView);
     158        Inc(pView);
    159159      if pView >= nPl then
    160         pView := me;
     160        pView := Me;
    161161    end
    162162  else
    163     pView := p;
     163    pView := P;
    164164  inherited ShowNewContent(NewMode);
    165165end;
     
    174174  List: ^TChart;
    175175
    176   function StatText(no: integer): string;
     176  function StatText(no: Integer): string;
    177177  var
    178     i: integer;
     178    I: Integer;
    179179  begin
    180180    if (CurrentReport.TurnOfCivilReport >= 0) and
    181       (Server(sGetChart + no shl 4, me, pView, List^) >= rExecuted) then
     181      (Server(sGetChart + no shl 4, Me, pView, List^) >= rExecuted) then
    182182    begin
    183       i := List[CurrentReport.TurnOfCivilReport];
     183      I := List[CurrentReport.TurnOfCivilReport];
    184184      case no of
    185185        stPop:
    186           result := Format(Phrases.Lookup('FRSTATPOP'), [i]);
     186          Result := Format(Phrases.Lookup('FRSTATPOP'), [I]);
    187187        stTerritory:
    188           result := Format(Phrases.Lookup('FRSTATTER'), [i]);
     188          Result := Format(Phrases.Lookup('FRSTATTER'), [I]);
    189189        stScience:
    190           result := Format(Phrases.Lookup('FRSTATTECH'), [i div nAdv]);
     190          Result := Format(Phrases.Lookup('FRSTATTECH'), [I div nAdv]);
    191191        stExplore:
    192           result := Format(Phrases.Lookup('FRSTATEXP'),
    193             [i * 100 div (G.lx * G.ly)]);
     192          Result := Format(Phrases.Lookup('FRSTATEXP'),
     193            [I * 100 div (G.lx * G.ly)]);
    194194      end;
    195195    end
     
    197197
    198198var
    199   p1, Treaty: integer;
    200   s: string;
    201   HasContact, ExtinctPart: boolean;
     199  p1, Treaty: Integer;
     200  S: string;
     201  HasContact, ExtinctPart: Boolean;
    202202begin
    203203  GetMem(List, 4 * (MyRO.Turn + 2));
     
    208208    (1 shl pView and MyRO.Alive <> 0) then
    209209  begin
    210     s := Format(Phrases.Lookup('FROLDCIVILREP'),
     210    S := Format(Phrases.Lookup('FROLDCIVILREP'),
    211211      [TurnToString(CurrentReport.TurnOfCivilReport)]);
    212     ReportText.Add('C' + s);
     212    ReportText.Add('C' + S);
    213213    ReportText.Add('');
    214214  end;
     
    223223  ReportText.Add('S' + StatText(stScience));
    224224  ReportText.Add('E' + StatText(stExplore));
    225   HasContact := false;
     225  HasContact := False;
    226226  for p1 := 0 to nPl - 1 do
    227     if (p1 <> me) and (CurrentReport.Treaty[p1] > trNoContact) then
    228       HasContact := true;
     227    if (p1 <> Me) and (CurrentReport.Treaty[p1] > trNoContact) then
     228      HasContact := True;
    229229  if HasContact then
    230230  begin
    231231    ReportText.Add('');
    232232    ReportText.Add(' ' + Phrases.Lookup('FRRELATIONS'));
    233     for ExtinctPart := false to true do
     233    for ExtinctPart := False to True do
    234234      for Treaty := trAlliance downto trNone do
    235235        for p1 := 0 to nPl - 1 do
    236           if (p1 <> me) and (CurrentReport.Treaty[p1] = Treaty) and
     236          if (p1 <> Me) and (CurrentReport.Treaty[p1] = Treaty) and
    237237            ((1 shl p1 and MyRO.Alive = 0) = ExtinctPart) then
    238238          begin
    239             s := Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty));
     239            S := Tribe[p1].TString(Phrases.Lookup('HAVETREATY', Treaty));
    240240            if ExtinctPart then
    241               s := '(' + s + ')';
    242             ReportText.Add(char(48 + Treaty) + s);
     241              S := '(' + S + ')';
     242            ReportText.Add(char(48 + Treaty) + S);
    243243          end;
    244244  end;
     
    250250procedure TNatStatDlg.OffscreenPaint;
    251251var
    252   i, y: integer;
    253   s: string;
    254   ps: pchar;
    255   Extinct: boolean;
     252  I, Y: Integer;
     253  S: string;
     254  ps: PChar;
     255  Extinct: Boolean;
    256256
    257257begin
     
    260260  Extinct := 1 shl pView and MyRO.Alive = 0;
    261261
    262   BitBltCanvas(offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
     262  BitBltCanvas(Offscreen.Canvas, 0, 0, ClientWidth, ClientHeight,
    263263    Back.Canvas, 0, 0);
    264264
    265   offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    266   RisedTextout(offscreen.Canvas,
     265  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
     266  RisedTextout(Offscreen.Canvas,
    267267    40 { (ClientWidth-BiColorTextWidth(offscreen.canvas,caption)) div 2 } ,
    268268    7, Caption);
    269269
    270   offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    271 
    272   with offscreen do
     270  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
     271
     272  with Offscreen do
    273273  begin
    274274    // show leader picture
     
    276276    if Assigned(Tribe[pView].faceHGr) then
    277277    begin
    278       Dump(offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48,
     278      Dump(Offscreen, Tribe[pView].faceHGr, 18, yIcon - 4, 64, 48,
    279279        1 + Tribe[pView].facepix mod 10 * 65,
    280280        1 + Tribe[pView].facepix div 10 * 49);
    281       frame(offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48,
     281      frame(Offscreen.Canvas, 18 - 1, yIcon - 4 - 1, 18 + 64, yIcon - 4 + 48,
    282282        $000000, $000000);
    283283    end;
    284284
    285     if (pView = me) or not Extinct then
     285    if (pView = Me) or not Extinct then
    286286      LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib,
    287287        Phrases.Lookup('GOVERNMENT', CurrentReport.Government) +
    288288        Phrases.Lookup('FRAND'));
    289     if pView = me then
     289    if pView = Me then
    290290    begin
    291291      LoweredTextOut(Canvas, -1, MainTexture, xAttrib, yAttrib + 19,
     
    314314      if MyRO.Treaty[pView] = trNoContact then
    315315      begin
    316         s := Phrases.Lookup('FRNOCONTACT');
     316        S := Phrases.Lookup('FRNOCONTACT');
    317317        LoweredTextOut(Canvas, -1, MainTexture,
    318           (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, yRelation + 9, s);
     318          (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, yRelation + 9, S);
    319319      end
    320320      else if ShowContact then
     
    340340        FrameImage(Canvas, BigImp, xIcon, yIcon, xSizeBig, ySizeBig, 0, 200)
    341341        { else if CurrentReport.Government=gAnarchy then
    342           FrameImage(canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400,
     342          FrameImage(Canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,112,400,
    343343          ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact))
    344344          else
    345           FrameImage(canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,
     345          FrameImage(Canvas,BigImp,xIcon,yIcon,xSizeBig,ySizeBig,
    346346          56*(CurrentReport.Government-1),40,
    347347          ContactEnabled and (MyRO.Happened and phGameEnd=0) and (ClientMode<scContact)) };
     
    361361      end;
    362362
    363       y := 0;
    364       for i := 0 to ReportText.Count - 1 do
    365       begin
    366         if (i >= LinesDown) and (i < LinesDown + ReportLines) then
     363      Y := 0;
     364      for I := 0 to ReportText.Count - 1 do
     365      begin
     366        if (I >= LinesDown) and (I < LinesDown + ReportLines) then
    367367        begin
    368           s := ReportText[i];
    369           if s <> '' then
     368          S := ReportText[I];
     369          if S <> '' then
    370370          begin
    371371            // LineType:=s[1];
    372             delete(s, 1, 1);
     372            Delete(S, 1, 1);
    373373            BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkMisc, cliPaperText],
    374               $7F007F, xReport + 8, yReport + LineSpacing * y, s);
     374              $7F007F, xReport + 8, yReport + LineSpacing * Y, S);
    375375          end;
    376           inc(y);
     376          Inc(Y);
    377377        end;
    378378      end;
     
    380380    else
    381381    begin
    382       s := Phrases.Lookup('FRNOCIVILREP');
    383       RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, s)) div 2,
    384         yReport + hReport div 2 - 10, s);
     382      S := Phrases.Lookup('FRNOCIVILREP');
     383      RisedTextout(Canvas, (ClientWidth - BiColorTextWidth(Canvas, S)) div 2,
     384        yReport + hReport div 2 - 10, S);
    385385    end;
    386386
    387387    if soTellAI in OptionChecked then begin
    388       Server(sGetAIInfo, me, pView, ps);
     388      Server(sGetAIInfo, Me, pView, ps);
    389389      LoweredTextOut(Canvas, -1, MainTexture, 42, 445, ps);
    390390    end else
     
    392392        Phrases2.Lookup('MENU_TELLAI'));
    393393  end;
    394   ContactBtn.SetBack(offscreen.Canvas, ContactBtn.Left, ContactBtn.Top);
     394  ContactBtn.SetBack(Offscreen.Canvas, ContactBtn.Left, ContactBtn.Top);
    395395
    396396  MarkUsedOffscreen(ClientWidth, ClientHeight);
     
    404404procedure TNatStatDlg.DialogBtnClick(Sender: TObject);
    405405var
    406   ContactResult: integer;
     406  ContactResult: Integer;
    407407begin
    408408  ContactResult := MainScreen.DipCall(scContact + pView shl 4);
     
    412412      SoundMessage(Phrases.Lookup('FRCOLDWAR'), 'MSG_DEFAULT')
    413413    else if MyRO.Government = gAnarchy then
    414       SoundMessage(Tribe[me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT')
     414      SoundMessage(Tribe[Me].TPhrase('FRMYANARCHY'), 'MSG_DEFAULT')
    415415    else if ContactResult = eAnarchy then
    416416      if MyRO.Treaty[pView] >= trPeace then
     
    428428procedure TNatStatDlg.ToggleBtnClick(Sender: TObject);
    429429var
    430   p1, StartCount: integer;
    431   m: TMenuItem;
    432   ExtinctPart: boolean;
     430  p1, StartCount: Integer;
     431  M: TMenuItem;
     432  ExtinctPart: Boolean;
    433433begin
    434434  EmptyMenu(Popup.Items);
    435435
    436436  // own nation
    437   if G.Difficulty[me] <> 0 then
    438   begin
    439     m := TMenuItem.Create(Popup);
    440     m.RadioItem := true;
    441     m.Caption := Tribe[me].TPhrase('TITLE_NATION');
    442     m.Tag := me;
    443     m.OnClick := PlayerClick;
    444     if me = pView then
    445       m.Checked := true;
    446     Popup.Items.Add(m);
     437  if G.Difficulty[Me] <> 0 then
     438  begin
     439    M := TMenuItem.Create(Popup);
     440    M.RadioItem := True;
     441    M.Caption := Tribe[Me].TPhrase('TITLE_NATION');
     442    M.Tag := Me;
     443    M.OnClick := PlayerClick;
     444    if Me = pView then
     445      M.Checked := True;
     446    Popup.Items.Add(M);
    447447  end;
    448448
    449449  // foreign nations
    450   for ExtinctPart := false to true do
     450  for ExtinctPart := False to True do
    451451  begin
    452452    StartCount := Popup.Items.Count;
     
    456456        (1 shl p1 and MyRO.Alive <> 0) and (MyRO.Treaty[p1] >= trNone) then
    457457      begin
    458         m := TMenuItem.Create(Popup);
    459         m.RadioItem := true;
    460         m.Caption := Tribe[p1].TPhrase('TITLE_NATION');
     458        M := TMenuItem.Create(Popup);
     459        M.RadioItem := True;
     460        M.Caption := Tribe[p1].TPhrase('TITLE_NATION');
    461461        if ExtinctPart then
    462           m.Caption := '(' + m.Caption + ')';
    463         m.Tag := p1;
    464         m.OnClick := PlayerClick;
     462          M.Caption := '(' + M.Caption + ')';
     463        M.Tag := p1;
     464        M.OnClick := PlayerClick;
    465465        if p1 = pView then
    466           m.Checked := true;
    467         Popup.Items.Add(m);
     466          M.Checked := True;
     467        Popup.Items.Add(M);
    468468      end;
    469469    if (StartCount > 0) and (Popup.Items.Count > StartCount) then
    470470    begin // seperator
    471       m := TMenuItem.Create(Popup);
    472       m.Caption := '-';
    473       Popup.Items.Insert(StartCount, m);
     471      M := TMenuItem.Create(Popup);
     472      M.Caption := '-';
     473      Popup.Items.Insert(StartCount, M);
    474474    end;
    475475  end;
     
    478478end;
    479479
    480 procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: word;
     480procedure TNatStatDlg.FormKeyDown(Sender: TObject; var Key: Word;
    481481  Shift: TShiftState);
    482482var
    483   i: integer;
     483  I: Integer;
    484484begin
    485485  if Key = VK_F9 then // my key
    486486  begin // toggle nation
    487     i := 0;
     487    I := 0;
    488488    repeat
    489489      pView := (pView + 1) mod nPl;
    490       inc(i);
    491     until (i >= nPl) or (1 shl pView and MyRO.Alive <> 0) and
     490      Inc(I);
     491    until (I >= nPl) or (1 shl pView and MyRO.Alive <> 0) and
    492492      (MyRO.Treaty[pView] >= trNone);
    493     if i >= nPl then
    494       pView := me;
     493    if I >= nPl then
     494      pView := Me;
    495495    Tag := pView;
    496496    PlayerClick(self); // no, this is not nice
     
    502502procedure TNatStatDlg.EcoChange;
    503503begin
    504   if Visible and (pView = me) then
     504  if Visible and (pView = Me) then
    505505  begin
    506506    SelfReport.Government := MyRO.Government;
     
    514514  if LinesDown > 0 then
    515515  begin
    516     dec(LinesDown);
     516    Dec(LinesDown);
    517517    SmartUpdateContent;
    518518  end;
     
    523523  if LinesDown + ReportLines < ReportText.Count then
    524524  begin
    525     inc(LinesDown);
     525    Inc(LinesDown);
    526526    SmartUpdateContent;
    527527  end;
  • trunk/LocalPlayer/Nego.pas

    r442 r447  
    1515type
    1616  THistory = record
    17     n: Integer;
     17    N: Integer;
    1818    Text: array[0 .. MaxHistory - 1] of ansistring;
    1919  end;
     
    5959    procedure FormDestroy(Sender: TObject);
    6060    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    61       Shift: TShiftState; X, Y: integer);
     61      Shift: TShiftState; X, Y: Integer);
    6262    procedure OkBtnClick(Sender: TObject);
    6363    procedure BwdBtnClick(Sender: TObject);
     
    7878
    7979  private
    80     Page, DipCommand: integer;
     80    Page, DipCommand: Integer;
    8181    CurrentOffer: TOffer;
    8282    MyAllowed, OppoAllowed: TPriceSet;
     
    8484    History: array [0 .. nPl - 1] of THistory;
    8585    RomanFont: TFont;
    86     Costs, Delivers: array [0 .. 11] of cardinal;
     86    Costs, Delivers: array [0 .. 11] of Cardinal;
    8787    procedure ResetCurrentOffer;
    8888    procedure BuildCurrentOffer;
    8989    procedure FindAllowed;
    9090    procedure SplitText(Text: string; Bounds: TRect);
    91     procedure PaintNationPicture(X, Y, p: integer);
     91    procedure PaintNationPicture(X, Y, P: Integer);
    9292    procedure SetButtonStates;
    9393  end;
     
    183183procedure TNegoDlg.ResetCurrentOffer;
    184184var
    185   i: integer;
     185  I: Integer;
    186186begin
    187187  CurrentOffer.nDeliver := 0;
    188188  CurrentOffer.nCost := 0;
    189   for i := 0 to 11 do
    190     Costs[i] := $FFFFFFFF;
    191   for i := 0 to 11 do
    192     Delivers[i] := $FFFFFFFF;
     189  for I := 0 to 11 do
     190    Costs[I] := $FFFFFFFF;
     191  for I := 0 to 11 do
     192    Delivers[I] := $FFFFFFFF;
    193193end;
    194194
     
    201201  else
    202202    PassBtn.SmartHint := Phrases.Lookup('BTN_PASS');
    203   case MyRO.Treaty[DipMem[me].pContact] of
     203  case MyRO.Treaty[DipMem[Me].pContact] of
    204204    trNone:
    205205      begin
     
    237237begin
    238238  if ClientMode <> scDipStart then
    239     with History[me] do
    240     begin
    241       if n = MaxHistory then
    242       begin
    243         move(Text[2], Text[0], (MaxHistory - 2) * sizeof(integer));
    244         dec(n, 2);
     239    with History[Me] do
     240    begin
     241      if N = MaxHistory then
     242      begin
     243        Move(Text[2], Text[0], (MaxHistory - 2) * SizeOf(Integer));
     244        Dec(N, 2);
    245245      end;
    246       Text[n] := copy(DipCommandToString(DipMem[me].pContact, me,
    247         DipMem[me].FormerTreaty, DipMem[me].SentCommand, ClientMode,
    248         DipMem[me].SentOffer, ReceivedOffer), 1, 255);
    249       inc(n);
     246      Text[N] := Copy(DipCommandToString(DipMem[Me].pContact, Me,
     247        DipMem[Me].FormerTreaty, DipMem[Me].SentCommand, ClientMode,
     248        DipMem[Me].SentOffer, ReceivedOffer), 1, 255);
     249      Inc(N);
    250250    end;
    251   assert(History[me].n mod 2 = 1);
    252 
    253   Page := History[me].n;
     251  Assert(History[Me].N mod 2 = 1);
     252
     253  Page := History[Me].N;
    254254  FindAllowed;
    255255  ResetCurrentOffer;
     
    283283procedure TNegoDlg.SplitText(Text: string; Bounds: TRect);
    284284var
    285   nLines, Line, Start, Stop, OrdinaryStop, Indent, Y: integer;
    286   s: string;
    287   preview, Dot: boolean;
     285  nLines, Line, Start, Stop, OrdinaryStop, Indent, Y: Integer;
     286  S: string;
     287  preview, Dot: Boolean;
    288288begin
    289289  nLines := 0;
    290   for preview := true downto false do
     290  for preview := True downto False do
    291291  begin
    292292    Start := 1;
     
    295295    while Start < Length(Text) do
    296296    begin
    297       Dot := false;
     297      Dot := False;
    298298      if (Start = 1) or (Text[Start - 1] = '\') then
    299299        if Text[Start] = '-' then
    300300        begin
    301301          Indent := ListIndent;
    302           inc(Start);
     302          Inc(Start);
    303303          if Start = Length(Text) then
    304             break;
    305           Dot := true;
     304            Break;
     305          Dot := True;
    306306        end
    307307        else
     
    310310      while (Stop < Length(Text)) and (Text[Stop] <> '\') do
    311311      begin
    312         inc(Stop);
     312        Inc(Stop);
    313313        if BiColorTextWidth(Offscreen.Canvas,
    314           copy(Text, Start, Stop - Start + 1)) > Bounds.Right - Bounds.Left -
     314          Copy(Text, Start, Stop - Start + 1)) > Bounds.Right - Bounds.Left -
    315315          PaperBorder_Left - PaperBorder_Right - Indent then
    316316        begin
    317           dec(Stop);
    318           break
     317          Dec(Stop);
     318          Break
    319319        end;
    320320      end;
     
    324324        while (Text[OrdinaryStop + 1] <> ' ') and
    325325          (Text[OrdinaryStop + 1] <> '\') do
    326           dec(OrdinaryStop);
     326          Dec(OrdinaryStop);
    327327        if (OrdinaryStop + 1 - Start) * 2 >= Stop - Start then
    328328          Stop := OrdinaryStop
     
    334334          Sprite(Offscreen, HGrSystem, Bounds.Left + PaperBorder_Left +
    335335            (ListIndent - 14), Y + 7, 8, 8, 90, 16);
    336         s := copy(Text, Start, Stop - Start + 1);
     336        S := Copy(Text, Start, Stop - Start + 1);
    337337        BiColorTextOut(Offscreen.Canvas, Colors.Canvas.Pixels[clkMisc,
    338338          cliPaperText], $7F007F, Bounds.Left + PaperBorder_Left +
    339           Indent, Y, s);
     339          Indent, Y, S);
    340340      end;
    341       inc(Line);
     341      Inc(Line);
    342342      Start := Stop + 2;
    343343    end;
     
    348348procedure TNegoDlg.FindAllowed;
    349349var
    350   i: integer;
     350  I: Integer;
    351351begin
    352352  CommandAllowed := [scDipOffer - scDipStart];
    353353  if ClientMode <> scDipBreak then
    354     include(CommandAllowed, scDipBreak - scDipStart);
    355   if MyRO.Treaty[DipMem[me].pContact] >= trPeace then
    356     include(CommandAllowed, scDipCancelTreaty - scDipStart);
    357   if (ClientMode = scDipOffer) and (Server(scDipAccept - sExecute, me, 0, nil^)
     354    Include(CommandAllowed, scDipBreak - scDipStart);
     355  if MyRO.Treaty[DipMem[Me].pContact] >= trPeace then
     356    Include(CommandAllowed, scDipCancelTreaty - scDipStart);
     357  if (ClientMode = scDipOffer) and (Server(scDipAccept - sExecute, Me, 0, nil^)
    358358    >= rExecuted) then
    359     include(CommandAllowed, scDipAccept - scDipStart);
     359    Include(CommandAllowed, scDipAccept - scDipStart);
    360360
    361361  MyAllowed := [opChoose shr 24, opMoney shr 24];
    362362  OppoAllowed := [opChoose shr 24, opMoney shr 24];
    363   if not IsCivilReportNew(DipMem[me].pContact) then
     363  if not IsCivilReportNew(DipMem[Me].pContact) then
    364364  begin // no up-to-date civil report
    365365    MyAllowed := MyAllowed + [opCivilReport shr 24];
    366     for i := 0 to nAdv - 1 do
    367       if MyRO.Tech[i] >= tsApplicable then
     366    for I := 0 to nAdv - 1 do
     367      if MyRO.Tech[I] >= tsApplicable then
    368368      begin
    369369        MyAllowed := MyAllowed + [opAllTech shr 24];
    370         break
     370        Break
    371371      end;
    372372    OppoAllowed := OppoAllowed + [opCivilReport shr 24, opAllTech shr 24];
     
    374374  else
    375375  begin // check techs
    376     for i := 0 to nAdv - 1 do
    377       if not(i in FutureTech) then
    378         if (MyRO.Tech[i] < tsSeen) and
    379           (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] >= tsApplicable) then
     376    for I := 0 to nAdv - 1 do
     377      if not(I in FutureTech) then
     378        if (MyRO.Tech[I] < tsSeen) and
     379          (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] >= tsApplicable) then
    380380          OppoAllowed := OppoAllowed + [opAllTech shr 24]
    381         else if (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] < tsSeen) and
    382           (MyRO.Tech[i] >= tsApplicable) then
     381        else if (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] < tsSeen) and
     382          (MyRO.Tech[I] >= tsApplicable) then
    383383          MyAllowed := MyAllowed + [opAllTech shr 24];
    384384  end;
    385   if not IsMilReportNew(DipMem[me].pContact) then
     385  if not IsMilReportNew(DipMem[Me].pContact) then
    386386  begin // no up-to-date military report
    387387    MyAllowed := MyAllowed + [opMilReport shr 24];
     
    397397      OppoAllowed := OppoAllowed + [opAllModel shr 24];
    398398  end;
    399   if MyRO.Treaty[DipMem[me].pContact] < trAlliance then
     399  if MyRO.Treaty[DipMem[Me].pContact] < trAlliance then
    400400  begin
    401401    MyAllowed := MyAllowed + [opTreaty shr 24, opMap shr 24];
     
    407407    OppoAllowed:=OppoAllowed+[opLowTreaty shr 24];
    408408    end; }
    409   for i := 0 to nShipPart - 1 do
    410   begin
    411     if MyRO.Ship[me].Parts[i] > 0 then
    412       include(MyAllowed, opShipParts shr 24);
    413     if MyRO.Ship[DipMem[me].pContact].Parts[i] > 0 then
    414       include(OppoAllowed, opShipParts shr 24);
    415   end;
    416   MyAllowed := MyAllowed - DipMem[me].DeliveredPrices *
     409  for I := 0 to nShipPart - 1 do
     410  begin
     411    if MyRO.Ship[Me].Parts[I] > 0 then
     412      Include(MyAllowed, opShipParts shr 24);
     413    if MyRO.Ship[DipMem[Me].pContact].Parts[I] > 0 then
     414      Include(OppoAllowed, opShipParts shr 24);
     415  end;
     416  MyAllowed := MyAllowed - DipMem[Me].DeliveredPrices *
    417417    [opAllTech shr 24, opAllModel shr 24, opCivilReport shr 24,
    418418    opMilReport shr 24, opMap shr 24];
    419   OppoAllowed := OppoAllowed - DipMem[me].ReceivedPrices *
     419  OppoAllowed := OppoAllowed - DipMem[Me].ReceivedPrices *
    420420    [opAllTech shr 24, opAllModel shr 24, opCivilReport shr 24,
    421421    opMilReport shr 24, opMap shr 24];
    422422end;
    423423
    424 procedure TNegoDlg.PaintNationPicture(X, Y, p: integer);
     424procedure TNegoDlg.PaintNationPicture(X, Y, P: Integer);
    425425begin
    426426  with Offscreen.Canvas do
    427427  begin
    428428    Pen.Color := $000000;
    429     Brush.Color := Tribe[p].Color;
     429    Brush.Color := Tribe[P].Color;
    430430    Rectangle(X - 6, Y - 1, X + 70, Y + 49);
    431431    Brush.Color := $000000;
    432     Tribe[p].InitAge(GetAge(p));
    433     if Assigned(Tribe[p].faceHGr) then
    434       Dump(Offscreen, Tribe[p].faceHGr, X, Y, 64, 48,
    435         1 + Tribe[p].facepix mod 10 * 65, 1 + Tribe[p].facepix div 10 * 49)
     432    Tribe[P].InitAge(GetAge(P));
     433    if Assigned(Tribe[P].faceHGr) then
     434      Dump(Offscreen, Tribe[P].faceHGr, X, Y, 64, 48,
     435        1 + Tribe[P].facepix mod 10 * 65, 1 + Tribe[P].facepix div 10 * 49)
    436436    else
    437437      FillRect(Rect(X, Y, X + 64, Y + 48));
     
    443443procedure TNegoDlg.SetButtonStates;
    444444var
    445   cix: integer;
    446   IsActionPage: boolean;
    447 begin
    448   IsActionPage := Page = History[me].n;
     445  cix: Integer;
     446  IsActionPage: Boolean;
     447begin
     448  IsActionPage := Page = History[Me].N;
    449449
    450450  AcceptBtn.Possible := IsActionPage and
     
    483483procedure TNegoDlg.OffscreenPaint;
    484484var
    485   i, cred: integer;
    486   s: string;
    487   OkEnabled: boolean;
     485  I, cred: Integer;
     486  S: string;
     487  OkEnabled: Boolean;
    488488begin
    489489  if (OffscreenUser <> nil) and (OffscreenUser <> self) then
     
    492492  OffscreenUser := self;
    493493
    494   if (DipCommand >= 0) and (Page = History[me].n) then
    495     History[me].Text[History[me].n] :=
    496       copy(DipCommandToString(me, DipMem[me].pContact,
    497       MyRO.Treaty[DipMem[me].pContact], ClientMode, DipCommand, ReceivedOffer,
     494  if (DipCommand >= 0) and (Page = History[Me].N) then
     495    History[Me].Text[History[Me].N] :=
     496      Copy(DipCommandToString(Me, DipMem[Me].pContact,
     497      MyRO.Treaty[DipMem[Me].pContact], ClientMode, DipCommand, ReceivedOffer,
    498498      CurrentOffer), 1, 255);
    499499
    500   FwdBtn.Visible := Page < History[me].n;
     500  FwdBtn.Visible := Page < History[Me].N;
    501501  BwdBtn.Visible := Page >= 2;
    502   if Page < History[me].n then
    503     OkEnabled := false
     502  if Page < History[Me].N then
     503    OkEnabled := False
    504504  else if DipCommand = scDipOffer then
    505     OkEnabled := Server(scDipOffer - sExecute, me, 0, CurrentOffer) >= rExecuted
     505    OkEnabled := Server(scDipOffer - sExecute, Me, 0, CurrentOffer) >= rExecuted
    506506  else
    507507    OkEnabled := DipCommand >= 0;
     
    532532    yPad1 + 41 + 42 * 2, $FFFFFF, $B0B0B0);
    533533
    534   PaintNationPicture(xNationPicture0, yNationPicture, DipMem[me].pContact);
    535   PaintNationPicture(xNationPicture1, yNationPicture, me);
    536 
    537   if History[me].Text[Page - 1] <> '' then
     534  PaintNationPicture(xNationPicture0, yNationPicture, DipMem[Me].pContact);
     535  PaintNationPicture(xNationPicture1, yNationPicture, Me);
     536
     537  if History[Me].Text[Page - 1] <> '' then
    538538  begin
    539539    FillSeamless(Offscreen.Canvas, xText0, yText0, wText, hText, 0, 0, Paper);
    540     i := Page - 1;
    541     if History[me].Text[0] = '' then
    542       dec(i);
    543     if i < 16 then
     540    I := Page - 1;
     541    if History[Me].Text[0] = '' then
     542      Dec(I);
     543    if I < 16 then
    544544    begin
    545545      Offscreen.Canvas.Font.Assign(RomanFont);
    546546      Offscreen.Canvas.TextOut
    547         (xText0 + (wText - Offscreen.Canvas.TextWidth(RomanNo[i])) div 2,
    548         yText0 + (hText - Offscreen.Canvas.TextHeight(RomanNo[i])) div 2,
    549         RomanNo[i]);
     547        (xText0 + (wText - Offscreen.Canvas.TextWidth(RomanNo[I])) div 2,
     548        yText0 + (hText - Offscreen.Canvas.TextHeight(RomanNo[I])) div 2,
     549        RomanNo[I]);
    550550    end
    551551  end;
    552552  FillSeamless(Offscreen.Canvas, xText1, yText1, wText, hText, 0, 0, Paper);
    553   i := Page;
    554   if History[me].Text[0] = '' then
    555     dec(i);
    556   if i < 16 then
     553  I := Page;
     554  if History[Me].Text[0] = '' then
     555    Dec(I);
     556  if I < 16 then
    557557  begin
    558558    Offscreen.Canvas.Font.Assign(RomanFont);
    559559    Offscreen.Canvas.TextOut
    560       (xText1 + (wText - Offscreen.Canvas.TextWidth(RomanNo[i])) div 2,
    561       yText1 + (hText - Offscreen.Canvas.TextHeight(RomanNo[i])) div 2,
    562       RomanNo[i]);
     560      (xText1 + (wText - Offscreen.Canvas.TextWidth(RomanNo[I])) div 2,
     561      yText1 + (hText - Offscreen.Canvas.TextHeight(RomanNo[I])) div 2,
     562      RomanNo[I]);
    563563  end;
    564564  with Offscreen.Canvas do
    565565  begin
    566566    Brush.Color := MainTexture.ColorBevelShade;
    567     if History[me].Text[Page - 1] <> '' then
     567    if History[Me].Text[Page - 1] <> '' then
    568568    begin
    569569      FillRect(Rect(xText0 + wText, yText0 + PaperShade,
     
    583583  { if Page=History[me].n then
    584584    begin // show attitude
    585     s:=Phrases.Lookup('ATTITUDE',MyRO.EnemyReport[DipMem[me].pContact].Attitude);
     585    S:=Phrases.Lookup('ATTITUDE',MyRO.EnemyReport[DipMem[Me].pContact].Attitude);
    586586    //LoweredTextOut(Offscreen.Canvas,-1,MainTexture,
    587587    RisedTextOut(Offscreen.Canvas,xText0+wText div 2-
    588     BiColorTextWidth(Offscreen.Canvas,s) div 2,yAttitude,s);
    589     s:=Phrases.Lookup('ATTITUDE',MyRO.Attitude[DipMem[me].pContact]);
     588    BiColorTextWidth(Offscreen.Canvas,S) div 2,yAttitude,S);
     589    S:=Phrases.Lookup('ATTITUDE',MyRO.Attitude[DipMem[Me].pContact]);
    590590    //LoweredTextOut(Offscreen.Canvas,-1,MainTexture,
    591591    RisedTextOut(Offscreen.Canvas,xText1+wText div 2-
    592     BiColorTextWidth(Offscreen.Canvas,s) div 2,yAttitude,s);
     592    BiColorTextWidth(Offscreen.Canvas,S) div 2,yAttitude,S);
    593593    end; }
    594594
    595   if History[me].Text[Page - 1] <> '' then
    596     SplitText(History[me].Text[Page - 1], Rect(xText0, yText0, xText0 + wText,
     595  if History[Me].Text[Page - 1] <> '' then
     596    SplitText(History[Me].Text[Page - 1], Rect(xText0, yText0, xText0 + wText,
    597597      yText0 + hText));
    598   if (Page < History[me].n) or OkEnabled then
    599     SplitText(History[me].Text[Page], Rect(xText1, yText1, xText1 + wText,
     598  if (Page < History[Me].N) or OkEnabled then
     599    SplitText(History[Me].Text[Page], Rect(xText1, yText1, xText1 + wText,
    600600      yText1 + hText));
    601601
    602602  // show credibility
    603603  Offscreen.Canvas.Font.Assign(UniFont[ftTiny]);
    604   cred := MyRO.EnemyReport[DipMem[me].pContact].Credibility;
     604  cred := MyRO.EnemyReport[DipMem[Me].pContact].Credibility;
    605605  case cred of
    606606    0 .. 49:
    607       i := 3;
     607      I := 3;
    608608    50 .. 90:
    609       i := 0;
     609      I := 0;
    610610    91 .. 100:
    611       i := 1;
    612   end;
    613   PaintProgressBar(Offscreen.Canvas, i, xCred0, yCred0 + 17, (cred + 2) div 5,
     611      I := 1;
     612  end;
     613  PaintProgressBar(Offscreen.Canvas, I, xCred0, yCred0 + 17, (cred + 2) div 5,
    614614    0, 20, MainTexture);
    615   s := IntToStr(cred);
     615  S := IntToStr(cred);
    616616  RisedTextOut(Offscreen.Canvas, xCred0 + 10 -
    617     (BiColorTextWidth(Offscreen.Canvas, s) + 1) div 2, yCred0, s);
     617    (BiColorTextWidth(Offscreen.Canvas, S) + 1) div 2, yCred0, S);
    618618  case MyRO.Credibility of
    619619    0 .. 49:
    620       i := 3;
     620      I := 3;
    621621    50 .. 90:
    622       i := 0;
     622      I := 0;
    623623    91 .. 100:
    624       i := 1;
    625   end;
    626   PaintProgressBar(Offscreen.Canvas, i, xCred1, yCred1 + 17,
     624      I := 1;
     625  end;
     626  PaintProgressBar(Offscreen.Canvas, I, xCred1, yCred1 + 17,
    627627    (MyRO.Credibility + 2) div 5, 0, 20, MainTexture);
    628   s := IntToStr(MyRO.Credibility);
     628  S := IntToStr(MyRO.Credibility);
    629629  RisedTextOut(Offscreen.Canvas, xCred1 + 10 -
    630     (BiColorTextWidth(Offscreen.Canvas, s) + 1) div 2, yCred1, s);
     630    (BiColorTextWidth(Offscreen.Canvas, S) + 1) div 2, yCred1, S);
    631631
    632632  MarkUsedOffscreen(ClientWidth, ClientHeight);
     
    635635procedure TNegoDlg.Initiate;
    636636begin
    637   History[me].n := 1;
    638   History[me].Text[0] := '';
     637  History[Me].N := 1;
     638  History[Me].Text[0] := '';
    639639end;
    640640
    641641procedure TNegoDlg.Respond;
    642642begin
    643   History[me].n := 0;
     643  History[Me].N := 0;
    644644end;
    645645
    646646procedure TNegoDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
    647   Shift: TShiftState; X, Y: integer);
     647  Shift: TShiftState; X, Y: Integer);
    648648begin
    649649  if (X >= xNationPicture0) and (X < xNationPicture0 + 64) and
    650650    (Y >= yNationPicture) and (Y < yNationPicture + 48) then
    651     NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), DipMem[me].pContact)
     651    NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), DipMem[Me].pContact)
    652652  else if (X >= xNationPicture1) and (X < xNationPicture1 + 64) and
    653653    (Y >= yNationPicture) and (Y < yNationPicture + 48) then
    654     NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), me)
     654    NatStatDlg.ShowNewContent(WindowModeMakePersistent(FWindowMode), Me)
    655655end;
    656656
    657657procedure TNegoDlg.BwdBtnClick(Sender: TObject);
    658658begin
    659   dec(Page, 2);
     659  Dec(Page, 2);
    660660  SetButtonStates;
    661661  SmartUpdateContent;
     
    664664procedure TNegoDlg.FwdBtnClick(Sender: TObject);
    665665begin
    666   inc(Page, 2);
     666  Inc(Page, 2);
    667667  SetButtonStates;
    668668  SmartUpdateContent;
     
    671671procedure TNegoDlg.OkBtnClick(Sender: TObject);
    672672begin
    673   inc(History[me].n);
     673  Inc(History[Me].N);
    674674  if DipCommand = scDipOffer then
    675675    MainScreen.OfferCall(CurrentOffer)
     
    697697procedure TNegoDlg.BuildCurrentOffer;
    698698var
    699   i: integer;
     699  I: Integer;
    700700begin
    701701  CurrentOffer.nDeliver := 0;
    702702  CurrentOffer.nCost := 0;
    703   for i := 0 to 11 do
    704     if Delivers[i] <> $FFFFFFFF then
    705     begin
    706       CurrentOffer.Price[CurrentOffer.nDeliver] := Delivers[i];
    707       inc(CurrentOffer.nDeliver);
     703  for I := 0 to 11 do
     704    if Delivers[I] <> $FFFFFFFF then
     705    begin
     706      CurrentOffer.Price[CurrentOffer.nDeliver] := Delivers[I];
     707      Inc(CurrentOffer.nDeliver);
    708708    end;
    709   for i := 0 to 11 do
    710     if Costs[i] <> $FFFFFFFF then
     709  for I := 0 to 11 do
     710    if Costs[I] <> $FFFFFFFF then
    711711    begin
    712712      CurrentOffer.Price[CurrentOffer.nDeliver + CurrentOffer.nCost] :=
    713         Costs[i];
    714       inc(CurrentOffer.nCost);
     713        Costs[I];
     714      Inc(CurrentOffer.nCost);
    715715    end;
    716716end;
     
    718718procedure TNegoDlg.WantClick(Sender: TObject);
    719719var
    720   a, i, max: integer;
    721   Price: cardinal;
    722 begin
    723   if (Page <> History[me].n) or (ClientMode = scDipCancelTreaty) or
     720  A, I, Max: Integer;
     721  Price: Cardinal;
     722begin
     723  if (Page <> History[Me].N) or (ClientMode = scDipCancelTreaty) or
    724724    (ClientMode = scDipBreak) then
    725     exit;
     725    Exit;
    726726  if Costs[TButtonN(Sender).Tag and $FF] <> $FFFFFFFF then
    727727    Price := $FFFFFFFF // toggle off
     
    731731    begin
    732732      SimpleMessage(Phrases.Lookup('MAX2WANTS'));
    733       exit
     733      Exit
    734734    end;
    735735    Price := ButtonPrice[TButtonN(Sender).Tag and $FF];
    736736    if not(Price shr 24 in OppoAllowed) then
    737       exit;
     737      Exit;
    738738    case Price of
    739739      opCivilReport, opMilReport:
    740         inc(Price, DipMem[me].pContact shl 16 + MyRO.Turn);
     740        Inc(Price, DipMem[Me].pContact shl 16 + MyRO.Turn);
    741741        // !!! choose player and year!
    742742      opMoney:
     
    747747          InputDlg.ShowModal;
    748748          if InputDlg.ModalResult <> mrOK then
    749             exit;
    750           val(InputDlg.EInput.Text, a, i);
    751           if (i <> 0) or (a <= 0) or (a >= MaxMoneyPrice) then
    752             exit;
    753           inc(Price, a);
     749            Exit;
     750          val(InputDlg.EInput.Text, A, I);
     751          if (I <> 0) or (A <= 0) or (A >= MaxMoneyPrice) then
     752            Exit;
     753          Inc(Price, A);
    754754        end;
    755755      opShipParts:
     
    765765              ShowModal;
    766766              if ModalResult <> mrOK then
    767                 exit
     767                Exit
    768768            end;
    769769          ModalSelectDlg.ShowNewContent(wmModal, kEShipPart);
    770           if ModalSelectDlg.result < 0 then
    771             exit;
    772           inc(Price, ModalSelectDlg.result shl 16);
    773           max := MyRO.Ship[DipMem[me].pContact].Parts[ModalSelectDlg.result];
     770          if ModalSelectDlg.Result < 0 then
     771            Exit;
     772          Inc(Price, ModalSelectDlg.Result shl 16);
     773          Max := MyRO.Ship[DipMem[Me].pContact].Parts[ModalSelectDlg.Result];
    774774          InputDlg.Caption := Phrases.Lookup('TITLE_NUMBER');
    775775          InputDlg.EInput.Text := '';
     
    777777          InputDlg.ShowModal;
    778778          if InputDlg.ModalResult <> mrOK then
    779             exit;
    780           val(InputDlg.EInput.Text, a, i);
    781           if (i <> 0) or (a <= 0) then
    782             exit;
    783           if a > max then
    784             a := max;
    785           if a > MaxShipPartPrice then
    786             a := MaxShipPartPrice;
    787           inc(Price, a);
     779            Exit;
     780          val(InputDlg.EInput.Text, A, I);
     781          if (I <> 0) or (A <= 0) then
     782            Exit;
     783          if A > Max then
     784            A := Max;
     785          if A > MaxShipPartPrice then
     786            A := MaxShipPartPrice;
     787          Inc(Price, A);
    788788        end;
    789789      opAllTech:
    790790        begin // choose technology
    791791          ModalSelectDlg.ShowNewContent(wmModal, kChooseETech);
    792           if ModalSelectDlg.result < 0 then
    793             exit;
    794           if ModalSelectDlg.result = adAll then
     792          if ModalSelectDlg.Result < 0 then
     793            Exit;
     794          if ModalSelectDlg.Result = adAll then
    795795            Price := opAllTech
    796796          else
    797             Price := OpTech + ModalSelectDlg.result;
     797            Price := OpTech + ModalSelectDlg.Result;
    798798        end;
    799799      opAllModel:
    800800        begin // choose model
    801801          ModalSelectDlg.ShowNewContent(wmModal, kChooseEModel);
    802           if ModalSelectDlg.result < 0 then
    803             exit;
    804           if ModalSelectDlg.result = mixAll then
     802          if ModalSelectDlg.Result < 0 then
     803            Exit;
     804          if ModalSelectDlg.Result = mixAll then
    805805            Price := opAllModel
    806806          else
    807             Price := OpModel + MyRO.EnemyModel[ModalSelectDlg.result].mix;
     807            Price := OpModel + MyRO.EnemyModel[ModalSelectDlg.Result].mix;
    808808        end;
    809809      opTreaty:
    810810        begin
    811           if MyRO.Treaty[DipMem[me].pContact] < trPeace then
     811          if MyRO.Treaty[DipMem[Me].pContact] < trPeace then
    812812            Price := opTreaty + trPeace
    813813          else
    814             Price := opTreaty + MyRO.Treaty[DipMem[me].pContact] + 1;
     814            Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact] + 1;
    815815        end;
    816816      { opLowTreaty:
    817817        begin
    818         if MyRO.Treaty[DipMem[me].pContact]=trNone then Price:=opTreaty+trCeaseFire
    819         else Price:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;
     818        if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire
     819        else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
    820820        end }
    821821    end;
     
    831831procedure TNegoDlg.OfferClick(Sender: TObject);
    832832var
    833   a, i, max: integer;
    834   Price: cardinal;
    835 begin
    836   if (Page <> History[me].n) or (ClientMode = scDipCancelTreaty) or
     833  A, I, Max: Integer;
     834  Price: Cardinal;
     835begin
     836  if (Page <> History[Me].N) or (ClientMode = scDipCancelTreaty) or
    837837    (ClientMode = scDipBreak) then
    838     exit;
     838    Exit;
    839839  if Delivers[TButtonN(Sender).Tag and $FF] <> $FFFFFFFF then
    840840    Price := $FFFFFFFF // toggle off
     
    844844    begin
    845845      SimpleMessage(Phrases.Lookup('MAX2OFFERS'));
    846       exit;
     846      Exit;
    847847    end;
    848848    Price := ButtonPrice[TButtonN(Sender).Tag and $FF];
    849849    if not(Price shr 24 in MyAllowed) then
    850       exit;
     850      Exit;
    851851    case Price of
    852852      opCivilReport, opMilReport:
    853         inc(Price, me shl 16 + MyRO.Turn); // !!! choose player and year!
     853        Inc(Price, Me shl 16 + MyRO.Turn); // !!! choose player and year!
    854854      opMoney:
    855855        begin // choose amount
     
    859859          InputDlg.ShowModal;
    860860          if InputDlg.ModalResult <> mrOK then
    861             exit;
    862           val(InputDlg.EInput.Text, a, i);
    863           if (i <> 0) or (a <= 0) or (a >= MaxMoneyPrice) then
    864             exit;
    865           if (Price = opMoney) and (a > MyRO.Money) then
    866             a := MyRO.Money;
    867           inc(Price, a);
     861            Exit;
     862          val(InputDlg.EInput.Text, A, I);
     863          if (I <> 0) or (A <= 0) or (A >= MaxMoneyPrice) then
     864            Exit;
     865          if (Price = opMoney) and (A > MyRO.Money) then
     866            A := MyRO.Money;
     867          Inc(Price, A);
    868868        end;
    869869      opShipParts:
    870870        begin // choose type and number
    871871          ModalSelectDlg.ShowNewContent(wmModal, kShipPart);
    872           if ModalSelectDlg.result < 0 then
    873             exit;
    874           inc(Price, ModalSelectDlg.result shl 16);
    875           max := MyRO.Ship[me].Parts[ModalSelectDlg.result];
     872          if ModalSelectDlg.Result < 0 then
     873            Exit;
     874          Inc(Price, ModalSelectDlg.Result shl 16);
     875          Max := MyRO.Ship[Me].Parts[ModalSelectDlg.Result];
    876876          InputDlg.Caption := Phrases.Lookup('TITLE_NUMBER');
    877877          InputDlg.EInput.Text := '';
     
    879879          InputDlg.ShowModal;
    880880          if InputDlg.ModalResult <> mrOK then
    881             exit;
    882           val(InputDlg.EInput.Text, a, i);
    883           if (i <> 0) or (a <= 0) then
    884             exit;
    885           if a > max then
    886             a := max;
    887           if a > MaxShipPartPrice then
    888             a := MaxShipPartPrice;
    889           inc(Price, a);
     881            Exit;
     882          val(InputDlg.EInput.Text, A, I);
     883          if (I <> 0) or (A <= 0) then
     884            Exit;
     885          if A > Max then
     886            A := Max;
     887          if A > MaxShipPartPrice then
     888            A := MaxShipPartPrice;
     889          Inc(Price, A);
    890890        end;
    891891      opAllTech:
    892892        begin // choose technology
    893893          ModalSelectDlg.ShowNewContent(wmModal, kChooseTech);
    894           if ModalSelectDlg.result < 0 then
    895             exit;
    896           if ModalSelectDlg.result = adAll then
     894          if ModalSelectDlg.Result < 0 then
     895            Exit;
     896          if ModalSelectDlg.Result = adAll then
    897897            Price := opAllTech
    898898          else
    899             Price := OpTech + ModalSelectDlg.result;
     899            Price := OpTech + ModalSelectDlg.Result;
    900900        end;
    901901      opAllModel:
    902902        begin // choose model
    903903          ModalSelectDlg.ShowNewContent(wmModal, kChooseModel);
    904           if ModalSelectDlg.result < 0 then
    905             exit;
    906           if ModalSelectDlg.result = mixAll then
     904          if ModalSelectDlg.Result < 0 then
     905            Exit;
     906          if ModalSelectDlg.Result = mixAll then
    907907            Price := opAllModel
    908908          else
    909             Price := OpModel + ModalSelectDlg.result;
     909            Price := OpModel + ModalSelectDlg.Result;
    910910        end;
    911911      opTreaty:
    912912        begin
    913           if MyRO.Treaty[DipMem[me].pContact] < trPeace then
     913          if MyRO.Treaty[DipMem[Me].pContact] < trPeace then
    914914            Price := opTreaty + trPeace
    915915          else
    916             Price := opTreaty + MyRO.Treaty[DipMem[me].pContact] + 1;
     916            Price := opTreaty + MyRO.Treaty[DipMem[Me].pContact] + 1;
    917917        end;
    918918      { opLowTreaty:
    919919        begin
    920         if MyRO.Treaty[DipMem[me].pContact]=trNone then Price:=opTreaty+trCeaseFire
    921         else Price:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;
     920        if MyRO.Treaty[DipMem[Me].pContact]=trNone then Price:=opTreaty+trCeaseFire
     921        else Price:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
    922922        end }
    923923    end;
     
    933933procedure TNegoDlg.FastBtnClick(Sender: TObject);
    934934var
    935   NewCommand: cardinal;
    936 begin
    937   if Page <> History[me].n then
    938     exit;
     935  NewCommand: Cardinal;
     936begin
     937  if Page <> History[Me].N then
     938    Exit;
    939939  NewCommand := TButtonN(Sender).Tag and $FF + scDipStart;
    940940  if not(NewCommand - scDipStart in CommandAllowed) then
    941     exit;
     941    Exit;
    942942  if (NewCommand = scDipCancelTreaty) and
    943     (MyRO.Turn < MyRO.LastCancelTreaty[DipMem[me].pContact] + CancelTreatyTurns)
     943    (MyRO.Turn < MyRO.LastCancelTreaty[DipMem[Me].pContact] + CancelTreatyTurns)
    944944  then
    945945  begin
    946946    SimpleMessage(Phrases.Lookup('CANCELTREATYRUSH'));
    947     exit;
     947    Exit;
    948948  end;
    949949  if (NewCommand = scDipOffer) and ((ClientMode = scDipCancelTreaty) or
  • trunk/LocalPlayer/PVSB.pas

    r442 r447  
    3030    procedure Init(Max, PageSize: Integer);
    3131    procedure SetPos(Pos: Integer);
    32     function Process(const Msg: TMessage): boolean;
     32    function Process(const Msg: TMessage): Boolean;
    3333    function ProcessMouseWheel(Delta: Integer): Boolean;
    34     procedure Show(Visible: boolean);
     34    procedure Show(Visible: Boolean);
    3535    procedure EndSB;
    3636    procedure SetBorderSpacing(Top, Right, Bottom: Integer);
     
    6363end;
    6464
    65 function TPVScrollBar.Process(const Msg: TMessage): boolean;
     65function TPVScrollBar.Process(const Msg: TMessage): Boolean;
    6666var
    67   NewPos: integer;
     67  NewPos: Integer;
    6868begin
    6969    if Max < ScrollBar.PageSize then
    70       result := false
     70      Result := False
    7171    else
    7272    begin
    7373      if (Msg.wParam and $ffff) in [SB_THUMBPOSITION, SB_THUMBTRACK] then
    7474      begin
    75         result := ((Msg.wParam shr 16) and $ffff) <> ScrollBar.Position;
     75        Result := ((Msg.wParam shr 16) and $ffff) <> ScrollBar.Position;
    7676        ScrollBar.Position := (Msg.wParam shr 16) and $ffff;
    7777      end else begin
     
    9292        if NewPos > Max - ScrollBar.PageSize + 1 then
    9393          NewPos := Max - ScrollBar.PageSize + 1;
    94         result := NewPos <> ScrollBar.Position;
     94        Result := NewPos <> ScrollBar.Position;
    9595        if (NewPos <> ScrollBar.Position) or ((Msg.wParam and $ffff) = SB_ENDSCROLL) then
    9696        begin
     
    103103function TPVScrollBar.ProcessMouseWheel(Delta: Integer): Boolean;
    104104var
    105   NewPos: integer;
     105  NewPos: Integer;
    106106begin
    107107    if Max < ScrollBar.PageSize then Result := False
     
    118118end;
    119119
    120 procedure TPVScrollBar.Show(Visible: boolean);
     120procedure TPVScrollBar.Show(Visible: Boolean);
    121121begin
    122122  if not Visible or (Max < ScrollBar.PageSize) then
  • trunk/LocalPlayer/Rates.pas

    r442 r447  
    4646procedure TRatesDlg.OffscreenPaint;
    4747var
    48   p, x, y, current, max, i: integer;
    49   s, s1: string;
     48  P, X, Y, current, Max, I: Integer;
     49  S, s1: string;
    5050begin
    5151  if (OffscreenUser <> nil) and (OffscreenUser <> self) then
     
    6464  BtnFrame(Offscreen.Canvas, CloseBtn.BoundsRect, MainTexture);
    6565  Offscreen.Canvas.Font.Assign(UniFont[ftCaption]);
    66   s := Phrases.Lookup('TITLE_RATES');
     66  S := Phrases.Lookup('TITLE_RATES');
    6767  RisedTextOut(Offscreen.Canvas,
    68     (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s)) div 2 - 1, 7, s);
    69 
    70   if MyRO.Wonder[woLiberty].EffectiveOwner = me then
    71     s := Phrases.Lookup('NORATES')
    72   else
    73     s := Phrases.Lookup('RATES');
     68    (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2 - 1, 7, S);
     69
     70  if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
     71    S := Phrases.Lookup('NORATES')
     72  else
     73    S := Phrases.Lookup('RATES');
    7474  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    75   p := pos('\', s);
    76   if p = 0 then
    77     RisedTextOut(Offscreen.Canvas, (ClientWidth - BiColorTextWidth(Canvas, s))
    78       div 2, 114, s)
    79   else
    80   begin
    81     s1 := copy(s, 1, p - 1);
     75  P := Pos('\', S);
     76  if P = 0 then
     77    RisedTextOut(Offscreen.Canvas, (ClientWidth - BiColorTextWidth(Canvas, S))
     78      div 2, 114, S)
     79  else
     80  begin
     81    s1 := Copy(S, 1, P - 1);
    8282    RisedTextOut(Offscreen.Canvas,
    8383      (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s1)) div 2,
    8484      114 - MessageLineSpacing div 2, s1);
    85     s1 := copy(s, p + 1, 255);
     85    s1 := Copy(S, P + 1, 255);
    8686    RisedTextOut(Offscreen.Canvas,
    8787      (ClientWidth - BiColorTextWidth(Offscreen.Canvas, s1)) div 2,
     
    9090  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    9191
    92   if MyRO.Wonder[woLiberty].EffectiveOwner = me then
     92  if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
    9393  begin
    9494    GlowFrame(Offscreen, ClientWidth div 2 - xSizeBig div 2, 52, xSizeBig,
    95       ySizeBig, Tribe[me].Color);
     95      ySizeBig, Tribe[Me].Color);
    9696    BitBltCanvas(Offscreen.Canvas, ClientWidth div 2 - xSizeBig div 2, 52,
    9797      xSizeBig, ySizeBig, BigImp.Canvas, (woLiberty mod 7) * xSizeBig,
     
    102102    // ImageOp_CBC(Offscreen,Templates,260,40,145,112,36,36,$404000,$8B8BEB);
    103103
    104     s := Phrases.Lookup('SCIENCE');
    105     RisedTextOut(Offscreen.Canvas,
    106       16 + 120 - BiColorTextWidth(Offscreen.Canvas, s), 44, s);
    107     s := Format('%d%%', [100 - MyRO.TaxRate - MyRO.LuxRate]);
    108     RisedTextOut(Offscreen.Canvas,
    109       16 + 120 - BiColorTextWidth(Offscreen.Canvas, s), 60, s);
     104    S := Phrases.Lookup('SCIENCE');
     105    RisedTextOut(Offscreen.Canvas,
     106      16 + 120 - BiColorTextWidth(Offscreen.Canvas, S), 44, S);
     107    S := Format('%d%%', [100 - MyRO.TaxRate - MyRO.LuxRate]);
     108    RisedTextOut(Offscreen.Canvas,
     109      16 + 120 - BiColorTextWidth(Offscreen.Canvas, S), 60, S);
    110110    // PaintProgressBar(Offscreen.Canvas,2,16,81,(100-MyRO.LuxRate-MyRO.TaxRate)*120 div 100,0,120,MainTexture);
    111111
    112112    // reverse progress bar for science
    113     x := 16;
    114     y := 81;
     113    X := 16;
     114    Y := 81;
    115115    current := (100 - MyRO.LuxRate - MyRO.TaxRate) * 120 div 100;
    116     max := 120;
    117     Frame(Offscreen.Canvas, x - 1, y - 1, x + max, y + 7, $000000, $000000);
    118     RFrame(Offscreen.Canvas, x - 2, y - 2, x + max + 1, y + 8,
     116    Max := 120;
     117    Frame(Offscreen.Canvas, X - 1, Y - 1, X + Max, Y + 7, $000000, $000000);
     118    RFrame(Offscreen.Canvas, X - 2, Y - 2, X + Max + 1, Y + 8,
    119119      MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    120120    with Offscreen.Canvas do
    121121    begin
    122       for i := 0 to current div 8 - 1 do
    123         BitBltCanvas(Offscreen.Canvas, x + max - 8 - i * 8, y, 8, 7,
     122      for I := 0 to current div 8 - 1 do
     123        BitBltCanvas(Offscreen.Canvas, X + Max - 8 - I * 8, Y, 8, 7,
    124124          HGrSystem.Data.Canvas, 104, 9 + 8 * 2);
    125       BitBltCanvas(Offscreen.Canvas, x + max - current, y, current - 8 * (current div 8), 7,
     125      BitBltCanvas(Offscreen.Canvas, X + Max - current, Y, current - 8 * (current div 8), 7,
    126126        HGrSystem.Data.Canvas, 104, 9 + 8 * 2);
    127127      Brush.Color := $000000;
    128       FillRect(Rect(x, y, x + max - current, y + 7));
     128      FillRect(Rect(X, Y, X + Max - current, Y + 7));
    129129      Brush.Style := bsClear;
    130130    end;
    131131
    132132    RisedTextOut(Offscreen.Canvas, 16 + 160, 44, Phrases.Lookup('LUX'));
    133     s := Format('%d%%', [MyRO.LuxRate]);
    134     RisedTextOut(Offscreen.Canvas,
    135       16 + 160 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 60, s);
     133    S := Format('%d%%', [MyRO.LuxRate]);
     134    RisedTextOut(Offscreen.Canvas,
     135      16 + 160 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 60, S);
    136136    PaintProgressBar(Offscreen.Canvas, 5, 16 + 160, 81,
    137137      MyRO.LuxRate * 120 div 100, 0, 120, MainTexture);
     
    144144    MainTexture.ColorBevelLight);
    145145  RisedTextOut(Offscreen.Canvas, 16 + 80, 164, Phrases.Lookup('TAXRATE'));
    146   s := Format('%d%%', [MyRO.TaxRate]);
     146  S := Format('%d%%', [MyRO.TaxRate]);
    147147  RisedTextOut(Offscreen.Canvas,
    148     16 + 80 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 180, s);
     148    16 + 80 { +120-BiColorTextWidth(Offscreen.Canvas,s) } , 180, S);
    149149  PaintProgressBar(Offscreen.Canvas, 0, 16 + 80, 201,
    150150    MyRO.TaxRate * 120 div 100, 0, 120, MainTexture);
     
    164164begin
    165165  Caption := Phrases.Lookup('TITLE_RATES');
    166   if MyRO.Wonder[woLiberty].EffectiveOwner = me then
    167   begin
    168     ScienceBtn.Visible := false;
    169     LuxBtn.Visible := false;
     166  if MyRO.Wonder[woLiberty].EffectiveOwner = Me then
     167  begin
     168    ScienceBtn.Visible := False;
     169    LuxBtn.Visible := False;
    170170  end
    171171  else
    172172  begin
    173     ScienceBtn.Visible := true;
    174     LuxBtn.Visible := true;
     173    ScienceBtn.Visible := True;
     174    LuxBtn.Visible := True;
    175175  end;
    176176  OffscreenPaint;
     
    184184procedure TRatesDlg.TaxLuxBtnClick(Sender: TObject);
    185185var
    186   NewTax, NewLux: integer;
     186  NewTax, NewLux: Integer;
    187187begin
    188188  NewTax := MyRO.TaxRate div 10;
     
    191191  begin
    192192    if NewTax < 10 then
    193       inc(NewTax);
     193      Inc(NewTax);
    194194    if NewTax + NewLux > 10 then
    195       dec(NewLux);
     195      Dec(NewLux);
    196196  end
    197197  else if (Sender = TaxDownBtn) and (NewTax > 0) then
    198     dec(NewTax)
     198    Dec(NewTax)
    199199  else if (Sender = ScienceBtn) and (NewLux > 0) then
    200     dec(NewLux)
     200    Dec(NewLux)
    201201  else if (Sender = LuxBtn) and (NewLux + NewTax < 100) then
    202     inc(NewLux);
    203   if Server(sSetRates, me, NewTax + NewLux shl 4, nil^) <> eNotChanged then
     202    Inc(NewLux);
     203  if Server(sSetRates, Me, NewTax + NewLux shl 4, nil^) <> eNotChanged then
    204204  begin
    205205    CityOptimizer_BeginOfTurn;
    206206    SmartUpdateContent;
    207     MainScreen.UpdateViews(true);
     207    MainScreen.UpdateViews(True);
    208208  end;
    209209end;
  • trunk/LocalPlayer/Select.pas

    r442 r447  
    3131      WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
    3232    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    33       x, y: integer);
     33      X, Y: Integer);
    3434    procedure FormCreate(Sender: TObject);
    3535    procedure FormDestroy(Sender: TObject);
    3636    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    37       Shift: TShiftState; x, y: integer);
     37      Shift: TShiftState; X, Y: Integer);
    3838    procedure FormPaint(Sender: TObject);
    3939    procedure CloseBtnClick(Sender: TObject);
    40     procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
     40    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    4141    procedure FormShow(Sender: TObject);
    4242    procedure ModeBtnClick(Sender: TObject);
    4343    procedure ToggleBtnClick(Sender: TObject);
    44     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     44    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    4545    procedure PlayerClick(Sender: TObject);
    4646  private
     
    5959    Lines: array [0 .. MaxLayer - 1] of Integer;
    6060    FirstShrinkedLine: array [0 .. MaxLayer - 1] of Integer;
    61     code: array [0 .. MaxLayer - 1, 0 .. 4095] of Integer;
     61    Code: array [0 .. MaxLayer - 1, 0 .. 4095] of Integer;
    6262    Column: array [0 .. nPl - 1] of Integer;
    6363    Closable: Boolean;
     
    6666    procedure ScrollBarUpdate(Sender: TObject);
    6767    procedure InitLines;
    68     procedure line(ca: TCanvas; l: integer; NonText, lit: boolean);
    69     function RenameCity(cix: integer): boolean;
    70     function RenameModel(mix: integer): boolean;
     68    procedure Line(ca: TCanvas; L: Integer; NonText, lit: Boolean);
     69    function RenameCity(cix: Integer): Boolean;
     70    function RenameModel(mix: Integer): Boolean;
    7171    procedure OnScroll(var Msg: TMessage); message WM_VSCROLL;
    7272    procedure OnMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
    7373  public
    74     result: integer;
    75     function OnlyChoice(TestKind: TListKind): integer;
     74    Result: Integer;
     75    function OnlyChoice(TestKind: TListKind): Integer;
    7676    // -2=empty, -1=ambiguous, other=only choice
    7777    procedure OffscreenPaint; override;
    7878    procedure ShowNewContent(NewMode: TWindowMode; ListKind: TListKind);
    79     procedure ShowNewContent_CityProject(NewMode: TWindowMode; cix: integer);
    80     procedure ShowNewContent_MilReport(NewMode: TWindowMode; p: integer);
     79    procedure ShowNewContent_CityProject(NewMode: TWindowMode; cix: Integer);
     80    procedure ShowNewContent_MilReport(NewMode: TWindowMode; P: Integer);
    8181    procedure EcoChange;
    8282    procedure TechChange;
     
    135135procedure TListDlg.CloseBtnClick(Sender: TObject);
    136136begin
    137   Closable := true;
     137  Closable := True;
    138138  Close;
    139139end;
    140140
    141 procedure TListDlg.FormCloseQuery(Sender: TObject; var CanClose: boolean);
     141procedure TListDlg.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    142142begin
    143143  CanClose := Closable or not(Kind in MustChooseKind);
     
    149149  if ScrollBar.Process(Msg) then  begin
    150150    Selected := -2;
    151     SmartUpdateContent(true);
     151    SmartUpdateContent(True);
    152152  end;
    153153  }
     
    158158  if not Closable and (Selected <> -2) then
    159159  begin
    160     line(Canvas, Selected, false, false);
     160    Line(Canvas, Selected, False, False);
    161161    Selected := -2;
    162162  end;
     
    165165procedure TListDlg.FormPaint(Sender: TObject);
    166166var
    167   s: string;
     167  S: string;
    168168begin
    169169  inherited;
    170170  Canvas.Font.Assign(UniFont[ftNormal]);
    171171  if Selected <> -2 then
    172     line(Canvas, Selected, false, true);
    173   s := '';
     172    Line(Canvas, Selected, False, True);
     173  S := '';
    174174  if (Kind = kAdvance) and (MyData.FarTech <> adNone) then
    175     s := Format(Phrases.Lookup('TECHFOCUS'),
     175    S := Format(Phrases.Lookup('TECHFOCUS'),
    176176      [Phrases.Lookup('ADVANCES', MyData.FarTech)])
    177177  else if Kind = kModels then
    178     s := Tribe[me].TPhrase('SHORTNAME')
     178    S := Tribe[Me].TPhrase('SHORTNAME')
    179179  else if Kind = kEModels then
    180     s := Tribe[pView].TPhrase('SHORTNAME') + ' (' +
     180    S := Tribe[pView].TPhrase('SHORTNAME') + ' (' +
    181181      TurnToString(MyRO.EnemyReport[pView].TurnOfMilReport) + ')';
    182   if s <> '' then
     182  if S <> '' then
    183183    LoweredTextOut(Canvas, -1, MainTexture,
    184       (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, 31, s);
     184      (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, 31, S);
    185185  if not MultiPage and (Kind in [kProject, kAdvance, kFarAdvance]) and not Phrases2FallenBackToEnglish
    186186  then
    187187  begin
    188     s := Phrases2.Lookup('SHIFTCLICK');
     188    S := Phrases2.Lookup('SHIFTCLICK');
    189189    LoweredTextOut(Canvas, -2, MainTexture,
    190       (ClientWidth - BiColorTextWidth(Canvas, s)) div 2, ClientHeight - 29, s);
    191   end;
    192 end;
    193 
    194 procedure TListDlg.line(ca: TCanvas; l: integer; NonText, lit: boolean);
     190      (ClientWidth - BiColorTextWidth(Canvas, S)) div 2, ClientHeight - 29, S);
     191  end;
     192end;
     193
     194procedure TListDlg.Line(ca: TCanvas; L: Integer; NonText, lit: Boolean);
    195195// paint a line
    196196
    197   procedure DisplayProject(x, y, pix: integer);
     197  procedure DisplayProject(X, Y, pix: Integer);
    198198  begin
    199199    if pix and (cpType or cpImp) = 0 then
    200       with Tribe[me].ModelPicture[pix and cpIndex] do
    201         Sprite(offscreen, HGr, x, y, 64, 48, pix mod 10 * 65 + 1,
     200      with Tribe[Me].ModelPicture[pix and cpIndex] do
     201        Sprite(Offscreen, HGr, X, Y, 64, 48, pix mod 10 * 65 + 1,
    202202          pix div 10 * 49 + 1)
    203203    else
    204204    begin
    205       Frame(offscreen.Canvas, x + (16 - 1), y + (16 - 2), x + (16 + xSizeSmall),
    206         y + (16 - 1 + ySizeSmall), MainTexture.ColorBevelLight,
     205      Frame(Offscreen.Canvas, X + (16 - 1), Y + (16 - 2), X + (16 + xSizeSmall),
     206        Y + (16 - 1 + ySizeSmall), MainTexture.ColorBevelLight,
    207207        MainTexture.ColorBevelShade);
    208208      if pix and cpType = 0 then
    209209        if (pix and cpIndex = imPalace) and (MyRO.Government <> gAnarchy) then
    210           BitBltCanvas(offscreen.Canvas, x + 16, y + (16 - 1), xSizeSmall,
     210          BitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall,
    211211            ySizeSmall, SmallImp.Canvas, (MyRO.Government - 1) *
    212212            xSizeSmall, ySizeSmall)
    213213        else
    214           BitBltCanvas(offscreen.Canvas, x + 16, y + (16 - 1), xSizeSmall,
     214          BitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall,
    215215            ySizeSmall, SmallImp.Canvas, pix and cpIndex mod 7 *
    216216            xSizeSmall, (pix and cpIndex + SystemIconLines * 7) div 7 *
    217217            ySizeSmall)
    218218      else
    219         BitBltCanvas(offscreen.Canvas, x + 16, y + (16 - 1), xSizeSmall,
     219        BitBltCanvas(Offscreen.Canvas, X + 16, Y + (16 - 1), xSizeSmall,
    220220          ySizeSmall, SmallImp.Canvas, (3 + pix and cpIndex) *
    221221          xSizeSmall, 0);
     
    223223  end;
    224224
    225   procedure ReplaceText(x, y, Color: integer; s: string);
     225  procedure ReplaceText(X, Y, Color: Integer; S: string);
    226226  var
    227227    TextSize: TSize;
     
    229229    if ca = Canvas then
    230230    begin
    231       TextSize.cx := BiColorTextWidth(ca, s);
    232       TextSize.cy := ca.TextHeight(s);
    233       if y + TextSize.cy >= TitleHeight + InnerHeight then
    234         TextSize.cy := TitleHeight + InnerHeight - y;
    235       Fill(ca, x, y, TextSize.cx, TextSize.cy, (Maintexture.Width - ClientWidth)
     231      TextSize.cx := BiColorTextWidth(ca, S);
     232      TextSize.cy := ca.TextHeight(S);
     233      if Y + TextSize.cy >= TitleHeight + InnerHeight then
     234        TextSize.cy := TitleHeight + InnerHeight - Y;
     235      Fill(ca, X, Y, TextSize.cx, TextSize.cy, (Maintexture.Width - ClientWidth)
    236236        div 2, (Maintexture.Height - ClientHeight) div 2);
    237237    end;
    238     LoweredTextOut(ca, Color, MainTexture, x, y, s);
     238    LoweredTextOut(ca, Color, MainTexture, X, Y, S);
    239239  end;
    240240
    241241var
    242   icon, ofs, x, y, y0, lix, i, j, TextColor, Available, first, test,
    243     FutureCount, growth, TrueFood, TrueProd: integer;
     242  icon, ofs, X, Y, y0, lix, I, J, TextColor, Available, first, Test,
     243    FutureCount, growth, TrueFood, TrueProd: Integer;
    244244  CityReport: TCityReportNew;
    245245  mox: ^TModelInfo;
    246   s, number: string;
    247   CanGrow: boolean;
    248 begin
    249   lix := code[Layer, ScrollBar.Position + l];
    250   y0 := 2 + (l + 1) * LineDistance;
    251   if ScrollBar.Position + l >= FirstShrinkedLine[Layer] then
    252     ofs := (ScrollBar.Position + l - FirstShrinkedLine[Layer]) and 1 * 33
     246  S, number: string;
     247  CanGrow: Boolean;
     248begin
     249  lix := Code[Layer, ScrollBar.Position + L];
     250  y0 := 2 + (L + 1) * LineDistance;
     251  if ScrollBar.Position + L >= FirstShrinkedLine[Layer] then
     252    ofs := (ScrollBar.Position + L - FirstShrinkedLine[Layer]) and 1 * 33
    253253  else { if FirstShrinkedLine[Layer]<Lines[Layer] then }
    254254    ofs := 33;
     
    257257    with MyCity[lix] do
    258258    begin
    259       x := 104 - 76;
    260       y := y0;
     259      X := 104 - 76;
     260      Y := y0;
    261261      if ca = Canvas then
    262262      begin
    263         x := x + SideFrame;
    264         y := y + TitleHeight;
     263        X := X + SideFrame;
     264        Y := Y + TitleHeight;
    265265      end;
    266266      if lit then
     
    268268      else
    269269        TextColor := -1;
    270       s := CityName(ID);
    271       while BiColorTextWidth(ca, s) > CityNameSpace do
    272         delete(s, length(s), 1);
    273       ReplaceText(x + 15, y, TextColor, s);
     270      S := CityName(ID);
     271      while BiColorTextWidth(ca, S) > CityNameSpace do
     272        Delete(S, Length(S), 1);
     273      ReplaceText(X + 15, Y, TextColor, S);
    274274
    275275      if NonText then
    276         with offscreen.Canvas do
     276        with Offscreen.Canvas do
    277277        begin // city size
    278           brush.Color := $000000;
    279           fillrect(rect(x - 4 - 11, y + 1, x - 4 + 13, y + 21));
    280           brush.Color := $FFFFFF;
    281           fillrect(rect(x - 4 - 12, y, x - 4 + 12, y + 20));
    282           brush.style := bsClear;
     278          Brush.Color := $000000;
     279          FillRect(rect(X - 4 - 11, Y + 1, X - 4 + 13, Y + 21));
     280          Brush.Color := $FFFFFF;
     281          FillRect(rect(X - 4 - 12, Y, X - 4 + 12, Y + 20));
     282          Brush.style := bsClear;
    283283          Font.Color := $000000;
    284           s := inttostr(MyCity[lix].Size);
    285           TextOut(x - 4 - textwidth(s) div 2, y, s);
     284          S := IntToStr(MyCity[lix].Size);
     285          TextOut(X - 4 - textwidth(S) div 2, Y, S);
    286286        end;
    287287
     
    289289      begin
    290290        first := -1;
    291         for j := 0 to nCityEventPriority - 1 do
    292           if (Flags and CityRepMask and CityEventPriority[j] <> 0) then
    293           begin
    294             first := j;
     291        for J := 0 to nCityEventPriority - 1 do
     292          if (Flags and CityRepMask and CityEventPriority[J] <> 0) then
     293          begin
     294            first := J;
    295295            Break;
    296296          end;
    297297        if first >= 0 then
    298298        begin
    299           i := 0;
    300           test := 1;
    301           while test < CityEventPriority[first] do
    302           begin
    303             inc(i);
    304             inc(test, test);
    305           end;
    306           s := CityEventName(i);
     299          I := 0;
     300          Test := 1;
     301          while Test < CityEventPriority[first] do
     302          begin
     303            Inc(I);
     304            Inc(Test, Test);
     305          end;
     306          S := CityEventName(I);
    307307          { if CityEventPriority[first]=chNoGrowthWarning then
    308308            if Built[imAqueduct]=0 then
    309             s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
    310             else begin s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); i:=17 end; }
    311           ReplaceText(x + (CityNameSpace + 4 + 40 + 18 + 8), y, TextColor, s);
     309            S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
     310            else begin S:=Format(S,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); I:=17 end; }
     311          ReplaceText(X + (CityNameSpace + 4 + 40 + 18 + 8), Y, TextColor, S);
    312312          if NonText then
    313313          begin
    314             Sprite(offscreen, HGrSystem, 105 - 76 + CityNameSpace + 4 + 40,
    315               y0 + 1, 18, 18, 1 + i mod 3 * 19, 1 + i div 3 * 19);
    316             x := InnerWidth - 26;
    317             for j := nCityEventPriority - 1 downto first + 1 do
    318               if (Flags and CityRepMask and CityEventPriority[j] <> 0) then
     314            Sprite(Offscreen, HGrSystem, 105 - 76 + CityNameSpace + 4 + 40,
     315              y0 + 1, 18, 18, 1 + I mod 3 * 19, 1 + I div 3 * 19);
     316            X := InnerWidth - 26;
     317            for J := nCityEventPriority - 1 downto first + 1 do
     318              if (Flags and CityRepMask and CityEventPriority[J] <> 0) then
    319319              begin
    320                 i := 0;
    321                 test := 1;
    322                 while test < CityEventPriority[j] do
     320                I := 0;
     321                Test := 1;
     322                while Test < CityEventPriority[J] do
    323323                begin
    324                   inc(i);
    325                   inc(test, test);
     324                  Inc(I);
     325                  Inc(Test, Test);
    326326                end;
    327                 if (CityEventPriority[j] = chNoGrowthWarning) and
     327                if (CityEventPriority[J] = chNoGrowthWarning) and
    328328                  (Built[imAqueduct] > 0) then
    329                   i := 17;
    330                 Sprite(offscreen, HGrSystem, x, y0 + 1, 18, 18,
    331                   1 + i mod 3 * 19, 1 + i div 3 * 19);
    332                 dec(x, 20);
     329                  I := 17;
     330                Sprite(Offscreen, HGrSystem, X, y0 + 1, 18, 18,
     331                  1 + I mod 3 * 19, 1 + I div 3 * 19);
     332                Dec(X, 20);
    333333              end;
    334334          end;
     
    340340        CityReport.HypoTaxRate := -1;
    341341        CityReport.HypoLuxuryRate := -1;
    342         Server(sGetCityReportNew, me, lix, CityReport);
     342        Server(sGetCityReportNew, Me, lix, CityReport);
    343343        TrueFood := Food;
    344344        TrueProd := Prod;
    345         if supervising then
     345        if Supervising then
    346346        begin // normalize city from after-turn state
    347           dec(TrueFood, CityReport.FoodSurplus);
     347          Dec(TrueFood, CityReport.FoodSurplus);
    348348          if TrueFood < 0 then
    349349            TrueFood := 0; // shouldn't happen
    350           dec(TrueProd, CityReport.Production);
     350          Dec(TrueProd, CityReport.Production);
    351351          if TrueProd < 0 then
    352352            TrueProd := 0; // shouldn't happen
    353353        end;
    354354
    355         s := ''; // disorder info
     355        S := ''; // disorder info
    356356        if Flags and chCaptured <> 0 then
    357           s := Phrases.Lookup('CITYEVENTS', 14)
     357          S := Phrases.Lookup('CITYEVENTS', 14)
    358358        else if CityReport.HappinessBalance < 0 then
    359           s := Phrases.Lookup('CITYEVENTS', 0);
    360         if s <> '' then
     359          S := Phrases.Lookup('CITYEVENTS', 0);
     360        if S <> '' then
    361361        begin { disorder }
    362362          if NonText then
    363363          begin
    364             DarkGradient(offscreen.Canvas, 99 + 31 + CityNameSpace + 4,
     364            DarkGradient(Offscreen.Canvas, 99 + 31 + CityNameSpace + 4,
    365365              y0 + 2, 131, 3);
    366366            ca.Font.Assign(UniFont[ftSmall]);
    367             RisedTextout(offscreen.Canvas, 103 + CityNameSpace + 4 + 31,
    368               y0 + 1, s);
     367            RisedTextout(Offscreen.Canvas, 103 + CityNameSpace + 4 + 31,
     368              y0 + 1, S);
    369369            ca.Font.Assign(UniFont[ftNormal]);
    370370          end;
     
    373373        begin
    374374          { s:=IntToStr(CityReport.FoodSurplus);
    375             ReplaceText(x+(CityNameSpace+4+48)-BiColorTextWidth(ca,s),y,TextColor,s); }
    376           s := inttostr(CityReport.Science);
    377           ReplaceText(x + CityNameSpace + 4 + 370 + 48 - BiColorTextWidth(ca,
    378             s), y, TextColor, s);
    379           s := inttostr(CityReport.Production);
    380           ReplaceText(x + CityNameSpace + 4 + 132 - BiColorTextWidth(ca, s), y,
    381             TextColor, s);
     375            ReplaceText(X+(CityNameSpace+4+48)-BiColorTextWidth(ca,S),Y,TextColor,S); }
     376          S := IntToStr(CityReport.Science);
     377          ReplaceText(X + CityNameSpace + 4 + 370 + 48 - BiColorTextWidth(ca,
     378            S), Y, TextColor, S);
     379          S := IntToStr(CityReport.Production);
     380          ReplaceText(X + CityNameSpace + 4 + 132 - BiColorTextWidth(ca, S), Y,
     381            TextColor, S);
    382382          if NonText then
    383383          begin
    384384            // Sprite(offscreen,HGrSystem,x+CityNameSpace+4+333+1,y+6,10,10,66,115);
    385             Sprite(offscreen, HGrSystem, x + CityNameSpace + 4 + 370 + 48 + 1,
    386               y + 6, 10, 10, 77, 126);
    387             Sprite(offscreen, HGrSystem, x + CityNameSpace + 4 + 132 + 1, y + 6,
     385            Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 370 + 48 + 1,
     386              Y + 6, 10, 10, 77, 126);
     387            Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 132 + 1, Y + 6,
    388388              10, 10, 88, 115);
    389389          end;
    390390        end;
    391         s := inttostr(CityTaxBalance(lix, CityReport));
    392         ReplaceText(x + CityNameSpace + 4 + 370 - BiColorTextWidth(ca, s), y,
    393           TextColor, s);
     391        S := IntToStr(CityTaxBalance(lix, CityReport));
     392        ReplaceText(X + CityNameSpace + 4 + 370 - BiColorTextWidth(ca, S), Y,
     393          TextColor, S);
    394394        // if Project and (cpImp+cpIndex)<>cpImp+imTrGoods then
    395395        // ReplaceText(x+CityNameSpace+4+333+1,y,TextColor,Format('%d/%d',[TrueProd,CityReport.ProjectCost]));
    396396        if NonText then
    397397        begin
    398           Sprite(offscreen, HGrSystem, x + CityNameSpace + 4 + 370 + 1, y + 6,
     398          Sprite(Offscreen, HGrSystem, X + CityNameSpace + 4 + 370 + 1, Y + 6,
    399399            10, 10, 132, 115);
    400400
     
    404404            ((Size < NeedAqueductSize) or (Built[imAqueduct] = 1) and
    405405            (Size < NeedSewerSize) or (Built[imSewer] = 1));
    406           PaintRelativeProgressBar(offscreen.Canvas, 1, x + 15 + CityNameSpace +
    407             4, y + 7, 68, TrueFood, CutCityFoodSurplus(CityReport.FoodSurplus,
     406          PaintRelativeProgressBar(Offscreen.Canvas, 1, X + 15 + CityNameSpace +
     407            4, Y + 7, 68, TrueFood, CutCityFoodSurplus(CityReport.FoodSurplus,
    408408            (MyRO.Government <> gAnarchy) and (Flags and chCaptured = 0),
    409409            MyRO.Government, Size), CityReport.Storage, CanGrow, MainTexture);
     
    411411          if Project <> cpImp + imTrGoods then
    412412          begin
    413             DisplayProject(ofs + 104 - 76 + x - 28 + CityNameSpace + 4 + 206 -
     413            DisplayProject(ofs + 104 - 76 + X - 28 + CityNameSpace + 4 + 206 -
    414414              60, y0 - 15, Project);
    415415
     
    419419              (Flags and chCaptured <> 0) then
    420420              growth := 0;
    421             PaintRelativeProgressBar(offscreen.Canvas, 4,
    422               x + CityNameSpace + 4 + 304 - 60 + 9, y + 7, 68, TrueProd, growth,
    423               CityReport.ProjectCost, true, MainTexture);
     421            PaintRelativeProgressBar(Offscreen.Canvas, 4,
     422              X + CityNameSpace + 4 + 304 - 60 + 9, Y + 7, 68, TrueProd, growth,
     423              CityReport.ProjectCost, True, MainTexture);
    424424          end;
    425425        end;
     
    428428  else if Kind in [kModels, kEModels] then
    429429  begin
    430     x := 104;
    431     y := y0;
     430    X := 104;
     431    Y := y0;
    432432    if ca = Canvas then
    433433    begin
    434       x := x + SideFrame;
    435       y := y + TitleHeight;
     434      X := X + SideFrame;
     435      Y := Y + TitleHeight;
    436436    end;
    437437    if lit then
     
    442442    begin
    443443      Available := 0;
    444       for j := 0 to MyRO.nUn - 1 do
    445         if (MyUn[j].Loc >= 0) and (MyUn[j].mix = lix) then
    446           inc(Available);
     444      for J := 0 to MyRO.nUn - 1 do
     445        if (MyUn[J].Loc >= 0) and (MyUn[J].mix = lix) then
     446          Inc(Available);
    447447      if MainScreen.mNames.Checked then
    448         s := Tribe[me].ModelName[lix]
     448        S := Tribe[Me].ModelName[lix]
    449449      else
    450         s := Format(Tribe[me].TPhrase('GENMODEL'), [lix]);
     450        S := Format(Tribe[Me].TPhrase('GENMODEL'), [lix]);
    451451      if NonText then
    452452        DisplayProject(8 + ofs, y0 - 15, lix);
     
    456456      Available := MyRO.EnemyReport[pView].UnCount[lix];
    457457      if MainScreen.mNames.Checked then
    458         s := Tribe[pView].ModelName[lix]
     458        S := Tribe[pView].ModelName[lix]
    459459      else
    460         s := Format(Tribe[pView].TPhrase('GENMODEL'), [lix]);
     460        S := Format(Tribe[pView].TPhrase('GENMODEL'), [lix]);
    461461      if NonText then
    462462        with Tribe[pView].ModelPicture[lix] do
    463           Sprite(offscreen, HGr, 8 + ofs, y0 - 15, 64, 48, pix mod 10 * 65 + 1,
     463          Sprite(Offscreen, HGr, 8 + ofs, y0 - 15, 64, 48, pix mod 10 * 65 + 1,
    464464            pix div 10 * 49 + 1);
    465465    end;
    466466    if Available > 0 then
    467       ReplaceText(x + 32 - BiColorTextWidth(ca, inttostr(Available)), y,
    468         TextColor, inttostr(Available));
    469     ReplaceText(x + 40, y, TextColor, s);
     467      ReplaceText(X + 32 - BiColorTextWidth(ca, IntToStr(Available)), Y,
     468        TextColor, IntToStr(Available));
     469    ReplaceText(X + 40, Y, TextColor, S);
    470470  end
    471471  else
     
    474474      kAllEModels, kChooseEModel:
    475475        if lix = mixAll then
    476           s := Phrases.Lookup('PRICECAT_ALLMODEL')
     476          S := Phrases.Lookup('PRICECAT_ALLMODEL')
    477477        else
    478478        begin
     
    480480          if MainScreen.mNames.Checked then
    481481          begin
    482             s := Tribe[mox.Owner].ModelName[mox.mix];
    483             if (Kind = kAllEModels) and (code[1, ScrollBar.Position + l] = 0) then
    484               s := Format(Tribe[mox.Owner].TPhrase('OWNED'), [s]);
     482            S := Tribe[mox.Owner].ModelName[mox.mix];
     483            if (Kind = kAllEModels) and (Code[1, ScrollBar.Position + L] = 0) then
     484              S := Format(Tribe[mox.Owner].TPhrase('OWNED'), [S]);
    485485          end
    486486          else
    487             s := Format(Tribe[mox.Owner].TPhrase('GENMODEL'), [mox.mix]);
     487            S := Format(Tribe[mox.Owner].TPhrase('GENMODEL'), [mox.mix]);
    488488          if NonText then
    489489            with Tribe[mox.Owner].ModelPicture[mox.mix] do
    490               Sprite(offscreen, HGr, 8 + ofs, y0 - 15, 64, 48,
     490              Sprite(Offscreen, HGr, 8 + ofs, y0 - 15, 64, 48,
    491491                pix mod 10 * 65 + 1, pix div 10 * 49 + 1);
    492492        end;
    493493      kChooseModel:
    494494        if lix = mixAll then
    495           s := Phrases.Lookup('PRICECAT_ALLMODEL')
     495          S := Phrases.Lookup('PRICECAT_ALLMODEL')
    496496        else
    497497        begin
    498           s := Tribe[me].ModelName[lix];
     498          S := Tribe[Me].ModelName[lix];
    499499          if NonText then
    500500            DisplayProject(8 + ofs, y0 - 15, lix);
     
    503503        begin
    504504          if lix and cpType <> 0 then
    505             s := Phrases.Lookup('CITYTYPE', lix and cpIndex)
     505            S := Phrases.Lookup('CITYTYPE', lix and cpIndex)
    506506          else if lix and cpImp = 0 then
    507507            with MyModel[lix and cpIndex] do
    508508            begin
    509               s := Tribe[me].ModelName[lix and cpIndex];
     509              S := Tribe[Me].ModelName[lix and cpIndex];
    510510              if lix and cpConscripts <> 0 then
    511                 s := Format(Phrases.Lookup('CONSCRIPTS'), [s]);
     511                S := Format(Phrases.Lookup('CONSCRIPTS'), [S]);
    512512            end
    513513          else
    514514          begin
    515             s := Phrases.Lookup('IMPROVEMENTS', lix and cpIndex);
     515            S := Phrases.Lookup('IMPROVEMENTS', lix and cpIndex);
    516516            if (Imp[lix and cpIndex].Kind in [ikNatLocal, ikNatGlobal]) and
    517517              (MyRO.NatBuilt[lix and cpIndex] > 0) or
     
    519519              (MyCity[cixProject].Built[imPower] + MyCity[cixProject].Built
    520520              [imHydro] + MyCity[cixProject].Built[imNuclear] > 0) then
    521               s := Format(Phrases.Lookup('NATEXISTS'), [s]);
     521              S := Format(Phrases.Lookup('NATEXISTS'), [S]);
    522522          end;
    523523          if NonText then
     
    527527        begin
    528528          if lix = adAll then
    529             s := Phrases.Lookup('PRICECAT_ALLTECH')
     529            S := Phrases.Lookup('PRICECAT_ALLTECH')
    530530          else
    531531          begin
    532532            if lix = adNexus then
    533               s := Phrases.Lookup('NEXUS')
     533              S := Phrases.Lookup('NEXUS')
    534534            else if lix = adNone then
    535               s := Phrases.Lookup('NOFARTECH')
     535              S := Phrases.Lookup('NOFARTECH')
    536536            else if lix = adMilitary then
    537               s := Phrases.Lookup('INITUNIT')
     537              S := Phrases.Lookup('INITUNIT')
    538538            else
    539539            begin
    540               s := Phrases.Lookup('ADVANCES', lix);
     540              S := Phrases.Lookup('ADVANCES', lix);
    541541              if (Kind = kAdvance) and (lix in FutureTech) then
    542542                if MyRO.Tech[lix] < tsApplicable then
    543                   s := s + ' 1'
     543                  S := S + ' 1'
    544544                else
    545                   s := s + ' ' + inttostr(MyRO.Tech[lix] + 1);
     545                  S := S + ' ' + IntToStr(MyRO.Tech[lix] + 1);
    546546            end;
    547             if BiColorTextWidth(ca, s) > TechNameSpace + 8 then
     547            if BiColorTextWidth(ca, S) > TechNameSpace + 8 then
    548548            begin
    549549              repeat
    550                 delete(s, length(s), 1);
    551               until BiColorTextWidth(ca, s) <= TechNameSpace + 5;
    552               s := s + '.';
     550                Delete(S, Length(S), 1);
     551              until BiColorTextWidth(ca, S) <= TechNameSpace + 5;
     552              S := S + '.';
    553553            end;
    554554
     
    557557              if lix = adNexus then
    558558              begin
    559                 Frame(offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
     559                Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
    560560                  y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    561                 Dump(offscreen, HGrSystem, (8 + 16), y0, 36, 20, 223, 295)
     561                Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 223, 295)
    562562              end
    563563              else if lix = adNone then
    564564              begin
    565                 Frame(offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
     565                Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
    566566                  y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    567                 Dump(offscreen, HGrSystem, (8 + 16), y0, 36, 20, 260, 295)
     567                Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 260, 295)
    568568              end
    569569              else if lix = adMilitary then
    570570              begin
    571                 Frame(offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
     571                Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1, (8 + 16 + 36),
    572572                  y0 + 20, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    573                 Dump(offscreen, HGrSystem, (8 + 16), y0, 36, 20, 38, 295)
     573                Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20, 38, 295)
    574574              end
    575575              else
    576576              begin
    577                 Frame(offscreen.Canvas, (8 + 16 - 1), y0 - 1,
     577                Frame(Offscreen.Canvas, (8 + 16 - 1), y0 - 1,
    578578                  (8 + 16 + xSizeSmall), y0 + ySizeSmall,
    579579                  MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    580580                if AdvIcon[lix] < 84 then
    581                   BitBltCanvas(offscreen.Canvas, (8 + 16), y0, xSizeSmall,
     581                  BitBltCanvas(Offscreen.Canvas, (8 + 16), y0, xSizeSmall,
    582582                    ySizeSmall, SmallImp.Canvas,
    583583                    (AdvIcon[lix] + SystemIconLines * 7) mod 7 * xSizeSmall,
     
    585585                    ySizeSmall)
    586586                else
    587                   Dump(offscreen, HGrSystem, (8 + 16), y0, 36, 20,
     587                  Dump(Offscreen, HGrSystem, (8 + 16), y0, 36, 20,
    588588                    1 + (AdvIcon[lix] - 84) mod 8 * 37,
    589589                    295 + (AdvIcon[lix] - 84) div 8 * 21);
    590                 j := AdvValue[lix] div 1000;
    591                 BitBltCanvas(offscreen.Canvas, (8 + 16 - 4), y0 + 2, 14, 14,
    592                   HGrSystem.Mask.Canvas, 127 + j * 15,
     590                J := AdvValue[lix] div 1000;
     591                BitBltCanvas(Offscreen.Canvas, (8 + 16 - 4), y0 + 2, 14, 14,
     592                  HGrSystem.Mask.Canvas, 127 + J * 15,
    593593                  85, SRCAND);
    594                 Sprite(offscreen, HGrSystem, (8 + 16 - 5), y0 + 1, 14, 14,
    595                   127 + j * 15, 85);
     594                Sprite(Offscreen, HGrSystem, (8 + 16 - 5), y0 + 1, 14, 14,
     595                  127 + J * 15, 85);
    596596              end;
    597597            end;
     
    600600          if NonText and (Kind in [kAdvance, kScience]) then
    601601          begin // show research state
    602             for j := 0 to nColumn - 1 do
     602            for J := 0 to nColumn - 1 do
    603603            begin
    604604              FutureCount := 0;
    605               if j = 0 then // own science
     605              if J = 0 then // own science
    606606                if lix = MyRO.ResearchTech then
    607607                begin
    608                   Server(sGetTechCost, me, 0, icon);
     608                  Server(sGetTechCost, Me, 0, icon);
    609609                  icon := 4 + MyRO.Research * 4 div icon;
    610610                  if icon > 4 + 3 then
     
    625625                  icon := -1
    626626              else
    627                 with MyRO.EnemyReport[Column[j]]^ do // enemy science
    628                   if (MyRO.Alive and (1 shl Column[j]) <> 0) and
     627                with MyRO.EnemyReport[Column[J]]^ do // enemy science
     628                  if (MyRO.Alive and (1 shl Column[J]) <> 0) and
    629629                    (TurnOfCivilReport >= 0) and (lix = ResearchTech) and
    630630                    ((lix = adMilitary) or (lix in FutureTech) or
     
    649649                    icon := -1;
    650650              if icon >= 0 then
    651                 Sprite(offscreen, HGrSystem, 104 - 33 + 15 + 3 + TechNameSpace +
    652                   24 * j, y0 + 3, 14, 14, 67 + icon * 15, 85)
     651                Sprite(Offscreen, HGrSystem, 104 - 33 + 15 + 3 + TechNameSpace +
     652                  24 * J, y0 + 3, 14, 14, 67 + icon * 15, 85)
    653653              else if (Kind = kScience) and (FutureCount > 0) then
    654654              begin
    655                 number := inttostr(FutureCount);
    656                 RisedTextout(ca, 104 - 33 + 15 + 10 + TechNameSpace + 24 * j -
     655                number := IntToStr(FutureCount);
     656                RisedTextout(ca, 104 - 33 + 15 + 10 + TechNameSpace + 24 * J -
    657657                  BiColorTextWidth(ca, number) div 2, y0, number);
    658658              end;
     
    661661        end; // kAdvance, kScience
    662662      kTribe:
    663         s := TribeNames[lix];
     663        S := TribeNames[lix];
    664664      kShipPart:
    665665        begin
    666           s := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +
    667             inttostr(MyRO.Ship[me].Parts[lix]) + ')';
     666          S := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +
     667            IntToStr(MyRO.Ship[Me].Parts[lix]) + ')';
    668668          if NonText then
    669669            DisplayProject(8 + ofs, y0 - 15, cpImp + imShipComp + lix);
     
    671671      kEShipPart:
    672672        begin
    673           s := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +
    674             inttostr(MyRO.Ship[DipMem[me].pContact].Parts[lix]) + ')';
     673          S := Phrases.Lookup('IMPROVEMENTS', imShipComp + lix) + ' (' +
     674            IntToStr(MyRO.Ship[DipMem[Me].pContact].Parts[lix]) + ')';
    675675          if NonText then
    676676            DisplayProject(8 + ofs, y0 - 15, cpImp + imShipComp + lix);
     
    678678      kGov:
    679679        begin
    680           s := Phrases.Lookup('GOVERNMENT', lix);
     680          S := Phrases.Lookup('GOVERNMENT', lix);
    681681          if NonText then
    682682          begin
    683             Frame(offscreen.Canvas, 8 + 16 - 1, y0 - 15 + (16 - 2),
     683            Frame(Offscreen.Canvas, 8 + 16 - 1, y0 - 15 + (16 - 2),
    684684              8 + 16 + xSizeSmall, y0 - 15 + (16 - 1 + ySizeSmall),
    685685              MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    686             BitBltCanvas(offscreen.Canvas, 8 + 16, y0 - 15 + (16 - 1),
     686            BitBltCanvas(Offscreen.Canvas, 8 + 16, y0 - 15 + (16 - 1),
    687687              xSizeSmall, ySizeSmall, SmallImp.Canvas,
    688688              (lix - 1) * xSizeSmall, ySizeSmall);
     
    690690        end;
    691691      kMission:
    692         s := Phrases.Lookup('SPYMISSION', lix);
     692        S := Phrases.Lookup('SPYMISSION', lix);
    693693    end;
    694694    case Kind of
    695695      kTribe, kMission: // center text
    696696        if Lines[0] > MaxLines then
    697           x := (InnerWidth - GetSystemMetrics(SM_CXVSCROLL)) div 2 -
    698             BiColorTextWidth(ca, s) div 2
     697          X := (InnerWidth - GetSystemMetrics(SM_CXVSCROLL)) div 2 -
     698            BiColorTextWidth(ca, S) div 2
    699699        else
    700           x := InnerWidth div 2 - BiColorTextWidth(ca, s) div 2;
     700          X := InnerWidth div 2 - BiColorTextWidth(ca, S) div 2;
    701701      kAdvance, kFarAdvance, kScience, kChooseTech, kChooseETech,
    702702        kStealTech, kGov:
    703         x := 104 - 33;
     703        X := 104 - 33;
    704704      kAllEModels:
    705         x := 104;
     705        X := 104;
    706706    else
    707       x := 104 + 15;
     707      X := 104 + 15;
    708708    end;
    709     y := y0;
     709    Y := y0;
    710710    if ca = Canvas then
    711711    begin
    712       x := x + SideFrame;
    713       y := y + TitleHeight;
     712      X := X + SideFrame;
     713      Y := Y + TitleHeight;
    714714    end;
    715715    if lit then
     
    718718      TextColor := -1;
    719719    { if Kind=kTribe then ReplaceText_Tribe(x,y,TextColor,
    720       integer(TribeNames.Objects[lix]),s)
    721       else } ReplaceText(x, y, TextColor, s);
     720      Integer(TribeNames.Objects[lix]),S)
     721      else } ReplaceText(X, Y, TextColor, S);
    722722  end;
    723723end;
     
    725725procedure TListDlg.OffscreenPaint;
    726726var
    727   i, j: integer;
     727  I, J: Integer;
    728728begin
    729729  case Kind of
    730730    kCities:
    731       Caption := Tribe[me].TPhrase('TITLE_CITIES');
     731      Caption := Tribe[Me].TPhrase('TITLE_CITIES');
    732732    kCityEvents:
    733733      Caption := Format(Phrases.Lookup('TITLE_EVENTS'),
     
    736736
    737737  inherited;
    738   offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
     738  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    739739  FillOffscreen(0, 0, InnerWidth, InnerHeight);
    740   with offscreen.Canvas do
     740  with Offscreen.Canvas do
    741741  begin
    742742    if Kind = kScience then
    743       for i := 1 to nColumn - 1 do
     743      for I := 1 to nColumn - 1 do
    744744      begin
    745745        Pen.Color := $000000;
    746         MoveTo(104 - 33 + 15 + TechNameSpace + 24 * i, 0);
    747         LineTo(104 - 33 + 15 + TechNameSpace + 24 * i, InnerHeight);
    748         MoveTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * i, 0);
    749         LineTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * i, InnerHeight);
    750         if MyRO.EnemyReport[Column[i]].TurnOfCivilReport >= MyRO.Turn - 1 then
    751         begin
    752           brush.Color := Tribe[Column[i]].Color;
    753           fillrect(rect(104 - 33 + 14 + TechNameSpace + 24 * i + 1 * 2, 0,
    754             104 - 33 + 17 + TechNameSpace + 24 * i + 8 * 2, InnerHeight));
    755           brush.style := bsClear;
     746        MoveTo(104 - 33 + 15 + TechNameSpace + 24 * I, 0);
     747        LineTo(104 - 33 + 15 + TechNameSpace + 24 * I, InnerHeight);
     748        MoveTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * I, 0);
     749        LineTo(104 - 33 + 15 + TechNameSpace + 9 * 2 + 24 * I, InnerHeight);
     750        if MyRO.EnemyReport[Column[I]].TurnOfCivilReport >= MyRO.Turn - 1 then
     751        begin
     752          Brush.Color := Tribe[Column[I]].Color;
     753          FillRect(rect(104 - 33 + 14 + TechNameSpace + 24 * I + 1 * 2, 0,
     754            104 - 33 + 17 + TechNameSpace + 24 * I + 8 * 2, InnerHeight));
     755          Brush.style := bsClear;
    756756        end
    757757        else
    758758        begin // colored player columns
    759           Pen.Color := Tribe[Column[i]].Color;
    760           for j := 1 to 8 do
    761           begin
    762             MoveTo(104 - 33 + 15 + TechNameSpace + 24 * i + j * 2, 0);
    763             LineTo(104 - 33 + 15 + TechNameSpace + 24 * i + j * 2, InnerHeight);
    764           end;
    765         end;
    766       end;
    767 
    768     for i := -1 to DispLines do
    769       if (i + ScrollBar.Position >= 0) and (i + ScrollBar.Position < Lines[Layer]) then
    770         Self.line(offscreen.Canvas, i, true, false);
     759          Pen.Color := Tribe[Column[I]].Color;
     760          for J := 1 to 8 do
     761          begin
     762            MoveTo(104 - 33 + 15 + TechNameSpace + 24 * I + J * 2, 0);
     763            LineTo(104 - 33 + 15 + TechNameSpace + 24 * I + J * 2, InnerHeight);
     764          end;
     765        end;
     766      end;
     767
     768    for I := -1 to DispLines do
     769      if (I + ScrollBar.Position >= 0) and (I + ScrollBar.Position < Lines[Layer]) then
     770        Self.Line(Offscreen.Canvas, I, True, False);
    771771  end;
    772772  MarkUsedOffscreen(InnerWidth, 8 + 48 + DispLines * LineDistance);
     
    774774
    775775procedure TListDlg.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState;
    776   x, y: integer);
     776  X, Y: Integer);
    777777var
    778   i0, Sel0, iColumn, OldScienceNation, xScreen: integer;
    779   s: string;
    780 begin
    781   y := y - TitleHeight;
     778  i0, Sel0, iColumn, OldScienceNation, xScreen: Integer;
     779  S: string;
     780begin
     781  Y := Y - TitleHeight;
    782782  i0 := ScrollBar.Position;
    783783  Sel0 := Selected;
    784   if (x >= SideFrame) and (x < SideFrame + InnerWidth) and (y >= 0) and
    785     (y < InnerHeight) and (y mod LineDistance >= 4) and (y mod LineDistance < 20)
     784  if (X >= SideFrame) and (X < SideFrame + InnerWidth) and (Y >= 0) and
     785    (Y < InnerHeight) and (Y mod LineDistance >= 4) and (Y mod LineDistance < 20)
    786786  then
    787     Selected := y div LineDistance - 1
     787    Selected := Y div LineDistance - 1
    788788  else
    789789    Selected := -2;
     
    794794  begin
    795795    if Sel0 <> -2 then
    796       line(Canvas, Sel0, false, false);
     796      Line(Canvas, Sel0, False, False);
    797797    if Selected <> -2 then
    798       line(Canvas, Selected, false, true);
     798      Line(Canvas, Selected, False, True);
    799799  end;
    800800
     
    803803    OldScienceNation := ScienceNation;
    804804    ScienceNation := -1;
    805     if (x >= SideFrame + (104 - 33 + 15 + TechNameSpace)) and
    806       ((x - SideFrame - (104 - 33 + 15 + TechNameSpace)) mod 24 <= 18) and
    807       (y >= 0) and (y < InnerHeight) then
     805    if (X >= SideFrame + (104 - 33 + 15 + TechNameSpace)) and
     806      ((X - SideFrame - (104 - 33 + 15 + TechNameSpace)) mod 24 <= 18) and
     807      (Y >= 0) and (Y < InnerHeight) then
    808808    begin
    809       iColumn := (x - SideFrame - (104 - 33 + 15 + TechNameSpace)) div 24;
     809      iColumn := (X - SideFrame - (104 - 33 + 15 + TechNameSpace)) div 24;
    810810      if (iColumn >= 1) and (iColumn < nColumn) then
    811811        ScienceNation := Column[iColumn];
     
    818818      if ScienceNation >= 0 then
    819819      begin
    820         s := Tribe[ScienceNation].TPhrase('SHORTNAME');
     820        S := Tribe[ScienceNation].TPhrase('SHORTNAME');
    821821        if MyRO.Alive and (1 shl ScienceNation) = 0 then
    822           s := Format(Phrases.Lookup('SCIENCEREPORT_EXTINCT'), [s]) // extinct
     822          S := Format(Phrases.Lookup('SCIENCEREPORT_EXTINCT'), [S]) // extinct
    823823        else if MyRO.EnemyReport[ScienceNation].TurnOfCivilReport < MyRO.Turn - 1
    824824        then
    825           s := s + ' (' + TurnToString(MyRO.EnemyReport[ScienceNation]
     825          S := S + ' (' + TurnToString(MyRO.EnemyReport[ScienceNation]
    826826            .TurnOfCivilReport) + ')'; // old report
    827         xScreen := (ClientWidth - BiColorTextWidth(Canvas, s)) div 2;
     827        xScreen := (ClientWidth - BiColorTextWidth(Canvas, S)) div 2;
    828828        LoweredTextOut(Canvas, -1, MainTexture, xScreen + 10,
    829           ClientHeight - 29, s);
     829          ClientHeight - 29, S);
    830830        BitBltCanvas(ScienceNationDotBuffer.Canvas, 0, 0, ScienceNationDot.Width,
    831831          ScienceNationDot.Height, Canvas, xScreen - 10, ClientHeight - 27);
     
    853853end;
    854854
    855 function TListDlg.RenameCity(cix: integer): boolean;
     855function TListDlg.RenameCity(cix: Integer): Boolean;
    856856var
    857857  CityNameInfo: TCityNameInfo;
     
    870870        (CityNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt);
    871871    Server(CommandWithData(cSetCityName, CityNameInfo.GetCommandDataSize),
    872       me, 0, CityNameInfo);
     872      Me, 0, CityNameInfo);
    873873    if CityDlg.Visible then
    874874    begin
     
    882882end;
    883883
    884 function TListDlg.RenameModel(mix: integer): boolean;
     884function TListDlg.RenameModel(mix: Integer): Boolean;
    885885var
    886886  ModelNameInfo: TModelNameInfo;
    887887begin
    888888  InputDlg.Caption := Phrases.Lookup('TITLE_MODELNAME');
    889   InputDlg.EInput.Text := Tribe[me].ModelName[mix];
     889  InputDlg.EInput.Text := Tribe[Me].ModelName[mix];
    890890  InputDlg.CenterToRect(BoundsRect);
    891891  InputDlg.ShowModal;
    892892  if (InputDlg.ModalResult = mrOK) and (InputDlg.EInput.Text <> '') and
    893     (InputDlg.EInput.Text <> Tribe[me].ModelName[mix]) then
     893    (InputDlg.EInput.Text <> Tribe[Me].ModelName[mix]) then
    894894  begin
    895895    ModelNameInfo.mix := mix;
     
    899899        (ModelNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt);
    900900    Server(CommandWithData(cSetModelName, ModelNameInfo.GetCommandDataSize),
    901       me, 0, ModelNameInfo);
     901      Me, 0, ModelNameInfo);
    902902    if UnitStatDlg.Visible then
    903903    begin
     
    905905      UnitStatDlg.Invalidate;
    906906    end;
    907     result := true;
     907    Result := True;
    908908  end
    909909  else
    910     result := false;
     910    Result := False;
    911911end;
    912912
    913913procedure TListDlg.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
    914   Shift: TShiftState; x, y: integer);
     914  Shift: TShiftState; X, Y: Integer);
    915915var
    916   lix: integer;
     916  lix: Integer;
    917917begin
    918918  if ScrollBar.Position + Selected >= 0 then
    919     lix := code[Layer, ScrollBar.Position + Selected];
     919    lix := Code[Layer, ScrollBar.Position + Selected];
    920920  if Kind in [kScience, kCities, kCityEvents, kModels, kEModels, kAllEModels]
    921921  then
    922     include(Shift, ssShift); // don't close list window
     922    Include(Shift, ssShift); // don't close list window
    923923  if (ssLeft in Shift) and not(ssShift in Shift) then
    924924  begin
    925925    if Selected <> -2 then
    926926    begin
    927       result := lix;
    928       Closable := true;
     927      Result := lix;
     928      Closable := True;
    929929      Close;
    930930    end;
     
    937937          MainScreen.ZoomToCity(MyCity[lix].Loc);
    938938        kCityEvents:
    939           MainScreen.ZoomToCity(MyCity[lix].Loc, false, MyCity[lix].Flags and
     939          MainScreen.ZoomToCity(MyCity[lix].Loc, False, MyCity[lix].Flags and
    940940            CityRepMask);
    941941        kModels, kChooseModel:
     
    944944        kEModels:
    945945          UnitStatDlg.ShowNewContent_EnemyModel(wmPersistent,
    946             code[1, ScrollBar.Position + Selected]);
     946            Code[1, ScrollBar.Position + Selected]);
    947947        kAllEModels, kChooseEModel:
    948948          if lix <> mixAll then
     
    987987procedure TListDlg.InitLines;
    988988var
    989   required: array [0 .. nAdv - 1] of integer;
    990 
    991   procedure TryAddImpLine(Layer, Project: integer);
    992   begin
    993     if Server(sSetCityProject - sExecute, me, cixProject, Project) >= rExecuted
     989  required: array [0 .. nAdv - 1] of Integer;
     990
     991  procedure TryAddImpLine(Layer, Project: Integer);
     992  begin
     993    if Server(sSetCityProject - sExecute, Me, cixProject, Project) >= rExecuted
    994994    then
    995995    begin
    996       code[Layer, Lines[Layer]] := Project;
    997       inc(Lines[Layer]);
     996      Code[Layer, Lines[Layer]] := Project;
     997      Inc(Lines[Layer]);
    998998    end;
    999999  end;
     
    10011001  procedure SortTechs;
    10021002  var
    1003     i, j, swap: integer;
     1003    I, J, swap: Integer;
    10041004  begin // sort by advancedness
    1005     for i := 0 to Lines[0] - 2 do
    1006       if code[0, i] < adMilitary then
    1007         for j := i + 1 to Lines[0] - 1 do
    1008           if AdvValue[code[0, i]] * nAdv + code[0, i] < AdvValue[code[0, j]] *
    1009             nAdv + code[0, j] then
    1010           begin
    1011             swap := code[0, i];
    1012             code[0, i] := code[0, j];
    1013             code[0, j] := swap;
     1005    for I := 0 to Lines[0] - 2 do
     1006      if Code[0, I] < adMilitary then
     1007        for J := I + 1 to Lines[0] - 1 do
     1008          if AdvValue[Code[0, I]] * nAdv + Code[0, I] < AdvValue[Code[0, J]] *
     1009            nAdv + Code[0, J] then
     1010          begin
     1011            swap := Code[0, I];
     1012            Code[0, I] := Code[0, J];
     1013            Code[0, J] := swap;
    10141014          end;
    10151015  end;
     
    10171017  procedure SortCities;
    10181018  var
    1019     i, j, swap: integer;
    1020   begin
    1021     for i := 0 to Lines[0] - 2 do
    1022       for j := i + 1 to Lines[0] - 1 do
    1023         if CityName(MyCity[code[0, i]].ID) > CityName(MyCity[code[0, j]].ID)
     1019    I, J, swap: Integer;
     1020  begin
     1021    for I := 0 to Lines[0] - 2 do
     1022      for J := I + 1 to Lines[0] - 1 do
     1023        if CityName(MyCity[Code[0, I]].ID) > CityName(MyCity[Code[0, J]].ID)
    10241024        then
    10251025        begin
    1026           swap := code[0, i];
    1027           code[0, i] := code[0, j];
    1028           code[0, j] := swap;
     1026          swap := Code[0, I];
     1027          Code[0, I] := Code[0, J];
     1028          Code[0, J] := swap;
    10291029        end;
    10301030  end;
    10311031
    10321032  function ModelSortValue(const mi: TModelInfo;
    1033     MixPlayers: boolean = false): integer;
    1034   begin
    1035     result := (mi.Domain + 1) shl 28 - mi.mix;
     1033    MixPlayers: Boolean = False): Integer;
     1034  begin
     1035    Result := (mi.Domain + 1) shl 28 - mi.mix;
    10361036    if MixPlayers then
    1037       dec(result, ModelCode(mi) shl 16);
     1037      Dec(Result, ModelCode(mi) shl 16);
    10381038  end;
    10391039
    10401040  procedure SortModels;
    10411041  var
    1042     i, j, swap: integer;
     1042    I, J, swap: Integer;
    10431043  begin // sort by code[2]
    1044     for i := 0 to Lines[0] - 2 do
    1045       for j := i + 1 to Lines[0] - 1 do
    1046         if code[2, i] > code[2, j] then
    1047         begin
    1048           swap := code[0, i];
    1049           code[0, i] := code[0, j];
    1050           code[0, j] := swap;
    1051           swap := code[1, i];
    1052           code[1, i] := code[1, j];
    1053           code[1, j] := swap;
    1054           swap := code[2, i];
    1055           code[2, i] := code[2, j];
    1056           code[2, j] := swap;
    1057         end;
    1058   end;
    1059 
    1060   procedure MarkPreqs(i: integer);
    1061   begin
    1062     required[i] := 1;
    1063     if MyRO.Tech[i] < tsSeen then
     1044    for I := 0 to Lines[0] - 2 do
     1045      for J := I + 1 to Lines[0] - 1 do
     1046        if Code[2, I] > Code[2, J] then
     1047        begin
     1048          swap := Code[0, I];
     1049          Code[0, I] := Code[0, J];
     1050          Code[0, J] := swap;
     1051          swap := Code[1, I];
     1052          Code[1, I] := Code[1, J];
     1053          Code[1, J] := swap;
     1054          swap := Code[2, I];
     1055          Code[2, I] := Code[2, J];
     1056          Code[2, J] := swap;
     1057        end;
     1058  end;
     1059
     1060  procedure MarkPreqs(I: Integer);
     1061  begin
     1062    required[I] := 1;
     1063    if MyRO.Tech[I] < tsSeen then
    10641064    begin
    1065       if (AdvPreq[i, 0] >= 0) then
    1066         MarkPreqs(AdvPreq[i, 0]);
    1067       if (AdvPreq[i, 1] >= 0) then
    1068         MarkPreqs(AdvPreq[i, 1]);
     1065      if (AdvPreq[I, 0] >= 0) then
     1066        MarkPreqs(AdvPreq[I, 0]);
     1067      if (AdvPreq[I, 1] >= 0) then
     1068        MarkPreqs(AdvPreq[I, 1]);
    10691069    end;
    10701070  end;
    10711071
    10721072var
    1073   Loc1, i, j, p1, dx, dy, mix, emix, EnemyType, TestEnemyType: integer;
     1073  Loc1, I, J, p1, dx, dy, mix, emix, EnemyType, TestEnemyType: Integer;
    10741074  mi: TModelInfo;
    10751075  PPicture, PTestPicture: ^TModelPicture;
    1076   ModelOk: array [0 .. 4095] of boolean;
    1077   ok: boolean;
    1078 begin
    1079   for i := 0 to MaxLayer - 1 do
    1080   begin
    1081     Lines[i] := 0;
    1082     FirstShrinkedLine[i] := MaxInt;
     1076  ModelOk: array [0 .. 4095] of Boolean;
     1077  ok: Boolean;
     1078begin
     1079  for I := 0 to MaxLayer - 1 do
     1080  begin
     1081    Lines[I] := 0;
     1082    FirstShrinkedLine[I] := MaxInt;
    10831083  end;
    10841084  case Kind of
     
    10861086      begin
    10871087        // improvements
    1088         code[0, 0] := cpImp + imTrGoods;
     1088        Code[0, 0] := cpImp + imTrGoods;
    10891089        Lines[0] := 1;
    1090         for i := nWonder to nImp - 1 do
    1091           if Imp[i].Kind = ikCommon then
    1092             TryAddImpLine(0, i + cpImp);
    1093         for i := nWonder to nImp - 1 do
    1094           if not(Imp[i].Kind in [ikCommon, ikTrGoods]) and
    1095             ((MyRO.NatBuilt[i] = 0) or (Imp[i].Kind = ikNatLocal)) then
    1096             TryAddImpLine(0, i + cpImp);
    1097         for i := 0 to nCityType - 1 do
    1098           if MyData.ImpOrder[i, 0] >= 0 then
    1099           begin
    1100             code[0, Lines[0]] := cpType + i;
    1101             inc(Lines[0]);
     1090        for I := nWonder to nImp - 1 do
     1091          if Imp[I].Kind = ikCommon then
     1092            TryAddImpLine(0, I + cpImp);
     1093        for I := nWonder to nImp - 1 do
     1094          if not(Imp[I].Kind in [ikCommon, ikTrGoods]) and
     1095            ((MyRO.NatBuilt[I] = 0) or (Imp[I].Kind = ikNatLocal)) then
     1096            TryAddImpLine(0, I + cpImp);
     1097        for I := 0 to nCityType - 1 do
     1098          if MyData.ImpOrder[I, 0] >= 0 then
     1099          begin
     1100            Code[0, Lines[0]] := cpType + I;
     1101            Inc(Lines[0]);
    11021102          end;
    11031103
    11041104        // wonders
    1105         for i := 0 to nWonder - 1 do
    1106           TryAddImpLine(1, i + cpImp);
     1105        for I := 0 to nWonder - 1 do
     1106          TryAddImpLine(1, I + cpImp);
    11071107
    11081108        // units
    1109         for i := 0 to MyRO.nModel - 1 do
     1109        for I := 0 to MyRO.nModel - 1 do
    11101110        begin
    11111111          { if MyModel[i].Kind=mkSlaves then
    1112             ok:= MyRO.Wonder[woPyramids].EffectiveOwner=me
    1113             else } if MyModel[i].Domain = dSea then
    1114           begin
    1115             ok := false;
     1112            ok:= MyRO.Wonder[woPyramids].EffectiveOwner=Me
     1113            else } if MyModel[I].Domain = dSea then
     1114          begin
     1115            ok := False;
    11161116            for dx := -2 to 2 do
    11171117              for dy := -2 to 2 do
     
    11221122                    ((MyMap[Loc1] and fTerrain = fShore) or
    11231123                    (MyMap[Loc1] and fCanal > 0)) then
    1124                     ok := true;
     1124                    ok := True;
    11251125                end;
    11261126          end
    11271127          else
    1128             ok := true;
     1128            ok := True;
    11291129          if ok then
    11301130          begin
    1131             if MyModel[i].Status and msObsolete = 0 then
     1131            if MyModel[I].Status and msObsolete = 0 then
    11321132            begin
    1133               code[2, Lines[2]] := i;
    1134               inc(Lines[2]);
     1133              Code[2, Lines[2]] := I;
     1134              Inc(Lines[2]);
    11351135            end;
    1136             if MyModel[i].Status and msAllowConscripts <> 0 then
     1136            if MyModel[I].Status and msAllowConscripts <> 0 then
    11371137            begin
    1138               code[2, Lines[2]] := i + cpConscripts;
    1139               inc(Lines[2]);
     1138              Code[2, Lines[2]] := I + cpConscripts;
     1139              Inc(Lines[2]);
    11401140            end;
    11411141          end;
     
    11511151          MarkPreqs(MyData.FarTech);
    11521152        end;
    1153         for i := 0 to nAdv - 1 do
    1154           if ((i in FutureTech) or (MyRO.Tech[i] < tsApplicable)) and
    1155             (Server(sSetResearch - sExecute, me, i, nil^) >= rExecuted) and
    1156             ((MyData.FarTech = adNone) or (required[i] > 0)) then
    1157           begin
    1158             code[0, Lines[0]] := i;
    1159             inc(Lines[0]);
     1153        for I := 0 to nAdv - 1 do
     1154          if ((I in FutureTech) or (MyRO.Tech[I] < tsApplicable)) and
     1155            (Server(sSetResearch - sExecute, Me, I, nil^) >= rExecuted) and
     1156            ((MyData.FarTech = adNone) or (required[I] > 0)) then
     1157          begin
     1158            Code[0, Lines[0]] := I;
     1159            Inc(Lines[0]);
    11601160          end;
    11611161        SortTechs;
    11621162        if Lines[0] = 0 then // no more techs -- offer nexus
    11631163        begin
    1164           code[0, Lines[0]] := adNexus;
    1165           inc(Lines[0]);
    1166         end;
    1167         ok := false;
    1168         for i := 0 to nDomains - 1 do
    1169           if (upgrade[i, 0].Preq = preNone) or
    1170             (MyRO.Tech[upgrade[i, 0].Preq] >= tsApplicable) then
    1171             ok := true;
     1164          Code[0, Lines[0]] := adNexus;
     1165          Inc(Lines[0]);
     1166        end;
     1167        ok := False;
     1168        for I := 0 to nDomains - 1 do
     1169          if (upgrade[I, 0].Preq = preNone) or
     1170            (MyRO.Tech[upgrade[I, 0].Preq] >= tsApplicable) then
     1171            ok := True;
    11721172        if ok then { new unit class }
    11731173        begin
    1174           code[0, Lines[0]] := adMilitary;
    1175           inc(Lines[0]);
     1174          Code[0, Lines[0]] := adMilitary;
     1175          Inc(Lines[0]);
    11761176        end;
    11771177      end;
    11781178    kFarAdvance:
    11791179      begin
    1180         code[0, Lines[0]] := adNone;
    1181         inc(Lines[0]);
    1182         for i := 0 to nAdv - 1 do
    1183           if not(i in FutureTech) and (MyRO.Tech[i] < tsApplicable) and
    1184             ((AdvValue[i] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and
    1185             ((AdvValue[i] < 1000) or (MyRO.Tech[adScience] > tsNA)) then
    1186           begin
    1187             code[0, Lines[0]] := i;
    1188             inc(Lines[0]);
     1180        Code[0, Lines[0]] := adNone;
     1181        Inc(Lines[0]);
     1182        for I := 0 to nAdv - 1 do
     1183          if not(I in FutureTech) and (MyRO.Tech[I] < tsApplicable) and
     1184            ((AdvValue[I] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and
     1185            ((AdvValue[I] < 1000) or (MyRO.Tech[adScience] > tsNA)) then
     1186          begin
     1187            Code[0, Lines[0]] := I;
     1188            Inc(Lines[0]);
    11891189          end;
    11901190        SortTechs;
     
    11921192    kChooseTech:
    11931193      begin
    1194         for i := 0 to nAdv - 1 do
    1195           if not(i in FutureTech) and (MyRO.Tech[i] >= tsApplicable) and
    1196             (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] < tsSeen) then
    1197           begin
    1198             code[0, Lines[0]] := i;
    1199             inc(Lines[0]);
     1194        for I := 0 to nAdv - 1 do
     1195          if not(I in FutureTech) and (MyRO.Tech[I] >= tsApplicable) and
     1196            (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] < tsSeen) then
     1197          begin
     1198            Code[0, Lines[0]] := I;
     1199            Inc(Lines[0]);
    12001200          end;
    12011201        SortTechs;
    12021202        // if Lines[0]>1 then
    12031203        begin
    1204           code[0, Lines[0]] := adAll;
    1205           inc(Lines[0]);
     1204          Code[0, Lines[0]] := adAll;
     1205          Inc(Lines[0]);
    12061206        end;
    12071207      end;
    12081208    kChooseETech:
    12091209      begin
    1210         for i := 0 to nAdv - 1 do
    1211           if not(i in FutureTech) and (MyRO.Tech[i] < tsSeen) and
    1212             (MyRO.EnemyReport[DipMem[me].pContact].Tech[i] >= tsApplicable) then
    1213           begin
    1214             code[0, Lines[0]] := i;
    1215             inc(Lines[0]);
     1210        for I := 0 to nAdv - 1 do
     1211          if not(I in FutureTech) and (MyRO.Tech[I] < tsSeen) and
     1212            (MyRO.EnemyReport[DipMem[Me].pContact].Tech[I] >= tsApplicable) then
     1213          begin
     1214            Code[0, Lines[0]] := I;
     1215            Inc(Lines[0]);
    12161216          end;
    12171217        SortTechs;
    12181218        // if Lines[0]>1 then
    12191219        begin
    1220           code[0, Lines[0]] := adAll;
    1221           inc(Lines[0]);
     1220          Code[0, Lines[0]] := adAll;
     1221          Inc(Lines[0]);
    12221222        end;
    12231223      end;
    12241224    kStealTech:
    12251225      begin
    1226         for i := 0 to nAdv - 1 do
    1227           if Server(sStealTech - sExecute, me, i, nil^) >= rExecuted then
    1228           begin
    1229             code[0, Lines[0]] := i;
    1230             inc(Lines[0]);
     1226        for I := 0 to nAdv - 1 do
     1227          if Server(sStealTech - sExecute, Me, I, nil^) >= rExecuted then
     1228          begin
     1229            Code[0, Lines[0]] := I;
     1230            Inc(Lines[0]);
    12311231          end;
    12321232        SortTechs;
     
    12341234    kScience:
    12351235      begin
    1236         Column[0] := me;
     1236        Column[0] := Me;
    12371237        nColumn := 1;
    12381238        for EnemyType := 0 to 2 do
     
    12521252              begin
    12531253                Column[nColumn] := p1;
    1254                 inc(nColumn);
     1254                Inc(nColumn);
    12551255              end;
    12561256            end;
    1257         for i := 0 to nAdv - 1 do
    1258         begin
    1259           ok := (MyRO.Tech[i] <> tsNA) or (MyRO.ResearchTech = i);
    1260           for j := 1 to nColumn - 1 do
    1261             with MyRO.EnemyReport[Column[j]]^ do
    1262               if (Tech[i] <> tsNA) or (TurnOfCivilReport >= 0) and
    1263                 (ResearchTech = i) then
    1264                 ok := true;
     1257        for I := 0 to nAdv - 1 do
     1258        begin
     1259          ok := (MyRO.Tech[I] <> tsNA) or (MyRO.ResearchTech = I);
     1260          for J := 1 to nColumn - 1 do
     1261            with MyRO.EnemyReport[Column[J]]^ do
     1262              if (Tech[I] <> tsNA) or (TurnOfCivilReport >= 0) and
     1263                (ResearchTech = I) then
     1264                ok := True;
    12651265          if ok then
    12661266          begin
    1267             code[0, Lines[0]] := i;
    1268             inc(Lines[0]);
     1267            Code[0, Lines[0]] := I;
     1268            Inc(Lines[0]);
    12691269          end;
    12701270        end;
     
    12721272
    12731273        ok := MyRO.ResearchTech = adMilitary;
    1274         for j := 1 to nColumn - 1 do
    1275           with MyRO.EnemyReport[Column[j]]^ do
    1276             if (MyRO.Alive and (1 shl Column[j]) <> 0) and
     1274        for J := 1 to nColumn - 1 do
     1275          with MyRO.EnemyReport[Column[J]]^ do
     1276            if (MyRO.Alive and (1 shl Column[J]) <> 0) and
    12771277              (TurnOfCivilReport >= 0) and (ResearchTech = adMilitary) then
    1278               ok := true;
     1278              ok := True;
    12791279        if ok then
    12801280        begin
    1281           code[0, Lines[0]] := adMilitary;
    1282           inc(Lines[0]);
     1281          Code[0, Lines[0]] := adMilitary;
     1282          Inc(Lines[0]);
    12831283        end
    12841284      end;
     
    12861286      begin
    12871287        if ClientMode < scContact then
    1288           for i := 0 to MyRO.nCity - 1 do
    1289             if MyCity[i].Loc >= 0 then
     1288          for I := 0 to MyRO.nCity - 1 do
     1289            if MyCity[I].Loc >= 0 then
    12901290            begin
    1291               code[0, Lines[0]] := i;
    1292               inc(Lines[0]);
     1291              Code[0, Lines[0]] := I;
     1292              Inc(Lines[0]);
    12931293            end;
    12941294        SortCities;
     
    12971297    kCityEvents:
    12981298      begin
    1299         for i := 0 to MyRO.nCity - 1 do
    1300           if (MyCity[i].Loc >= 0) and (MyCity[i].Flags and CityRepMask <> 0)
     1299        for I := 0 to MyRO.nCity - 1 do
     1300          if (MyCity[I].Loc >= 0) and (MyCity[I].Flags and CityRepMask <> 0)
    13011301          then
    13021302          begin
    1303             code[0, Lines[0]] := i;
    1304             inc(Lines[0]);
     1303            Code[0, Lines[0]] := I;
     1304            Inc(Lines[0]);
    13051305          end;
    13061306        SortCities;
     
    13091309    { kChooseECity:
    13101310      begin
    1311       for i:=0 to MyRO.nEnemyCity-1 do
    1312       if (MyRO.EnemyCity[i].Loc>=0)
    1313       and (MyRO.EnemyCity[i].owner=DipMem[me].pContact) then
    1314       begin code[0,Lines[0]]:=i; inc(Lines[0]); end;
     1311      for I:=0 to MyRO.nEnemyCity-1 do
     1312      if (MyRO.EnemyCity[I].Loc>=0)
     1313      and (MyRO.EnemyCity[I].owner=DipMem[Me].pContact) then
     1314      begin Code[0,Lines[0]]:=I; Inc(Lines[0]); end;
    13151315      FirstShrinkedLine:=0
    13161316      end; }
     
    13191319        for mix := 0 to MyRO.nModel - 1 do
    13201320        begin
    1321           code[0, mix] := mix;
    1322           MakeModelInfo(me, mix, MyModel[mix], mi);
    1323           code[2, mix] := ModelSortValue(mi);
     1321          Code[0, mix] := mix;
     1322          MakeModelInfo(Me, mix, MyModel[mix], mi);
     1323          Code[2, mix] := ModelSortValue(mi);
    13241324        end;
    13251325        Lines[0] := MyRO.nModel;
     
    13311331        for mix := 3 to MyRO.nModel - 1 do
    13321332        begin // check if opponent already has this model
    1333           MakeModelInfo(me, mix, MyModel[mix], mi);
    1334           ok := true;
     1333          MakeModelInfo(Me, mix, MyModel[mix], mi);
     1334          ok := True;
    13351335          for emix := 0 to MyRO.nEnemyModel - 1 do
    1336             if (MyRO.EnemyModel[emix].Owner = DipMem[me].pContact) and
     1336            if (MyRO.EnemyModel[emix].Owner = DipMem[Me].pContact) and
    13371337              IsSameModel(MyRO.EnemyModel[emix], mi) then
    1338               ok := false;
     1338              ok := False;
    13391339          if ok then
    13401340          begin
    1341             code[0, Lines[0]] := mix;
    1342             MakeModelInfo(me, mix, MyModel[mix], mi);
    1343             code[2, Lines[0]] := ModelSortValue(mi);
    1344             inc(Lines[0]);
     1341            Code[0, Lines[0]] := mix;
     1342            MakeModelInfo(Me, mix, MyModel[mix], mi);
     1343            Code[2, Lines[0]] := ModelSortValue(mi);
     1344            Inc(Lines[0]);
    13451345          end;
    13461346        end;
     
    13481348        // if Lines[0]>1 then
    13491349        begin
    1350           code[0, Lines[0]] := mixAll;
    1351           inc(Lines[0]);;
     1350          Code[0, Lines[0]] := mixAll;
     1351          Inc(Lines[0]);;
    13521352        end;
    13531353        FirstShrinkedLine[0] := 0;
     
    13561356      begin
    13571357        if MyRO.TestFlags and tfUncover <> 0 then
    1358           Server(sGetModels, me, 0, nil^);
     1358          Server(sGetModels, Me, 0, nil^);
    13591359        for emix := 0 to MyRO.nEnemyModel - 1 do
    1360           ModelOk[emix] := MyRO.EnemyModel[emix].Owner = DipMem[me].pContact;
     1360          ModelOk[emix] := MyRO.EnemyModel[emix].Owner = DipMem[Me].pContact;
    13611361        for mix := 0 to MyRO.nModel - 1 do
    13621362        begin // don't list models I already have
    1363           MakeModelInfo(me, mix, MyModel[mix], mi);
     1363          MakeModelInfo(Me, mix, MyModel[mix], mi);
    13641364          for emix := 0 to MyRO.nEnemyModel - 1 do
    13651365            ModelOk[emix] := ModelOk[emix] and
     
    13691369          if ModelOk[emix] then
    13701370          begin
    1371             if not Assigned(Tribe[DipMem[me].pContact].ModelPicture
     1371            if not Assigned(Tribe[DipMem[Me].pContact].ModelPicture
    13721372              [MyRO.EnemyModel[emix].mix].HGr) then
    13731373              InitEnemyModel(emix);
    1374             code[0, Lines[0]] := emix;
    1375             code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix]);
    1376             inc(Lines[0]);
     1374            Code[0, Lines[0]] := emix;
     1375            Code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix]);
     1376            Inc(Lines[0]);
    13771377          end;
    13781378        SortModels;
    13791379        // if not IsMilReportNew(DipMem[me].pContact) or (Lines[0]>1) then
    13801380        begin
    1381           code[0, Lines[0]] := mixAll;
    1382           inc(Lines[0]);
     1381          Code[0, Lines[0]] := mixAll;
     1382          Inc(Lines[0]);
    13831383        end;
    13841384        FirstShrinkedLine[0] := 0;
     
    13861386    kEModels:
    13871387      begin
    1388         for i := 0 to MyRO.EnemyReport[pView].nModelCounted - 1 do
    1389         begin
    1390           code[1, Lines[0]] := MyRO.nEnemyModel - 1;
    1391           while (code[1, Lines[0]] >= 0) and
    1392             not((MyRO.EnemyModel[code[1, Lines[0]]].Owner = pView) and
    1393             (MyRO.EnemyModel[code[1, Lines[0]]].mix = i)) do
    1394             dec(code[1, Lines[0]]);
    1395           if not Assigned(Tribe[pView].ModelPicture[i].HGr) then
    1396             InitEnemyModel(code[1, Lines[0]]);
    1397           code[0, Lines[0]] := i;
    1398           code[2, Lines[0]] :=
    1399             ModelSortValue(MyRO.EnemyModel[code[1, Lines[0]]]);
    1400           inc(Lines[0]);
     1388        for I := 0 to MyRO.EnemyReport[pView].nModelCounted - 1 do
     1389        begin
     1390          Code[1, Lines[0]] := MyRO.nEnemyModel - 1;
     1391          while (Code[1, Lines[0]] >= 0) and
     1392            not((MyRO.EnemyModel[Code[1, Lines[0]]].Owner = pView) and
     1393            (MyRO.EnemyModel[Code[1, Lines[0]]].mix = I)) do
     1394            Dec(Code[1, Lines[0]]);
     1395          if not Assigned(Tribe[pView].ModelPicture[I].HGr) then
     1396            InitEnemyModel(Code[1, Lines[0]]);
     1397          Code[0, Lines[0]] := I;
     1398          Code[2, Lines[0]] :=
     1399            ModelSortValue(MyRO.EnemyModel[Code[1, Lines[0]]]);
     1400          Inc(Lines[0]);
    14011401        end;
    14021402        SortModels;
     
    14051405    kAllEModels:
    14061406      begin
    1407         if (MyRO.TestFlags and tfUncover <> 0) or (G.Difficulty[me] = 0) then
    1408           Server(sGetModels, me, 0, nil^);
     1407        if (MyRO.TestFlags and tfUncover <> 0) or (G.Difficulty[Me] = 0) then
     1408          Server(sGetModels, Me, 0, nil^);
    14091409        for emix := 0 to MyRO.nEnemyModel - 1 do
    14101410          if (MyRO.EnemyModel[emix].mix >= 3) and
     
    14161416            if not Assigned(PPicture.HGr) then
    14171417              InitEnemyModel(emix);
    1418             ok := true;
     1418            ok := True;
    14191419            if MainScreen.mNames.Checked then
    1420               for j := 0 to Lines[0] - 1 do
     1420              for J := 0 to Lines[0] - 1 do
    14211421              begin
    1422                 PTestPicture := @Tribe[MyRO.EnemyModel[code[0, j]].Owner]
    1423                   .ModelPicture[MyRO.EnemyModel[code[0, j]].mix];
     1422                PTestPicture := @Tribe[MyRO.EnemyModel[Code[0, J]].Owner]
     1423                  .ModelPicture[MyRO.EnemyModel[Code[0, J]].mix];
    14241424                if (PPicture.HGr = PTestPicture.HGr) and
    14251425                  (PPicture.pix = PTestPicture.pix) and
    14261426                  (ModelHash(MyRO.EnemyModel[emix])
    1427                   = ModelHash(MyRO.EnemyModel[code[0, j]])) then
     1427                  = ModelHash(MyRO.EnemyModel[Code[0, J]])) then
    14281428                begin
    1429                   code[1, j] := 1;
    1430                   ok := false;
     1429                  Code[1, J] := 1;
     1430                  ok := False;
    14311431                  Break;
    14321432                end;
     
    14341434            if ok then
    14351435            begin
    1436               code[0, Lines[0]] := emix;
    1437               code[1, Lines[0]] := 0;
    1438               code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix], true);
    1439               inc(Lines[0]);
     1436              Code[0, Lines[0]] := emix;
     1437              Code[1, Lines[0]] := 0;
     1438              Code[2, Lines[0]] := ModelSortValue(MyRO.EnemyModel[emix], True);
     1439              Inc(Lines[0]);
    14401440            end;
    14411441          end;
     
    14441444      end;
    14451445    kTribe:
    1446       for i := 0 to TribeNames.Count - 1 do
    1447       begin
    1448         code[0, Lines[0]] := i;
    1449         inc(Lines[0]);
     1446      for I := 0 to TribeNames.Count - 1 do
     1447      begin
     1448        Code[0, Lines[0]] := I;
     1449        Inc(Lines[0]);
    14501450      end;
    14511451    (* kDeliver:
    1452       if MyRO.Treaty[DipMem[me].pContact]<trAlliance then
     1452      if MyRO.Treaty[DipMem[Me].pContact]<trAlliance then
    14531453      begin // suggest next treaty level
    1454       code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[me].pContact]+1;
    1455       inc(Lines[0]);
    1456       end;
    1457       if MyRO.Treaty[DipMem[me].pContact]=trNone then
     1454      Code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]+1;
     1455      Inc(Lines[0]);
     1456      end;
     1457      if MyRO.Treaty[DipMem[Me].pContact]=trNone then
    14581458      begin // suggest peace
    1459       code[0,Lines[0]]:=opTreaty+trPeace;
    1460       inc(Lines[0]);
    1461       end;
    1462       if MyRO.Treaty[DipMem[me].pContact]>trNone then
     1459      Code[0,Lines[0]]:=opTreaty+trPeace;
     1460      Inc(Lines[0]);
     1461      end;
     1462      if MyRO.Treaty[DipMem[Me].pContact]>trNone then
    14631463      begin // suggest next treaty level
    1464       code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[me].pContact]-1;
    1465       inc(Lines[0]);
     1464      Code[0,Lines[0]]:=opTreaty+MyRO.Treaty[DipMem[Me].pContact]-1;
     1465      Inc(Lines[0]);
    14661466      end; *)
    14671467    kShipPart:
    14681468      begin
    14691469        Lines[0] := 0;
    1470         for i := 0 to nShipPart - 1 do
    1471           if MyRO.Ship[me].Parts[i] > 0 then
    1472           begin
    1473             code[0, Lines[0]] := i;
    1474             inc(Lines[0]);
     1470        for I := 0 to nShipPart - 1 do
     1471          if MyRO.Ship[Me].Parts[I] > 0 then
     1472          begin
     1473            Code[0, Lines[0]] := I;
     1474            Inc(Lines[0]);
    14751475          end;
    14761476      end;
     
    14781478      begin
    14791479        Lines[0] := 0;
    1480         for i := 0 to nShipPart - 1 do
    1481           if MyRO.Ship[DipMem[me].pContact].Parts[i] > 0 then
    1482           begin
    1483             code[0, Lines[0]] := i;
    1484             inc(Lines[0]);
     1480        for I := 0 to nShipPart - 1 do
     1481          if MyRO.Ship[DipMem[Me].pContact].Parts[I] > 0 then
     1482          begin
     1483            Code[0, Lines[0]] := I;
     1484            Inc(Lines[0]);
    14851485          end;
    14861486      end;
    14871487    kGov:
    1488       for i := 1 to nGov - 1 do
    1489         if (GovPreq[i] <> preNA) and
    1490           ((GovPreq[i] = preNone) or (MyRO.Tech[GovPreq[i]] >= tsApplicable))
     1488      for I := 1 to nGov - 1 do
     1489        if (GovPreq[I] <> preNA) and
     1490          ((GovPreq[I] = preNone) or (MyRO.Tech[GovPreq[I]] >= tsApplicable))
    14911491        then
    14921492        begin
    1493           code[0, Lines[0]] := i;
    1494           inc(Lines[0]);
     1493          Code[0, Lines[0]] := I;
     1494          Inc(Lines[0]);
    14951495        end;
    14961496    kMission:
    1497       for i := 0 to nSpyMission - 1 do
    1498       begin
    1499         code[0, Lines[0]] := i;
    1500         inc(Lines[0]);
     1497      for I := 0 to nSpyMission - 1 do
     1498      begin
     1499        Code[0, Lines[0]] := I;
     1500        Inc(Lines[0]);
    15011501      end;
    15021502  end;
     
    15051505    if Lines[0] + Lines[1] + Lines[2] <= MaxLines then
    15061506    begin
    1507       for i := 0 to Lines[1] - 1 do // add wonders to first page
    1508       begin
    1509         code[0, Lines[0]] := code[1, i];
    1510         inc(Lines[0]);
     1507      for I := 0 to Lines[1] - 1 do // add wonders to first page
     1508      begin
     1509        Code[0, Lines[0]] := Code[1, I];
     1510        Inc(Lines[0]);
    15111511      end;
    15121512      Lines[1] := 0;
    15131513      FirstShrinkedLine[0] := Lines[0];
    1514       for i := 0 to Lines[2] - 1 do // add models to first page
    1515       begin
    1516         code[0, Lines[0]] := code[2, i];
    1517         inc(Lines[0]);
     1514      for I := 0 to Lines[2] - 1 do // add models to first page
     1515      begin
     1516        Code[0, Lines[0]] := Code[2, I];
     1517        Inc(Lines[0]);
    15181518      end;
    15191519      Lines[2] := 0;
     
    15211521end;
    15221522
    1523 function TListDlg.OnlyChoice(TestKind: TListKind): integer;
     1523function TListDlg.OnlyChoice(TestKind: TListKind): Integer;
    15241524begin
    15251525  Kind := TestKind;
    15261526  InitLines;
    15271527  if Lines[0] = 0 then
    1528     result := -2
     1528    Result := -2
    15291529  else if Lines[0] > 1 then
    1530     result := -1
     1530    Result := -1
    15311531  else
    1532     result := code[0, 0];
     1532    Result := Code[0, 0];
    15331533end;
    15341534
    15351535procedure TListDlg.FormShow(Sender: TObject);
    15361536var
    1537   i: integer;
    1538 begin
    1539   result := -1;
    1540   Closable := false;
     1537  I: Integer;
     1538begin
     1539  Result := -1;
     1540  Closable := False;
    15411541
    15421542  if Kind = kTribe then
     
    15541554  InitLines;
    15551555
    1556   MultiPage := false;
    1557   for i := 1 to MaxLayer - 1 do
    1558     if Lines[i] > 0 then
    1559       MultiPage := true;
     1556  MultiPage := False;
     1557  for I := 1 to MaxLayer - 1 do
     1558    if Lines[I] > 0 then
     1559      MultiPage := True;
    15601560  WideBottom := MultiPage or (Kind = kScience) or
    15611561    not Phrases2FallenBackToEnglish and
     
    15711571
    15721572  DispLines := Lines[0];
    1573   for i := 0 to MaxLayer - 1 do
    1574     if Lines[i] > DispLines then
    1575       DispLines := Lines[i];
     1573  for I := 0 to MaxLayer - 1 do
     1574    if Lines[I] > DispLines then
     1575      DispLines := Lines[I];
    15761576  if WideBottom then
    15771577  begin
     
    15881588    ClientHeight := InnerHeight + TitleHeight + NarrowFrame;
    15891589  end;
    1590   assert(ClientHeight <= Maintexture.Height);
     1590  Assert(ClientHeight <= Maintexture.Height);
    15911591
    15921592  TechNameSpace := 224;
     
    16491649    Layer0Btn.Top := ClientHeight - 31;
    16501650    Layer0Btn.Left := ClientWidth div 2 - (12 + 29);
    1651     Layer0Btn.Down := true;
     1651    Layer0Btn.Down := True;
    16521652    Layer1Btn.Top := ClientHeight - 31;
    16531653    Layer1Btn.Left := ClientWidth div 2 - (12 - 29);
    1654     Layer1Btn.Down := false;
     1654    Layer1Btn.Down := False;
    16551655    Layer2Btn.Top := ClientHeight - 31;
    16561656    Layer2Btn.Left := ClientWidth div 2 - 12;
    1657     Layer2Btn.Down := false;
     1657    Layer2Btn.Down := False;
    16581658  end;
    16591659
     
    16681668procedure TListDlg.ShowNewContent(NewMode: TWindowMode; ListKind: TListKind);
    16691669var
    1670   i: integer;
    1671   ShowFocus, forceclose: boolean;
     1670  I: Integer;
     1671  ShowFocus, forceclose: Boolean;
    16721672begin
    16731673  forceclose := (ListKind <> Kind) and
     
    17331733  if Kind = kAdvance then // show focus button?
    17341734    if MyData.FarTech <> adNone then
    1735       ShowFocus := true
     1735      ShowFocus := True
    17361736    else
    17371737    begin
    1738       ShowFocus := false;
    1739       for i := 0 to nAdv - 1 do
    1740         if not(i in FutureTech) and (MyRO.Tech[i] < tsApplicable) and
    1741           ((AdvValue[i] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and
    1742           ((AdvValue[i] < 1000) or (MyRO.Tech[adScience] > tsNA)) and
    1743           (Server(sSetResearch - sExecute, me, i, nil^) < rExecuted) then
    1744           ShowFocus := true;
     1738      ShowFocus := False;
     1739      for I := 0 to nAdv - 1 do
     1740        if not(I in FutureTech) and (MyRO.Tech[I] < tsApplicable) and
     1741          ((AdvValue[I] < 2000) or (MyRO.Tech[adMassProduction] > tsNA)) and
     1742          ((AdvValue[I] < 1000) or (MyRO.Tech[adScience] > tsNA)) and
     1743          (Server(sSetResearch - sExecute, Me, I, nil^) < rExecuted) then
     1744          ShowFocus := True;
    17451745    end;
    1746   ToggleBtn.Visible := (Kind = kCities) and not supervising or (Kind = kAdvance)
     1746  ToggleBtn.Visible := (Kind = kCities) and not Supervising or (Kind = kAdvance)
    17471747    and ShowFocus or (Kind = kModels) or (Kind = kEModels);
    17481748  CloseBtn.Visible := not(Kind in MustChooseKind);
     
    17511751end;
    17521752
    1753 procedure TListDlg.ShowNewContent_CityProject(NewMode: TWindowMode; cix: integer);
     1753procedure TListDlg.ShowNewContent_CityProject(NewMode: TWindowMode; cix: Integer);
    17541754begin
    17551755  cixProject := cix;
     
    17571757end;
    17581758
    1759 procedure TListDlg.ShowNewContent_MilReport(NewMode: TWindowMode; p: integer);
    1760 begin
    1761   pView := p;
    1762   if p = me then
     1759procedure TListDlg.ShowNewContent_MilReport(NewMode: TWindowMode; P: Integer);
     1760begin
     1761  pView := P;
     1762  if P = Me then
    17631763    ShowNewContent(NewMode, kModels)
    17641764  else
     
    17681768procedure TListDlg.PlayerClick(Sender: TObject);
    17691769begin
    1770   if TComponent(Sender).Tag = me then
     1770  if TComponent(Sender).Tag = Me then
    17711771    Kind := kModels
    17721772  else
     
    17961796procedure TListDlg.ToggleBtnClick(Sender: TObject);
    17971797var
    1798   p1: integer;
    1799   m: TMenuItem;
     1798  p1: Integer;
     1799  M: TMenuItem;
    18001800begin
    18011801  case Kind of
    18021802    kAdvance:
    18031803      begin
    1804         result := adFar;
    1805         Closable := true;
     1804        Result := adFar;
     1805        Closable := True;
    18061806        Close;
    18071807      end;
     
    18181818      begin
    18191819        EmptyMenu(Popup.Items);
    1820         if G.Difficulty[me] > 0 then
    1821         begin
    1822           m := TMenuItem.Create(Popup);
    1823           m.RadioItem := true;
    1824           m.Caption := Tribe[me].TPhrase('SHORTNAME');
    1825           m.Tag := me;
    1826           m.OnClick := PlayerClick;
     1820        if G.Difficulty[Me] > 0 then
     1821        begin
     1822          M := TMenuItem.Create(Popup);
     1823          M.RadioItem := True;
     1824          M.Caption := Tribe[Me].TPhrase('SHORTNAME');
     1825          M.Tag := Me;
     1826          M.OnClick := PlayerClick;
    18271827          if Kind = kModels then
    1828             m.Checked := true;
    1829           Popup.Items.Add(m);
     1828            M.Checked := True;
     1829          Popup.Items.Add(M);
    18301830        end;
    18311831        for p1 := 0 to nPl - 1 do
    1832           if (p1 <> me) and (MyRO.EnemyReport[p1] <> nil) and
     1832          if (p1 <> Me) and (MyRO.EnemyReport[p1] <> nil) and
    18331833            (MyRO.EnemyReport[p1].TurnOfMilReport >= 0) then
    18341834          begin
    1835             m := TMenuItem.Create(Popup);
    1836             m.RadioItem := true;
    1837             m.Caption := Tribe[p1].TPhrase('SHORTNAME');
    1838             m.Tag := p1;
    1839             m.OnClick := PlayerClick;
     1835            M := TMenuItem.Create(Popup);
     1836            M.RadioItem := True;
     1837            M.Caption := Tribe[p1].TPhrase('SHORTNAME');
     1838            M.Tag := p1;
     1839            M.OnClick := PlayerClick;
    18401840            if (Kind = kEModels) and (p1 = pView) then
    1841               m.Checked := true;
    1842             Popup.Items.Add(m);
     1841              M.Checked := True;
     1842            Popup.Items.Add(M);
    18431843          end;
    18441844        Popup.Popup(Left + ToggleBtn.Left, Top + ToggleBtn.Top +
     
    18481848end;
    18491849
    1850 procedure TListDlg.FormKeyDown(Sender: TObject; var Key: word;
     1850procedure TListDlg.FormKeyDown(Sender: TObject; var Key: Word;
    18511851  Shift: TShiftState);
    18521852begin
     
    18941894begin
    18951895  Selected := -2;
    1896   SmartUpdateContent(true);
     1896  SmartUpdateContent(True);
    18971897end;
    18981898
  • trunk/LocalPlayer/TechTree.pas

    r426 r447  
    5555  yLegendPitch = 32;
    5656
    57 function min(a, b: Integer): Integer;
    58 begin
    59   if a < b then
    60     result := a
     57function Min(A, B: Integer): Integer;
     58begin
     59  if A < B then
     60    Result := A
    6161  else
    62     result := b;
    63 end;
    64 
    65 function max(a, b: Integer): Integer;
    66 begin
    67   if a > b then
    68     result := a
     62    Result := B;
     63end;
     64
     65function Max(A, B: Integer): Integer;
     66begin
     67  if A > B then
     68    Result := A
    6969  else
    70     result := b;
     70    Result := B;
    7171end;
    7272
     
    8484procedure TTechTreeDlg.FormPaint(Sender: TObject);
    8585var
    86   X, w: Integer;
     86  X, W: Integer;
    8787begin
    8888  with Canvas do begin
    8989    // black border
    90     brush.color := $000000;
    91     fillrect(rect(0, 0, BlackBorder, ClientHeight));
    92     fillrect(rect(BlackBorder, 0, ClientWidth - BlackBorder, BlackBorder));
    93     fillrect(rect(ClientWidth - BlackBorder, 0, ClientWidth, ClientHeight));
    94     fillrect(rect(BlackBorder, ClientHeight - BlackBorder,
     90    Brush.Color := $000000;
     91    FillRect(rect(0, 0, BlackBorder, ClientHeight));
     92    FillRect(rect(BlackBorder, 0, ClientWidth - BlackBorder, BlackBorder));
     93    FillRect(rect(ClientWidth - BlackBorder, 0, ClientWidth, ClientHeight));
     94    FillRect(rect(BlackBorder, ClientHeight - BlackBorder,
    9595      ClientWidth - BlackBorder, ClientHeight));
    9696
    9797    // texturize empty space
    98     brush.color := $FFFFFF;
     98    Brush.Color := $FFFFFF;
    9999    if xOffset > 0 then
    100100      FillRectSeamless(Canvas, BlackBorder, BlackBorder, BlackBorder + xOffset,
     
    105105        ClientWidth - BlackBorder, ClientHeight - BlackBorder,
    106106        -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
    107     X := max(BlackBorder, BlackBorder + xOffset);
    108     w := min(BlackBorder + xOffset + Image.width, ClientWidth - BlackBorder);
     107    X := Max(BlackBorder, BlackBorder + xOffset);
     108    W := Min(BlackBorder + xOffset + Image.width, ClientWidth - BlackBorder);
    109109    if yOffset > 0 then
    110       FillRectSeamless(Canvas, X, BlackBorder, w, BlackBorder + yOffset,
     110      FillRectSeamless(Canvas, X, BlackBorder, W, BlackBorder + yOffset,
    111111        -BlackBorder - xOffset, -BlackBorder - yOffset, Paper);
    112112    if yOffset + Image.height < ClientHeight - 2 * BlackBorder then
    113       FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.height, w,
     113      FillRectSeamless(Canvas, X, BlackBorder + yOffset + Image.height, W,
    114114        ClientHeight - BlackBorder, -BlackBorder - xOffset,
    115115        -BlackBorder - yOffset, Paper);
    116116  end;
    117   BitBltCanvas(Canvas, max(BlackBorder, BlackBorder + xOffset),
    118     max(BlackBorder, BlackBorder + yOffset),
    119     min(Image.width, min(Image.width + xOffset,
    120     min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset))
    121     ), min(Image.height, min(Image.height + yOffset,
    122     min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder -
    123     yOffset))), Image.Canvas, max(0, -xOffset),
    124     max(0, -yOffset));
     117  BitBltCanvas(Canvas, Max(BlackBorder, BlackBorder + xOffset),
     118    Max(BlackBorder, BlackBorder + yOffset),
     119    Min(Image.width, Min(Image.width + xOffset,
     120    Min(ClientWidth - 2 * BlackBorder, ClientWidth - 2 * BlackBorder - xOffset))
     121    ), Min(Image.height, Min(Image.height + yOffset,
     122    Min(ClientHeight - 2 * BlackBorder, ClientHeight - 2 * BlackBorder -
     123    yOffset))), Image.Canvas, Max(0, -xOffset),
     124    Max(0, -yOffset));
    125125end;
    126126
     
    128128var
    129129  X, Y, ad: Integer;
    130   s: string;
     130  S: string;
    131131  NewWidth: Integer;
    132132  NewHeight: Integer;
     
    142142      // write advance names
    143143      Font.Assign(UniFont[ftSmall]);
    144       Font.color := clBlack;
    145       brush.Style := bsClear;
     144      Font.Color := clBlack;
     145      Brush.Style := bsClear;
    146146      for X := 0 to (Image.width - xStart) div xPitch do
    147147        for Y := 0 to (Image.height - yStart) div yPitch do
     
    150150          if ad and $FFFF00 = 0 then
    151151          begin
    152             s := Phrases.Lookup('ADVANCES', ad);
    153             while TextWidth(s) > 112 do
    154               Delete(s, Length(s), 1);
    155             TextOut(xStart + X * xPitch + 2, yStart + Y * yPitch, s);
     152            S := Phrases.Lookup('ADVANCES', ad);
     153            while TextWidth(S) > 112 do
     154              Delete(S, Length(S), 1);
     155            TextOut(xStart + X * xPitch + 2, yStart + Y * yPitch, S);
    156156            Pixels[xStart + X * xPitch + 10, yStart + Y * yPitch - 1]
    157157              := TransparentColor2;
     
    191191  if Button = mbLeft then
    192192  begin
    193     dragging := true;
     193    dragging := True;
    194194    xDown := X;
    195195    yDown := Y;
     
    200200  Shift: TShiftState; X, Y: Integer);
    201201begin
    202   dragging := false;
     202  dragging := False;
    203203end;
    204204
  • trunk/LocalPlayer/Term.pas

    r442 r447  
    232232    procedure Timer1Timer(Sender: TObject);
    233233    procedure MapBoxMouseDown(Sender: TObject; Button: TMouseButton;
    234       Shift: TShiftState; x, y: integer);
     234      Shift: TShiftState; X, Y: Integer);
    235235    procedure EOTClick(Sender: TObject);
    236236    procedure PanelBoxMouseDown(Sender: TObject; Button: TMouseButton;
    237       Shift: TShiftState; x, y: integer);
    238     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     237      Shift: TShiftState; X, Y: Integer);
     238    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    239239    procedure mDisbandOrUtilizeClick(Sender: TObject);
    240240    procedure FormResize(Sender: TObject);
    241241    procedure PanelBtnClick(Sender: TObject);
    242     procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
     242    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    243243    procedure Toggle(Sender: TObject);
    244244    procedure PanelBoxMouseMove(Sender: TObject; Shift: TShiftState;
    245       x, y: integer);
     245      X, Y: Integer);
    246246    procedure PanelBoxMouseUp(Sender: TObject; Button: TMouseButton;
    247       Shift: TShiftState; x, y: integer);
     247      Shift: TShiftState; X, Y: Integer);
    248248    procedure MapBoxMouseMove(Sender: TObject; Shift: TShiftState;
    249       x, y: integer);
     249      X, Y: Integer);
    250250    procedure mShowClick(Sender: TObject);
    251251    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    252       Shift: TShiftState; x, y: integer);
    253     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; x, y: integer);
     252      Shift: TShiftState; X, Y: Integer);
     253    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    254254    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
    255       Shift: TShiftState; x, y: integer);
     255      Shift: TShiftState; X, Y: Integer);
    256256    procedure FormPaint(Sender: TObject);
    257257    procedure mRepClicked(Sender: TObject);
     
    263263    procedure mNamesClick(Sender: TObject);
    264264    procedure MapBtnClick(Sender: TObject);
    265     procedure FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
     265    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    266266    procedure CreateUnitClick(Sender: TObject);
    267267    procedure mSoundOffClick(Sender: TObject);
     
    324324    NoMap: TIsoMap;
    325325    NoMapPanel: TIsoMap;
    326     function ChooseUnusedTribe: integer;
     326    function ChooseUnusedTribe: Integer;
    327327    function DoJob(j0: Integer): Integer;
    328328    procedure GetTribeList;
    329329    procedure InitModule;
    330330    procedure DoneModule;
    331     procedure InitTurn(NewPlayer: integer);
     331    procedure InitTurn(NewPlayer: Integer);
    332332    procedure SaveMenuItemsState;
    333333    procedure ScrollBarUpdate(Sender: TObject);
     
    341341    procedure FocusNextUnit(Dir: Integer = 1);
    342342    procedure NextUnit(NearLoc: Integer; AutoTurn: Boolean);
    343     procedure Scroll(dx, dy: integer);
    344     procedure SetMapPos(Loc: integer; MapPos: TPoint);
    345     procedure Centre(Loc: integer);
    346     procedure SetTroopLoc(Loc: integer);
    347     procedure ProcessRect(x0, y0, nx, ny, Options: integer);
    348     procedure PaintLoc(Loc: integer; Radius: integer = 0);
    349     procedure PaintLoc_BeforeMove(FromLoc: integer);
    350     procedure PaintLocTemp(Loc: integer; Style: TPaintLocTempStyle = pltsNormal);
    351     procedure PaintBufferToScreen(xMap, yMap, width, height: integer);
     343    procedure Scroll(dx, dy: Integer);
     344    procedure SetMapPos(Loc: Integer; MapPos: TPoint);
     345    procedure Centre(Loc: Integer);
     346    procedure SetTroopLoc(Loc: Integer);
     347    procedure ProcessRect(x0, y0, nx, ny, Options: Integer);
     348    procedure PaintLoc(Loc: Integer; Radius: Integer = 0);
     349    procedure PaintLoc_BeforeMove(FromLoc: Integer);
     350    procedure PaintLocTemp(Loc: Integer; Style: TPaintLocTempStyle = pltsNormal);
     351    procedure PaintBufferToScreen(xMap, yMap, width, height: Integer);
    352352    procedure PaintDestination;
    353     procedure SetUnFocus(uix: integer);
    354     function MoveUnit(dx, dy: integer; Options: integer = 0): integer;
    355     procedure MoveToLoc(Loc: integer; CheckSuicide: boolean);
    356     procedure MoveOnScreen(ShowMove: TShowMove; Step0, Step1, nStep: integer;
    357       Restore: boolean = true);
    358     procedure FocusOnLoc(Loc: integer; Options: integer = 0);
    359     function EndTurn(WasSkipped: boolean = false): boolean;
     353    procedure SetUnFocus(uix: Integer);
     354    function MoveUnit(dx, dy: Integer; Options: Integer = 0): Integer;
     355    procedure MoveToLoc(Loc: Integer; CheckSuicide: Boolean);
     356    procedure MoveOnScreen(ShowMove: TShowMove; Step0, Step1, nStep: Integer;
     357      Restore: Boolean = True);
     358    procedure FocusOnLoc(Loc: Integer; Options: Integer = 0);
     359    function EndTurn(WasSkipped: Boolean = False): Boolean;
    360360    procedure EndNego;
    361     function IsPanelPixel(x, y: integer): boolean;
     361    function IsPanelPixel(X, Y: Integer): Boolean;
    362362    procedure InitPopup(Popup: TPopupMenu);
    363363    procedure SetMapOptions;
     
    365365    procedure CheckTerrainBtnVisible;
    366366    procedure RememberPeaceViolation;
    367     procedure SetDebugMap(p: integer);
    368     procedure SetViewpoint(p: integer);
    369     function LocationOfScreenPixel(x, y: integer): Integer;
     367    procedure SetDebugMap(P: Integer);
     368    procedure SetViewpoint(P: Integer);
     369    function LocationOfScreenPixel(X, Y: Integer): Integer;
    370370    function GetCenterLoc: Integer;
    371371    procedure SetTileSizeCenter(TileSize: TTileSize);
    372372    procedure SetTileSize(TileSize: TTileSize; Loc: Integer; MapPos: TPoint);
    373     procedure RectInvalidate(Left, Top, Rigth, Bottom: integer);
     373    procedure RectInvalidate(Left, Top, Rigth, Bottom: Integer);
    374374    procedure ShowEnemyShipChange(ShowShipChange: TShowShipChange);
    375     procedure SmartRectInvalidate(Left, Top, Rigth, Bottom: integer);
     375    procedure SmartRectInvalidate(Left, Top, Rigth, Bottom: Integer);
    376376    procedure LoadSettings;
    377377    procedure SaveSettings;
     
    381381    procedure UpdateKeyShortcuts;
    382382    procedure SetFullScreen(Active: Boolean);
    383     procedure PaintZoomedTile(dst: TBitmap; x, y, Loc: integer);
     383    procedure PaintZoomedTile(dst: TBitmap; X, Y, Loc: Integer);
    384384  public
    385385    UsedOffscreenWidth: Integer;
     
    387387    Offscreen: TBitmap;
    388388    OffscreenUser: TForm;
    389     procedure Client(Command, NewPlayer: integer; var Data);
    390     procedure SetAIName(p: integer; Name: string);
    391     function ZoomToCity(Loc: integer; NextUnitOnClose: boolean = false;
    392       ShowEvent: integer = 0): boolean;
    393     procedure CityClosed(Activateuix: integer; StepFocus: boolean = false;
    394       SelectFocus: boolean = false);
    395     function DipCall(Command: integer): integer;
    396     function OfferCall(var Offer: TOffer): integer;
    397     procedure UpdateViews(UpdateCityScreen: boolean = false);
    398     function ContactRefused(p: integer; Item: String): boolean;
     389    procedure Client(Command, NewPlayer: Integer; var Data);
     390    procedure SetAIName(P: Integer; Name: string);
     391    function ZoomToCity(Loc: Integer; NextUnitOnClose: Boolean = False;
     392      ShowEvent: Integer = 0): Boolean;
     393    procedure CityClosed(Activateuix: Integer; StepFocus: Boolean = False;
     394      SelectFocus: Boolean = False);
     395    function DipCall(Command: Integer): Integer;
     396    function OfferCall(var Offer: TOffer): Integer;
     397    procedure UpdateViews(UpdateCityScreen: Boolean = False);
     398    function ContactRefused(P: Integer; Item: String): Boolean;
    399399  end;
    400400
     
    407407
    408408  TTribeInfo = record
    409     trix: integer;
     409    trix: Integer;
    410410    FileName: ShortString;
    411411    function GetCommandDataSize: Byte;
     
    415415
    416416  TCityNameInfo = record
    417     ID: integer;
     417    ID: Integer;
    418418    NewName: ShortString;
    419419    function GetCommandDataSize: Byte;
     
    423423
    424424  TModelNameInfo = record
    425     mix: integer;
     425    mix: Integer;
    426426    NewName: ShortString;
    427427    function GetCommandDataSize: Byte;
     
    472472  usToldNoReturn = $100;
    473473  usPersistent = usStay or usGoto or usEnhance or usRecover or
    474     integer($FFFF0000);
     474    Integer($FFFF0000);
    475475
    476476  { model status flags }
     
    486486  adNexus = $803;
    487487
    488   SpecialModelPictureCode: array [0 .. nSpecialModel - 1] of integer = (10,
     488  SpecialModelPictureCode: array [0 .. nSpecialModel - 1] of Integer = (10,
    489489    11, 40, 41, 21, 30, { 50,51, } 64, 74, { 71, } 73);
    490490
     
    499499
    500500  nCityEventPriority = 16;
    501   CityEventPriority: array [0 .. nCityEventPriority - 1] of integer =
     501  CityEventPriority: array [0 .. nCityEventPriority - 1] of Integer =
    502502    (chDisorder, chImprovementLost, chUnitLost, chAllImpsMade, chProduction,
    503503    chOldWonder, chNoSettlerProd, chPopDecrease, chProductionSabotaged,
     
    574574  DipMem: array [0 .. nPl - 1] of TDipMem;
    575575
    576 function CityEventName(i: integer): string;
    577 function RoughCredibility(Credibility: integer): integer;
    578 
    579 function InitEnemyModel(emix: integer): boolean;
     576function CityEventName(I: Integer): string;
     577function RoughCredibility(Credibility: Integer): Integer;
     578
     579function InitEnemyModel(emix: Integer): Boolean;
    580580procedure InitAllEnemyModels;
    581 procedure InitMyModel(mix: integer; final: boolean);
    582 
    583 procedure ImpImage(ca: TCanvas; x, y, iix: integer; Government: integer = -1;
    584   IsControl: boolean = false);
     581procedure InitMyModel(mix: Integer; final: Boolean);
     582
     583procedure ImpImage(ca: TCanvas; X, Y, iix: Integer; Government: Integer = -1;
     584  IsControl: Boolean = False);
    585585procedure HelpOnTerrain(Loc: Integer; NewMode: TWindowMode);
    586586function AlignUp(Value, Alignment: Integer): Integer;
     
    610610  MoveTime = 300; // {time for moving a unit in ms}
    611611  WaitAfterShowMove = 32;
    612   FastScrolling = false; // causes problems with overlapping windows
     612  FastScrolling = False; // causes problems with overlapping windows
    613613
    614614  nBrushTypes = 26;
     
    648648  CurrentMoveInfo: TCurrentMoveInfo;
    649649
    650 function CityEventName(i: integer): string;
    651 begin
    652   if i = 14 then // chAllImpsMade
     650function CityEventName(I: Integer): string;
     651begin
     652  if I = 14 then // chAllImpsMade
    653653    if not Phrases2FallenBackToEnglish then
    654       result := Phrases2.Lookup('CITYEVENT_ALLIMPSMADE')
     654      Result := Phrases2.Lookup('CITYEVENT_ALLIMPSMADE')
    655655    else
    656       result := Phrases.Lookup('CITYEVENTS', 1)
     656      Result := Phrases.Lookup('CITYEVENTS', 1)
    657657  else
    658     result := Phrases.Lookup('CITYEVENTS', i);
     658    Result := Phrases.Lookup('CITYEVENTS', I);
    659659end;
    660660
     
    666666  TBuffer = array [0 .. 99999, 0 .. 2] of Integer;
    667667var
    668   Sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch: Integer;
     668  Sum, Cnt, dx, dy, nx, ny, ix, iy, ir, X, Y, C, ch: Integer;
    669669  xdivider, ydivider: Integer;
    670670  Resampled: ^TBuffer;
     
    682682      PixelPtr := PixelPointer(BigImp, ScaleToNative(ix * xSizeBig),
    683683        ScaleToNative(Cut + iy * ySizeBig));
    684       for y := 0 to ScaleToNative(ySizeBig - 2 * Cut) - 1 do begin
    685         ydivider := (ScaleFromNative(y) * ySizeSmall div (ySizeBig - 2 * Cut) + 1) *
    686           (ySizeBig - 2 * Cut) - ScaleFromNative(y) * ySizeSmall;
     684      for Y := 0 to ScaleToNative(ySizeBig - 2 * Cut) - 1 do begin
     685        ydivider := (ScaleFromNative(Y) * ySizeSmall div (ySizeBig - 2 * Cut) + 1) *
     686          (ySizeBig - 2 * Cut) - ScaleFromNative(Y) * ySizeSmall;
    687687        if ydivider > ySizeSmall then
    688688          ydivider := ySizeSmall;
    689         for x := 0 to ScaleToNative(xSizeBig) - 1 do begin
    690           ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(x) *
    691             xSizeSmall div xSizeBig + ScaleFromNative(y) *
     689        for X := 0 to ScaleToNative(xSizeBig) - 1 do begin
     690          ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(X) *
     691            xSizeSmall div xSizeBig + ScaleFromNative(Y) *
    692692            ySizeSmall div (ySizeBig - 2 * Cut) * nx;
    693           xdivider := (ScaleFromNative(x) * xSizeSmall div xSizeBig + 1) *
    694             xSizeBig - ScaleFromNative(x) * xSizeSmall;
     693          xdivider := (ScaleFromNative(X) * xSizeSmall div xSizeBig + 1) *
     694            xSizeBig - ScaleFromNative(X) * xSizeSmall;
    695695          if xdivider > xSizeSmall then
    696696            xdivider := xSizeSmall;
    697697          for ch := 0 to 2 do begin
    698             c := PixelPtr.Pixel^.Planes[ch];
    699             Inc(Resampled[ir, ch], c * xdivider * ydivider);
     698            C := PixelPtr.Pixel^.Planes[ch];
     699            Inc(Resampled[ir, ch], C * xdivider * ydivider);
    700700            if xdivider < xSizeSmall then
    701               Inc(Resampled[ir + 1, ch], c * (xSizeSmall - xdivider) *
     701              Inc(Resampled[ir + 1, ch], C * (xSizeSmall - xdivider) *
    702702                ydivider);
    703703            if ydivider < ySizeSmall then
    704704              Inc(Resampled[ir + nx, ch],
    705                 c * xdivider * (ySizeSmall - ydivider));
     705                C * xdivider * (ySizeSmall - ydivider));
    706706            if (xdivider < xSizeSmall) and (ydivider < ySizeSmall) then
    707               Inc(Resampled[ir + nx + 1, ch], c * (xSizeSmall - xdivider) *
     707              Inc(Resampled[ir + nx + 1, ch], C * (xSizeSmall - xdivider) *
    708708                (ySizeSmall - ydivider));
    709709          end;
     
    719719  SmallImp.BeginUpdate;
    720720  PixelPtr := PixelPointer(SmallImp);
    721   for y := 0 to ScaleToNative(ny) - 1 do begin
    722     for x := 0 to ScaleToNative(nx) - 1 do begin
     721  for Y := 0 to ScaleToNative(ny) - 1 do begin
     722    for X := 0 to ScaleToNative(nx) - 1 do begin
    723723      for ch := 0 to 2 do begin
    724724        Sum := 0;
    725725        Cnt := 0;
    726726        for dy := -1 to 1 do
    727           if ((dy >= 0) or (ScaleFromNative(y) mod ySizeSmall > 0)) and
    728             ((dy <= 0) or (ScaleFromNative(y) mod ySizeSmall < ySizeSmall - 1)) then
     727          if ((dy >= 0) or (ScaleFromNative(Y) mod ySizeSmall > 0)) and
     728            ((dy <= 0) or (ScaleFromNative(Y) mod ySizeSmall < ySizeSmall - 1)) then
    729729            for dx := -1 to 1 do
    730               if ((dx >= 0) or (ScaleFromNative(x) mod xSizeSmall > 0)) and
    731                 ((dx <= 0) or (ScaleFromNative(x) mod xSizeSmall < xSizeSmall - 1)) then
     730              if ((dx >= 0) or (ScaleFromNative(X) mod xSizeSmall > 0)) and
     731                ((dx <= 0) or (ScaleFromNative(X) mod xSizeSmall < xSizeSmall - 1)) then
    732732              begin
    733                 Inc(Sum, Resampled[ScaleFromNative(x) + dx + nx * (ScaleFromNative(y) + dy), ch]);
     733                Inc(Sum, Resampled[ScaleFromNative(X) + dx + nx * (ScaleFromNative(Y) + dy), ch]);
    734734                Inc(Cnt);
    735735              end;
    736         Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative(x) + nx * ScaleFromNative(y), ch] - Sum *
     736        Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative(X) + nx * ScaleFromNative(Y), ch] - Sum *
    737737          Sharpen) div (800 * xSizeBig * (ySizeBig - 2 * Cut));
    738738        if Sum < 0 then Sum := 0;
     
    748748end;
    749749
    750 procedure ImpImage(ca: TCanvas; x, y, iix: integer; Government: integer;
    751   IsControl: boolean);
     750procedure ImpImage(ca: TCanvas; X, Y, iix: Integer; Government: Integer;
     751  IsControl: Boolean);
    752752begin
    753753  if Government < 0 then
     
    755755  if (iix = imPalace) and (Government <> gAnarchy) then
    756756    iix := Government - 8;
    757   FrameImage(ca, BigImp, x, y, xSizeBig, ySizeBig, (iix + SystemIconLines * 7)
     757  FrameImage(ca, BigImp, X, Y, xSizeBig, ySizeBig, (iix + SystemIconLines * 7)
    758758    mod 7 * xSizeBig, (iix + SystemIconLines * 7) div 7 * ySizeBig, IsControl);
    759759end;
     
    778778{ *** tribe management procedures *** }
    779779
    780 function RoughCredibility(Credibility: integer): integer;
     780function RoughCredibility(Credibility: Integer): Integer;
    781781begin
    782782  case Credibility of
    783783    0 .. 69:
    784       result := 0;
     784      Result := 0;
    785785    70 .. 89:
    786       result := 1;
     786      Result := 1;
    787787    90 .. 99:
    788       result := 2;
     788      Result := 2;
    789789    100:
    790       result := 3;
    791   end;
    792 end;
    793 
    794 procedure ChooseModelPicture(p, mix, code, Hash, Turn: integer;
    795   ForceNew, final: boolean);
     790      Result := 3;
     791  end;
     792end;
     793
     794procedure ChooseModelPicture(P, mix, Code, Hash, Turn: Integer;
     795  ForceNew, final: Boolean);
    796796var
    797   i: integer;
     797  I: Integer;
    798798  Picture: TModelPictureInfo;
    799   IsNew: boolean;
    800 begin
    801   Picture.trix := p;
     799  IsNew: Boolean;
     800begin
     801  Picture.trix := P;
    802802  Picture.mix := mix;
    803   if code = 74 then
     803  if Code = 74 then
    804804  begin // use correct pictures for slaves
    805     if Tribe[p].mixSlaves < 0 then
    806       if not TribeOriginal[p] then
    807         Tribe[p].mixSlaves := mix
     805    if Tribe[P].mixSlaves < 0 then
     806      if not TribeOriginal[P] then
     807        Tribe[P].mixSlaves := mix
    808808      else
    809809      begin
    810         i := mix + p shl 16;
    811         Server(cSetSlaveIndex, 0, 0, i);
     810        I := mix + P shl 16;
     811        Server(cSetSlaveIndex, 0, 0, I);
    812812      end;
    813813    if ToldSlavery = 1 then
     
    817817    Picture.Hash := 0;
    818818    Picture.GrName := 'StdUnits.png';
    819     IsNew := true;
     819    IsNew := True;
    820820  end
    821821  else
    822822  begin
    823823    Picture.Hash := Hash;
    824     IsNew := Tribe[p].ChooseModelPicture(Picture, code, Turn, ForceNew);
     824    IsNew := Tribe[P].ChooseModelPicture(Picture, Code, Turn, ForceNew);
    825825  end;
    826826  if final then
    827     if not TribeOriginal[p] then
    828       Tribe[p].SetModelPicture(Picture, IsNew)
     827    if not TribeOriginal[P] then
     828      Tribe[P].SetModelPicture(Picture, IsNew)
    829829    else if IsNew then
    830830      Server(CommandWithData(cSetNewModelPicture, Picture.GetCommandDataSize),
     
    834834        0, 0, Picture)
    835835  else
    836     with Tribe[p].ModelPicture[mix] do
     836    with Tribe[P].ModelPicture[mix] do
    837837    begin
    838838      HGr := LoadGraphicSet(Picture.GrName);
     
    841841end;
    842842
    843 function InitEnemyModel(emix: integer): boolean;
     843function InitEnemyModel(emix: Integer): Boolean;
    844844begin
    845845  if GameMode = cMovie then
    846846  begin
    847     result := false;
    848     exit;
     847    Result := False;
     848    Exit;
    849849  end;
    850850  with MyRO.EnemyModel[emix] do
    851851    ChooseModelPicture(Owner, mix, ModelCode(MyRO.EnemyModel[emix]),
    852       ModelHash(MyRO.EnemyModel[emix]), MyRO.Turn, false, true);
    853   result := true;
     852      ModelHash(MyRO.EnemyModel[emix]), MyRO.Turn, False, True);
     853  Result := True;
    854854end;
    855855
    856856procedure InitAllEnemyModels;
    857857var
    858   emix: integer;
     858  emix: Integer;
    859859begin
    860860  for emix := 0 to MyRO.nEnemyModel - 1 do
     
    864864end;
    865865
    866 procedure InitMyModel(mix: integer; final: boolean);
     866procedure InitMyModel(mix: Integer; final: Boolean);
    867867var
    868868  mi: TModelInfo;
    869869begin
    870870  if (GameMode = cMovie) and (MyModel[mix].Kind < $08) then
    871     exit;
     871    Exit;
    872872  // don't exit for special units because cSetModelPicture comes after TellNewModels
    873   MakeModelInfo(me, mix, MyModel[mix], mi);
    874   ChooseModelPicture(me, mix, ModelCode(mi), ModelHash(mi), MyRO.Turn,
    875     false, final);
    876 end;
    877 
    878 function AttackSound(code: integer): string;
    879 begin
    880   result := 'ATTACK_' + char(48 + code div 100 mod 10) +
    881     char(48 + code div 10 mod 10) + char(48 + code mod 10);
    882 end;
    883 
    884 procedure CheckToldNoReturn(uix: integer);
     873  MakeModelInfo(Me, mix, MyModel[mix], mi);
     874  ChooseModelPicture(Me, mix, ModelCode(mi), ModelHash(mi), MyRO.Turn,
     875    False, final);
     876end;
     877
     878function AttackSound(Code: Integer): string;
     879begin
     880  Result := 'ATTACK_' + char(48 + Code div 100 mod 10) +
     881    char(48 + Code div 10 mod 10) + char(48 + Code mod 10);
     882end;
     883
     884procedure CheckToldNoReturn(uix: Integer);
    885885// check whether aircraft survived low-fuel warning
    886886begin
    887   assert(not supervising);
     887  Assert(not Supervising);
    888888  with MyUn[uix] do
    889889    if (Status and usToldNoReturn <> 0) and
     
    893893end;
    894894
    895 function CreateTribe(p: integer; FileName: string; Original: boolean): boolean;
     895function CreateTribe(P: Integer; FileName: string; Original: Boolean): Boolean;
    896896begin
    897897  FileName := LocalizedFilePath('Tribes' + DirectorySeparator + FileName +
     
    903903  end;
    904904
    905   TribeOriginal[p] := Original;
    906   Tribe[p] := TTribe.Create(FileName);
    907   with Tribe[p] do
     905  TribeOriginal[P] := Original;
     906  Tribe[P] := TTribe.Create(FileName);
     907  with Tribe[P] do
    908908  begin
    909909    if (GameMode = cNewGame) or not Original then
    910910    begin
    911       Term.ChooseModelPicture(p, 0, 010, 1, 0, true, true);
    912       Term.ChooseModelPicture(p, 1, 040, 1, 0, true, true);
    913       Term.ChooseModelPicture(p, 2, 041, 1, 0, true, true);
    914       Term.ChooseModelPicture(p, -1, 017, 1, 0, true, true);
    915     end;
    916     DipMem[p].pContact := -1;
    917   end;
    918   result := true;
     911      Term.ChooseModelPicture(P, 0, 010, 1, 0, True, True);
     912      Term.ChooseModelPicture(P, 1, 040, 1, 0, True, True);
     913      Term.ChooseModelPicture(P, 2, 041, 1, 0, True, True);
     914      Term.ChooseModelPicture(P, -1, 017, 1, 0, True, True);
     915    end;
     916    DipMem[P].pContact := -1;
     917  end;
     918  Result := True;
    919919end;
    920920
    921921procedure TellNewContacts;
    922922var
    923   p1: integer;
    924 begin
    925   if not supervising then
     923  p1: Integer;
     924begin
     925  if not Supervising then
    926926    for p1 := 0 to nPl - 1 do
    927       if (p1 <> me) and (1 shl p1 and MyData.ToldContact = 0) and
     927      if (p1 <> Me) and (1 shl p1 and MyData.ToldContact = 0) and
    928928        (1 shl p1 and MyRO.Alive <> 0) and (MyRO.Treaty[p1] > trNoContact) then
    929929      begin
     
    935935procedure TellNewModels;
    936936var
    937   mix: integer;
     937  mix: Integer;
    938938  ModelNameInfo: TModelNameInfo;
    939939begin
    940   if supervising then
    941     exit;
    942   with Tribe[me] do
     940  if Supervising then
     941    Exit;
     942  with Tribe[Me] do
    943943    while MyData.ToldModels < MyRO.nModel do
    944944    begin { new Unit class available }
     
    951951      end;
    952952      if not Assigned(ModelPicture[MyData.ToldModels].HGr) then
    953         InitMyModel(MyData.ToldModels, true);
     953        InitMyModel(MyData.ToldModels, True);
    954954      { only run if no researched model }
    955955      with MessgExDlg do
     
    983983             (ModelNameInfo.GetCommandDataSize - 1 - CommandDataMaxSize), MaxInt);
    984984          Server(CommandWithData(cSetModelName, ModelNameInfo.GetCommandDataSize),
    985             me, 0, ModelNameInfo);
     985            Me, 0, ModelNameInfo);
    986986        end;
    987987      end;
     
    992992            MyModel[mix].Status := MyModel[mix].Status or msObsolete;
    993993      end;
    994       inc(MyData.ToldModels);
     994      Inc(MyData.ToldModels);
    995995    end;
    996996end;
     
    10171017end;
    10181018
    1019 procedure TMainScreen.PaintZoomedTile(dst: TBitmap; x, y, Loc: integer);
    1020 
    1021   procedure TSprite(xDst, yDst, xSrc, ySrc: integer);
     1019procedure TMainScreen.PaintZoomedTile(dst: TBitmap; X, Y, Loc: Integer);
     1020
     1021  procedure TSprite(xDst, yDst, xSrc, ySrc: Integer);
    10221022  begin
    10231023    with NoMapPanel do
    1024       Sprite(dst, HGrTerrain, x + xDst, y + yDst, xxt * 2, yyt * 3,
     1024      Sprite(dst, HGrTerrain, X + xDst, Y + yDst, xxt * 2, yyt * 3,
    10251025        1 + xSrc * (xxt * 2 + 1), 1 + ySrc * (yyt * 3 + 1));
    10261026  end;
    10271027
    1028   procedure TSprite4(xSrc, ySrc: integer);
     1028  procedure TSprite4(xSrc, ySrc: Integer);
    10291029  begin
    10301030    with NoMapPanel do begin
    1031       Sprite(dst, HGrTerrain, x + xxt, y + yyt + 2, xxt * 2, yyt * 2 - 2,
     1031      Sprite(dst, HGrTerrain, X + xxt, Y + yyt + 2, xxt * 2, yyt * 2 - 2,
    10321032        1 + xSrc * (xxt * 2 + 1), 3 + yyt + ySrc * (yyt * 3 + 1));
    1033       Sprite(dst, HGrTerrain, x + 4, y + 2 * yyt, xxt * 2 - 4, yyt * 2,
     1033      Sprite(dst, HGrTerrain, X + 4, Y + 2 * yyt, xxt * 2 - 4, yyt * 2,
    10341034        5 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1));
    1035       Sprite(dst, HGrTerrain, x + xxt * 2, y + 2 * yyt, xxt * 2 - 4, yyt * 2,
     1035      Sprite(dst, HGrTerrain, X + xxt * 2, Y + 2 * yyt, xxt * 2 - 4, yyt * 2,
    10361036        1 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1));
    1037       Sprite(dst, HGrTerrain, x + xxt, y + yyt * 3, xxt * 2, yyt * 2 - 2,
     1037      Sprite(dst, HGrTerrain, X + xxt, Y + yyt * 3, xxt * 2, yyt * 2 - 2,
    10381038        1 + xSrc * (xxt * 2 + 1), 1 + yyt + ySrc * (yyt * 3 + 1));
    10391039    end;
     
    10411041
    10421042var
    1043   cix, ySrc, Tile: integer;
     1043  cix, ySrc, Tile: Integer;
    10441044begin
    10451045  with NoMapPanel do begin
     
    10551055        cix := MyRO.nCity - 1;
    10561056        while (cix >= 0) and (MyCity[cix].Loc <> Loc) do
    1057           dec(cix);
    1058         assert(cix >= 0);
     1057          Dec(cix);
     1058        Assert(cix >= 0);
    10591059        if MyCity[cix].Built[imSupermarket] > 0 then
    10601060          Tile := Tile or tiFarm
     
    11471147end;
    11481148
    1149 function ChooseResearch: boolean;
     1149function ChooseResearch: Boolean;
    11501150var
    1151   ChosenResearch: integer;
     1151  ChosenResearch: Integer;
    11521152begin
    11531153  if (MyData.FarTech <> adNone) and (MyRO.Tech[MyData.FarTech] >= tsApplicable)
     
    11581158    repeat
    11591159      ModalSelectDlg.ShowNewContent(wmModal, kAdvance);
    1160       if ModalSelectDlg.result < 0 then
    1161       begin
    1162         result := false;
    1163         exit;
    1164       end;
    1165       ChosenResearch := ModalSelectDlg.result;
     1160      if ModalSelectDlg.Result < 0 then
     1161      begin
     1162        Result := False;
     1163        Exit;
     1164      end;
     1165      ChosenResearch := ModalSelectDlg.Result;
    11661166      if ChosenResearch = adMilitary then
    11671167      begin
    11681168        DraftDlg.ShowNewContent(wmModal);
    11691169        if DraftDlg.ModalResult <> mrOK then
    1170           Tribe[me].ModelPicture[MyRO.nModel].HGr := nil;
     1170          Tribe[Me].ModelPicture[MyRO.nModel].HGr := nil;
    11711171      end;
    11721172    until (ChosenResearch <> adMilitary) or (DraftDlg.ModalResult = mrOK);
    11731173
    11741174    if ChosenResearch = adMilitary then
    1175       InitMyModel(MyRO.nModel, true)
     1175      InitMyModel(MyRO.nModel, True)
    11761176    else if ChosenResearch = adFar then
    11771177    begin
    11781178      ModalSelectDlg.ShowNewContent(wmModal, kFarAdvance);
    1179       if ModalSelectDlg.result >= 0 then
    1180         if (ModalSelectDlg.result = adNone) or
    1181           (Server(sSetResearch - sExecute, me, ModalSelectDlg.result, nil^) <
     1179      if ModalSelectDlg.Result >= 0 then
     1180        if (ModalSelectDlg.Result = adNone) or
     1181          (Server(sSetResearch - sExecute, Me, ModalSelectDlg.Result, nil^) <
    11821182          rExecuted) then
    1183           MyData.FarTech := ModalSelectDlg.result
     1183          MyData.FarTech := ModalSelectDlg.Result
    11841184        else
    11851185        begin
    1186           ChosenResearch := ModalSelectDlg.result;
     1186          ChosenResearch := ModalSelectDlg.Result;
    11871187          // can be researched immediately
    11881188          MyData.FarTech := adNone;
     
    11931193    MyData.FarTech := adNexus
    11941194  else
    1195     Server(sSetResearch, me, ChosenResearch, nil^);
     1195    Server(sSetResearch, Me, ChosenResearch, nil^);
    11961196  ListDlg.TechChange;
    1197   result := true;
     1197  Result := True;
    11981198end;
    11991199
     
    12231223(* ** client function handling ** *)
    12241224
    1225 function TMainScreen.DipCall(Command: integer): integer;
     1225function TMainScreen.DipCall(Command: Integer): Integer;
    12261226var
    1227   i: integer;
    1228   IsTreatyDeal: boolean;
    1229 begin
    1230   result := Server(Command, me, 0, nil^);
    1231   if result >= rExecuted then
     1227  I: Integer;
     1228  IsTreatyDeal: Boolean;
     1229begin
     1230  Result := Server(Command, Me, 0, nil^);
     1231  if Result >= rExecuted then
    12321232  begin
    12331233    if Command and $FF0F = scContact then
    12341234    begin
    1235       DipMem[me].pContact := Command shr 4 and $F;
     1235      DipMem[Me].pContact := Command shr 4 and $F;
    12361236      NegoDlg.Initiate;
    1237       DipMem[me].DeliveredPrices := [];
    1238       DipMem[me].ReceivedPrices := [];
    1239     end;
    1240 
    1241     DipMem[me].SentCommand := Command;
    1242     DipMem[me].FormerTreaty := MyRO.Treaty[DipMem[me].pContact];
     1237      DipMem[Me].DeliveredPrices := [];
     1238      DipMem[Me].ReceivedPrices := [];
     1239    end;
     1240
     1241    DipMem[Me].SentCommand := Command;
     1242    DipMem[Me].FormerTreaty := MyRO.Treaty[DipMem[Me].pContact];
    12431243    if Command = scDipCancelTreaty then
    12441244      Play('CANCELTREATY')
    12451245    else if Command = scDipAccept then
    12461246    begin // remember delivered and received prices
    1247       for i := 0 to ReceivedOffer.nDeliver - 1 do
    1248         include(DipMem[me].ReceivedPrices, ReceivedOffer.Price[i] shr 24);
    1249       for i := 0 to ReceivedOffer.nCost - 1 do
    1250         include(DipMem[me].DeliveredPrices,
    1251           ReceivedOffer.Price[ReceivedOffer.nDeliver + i] shr 24);
    1252       IsTreatyDeal := false;
    1253       for i := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do
    1254         if ReceivedOffer.Price[i] and opMask = opTreaty then
    1255           IsTreatyDeal := true;
     1247      for I := 0 to ReceivedOffer.nDeliver - 1 do
     1248        Include(DipMem[Me].ReceivedPrices, ReceivedOffer.Price[I] shr 24);
     1249      for I := 0 to ReceivedOffer.nCost - 1 do
     1250        Include(DipMem[Me].DeliveredPrices,
     1251          ReceivedOffer.Price[ReceivedOffer.nDeliver + I] shr 24);
     1252      IsTreatyDeal := False;
     1253      for I := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do
     1254        if ReceivedOffer.Price[I] and opMask = opTreaty then
     1255          IsTreatyDeal := True;
    12561256      if IsTreatyDeal then
    12571257        Play('NEWTREATY')
     
    12601260    end;
    12611261    CityDlg.CloseAction := None;
    1262     if G.RO[DipMem[me].pContact] <> nil then
     1262    if G.RO[DipMem[Me].pContact] <> nil then
    12631263    begin // close windows for next player
    12641264      ApplyToVisibleForms(faClose);
     
    12741274end;
    12751275
    1276 function TMainScreen.OfferCall(var Offer: TOffer): integer;
    1277 begin
    1278   result := Server(scDipOffer, me, 0, Offer);
    1279   if result >= rExecuted then
    1280   begin
    1281     DipMem[me].SentCommand := scDipOffer;
    1282     DipMem[me].FormerTreaty := MyRO.Treaty[DipMem[me].pContact];
    1283     DipMem[me].SentOffer := Offer;
     1276function TMainScreen.OfferCall(var Offer: TOffer): Integer;
     1277begin
     1278  Result := Server(scDipOffer, Me, 0, Offer);
     1279  if Result >= rExecuted then
     1280  begin
     1281    DipMem[Me].SentCommand := scDipOffer;
     1282    DipMem[Me].FormerTreaty := MyRO.Treaty[DipMem[Me].pContact];
     1283    DipMem[Me].SentOffer := Offer;
    12841284    CityDlg.CloseAction := None;
    1285     if G.RO[DipMem[me].pContact] <> nil then
     1285    if G.RO[DipMem[Me].pContact] <> nil then
    12861286    begin // close windows for next player
    12871287      ApplyToVisibleForms(faClose);
     
    12971297end;
    12981298
    1299 procedure TMainScreen.SetUnFocus(uix: integer);
     1299procedure TMainScreen.SetUnFocus(uix: Integer);
    13001300var
    1301   Loc0: integer;
    1302 begin
    1303   assert(not((uix >= 0) and supervising));
     1301  Loc0: Integer;
     1302begin
     1303  Assert(not((uix >= 0) and Supervising));
    13041304  if uix <> UnFocus then
    13051305  begin
    1306     DestinationMarkON := false;
     1306    DestinationMarkON := False;
    13071307    PaintDestination;
    13081308    if uix >= 0 then
    13091309      UnStartLoc := MyUn[uix].Loc;
    1310     BlinkON := false;
     1310    BlinkON := False;
    13111311    BlinkTime := -1;
    13121312    if UnFocus >= 0 then
     
    13281328procedure TMainScreen.CheckTerrainBtnVisible;
    13291329var
    1330   Tile: integer;
     1330  Tile: Integer;
    13311331  mox: ^TModel;
    13321332begin
     
    13401340  end
    13411341  else
    1342     TerrainBtn.Visible := false;
     1342    TerrainBtn.Visible := False;
    13431343end;
    13441344
     
    13481348  begin
    13491349    MovieSpeed1Btn.Down := MovieSpeed = 1;
    1350     MovieSpeed1Btn.Visible := true;
     1350    MovieSpeed1Btn.Visible := True;
    13511351    MovieSpeed2Btn.Down := MovieSpeed = 2;
    1352     MovieSpeed2Btn.Visible := true;
     1352    MovieSpeed2Btn.Visible := True;
    13531353    MovieSpeed3Btn.Down := MovieSpeed = 3;
    1354     MovieSpeed3Btn.Visible := true;
     1354    MovieSpeed3Btn.Visible := True;
    13551355    MovieSpeed4Btn.Down := MovieSpeed = 4;
    1356     MovieSpeed4Btn.Visible := true;
     1356    MovieSpeed4Btn.Visible := True;
    13571357  end
    13581358  else
    13591359  begin
    1360     MovieSpeed1Btn.Visible := false;
    1361     MovieSpeed2Btn.Visible := false;
    1362     MovieSpeed3Btn.Visible := false;
    1363     MovieSpeed4Btn.Visible := false;
     1360    MovieSpeed1Btn.Visible := False;
     1361    MovieSpeed2Btn.Visible := False;
     1362    MovieSpeed3Btn.Visible := False;
     1363    MovieSpeed4Btn.Visible := False;
    13641364  end;
    13651365end;
     
    13751375end;
    13761376
    1377 procedure TMainScreen.UpdateViews(UpdateCityScreen: boolean);
     1377procedure TMainScreen.UpdateViews(UpdateCityScreen: Boolean);
    13781378begin
    13791379  SumCities(TaxSum, ScienceSum);
     
    13851385end;
    13861386
    1387 procedure TMainScreen.SetAIName(p: integer; Name: string);
     1387procedure TMainScreen.SetAIName(P: Integer; Name: string);
    13881388begin
    13891389  if Name = '' then
    13901390  begin
    1391     if AILogo[p] <> nil then
    1392     begin
    1393       FreeAndNil(AILogo[p]);
     1391    if AILogo[P] <> nil then
     1392    begin
     1393      FreeAndNil(AILogo[P]);
    13941394    end;
    13951395  end
    13961396  else
    13971397  begin
    1398     if AILogo[p] = nil then
    1399       AILogo[p] := TBitmap.Create;
    1400     if not LoadGraphicFile(AILogo[p], HomeDir + Name + '.png', [gfNoError]) then
    1401     begin
    1402       FreeAndNil(AILogo[p]);
    1403     end;
    1404   end;
    1405 end;
    1406 
    1407 function TMainScreen.ContactRefused(p: integer; Item: String): boolean;
     1398    if AILogo[P] = nil then
     1399      AILogo[P] := TBitmap.Create;
     1400    if not LoadGraphicFile(AILogo[P], HomeDir + Name + '.png', [gfNoError]) then
     1401    begin
     1402      FreeAndNil(AILogo[P]);
     1403    end;
     1404  end;
     1405end;
     1406
     1407function TMainScreen.ContactRefused(P: Integer; Item: String): Boolean;
    14081408// return whether treaty was cancelled
    14091409var
    1410   s: string;
    1411 begin
    1412   assert(MyRO.Treaty[p] >= trPeace);
    1413   s := Tribe[p].TPhrase(Item);
    1414   if MyRO.Turn < MyRO.LastCancelTreaty[p] + CancelTreatyTurns then
    1415   begin
    1416     SimpleMessage(s);
    1417     result := false;
     1410  S: string;
     1411begin
     1412  Assert(MyRO.Treaty[P] >= trPeace);
     1413  S := Tribe[P].TPhrase(Item);
     1414  if MyRO.Turn < MyRO.LastCancelTreaty[P] + CancelTreatyTurns then
     1415  begin
     1416    SimpleMessage(S);
     1417    Result := False;
    14181418  end
    14191419  else
    14201420  begin
    1421     case MyRO.Treaty[p] of
     1421    case MyRO.Treaty[P] of
    14221422      trPeace:
    1423         s := s + ' ' + Phrases.Lookup('FRCANCELQUERY_PEACE');
     1423        S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_PEACE');
    14241424      trFriendlyContact:
    1425         s := s + ' ' + Phrases.Lookup('FRCANCELQUERY_FRIENDLY');
     1425        S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_FRIENDLY');
    14261426      trAlliance:
    1427         s := s + ' ' + Phrases.Lookup('FRCANCELQUERY_ALLIANCE');
    1428     end;
    1429     result := SimpleQuery(mkYesNo, s, 'NEGO_REJECTED') = mrOK;
    1430     if result then
     1427        S := S + ' ' + Phrases.Lookup('FRCANCELQUERY_ALLIANCE');
     1428    end;
     1429    Result := SimpleQuery(mkYesNo, S, 'NEGO_REJECTED') = mrOK;
     1430    if Result then
    14311431    begin
    14321432      Play('CANCELTREATY');
    1433       Server(sCancelTreaty, me, 0, nil^);
    1434       if MyRO.Treaty[p] = trNone then
     1433      Server(sCancelTreaty, Me, 0, nil^);
     1434      if MyRO.Treaty[P] = trNone then
    14351435        CityOptimizer_BeginOfTurn;
    14361436      // peace treaty was cancelled -- use formerly forbidden tiles
    1437       MapValid := false;
     1437      MapValid := False;
    14381438      PaintAllMaps;
    14391439    end;
     
    14431443procedure TMainScreen.RememberPeaceViolation;
    14441444var
    1445   uix, p1: integer;
     1445  uix, p1: Integer;
    14461446begin
    14471447  MyData.PeaceEvaHappened := 0;
     
    14511451      begin
    14521452        p1 := MyRO.Territory[Loc];
    1453         if (p1 <> me) and (p1 >= 0) and
     1453        if (p1 <> Me) and (p1 >= 0) and
    14541454          (MyRO.Turn = MyRO.EvaStart[p1] + (PeaceEvaTurns - 1)) then
    14551455          MyData.PeaceEvaHappened := MyData.PeaceEvaHappened or (1 shl p1);
     
    14891489
    14901490var
    1491   i, cix, mix: integer;
    1492   need: boolean;
     1491  I, cix, mix: Integer;
     1492  need: Boolean;
    14931493  mi: TModelInfo;
    14941494begin
    14951495  if (sbStart in Check) and not (sbStart in SoundPreloadDone) then begin
    1496     for i := 0 to nStartBlock - 1 do
    1497       PreparePlay(StartBlock[i]);
     1496    for I := 0 to nStartBlock - 1 do
     1497      PreparePlay(StartBlock[I]);
    14981498    SoundPreloadDone := SoundPreloadDone + [sbStart];
    14991499  end;
    15001500  if (sbWonder in Check) and not (sbWonder in SoundPreloadDone) then begin
    1501     need := false;
    1502     for i := 0 to nWonder - 1 do
    1503       if MyRO.Wonder[i].CityID <> WonderNotBuiltYet then
    1504         need := true;
     1501    need := False;
     1502    for I := 0 to nWonder - 1 do
     1503      if MyRO.Wonder[I].CityID <> WonderNotBuiltYet then
     1504        need := True;
    15051505    if need then begin
    1506       for i := 0 to nWonderBlock - 1 do
    1507         PreparePlay(WonderBlock[i]);
     1506      for I := 0 to nWonderBlock - 1 do
     1507        PreparePlay(WonderBlock[I]);
    15081508      SoundPreloadDone := SoundPreloadDone + [sbWonder];
    15091509    end;
     
    15111511  if ((sbScience in Check) and not (sbScience in SoundPreloadDone)) and
    15121512    (MyRO.Tech[adScience] >= tsApplicable) then begin
    1513     for i := 0 to nScienceBlock - 1 do
    1514       PreparePlay(ScienceBlock[i]);
     1513    for I := 0 to nScienceBlock - 1 do
     1514      PreparePlay(ScienceBlock[I]);
    15151515    SoundPreloadDone := SoundPreloadDone + [sbScience];
    15161516  end;
    15171517  if ((sbContact in Check) and not (sbContact in SoundPreloadDone)) and
    15181518    (MyRO.nEnemyModel + MyRO.nEnemyCity > 0) then begin
    1519     for i := 0 to nContactBlock - 1 do
    1520       PreparePlay(ContactBlock[i]);
     1519    for I := 0 to nContactBlock - 1 do
     1520      PreparePlay(ContactBlock[I]);
    15211521    SoundPreloadDone := SoundPreloadDone + [sbContact];
    15221522  end;
     
    15291529      with MyCity[cix] do
    15301530        if (Loc >= 0) and (Flags and CityRepMask <> 0) then
    1531           for i := 0 to 12 do
    1532             if 1 shl i and Flags and CityRepMask <> 0 then
    1533               PreparePlay(CityEventSoundItem[i]);
     1531          for I := 0 to 12 do
     1532            if 1 shl I and Flags and CityRepMask <> 0 then
     1533              PreparePlay(CityEventSoundItem[I]);
    15341534    for mix := 0 to MyRO.nModel - 1 do
    15351535      with MyModel[mix] do
    15361536        if Attack > 0 then
    15371537        begin
    1538           MakeModelInfo(me, mix, MyModel[mix], mi);
     1538          MakeModelInfo(Me, mix, MyModel[mix], mi);
    15391539          PreparePlay(AttackSound(ModelCode(mi)));
    15401540        end;
     
    15471547  Color: TColor;
    15481548  Name: string;
    1549   ok: boolean;
     1549  ok: Boolean;
    15501550begin
    15511551  UnusedTribeFiles.Clear;
     
    15671567end;
    15681568
    1569 function TMainScreen.ChooseUnusedTribe: integer;
     1569function TMainScreen.ChooseUnusedTribe: Integer;
    15701570var
    1571   i: Integer;
    1572   j: Integer;
     1571  I: Integer;
     1572  J: Integer;
    15731573  ColorDistance: Integer;
    15741574  BestColorDistance: Integer;
     
    15761576  CountBest: Integer;
    15771577begin
    1578   assert(UnusedTribeFiles.Count > 0);
    1579   result := -1;
     1578  Assert(UnusedTribeFiles.Count > 0);
     1579  Result := -1;
    15801580  BestColorDistance := -1;
    1581   for j := 0 to UnusedTribeFiles.Count - 1 do
     1581  for J := 0 to UnusedTribeFiles.Count - 1 do
    15821582  begin
    15831583    ColorDistance := 250; // consider differences more than this infinite
    1584     for i := 0 to nPl - 1 do
    1585       if Tribe[i] <> nil then
    1586       begin
    1587         TestColorDistance := abs(integer(UnusedTribeFiles.Objects[j])
    1588           shr 16 and $FF - Tribe[i].Color shr 16 and $FF) +
    1589           abs(integer(UnusedTribeFiles.Objects[j]) shr 8 and
    1590           $FF - Tribe[i].Color shr 8 and $FF) * 3 +
    1591           abs(integer(UnusedTribeFiles.Objects[j]) and
    1592           $FF - Tribe[i].Color and $FF) * 2;
     1584    for I := 0 to nPl - 1 do
     1585      if Tribe[I] <> nil then
     1586      begin
     1587        TestColorDistance := abs(Integer(UnusedTribeFiles.Objects[J])
     1588          shr 16 and $FF - Tribe[I].Color shr 16 and $FF) +
     1589          abs(Integer(UnusedTribeFiles.Objects[J]) shr 8 and
     1590          $FF - Tribe[I].Color shr 8 and $FF) * 3 +
     1591          abs(Integer(UnusedTribeFiles.Objects[J]) and
     1592          $FF - Tribe[I].Color and $FF) * 2;
    15931593        if TestColorDistance < ColorDistance then
    15941594          ColorDistance := TestColorDistance;
     
    16011601    if ColorDistance = BestColorDistance then
    16021602    begin
    1603       inc(CountBest);
     1603      Inc(CountBest);
    16041604      if DelphiRandom(CountBest) = 0 then
    1605         result := j;
     1605        Result := J;
    16061606    end;
    16071607  end;
     
    16101610procedure TMainScreen.ShowEnemyShipChange(ShowShipChange: TShowShipChange);
    16111611var
    1612   i, TestCost, MostCost: integer;
    1613   Ship1Plus, Ship2Plus: boolean;
     1612  I, TestCost, MostCost: Integer;
     1613  Ship1Plus, Ship2Plus: Boolean;
    16141614begin
    16151615  with ShowShipChange, MessgExDlg do
     
    16341634        begin
    16351635          OpenSound := 'SHIP_TRADED';
    1636           Ship1Plus := false;
    1637           Ship2Plus := false;
    1638           for i := 0 to nShipPart - 1 do
     1636          Ship1Plus := False;
     1637          Ship2Plus := False;
     1638          for I := 0 to nShipPart - 1 do
    16391639          begin
    1640             if Ship1Change[i] > 0 then
    1641               Ship1Plus := true;
    1642             if Ship2Change[i] > 0 then
    1643               Ship2Plus := true;
     1640            if Ship1Change[I] > 0 then
     1641              Ship1Plus := True;
     1642            if Ship2Change[I] > 0 then
     1643              Ship2Plus := True;
    16441644          end;
    16451645          if Ship1Plus and Ship2Plus then
     
    16681668    begin
    16691669      MostCost := 0;
    1670       for i := 0 to nShipPart - 1 do
    1671       begin
    1672         TestCost := abs(Ship1Change[i]) * Imp[imShipComp + i].Cost;
     1670      for I := 0 to nShipPart - 1 do
     1671      begin
     1672        TestCost := abs(Ship1Change[I]) * Imp[imShipComp + I].Cost;
    16731673        if TestCost > MostCost then
    16741674        begin
    16751675          MostCost := TestCost;
    1676           IconIndex := imShipComp + i;
     1676          IconIndex := imShipComp + I;
    16771677        end;
    16781678      end;
     
    16861686procedure TMainScreen.InitModule;
    16871687var
    1688   i, j, Domain: integer;
     1688  I, J, Domain: Integer;
    16891689begin
    16901690  { search icons for advances: }
    1691   for i := 0 to nAdv - 1 do
    1692     if i in FutureTech then
    1693       AdvIcon[i] := 96 + i - futResearchTechnology
     1691  for I := 0 to nAdv - 1 do
     1692    if I in FutureTech then
     1693      AdvIcon[I] := 96 + I - futResearchTechnology
    16941694    else
    16951695    begin
    1696       AdvIcon[i] := -1;
     1696      AdvIcon[I] := -1;
    16971697      for Domain := 0 to nDomains - 1 do
    1698         for j := 0 to nUpgrade - 1 do
    1699           if upgrade[Domain, j].Preq = i then
    1700             if AdvIcon[i] >= 0 then
    1701               AdvIcon[i] := 85
     1698        for J := 0 to nUpgrade - 1 do
     1699          if upgrade[Domain, J].Preq = I then
     1700            if AdvIcon[I] >= 0 then
     1701              AdvIcon[I] := 85
    17021702            else
    1703               AdvIcon[i] := 86 + Domain;
    1704       for j := 0 to nFeature - 1 do
    1705         if Feature[j].Preq = i then
     1703              AdvIcon[I] := 86 + Domain;
     1704      for J := 0 to nFeature - 1 do
     1705        if Feature[J].Preq = I then
    17061706          for Domain := 0 to nDomains - 1 do
    1707             if 1 shl Domain and Feature[j].Domains <> 0 then
    1708               if (AdvIcon[i] >= 0) and (AdvIcon[i] <> 86 + Domain) then
    1709                 AdvIcon[i] := 85
     1707            if 1 shl Domain and Feature[J].Domains <> 0 then
     1708              if (AdvIcon[I] >= 0) and (AdvIcon[I] <> 86 + Domain) then
     1709                AdvIcon[I] := 85
    17101710              else
    1711                 AdvIcon[i] := 86 + Domain;
    1712       for j := nWonder to nImp - 1 do
    1713         if Imp[j].Preq = i then
    1714           AdvIcon[i] := j;
    1715       for j := nWonder to nImp - 1 do
    1716         if (Imp[j].Preq = i) and (Imp[j].Kind <> ikCommon) then
    1717           AdvIcon[i] := j;
    1718       for j := 0 to nJob - 1 do
    1719         if i = JobPreq[j] then
    1720           AdvIcon[i] := 84;
    1721       for j := 0 to nWonder - 1 do
    1722         if Imp[j].Preq = i then
    1723           AdvIcon[i] := j;
    1724       if AdvIcon[i] < 0 then
    1725         if AdvValue[i] < 1000 then
    1726           AdvIcon[i] := -7
     1711                AdvIcon[I] := 86 + Domain;
     1712      for J := nWonder to nImp - 1 do
     1713        if Imp[J].Preq = I then
     1714          AdvIcon[I] := J;
     1715      for J := nWonder to nImp - 1 do
     1716        if (Imp[J].Preq = I) and (Imp[J].Kind <> ikCommon) then
     1717          AdvIcon[I] := J;
     1718      for J := 0 to nJob - 1 do
     1719        if I = JobPreq[J] then
     1720          AdvIcon[I] := 84;
     1721      for J := 0 to nWonder - 1 do
     1722        if Imp[J].Preq = I then
     1723          AdvIcon[I] := J;
     1724      if AdvIcon[I] < 0 then
     1725        if AdvValue[I] < 1000 then
     1726          AdvIcon[I] := -7
    17271727        else
    1728           AdvIcon[i] := 24 + AdvValue[i] div 1000;
    1729       for j := 2 to nGov - 1 do
    1730         if GovPreq[j] = i then
    1731           AdvIcon[i] := j - 8;
     1728          AdvIcon[I] := 24 + AdvValue[I] div 1000;
     1729      for J := 2 to nGov - 1 do
     1730        if GovPreq[J] = I then
     1731          AdvIcon[I] := J - 8;
    17321732    end;
    17331733  AdvIcon[adConscription] := 86 + dGround;
    17341734
    17351735  UnusedTribeFiles := tstringlist.Create;
    1736   UnusedTribeFiles.Sorted := true;
     1736  UnusedTribeFiles.Sorted := True;
    17371737  TribeNames := tstringlist.Create;
    17381738
    17391739  IsoEngine.Init(InitEnemyModel);
    17401740  // non-default tile size is missing a file, switch to default
    1741   MainMap.SetOutput(offscreen);
     1741  MainMap.SetOutput(Offscreen);
    17421742
    17431743  HGrStdUnits := LoadGraphicSet('StdUnits.png');
     
    17461746  InitSmallImp;
    17471747  SoundPreloadDone := [];
    1748   StartRunning := false;
    1749   StayOnTop_Ensured := false;
     1748  StartRunning := False;
     1749  StayOnTop_Ensured := False;
    17501750
    17511751  sb := TPVScrollbar.Create(Self);
     
    17611761end;
    17621762
    1763 procedure TMainScreen.InitTurn(NewPlayer: integer);
     1763procedure TMainScreen.InitTurn(NewPlayer: Integer);
    17641764const
    17651765  nAdvBookIcon = 16;
    17661766  AdvBookIcon: array [0 .. nAdvBookIcon - 1] of record Adv,
    1767     Icon: integer end = ((Adv: adPolyTheism; Icon: woZeus),
     1767    Icon: Integer end = ((Adv: adPolyTheism; Icon: woZeus),
    17681768    (Adv: adBronzeWorking; Icon: woColossus), (Adv: adMapMaking;
    17691769    Icon: woLighthouse), (Adv: adPoetry; Icon: imTheater), (Adv: adMonotheism;
     
    17771777  sbAll = [sbStart, sbWonder, sbScience, sbContact, sbTurn];
    17781778var
    1779   p1, i, ad, uix, cix, MoveOptions, MoveResult, Loc1,
     1779  p1, I, ad, uix, cix, MoveOptions, MoveResult, Loc1,
    17801780    NewAgeCenterTo, Winners, NewGovAvailable, dx,
    1781     dy: integer;
     1781    dy: Integer;
    17821782  MoveAdviceData: TMoveAdviceData;
    17831783  Picture: TModelPictureInfo;
    1784   s, Item, Item2: string;
     1784  S, Item, Item2: string;
    17851785  UpdatePanel, OwnWonder, ok, Stop, ShowCityList, WondersOnly,
    1786     AllowCityScreen: boolean;
    1787 begin
    1788   if IsMultiPlayerGame and (NewPlayer <> me) then
    1789   begin
    1790     UnitInfoBtn.Visible := false;
    1791     UnitBtn.Visible := false;
    1792     TerrainBtn.Visible := false;
    1793     EOT.Visible := false;
    1794   end;
    1795   if IsMultiPlayerGame and (NewPlayer <> me) and
     1786    AllowCityScreen: Boolean;
     1787begin
     1788  if IsMultiPlayerGame and (NewPlayer <> Me) then
     1789  begin
     1790    UnitInfoBtn.Visible := False;
     1791    UnitBtn.Visible := False;
     1792    TerrainBtn.Visible := False;
     1793    EOT.Visible := False;
     1794  end;
     1795  if IsMultiPlayerGame and (NewPlayer <> Me) and
    17961796    (G.RO[0].Happened and phShipComplete = 0) then
    17971797  begin // inter player screen
    1798     for i := 0 to ControlCount - 1 do
    1799       if Controls[i] is TButtonC then
    1800         Controls[i].Visible := false;
    1801     me := -1;
     1798    for I := 0 to ControlCount - 1 do
     1799      if Controls[I] is TButtonC then
     1800        Controls[I].Visible := False;
     1801    Me := -1;
    18021802    MainTexture.Age := -1;
    18031803    with Panel.Canvas do
     
    18151815    Invalidate;
    18161816
    1817     s := TurnToString(G.RO[0].Turn);
    1818     if supervising then
    1819       SimpleMessage(Format(Phrases.Lookup('SUPERTURN'), [s]))
     1817    S := TurnToString(G.RO[0].Turn);
     1818    if Supervising then
     1819      SimpleMessage(Format(Phrases.Lookup('SUPERTURN'), [S]))
    18201820    else
    1821       SimpleMessage(Format(Tribe[NewPlayer].TPhrase('TURN'), [s]));
    1822   end;
    1823   for i := 0 to ControlCount - 1 do
    1824     if Controls[i] is TButtonC then
    1825       Controls[i].Visible := true;
     1821      SimpleMessage(Format(Tribe[NewPlayer].TPhrase('TURN'), [S]));
     1822  end;
     1823  for I := 0 to ControlCount - 1 do
     1824    if Controls[I] is TButtonC then
     1825      Controls[I].Visible := True;
    18261826
    18271827  ItsMeAgain(NewPlayer);
    18281828  MyData := G.RO[NewPlayer].Data;
    1829   if not supervising then
     1829  if not Supervising then
    18301830    SoundPreload(sbAll);
    1831   if (me = 0) and ((MyRO.Turn = 0) or (ClientMode = cResume)) then
     1831  if (Me = 0) and ((MyRO.Turn = 0) or (ClientMode = cResume)) then
    18321832    Invalidate; // colorize empty space
    18331833
    1834   if not supervising then
     1834  if not Supervising then
    18351835  begin
    18361836
     
    18421842      else }
    18431843    begin
    1844       Age := GetAge(me);
     1844      Age := GetAge(Me);
    18451845      if MainTexture.Age <> Age then begin
    18461846        MainTexture.Age := Age;
     
    18691869  NatStatDlg.CheckAge;
    18701870  UnitStatDlg.CheckAge;
    1871   HelpDlg.Difficulty := G.Difficulty[me];
     1871  HelpDlg.Difficulty := G.Difficulty[Me];
    18721872
    18731873  UnFocus := -1;
    18741874  MarkCityLoc := -1;
    1875   BlinkON := false;
     1875  BlinkON := False;
    18761876  BlinkTime := -1;
    1877   Tracking := false;
    1878   TurnComplete := false;
     1877  Tracking := False;
     1878  TurnComplete := False;
    18791879
    18801880  if (ToldSlavery < 0) or
     
    18961896          Hash := 0;
    18971897          GrName := 'StdUnits.png';
    1898           Tribe[p1].SetModelPicture(Picture, true);
     1898          Tribe[p1].SetModelPicture(Picture, True);
    18991899        end;
    19001900  end;
    19011901
    1902   if not supervising and (ClientMode = cTurn) then
     1902  if not Supervising and (ClientMode = cTurn) then
    19031903  begin
    19041904    for cix := 0 to MyRO.nCity - 1 do
     
    19151915  if ClientMode = cMovieTurn then
    19161916  begin
    1917     UnitInfoBtn.Visible := false;
    1918     UnitBtn.Visible := false;
    1919     TerrainBtn.Visible := false;
     1917    UnitInfoBtn.Visible := False;
     1918    UnitBtn.Visible := False;
     1919    TerrainBtn.Visible := False;
    19201920    EOT.Hint := Phrases.Lookup('BTN_STOP');
    1921     EOT.Visible := true;
     1921    EOT.Visible := True;
    19221922  end
    19231923  else if ClientMode < scContact then
     
    19261926    UnitBtn.Visible := UnFocus >= 0;
    19271927    CheckTerrainBtnVisible;
    1928     TurnComplete := supervising;
     1928    TurnComplete := Supervising;
    19291929    EOT.Hint := Phrases.Lookup('BTN_ENDTURN');
    1930     EOT.Visible := Server(sTurn - sExecute, me, 0, nil^) >= rExecuted;
     1930    EOT.Visible := Server(sTurn - sExecute, Me, 0, nil^) >= rExecuted;
    19311931  end
    19321932  else
    19331933  begin
    1934     UnitInfoBtn.Visible := false;
    1935     UnitBtn.Visible := false;
    1936     TerrainBtn.Visible := false;
     1934    UnitInfoBtn.Visible := False;
     1935    UnitBtn.Visible := False;
     1936    TerrainBtn.Visible := False;
    19371937    EOT.Hint := Phrases.Lookup('BTN_NEGO');
    1938     EOT.Visible := true;
     1938    EOT.Visible := True;
    19391939  end;
    19401940  SetTroopLoc(-1);
    1941   MapValid := false;
     1941  MapValid := False;
    19421942  NewAgeCenterTo := 0;
    1943   if ((MyRO.Turn = 0) and not supervising or IsMultiPlayerGame or
     1943  if ((MyRO.Turn = 0) and not Supervising or IsMultiPlayerGame or
    19441944    (ClientMode = cResume)) and (MyRO.nCity > 0) then
    19451945  begin
     
    19861986        begin
    19871987          OpenSound := 'MSG_GAMEOVER';
    1988           MessgText := Tribe[me].TPhrase('GAMEOVER');
     1988          MessgText := Tribe[Me].TPhrase('GAMEOVER');
    19891989          IconKind := mikBigIcon;
    19901990          IconIndex := 8;
     
    19971997            begin
    19981998              Winners := Winners or 1 shl p1;
    1999               for i := 0 to nShipPart - 1 do
    2000                 if MyRO.Ship[p1].Parts[i] < ShipNeed[i] then
     1999              for I := 0 to nShipPart - 1 do
     2000                if MyRO.Ship[p1].Parts[I] < ShipNeed[I] then
    20012001                  Winners := Winners and not(1 shl p1);
    20022002            end;
    2003           assert(Winners <> 0);
    2004           if Winners and (1 shl me) <> 0 then
     2003          Assert(Winners <> 0);
     2004          if Winners and (1 shl Me) <> 0 then
    20052005          begin
    2006             s := '';
     2006            S := '';
    20072007            for p1 := 0 to nPl - 1 do
    2008               if (p1 <> me) and (1 shl p1 and Winners <> 0) then
    2009                 if s = '' then
    2010                   s := Tribe[p1].TPhrase('SHORTNAME')
     2008              if (p1 <> Me) and (1 shl p1 and Winners <> 0) then
     2009                if S = '' then
     2010                  S := Tribe[p1].TPhrase('SHORTNAME')
    20112011                else
    2012                   s := Format(Phrases.Lookup('SHAREDWIN_CONCAT'),
    2013                     [s, Tribe[p1].TPhrase('SHORTNAME')]);
     2012                  S := Format(Phrases.Lookup('SHAREDWIN_CONCAT'),
     2013                    [S, Tribe[p1].TPhrase('SHORTNAME')]);
    20142014
    20152015            OpenSound := 'MSG_YOUWIN';
    2016             MessgText := Tribe[me].TPhrase('MYSPACESHIP');
    2017             if s <> '' then
     2016            MessgText := Tribe[Me].TPhrase('MYSPACESHIP');
     2017            if S <> '' then
    20182018              MessgText := MessgText + '\' +
    2019                 Format(Phrases.Lookup('SHAREDWIN'), [s]);
     2019                Format(Phrases.Lookup('SHAREDWIN'), [S]);
    20202020            IconKind := mikBigIcon;
    20212021            IconIndex := 9;
     
    20232023          else
    20242024          begin
    2025             assert(me = 0);
     2025            Assert(Me = 0);
    20262026            OpenSound := 'MSG_GAMEOVER';
    20272027            MessgText := '';
     
    20352035        else { if MyRO.Happened and fTimeUp<>0 then }
    20362036        begin
    2037           assert(me = 0);
     2037          Assert(Me = 0);
    20382038          OpenSound := 'MSG_GAMEOVER';
    2039           if not supervising then
    2040             MessgText := Tribe[me].TPhrase('TIMEUP')
     2039          if not Supervising then
     2040            MessgText := Tribe[Me].TPhrase('TIMEUP')
    20412041          else
    20422042            MessgText := Phrases.Lookup('TIMEUPSUPER');
     
    20502050          p1 := 0;
    20512051          while (p1 < nPl - 1) and (Winners and (1 shl p1) = 0) do
    2052             inc(p1);
     2052            Inc(p1);
    20532053          if MyRO.Happened and phShipComplete = 0 then
    20542054            DiaDlg.ShowNewContent_Charts(wmModal);
    20552055        end;
    2056         TurnComplete := true;
    2057         exit;
    2058       end;
    2059     if not supervising and (1 shl me and MyRO.Alive = 0) then
    2060     begin
    2061       TurnComplete := true;
    2062       exit;
     2056        TurnComplete := True;
     2057        Exit;
     2058      end;
     2059    if not Supervising and (1 shl Me and MyRO.Alive = 0) then
     2060    begin
     2061      TurnComplete := True;
     2062      Exit;
    20632063    end;
    20642064
    20652065    if (ClientMode = cContinue) and
    2066       (DipMem[me].SentCommand and $FF0F = scContact) then
     2066      (DipMem[Me].SentCommand and $FF0F = scContact) then
    20672067      // contact was refused
    2068       if MyRO.Treaty[DipMem[me].pContact] >= trPeace then
    2069         ContactRefused(DipMem[me].pContact, 'FRREJECTED')
     2068      if MyRO.Treaty[DipMem[Me].pContact] >= trPeace then
     2069        ContactRefused(DipMem[Me].pContact, 'FRREJECTED')
    20702070      else
    2071         SoundMessage(Tribe[DipMem[me].pContact].TPhrase('FRREJECTED'),
     2071        SoundMessage(Tribe[DipMem[Me].pContact].TPhrase('FRREJECTED'),
    20722072          'NEGO_REJECTED');
    20732073
    2074     if not supervising and (Age > MyData.ToldAge) and
     2074    if not Supervising and (Age > MyData.ToldAge) and
    20752075      ((Age > 0) or (ClientMode <> cMovieTurn)) then
    20762076      with MessgExDlg do
     
    20802080          if Phrases2FallenBackToEnglish then
    20812081          begin
    2082             s := Tribe[me].TPhrase('AGE0');
     2082            S := Tribe[Me].TPhrase('AGE0');
    20832083            MessgText :=
    2084               Format(s, [TurnToString(MyRO.Turn), CityName(MyCity[0].ID)]);
     2084              Format(S, [TurnToString(MyRO.Turn), CityName(MyCity[0].ID)]);
    20852085          end
    20862086          else
    20872087          begin
    2088             s := Tribe[me].TString(Phrases2.Lookup('AGE0'));
    2089             MessgText := Format(s, [TurnToString(MyRO.Turn)]);
     2088            S := Tribe[Me].TString(Phrases2.Lookup('AGE0'));
     2089            MessgText := Format(S, [TurnToString(MyRO.Turn)]);
    20902090          end;
    20912091        end
    20922092        else
    20932093        begin
    2094           s := Tribe[me].TPhrase('AGE' + char(48 + Age));
    2095           MessgText := Format(s, [TurnToString(MyRO.Turn)]);
     2094          S := Tribe[Me].TPhrase('AGE' + char(48 + Age));
     2095          MessgText := Format(S, [TurnToString(MyRO.Turn)]);
    20962096        end;
    20972097        IconKind := mikAge;
     
    21152115          begin
    21162116            OpenSound := 'MSG_EXTINCT';
    2117             s := Tribe[p1].TPhrase('EXTINCT');
    2118             MessgText := Format(s, [TurnToString(MyRO.Turn)]);
    2119             if MyRO.Alive = 1 shl me then
     2117            S := Tribe[p1].TPhrase('EXTINCT');
     2118            MessgText := Format(S, [TurnToString(MyRO.Turn)]);
     2119            if MyRO.Alive = 1 shl Me then
    21202120              MessgText := MessgText + Phrases.Lookup('EXTINCTALL');
    21212121            Kind := mkOk;
     
    21242124            ShowModal;
    21252125          end;
    2126       if (ClientMode <> cMovieTurn) and not supervising then
     2126      if (ClientMode <> cMovieTurn) and not Supervising then
    21272127        DiaDlg.ShowNewContent_Charts(wmModal);
    21282128    end;
    21292129
    21302130    // tell changes of own credibility
    2131     if not supervising then
     2131    if not Supervising then
    21322132    begin
    21332133      if RoughCredibility(MyRO.Credibility) <>
     
    21362136        if RoughCredibility(MyRO.Credibility) >
    21372137          RoughCredibility(MyData.ToldOwnCredibility) then
    2138           s := Phrases.Lookup('CREDUP')
     2138          S := Phrases.Lookup('CREDUP')
    21392139        else
    2140           s := Phrases.Lookup('CREDDOWN');
    2141         TribeMessage(me, Format(s, [Phrases.Lookup('CREDIBILITY',
     2140          S := Phrases.Lookup('CREDDOWN');
     2141        TribeMessage(Me, Format(S, [Phrases.Lookup('CREDIBILITY',
    21422142          RoughCredibility(MyRO.Credibility))]), '');
    21432143      end;
     
    21452145    end;
    21462146
    2147     for i := 0 to nWonder - 1 do
    2148     begin
    2149       OwnWonder := false;
     2147    for I := 0 to nWonder - 1 do
     2148    begin
     2149      OwnWonder := False;
    21502150      for cix := 0 to MyRO.nCity - 1 do
    2151         if (MyCity[cix].Loc >= 0) and (MyCity[cix].ID = MyRO.Wonder[i].CityID)
     2151        if (MyCity[cix].Loc >= 0) and (MyCity[cix].ID = MyRO.Wonder[I].CityID)
    21522152        then
    2153           OwnWonder := true;
    2154       if MyRO.Wonder[i].CityID <> MyData.ToldWonders[i].CityID then
    2155       begin
    2156         if MyRO.Wonder[i].CityID = WonderDestroyed then
     2153          OwnWonder := True;
     2154      if MyRO.Wonder[I].CityID <> MyData.ToldWonders[I].CityID then
     2155      begin
     2156        if MyRO.Wonder[I].CityID = WonderDestroyed then
    21572157          with MessgExDlg do
    21582158          begin { tell about destroyed wonders }
    21592159            OpenSound := 'WONDER_DESTROYED';
    21602160            MessgText := Format(Phrases.Lookup('WONDERDEST'),
    2161               [Phrases.Lookup('IMPROVEMENTS', i)]);
     2161              [Phrases.Lookup('IMPROVEMENTS', I)]);
    21622162            Kind := mkOkHelp;
    21632163            HelpKind := hkImp;
    2164             HelpNo := i;
     2164            HelpNo := I;
    21652165            IconKind := mikImp;
    2166             IconIndex := i;
     2166            IconIndex := I;
    21672167            ShowModal;
    21682168          end
    21692169        else
    21702170        begin
    2171           if i = woManhattan then
    2172             if MyRO.Wonder[i].EffectiveOwner > me then
     2171          if I = woManhattan then
     2172            if MyRO.Wonder[I].EffectiveOwner > Me then
    21732173              MyData.ColdWarStart := MyRO.Turn - 1
    21742174            else
     
    21772177            with MessgExDlg do
    21782178            begin { tell about newly built wonders }
    2179               if i = woManhattan then
     2179              if I = woManhattan then
    21802180              begin
    21812181                OpenSound := 'MSG_COLDWAR';
    2182                 s := Tribe[MyRO.Wonder[i].EffectiveOwner].TPhrase('COLDWAR');
     2182                S := Tribe[MyRO.Wonder[I].EffectiveOwner].TPhrase('COLDWAR');
    21832183              end
    2184               else if MyRO.Wonder[i].EffectiveOwner >= 0 then
     2184              else if MyRO.Wonder[I].EffectiveOwner >= 0 then
    21852185              begin
    21862186                OpenSound := 'WONDER_BUILT';
    2187                 s := Tribe[MyRO.Wonder[i].EffectiveOwner]
     2187                S := Tribe[MyRO.Wonder[I].EffectiveOwner]
    21882188                  .TPhrase('WONDERBUILT');
    21892189              end
     
    21912191              begin
    21922192                OpenSound := 'MSG_DEFAULT';
    2193                 s := Phrases.Lookup('WONDERBUILTEXP');
     2193                S := Phrases.Lookup('WONDERBUILTEXP');
    21942194                // already expired when built
    21952195              end;
    2196               MessgText := Format(s, [Phrases.Lookup('IMPROVEMENTS', i),
    2197                 CityName(MyRO.Wonder[i].CityID)]);
     2196              MessgText := Format(S, [Phrases.Lookup('IMPROVEMENTS', I),
     2197                CityName(MyRO.Wonder[I].CityID)]);
    21982198              Kind := mkOkHelp;
    21992199              HelpKind := hkImp;
    2200               HelpNo := i;
     2200              HelpNo := I;
    22012201              IconKind := mikImp;
    2202               IconIndex := i;
     2202              IconIndex := I;
    22032203              ShowModal;
    22042204            end;
    22052205        end;
    22062206      end
    2207       else if (MyRO.Wonder[i].EffectiveOwner <> MyData.ToldWonders[i]
    2208         .EffectiveOwner) and (MyRO.Wonder[i].CityID > WonderDestroyed) then
    2209         if MyRO.Wonder[i].EffectiveOwner < 0 then
     2207      else if (MyRO.Wonder[I].EffectiveOwner <> MyData.ToldWonders[I]
     2208        .EffectiveOwner) and (MyRO.Wonder[I].CityID > WonderDestroyed) then
     2209        if MyRO.Wonder[I].EffectiveOwner < 0 then
    22102210        begin
    2211           if i <> woMIR then
     2211          if I <> woMIR then
    22122212            with MessgExDlg do
    22132213            begin { tell about expired wonders }
    22142214              OpenSound := 'WONDER_EXPIRED';
    22152215              MessgText := Format(Phrases.Lookup('WONDEREXP'),
    2216                 [Phrases.Lookup('IMPROVEMENTS', i),
    2217                 CityName(MyRO.Wonder[i].CityID)]);
     2216                [Phrases.Lookup('IMPROVEMENTS', I),
     2217                CityName(MyRO.Wonder[I].CityID)]);
    22182218              Kind := mkOkHelp;
    22192219              HelpKind := hkImp;
    2220               HelpNo := i;
     2220              HelpNo := I;
    22212221              IconKind := mikImp;
    2222               IconIndex := i;
     2222              IconIndex := I;
    22232223              ShowModal;
    22242224            end;
    22252225        end
    2226         else if (MyData.ToldWonders[i].EffectiveOwner >= 0) and not OwnWonder
     2226        else if (MyData.ToldWonders[I].EffectiveOwner >= 0) and not OwnWonder
    22272227        then
    22282228          with MessgExDlg do
    22292229          begin { tell about capture of wonders }
    22302230            OpenSound := 'WONDER_CAPTURED';
    2231             s := Tribe[MyRO.Wonder[i].EffectiveOwner].TPhrase('WONDERCAPT');
    2232             MessgText := Format(s, [Phrases.Lookup('IMPROVEMENTS', i),
    2233               CityName(MyRO.Wonder[i].CityID)]);
     2231            S := Tribe[MyRO.Wonder[I].EffectiveOwner].TPhrase('WONDERCAPT');
     2232            MessgText := Format(S, [Phrases.Lookup('IMPROVEMENTS', I),
     2233              CityName(MyRO.Wonder[I].CityID)]);
    22342234            Kind := mkOkHelp;
    22352235            HelpKind := hkImp;
    2236             HelpNo := i;
     2236            HelpNo := I;
    22372237            IconKind := mikImp;
    2238             IconIndex := i;
     2238            IconIndex := I;
    22392239            ShowModal;
    22402240          end;
     
    22502250  end; // ClientMode<>cResume
    22512251  MyData.ToldAlive := MyRO.Alive;
    2252   move(MyRO.Wonder, MyData.ToldWonders, SizeOf(MyData.ToldWonders));
     2252  Move(MyRO.Wonder, MyData.ToldWonders, SizeOf(MyData.ToldWonders));
    22532253
    22542254  NewGovAvailable := -1;
     
    22742274          IconKind := mikBook;
    22752275          IconIndex := -1;
    2276           for i := 0 to nAdvBookIcon - 1 do
    2277             if AdvBookIcon[i].Adv = ad then
    2278               IconIndex := AdvBookIcon[i].Icon;
     2276          for I := 0 to nAdvBookIcon - 1 do
     2277            if AdvBookIcon[I].Adv = ad then
     2278              IconIndex := AdvBookIcon[I].Icon;
    22792279          ShowModal;
    22802280          MyData.ToldTech[ad] := MyRO.Tech[ad];
    2281           for i := gMonarchy to nGov - 1 do
    2282             if GovPreq[i] = ad then
    2283               NewGovAvailable := i;
     2281          for I := gMonarchy to nGov - 1 do
     2282            if GovPreq[I] = ad then
     2283              NewGovAvailable := I;
    22842284        end;
    22852285  end;
    22862286
    2287   ShowCityList := false;
     2287  ShowCityList := False;
    22882288  if ClientMode = cTurn then
    22892289  begin
     
    22912291      ChooseResearch;
    22922292
    2293     UpdatePanel := false;
     2293    UpdatePanel := False;
    22942294    if MyRO.Happened and phChangeGov <> 0 then
    22952295    begin
    22962296      ModalSelectDlg.ShowNewContent(wmModal, kGov);
    22972297      Play('NEWGOV');
    2298       Server(sSetGovernment, me, ModalSelectDlg.result, nil^);
     2298      Server(sSetGovernment, Me, ModalSelectDlg.Result, nil^);
    22992299      CityOptimizer_BeginOfTurn;
    2300       UpdatePanel := true;
     2300      UpdatePanel := True;
    23012301    end;
    23022302  end; // ClientMode=cTurn
    23032303
    2304   if not supervising and ((ClientMode = cTurn) or (ClientMode = cMovieTurn))
     2304  if not Supervising and ((ClientMode = cTurn) or (ClientMode = cMovieTurn))
    23052305  then
    23062306    for cix := 0 to MyRO.nCity - 1 do
     
    23122312  begin
    23132313    // tell what happened in cities
    2314     for WondersOnly := true downto false do
     2314    for WondersOnly := True downto False do
    23152315      for cix := 0 to MyRO.nCity - 1 do
    23162316        with MyCity[cix] do
     
    23232323              begin { tell about newly built wonder }
    23242324                OpenSound := 'WONDER_BUILT';
    2325                 s := Tribe[me].TPhrase('WONDERBUILTOWN');
     2325                S := Tribe[Me].TPhrase('WONDERBUILTOWN');
    23262326                MessgText :=
    2327                   Format(s, [Phrases.Lookup('IMPROVEMENTS',
     2327                  Format(S, [Phrases.Lookup('IMPROVEMENTS',
    23282328                  Project0 and cpIndex), CityName(ID)]);
    23292329                Kind := mkOkHelp;
     
    23342334                ShowModal;
    23352335              end;
    2336             if not supervising and (ClientMode = cTurn) then
     2336            if not Supervising and (ClientMode = cTurn) then
    23372337            begin
    2338               AllowCityScreen := true;
     2338              AllowCityScreen := True;
    23392339              if (Status and 7 <> 0) and
    23402340                (Project and (cpImp + cpIndex) = cpImp + imTrGoods) then
     
    23422342                begin
    23432343                  if AutoBuild(cix, MyData.ImpOrder[Status and 7 - 1]) then
    2344                     AllowCityScreen := false
     2344                    AllowCityScreen := False
    23452345                  else if Flags and chProduction <> 0 then
    23462346                    Flags := (Flags and not chProduction) or chAllImpsMade
     
    23702370                  CityDlg.ShowNewContent(wmModal, MyCity[cix].Loc,
    23712371                    Flags and CityRepMask);
    2372                   UpdatePanel := true;
     2372                  UpdatePanel := True;
    23732373                end;
    23742374              end
     
    23762376              begin
    23772377                if Flags and CityRepMask <> 0 then
    2378                   ShowCityList := true;
     2378                  ShowCityList := True;
    23792379              end;
    23802380            end;
     
    23962396        begin
    23972397          Play('REVOLUTION');
    2398           Server(sRevolution, me, 0, nil^);
     2398          Server(sRevolution, Me, 0, nil^);
    23992399        end;
    24002400      end;
     
    24302430    Application.ProcessMessages;
    24312431
    2432     if not supervising then
     2432    if not Supervising then
    24332433      for uix := 0 to MyRO.nUn - 1 do
    24342434        with MyUn[uix] do
     
    24582458              begin // !!! Shinkansen
    24592459                MoveResult := eOK;
    2460                 ok := true;
    2461                 for i := 0 to MoveAdviceData.nStep - 1 do
     2460                ok := True;
     2461                for I := 0 to MoveAdviceData.nStep - 1 do
    24622462                begin
    2463                   Loc1 := dLoc(Loc, MoveAdviceData.dx[i],
    2464                     MoveAdviceData.dy[i]);
     2463                  Loc1 := dLoc(Loc, MoveAdviceData.dx[I],
     2464                    MoveAdviceData.dy[I]);
    24652465                  if (MyMap[Loc1] and (fCity or fOwned) = fCity)
    24662466                  // don't capture cities during auto move
     
    24682468                  // don't attack during auto move
    24692469                  begin
    2470                     ok := false;
     2470                    ok := False;
    24712471                    Break
    24722472                  end
     
    24752475                    if (Loc1 = MoveAdviceData.ToLoc) or
    24762476                      (MoveAdviceData.ToLoc = maNextCity) and
    2477                       (MyMap[dLoc(Loc, MoveAdviceData.dx[i],
    2478                       MoveAdviceData.dy[i])] and fCity <> 0) then
     2477                      (MyMap[dLoc(Loc, MoveAdviceData.dx[I],
     2478                      MoveAdviceData.dy[I])] and fCity <> 0) then
    24792479                      MoveOptions := muAutoNoWait
    24802480                    else
    24812481                      MoveOptions := 0;
    2482                     MoveResult := MoveUnit(MoveAdviceData.dx[i],
    2483                       MoveAdviceData.dy[i], MoveOptions);
     2482                    MoveResult := MoveUnit(MoveAdviceData.dx[I],
     2483                      MoveAdviceData.dy[I], MoveOptions);
    24842484                    if (MoveResult < rExecuted) or (MoveResult = eEnemySpotted)
    24852485                    then
    24862486                    begin
    2487                       ok := false;
     2487                      ok := False;
    24882488                      Break
    24892489                    end;
     
    24972497              begin
    24982498                MoveResult := eOK;
    2499                 Stop := true;
     2499                Stop := True;
    25002500              end;
    25012501
     
    25202520  end; // ClientMode=cTurn
    25212521
    2522   HaveStrategyAdvice := false;
     2522  HaveStrategyAdvice := False;
    25232523  // (GameMode<>cMovie) and not supervising
    25242524  // and AdvisorDlg.HaveStrategyAdvice;
    2525   GoOnPhase := true;
    2526   if supervising or (GameMode = cMovie) then
     2525  GoOnPhase := True;
     2526  if Supervising or (GameMode = cMovie) then
    25272527  begin
    25282528    SetTroopLoc(-1);
     
    25392539      SetUnFocus(-1)
    25402540    else
    2541       NextUnit(-1, false);
     2541      NextUnit(-1, False);
    25422542    if UnFocus < 0 then
    25432543    begin
     
    25562556end;
    25572557
    2558 procedure TMainScreen.Client(Command, NewPlayer: integer; var Data);
     2558procedure TMainScreen.Client(Command, NewPlayer: Integer; var Data);
    25592559var
    2560   i, j, p1, mix, ToLoc, AnimationSpeed, ShowMoveDomain, cix, ecix: integer;
     2560  I, J, p1, mix, ToLoc, AnimationSpeed, ShowMoveDomain, cix, ecix: Integer;
    25612561  Color: TColor;
    2562   Name, s: string;
     2562  Name, S: string;
    25632563  TribeInfo: TTribeInfo;
    25642564  mi: TModelInfo;
    2565   SkipTurn, IsAlpine, IsTreatyDeal: boolean;
     2565  SkipTurn, IsAlpine, IsTreatyDeal: Boolean;
    25662566begin
    25672567  case Command of
    25682568    cTurn, cResume, cContinue, cMovieTurn, scContact, scDipStart .. scDipBreak:
    25692569      begin
    2570         supervising := G.Difficulty[NewPlayer] = 0;
     2570        Supervising := G.Difficulty[NewPlayer] = 0;
    25712571        ArrangeMidPanel;
    25722572      end
     
    25742574  case Command of
    25752575    cDebugMessage:
    2576       LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(@Data));
     2576      LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(@Data));
    25772577
    25782578    cShowNego:
    25792579      with TShowNegoData(Data) do
    25802580      begin
    2581         s := Format('P%d to P%d: ', [pSender, pTarget]);
     2581        S := Format('P%d to P%d: ', [pSender, pTarget]);
    25822582        if (Action = scDipOffer) and (Offer.nDeliver + Offer.nCost > 0) then
    25832583        begin
    2584           s := s + 'Offer ';
    2585           for i := 0 to Offer.nDeliver + Offer.nCost - 1 do
     2584          S := S + 'Offer ';
     2585          for I := 0 to Offer.nDeliver + Offer.nCost - 1 do
    25862586          begin
    2587             if i = Offer.nDeliver then
    2588               s := s + ' for '
    2589             else if i > 0 then
    2590               s := s + '+';
    2591             case Offer.Price[i] and opMask of
     2587            if I = Offer.nDeliver then
     2588              S := S + ' for '
     2589            else if I > 0 then
     2590              S := S + '+';
     2591            case Offer.Price[I] and opMask of
    25922592              opChoose:
    2593                 s := s + 'Price of choice';
     2593                S := S + 'Price of choice';
    25942594              opCivilReport:
    2595                 s := s + 'State report';
     2595                S := S + 'State report';
    25962596              opMilReport:
    2597                 s := s + 'Military report';
     2597                S := S + 'Military report';
    25982598              opMap:
    2599                 s := s + 'Map';
     2599                S := S + 'Map';
    26002600              opTreaty:
    2601                 s := s + 'Treaty';
     2601                S := S + 'Treaty';
    26022602              opShipParts:
    2603                 s := s + 'Ship part';
     2603                S := S + 'Ship part';
    26042604              opMoney:
    2605                 s := s + IntToStr(Offer.Price[i] and $FFFFFF) + 'o';
     2605                S := S + IntToStr(Offer.Price[I] and $FFFFFF) + 'o';
    26062606              opTribute:
    2607                 s := s + IntToStr(Offer.Price[i] and $FFFFFF) + 'o tribute';
     2607                S := S + IntToStr(Offer.Price[I] and $FFFFFF) + 'o tribute';
    26082608              opTech:
    2609                 s := s + Phrases.Lookup('ADVANCES', Offer.Price[i] and $FFFFFF);
     2609                S := S + Phrases.Lookup('ADVANCES', Offer.Price[I] and $FFFFFF);
    26102610              opAllTech:
    2611                 s := s + 'All advances';
     2611                S := S + 'All advances';
    26122612              opModel:
    2613                 s := s + Tribe[pSender].ModelName[Offer.Price[i] and $FFFFFF];
     2613                S := S + Tribe[pSender].ModelName[Offer.Price[I] and $FFFFFF];
    26142614              opAllModel:
    2615                 s := s + 'All models';
     2615                S := S + 'All models';
    26162616            end;
    26172617          end;
    2618           LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(s));
     2618          LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(S));
    26192619        end
    26202620        else if Action = scDipAccept then
    26212621        begin
    2622           s := s + '--- ACCEPTED! ---';
    2623           LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(s));
     2622          S := S + '--- ACCEPTED! ---';
     2623          LogDlg.Add(NewPlayer, G.RO[0].Turn, PChar(S));
    26242624        end;
    26252625      end;
     
    26572657          AdvisorDlg.NewGame(Data); }
    26582658        GenerateNames := mNames.Checked;
    2659         GameOK := true;
     2659        GameOK := True;
    26602660        G := TNewGameData(Data);
    2661         me := -1;
     2661        Me := -1;
    26622662        pLogo := -1;
    26632663        ClientMode := -1;
    26642664        SetMapOptions;
    26652665        MainMap.pDebugMap := -1;
    2666         idle := false;
     2666        Idle := False;
    26672667        FillChar(Jump, SizeOf(Jump), 0);
    26682668        if StartRunning then
     
    26872687              ToldContact := 0;
    26882688              ToldOwnCredibility := InitialCredibility;
    2689               for i := 0 to nPl - 1 do
    2690                 if G.Difficulty[i] > 0 then
    2691                   inc(ToldAlive, 1 shl i);
     2689              for I := 0 to nPl - 1 do
     2690                if G.Difficulty[I] > 0 then
     2691                  Inc(ToldAlive, 1 shl I);
    26922692              PeaceEvaHappened := 0;
    2693               for i := 0 to nWonder - 1 do
    2694                 with ToldWonders[i] do
     2693              for I := 0 to nWonder - 1 do
     2694                with ToldWonders[I] do
    26952695                begin
    26962696                  CityID := -1;
     
    27192719        Age := 0;
    27202720        MovieSpeed := 1;
    2721         LogDlg.mSlot.Visible := true;
     2721        LogDlg.mSlot.Visible := True;
    27222722        LogDlg.Host := self;
    27232723        HelpDlg.ClearHistory;
     
    27252725
    27262726        MiniMap.Size := Point(G.lx, G.ly);
    2727         for i := 0 to nPl - 1 do
     2727        for I := 0 to nPl - 1 do
    27282728        begin
    2729           Tribe[i] := nil;
    2730           TribeOriginal[i] := false;
     2729          Tribe[I] := nil;
     2730          TribeOriginal[I] := False;
    27312731        end;
    27322732        ToldSlavery := -1;
    2733         RepaintOnResize := false;
    2734         Closable := false;
    2735         FirstMovieTurn := true;
     2733        RepaintOnResize := False;
     2734        Closable := False;
     2735        FirstMovieTurn := True;
    27362736
    27372737        MenuArea.Visible := GameMode <> cMovie;
     
    27442744      if NewPlayer = 0 then
    27452745      begin
    2746         i := 0;
     2746        I := 0;
    27472747        for p1 := 0 to nPl - 1 do
    27482748          if (G.Difficulty[p1] > 0) and (Tribe[p1] = nil) then
    2749             inc(i);
    2750         if i > UnusedTribeFiles.Count then
     2749            Inc(I);
     2750        if I > UnusedTribeFiles.Count then
    27512751        begin
    2752           GameOK := false;
     2752          GameOK := False;
    27532753          SimpleMessage(Phrases.Lookup('TOOFEWTRIBES'));
    27542754        end
     
    27612761              TribeInfo.trix := p1;
    27622762              TribeNames.Clear;
    2763               for j := 0 to UnusedTribeFiles.Count - 1 do
     2763              for J := 0 to UnusedTribeFiles.Count - 1 do
    27642764              begin
    2765                 GetTribeInfo(UnusedTribeFiles[j], Name, Color);
     2765                GetTribeInfo(UnusedTribeFiles[J], Name, Color);
    27662766                TribeNames.AddObject(Name, TObject(Color));
    27672767              end;
    2768               assert(TribeNames.Count > 0);
     2768              Assert(TribeNames.Count > 0);
    27692769              ModalSelectDlg.ShowNewContent(wmModal, kTribe);
    27702770              Application.ProcessMessages;
    2771               TribeInfo.FileName := UnusedTribeFiles[ModalSelectDlg.result];
    2772               UnusedTribeFiles.Delete(ModalSelectDlg.result);
     2771              TribeInfo.FileName := UnusedTribeFiles[ModalSelectDlg.Result];
     2772              UnusedTribeFiles.Delete(ModalSelectDlg.Result);
    27732773
    27742774              if GameMode = cLoadGame then
    2775                 CreateTribe(TribeInfo.trix, TribeInfo.FileName, false)
     2775                CreateTribe(TribeInfo.trix, TribeInfo.FileName, False)
    27762776              else
    27772777                Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize),
     
    27832783            then
    27842784            begin // autoselect enemy tribes
    2785               j := ChooseUnusedTribe;
    2786               TribeInfo.FileName := UnusedTribeFiles[j];
    2787               UnusedTribeFiles.Delete(j);
     2785              J := ChooseUnusedTribe;
     2786              TribeInfo.FileName := UnusedTribeFiles[J];
     2787              UnusedTribeFiles.Delete(J);
    27882788              TribeInfo.trix := p1;
    27892789              if GameMode = cLoadGame then
    2790                 CreateTribe(TribeInfo.trix, TribeInfo.FileName, false)
     2790                CreateTribe(TribeInfo.trix, TribeInfo.FileName, False)
    27912791              else
    27922792                Server(CommandWithData(cSetTribe, TribeInfo.GetCommandDataSize),
     
    28082808          LogDlg.Close;
    28092809        LogDlg.List.Clear;
    2810         StartRunning := not idle and (Jump[0] > 0); // AI called Reload
    2811         me := -1;
    2812         idle := false;
     2810        StartRunning := not Idle and (Jump[0] > 0); // AI called Reload
     2811        Me := -1;
     2812        Idle := False;
    28132813        ClientMode := -1;
    2814         UnitInfoBtn.Visible := false;
    2815         UnitBtn.Visible := false;
    2816         TerrainBtn.Visible := false;
    2817         MovieSpeed1Btn.Visible := false;
    2818         MovieSpeed2Btn.Visible := false;
    2819         MovieSpeed3Btn.Visible := false;
    2820         MovieSpeed4Btn.Visible := false;
    2821         EOT.Visible := false;
    2822         for i := 0 to ControlCount - 1 do
    2823           if Controls[i] is TButtonC then
    2824             Controls[i].Visible := false;
     2814        UnitInfoBtn.Visible := False;
     2815        UnitBtn.Visible := False;
     2816        TerrainBtn.Visible := False;
     2817        MovieSpeed1Btn.Visible := False;
     2818        MovieSpeed2Btn.Visible := False;
     2819        MovieSpeed3Btn.Visible := False;
     2820        MovieSpeed4Btn.Visible := False;
     2821        EOT.Visible := False;
     2822        for I := 0 to ControlCount - 1 do
     2823          if Controls[I] is TButtonC then
     2824            Controls[I].Visible := False;
    28252825        sb.Init(0, 1);
    28262826        for p1 := 0 to nPl - 1 do
     
    28282828            FreeAndNil(Tribe[p1]);
    28292829        Tribes.Done;
    2830         RepaintOnResize := false;
    2831         Closable := true;
     2830        RepaintOnResize := False;
     2831        Closable := True;
    28322832        Close;
    28332833        { if (GameMode=cNewGame) or (GameMode=cLoadGame) then
     
    28522852        Show;
    28532853        Update;
    2854         RepaintOnResize := true;
     2854        RepaintOnResize := True;
    28552855        xw := 0;
    28562856        yw := ywcenter;
    28572857        if not StayOnTop_Ensured then
    28582858        begin
    2859           StayOnTop_Ensured := true;
     2859          StayOnTop_Ensured := True;
    28602860          CityDlg.StayOnTop_Workaround;
    28612861          CityTypeDlg.StayOnTop_Workaround;
     
    28762876    cShowTurnChange:
    28772877      begin
    2878         if integer(Data) >= 0 then
     2878        if Integer(Data) >= 0 then
    28792879        begin
    2880           pLogo := integer(Data);
     2880          pLogo := Integer(Data);
    28812881          if G.RO[pLogo] = nil then
    28822882          begin
     
    29052905              ItsMeAgain(p1);
    29062906              for mix := 0 to MyRO.nModel - 1 do
    2907                 if not Assigned(Tribe[me].ModelPicture[mix].HGr) then
    2908                   InitMyModel(mix, true);
     2907                if not Assigned(Tribe[Me].ModelPicture[mix].HGr) then
     2908                  InitMyModel(mix, True);
    29092909            end;
    2910           me := -1;
     2910          Me := -1;
    29112911        end;
    29122912
     
    29172917            Jump[pTurn] := 0
    29182918          else
    2919             dec(Jump[pTurn]);
     2919            Dec(Jump[pTurn]);
    29202920        SkipTurn := Jump[pTurn] > 0;
    29212921        if SkipTurn then
     
    29262926          MiniMapPaint;
    29272927          InitAllEnemyModels; // necessary for correct replay
    2928           if not EndTurn(true) then
    2929             SkipTurn := false;
     2928          if not EndTurn(True) then
     2929            SkipTurn := False;
    29302930        end;
    29312931        if not SkipTurn then
     
    29342934            NegoDlg.Visible then
    29352935            NegoDlg.Close;
    2936           skipped := false; // always show my moves during my turn
    2937           idle := true;
     2936          skipped := False; // always show my moves during my turn
     2937          Idle := True;
    29382938          InitTurn(NewPlayer);
    2939           DipMem[me].pContact := -1;
    2940           (* if (me=0) and (MyRO.Alive and (1 shl me)=0)} then
     2939          DipMem[Me].pContact := -1;
     2940          (* if (Me=0) and (MyRO.Alive and (1 shl Me)=0)} then
    29412941            begin
    29422942            if SimpleQuery(Phrases.Lookup('RESIGN'))=mrIgnore then
    2943             Server(sResign,me,0,nil^)
    2944             else Server(sBreak,me,0,nil^)
     2943            Server(sResign,Me,0,nil^)
     2944            else Server(sBreak,Me,0,nil^)
    29452945            end
    29462946            else Play('TURNSTART'); *)
     
    29532953        pTurn := NewPlayer;
    29542954        pLogo := -1;
    2955         skipped := false; // always show my moves during my turn
    2956         idle := true;
     2955        skipped := False; // always show my moves during my turn
     2956        Idle := True;
    29572957        if FirstMovieTurn then
    29582958        begin
    29592959          CheckMovieSpeedBtnState;
    2960           FirstMovieTurn := false;
     2960          FirstMovieTurn := False;
    29612961        end;
    29622962        InitTurn(NewPlayer);
     
    29752975        pTurn := -1;
    29762976        pLogo := -1;
    2977         MapValid := false;
     2977        MapValid := False;
    29782978        ClientMode := -1;
    2979         idle := false;
    2980         skipped := false;
     2979        Idle := False;
     2980        skipped := False;
    29812981      end;
    29822982
     
    29882988        ItsMeAgain(0);
    29892989        MyData := nil;
    2990         UnitInfoBtn.Visible := false;
    2991         UnitBtn.Visible := false;
    2992         TerrainBtn.Visible := false;
    2993         MovieSpeed1Btn.Visible := false;
    2994         MovieSpeed2Btn.Visible := false;
    2995         MovieSpeed3Btn.Visible := false;
    2996         MovieSpeed4Btn.Visible := false;
    2997         EOT.Visible := false;
     2990        UnitInfoBtn.Visible := False;
     2991        UnitBtn.Visible := False;
     2992        TerrainBtn.Visible := False;
     2993        MovieSpeed1Btn.Visible := False;
     2994        MovieSpeed2Btn.Visible := False;
     2995        MovieSpeed3Btn.Visible := False;
     2996        MovieSpeed4Btn.Visible := False;
     2997        EOT.Visible := False;
    29982998        HelpDlg.Difficulty := 0;
    29992999        BrushType := fGrass;
    30003000        BrushLoc := -1;
    3001         Edited := false;
     3001        Edited := False;
    30023002        UnFocus := -1;
    30033003        MarkCityLoc := -1;
    3004         Tracking := false;
    3005         TurnComplete := false;
    3006         MapValid := false;
     3004        Tracking := False;
     3005        TurnComplete := False;
     3006        MapValid := False;
    30073007        FormResize(nil); // calculate geometrics and paint all
    30083008        SetTroopLoc(-1);
    3009         idle := true;
     3009        Idle := True;
    30103010      end;
    30113011
     
    30173017    scContact:
    30183018      begin
    3019         DipMem[NewPlayer].pContact := integer(Data);
     3019        DipMem[NewPlayer].pContact := Integer(Data);
    30203020        if Jump[NewPlayer] > 0 then
    30213021          DipCall(scReject)
     
    30243024          ClientMode := Command;
    30253025          InitTurn(NewPlayer);
    3026           MyData.ToldContact := MyData.ToldContact or (1 shl integer(Data));
     3026          MyData.ToldContact := MyData.ToldContact or (1 shl Integer(Data));
    30273027          // don't tell about new nation when already contacted by them
    30283028          with MessgExDlg do
    30293029          begin
    3030             OpenSound := 'CONTACT_' + char(48 + MyRO.EnemyReport[integer(Data)
     3030            OpenSound := 'CONTACT_' + char(48 + MyRO.EnemyReport[Integer(Data)
    30313031              ].Attitude);
    3032             MessgText := Tribe[integer(Data)].TPhrase('FRCONTACT');
     3032            MessgText := Tribe[Integer(Data)].TPhrase('FRCONTACT');
    30333033            Kind := mkYesNo;
    30343034            IconKind := mikTribe;
    3035             IconIndex := integer(Data);
     3035            IconIndex := Integer(Data);
    30363036            ShowModal;
    30373037            if ModalResult = mrOK then
    30383038            begin
    30393039              NegoDlg.Respond;
    3040               DipMem[me].DeliveredPrices := [];
    3041               DipMem[me].ReceivedPrices := [];
     3040              DipMem[Me].DeliveredPrices := [];
     3041              DipMem[Me].ReceivedPrices := [];
    30423042              DipCall(scDipStart);
    30433043            end
     
    30673067        else if Command = scDipAccept then
    30683068        begin // remember delivered and received prices
    3069           for i := 0 to DipMem[me].SentOffer.nDeliver - 1 do
    3070             include(DipMem[me].DeliveredPrices,
    3071               DipMem[me].SentOffer.Price[i] shr 24);
    3072           for i := 0 to DipMem[me].SentOffer.nCost - 1 do
    3073             include(DipMem[me].ReceivedPrices,
    3074               DipMem[me].SentOffer.Price[DipMem[me].SentOffer.nDeliver +
    3075               i] shr 24);
    3076           IsTreatyDeal := false;
    3077           for i := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do
    3078             if DipMem[me].SentOffer.Price[i] and opMask = opTreaty then
    3079               IsTreatyDeal := true;
     3069          for I := 0 to DipMem[Me].SentOffer.nDeliver - 1 do
     3070            Include(DipMem[Me].DeliveredPrices,
     3071              DipMem[Me].SentOffer.Price[I] shr 24);
     3072          for I := 0 to DipMem[Me].SentOffer.nCost - 1 do
     3073            Include(DipMem[Me].ReceivedPrices,
     3074              DipMem[Me].SentOffer.Price[DipMem[Me].SentOffer.nDeliver +
     3075              I] shr 24);
     3076          IsTreatyDeal := False;
     3077          for I := 0 to ReceivedOffer.nDeliver + ReceivedOffer.nCost - 1 do
     3078            if DipMem[Me].SentOffer.Price[I] and opMask = opTreaty then
     3079              IsTreatyDeal := True;
    30803080          if IsTreatyDeal then
    30813081            Play('NEWTREATY')
     
    30843084        end;
    30853085        NegoDlg.Start;
    3086         idle := true;
     3086        Idle := True;
    30873087      end;
    30883088
     
    30903090      if not IsMultiPlayerGame then
    30913091      begin
    3092         case G.RO[NewPlayer].Treaty[integer(Data)] of
     3092        case G.RO[NewPlayer].Treaty[Integer(Data)] of
    30933093          trPeace:
    3094             s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_PEACE');
     3094            S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_PEACE');
    30953095          trFriendlyContact:
    3096             s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_FRIENDLY');
     3096            S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_FRIENDLY');
    30973097          trAlliance:
    3098             s := Tribe[integer(Data)].TPhrase('FRCANCELBYREJECT_ALLIANCE');
     3098            S := Tribe[Integer(Data)].TPhrase('FRCANCELBYREJECT_ALLIANCE');
    30993099        end;
    3100         TribeMessage(integer(Data), s, 'CANCELTREATY');
     3100        TribeMessage(Integer(Data), S, 'CANCELTREATY');
    31013101      end;
    31023102
    31033103    cShowCancelTreatyByAlliance:
    3104       if idle and (NewPlayer = me) then
    3105         TribeMessage(integer(Data), Tribe[integer(Data)
     3104      if Idle and (NewPlayer = Me) then
     3105        TribeMessage(Integer(Data), Tribe[Integer(Data)
    31063106          ].TPhrase('FRENEMYALLIANCE'), 'CANCELTREATY');
    31073107
    31083108    cShowSupportAllianceAgainst:
    31093109      if not IsMultiPlayerGame and (Jump[0] = 0) then
    3110         TribeMessage(integer(Data) and $F, Tribe[integer(Data) and $F]
    3111           .TPhrase('FRMYALLIANCE1') + ' ' + Tribe[integer(Data) shr 4]
     3110        TribeMessage(Integer(Data) and $F, Tribe[Integer(Data) and $F]
     3111          .TPhrase('FRMYALLIANCE1') + ' ' + Tribe[Integer(Data) shr 4]
    31123112          .TPhrase('FRMYALLIANCE2'), 'CANCELTREATY');
    31133113
    31143114    cShowPeaceViolation:
    31153115      if not IsMultiPlayerGame and (Jump[0] = 0) then
    3116         TribeMessage(integer(Data),
    3117           Format(Tribe[integer(Data)].TPhrase('EVIOLATION'),
     3116        TribeMessage(Integer(Data),
     3117          Format(Tribe[Integer(Data)].TPhrase('EVIOLATION'),
    31183118          [TurnToString(MyRO.Turn + PeaceEvaTurns - 1)]), 'MSG_WITHDRAW');
    31193119
     
    31223122
    31233123    cShowUnitChanged, cShowCityChanged, cShowAfterMove, cShowAfterAttack:
    3124       if (idle and (NewPlayer = me) or not idle and not skipped) and
     3124      if (Idle and (NewPlayer = Me) or not Idle and not skipped) and
    31253125        not((GameMode = cMovie) and (MovieSpeed = 4)) then
    31263126      begin
    3127         assert(NewPlayer = me);
    3128         if not idle or (GameMode = cMovie) then
     3127        Assert(NewPlayer = Me);
     3128        if not Idle or (GameMode = cMovie) then
    31293129          Application.ProcessMessages;
    31303130        if Command = cShowCityChanged then
    31313131        begin
    3132           CurrentMoveInfo.DoShow := false;
    3133           if idle then
    3134             CurrentMoveInfo.DoShow := true
     3132          CurrentMoveInfo.DoShow := False;
     3133          if Idle then
     3134            CurrentMoveInfo.DoShow := True
    31353135          else if CurrentMoveInfo.IsAlly then
    31363136            CurrentMoveInfo.DoShow := not mAlNoMoves.Checked
     
    31403140        else if Command = cShowUnitChanged then
    31413141        begin
    3142           CurrentMoveInfo.DoShow := false;
    3143           if idle then
     3142          CurrentMoveInfo.DoShow := False;
     3143          if Idle then
    31443144            CurrentMoveInfo.DoShow := not mEffectiveMovesOnly.Checked
    31453145          else if CurrentMoveInfo.IsAlly then
     
    31553155        begin
    31563156          if Command = cShowCityChanged then
    3157             MapValid := false;
    3158           FocusOnLoc(integer(Data), flImmUpdate);
     3157            MapValid := False;
     3158          FocusOnLoc(Integer(Data), flImmUpdate);
    31593159          // OldUnFocus:=UnFocus;
    31603160          // UnFocus:=-1;
    31613161          if Command = cShowAfterMove then
    3162             PaintLoc(integer(Data), CurrentMoveInfo.AfterMovePaintRadius)
     3162            PaintLoc(Integer(Data), CurrentMoveInfo.AfterMovePaintRadius)
    31633163            // show discovered areas
    31643164          else
    3165             PaintLoc(integer(Data), 1);
     3165            PaintLoc(Integer(Data), 1);
    31663166          // UnFocus:=OldUnFocus;
    31673167          if (Command = cShowAfterAttack) and
     
    31733173            Update; // remove message box from screen
    31743174          end
    3175           else if not idle then
     3175          else if not Idle then
    31763176            if Command = cShowCityChanged then
    31773177              Sleep(MoveTime * WaitAfterShowMove div 16)
    31783178            else if (Command = cShowUnitChanged) and
    3179               (MyMap[integer(Data)] and fUnit <> 0) then
     3179              (MyMap[Integer(Data)] and fUnit <> 0) then
    31803180              Sleep(MoveTime * WaitAfterShowMove div 32)
    31813181        end // if CurrentMoveInfo.DoShow
    31823182        else
    3183           MapValid := false;
     3183          MapValid := False;
    31843184      end;
    31853185
    31863186    cShowMoving, cShowCapturing:
    3187       if (idle and (NewPlayer = me) or not idle and not skipped and
     3187      if (Idle and (NewPlayer = Me) or not Idle and not skipped and
    31883188        (TShowMove(Data).emix <> $FFFF)) and
    31893189        not((GameMode = cMovie) and (MovieSpeed = 4)) then
    31903190      begin
    3191         assert(NewPlayer = me);
    3192         if not idle or (GameMode = cMovie) then
     3191        Assert(NewPlayer = Me);
     3192        if not Idle or (GameMode = cMovie) then
    31933193          Application.ProcessMessages;
    31943194        with TShowMove(Data) do
    31953195        begin
    3196           CurrentMoveInfo.DoShow := false;
    3197           if not idle and (not Assigned(Tribe[Owner].ModelPicture[mix].HGr)) then
     3196          CurrentMoveInfo.DoShow := False;
     3197          if not Idle and (not Assigned(Tribe[Owner].ModelPicture[mix].HGr)) then
    31983198            InitEnemyModel(emix);
    31993199
    32003200          ToLoc := dLoc(FromLoc, dx, dy);
    3201           if idle then
     3201          if Idle then
    32023202          begin // own unit -- make discovered land visible
    3203             assert(Owner = me); // no foreign moves during my turn!
     3203            Assert(Owner = Me); // no foreign moves during my turn!
    32043204            CurrentMoveInfo.DoShow := not mEffectiveMovesOnly.Checked or
    32053205              (Command = cShowCapturing);
     
    32343234                else
    32353235                  CurrentMoveInfo.AfterMovePaintRadius := 1;
    3236                 if (MyRO.Wonder[woShinkansen].EffectiveOwner = me) and
     3236                if (MyRO.Wonder[woShinkansen].EffectiveOwner = Me) and
    32373237                  (Domain = dGround) and
    32383238                  (MyMap[FromLoc] and (fRR or fCity) <> 0) and
     
    32493249            CurrentMoveInfo.IsAlly := MyRO.Treaty[Owner] = trAlliance;
    32503250            if GameMode = cMovie then
    3251               CurrentMoveInfo.DoShow := true
     3251              CurrentMoveInfo.DoShow := True
    32523252            else if CurrentMoveInfo.IsAlly then
    32533253              CurrentMoveInfo.DoShow := not mAlNoMoves.Checked and
     
    32653265                  cix := MyRO.nCity - 1;
    32663266                  while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do
    3267                     dec(cix);
    3268                   s := CityName(MyCity[cix].ID);
     3267                    Dec(cix);
     3268                  S := CityName(MyCity[cix].ID);
    32693269                end
    32703270                else
     
    32723272                  ecix := MyRO.nEnemyCity - 1;
    32733273                  while (ecix >= 0) and (MyRO.EnemyCity[ecix].Loc <> ToLoc) do
    3274                     dec(ecix);
    3275                   s := CityName(MyRO.EnemyCity[ecix].ID);
     3274                    Dec(ecix);
     3275                  S := CityName(MyRO.EnemyCity[ecix].ID);
    32763276                end;
    32773277                TribeMessage(Owner, Format(Tribe[Owner].TPhrase('CAPTURE'),
    3278                   [s]), '');
     3278                  [S]), '');
    32793279                Update; // remove message box from screen
    32803280              end;
     
    33613361          end // if CurrentMoveInfo.DoShow
    33623362          else
    3363             MapValid := false;
     3363            MapValid := False;
    33643364        end;
    33653365      end;
    33663366
    33673367    cShowAttacking:
    3368       if (idle and (NewPlayer = me) or not idle and not skipped and
     3368      if (Idle and (NewPlayer = Me) or not Idle and not skipped and
    33693369        (TShowMove(Data).emix <> $FFFF)) and
    33703370        not((GameMode = cMovie) and (MovieSpeed = 4)) then
    33713371      begin
    3372         assert(NewPlayer = me);
    3373         if not idle or (GameMode = cMovie) then
     3372        Assert(NewPlayer = Me);
     3373        if not Idle or (GameMode = cMovie) then
    33743374          Application.ProcessMessages;
    33753375        with TShowMove(Data) do
    33763376        begin
    33773377          CurrentMoveInfo.AfterAttackExpeller := -1;
    3378           CurrentMoveInfo.DoShow := false;
    3379           if idle then
    3380             CurrentMoveInfo.DoShow := true // own unit -- always show attacks
     3378          CurrentMoveInfo.DoShow := False;
     3379          if Idle then
     3380            CurrentMoveInfo.DoShow := True // own unit -- always show attacks
    33813381          else
    33823382          begin
     
    33983398              cix := MyRO.nCity - 1;
    33993399              while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do
    3400                 dec(cix);
     3400                Dec(cix);
    34013401              if MyCity[cix].Status and csToldBombard = 0 then
    34023402              begin
    3403                 if not supervising then
     3403                if not Supervising then
    34043404                  MyCity[cix].Status := MyCity[cix].Status or csToldBombard;
    3405                 s := CityName(MyCity[cix].ID);
     3405                S := CityName(MyCity[cix].ID);
    34063406                SoundMessageEx(Format(Tribe[Owner].TPhrase('BOMBARD'),
    3407                   [s]), '');
     3407                  [S]), '');
    34083408                Update; // remove message box from screen
    34093409              end;
     
    34143414            if Flags and umExpelling <> 0 then
    34153415              Play('MOVE_EXPEL')
    3416             else if Owner = me then
     3416            else if Owner = Me then
    34173417            begin
    3418               MakeModelInfo(me, mix, MyModel[mix], mi);
     3418              MakeModelInfo(Me, mix, MyModel[mix], mi);
    34193419              Play(AttackSound(ModelCode(mi)));
    34203420            end
     
    34413441              MoveOnScreen(TShowMove(Data), 10, 0, 16);
    34423442            end
    3443             else if not idle then
     3443            else if not Idle then
    34443444              Sleep(MoveTime div 2);
    34453445            MainMap.AttackEnd;
    34463446          end // if CurrentMoveInfo.DoShow
    34473447          else
    3448             MapValid := false;
     3448            MapValid := False;
    34493449        end;
    34503450      end;
     
    34553455      else
    34563456      begin
    3457         s := Phrases.Lookup('FOREIGNINFO');
     3457        S := Phrases.Lookup('FOREIGNINFO');
    34583458        for p1 := 0 to nPl - 1 do
    34593459          if 3 shl (p1 * 2) and Cardinal(Data) <> 0 then
    3460             s := s + '\' + Tribe[p1].TPhrase('SHORTNAME');
    3461         SoundMessageEx(s, '');
     3460            S := S + '\' + Tribe[p1].TPhrase('SHORTNAME');
     3461        SoundMessageEx(S, '');
    34623462      end;
    34633463
     
    34713471        begin
    34723472          MessgText := Format(Phrases.Lookup('GRLIB_GENERAL'),
    3473             [Phrases.Lookup('ADVANCES', integer(Data))]);
     3473            [Phrases.Lookup('ADVANCES', Integer(Data))]);
    34743474          OpenSound := 'NEWADVANCE_GRLIB';
    34753475          Kind := mkOk;
     
    34813481    cRefreshDebugMap:
    34823482      begin
    3483         if integer(Data) = MainMap.pDebugMap then
     3483        if Integer(Data) = MainMap.pDebugMap then
    34843484        begin
    3485           MapValid := false;
     3485          MapValid := False;
    34863486          MainOffscreenPaint;
    34873487          Update;
     
    34943494        cSetTribe:
    34953495          with TTribeInfo(Data) do begin
    3496             i := UnusedTribeFiles.Count - 1;
    3497             while (i >= 0) and
    3498               (AnsiCompareFileName(UnusedTribeFiles[i], FileName) <> 0) do
    3499               dec(i);
    3500             if i >= 0 then
    3501               UnusedTribeFiles.Delete(i);
    3502             CreateTribe(trix, FileName, true);
     3496            I := UnusedTribeFiles.Count - 1;
     3497            while (I >= 0) and
     3498              (AnsiCompareFileName(UnusedTribeFiles[I], FileName) <> 0) do
     3499              Dec(I);
     3500            if I >= 0 then
     3501              UnusedTribeFiles.Delete(I);
     3502            CreateTribe(trix, FileName, True);
    35033503          end;
    35043504        cSetNewModelPicture:
     
    35113511              (TModelPictureInfo(Data), False);
    35123512        cSetSlaveIndex:
    3513           Tribe[integer(Data) shr 16].mixSlaves := integer(Data) and $FFFF;
     3513          Tribe[Integer(Data) shr 16].mixSlaves := Integer(Data) and $FFFF;
    35143514        cSetCityName:
    35153515          with TCityNameInfo(Data) do
     
    35283528procedure TMainScreen.FormCreate(Sender: TObject);
    35293529var
    3530   i, j: integer;
     3530  I, J: Integer;
    35313531begin
    35323532  NoMap := TIsoMap.Create;
     
    35703570
    35713571  // tag-controlled language
    3572   for i := 0 to ComponentCount - 1 do
    3573     if Components[i].Tag and $FF <> 0 then
    3574       if Components[i] is TMenuItem then begin
    3575         TMenuItem(Components[i]).Caption := Phrases.Lookup('CONTROLS',
    3576           -1 + Components[i].Tag and $FF);
    3577         for j := 0 to Length(SaveOption) - 1 do
    3578           if Components[i].Tag and $FF = SaveOption[j] then
    3579             TMenuItem(Components[i]).Checked := TSaveOption(j) in OptionChecked;
     3572  for I := 0 to ComponentCount - 1 do
     3573    if Components[I].Tag and $FF <> 0 then
     3574      if Components[I] is TMenuItem then begin
     3575        TMenuItem(Components[I]).Caption := Phrases.Lookup('CONTROLS',
     3576          -1 + Components[I].Tag and $FF);
     3577        for J := 0 to Length(SaveOption) - 1 do
     3578          if Components[I].Tag and $FF = SaveOption[J] then
     3579            TMenuItem(Components[I]).Checked := TSaveOption(J) in OptionChecked;
    35803580      end else
    3581       if Components[i] is TButtonBase then begin
    3582         TButtonBase(Components[i]).Hint := Phrases.Lookup('CONTROLS',
    3583           -1 + Components[i].Tag and $FF);
    3584         if (Components[i] is TButtonC) and
    3585           (TButtonC(Components[i]).ButtonIndex <> 1) then
    3586           TButtonC(Components[i]).ButtonIndex :=
    3587             Integer(MapOptionChecked) shr (Components[i].Tag shr 8) and 1 + 2
     3581      if Components[I] is TButtonBase then begin
     3582        TButtonBase(Components[I]).Hint := Phrases.Lookup('CONTROLS',
     3583          -1 + Components[I].Tag and $FF);
     3584        if (Components[I] is TButtonC) and
     3585          (TButtonC(Components[I]).ButtonIndex <> 1) then
     3586          TButtonC(Components[I]).ButtonIndex :=
     3587            Integer(MapOptionChecked) shr (Components[I].Tag shr 8) and 1 + 2
    35883588      end;
    35893589
     
    35983598    ManagementArea.Hint := Phrases2.Lookup('BTN_MANAGE');
    35993599  end;
    3600   for i := 0 to mRep.Count - 1 do
    3601   begin
    3602     j := mRep[i].Tag shr 8;
    3603     mRep[i].Caption := CityEventName(j);
    3604     mRep[i].Checked := CityRepMask and (1 shl j) <> 0;
     3600  for I := 0 to mRep.Count - 1 do
     3601  begin
     3602    J := mRep[I].Tag shr 8;
     3603    mRep[I].Caption := CityEventName(J);
     3604    mRep[I].Checked := CityRepMask and (1 shl J) <> 0;
    36053605  end;
    36063606
     
    36213621    else Buffer.height := 3 * ySizeBig;
    36223622  Buffer.Canvas.Font.Assign(UniFont[ftSmall]);
    3623   for i := 0 to nPl - 1 do
    3624     AILogo[i] := nil;
     3623  for I := 0 to nPl - 1 do
     3624    AILogo[I] := nil;
    36253625  Canvas.Font.Assign(UniFont[ftSmall]);
    36263626  InitButtons;
     
    36393639  FreeAndNil(Panel);
    36403640  for I := 0 to nPl - 1 do
    3641     if AILogo[i] <> nil then
     3641    if AILogo[I] <> nil then
    36423642      FreeAndNil(AILogo[I]);
    36433643  FreeAndNil(Offscreen);
     
    36993699    Status := Status and ($FFFF - usRecover - usGoto - usEnhance);
    37003700    if Job > jNone then
    3701       Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
     3701      Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
    37023702  end;
    37033703end;
     
    37253725      if DoJob(jCity) = eCity then
    37263726      begin
    3727         MapValid := false;
     3727        MapValid := False;
    37283728        PaintAll;
    3729         ZoomToCity(Loc0, true, chFounded);
     3729        ZoomToCity(Loc0, True, chFounded);
    37303730      end;
    37313731    end else begin
    37323732      CityOptimizer_BeforeRemoveUnit(UnFocus);
    3733       ServerResult := Server(sAddToCity, me, UnFocus, nil^);
     3733      ServerResult := Server(sAddToCity, Me, UnFocus, nil^);
    37343734      if ServerResult >= rExecuted then
    37353735      begin
    37363736        cix := MyRO.nCity - 1;
    37373737        while (cix >= 0) and (MyCity[cix].Loc <> Loc0) do
    3738           dec(cix);
    3739         assert(cix >= 0);
     3738          Dec(cix);
     3739        Assert(cix >= 0);
    37403740        CityOptimizer_CityChange(cix);
    37413741        CityOptimizer_AfterRemoveUnit; // does nothing here
    37423742        SetTroopLoc(Loc0);
    3743         UpdateViews(true);
    3744         DestinationMarkON := false;
     3743        UpdateViews(True);
     3744        DestinationMarkON := False;
    37453745        PaintDestination;
    37463746        UnFocus := -1;
    37473747        PaintLoc(Loc0);
    3748         NextUnit(UnStartLoc, true);
     3748        NextUnit(UnStartLoc, True);
    37493749      end
    37503750      else if ServerResult = eMaxSize then
     
    38293829      Destination := Status shr 16;
    38303830    Status := Status and not(usStay or usRecover) or usWaiting;
    3831     MoveToLoc(Destination, true);
     3831    MoveToLoc(Destination, True);
    38323832  end;
    38333833end;
     
    38503850    begin
    38513851      cixOldHome := Home;
    3852       if Server(sSetUnitHome, me, UnFocus, nil^) >= rExecuted then
     3852      if Server(sSetUnitHome, Me, UnFocus, nil^) >= rExecuted then
    38533853      begin
    38543854        CityOptimizer_CityChange(cixOldHome);
    38553855        CityOptimizer_CityChange(Home);
    3856         UpdateViews(true);
     3856        UpdateViews(True);
    38573857      end
    38583858      else
     
    38623862    begin
    38633863      Status := Status and not(usStay or usRecover or usEnhance);
    3864       MoveToLoc(maNextCity, true);
     3864      MoveToLoc(maNextCity, True);
    38653865    end;
    38663866  end;
     
    38823882procedure TMainScreen.mJumpClick(Sender: TObject);
    38833883begin
    3884   if supervising then
     3884  if Supervising then
    38853885    Jump[0] := 20
    38863886  else
    3887     Jump[me] := 20;
    3888   EndTurn(true);
     3887    Jump[Me] := 20;
     3888  EndTurn(True);
    38893889end;
    38903890
     
    38953895  if UnFocus >= 0 then
    38963896  with MyUn[UnFocus] do begin
    3897     i := Server(sLoadUnit, me, UnFocus, nil^);
    3898     if i >= rExecuted then
     3897    I := Server(sLoadUnit, Me, UnFocus, nil^);
     3898    if I >= rExecuted then
    38993899    begin
    39003900      if MyModel[mix].Domain = dAir then
     
    39023902      else
    39033903        Play('MOVE_LOAD');
    3904       DestinationMarkON := false;
     3904      DestinationMarkON := False;
    39053905      PaintDestination;
    39063906      Status := Status and ($FFFF - usWaiting - usStay - usRecover - usGoto - usEnhance);
    3907       NextUnit(UnStartLoc, true);
     3907      NextUnit(UnStartLoc, True);
    39083908    end
    3909     else if i = eNoTime_Load then
     3909    else if I = eNoTime_Load then
    39103910      if MyModel[mix].Domain = dAir then
    39113911        SoundMessage(Phrases.Lookup('NOTIMELOADAIR'), 'NOMOVE_TIME')
     
    39423942  with MyUn[UnFocus] do begin
    39433943    Status := Status and not usWaiting;
    3944     NextUnit(UnStartLoc, true);
     3944    NextUnit(UnStartLoc, True);
    39453945  end;
    39463946end;
     
    39713971  if not Edited or (SimpleQuery(mkYesNo, Phrases.Lookup('MAP_RANDOM'), '')
    39723972      = mrOK) then begin
    3973     Server(sRandomMap, me, 0, nil^);
    3974     Edited := true;
    3975     MapValid := false;
     3973    Server(sRandomMap, Me, 0, nil^);
     3974    Edited := True;
     3975    MapValid := False;
    39763976    PaintAllMaps;
    39773977  end;
     
    39823982  if UnFocus >= 0 then
    39833983  with MyUn[UnFocus] do begin
    3984     DestinationMarkON := false;
     3984    DestinationMarkON := False;
    39853985    PaintDestination;
    39863986    Status := Status and ($FFFF - usStay - usGoto - usEnhance) or usRecover;
    39873987    if Job > jNone then
    3988       Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
    3989     NextUnit(UnStartLoc, true);
     3988      Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
     3989    NextUnit(UnStartLoc, True);
    39903990  end;
    39913991end;
     
    39993999      QueryText := Phrases.Lookup('MAP_CLOSE');
    40004000      case SimpleQuery(mkYesNoCancel, QueryText, '') of
    4001         mrIgnore: Server(sAbandonMap, me, 0, nil^);
    4002         mrOK: Server(sSaveMap, me, 0, nil^);
     4001        mrIgnore: Server(sAbandonMap, Me, 0, nil^);
     4002        mrOK: Server(sSaveMap, Me, 0, nil^);
    40034003      end;
    40044004    end else
    4005       Server(sAbandonMap, me, 0, nil^);
     4005      Server(sAbandonMap, Me, 0, nil^);
    40064006  end else begin
    40074007    if Server(sGetGameChanged, 0, 0, nil^) = eOK then begin
     
    40224022  I: Integer;
    40234023begin
    4024   AltGovs := false;
    4025     for i := 2 to nGov - 1 do
    4026       if (GovPreq[i] <> preNA) and
    4027         ((GovPreq[i] = preNone) or (MyRO.Tech[GovPreq[i]] >= tsApplicable)) then
    4028         AltGovs := true;
     4024  AltGovs := False;
     4025    for I := 2 to nGov - 1 do
     4026      if (GovPreq[I] <> preNA) and
     4027        ((GovPreq[I] = preNone) or (MyRO.Tech[GovPreq[I]] >= tsApplicable)) then
     4028        AltGovs := True;
    40294029
    40304030    if not AltGovs then
     
    40324032    else
    40334033    begin
    4034       RevolutionChanged := false;
     4034      RevolutionChanged := False;
    40354035      if MyRO.Happened and phChangeGov <> 0 then
    40364036      begin
    40374037        ModalSelectDlg.ShowNewContent(wmModal, kGov);
    4038         if ModalSelectDlg.result >= 0 then
     4038        if ModalSelectDlg.Result >= 0 then
    40394039        begin
    40404040          Play('NEWGOV');
    4041           Server(sSetGovernment, me, ModalSelectDlg.result, nil^);
     4041          Server(sSetGovernment, Me, ModalSelectDlg.Result, nil^);
    40424042          CityOptimizer_BeginOfTurn;
    4043           RevolutionChanged := true;
     4043          RevolutionChanged := True;
    40444044        end;
    40454045      end
     
    40474047      with MessgExDlg do
    40484048      begin // revolution!
    4049         MessgExDlg.MessgText := Tribe[me].TPhrase('REVOLUTION');
     4049        MessgExDlg.MessgText := Tribe[Me].TPhrase('REVOLUTION');
    40504050        MessgExDlg.Kind := mkYesNo;
    40514051        MessgExDlg.IconKind := mikPureIcon;
     
    40554055        begin
    40564056          Play('REVOLUTION');
    4057           Server(sRevolution, me, 0, nil^);
    4058           RevolutionChanged := true;
     4057          Server(sRevolution, Me, 0, nil^);
     4058          RevolutionChanged := True;
    40594059          if NatStatDlg.Visible then
    40604060            NatStatDlg.Close;
     
    40644064      end;
    40654065      if RevolutionChanged then
    4066         UpdateViews(true);
     4066        UpdateViews(True);
    40674067    end;
    40684068end;
     
    40844084procedure TMainScreen.mRunClick(Sender: TObject);
    40854085begin
    4086   if supervising then
     4086  if Supervising then
    40874087    Jump[0] := 999999
    40884088  else
    4089     Jump[me] := 999999;
    4090   EndTurn(true);
     4089    Jump[Me] := 999999;
     4090  EndTurn(True);
    40914091end;
    40924092
     
    41004100  if UnFocus >= 0 then
    41014101    with TUn(MyUn[UnFocus]) do
    4102       Server(sSelectTransport, me, UnFocus, nil^);
     4102      Server(sSelectTransport, Me, UnFocus, nil^);
    41034103end;
    41044104
     
    41124112  if UnFocus >= 0 then
    41134113  with TUn(MyUn[UnFocus]) do begin
    4114     DestinationMarkON := false;
     4114    DestinationMarkON := False;
    41154115    PaintDestination;
    41164116    Status := Status and ($FFFF - usRecover - usGoto - usEnhance) or usStay;
    41174117    if Job > jNone then
    4118       Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
    4119     NextUnit(UnStartLoc, true);
     4118      Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
     4119    NextUnit(UnStartLoc, True);
    41204120  end;
    41214121end;
     
    41374137  I: Integer;
    41384138begin
    4139   if G.Difficulty[me] > 0 then
    4140     ListDlg.ShowNewContent_MilReport(wmPersistent, me)
     4139  if G.Difficulty[Me] > 0 then
     4140    ListDlg.ShowNewContent_MilReport(wmPersistent, Me)
    41414141  else
    41424142  begin
    4143     i := 1;
    4144     while (i < nPl) and (1 shl i and MyRO.Alive = 0) do
    4145       inc(i);
    4146     if i < nPl then
    4147       ListDlg.ShowNewContent_MilReport(wmPersistent, i);
     4143    I := 1;
     4144    while (I < nPl) and (1 shl I and MyRO.Alive = 0) do
     4145      Inc(I);
     4146    if I < nPl then
     4147      ListDlg.ShowNewContent_MilReport(wmPersistent, I);
    41484148  end;
    41494149end;
     
    41604160    if Master >= 0 then begin
    41614161      OldMaster := Master;
    4162       i := Server(sUnloadUnit, me, UnFocus, nil^);
    4163       if i >= rExecuted then
     4162      I := Server(sUnloadUnit, Me, UnFocus, nil^);
     4163      if I >= rExecuted then
    41644164      begin
    41654165        if MyModel[mix].Domain = dAir then
     
    41734173        Status := Status and not usWaiting;
    41744174        if MyModel[mix].Domain <> dAir then
    4175           NextUnit(Loc, true)
     4175          NextUnit(Loc, True)
    41764176        else
    41774177          PanelPaint;
    41784178      end
    4179       else if i = eNoTime_Load then
     4179      else if I = eNoTime_Load then
    41804180        if MyModel[mix].Domain = dAir then
    41814181          SoundMessage(Phrases.Lookup('NOTIMELOADAIR'), 'NOMOVE_TIME')
     
    41864186      NewFocus := -1;
    41874187      uix := UnFocus;
    4188       for i := 1 to MyRO.nUn - 1 do
     4188      for I := 1 to MyRO.nUn - 1 do
    41894189      begin
    41904190        uix := (uix + MyRO.nUn - 1) mod MyRO.nUn;
    41914191        if (MyUn[uix].Master = UnFocus) and
    4192           (MyUn[uix].Movement = integer(MyModel[MyUn[uix].mix].speed)) then
     4192          (MyUn[uix].Movement = Integer(MyModel[MyUn[uix].mix].speed)) then
    41934193        begin
    41944194          MyUn[uix].Status := MyUn[uix].Status or usWaiting;
     
    42104210  if UnFocus >= 0 then
    42114211  with MyUn[UnFocus] do begin
    4212     DestinationMarkON := false;
     4212    DestinationMarkON := False;
    42134213    PaintDestination;
    42144214    Status := Status and ($FFFF - usStay - usRecover - usGoto - usEnhance) or usWaiting;
    42154215  end;
    4216   NextUnit(-1, false);
     4216  NextUnit(-1, False);
    42174217end;
    42184218
     
    42294229procedure TMainScreen.FormResize(Sender: TObject);
    42304230var
    4231   MiniFrame, MaxMapWidth: integer;
     4231  MiniFrame, MaxMapWidth: Integer;
    42324232begin
    42334233  SmallScreen := ClientWidth < 1024;
     
    43074307  begin
    43084308    RectInvalidate(0, TopBarHeight, ClientWidth, TopBarHeight + MapHeight);
    4309     MapValid := false;
     4309    MapValid := False;
    43104310    PaintAll;
    43114311  end;
    43124312end;
    43134313
    4314 procedure TMainScreen.FormCloseQuery(Sender: TObject; var CanClose: boolean);
     4314procedure TMainScreen.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    43154315begin
    43164316  CanClose := Closable;
    4317   if not Closable and idle and (me = 0) and (ClientMode < scContact) then
     4317  if not Closable and Idle and (Me = 0) and (ClientMode < scContact) then
    43184318    mResign.Click;
    43194319end;
     
    43374337  begin
    43384338    MessgExDlg.CancelMovie;
    4339     Server(sBreak, me, 0, nil^);
     4339    Server(sBreak, Me, 0, nil^);
    43404340  end
    43414341  else if ClientMode < 0 then
    4342     skipped := true
     4342    skipped := True
    43434343  else if ClientMode >= scContact then
    43444344    NegoDlg.ShowNewContent(wmPersistent)
     
    43464346  begin
    43474347    Jump[pTurn] := 0;
    4348     StartRunning := false;
     4348    StartRunning := False;
    43494349  end
    43504350  else
     
    43594359  else
    43604360  with MainMap do begin
    4361     if supervising then
     4361    if Supervising then
    43624362      xTerrain := xMidPanel + 2 * xxt + 14
    43634363    else if ClientWidth < 1280 then
     
    43664366      xTerrain := ClientWidth div 2;
    43674367    xTroop := xTerrain + 2 * xxt + 12;
    4368     if SmallScreen and not supervising then
     4368    if SmallScreen and not Supervising then
    43694369      xTroop := xRightPanel + 10 - 3 * 66 -
    43704370        GetSystemMetrics(SM_CXVSCROLL) - 19 - 4;
     
    43754375end;
    43764376
    4377 function TMainScreen.EndTurn(WasSkipped: boolean): boolean;
    4378 
    4379   function IsResourceUnused(cix, NeedFood, NeedProd: integer): boolean;
     4377function TMainScreen.EndTurn(WasSkipped: Boolean): Boolean;
     4378
     4379  function IsResourceUnused(cix, NeedFood, NeedProd: Integer): Boolean;
    43804380  var
    4381     dx, dy, fix: integer;
     4381    dx, dy, fix: Integer;
    43824382    CityAreaInfo: TCityAreaInfo;
    43834383    TileInfo: TTileInfo;
    43844384  begin
    4385     Server(sGetCityAreaInfo, me, cix, CityAreaInfo);
     4385    Server(sGetCityAreaInfo, Me, cix, CityAreaInfo);
    43864386    for dy := -3 to 3 do
    43874387      for dx := -3 to 3 do
     
    43934393          begin
    43944394            TileInfo.ExplCity := cix;
    4395             Server(sGetHypoCityTileInfo, me, dLoc(MyCity[cix].Loc, dx, dy),
     4395            Server(sGetHypoCityTileInfo, Me, dLoc(MyCity[cix].Loc, dx, dy),
    43964396              TileInfo);
    43974397            if (TileInfo.Food >= NeedFood) and (TileInfo.Prod >= NeedProd) then
    43984398            begin
    4399               result := true;
    4400               exit
     4399              Result := True;
     4400              Exit
    44014401            end;
    44024402          end
    44034403        end;
    4404     result := false;
     4404    Result := False;
    44054405  end;
    44064406
    44074407var
    4408   p1, uix, cix, CenterLoc: integer;
     4408  p1, uix, cix, CenterLoc: Integer;
    44094409  MsgItem: string;
    44104410  CityReport: TCityReport;
    44114411  PlaneReturnData: TPlaneReturnData;
    4412   Zoom: boolean;
    4413 begin
    4414   result := false;
     4412  Zoom: Boolean;
     4413begin
     4414  Result := False;
    44154415  if ClientMode >= scDipOffer then
    44164416    Exit;
    44174417
    4418   if supervising and (me <> 0) then begin
     4418  if Supervising and (Me <> 0) then begin
    44194419    ApplyToVisibleForms(faClose);
    44204420    ItsMeAgain(0);
     
    44354435          PlaneReturnData.Loc := Loc;
    44364436          PlaneReturnData.Movement := 0; // end turn without further movement?
    4437           if Server(sGetPlaneReturn, me, uix, PlaneReturnData) = eNoWay then
     4437          if Server(sGetPlaneReturn, Me, uix, PlaneReturnData) = eNoWay then
    44384438          begin
    44394439            CenterLoc := Loc + G.lx * 6;
    44404440            // centering the unit itself would make it covered by the query dialog
    44414441            while CenterLoc >= G.lx * G.ly do
    4442               dec(CenterLoc, G.lx * 2);
     4442              Dec(CenterLoc, G.lx * 2);
    44434443            Centre(CenterLoc);
    44444444            SetTroopLoc(-1);
     
    44554455              SetTroopLoc(Loc);
    44564456              PanelPaint;
    4457               exit;
     4457              Exit;
    44584458            end;
    44594459            MyUn[uix].Status := MyUn[uix].Status or usToldNoReturn;
     
    44614461        end;
    44624462
    4463     if not supervising and (MyRO.TestFlags and tfImmImprove = 0) and
     4463    if not Supervising and (MyRO.TestFlags and tfImmImprove = 0) and
    44644464      (MyRO.Government <> gAnarchy) and (MyRO.Money + TaxSum < 0) and
    44654465      (MyRO.TaxRate < 100) then // low funds!
     
    44734473        ShowModal;
    44744474        if ModalResult <> mrOK then
    4475           exit;
     4475          Exit;
    44764476      end;
    44774477
     
    44814481          if (Loc >= 0) and (Flags and chCaptured = 0) then
    44824482          begin
    4483             Zoom := false;
     4483            Zoom := False;
    44844484            CityReport.HypoTiles := -1;
    44854485            CityReport.HypoTax := -1;
    44864486            CityReport.HypoLux := -1;
    4487             Server(sGetCityReport, me, cix, CityReport);
     4487            Server(sGetCityReport, Me, cix, CityReport);
    44884488
    44894489            if (CityReport.Working - CityReport.Happy > Size shr 1) and
     
    45764576    else
    45774577      EOT.Hint := Phrases.Lookup('BTN_SKIP');
    4578     result := true;
     4578    Result := True;
    45794579    SetTroopLoc(-1);
    45804580    pTurn := -1;
    45814581    pLogo := -1;
    4582     UnitInfoBtn.Visible := false;
    4583     UnitBtn.Visible := false;
    4584     TerrainBtn.Visible := false;
     4582    UnitInfoBtn.Visible := False;
     4583    UnitBtn.Visible := False;
     4584    TerrainBtn.Visible := False;
    45854585    EOT.ButtonIndex := eotCancel;
    4586     EOT.Visible := true;
    4587     MapValid := false;
     4586    EOT.Visible := True;
     4587    MapValid := False;
    45884588    PanelPaint;
    45894589    Update;
    45904590    ClientMode := -1;
    4591     idle := false;
     4591    Idle := False;
    45924592    skipped := WasSkipped;
    45934593    for p1 := 1 to nPl - 1 do
    45944594      if G.RO[p1] <> nil then
    4595         skipped := true; // don't show enemy moves in hotseat mode
     4595        skipped := True; // don't show enemy moves in hotseat mode
    45964596  end
    45974597  else
     
    46034603  if NegoDlg.Visible then
    46044604    NegoDlg.Close;
    4605   HaveStrategyAdvice := false;
     4605  HaveStrategyAdvice := False;
    46064606  // AdvisorDlg.HaveStrategyAdvice;
    46074607  // negotiation might have changed advices
    46084608  EOT.ButtonIndex := eotCancel;
    4609   EOT.Visible := true;
     4609  EOT.Visible := True;
    46104610  PanelPaint;
    46114611  Update;
    46124612  ClientMode := -1;
    4613   idle := false;
    4614 end;
    4615 
    4616 procedure TMainScreen.ProcessRect(x0, y0, nx, ny, Options: integer);
     4613  Idle := False;
     4614end;
     4615
     4616procedure TMainScreen.ProcessRect(x0, y0, nx, ny, Options: Integer);
    46174617var
    4618   xs, ys, xl, yl: integer;
     4618  xs, ys, xl, yl: Integer;
    46194619begin
    46204620  with MainMap do begin
     
    46254625    while abs(2 * (xs + G.lx * (xxt * 2)) + xl - MapWidth) <
    46264626      abs(2 * xs + xl - MapWidth) do
    4627         inc(xs, G.lx * (xxt * 2));
     4627        Inc(xs, G.lx * (xxt * 2));
    46284628    ys := (y0 - yw) * yyt - yyt;
    46294629    if xs + xl > MapWidth then
     
    46324632      yl := MapHeight - ys;
    46334633    if (xl <= 0) or (yl <= 0) then
    4634       exit;
     4634      Exit;
    46354635    if Options and prPaint <> 0 then begin
    46364636      if Options and prAutoBounds <> 0 then
     
    46444644end;
    46454645
    4646 procedure TMainScreen.PaintLoc(Loc: integer; Radius: integer = 0);
     4646procedure TMainScreen.PaintLoc(Loc: Integer; Radius: Integer = 0);
    46474647var
    4648   yLoc, x0: integer;
     4648  yLoc, x0: Integer;
    46494649begin
    46504650  if MapValid then begin
    46514651    yLoc := (Loc + G.lx * 1024) div G.lx - 1024;
    46524652    x0 := (Loc + (yLoc and 1 - 2 * Radius + G.lx * 1024) div 2) mod G.lx;
    4653     offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     4653    Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    46544654    ProcessRect(x0, yLoc - 2 * Radius, 4 * Radius + 1, 4 * Radius + 1,
    46554655      prPaint or prAutoBounds or prInvalidate);
     
    46584658end;
    46594659
    4660 procedure TMainScreen.PaintLocTemp(Loc: integer; Style: TPaintLocTempStyle);
     4660procedure TMainScreen.PaintLocTemp(Loc: Integer; Style: TPaintLocTempStyle);
    46614661var
    4662   y0, x0, xMap, yMap: integer;
     4662  y0, x0, xMap, yMap: Integer;
    46634663begin
    46644664  with NoMap do begin
    46654665    if not MapValid then
    4666       exit;
     4666      Exit;
    46674667    Buffer.Canvas.Font.Assign(UniFont[ftSmall]);
    46684668    y0 := Loc div G.lx;
     
    46724672    while abs(2 * (xMap + G.lx * (xxt * 2)) + 2 * xxt - MapWidth) <
    46734673      abs(2 * xMap + 2 * xxt - MapWidth) do
    4674       inc(xMap, G.lx * (xxt * 2));
     4674      Inc(xMap, G.lx * (xxt * 2));
    46754675    yMap := (y0 - yw) * yyt - yyt;
    46764676    NoMap.SetOutput(Buffer);
     
    46844684// panel protusions are added
    46854685// NoMap must be set to buffer and bounds before
    4686 procedure TMainScreen.PaintBufferToScreen(xMap, yMap, width, height: integer);
     4686procedure TMainScreen.PaintBufferToScreen(xMap, yMap, width, height: Integer);
    46874687begin
    46884688  if xMap + width > MapWidth then
     
    46924692  if (width <= 0) or (height <= 0) or (width + xMap <= 0) or (height + yMap <= 0)
    46934693  then
    4694     exit;
     4694    Exit;
    46954695
    46964696  NoMap.BitBltBitmap(Panel, -xMap - MapOffset, -yMap + MapHeight - overlap, xMidPanel,
     
    47194719end;
    47204720
    4721 procedure TMainScreen.PaintLoc_BeforeMove(FromLoc: integer);
     4721procedure TMainScreen.PaintLoc_BeforeMove(FromLoc: Integer);
    47224722var
    4723   yLoc, x0: integer;
     4723  yLoc, x0: Integer;
    47244724begin
    47254725  if MapValid then
     
    47274727    yLoc := (FromLoc + G.lx * 1024) div G.lx - 1024;
    47284728    x0 := (FromLoc + (yLoc and 1 + G.lx * 1024) div 2) mod G.lx;
    4729     offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     4729    Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    47304730    ProcessRect(x0, yLoc, 1, 1, prPaint or prAutoBounds);
    47314731  end
     
    47344734procedure TMainScreen.PaintDestination;
    47354735var
    4736   Destination: integer;
     4736  Destination: Integer;
    47374737begin
    47384738  if (UnFocus >= 0) and (MyUn[UnFocus].Status and usGoto <> 0) then
     
    47554755procedure TMainScreen.MainOffscreenPaint;
    47564756var
    4757   ProcessOptions: integer;
     4757  ProcessOptions: Integer;
    47584758  rec: TRect;
    4759   DoInvalidate: boolean;
    4760 begin
    4761   if me < 0 then
    4762     with offscreen.Canvas do
     4759  DoInvalidate: Boolean;
     4760begin
     4761  if Me < 0 then
     4762    with Offscreen.Canvas do
    47634763    begin
    47644764      Brush.Color := $000000;
     
    47664766      Brush.Style := bsClear;
    47674767      OffscreenUser := self;
    4768       exit;
     4768      Exit;
    47694769    end;
    47704770
     
    47774777    if MapValid and (xwd = xw) and (ywd = yw) then
    47784778      MainMap.SetPaintBounds(0, 0, UsedOffscreenWidth, UsedOffscreenHeight);
    4779     MapValid := false;
     4779    MapValid := False;
    47804780    OffscreenUser := self;
    47814781  end;
     
    47904790      (ywd - yw > MapHeight div yyt) then
    47914791    begin
    4792       offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     4792      Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    47934793      ProcessRect(xw, yw, MapWidth div xxt, MapHeight div yyt,
    47944794        prPaint or prInvalidate);
    47954795    end else begin
    47964796      if (xwd = xw) and (ywd = yw) then
    4797         exit; { map window not moved }
    4798       offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     4797        Exit; { map window not moved }
     4798      Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    47994799      rec := Rect(0, 0, MapWidth, MapHeight);
    48004800{$IFDEF WINDOWS}
    4801       ScrollDC(offscreen.Canvas.Handle, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
     4801      ScrollDC(Offscreen.Canvas.Handle, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
    48024802        rec, rec, 0, nil);
    48034803{$ENDIF}
    48044804{$IFDEF UNIX}
    4805       ScrollDC(offscreen.Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
     4805      ScrollDC(Offscreen.Canvas, (xwd - xw) * (xxt * 2), (ywd - yw) * yyt,
    48064806        rec, rec, 0, nil);
    48074807{$ENDIF}
    4808       for DoInvalidate := false to FastScrolling do begin
     4808      for DoInvalidate := False to FastScrolling do begin
    48094809        if DoInvalidate then begin
    48104810          rec.Bottom := MapHeight - overlap;
     
    48634863  xwd := xw;
    48644864  ywd := yw;
    4865   MapValid := true;
     4865  MapValid := True;
    48664866end;
    48674867
     
    49204920  function MovementToString(var Un: TUn): string;
    49214921  begin
    4922     result := ScreenTools.MovementToString(Un.Movement);
     4922    Result := ScreenTools.MovementToString(Un.Movement);
    49234923    if Un.Master >= 0 then
    4924       result := '(' + result + ')'
     4924      Result := '(' + Result + ')'
    49254925    else if (MyModel[Un.mix].Domain = dAir) and
    49264926      (MyModel[Un.mix].Kind <> mkSpecial_Glider) then
    4927       result := Format('%s(%d)', [result, Un.Fuel]);
     4927      Result := Format('%s(%d)', [Result, Un.Fuel]);
    49284928  end;
    49294929
    49304930var
    4931   i, uix, uixDefender, x, xSrc, ySrc, xSrcBase, ySrcBase, CostFactor, Count,
     4931  I, uix, uixDefender, X, xSrc, ySrc, xSrcBase, ySrcBase, CostFactor, Count,
    49324932    mixShow, xTreasurySection, xResearchSection, JobFocus, TrueMoney,
    4933     TrueResearch: integer;
     4933    TrueResearch: Integer;
    49344934  Tile: Cardinal;
    4935   s: string;
     4935  S: string;
    49364936  unx: TUn;
    49374937  UnitInfo: TUnitInfo;
    49384938  JobProgressData: TJobProgressData;
    4939   Prio: boolean;
     4939  Prio: Boolean;
    49404940begin
    49414941  if not Assigned(MyRO) then Exit;
     
    50145014    CopyMiniToPanel;
    50155015    if ClientMode <> cEditMap then // MapBtn icons
    5016       for i := 0 to 5 do
    5017         if i <> 3 then
    5018           Dump(Panel, HGrSystem, xMini + G.lx - 42 + 16 * i, PanelHeight - 26,
    5019             8, 8, 121 + i * 9, 61);
     5016      for I := 0 to 5 do
     5017        if I <> 3 then
     5018          Dump(Panel, HGrSystem, xMini + G.lx - 42 + 16 * I, PanelHeight - 26,
     5019            8, 8, 121 + I * 9, 61);
    50205020
    50215021    if ClientMode = cEditMap then
    50225022    begin
    5023       for i := 0 to TrRow - 1 do
    5024         trix[i] := -1;
     5023      for I := 0 to TrRow - 1 do
     5024        trix[I] := -1;
    50255025      Count := 0;
    5026       for i := 0 to nBrushTypes - 1 do
     5026      for I := 0 to nBrushTypes - 1 do
    50275027      begin // display terrain types
    50285028        if (Count >= TrRow * sb.Position) and (Count < TrRow * (sb.Position + 1))
    50295029        then
    50305030        begin
    5031           trix[Count - TrRow * sb.Position] := BrushTypes[i];
    5032           x := (Count - TrRow * sb.Position) * TrPitch;
     5031          trix[Count - TrRow * sb.Position] := BrushTypes[I];
     5032          X := (Count - TrRow * sb.Position) * TrPitch;
    50335033          xSrcBase := -1;
    5034           case BrushTypes[i] of
     5034          case BrushTypes[I] of
    50355035            0 .. 8:
    50365036              begin
    5037                 xSrc := BrushTypes[i];
     5037                xSrc := BrushTypes[I];
    50385038                ySrc := 0
    50395039              end;
     
    50435043                ySrcBase := 2;
    50445044                xSrc := 0;
    5045                 ySrc := 2 * integer(BrushTypes[i]) - 15
     5045                ySrc := 2 * Integer(BrushTypes[I]) - 15
    50465046              end;
    50475047            fRiver:
     
    50765076                ySrcBase := 2;
    50775077                xSrc := 8;
    5078                 ySrc := 12 + BrushTypes[i] shr 25;
     5078                ySrc := 12 + BrushTypes[I] shr 25;
    50795079              end;
    50805080            tiIrrigation, tiFarm, tiMine, tiBase:
    50815081              begin
    5082                 xSrc := BrushTypes[i] shr 12 - 1;
     5082                xSrc := BrushTypes[I] shr 12 - 1;
    50835083                ySrc := 12
    50845084              end;
     
    51035103          with MainMap do begin
    51045104            if xSrcBase >= 0 then
    5105               Sprite(Panel, HGrTerrain, xTroop + 2 + x, yTroop + 9 - yyt, xxt * 2,
     5105              Sprite(Panel, HGrTerrain, xTroop + 2 + X, yTroop + 9 - yyt, xxt * 2,
    51065106                yyt * 3, 1 + xSrcBase * (xxt * 2 + 1),
    51075107                1 + ySrcBase * (yyt * 3 + 1));
    5108             Sprite(Panel, HGrTerrain, xTroop + 2 + x, yTroop + 9 - yyt, xxt * 2,
     5108            Sprite(Panel, HGrTerrain, xTroop + 2 + X, yTroop + 9 - yyt, xxt * 2,
    51095109              yyt * 3, 1 + xSrc * (xxt * 2 + 1), 1 + ySrc * (yyt * 3 + 1));
    5110             if BrushTypes[i] = BrushType then begin
    5111               ScreenTools.Frame(Panel.Canvas, xTroop + 2 + x,
    5112                 yTroop + 7 - yyt div 2, xTroop + 2 * xxt + x,
     5110            if BrushTypes[I] = BrushType then begin
     5111              ScreenTools.Frame(Panel.Canvas, xTroop + 2 + X,
     5112                yTroop + 7 - yyt div 2, xTroop + 2 * xxt + X,
    51135113                yTroop + 2 * yyt + 11, $000000, $000000);
    5114               ScreenTools.Frame(Panel.Canvas, xTroop + 1 + x,
    5115                 yTroop + 6 - yyt div 2, xTroop + 2 * xxt - 1 + x,
     5114              ScreenTools.Frame(Panel.Canvas, xTroop + 1 + X,
     5115                yTroop + 6 - yyt div 2, xTroop + 2 * xxt - 1 + X,
    51165116                yTroop + 2 * yyt + 10, MainTexture.ColorMark, MainTexture.ColorMark);
    51175117            end;
    51185118          end;
    51195119        end;
    5120         inc(Count)
     5120        Inc(Count)
    51215121      end;
    51225122      case BrushType of
    51235123        fDesert, fPrairie, fTundra, fArctic, fSwamp, fHills, fMountains:
    5124           s := Phrases.Lookup('TERRAIN', BrushType);
     5124          S := Phrases.Lookup('TERRAIN', BrushType);
    51255125        fShore:
    5126           s := Format(Phrases.Lookup('TWOTERRAINS'),
     5126          S := Format(Phrases.Lookup('TWOTERRAINS'),
    51275127            [Phrases.Lookup('TERRAIN', fOcean), Phrases.Lookup('TERRAIN',
    51285128            fShore)]);
    51295129        fGrass:
    5130           s := Format(Phrases.Lookup('TWOTERRAINS'),
     5130          S := Format(Phrases.Lookup('TWOTERRAINS'),
    51315131            [Phrases.Lookup('TERRAIN', fGrass), Phrases.Lookup('TERRAIN',
    51325132            fGrass + 12)]);
    51335133        fForest:
    5134           s := Format(Phrases.Lookup('TWOTERRAINS'),
     5134          S := Format(Phrases.Lookup('TWOTERRAINS'),
    51355135            [Phrases.Lookup('TERRAIN', fForest), Phrases.Lookup('TERRAIN',
    51365136            fJungle)]);
    51375137        fRiver:
    5138           s := Phrases.Lookup('RIVER');
     5138          S := Phrases.Lookup('RIVER');
    51395139        fDeadLands, fDeadLands or fCobalt, fDeadLands or fUranium,
    51405140          fDeadLands or fMercury:
    5141           s := Phrases.Lookup('TERRAIN', 3 * 12 + BrushType shr 25);
     5141          S := Phrases.Lookup('TERRAIN', 3 * 12 + BrushType shr 25);
    51425142        fPrefStartPos:
    5143           s := Phrases.Lookup('MAP_PREFSTART');
     5143          S := Phrases.Lookup('MAP_PREFSTART');
    51445144        fStartPos:
    5145           s := Phrases.Lookup('MAP_START');
     5145          S := Phrases.Lookup('MAP_START');
    51465146        fPoll:
    5147           s := Phrases.Lookup('POLL');
     5147          S := Phrases.Lookup('POLL');
    51485148      else // terrain improvements
    51495149        begin
    51505150          case BrushType of
    51515151            fRoad:
    5152               i := 1;
     5152              I := 1;
    51535153            fRR:
    5154               i := 2;
     5154              I := 2;
    51555155            tiIrrigation:
    5156               i := 4;
     5156              I := 4;
    51575157            tiFarm:
    5158               i := 5;
     5158              I := 5;
    51595159            tiMine:
    5160               i := 7;
     5160              I := 7;
    51615161            fCanal:
    5162               i := 8;
     5162              I := 8;
    51635163            tiFort:
    5164               i := 10;
     5164              I := 10;
    51655165            tiBase:
    5166               i := 12;
     5166              I := 12;
    51675167          end;
    5168           s := Phrases.Lookup('JOBRESULT', i);
     5168          S := Phrases.Lookup('JOBRESULT', I);
    51695169        end
    51705170      end;
    51715171      LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 1,
    5172         PanelHeight - 19, s);
     5172        PanelHeight - 19, S);
    51735173    end
    51745174    else if TroopLoc >= 0 then
     
    51835183          else
    51845184            mixShow := mix;
    5185           with Tribe[me].ModelPicture[mixShow] do
     5185          with Tribe[Me].ModelPicture[mixShow] do
    51865186          begin
    51875187            Sprite(Panel, HGr, xMidPanel + 7 + 12, yTroop + 1, 64, 48,
     
    51935193
    51945194          MakeBlue(Panel, xMidPanel + 7 + 12 + 10, yTroop - 13, 44, 12);
    5195           s := MovementToString(MyUn[UnFocus]);
     5195          S := MovementToString(MyUn[UnFocus]);
    51965196          RisedTextOut(Panel.Canvas, xMidPanel + 7 + 12 + 32 -
    5197             BiColorTextWidth(Panel.Canvas, s) div 2, yTroop - 16, s);
    5198 
    5199           s := IntToStr(Health) + '%';
     5197            BiColorTextWidth(Panel.Canvas, S) div 2, yTroop - 16, S);
     5198
     5199          S := IntToStr(Health) + '%';
    52005200          LightGradient(Panel.Canvas, xMidPanel + 7 + 12 + 7, PanelHeight - 22,
    52015201            (Health + 1) div 2, (ColorOfHealth(Health) and $FEFEFE shr 2) * 3);
     
    52045204              div 2, PanelHeight - 22, 50 - (Health + 1) div 2, $000000);
    52055205          RisedTextOut(Panel.Canvas, xMidPanel + 7 + 12 + 32 -
    5206             BiColorTextWidth(Panel.Canvas, s) div 2, PanelHeight - 23, s);
     5206            BiColorTextWidth(Panel.Canvas, S) div 2, PanelHeight - 23, S);
    52075207
    52085208          FrameImage(Panel.Canvas, HGrSystem.Data,
     
    52105210            121 + Exp div ExpCost * 13, 28);
    52115211          if Job = jCity then
    5212             s := Tribe[me].ModelName[-1]
     5212            S := Tribe[Me].ModelName[-1]
    52135213          else
    5214             s := Tribe[me].ModelName[mix];
     5214            S := Tribe[Me].ModelName[mix];
    52155215          if Home >= 0 then
    52165216          begin
    52175217            LoweredTextOut(Panel.Canvas, -1, MainTexture,
    5218               xMidPanel + 7 + xUnitText + 18, yTroop + 5, s);
     5218              xMidPanel + 7 + xUnitText + 18, yTroop + 5, S);
    52195219            LoweredTextOut(Panel.Canvas, -1, MainTexture,
    52205220              xMidPanel + 7 + xUnitText + 18, yTroop + 21,
     
    52235223          else
    52245224            LoweredTextOut(Panel.Canvas, -1, MainTexture,
    5225               xMidPanel + 7 + xUnitText + 18, yTroop + 13, s);
     5225              xMidPanel + 7 + xUnitText + 18, yTroop + 13, S);
    52265226        end;
    52275227
    52285228      if (UnFocus >= 0) and (MyUn[UnFocus].Loc <> TroopLoc) then
    52295229      begin // divide panel
    5230         if SmallScreen and not supervising then
    5231           x := xTroop - 8
     5230        if SmallScreen and not Supervising then
     5231          X := xTroop - 8
    52325232        else
    5233           x := xTroop - 152;
     5233          X := xTroop - 152;
    52345234        Pen.Color := MainTexture.ColorBevelShade;
    5235         MoveTo(x - 1, PanelHeight - MidPanelHeight + 2);
    5236         LineTo(x - 1, PanelHeight);
     5235        MoveTo(X - 1, PanelHeight - MidPanelHeight + 2);
     5236        LineTo(X - 1, PanelHeight);
    52375237        Pen.Color := MainTexture.ColorBevelLight;
    5238         MoveTo(x, PanelHeight - MidPanelHeight + 2);
    5239         LineTo(x, PanelHeight);
    5240       end;
    5241 
    5242       for i := 0 to 23 do
    5243         trix[i] := -1;
     5238        MoveTo(X, PanelHeight - MidPanelHeight + 2);
     5239        LineTo(X, PanelHeight);
     5240      end;
     5241
     5242      for I := 0 to 23 do
     5243        trix[I] := -1;
    52445244      if MyMap[TroopLoc] and fUnit <> 0 then
    52455245      begin
     
    52515251            LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 10,
    52525252              PanelHeight - 24, Phrases.Lookup('PRESENT'));
    5253             Server(sGetDefender, me, TroopLoc, uixDefender);
     5253            Server(sGetDefender, Me, TroopLoc, uixDefender);
    52545254            Count := 0;
    5255             for Prio := true downto false do
     5255            for Prio := True downto False do
    52565256              for uix := 0 to MyRO.nUn - 1 do
    52575257                if (uix = uixDefender) = Prio then
     
    52645264                    begin
    52655265                      trix[Count - TrRow * sb.Position] := uix;
    5266                       MakeUnitInfo(me, unx, UnitInfo);
    5267                       x := (Count - TrRow * sb.Position) * TrPitch;
     5266                      MakeUnitInfo(Me, unx, UnitInfo);
     5267                      X := (Count - TrRow * sb.Position) * TrPitch;
    52685268                      if uix = UnFocus then
    52695269                      begin
    5270                         ScreenTools.Frame(Panel.Canvas, xTroop + 4 + x,
    5271                           yTroop + 3, xTroop + 64 + x, yTroop + 47,
     5270                        ScreenTools.Frame(Panel.Canvas, xTroop + 4 + X,
     5271                          yTroop + 3, xTroop + 64 + X, yTroop + 47,
    52725272                          $000000, $000000);
    5273                         ScreenTools.Frame(Panel.Canvas, xTroop + 3 + x,
    5274                           yTroop + 2, xTroop + 63 + x, yTroop + 46,
     5273                        ScreenTools.Frame(Panel.Canvas, xTroop + 3 + X,
     5274                          yTroop + 2, xTroop + 63 + X, yTroop + 46,
    52755275                          MainTexture.ColorMark, MainTexture.ColorMark);
    52765276                      end
    52775277                      else if (unx.Master >= 0) and (unx.Master = UnFocus) then
    52785278                      begin
    5279                         CFrame(Panel.Canvas, xTroop + 4 + x, yTroop + 3,
    5280                           xTroop + 64 + x, yTroop + 47, 8, $000000);
    5281                         CFrame(Panel.Canvas, xTroop + 3 + x, yTroop + 2,
    5282                           xTroop + 63 + x, yTroop + 46, 8, MainTexture.ColorMark);
     5279                        CFrame(Panel.Canvas, xTroop + 4 + X, yTroop + 3,
     5280                          xTroop + 64 + X, yTroop + 47, 8, $000000);
     5281                        CFrame(Panel.Canvas, xTroop + 3 + X, yTroop + 2,
     5282                          xTroop + 63 + X, yTroop + 46, 8, MainTexture.ColorMark);
    52835283                      end;
    52845284                      NoMapPanel.SetOutput(Panel);
    5285                       NoMapPanel.PaintUnit(xTroop + 2 + x, yTroop + 1, UnitInfo,
     5285                      NoMapPanel.PaintUnit(xTroop + 2 + X, yTroop + 1, UnitInfo,
    52865286                        unx.Status);
    52875287                      if (ClientMode < scContact) and
     
    52895289                        (unx.Status and (usStay or usRecover or usGoto) <> 0))
    52905290                      then
    5291                         Sprite(Panel, HGrSystem, xTroop + 2 + 60 - 20 + x,
     5291                        Sprite(Panel, HGrSystem, xTroop + 2 + 60 - 20 + X,
    52925292                          yTroop + 35, 20, 20, 81, 25);
    52935293
    5294                       if not supervising then
     5294                      if not Supervising then
    52955295                      begin
    5296                         MakeBlue(Panel, xTroop + 2 + 10 + x,
     5296                        MakeBlue(Panel, xTroop + 2 + 10 + X,
    52975297                          yTroop - 13, 44, 12);
    5298                         s := MovementToString(unx);
     5298                        S := MovementToString(unx);
    52995299                        RisedTextOut(Panel.Canvas,
    5300                           xTroop + x + 34 - BiColorTextWidth(Panel.Canvas, s)
    5301                           div 2, yTroop - 16, s);
     5300                          xTroop + X + 34 - BiColorTextWidth(Panel.Canvas, S)
     5301                          div 2, yTroop - 16, S);
    53025302                      end;
    53035303                    end;
    5304                     inc(Count)
     5304                    Inc(Count)
    53055305                  end;
    53065306                end; // for uix:=0 to MyRO.nUn-1
    5307             assert(Count = TrCnt);
     5307            Assert(Count = TrCnt);
    53085308          end;
    53095309        end
     
    53125312          LoweredTextOut(Panel.Canvas, -1, MainTexture, xTroop + 8,
    53135313            PanelHeight - 24, Phrases.Lookup('PRESENT'));
    5314           Server(sGetUnits, me, TroopLoc, Count);
    5315           for i := 0 to Count - 1 do
    5316             if (i >= TrRow * sb.Position) and (i < TrRow * (sb.Position + 1)) then
     5314          Server(sGetUnits, Me, TroopLoc, Count);
     5315          for I := 0 to Count - 1 do
     5316            if (I >= TrRow * sb.Position) and (I < TrRow * (sb.Position + 1)) then
    53175317            begin // display enemy units
    5318               trix[i - TrRow * sb.Position] := i;
    5319               x := (i - TrRow * sb.Position) * TrPitch;
     5318              trix[I - TrRow * sb.Position] := I;
     5319              X := (I - TrRow * sb.Position) * TrPitch;
    53205320              NoMapPanel.SetOutput(Panel);
    5321               NoMapPanel.PaintUnit(xTroop + 2 + x, yTroop + 1,
    5322                 MyRO.EnemyUn[MyRO.nEnemyUn + i], 0);
     5321              NoMapPanel.PaintUnit(xTroop + 2 + X, yTroop + 1,
     5322                MyRO.EnemyUn[MyRO.nEnemyUn + I], 0);
    53235323            end;
    53245324        end;
    53255325      end;
    5326       if not SmallScreen or supervising then
     5326      if not SmallScreen or Supervising then
    53275327      begin // show terrain and improvements
    53285328        with NoMapPanel do
     
    53305330        if (UnFocus >= 0) and (MyUn[UnFocus].Job <> jNone) then begin
    53315331          JobFocus := MyUn[UnFocus].Job;
    5332           Server(sGetJobProgress, me, MyUn[UnFocus].Loc, JobProgressData);
     5332          Server(sGetJobProgress, Me, MyUn[UnFocus].Loc, JobProgressData);
    53335333          MakeBlue(Panel, xTerrain - 72, 148 - 17, 144, 31);
    53345334          PaintRelativeProgressBar(Panel.Canvas, 3, xTerrain - 68, 148 + 3, 63,
    53355335            JobProgressData[JobFocus].Done,
    53365336            JobProgressData[JobFocus].NextTurnPlus,
    5337             JobProgressData[JobFocus].Required, true, MainTexture);
    5338           s := Format('%s/%s',
     5337            JobProgressData[JobFocus].Required, True, MainTexture);
     5338          S := Format('%s/%s',
    53395339            [ScreenTools.MovementToString(JobProgressData[JobFocus].Done),
    53405340            ScreenTools.MovementToString(JobProgressData[JobFocus].Required)]);
    5341           RisedTextOut(Panel.Canvas, xTerrain + 6, 148 - 3, s);
     5341          RisedTextOut(Panel.Canvas, xTerrain + 6, 148 - 3, S);
    53425342          Tile := MyMap[MyUn[UnFocus].Loc];
    53435343          if (JobFocus = jRoad) and (Tile and fRiver <> 0) then
     
    53545354              JobFocus := nJob + 4
    53555355          end;
    5356           s := Phrases.Lookup('JOBRESULT', JobFocus);
     5356          S := Phrases.Lookup('JOBRESULT', JobFocus);
    53575357          RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas,
    5358             s) div 2, 148 - 19, s);
     5358            S) div 2, 148 - 19, S);
    53595359        end;
    53605360        if MyMap[TroopLoc] and (fTerrain or fSpecial) = fGrass or fSpecial1 then
    5361           s := Phrases.Lookup('TERRAIN', fGrass + 12)
     5361          S := Phrases.Lookup('TERRAIN', fGrass + 12)
    53625362        else if MyMap[TroopLoc] and fDeadLands <> 0 then
    5363           s := Phrases.Lookup('TERRAIN', 3 * 12)
     5363          S := Phrases.Lookup('TERRAIN', 3 * 12)
    53645364        else if (MyMap[TroopLoc] and fTerrain = fForest) and
    53655365          IsJungle(TroopLoc div G.lx) then
    5366           s := Phrases.Lookup('TERRAIN', fJungle)
     5366          S := Phrases.Lookup('TERRAIN', fJungle)
    53675367        else
    5368           s := Phrases.Lookup('TERRAIN', MyMap[TroopLoc] and fTerrain);
    5369         RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas, s)
    5370           div 2, 99, s);
     5368          S := Phrases.Lookup('TERRAIN', MyMap[TroopLoc] and fTerrain);
     5369        RisedTextOut(Panel.Canvas, xTerrain - BiColorTextWidth(Panel.Canvas, S)
     5370          div 2, 99, S);
    53715371      end;
    53725372
     
    53795379  end;
    53805380
    5381   for i := 0 to ControlCount - 1 do
    5382     if Controls[i] is TButtonB then
    5383       with TButtonB(Controls[i]) do
     5381  for I := 0 to ControlCount - 1 do
     5382    if Controls[I] is TButtonB then
     5383      with TButtonB(Controls[I]) do
    53845384      begin
    53855385        if Visible then
     
    53975397  if ClientMode <> cEditMap then
    53985398  begin
    5399     for i := 0 to ControlCount - 1 do
    5400       if Controls[i] is TButtonC then
    5401         with TButtonC(Controls[i]) do
     5399    for I := 0 to ControlCount - 1 do
     5400      if Controls[I] is TButtonC then
     5401        with TButtonC(Controls[I]) do
    54025402        begin
    54035403          Dump(Panel, HGrSystem, Left, Top - self.ClientHeight + PanelHeight,
     
    54395439    TrueMoney := MyRO.Money;
    54405440    TrueResearch := MyRO.Research;
    5441     if supervising then
     5441    if Supervising then
    54425442    begin // normalize values from after-turn state
    5443       dec(TrueMoney, TaxSum);
     5443      Dec(TrueMoney, TaxSum);
    54445444      if TrueMoney < 0 then
    54455445        TrueMoney := 0; // shouldn't happen
    5446       dec(TrueResearch, ScienceSum);
     5446      Dec(TrueResearch, ScienceSum);
    54475447      if TrueResearch < 0 then
    54485448        TrueResearch := 0; // shouldn't happen
     
    54525452    ImageOp_BCC(TopBar, Templates.Data, Point(xTreasurySection + 8, 1), TreasuryIcon.BoundsRect,
    54535453      $40A040, $4030C0);
    5454     s := IntToStr(TrueMoney);
     5454    S := IntToStr(TrueMoney);
    54555455    LoweredTextOut(TopBar.Canvas, -1, MainTexture, xTreasurySection + 48, 0,
    5456       s + '%c');
     5456      S + '%c');
    54575457    if MyRO.Government <> gAnarchy then
    54585458    begin
     
    54605460        $0000C0, $0080C0);
    54615461      if TaxSum >= 0 then
    5462         s := Format(Phrases.Lookup('MONEYGAINPOS'), [TaxSum])
     5462        S := Format(Phrases.Lookup('MONEYGAINPOS'), [TaxSum])
    54635463      else
    5464         s := Format(Phrases.Lookup('MONEYGAINNEG'), [TaxSum]);
     5464        S := Format(Phrases.Lookup('MONEYGAINNEG'), [TaxSum]);
    54655465      LoweredTextOut(TopBar.Canvas, -1, MainTexture, xTreasurySection + 48 +
    5466         15, 18, s);
     5466        15, 18, S);
    54675467    end;
    54685468
     
    54845484      else
    54855485        CostFactor := 2;
    5486       Server(sGetTechCost, me, 0, i);
     5486      Server(sGetTechCost, Me, 0, I);
    54875487      CostFactor := CostFactor * 22; // length of progress bar
    54885488      PaintRelativeProgressBar(TopBar.Canvas, 2, xResearchSection + 48 + 1, 26,
    5489         CostFactor, TrueResearch, ScienceSum, i, true, MainTexture);
     5489        CostFactor, TrueResearch, ScienceSum, I, True, MainTexture);
    54905490
    54915491      if MyRO.ResearchTech < 0 then
    5492         s := Phrases.Lookup('SCIENCE')
     5492        S := Phrases.Lookup('SCIENCE')
    54935493      else if MyRO.ResearchTech = adMilitary then
    5494         s := Phrases.Lookup('INITUNIT')
     5494        S := Phrases.Lookup('INITUNIT')
    54955495      else
    54965496      begin
    5497         s := Phrases.Lookup('ADVANCES', MyRO.ResearchTech);
     5497        S := Phrases.Lookup('ADVANCES', MyRO.ResearchTech);
    54985498        if MyRO.ResearchTech in FutureTech then
    54995499          if MyRO.Tech[MyRO.ResearchTech] >= 1 then
    5500             s := s + ' ' + IntToStr(MyRO.Tech[MyRO.ResearchTech] + 1)
     5500            S := S + ' ' + IntToStr(MyRO.Tech[MyRO.ResearchTech] + 1)
    55015501          else
    5502             s := s + ' 1';
     5502            S := S + ' 1';
    55035503      end;
    55045504      if ScienceSum > 0 then
    55055505      begin
    55065506        { j:=(i-MyRO.Research-1) div ScienceSum +1;
    5507           if j<1 then j:=1;
    5508           if j>1 then
    5509           s:=Format(Phrases.Lookup('TECHWAIT'),[s,j]); }
     5507          if J<1 then J:=1;
     5508          if J>1 then
     5509          S:=Format(Phrases.Lookup('TECHWAIT'),[S,J]); }
    55105510        LoweredTextOut(TopBar.Canvas, -1, MainTexture,
    5511           xResearchSection + 48, 0, s);
     5511          xResearchSection + 48, 0, S);
    55125512      end
    55135513      else
    55145514        LoweredTextOut(TopBar.Canvas, -1, MainTexture,
    5515           xResearchSection + 48, 0, s);
     5515          xResearchSection + 48, 0, S);
    55165516    end
    55175517    else
     
    55215521      ImageOp_BCC(TopBar, Templates.Data, Point(xResearchSection + 48 + CostFactor + 11,
    55225522        22), ChangeIcon.BoundsRect, $0000C0, $0080C0);
    5523       s := Format(Phrases.Lookup('TECHGAIN'), [ScienceSum]);
     5523      S := Format(Phrases.Lookup('TECHGAIN'), [ScienceSum]);
    55245524      LoweredTextOut(TopBar.Canvas, -1, MainTexture, xResearchSection + 48 +
    5525         CostFactor + 26, 18, s);
     5525        CostFactor + 26, 18, S);
    55265526    end;
    55275527  end;
     
    55295529  begin
    55305530    TopBar.Canvas.Font.Assign(UniFont[ftCaption]);
    5531     s := TurnToString(MyRO.Turn);
     5531    S := TurnToString(MyRO.Turn);
    55325532    RisedTextOut(TopBar.Canvas,
    5533       40 + (xTreasurySection - 40 - BiColorTextWidth(TopBar.Canvas, s))
    5534       div 2, 6, s);
     5533      40 + (xTreasurySection - 40 - BiColorTextWidth(TopBar.Canvas, S))
     5534      div 2, 6, S);
    55355535    TopBar.Canvas.Font.Assign(UniFont[ftNormal]);
    55365536  end;
     
    55405540procedure TMainScreen.FocusNextUnit(Dir: Integer);
    55415541var
    5542   i, uix, NewFocus: Integer;
     5542  I, uix, NewFocus: Integer;
    55435543begin
    55445544  if ClientMode >= scContact then
     
    55475547  PaintDestination;
    55485548  NewFocus := -1;
    5549   for i := 1 to MyRO.nUn do begin
    5550     uix := (UnFocus + i * Dir + MyRO.nUn) mod MyRO.nUn;
     5549  for I := 1 to MyRO.nUn do begin
     5550    uix := (UnFocus + I * Dir + MyRO.nUn) mod MyRO.nUn;
    55515551    if (MyUn[uix].Loc >= 0) and (MyUn[uix].Status and usStay = 0) then begin
    55525552      NewFocus := uix;
     
    55615561end;
    55625562
    5563 procedure TMainScreen.FocusOnLoc(Loc: integer; Options: integer = 0);
     5563procedure TMainScreen.FocusOnLoc(Loc: Integer; Options: Integer = 0);
    55645564var
    5565   dx: integer;
    5566   Outside, Changed: boolean;
     5565  dx: Integer;
     5566  Outside, Changed: Boolean;
    55675567begin
    55685568  with MainMap do begin
     
    55725572      (Loc div G.lx >= yw + (MapHeight - 1) div yyt - 2));
    55735573  end;
    5574   Changed := true;
     5574  Changed := True;
    55755575  if Outside then begin
    55765576    Centre(Loc);
     
    55805580    PaintAllMaps
    55815581  else
    5582     Changed := false;
     5582    Changed := False;
    55835583  if Options and flRepaintPanel <> 0 then
    55845584    PanelPaint;
     
    55905590var
    55915591  Dist, TestDist: Single;
    5592   i, uix, NewFocus: Integer;
     5592  I, uix, NewFocus: Integer;
    55935593  GotoOnly: Boolean;
    55945594begin
     
    56005600  for GotoOnly := GoOnPhase downto False do begin
    56015601    NewFocus := -1;
    5602     for i := 1 to MyRO.nUn do begin
    5603       uix := (UnFocus + i) mod MyRO.nUn;
     5602    for I := 1 to MyRO.nUn do begin
     5603      uix := (UnFocus + I) mod MyRO.nUn;
    56045604      if (MyUn[uix].Loc >= 0) and (MyUn[uix].Job = jNone) and
    56055605        (MyUn[uix].Status and (usStay or usRecover or usWaiting) = usWaiting)
     
    56405640end;
    56415641
    5642 procedure TMainScreen.Scroll(dx, dy: integer);
     5642procedure TMainScreen.Scroll(dx, dy: Integer);
    56435643begin
    56445644  xw := (xw + G.lx + dx) mod G.lx;
     
    56645664procedure TMainScreen.Timer1Timer(Sender: TObject);
    56655665var
    5666   dx, dy, ScrollSpeed: integer;
    5667 begin
    5668   if idle and (me >= 0) and (GameMode <> cMovie) then
     5666  dx, dy, ScrollSpeed: Integer;
     5667begin
     5668  if Idle and (Me >= 0) and (GameMode <> cMovie) then
    56695669    if (fsModal in Screen.ActiveForm.FormState) or
    56705670      (Screen.ActiveForm is TBufferedDrawDlg) and
     
    56745674      if not BlinkON then
    56755675      begin
    5676         BlinkON := true;
     5676        BlinkON := True;
    56775677        if UnFocus >= 0 then
    56785678          PaintLocTemp(MyUn[UnFocus].Loc)
    5679         else if TurnComplete and not supervising then
     5679        else if TurnComplete and not Supervising then
    56805680          EOT.SetButtonIndexFast(eotBlinkOn);
    56815681      end;
     
    56895689        dx := 0;
    56905690        dy := 0;
    5691         if Mouse.CursorPos.y < Screen.height - PanelHeight then
    5692           if Mouse.CursorPos.x = 0 then
     5691        if Mouse.CursorPos.Y < Screen.height - PanelHeight then
     5692          if Mouse.CursorPos.X = 0 then
    56935693            dx := -ScrollSpeed // scroll left
    5694           else if Mouse.CursorPos.x = Screen.width - 1 then
     5694          else if Mouse.CursorPos.X = Screen.width - 1 then
    56955695            dx := ScrollSpeed; // scroll right
    5696         if Mouse.CursorPos.y = 0 then
     5696        if Mouse.CursorPos.Y = 0 then
    56975697          dy := -ScrollSpeed // scroll up
    5698         else if (Mouse.CursorPos.y = Screen.height - 1) and
    5699           (Mouse.CursorPos.x >= TerrainBtn.Left + TerrainBtn.width) and
    5700           (Mouse.CursorPos.x < xRightPanel + 10 - 8) then
     5698        else if (Mouse.CursorPos.Y = Screen.height - 1) and
     5699          (Mouse.CursorPos.X >= TerrainBtn.Left + TerrainBtn.width) and
     5700          (Mouse.CursorPos.X < xRightPanel + 10 - 8) then
    57015701          dy := ScrollSpeed; // scroll down
    57025702        if (dx <> 0) or (dy <> 0) then
     
    57115711      BlinkTime := (BlinkTime + 1) mod (BlinkOnTime + BlinkOffTime);
    57125712      BlinkON := BlinkTime >= BlinkOffTime;
    5713       DestinationMarkON := true;
     5713      DestinationMarkON := True;
    57145714      if UnFocus >= 0 then
    57155715      begin
     
    57225722        end;
    57235723      end
    5724       else if TurnComplete and not supervising then
     5724      else if TurnComplete and not Supervising then
    57255725      begin
    57265726        if BlinkTime = 0 then
     
    57325732end;
    57335733
    5734 procedure TMainScreen.SetMapPos(Loc: integer; MapPos: TPoint);
     5734procedure TMainScreen.SetMapPos(Loc: Integer; MapPos: TPoint);
    57355735begin
    57365736  with MainMap do begin
     
    57505750end;
    57515751
    5752 procedure TMainScreen.Centre(Loc: integer);
     5752procedure TMainScreen.Centre(Loc: Integer);
    57535753begin
    57545754  SetMapPos(Loc, Point(MapWidth div 2, MapHeight div 2));
    57555755end;
    57565756
    5757 function TMainScreen.ZoomToCity(Loc: integer; NextUnitOnClose: boolean = false;
    5758   ShowEvent: integer = 0): boolean;
    5759 begin
    5760   result := MyMap[Loc] and (fOwned or fSpiedOut) <> 0;
    5761   if result then
     5757function TMainScreen.ZoomToCity(Loc: Integer; NextUnitOnClose: Boolean = False;
     5758  ShowEvent: Integer = 0): Boolean;
     5759begin
     5760  Result := MyMap[Loc] and (fOwned or fSpiedOut) <> 0;
     5761  if Result then
    57625762    with CityDlg do
    57635763    begin
     
    57855785end;
    57865786
    5787 function TMainScreen.LocationOfScreenPixel(x, y: integer): Integer;
     5787function TMainScreen.LocationOfScreenPixel(X, Y: Integer): Integer;
    57885788var
    5789   qx, qy: integer;
     5789  qx, qy: Integer;
    57905790begin
    57915791  with MainMap do begin
    5792     qx := (x * (yyt * 2) + y * (xxt * 2) + xxt * yyt * 2) div (xxt * yyt * 4) - 1;
    5793     qy := (y * (xxt * 2) - x * (yyt * 2) - xxt * yyt * 2 + 4000 * xxt * yyt)
     5792    qx := (X * (yyt * 2) + Y * (xxt * 2) + xxt * yyt * 2) div (xxt * yyt * 4) - 1;
     5793    qy := (Y * (xxt * 2) - X * (yyt * 2) - xxt * yyt * 2 + 4000 * xxt * yyt)
    57945794      div (xxt * yyt * 4) - 999;
    57955795    Result := (xw + (qx - qy + 2048) div 2 - 1024 + G.lx) mod G.lx + G.lx *
     
    58055805
    58065806procedure TMainScreen.MapBoxMouseDown(Sender: TObject; Button: TMouseButton;
    5807   Shift: TShiftState; x, y: integer);
     5807  Shift: TShiftState; X, Y: Integer);
    58085808var
    5809   i, uix, emix, p1, dx, dy, MouseLoc: integer;
     5809  I, uix, emix, p1, dx, dy, MouseLoc: Integer;
    58105810  EditTileData: TEditTileData;
    5811   m, m2: TMenuItem;
     5811  M, m2: TMenuItem;
    58125812  MoveAdviceData: TMoveAdviceData;
    5813   DoCenter: boolean;
     5813  DoCenter: Boolean;
    58145814begin
    58155815  if GameMode = cMovie then
    5816     exit;
     5816    Exit;
    58175817
    58185818  if CityDlg.Visible then
     
    58205820  if UnitStatDlg.Visible then
    58215821    UnitStatDlg.Close;
    5822   MouseLoc := LocationOfScreenPixel(x, y);
     5822  MouseLoc := LocationOfScreenPixel(X, Y);
    58235823  if (MouseLoc < 0) or (MouseLoc >= G.lx * G.ly) then
    5824     exit;
     5824    Exit;
    58255825  if (Button = mbLeft) and not(ssShift in Shift) then
    58265826  begin
    5827     DoCenter := true;
     5827    DoCenter := True;
    58285828    if ClientMode = cEditMap then
    58295829    begin
    5830       DoCenter := false;
     5830      DoCenter := False;
    58315831      EditTileData.Loc := MouseLoc;
    58325832      if ssCtrl in Shift then // toggle special resource
     
    58665866      else
    58675867        EditTileData.NewTile := MyMap[MouseLoc] xor BrushType;
    5868       Server(sEditTile, me, 0, EditTileData);
    5869       Edited := true;
     5868      Server(sEditTile, Me, 0, EditTileData);
     5869      Edited := True;
    58705870      BrushLoc := MouseLoc;
    58715871      PaintLoc(MouseLoc, 2);
     
    58935893      begin
    58945894        ZoomToCity(MouseLoc);
    5895         DoCenter := false;
     5895        DoCenter := False;
    58965896      end
    58975897      else
    58985898      begin
    58995899        UnitStatDlg.ShowNewContent_EnemyCity(wmPersistent, MouseLoc);
    5900         DoCenter := false;
     5900        DoCenter := False;
    59015901      end;
    59025902    end
     
    59045904      if MyMap[MouseLoc] and fOwned <> 0 then
    59055905      begin
    5906         DoCenter := false;
    5907         if not supervising and (ClientMode < scContact) then
     5906        DoCenter := False;
     5907        if not Supervising and (ClientMode < scContact) then
    59085908        begin // not in negotiation mode
    59095909          if (UnFocus >= 0) and (MyUn[UnFocus].Loc = MouseLoc) then
    59105910          begin // rotate
    59115911            uix := (UnFocus + 1) mod MyRO.nUn;
    5912             i := MyRO.nUn - 1;
    5913             while i > 0 do
     5912            I := MyRO.nUn - 1;
     5913            while I > 0 do
    59145914            begin
    59155915              if (MyUn[uix].Loc = MouseLoc) and (MyUn[uix].Job = jNone) and
     
    59175917                usWaiting) = usWaiting) then
    59185918                Break;
    5919               dec(i);
     5919              Dec(I);
    59205920              uix := (uix + 1) mod MyRO.nUn;
    59215921            end;
    5922             if i = 0 then
     5922            if I = 0 then
    59235923              uix := UnFocus;
    59245924          end
    59255925          else
    5926             Server(sGetDefender, me, MouseLoc, uix);
     5926            Server(sGetDefender, Me, MouseLoc, uix);
    59275927          if uix <> UnFocus then
    59285928            SetUnFocus(uix);
    5929           TurnComplete := false;
     5929          TurnComplete := False;
    59305930          EOT.ButtonIndex := eotGray;
    59315931        end;
     
    59355935      else if (MyMap[MouseLoc] and fSpiedOut <> 0) and not(ssCtrl in Shift) then
    59365936      begin
    5937         DoCenter := false;
     5937        DoCenter := False;
    59385938        SetTroopLoc(MouseLoc);
    59395939        PanelPaint;
     
    59415941      else
    59425942      begin
    5943         DoCenter := false;
     5943        DoCenter := False;
    59445944        UnitStatDlg.ShowNewContent_EnemyLoc(wmPersistent, MouseLoc);
    59455945      end;
     
    59535953    not(ssShift in Shift) then
    59545954  begin
    5955     if supervising then
     5955    if Supervising then
    59565956    begin
    59575957      EditLoc := MouseLoc;
    5958       Server(sGetModels, me, 0, nil^);
     5958      Server(sGetModels, Me, 0, nil^);
    59595959      EmptyMenu(mCreateUnit);
    59605960      for p1 := 0 to nPl - 1 do
    59615961        if 1 shl p1 and MyRO.Alive <> 0 then
    59625962        begin
    5963           m := TMenuItem.Create(mCreateUnit);
    5964           m.Caption := Tribe[p1].TPhrase('SHORTNAME');
     5963          M := TMenuItem.Create(mCreateUnit);
     5964          M.Caption := Tribe[p1].TPhrase('SHORTNAME');
    59655965          for emix := MyRO.nEnemyModel - 1 downto 0 do
    59665966            if (MyRO.EnemyModel[emix].Owner = p1) and
    5967               (Server(sCreateUnit - sExecute + p1 shl 4, me,
     5967              (Server(sCreateUnit - sExecute + p1 shl 4, Me,
    59685968              MyRO.EnemyModel[emix].mix, MouseLoc) >= rExecuted) then
    59695969            begin
    59705970              if not Assigned(Tribe[p1].ModelPicture[MyRO.EnemyModel[emix].mix].HGr) then
    59715971                InitEnemyModel(emix);
    5972               m2 := TMenuItem.Create(m);
     5972              m2 := TMenuItem.Create(M);
    59735973              m2.Caption := Tribe[p1].ModelName[MyRO.EnemyModel[emix].mix];
    59745974              m2.Tag := p1 shl 16 + MyRO.EnemyModel[emix].mix;
    59755975              m2.OnClick := CreateUnitClick;
    5976               m.Add(m2);
     5976              M.Add(m2);
    59775977            end;
    5978           m.Visible := m.Count > 0;
    5979           mCreateUnit.Add(m);
     5978          M.Visible := M.Count > 0;
     5979          mCreateUnit.Add(M);
    59805980        end;
    59815981      if FullScreen then
    5982         EditPopup.Popup(Left + x, Top + y)
     5982        EditPopup.Popup(Left + X, Top + Y)
    59835983      else
    5984         EditPopup.Popup(Left + x + 4,
    5985           Top + y + GetSystemMetrics(SM_CYCAPTION) + 4);
     5984        EditPopup.Popup(Left + X + 4,
     5985          Top + Y + GetSystemMetrics(SM_CYCAPTION) + 4);
    59865986    end
    59875987    else if (UnFocus >= 0) and (MyUn[UnFocus].Loc <> MouseLoc) then
     
    59945994        if abs(dx) + abs(dy) < 3 then
    59955995        begin
    5996           DestinationMarkON := false;
     5996          DestinationMarkON := False;
    59975997          PaintDestination;
    59985998          Status := Status and ($FFFF - usStay - usRecover - usGoto - usEnhance)
     
    60076007            with MyUn[UnFocus], BattleDlg.Forecast do
    60086008            begin
    6009               pAtt := me;
     6009              pAtt := Me;
    60106010              mixAtt := mix;
    60116011              HealthAtt := Health;
     
    60146014            end;
    60156015            BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement;
    6016             if (Server(sGetBattleForecastEx, me, MouseLoc, BattleDlg.Forecast)
     6016            if (Server(sGetBattleForecastEx, Me, MouseLoc, BattleDlg.Forecast)
    60176017              >= rExecuted) and (BattleDlg.Forecast.EndHealthAtt <= 0) then
    60186018            begin
    60196019              BattleDlg.uix := UnFocus;
    60206020              BattleDlg.ToLoc := MouseLoc;
    6021               BattleDlg.IsSuicideQuery := true;
     6021              BattleDlg.IsSuicideQuery := True;
    60226022              BattleDlg.ShowModal;
    60236023              if BattleDlg.ModalResult <> mrOK then
    6024                 exit;
     6024                Exit;
    60256025            end;
    60266026          end;
    6027           DestinationMarkON := false;
     6027          DestinationMarkON := False;
    60286028          PaintDestination;
    60296029          Status := Status and not(usStay or usRecover or usEnhance) or
    60306030            usWaiting;
    6031           MoveToLoc(MouseLoc, false); { goto }
     6031          MoveToLoc(MouseLoc, False); { goto }
    60326032        end;
    60336033      end;
     
    60366036    (MyModel[MyUn[UnFocus].mix].Kind in [mkSettler, mkSlaves]) then
    60376037  begin
    6038     DestinationMarkON := false;
     6038    DestinationMarkON := False;
    60396039    PaintDestination;
    60406040    MyUn[UnFocus].Status := MyUn[UnFocus].Status and
     
    60426042    uix := UnFocus;
    60436043    if MouseLoc <> MyUn[uix].Loc then
    6044       MoveToLoc(MouseLoc, true); { goto }
     6044      MoveToLoc(MouseLoc, True); { goto }
    60456045    if (UnFocus = uix) and (MyUn[uix].Loc = MouseLoc) then
    60466046      mEnhance.Click;
     
    60556055    with MyUn[UnFocus], BattleDlg.Forecast do
    60566056    begin
    6057       pAtt := me;
     6057      pAtt := Me;
    60586058      mixAtt := mix;
    60596059      HealthAtt := Health;
     
    60626062    end;
    60636063    BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement;
    6064     if Server(sGetBattleForecastEx, me, MouseLoc, BattleDlg.Forecast) >= rExecuted
     6064    if Server(sGetBattleForecastEx, Me, MouseLoc, BattleDlg.Forecast) >= rExecuted
    60656065    then
    60666066    begin
    60676067      BattleDlg.uix := UnFocus;
    60686068      BattleDlg.ToLoc := MouseLoc;
    6069       BattleDlg.Left := x - BattleDlg.width div 2;
     6069      BattleDlg.Left := X - BattleDlg.width div 2;
    60706070      if BattleDlg.Left < 0 then
    60716071        BattleDlg.Left := 0
    60726072      else if BattleDlg.Left + BattleDlg.width > Screen.width then
    60736073        BattleDlg.Left := Screen.width - BattleDlg.width;
    6074       BattleDlg.Top := y - BattleDlg.height div 2;
     6074      BattleDlg.Top := Y - BattleDlg.height div 2;
    60756075      if BattleDlg.Top < 0 then
    60766076        BattleDlg.Top := 0
    60776077      else if BattleDlg.Top + BattleDlg.height > Screen.height then
    60786078        BattleDlg.Top := Screen.height - BattleDlg.height;
    6079       BattleDlg.IsSuicideQuery := false;
     6079      BattleDlg.IsSuicideQuery := False;
    60806080      BattleDlg.Show;
    60816081    end;
     
    60836083end;
    60846084
    6085 function TMainScreen.MoveUnit(dx, dy: integer; Options: integer): integer;
     6085function TMainScreen.MoveUnit(dx, dy: Integer; Options: Integer): Integer;
    60866086// move focused unit to adjacent tile
    60876087var
    6088   i, cix, uix, euix, FromLoc, ToLoc, DirCode, UnFocus0, Defender, Mission, p1,
    6089     NewTiles, cixChanged: integer;
     6088  I, cix, uix, euix, FromLoc, ToLoc, DirCode, UnFocus0, Defender, Mission, p1,
     6089    NewTiles, cixChanged: Integer;
    60906090  OldToTile: Cardinal;
    60916091  CityCaptured, IsAttack, OldUnrest, NewUnrest, NeedEcoUpdate, NeedRepaintPanel,
    6092     ToTransport, ToShip: boolean;
     6092    ToTransport, ToShip: Boolean;
    60936093  PlaneReturnData: TPlaneReturnData;
    60946094  QueryItem: string;
    60956095begin
    6096   result := eInvalid;
     6096  Result := eInvalid;
    60976097  UnFocus0 := UnFocus;
    60986098  FromLoc := MyUn[UnFocus].Loc;
     
    61006100  if (ToLoc < 0) or (ToLoc >= G.lx * G.ly) then
    61016101  begin
    6102     result := eInvalid;
    6103     exit;
     6102    Result := eInvalid;
     6103    Exit;
    61046104  end;
    61056105  if MyMap[ToLoc] and fStealthUnit <> 0 then
    61066106  begin
    61076107    SoundMessage(Phrases.Lookup('ATTACKSTEALTH'), '');
    6108     exit;
     6108    Exit;
    61096109  end;
    61106110  if MyMap[ToLoc] and fHiddenUnit <> 0 then
    61116111  begin
    61126112    SoundMessage(Phrases.Lookup('ATTACKSUB'), '');
    6113     exit;
     6113    Exit;
    61146114  end;
    61156115
     
    61216121    begin
    61226122      SoundMessage(Phrases.Lookup('NOATTACKER'), '');
    6123       exit;
     6123      Exit;
    61246124    end;
    61256125    euix := MyRO.nEnemyUn - 1;
    61266126    while (euix >= 0) and (MyRO.EnemyUn[euix].Loc <> ToLoc) do
    6127       dec(euix);
     6127      Dec(euix);
    61286128  end;
    61296129
    61306130  DirCode := dx and 7 shl 4 + dy and 7 shl 7;
    6131   result := Server(sMoveUnit - sExecute + DirCode, me, UnFocus, nil^);
    6132   if (result < rExecuted) and (MyUn[UnFocus].Job > jNone) then
    6133     Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
    6134   if (result < rExecuted) and (result <> eNoTime_Move) then
    6135   begin
    6136     case result of
     6131  Result := Server(sMoveUnit - sExecute + DirCode, Me, UnFocus, nil^);
     6132  if (Result < rExecuted) and (MyUn[UnFocus].Job > jNone) then
     6133    Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
     6134  if (Result < rExecuted) and (Result <> eNoTime_Move) then
     6135  begin
     6136    case Result of
    61376137      eNoTime_Load:
    61386138        if MyModel[MyUn[UnFocus].mix].Domain = dAir then
     
    61706170            (MyMap[ToLoc] and (fUnit or fOwned) = fUnit or fOwned) then
    61716171          begin // false load attempt
    6172             ToShip := false;
    6173             ToTransport := false;
     6172            ToShip := False;
     6173            ToTransport := False;
    61746174            for uix := 0 to MyRO.nUn - 1 do
    61756175              if (MyUn[uix].Loc = ToLoc) and
    61766176                (MyModel[MyUn[uix].mix].Domain = dSea) then
    61776177              begin
    6178                 ToShip := true;
     6178                ToShip := True;
    61796179                if MyModel[MyUn[uix].mix].Cap[mcSeaTrans] > 0 then
    6180                   ToTransport := true;
     6180                  ToTransport := True;
    61816181              end;
    61826182            if ToTransport then
     
    61936193      Play('NOMOVE_DEFAULT');
    61946194    end;
    6195     exit;
    6196   end;
    6197 
    6198   if ((result = eWon) or (result = eLost) or (result = eBloody)) and
     6195    Exit;
     6196  end;
     6197
     6198  if ((Result = eWon) or (Result = eLost) or (Result = eBloody)) and
    61996199    (MyUn[UnFocus].Movement < 100) and
    62006200    (MyModel[MyUn[UnFocus].mix].Cap[mcWill] = 0) then
     
    62036203      [MyUn[UnFocus].Movement]), 'NOMOVE_TIME') <> mrOK then
    62046204    begin
    6205       result := eInvalid;
    6206       exit;
     6205      Result := eInvalid;
     6206      Exit;
    62076207    end;
    62086208    Update; // remove message box from screen
    62096209  end;
    62106210
    6211   OldUnrest := false;
    6212   NewUnrest := false;
    6213   if (result >= rExecuted) and (result and rUnitRemoved = 0) and
     6211  OldUnrest := False;
     6212  NewUnrest := False;
     6213  if (Result >= rExecuted) and (Result and rUnitRemoved = 0) and
    62146214    (MyMap[ToLoc] and (fUnit or fOwned) <> fUnit) then
    62156215  begin
     
    62216221      begin
    62226222        QueryItem := 'UNREST_NOTOWN';
    6223         p1 := me;
     6223        p1 := Me;
    62246224      end
    62256225      else
     
    62386238        if ModalResult <> mrOK then
    62396239        begin
    6240           result := eInvalid;
    6241           exit;
     6240          Result := eInvalid;
     6241          Exit;
    62426242        end;
    62436243      end;
     
    62466246  end;
    62476247
    6248   if (result >= rExecuted) and (MyModel[MyUn[UnFocus].mix].Domain = dAir) and
     6248  if (Result >= rExecuted) and (MyModel[MyUn[UnFocus].mix].Domain = dAir) and
    62496249    (MyUn[UnFocus].Status and usToldNoReturn = 0) then
    62506250  begin // can plane return?
     
    62666266        PlaneReturnData.Movement := MyUn[UnFocus].Movement - 150;
    62676267    end;
    6268     if Server(sGetPlaneReturn, me, UnFocus, PlaneReturnData) = eNoWay then
     6268    if Server(sGetPlaneReturn, Me, UnFocus, PlaneReturnData) = eNoWay then
    62696269    begin
    62706270      if MyModel[MyUn[UnFocus].mix].Kind = mkSpecial_Glider then
     
    62756275        <> mrOK then
    62766276      begin
    6277         result := eInvalid;
    6278         exit;
     6277        Result := eInvalid;
     6278        Exit;
    62796279      end;
    62806280      Update; // remove message box from screen
     
    62836283  end;
    62846284
    6285   if result = eMissionDone then
     6285  if Result = eMissionDone then
    62866286  begin
    62876287    ModalSelectDlg.ShowNewContent(wmModal, kMission);
    62886288    Update; // dialog still on screen
    6289     Mission := ModalSelectDlg.result;
     6289    Mission := ModalSelectDlg.Result;
    62906290    if Mission < 0 then
    6291       exit;
    6292     Server(sSetSpyMission + Mission shl 4, me, 0, nil^);
    6293   end;
    6294 
    6295   CityCaptured := false;
    6296   if result = eNoTime_Move then
     6291      Exit;
     6292    Server(sSetSpyMission + Mission shl 4, Me, 0, nil^);
     6293  end;
     6294
     6295  CityCaptured := False;
     6296  if Result = eNoTime_Move then
    62976297    Play('NOMOVE_TIME')
    62986298  else
    62996299  begin
    6300     NeedEcoUpdate := false;
    6301     DestinationMarkON := false;
     6300    NeedEcoUpdate := False;
     6301    DestinationMarkON := False;
    63026302    PaintDestination;
    6303     if result and rUnitRemoved <> 0 then
     6303    if Result and rUnitRemoved <> 0 then
    63046304      CityOptimizer_BeforeRemoveUnit(UnFocus);
    6305     IsAttack := (result = eBombarded) or (result <> eMissionDone) and
     6305    IsAttack := (Result = eBombarded) or (Result <> eMissionDone) and
    63066306      (MyMap[ToLoc] and (fUnit or fOwned) = fUnit);
    63076307    if not IsAttack then
     
    63096309      cix := MyRO.nCity - 1; { look for own city at dest location }
    63106310      while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do
    6311         dec(cix);
    6312       if (result <> eMissionDone) and (MyMap[ToLoc] and fCity <> 0) and (cix < 0)
     6311        Dec(cix);
     6312      if (Result <> eMissionDone) and (MyMap[ToLoc] and fCity <> 0) and (cix < 0)
    63136313      then
    6314         CityCaptured := true;
    6315       result := Server(sMoveUnit + DirCode, me, UnFocus, nil^);
    6316       case result of
     6314        CityCaptured := True;
     6315      Result := Server(sMoveUnit + DirCode, Me, UnFocus, nil^);
     6316      case Result of
    63176317        eHiddenUnit:
    63186318          begin
     
    63326332        rExecuted .. maxint:
    63336333          begin
    6334             if result and rUnitRemoved <> 0 then
     6334            if Result and rUnitRemoved <> 0 then
    63356335              UnFocus := -1 // unit died
    63366336            else
    63376337            begin
    6338               assert(UnFocus >= 0);
     6338              Assert(UnFocus >= 0);
    63396339              MyUn[UnFocus].Status := MyUn[UnFocus].Status and
    63406340                not(usStay or usRecover);
     
    63466346              begin // borders have moved, unrest might have changed in any city
    63476347                CityOptimizer_BeginOfTurn;
    6348                 NeedEcoUpdate := true;
     6348                NeedEcoUpdate := True;
    63496349              end
    63506350              else
     
    63566356                    if MyUn[uix].Master = UnFocus then
    63576357                      CityOptimizer_CityChange(MyUn[uix].Home);
    6358                   NeedEcoUpdate := true;
     6358                  NeedEcoUpdate := True;
    63596359                end;
    63606360                if (MyRO.Government = gDespotism) and
     
    63666366                    while (cixChanged >= 0) and
    63676367                      (MyCity[cixChanged].Loc <> FromLoc) do
    6368                       dec(cixChanged);
    6369                     assert(cixChanged >= 0);
     6368                      Dec(cixChanged);
     6369                    Assert(cixChanged >= 0);
    63706370                    if cixChanged >= 0 then
    63716371                    begin
    63726372                      CityOptimizer_CityChange(cixChanged);
    6373                       NeedEcoUpdate := true;
     6373                      NeedEcoUpdate := True;
    63746374                    end;
    63756375                  end;
     
    63796379                    while (cixChanged >= 0) and
    63806380                      (MyCity[cixChanged].Loc <> ToLoc) do
    6381                       dec(cixChanged);
    6382                     assert(cixChanged >= 0);
     6381                      Dec(cixChanged);
     6382                    Assert(cixChanged >= 0);
    63836383                    if cixChanged >= 0 then
    63846384                    begin
    63856385                      CityOptimizer_CityChange(cixChanged);
    6386                       NeedEcoUpdate := true;
     6386                      NeedEcoUpdate := True;
    63876387                    end;
    63886388                  end;
     
    63926392          end;
    63936393      else
    6394         assert(false);
     6394        Assert(False);
    63956395      end;
    63966396      SetTroopLoc(ToLoc);
     
    63986398    else
    63996399    begin { enemy unit -- attack }
    6400       if result = eBombarded then
     6400      if Result = eBombarded then
    64016401        Defender := MyRO.Territory[ToLoc]
    64026402      else
     
    64056405        if SimpleQuery(mkYesNo,Phrases.Lookup('FRCANCELQUERY_CEASEFIRE'),
    64066406        'MSG_DEFAULT')<>mrOK then
    6407         exit; }
    6408       if (Options and muNoSuicideCheck = 0) and (result and rUnitRemoved <> 0)
    6409         and (result <> eMissionDone) then
     6407        Exit; }
     6408      if (Options and muNoSuicideCheck = 0) and (Result and rUnitRemoved <> 0)
     6409        and (Result <> eMissionDone) then
    64106410      begin // suicide query
    64116411        with MyUn[UnFocus], BattleDlg.Forecast do
    64126412        begin
    6413           pAtt := me;
     6413          pAtt := Me;
    64146414          mixAtt := mix;
    64156415          HealthAtt := Health;
     
    64186418        end;
    64196419        BattleDlg.Forecast.Movement := MyUn[UnFocus].Movement;
    6420         Server(sGetBattleForecastEx, me, ToLoc, BattleDlg.Forecast);
     6420        Server(sGetBattleForecastEx, Me, ToLoc, BattleDlg.Forecast);
    64216421        BattleDlg.uix := UnFocus;
    64226422        BattleDlg.ToLoc := ToLoc;
    6423         BattleDlg.IsSuicideQuery := true;
     6423        BattleDlg.IsSuicideQuery := True;
    64246424        BattleDlg.ShowModal;
    64256425        if BattleDlg.ModalResult <> mrOK then
    6426           exit;
     6426          Exit;
    64276427      end;
    64286428
    64296429      cixChanged := -1;
    6430       if (result and rUnitRemoved <> 0) and (MyRO.Government = gDespotism) and
     6430      if (Result and rUnitRemoved <> 0) and (MyRO.Government = gDespotism) and
    64316431        (MyModel[MyUn[UnFocus].mix].Kind = mkSpecial_TownGuard) and
    64326432        (MyMap[FromLoc] and fCity <> 0) then
     
    64346434        cixChanged := MyRO.nCity - 1;
    64356435        while (cixChanged >= 0) and (MyCity[cixChanged].Loc <> FromLoc) do
    6436           dec(cixChanged);
    6437         assert(cixChanged >= 0);
    6438       end;
    6439 
    6440       for i := 0 to MyRO.nEnemyModel - 1 do
    6441         LostArmy[i] := MyRO.EnemyModel[i].Lost;
     6436          Dec(cixChanged);
     6437        Assert(cixChanged >= 0);
     6438      end;
     6439
     6440      for I := 0 to MyRO.nEnemyModel - 1 do
     6441        LostArmy[I] := MyRO.EnemyModel[I].Lost;
    64426442      OldToTile := MyMap[ToLoc];
    6443       result := Server(sMoveUnit + DirCode, me, UnFocus, nil^);
     6443      Result := Server(sMoveUnit + DirCode, Me, UnFocus, nil^);
    64446444      nLostArmy := 0;
    6445       for i := 0 to MyRO.nEnemyModel - 1 do
    6446       begin
    6447         LostArmy[i] := MyRO.EnemyModel[i].Lost - LostArmy[i];
    6448         inc(nLostArmy, LostArmy[i]);
    6449       end;
    6450       if result and rUnitRemoved <> 0 then
     6445      for I := 0 to MyRO.nEnemyModel - 1 do
     6446      begin
     6447        LostArmy[I] := MyRO.EnemyModel[I].Lost - LostArmy[I];
     6448        Inc(nLostArmy, LostArmy[I]);
     6449      end;
     6450      if Result and rUnitRemoved <> 0 then
    64516451      begin
    64526452        UnFocus := -1;
     
    64576457      begin // city was destroyed, borders have moved, unrest might have changed in any city
    64586458        CityOptimizer_BeginOfTurn;
    6459         NeedEcoUpdate := true;
     6459        NeedEcoUpdate := True;
    64606460      end
    64616461      else
     
    64646464        begin
    64656465          CityOptimizer_CityChange(cixChanged);
    6466           NeedEcoUpdate := true;
     6466          NeedEcoUpdate := True;
    64676467        end;
    6468         if (result = eWon) or (result = eBloody) or (result = eExpelled) then
     6468        if (Result = eWon) or (Result = eBloody) or (Result = eExpelled) then
    64696469        begin
    64706470          CityOptimizer_TileBecomesAvailable(ToLoc);
    6471           NeedEcoUpdate := true;
     6471          NeedEcoUpdate := True;
    64726472        end;
    64736473      end;
     
    64846484      end;
    64856485    end;
    6486     if result and rUnitRemoved <> 0 then
     6486    if Result and rUnitRemoved <> 0 then
    64876487    begin
    64886488      CityOptimizer_AfterRemoveUnit;
    64896489      ListDlg.RemoveUnit;
    6490       NeedEcoUpdate := true;
     6490      NeedEcoUpdate := True;
    64916491    end;
    64926492    if NeedEcoUpdate then
    64936493    begin
    6494       UpdateViews(true);
     6494      UpdateViews(True);
    64956495      Update;
    64966496    end;
    64976497  end;
    64986498
    6499   if result = eMissionDone then
     6499  if Result = eMissionDone then
    65006500  begin
    65016501    p1 := MyRO.Territory[ToLoc];
     
    65036503      smStealMap:
    65046504        begin
    6505           MapValid := false;
     6505          MapValid := False;
    65066506          PaintAllMaps
    65076507        end;
     
    65166516    CheckToldNoReturn(UnFocus);
    65176517
    6518   NeedRepaintPanel := false;
    6519   if result >= rExecuted then
     6518  NeedRepaintPanel := False;
     6519  if Result >= rExecuted then
    65206520  begin
    65216521    if CityCaptured and (MyMap[ToLoc] and fCity = 0) then
    65226522    begin // city destroyed
    6523       for i := 0 to nWonder - 1 do { tell about destroyed wonders }
    6524         if (MyRO.Wonder[i].CityID = WonderDestroyed) and (MyData.ToldWonders[i].CityID <> WonderDestroyed)
     6523      for I := 0 to nWonder - 1 do { tell about destroyed wonders }
     6524        if (MyRO.Wonder[I].CityID = WonderDestroyed) and (MyData.ToldWonders[I].CityID <> WonderDestroyed)
    65256525        then
    65266526          with MessgExDlg do
    65276527          begin
    65286528            if WondersDlg.Visible then
    6529               WondersDlg.SmartUpdateContent(false);
     6529              WondersDlg.SmartUpdateContent(False);
    65306530            OpenSound := 'WONDER_DESTROYED';
    65316531            MessgText := Format(Phrases.Lookup('WONDERDEST'),
    6532               [Phrases.Lookup('IMPROVEMENTS', i)]);
     6532              [Phrases.Lookup('IMPROVEMENTS', I)]);
    65336533            Kind := mkOkHelp;
    65346534            HelpKind := hkImp;
    6535             HelpNo := i;
     6535            HelpNo := I;
    65366536            IconKind := mikImp;
    6537             IconIndex := i;
     6537            IconIndex := I;
    65386538            ShowModal;
    6539             MyData.ToldWonders[i] := MyRO.Wonder[i];
     6539            MyData.ToldWonders[I] := MyRO.Wonder[I];
    65406540          end;
    65416541    end;
     
    65436543    begin // city captured
    65446544      ListDlg.AddCity;
    6545       for i := 0 to nWonder - 1 do { tell about capture of wonders }
    6546         if MyRO.City[MyRO.nCity - 1].Built[i] > 0 then
     6545      for I := 0 to nWonder - 1 do { tell about capture of wonders }
     6546        if MyRO.City[MyRO.nCity - 1].Built[I] > 0 then
    65476547          with MessgExDlg do
    65486548          begin
    65496549            if WondersDlg.Visible then
    6550               WondersDlg.SmartUpdateContent(false);
     6550              WondersDlg.SmartUpdateContent(False);
    65516551            OpenSound := 'WONDER_CAPTURED';
    6552             MessgText := Format(Tribe[me].TPhrase('WONDERCAPTOWN'),
    6553               [Phrases.Lookup('IMPROVEMENTS', i)]);
     6552            MessgText := Format(Tribe[Me].TPhrase('WONDERCAPTOWN'),
     6553              [Phrases.Lookup('IMPROVEMENTS', I)]);
    65546554            Kind := mkOkHelp;
    65556555            HelpKind := hkImp;
    6556             HelpNo := i;
     6556            HelpNo := I;
    65576557            IconKind := mikImp;
    6558             IconIndex := i;
     6558            IconIndex := I;
    65596559            ShowModal;
    6560             MyData.ToldWonders[i] := MyRO.Wonder[i];
     6560            MyData.ToldWonders[I] := MyRO.Wonder[I];
    65616561          end;
    65626562
     
    65646564      begin { Temple of Zeus -- choose advance to steal }
    65656565        ModalSelectDlg.ShowNewContent(wmModal, kStealTech);
    6566         Server(sStealTech, me, ModalSelectDlg.result, nil^);
     6566        Server(sStealTech, Me, ModalSelectDlg.Result, nil^);
    65676567      end;
    65686568      TellNewModels;
     
    65706570      cix := MyRO.nCity - 1;
    65716571      while (cix >= 0) and (MyCity[cix].Loc <> ToLoc) do
    6572         dec(cix);
    6573       assert(cix >= 0);
     6572        Dec(cix);
     6573      Assert(cix >= 0);
    65746574      MyCity[cix].Status := MyCity[cix].Status and not csResourceWeightsMask or
    65756575        (3 shl 4);
    65766576      // captured city, set to maximum growth
    65776577      NewTiles := 1 shl 13; { exploit central tile only }
    6578       Server(sSetCityTiles, me, cix, NewTiles);
     6578      Server(sSetCityTiles, Me, cix, NewTiles);
    65796579    end
    65806580    else
    6581       NeedRepaintPanel := true;
     6581      NeedRepaintPanel := True;
    65826582  end;
    65836583  TellNewContacts;
     
    65936593  if Options and (muAutoNoWait or muAutoNext) <> 0 then
    65946594  begin
    6595     if (UnFocus >= 0) and ((result = eNoTime_Move) or UnitExhausted(UnFocus) or
     6595    if (UnFocus >= 0) and ((Result = eNoTime_Move) or UnitExhausted(UnFocus) or
    65966596      (MyUn[UnFocus].Master >= 0) or (MyModel[MyUn[UnFocus].mix].Domain = dAir)
    65976597      and ((MyMap[MyUn[UnFocus].Loc] and fCity <> 0)
     
    66076607        end
    66086608        else
    6609           NextUnit(UnStartLoc, true);
     6609          NextUnit(UnStartLoc, True);
    66106610    end
    66116611    else if (UnFocus < 0) and (Options and muAutoNext <> 0) then
    6612       NextUnit(UnStartLoc, result <> eMissionDone);
     6612      NextUnit(UnStartLoc, Result <> eMissionDone);
    66136613  end;
    66146614
     
    66186618    else
    66196619    begin
    6620       assert(result <> eMissionDone);
     6620      Assert(Result <> eMissionDone);
    66216621      CheckTerrainBtnVisible;
    66226622      FocusOnLoc(ToLoc, flRepaintPanel or flImmUpdate);
    66236623    end;
    66246624
    6625   if (result >= rExecuted) and CityCaptured and (MyMap[ToLoc] and fCity <> 0)
     6625  if (Result >= rExecuted) and CityCaptured and (MyMap[ToLoc] and fCity <> 0)
    66266626  then
    66276627    ZoomToCity(ToLoc, UnFocus < 0, chCaptured); // show captured city
     
    66296629
    66306630procedure TMainScreen.MoveOnScreen(ShowMove: TShowMove;
    6631   Step0, Step1, nStep: integer; Restore: boolean = true);
     6631  Step0, Step1, nStep: Integer; Restore: Boolean = True);
    66326632var
    66336633  ToLoc, xFromLoc, yFromLoc, xToLoc, yToLoc, xFrom, yFrom, xTo, yTo, xMin, yMin,
    6634     xRange, yRange, xw1, Step, xMoving, yMoving, SliceCount: integer;
     6634    xRange, yRange, xw1, Step, xMoving, yMoving, SliceCount: Integer;
    66356635  UnitInfo: TUnitInfo;
    66366636  Ticks0, Ticks: TDateTime;
    66376637begin
    6638   Timer1.Enabled := false;
     6638  Timer1.Enabled := False;
    66396639  Ticks0 := NowPrecise;
    66406640  with ShowMove do
     
    66456645    UnitInfo.Job := jNone;
    66466646    UnitInfo.Flags := Flags;
    6647     if Owner <> me then
     6647    if Owner <> Me then
    66486648      UnitInfo.emix := emix;
    66496649
     
    66646664        * xxt - MapWidth) < abs(((xFromLoc - xw1) * 2 + yFromLoc and 1 + 1) * xxt
    66656665        * 2 + dx * xxt - MapWidth) do
    6666         dec(xw1, G.lx);
     6666        Dec(xw1, G.lx);
    66676667
    66686668      xTo := (xToLoc - xw1) * (xxt * 2) + yToLoc and 1 * xxt + (xxt - xxu);
     
    66846684        yRange := yFrom - yTo;
    66856685      end;
    6686       inc(xRange, xxt * 2);
    6687       inc(yRange, yyt * 3);
     6686      Inc(xRange, xxt * 2);
     6687      Inc(yRange, yyt * 3);
    66886688    end;
    66896689
     
    66946694    begin
    66956695      BitBltCanvas(Buffer.Canvas, 0, 0, xRange, yRange,
    6696         offscreen.Canvas, xMin, yMin);
     6696        Offscreen.Canvas, xMin, yMin);
    66976697      if Step1 <> Step0 then
    66986698      begin
     
    67236723          < MoveTime) then
    67246724        begin
    6725           if not idle or (GameMode = cMovie) then
     6725          if not Idle or (GameMode = cMovie) then
    67266726            Application.ProcessMessages;
    67276727          Sleep(1);
    6728           inc(SliceCount)
     6728          Inc(SliceCount)
    67296729        end;
    67306730        Ticks := NowPrecise;
     
    67356735  if Restore then
    67366736  begin
    6737     BitBltCanvas(Buffer.Canvas, 0, 0, xRange, yRange, offscreen.Canvas, xMin, yMin);
     6737    BitBltCanvas(Buffer.Canvas, 0, 0, xRange, yRange, Offscreen.Canvas, xMin, yMin);
    67386738    PaintBufferToScreen(xMin, yMin, xRange, yRange);
    67396739  end;
    67406740  BlinkTime := -1;
    6741   Timer1.Enabled := true;
    6742 end;
    6743 
    6744 procedure TMainScreen.MoveToLoc(Loc: integer; CheckSuicide: boolean);
     6741  Timer1.Enabled := True;
     6742end;
     6743
     6744procedure TMainScreen.MoveToLoc(Loc: Integer; CheckSuicide: Boolean);
    67456745// path finder: move focused unit to loc, start multi-turn goto if too far
    67466746var
    6747   uix, i, MoveOptions, NextLoc, MoveResult: integer;
     6747  uix, I, MoveOptions, NextLoc, MoveResult: Integer;
    67486748  MoveAdviceData: TMoveAdviceData;
    67496749  StopReason: (None, Arrived, Dead, NoTime, EnemySpotted, MoveError);
    67506750begin
    67516751  if MyUn[UnFocus].Job > jNone then
    6752     Server(sStartJob + jNone shl 4, me, UnFocus, nil^);
     6752    Server(sStartJob + jNone shl 4, Me, UnFocus, nil^);
    67536753  if GetMoveAdvice(UnFocus, Loc, MoveAdviceData) >= rExecuted then
    67546754  begin
     
    67566756    StopReason := None;
    67576757    repeat
    6758       for i := 0 to MoveAdviceData.nStep - 1 do
    6759       begin
    6760         if i = MoveAdviceData.nStep - 1 then
     6758      for I := 0 to MoveAdviceData.nStep - 1 do
     6759      begin
     6760        if I = MoveAdviceData.nStep - 1 then
    67616761          MoveOptions := muAutoNext
    67626762        else
    67636763          MoveOptions := 0;
    6764         NextLoc := dLoc(MyUn[uix].Loc, MoveAdviceData.dx[i],
    6765           MoveAdviceData.dy[i]);
     6764        NextLoc := dLoc(MyUn[uix].Loc, MoveAdviceData.dx[I],
     6765          MoveAdviceData.dy[I]);
    67666766        if (NextLoc = Loc) or (Loc = maNextCity) and
    67676767          (MyMap[NextLoc] and fCity <> 0) then
     
    67696769        if not CheckSuicide and (NextLoc = Loc) then
    67706770          MoveOptions := MoveOptions or muNoSuicideCheck;
    6771         MoveResult := MoveUnit(MoveAdviceData.dx[i], MoveAdviceData.dy[i],
     6771        MoveResult := MoveUnit(MoveAdviceData.dx[I], MoveAdviceData.dy[I],
    67726772          MoveOptions);
    67736773        if MoveResult < rExecuted then
     
    67816781      end;
    67826782      if (StopReason = None) and ((MoveAdviceData.nStep < 25) or
    6783         (MyRO.Wonder[woShinkansen].EffectiveOwner <> me)) then
     6783        (MyRO.Wonder[woShinkansen].EffectiveOwner <> Me)) then
    67846784        StopReason := NoTime;
    67856785      if StopReason <> None then
     
    67876787      if GetMoveAdvice(UnFocus, Loc, MoveAdviceData) < rExecuted then
    67886788      begin
    6789         assert(false);
     6789        Assert(False);
    67906790        Break;
    67916791      end;
    6792     until false;
     6792    until False;
    67936793
    67946794    case StopReason of
    67956795      None:
    6796         assert(false);
     6796        Assert(False);
    67976797      Arrived:
    67986798        MyUn[uix].Status := MyUn[uix].Status and ($FFFF - usGoto);
    67996799      Dead:
    68006800        if UnFocus < 0 then
    6801           NextUnit(UnStartLoc, false);
     6801          NextUnit(UnStartLoc, False);
    68026802    else
    68036803      begin // multi-turn goto
     
    68126812        begin
    68136813          MyUn[uix].Status := MyUn[uix].Status and not usWaiting;
    6814           NextUnit(UnStartLoc, true);
     6814          NextUnit(UnStartLoc, True);
    68156815        end;
    68166816      end;
     
    68206820
    68216821procedure TMainScreen.PanelBoxMouseDown(Sender: TObject; Button: TMouseButton;
    6822   Shift: TShiftState; x, y: integer);
     6822  Shift: TShiftState; X, Y: Integer);
    68236823var
    6824   i, xMouse, MouseLoc, p1: integer;
     6824  I, xMouse, MouseLoc, p1: Integer;
    68256825begin
    68266826  if GameMode = cMovie then
    6827     exit;
     6827    Exit;
    68286828
    68296829  if Button = mbLeft then
    68306830  begin
    6831     if (x >= xMini + 2) and (y >= yMini + 2) and (x < xMini + 2 + 2 * G.lx) and
    6832       (y < yMini + 2 + G.ly) then
     6831    if (X >= xMini + 2) and (Y >= yMini + 2) and (X < xMini + 2 + 2 * G.lx) and
     6832      (Y < yMini + 2 + G.ly) then
    68336833      if ssShift in Shift then
    68346834      begin
    68356835        with MainMap do
    6836           xMouse := (xwMini + (x - (xMini + 2) + MapWidth div (xxt * 2) + G.lx)
     6836          xMouse := (xwMini + (X - (xMini + 2) + MapWidth div (xxt * 2) + G.lx)
    68376837            div 2) mod G.lx;
    6838         MouseLoc := xMouse + G.lx * (y - (yMini + 2));
     6838        MouseLoc := xMouse + G.lx * (Y - (yMini + 2));
    68396839        if MyMap[MouseLoc] and fTerrain <> fUNKNOWN then
    68406840        begin
    68416841          p1 := MyRO.Territory[MouseLoc];
    6842           if (p1 = me) or (p1 >= 0) and (MyRO.Treaty[p1] >= trNone) then
     6842          if (p1 = Me) or (p1 >= 0) and (MyRO.Treaty[p1] >= trNone) then
    68436843            NatStatDlg.ShowNewContent(wmPersistent, p1);
    68446844        end;
     
    68506850        if UnitStatDlg.Visible then
    68516851          UnitStatDlg.Close;
    6852         Tracking := true;
    6853         PanelBoxMouseMove(Sender, Shift + [ssLeft], x, y);
     6852        Tracking := True;
     6853        PanelBoxMouseMove(Sender, Shift + [ssLeft], X, Y);
    68546854      end
    6855     else if (ClientMode <> cEditMap) and (x >= ClientWidth - xPalace) and
    6856       (y >= yPalace) and (x < ClientWidth - xPalace + xSizeBig) and
    6857       (y < yPalace + ySizeBig) then
     6855    else if (ClientMode <> cEditMap) and (X >= ClientWidth - xPalace) and
     6856      (Y >= yPalace) and (X < ClientWidth - xPalace + xSizeBig) and
     6857      (Y < yPalace + ySizeBig) then
    68586858    begin
    68596859      InitPopup(StatPopup);
     
    68666866          GetSystemMetrics(SM_CYCAPTION) + 3)
    68676867    end
    6868     (* else if (x>=xAdvisor-3) and (y>=yAdvisor-3)
    6869       and (x<xAdvisor+16+3) and (y<yAdvisor+16+3) and HaveStrategyAdvice then
     6868    (* else if (X>=xAdvisor-3) and (Y>=yAdvisor-3)
     6869      and (X<xAdvisor+16+3) and (Y<yAdvisor+16+3) and HaveStrategyAdvice then
    68706870      AdviceBtnClick *)
    6871     else if (x >= xTroop + 1) and (y >= yTroop + 1) and
    6872       (x < xTroop + TrRow * TrPitch) and (y <= yTroop + 55) then
    6873     begin
    6874       i := (x - xTroop - 1) div TrPitch;
    6875       if trix[i] >= 0 then
     6871    else if (X >= xTroop + 1) and (Y >= yTroop + 1) and
     6872      (X < xTroop + TrRow * TrPitch) and (Y <= yTroop + 55) then
     6873    begin
     6874      I := (X - xTroop - 1) div TrPitch;
     6875      if trix[I] >= 0 then
    68766876        if ClientMode = cEditMap then
    68776877        begin
    6878           BrushType := trix[i];
     6878          BrushType := trix[I];
    68796879          PanelPaint
    68806880        end
     
    68846884            if ssShift in Shift then
    68856885              UnitStatDlg.ShowNewContent_OwnModel(wmPersistent,
    6886                 MyUn[trix[i]].mix)
    6887             else if not supervising and (ClientMode < scContact) and
    6888               (x - xTroop - 1 - i * TrPitch >= 60 - 20) and (y >= yTroop + 35)
    6889               and ((MyUn[trix[i]].Job > jNone) or (MyUn[trix[i]].Status and
     6886                MyUn[trix[I]].mix)
     6887            else if not Supervising and (ClientMode < scContact) and
     6888              (X - xTroop - 1 - I * TrPitch >= 60 - 20) and (Y >= yTroop + 35)
     6889              and ((MyUn[trix[I]].Job > jNone) or (MyUn[trix[I]].Status and
    68906890              (usStay or usRecover or usGoto) <> 0)) then
    68916891            begin // wake up
    6892               MyUn[trix[i]].Status := MyUn[trix[i]].Status and
     6892              MyUn[trix[I]].Status := MyUn[trix[I]].Status and
    68936893                ($FFFF - usStay - usRecover - usGoto - usEnhance) or usWaiting;
    6894               if MyUn[trix[i]].Job > jNone then
    6895                 Server(sStartJob + jNone shl 4, me, trix[i], nil^);
     6894              if MyUn[trix[I]].Job > jNone then
     6895                Server(sStartJob + jNone shl 4, Me, trix[I], nil^);
    68966896              if (UnFocus < 0) and not CityDlg.Visible then
    68976897              begin
    6898                 SetUnFocus(trix[i]);
    6899                 SetTroopLoc(MyUn[trix[i]].Loc);
     6898                SetUnFocus(trix[I]);
     6899                SetTroopLoc(MyUn[trix[I]].Loc);
    69006900                FocusOnLoc(TroopLoc, flRepaintPanel)
    69016901              end
     
    69036903              begin
    69046904                if CityDlg.Visible and (CityDlg.RestoreUnFocus < 0) then
    6905                   CityDlg.RestoreUnFocus := trix[i];
     6905                  CityDlg.RestoreUnFocus := trix[I];
    69066906                PanelPaint;
    69076907              end
     
    69096909            else if (ClientMode < scContact) then
    69106910            begin
    6911               if supervising then
    6912                 UnitStatDlg.ShowNewContent_OwnUnit(wmPersistent, trix[i])
     6911              if Supervising then
     6912                UnitStatDlg.ShowNewContent_OwnUnit(wmPersistent, trix[I])
    69136913              else if CityDlg.Visible then
    69146914              begin
     
    69166916                CityDlg.Close;
    69176917                SumCities(TaxSum, ScienceSum);
    6918                 SetUnFocus(trix[i]);
     6918                SetUnFocus(trix[I]);
    69196919              end
    69206920              else
    69216921              begin
    6922                 DestinationMarkON := false;
     6922                DestinationMarkON := False;
    69236923                PaintDestination;
    6924                 UnFocus := trix[i];
     6924                UnFocus := trix[I];
    69256925                UnStartLoc := TroopLoc;
    69266926                BlinkTime := 0;
    6927                 BlinkON := false;
     6927                BlinkON := False;
    69286928                PaintLoc(TroopLoc);
    69296929              end;
    69306930              if UnFocus >= 0 then
    69316931              begin
    6932                 UnitInfoBtn.Visible := true;
    6933                 UnitBtn.Visible := true;
    6934                 TurnComplete := false;
     6932                UnitInfoBtn.Visible := True;
     6933                UnitBtn.Visible := True;
     6934                TurnComplete := False;
    69356935                EOT.ButtonIndex := eotGray;
    69366936              end;
     
    69396939            end;
    69406940          end
    6941           else if Server(sGetUnits, me, TroopLoc, TrCnt) >= rExecuted then
     6941          else if Server(sGetUnits, Me, TroopLoc, TrCnt) >= rExecuted then
    69426942            if ssShift in Shift then
    69436943              UnitStatDlg.ShowNewContent_EnemyModel(wmPersistent,
    6944                 MyRO.EnemyUn[MyRO.nEnemyUn + trix[i]].emix) // model info
     6944                MyRO.EnemyUn[MyRO.nEnemyUn + trix[I]].emix) // model info
    69456945            else
    69466946              UnitStatDlg.ShowNewContent_EnemyUnit(wmPersistent,
    6947                 MyRO.nEnemyUn + trix[i]); // unit info
    6948     end;
    6949   end;
    6950 end;
    6951 
    6952 procedure TMainScreen.SetTroopLoc(Loc: integer);
     6947                MyRO.nEnemyUn + trix[I]); // unit info
     6948    end;
     6949  end;
     6950end;
     6951
     6952procedure TMainScreen.SetTroopLoc(Loc: Integer);
    69536953var
    6954   trixFocus, uix, uixDefender: integer;
    6955   Prio: boolean;
     6954  trixFocus, uix, uixDefender: Integer;
     6955  Prio: Boolean;
    69566956begin
    69576957  TroopLoc := Loc;
     
    69656965    if MyMap[Loc] and fOwned <> 0 then
    69666966    begin // count own units here
    6967       Server(sGetDefender, me, TroopLoc, uixDefender);
    6968       for Prio := true downto false do
     6967      Server(sGetDefender, Me, TroopLoc, uixDefender);
     6968      for Prio := True downto False do
    69696969        for uix := 0 to MyRO.nUn - 1 do
    69706970          if ((uix = uixDefender) = Prio) and (MyUn[uix].Loc = Loc) then
     
    69726972            if uix = UnFocus then
    69736973              trixFocus := TrCnt;
    6974             inc(TrCnt);
     6974            Inc(TrCnt);
    69756975          end;
    69766976    end
    69776977    else // count enemy units here
    6978       Server(sGetUnits, me, Loc, TrCnt);
     6978      Server(sGetUnits, Me, Loc, TrCnt);
    69796979  if TrCnt = 0 then
    69806980    sb.Init(0, 1)
     
    69876987end;
    69886988
    6989 (* procedure TMainScreen.ShowMoveHint(ToLoc: integer; Force: boolean = false);
     6989(* procedure TMainScreen.ShowMoveHint(ToLoc: Integer; Force: Boolean = False);
    69906990  var
    6991   Step,Loc,x0,y0,xs,ys: integer;
     6991  Step,Loc,x0,y0,xs,ys: Integer;
    69926992  Info: string;
    69936993  InfoSize: TSize;
     
    70027002  MoveAdvice.MoreTurns:=0;
    70037003  MoveAdvice.MaxHostile_MovementLeft:=MyUn[UnFocus].Health-50;
    7004   if Server(sGetMoveAdvice,me,UnFocus,MoveAdvice)<rExecuted then
     7004  if Server(sGetMoveAdvice,Me,UnFocus,MoveAdvice)<rExecuted then
    70057005  ToLoc:=-1
    70067006  end;
    7007   if (ToLoc=MoveHintToLoc) and not Force then exit;
     7007  if (ToLoc=MoveHintToLoc) and not Force then Exit;
    70087008  if (ToLoc<>MoveHintToLoc) and (MoveHintToLoc>=0) then
    70097009  begin invalidate; update end; // clear old hint from screen
    70107010  MoveHintToLoc:=ToLoc;
    7011   if ToLoc<0 then exit;
    7012 
    7013   with canvas do
     7011  if ToLoc<0 then Exit;
     7012
     7013  with Canvas do
    70147014  begin
    70157015  Pen.Color:=$80C0FF;
     
    70227022  xs:=(x0-xw)*66+y0 and 1*33-G.lx*66;
    70237023  while abs(2*(xs+G.lx*66)-MapWidth)<abs(2*xs-MapWidth) do
    7024   inc(xs,G.lx*66);
     7024  Inc(xs,G.lx*66);
    70257025  ys:=(y0-yw)*16;
    70267026  if Step=0 then moveto(xs+33,ys+16)
     
    70307030  end;
    70317031  Brush.Color:=$80C0FF;
    7032   Info:=' '+inttostr(88)+' ';
     7032  Info:=' '+IntToStr(88)+' ';
    70337033  InfoSize:=TextExtent(Info);
    70347034  TextOut(xs+33-InfoSize.cx div 2, ys+16-InfoSize.cy div 2, Info);
     
    70377037  end; *)
    70387038
    7039 procedure TMainScreen.SetDebugMap(p: integer);
    7040 begin
    7041   MainMap.pDebugMap := p;
     7039procedure TMainScreen.SetDebugMap(P: Integer);
     7040begin
     7041  MainMap.pDebugMap := P;
    70427042  MapOptions := MapOptions - [moLocCodes];
    7043   mLocCodes.Checked := false;
    7044   MapValid := false;
     7043  mLocCodes.Checked := False;
     7044  MapValid := False;
    70457045  MainOffscreenPaint;
    70467046end;
    70477047
    7048 procedure TMainScreen.SetViewpoint(p: integer);
     7048procedure TMainScreen.SetViewpoint(P: Integer);
    70497049var
    7050   i: Integer;
    7051 begin
    7052   if supervising and (G.RO[0].Turn > 0) and
    7053     ((p = 0) or (1 shl p and G.RO[0].Alive <> 0)) then
     7050  I: Integer;
     7051begin
     7052  if Supervising and (G.RO[0].Turn > 0) and
     7053    ((P = 0) or (1 shl P and G.RO[0].Alive <> 0)) then
    70547054  begin
    70557055    ApplyToVisibleForms(faClose);
    7056     ItsMeAgain(p);
     7056    ItsMeAgain(P);
    70577057    SumCities(TaxSum, ScienceSum);
    7058     for i := 0 to MyRO.nModel - 1 do
    7059       if not Assigned(Tribe[me].ModelPicture[i].HGr) then
    7060         InitMyModel(i, True);
     7058    for I := 0 to MyRO.nModel - 1 do
     7059      if not Assigned(Tribe[Me].ModelPicture[I].HGr) then
     7060        InitMyModel(I, True);
    70617061
    70627062    SetTroopLoc(-1);
     
    71467146end;
    71477147
    7148 procedure TMainScreen.FormKeyDown(Sender: TObject; var Key: word;
     7148procedure TMainScreen.FormKeyDown(Sender: TObject; var Key: Word;
    71497149  Shift: TShiftState);
    71507150
     
    71567156  end;
    71577157
    7158   procedure SetViewpointMe(p: Integer);
    7159   begin
    7160     if p = me then SetViewpoint(p)
    7161       else SetViewpoint(p);
     7158  procedure SetViewpointMe(P: Integer);
     7159  begin
     7160    if P = Me then SetViewpoint(P)
     7161      else SetViewpoint(P);
    71627162  end;
    71637163
     
    71957195         'A':
    71967196          begin // auto symmetry
    7197           Server($7F0,me,0,nil^);
    7198           MapValid:=false;
     7197          Server($7F0,Me,0,nil^);
     7198          MapValid:=False;
    71997199          PaintAll;
    72007200          end;
     
    72037203          dy:=0;
    72047204          for dx:=G.lx to G.lx*(G.ly-1)-1 do
    7205           if MyMap[dx] and fTerrain>=fGrass then inc(dy);
     7205          if MyMap[dx] and fTerrain>=fGrass then Inc(dy);
    72067206          dy:=dy
    72077207          end;
     
    73307330function TMainScreen.DoJob(j0: Integer): Integer;
    73317331var
    7332   Loc0, Movement0: integer;
     7332  Loc0, Movement0: Integer;
    73337333begin
    73347334  with MyUn[UnFocus] do
    73357335  begin
    7336     DestinationMarkON := false;
     7336    DestinationMarkON := False;
    73377337    PaintDestination;
    73387338    Loc0 := Loc;
    73397339    Movement0 := Movement;
    73407340    if j0 < 0 then
    7341       result := ProcessEnhancement(UnFocus, MyData.EnhancementJobs)
     7341      Result := ProcessEnhancement(UnFocus, MyData.EnhancementJobs)
    73427342      // terrain enhancement
    73437343    else
    7344       result := Server(sStartJob + j0 shl 4, me, UnFocus, nil^);
    7345     if result >= rExecuted then
    7346     begin
    7347       if result = eDied then
     7344      Result := Server(sStartJob + j0 shl 4, Me, UnFocus, nil^);
     7345    if Result >= rExecuted then
     7346    begin
     7347      if Result = eDied then
    73487348        UnFocus := -1;
    73497349      PaintLoc(Loc0);
    73507350      if UnFocus >= 0 then
    73517351      begin
    7352         if (j0 < 0) and (result <> eJobDone) then
     7352        if (j0 < 0) and (Result <> eJobDone) then
    73537353          // multi-turn terrain enhancement
    73547354          Status := Status and ($FFFF - usStay - usRecover - usGoto) or
     
    73607360        begin
    73617361          Status := Status and not usWaiting;
    7362           NextUnit(UnStartLoc, true);
     7362          NextUnit(UnStartLoc, True);
    73637363        end
    73647364        else
     
    73667366      end
    73677367      else
    7368         NextUnit(UnStartLoc, true);
    7369     end;
    7370   end;
    7371   case result of
     7368        NextUnit(UnStartLoc, True);
     7369    end;
     7370  end;
     7371  case Result of
    73727372    eNoBridgeBuilding:
    73737373      SoundMessage(Phrases.Lookup('NOBB'), 'INVALID');
     
    73787378        'NOMOVE_TREATY');
    73797379  else
    7380     if result < rExecuted then
     7380    if Result < rExecuted then
    73817381      Play('INVALID');
    73827382  end;
     
    73907390  with TUn(MyUn[UnFocus]) do begin
    73917391    if (Sender = mUtilize) and
    7392       not(Server(sRemoveUnit - sExecute, me, UnFocus, nil^) = eUtilized) then
     7392      not(Server(sRemoveUnit - sExecute, Me, UnFocus, nil^) = eUtilized) then
    73937393    begin
    73947394      SimpleMessage(Phrases2.Lookup('SHIP_UTILIZE'));
    73957395      // freight for colony ship is the only case in which the command is
    73967396      // available to player though not valid
    7397       exit;
     7397      Exit;
    73987398    end;
    73997399    if (Sender = mUtilize) and (Health < 100) then
    74007400      if SimpleQuery(mkYesNo, Phrases.Lookup('DAMAGED_UTILIZE'), '') <> mrOK
    74017401      then
    7402         exit;
     7402        Exit;
    74037403    Loc0 := Loc;
    74047404    CityOptimizer_BeforeRemoveUnit(UnFocus);
    7405     if Server(sRemoveUnit, me, UnFocus, nil^) = eUtilized then
     7405    if Server(sRemoveUnit, Me, UnFocus, nil^) = eUtilized then
    74067406      Play('CITY_UTILIZE')
    74077407    else
     
    74097409    CityOptimizer_AfterRemoveUnit;
    74107410    SetTroopLoc(Loc0);
    7411     UpdateViews(true);
    7412     DestinationMarkON := false;
     7411    UpdateViews(True);
     7412    DestinationMarkON := False;
    74137413    PaintDestination;
    74147414    UnFocus := -1;
    74157415    PaintLoc(Loc0);
    7416     NextUnit(UnStartLoc, true);
     7416    NextUnit(UnStartLoc, True);
    74177417  end;
    74187418end;
     
    74207420procedure TMainScreen.InitPopup(Popup: TPopupMenu);
    74217421var
    7422   i, p1, Tile, Test: integer;
    7423   NoSuper, extended, Multi, NeedSep, HaveCities: boolean;
    7424   LastSep, m: TMenuItem;
     7422  I, p1, Tile, Test: Integer;
     7423  NoSuper, Extended, Multi, NeedSep, HaveCities: Boolean;
     7424  LastSep, M: TMenuItem;
    74257425  mox: ^TModel;
    74267426begin
    7427   NoSuper := not supervising and (1 shl me and MyRO.Alive <> 0);
    7428   HaveCities := false;
    7429   for i := 0 to MyRO.nCity - 1 do
    7430     if MyCity[i].Loc >= 0 then
    7431     begin
    7432       HaveCities := true;
     7427  NoSuper := not Supervising and (1 shl Me and MyRO.Alive <> 0);
     7428  HaveCities := False;
     7429  for I := 0 to MyRO.nCity - 1 do
     7430    if MyCity[I].Loc >= 0 then
     7431    begin
     7432      HaveCities := True;
    74337433      Break;
    74347434    end;
     
    74367436  begin
    74377437    mTechTree.Visible := ClientMode <> cEditMap;
    7438     mResign.Enabled := supervising or (me = 0) and (ClientMode < scContact);
     7438    mResign.Enabled := Supervising or (Me = 0) and (ClientMode < scContact);
    74397439    mRandomMap.Visible := (ClientMode = cEditMap) and
    7440       (Server(sMapGeneratorRequest, me, 0, nil^) = eOK);
     7440      (Server(sMapGeneratorRequest, Me, 0, nil^) = eOK);
    74417441    mOptions.Visible := ClientMode <> cEditMap;
    74427442    mManip.Visible := ClientMode <> cEditMap;
     
    74527452      case SoundMode of
    74537453        smOff:
    7454           mSoundOff.Checked := true;
     7454          mSoundOff.Checked := True;
    74557455        smOn:
    7456           mSoundOn.Checked := true;
     7456          mSoundOn.Checked := True;
    74577457        smOnAlt:
    7458           mSoundOnAlt.Checked := true;
    7459       end;
    7460 
    7461       for i := 0 to nTestFlags - 1 do
    7462         mManip[i].Checked := MyRO.TestFlags and (1 shl i) <> 0;
    7463       mManip.Enabled := supervising or (me = 0);
    7464 
    7465       Multi := false;
     7458          mSoundOnAlt.Checked := True;
     7459      end;
     7460
     7461      for I := 0 to nTestFlags - 1 do
     7462        mManip[I].Checked := MyRO.TestFlags and (1 shl I) <> 0;
     7463      mManip.Enabled := Supervising or (Me = 0);
     7464
     7465      Multi := False;
    74667466      for p1 := 1 to nPl - 1 do
    74677467        if G.RO[p1] <> nil then
    7468           Multi := true;
     7468          Multi := True;
    74697469      mEnemyMovement.Visible := not Multi;
    74707470    end;
     
    74727472    if NoSuper and (ClientMode < scContact) then
    74737473    begin
    7474       mCityTypes.Enabled := false;
     7474      mCityTypes.Enabled := False;
    74757475      // check if city types already usefull:
    74767476      if MyRO.nCity > 0 then
    7477         for i := nWonder to nImp - 1 do
    7478           if (i <> imTrGoods) and (Imp[i].Kind = ikCommon) and
    7479             (Imp[i].Preq <> preNA) and
    7480             ((Imp[i].Preq = preNone) or (MyRO.Tech[Imp[i].Preq] >= tsApplicable))
     7477        for I := nWonder to nImp - 1 do
     7478          if (I <> imTrGoods) and (Imp[I].Kind = ikCommon) and
     7479            (Imp[I].Preq <> preNA) and
     7480            ((Imp[I].Preq = preNone) or (MyRO.Tech[Imp[I].Preq] >= tsApplicable))
    74817481          then
    74827482          begin
    7483             mCityTypes.Enabled := true;
     7483            mCityTypes.Enabled := True;
    74847484            Break
    74857485          end;
    74867486    end;
    7487     mViewpoint.Visible := (ClientMode <> cEditMap) and supervising;
     7487    mViewpoint.Visible := (ClientMode <> cEditMap) and Supervising;
    74887488    mViewpoint.Enabled := G.RO[0].Turn > 0;
    7489     if supervising then
     7489    if Supervising then
    74907490    begin
    74917491      EmptyMenu(mViewpoint);
     
    74937493        if (p1 = 0) or (1 shl p1 and G.RO[0].Alive <> 0) then
    74947494        begin
    7495           m := TMenuItem.Create(mViewpoint);
     7495          M := TMenuItem.Create(mViewpoint);
    74967496          if p1 = 0 then
    7497             m.Caption := Phrases.Lookup('SUPER')
     7497            M.Caption := Phrases.Lookup('SUPER')
    74987498          else
    7499             m.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));
    7500           m.Tag := p1;
    7501           m.OnClick := ViewpointClick;
     7499            M.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));
     7500          M.Tag := p1;
     7501          M.OnClick := ViewpointClick;
    75027502          if p1 < 10 then
    7503             m.ShortCut := ShortCut(48 + p1, [ssCtrl]);
    7504           m.RadioItem := true;
    7505           if p1 = me then
    7506             m.Checked := true;
    7507           mViewpoint.Add(m);
     7503            M.ShortCut := ShortCut(48 + p1, [ssCtrl]);
     7504          M.RadioItem := True;
     7505          if p1 = Me then
     7506            M.Checked := True;
     7507          mViewpoint.Add(M);
    75087508        end
    75097509    end;
    7510     mDebugMap.Visible := (ClientMode <> cEditMap) and supervising;
    7511     if supervising then
     7510    mDebugMap.Visible := (ClientMode <> cEditMap) and Supervising;
     7511    if Supervising then
    75127512    begin
    75137513      EmptyMenu(mDebugMap);
     
    75157515        if (p1 = 0) or (1 shl p1 and G.RO[0].Alive <> 0) then
    75167516        begin
    7517           m := TMenuItem.Create(mDebugMap);
     7517          M := TMenuItem.Create(mDebugMap);
    75187518          if p1 = 0 then
    7519             m.Caption := Phrases2.Lookup('MENU_DEBUGMAPOFF')
     7519            M.Caption := Phrases2.Lookup('MENU_DEBUGMAPOFF')
    75207520          else
    7521             m.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));
     7521            M.Caption := Tribe[p1].TString(Phrases2.Lookup('BELONG'));
    75227522          if p1 = 0 then
    7523             m.Tag := -1
     7523            M.Tag := -1
    75247524          else
    7525             m.Tag := p1;
    7526           m.OnClick := DebugMapClick;
     7525            M.Tag := p1;
     7526          M.OnClick := DebugMapClick;
    75277527          if p1 < 10 then
    7528             m.ShortCut := ShortCut(48 + p1, [ssAlt]);
    7529           m.RadioItem := true;
    7530           if m.Tag = MainMap.pDebugMap then
    7531             m.Checked := true;
    7532           mDebugMap.Add(m);
     7528            M.ShortCut := ShortCut(48 + p1, [ssAlt]);
     7529          M.RadioItem := True;
     7530          if M.Tag = MainMap.pDebugMap then
     7531            M.Checked := True;
     7532          mDebugMap.Add(M);
    75337533        end;
    75347534    end;
     
    75457545      (ClientMode < scContact);
    75467546    mUnitStat.Enabled := NoSuper or (MyRO.Turn > 0);
    7547     mCityStat.Visible := 1 shl me and MyRO.Alive <> 0;
     7547    mCityStat.Visible := 1 shl Me and MyRO.Alive <> 0;
    75487548    mCityStat.Enabled := HaveCities;
    7549     mScienceStat.Visible := true;
     7549    mScienceStat.Visible := True;
    75507550    mScienceStat.Enabled := not NoSuper or (MyRO.ResearchTech >= 0) or
    75517551      (MyRO.Happened and phTech <> 0) or (MyRO.Happened and phGameEnd <> 0)
     
    75547554    mEUnitStat.Enabled := MyRO.nEnemyModel > 0;
    75557555    { mWonders.Enabled:= false;
    7556       for i:=0 to nWonder - 1 do if MyRO.Wonder[i].CityID <> WonderNotBuiltYet then
    7557       mWonders.Enabled:=true; }
     7556      for I:=0 to nWonder - 1 do if MyRO.Wonder[I].CityID <> WonderNotBuiltYet then
     7557      mWonders.Enabled:=True; }
    75587558    mDiagram.Enabled := MyRO.Turn >= 2;
    7559     mShips.Enabled := false;
     7559    mShips.Enabled := False;
    75607560    for p1 := 0 to nPl - 1 do
    75617561      if MyRO.Ship[p1].Parts[spComp] + MyRO.Ship[p1].Parts[spPow] +
    75627562        MyRO.Ship[p1].Parts[spHab] > 0 then
    7563         mShips.Enabled := true;
     7563        mShips.Enabled := True;
    75647564  end
    75657565  else if Popup = UnitPopup then
     
    75677567    mox := @MyModel[MyUn[UnFocus].mix];
    75687568    Tile := MyMap[MyUn[UnFocus].Loc];
    7569     extended := Tile and fCity = 0;
    7570     if extended then
     7569    Extended := Tile and fCity = 0;
     7570    if Extended then
    75717571    begin
    75727572      mCity.Caption := Phrases.Lookup('BTN_FOUND');
     
    75797579    end;
    75807580
    7581     extended := extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)
     7581    Extended := Extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)
    75827582      and (MyRO.Wonder[woPyramids].EffectiveOwner >= 0)) and
    75837583      (MyUn[UnFocus].Master < 0) and (Tile and fDeadLands = 0);
    75847584    if (mox.Kind = mkFreight) and (Tile and fCity <> 0) and
    75857585      not Phrases2FallenBackToEnglish or
    7586       (Server(sRemoveUnit - sExecute, me, UnFocus, nil^) = eUtilized) then
    7587     begin
    7588       mDisband.Visible := false;
    7589       mUtilize.Visible := true;
     7586      (Server(sRemoveUnit - sExecute, Me, UnFocus, nil^) = eUtilized) then
     7587    begin
     7588      mDisband.Visible := False;
     7589      mUtilize.Visible := True;
    75907590      if mox.Kind = mkFreight then
    75917591        mUtilize.Caption := Phrases.Lookup('UTILIZE')
     
    75957595    else
    75967596    begin
    7597       mDisband.Visible := true;
    7598       mUtilize.Visible := false
     7597      mDisband.Visible := True;
     7598      mUtilize.Visible := False
    75997599    end;
    76007600    mGoOn.Visible := MyUn[UnFocus].Status and (usGoto or usWaiting) = usGoto or
     
    76037603    mRecover.Visible := (MyUn[UnFocus].Health < 100) and
    76047604      (Tile and fTerrain >= fGrass) and
    7605       ((MyRO.Wonder[woGardens].EffectiveOwner = me) or
     7605      ((MyRO.Wonder[woGardens].EffectiveOwner = Me) or
    76067606      (Tile and fTerrain <> fArctic) and (Tile and fTerrain <> fDesert)) and
    76077607      not((mox.Domain = dAir) and (Tile and fCity = 0) and
     
    76097609    mStay.Visible := not((mox.Domain = dAir) and (Tile and fCity = 0) and
    76107610      (Tile and fTerImp <> tiBase));
    7611     mCity.Visible := extended and (mox.Kind = mkSettler) or
     7611    mCity.Visible := Extended and (mox.Kind = mkSettler) or
    76127612      (Tile and fCity <> 0) and ((mox.Kind in [mkSettler, mkSlaves]) or
    76137613      (MyUn[UnFocus].Flags and unConscripts <> 0));
     
    76177617      (MyUn[UnFocus].Status and (usRecover or usGoto) <> 0);
    76187618
    7619     Test := Server(sLoadUnit - sExecute, me, UnFocus, nil^);
     7619    Test := Server(sLoadUnit - sExecute, Me, UnFocus, nil^);
    76207620    mLoad.Visible := (Test >= rExecuted) or (Test = eNoTime_Load);
    76217621    mUnload.Visible := (MyUn[UnFocus].Master >= 0) or
    76227622      (MyUn[UnFocus].TroopLoad + MyUn[UnFocus].AirLoad > 0);
    7623     mSelectTransport.Visible := Server(sSelectTransport - sExecute, me, UnFocus,
     7623    mSelectTransport.Visible := Server(sSelectTransport - sExecute, Me, UnFocus,
    76247624      nil^) >= rExecuted;
    76257625  end
     
    76287628    mox := @MyModel[MyUn[UnFocus].mix];
    76297629    Tile := MyMap[MyUn[UnFocus].Loc];
    7630     extended := Tile and fCity = 0;
     7630    Extended := Tile and fCity = 0;
    76317631
    76327632    if (Tile and fRiver <> 0) and (MyRO.Tech[adBridgeBuilding] >= tsApplicable)
     
    76487648      mClear.Caption := Phrases.Lookup('BTN_DRAIN');
    76497649
    7650     extended := extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)
     7650    Extended := Extended and ((mox.Kind = mkSettler) or (mox.Kind = mkSlaves)
    76517651      and (MyRO.Wonder[woPyramids].EffectiveOwner >= 0)) and
    76527652      (MyUn[UnFocus].Master < 0);
    7653     if extended then
     7653    if Extended then
    76547654    begin
    76557655      mRoad.Visible := JobTest(UnFocus, jRoad, [eNoBridgeBuilding, eTreaty]);
     
    76717671    else
    76727672    begin
    7673       for i := 0 to Popup.Items.Count - 1 do
    7674         Popup.Items[i].Visible := false;
     7673      for I := 0 to Popup.Items.Count - 1 do
     7674        Popup.Items[I].Visible := False;
    76757675    end;
    76767676  end;
     
    76787678  // set menu seperators
    76797679  LastSep := nil;
    7680   NeedSep := false;
    7681   for i := 0 to Popup.Items.Count - 1 do
    7682     if Popup.Items[i].Caption = '-' then
    7683     begin
    7684       Popup.Items[i].Visible := NeedSep;
     7680  NeedSep := False;
     7681  for I := 0 to Popup.Items.Count - 1 do
     7682    if Popup.Items[I].Caption = '-' then
     7683    begin
     7684      Popup.Items[I].Visible := NeedSep;
    76857685      if NeedSep then
    7686         LastSep := Popup.Items[i];
    7687       NeedSep := false
     7686        LastSep := Popup.Items[I];
     7687      NeedSep := False
    76887688    end
    7689     else if Popup.Items[i].Visible then
    7690       NeedSep := true;
     7689    else if Popup.Items[I].Visible then
     7690      NeedSep := True;
    76917691  if (LastSep <> nil) and not NeedSep then
    7692     LastSep.Visible := false
     7692    LastSep.Visible := False
    76937693end;
    76947694
     
    77097709end;
    77107710
    7711 procedure TMainScreen.CityClosed(Activateuix: integer; StepFocus: boolean;
    7712   SelectFocus: boolean);
    7713 begin
    7714   if supervising then
     7711procedure TMainScreen.CityClosed(Activateuix: Integer; StepFocus: Boolean;
     7712  SelectFocus: Boolean);
     7713begin
     7714  if Supervising then
    77157715  begin
    77167716    SetTroopLoc(-1);
     
    77297729    end
    77307730    else if StepFocus then
    7731       NextUnit(TroopLoc, true)
     7731      NextUnit(TroopLoc, True)
    77327732    else
    77337733    begin
     
    77447744
    77457745procedure TMainScreen.PanelBoxMouseMove(Sender: TObject; Shift: TShiftState;
    7746   x, y: integer);
     7746  X, Y: Integer);
    77477747var
    7748   xCentre, yCentre: integer;
     7748  xCentre, yCentre: Integer;
    77497749begin
    77507750  if Tracking and (ssLeft in Shift) then
    77517751  with MainMap do begin
    7752     if (x >= xMini + 2) and (y >= yMini + 2) and (x < xMini + 2 + 2 * G.lx) and
    7753       (y < yMini + 2 + G.ly) then
    7754     begin
    7755       xCentre := (xwMini + (x - xMini - 2) div 2 + G.lx div 2 +
     7752    if (X >= xMini + 2) and (Y >= yMini + 2) and (X < xMini + 2 + 2 * G.lx) and
     7753      (Y < yMini + 2 + G.ly) then
     7754    begin
     7755      xCentre := (xwMini + (X - xMini - 2) div 2 + G.lx div 2 +
    77567756        MapWidth div (xxt * 4)) mod G.lx;
    7757       yCentre := (y - yMini - 2);
     7757      yCentre := (Y - yMini - 2);
    77587758      xw := (xCentre - MapWidth div (xxt * 4) + G.lx) mod G.lx;
    77597759      if ywmax <= 0 then
     
    77697769      BitBltCanvas(Buffer.Canvas, 0, 0, G.lx * 2, G.ly, MiniMap.Bitmap.Canvas, 0, 0);
    77707770      if ywmax <= 0 then
    7771         Frame(Buffer.Canvas, x - xMini - 2 - MapWidth div (xxt * 2), 0,
    7772           x - xMini - 2 + MapWidth div (xxt * 2) - 1, G.ly - 1,
     7771        Frame(Buffer.Canvas, X - xMini - 2 - MapWidth div (xxt * 2), 0,
     7772          X - xMini - 2 + MapWidth div (xxt * 2) - 1, G.ly - 1,
    77737773          MainTexture.ColorMark, MainTexture.ColorMark)
    77747774      else
    7775         Frame(Buffer.Canvas, x - xMini - 2 - MapWidth div (xxt * 2), yw,
    7776           x - xMini - 2 + MapWidth div (xxt * 2) - 1, yw + MapHeight div yyt -
     7775        Frame(Buffer.Canvas, X - xMini - 2 - MapWidth div (xxt * 2), yw,
     7776          X - xMini - 2 + MapWidth div (xxt * 2) - 1, yw + MapHeight div yyt -
    77777777          2, MainTexture.ColorMark, MainTexture.ColorMark);
    77787778      BitBltCanvas(Panel.Canvas, xMini + 2, yMini + 2, G.lx * 2, G.ly,
     
    77867786  end
    77877787  else
    7788     Tracking := false;
     7788    Tracking := False;
    77897789end;
    77907790
    77917791procedure TMainScreen.PanelBoxMouseUp(Sender: TObject; Button: TMouseButton;
    7792   Shift: TShiftState; x, y: integer);
     7792  Shift: TShiftState; X, Y: Integer);
    77937793begin
    77947794  if Tracking then
    77957795  begin
    7796     Tracking := false;
     7796    Tracking := False;
    77977797    xwMini := xw;
    77987798    ywMini := yw;
     
    78037803
    78047804procedure TMainScreen.MapBoxMouseMove(Sender: TObject; Shift: TShiftState;
    7805   x, y: integer);
     7805  X, Y: Integer);
    78067806var
    7807   MouseLoc: integer;
    7808 begin
    7809   xMouse := x;
    7810   yMouse := y;
     7807  MouseLoc: Integer;
     7808begin
     7809  xMouse := X;
     7810  yMouse := Y;
    78117811  if (ClientMode = cEditMap) and (ssLeft in Shift) and not Tracking then
    78127812  begin
    7813     MouseLoc := LocationOfScreenPixel(x, y);
     7813    MouseLoc := LocationOfScreenPixel(X, Y);
    78147814    if MouseLoc <> BrushLoc then
    7815       MapBoxMouseDown(nil, mbLeft, Shift, x, y);
     7815      MapBoxMouseDown(nil, mbLeft, Shift, X, Y);
    78167816  end
    7817   (* else if idle and (UnFocus>=0) then
     7817  (* else if Idle and (UnFocus>=0) then
    78187818    begin
    78197819    qx:=(xMouse*32+yMouse*66+16*66) div(32*66)-1;
     
    78287828  TMenuItem(Sender).Checked := not TMenuItem(Sender).Checked;
    78297829  SetMapOptions;
    7830   MapValid := false;
     7830  MapValid := False;
    78317831  PaintAllMaps;
    78327832end;
     
    78347834procedure TMainScreen.mNamesClick(Sender: TObject);
    78357835var
    7836   p1: integer;
     7836  p1: Integer;
    78377837begin
    78387838  mNames.Checked := not mNames.Checked;
     
    78447844      else
    78457845        Tribe[p1].NumberName := p1;
    7846   MapValid := false;
     7846  MapValid := False;
    78477847  PaintAll;
    78487848end;
    78497849
    7850 function TMainScreen.IsPanelPixel(x, y: integer): boolean;
    7851 begin
    7852   result := (y >= TopBarHeight + MapHeight) or (y >= ClientHeight - PanelHeight)
    7853     and ((x < xMidPanel) or (x >= xRightPanel));
     7850function TMainScreen.IsPanelPixel(X, Y: Integer): Boolean;
     7851begin
     7852  Result := (Y >= TopBarHeight + MapHeight) or (Y >= ClientHeight - PanelHeight)
     7853    and ((X < xMidPanel) or (X >= xRightPanel));
    78547854end;
    78557855
    78567856procedure TMainScreen.FormMouseDown(Sender: TObject; Button: TMouseButton;
    7857   Shift: TShiftState; x, y: integer);
    7858 begin
    7859   if idle then
    7860     if (x < 40) and (y < 40) then
     7857  Shift: TShiftState; X, Y: Integer);
     7858begin
     7859  if Idle then
     7860    if (X < 40) and (Y < 40) then
    78617861    begin
    78627862      if GameMode <> cMovie then
     
    78707870      end;
    78717871    end
    7872     else if IsPanelPixel(x, y) then
    7873       PanelBoxMouseDown(Sender, Button, Shift, x,
    7874         y - (ClientHeight - PanelHeight))
    7875     else if (y >= TopBarHeight) and (x >= MapOffset) and
    7876       (x < MapOffset + MapWidth) then
    7877       MapBoxMouseDown(Sender, Button, Shift, x - MapOffset, y - TopBarHeight)
     7872    else if IsPanelPixel(X, Y) then
     7873      PanelBoxMouseDown(Sender, Button, Shift, X,
     7874        Y - (ClientHeight - PanelHeight))
     7875    else if (Y >= TopBarHeight) and (X >= MapOffset) and
     7876      (X < MapOffset + MapWidth) then
     7877      MapBoxMouseDown(Sender, Button, Shift, X - MapOffset, Y - TopBarHeight)
    78787878end;
    78797879
    78807880procedure TMainScreen.FormMouseMove(Sender: TObject; Shift: TShiftState;
    7881   x, y: integer);
    7882 begin
    7883   if idle then
    7884     if IsPanelPixel(x, y) then
    7885       PanelBoxMouseMove(Sender, Shift, x, y - (ClientHeight - PanelHeight))
    7886     else if (y >= TopBarHeight) and (x >= MapOffset) and
    7887       (x < MapOffset + MapWidth) then
    7888       MapBoxMouseMove(Sender, Shift, x - MapOffset, y - TopBarHeight);
     7881  X, Y: Integer);
     7882begin
     7883  if Idle then
     7884    if IsPanelPixel(X, Y) then
     7885      PanelBoxMouseMove(Sender, Shift, X, Y - (ClientHeight - PanelHeight))
     7886    else if (Y >= TopBarHeight) and (X >= MapOffset) and
     7887      (X < MapOffset + MapWidth) then
     7888      MapBoxMouseMove(Sender, Shift, X - MapOffset, Y - TopBarHeight);
    78897889end;
    78907890
    78917891procedure TMainScreen.FormMouseUp(Sender: TObject; Button: TMouseButton;
    7892   Shift: TShiftState; x, y: integer);
    7893 begin
    7894   if idle then
    7895     PanelBoxMouseUp(Sender, Button, Shift, x, y - (ClientHeight - PanelHeight));
     7892  Shift: TShiftState; X, Y: Integer);
     7893begin
     7894  if Idle then
     7895    PanelBoxMouseUp(Sender, Button, Shift, X, Y - (ClientHeight - PanelHeight));
    78967896end;
    78977897
     
    79027902    with Canvas do
    79037903    begin // pillarbox, make left and right border black
    7904       if me < 0 then
     7904      if Me < 0 then
    79057905        Brush.Color := $000000
    79067906      else
     
    79297929    end;
    79307930  BitBltCanvas(Canvas, MapOffset, TopBarHeight, MapWidth, MapHeight - overlap,
    7931     offscreen.Canvas, 0, 0);
     7931    Offscreen.Canvas, 0, 0);
    79327932  BitBltCanvas(Canvas, 0, 0, ClientWidth, TopBarHeight, TopBar.Canvas,
    79337933    0, 0);
    79347934  if xMidPanel > MapOffset then
    79357935    BitBltCanvas(Canvas, xMidPanel, TopBarHeight + MapHeight - overlap,
    7936       ClientWidth div 2 - xMidPanel, overlap, offscreen.Canvas,
     7936      ClientWidth div 2 - xMidPanel, overlap, Offscreen.Canvas,
    79377937      xMidPanel - MapOffset, MapHeight - overlap)
    79387938  else
    79397939    BitBltCanvas(Canvas, MapOffset, TopBarHeight + MapHeight - overlap,
    7940       ClientWidth div 2 - MapOffset, overlap, offscreen.Canvas, 0,
     7940      ClientWidth div 2 - MapOffset, overlap, Offscreen.Canvas, 0,
    79417941      MapHeight - overlap);
    79427942  if xRightPanel < MapOffset + MapWidth then
    79437943    BitBltCanvas(Canvas, ClientWidth div 2, TopBarHeight + MapHeight - overlap,
    7944       xRightPanel - ClientWidth div 2, overlap, offscreen.Canvas,
     7944      xRightPanel - ClientWidth div 2, overlap, Offscreen.Canvas,
    79457945      ClientWidth div 2 - MapOffset, MapHeight - overlap)
    79467946  else
    79477947    BitBltCanvas(Canvas, ClientWidth div 2, TopBarHeight + MapHeight - overlap,
    79487948      MapOffset + MapWidth - ClientWidth div 2, overlap,
    7949       offscreen.Canvas, ClientWidth div 2 - MapOffset,
     7949      Offscreen.Canvas, ClientWidth div 2 - MapOffset,
    79507950      MapHeight - overlap);
    79517951  BitBltCanvas(Canvas, 0, TopBarHeight + MapHeight - overlap, xMidPanel,
     
    79607960end;
    79617961
    7962 procedure TMainScreen.RectInvalidate(Left, Top, Rigth, Bottom: integer);
     7962procedure TMainScreen.RectInvalidate(Left, Top, Rigth, Bottom: Integer);
    79637963var
    79647964  r0: HRgn;
    79657965begin
    79667966  r0 := CreateRectRgn(Left, Top, Rigth, Bottom);
    7967   InvalidateRgn(Handle, r0, false);
     7967  InvalidateRgn(Handle, r0, False);
    79687968  DeleteObject(r0);
    79697969end;
    79707970
    7971 procedure TMainScreen.SmartRectInvalidate(Left, Top, Rigth, Bottom: integer);
     7971procedure TMainScreen.SmartRectInvalidate(Left, Top, Rigth, Bottom: Integer);
    79727972var
    7973   i: integer;
     7973  I: Integer;
    79747974  r0, r1: HRgn;
    79757975begin
    79767976  r0 := CreateRectRgn(Left, Top, Rigth, Bottom);
    7977   for i := 0 to ControlCount - 1 do
    7978     if not(Controls[i] is TArea) and Controls[i].Visible then
    7979     begin
    7980       with Controls[i].BoundsRect do
     7977  for I := 0 to ControlCount - 1 do
     7978    if not(Controls[I] is TArea) and Controls[I].Visible then
     7979    begin
     7980      with Controls[I].BoundsRect do
    79817981        r1 := CreateRectRgn(Left, Top, Right, Bottom);
    79827982      CombineRgn(r0, r0, r1, RGN_DIFF);
    79837983      DeleteObject(r1);
    79847984    end;
    7985   InvalidateRgn(Handle, r0, false);
     7985  InvalidateRgn(Handle, r0, False);
    79867986  DeleteObject(r0);
    79877987end;
     
    80488048procedure TMainScreen.FormClose(Sender: TObject; var Action: TCloseAction);
    80498049begin
    8050   Timer1.Enabled := false;
     8050  Timer1.Enabled := False;
    80518051end;
    80528052
    80538053procedure TMainScreen.Radio(Sender: TObject);
    80548054begin
    8055   TMenuItem(Sender).Checked := true;
     8055  TMenuItem(Sender).Checked := True;
    80568056end;
    80578057
    80588058procedure TMainScreen.mManipClick(Sender: TObject);
    80598059var
    8060   Flag: integer;
     8060  Flag: Integer;
    80618061begin
    80628062  with TMenuItem(Sender) do
     
    80708070      Play('CHEAT');
    80718071    end;
    8072     if not supervising then
     8072    if not Supervising then
    80738073    begin
    80748074      if Flag = tfUncover then
    80758075      begin
    8076         MapValid := false;
     8076        MapValid := False;
    80778077        PaintAllMaps;
    80788078      end
     
    80988098  else
    80998099  begin
    8100     MapValid := false;
     8100    MapValid := False;
    81018101    PaintAllMaps;
    81028102  end; // update main map
     
    81178117  end;
    81188118  SetMapOptions;
    8119   MapValid := false;
     8119  MapValid := False;
    81208120  PaintAllMaps;
    81218121end;
     
    81358135  end;
    81368136  SetMapOptions;
    8137   MapValid := false;
     8137  MapValid := False;
    81388138  PaintAllMaps;
    81398139end;
    81408140
    8141 procedure TMainScreen.FormKeyUp(Sender: TObject; var Key: word;
     8141procedure TMainScreen.FormKeyUp(Sender: TObject; var Key: Word;
    81428142  Shift: TShiftState);
    81438143begin
    8144   if idle and (Key = VK_APPS) then
     8144  if Idle and (Key = VK_APPS) then
    81458145  begin
    81468146    InitPopup(GamePopup);
     
    81508150      GamePopup.Popup(Left + 4, Top + GetSystemMetrics(SM_CYCAPTION) + 4 +
    81518151        TopBarHeight - 1);
    8152     exit;
     8152    Exit;
    81538153  end; // windows menu button calls game menu
    81548154end;
     
    81568156procedure TMainScreen.CreateUnitClick(Sender: TObject);
    81578157var
    8158   p1, mix: integer;
     8158  p1, mix: Integer;
    81598159begin
    81608160  p1 := TComponent(Sender).Tag shr 16;
    81618161  mix := TComponent(Sender).Tag and $FFFF;
    8162   if Server(sCreateUnit + p1 shl 4, me, mix, EditLoc) >= rExecuted then
     8162  if Server(sCreateUnit + p1 shl 4, Me, mix, EditLoc) >= rExecuted then
    81638163    PaintLoc(EditLoc);
    81648164end;
     
    81818181{ procedure TMainScreen.AdviceBtnClick;
    81828182  var
    8183   OldAdviceLoc: integer;
    8184   begin
    8185   DestinationMarkON:=false;
     8183  OldAdviceLoc: Integer;
     8184  begin
     8185  DestinationMarkON:=False;
    81868186  PaintDestination;
    81878187  AdvisorDlg.GiveStrategyAdvice;
     
    81938193{ procedure TMainScreen.SetAdviceLoc(Loc: integer; AvoidRect: TRect);
    81948194  var
    8195   OldAdviceLoc,x,y: integer;
     8195  OldAdviceLoc,X,Y: Integer;
    81968196  begin
    81978197  if Loc<>MainMap.AdviceLoc then
     
    81998199  if Loc>=0 then
    82008200  begin // center
    8201   y:=Loc div G.lx;
    8202   x:=(Loc+G.lx - AvoidRect.Right div (2*66)) mod G.lx;
    8203   Centre(y*G.lx+x);
     8201  Y:=Loc div G.lx;
     8202  X:=(Loc+G.lx - AvoidRect.Right div (2*66)) mod G.lx;
     8203  Centre(Y*G.lx+X);
    82048204  PaintAllMaps;
    82058205  end;
     
    82598259procedure TMainScreen.SaveMenuItemsState;
    82608260var
    8261   i, j: integer;
     8261  I, J: Integer;
    82628262begin
    82638263  if soTellAI in OptionChecked then OptionChecked := [soTellAI]
    82648264    else OptionChecked := [];
    8265   for i := 0 to ComponentCount - 1 do
    8266     if Components[i] is TMenuItem then
    8267       for j := 0 to Length(SaveOption) - 1 do
    8268         if TMenuItem(Components[i]).Checked and
    8269           (TMenuItem(Components[i]).Tag = SaveOption[j]) then
    8270           OptionChecked := OptionChecked + [TSaveOption(j)];
     8265  for I := 0 to ComponentCount - 1 do
     8266    if Components[I] is TMenuItem then
     8267      for J := 0 to Length(SaveOption) - 1 do
     8268        if TMenuItem(Components[I]).Checked and
     8269          (TMenuItem(Components[I]).Tag = SaveOption[J]) then
     8270          OptionChecked := OptionChecked + [TSaveOption(J)];
    82718271end;
    82728272
     
    82808280  with Reg do
    82818281  try
    8282     OpenKey(AppRegistryKey, true);
     8282    OpenKey(AppRegistryKey, True);
    82838283    WriteInteger('TileSize', Integer(MainMap.TileSize));
    82848284    WriteInteger('OptionChecked', Integer(OptionChecked));
    82858285    WriteInteger('MapOptionChecked', Integer(MapOptionChecked));
    8286     WriteInteger('CityReport', integer(CityRepMask));
     8286    WriteInteger('CityReport', Integer(CityRepMask));
    82878287  finally
    82888288    Free;
  • trunk/LocalPlayer/Tribes.pas

    r438 r447  
    4949    constructor Create(FileName: string);
    5050    destructor Destroy; override;
    51     function GetCityName(i: Integer): string;
    52 {$IFNDEF SCR} procedure SetCityName(i: Integer; NewName: string); {$ENDIF}
     51    function GetCityName(I: Integer): string;
     52{$IFNDEF SCR} procedure SetCityName(I: Integer; NewName: string); {$ENDIF}
    5353{$IFNDEF SCR} function TString(Template: string): string;
    5454    function TPhrase(Item: string): string; {$ENDIF}
     
    7474procedure FindStdModelPicture(Code: Integer; var pix: Integer; var Name: string);
    7575function GetTribeInfo(FileName: string; var Name: string; var Color: TColor): Boolean;
    76 procedure FindPosition(HGr: TGraphicSet; x, y, xmax, ymax: Integer; Mark: TColor;
     76procedure FindPosition(HGr: TGraphicSet; X, Y, xmax, ymax: Integer; Mark: TColor;
    7777  var xp, yp: Integer);
    7878
     
    215215function Get: string;
    216216var
    217   p: Integer;
     217  P: Integer;
    218218begin
    219219  while (Input <> '') and ((Input[1] = ' ') or (Input[1] = #9)) do
    220220    Delete(Input, 1, 1);
    221   p := Pos(',', Input);
    222   if p = 0 then
    223     p := Length(Input) + 1;
    224   Result := Copy(Input, 1, p - 1);
    225   Delete(Input, 1, p);
     221  P := Pos(',', Input);
     222  if P = 0 then
     223    P := Length(Input) + 1;
     224  Result := Copy(Input, 1, P - 1);
     225  Delete(Input, 1, P);
    226226end;
    227227
    228228function GetNum: Integer;
    229229var
    230   i: Integer;
    231 begin
    232   Val(Get, Result, i);
    233   if i <> 0 then
     230  I: Integer;
     231begin
     232  Val(Get, Result, I);
     233  if I <> 0 then
    234234    Result := 0;
    235235end;
     
    237237procedure FindStdModelPicture(Code: Integer; var pix: Integer; var Name: string);
    238238var
    239   i: Integer;
    240 begin
    241   for i := 0 to StdUnitScript.Count - 1 do
     239  I: Integer;
     240begin
     241  for I := 0 to StdUnitScript.Count - 1 do
    242242  begin // look through StdUnits
    243     Input := StdUnitScript[i];
     243    Input := StdUnitScript[I];
    244244    pix := GetNum;
    245245    if Code = GetNum then
     
    340340end;
    341341
    342 procedure FindPosition(HGr: TGraphicSet; x, y, xmax, ymax: Integer; Mark: TColor;
     342procedure FindPosition(HGr: TGraphicSet; X, Y, xmax, ymax: Integer; Mark: TColor;
    343343  var xp, yp: Integer);
    344344begin
    345345  xp := 0;
    346   while (xp < xmax) and (HGr.Data.Canvas.Pixels[x + 1 + xp, y] <> Mark) do
     346  while (xp < xmax) and (HGr.Data.Canvas.Pixels[X + 1 + xp, Y] <> Mark) do
    347347    Inc(xp);
    348348  yp := 0;
    349   while (yp < ymax) and (HGr.Data.Canvas.Pixels[x, y + 1 + yp] <> Mark) do
     349  while (yp < ymax) and (HGr.Data.Canvas.Pixels[X, Y + 1 + yp] <> Mark) do
    350350    Inc(yp);
    351351end;
    352352
    353 function TTribe.GetCityName(i: Integer): string;
     353function TTribe.GetCityName(I: Integer): string;
    354354begin
    355355  Result := '';
    356   if nCityLines > i then
    357   begin
    358     Result := Script[CityLine0 + i];
     356  if nCityLines > I then
     357  begin
     358    Result := Script[CityLine0 + I];
    359359    while (Result <> '') and ((Result[1] = ' ') or (Result[1] = #9)) do
    360360      Delete(Result, 1, 1);
     
    362362{$IFNDEF SCR}
    363363  else
    364     Result := Format(TPhrase('GENCITY'), [i + 1]);
     364    Result := Format(TPhrase('GENCITY'), [I + 1]);
    365365{$ENDIF}
    366366end;
    367367
    368368{$IFNDEF SCR}
    369 procedure TTribe.SetCityName(i: Integer; NewName: string);
    370 begin
    371   while nCityLines <= i do
     369procedure TTribe.SetCityName(I: Integer; NewName: string);
     370begin
     371  while nCityLines <= I do
    372372  begin
    373373    Script.Insert(CityLine0 + nCityLines, Format(TPhrase('GENCITY'),
     
    375375    Inc(nCityLines);
    376376  end;
    377   Script[CityLine0 + i] := NewName;
     377  Script[CityLine0 + I] := NewName;
    378378end;
    379379
    380380function TTribe.TString(Template: string): string;
    381381var
    382   p: Integer;
     382  P: Integer;
    383383  Variant: Char;
    384384  CaseUp: Boolean;
    385385begin
    386386  repeat
    387     p := pos('#', Template);
    388     if (p = 0) or (p = Length(Template)) then
     387    P := Pos('#', Template);
     388    if (P = 0) or (P = Length(Template)) then
    389389      Break;
    390     Variant := Template[p + 1];
     390    Variant := Template[P + 1];
    391391    CaseUp := Variant in ['A' .. 'Z'];
    392392    if CaseUp then
    393393      Inc(Variant, 32);
    394     Delete(Template, p, 2);
     394    Delete(Template, P, 2);
    395395    if Variant in ['a' .. 'z'] then
    396396    begin
    397397      if NumberName < 0 then
    398         Insert(Name[Variant], Template, p)
     398        Insert(Name[Variant], Template, P)
    399399      else
    400         Insert(Format('P%d', [NumberName]), Template, p);
    401       if CaseUp and (Length(Template) >= p) and
    402         (Template[p] in ['a' .. 'z', #$E0 .. #$FF]) then
    403         Dec(Template[p], 32);
     400        Insert(Format('P%d', [NumberName]), Template, P);
     401      if CaseUp and (Length(Template) >= P) and
     402        (Template[P] in ['a' .. 'z', #$E0 .. #$FF]) then
     403        Dec(Template[P], 32);
    404404    end
    405405  until False;
     
    418418  TLine = array [0 .. 649, 0 .. 2] of Byte;
    419419var
    420   i, x, Gray: Integer;
     420  I, X, Gray: Integer;
    421421  Item: string;
    422422begin
     
    426426  with Script do
    427427  begin
    428     i := 0;
    429     while (i < Count) and (Copy(Strings[i], 1, 6) <>
     428    I := 0;
     429    while (I < Count) and (Copy(Strings[I], 1, 6) <>
    430430        '#AGE' + char(48 + Age) + ' ') do
    431       Inc(i);
    432     if i < Count then
    433     begin
    434       Input := Strings[i];
     431      Inc(I);
     432    if I < Count then
     433    begin
     434      Input := Strings[I];
    435435      system.Delete(Input, 1, 6);
    436436      Item := Get;
     
    448448          end;
    449449        cHGr := LoadGraphicSet(Item + '.png');
    450         for x := 0 to 3 do
    451           with CityPicture[x] do begin
    452             FindPosition(cHGr, x * 65, cpix * 49, 63, 47, $00FFFF,
     450        for X := 0 to 3 do
     451          with CityPicture[X] do begin
     452            FindPosition(cHGr, X * 65, cpix * 49, 63, 47, $00FFFF,
    453453              xShield, yShield);
    454454            // FindPosition(cHGr,x*65,cpix*49,$FFFFFF,xf,yf);
     
    486486procedure TTribe.SetModelPicture(const Info: TModelPictureInfo; IsNew: Boolean);
    487487var
    488   i: Integer;
     488  I: Integer;
    489489  ok: Boolean;
    490490begin
     
    493493    if not IsNew then
    494494    begin
    495       i := nPictureList - 1;
    496       while (i >= 0) and (PictureList[i].Hash <> Info.Hash) do
    497         Dec(i);
    498       assert(i >= 0);
    499       assert(PictureList[i].HGr = LoadGraphicSet(GrName));
    500       assert(PictureList[i].pix = pix);
    501       ModelPicture[mix].HGr := PictureList[i].HGr;
    502       ModelPicture[mix].pix := PictureList[i].pix;
    503       ModelName[mix] := PictureList[i].ModelName;
     495      I := nPictureList - 1;
     496      while (I >= 0) and (PictureList[I].Hash <> Info.Hash) do
     497        Dec(I);
     498      Assert(I >= 0);
     499      Assert(PictureList[I].HGr = LoadGraphicSet(GrName));
     500      Assert(PictureList[I].pix = pix);
     501      ModelPicture[mix].HGr := PictureList[I].HGr;
     502      ModelPicture[mix].pix := PictureList[I].pix;
     503      ModelName[mix] := PictureList[I].ModelName;
    504504    end
    505505    else
     
    515515      // read model name from tribe script
    516516      ok := False;
    517       for i := 0 to Script.Count - 1 do
    518       begin
    519         Input := Script[i];
     517      for I := 0 to Script.Count - 1 do
     518      begin
     519        Input := Script[I];
    520520        if Input = '#UNITS ' + ExtractFileNameOnly(GrName) then
    521521          ok := True
     
    531531      if ModelName[mix] = '' then
    532532      begin // read model name from StdUnits.txt
    533         for i := 0 to StdUnitScript.Count - 1 do
     533        for I := 0 to StdUnitScript.Count - 1 do
    534534        begin
    535           Input := StdUnitScript[i];
     535          Input := StdUnitScript[I];
    536536          if GetNum = pix then
    537537          begin
     
    567567  Code, Turn: Integer; ForceNew: Boolean): Boolean;
    568568var
    569   i: Integer;
     569  I: Integer;
    570570  Cnt: Integer;
    571571  HGr: TGraphicSet;
     
    606606  if not ForceNew and (Picture.Hash > 0) then
    607607  begin
    608     for i := 0 to nPictureList - 1 do
    609       if PictureList[i].Hash = Picture.Hash then
    610       begin
    611         Picture.GrName := PictureList[i].HGr.Name;
    612         Picture.pix := PictureList[i].pix;
     608    for I := 0 to nPictureList - 1 do
     609      if PictureList[I].Hash = Picture.Hash then
     610      begin
     611        Picture.GrName := PictureList[I].HGr.Name;
     612        Picture.pix := PictureList[I].pix;
    613613        Result := False;
    614614        Exit;
     
    622622  TestPic.GrName := 'StdUnits.png';
    623623  HGr := HGrStdUnits;
    624   for i := 0 to StdUnitScript.Count - 1 do
     624  for I := 0 to StdUnitScript.Count - 1 do
    625625  begin // look through StdUnits
    626     Input := StdUnitScript[i];
     626    Input := StdUnitScript[I];
    627627    Check;
    628628  end;
    629629
    630630  ok := False;
    631   for i := 0 to Script.Count - 1 do
     631  for I := 0 to Script.Count - 1 do
    632632  begin // look through units defined in tribe script
    633     Input := Script[i];
     633    Input := Script[I];
    634634    if Copy(Input, 1, 6) = '#UNITS' then
    635635    begin
  • trunk/LocalPlayer/UKeyBindings.pas

    r424 r447  
    397397end.
    398398
     399
  • trunk/LocalPlayer/UnitStat.pas

    r442 r447  
    2828  public
    2929    procedure CheckAge;
    30     procedure ShowNewContent_OwnModel(NewMode: TWindowMode; mix: integer);
    31     procedure ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: integer);
    32     procedure ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: integer);
    33     procedure ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: integer);
    34     procedure ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: integer);
    35     procedure ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: integer);
     30    procedure ShowNewContent_OwnModel(NewMode: TWindowMode; mix: Integer);
     31    procedure ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: Integer);
     32    procedure ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: Integer);
     33    procedure ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: Integer);
     34    procedure ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: Integer);
     35    procedure ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: Integer);
    3636
    3737  protected
    3838    mixShow, // for dkOwnModel
    39     uixShow, euixShow, ecixShow, UnitLoc, AgePrepared: integer;
     39    uixShow, euixShow, ecixShow, UnitLoc, AgePrepared: Integer;
    4040    // for dkEnemyUnit, euixShow=-1 ->
    4141    mox: ^TModelInfo; // for dkEnemyModel
     
    121121procedure TUnitStatDlg.FormShow(Sender: TObject);
    122122var
    123   owner, mix: integer;
    124   IsSpecialUnit: boolean;
     123  owner, mix: Integer;
     124  IsSpecialUnit: Boolean;
    125125begin
    126126  if Kind in [dkEnemyUnit, dkEnemyCityDefense, dkEnemyCity] then
     
    132132        euixShow := MyRO.nEnemyUn - 1;
    133133        while (euixShow >= 0) and (MyRO.EnemyUn[euixShow].Loc <> UnitLoc) do
    134           dec(euixShow);
    135         assert(euixShow >= 0);
     134          Dec(euixShow);
     135        Assert(euixShow >= 0);
    136136      end;
    137137      with MyRO.EnemyUn[euixShow] do
     
    148148      ecixShow := MyRO.nEnemyCity - 1;
    149149      while (ecixShow >= 0) and (MyRO.EnemyCity[ecixShow].Loc <> UnitLoc) do
    150         dec(ecixShow);
    151       assert(ecixShow >= 0);
     150        Dec(ecixShow);
     151      Assert(ecixShow >= 0);
    152152    end;
    153153  end;
     
    178178  end;
    179179
    180   SwitchBtn.Visible := not supervising and (Kind = dkOwnModel);
    181   ConscriptsBtn.Visible := not supervising and (Kind = dkOwnModel) and
     180  SwitchBtn.Visible := not Supervising and (Kind = dkOwnModel);
     181  ConscriptsBtn.Visible := not Supervising and (Kind = dkOwnModel) and
    182182    (MyRO.Tech[adConscription] >= tsApplicable) and
    183183    (MyModel[mixShow].Domain = dGround) and (MyModel[mixShow].Kind < mkScout);
    184   IsSpecialUnit := false;
     184  IsSpecialUnit := False;
    185185  if Kind in [dkEnemyCity, dkEnemyCityDefense] then
    186186    Caption := CityName(MyRO.EnemyCity[ecixShow].ID)
     
    190190      dkOwnModel:
    191191        begin
    192           owner := me;
     192          owner := Me;
    193193          mix := mixShow;
    194194          IsSpecialUnit := MyModel[mix].Kind >= $10;
     
    196196      dkOwnUnit:
    197197        begin
    198           owner := me;
     198          owner := Me;
    199199          mix := MyUn[uixShow].mix;
    200200          IsSpecialUnit := MyModel[mix].Kind >= $10;
     
    218218end;
    219219
    220 procedure TUnitStatDlg.ShowNewContent_OwnModel(NewMode: TWindowMode; mix: integer);
     220procedure TUnitStatDlg.ShowNewContent_OwnModel(NewMode: TWindowMode; mix: Integer);
    221221begin
    222222  Kind := dkOwnModel;
     
    225225end;
    226226
    227 procedure TUnitStatDlg.ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: integer);
     227procedure TUnitStatDlg.ShowNewContent_OwnUnit(NewMode: TWindowMode; uix: Integer);
    228228begin
    229229  Kind := dkOwnUnit;
     
    232232end;
    233233
    234 procedure TUnitStatDlg.ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: integer);
     234procedure TUnitStatDlg.ShowNewContent_EnemyUnit(NewMode: TWindowMode; euix: Integer);
    235235begin
    236236  Kind := dkEnemyUnit;
     
    240240end;
    241241
    242 procedure TUnitStatDlg.ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: integer);
     242procedure TUnitStatDlg.ShowNewContent_EnemyLoc(NewMode: TWindowMode; Loc: Integer);
    243243begin
    244244  Kind := dkEnemyUnit;
     
    248248end;
    249249
    250 procedure TUnitStatDlg.ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: integer);
     250procedure TUnitStatDlg.ShowNewContent_EnemyModel(NewMode: TWindowMode; emix: Integer);
    251251begin
    252252  Kind := dkEnemyModel;
     
    255255end;
    256256
    257 procedure TUnitStatDlg.ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: integer);
     257procedure TUnitStatDlg.ShowNewContent_EnemyCity(NewMode: TWindowMode; Loc: Integer);
    258258begin
    259259  if MyMap[Loc] and fUnit <> 0 then
     
    286286  PPicture: ^TModelPicture;
    287287
    288   function IsToCount(emix: integer): boolean;
     288  function IsToCount(emix: Integer): Boolean;
    289289  var
    290290    PTestPicture: ^TModelPicture;
     
    294294      PTestPicture := @Tribe[MyRO.EnemyModel[emix].owner].ModelPicture
    295295        [MyRO.EnemyModel[emix].mix];
    296       result := (PPicture.HGr = PTestPicture.HGr) and
     296      Result := (PPicture.HGr = PTestPicture.HGr) and
    297297        (PPicture.pix = PTestPicture.pix) and
    298298        (ModelHash(mox^) = ModelHash(MyRO.EnemyModel[emix]));
    299299    end
    300300    else
    301       result := (MyRO.EnemyModel[emix].owner = mox.owner) and
     301      Result := (MyRO.EnemyModel[emix].owner = mox.owner) and
    302302        (MyRO.EnemyModel[emix].mix = mox.mix);
    303303  end;
    304304
    305   procedure FeatureBar(dst: TBitmap; x, y: integer; const mi: TModelInfo;
     305  procedure FeatureBar(dst: TBitmap; X, Y: Integer; const mi: TModelInfo;
    306306    T: TTexture);
    307307  var
    308     i, w, dx, num: integer;
    309     s: string;
    310   begin
    311     DarkGradient(dst.Canvas, x - 6, y + 1, 180, 1);
     308    I, W, dx, num: Integer;
     309    S: string;
     310  begin
     311    DarkGradient(dst.Canvas, X - 6, Y + 1, 180, 1);
    312312    with dst.Canvas do
    313313      if mi.Kind >= $10 then
    314314      begin
    315         s := Phrases.Lookup('UNITSPECIAL');
     315        S := Phrases.Lookup('UNITSPECIAL');
    316316        Font.Color := $000000;
    317         Textout(x - 1, y + 1, s);
     317        Textout(X - 1, Y + 1, S);
    318318        Font.Color := $B0B0B0;
    319         Textout(x - 2, y, s);
     319        Textout(X - 2, Y, S);
    320320      end
    321321      else
     
    323323        Font.Color := $000000;
    324324        dx := 2;
    325         for i := 3 to nFeature - 1 do
     325        for I := 3 to nFeature - 1 do
    326326        begin
    327327          num := 0;
    328           case i of
     328          case I of
    329329            mcSeaTrans:
    330330              if mi.Domain = dSea then
     
    342342                num := mi.TTrans;
    343343            mcFirstNonCap .. nFeature - 1:
    344               if mi.Cap and (1 shl (i - mcFirstNonCap)) <> 0 then
     344              if mi.Cap and (1 shl (I - mcFirstNonCap)) <> 0 then
    345345                num := 1
    346346          end;
    347347          if (num > 0) and
    348             ((i <> mcSE) or (mi.Cap and (1 shl (mcNP - mcFirstNonCap)) = 0))
     348            ((I <> mcSE) or (mi.Cap and (1 shl (mcNP - mcFirstNonCap)) = 0))
    349349          then
    350350          begin
    351351            if num > 1 then
    352352            begin
    353               s := IntToStr(num);
    354               w := TextWidth(s);
     353              S := IntToStr(num);
     354              W := TextWidth(S);
    355355              Brush.Color := $FFFFFF;
    356               FillRect(Rect(x - 3 + dx, y + 2, x + w - 1 + dx, y + 16));
     356              FillRect(Rect(X - 3 + dx, Y + 2, X + W - 1 + dx, Y + 16));
    357357              Brush.Style := bsClear;
    358               Textout(x - 3 + dx + 1, y, s);
    359               inc(dx, w + 1)
     358              Textout(X - 3 + dx + 1, Y, S);
     359              Inc(dx, W + 1)
    360360            end;
    361361            Brush.Color := $C0C0C0;
    362             FrameRect(Rect(x - 3 + dx, y + 2, x + 11 + dx, y + 16));
     362            FrameRect(Rect(X - 3 + dx, Y + 2, X + 11 + dx, Y + 16));
    363363            Brush.Style := bsClear;
    364             Sprite(dst, HGrSystem, x - 1 + dx, y + 4, 10, 10,
    365               66 + i mod 11 * 11, 137 + i div 11 * 11);
    366             inc(dx, 15)
     364            Sprite(dst, HGrSystem, X - 1 + dx, Y + 4, 10, 10,
     365              66 + I mod 11 * 11, 137 + I div 11 * 11);
     366            Inc(dx, 15)
    367367          end;
    368368        end;
     
    370370  end; { featurebar }
    371371
    372   procedure NumberBarS(dst: TBitmap; x, y: integer; Cap, s: string; T: TTexture);
    373   begin
    374     DLine(dst.Canvas, x - 2, x + 170, y + 16, T.ColorBevelShade, T.ColorBevelLight);
    375     LoweredTextOut(dst.Canvas, -1, T, x - 2, y, Cap);
    376     RisedTextout(dst.Canvas, x + 170 - BiColorTextWidth(dst.Canvas, s), y, s);
     372  procedure NumberBarS(dst: TBitmap; X, Y: Integer; Cap, S: string; T: TTexture);
     373  begin
     374    DLine(dst.Canvas, X - 2, X + 170, Y + 16, T.ColorBevelShade, T.ColorBevelLight);
     375    LoweredTextOut(dst.Canvas, -1, T, X - 2, Y, Cap);
     376    RisedTextout(dst.Canvas, X + 170 - BiColorTextWidth(dst.Canvas, S), Y, S);
    377377  end;
    378378
    379379var
    380   i, j, x, y, cix, uix, emix, InProd, Available, Destroyed, Loc, Cnt, yView,
    381     yTotal, yCaption: integer;
    382   s: string;
     380  I, J, X, Y, cix, uix, emix, InProd, Available, Destroyed, Loc, Cnt, yView,
     381    yTotal, yCaption: Integer;
     382  S: string;
    383383  ui: TUnitInfo;
    384384  mi: TModelInfo;
     
    389389    dkOwnModel:
    390390      begin
    391         BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hOwnModel,
     391        BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hOwnModel,
    392392          Back.Canvas, 0, 0);
    393393        yView := 13;
     
    396396    dkEnemyModel:
    397397      begin
    398         BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyModel,
     398        BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyModel,
    399399          Back.Canvas, wCommon, 0);
    400400        yView := 13;
     
    403403    dkEnemyUnit, dkOwnUnit:
    404404      begin
    405         BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyUnit,
     405        BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyUnit,
    406406          Back.Canvas, 2 * wCommon, 0);
    407407        yView := 13;
     
    410410    dkEnemyCityDefense:
    411411      begin
    412         BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyCityDefense,
     412        BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyCityDefense,
    413413          Back.Canvas, 3 * wCommon, 0);
    414414        yView := 171;
     
    417417    dkEnemyCity:
    418418      begin
    419         BitBltCanvas(offscreen.Canvas, 0, 0, wCommon, hEnemyCity,
     419        BitBltCanvas(Offscreen.Canvas, 0, 0, wCommon, hEnemyCity,
    420420          Back.Canvas, 4 * wCommon, 0);
    421421      end;
     
    427427  begin // show city defense facilities
    428428    Cnt := 0;
    429     for i := 0 to 3 do
    430       if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then
    431         inc(Cnt);
    432     x := (wCommon - Cnt * xSizeSmall) div 2 - (Cnt - 1) * 2;
    433     for i := 0 to 3 do
    434       if MyRO.EnemyCity[ecixShow].Flags and (2 shl i) <> 0 then
    435       begin
    436         case i of
    437           0: j := imWalls;
    438           1: j := imCoastalFort;
    439           2: j := imMissileBat;
    440           3: j := imBunker
     429    for I := 0 to 3 do
     430      if MyRO.EnemyCity[ecixShow].Flags and (2 shl I) <> 0 then
     431        Inc(Cnt);
     432    X := (wCommon - Cnt * xSizeSmall) div 2 - (Cnt - 1) * 2;
     433    for I := 0 to 3 do
     434      if MyRO.EnemyCity[ecixShow].Flags and (2 shl I) <> 0 then
     435      begin
     436        case I of
     437          0: J := imWalls;
     438          1: J := imCoastalFort;
     439          2: J := imMissileBat;
     440          3: J := imBunker
    441441        end;
    442         Frame(offscreen.Canvas, x - 1, yImp - 1, x + xSizeSmall,
     442        Frame(Offscreen.Canvas, X - 1, yImp - 1, X + xSizeSmall,
    443443          yImp + ySizeSmall, MainTexture.ColorBevelLight,
    444444          MainTexture.ColorBevelShade);
    445         BitBltCanvas(offscreen.Canvas, x, yImp, xSizeSmall, ySizeSmall,
    446           SmallImp.Canvas, j mod 7 * xSizeSmall,
    447           (j + SystemIconLines * 7) div 7 * ySizeSmall);
    448         inc(x, xSizeSmall + 4);
     445        BitBltCanvas(Offscreen.Canvas, X, yImp, xSizeSmall, ySizeSmall,
     446          SmallImp.Canvas, J mod 7 * xSizeSmall,
     447          (J + SystemIconLines * 7) div 7 * ySizeSmall);
     448        Inc(X, xSizeSmall + 4);
    449449      end;
    450450  end;
     
    454454    PPicture := @Tribe[mox.owner].ModelPicture[mox.mix];
    455455    Available := 0;
    456     if G.Difficulty[me] = 0 then // supervisor -- count stacked units too
     456    if G.Difficulty[Me] = 0 then // supervisor -- count stacked units too
    457457      for Loc := 0 to G.lx * G.ly - 1 do
    458458      begin
    459459        if MyMap[Loc] and fUnit <> 0 then
    460460        begin
    461           Server(sGetUnits, me, Loc, Cnt);
     461          Server(sGetUnits, Me, Loc, Cnt);
    462462          for uix := 0 to Cnt - 1 do
    463463            if IsToCount(MyRO.EnemyUn[MyRO.nEnemyUn + uix].emix) then
    464               inc(Available);
     464              Inc(Available);
    465465        end;
    466466      end
     
    469469        if (MyRO.EnemyUn[uix].Loc >= 0) and IsToCount(MyRO.EnemyUn[uix].emix)
    470470        then
    471           inc(Available);
     471          Inc(Available);
    472472    Destroyed := 0;
    473473    for emix := 0 to MyRO.nEnemyModel - 1 do
    474474      if IsToCount(emix) then
    475         inc(Destroyed, MyRO.EnemyModel[emix].Lost);
     475        Inc(Destroyed, MyRO.EnemyModel[emix].Lost);
    476476  end
    477477  else
     
    480480    for uix := 0 to MyRO.nUn - 1 do
    481481      if (MyUn[uix].Loc >= 0) and (MyUn[uix].mix = mixShow) then
    482         inc(Available);
     482        Inc(Available);
    483483    InProd := 0;
    484484    for cix := 0 to MyRO.nCity - 1 do
    485485      if (MyCity[cix].Loc >= 0) and
    486486        (MyCity[cix].Project and (cpImp + cpIndex) = mixShow) then
    487         inc(InProd);
    488   end;
    489 
    490   offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
     487        Inc(InProd);
     488  end;
     489
     490  Offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    491491  if Kind in [dkEnemyCityDefense, dkEnemyCity] then
    492492  begin
    493     NoMap.SetOutput(offscreen);
    494     NoMap.PaintCity(ClientWidth div 2, 53, MyRO.EnemyCity[ecixShow], false);
    495 
    496     s := Tribe[MyRO.EnemyCity[ecixShow].owner].TPhrase('UNITOWNER');
    497     LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    498       (ClientWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2, 105, s);
     493    NoMap.SetOutput(Offscreen);
     494    NoMap.PaintCity(ClientWidth div 2, 53, MyRO.EnemyCity[ecixShow], False);
     495
     496    S := Tribe[MyRO.EnemyCity[ecixShow].owner].TPhrase('UNITOWNER');
     497    LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     498      (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2, 105, S);
    499499  end;
    500500
     
    502502  begin // show unit stats
    503503    if Kind = dkOwnModel then
    504       MakeModelInfo(me, mixShow, MyModel[mixShow], mi)
     504      MakeModelInfo(Me, mixShow, MyModel[mixShow], mi)
    505505    else if Kind = dkOwnUnit then
    506506    begin
    507       MakeUnitInfo(me, MyUn[uixShow], ui);
    508       MakeModelInfo(me, MyUn[uixShow].mix, MyModel[MyUn[uixShow].mix], mi);
     507      MakeUnitInfo(Me, MyUn[uixShow], ui);
     508      MakeModelInfo(Me, MyUn[uixShow].mix, MyModel[MyUn[uixShow].mix], mi);
    509509    end
    510510    else
     
    522522          { Frame(offscreen.canvas,xView-1,yView-1,xView+64,yView+48,
    523523            MainTexture.ColorBevelShade,MainTexture.ColorBevelLight);
    524             RFrame(offscreen.canvas,xView-2,yView-2,xView+65,yView+49,
     524            RFrame(Offscreen.Canvas,xView-2,yView-2,xView+65,yView+49,
    525525            MainTexture.ColorBevelShade,MainTexture.ColorBevelLight); }
    526           with offscreen.Canvas do
     526          with Offscreen.Canvas do
    527527          begin
    528528            Brush.Color := HGrSystem.Data.Canvas.Pixels[98, 67];
    529             offscreen.Canvas.FillRect(Rect(xView, yView, xView + 64,
     529            Offscreen.Canvas.FillRect(Rect(xView, yView, xView + 64,
    530530              yView + 16));
    531531            Brush.Style := bsClear;
     
    534534          if MyMap[Loc] and fTerrain >= fForest then
    535535          begin
    536             x := 1 + 2 * (xxt * 2 + 1);
    537             y := 1 + yyt + 2 * (yyt * 3 + 1);
     536            X := 1 + 2 * (xxt * 2 + 1);
     537            Y := 1 + yyt + 2 * (yyt * 3 + 1);
    538538          end
    539539          else
    540540          begin
    541             x := integer(MyMap[Loc] and fTerrain) * (xxt * 2 + 1) + 1;
    542             y := 1 + yyt;
     541            X := Integer(MyMap[Loc] and fTerrain) * (xxt * 2 + 1) + 1;
     542            Y := 1 + yyt;
    543543          end;
    544           for j := -1 to 1 do
    545             for i := -1 to 1 do
    546               if (i + j) and 1 = 0 then
     544          for J := -1 to 1 do
     545            for I := -1 to 1 do
     546              if (I + J) and 1 = 0 then
    547547              begin
    548                 Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2,
    549                   yyt * 2, x, y);
     548                Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2,
     549                  yyt * 2, X, Y);
    550550                if MyMap[Loc] and (fTerrain or fSpecial) = fGrass or fSpecial1
    551551                then
    552                   Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
     552                  Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2,
    553553                    1 + 2 * (xxt * 2 + 1), 1 + yyt + 1 * (yyt * 3 + 1))
    554554                else if (MyMap[Loc] and fTerrain = fForest) and
    555555                  IsJungle(Loc div G.lx) then
    556                   Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
     556                  Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2,
    557557                    1 + 7 * (xxt * 2 + 1), 1 + yyt + 19 * (yyt * 3 + 1))
    558558                else if MyMap[Loc] and fTerrain >= fForest then
    559                   Sprite(Buffer, HGrTerrain, i * xxt, j * yyt, xxt * 2, yyt * 2,
     559                  Sprite(Buffer, HGrTerrain, I * xxt, J * yyt, xxt * 2, yyt * 2,
    560560                    1 + 7 * (xxt * 2 + 1),
    561                     1 + yyt + 2 * integer(2 + MyMap[Loc] and fTerrain - fForest)
     561                    1 + yyt + 2 * Integer(2 + MyMap[Loc] and fTerrain - fForest)
    562562                    * (yyt * 3 + 1));
    563563              end;
    564           BitBltCanvas(offscreen.Canvas, xView, yView + 16, 64, 32,
     564          BitBltCanvas(Offscreen.Canvas, xView, yView + 16, 64, 32,
    565565            Buffer.Canvas, 1, 0);
    566566
    567567          // show unit, experience and health
    568           Sprite(offscreen, HGr, xView, yView, 64, 48, pix mod 10 * 65 + 1,
     568          Sprite(Offscreen, HGr, xView, yView, 64, 48, pix mod 10 * 65 + 1,
    569569            pix div 10 * 49 + 1);
    570570          if Flags and unFortified <> 0 then
    571             Sprite(offscreen, HGrStdUnits, xView, yView, xxu * 2, yyu * 2,
     571            Sprite(Offscreen, HGrStdUnits, xView, yView, xxu * 2, yyu * 2,
    572572              1 + 6 * (xxu * 2 + 1), 1);
    573           FrameImage(offscreen.Canvas, HGrSystem.Data, xView - 20,
     573          FrameImage(Offscreen.Canvas, HGrSystem.Data, xView - 20,
    574574            yView + 5, 12, 14, 121 + Exp div ExpCost * 13, 28);
    575575          if Health < 100 then
    576576          begin
    577             s := IntToStr(Health) + '%';
    578             LightGradient(offscreen.Canvas, xView - 45, yView + 24, 38,
     577            S := IntToStr(Health) + '%';
     578            LightGradient(Offscreen.Canvas, xView - 45, yView + 24, 38,
    579579              (ColorOfHealth(Health) and $FEFEFE shr 2) * 3);
    580             RisedTextout(offscreen.Canvas, xView - 45 + 20 -
    581               BiColorTextWidth(offscreen.Canvas, s) div 2, yView + 23, s);
     580            RisedTextout(Offscreen.Canvas, xView - 45 + 20 -
     581              BiColorTextWidth(Offscreen.Canvas, S) div 2, yView + 23, S);
    582582          end;
    583583
    584584          if Kind = dkEnemyUnit then
    585585          begin
    586             s := Tribe[mox.owner].TPhrase('UNITOWNER');
    587             LoweredTextOut(offscreen.Canvas, -1, MainTexture,
    588               (ClientWidth - BiColorTextWidth(offscreen.Canvas, s)) div 2,
    589               yView + 80, s);
     586            S := Tribe[mox.owner].TPhrase('UNITOWNER');
     587            LoweredTextOut(Offscreen.Canvas, -1, MainTexture,
     588              (ClientWidth - BiColorTextWidth(Offscreen.Canvas, S)) div 2,
     589              yView + 80, S);
    590590          end;
    591591        end
    592592      else
    593593      begin
    594         FrameImage(offscreen.Canvas, BigImp, xView + 4, yView, 56, 40, 0, 0);
    595         Sprite(offscreen, HGr, xView, yView - 4, 64, 44, pix mod 10 * 65 + 1,
     594        FrameImage(Offscreen.Canvas, BigImp, xView + 4, yView, 56, 40, 0, 0);
     595        Sprite(Offscreen, HGr, xView, yView - 4, 64, 44, pix mod 10 * 65 + 1,
    596596          pix div 10 * 49 + 1);
    597597      end;
    598598
    599       DarkGradient(offscreen.Canvas, xTotal - 6, yTotal + 1, 180, 2);
    600       RisedTextout(offscreen.Canvas, xTotal - 2, yTotal,
     599      DarkGradient(Offscreen.Canvas, xTotal - 6, yTotal + 1, 180, 2);
     600      RisedTextout(Offscreen.Canvas, xTotal - 2, yTotal,
    601601        Phrases.Lookup('UNITSTRENGTH'));
    602       s := IntToStr(mi.Attack) + '/' + IntToStr(mi.Defense);
    603       RisedTextout(offscreen.Canvas,
    604         xTotal + 170 - BiColorTextWidth(offscreen.Canvas, s), yTotal, s);
    605       FeatureBar(offscreen, xTotal, yTotal + 19, mi, MainTexture);
    606       NumberBarS(offscreen, xTotal, yTotal + 38, Phrases.Lookup('UNITSPEED'),
     602      S := IntToStr(mi.Attack) + '/' + IntToStr(mi.Defense);
     603      RisedTextout(Offscreen.Canvas,
     604        xTotal + 170 - BiColorTextWidth(Offscreen.Canvas, S), yTotal, S);
     605      FeatureBar(Offscreen, xTotal, yTotal + 19, mi, MainTexture);
     606      NumberBarS(Offscreen, xTotal, yTotal + 38, Phrases.Lookup('UNITSPEED'),
    607607        MovementToString(mi.Speed), MainTexture);
    608       LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2, yTotal + 57,
     608      LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2, yTotal + 57,
    609609        Phrases.Lookup('UNITCOST'));
    610       DLine(offscreen.Canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16,
     610      DLine(Offscreen.Canvas, xTotal - 2, xTotal + 170, yTotal + 57 + 16,
    611611        MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    612       if G.Difficulty[me] = 0 then
    613         s := IntToStr(mi.cost)
     612      if G.Difficulty[Me] = 0 then
     613        S := IntToStr(mi.cost)
    614614      else
    615         s := IntToStr(mi.cost * BuildCostMod[G.Difficulty[me]] div 12);
    616       RisedTextout(offscreen.Canvas,
    617         xTotal + 159 - BiColorTextWidth(offscreen.Canvas, s), yTotal + 57, s);
    618       Sprite(offscreen, HGrSystem, xTotal + 160, yTotal + 57 + 5, 10,
     615        S := IntToStr(mi.cost * BuildCostMod[G.Difficulty[Me]] div 12);
     616      RisedTextout(Offscreen.Canvas,
     617        xTotal + 159 - BiColorTextWidth(Offscreen.Canvas, S), yTotal + 57, S);
     618      Sprite(Offscreen, HGrSystem, xTotal + 160, yTotal + 57 + 5, 10,
    619619        10, 88, 115);
    620620
     
    624624        begin
    625625          if MyModel[mixShow].Kind = mkEnemyDeveloped then
    626             LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2,
     626            LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2,
    627627              (yTotal + StatDown - 19), Phrases.Lookup('UNITADOPT'))
    628628          else
    629             LoweredTextOut(offscreen.Canvas, -1, MainTexture, xTotal - 2,
     629            LoweredTextOut(Offscreen.Canvas, -1, MainTexture, xTotal - 2,
    630630              (yTotal + StatDown - 19), Phrases.Lookup('UNITINTRO'));
    631           DLine(offscreen.Canvas, xTotal - 2, xTotal + 170,
     631          DLine(Offscreen.Canvas, xTotal - 2, xTotal + 170,
    632632            (yTotal + StatDown - 19) + 16, MainTexture.ColorTextShade,
    633633            MainTexture.ColorTextLight);
    634           s := TurnToString(MyModel[mixShow].IntroTurn);
    635           RisedTextout(offscreen.Canvas,
    636             xTotal + 170 - BiColorTextWidth(offscreen.Canvas, s),
    637             (yTotal + StatDown - 19), s);
     634          S := TurnToString(MyModel[mixShow].IntroTurn);
     635          RisedTextout(Offscreen.Canvas,
     636            xTotal + 170 - BiColorTextWidth(Offscreen.Canvas, S),
     637            (yTotal + StatDown - 19), S);
    638638        end;
    639639
    640         NumberBar(offscreen, xTotal, yTotal + StatDown,
     640        NumberBar(Offscreen, xTotal, yTotal + StatDown,
    641641          Phrases.Lookup('UNITBUILT'), MyModel[mixShow].Built, MainTexture);
    642642        if MyModel[mixShow].Lost > 0 then
    643           NumberBar(offscreen, xTotal, yTotal + StatDown + 19,
     643          NumberBar(Offscreen, xTotal, yTotal + StatDown + 19,
    644644            Phrases.Lookup('UNITLOST'), MyModel[mixShow].Lost, MainTexture);
    645645        if InProd > 0 then
    646           NumberBar(offscreen, xTotal, yTotal + StatDown + 57,
     646          NumberBar(Offscreen, xTotal, yTotal + StatDown + 57,
    647647            Phrases.Lookup('UNITINPROD'), InProd, MainTexture);
    648648        if Available > 0 then
    649           NumberBar(offscreen, xTotal, yTotal + StatDown + 38,
     649          NumberBar(Offscreen, xTotal, yTotal + StatDown + 38,
    650650            Phrases.Lookup('UNITAVAILABLE'), Available, MainTexture);
    651651
     
    674674      begin
    675675        if Destroyed > 0 then
    676           NumberBar(offscreen, xTotal, yTotal + StatDown - 19,
     676          NumberBar(Offscreen, xTotal, yTotal + StatDown - 19,
    677677            Phrases.Lookup('UNITDESTROYED'), Destroyed, MainTexture);
    678678        if Available > 0 then
    679           NumberBar(offscreen, xTotal, yTotal + StatDown,
     679          NumberBar(Offscreen, xTotal, yTotal + StatDown,
    680680            Phrases.Lookup('UNITKNOWN'), Available, MainTexture);
    681681      end;
     
    683683  end;
    684684
    685   offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
     685  Offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    686686  case Kind of
    687687    dkOwnModel, dkEnemyModel:
     
    692692      yCaption := 79;
    693693  end;
    694   RisedTextout(offscreen.Canvas,
    695     (ClientWidth - BiColorTextWidth(offscreen.Canvas, Caption)) div 2,
     694  RisedTextout(Offscreen.Canvas,
     695    (ClientWidth - BiColorTextWidth(Offscreen.Canvas, Caption)) div 2,
    696696    yCaption, Caption);
    697697end;
  • trunk/LocalPlayer/Wonders.pas

    r442 r447  
    2323    Selection: Integer;
    2424    Center: TPoint;
    25     procedure DarkIcon(i: Integer);
    26     procedure Glow(i, GlowColor: Integer);
     25    procedure DarkIcon(I: Integer);
     26    procedure Glow(I, GlowColor: Integer);
    2727    procedure PaintBackgroundShape;
    2828  public
     
    116116  for Y := 0 to Height - 1 do begin
    117117    for X := 0 to Width - 1 do begin
    118       r := X * X * ((Height div 4) * (Height div 4)) + Y * Y * ((Width div 4) * (Width div 4));
     118      R := X * X * ((Height div 4) * (Height div 4)) + Y * Y * ((Width div 4) * (Width div 4));
    119119      ax := ((1 shl 16 div (Height div 4)) * (Width div 4)) * Y;
    120       if (r < ScaleToNative(8) * Height * Width * Width) and
    121         ((r >= (Height div 4) * (Height div 2) * (Width div 2) * (Width div 2)) and (ax < amax2 * X) and
     120      if (R < ScaleToNative(8) * Height * Width * Width) and
     121        ((R >= (Height div 4) * (Height div 2) * (Width div 2) * (Width div 2)) and (ax < amax2 * X) and
    122122        ((ax < amax0 * X) or (ax > amin2 * X)) or (ax > amin1 * X) and
    123123        ((ax < amax1 * X) or (ax > amin3 * X))) then begin
    124124        for ch := 0 to 2 do begin
    125           c := Line[0].Pixel^.Planes[ch] - Darken;
    126           if c < 0 then Line[0].Pixel^.Planes[ch] := 0
    127             else Line[0].Pixel^.Planes[ch] := c;
    128           c := Line[1].Pixel^.Planes[ch] - Darken;
    129           if c < 0 then Line[1].Pixel^.Planes[ch] := 0
    130             else Line[1].Pixel^.Planes[ch] := c;
    131           c := Line[2].Pixel^.Planes[ch] - Darken;
    132           if c < 0 then Line[2].Pixel^.Planes[ch] := 0
    133             else Line[2].Pixel^.Planes[ch] := c;
    134           c := Line[3].Pixel^.Planes[ch] - Darken;
    135           if c < 0 then Line[3].Pixel^.Planes[ch] := 0
    136             else Line[3].Pixel^.Planes[ch] := c;
     125          C := Line[0].Pixel^.Planes[ch] - Darken;
     126          if C < 0 then Line[0].Pixel^.Planes[ch] := 0
     127            else Line[0].Pixel^.Planes[ch] := C;
     128          C := Line[1].Pixel^.Planes[ch] - Darken;
     129          if C < 0 then Line[1].Pixel^.Planes[ch] := 0
     130            else Line[1].Pixel^.Planes[ch] := C;
     131          C := Line[2].Pixel^.Planes[ch] - Darken;
     132          if C < 0 then Line[2].Pixel^.Planes[ch] := 0
     133            else Line[2].Pixel^.Planes[ch] := C;
     134          C := Line[3].Pixel^.Planes[ch] - Darken;
     135          if C < 0 then Line[3].Pixel^.Planes[ch] := 0
     136            else Line[3].Pixel^.Planes[ch] := C;
    137137        end;
    138138      end;
     
    150150end;
    151151
    152 procedure TWondersDlg.DarkIcon(i: Integer);
    153 var
    154   X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, c: Integer;
     152procedure TWondersDlg.DarkIcon(I: Integer);
     153var
     154  X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, C: Integer;
    155155  Src, Dst: TPixelPointer;
    156156begin
    157157  Offscreen.BeginUpdate;
    158   x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X;
    159   y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y;
    160   x0Src := (i mod 7) * xSizeBig;
    161   y0Src := (i div 7 + SystemIconLines) * ySizeBig;
     158  x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[I].X;
     159  y0Dst := ClientHeight div 2 - ySizeBig div 2 + RingPosition[I].Y;
     160  x0Src := (I mod 7) * xSizeBig;
     161  y0Src := (I div 7 + SystemIconLines) * ySizeBig;
    162162  Src := PixelPointer(BigImp, ScaleToNative(x0Src), ScaleToNative(y0Src));
    163163  Dst := PixelPointer(Offscreen, ScaleToNative(x0Dst), ScaleToNative(y0Dst));
     
    167167        15 + (255 - Src.Pixel^.R) * 9) div 128;
    168168      for ch := 0 to 2 do begin
    169         c := Dst.Pixel^.Planes[ch] - Darken;
    170         if c < 0 then Dst.Pixel^.Planes[ch] := 0
    171           else Dst.Pixel^.Planes[ch] := c;
     169        C := Dst.Pixel^.Planes[ch] - Darken;
     170        if C < 0 then Dst.Pixel^.Planes[ch] := 0
     171          else Dst.Pixel^.Planes[ch] := C;
    172172      end;
    173173      Src.NextPixel;
     
    180180end;
    181181
    182 procedure TWondersDlg.Glow(i, GlowColor: Integer);
     182procedure TWondersDlg.Glow(I, GlowColor: Integer);
    183183begin
    184184  GlowFrame(Offscreen,
    185     ClientWidth div 2 - xSizeBig div 2 + RingPosition[i].X,
    186     ClientHeight div 2 - ySizeBig div 2 + RingPosition[i].Y,
     185    ClientWidth div 2 - xSizeBig div 2 + RingPosition[I].X,
     186    ClientHeight div 2 - ySizeBig div 2 + RingPosition[I].Y,
    187187    xSizeBig, ySizeBig, GlowColor);
    188188end;
  • trunk/Log.pas

    r442 r447  
    2727    procedure mClearClick(Sender: TObject);
    2828    procedure mSlotClick(Sender: TObject);
    29     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     29    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    3030    procedure Toggle(Sender: TObject);
    3131    procedure ListMouseDown(Sender: TObject; Button: TMouseButton;
    3232      Shift: TShiftState; X, Y: Integer);
    33     procedure FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
     33    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    3434  public
    3535    Host: TForm;
    36     procedure Add(Level, Turn: Integer; Text: pchar);
     36    procedure Add(Level, Turn: Integer; Text: PChar);
    3737  private
    3838    MaxLevel: Integer;
     
    6161begin
    6262  MaxLevel := TMenuItem(Sender).Tag;
    63   TMenuItem(Sender).Checked := true;
     63  TMenuItem(Sender).Checked := True;
    6464end;
    6565
    66 procedure TLogDlg.Add(Level, Turn: Integer; Text: pchar);
     66procedure TLogDlg.Add(Level, Turn: Integer; Text: PChar);
    6767begin
    6868  if (MaxLevel > 0) and (Level <= MaxLevel) or (Level = 1 shl 16 + 1) and
     
    8989var
    9090  X, Y: Integer;
    91   s: string;
     91  S: string;
    9292begin
    9393  for Y := 0 to 2 do
    9494  begin
    95     s := '| ';
     95    S := '| ';
    9696    for X := 0 to 2 do
    9797      if G.Difficulty[SlotNo[Y, X]] = 0 then
    98         s := s + 'SUP |'
     98        S := S + 'SUP |'
    9999      else if G.Difficulty[SlotNo[Y, X]] < 0 then
    100         s := s + '--- |'
     100        S := S + '--- |'
    101101      else
    102102      begin
     
    104104        begin // check multi control
    105105          if G.Difficulty[SlotNo[Y, X] + 3] >= 0 then
    106             s := s + Tribe[SlotNo[Y, X] + 3].TPhrase('SHORTNAME') + '+';
     106            S := S + Tribe[SlotNo[Y, X] + 3].TPhrase('SHORTNAME') + '+';
    107107          if G.Difficulty[SlotNo[Y, X] + 6] >= 0 then
    108             s := s + Tribe[SlotNo[Y, X] + 6].TPhrase('SHORTNAME') + '+';
     108            S := S + Tribe[SlotNo[Y, X] + 6].TPhrase('SHORTNAME') + '+';
    109109        end;
    110         s := s + Tribe[SlotNo[Y, X]].TPhrase('SHORTNAME') + ' | ';
     110        S := S + Tribe[SlotNo[Y, X]].TPhrase('SHORTNAME') + ' | ';
    111111      end;
    112     List.Lines.Add(s);
     112    List.Lines.Add(S);
    113113  end;
    114114  PostMessage(List.Handle, WM_VSCROLL, SB_BOTTOM, 0);
    115115end;
    116116
    117 procedure TLogDlg.FormKeyDown(Sender: TObject; var Key: word;
     117procedure TLogDlg.FormKeyDown(Sender: TObject; var Key: Word;
    118118  Shift: TShiftState);
    119119begin
     
    134134end;
    135135
    136 procedure TLogDlg.FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
     136procedure TLogDlg.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    137137begin
    138138  if Host <> nil then
  • trunk/Messg.pas

    r358 r447  
    5353procedure TMessgDlg.FormShow(Sender: TObject);
    5454begin
    55   Button1.Visible := true;
     55  Button1.Visible := True;
    5656  Button2.Visible := not(Kind in [mkOK]);
    5757  if Button2.Visible then
     
    7070  end;
    7171
    72   SplitText(true);
     72  SplitText(True);
    7373  CorrectHeight;
    7474end;
  • trunk/Network/UNetworkClient.pas

    r423 r447  
    176176end.
    177177
     178
  • trunk/Network/UNetworkCommon.pas

    r423 r447  
    4444end.
    4545
     46
  • trunk/Network/UNetworkServer.pas

    r424 r447  
    6969    ServerEventLoop: TEventLoop;
    7070    procedure ConnectExecute(Sender: TConnectionBasedSocket; AStream: TSocketStream);
    71     procedure Client(Command: TCommand; Player: integer; var Data);
     71    procedure Client(Command: TCommand; Player: Integer; var Data);
    7272  public
    7373    TCPServer: TTCPServer;
     
    8181{$ENDIF}
    8282
    83 procedure Client(Command, Player: integer; var Data); stdcall;
     83procedure Client(Command, Player: Integer; var Data); stdcall;
    8484
    8585
     
    9191{$ENDIF}
    9292
    93 procedure Client(Command, Player: integer; var Data);
     93procedure Client(Command, Player: Integer; var Data);
    9494begin
    9595  {$IFDEF UNIX}
     
    338338end.
    339339
     340
  • trunk/NoTerm.pas

    r442 r447  
    1818    procedure FormPaint(Sender: TObject);
    1919    procedure FormCreate(Sender: TObject);
    20     procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
     20    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    2121  public
    22     procedure Client(Command, Player: integer; var Data);
     22    procedure Client(Command, Player: Integer; var Data);
    2323  private
    2424    Me: Integer;
     
    4343    procedure NewStat;
    4444    procedure EndPlaying;
    45     procedure ShowActive(p: integer; Active: boolean);
     45    procedure ShowActive(P: Integer; Active: Boolean);
    4646    procedure ShowYear;
    4747  end;
     
    5050  NoTermDlg: TNoTermDlg;
    5151
    52 procedure Client(Command, Player: integer; var Data); stdcall;
     52procedure Client(Command, Player: Integer; var Data); stdcall;
    5353
    5454
     
    6969  dxBrain = 128;
    7070  dyBrain = 128;
    71   xBrain: array [0 .. nPlOffered - 1] of integer = (x0Brain, x0Brain,
     71  xBrain: array [0 .. nPlOffered - 1] of Integer = (x0Brain, x0Brain,
    7272    x0Brain + dxBrain, x0Brain + dxBrain, x0Brain + dxBrain, x0Brain,
    7373    x0Brain - dxBrain, x0Brain - dxBrain, x0Brain - dxBrain);
    74   yBrain: array [0 .. nPlOffered - 1] of integer = (y0Brain, y0Brain - dyBrain,
     74  yBrain: array [0 .. nPlOffered - 1] of Integer = (y0Brain, y0Brain - dyBrain,
    7575    y0Brain - dyBrain, y0Brain, y0Brain + dyBrain, y0Brain + dyBrain,
    7676    y0Brain + dyBrain, y0Brain, y0Brain - dyBrain);
    77   xActive: array [0 .. nPlOffered - 1] of integer = (0, 0, 36, 51, 36, 0,
     77  xActive: array [0 .. nPlOffered - 1] of Integer = (0, 0, 36, 51, 36, 0,
    7878    -36, -51, -36);
    79   yActive: array [0 .. nPlOffered - 1] of integer = (0, -51, -36, 0, 36, 51,
     79  yActive: array [0 .. nPlOffered - 1] of Integer = (0, -51, -36, 0, 36, 51,
    8080    36, 0, -36);
    8181
    8282var
    83   FormsCreated: boolean;
     83  FormsCreated: Boolean;
    8484
    8585procedure TNoTermDlg.FormCreate(Sender: TObject);
     
    108108procedure TNoTermDlg.EndPlaying;
    109109var
    110   EndCommand: integer;
     110  EndCommand: Integer;
    111111begin
    112112  NewStat;
    113   if G.RO[me].Turn > 0 then
     113  if G.RO[Me].Turn > 0 then
    114114    with MessgDlg do
    115115    begin
     
    127127end;
    128128
    129 procedure TNoTermDlg.ShowActive(p: integer; Active: boolean);
    130 begin
    131   if p < nPlOffered then
    132     Sprite(Canvas, HGrSystem, x0Brain + 28 + xActive[p],
    133       y0Brain + 28 + yActive[p], 8, 8, 81 + 9 * Byte(Active), 16);
     129procedure TNoTermDlg.ShowActive(P: Integer; Active: Boolean);
     130begin
     131  if P < nPlOffered then
     132    Sprite(Canvas, HGrSystem, x0Brain + 28 + xActive[P],
     133      y0Brain + 28 + yActive[P], 8, 8, 81 + 9 * Byte(Active), 16);
    134134end;
    135135
     
    138138  Fill(State.Canvas, 0, 0, 192, 20, 64, 287 + 138);
    139139  RisedTextOut(State.Canvas, 0, 0, Format(Phrases.Lookup('AIT_ROUND'), [Round])
    140     + ' ' + TurnToString(G.RO[me].Turn));
     140    + ' ' + TurnToString(G.RO[Me].Turn));
    141141  BitBltCanvas(Canvas, 64, 287 + 138, 192, 20, State.Canvas, 0, 0);
    142142end;
    143143
    144 procedure TNoTermDlg.Client(Command, Player: integer; var Data);
    145 var
    146   i, x, y, p: integer;
    147   ActiveDuration: extended;
    148   ShipComplete: boolean;
    149   r: TRect;
     144procedure TNoTermDlg.Client(Command, Player: Integer; var Data);
     145var
     146  I, X, Y, P: Integer;
     147  ActiveDuration: Extended;
     148  ShipComplete: Boolean;
     149  R: TRect;
    150150  nowt: TDateTime;
    151151begin
    152152  case Command of
    153153    cDebugMessage:
    154       LogDlg.Add(Player, G.RO[0].Turn, pchar(@Data));
     154      LogDlg.Add(Player, G.RO[0].Turn, PChar(@Data));
    155155
    156156    cInitModule:
     
    160160        Shade := TBitmap.Create;
    161161        Shade.SetSize(64, 64);
    162         for x := 0 to 63 do
    163           for y := 0 to 63 do
    164             if Odd(x + y) then
    165               Shade.Canvas.Pixels[x, y] := $FFFFFF
     162        for X := 0 to 63 do
     163          for Y := 0 to 63 do
     164            if Odd(X + Y) then
     165              Shade.Canvas.Pixels[X, Y] := $FFFFFF
    166166            else
    167               Shade.Canvas.Pixels[x, y] := $000000;
     167              Shade.Canvas.Pixels[X, Y] := $000000;
    168168        State := TBitmap.Create;
    169169        State.SetSize(192, 20);
     
    181181    cNewGame, cLoadGame:
    182182      begin
    183         inc(Round);
     183        Inc(Round);
    184184        if Mode = rmRunning then
    185185        begin
     
    190190          Show;
    191191        G := TNewGameData(Data);
    192         LogDlg.mSlot.Visible := false;
     192        LogDlg.mSlot.Visible := False;
    193193        LogDlg.Host := nil;
    194         ToldAlive := G.RO[me].Alive;
     194        ToldAlive := G.RO[Me].Alive;
    195195        Active := -1;
    196196        FillChar(DisallowShowActive, SizeOf(DisallowShowActive), 0); // false
     
    213213    cTurn, cResume, cContinue:
    214214      begin
    215         me := Player;
     215        Me := Player;
    216216        if Active >= 0 then
    217217        begin
    218           ShowActive(Active, false);
     218          ShowActive(Active, False);
    219219          Active := -1;
    220220        end; // should not happen
     
    228228        TurnTime := SecondOf(nowt - LastNewTurn);
    229229        LastNewTurn := nowt;
    230         if (G.RO[me].Alive <> ToldAlive) then
    231         begin
    232           for p := 1 to nPlOffered - 1 do
    233             if 1 shl p and (G.RO[me].Alive xor ToldAlive) <> 0 then
     230        if (G.RO[Me].Alive <> ToldAlive) then
     231        begin
     232          for P := 1 to nPlOffered - 1 do
     233            if 1 shl P and (G.RO[Me].Alive xor ToldAlive) <> 0 then
    234234            begin
    235               r := Rect(xBrain[p], yBrain[p] - 16, xBrain[p] + 64,
    236                 yBrain[p] - 16 + 64);
    237               InvalidateRect(Handle, @r, false);
     235              R := Rect(xBrain[P], yBrain[P] - 16, xBrain[P] + 64,
     236                yBrain[P] - 16 + 64);
     237              InvalidateRect(Handle, @R, False);
    238238            end;
    239           ToldAlive := G.RO[me].Alive;
     239          ToldAlive := G.RO[Me].Alive;
    240240        end;
    241241        Application.ProcessMessages;
    242242        if Mode = rmQuit then
    243243          EndPlaying
    244         else if G.RO[me].Happened and phGameEnd <> 0 then
     244        else if G.RO[Me].Happened and phGameEnd <> 0 then
    245245        begin // game ended, update statistics
    246           for p := 1 to nPlOffered - 1 do
    247             if Assigned(PlayersBrain[p]) then
    248               if 1 shl p and G.RO[me].Alive = 0 then
    249                 inc(ExtStat[p]) // extinct
    250               else if G.RO[me].Alive = 1 shl p then
    251                 inc(AloneStat[p]) // only player alive
     246          for P := 1 to nPlOffered - 1 do
     247            if Assigned(PlayersBrain[P]) then
     248              if 1 shl P and G.RO[Me].Alive = 0 then
     249                Inc(ExtStat[P]) // extinct
     250              else if G.RO[Me].Alive = 1 shl P then
     251                Inc(AloneStat[P]) // only player alive
    252252              else
    253253              begin // alive but not alone -- check colony ship
    254                 ShipComplete := true;
    255                 for i := 0 to nShipPart - 1 do
    256                   if G.RO[me].Ship[p].Parts[i] < ShipNeed[i] then
    257                     ShipComplete := false;
     254                ShipComplete := True;
     255                for I := 0 to nShipPart - 1 do
     256                  if G.RO[Me].Ship[P].Parts[I] < ShipNeed[I] then
     257                    ShipComplete := False;
    258258                if ShipComplete then
    259                   inc(WinStat[p]);
     259                  Inc(WinStat[P]);
    260260              end;
    261261          if Mode = rmRunning then
    262             Server(sNextRound, me, 0, nil^);
     262            Server(sNextRound, Me, 0, nil^);
    263263        end
    264264        else if Mode = rmRunning then
    265           Server(sTurn, me, 0, nil^);
     265          Server(sTurn, Me, 0, nil^);
    266266        if Mode = rmStop then
    267267        begin
     
    280280          TotalStatTime := TotalStatTime + ActiveDuration;
    281281          if not DisallowShowActive[Active] then
    282             ShowActive(Active, false);
     282            ShowActive(Active, False);
    283283          DisallowShowActive[Active] := (ActiveDuration < TurnTime * 0.25) and
    284284            (ActiveDuration < ShowActiveThreshold);
     
    286286        LastShowTurnChange := nowt;
    287287
    288         Active := integer(Data);
     288        Active := Integer(Data);
    289289        if (Active >= 0) and not DisallowShowActive[Active] then
    290           ShowActive(Active, true);
     290          ShowActive(Active, True);
    291291      end;
    292292  end;
     
    302302    GoBtn.ButtonIndex := 23;
    303303    GoBtn.Update;
    304     Server(sTurn, me, 0, nil^);
     304    Server(sTurn, Me, 0, nil^);
    305305  end;
    306306end;
     
    314314procedure TNoTermDlg.FormPaint(Sender: TObject);
    315315var
    316   i, TimeShare: integer;
     316  I, TimeShare: Integer;
    317317begin
    318318  Fill(Canvas, 3, 3, ClientWidth - 6, ClientHeight - 6, 0, 0);
     
    330330    7, Caption);
    331331  Canvas.Font.Assign(UniFont[ftSmall]);
    332   for i := 1 to nPlOffered - 1 do
    333     if Assigned(PlayersBrain[i]) then
     332  for I := 1 to nPlOffered - 1 do
     333    if Assigned(PlayersBrain[I]) then
    334334    begin
    335       Frame(Canvas, xBrain[i] - 24, yBrain[i] - 8 - 16, xBrain[i] - 24 + 111,
    336         yBrain[i] - 8 - 16 + 111, MainTexture.ColorBevelShade,
     335      Frame(Canvas, xBrain[I] - 24, yBrain[I] - 8 - 16, xBrain[I] - 24 + 111,
     336        yBrain[I] - 8 - 16 + 111, MainTexture.ColorBevelShade,
    337337        MainTexture.ColorBevelShade);
    338       FrameImage(Canvas, PlayersBrain[i].Picture, xBrain[i],
    339         yBrain[i] - 16, 64, 64, 0, 0);
    340       if 1 shl i and G.RO[me].Alive = 0 then
    341         BitBltCanvas(Canvas, xBrain[i], yBrain[i] - 16, 64, 64,
     338      FrameImage(Canvas, PlayersBrain[I].Picture, xBrain[I],
     339        yBrain[I] - 16, 64, 64, 0, 0);
     340      if 1 shl I and G.RO[Me].Alive = 0 then
     341        BitBltCanvas(Canvas, xBrain[I], yBrain[I] - 16, 64, 64,
    342342          Shade.Canvas, 0, 0, SRCAND);
    343       Sprite(Canvas, HGrSystem, xBrain[i] + 30 - 14, yBrain[i] + 53, 14,
     343      Sprite(Canvas, HGrSystem, xBrain[I] + 30 - 14, yBrain[I] + 53, 14,
    344344        14, 1, 316);
    345       RisedTextOut(Canvas, xBrain[i] + 30 - 16 - BiColorTextWidth(Canvas,
    346         IntToStr(WinStat[i])), yBrain[i] + 51, IntToStr(WinStat[i]));
    347       Sprite(Canvas, HGrSystem, xBrain[i] + 34, yBrain[i] + 53, 14, 14,
     345      RisedTextOut(Canvas, xBrain[I] + 30 - 16 - BiColorTextWidth(Canvas,
     346        IntToStr(WinStat[I])), yBrain[I] + 51, IntToStr(WinStat[I]));
     347      Sprite(Canvas, HGrSystem, xBrain[I] + 34, yBrain[I] + 53, 14, 14,
    348348        1 + 15, 316);
    349       RisedTextOut(Canvas, xBrain[i] + 34 + 16, yBrain[i] + 51,
    350         IntToStr(AloneStat[i]));
    351       Sprite(Canvas, HGrSystem, xBrain[i] + 30 - 14, yBrain[i] + 53 + 16, 14,
     349      RisedTextOut(Canvas, xBrain[I] + 34 + 16, yBrain[I] + 51,
     350        IntToStr(AloneStat[I]));
     351      Sprite(Canvas, HGrSystem, xBrain[I] + 30 - 14, yBrain[I] + 53 + 16, 14,
    352352        14, 1 + 30, 316);
    353       RisedTextOut(Canvas, xBrain[i] + 30 - 16 - BiColorTextWidth(Canvas,
    354         IntToStr(ExtStat[i])), yBrain[i] + 51 + 16, IntToStr(ExtStat[i]));
    355       Sprite(Canvas, HGrSystem, xBrain[i] + 34, yBrain[i] + 53 + 16, 14, 14,
     353      RisedTextOut(Canvas, xBrain[I] + 30 - 16 - BiColorTextWidth(Canvas,
     354        IntToStr(ExtStat[I])), yBrain[I] + 51 + 16, IntToStr(ExtStat[I]));
     355      Sprite(Canvas, HGrSystem, xBrain[I] + 34, yBrain[I] + 53 + 16, 14, 14,
    356356        1 + 45, 316);
    357357      if TotalStatTime > 0 then
    358358      begin
    359         TimeShare := trunc(TimeStat[i] / TotalStatTime * 100 + 0.5);
    360         RisedTextOut(Canvas, xBrain[i] + 34 + 16, yBrain[i] + 51 + 16,
     359        TimeShare := trunc(TimeStat[I] / TotalStatTime * 100 + 0.5);
     360        RisedTextOut(Canvas, xBrain[I] + 34 + 16, yBrain[I] + 51 + 16,
    361361          IntToStr(TimeShare) + '%');
    362362      end;
    363       ShowActive(i, i = Active);
     363      ShowActive(I, I = Active);
    364364    end;
    365365  Sprite(Canvas, HGrSystem2, x0Brain + 32 - 20, y0Brain + 32 - 20, 40,
     
    381381end;
    382382
    383 procedure TNoTermDlg.FormKeyDown(Sender: TObject; var Key: word;
     383procedure TNoTermDlg.FormKeyDown(Sender: TObject; var Key: Word;
    384384  Shift: TShiftState);
    385385begin
  • trunk/Packages/CevoComponents/AsyncProcess2.pas

    r290 r447  
    122122
    123123end.
     124
  • trunk/Packages/CevoComponents/BaseWin.pas

    r442 r447  
    2323    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    2424    procedure FormDeactivate(Sender: TObject);
    25     procedure SmartUpdateContent(ImmUpdate: Boolean = false);
     25    procedure SmartUpdateContent(ImmUpdate: Boolean = False);
    2626    procedure StayOnTop_Workaround;
    2727  protected
     
    5050    CaptionRight: Integer;
    5151    InnerWidth: Integer;
    52     InnerHeight: integer;
     52    InnerHeight: Integer;
    5353    WideBottom: Boolean;
    5454    FullCaption: Boolean;
     
    180180      UserLeft := Left;
    181181      UserTop := Top;
    182       Visible := false;
     182      Visible := False;
    183183      FWindowMode := NewMode;
    184184      ShowModal;
     
    186186    else if forceclose then
    187187    begin // make modal
    188       Visible := false;
     188      Visible := False;
    189189      FWindowMode := NewMode;
    190190      Left := UserLeft;
     
    272272procedure TFramedDlg.SmartInvalidate;
    273273var
    274   i, BottomFrame: integer;
     274  I, BottomFrame: Integer;
    275275  r0, r1: HRgn;
    276276begin
     
    281281  r0 := CreateRectRgn(SideFrame, TitleHeight, ClientWidth - SideFrame,
    282282    ClientHeight - BottomFrame);
    283   for i := 0 to ControlCount - 1 do
    284     if not(Controls[i] is TArea) and Controls[i].Visible then
     283  for I := 0 to ControlCount - 1 do
     284    if not(Controls[I] is TArea) and Controls[I].Visible then
    285285    begin
    286       with Controls[i].BoundsRect do
     286      with Controls[I].BoundsRect do
    287287        r1 := CreateRectRgn(Left, Top, Right, Bottom);
    288288      CombineRgn(r0, r0, r1, RGN_DIFF);
     
    295295procedure TFramedDlg.VPaint;
    296296
    297   procedure CornerFrame(x0, y0, x1, y1: integer);
     297  procedure CornerFrame(x0, y0, x1, y1: Integer);
    298298  begin
    299299    Frame(Canvas, x0 + 1, y0 + 1, x1 - 2, y1 - 2, MainTexture.ColorBevelLight,
     
    308308
    309309var
    310   i, l, FrameTop, FrameBottom, InnerBottom, Cut, xTexOffset,
    311     yTexOffset: integer;
     310  I, L, FrameTop, FrameBottom, InnerBottom, Cut, xTexOffset,
     311    yTexOffset: Integer;
    312312  R: TRect;
    313313begin
     
    321321  end;
    322322  Canvas.Font.Assign(UniFont[ftCaption]);
    323   l := BiColorTextWidth(Canvas, Caption);
    324   Cut := (ClientWidth - l) div 2;
     323  L := BiColorTextWidth(Canvas, Caption);
     324  Cut := (ClientWidth - L) div 2;
    325325  xTexOffset := (Maintexture.Width - ClientWidth) div 2;
    326326  yTexOffset := (Maintexture.Height - ClientHeight) div 2;
     
    446446  RisedTextOut(Canvas, Cut - 1, 7, Caption);
    447447
    448   for i := 0 to ControlCount - 1 do
    449     if Controls[i].Visible and (Controls[i] is TButtonBase) then
     448  for I := 0 to ControlCount - 1 do
     449    if Controls[I].Visible and (Controls[I] is TButtonBase) then
    450450    begin
    451       R := Controls[i].BoundsRect;
     451      R := Controls[I].BoundsRect;
    452452      if (R.Bottom <= TitleHeight) or (R.Top >= InnerBottom) then
    453453        BtnFrame(Canvas, R, MainTexture);
     
    463463begin
    464464  if FullCaption then
    465     exit;
     465    Exit;
    466466  r0 := CreateRectRgn(0, 0, ClientWidth, ClientHeight);
    467467  r1 := CreateRectRgn(0, 0, CaptionLeft, TitleHeight - NarrowFrame);
  • trunk/Packages/CevoComponents/ButtonB.pas

    r290 r447  
    1111  private
    1212    FMask: TBitmap;
    13     FIndex: integer;
    14     procedure SetIndex(Text: integer);
     13    FIndex: Integer;
     14    procedure SetIndex(Text: Integer);
    1515  public
    1616    property Mask: TBitmap read FMask write FMask;
    1717  published
    1818    property Visible;
    19     property ButtonIndex: integer read FIndex write SetIndex;
     19    property ButtonIndex: Integer read FIndex write SetIndex;
    2020    property OnClick;
    2121  protected
     
    6161end;
    6262
    63 procedure TButtonB.SetIndex(Text: integer);
     63procedure TButtonB.SetIndex(Text: Integer);
    6464begin
    6565  if Text <> FIndex then begin
  • trunk/Packages/CevoComponents/ButtonBase.pas

    r431 r447  
    1515    ClickProc: TNotifyEvent;
    1616    DownChangedProc: TNotifyEvent;
    17     procedure SetDown(x: boolean);
     17    procedure SetDown(X: Boolean);
    1818    // procedure PlayDownSound;
    1919    // procedure PlayUpSound;
    2020    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
    21       x, y: integer); override;
     21      X, Y: Integer); override;
    2222    procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
    23       x, y: integer); override;
    24     procedure MouseMove(Shift: TShiftState; x, y: integer); override;
     23      X, Y: Integer); override;
     24    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    2525  private
    26     Active: boolean;
     26    Active: Boolean;
    2727  public
    2828    constructor Create(aOwner: TComponent); override;
     
    3232  published
    3333    property Visible;
    34     property Down: boolean read FDown write SetDown;
    35     property Permanent: boolean read FPermanent write FPermanent;
     34    property Down: Boolean read FDown write SetDown;
     35    property Permanent: Boolean read FPermanent write FPermanent;
    3636    property OnClick: TNotifyEvent read ClickProc write ClickProc;
    3737    property OnDownChanged: TNotifyEvent read DownChangedProc
     
    5050  // FUpSound:='';
    5151  FGraphic := nil;
    52   Active := false;
    53   FDown := false;
    54   FPermanent := false;
     52  Active := False;
     53  FDown := False;
     54  FPermanent := False;
    5555  ClickProc := nil;
    5656end;
    5757
    5858procedure TButtonBase.MouseDown(Button: TMouseButton; Shift: TShiftState;
    59   x, y: integer);
     59  X, Y: Integer);
    6060begin
    61   Active := true;
    62   MouseMove(Shift, x, y);
     61  Active := True;
     62  MouseMove(Shift, X, Y);
    6363end;
    6464
    6565procedure TButtonBase.MouseUp(Button: TMouseButton; Shift: TShiftState;
    66   x, y: integer);
     66  X, Y: Integer);
    6767begin
    6868  if ssLeft in Shift then
    69     exit;
    70   MouseMove(Shift, x, y);
     69    Exit;
     70  MouseMove(Shift, X, Y);
    7171  if Active and FDown then
    7272  begin
    7373    // PlayUpSound;
    74     Active := false;
     74    Active := False;
    7575    if FDown <> FPermanent then
    7676    begin
     
    8686  begin
    8787    // if FDown then PlayUpSound;
    88     Active := false;
     88    Active := False;
    8989    if FDown then
    9090    begin
    91       FDown := false;
     91      FDown := False;
    9292      Invalidate;
    9393      if @DownChangedProc <> nil then
     
    9797end;
    9898
    99 procedure TButtonBase.MouseMove(Shift: TShiftState; x, y: integer);
     99procedure TButtonBase.MouseMove(Shift: TShiftState; X, Y: Integer);
    100100begin
    101101  if Active then
    102     if (x >= 0) and (x < Width) and (y >= 0) and (y < Height) then
     102    if (X >= 0) and (X < Width) and (Y >= 0) and (Y < Height) then
    103103      if (ssLeft in Shift) and not FDown then
    104104      begin
    105105        { PlayDownSound; }
    106         FDown := true;
     106        FDown := True;
    107107        Paint;
    108108        if @DownChangedProc <> nil then
     
    113113    begin
    114114      { PlayUpSound; }
    115       FDown := false;
     115      FDown := False;
    116116      Paint;
    117117      if @DownChangedProc <> nil then
     
    120120end;
    121121
    122 procedure TButtonBase.SetDown(x: boolean);
     122procedure TButtonBase.SetDown(X: Boolean);
    123123begin
    124   FDown := x;
     124  FDown := X;
    125125  Invalidate;
    126126end;
  • trunk/Packages/CevoComponents/ButtonC.pas

    r431 r447  
    1414  published
    1515    property Visible;
    16     property ButtonIndex: integer read FIndex write SetIndex;
     16    property ButtonIndex: Integer read FIndex write SetIndex;
    1717    property OnClick;
    1818  protected
     
    5050end;
    5151
    52 procedure TButtonC.SetIndex(Text: integer);
     52procedure TButtonC.SetIndex(Text: Integer);
    5353begin
    5454  if Text <> FIndex then
  • trunk/Packages/CevoComponents/ButtonN.pas

    r290 r447  
    1010    constructor Create(aOwner: TComponent); override;
    1111  private
    12     FPossible, FLit: boolean;
     12    FPossible, FLit: Boolean;
    1313    FGraphic, FMask, FBackGraphic: TBitmap;
    14     FIndex, BackIndex: integer;
     14    FIndex, BackIndex: Integer;
    1515    FSmartHint: string;
    1616    ChangeProc: TNotifyEvent;
    17     procedure SetPossible(x: boolean);
    18     procedure SetLit(x: boolean);
    19     procedure SetIndex(x: integer);
    20     procedure SetSmartHint(x: string);
     17    procedure SetPossible(X: Boolean);
     18    procedure SetLit(X: Boolean);
     19    procedure SetIndex(X: Integer);
     20    procedure SetSmartHint(X: string);
    2121  published
    22     property Possible: boolean read FPossible write SetPossible;
    23     property Lit: boolean read FLit write SetLit;
     22    property Possible: Boolean read FPossible write SetPossible;
     23    property Lit: Boolean read FLit write SetLit;
    2424    property SmartHint: string read FSmartHint write SetSmartHint;
    2525    property Graphic: TBitmap read FGraphic write FGraphic;
    2626    property Mask: TBitmap read FMask write FMask;
    2727    property BackGraphic: TBitmap read FBackGraphic write FBackGraphic;
    28     property ButtonIndex: integer read FIndex write SetIndex;
     28    property ButtonIndex: Integer read FIndex write SetIndex;
    2929    property OnClick: TNotifyEvent read ChangeProc write ChangeProc;
    3030  protected
    3131    procedure Paint; override;
    3232    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
    33       x, y: integer); override;
     33      X, Y: Integer); override;
    3434  end;
    3535
     
    4646begin
    4747  inherited;
    48   ShowHint := true;
     48  ShowHint := True;
    4949  FGraphic := nil;
    5050  FBackGraphic := nil;
    51   FPossible := true;
    52   FLit := false;
     51  FPossible := True;
     52  FLit := False;
    5353  FIndex := -1;
    5454  ChangeProc := nil;
     
    6363    begin
    6464      BitBltCanvas(Canvas, 1, 1, 40, 40, FBackGraphic.Canvas,
    65         1 + 80 * BackIndex + 40 * byte(FPossible and FLit), 176);
     65        1 + 80 * BackIndex + 40 * Byte(FPossible and FLit), 176);
    6666      if FPossible then
    6767      begin
     
    8383
    8484procedure TButtonN.MouseDown(Button: TMouseButton; Shift: TShiftState;
    85   x, y: integer);
     85  X, Y: Integer);
    8686begin
    8787  if FPossible and (Button = mbLeft) and (@ChangeProc <> nil) then
     
    8989end;
    9090
    91 procedure TButtonN.SetPossible(x: boolean);
     91procedure TButtonN.SetPossible(X: Boolean);
    9292begin
    93   if x <> FPossible then
     93  if X <> FPossible then
    9494  begin
    95     FPossible := x;
    96     if x then
     95    FPossible := X;
     96    if X then
    9797      Hint := FSmartHint
    9898    else
     
    102102end;
    103103
    104 procedure TButtonN.SetLit(x: boolean);
     104procedure TButtonN.SetLit(X: Boolean);
    105105begin
    106   if x <> FLit then
     106  if X <> FLit then
    107107  begin
    108     FLit := x;
     108    FLit := X;
    109109    Invalidate;
    110110  end;
    111111end;
    112112
    113 procedure TButtonN.SetIndex(x: integer);
     113procedure TButtonN.SetIndex(X: Integer);
    114114begin
    115   if x <> FIndex then
     115  if X <> FIndex then
    116116  begin
    117     FIndex := x;
    118     if x < 6 then
     117    FIndex := X;
     118    if X < 6 then
    119119      BackIndex := 1
    120120    else
     
    124124end;
    125125
    126 procedure TButtonN.SetSmartHint(x: string);
     126procedure TButtonN.SetSmartHint(X: string);
    127127begin
    128   if x <> FSmartHint then
     128  if X <> FSmartHint then
    129129  begin
    130     FSmartHint := x;
     130    FSmartHint := X;
    131131    if FPossible then
    132       Hint := x;
     132      Hint := X;
    133133  end;
    134134end;
  • trunk/Packages/CevoComponents/CevoComponents.pas

    r396 r447  
    2929  RegisterPackage('CevoComponents', @Register);
    3030end.
     31
  • trunk/Packages/CevoComponents/Directories.pas

    r381 r447  
    3333
    3434  if Lang = '' then begin
    35     for i := 1 to Paramcount - 1 do
    36       if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
    37         (ParamStrUTF8(i) = '--lang') then
    38           Lang := ParamStrUTF8(i + 1);
     35    for I := 1 to Paramcount - 1 do
     36      if (ParamStrUTF8(I) = '--LANG') or (ParamStrUTF8(I) = '-l') or
     37        (ParamStrUTF8(I) = '--lang') then
     38          Lang := ParamStrUTF8(I + 1);
    3939  end;
    4040  if Lang = '' then begin
     
    7373        (Dst.Time < Src.Time) then
    7474        CopyFile(SourceDir + DirectorySeparator + Src.Name,
    75           DestinationDir + DirectorySeparator + Src.Name, false);
     75          DestinationDir + DirectorySeparator + Src.Name, False);
    7676      FindClose(Dst);
    7777    until FindNext(Src) <> 0;
  • trunk/Packages/CevoComponents/DrawDlg.pas

    r423 r447  
    331331end.
    332332
     333
  • trunk/Packages/CevoComponents/EOTButton.pas

    r330 r447  
    1919    constructor Create(aOwner: TComponent); override;
    2020    destructor Destroy; override;
    21     procedure SetButtonIndexFast(x: integer);
    22     procedure SetBack(ca: TCanvas; x, y: integer);
     21    procedure SetButtonIndexFast(X: Integer);
     22    procedure SetBack(ca: TCanvas; X, Y: Integer);
    2323  private
    2424    FTemplate: TBitmap;
    25     FIndex: integer;
    26     procedure SetIndex(x: integer);
     25    FIndex: Integer;
     26    procedure SetIndex(X: Integer);
    2727  public
    2828    property Template: TBitmap read FTemplate write FTemplate;
    2929  published
    3030    property Visible;
    31     property ButtonIndex: integer read FIndex write SetIndex;
     31    property ButtonIndex: Integer read FIndex write SetIndex;
    3232    property OnClick;
    3333  protected
     
    6060  Back.SetSize(48, 48);
    6161  Back.Canvas.FillRect(0, 0, Back.Width, Back.Height);
    62   ShowHint := true;
     62  ShowHint := True;
    6363  SetBounds(0, 0, 48, 48);
    6464end;
     
    8989end;
    9090
    91 procedure TEOTButton.SetIndex(x: integer);
     91procedure TEOTButton.SetIndex(X: Integer);
    9292begin
    93   if x <> FIndex then begin
    94     FIndex := x;
     93  if X <> FIndex then begin
     94    FIndex := X;
    9595    Invalidate;
    9696  end;
    9797end;
    9898
    99 procedure TEOTButton.SetButtonIndexFast(x: integer);
     99procedure TEOTButton.SetButtonIndexFast(X: Integer);
    100100begin
    101   if Visible and (x <> FIndex) then begin
    102     FIndex := x;
     101  if Visible and (X <> FIndex) then begin
     102    FIndex := X;
    103103    try
    104104      Paint;
     
    108108end;
    109109
    110 procedure TEOTButton.SetBack(ca: TCanvas; x, y: integer);
     110procedure TEOTButton.SetBack(ca: TCanvas; X, Y: Integer);
    111111begin
    112   BitBltCanvas(Back.Canvas, 0, 0, 48, 48, ca, x, y);
     112  BitBltCanvas(Back.Canvas, 0, 0, 48, 48, ca, X, Y);
    113113end;
    114114
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r442 r447  
    1717
    1818{$IFDEF WINDOWS}
    19 function ChangeResolution(x, y, bpp, freq: integer): boolean;
     19function ChangeResolution(X, Y, bpp, freq: Integer): Boolean;
    2020{$ENDIF}
    2121procedure RestoreResolution;
    2222procedure EmptyMenu(MenuItems: TMenuItem; Keep: Integer = 0);
    23 function TurnToYear(Turn: integer): integer;
    24 function TurnToString(Turn: integer): string;
    25 function MovementToString(Movement: integer): string;
    26 procedure BtnFrame(ca: TCanvas; p: TRect; T: TTexture);
    27 procedure EditFrame(ca: TCanvas; p: TRect; T: TTexture);
    28 function HexStringToColor(S: string): integer;
     23function TurnToYear(Turn: Integer): Integer;
     24function TurnToString(Turn: Integer): string;
     25function MovementToString(Movement: Integer): string;
     26procedure BtnFrame(ca: TCanvas; P: TRect; T: TTexture);
     27procedure EditFrame(ca: TCanvas; P: TRect; T: TTexture);
     28function HexStringToColor(S: string): Integer;
    2929function ExtractFileNameWithoutExt(const Filename: string): string;
    30 function LoadGraphicFile(Bmp: TBitmap; FileName: string; Options: TLoadGraphicFileOptions = []): boolean;
     30function LoadGraphicFile(Bmp: TBitmap; FileName: string; Options: TLoadGraphicFileOptions = []): Boolean;
    3131function LoadGraphicSet(const Name: string; Transparency: Boolean = True): TGraphicSet;
    32 procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     32procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
    3333procedure BitmapReplaceColor(Dst: TBitmap; X, Y, Width, Height: Integer; OldColor, NewColor: TColor);
    34 procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     34procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
    3535  overload;
    36 procedure Sprite(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     36procedure Sprite(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
    3737  overload;
    3838procedure MakeBlue(Dst: TBitmap; X, Y, Width, Height: Integer);
     
    4545procedure ImageOp_CBC(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height,
    4646  Color0, Color2: Integer);
    47 procedure ImageOp_CCC(bmp: TBitmap; x, y, Width, Height, Color0, Color1, Color2: Integer);
     47procedure ImageOp_CCC(bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer);
    4848function BitBltCanvas(DestCanvas: TCanvas; X, Y, Width, Height: Integer;
    4949  SrcCanvas: TCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; overload;
     
    5454function BitBltBitmap(Dest: TBitmap; DestRect: TRect;
    5555  Src: TBitmap; SrcPos: TPoint; Rop: DWORD = SRCCOPY): Boolean; overload;
    56 procedure SLine(ca: TCanvas; x0, x1, y: integer; cl: TColor);
    57 procedure DLine(ca: TCanvas; x0, x1, y: integer; cl0, cl1: TColor);
    58 procedure Frame(ca: TCanvas; x0, y0, x1, y1: integer; cl0, cl1: TColor);
    59 procedure RFrame(ca: TCanvas; x0, y0, x1, y1: integer; cl0, cl1: TColor);
    60 procedure CFrame(ca: TCanvas; x0, y0, x1, y1, Corner: integer; cl: TColor);
     56procedure SLine(ca: TCanvas; x0, x1, Y: Integer; cl: TColor);
     57procedure DLine(ca: TCanvas; x0, x1, Y: Integer; cl0, cl1: TColor);
     58procedure Frame(ca: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor);
     59procedure RFrame(ca: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor);
     60procedure CFrame(ca: TCanvas; x0, y0, x1, y1, Corner: Integer; cl: TColor);
    6161procedure FrameImage(ca: TCanvas; Src: TBitmap;
    62   x, y, Width, Height, xSrc, ySrc: integer; IsControl: boolean = False);
    63 procedure GlowFrame(Dst: TBitmap; x0, y0, Width, Height: integer; cl: TColor);
     62  X, Y, Width, Height, xSrc, ySrc: Integer; IsControl: Boolean = False);
     63procedure GlowFrame(Dst: TBitmap; x0, y0, Width, Height: Integer; cl: TColor);
    6464procedure InitOrnament;
    6565procedure InitCityMark(T: TTexture);
    66 procedure Fill(ca: TCanvas; Left, Top, Width, Height, xOffset, yOffset: integer); overload;
     66procedure Fill(ca: TCanvas; Left, Top, Width, Height, xOffset, yOffset: Integer); overload;
    6767procedure Fill(Canvas: TCanvas; Rect: TRect; Offset: TPoint); overload;
    68 procedure FillLarge(ca: TCanvas; x0, y0, x1, y1, xm: integer);
    69 procedure FillSeamless(ca: TCanvas; Left, Top, Width, Height, xOffset, yOffset: integer;
     68procedure FillLarge(ca: TCanvas; x0, y0, x1, y1, xm: Integer);
     69procedure FillSeamless(ca: TCanvas; Left, Top, Width, Height, xOffset, yOffset: Integer;
    7070  const Texture: TBitmap);
    71 procedure FillRectSeamless(ca: TCanvas; x0, y0, x1, y1, xOffset, yOffset: integer;
     71procedure FillRectSeamless(ca: TCanvas; x0, y0, x1, y1, xOffset, yOffset: Integer;
    7272  const Texture: TBitmap);
    73 procedure PaintBackground(Form: TForm; Left, Top, Width, Height: integer);
    74 procedure Corner(ca: TCanvas; x, y, Kind: integer; T: TTexture);
    75 procedure BiColorTextOut(ca: TCanvas; clMain, clBack: TColor; x, y: integer; s: string);
     73procedure PaintBackground(Form: TForm; Left, Top, Width, Height: Integer);
     74procedure Corner(ca: TCanvas; X, Y, Kind: Integer; T: TTexture);
     75procedure BiColorTextOut(ca: TCanvas; clMain, clBack: TColor; X, Y: Integer; S: string);
    7676procedure LoweredTextOut(ca: TCanvas; cl: TColor; T: TTexture;
    77   x, y: integer; s: string);
    78 function BiColorTextWidth(ca: TCanvas; s: string): integer;
    79 procedure RisedTextOut(ca: TCanvas; x, y: integer; s: string);
    80 procedure LightGradient(ca: TCanvas; x, y, Width, Color: integer);
    81 procedure DarkGradient(ca: TCanvas; x, y, Width, Kind: integer);
    82 procedure VLightGradient(ca: TCanvas; x, y, Height, Color: integer);
    83 procedure VDarkGradient(ca: TCanvas; x, y, Height, Kind: integer);
     77  X, Y: Integer; S: string);
     78function BiColorTextWidth(ca: TCanvas; S: string): Integer;
     79procedure RisedTextOut(ca: TCanvas; X, Y: Integer; S: string);
     80procedure LightGradient(ca: TCanvas; X, Y, Width, Color: Integer);
     81procedure DarkGradient(ca: TCanvas; X, Y, Width, Kind: Integer);
     82procedure VLightGradient(ca: TCanvas; X, Y, Height, Color: Integer);
     83procedure VDarkGradient(ca: TCanvas; X, Y, Height, Kind: Integer);
    8484procedure UnderlinedTitleValue(Canvas: TCanvas; Title, Value: string; X, Y, Width: Integer);
    85 procedure NumberBar(dst: TBitmap; x, y: integer; Cap: string; val: integer;
     85procedure NumberBar(dst: TBitmap; X, Y: Integer; Cap: string; val: Integer;
    8686  T: TTexture);
    87 procedure CountBar(dst: TBitmap; x, y, w: integer; Kind: integer;
    88   Cap: string; val: integer; T: TTexture);
    89 procedure PaintProgressBar(ca: TCanvas; Kind, x, y, pos, Growth, max: integer;
     87procedure CountBar(dst: TBitmap; X, Y, W: Integer; Kind: Integer;
     88  Cap: string; val: Integer; T: TTexture);
     89procedure PaintProgressBar(ca: TCanvas; Kind, X, Y, Pos, Growth, Max: Integer;
    9090  T: TTexture);
    9191procedure PaintRelativeProgressBar(ca: TCanvas;
    92   Kind, x, y, size, pos, Growth, max: integer; IndicateComplete: boolean;
     92  Kind, X, Y, size, Pos, Growth, Max: Integer; IndicateComplete: Boolean;
    9393  T: TTexture);
    94 procedure PaintLogo(Canvas: TCanvas; X, Y, LightColor, ShadeColor: integer);
     94procedure PaintLogo(Canvas: TCanvas; X, Y, LightColor, ShadeColor: Integer);
    9595procedure LoadPhrases;
    9696procedure Texturize(Dest, Texture: TBitmap; TransparentColor: Cardinal);
     
    204204  {$IFDEF WINDOWS}
    205205  StartResolution: TDeviceMode;
    206   ResolutionChanged: boolean;
     206  ResolutionChanged: Boolean;
    207207  {$ENDIF}
    208208
     
    210210
    211211{$IFDEF WINDOWS}
    212 function ChangeResolution(x, y, bpp, freq: integer): boolean;
     212function ChangeResolution(X, Y, bpp, freq: Integer): Boolean;
    213213var
    214214  DevMode: TDeviceMode;
     
    217217  DevMode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT or DM_BITSPERPEL or
    218218    DM_DISPLAYFREQUENCY;
    219   DevMode.dmPelsWidth := x;
    220   DevMode.dmPelsHeight := y;
     219  DevMode.dmPelsWidth := X;
     220  DevMode.dmPelsHeight := Y;
    221221  DevMode.dmBitsPerPel := bpp;
    222222  DevMode.dmDisplayFrequency := freq;
     
    318318end;
    319319
    320 procedure BtnFrame(ca: TCanvas; p: TRect; T: TTexture);
    321 begin
    322   RFrame(ca, p.Left - 1, p.Top - 1, p.Right, p.Bottom, T.ColorBevelShade,
     320procedure BtnFrame(ca: TCanvas; P: TRect; T: TTexture);
     321begin
     322  RFrame(ca, P.Left - 1, P.Top - 1, P.Right, P.Bottom, T.ColorBevelShade,
    323323    T.ColorBevelLight);
    324324end;
    325325
    326 procedure EditFrame(ca: TCanvas; p: TRect; T: TTexture);
    327 begin
    328   Frame(ca, p.Left - 1, p.Top - 1, p.Right, p.Bottom, $000000, $000000);
    329   Frame(ca, p.Left - 2, p.Top - 2, p.Right + 1, p.Bottom + 1, $000000, $000000);
    330   Frame(ca, p.Left - 3, p.Top - 3, p.Right + 2, p.Bottom + 1, $000000, $000000);
    331   RFrame(ca, p.Left - 4, p.Top - 4, p.Right + 3, p.Bottom + 2, T.ColorBevelShade,
     326procedure EditFrame(ca: TCanvas; P: TRect; T: TTexture);
     327begin
     328  Frame(ca, P.Left - 1, P.Top - 1, P.Right, P.Bottom, $000000, $000000);
     329  Frame(ca, P.Left - 2, P.Top - 2, P.Right + 1, P.Bottom + 1, $000000, $000000);
     330  Frame(ca, P.Left - 3, P.Top - 3, P.Right + 2, P.Bottom + 1, $000000, $000000);
     331  RFrame(ca, P.Left - 4, P.Top - 4, P.Right + 3, P.Bottom + 2, T.ColorBevelShade,
    332332    T.ColorBevelLight);
    333333end;
     
    335335function HexCharToInt(X: Char): Integer;
    336336begin
    337   case x of
     337  case X of
    338338    '0' .. '9': Result := Ord(X) - Ord('0');
    339339    'A' .. 'F': Result := Ord(X) - Ord('A') + 10;
     
    492492function LoadGraphicSet(const Name: string; Transparency: Boolean = True): TGraphicSet;
    493493var
    494   x: Integer;
    495   y: Integer;
     494  X: Integer;
     495  Y: Integer;
    496496  OriginalColor: Integer;
    497497  FileName: string;
     
    522522      DataPixel := PixelPointer(Result.Data);
    523523      MaskPixel := PixelPointer(Result.Mask);
    524       for y := 0 to ScaleToNative(Result.Data.Height) - 1 do begin
    525         for x := 0 to ScaleToNative(Result.Data.Width) - 1 do begin
     524      for Y := 0 to ScaleToNative(Result.Data.Height) - 1 do begin
     525        for X := 0 to ScaleToNative(Result.Data.Width) - 1 do begin
    526526          OriginalColor := DataPixel.Pixel^.ARGB and $FFFFFF;
    527527          if (OriginalColor = TransparentColor1) or (OriginalColor = TransparentColor2) then begin
     
    552552end;
    553553
    554 procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     554procedure Dump(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
    555555begin
    556556  BitBltCanvas(dst.Canvas, xDst, yDst, Width, Height,
     
    650650    Height := ScaleToNative(dst.Height) - yDst;
    651651  if (Width < 0) or (Height < 0) then
    652     exit;
     652    Exit;
    653653
    654654  dst.BeginUpdate;
     
    659659    for X := 0 to Width - 1 do  begin
    660660      Brightness := PixelSrc.Pixel^.B; // One byte for 8-bit color
    661       test := (PixelDst.Pixel^.R * Brightness) shr 7;
    662       if test >= 256 then
     661      Test := (PixelDst.Pixel^.R * Brightness) shr 7;
     662      if Test >= 256 then
    663663        PixelDst.Pixel^.R := 255
    664664      else
    665         PixelDst.Pixel^.R := test; // Red
    666       test := (PixelDst.Pixel^.G * Brightness) shr 7;
    667       if test >= 256 then
     665        PixelDst.Pixel^.R := Test; // Red
     666      Test := (PixelDst.Pixel^.G * Brightness) shr 7;
     667      if Test >= 256 then
    668668        PixelDst.Pixel^.G := 255
    669669      else
    670         PixelDst.Pixel^.G := test; // Green
    671       test := (PixelDst.Pixel^.B * Brightness) shr 7;
    672       if test >= 256 then
     670        PixelDst.Pixel^.G := Test; // Green
     671      Test := (PixelDst.Pixel^.B * Brightness) shr 7;
     672      if Test >= 256 then
    673673        PixelDst.Pixel^.R := 255
    674674      else
     
    716716    Height := ScaleToNative(dst.Height) - yDst;
    717717  if (Width < 0) or (Height < 0) then
    718     exit;
     718    Exit;
    719719
    720720  Src.BeginUpdate;
     
    765765// R channel = Color2 amp
    766766var
    767   ix, iy, amp0, amp1, trans, Value: integer;
     767  ix, iy, amp0, amp1, trans, Value: Integer;
    768768  SrcPixel: TPixelPointer;
    769769  DstPixel: TPixelPointer;
     
    807807end;
    808808
    809 procedure ImageOp_CCC(bmp: TBitmap; x, y, Width, Height, Color0, Color1, Color2: Integer);
     809procedure ImageOp_CCC(bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer);
    810810// Bmp is template
    811811// B channel = Color0 amp, 128=original brightness
     
    813813// R channel = Color2 amp, 128=original brightness
    814814var
    815   i, Red, Green: Integer;
     815  I, Red, Green: Integer;
    816816  PixelPtr: TPixelPointer;
    817817begin
     
    821821  Height := ScaleToNative(Height);
    822822  bmp.BeginUpdate;
    823   assert(bmp.PixelFormat = pf24bit);
    824   Height := y + Height;
    825   PixelPtr := PixelPointer(Bmp, x, y);
    826   while y < Height do begin
    827     for i := 0 to Width - 1 do begin
     823  Assert(bmp.PixelFormat = pf24bit);
     824  Height := Y + Height;
     825  PixelPtr := PixelPointer(Bmp, X, Y);
     826  while Y < Height do begin
     827    for I := 0 to Width - 1 do begin
    828828      Red := ((PixelPtr.Pixel^.B * (Color0 and $0000FF) + PixelPtr.Pixel^.G *
    829829        (Color1 and $0000FF) + PixelPtr.Pixel^.R * (Color2 and $0000FF)) shr 8) and $ff;
     
    838838      PixelPtr.NextPixel;
    839839    end;
    840     Inc(y);
     840    Inc(Y);
    841841    PixelPtr.NextLine;
    842842  end;
     
    844844end;
    845845
    846 procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     846procedure Sprite(Canvas: TCanvas; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
    847847begin
    848848  BitBltCanvas(Canvas, xDst, yDst, Width, Height,
     
    852852end;
    853853
    854 procedure Sprite(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: integer);
     854procedure Sprite(dst: TBitmap; HGr: TGraphicSet; xDst, yDst, Width, Height, xGr, yGr: Integer);
    855855begin
    856856  BitBltCanvas(dst.Canvas, xDst, yDst, Width, Height,
     
    890890end;
    891891
    892 procedure SLine(ca: TCanvas; x0, x1, y: integer; cl: TColor);
     892procedure SLine(ca: TCanvas; x0, x1, Y: Integer; cl: TColor);
    893893begin
    894894  with ca do begin
    895895    Pen.Color := cl;
    896     MoveTo(x0, y);
    897     LineTo(x1 + 1, y);
    898   end;
    899 end;
    900 
    901 procedure DLine(ca: TCanvas; x0, x1, y: integer; cl0, cl1: TColor);
     896    MoveTo(x0, Y);
     897    LineTo(x1 + 1, Y);
     898  end;
     899end;
     900
     901procedure DLine(ca: TCanvas; x0, x1, Y: Integer; cl0, cl1: TColor);
    902902begin
    903903  with ca do begin
    904904    Pen.Color := cl0;
    905     MoveTo(x0, y);
    906     LineTo(x1, y);
     905    MoveTo(x0, Y);
     906    LineTo(x1, Y);
    907907    Pen.Color := cl1;
    908     MoveTo(x0 + 1, y + 1);
    909     LineTo(x1 + 1, y + 1);
    910     Pixels[x0, y + 1] := cl0;
    911     Pixels[x1, y] := cl1;
    912   end;
    913 end;
    914 
    915 procedure Frame(ca: TCanvas; x0, y0, x1, y1: integer; cl0, cl1: TColor);
     908    MoveTo(x0 + 1, Y + 1);
     909    LineTo(x1 + 1, Y + 1);
     910    Pixels[x0, Y + 1] := cl0;
     911    Pixels[x1, Y] := cl1;
     912  end;
     913end;
     914
     915procedure Frame(ca: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor);
    916916begin
    917917  with ca do begin
     
    926926end;
    927927
    928 procedure RFrame(ca: TCanvas; x0, y0, x1, y1: integer; cl0, cl1: TColor);
     928procedure RFrame(ca: TCanvas; x0, y0, x1, y1: Integer; cl0, cl1: TColor);
    929929begin
    930930  with ca do begin
     
    942942end;
    943943
    944 procedure CFrame(ca: TCanvas; x0, y0, x1, y1, Corner: integer; cl: TColor);
     944procedure CFrame(ca: TCanvas; x0, y0, x1, y1, Corner: Integer; cl: TColor);
    945945begin
    946946  with ca do begin
     
    962962
    963963procedure FrameImage(ca: TCanvas; Src: TBitmap;
    964   x, y, Width, Height, xSrc, ySrc: integer; IsControl: boolean = False);
     964  X, Y, Width, Height, xSrc, ySrc: Integer; IsControl: Boolean = False);
    965965begin
    966966  if IsControl then begin
    967     Frame(ca, x - 1, y - 1, x + Width, y + Height, $B0B0B0, $FFFFFF);
    968     RFrame(ca, x - 2, y - 2, x + Width + 1, y + Height + 1, $FFFFFF, $B0B0B0);
     967    Frame(ca, X - 1, Y - 1, X + Width, Y + Height, $B0B0B0, $FFFFFF);
     968    RFrame(ca, X - 2, Y - 2, X + Width + 1, Y + Height + 1, $FFFFFF, $B0B0B0);
    969969  end else
    970     Frame(ca, x - 1, y - 1, x + Width, y + Height, $000000, $000000);
    971   BitBltCanvas(ca, x, y, Width, Height, Src.Canvas, xSrc, ySrc);
     970    Frame(ca, X - 1, Y - 1, X + Width, Y + Height, $000000, $000000);
     971  BitBltCanvas(ca, X, Y, Width, Height, Src.Canvas, xSrc, ySrc);
    972972end;
    973973
    974974procedure GlowFrame(Dst: TBitmap; x0, y0, Width, Height: Integer; cl: TColor);
    975975var
    976   x, y, ch, r: Integer;
     976  X, Y, ch, R: Integer;
    977977  DstPtr: TPixelPointer;
    978978  DpiGlowRange: Integer;
     
    985985  Dst.BeginUpdate;
    986986  DstPtr := PixelPointer(Dst, x0 - DpiGlowRange + 1, y0 - DpiGlowRange + 1);
    987   for y := -DpiGlowRange + 1 to Height - 1 + DpiGlowRange - 1 do begin
    988     for x := -DpiGlowRange + 1 to Width - 1 + DpiGlowRange - 1 do begin
    989       if x < 0 then
    990         if y < 0 then
    991           r := round(sqrt(sqr(x) + sqr(y)))
    992         else if y >= Height then
    993           r := round(sqrt(sqr(x) + sqr(y - (Height - 1))))
     987  for Y := -DpiGlowRange + 1 to Height - 1 + DpiGlowRange - 1 do begin
     988    for X := -DpiGlowRange + 1 to Width - 1 + DpiGlowRange - 1 do begin
     989      if X < 0 then
     990        if Y < 0 then
     991          R := round(sqrt(sqr(X) + sqr(Y)))
     992        else if Y >= Height then
     993          R := round(sqrt(sqr(X) + sqr(Y - (Height - 1))))
    994994        else
    995           r := -x
    996       else if x >= Width then
    997         if y < 0 then
    998           r := round(sqrt(sqr(x - (Width - 1)) + sqr(y)))
    999         else if y >= Height then
    1000           r := round(sqrt(sqr(x - (Width - 1)) + sqr(y - (Height - 1))))
     995          R := -X
     996      else if X >= Width then
     997        if Y < 0 then
     998          R := round(sqrt(sqr(X - (Width - 1)) + sqr(Y)))
     999        else if Y >= Height then
     1000          R := round(sqrt(sqr(X - (Width - 1)) + sqr(Y - (Height - 1))))
    10011001        else
    1002           r := x - (Width - 1)
    1003       else if y < 0 then
    1004         r := -y
    1005       else if y >= Height then
    1006         r := y - (Height - 1)
     1002          R := X - (Width - 1)
     1003      else if Y < 0 then
     1004        R := -Y
     1005      else if Y >= Height then
     1006        R := Y - (Height - 1)
    10071007      else begin
    10081008        DstPtr.NextPixel;
    10091009        continue;
    10101010      end;
    1011       if r = 0 then
    1012         r := 1;
    1013       if r < DpiGlowRange then
     1011      if R = 0 then
     1012        R := 1;
     1013      if R < DpiGlowRange then
    10141014        for ch := 0 to 2 do
    10151015          DstPtr.Pixel^.Planes[2 - ch] :=
    1016             (DstPtr.Pixel^.Planes[2 - ch] * (r - 1) + (cl shr (8 * ch) and $FF) *
    1017             (DpiGlowRange - r)) div (DpiGlowRange - 1);
     1016            (DstPtr.Pixel^.Planes[2 - ch] * (R - 1) + (cl shr (8 * ch) and $FF) *
     1017            (DpiGlowRange - R)) div (DpiGlowRange - 1);
    10181018      DstPtr.NextPixel;
    10191019    end;
     
    10651065procedure InitCityMark(T: TTexture);
    10661066var
    1067   x: Integer;
    1068   y: Integer;
     1067  X: Integer;
     1068  Y: Integer;
    10691069  Intensity: Integer;
    10701070begin
    1071   for x := 0 to CityMark1.Width - 1 do begin
    1072     for y := 0 to CityMark1.Height - 1 do begin
    1073       if HGrSystem.Mask.Canvas.Pixels[CityMark1.Left + x, CityMark1.Top + y] = 0 then
     1071  for X := 0 to CityMark1.Width - 1 do begin
     1072    for Y := 0 to CityMark1.Height - 1 do begin
     1073      if HGrSystem.Mask.Canvas.Pixels[CityMark1.Left + X, CityMark1.Top + Y] = 0 then
    10741074      begin
    10751075        Intensity := HGrSystem.Data.Canvas.Pixels[CityMark1.Left +
    1076           x, CityMark1.Top + y] and $FF;
    1077         HGrSystem.Data.Canvas.Pixels[CityMark2.Left + x, CityMark2.Top + y] :=
     1076          X, CityMark1.Top + Y] and $FF;
     1077        HGrSystem.Data.Canvas.Pixels[CityMark2.Left + X, CityMark2.Top + Y] :=
    10781078          T.ColorMark and $FF * Intensity div $FF + T.ColorMark shr 8 and
    10791079          $FF * Intensity div $FF shl 8 + T.ColorMark shr 16 and
     
    11031103  function Band(I: Integer): Integer;
    11041104  var
    1105     n: integer;
     1105    N: Integer;
    11061106  begin
    1107     n := ((MainTexture.Height div 2) div (y1 - y0)) * 2;
     1107    N := ((MainTexture.Height div 2) div (y1 - y0)) * 2;
    11081108    while MainTexture.Height div 2 + (I + 1) * (y1 - y0) > MainTexture.Height do
    1109       Dec(I, n);
     1109      Dec(I, N);
    11101110    while MainTexture.Height div 2 + I * (y1 - y0) < 0 do
    1111       Inc(I, n);
     1111      Inc(I, N);
    11121112    Result := I;
    11131113  end;
     
    11371137  const Texture: TBitmap);
    11381138var
    1139   x, y, x0cut, y0cut, x1cut, y1cut: Integer;
     1139  X, Y, x0cut, y0cut, x1cut, y1cut: Integer;
    11401140begin
    11411141  while xOffset < 0 do
     
    11431143  while yOffset < 0 do
    11441144    Inc(yOffset, Texture.Height);
    1145   for y := (Top + yOffset) div Texture.Height to (Top + yOffset + Height - 1) div
     1145  for Y := (Top + yOffset) div Texture.Height to (Top + yOffset + Height - 1) div
    11461146    Texture.Height do
    11471147  begin
    1148     y0cut := Top + yOffset - y * Texture.Height;
     1148    y0cut := Top + yOffset - Y * Texture.Height;
    11491149    if y0cut < 0 then
    11501150      y0cut := 0;
    1151     y1cut := (y + 1) * Texture.Height - (Top + yOffset + Height);
     1151    y1cut := (Y + 1) * Texture.Height - (Top + yOffset + Height);
    11521152    if y1cut < 0 then
    11531153      y1cut := 0;
    1154     for x := (Left + xOffset) div Texture.Width to (Left + xOffset + Width - 1) div
     1154    for X := (Left + xOffset) div Texture.Width to (Left + xOffset + Width - 1) div
    11551155      Texture.Width do
    11561156    begin
    1157       x0cut := Left + xOffset - x * Texture.Width;
     1157      x0cut := Left + xOffset - X * Texture.Width;
    11581158      if x0cut < 0 then
    11591159        x0cut := 0;
    1160       x1cut := (x + 1) * Texture.Width - (Left + xOffset + Width);
     1160      x1cut := (X + 1) * Texture.Width - (Left + xOffset + Width);
    11611161      if x1cut < 0 then
    11621162        x1cut := 0;
    1163       BitBltCanvas(ca, x * Texture.Width + x0cut - xOffset,
    1164         y * Texture.Height + y0cut - yOffset, Texture.Width - x0cut - x1cut,
     1163      BitBltCanvas(ca, X * Texture.Width + x0cut - xOffset,
     1164        Y * Texture.Height + y0cut - yOffset, Texture.Width - x0cut - x1cut,
    11651165        Texture.Height - y0cut - y1cut, Texture.Canvas, x0cut, y0cut);
    11661166    end;
     
    11801180end;
    11811181
    1182 procedure Corner(ca: TCanvas; x, y, Kind: Integer; T: TTexture);
     1182procedure Corner(ca: TCanvas; X, Y, Kind: Integer; T: TTexture);
    11831183begin
    11841184  { BitBltCanvas(ca,x,y,8,8,T.HGr.Mask.Canvas,
    11851185    T.xGr+29+Kind*9,T.yGr+89,SRCAND);
    1186     BitBltCanvas(ca,x,y,8,8,T.HGr.Data.Canvas,
     1186    BitBltCanvas(ca,X,Y,8,8,T.HGr.Data.Canvas,
    11871187    T.xGr+29+Kind*9,T.yGr+89,SRCPAINT); }
    11881188end;
    11891189
    1190 procedure BiColorTextOut(ca: TCanvas; clMain, clBack: TColor; x, y: Integer; s: string);
    1191 
    1192   procedure PaintIcon(x, y, Kind: Integer);
     1190procedure BiColorTextOut(ca: TCanvas; clMain, clBack: TColor; X, Y: Integer; S: string);
     1191
     1192  procedure PaintIcon(X, Y, Kind: Integer);
    11931193  begin
    1194     BitBltCanvas(ca, x, y + 6, 10, 10, HGrSystem.Mask.Canvas,
     1194    BitBltCanvas(ca, X, Y + 6, 10, 10, HGrSystem.Mask.Canvas,
    11951195      66 + Kind mod 11 * 11, 115 + Kind div 11 * 11, SRCAND);
    1196     BitBltCanvas(ca, x, y + 6, 10, 10, HGrSystem.Data.Canvas,
     1196    BitBltCanvas(ca, X, Y + 6, 10, 10, HGrSystem.Data.Canvas,
    11971197      66 + Kind mod 11 * 11, 115 + Kind div 11 * 11, SRCPAINT);
    11981198  end;
    11991199
    12001200var
    1201   p, xp: Integer;
     1201  P, xp: Integer;
    12021202  sp: string;
    12031203  shadow: Boolean;
    12041204  Text: string;
    12051205begin
    1206   Inc(x);
    1207   Inc(y);
     1206  Inc(X);
     1207  Inc(Y);
    12081208  for shadow := True downto False do
    12091209    with ca do
     
    12141214        else
    12151215          Font.Color := clMain;
    1216         sp := s;
    1217         xp := x;
     1216        sp := S;
     1217        xp := X;
    12181218        repeat
    1219           p := pos('%', sp);
    1220           if (p = 0) or (p + 1 > Length(sp)) or not
    1221             (sp[p + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w']) then
     1219          P := Pos('%', sp);
     1220          if (P = 0) or (P + 1 > Length(sp)) or not
     1221            (sp[P + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w']) then
    12221222          begin
    1223             ca.Textout(xp, y, sp);
     1223            ca.Textout(xp, Y, sp);
    12241224            Break;
    12251225          end
    12261226          else
    12271227          begin
    1228             Text := Copy(sp, 1, p - 1);
    1229             Textout(xp, y, Text);
     1228            Text := Copy(sp, 1, P - 1);
     1229            Textout(xp, Y, Text);
    12301230            Inc(xp, ca.TextWidth(Text));
    12311231            if not shadow then
    1232               case sp[p + 1] of
    1233                 'c': PaintIcon(xp + 1, y, 6);
    1234                 'f': PaintIcon(xp + 1, y, 0);
    1235                 'l': PaintIcon(xp + 1, y, 8);
    1236                 'm': PaintIcon(xp + 1, y, 17);
    1237                 'n': PaintIcon(xp + 1, y, 7);
    1238                 'o': PaintIcon(xp + 1, y, 16);
    1239                 'p': PaintIcon(xp + 1, y, 2);
    1240                 'r': PaintIcon(xp + 1, y, 12);
    1241                 't': PaintIcon(xp + 1, y, 4);
    1242                 'w': PaintIcon(xp + 1, y, 13);
     1232              case sp[P + 1] of
     1233                'c': PaintIcon(xp + 1, Y, 6);
     1234                'f': PaintIcon(xp + 1, Y, 0);
     1235                'l': PaintIcon(xp + 1, Y, 8);
     1236                'm': PaintIcon(xp + 1, Y, 17);
     1237                'n': PaintIcon(xp + 1, Y, 7);
     1238                'o': PaintIcon(xp + 1, Y, 16);
     1239                'p': PaintIcon(xp + 1, Y, 2);
     1240                'r': PaintIcon(xp + 1, Y, 12);
     1241                't': PaintIcon(xp + 1, Y, 4);
     1242                'w': PaintIcon(xp + 1, Y, 13);
    12431243              end;
    12441244            Inc(xp, 10);
    1245             Delete(sp, 1, p + 1);
     1245            Delete(sp, 1, P + 1);
    12461246          end;
    12471247        until False;
    1248         Dec(x);
    1249         Dec(y);
     1248        Dec(X);
     1249        Dec(Y);
    12501250      end;
    12511251end;
    12521252
    1253 function BiColorTextWidth(ca: TCanvas; s: string): Integer;
     1253function BiColorTextWidth(ca: TCanvas; S: string): Integer;
    12541254var
    12551255  P: Integer;
     
    12571257  Result := 1;
    12581258  repeat
    1259     P := Pos('%', s);
    1260     if (P = 0) or (P = Length(s)) then
     1259    P := Pos('%', S);
     1260    if (P = 0) or (P = Length(S)) then
    12611261    begin
    1262       Inc(Result, ca.TextWidth(s));
     1262      Inc(Result, ca.TextWidth(S));
    12631263      Break;
    12641264    end
    12651265    else
    12661266    begin
    1267       if not (s[P + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w'])
     1267      if not (S[P + 1] in ['c', 'f', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'w'])
    12681268      then
    1269         Inc(Result, ca.TextWidth(copy(s, 1, P + 1)))
     1269        Inc(Result, ca.TextWidth(Copy(S, 1, P + 1)))
    12701270      else
    1271         Inc(Result, ca.TextWidth(copy(s, 1, P - 1)) + 10);
    1272       Delete(s, 1, P + 1);
     1271        Inc(Result, ca.TextWidth(Copy(S, 1, P - 1)) + 10);
     1272      Delete(S, 1, P + 1);
    12731273    end;
    12741274  until False;
     
    12761276
    12771277procedure LoweredTextOut(ca: TCanvas; cl: TColor; T: TTexture;
    1278   x, y: Integer; s: string);
     1278  X, Y: Integer; S: string);
    12791279begin
    12801280  if cl = -2 then
    12811281    BiColorTextOut(ca, (T.ColorBevelShade and $FEFEFE) shr 1,
    1282       T.ColorBevelLight, x, y, s)
     1282      T.ColorBevelLight, X, Y, S)
    12831283  else if cl < 0 then
    1284     BiColorTextOut(ca, T.ColorTextShade, T.ColorTextLight, x, y, s)
     1284    BiColorTextOut(ca, T.ColorTextShade, T.ColorTextLight, X, Y, S)
    12851285  else
    1286     BiColorTextOut(ca, cl, T.ColorTextLight, x, y, s);
    1287 end;
    1288 
    1289 procedure RisedTextOut(ca: TCanvas; x, y: integer; s: string);
    1290 begin
    1291   BiColorTextOut(ca, $FFFFFF, $000000, x, y, s);
    1292 end;
    1293 
    1294 procedure Gradient(ca: TCanvas; x, y, dx, dy, Width, Height, Color: Integer;
    1295   Brightness: array of integer);
    1296 var
    1297   i, r, g, b: Integer;
    1298 begin
    1299   for i := 0 to Length(Brightness) - 1 do begin // gradient
    1300     r := Color and $FF + Brightness[i];
    1301     if r < 0 then
    1302       r := 0
    1303     else if r >= 256 then
    1304       r := 255;
    1305     g := Color shr 8 and $FF + Brightness[i];
    1306     if g < 0 then
    1307       g := 0
    1308     else if g >= 256 then
    1309       g := 255;
    1310     b := Color shr 16 and $FF + Brightness[i];
    1311     if b < 0 then
    1312       b := 0
    1313     else if b >= 256 then
    1314       b := 255;
    1315     ca.Pen.Color := r + g shl 8 + b shl 16;
    1316     ca.MoveTo(x + dx * i, y + dy * i);
    1317     ca.LineTo(x + dx * i + Width, y + dy * i + Height);
     1286    BiColorTextOut(ca, cl, T.ColorTextLight, X, Y, S);
     1287end;
     1288
     1289procedure RisedTextOut(ca: TCanvas; X, Y: Integer; S: string);
     1290begin
     1291  BiColorTextOut(ca, $FFFFFF, $000000, X, Y, S);
     1292end;
     1293
     1294procedure Gradient(ca: TCanvas; X, Y, dx, dy, Width, Height, Color: Integer;
     1295  Brightness: array of Integer);
     1296var
     1297  I, R, G, B: Integer;
     1298begin
     1299  for I := 0 to Length(Brightness) - 1 do begin // gradient
     1300    R := Color and $FF + Brightness[I];
     1301    if R < 0 then
     1302      R := 0
     1303    else if R >= 256 then
     1304      R := 255;
     1305    G := Color shr 8 and $FF + Brightness[I];
     1306    if G < 0 then
     1307      G := 0
     1308    else if G >= 256 then
     1309      G := 255;
     1310    B := Color shr 16 and $FF + Brightness[I];
     1311    if B < 0 then
     1312      B := 0
     1313    else if B >= 256 then
     1314      B := 255;
     1315    ca.Pen.Color := R + G shl 8 + B shl 16;
     1316    ca.MoveTo(X + dx * I, Y + dy * I);
     1317    ca.LineTo(X + dx * I + Width, Y + dy * I + Height);
    13181318  end;
    13191319  ca.Pen.Color := $000000;
    1320   ca.MoveTo(x + 1, y + 16 * dy + Height);
    1321   ca.LineTo(x + 16 * dx + Width, y + 16 * dy + Height);
    1322   ca.LineTo(x + 16 * dx + Width, y);
    1323 end;
    1324 
    1325 procedure LightGradient(ca: TCanvas; x, y, Width, Color: Integer);
     1320  ca.MoveTo(X + 1, Y + 16 * dy + Height);
     1321  ca.LineTo(X + 16 * dx + Width, Y + 16 * dy + Height);
     1322  ca.LineTo(X + 16 * dx + Width, Y);
     1323end;
     1324
     1325procedure LightGradient(ca: TCanvas; X, Y, Width, Color: Integer);
    13261326const
    1327   Brightness: array [0 .. 15] of integer =
     1327  Brightness: array [0 .. 15] of Integer =
    13281328    (16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -24, -28, -32, -36, -40, -44);
    13291329begin
    1330   Gradient(ca, x, y, 0, 1, Width, 0, Color, Brightness);
    1331 end;
    1332 
    1333 procedure DarkGradient(ca: TCanvas; x, y, Width, Kind: Integer);
     1330  Gradient(ca, X, Y, 0, 1, Width, 0, Color, Brightness);
     1331end;
     1332
     1333procedure DarkGradient(ca: TCanvas; X, Y, Width, Kind: Integer);
    13341334const
    1335   Brightness: array [0 .. 15] of integer =
     1335  Brightness: array [0 .. 15] of Integer =
    13361336    (16, 12, 8, 4, 0, -4, -8, -12 - 24, -16 + 16, -20, -24, -28, -32, -36, -40, -44);
    13371337begin
    1338   Gradient(ca, x, y, 0, 1, Width, 0, HGrSystem.Data.Canvas.Pixels
     1338  Gradient(ca, X, Y, 0, 1, Width, 0, HGrSystem.Data.Canvas.Pixels
    13391339    [187, 137 + Kind], Brightness);
    13401340end;
    13411341
    1342 procedure VLightGradient(ca: TCanvas; x, y, Height, Color: Integer);
     1342procedure VLightGradient(ca: TCanvas; X, Y, Height, Color: Integer);
    13431343const
    1344   Brightness: array [0 .. 15] of integer =
     1344  Brightness: array [0 .. 15] of Integer =
    13451345    (16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -24, -28, -32, -36, -40, -44);
    13461346begin
    1347   Gradient(ca, x, y, 1, 0, 0, Height, Color, Brightness);
    1348 end;
    1349 
    1350 procedure VDarkGradient(ca: TCanvas; x, y, Height, Kind: Integer);
     1347  Gradient(ca, X, Y, 1, 0, 0, Height, Color, Brightness);
     1348end;
     1349
     1350procedure VDarkGradient(ca: TCanvas; X, Y, Height, Kind: Integer);
    13511351const
    1352   Brightness: array [0 .. 15] of integer =
     1352  Brightness: array [0 .. 15] of Integer =
    13531353    (16, 12, 8, 4, 0, -4, -8, -12 - 24, -16 + 16, -20, -24, -28, -32, -36, -40, -44);
    13541354begin
    1355   Gradient(ca, x, y, 1, 0, 0, Height,
     1355  Gradient(ca, X, Y, 1, 0, 0, Height,
    13561356    HGrSystem.Data.Canvas.Pixels[187, 137 + Kind], Brightness);
    13571357end;
     
    13641364end;
    13651365
    1366 procedure NumberBar(dst: TBitmap; x, y: integer; Cap: string;
     1366procedure NumberBar(dst: TBitmap; X, Y: Integer; Cap: string;
    13671367  val: Integer; T: TTexture);
    13681368var
    1369   s: string;
     1369  S: string;
    13701370begin
    13711371  if val > 0 then
    13721372  begin
    1373     DLine(dst.Canvas, x - 2, x + 170, y + 16, T.ColorBevelShade,
     1373    DLine(dst.Canvas, X - 2, X + 170, Y + 16, T.ColorBevelShade,
    13741374      T.ColorBevelLight);
    1375     LoweredTextOut(dst.Canvas, -1, T, x - 2, y, Cap);
    1376     s := IntToStr(val);
    1377     RisedTextOut(dst.Canvas, x + 170 - BiColorTextWidth(dst.Canvas,
    1378       s), y, s);
    1379   end;
    1380 end;
    1381 
    1382 procedure CountBar(dst: TBitmap; x, y, w: Integer; Kind: Integer;
     1375    LoweredTextOut(dst.Canvas, -1, T, X - 2, Y, Cap);
     1376    S := IntToStr(val);
     1377    RisedTextOut(dst.Canvas, X + 170 - BiColorTextWidth(dst.Canvas,
     1378      S), Y, S);
     1379  end;
     1380end;
     1381
     1382procedure CountBar(dst: TBitmap; X, Y, W: Integer; Kind: Integer;
    13831383  Cap: string; val: Integer; T: TTexture);
    13841384var
    1385   i, sd, ld, cl, xIcon, yIcon: Integer;
    1386   s: string;
     1385  I, sd, ld, cl, xIcon, yIcon: Integer;
     1386  S: string;
    13871387begin
    13881388  // val:=random(40); //!!!
     
    13961396    // DLine(dst.Canvas,x-2,x+170+32,y+16,T.ColorBevelShade,T.ColorBevelLight);
    13971397
    1398     xIcon := x - 5;
    1399     yIcon := y + 15;
    1400     DLine(dst.Canvas, x - 2, xIcon + w + 2, yIcon + 16, T.ColorBevelShade,
     1398    xIcon := X - 5;
     1399    yIcon := Y + 15;
     1400    DLine(dst.Canvas, X - 2, xIcon + W + 2, yIcon + 16, T.ColorBevelShade,
    14011401      T.ColorBevelLight);
    14021402
    1403     s := IntToStr(val);
     1403    S := IntToStr(val);
    14041404    if val < 0 then
    14051405      cl := $0000FF
    14061406    else
    14071407      cl := -1;
    1408     LoweredTextOut(dst.Canvas, cl, T, x - 2, y, Cap);
     1408    LoweredTextOut(dst.Canvas, cl, T, X - 2, Y, Cap);
    14091409    LoweredTextOut(dst.Canvas, cl, T,
    1410       xIcon + w + 2 - BiColorTextWidth(dst.Canvas, s), yIcon, s);
     1410      xIcon + W + 2 - BiColorTextWidth(dst.Canvas, S), yIcon, S);
    14111411
    14121412    if (Kind = 12) and (val >= 100) then
     
    14161416      if sd = 0 then
    14171417        sd := 1;
    1418       if sd < w - 44 then
     1418      if sd < W - 44 then
    14191419        ld := sd
    14201420      else
    1421         ld := w - 44;
    1422       for i := 0 to val mod 10 - 1 do
     1421        ld := W - 44;
     1422      for I := 0 to val mod 10 - 1 do
    14231423      begin
    1424         BitBltCanvas(dst.Canvas, xIcon + 4 + i * (14 * ld div sd), yIcon + 2 + 1, 14,
     1424        BitBltCanvas(dst.Canvas, xIcon + 4 + I * (14 * ld div sd), yIcon + 2 + 1, 14,
    14251425          14, HGrSystem.Mask.Canvas, 67 + Kind mod 8 * 15,
    14261426          70 + Kind div 8 * 15, SRCAND);
    1427         Sprite(dst, HGrSystem, xIcon + 3 + i * (14 * ld div sd), yIcon + 2,
     1427        Sprite(dst, HGrSystem, xIcon + 3 + I * (14 * ld div sd), yIcon + 2,
    14281428          14, 14, 67 + Kind mod 8 * 15, 70 + Kind div 8 * 15);
    14291429      end;
    1430       for i := 0 to val div 10 - 1 do
     1430      for I := 0 to val div 10 - 1 do
    14311431      begin
    14321432        BitBltCanvas(dst.Canvas, xIcon + 4 + (val mod 10) *
    1433           (14 * ld div sd) + i * (14 * ld div sd), yIcon + 3, 14, 14,
     1433          (14 * ld div sd) + I * (14 * ld div sd), yIcon + 3, 14, 14,
    14341434          HGrSystem.Mask.Canvas, 67 + 7 mod 8 * 15,
    14351435          70 + 7 div 8 * 15, SRCAND);
    14361436        Sprite(dst, HGrSystem, xIcon + 3 + (val mod 10) *
    1437           (14 * ld div sd) + i * (14 * ld div sd), yIcon + 2, 14,
     1437          (14 * ld div sd) + I * (14 * ld div sd), yIcon + 2, 14,
    14381438          14, 67 + 7 mod 8 * 15,
    14391439          70 + 7 div 8 * 15);
     
    14491449      if sd = 0 then
    14501450        sd := 1;
    1451       if sd < w - 44 then
     1451      if sd < W - 44 then
    14521452        ld := sd
    14531453      else
    1454         ld := w - 44;
    1455       for i := 0 to val div 10 - 1 do
     1454        ld := W - 44;
     1455      for I := 0 to val div 10 - 1 do
    14561456      begin
    1457         BitBltCanvas(dst.Canvas, xIcon + 4 + i * (14 * ld div sd), yIcon + 3, 14, 14,
     1457        BitBltCanvas(dst.Canvas, xIcon + 4 + I * (14 * ld div sd), yIcon + 3, 14, 14,
    14581458          HGrSystem.Mask.Canvas, 67 + Kind mod 8 * 15,
    14591459          70 + Kind div 8 * 15, SRCAND);
    1460         Sprite(dst, HGrSystem, xIcon + 3 + i * (14 * ld div sd), yIcon + 2,
     1460        Sprite(dst, HGrSystem, xIcon + 3 + I * (14 * ld div sd), yIcon + 2,
    14611461          14, 14, 67 + Kind mod 8 * 15, 70 + Kind div 8 * 15);
    14621462      end;
    1463       for i := 0 to val mod 10 - 1 do
     1463      for I := 0 to val mod 10 - 1 do
    14641464      begin
    14651465        BitBltCanvas(dst.Canvas, xIcon + 4 + (val div 10) *
    1466           (14 * ld div sd) + i * (10 * ld div sd), yIcon + 7, 10, 10,
     1466          (14 * ld div sd) + I * (10 * ld div sd), yIcon + 7, 10, 10,
    14671467          HGrSystem.Mask.Canvas, 66 + Kind mod 11 * 11,
    14681468          115 + Kind div 11 * 11, SRCAND);
    14691469        Sprite(dst, HGrSystem, xIcon + 3 + (val div 10) *
    1470           (14 * ld div sd) + i * (10 * ld div sd), yIcon + 6, 10,
     1470          (14 * ld div sd) + I * (10 * ld div sd), yIcon + 6, 10,
    14711471          10, 66 + Kind mod 11 * 11,
    14721472          115 + Kind div 11 * 11);
     
    14761476end;
    14771477
    1478 procedure PaintProgressBar(ca: TCanvas; Kind, x, y, pos, Growth, max: Integer;
     1478procedure PaintProgressBar(ca: TCanvas; Kind, X, Y, Pos, Growth, Max: Integer;
    14791479  T: TTexture);
    14801480var
    1481   i: Integer;
    1482 begin
    1483   if pos > max then
    1484     pos := max;
     1481  I: Integer;
     1482begin
     1483  if Pos > Max then
     1484    Pos := Max;
    14851485  if Growth < 0 then
    14861486  begin
    1487     pos := pos + Growth;
    1488     if pos < 0 then
     1487    Pos := Pos + Growth;
     1488    if Pos < 0 then
    14891489    begin
    1490       Growth := Growth - pos;
    1491       pos := 0;
     1490      Growth := Growth - Pos;
     1491      Pos := 0;
    14921492    end;
    14931493  end
    1494   else if pos + Growth > max then
    1495     Growth := max - pos;
    1496   Frame(ca, x - 1, y - 1, x + max, y + 7, $000000, $000000);
    1497   RFrame(ca, x - 2, y - 2, x + max + 1, y + 8, T.ColorBevelShade,
     1494  else if Pos + Growth > Max then
     1495    Growth := Max - Pos;
     1496  Frame(ca, X - 1, Y - 1, X + Max, Y + 7, $000000, $000000);
     1497  RFrame(ca, X - 2, Y - 2, X + Max + 1, Y + 8, T.ColorBevelShade,
    14981498    T.ColorBevelLight);
    14991499  with ca do
    15001500  begin
    1501     for i := 0 to pos div 8 - 1 do
    1502       BitBltCanvas(ca, x + i * 8, y, 8, 7,
     1501    for I := 0 to Pos div 8 - 1 do
     1502      BitBltCanvas(ca, X + I * 8, Y, 8, 7,
    15031503        HGrSystem.Data.Canvas, 104, 9 + 8 * Kind);
    1504     BitBltCanvas(ca, x + 8 * (pos div 8), y, pos - 8 * (pos div 8), 7,
     1504    BitBltCanvas(ca, X + 8 * (Pos div 8), Y, Pos - 8 * (Pos div 8), 7,
    15051505      HGrSystem.Data.Canvas, 104, 9 + 8 * Kind);
    15061506    if Growth > 0 then
    15071507    begin
    1508       for i := 0 to Growth div 8 - 1 do
    1509         BitBltCanvas(ca, x + pos + i * 8, y, 8, 7,
     1508      for I := 0 to Growth div 8 - 1 do
     1509        BitBltCanvas(ca, X + Pos + I * 8, Y, 8, 7,
    15101510          HGrSystem.Data.Canvas, 112, 9 + 8 * Kind);
    1511       BitBltCanvas(ca, x + pos + 8 * (Growth div 8), y,
     1511      BitBltCanvas(ca, X + Pos + 8 * (Growth div 8), Y,
    15121512        Growth - 8 * (Growth div 8), 7, HGrSystem.Data.Canvas,
    15131513        112, 9 + 8 * Kind);
     
    15151515    else if Growth < 0 then
    15161516    begin
    1517       for i := 0 to -Growth div 8 - 1 do
    1518         BitBltCanvas(ca, x + pos + i * 8, y, 8, 7,
     1517      for I := 0 to -Growth div 8 - 1 do
     1518        BitBltCanvas(ca, X + Pos + I * 8, Y, 8, 7,
    15191519          HGrSystem.Data.Canvas, 104, 1);
    1520       BitBltCanvas(ca, x + pos + 8 * (-Growth div 8), y, -Growth -
     1520      BitBltCanvas(ca, X + Pos + 8 * (-Growth div 8), Y, -Growth -
    15211521        8 * (-Growth div 8), 7,
    15221522        HGrSystem.Data.Canvas, 104, 1);
    15231523    end;
    15241524    Brush.Color := $000000;
    1525     FillRect(Rect(x + pos + abs(Growth), y, x + max, y + 7));
     1525    FillRect(Rect(X + Pos + abs(Growth), Y, X + Max, Y + 7));
    15261526    Brush.Style := bsClear;
    15271527  end;
     
    15301530// pos and growth are relative to max, set size independent
    15311531procedure PaintRelativeProgressBar(ca: TCanvas;
    1532   Kind, x, y, size, pos, Growth, max: Integer; IndicateComplete: Boolean;
     1532  Kind, X, Y, size, Pos, Growth, Max: Integer; IndicateComplete: Boolean;
    15331533  T: TTexture);
    15341534begin
    15351535  if Growth > 0 then
    1536     PaintProgressBar(ca, Kind, x, y, pos * size div max,
    1537       (Growth * size + max div 2) div max, size, T)
     1536    PaintProgressBar(ca, Kind, X, Y, Pos * size div Max,
     1537      (Growth * size + Max div 2) div Max, size, T)
    15381538  else
    1539     PaintProgressBar(ca, Kind, x, y, pos * size div max,
    1540       (Growth * size - max div 2) div max, size, T);
    1541   if IndicateComplete and (pos + Growth >= max) then
    1542     Sprite(ca, HGrSystem, x + size - 10, y - 7, 23, 16, 1, 129);
     1539    PaintProgressBar(ca, Kind, X, Y, Pos * size div Max,
     1540      (Growth * size - Max div 2) div Max, size, T);
     1541  if IndicateComplete and (Pos + Growth >= Max) then
     1542    Sprite(ca, HGrSystem, X + size - 10, Y - 7, 23, 16, 1, 129);
    15431543end;
    15441544
     
    16101610procedure DarkenImage(Bitmap: TBitmap; Change: Integer);
    16111611var
    1612   x, y: integer;
     1612  X, Y: Integer;
    16131613  PicturePixel: TPixelPointer;
    16141614begin
    16151615  Bitmap.BeginUpdate;
    16161616  PicturePixel := PixelPointer(Bitmap);
    1617   for y := 0 to ScaleToNative(Bitmap.Height) - 1 do begin
    1618     for x := 0 to ScaleToNative(Bitmap.Width) - 1 do begin
     1617  for Y := 0 to ScaleToNative(Bitmap.Height) - 1 do begin
     1618    for X := 0 to ScaleToNative(Bitmap.Width) - 1 do begin
    16191619      PicturePixel.Pixel^.B := Max(PicturePixel.Pixel^.B - Change, 0);
    16201620      PicturePixel.Pixel^.G := Max(PicturePixel.Pixel^.G - Change, 0);
     
    16621662  Section: TFontType;
    16631663  FontScript: TextFile;
    1664   Size: integer;
     1664  Size: Integer;
    16651665  S: string;
    1666   I: integer;
    1667   P: integer;
     1666  I: Integer;
     1667  P: Integer;
    16681668begin
    16691669  Section := ftNormal;
     
    16721672    Reset(FontScript);
    16731673    while not Eof(FontScript) do begin
    1674       ReadLn(FontScript, s);
    1675       if s <> '' then
    1676         if s[1] = '#' then begin
    1677           s := TrimRight(s);
    1678           if s = '#SMALL' then Section := ftSmall
    1679           else if s = '#TINY' then Section := ftTiny
    1680           else if s = '#CAPTION' then Section := ftCaption
    1681           else if s = '#BUTTON' then Section := ftButton
     1674      ReadLn(FontScript, S);
     1675      if S <> '' then
     1676        if S[1] = '#' then begin
     1677          S := TrimRight(S);
     1678          if S = '#SMALL' then Section := ftSmall
     1679          else if S = '#TINY' then Section := ftTiny
     1680          else if S = '#CAPTION' then Section := ftCaption
     1681          else if S = '#BUTTON' then Section := ftButton
    16821682          else Section := ftNormal;
    16831683        end else begin
    1684           p := Pos(',', s);
    1685           if p > 0 then begin
    1686             UniFont[section].Name := Trim(Copy(s, 1, p - 1));
     1684          P := Pos(',', S);
     1685          if P > 0 then begin
     1686            UniFont[section].Name := Trim(Copy(S, 1, P - 1));
    16871687            Size := 0;
    1688             for i := p + 1 to Length(s) do
    1689               case s[i] of
     1688            for I := P + 1 to Length(S) do
     1689              case S[I] of
    16901690                '0' .. '9':
    1691                   Size := Size * 10 + Byte(s[i]) - 48;
     1691                  Size := Size * 10 + Byte(S[I]) - 48;
    16921692                'B', 'b':
    16931693                  UniFont[section].Style := UniFont[section].Style + [fsBold];
  • trunk/Packages/CevoComponents/Sound.pas

    r424 r447  
    280280begin
    281281  Result := 0;
    282   while (Result < SoundList.Count) and (SoundList[result].FFileName <> FileName) do
     282  while (Result < SoundList.Count) and (SoundList[Result].FFileName <> FileName) do
    283283    Inc(Result);
    284284  if Result = SoundList.Count then begin
  • trunk/Packages/CevoComponents/StringTables.pas

    r300 r447  
    1616    constructor Create;
    1717    destructor Destroy; override;
    18     function LoadFromFile(const FileName: String): boolean;
    19     function GetHandle(const Item: string): integer;
    20     function LookupByHandle(Handle: integer; Index: integer = -1): string;
     18    function LoadFromFile(const FileName: String): Boolean;
     19    function GetHandle(const Item: string): Integer;
     20    function LookupByHandle(Handle: Integer; Index: Integer = -1): string;
    2121    function Lookup(const Item: string; Index: Integer = -1): string;
    22     function Search(const Content: string; var Handle, Index: integer): boolean;
     22    function Search(const Content: string; var Handle, Index: Integer): Boolean;
    2323  end;
    2424
     
    4545end;
    4646
    47 function TStringTable.LoadFromFile(const FileName: String): boolean;
     47function TStringTable.LoadFromFile(const FileName: String): Boolean;
    4848begin
    4949  Result := True;
     
    5656end;
    5757
    58 function TStringTable.GetHandle(const Item: string): integer;
     58function TStringTable.GetHandle(const Item: string): Integer;
    5959var
    6060  I: Integer;
     
    6767end;
    6868
    69 function TStringTable.LookupByHandle(Handle: integer; Index: integer): string;
     69function TStringTable.LookupByHandle(Handle: Integer; Index: Integer): string;
    7070var
    71   s: string;
     71  S: string;
    7272begin
    7373  if Index < 0 then begin
     
    7777    end else begin
    7878      if Pos(' ', Lines[Handle]) = 0 then S := ''
    79         else s := Copy(Lines[Handle], Pos(' ', Lines[Handle]) + 1, MaxInt);
     79        else S := Copy(Lines[Handle], Pos(' ', Lines[Handle]) + 1, MaxInt);
    8080      while ((Handle + 1) < Lines.Count) and (Copy(Lines[Handle + 1], 1, 1) <> '#') do begin
    8181        Inc(Handle);
    8282        if (Length(Lines[Handle]) > 0) and (Lines[Handle][1] <> '''') then begin
    83           if (s <> '') and (s[Length(s)] <> '\') then
    84             s := s + ' ';
    85           s := s + Lines[Handle];
     83          if (S <> '') and (S[Length(S)] <> '\') then
     84            S := S + ' ';
     85          S := S + Lines[Handle];
    8686        end;
    8787      end;
     
    116116{ might become necessary for 1.3
    117117
    118   function TStringTable.Lookup(const Fallback: TStringTable; const Item: string; Index: integer): string;
     118  function TStringTable.Lookup(const Fallback: TStringTable; const Item: string; Index: Integer): string;
    119119  var
    120   Handle: integer;
     120  Handle: Integer;
    121121  begin
    122122  Handle:=Gethandle(Item);
    123   if Handle>=0 then result:=LookupByHandle(Handle, Index)
    124   else result:='';
    125   if result='' then
    126   result:=Fallback.Lookup(Item, Index);
     123  if Handle>=0 then Result:=LookupByHandle(Handle, Index)
     124  else Result:='';
     125  if Result='' then
     126  Result:=Fallback.Lookup(Item, Index);
    127127  end;
    128128
    129   function TStringTable.TryLookup(const Item: string; Index: integer): string;
     129  function TStringTable.TryLookup(const Item: string; Index: Integer): string;
    130130  var
    131   Handle: integer;
     131  Handle: Integer;
    132132  begin
    133133  Handle:=Gethandle(Item);
    134   if Handle>=0 then result:=LookupByHandle(Handle, Index)
    135   else result:='';
     134  if Handle>=0 then Result:=LookupByHandle(Handle, Index)
     135  else Result:='';
    136136  end; }
    137137
    138138function TStringTable.Search(const Content: string;
    139   var Handle, Index: integer): boolean;
     139  var Handle, Index: Integer): Boolean;
    140140var
    141   h, i: integer;
     141  H, I: Integer;
    142142  UContent: string;
    143143begin
    144144  UContent := UpperCase(Content);
    145   h := Handle;
    146   if h < 0 then
    147     i := 0
     145  H := Handle;
     146  if H < 0 then
     147    I := 0
    148148  else
    149     i := Index + 1;
     149    I := Index + 1;
    150150  repeat
    151     if h + i + 1 >= Lines.Count then
     151    if H + I + 1 >= Lines.Count then
    152152    begin
    153       result := false;
    154       exit;
     153      Result := False;
     154      Exit;
    155155    end;
    156     if Copy(Lines[h + i + 1], 1, 1) = '#' then
     156    if Copy(Lines[H + I + 1], 1, 1) = '#' then
    157157    begin
    158       h := h + i + 1;
    159       i := -1;
     158      H := H + I + 1;
     159      I := -1;
    160160    end;
    161     if (h >= 0) and not ((Length(Lines[h + i + 1]) > 0) and (Lines[h + i + 1][1] in ['#', ':', ';'])) and
    162       (Pos(UContent, UpperCase(Lines[h + i + 1])) > 0) then
     161    if (H >= 0) and not ((Length(Lines[H + I + 1]) > 0) and (Lines[H + I + 1][1] in ['#', ':', ';'])) and
     162      (Pos(UContent, UpperCase(Lines[H + I + 1])) > 0) then
    163163    begin
    164       Index := i;
    165       Handle := h;
     164      Index := I;
     165      Handle := H;
    166166      Result := True;
    167167      Exit;
  • trunk/Packages/CevoComponents/UGraphicSet.pas

    r424 r447  
    272272end.
    273273
     274
  • trunk/Packages/CevoComponents/UTexture.pas

    r380 r447  
    9797end.
    9898
     99
  • trunk/Packages/Common/Common.pas

    r396 r447  
    3737  RegisterPackage('Common', @Register);
    3838end.
     39
  • trunk/Packages/Common/StopWatch.pas

    r424 r447  
    3535implementation
    3636
    37 constructor TStopWatch.Create(const startOnCreate : boolean = false) ;
     37constructor TStopWatch.Create(const startOnCreate : Boolean = False) ;
    3838begin
    3939  inherited Create;
     
    7272begin
    7373  dt := ElapsedMiliseconds / MSecsPerSec / SecsPerDay;
    74   result := Format('%d days, %s', [Trunc(dt), FormatDateTime('hh:nn:ss.z', Frac(dt))]) ;
     74  Result := Format('%d days, %s', [Trunc(dt), FormatDateTime('hh:nn:ss.z', Frac(dt))]) ;
    7575end;
    7676
     
    9393
    9494end.
     95
  • trunk/Packages/Common/UAboutDialog.pas

    r424 r447  
    5151end.
    5252
     53
  • trunk/Packages/Common/UCommon.pas

    r424 r447  
    4242  clLightRed = TColor($8080FF);
    4343
    44 function AddLeadingZeroes(const aNumber, Length : integer) : string;
     44function AddLeadingZeroes(const aNumber, Length : Integer) : string;
    4545function BinToInt(BinStr: string): Int64;
    4646function BinToHexString(Source: AnsiString): string;
     
    9696function BinToInt(BinStr : string) : Int64;
    9797var
    98   i : byte;
     98  I : Byte;
    9999  RetVar : Int64;
    100100begin
    101101  BinStr := UpperCase(BinStr);
    102   if BinStr[length(BinStr)] = 'B' then Delete(BinStr,length(BinStr),1);
     102  if BinStr[Length(BinStr)] = 'B' then Delete(BinStr,Length(BinStr),1);
    103103  RetVar := 0;
    104   for i := 1 to length(BinStr) do begin
    105     if not (BinStr[i] in ['0','1']) then begin
     104  for I := 1 to Length(BinStr) do begin
     105    if not (BinStr[I] in ['0','1']) then begin
    106106      RetVar := 0;
    107107      Break;
    108108    end;
    109     RetVar := (RetVar shl 1) + (byte(BinStr[i]) and 1) ;
     109    RetVar := (RetVar shl 1) + (Byte(BinStr[I]) and 1) ;
    110110  end;
    111111
     
    435435end;
    436436
    437 function AddLeadingZeroes(const aNumber, Length : integer) : string;
     437function AddLeadingZeroes(const aNumber, Length : Integer) : string;
    438438begin
    439439  Result := SysUtils.Format('%.*d', [Length, aNumber]) ;
     
    614614  begin
    615615    for J := ReadFrom to Len do
    616       if (S[j] = C) then
     616      if (S[J] = C) then
    617617      begin
    618618        Result := J;
     
    631631    Inc(I);
    632632    APos := ReadUntil(I, '<');
    633     Result := Result + Copy(S, I, APos - i);
     633    Result := Result + Copy(S, I, APos - I);
    634634    I := ReadUntil(APos + 1, '>');
    635635  end;
  • trunk/Packages/Common/UFindFile.pas

    r424 r447  
    66Tired of using FindFirst, Next and Close?
    77Come see how to encapsulate all those functions
    8 in a single "find-files-recursively" component.
     8in A Single "find-files-recursively" component.
    99It's easy to use, free and with code.
    1010
     
    3434  TFindFile = class(TComponent)
    3535  private
    36     s : TStringList;
    37     fSubFolder : boolean;
     36    S : TStringList;
     37    fSubFolder : Boolean;
    3838    fAttr: TFileAttrib;
    3939    fPath : string;
     
    4747  published
    4848    property FileAttr: TFileAttrib read fAttr write fAttr;
    49     property InSubFolders : boolean read fSubFolder write fSubFolder;
     49    property InSubFolders : Boolean read fSubFolder write fSubFolder;
    5050    property Path : string read fPath write SetPath;
    5151    property FileMask : string read fFileMask write fFileMask ;
     
    7979  FileMask := FilterAll;
    8080  FileAttr := [ffaAnyFile];
    81   s := TStringList.Create;
     81  S := TStringList.Create;
    8282end;
    8383
    8484destructor TFindFile.Destroy;
    8585begin
    86   s.Free;
     86  S.Free;
    8787  inherited Destroy;
    8888end;
     
    101101function TFindFile.SearchForFiles: TStringList;
    102102begin
    103   s.Clear;
     103  S.Clear;
    104104  try
    105105    FileSearch(Path);
    106106  finally
    107     Result := s;
     107    Result := S;
    108108  end;
    109109end;
     
    111111procedure TFindFile.FileSearch(const InPath : string);
    112112var Rec  : TSearchRec;
    113     Attr : integer;
     113    Attr : Integer;
    114114begin
    115115  Attr := 0;
     
    125125  try
    126126    repeat
    127       s.Add(inPath + Rec.Name);
     127      S.Add(inPath + Rec.Name);
    128128    until SysUtils.FindNext(Rec) <> 0;
    129129  finally
  • trunk/Packages/Common/UFormAbout.pas

    r423 r447  
    8383end.
    8484
     85
  • trunk/Packages/Common/UGeometric.pas

    r424 r447  
    5252function PointToLineDistance(const P, V, W: TPoint): Integer;
    5353var
    54   l2, t: Double;
     54  l2, T: Double;
    5555  tt: TPoint;
    5656begin
     
    165165end.
    166166
     167
  • trunk/Packages/Common/UJobProgressView.pas

    r424 r447  
    221221      for I := 0 to ListViewJobs.Items.Count - 1 do
    222222      begin
    223         ItemRect := ListViewJobs.Items[i].DisplayRect(drBounds);
     223        ItemRect := ListViewJobs.Items[I].DisplayRect(drBounds);
    224224        Maxh := Max(Maxh, ItemRect.Top + (ItemRect.Bottom - ItemRect.Top));
    225225      end;
  • trunk/Packages/Common/UMetaCanvas.pas

    r424 r447  
    124124    procedure SetWidth(AValue: Integer); override;
    125125    function GetWidth: Integer; override;
    126     procedure DoLine (x1,y1,x2,y2:integer); override;
     126    procedure DoLine (x1,y1,x2,y2:Integer); override;
    127127    procedure DoTextOut(X, Y: Integer; Text: string); override;
    128128    procedure DoRectangle(const Bounds: TRect); override;
     
    451451end;
    452452
    453 procedure TMetaCanvas.DoLine(x1, y1, x2, y2: integer);
     453procedure TMetaCanvas.DoLine(x1, y1, x2, y2: Integer);
    454454var
    455455  NewObj: TCanvasLine;
     
    665665end.
    666666
     667
  • trunk/Packages/Common/UPrefixMultiplier.pas

    r423 r447  
    3030  BasePrefixMultipliers: TPrefixMultiplierDef =
    3131  (
    32     (ShortText: 'y'; FullText: 'yocto'; Value: 1e-24),
    33           (ShortText: 'z'; FullText: 'zepto'; Value: 1e-21),
    34     (ShortText: 'a'; FullText: 'atto'; Value: 1e-18),
    35     (ShortText: 'f'; FullText: 'femto'; Value: 1e-15),
    36     (ShortText: 'p'; FullText: 'piko'; Value: 1e-12),
    37     (ShortText: 'n'; FullText: 'nano'; Value: 1e-9),
    38     (ShortText: 'u'; FullText: 'mikro'; Value: 1e-6),
    39     (ShortText: 'm'; FullText: 'mili'; Value: 1e-3),
     32    (ShortText: 'y'; FullText: 'yocto'; Value: 1E-24),
     33          (ShortText: 'z'; FullText: 'zepto'; Value: 1E-21),
     34    (ShortText: 'a'; FullText: 'atto'; Value: 1E-18),
     35    (ShortText: 'f'; FullText: 'femto'; Value: 1E-15),
     36    (ShortText: 'p'; FullText: 'piko'; Value: 1E-12),
     37    (ShortText: 'n'; FullText: 'nano'; Value: 1E-9),
     38    (ShortText: 'u'; FullText: 'mikro'; Value: 1E-6),
     39    (ShortText: 'm'; FullText: 'mili'; Value: 1E-3),
    4040    (ShortText: ''; FullText: ''; Value: 1e0),
    4141    (ShortText: 'k'; FullText: 'kilo'; Value: 1e3),
     
    5151  TimePrefixMultipliers: TPrefixMultiplierDef =
    5252  (
    53     (ShortText: 'ys'; FullText: 'yocto'; Value: 1e-24),
    54           (ShortText: 'zs'; FullText: 'zepto'; Value: 1e-21),
    55     (ShortText: 'as'; FullText: 'atto'; Value: 1e-18),
    56     (ShortText: 'fs'; FullText: 'femto'; Value: 1e-15),
    57     (ShortText: 'ps'; FullText: 'piko'; Value: 1e-12),
    58     (ShortText: 'ns'; FullText: 'nano'; Value: 1e-9),
    59     (ShortText: 'us'; FullText: 'mikro'; Value: 1e-6),
    60     (ShortText: 'ms'; FullText: 'mili'; Value: 1e-3),
     53    (ShortText: 'ys'; FullText: 'yocto'; Value: 1E-24),
     54          (ShortText: 'zs'; FullText: 'zepto'; Value: 1E-21),
     55    (ShortText: 'as'; FullText: 'atto'; Value: 1E-18),
     56    (ShortText: 'fs'; FullText: 'femto'; Value: 1E-15),
     57    (ShortText: 'ps'; FullText: 'piko'; Value: 1E-12),
     58    (ShortText: 'ns'; FullText: 'nano'; Value: 1E-9),
     59    (ShortText: 'us'; FullText: 'mikro'; Value: 1E-6),
     60    (ShortText: 'ms'; FullText: 'mili'; Value: 1E-3),
    6161    (ShortText: 's'; FullText: 'sekunda'; Value: 1),
    6262    (ShortText: 'min'; FullText: 'minuta'; Value: 60),
  • trunk/Packages/Common/UResetableThread.pas

    r423 r447  
    296296end.
    297297
     298
  • trunk/Packages/Common/UScaleDPI.pas

    r424 r447  
    259259    begin
    260260      ImgList.Add(Temp[I], nil);
    261       Temp[i].Free;
     261      Temp[I].Free;
    262262    end;
    263263  finally
  • trunk/Packages/Common/UStringTable.pas

    r424 r447  
    3939function TStringTable.GetColCount: Integer;
    4040begin
    41   Result := Size.x;
     41  Result := Size.X;
    4242end;
    4343
  • trunk/Packages/Common/UTheme.pas

    r424 r447  
    188188
    189189end.
     190
  • trunk/Packages/Common/UTranslator.pas

    r424 r447  
    420420
    421421  if Lang = '' then begin
    422     for i := 1 to Paramcount - 1 do
    423       if (ParamStr(i) = '--LANG') or (ParamStr(i) = '-l') or
    424         (ParamStr(i) = '--lang') then
    425         Lang := ParamStr(i + 1);
     422    for I := 1 to Paramcount - 1 do
     423      if (ParamStr(I) = '--LANG') or (ParamStr(I) = '-l') or
     424        (ParamStr(I) = '--lang') then
     425        Lang := ParamStr(I + 1);
    426426  end;
    427427  if Lang = '' then begin
     
    473473      DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    474474    if FileExistsUTF8(Result) then
    475       exit;
     475      Exit;
    476476
    477477    Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator + LangID +
    478478      DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    479479    if FileExistsUTF8(Result) then
    480       exit;
     480      Exit;
    481481
    482482    Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
    483483      + LangID + DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    484484    if FileExistsUTF8(Result) then
    485       exit;
     485      Exit;
    486486
    487487    Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
     
    489489      ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    490490    if FileExistsUTF8(Result) then
    491       exit;
     491      Exit;
    492492
    493493    {$IFDEF UNIX}
     
    496496      ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    497497    if FileExistsUTF8(Result) then
    498       exit;
     498      Exit;
    499499    {$ENDIF}
    500500    // Let us search for reducted files
    501     LangShortID := copy(LangID, 1, 2);
     501    LangShortID := Copy(LangID, 1, 2);
    502502    // At first, check all was checked
    503503    Result := ExtractFilePath(ParamStrUTF8(0)) + LangShortID +
    504504      DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    505505    if FileExistsUTF8(Result) then
    506       exit;
     506      Exit;
    507507
    508508    Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator +
     
    510510      ExtractFileName(ParamStrUTF8(0)), LCExt);
    511511    if FileExistsUTF8(Result) then
    512       exit;
     512      Exit;
    513513
    514514    Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
     
    516516      ExtractFileName(ParamStrUTF8(0)), LCExt);
    517517    if FileExistsUTF8(Result) then
    518       exit;
     518      Exit;
    519519
    520520    Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator
     
    522522      ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    523523    if FileExistsUTF8(Result) then
    524       exit;
     524      Exit;
    525525
    526526    // Full language in file name - this will be default for the project
     
    529529      Result := ExtractFilePath(ParamStrUTF8(0)) + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangID])) + LCExt;
    530530      if FileExistsUTF8(Result) then
    531         exit;
     531        Exit;
    532532      // Common location (like in Lazarus)
    533533      Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator +
    534534        ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangID])) + LCExt;
    535535      if FileExistsUTF8(Result) then
    536         exit;
     536        Exit;
    537537
    538538      Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' +
    539539        DirectorySeparator + ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangID])) + LCExt;
    540540      if FileExistsUTF8(Result) then
    541         exit;
     541        Exit;
    542542    except
    543543      Result := ''; // Or do something else (useless)
     
    548548      ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), LCExt);
    549549    if FileExistsUTF8(Result) then
    550       exit;
     550      Exit;
    551551    {$ENDIF}
    552552    Result := ExtractFilePath(ParamStrUTF8(0)) + ChangeFileExt(
    553553      ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangShortID])) + LCExt;
    554554    if FileExistsUTF8(Result) then
    555       exit;
     555      Exit;
    556556
    557557    Result := ExtractFilePath(ParamStrUTF8(0)) + 'locale' + DirectorySeparator +
    558558      ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangShortID])) + LCExt;
    559559    if FileExistsUTF8(Result) then
    560       exit;
     560      Exit;
    561561
    562562    Result := ExtractFilePath(ParamStrUTF8(0)) + 'languages' + DirectorySeparator +
    563563      ChangeFileExt(ExtractFileName(ParamStrUTF8(0)), Format(FormatLang, [LangShortID])) + LCExt;
    564564    if FileExistsUTF8(Result) then
    565       exit;
     565      Exit;
    566566  end;
    567567
  • trunk/Platform.pas

    r442 r447  
    6161end.
    6262
     63
  • trunk/Protocol.pas

    r420 r447  
    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),
     
    15631563  TGetCityData = record
    15641564    Owner: Integer;
    1565     c: TCity;
     1565    C: TCity;
    15661566  end;
    15671567
     
    16441644  TCreateUnitData = record
    16451645    Loc: Integer;
    1646     p: Integer;
     1646    P: Integer;
    16471647    mix: Integer;
    16481648  end;
     
    16531653  TOwnerList = array [0 .. INFIN] of ShortInt;
    16541654  TByteList = array [0 .. INFIN] of Byte;
    1655   TIntList = array [0 .. INFIN] of integer;
     1655  TIntList = array [0 .. INFIN] of Integer;
    16561656  TCityList = array [0 .. INFIN] of TCity;
    16571657  TUnList = array [0 .. INFIN] of TUn;
     
    18151815    0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
    18161816
    1817   SpecialModelPreq: array [0 .. nSpecialModel - 1] of integer = (preNone,
     1817  SpecialModelPreq: array [0 .. nSpecialModel - 1] of Integer = (preNone,
    18181818    adExplosives, preNone, preNone, (* adWri, *) adIntelligence, adTrade,
    18191819    (* adTheCorporation,adHorsebackRiding,adAutomobile,adNavigation,
     
    18241824  DelphiRandSeed: Integer;
    18251825
    1826 procedure MakeUnitInfo(p: Integer; const u: TUn; var ui: TUnitInfo);
    1827 procedure MakeModelInfo(p, mix: Integer; const m: TModel; var mi: TModelInfo);
     1826procedure MakeUnitInfo(P: Integer; const U: TUn; var ui: TUnitInfo);
     1827procedure MakeModelInfo(P, mix: Integer; const M: TModel; var mi: TModelInfo);
    18281828function IsSameModel(const mi1, mi2: TModelInfo): Boolean;
    18291829function SpecialTile(Loc, TerrType, lx: Integer): Integer;
     
    18361836implementation
    18371837
    1838 procedure MakeUnitInfo(p: Integer; const u: TUn; var ui: TUnitInfo);
     1838procedure MakeUnitInfo(P: Integer; const U: TUn; var ui: TUnitInfo);
    18391839begin
    1840   ui.Owner := p;
    1841   ui.Loc := u.Loc;
    1842   ui.Health := u.Health;
    1843   ui.Fuel := u.Fuel;
    1844   ui.Job := u.Job;
    1845   ui.Exp := u.Exp;
    1846   ui.Load := u.TroopLoad + u.AirLoad;
    1847   ui.mix := u.mix;
    1848   ui.Flags := u.Flags;
     1840  ui.Owner := P;
     1841  ui.Loc := U.Loc;
     1842  ui.Health := U.Health;
     1843  ui.Fuel := U.Fuel;
     1844  ui.Job := U.Job;
     1845  ui.Exp := U.Exp;
     1846  ui.Load := U.TroopLoad + U.AirLoad;
     1847  ui.mix := U.mix;
     1848  ui.Flags := U.Flags;
    18491849end;
    18501850
    1851 procedure MakeModelInfo(p, mix: Integer; const m: TModel; var mi: TModelInfo);
     1851procedure MakeModelInfo(P, mix: Integer; const M: TModel; var mi: TModelInfo);
    18521852var
    1853   i: Integer;
     1853  I: Integer;
    18541854begin
    1855   mi.Owner := p;
     1855  mi.Owner := P;
    18561856  mi.mix := mix;
    1857   mi.ID := m.ID;
    1858   mi.Domain := m.Domain;
    1859   if m.Kind = mkEnemyDeveloped then
     1857  mi.ID := M.ID;
     1858  mi.Domain := M.Domain;
     1859  if M.Kind = mkEnemyDeveloped then
    18601860    mi.Kind := mkSelfDeveloped // important for IsSameModel()
    18611861  else
    1862     mi.Kind := m.Kind;
    1863   mi.Attack := m.Attack;
    1864   mi.Defense := m.Defense;
    1865   mi.Speed := m.Speed;
    1866   mi.Cost := m.Cost;
     1862    mi.Kind := M.Kind;
     1863  mi.Attack := M.Attack;
     1864  mi.Defense := M.Defense;
     1865  mi.Speed := M.Speed;
     1866  mi.Cost := M.Cost;
    18671867  if mi.Domain = dAir then
    18681868  begin
    1869     mi.TTrans := m.Cap[mcAirTrans] * m.MTrans;
    1870     mi.ATrans_Fuel := m.Cap[mcFuel];
     1869    mi.TTrans := M.Cap[mcAirTrans] * M.MTrans;
     1870    mi.ATrans_Fuel := M.Cap[mcFuel];
    18711871  end
    18721872  else
    18731873  begin
    1874     mi.TTrans := m.Cap[mcSeaTrans] * m.MTrans;
    1875     mi.ATrans_Fuel := m.Cap[mcCarrier] * m.MTrans;
    1876   end;
    1877   mi.Bombs := m.Cap[mcBombs] * m.MStrength * 2;
     1874    mi.TTrans := M.Cap[mcSeaTrans] * M.MTrans;
     1875    mi.ATrans_Fuel := M.Cap[mcCarrier] * M.MTrans;
     1876  end;
     1877  mi.Bombs := M.Cap[mcBombs] * M.MStrength * 2;
    18781878  mi.Cap := 0;
    1879   for i := mcFirstNonCap to nFeature - 1 do
    1880     if m.Cap[i] > 0 then
    1881       mi.Cap := mi.Cap or (1 shl (i - mcFirstNonCap));
     1879  for I := mcFirstNonCap to nFeature - 1 do
     1880    if M.Cap[I] > 0 then
     1881      mi.Cap := mi.Cap or (1 shl (I - mcFirstNonCap));
    18821882  mi.MaxUpgrade := 0;
    1883   for i := 1 to nUpgrade - 1 do
    1884     if m.Upgrades and (1 shl i) <> 0 then
    1885       mi.MaxUpgrade := i;
    1886   mi.Weight := m.Weight;
     1883  for I := 1 to nUpgrade - 1 do
     1884    if M.Upgrades and (1 shl I) <> 0 then
     1885      mi.MaxUpgrade := I;
     1886  mi.Weight := M.Weight;
    18871887  mi.Lost := 0;
    18881888end;
     
    18961896  Compare1 := @mi1;
    18971897  Compare2 := @mi2;
    1898   result := (Compare1[1] and $FFFF0000 = Compare2[1] and $FFFF0000) and
     1898  Result := (Compare1[1] and $FFFF0000 = Compare2[1] and $FFFF0000) and
    18991899    (Compare1[2] = Compare2[2]) and (Compare1[3] = Compare2[3]) and
    19001900    (Compare1[4] = Compare2[4]) and (Compare1[5] = Compare2[5])
     
    19031903function SpecialTile(Loc, TerrType, lx: Integer): Integer;
    19041904var
    1905   x, y, qx, qy, a: Integer;
     1905  X, Y, qx, qy, A: Integer;
    19061906begin
    19071907  if TerrType = fOcean then
    1908     result := 0
     1908    Result := 0
    19091909  else
    19101910  begin
    1911     y := Loc div lx;
    1912     x := Loc - y * lx;
     1911    Y := Loc div lx;
     1912    X := Loc - Y * lx;
    19131913    if TerrType = fGrass then { formula for productive grassland }
    1914       if Odd((lymax + x - y shr 1) shr 1 + x + (y + 1) shr 1) then
    1915         result := 1
     1914      if Odd((lymax + X - Y shr 1) shr 1 + X + (Y + 1) shr 1) then
     1915        Result := 1
    19161916      else
    1917         result := 0
     1917        Result := 0
    19181918    else { formula for special resources }
    19191919    begin
    1920       a := 4 * x - y + 9980;
    1921       qx := a div 10;
    1922       if (qx * 10 = a) and (qx and 3 <> 0) then
     1920      A := 4 * X - Y + 9980;
     1921      qx := A div 10;
     1922      if (qx * 10 = A) and (qx and 3 <> 0) then
    19231923      begin
    1924         qy := (y + x) div 5;
     1924        qy := (Y + X) div 5;
    19251925        if qy and 3 <> qx shr 2 and 1 * 2 then
    19261926          if (TerrType = fArctic) or (TerrType = fSwamp) then
    1927             result := 1
     1927            Result := 1
    19281928          else if TerrType = fShore then
    19291929          begin
    19301930            if (qx + qy) and 1 = 0 then
    19311931              if qx and 3 = 2 then
    1932                 result := 2
     1932                Result := 2
    19331933              else
    1934                 result := 1
     1934                Result := 1
    19351935            else
    1936               result := 0
     1936              Result := 0
    19371937          end
    19381938          else
    1939             result := (qx + qy) and 1 + 1
     1939            Result := (qx + qy) and 1 + 1
    19401940        else
    1941           result := 0;
     1941          Result := 0;
    19421942      end
    19431943      else
    1944         result := 0;
     1944        Result := 0;
    19451945    end;
    19461946  end;
  • trunk/Settings.pas

    r433 r447  
    293293end.
    294294
     295
  • trunk/Start.pas

    r442 r447  
    6969    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    7070    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    71       Shift: TShiftState; x, y: integer);
     71      Shift: TShiftState; X, Y: Integer);
    7272    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
    73       Shift: TShiftState; x, y: integer);
    74     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; x, y: integer);
     73      Shift: TShiftState; X, Y: Integer);
     74    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    7575    procedure Up1BtnClick(Sender: TObject);
    7676    procedure Down1BtnClick(Sender: TObject);
     
    122122    MiniMap: TMiniMap;
    123123    LastGame: string;
    124     procedure DrawAction(y, IconIndex: integer; HeaderItem, TextItem: string);
     124    procedure DrawAction(Y, IconIndex: Integer; HeaderItem, TextItem: string);
    125125    procedure InitPopup(PlayerIndex: Integer);
    126126    procedure OfferBrain(Brain: TBrain; FixedLines: Integer);
     
    129129    procedure ChangeTab(NewTab: TStartTab);
    130130    procedure UnlistBackupFile(FileName: string);
    131     procedure SmartInvalidate(x0, y0, x1, y1: integer;
    132       invalidateTab0: boolean = false); overload;
     131    procedure SmartInvalidate(x0, y0, x1, y1: Integer;
     132      invalidateTab0: Boolean = False); overload;
    133133    procedure LoadConfig;
    134134    procedure SaveConfig;
     
    160160  // attention: lx*ly+1 must be prime!
    161161  { MaxWorldSize=8;
    162     lxpre: array[0..nWorldSize-1] of integer =(30,40,50,60,70,90,110,130);
    163     lypre: array[0..nWorldSize-1] of integer =(46,52,60,70,84,94,110,130);
     162    lxpre: array[0..nWorldSize-1] of Integer =(30,40,50,60,70,90,110,130);
     163    lypre: array[0..nWorldSize-1] of Integer =(46,52,60,70,84,94,110,130);
    164164    DefaultWorldTiles=4200; }
    165165  MaxWorldSize = 6;
     
    192192  dxBrain = 104;
    193193  dyBrain = 80;
    194   xBrain: array [0 .. nPlOffered - 1] of integer = (x0Brain, x0Brain,
     194  xBrain: array [0 .. nPlOffered - 1] of Integer = (x0Brain, x0Brain,
    195195    x0Brain + dxBrain, x0Brain + dxBrain, x0Brain + dxBrain, x0Brain,
    196196    x0Brain - dxBrain, x0Brain - dxBrain, x0Brain - dxBrain);
    197   yBrain: array [0 .. nPlOffered - 1] of integer = (y0Brain, y0Brain - dyBrain,
     197  yBrain: array [0 .. nPlOffered - 1] of Integer = (y0Brain, y0Brain - dyBrain,
    198198    y0Brain - dyBrain, y0Brain, y0Brain + dyBrain, y0Brain + dyBrain,
    199199    y0Brain + dyBrain, y0Brain, y0Brain - dyBrain);
     
    202202  TabHeight = 40;
    203203
    204   InitAlive: array [1 .. nPl] of integer = (1, 1 + 2, 1 + 2 + 32,
     204  InitAlive: array [1 .. nPl] of Integer = (1, 1 + 2, 1 + 2 + 32,
    205205    1 + 2 + 8 + 128, 1 + 2 + 8 + 32 + 128, 1 + 2 + 8 + 16 + 64 + 128,
    206206    1 + 2 + 4 + 16 + 32 + 64 + 256, 511 - 32, 511, 511 - 32, 511, 511 - 32, 511,
    207207    511 - 32, 511);
    208   InitMulti: array [nPlOffered + 1 .. nPl] of integer = (256, 256, 256 + 128,
     208  InitMulti: array [nPlOffered + 1 .. nPl] of Integer = (256, 256, 256 + 128,
    209209    256 + 128, 256 + 128 + 64, 256 + 128 + 64);
    210210
    211   PlayerAutoDiff: array [1 .. 5] of integer = (1, 1, 2, 2, 3);
    212   EnemyAutoDiff: array [1 .. 5] of integer = (4, 3, 2, 1, 1);
     211  PlayerAutoDiff: array [1 .. 5] of Integer = (1, 1, 2, 2, 3);
     212  EnemyAutoDiff: array [1 .. 5] of Integer = (4, 3, 2, 1, 1);
    213213
    214214{ TStartDlg }
     
    216216procedure TStartDlg.FormCreate(Sender: TObject);
    217217var
    218   x, i: Integer;
     218  X, I: Integer;
    219219  PlayerSlot: TPlayerSlot;
    220220  AIBrains: TBrains;
     
    236236
    237237  BrainDefault := nil;
    238   for i := Brains.IndexOf(BrainRandom) to Brains.Count - 1 do
    239     if AnsiCompareFileName(DefaultAI, Brains[i].FileName) = 0 then
    240       BrainDefault := Brains[i];
     238  for I := Brains.IndexOf(BrainRandom) to Brains.Count - 1 do
     239    if AnsiCompareFileName(DefaultAI, Brains[I].FileName) = 0 then
     240      BrainDefault := Brains[I];
    241241  if (BrainDefault = BrainRandom) and (Brains.GetKindCount(btAI) < 2) then
    242242    BrainDefault := nil;
     
    260260  ReplayBtn.Hint := Phrases.Lookup('BTN_REPLAY');
    261261  PlayerSlots.Count := nPlOffered;
    262   for i := 0 to PlayerSlots.Count - 1 do
    263   with PlayerSlots[i] do begin
     262  for I := 0 to PlayerSlots.Count - 1 do
     263  with PlayerSlots[I] do begin
    264264    DiffUpBtn := TButtonC.Create(self);
    265265    DiffUpBtn.Graphic := HGrSystem.Data;
    266     DiffUpBtn.left := xBrain[i] - 18;
    267     DiffUpBtn.top := yBrain[i] + 39;
     266    DiffUpBtn.left := xBrain[I] - 18;
     267    DiffUpBtn.top := yBrain[I] + 39;
    268268    DiffUpBtn.ButtonIndex := 1;
    269269    DiffUpBtn.Parent := self;
     
    271271    DiffDownBtn := TButtonC.Create(self);
    272272    DiffDownBtn.Graphic := HGrSystem.Data;
    273     DiffDownBtn.left := xBrain[i] - 18;
    274     DiffDownBtn.top := yBrain[i] + 51;
     273    DiffDownBtn.left := xBrain[I] - 18;
     274    DiffDownBtn.top := yBrain[I] + 51;
    275275    DiffDownBtn.ButtonIndex := 0;
    276276    DiffDownBtn.Parent := self;
    277277    DiffDownBtn.OnClick := DiffBtnClick;
    278278  end;
    279   for i := 6 to 8 do
    280   with PlayerSlots[i] do begin
     279  for I := 6 to 8 do
     280  with PlayerSlots[I] do begin
    281281    MultiBtn := TButtonC.Create(self);
    282282    MultiBtn.Graphic := HGrSystem.Data;
    283     MultiBtn.left := xBrain[i] - 18;
    284     MultiBtn.top := yBrain[i];
     283    MultiBtn.left := xBrain[I] - 18;
     284    MultiBtn.top := yBrain[I];
    285285    MultiBtn.Parent := self;
    286286    MultiBtn.OnClick := MultiBtnClick;
     
    288288  end;
    289289
    290   x := BiColorTextWidth(Canvas, Phrases.Lookup('STARTCONTROLS', 7)) div 2;
    291   CustomizeBtn.left := x0Brain + 32 - 16 - x;
     290  X := BiColorTextWidth(Canvas, Phrases.Lookup('STARTCONTROLS', 7)) div 2;
     291  CustomizeBtn.left := x0Brain + 32 - 16 - X;
    292292  if AutoDiff < 0 then
    293293    CustomizeBtn.ButtonIndex := 3
     
    339339end;
    340340
    341 procedure TStartDlg.SmartInvalidate(x0, y0, x1, y1: integer;
    342   invalidateTab0: boolean);
    343 var
    344   i: integer;
     341procedure TStartDlg.SmartInvalidate(x0, y0, x1, y1: Integer;
     342  invalidateTab0: Boolean);
     343var
     344  I: Integer;
    345345  r0, r1: HRgn;
    346346begin
    347347  r0 := CreateRectRgn(x0, y0, x1, y1);
    348   for i := 0 to ControlCount - 1 do
    349     if not (Controls[i] is TArea) and Controls[i].Visible then
     348  for I := 0 to ControlCount - 1 do
     349    if not (Controls[I] is TArea) and Controls[I].Visible then
    350350    begin
    351       with Controls[i].BoundsRect do
     351      with Controls[I].BoundsRect do
    352352        r1 := CreateRectRgn(left, top, Right, Bottom);
    353353      CombineRgn(r0, r0, r1, RGN_DIFF);
     
    359359    DeleteObject(r1);
    360360  end;
    361   InvalidateRgn(Handle, r0, false);
     361  InvalidateRgn(Handle, r0, False);
    362362  DeleteObject(r0);
    363363end;
     
    530530end;
    531531
    532 procedure TStartDlg.DrawAction(y, IconIndex: integer; HeaderItem, TextItem: string);
     532procedure TStartDlg.DrawAction(Y, IconIndex: Integer; HeaderItem, TextItem: string);
    533533begin
    534534  Canvas.Font.Assign(UniFont[ftCaption]);
    535535  Canvas.Font.Style := Canvas.Font.Style + [fsUnderline];
    536   RisedTextOut(Canvas, xAction, y - 3, Phrases2.Lookup(HeaderItem));
     536  RisedTextOut(Canvas, xAction, Y - 3, Phrases2.Lookup(HeaderItem));
    537537  Canvas.Font.Assign(UniFont[ftNormal]);
    538538  BiColorTextOut(Canvas, Colors.Canvas.Pixels[clkAge0 - 1, cliDimmedText],
    539     $000000, xAction, y + 21, Phrases2.Lookup(TextItem));
     539    $000000, xAction, Y + 21, Phrases2.Lookup(TextItem));
    540540
    541541  UnshareBitmap(LogoBuffer);
    542542  BitBltCanvas(LogoBuffer.Canvas, 0, 0, 50, 50, Canvas,
    543     xActionIcon - 2, y - 2);
     543    xActionIcon - 2, Y - 2);
    544544  GlowFrame(LogoBuffer, 8, 8, 34, 34, $202020);
    545   BitBltCanvas(Canvas, xActionIcon - 2, y - 2, 50, 50,
     545  BitBltCanvas(Canvas, xActionIcon - 2, Y - 2, 50, 50,
    546546    LogoBuffer.Canvas, 0, 0);
    547   BitBltCanvas(Canvas, xActionIcon, y, 40, 40, BigImp.Canvas,
     547  BitBltCanvas(Canvas, xActionIcon, Y, 40, 40, BigImp.Canvas,
    548548    (IconIndex mod 7) * xSizeBig + 8, (IconIndex div 7) * ySizeBig);
    549   RFrame(Canvas, xActionIcon - 1, y - 1, xActionIcon + 40, y + 40,
     549  RFrame(Canvas, xActionIcon - 1, Y - 1, xActionIcon + 40, Y + 40,
    550550    $000000, $000000);
    551551end;
     
    555555  TabNames: array[TStartTab] of Integer = (0, 11, 3, 4);
    556556var
    557   i, w, h, xMini, yMini, y: integer;
    558   s: string;
     557  I, W, H, xMini, yMini, Y: Integer;
     558  S: string;
    559559  Tab2: TStartTab;
    560560  MainAction: TMainAction;
     
    588588
    589589  // draw tabs
    590   Frame(Canvas, 2, 2 + 2 * integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize - 1,
     590  Frame(Canvas, 2, 2 + 2 * Integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize - 1,
    591591    TabHeight, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    592   Frame(Canvas, 1, 1 + 2 * integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize,
     592  Frame(Canvas, 1, 1 + 2 * Integer(Tab <> tbMain), TabOffset + (0 + 1) * TabSize,
    593593    TabHeight, MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
    594   Canvas.Pixels[1, 1 + 2 * integer(Tab <> tbMain)] := MainTexture.ColorBevelShade;
     594  Canvas.Pixels[1, 1 + 2 * Integer(Tab <> tbMain)] := MainTexture.ColorBevelShade;
    595595  for Tab2 := tbMap to tbPrevious do
    596596  begin
    597     Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 2, 2 + 2 * integer(Tab <> Tab2),
     597    Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 2, 2 + 2 * Integer(Tab <> Tab2),
    598598      TabOffset + (Integer(Tab2) + 1) * TabSize - 1, TabHeight, MainTexture.ColorBevelLight,
    599599      MainTexture.ColorBevelShade);
    600     Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * integer(Tab <> Tab2),
     600    Frame(Canvas, TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * Integer(Tab <> Tab2),
    601601      TabOffset + (Integer(Tab2) + 1) * TabSize, TabHeight, MainTexture.ColorBevelLight,
    602602      MainTexture.ColorBevelShade);
    603     Canvas.Pixels[TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * integer(Tab <> Tab2)] :=
     603    Canvas.Pixels[TabOffset + Integer(Tab2) * TabSize + 1, 1 + 2 * Integer(Tab <> Tab2)] :=
    604604      MainTexture.ColorBevelShade;
    605605  end;
     
    607607  for Tab2 := tbMap to tbPrevious do
    608608  begin
    609     s := Phrases.Lookup('STARTCONTROLS', TabNames[Tab2]);
     609    S := Phrases.Lookup('STARTCONTROLS', TabNames[Tab2]);
    610610    RisedTextOut(Canvas, TabOffset + Integer(Tab2) * TabSize + 1 +
    611       (TabSize - BiColorTextWidth(Canvas, s)) div 2,
    612       10 + 2 * integer(Tab <> Tab2), s);
     611      (TabSize - BiColorTextWidth(Canvas, S)) div 2,
     612      10 + 2 * Integer(Tab <> Tab2), S);
    613613  end;
    614614  Frame(Canvas, TabOffset + 4 * TabSize + 1, -1, ClientWidth, TabHeight,
     
    640640  UnshareBitmap(LogoBuffer);
    641641  BitBltCanvas(LogoBuffer.Canvas, 0, 0, MenuLogo.Width, MenuLogo.Height, Canvas, 6,
    642     3 + 2 * integer(Tab <> tbMain));
     642    3 + 2 * Integer(Tab <> tbMain));
    643643
    644644  ImageOp_BCC(LogoBuffer, Templates.Data, 0, 0, MenuLogo.Left, MenuLogo.Top,
     
    646646  ImageOp_BCC(LogoBuffer, Templates.Data, 10, 27, MenuLogo.Left + 10,
    647647    MenuLogo.Top + 27, MenuLogo.Width - 10, 9, $BFBF20, $4040DF); // logo part 2
    648   BitBltCanvas(Canvas, 6, 3 + 2 * integer(Tab <> tbMain), MenuLogo.Width, MenuLogo.Height,
     648  BitBltCanvas(Canvas, 6, 3 + 2 * Integer(Tab <> tbMain), MenuLogo.Width, MenuLogo.Height,
    649649    LogoBuffer.Canvas, 0, 0);
    650650
    651651  if Page = pgMain then begin
    652652    if SelectedAction <> maNone then // mark selected action
    653       for i := 0 to (ClientWidth - 2 * ActionSideBorder) div wBuffer + 1 do
     653      for I := 0 to (ClientWidth - 2 * ActionSideBorder) div wBuffer + 1 do
    654654      begin
    655         w := ClientWidth - 2 * ActionSideBorder - i * wBuffer;
    656         if w > wBuffer then
    657           w := wBuffer;
    658         h := ActionPitch;
    659         if yAction + Integer(SelectedAction) * ActionPitch - 8 + h > ClientHeight - ActionBottomBorder
     655        W := ClientWidth - 2 * ActionSideBorder - I * wBuffer;
     656        if W > wBuffer then
     657          W := wBuffer;
     658        H := ActionPitch;
     659        if yAction + Integer(SelectedAction) * ActionPitch - 8 + H > ClientHeight - ActionBottomBorder
    660660        then
    661           h := ClientHeight - ActionBottomBorder -
     661          H := ClientHeight - ActionBottomBorder -
    662662            (yAction + Integer(SelectedAction) * ActionPitch - 8);
    663663
    664664        UnshareBitmap(LogoBuffer);
    665         BitBltCanvas(LogoBuffer.Canvas, 0, 0, w, h, Canvas,
    666           ActionSideBorder + i * wBuffer, yAction + Integer(SelectedAction) * ActionPitch
     665        BitBltCanvas(LogoBuffer.Canvas, 0, 0, W, H, Canvas,
     666          ActionSideBorder + I * wBuffer, yAction + Integer(SelectedAction) * ActionPitch
    667667          - 8);
    668         MakeBlue(LogoBuffer, 0, 0, w, h);
    669         BitBltCanvas(Canvas, ActionSideBorder + i * wBuffer,
    670           yAction + Integer(SelectedAction) * ActionPitch - 8, w, h,
     668        MakeBlue(LogoBuffer, 0, 0, W, H);
     669        BitBltCanvas(Canvas, ActionSideBorder + I * wBuffer,
     670          yAction + Integer(SelectedAction) * ActionPitch - 8, W, H,
    671671          LogoBuffer.Canvas, 0, 0);
    672672      end;
    673     y := yAction;
     673    Y := yAction;
    674674    for MainAction := Low(TMainActionSet) to High(TMainActionSet) do
    675675    begin
    676676      if MainAction in ActionsOffered then
    677677        case MainAction of
    678           maConfig: DrawAction(y, 25, 'ACTIONHEADER_CONFIG', 'ACTION_CONFIG');
    679           maManual: DrawAction(y, 19, 'ACTIONHEADER_MANUAL', 'ACTION_MANUAL');
    680           maCredits: DrawAction(y, 22, 'ACTIONHEADER_CREDITS', 'ACTION_CREDITS');
    681           maAIDev: DrawAction(y, 24, 'ACTIONHEADER_AIDEV', 'ACTION_AIDEV');
     678          maConfig: DrawAction(Y, 25, 'ACTIONHEADER_CONFIG', 'ACTION_CONFIG');
     679          maManual: DrawAction(Y, 19, 'ACTIONHEADER_MANUAL', 'ACTION_MANUAL');
     680          maCredits: DrawAction(Y, 22, 'ACTIONHEADER_CREDITS', 'ACTION_CREDITS');
     681          maAIDev: DrawAction(Y, 24, 'ACTIONHEADER_AIDEV', 'ACTION_AIDEV');
    682682          maWeb:
    683683            begin
    684684              Canvas.Font.Assign(UniFont[ftCaption]);
    685685              // Canvas.Font.Style:=Canvas.Font.Style+[fsUnderline];
    686               RisedTextOut(Canvas, xActionIcon + 99, y,
     686              RisedTextOut(Canvas, xActionIcon + 99, Y,
    687687                Format(Phrases2.Lookup('ACTIONHEADER_WEB'), [CevoHomepageShort]));
    688688              Canvas.Font.Assign(UniFont[ftNormal]);
     
    690690              UnshareBitmap(LogoBuffer);
    691691              BitBltCanvas(LogoBuffer.Canvas, 0, 0, LinkArrows.Width, LinkArrows.Height, Canvas,
    692                 xActionIcon, y + 2);
     692                xActionIcon, Y + 2);
    693693              ImageOp_BCC(LogoBuffer, Templates.Data, Point(0, 0), LinkArrows.BoundsRect, 0,
    694694                Colors.Canvas.Pixels[clkAge0 - 1, cliDimmedText]);
    695               BitBltCanvas(Canvas, xActionIcon, y + 2, LinkArrows.Width, LinkArrows.Height,
     695              BitBltCanvas(Canvas, xActionIcon, Y + 2, LinkArrows.Width, LinkArrows.Height,
    696696                LogoBuffer.Canvas, 0, 0);
    697697            end;
    698698        end;
    699       Inc(y, ActionPitch);
     699      Inc(Y, ActionPitch);
    700700    end;
    701701  end
     
    705705      TurnToString(MaxTurn), 344, y0Mini + 61, 170);
    706706
    707     s := Phrases.Lookup('STARTCONTROLS', 7);
    708     w := Canvas.TextWidth(s);
    709     LoweredTextOut(Canvas, -2, MainTexture, x0Brain + 32 - w div 2,
    710       y0Brain + dyBrain + 69, s);
     707    S := Phrases.Lookup('STARTCONTROLS', 7);
     708    W := Canvas.TextWidth(S);
     709    LoweredTextOut(Canvas, -2, MainTexture, x0Brain + 32 - W div 2,
     710      y0Brain + dyBrain + 69, S);
    711711
    712712    InitOrnament;
    713713    if AutoDiff < 0 then
    714714    begin
    715       for i := 12 to 19 do
    716         if (i < 13) or (i > 17) then begin
    717           BitBltCanvas(Canvas, 9 + i * 27, yLogo - 2, Ornament.Width, Ornament.Height,
     715      for I := 12 to 19 do
     716        if (I < 13) or (I > 17) then begin
     717          BitBltCanvas(Canvas, 9 + I * 27, yLogo - 2, Ornament.Width, Ornament.Height,
    718718            HGrSystem2.Mask.Canvas, Ornament.Left, Ornament.Top, SRCAND);
    719           BitBltCanvas(Canvas, 9 + i * 27, yLogo - 2, Ornament.Width, Ornament.Height,
     719          BitBltCanvas(Canvas, 9 + I * 27, yLogo - 2, Ornament.Width, Ornament.Height,
    720720            HGrSystem2.Data.Canvas, Ornament.Left, Ornament.Top, SRCPAINT);
    721721        end;
     
    723723        MainTexture.ColorBevelShade);
    724724
    725       for i := 0 to nPlOffered - 1 do
    726         if 1 shl i and SlotAvailable <> 0 then
     725      for I := 0 to nPlOffered - 1 do
     726        if 1 shl I and SlotAvailable <> 0 then
    727727        begin
    728           if Assigned(PlayersBrain[i]) then
    729             FrameImage(Canvas, PlayersBrain[i].Picture, xBrain[i], yBrain[i],
    730               64, 64, 0, 0, true)
     728          if Assigned(PlayersBrain[I]) then
     729            FrameImage(Canvas, PlayersBrain[I].Picture, xBrain[I], yBrain[I],
     730              64, 64, 0, 0, True)
    731731          else
    732             FrameImage(Canvas, EmptyPicture, xBrain[i], yBrain[i], 64, 64,
    733               0, 0, true);
    734           if Assigned(PlayersBrain[I]) and (PlayersBrain[i].Kind in [btTerm, btRandom, btAI]) then
     732            FrameImage(Canvas, EmptyPicture, xBrain[I], yBrain[I], 64, 64,
     733              0, 0, True);
     734          if Assigned(PlayersBrain[I]) and (PlayersBrain[I].Kind in [btTerm, btRandom, btAI]) then
    735735          begin
    736             BitBltCanvas(Canvas, xBrain[i] - 18, yBrain[i] + 19, 12, 14,
    737               HGrSystem.Data.Canvas, 134 + (Difficulty[i] - 1) *
     736            BitBltCanvas(Canvas, xBrain[I] - 18, yBrain[I] + 19, 12, 14,
     737              HGrSystem.Data.Canvas, 134 + (Difficulty[I] - 1) *
    738738              13, 28);
    739             Frame(Canvas, xBrain[i] - 19, yBrain[i] + 18, xBrain[i] - 18 + 12,
    740               yBrain[i] + (19 + 14), $000000, $000000);
    741             RFrame(Canvas, PlayerSlots[i].DiffUpBtn.left - 1, PlayerSlots[i].DiffUpBtn.top - 1,
    742               PlayerSlots[i].DiffUpBtn.left + 12, PlayerSlots[i].DiffUpBtn.top + 24,
     739            Frame(Canvas, xBrain[I] - 19, yBrain[I] + 18, xBrain[I] - 18 + 12,
     740              yBrain[I] + (19 + 14), $000000, $000000);
     741            RFrame(Canvas, PlayerSlots[I].DiffUpBtn.left - 1, PlayerSlots[I].DiffUpBtn.top - 1,
     742              PlayerSlots[I].DiffUpBtn.left + 12, PlayerSlots[I].DiffUpBtn.top + 24,
    743743              MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    744744            with Canvas do
    745745            begin
    746746              Brush.Color := $000000;
    747               FillRect(Rect(xBrain[i] - 5, yBrain[i] + 25, xBrain[i] - 2,
    748                 yBrain[i] + 27));
     747              FillRect(Rect(xBrain[I] - 5, yBrain[I] + 25, xBrain[I] - 2,
     748                yBrain[I] + 27));
    749749              Brush.Style := bsClear;
    750750            end;
     
    754754                PlayerSlots[I].MultiBtn.left + 12, PlayerSlots[I].MultiBtn.top + 12,
    755755                MainTexture.ColorBevelShade, MainTexture.ColorBevelLight);
    756               BitBltCanvas(Canvas, xBrain[i] - 31, yBrain[i], 13, 12,
     756              BitBltCanvas(Canvas, xBrain[I] - 31, yBrain[I], 13, 12,
    757757                HGrSystem.Data.Canvas, 88, 47);
    758758            end;
    759759          end;
    760           if Assigned(PlayersBrain[i]) then
     760          if Assigned(PlayersBrain[I]) then
    761761          begin
    762             PlayerSlots[i].DiffUpBtn.Hint := Format(Phrases.Lookup('STARTCONTROLS', 9),
    763               [PlayersBrain[i].Name]);
    764             PlayerSlots[i].DiffDownBtn.Hint := PlayerSlots[i].DiffUpBtn.Hint;
     762            PlayerSlots[I].DiffUpBtn.Hint := Format(Phrases.Lookup('STARTCONTROLS', 9),
     763              [PlayersBrain[I].Name]);
     764            PlayerSlots[I].DiffDownBtn.Hint := PlayerSlots[I].DiffUpBtn.Hint;
    765765          end;
    766766        end;
     
    773773        yMain + 140 { y0Mini-77 } , Phrases.Lookup('STARTCONTROLS', 15));
    774774      if Page = pgStartRandom then
    775         s := IntToStr(AutoEnemies)
     775        S := IntToStr(AutoEnemies)
    776776      else if nMapStartPositions = 0 then
    777         s := '0'
     777        S := '0'
    778778      else
    779         s := IntToStr(nMapStartPositions - 1);
    780       RisedTextOut(Canvas, 198 - BiColorTextWidth(Canvas, s), yMain + 140, s);
     779        S := IntToStr(nMapStartPositions - 1);
     780      RisedTextOut(Canvas, 198 - BiColorTextWidth(Canvas, S), yMain + 140, S);
    781781
    782782      DLine(Canvas, 24, xDefault - 6, yMain + 164 + 19,
     
    786786      if AutoDiff = 1 then
    787787        FrameImage(Canvas, Brains.GetBeginner.Picture, xDefault, yDefault, 64,
    788           64, 0, 0, false)
     788          64, 0, 0, False)
    789789      else
    790790        FrameImage(Canvas, BrainDefault.Picture, xDefault, yDefault, 64, 64,
    791           0, 0, true);
     791          0, 0, True);
    792792      DLine(Canvas, 56, 272, y0Mini + 61 + 19, MainTexture.ColorBevelLight,
    793793        MainTexture.ColorBevelShade);
     
    795795      RisedTextOut(Canvas, 56, y0Mini + 61,
    796796        Phrases.Lookup('STARTCONTROLS', 14));
    797       s := Phrases.Lookup('AUTODIFF', AutoDiff - 1);
    798       RisedTextOut(Canvas, 272 - BiColorTextWidth(Canvas, s), y0Mini + 61, s);
    799 
    800       for i := 0 to 19 do
    801         if (i < 2) or (i > 6) then begin
    802           BitBltCanvas(Canvas, 9 + i * 27, yLogo - 2, Ornament.Width, Ornament.Height,
     797      S := Phrases.Lookup('AUTODIFF', AutoDiff - 1);
     798      RisedTextOut(Canvas, 272 - BiColorTextWidth(Canvas, S), y0Mini + 61, S);
     799
     800      for I := 0 to 19 do
     801        if (I < 2) or (I > 6) then begin
     802          BitBltCanvas(Canvas, 9 + I * 27, yLogo - 2, Ornament.Width, Ornament.Height,
    803803            HGrSystem2.Mask.Canvas, Ornament.Left, Ornament.Top, SRCAND);
    804           BitBltCanvas(Canvas, 9 + i * 27, yLogo - 2, Ornament.Width, Ornament.Height,
     804          BitBltCanvas(Canvas, 9 + I * 27, yLogo - 2, Ornament.Width, Ornament.Height,
    805805            HGrSystem2.Data.Canvas, Ornament.Left, Ornament.Top, SRCPAINT);
    806806        end;
     
    825825        MainTexture.ColorBevelShade);
    826826    RisedTextOut(Canvas, 344, y0Mini + 61, Phrases.Lookup('STARTCONTROLS', 8));
    827     s := TurnToString(LoadTurn);
    828     RisedTextOut(Canvas, 514 - BiColorTextWidth(Canvas, s), y0Mini + 61, s);
     827    S := TurnToString(LoadTurn);
     828    RisedTextOut(Canvas, 514 - BiColorTextWidth(Canvas, S), y0Mini + 61, S);
    829829  end
    830830  else if Page = pgEditRandom then
     
    840840  begin
    841841    // DLine(Canvas,344,514,y0Mini+61+19,MainTexture.ColorBevelLight,MainTexture.ColorBevelShade);
    842     s := Format(Phrases2.Lookup('MAPPROP'),
     842    S := Format(Phrases2.Lookup('MAPPROP'),
    843843      [(nMapLandTiles * 100 + 556) div 1112,
    844844      // 1112 is typical for world with 100% size and default land mass
    845845      nMapStartPositions]);
    846     RisedTextOut(Canvas, x0Mini - BiColorTextWidth(Canvas, s) div 2,
    847       y0Mini + 61, s);
     846    RisedTextOut(Canvas, x0Mini - BiColorTextWidth(Canvas, S) div 2,
     847      y0Mini + 61, S);
    848848  end;
    849849
     
    888888      MainTexture.ColorBevelLight);
    889889
    890     s := '';
     890    S := '';
    891891    if MiniMap.Mode = mmPicture then
    892892    begin
     
    894894        MiniMap.Bitmap.Canvas, 0, 0);
    895895      if Page = pgStartRandom then
    896         s := Phrases.Lookup('RANMAP')
     896        S := Phrases.Lookup('RANMAP')
    897897    end
    898898    else if MiniMap.Mode = mmMultiPlayer then
    899       s := Phrases.Lookup('MPMAP')
     899      S := Phrases.Lookup('MPMAP')
    900900    else if Page = pgStartMap then
    901       s := Copy(MapFileName, 1, Length(MapFileName) - Length(CevoMapExt))
     901      S := Copy(MapFileName, 1, Length(MapFileName) - Length(CevoMapExt))
    902902    else if Page = pgEditMap then
    903       s := List.Items[List.ItemIndex]
     903      S := List.Items[List.ItemIndex]
    904904    else if Page = pgNoLoad then
    905       s := Phrases.Lookup('NOGAMES');
    906     if s <> '' then
    907       RisedTextOut(Canvas, x0Mini + 2 - BiColorTextWidth(Canvas, s) div 2,
    908         y0Mini - 8, s);
     905      S := Phrases.Lookup('NOGAMES');
     906    if S <> '' then
     907      RisedTextOut(Canvas, x0Mini + 2 - BiColorTextWidth(Canvas, S) div 2,
     908        y0Mini - 8, S);
    909909  end;
    910910end;
     
    959959      begin // load
    960960        FileName := List.Items[List.ItemIndex];
    961         if LoadGame(GetSavedDir + DirectorySeparator, FileName + CevoExt, LoadTurn, false)
     961        if LoadGame(GetSavedDir + DirectorySeparator, FileName + CevoExt, LoadTurn, False)
    962962        then
    963963          UnlistBackupFile(FileName)
     
    979979        with Reg do
    980980        try
    981           OpenKey(AppRegistryKey, true);
     981          OpenKey(AppRegistryKey, True);
    982982          if ValueExists('GameCount') then GameCount := ReadInteger('GameCount')
    983983            else GameCount := 0;
     
    11681168          if Assigned(PlayersBrain[I]) and (PlayersBrain[I].Kind = btTerm) then begin
    11691169            PlayersBrain[I] := nil;
    1170             PlayerSlots[I].DiffUpBtn.Visible := false;
     1170            PlayerSlots[I].DiffUpBtn.Visible := False;
    11711171            PlayerSlots[I].DiffUpBtn.Tag := 0;
    1172             PlayerSlots[I].DiffDownBtn.Visible := false;
     1172            PlayerSlots[I].DiffDownBtn.Visible := False;
    11731173            PlayerSlots[I].DiffDownBtn.Tag := 0;
    11741174            if PlayerSlots[I].OfferMultiple then begin
    1175               PlayerSlots[I].MultiBtn.Visible := false;
     1175              PlayerSlots[I].MultiBtn.Visible := False;
    11761176              PlayerSlots[I].MultiBtn.Tag := 0;
    11771177            end;
     
    11991199  J := FixedLines;
    12001200  while (J < PopupMenu1.Items.Count) and
    1201     (StrIComp(pchar(MenuItem.Caption), pchar(PopupMenu1.Items[J].Caption)) > 0) do
     1201    (StrIComp(PChar(MenuItem.Caption), PChar(PopupMenu1.Items[J].Caption)) > 0) do
    12021202    Inc(J);
    12031203  MenuItem.RadioItem := True;
     
    12101210var
    12111211  I: Integer;
    1212   FixedLines: integer;
     1212  FixedLines: Integer;
    12131213  MenuItem: TMenuItem;
    12141214  AIBrains: TBrains;
     
    12441244    end;
    12451245    for I := Brains.IndexOf(BrainTerm) downto 0 do // offer game interfaces
    1246       if (PlayerPopupIndex = 0) or (Brains[i].Kind = btTerm) and
     1246      if (PlayerPopupIndex = 0) or (Brains[I].Kind = btTerm) and
    12471247        (PlayersBrain[0].Kind <> btNoTerm) then begin
    12481248        OfferBrain(Brains[I], FixedLines);
     
    12681268        if (AIBrains[I].Flags and fMultiple <> 0) or (AIBrains[I].Flags and fUsed = 0)
    12691269          or (Brains[I] = PlayersBrain[PlayerPopupIndex]) then
    1270           OfferBrain(AIBrains[i], FixedLines);
     1270          OfferBrain(AIBrains[I], FixedLines);
    12711271      FreeAndNil(AIBrains);
    12721272    end;
     
    12831283    repeat
    12841284      I := FormerGames.Count;
    1285       while (I > 0) and (F.Time < integer(FormerGames.Objects[I - 1])) do
     1285      while (I > 0) and (F.Time < Integer(FormerGames.Objects[I - 1])) do
    12861286        Dec(I);
    12871287      FormerGames.InsertObject(I, Copy(F.Name, 1, Length(F.Name) - 5),
     
    12971297procedure TStartDlg.UpdateMaps;
    12981298var
    1299   f: TSearchRec;
     1299  F: TSearchRec;
    13001300begin
    13011301  Maps.Clear;
    1302   if FindFirst(GetMapsDir + DirectorySeparator + '*' + CevoMapExt, $21, f) = 0 then
     1302  if FindFirst(GetMapsDir + DirectorySeparator + '*' + CevoMapExt, $21, F) = 0 then
    13031303    repeat
    1304       Maps.Add(Copy(f.Name, 1, Length(f.Name) - Length(CevoMapExt)));
    1305     until FindNext(f) <> 0;
     1304      Maps.Add(Copy(F.Name, 1, Length(F.Name) - Length(CevoMapExt)));
     1305    until FindNext(F) <> 0;
    13061306  FindClose(F);
    13071307  Maps.Sort;
     
    13141314procedure TStartDlg.ChangePage(NewPage: TStartPage);
    13151315var
    1316   i, j, p1: integer;
    1317   s: string;
     1316  I, J, p1: Integer;
     1317  S: string;
    13181318  Reg: TRegistry;
    1319   InvalidateTab0: boolean;
     1319  InvalidateTab0: Boolean;
    13201320begin
    13211321  InvalidateTab0 := (Page = pgMain) or (NewPage = pgMain);
     
    13261326        StartBtn.Caption := Phrases.Lookup('STARTCONTROLS', 1);
    13271327        if Page = pgStartRandom then
    1328           i := nPlOffered
     1328          I := nPlOffered
    13291329        else
    13301330        begin
    1331           i := nMapStartPositions;
    1332           if i = 0 then
     1331          I := nMapStartPositions;
     1332          if I = 0 then
    13331333          begin
    13341334            PlayersBrain[0] := BrainSuperVirtual;
     
    13361336          end;
    13371337          if PlayersBrain[0].Kind in [btNoTerm, btSuperVirtual] then
    1338             inc(i);
    1339           if i > nPl then
    1340             i := nPl;
    1341           if i <= nPlOffered then
     1338            Inc(I);
     1339          if I > nPl then
     1340            I := nPl;
     1341          if I <= nPlOffered then
    13421342            MultiControl := 0
    13431343          else
    1344             MultiControl := InitMulti[i];
     1344            MultiControl := InitMulti[I];
    13451345        end;
    1346         if InitAlive[i] <> SlotAvailable then
     1346        if InitAlive[I] <> SlotAvailable then
    13471347          if Page = pgStartRandom then
    13481348          begin // restore AI assignment of last start
     
    13531353              for p1 := 0 to nPlOffered - 1 do begin
    13541354                PlayersBrain[p1] := nil;
    1355                 s := ReadString('Control' + IntToStr(p1));
     1355                S := ReadString('Control' + IntToStr(p1));
    13561356                Difficulty[p1] := ReadInteger('Diff' + IntToStr(p1));
    1357                 if s <> '' then
    1358                   for j := 0 to Brains.Count - 1 do
    1359                     if AnsiCompareFileName(s, Brains[j].FileName) = 0 then
    1360                       PlayersBrain[p1] := Brains[j];
     1357                if S <> '' then
     1358                  for J := 0 to Brains.Count - 1 do
     1359                    if AnsiCompareFileName(S, Brains[J].FileName) = 0 then
     1360                      PlayersBrain[p1] := Brains[J];
    13611361              end;
    13621362            finally
     
    13661366          else
    13671367            for p1 := 1 to nPl - 1 do
    1368               if 1 shl p1 and InitAlive[i] <> 0 then
     1368              if 1 shl p1 and InitAlive[I] <> 0 then
    13691369              begin
    13701370                PlayersBrain[p1] := BrainDefault;
     
    13731373              else
    13741374                PlayersBrain[p1] := nil;
    1375         SlotAvailable := InitAlive[i];
    1376         for i := 0 to nPlOffered - 1 do
    1377           if (AutoDiff < 0) and Assigned(PlayersBrain[i]) and
    1378             (PlayersBrain[i].Kind in [btTerm, btRandom, btAI]) then
     1375        SlotAvailable := InitAlive[I];
     1376        for I := 0 to nPlOffered - 1 do
     1377          if (AutoDiff < 0) and Assigned(PlayersBrain[I]) and
     1378            (PlayersBrain[I].Kind in [btTerm, btRandom, btAI]) then
    13791379          begin
    1380             PlayerSlots[i].DiffUpBtn.Tag := 768;
    1381             PlayerSlots[i].DiffDownBtn.Tag := 768;
     1380            PlayerSlots[I].DiffUpBtn.Tag := 768;
     1381            PlayerSlots[I].DiffDownBtn.Tag := 768;
    13821382          end
    13831383          else
    13841384          begin
    1385             PlayerSlots[i].DiffUpBtn.Tag := 0;
    1386             PlayerSlots[i].DiffDownBtn.Tag := 0;
     1385            PlayerSlots[I].DiffUpBtn.Tag := 0;
     1386            PlayerSlots[I].DiffDownBtn.Tag := 0;
    13871387          end;
    1388         for i := 6 to 8 do
    1389           if (AutoDiff < 0) and Assigned(PlayersBrain[i]) and
    1390             (PlayersBrain[i].Kind in [btTerm, btRandom, btAI]) then
     1388        for I := 6 to 8 do
     1389          if (AutoDiff < 0) and Assigned(PlayersBrain[I]) and
     1390            (PlayersBrain[I].Kind in [btTerm, btRandom, btAI]) then
    13911391          begin
    1392             PlayerSlots[i].MultiBtn.Tag := 768;
    1393             PlayerSlots[i].MultiBtn.ButtonIndex := 2 + (MultiControl shr i) and 1;
    1394             PlayerSlots[i].MultiBtn.Enabled := Page = pgStartRandom
     1392            PlayerSlots[I].MultiBtn.Tag := 768;
     1393            PlayerSlots[I].MultiBtn.ButtonIndex := 2 + (MultiControl shr I) and 1;
     1394            PlayerSlots[I].MultiBtn.Enabled := Page = pgStartRandom
    13951395          end
    13961396          else
    1397             PlayerSlots[i].MultiBtn.Tag := 0;
     1397            PlayerSlots[I].MultiBtn.Tag := 0;
    13981398        if (AutoDiff > 0) and (Page <> pgStartMap) then
    13991399        begin
     
    14341434
    14351435  PaintInfo;
    1436   for i := 0 to ControlCount - 1 do
    1437     Controls[i].Visible := Controls[i].Tag and (256 shl Integer(Page)) <> 0;
     1436  for I := 0 to ControlCount - 1 do
     1437    Controls[I].Visible := Controls[I].Tag and (256 shl Integer(Page)) <> 0;
    14381438  if Page = pgLoad then
    14391439    ReplayBtn.Visible := MiniMap.Mode <> mmMultiPlayer;
     
    14791479
    14801480procedure TStartDlg.FormMouseDown(Sender: TObject; Button: TMouseButton;
    1481   Shift: TShiftState; x, y: integer);
     1481  Shift: TShiftState; X, Y: Integer);
    14821482var
    14831483  I: Integer;
    14841484begin
    1485   if (y < TabHeight + 1) and (x - TabOffset < TabSize * 4) and
    1486     ((x - TabOffset) div TabSize <> Integer(Tab)) then
     1485  if (Y < TabHeight + 1) and (X - TabOffset < TabSize * 4) and
     1486    ((X - TabOffset) div TabSize <> Integer(Tab)) then
    14871487  begin
    14881488    // Play('BUTTON_DOWN');
    14891489    ListIndex[Tab] := List.ItemIndex;
    1490     ChangeTab(TStartTab((x - TabOffset) div TabSize));
     1490    ChangeTab(TStartTab((X - TabOffset) div TabSize));
    14911491  end
    14921492  else if Page = pgMain then begin
     
    15031503  begin
    15041504    for I := 0 to nPlOffered - 1 do
    1505       if (1 shl I and SlotAvailable <> 0) and (x >= xBrain[I]) and
    1506         (y >= yBrain[I]) and (x < xBrain[I] + 64) and (y < yBrain[I] + 64) then
     1505      if (1 shl I and SlotAvailable <> 0) and (X >= xBrain[I]) and
     1506        (Y >= yBrain[I]) and (X < xBrain[I] + 64) and (Y < yBrain[I] + 64) then
    15071507      begin
    15081508        InitPopup(I);
     
    15141514  end
    15151515  else if (AutoDiff > 1) and ((Page = pgStartRandom) or (Page = pgStartMap)) and
    1516     (x >= xDefault) and (y >= yDefault) and (x < xDefault + 64) and
    1517     (y < yDefault + 64) then
     1516    (X >= xDefault) and (Y >= yDefault) and (X < xDefault + 64) and
     1517    (Y < yDefault + 64) then
    15181518    if Brains.GetKindCount(btAI) < 2 then
    15191519      SimpleMessage(Phrases.Lookup('NOALTAI'))
     
    15231523      PopupMenu1.Popup(left + xDefault + 4, top + yDefault + 4);
    15241524    end
    1525   else if (Page = pgLoad) and (LastTurn > 0) and (y >= yTurnSlider) and
    1526     (y < yTurnSlider + 7) and (x >= xTurnSlider) and
    1527     (x <= xTurnSlider + wTurnSlider) then
    1528   begin
    1529     LoadTurn := LastTurn * (x - xTurnSlider) div wTurnSlider;
     1525  else if (Page = pgLoad) and (LastTurn > 0) and (Y >= yTurnSlider) and
     1526    (Y < yTurnSlider + 7) and (X >= xTurnSlider) and
     1527    (X <= xTurnSlider + wTurnSlider) then
     1528  begin
     1529    LoadTurn := LastTurn * (X - xTurnSlider) div wTurnSlider;
    15301530    SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider + 2,
    15311531      yTurnSlider + 9);
     
    15401540      if MaxTurn < 1400 then
    15411541      begin
    1542         inc(MaxTurn, 200);
     1542        Inc(MaxTurn, 200);
    15431543        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 82);
    15441544      end;
     
    15461546      if LoadTurn < LastTurn then
    15471547      begin
    1548         inc(LoadTurn);
     1548        Inc(LoadTurn);
    15491549        SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider
    15501550          + 2, yTurnSlider + 9);
     
    15531553      if StartLandMass < 96 then
    15541554      begin
    1555         inc(StartLandMass, 5);
     1555        Inc(StartLandMass, 5);
    15561556        PaintInfo;
    15571557        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 61 + 21);
     
    15661566      if MaxTurn > 400 then
    15671567      begin
    1568         dec(MaxTurn, 200);
     1568        Dec(MaxTurn, 200);
    15691569        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 82);
    15701570      end;
     
    15721572      if LoadTurn > 0 then
    15731573      begin
    1574         dec(LoadTurn);
     1574        Dec(LoadTurn);
    15751575        SmartInvalidate(xTurnSlider - 2, y0Mini + 61, xTurnSlider + wTurnSlider
    15761576          + 2, yTurnSlider + 9);
     
    15791579      if StartLandMass > 10 then
    15801580      begin
    1581         dec(StartLandMass, 5);
     1581        Dec(StartLandMass, 5);
    15821582        PaintInfo;
    15831583        SmartInvalidate(344, y0Mini + 61, 514, y0Mini + 61 + 21);
     
    16341634procedure TStartDlg.RenameBtnClick(Sender: TObject);
    16351635var
    1636   i: integer;
     1636  I: Integer;
    16371637  NewName: string;
    1638   f: file;
    1639   ok: boolean;
     1638  F: file;
     1639  ok: Boolean;
    16401640  MapPictureFileName: string;
    16411641begin
     
    16551655      (NewName <> List.Items[List.ItemIndex]) then
    16561656    begin
    1657       for i := 1 to Length(NewName) do
    1658         if NewName[i] in ['\', '/', ':', '*', '?', '"', '<', '>', '|'] then
     1657      for I := 1 to Length(NewName) do
     1658        if NewName[I] in ['\', '/', ':', '*', '?', '"', '<', '>', '|'] then
    16591659        begin
    1660           SimpleMessage(Format(Phrases.Lookup('NOFILENAME'), [NewName[i]]));
     1660          SimpleMessage(Format(Phrases.Lookup('NOFILENAME'), [NewName[I]]));
    16611661          Exit;
    16621662        end;
    16631663      if Page = pgLoad then
    1664         AssignFile(f, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
     1664        AssignFile(F, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
    16651665      else
    1666         AssignFile(f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] +
     1666        AssignFile(F, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] +
    16671667          CevoMapExt);
    1668       ok := true;
     1668      ok := True;
    16691669      try
    16701670        if Page = pgLoad then
    1671           Rename(f, GetSavedDir + DirectorySeparator + NewName + CevoExt)
     1671          Rename(F, GetSavedDir + DirectorySeparator + NewName + CevoExt)
    16721672        else
    1673           Rename(f, GetMapsDir + DirectorySeparator + NewName + CevoMapExt);
     1673          Rename(F, GetMapsDir + DirectorySeparator + NewName + CevoMapExt);
    16741674      except
    16751675        // Play('INVALID');
     
    16821682        if FileExists(MapPictureFileName) then
    16831683        try
    1684           AssignFile(f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex]
     1684          AssignFile(F, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex]
    16851685            + CevoMapPictureExt);
    1686           Rename(f, GetMapsDir + DirectorySeparator + NewName + CevoMapPictureExt);
     1686          Rename(F, GetMapsDir + DirectorySeparator + NewName + CevoMapPictureExt);
    16871687        except
    16881688        end;
     
    17041704procedure TStartDlg.DeleteBtnClick(Sender: TObject);
    17051705var
    1706   iDel: integer;
    1707   f: file;
     1706  iDel: Integer;
     1707  F: file;
    17081708begin
    17091709  if List.ItemIndex >= 0 then
     
    17181718    begin
    17191719      if Page = pgLoad then
    1720         AssignFile(f, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
     1720        AssignFile(F, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
    17211721      else
    1722         AssignFile(f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] +
     1722        AssignFile(F, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] +
    17231723          CevoMapExt);
    1724       Erase(f);
     1724      Erase(F);
    17251725      iDel := List.ItemIndex;
    17261726      if Page = pgLoad then
     
    17431743          List.Invalidate;
    17441744          if Page = pgLoad then
    1745             TurnValid := false;
     1745            TurnValid := False;
    17461746          PaintInfo;
    17471747          if Page = pgLoad then
     
    18421842
    18431843procedure TStartDlg.FormMouseUp(Sender: TObject; Button: TMouseButton;
    1844   Shift: TShiftState; x, y: integer);
     1844  Shift: TShiftState; X, Y: Integer);
    18451845begin
    18461846  Tracking := False;
     
    18481848
    18491849procedure TStartDlg.FormMouseMove(Sender: TObject; Shift: TShiftState;
    1850   x, y: integer);
     1850  X, Y: Integer);
    18511851var
    18521852  OldLoadTurn: Integer;
     
    18551855  if Tracking then
    18561856  begin
    1857     x := x - xTurnSlider;
    1858     if x < 0 then
    1859       x := 0
    1860     else if x > wTurnSlider then
    1861       x := wTurnSlider;
     1857    X := X - xTurnSlider;
     1858    if X < 0 then
     1859      X := 0
     1860    else if X > wTurnSlider then
     1861      X := wTurnSlider;
    18621862    OldLoadTurn := LoadTurn;
    1863     LoadTurn := LastTurn * x div wTurnSlider;
     1863    LoadTurn := LastTurn * X div wTurnSlider;
    18641864    if LoadTurn < OldLoadTurn then
    18651865    begin
     
    18791879  else if Page = pgMain then
    18801880  begin
    1881     if (x >= ActionSideBorder) and (x < ClientWidth - ActionSideBorder) and
    1882       (y >= yAction - 8) and (y < ClientHeight - ActionBottomBorder) then
     1881    if (X >= ActionSideBorder) and (X < ClientWidth - ActionSideBorder) and
     1882      (Y >= yAction - 8) and (Y < ClientHeight - ActionBottomBorder) then
    18831883    begin
    1884       NewSelectedAction := TMainAction((y - (yAction - 8)) div ActionPitch);
     1884      NewSelectedAction := TMainAction((Y - (yAction - 8)) div ActionPitch);
    18851885      if not (NewSelectedAction in ActionsOffered) then
    18861886        NewSelectedAction := maNone;
  • trunk/UBrain.pas

    r442 r447  
    206206end.
    207207
     208
  • trunk/UMiniMap.pas

    r442 r447  
    330330end.
    331331
     332
  • trunk/UnitProcessing.pas

    r442 r447  
    1313  TMoveInfo = record
    1414    MoveType: TMoveType;
    15     Cost, ToMaster, EndHealth, Defender, Dcix, Duix, EndHealthDef: integer;
    16     MountainDelay: boolean;
     15    Cost, ToMaster, EndHealth, Defender, Dcix, Duix, EndHealthDef: Integer;
     16    MountainDelay: Boolean;
    1717  end;
    1818
    1919var
    20   uixSelectedTransport: integer;
    21   Worked: array [0 .. nPl - 1] of integer; { settler work statistics }
     20  uixSelectedTransport: Integer;
     21  Worked: array [0 .. nPl - 1] of Integer; { settler work statistics }
    2222
    2323  // Moving/Combat
    24 function HostileDamage(p, mix, Loc, MP: integer): integer;
    25 function CalculateMove(p, uix, ToLoc, MoveLength: integer; TestOnly: boolean;
    26   var MoveInfo: TMoveInfo): integer;
    27 function GetBattleForecast(Loc: integer; var BattleForecast: TBattleForecast;
    28   var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: integer): integer;
    29 function LoadUnit(p, uix: integer; TestOnly: boolean): integer;
    30 function UnloadUnit(p, uix: integer; TestOnly: boolean): integer;
    31 procedure Recover(p, uix: integer);
    32 function GetMoveAdvice(p, uix: integer; var a: TMoveAdviceData): integer;
    33 function CanPlaneReturn(p, uix: integer;
    34   PlaneReturnData: TPlaneReturnData): boolean;
     24function HostileDamage(P, mix, Loc, MP: Integer): Integer;
     25function CalculateMove(P, uix, ToLoc, MoveLength: Integer; TestOnly: Boolean;
     26  var MoveInfo: TMoveInfo): Integer;
     27function GetBattleForecast(Loc: Integer; var BattleForecast: TBattleForecast;
     28  var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: Integer): Integer;
     29function LoadUnit(P, uix: Integer; TestOnly: Boolean): Integer;
     30function UnloadUnit(P, uix: Integer; TestOnly: Boolean): Integer;
     31procedure Recover(P, uix: Integer);
     32function GetMoveAdvice(P, uix: Integer; var A: TMoveAdviceData): Integer;
     33function CanPlaneReturn(P, uix: Integer;
     34  PlaneReturnData: TPlaneReturnData): Boolean;
    3535
    3636// Terrain Improvement
    37 function StartJob(p, uix, NewJob: integer; TestOnly: boolean): integer;
    38 function Work(p, uix: integer): boolean;
    39 function GetJobProgress(p, Loc: integer;
    40   var JobProgressData: TJobProgressData): integer;
     37function StartJob(P, uix, NewJob: Integer; TestOnly: Boolean): Integer;
     38function Work(P, uix: Integer): Boolean;
     39function GetJobProgress(P, Loc: Integer;
     40  var JobProgressData: TJobProgressData): Integer;
    4141
    4242// Start/End Game
     
    7474
    7575type
    76   TToWorkList = array [0 .. INFIN, 0 .. nJob - 1] of word;
     76  TToWorkList = array [0 .. INFIN, 0 .. nJob - 1] of Word;
    7777
    7878var
     
    8383    ____________________________________________________________________
    8484  }
    85 function HostileDamage(p, mix, Loc, MP: integer): integer;
    86 var
    87   Tile: integer;
     85function HostileDamage(P, mix, Loc, MP: Integer): Integer;
     86var
     87  Tile: Integer;
    8888begin
    8989  Tile := RealMap[Loc];
    90   if (RW[p].Model[mix].Domain >= dSea) or (RW[p].Model[mix].Kind = mkSettler)
    91     and (RW[p].Model[mix].Speed >= 200) or
     90  if (RW[P].Model[mix].Domain >= dSea) or (RW[P].Model[mix].Kind = mkSettler)
     91    and (RW[P].Model[mix].Speed >= 200) or
    9292    (Tile and (fCity or fRiver or fCanal) <> 0) or (Tile and fTerImp = tiBase)
    93     or (GWonder[woGardens].EffectiveOwner = p) then
    94     result := 0
     93    or (GWonder[woGardens].EffectiveOwner = P) then
     94    Result := 0
    9595  else if (Tile and fTerrain = fDesert) and
    9696    (Tile and fSpecial <> fSpecial1 { Oasis } ) then
    9797  begin
    98     assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
    99     result := (DesertThurst * MP - 1) div RW[p].Model[mix].Speed + 1
     98    Assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
     99    Result := (DesertThurst * MP - 1) div RW[P].Model[mix].Speed + 1
    100100  end
    101101  else if Tile and fTerrain = fArctic then
    102102  begin
    103     assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
    104     result := (ArcticThurst * MP - 1) div RW[p].Model[mix].Speed + 1
     103    Assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
     104    Result := (ArcticThurst * MP - 1) div RW[P].Model[mix].Speed + 1
    105105  end
    106106  else
    107     result := 0
    108 end;
    109 
    110 function Controlled(p, Loc: integer; IsDest: boolean): integer;
     107    Result := 0;
     108end;
     109
     110function Controlled(P, Loc: Integer; IsDest: Boolean): Integer;
    111111{ whether tile at Loc is in control zone of enemy unit
    112112  returns combination of tile control flags }
    113113var
    114   Loc1, V8: integer;
     114  Loc1, V8: Integer;
    115115  Adjacent: TVicinity8Loc;
    116116begin
    117   result := 0;
    118   if IsDest and (Occupant[Loc] = p) and (ZoCMap[Loc] > 0) then
    119     exit;
     117  Result := 0;
     118  if IsDest and (Occupant[Loc] = P) and (ZoCMap[Loc] > 0) then
     119    Exit;
    120120  // destination tile, not controlled if already occupied
    121121
    122   if (RealMap[Loc] and fCity = 0) or (integer(RealMap[Loc] shr 27) <> p) and
    123     (ServerVersion[p] >= $000EF0) then
     122  if (RealMap[Loc] and fCity = 0) or (Integer(RealMap[Loc] shr 27) <> P) and
     123    (ServerVersion[P] >= $000EF0) then
    124124  begin // not own city
    125125    V8_to_Loc(Loc, Adjacent);
     
    128128      Loc1 := Adjacent[V8];
    129129      if (Loc1 >= 0) and (Loc1 < MapSize) and (ZoCMap[Loc1] > 0) and
    130         (Occupant[Loc1] >= 0) and (Occupant[Loc1] <> p) and
    131         (RW[p].Treaty[Occupant[Loc1]] < trAlliance) then
    132         if ObserveLevel[Loc1] and (3 shl (p * 2)) > 0 then
     130        (Occupant[Loc1] >= 0) and (Occupant[Loc1] <> P) and
     131        (RW[P].Treaty[Occupant[Loc1]] < trAlliance) then
     132        if ObserveLevel[Loc1] and (3 shl (P * 2)) > 0 then
    133133        begin // p observes tile
    134           result := coKnown or coTrue;
    135           exit;
     134          Result := coKnown or coTrue;
     135          Exit;
    136136        end
    137137        else
    138           result := coTrue; // p does not observe tile
     138          Result := coTrue; // p does not observe tile
    139139    end;
    140140  end;
    141141end;
    142142
    143 function GetMoveCost(p, mix, FromLoc, ToLoc, MoveLength: integer;
    144   var MoveCost: integer): integer;
     143function GetMoveCost(P, mix, FromLoc, ToLoc, MoveLength: Integer;
     144  var MoveCost: Integer): Integer;
    145145// MoveLength - 2 for short move, 3 for long move
    146146var
    147   FromTile, ToTile: integer;
    148 begin
    149   result := eOK;
     147  FromTile, ToTile: Integer;
     148begin
     149  Result := eOK;
    150150  FromTile := RealMap[FromLoc];
    151151  ToTile := RealMap[ToLoc];
    152   with RW[p].Model[mix] do
     152  with RW[P].Model[mix] do
    153153  begin
    154154    case Domain of
     
    160160          if (FromTile and (fRR or fCity) <> 0) and
    161161            (ToTile and (fRR or fCity) <> 0) then
    162             if GWonder[woShinkansen].EffectiveOwner = p then
     162            if GWonder[woShinkansen].EffectiveOwner = P then
    163163              MoveCost := 0
    164164            else
     
    174174              MoveCost := 20
    175175          else if Cap[mcOver] > 0 then
    176             result := eNoRoad
     176            Result := eNoRoad
    177177          else
    178178            case Terrain[ToTile and fTerrain].MoveCost of
     
    181181              2:
    182182                begin
    183                   assert(Speed - 150 <= 600);
     183                  Assert(Speed - 150 <= 600);
    184184                  MoveCost := 50 + (Speed - 150) * 13 shr 7; // heavy terrain
    185185                end;
     
    187187                begin
    188188                  MoveCost := Speed;
    189                   result := eMountains;
    190                   exit;
     189                  Result := eMountains;
     190                  Exit;
    191191                end;
    192192            end;
     
    194194        end
    195195        else
    196           result := eDomainMismatch;
     196          Result := eDomainMismatch;
    197197
    198198      dSea:
     
    202202            MoveCost := 50 * MoveLength { valid move }
    203203          else
    204             result := eNoNav { navigation required for open sea }
    205         else
    206           result := eDomainMismatch;
     204            Result := eNoNav { navigation required for open sea }
     205        else
     206          Result := eDomainMismatch;
    207207
    208208      dAir:
     
    212212end;
    213213
    214 function CalculateMove(p, uix, ToLoc, MoveLength: integer; TestOnly: boolean;
    215   var MoveInfo: TMoveInfo): integer;
     214function CalculateMove(P, uix, ToLoc, MoveLength: Integer; TestOnly: Boolean;
     215  var MoveInfo: TMoveInfo): Integer;
    216216var
    217217  uix1, p1, FromLoc, DestControlled, AStr, DStr, ABaseDamage,
    218     DBaseDamage: integer;
     218    DBaseDamage: Integer;
    219219  PModel: ^TModel;
    220220  BattleForecast: TBattleForecast;
    221221begin
    222   with RW[p], Un[uix] do
     222  with RW[P], Un[uix] do
    223223  begin
    224224    PModel := @Model[mix];
    225225    FromLoc := Loc;
    226226
    227     BattleForecast.pAtt := p;
     227    BattleForecast.pAtt := P;
    228228    BattleForecast.mixAtt := mix;
    229229    BattleForecast.HealthAtt := Health;
     
    231231    BattleForecast.FlagsAtt := Flags;
    232232    BattleForecast.Movement := Movement;
    233     result := GetBattleForecast(ToLoc, BattleForecast, MoveInfo.Duix,
     233    Result := GetBattleForecast(ToLoc, BattleForecast, MoveInfo.Duix,
    234234      MoveInfo.Dcix, AStr, DStr, ABaseDamage, DBaseDamage);
    235235
    236     if result = eHiddenUnit then
     236    if Result = eHiddenUnit then
    237237      if TestOnly then
    238         result := eOK // behave just like unit was moving
     238        Result := eOK // behave just like unit was moving
    239239      else if Mode > moLoading_Fast then
    240240        Map[ToLoc] := Map[ToLoc] or fHiddenUnit;
    241     if result = eStealthUnit then
     241    if Result = eStealthUnit then
    242242      if TestOnly then
    243         result := eOK // behave just like unit was moving
     243        Result := eOK // behave just like unit was moving
    244244      else if Mode > moLoading_Fast then
    245245        Map[ToLoc] := Map[ToLoc] or fStealthUnit;
    246     if result < rExecuted then
    247       exit;
    248 
    249     case result of
     246    if Result < rExecuted then
     247      Exit;
     248
     249    case Result of
    250250      eOK:
    251251        MoveInfo.MoveType := mtMove;
     
    261261      begin
    262262        p1 := RealMap[ToLoc] shr 27;
    263         if (p1 < nPl) and (p1 <> p) and
     263        if (p1 < nPl) and (p1 <> P) and
    264264          ((RealMap[Loc] shr 27 <> Cardinal(p1)) and (PModel.Kind <> mkDiplomat)
    265265          and (Treaty[p1] >= trPeace) and (Treaty[p1] < trAlliance) or
    266266          (RealMap[ToLoc] and fCity <> 0) and (Treaty[p1] >= trPeace)) then
    267267        begin
    268           result := eTreaty;
    269           exit;
     268          Result := eTreaty;
     269          Exit;
    270270        end; // keep peace treaty!
    271271      end;
    272272      if (RealMap[ToLoc] and fCity <> 0) and
    273         (RealMap[ToLoc] shr 27 <> Cardinal(p)) then // empty enemy city
     273        (RealMap[ToLoc] shr 27 <> Cardinal(P)) then // empty enemy city
    274274        if PModel.Kind = mkDiplomat then
    275275        begin
     
    280280          if PModel.Flags and mdCivil <> 0 then
    281281          begin
    282             result := eNoCapturer;
    283             exit;
     282            Result := eNoCapturer;
     283            Exit;
    284284          end;
    285285          MoveInfo.MoveType := mtCapture;
     
    289289          if (PModel.Domain = dSea) and (PModel.Cap[mcArtillery] = 0) then
    290290          begin
    291             result := eDomainMismatch;
    292             exit;
     291            Result := eDomainMismatch;
     292            Exit;
    293293          end
    294294          else if (PModel.Attack = 0) and
     
    296296          then
    297297          begin
    298             result := eNoBombarder;
    299             exit;
     298            Result := eNoBombarder;
     299            Exit;
    300300          end
    301301          else if Movement < 100 then
    302302          begin
    303             result := eNoTime_Bombard;
    304             exit;
     303            Result := eNoTime_Bombard;
     304            Exit;
    305305          end;
    306306          MoveInfo.MoveType := mtBombard;
    307           result := eBombarded;
    308         end;
    309     end;
    310 
    311     MoveInfo.MountainDelay := false;
     307          Result := eBombarded;
     308        end;
     309    end;
     310
     311    MoveInfo.MountainDelay := False;
    312312    if MoveInfo.MoveType in [mtAttack, mtBombard, mtExpel] then
    313313    begin
     
    317317      then
    318318      begin
    319         result := eViolation;
    320         exit
     319        Result := eViolation;
     320        Exit;
    321321      end;
    322322      if MoveInfo.MoveType = mtBombard then
     
    337337        MoveInfo.Cost := PModel.Speed;
    338338        if RealMap[ToLoc] and fTerrain < fGrass then
    339           result := eDomainMismatch;
     339          Result := eDomainMismatch;
    340340      end
    341341      else
    342342      begin
    343         result := GetMoveCost(p, mix, FromLoc, ToLoc, MoveLength,
     343        Result := GetMoveCost(P, mix, FromLoc, ToLoc, MoveLength,
    344344          MoveInfo.Cost);
    345         if result = eMountains then
    346         begin
    347           result := eOK;
    348           MoveInfo.MountainDelay := true
     345        if Result = eMountains then
     346        begin
     347          Result := eOK;
     348          MoveInfo.MountainDelay := True
    349349        end;
    350350      end;
    351       if (result >= rExecuted) and (MoveInfo.MoveType = mtSpyMission) then
    352         result := eMissionDone;
     351      if (Result >= rExecuted) and (MoveInfo.MoveType = mtSpyMission) then
     352        Result := eMissionDone;
    353353
    354354      MoveInfo.ToMaster := -1;
    355       if (result = eDomainMismatch) and (PModel.Domain < dSea) and
     355      if (Result = eDomainMismatch) and (PModel.Domain < dSea) and
    356356        (PModel.Cap[mcOver] = 0) then
    357357      begin
     
    361361              (TroopLoad < Model[mix].MTrans * Model[mix].Cap[mcSeaTrans]) then
    362362            begin
    363               result := eLoaded;
     363              Result := eLoaded;
    364364              MoveInfo.Cost := PModel.Speed;
    365365              MoveInfo.ToMaster := uix1;
     
    378378              (AirLoad < Model[mix].MTrans * Model[mix].Cap[mcCarrier]) then
    379379            begin // load plane to ship
    380               result := eLoaded;
     380              Result := eLoaded;
    381381              MoveInfo.ToMaster := uix1;
    382382              if (uixSelectedTransport >= 0) and (uix1 = uixSelectedTransport)
     
    385385            end;
    386386      end;
    387       if result < rExecuted then
    388         exit;
     387      if Result < rExecuted then
     388        Exit;
    389389
    390390      if (Master < 0) and (MoveInfo.ToMaster < 0) then
    391         MoveInfo.EndHealth := Health - HostileDamage(p, mix, ToLoc,
     391        MoveInfo.EndHealth := Health - HostileDamage(P, mix, ToLoc,
    392392          MoveInfo.Cost)
    393393      else
     
    395395
    396396      if (Mode = moPlaying) and (PModel.Flags and mdZOC <> 0) and (Master < 0)
    397         and (MoveInfo.ToMaster < 0) and (Controlled(p, FromLoc, false) >= coTrue)
     397        and (MoveInfo.ToMaster < 0) and (Controlled(P, FromLoc, False) >= coTrue)
    398398      then
    399399      begin
    400         DestControlled := Controlled(p, ToLoc, true);
     400        DestControlled := Controlled(P, ToLoc, True);
    401401        if DestControlled >= coTrue + coKnown then
    402402        begin
    403           result := eZOC;
    404           exit;
     403          Result := eZOC;
     404          Exit;
    405405        end
    406406        else if not TestOnly and (DestControlled >= coTrue) then
    407407        begin
    408           result := eZOC_EnemySpotted;
    409           exit;
     408          Result := eZOC_EnemySpotted;
     409          Exit;
    410410        end;
    411411      end;
    412       if (Movement = 0) and (ServerVersion[p] >= $0100F1) or
     412      if (Movement = 0) and (ServerVersion[P] >= $0100F1) or
    413413        (MoveInfo.Cost > Movement) then
    414414        if (Master >= 0) or (MoveInfo.ToMaster >= 0) then
    415415        begin
    416           result := eNoTime_Load;
    417           exit;
     416          Result := eNoTime_Load;
     417          Exit;
    418418        end
    419419        else
    420420        begin
    421           result := eNoTime_Move;
    422           exit;
     421          Result := eNoTime_Move;
     422          Exit;
    423423        end;
    424424      if (MoveInfo.EndHealth <= 0) or (MoveInfo.MoveType = mtSpyMission) then
    425         result := result or rUnitRemoved;
     425        Result := Result or rUnitRemoved;
    426426      // spy mission or victim of HostileDamage
    427427
     
    438438end;
    439439
    440 function GetBattleForecast(Loc: integer; var BattleForecast: TBattleForecast;
    441   var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: integer): integer;
    442 var
    443   Time, Defender, ABon, DBon, DCnt, MultiDamage: integer;
     440function GetBattleForecast(Loc: Integer; var BattleForecast: TBattleForecast;
     441  var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: Integer): Integer;
     442var
     443  Time, Defender, ABon, DBon, DCnt, MultiDamage: Integer;
    444444  PModel, DModel: ^TModel;
    445445begin
     
    449449    if (Defender < 0) or (Defender = pAtt) then
    450450    begin
    451       result := eOK;
    452       exit;
     451      Result := eOK;
     452      Exit;
    453453    end; // no attack, simple move
    454454
     
    459459      EndHealthAtt := HealthAtt;
    460460      EndHealthDef := RW[Defender].Un[Duix].Health;
    461       result := eOK;
    462       exit;
     461      Result := eOK;
     462      Exit;
    463463    end;
    464464
     
    470470        (ObserveLevel[Loc] shr (2 * pAtt) and 3 < lObserveAll) then
    471471      begin
    472         result := eHiddenUnit;
    473         exit;
     472        Result := eHiddenUnit;
     473        Exit;
    474474      end; // attacking submarine not allowed
    475475      if (DModel.Cap[mcStealth] > 0) and
    476476        (ObserveLevel[Loc] shr (2 * pAtt) and 3 <> lObserveSuper) then
    477477      begin
    478         result := eStealthUnit;
    479         exit;
     478        Result := eStealthUnit;
     479        Exit;
    480480      end; // attacking stealth aircraft not allowed
    481481      if (DModel.Domain = dAir) and (DModel.Kind <> mkSpecial_Glider) and
    482482        (PModel.Domain <> dAir) then
    483483      begin
    484         result := eDomainMismatch;
    485         exit;
     484        Result := eDomainMismatch;
     485        Exit;
    486486      end; // can't attack plane
    487487    end;
     
    492492      (PModel.Domain = dSea) and (RealMap[Loc] and fTerrain >= fGrass)) then
    493493    begin
    494       result := eDomainMismatch;
    495       exit;
     494      Result := eDomainMismatch;
     495      Exit;
    496496    end;
    497497    if (PModel.Attack = 0) and not((PModel.Cap[mcBombs] > 0) and
    498498      (FlagsAtt and unBombsLoaded <> 0) and (DModel.Domain < dAir)) then
    499499    begin
    500       result := eInvalid;
    501       exit;
     500      Result := eInvalid;
     501      Exit;
    502502    end;
    503503
    504504    if Movement = 0 then
    505505    begin
    506       result := eNoTime_Attack;
    507       exit;
    508     end;
    509 
    510 {$IFOPT O-}assert(InvalidTreatyMap = 0); {$ENDIF}
     506      Result := eNoTime_Attack;
     507      Exit;
     508    end;
     509
     510{$IFOPT O-}Assert(InvalidTreatyMap = 0); {$ENDIF}
    511511    if RW[pAtt].Treaty[Defender] >= trPeace then
    512512    begin
    513513      if (PModel.Domain <> dAir) and (PModel.Attack > 0) and
    514         (integer(RealMap[Loc] shr 27) = pAtt) then
     514        (Integer(RealMap[Loc] shr 27) = pAtt) then
    515515        if Movement >= 100 then
    516516        begin // expel friendly unit
    517517          EndHealthDef := RW[Defender].Un[Duix].Health;
    518518          EndHealthAtt := HealthAtt;
    519           result := eExpelled
     519          Result := eExpelled
    520520        end
    521521        else
    522           result := eNoTime_Expel
     522          Result := eNoTime_Expel
    523523      else
    524         result := eTreaty;
    525       exit;
     524        Result := eTreaty;
     525      Exit;
    526526    end;
    527527
     
    534534        (Continent[RW[Defender].City[Dcix].Loc] = GrWallContinent[Defender]))
    535535      then
    536         inc(DBon, 8)
     536        Inc(DBon, 8)
    537537      else if (PModel.Domain = dSea) and
    538538        (RW[Defender].City[Dcix].Built[imCoastalFort] = 1) then
    539         inc(DBon, 4)
     539        Inc(DBon, 4)
    540540      else if (PModel.Domain = dAir) and
    541541        (RW[Defender].City[Dcix].Built[imMissileBat] = 1) then
    542         inc(DBon, 4);
     542        Inc(DBon, 4);
    543543      if RW[Defender].City[Dcix].Built[imBunker] = 1 then
    544         inc(DBon, 4)
     544        Inc(DBon, 4)
    545545    end;
    546546    if (PModel.Domain = dAir) and (DModel.Cap[mcAirDef] > 0) then
    547       inc(DBon, 4);
     547      Inc(DBon, 4);
    548548    DStr := DModel.Defense * DBon * 100;
    549549    if (DModel.Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or
     
    622622
    623623    if EndHealthDef > 0 then
    624       result := eLost
     624      Result := eLost
    625625    else if EndHealthAtt > 0 then
    626       result := eWon
     626      Result := eWon
    627627    else
    628       result := eBloody;
     628      Result := eBloody;
    629629  end;
    630630end;
    631631
    632 function LoadUnit(p, uix: integer; TestOnly: boolean): integer;
    633 var
    634   uix1, d, Cost, ToMaster: integer;
    635 begin
    636   result := eOK;
    637   with RW[p].Un[uix] do
    638   begin
    639     d := RW[p].Model[mix].Domain;
    640     if (Master >= 0) or (d = dSea) or
    641       (RW[p].Model[mix].Cap[mcAirTrans] + RW[p].Model[mix].Cap[mcOver] > 0) then
    642       result := eViolation
     632function LoadUnit(P, uix: Integer; TestOnly: Boolean): Integer;
     633var
     634  uix1, D, Cost, ToMaster: Integer;
     635begin
     636  Result := eOK;
     637  with RW[P].Un[uix] do
     638  begin
     639    D := RW[P].Model[mix].Domain;
     640    if (Master >= 0) or (D = dSea) or
     641      (RW[P].Model[mix].Cap[mcAirTrans] + RW[P].Model[mix].Cap[mcOver] > 0) then
     642      Result := eViolation
    643643    else
    644644    begin
    645645      ToMaster := -1;
    646       for uix1 := 0 to RW[p].nUn - 1 do
    647         if RW[p].Un[uix1].Loc = Loc then
    648           with RW[p].Un[uix1], RW[p].Model[mix] do
    649             if (d < dSea) and
     646      for uix1 := 0 to RW[P].nUn - 1 do
     647        if RW[P].Un[uix1].Loc = Loc then
     648          with RW[P].Un[uix1], RW[P].Model[mix] do
     649            if (D < dSea) and
    650650              (TroopLoad < MTrans * (Cap[mcSeaTrans] + Cap[mcAirTrans])) or
    651               (d = dAir) and (AirLoad < MTrans * Cap[mcCarrier]) then
     651              (D = dAir) and (AirLoad < MTrans * Cap[mcCarrier]) then
    652652            begin { load onto unit uix1 }
    653653              if (uixSelectedTransport < 0) or (uix1 = uixSelectedTransport)
     
    661661            end;
    662662      if ToMaster < 0 then
    663         result := eNoLoadCapacity
     663        Result := eNoLoadCapacity
    664664      else
    665665      begin
    666         if d = dAir then
     666        if D = dAir then
    667667          Cost := 100
    668668        else
    669           Cost := RW[p].Model[mix].Speed;
     669          Cost := RW[P].Model[mix].Speed;
    670670        if Movement < Cost then
    671           result := eNoTime_Load
     671          Result := eNoTime_Load
    672672        else if not TestOnly then
    673673        begin
    674           FreeUnit(p, uix);
    675           dec(Movement, Cost);
    676           if d = dAir then
    677             inc(RW[p].Un[ToMaster].AirLoad)
     674          FreeUnit(P, uix);
     675          Dec(Movement, Cost);
     676          if D = dAir then
     677            Inc(RW[P].Un[ToMaster].AirLoad)
    678678          else
    679             inc(RW[p].Un[ToMaster].TroopLoad);
     679            Inc(RW[P].Un[ToMaster].TroopLoad);
    680680          Master := ToMaster;
    681681          UpdateUnitMap(Loc);
     
    686686end;
    687687
    688 function UnloadUnit(p, uix: integer; TestOnly: boolean): integer;
    689 var
    690   Cost: integer;
    691 begin
    692   result := eOK;
    693   with RW[p].Un[uix] do
     688function UnloadUnit(P, uix: Integer; TestOnly: Boolean): Integer;
     689var
     690  Cost: Integer;
     691begin
     692  Result := eOK;
     693  with RW[P].Un[uix] do
    694694    if Master < 0 then
    695       result := eNotChanged
    696     else if (RW[p].Model[mix].Domain < dSea) and
     695      Result := eNotChanged
     696    else if (RW[P].Model[mix].Domain < dSea) and
    697697      (RealMap[Loc] and fTerrain < fGrass) then
    698       result := eDomainMismatch
     698      Result := eDomainMismatch
    699699      // else if (RW[p].Model[mix].Domain<dSea)
    700700      // and (RW[p].Model[mix].Flags and mdCivil<>0)
     
    702702    else
    703703    begin
    704       if RW[p].Model[mix].Domain = dAir then
     704      if RW[P].Model[mix].Domain = dAir then
    705705        Cost := 100
    706706      else
    707         Cost := RW[p].Model[mix].Speed;
     707        Cost := RW[P].Model[mix].Speed;
    708708      if Movement < Cost then
    709         result := eNoTime_Load
     709        Result := eNoTime_Load
    710710      else if not TestOnly then
    711711      begin
    712         dec(Movement, Cost);
    713         if RW[p].Model[mix].Domain = dAir then
    714           dec(RW[p].Un[Master].AirLoad)
    715         else
    716         begin
    717           dec(RW[p].Un[Master].TroopLoad);
     712        Dec(Movement, Cost);
     713        if RW[P].Model[mix].Domain = dAir then
     714          Dec(RW[P].Un[Master].AirLoad)
     715        else
     716        begin
     717          Dec(RW[P].Un[Master].TroopLoad);
    718718          // Movement:=0 // no more movement after unload
    719719        end;
    720720        Master := -1;
    721         PlaceUnit(p, uix);
     721        PlaceUnit(P, uix);
    722722        UpdateUnitMap(Loc);
    723723      end;
     
    725725end;
    726726
    727 procedure Recover(p, uix: integer);
    728 var
    729   cix, Recovery: integer;
    730 begin
    731   with RW[p], Un[uix] do
     727procedure Recover(P, uix: Integer);
     728var
     729  cix, Recovery: Integer;
     730begin
     731  with RW[P], Un[uix] do
    732732  begin
    733733    if (Master >= 0) and (Model[Un[Master].mix].Cap[mcSupplyShip] > 0) then
     
    739739      cix := nCity - 1;
    740740      while (cix >= 0) and (City[cix].Loc <> Loc) do
    741         dec(cix);
     741        Dec(cix);
    742742      if City[cix].Flags and chDisorder <> 0 then
    743743        Recovery := NoCityRecovery
     
    762762    if Recovery > 100 - Health then
    763763      Recovery := 100 - Health;
    764     inc(Health, Recovery);
     764    Inc(Health, Recovery);
    765765  end;
    766766end;
    767767
    768 function GetMoveAdvice(p, uix: integer; var a: TMoveAdviceData): integer;
     768function GetMoveAdvice(P, uix: Integer; var A: TMoveAdviceData): Integer;
    769769const
    770770  // domains
     
    778778  gmaAlpine = 8;
    779779var
    780   i, FromLoc, EndLoc, T, T1, maxmov, initmov, Loc, Loc1, FromTile, ToTile, V8,
     780  I, FromLoc, EndLoc, T, T1, maxmov, initmov, Loc, Loc1, FromTile, ToTile, V8,
    781781    MoveInfo, HeavyCost, RailCost, MoveCost, AddDamage, MaxDamage,
    782     MovementLeft: integer;
     782    MovementLeft: Integer;
    783783  Map: ^TTileList;
    784784  Q: TIPQ;
    785785  Adjacent: TVicinity8Loc;
    786   From: array [0 .. lxmax * lymax - 1] of integer;
    787   Time: array [0 .. lxmax * lymax - 1] of integer;
    788   Damage: array [0 .. lxmax * lymax - 1] of integer;
    789   MountainDelay, Resistant: boolean;
     786  From: array [0 .. lxmax * lymax - 1] of Integer;
     787  Time: array [0 .. lxmax * lymax - 1] of Integer;
     788  Damage: array [0 .. lxmax * lymax - 1] of Integer;
     789  MountainDelay, Resistant: Boolean;
    790790  // tt,tt0: int64;
    791791begin
    792792  // QueryPerformanceCounter(tt0);
    793793
    794   MaxDamage := RW[p].Un[uix].Health - 1;
    795   if MaxDamage > a.MaxHostile_MovementLeft then
    796     if a.MaxHostile_MovementLeft >= 0 then
    797       MaxDamage := a.MaxHostile_MovementLeft
     794  MaxDamage := RW[P].Un[uix].Health - 1;
     795  if MaxDamage > A.MaxHostile_MovementLeft then
     796    if A.MaxHostile_MovementLeft >= 0 then
     797      MaxDamage := A.MaxHostile_MovementLeft
    798798    else
    799799      MaxDamage := 0;
    800800
    801   Map := @(RW[p].Map^);
    802   if (a.ToLoc <> maNextCity) and ((a.ToLoc < 0) or (a.ToLoc >= MapSize)) then
    803   begin
    804     result := eInvalid;
    805     exit;
     801  Map := @(RW[P].Map^);
     802  if (A.ToLoc <> maNextCity) and ((A.ToLoc < 0) or (A.ToLoc >= MapSize)) then
     803  begin
     804    Result := eInvalid;
     805    Exit;
    806806  end;
    807   if (a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain = fUNKNOWN) then
    808   begin
    809     result := eNoWay;
    810     exit;
     807  if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain = fUNKNOWN) then
     808  begin
     809    Result := eNoWay;
     810    Exit;
    811811  end;
    812812
    813   with RW[p].Model[RW[p].Un[uix].mix] do
     813  with RW[P].Model[RW[P].Un[uix].mix] do
    814814    case Domain of
    815815      dGround:
    816         if (a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain = fOcean) then
    817         begin
    818           result := eDomainMismatch;
    819           exit;
     816        if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain = fOcean) then
     817        begin
     818          Result := eDomainMismatch;
     819          Exit;
    820820        end
    821821        else
     
    826826            MoveInfo := gmaGround_NoZoC;
    827827          if Cap[mcOver] > 0 then
    828             inc(MoveInfo, gmaOver);
     828            Inc(MoveInfo, gmaOver);
    829829          if Cap[mcAlpine] > 0 then
    830             inc(MoveInfo, gmaAlpine);
     830            Inc(MoveInfo, gmaAlpine);
    831831          HeavyCost := 50 + (Speed - 150) * 13 shr 7;
    832           if GWonder[woShinkansen].EffectiveOwner = p then
     832          if GWonder[woShinkansen].EffectiveOwner = P then
    833833            RailCost := 0
    834834          else
     
    836836          maxmov := Speed;
    837837          initmov := 0;
    838           Resistant := (GWonder[woGardens].EffectiveOwner = p) or
     838          Resistant := (GWonder[woGardens].EffectiveOwner = P) or
    839839            (Kind = mkSettler) and (Speed >= 200);
    840840        end;
    841841      dSea:
    842         if (a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain >= fGrass) and
    843           (Map[a.ToLoc] and (fCity or fUnit or fCanal) = 0) then
    844         begin
    845           result := eDomainMismatch;
    846           exit;
     842        if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain >= fGrass) and
     843          (Map[A.ToLoc] and (fCity or fUnit or fCanal) = 0) then
     844        begin
     845          Result := eDomainMismatch;
     846          Exit;
    847847        end
    848848        else
     
    850850          MoveInfo := gmaSea;
    851851          if Cap[mcNav] > 0 then
    852             inc(MoveInfo, gmaNav);
    853           maxmov := UnitSpeed(p, RW[p].Un[uix].mix, 100);
    854           initmov := maxmov - UnitSpeed(p, RW[p].Un[uix].mix,
    855             RW[p].Un[uix].Health);
     852            Inc(MoveInfo, gmaNav);
     853          maxmov := UnitSpeed(P, RW[P].Un[uix].mix, 100);
     854          initmov := maxmov - UnitSpeed(P, RW[P].Un[uix].mix,
     855            RW[P].Un[uix].Health);
    856856        end;
    857857      dAir:
     
    863863    end;
    864864
    865   FromLoc := RW[p].Un[uix].Loc;
     865  FromLoc := RW[P].Un[uix].Loc;
    866866  FillChar(Time, SizeOf(Time), 255); { -1 }
    867867  Damage[FromLoc] := 0;
    868868  Q := TIPQ.Create(MapSize);
    869   Q.Put(FromLoc, (maxmov - RW[p].Un[uix].Movement) shl 8);
     869  Q.Put(FromLoc, (maxmov - RW[P].Un[uix].Movement) shl 8);
    870870  while Q.Get(Loc, T) do
    871871  begin
    872872    Time[Loc] := T;
    873     if T >= (a.MoreTurns + 1) shl 20 then
     873    if T >= (A.MoreTurns + 1) shl 20 then
    874874    begin
    875875      Loc := -1;
     
    877877    end;
    878878    FromTile := Map[Loc];
    879     if (Loc = a.ToLoc) or (a.ToLoc = maNextCity) and (FromTile and fCity <> 0)
     879    if (Loc = A.ToLoc) or (A.ToLoc = maNextCity) and (FromTile and fCity <> 0)
    880880    then
    881881      Break;
    882882    if T and $FFF00 = $FFF00 then
    883       inc(T, $100000); // indicates mountain delay
     883      Inc(T, $100000); // indicates mountain delay
    884884    V8_to_Loc(Loc, Adjacent);
    885885    for V8 := 0 to 7 do
     
    889889      begin
    890890        ToTile := Map[Loc1];
    891         if (Loc1 = a.ToLoc) and (ToTile and (fUnit or fOwned) = fUnit) and
     891        if (Loc1 = A.ToLoc) and (ToTile and (fUnit or fOwned) = fUnit) and
    892892          not((MoveInfo and 3 = gmaSea) and (FromTile and fTerrain >= fGrass))
    893893          and not((MoveInfo and 3 = gmaAir) and ((FromTile and fCity <> 0) or
     
    898898        end
    899899        else if (ToTile and fTerrain <> fUNKNOWN) and
    900           ((Loc1 = a.ToLoc) or (ToTile and (fCity or fOwned) <> fCity))
     900          ((Loc1 = A.ToLoc) or (ToTile and (fCity or fOwned) <> fCity))
    901901        // don't move through enemy cities
    902           and ((Loc1 = a.ToLoc) or (ToTile and (fUnit or fOwned) <> fUnit))
     902          and ((Loc1 = A.ToLoc) or (ToTile and (fUnit or fOwned) <> fUnit))
    903903        // way is blocked
    904904          and (ToTile and not FromTile and fPeace = 0) and
     
    910910          // calculate move cost, must be identic to GetMoveCost function
    911911          AddDamage := 0;
    912           MountainDelay := false;
     912          MountainDelay := False;
    913913          case MoveInfo of
    914914
     
    956956                    begin
    957957                      MoveCost := maxmov;
    958                       MountainDelay := true;
     958                      MountainDelay := True;
    959959                    end;
    960960                end;
     
    990990          if (MoveCost > 0) and not MountainDelay then
    991991            if V8 and 1 <> 0 then
    992               inc(MoveCost, MoveCost * 2)
     992              Inc(MoveCost, MoveCost * 2)
    993993            else
    994               inc(MoveCost, MoveCost);
     994              Inc(MoveCost, MoveCost);
    995995
    996996          if (MoveInfo and 2 <> 0) // ground unit, check transport load/unload
     
    10111011                if FromTile and (fTerrain or fCity or fRiver or fCanal or
    10121012                  fSpecial1 { Oasis } ) = fDesert then
    1013                   inc(AddDamage, (DesertThurst * (maxmov - T shr 8 and $FFF) -
     1013                  Inc(AddDamage, (DesertThurst * (maxmov - T shr 8 and $FFF) -
    10141014                    1) div maxmov + 1)
    10151015                else if FromTile and (fTerrain or fCity or fRiver or fCanal) = fArctic
    10161016                then
    1017                   inc(AddDamage, (ArcticThurst * (maxmov - T shr 8 and $FFF) -
     1017                  Inc(AddDamage, (ArcticThurst * (maxmov - T shr 8 and $FFF) -
    10181018                    1) div maxmov + 1);
    10191019
     
    10371037  end;
    10381038  FreeAndNil(Q);
    1039   if (Loc = a.ToLoc) or (a.ToLoc = maNextCity) and (Loc >= 0) and
     1039  if (Loc = A.ToLoc) or (A.ToLoc = maNextCity) and (Loc >= 0) and
    10401040    (Map[Loc] and fCity <> 0) then
    10411041  begin
    1042     a.MoreTurns := T shr 20;
     1042    A.MoreTurns := T shr 20;
    10431043    EndLoc := Loc;
    1044     a.nStep := 0;
     1044    A.nStep := 0;
    10451045    while Loc <> FromLoc do
    10461046    begin
    10471047      if Time[Loc] < $100000 then
    1048         inc(a.nStep);
     1048        Inc(A.nStep);
    10491049      Loc := From[Loc];
    10501050    end;
    10511051    Loc := EndLoc;
    1052     i := a.nStep;
     1052    I := A.nStep;
    10531053    while Loc <> FromLoc do
    10541054    begin
    10551055      if Time[Loc] < $100000 then
    10561056      begin
    1057         dec(i);
    1058         if i < 25 then
    1059         begin
    1060           a.dx[i] := ((Loc mod lx * 2 + Loc div lx and 1) -
     1057        Dec(I);
     1058        if I < 25 then
     1059        begin
     1060          A.dx[I] := ((Loc mod lx * 2 + Loc div lx and 1) -
    10611061            (From[Loc] mod lx * 2 + From[Loc] div lx and 1) + 3 * lx)
    10621062            mod (2 * lx) - lx;
    1063           a.dy[i] := Loc div lx - From[Loc] div lx;
     1063          A.dy[I] := Loc div lx - From[Loc] div lx;
    10641064        end
    10651065      end;
    10661066      Loc := From[Loc];
    10671067    end;
    1068     a.MaxHostile_MovementLeft := maxmov - Time[EndLoc] shr 8 and $FFF;
    1069     if a.nStep > 25 then
    1070       a.nStep := 25;
    1071     result := eOK
     1068    A.MaxHostile_MovementLeft := maxmov - Time[EndLoc] shr 8 and $FFF;
     1069    if A.nStep > 25 then
     1070      A.nStep := 25;
     1071    Result := eOK
    10721072  end
    10731073  else
    1074     result := eNoWay;
     1074    Result := eNoWay;
    10751075
    10761076  // QueryPerformanceCounter(tt);{time in s is: (tt-tt0)/PerfFreq}
    10771077end;
    10781078
    1079 function CanPlaneReturn(p, uix: integer;
    1080   PlaneReturnData: TPlaneReturnData): boolean;
     1079function CanPlaneReturn(P, uix: Integer;
     1080  PlaneReturnData: TPlaneReturnData): Boolean;
    10811081const
    10821082  mfEnd = 1;
    10831083  mfReached = 2;
    10841084var
    1085   uix1, T, T1, Loc, Loc1, FromTile, ToTile, V8, MoveCost, maxmov: integer;
     1085  uix1, T, T1, Loc, Loc1, FromTile, ToTile, V8, MoveCost, maxmov: Integer;
    10861086  Map: ^TTileList;
    10871087  Q: TIPQ;
    10881088  Adjacent: TVicinity8Loc;
    1089   MapFlags: array [0 .. lxmax * lymax - 1] of byte;
    1090 begin
    1091   Map := @(RW[p].Map^);
     1089  MapFlags: array [0 .. lxmax * lymax - 1] of Byte;
     1090begin
     1091  Map := @(RW[P].Map^);
    10921092
    10931093  // calculate possible return points
    10941094  FillChar(MapFlags, SizeOf(MapFlags), 0);
    1095   if RW[p].Model[RW[p].Un[uix].mix].Kind = mkSpecial_Glider then
     1095  if RW[P].Model[RW[P].Un[uix].mix].Kind = mkSpecial_Glider then
    10961096  begin
    10971097    for Loc := 0 to MapSize - 1 do
     
    11061106        (Map[Loc] and (fUnit or fOwned) <> fUnit) then
    11071107        MapFlags[Loc] := MapFlags[Loc] or mfEnd;
    1108     if RW[p].Model[RW[p].Un[uix].mix].Cap[mcAirTrans] = 0 then
     1108    if RW[P].Model[RW[P].Un[uix].mix].Cap[mcAirTrans] = 0 then
    11091109    // plane can land on carriers
    1110       for uix1 := 0 to RW[p].nUn - 1 do
    1111         with RW[p].Un[uix1], RW[p].Model[mix] do
     1110      for uix1 := 0 to RW[P].nUn - 1 do
     1111        with RW[P].Un[uix1], RW[P].Model[mix] do
    11121112          if AirLoad < MTrans * Cap[mcCarrier] then
    11131113            MapFlags[Loc] := MapFlags[Loc] or mfEnd;
    11141114  end;
    11151115
    1116   with RW[p].Un[uix] do
     1116  with RW[P].Un[uix] do
    11171117  begin
    11181118    if Master >= 0 then // can return to same carrier, even if full now
    11191119      MapFlags[Loc] := MapFlags[Loc] or mfEnd;
    1120     maxmov := RW[p].Model[mix].Speed;
     1120    maxmov := RW[P].Model[mix].Speed;
    11211121  end;
    11221122
    1123   result := false;
     1123  Result := False;
    11241124  Q := TIPQ.Create(MapSize);
    11251125  Q.Put(PlaneReturnData.Loc, (maxmov - PlaneReturnData.Movement) shl 8);
     
    11291129    if T >= (PlaneReturnData.Fuel + 1) shl 20 then
    11301130    begin
    1131       result := false;
     1131      Result := False;
    11321132      Break;
    11331133    end;
    11341134    if MapFlags[Loc] and mfEnd <> 0 then
    11351135    begin
    1136       result := true;
     1136      Result := True;
    11371137      Break;
    11381138    end;
     
    11731173  ____________________________________________________________________
    11741174}
    1175 function CalculateJobWork(p, Loc, Job: integer; var JobWork: integer): integer;
    1176 var
    1177   TerrType: integer;
    1178 begin
    1179   result := eOK;
     1175function CalculateJobWork(P, Loc, Job: Integer; var JobWork: Integer): Integer;
     1176var
     1177  TerrType: Integer;
     1178begin
     1179  Result := eOK;
    11801180  TerrType := RealMap[Loc] and fTerrain;
    11811181  with Terrain[TerrType] do
     
    11831183      jCity:
    11841184        if RealMap[Loc] and fCity <> 0 then
    1185           result := eInvalid
     1185          Result := eInvalid
    11861186        else if IrrEff = 0 then
    1187           result := eNoCityTerrain
     1187          Result := eNoCityTerrain
    11881188        else
    11891189          JobWork := CityWork;
     
    11931193          JobWork := MoveCost * RoadWork;
    11941194          if RealMap[Loc] and fRiver <> 0 then
    1195             if RW[p].Tech[adBridgeBuilding] >= tsApplicable then
    1196               inc(JobWork, RoadBridgeWork) { across river }
     1195            if RW[P].Tech[adBridgeBuilding] >= tsApplicable then
     1196              Inc(JobWork, RoadBridgeWork) { across river }
    11971197            else
    1198               result := eNoBridgeBuilding;
     1198              Result := eNoBridgeBuilding;
    11991199        end
    12001200        else
    1201           result := eInvalid;
     1201          Result := eInvalid;
    12021202      jRR:
    12031203        if RealMap[Loc] and fRoad = 0 then
    1204           result := eNoPreq
     1204          Result := eNoPreq
    12051205        else if RealMap[Loc] and fRR <> 0 then
    1206           result := eInvalid
     1206          Result := eInvalid
    12071207        else
    12081208        begin
    12091209          JobWork := MoveCost * RRWork;
    12101210          if RealMap[Loc] and fRiver <> 0 then
    1211             inc(JobWork, RRBridgeWork); { across river }
     1211            Inc(JobWork, RRBridgeWork); { across river }
    12121212        end;
    12131213      jClear:
    1214         if (TerrType = fDesert) and (GWonder[woGardens].EffectiveOwner <> p)
     1214        if (TerrType = fDesert) and (GWonder[woGardens].EffectiveOwner <> P)
    12151215        then
    1216           result := eInvalid
     1216          Result := eInvalid
    12171217        else if ClearTerrain >= 0 then
    12181218          JobWork := IrrClearWork
    12191219        else
    1220           result := eInvalid;
     1220          Result := eInvalid;
    12211221      jIrr:
    12221222        begin
     
    12241224          if (IrrEff = 0) or (RealMap[Loc] and fTerImp = tiIrrigation) or
    12251225            (RealMap[Loc] and fTerImp = tiFarm) then
    1226             result := eInvalid;
     1226            Result := eInvalid;
    12271227        end;
    12281228      jFarm:
    12291229        if RealMap[Loc] and fTerImp <> tiIrrigation then
    1230           result := eNoPreq
     1230          Result := eNoPreq
    12311231        else
    12321232        begin
    12331233          JobWork := IrrClearWork * FarmWork;
    12341234          if (JobWork <= 0) or (RealMap[Loc] and fTerImp = tiFarm) then
    1235             result := eInvalid;
     1235            Result := eInvalid;
    12361236        end;
    12371237      jAfforest:
     
    12391239          JobWork := MineAfforestWork
    12401240        else
    1241           result := eInvalid;
     1241          Result := eInvalid;
    12421242      jMine:
    12431243        begin
    12441244          JobWork := MineAfforestWork;
    12451245          if (MineEff = 0) or (RealMap[Loc] and fTerImp = tiMine) then
    1246             result := eInvalid;
     1246            Result := eInvalid;
    12471247        end;
    12481248      jFort:
     
    12501250          JobWork := MoveCost * FortWork
    12511251        else
    1252           result := eInvalid;
     1252          Result := eInvalid;
    12531253      jCanal:
    12541254        if (RealMap[Loc] and fCanal = 0) and (TerrType in TerrType_Canalable)
     
    12561256          JobWork := CanalWork
    12571257        else
    1258           result := eInvalid;
     1258          Result := eInvalid;
    12591259      jTrans:
    12601260        begin
    12611261          JobWork := TransWork;
    12621262          if JobWork <= 0 then
    1263             result := eInvalid;
     1263            Result := eInvalid;
    12641264        end;
    12651265      jPoll:
     
    12671267          JobWork := PollWork
    12681268        else
    1269           result := eInvalid;
     1269          Result := eInvalid;
    12701270      jBase:
    12711271        if RealMap[Loc] and fTerImp <> tiBase then
    12721272          JobWork := MoveCost * BaseWork
    12731273        else
    1274           result := eInvalid;
     1274          Result := eInvalid;
    12751275      jPillage:
    12761276        if RealMap[Loc] and (fRoad or fRR or fCanal or fTerImp) <> 0 then
    12771277          JobWork := PillageWork
    12781278        else
    1279           result := eInvalid;
    1280     end;
    1281 end;
    1282 
    1283 function StartJob(p, uix, NewJob: integer; TestOnly: boolean): integer;
    1284 var
    1285   JobWork, Loc0, p1, uix1, TerrType: integer;
    1286 begin
    1287 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
    1288   result := eOK;
    1289   with RW[p].Un[uix] do
     1279          Result := eInvalid;
     1280    end;
     1281end;
     1282
     1283function StartJob(P, uix, NewJob: Integer; TestOnly: Boolean): Integer;
     1284var
     1285  JobWork, Loc0, p1, uix1, TerrType: Integer;
     1286begin
     1287{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
     1288  Result := eOK;
     1289  with RW[P].Un[uix] do
    12901290  begin
    12911291    if NewJob = Job then
    12921292    begin
    1293       result := eNotChanged;
    1294       exit;
     1293      Result := eNotChanged;
     1294      Exit;
    12951295    end;
    12961296    if NewJob = jNone then
     
    12981298      if not TestOnly then
    12991299        Job := jNone;
    1300       exit;
     1300      Exit;
    13011301    end;
    13021302    Loc0 := Loc;
     
    13041304      (NewJob <> jRR) then
    13051305    begin
    1306       result := eDeadLands;
    1307       exit;
     1306      Result := eDeadLands;
     1307      Exit;
    13081308    end;
    13091309    TerrType := RealMap[Loc0] and fTerrain;
    13101310    if (RealMap[Loc0] and fCity <> 0) or (TerrType < fGrass) or (Master >= 0) or
    1311       not((NewJob = jPillage) and (RW[p].Model[mix].Domain = dGround) or
    1312       (RW[p].Model[mix].Kind = mkSettler) or (NewJob <> jCity) and
    1313       (RW[p].Model[mix].Kind = mkSlaves) and (GWonder[woPyramids].EffectiveOwner
     1311      not((NewJob = jPillage) and (RW[P].Model[mix].Domain = dGround) or
     1312      (RW[P].Model[mix].Kind = mkSettler) or (NewJob <> jCity) and
     1313      (RW[P].Model[mix].Kind = mkSlaves) and (GWonder[woPyramids].EffectiveOwner
    13141314      >= 0)) then
    13151315    begin
    1316       result := eInvalid;
    1317       exit;
     1316      Result := eInvalid;
     1317      Exit;
    13181318    end;
    13191319    if (JobPreq[NewJob] <> preNone) and
    1320       (RW[p].Tech[JobPreq[NewJob]] < tsApplicable) then
    1321     begin
    1322       result := eNoPreq;
    1323       exit;
    1324     end;
    1325 
    1326     result := CalculateJobWork(p, Loc0, NewJob, JobWork);
    1327     if (Mode = moPlaying) and (result = eOK) and (NewJob <> jPoll) then
     1320      (RW[P].Tech[JobPreq[NewJob]] < tsApplicable) then
     1321    begin
     1322      Result := eNoPreq;
     1323      Exit;
     1324    end;
     1325
     1326    Result := CalculateJobWork(P, Loc0, NewJob, JobWork);
     1327    if (Mode = moPlaying) and (Result = eOK) and (NewJob <> jPoll) then
    13281328    begin // not allowed in territory of friendly nation
    13291329      p1 := RealMap[Loc0] shr 27; // owner of territory
    1330       if (p1 < nPl) and (p1 <> p) and (RW[p].Treaty[p1] >= trPeace) then
    1331         result := eTreaty; // keep peace treaty!
    1332     end;
    1333     if TestOnly or (result < rExecuted) then
    1334       exit;
     1330      if (p1 < nPl) and (p1 <> P) and (RW[P].Treaty[p1] >= trPeace) then
     1331        Result := eTreaty; // keep peace treaty!
     1332    end;
     1333    if TestOnly or (Result < rExecuted) then
     1334      Exit;
    13351335
    13361336    if (ToWork[Loc0, NewJob] = 0) or (ToWork[Loc0, NewJob] > JobWork) then
     
    13381338    Job := NewJob;
    13391339    Flags := Flags and not unFortified;
    1340     for uix1 := 0 to RW[p].nUn - 1 do
    1341       if (RW[p].Un[uix1].Loc = Loc) and
    1342         (RW[p].Un[uix1].Job in ContraJobs[NewJob]) then
    1343         RW[p].Un[uix1].Job := jNone; // stop contradictive jobs
    1344     if ServerVersion[p] < $000EF0 then
    1345       if Work(p, uix) then
    1346         result := eJobDone;
    1347     if (NewJob = jCity) and (result = eJobDone) then
    1348     begin
    1349       RemoveUnit_UpdateMap(p, uix);
    1350       result := eCity;
     1340    for uix1 := 0 to RW[P].nUn - 1 do
     1341      if (RW[P].Un[uix1].Loc = Loc) and
     1342        (RW[P].Un[uix1].Job in ContraJobs[NewJob]) then
     1343        RW[P].Un[uix1].Job := jNone; // stop contradictive jobs
     1344    if ServerVersion[P] < $000EF0 then
     1345      if Work(P, uix) then
     1346        Result := eJobDone;
     1347    if (NewJob = jCity) and (Result = eJobDone) then
     1348    begin
     1349      RemoveUnit_UpdateMap(P, uix);
     1350      Result := eCity;
    13511351    end
    13521352    else if Health <= 0 then
    13531353    begin // victim of HostileDamage
    1354       RemoveUnit_UpdateMap(p, uix);
    1355       result := result or rUnitRemoved;
     1354      RemoveUnit_UpdateMap(P, uix);
     1355      Result := Result or rUnitRemoved;
    13561356    end;
    13571357    if Mode > moLoading_Fast then
    13581358    begin
    1359       if result = eCity then
    1360       begin
    1361         ObserveLevel[Loc0] := ObserveLevel[Loc0] and not(3 shl (2 * p));
    1362         Discover21(Loc0, p, lObserveUnhidden, true, true);
     1359      if Result = eCity then
     1360      begin
     1361        ObserveLevel[Loc0] := ObserveLevel[Loc0] and not(3 shl (2 * P));
     1362        Discover21(Loc0, P, lObserveUnhidden, True, True);
    13631363        // CheckContact;
    13641364      end;
     
    13671367end;
    13681368
    1369 function Work(p, uix: integer): boolean;
    1370 var
    1371   uix1, j0: integer;
    1372 begin
    1373   result := false;
    1374   with RW[p].Un[uix] do
     1369function Work(P, uix: Integer): Boolean;
     1370var
     1371  uix1, j0: Integer;
     1372begin
     1373  Result := False;
     1374  with RW[P].Un[uix] do
    13751375    if Movement >= 100 then
    13761376    begin
    1377       assert(ToWork[Loc, Job] < $FFFF); // should have been set by StartJob
     1377      Assert(ToWork[Loc, Job] < $FFFF); // should have been set by StartJob
    13781378      if Job >= jRoad then
    1379         if integer(Movement) >= integer(ToWork[Loc, Job]) then { work complete }
    1380         begin
    1381           result := true;
     1379        if Integer(Movement) >= Integer(ToWork[Loc, Job]) then { work complete }
     1380        begin
     1381          Result := True;
    13821382          if Job <> jIrr then
    1383             Health := Health - HostileDamage(p, mix, Loc, ToWork[Loc, Job]);
    1384           dec(Movement, ToWork[Loc, Job]);
     1383            Health := Health - HostileDamage(P, mix, Loc, ToWork[Loc, Job]);
     1384          Dec(Movement, ToWork[Loc, Job]);
    13851385          if not(Job in [jCity, jPillage, jPoll]) then
    1386             inc(Worked[p], ToWork[Loc, Job]);
     1386            Inc(Worked[P], ToWork[Loc, Job]);
    13871387          if Job = jCity then
    13881388          begin // found new city
    1389             FoundCity(p, Loc);
    1390             inc(Founded[p]);
    1391             with RW[p].City[RW[p].nCity - 1] do
     1389            FoundCity(P, Loc);
     1390            Inc(Founded[P]);
     1391            with RW[P].City[RW[P].nCity - 1] do
    13921392            begin
    1393               ID := p shl 12 + Founded[p] - 1;
     1393              ID := P shl 12 + Founded[P] - 1;
    13941394              Flags := chFounded;
    13951395            end;
    13961396            if Mode = moPlaying then
    13971397            begin
    1398               LogCheckBorders(p, RW[p].nCity - 1);
    1399               RecalcPeaceMap(p);
     1398              LogCheckBorders(P, RW[P].nCity - 1);
     1399              RecalcPeaceMap(P);
    14001400            end;
    14011401{$IFOPT O-} if Mode < moPlaying then
    1402               InvalidTreatyMap := not(1 shl p); {$ENDIF}
     1402              InvalidTreatyMap := not(1 shl P); {$ENDIF}
    14031403            // territory should not be considered for the rest of the command
    14041404            // execution, because during loading a game it's incorrect before
    14051405            // subsequent sIntExpandTerritory is processed
    1406             RW[p].Un[uix].Health := 0; // causes unit to be removed later
     1406            RW[P].Un[uix].Health := 0; // causes unit to be removed later
    14071407          end
    14081408          else
    1409             CompleteJob(p, Loc, Job);
     1409            CompleteJob(P, Loc, Job);
    14101410          ToWork[Loc, Job] := 0;
    14111411          j0 := Job;
    1412           for uix1 := 0 to RW[p].nUn - 1 do
    1413             if (RW[p].Un[uix1].Loc = Loc) and (RW[p].Un[uix1].Job = j0) then
    1414               RW[p].Un[uix1].Job := jNone
     1412          for uix1 := 0 to RW[P].nUn - 1 do
     1413            if (RW[P].Un[uix1].Loc = Loc) and (RW[P].Un[uix1].Job = j0) then
     1414              RW[P].Un[uix1].Job := jNone
    14151415        end
    14161416        else
    14171417        begin
    1418           dec(ToWork[Loc, Job], Movement);
     1418          Dec(ToWork[Loc, Job], Movement);
    14191419          if not(Job in [jCity, jPillage, jPoll]) then
    1420             inc(Worked[p], Movement);
    1421           Health := Health - HostileDamage(p, mix, Loc, Movement);
     1420            Inc(Worked[P], Movement);
     1421          Health := Health - HostileDamage(P, mix, Loc, Movement);
    14221422          Movement := 0;
    14231423        end
     
    14251425end;
    14261426
    1427 function GetJobProgress(p, Loc: integer;
    1428   var JobProgressData: TJobProgressData): integer;
    1429 var
    1430   Job, JobResult, uix: integer;
     1427function GetJobProgress(P, Loc: Integer;
     1428  var JobProgressData: TJobProgressData): Integer;
     1429var
     1430  Job, JobResult, uix: Integer;
    14311431begin
    14321432  for Job := 0 to nJob - 1 do
    14331433  begin
    1434     JobResult := CalculateJobWork(p, Loc, Job, JobProgressData[Job].Required);
     1434    JobResult := CalculateJobWork(P, Loc, Job, JobProgressData[Job].Required);
    14351435    if JobResult = eOK then
    14361436    begin
     
    14481448    JobProgressData[Job].NextTurnPlus := 0;
    14491449  end;
    1450   for uix := 0 to RW[p].nUn - 1 do
    1451     if (RW[p].Un[uix].Loc = Loc) and (RW[p].Un[uix].Movement >= 100) then
    1452       inc(JobProgressData[RW[p].Un[uix].Job].NextTurnPlus,
    1453         RW[p].Un[uix].Movement);
    1454   result := eOK;
     1450  for uix := 0 to RW[P].nUn - 1 do
     1451    if (RW[P].Un[uix].Loc = Loc) and (RW[P].Un[uix].Movement >= 100) then
     1452      Inc(JobProgressData[RW[P].Un[uix].Job].NextTurnPlus,
     1453        RW[P].Un[uix].Movement);
     1454  Result := eOK;
    14551455end;
    14561456
Note: See TracChangeset for help on using the changeset viewer.