Ignore:
Timestamp:
Nov 30, 2023, 10:16:14 PM (12 months ago)
Author:
chronos
Message:
  • Modified: Updated high dpi branch from trunk.
  • Modified: Use generics.collections instead of fgl.
  • Modified: Compile with Delphi syntax.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/CityProcessing.pas

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