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/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;
Note: See TracChangeset for help on using the changeset viewer.