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/ToolAI.pas

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