Changeset 447 for trunk/AI/StdAI/AI.pas


Ignore:
Timestamp:
May 19, 2022, 10:39:34 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Use first capital letter in identifiers.
File:
1 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
Note: See TracChangeset for help on using the changeset viewer.