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/LocalPlayer/ClientTools.pas

    r442 r447  
    99const
    1010  nOfferedResourceWeights = 6;
    11   OfferedResourceWeights: array [0 .. nOfferedResourceWeights - 1] of cardinal =
     11  OfferedResourceWeights: array [0 .. nOfferedResourceWeights - 1] of Cardinal =
    1212    (rwOff, rwMaxScience, rwForceScience, rwMaxGrowth, rwForceProd, rwMaxProd);
    1313
    1414type
    15   TImpOrder = array [0 .. (nImp + 4) div 4 * 4 - 1] of shortint;
    16   TEnhancementJobs = array [0 .. 11, 0 .. 7] of byte;
     15  TImpOrder = array [0 .. (nImp + 4) div 4 * 4 - 1] of ShortInt;
     16  TEnhancementJobs = array [0 .. 11, 0 .. 7] of Byte;
    1717  JobResultSet = set of 0 .. 39;
    1818
     
    3636  Server: TServerCall;
    3737  G: TNewGameData;
    38   me: integer;
     38  Me: Integer;
    3939  MyRO: ^TPlayerContext;
    4040  MyMap: ^TTileList;
     
    4343  MyModel: ^TModelList;
    4444
    45   AdvValue: array [0 .. nAdv - 1] of integer;
    46 
    47 function dLoc(Loc, dx, dy: integer): integer;
    48 function Distance(Loc0, Loc1: integer): integer;
    49 function UnrestAtLoc(uix, Loc: integer): boolean;
    50 function GetMoveAdvice(uix, ToLoc: integer;
    51   var MoveAdviceData: TMoveAdviceData): integer;
    52 function ColorOfHealth(Health: integer): integer;
    53 function IsMultiPlayerGame: boolean;
    54 procedure ItsMeAgain(p: integer);
    55 function GetAge(p: integer): integer;
    56 function IsCivilReportNew(Enemy: integer): boolean;
    57 function IsMilReportNew(Enemy: integer): boolean;
    58 function CutCityFoodSurplus(FoodSurplus: integer; IsCityAlive: boolean;
    59   gov, size: integer): integer;
    60 function CityTaxBalance(cix: integer; const CityReport: TCityReportNew): integer;
    61 procedure SumCities(var TaxSum, ScienceSum: integer);
    62 function JobTest(uix, Job: integer; IgnoreResults: JobResultSet = []): boolean;
    63 procedure GetUnitInfo(Loc: integer; var uix: integer; var UnitInfo: TUnitInfo);
    64 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);
    65 function UnitExhausted(uix: integer): boolean;
    66 function ModelHash(const ModelInfo: TModelInfo): integer;
    67 function ProcessEnhancement(uix: integer; const Jobs: TEnhancementJobs): integer;
    68 function AutoBuild(cix: integer; const ImpOrder: TImpOrder): boolean;
    69 procedure DebugMessage(Level: integer; Text: string);
     45  AdvValue: array [0 .. nAdv - 1] of Integer;
     46
     47function dLoc(Loc, dx, dy: Integer): Integer;
     48function Distance(Loc0, Loc1: Integer): Integer;
     49function UnrestAtLoc(uix, Loc: Integer): Boolean;
     50function GetMoveAdvice(uix, ToLoc: Integer;
     51  var MoveAdviceData: TMoveAdviceData): Integer;
     52function ColorOfHealth(Health: Integer): Integer;
     53function IsMultiPlayerGame: Boolean;
     54procedure ItsMeAgain(P: Integer);
     55function GetAge(P: Integer): Integer;
     56function IsCivilReportNew(Enemy: Integer): Boolean;
     57function IsMilReportNew(Enemy: Integer): Boolean;
     58function CutCityFoodSurplus(FoodSurplus: Integer; IsCityAlive: Boolean;
     59  gov, size: Integer): Integer;
     60function CityTaxBalance(cix: Integer; const CityReport: TCityReportNew): Integer;
     61procedure SumCities(var TaxSum, ScienceSum: Integer);
     62function JobTest(uix, Job: Integer; IgnoreResults: JobResultSet = []): Boolean;
     63procedure GetUnitInfo(Loc: Integer; var uix: Integer; var UnitInfo: TUnitInfo);
     64procedure GetCityInfo(Loc: Integer; var cix: Integer; var CityInfo: TCityInfo);
     65function UnitExhausted(uix: Integer): Boolean;
     66function ModelHash(const ModelInfo: TModelInfo): Integer;
     67function ProcessEnhancement(uix: Integer; const Jobs: TEnhancementJobs): Integer;
     68function AutoBuild(cix: Integer; const ImpOrder: TImpOrder): Boolean;
     69procedure DebugMessage(Level: Integer; Text: string);
    7070procedure CityOptimizer_BeginOfTurn;
    71 procedure CityOptimizer_CityChange(cix: integer);
    72 procedure CityOptimizer_TileBecomesAvailable(Loc: integer);
    73 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: integer);
    74 procedure CityOptimizer_BeforeRemoveUnit(uix: integer);
     71procedure CityOptimizer_CityChange(cix: Integer);
     72procedure CityOptimizer_TileBecomesAvailable(Loc: Integer);
     73procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: Integer);
     74procedure CityOptimizer_BeforeRemoveUnit(uix: Integer);
    7575procedure CityOptimizer_AfterRemoveUnit;
    7676procedure CityOptimizer_EndOfTurn;
     
    8484
    8585var
    86   CityNeedsOptimize: array [0 .. ncmax - 1] of boolean;
    87 
    88 function dLoc(Loc, dx, dy: integer): integer;
    89 var
    90   y0: integer;
     86  CityNeedsOptimize: array [0 .. ncmax - 1] of Boolean;
     87
     88function dLoc(Loc, dx, dy: Integer): Integer;
     89var
     90  y0: Integer;
    9191begin
    9292  y0 := (Loc + G.lx * 1024) div G.lx - 1024;
     
    9494end;
    9595
    96 function Distance(Loc0, Loc1: integer): integer;
    97 var
    98   dx, dy: integer;
     96function Distance(Loc0, Loc1: Integer): Integer;
     97var
     98  dx, dy: Integer;
    9999begin
    100100  Inc(Loc0, G.lx * 1024);
     
    106106end;
    107107
    108 function UnrestAtLoc(uix, Loc: integer): boolean;
    109 var
    110   uix1: integer;
     108function UnrestAtLoc(uix, Loc: Integer): Boolean;
     109var
     110  uix1: Integer;
    111111begin
    112112  Result := False;
     
    114114    case MyRO.Government of
    115115      gRepublic, gFuture:
    116         Result := (MyRO.Territory[Loc] >= 0) and (MyRO.Territory[Loc] <> me) and
     116        Result := (MyRO.Territory[Loc] >= 0) and (MyRO.Territory[Loc] <> Me) and
    117117          (MyRO.Treaty[MyRO.Territory[Loc]] < trAlliance);
    118118      gDemocracy:
    119         Result := (MyRO.Territory[Loc] < 0) or (MyRO.Territory[Loc] <> me) and
     119        Result := (MyRO.Territory[Loc] < 0) or (MyRO.Territory[Loc] <> Me) and
    120120          (MyRO.Treaty[MyRO.Territory[Loc]] < trAlliance);
    121121    end;
     
    127127end;
    128128
    129 function GetMoveAdvice(uix, ToLoc: integer;
    130   var MoveAdviceData: TMoveAdviceData): integer;
    131 var
    132   MinEndHealth: integer;
     129function GetMoveAdvice(uix, ToLoc: Integer;
     130  var MoveAdviceData: TMoveAdviceData): Integer;
     131var
     132  MinEndHealth: Integer;
    133133begin
    134134  if MyModel[MyUn[uix].mix].Domain = dGround then
     
    142142      MoveAdviceData.MoreTurns := 999;
    143143      MoveAdviceData.MaxHostile_MovementLeft := MyUn[uix].Health - MinEndHealth;
    144       Result := Server(sGetMoveAdvice, me, uix, MoveAdviceData);
     144      Result := Server(sGetMoveAdvice, Me, uix, MoveAdviceData);
    145145      if (MinEndHealth <= 1) or (Result <> eNoWay) then
    146         exit;
     146        Exit;
    147147    end;
    148148    case MinEndHealth of
     
    159159end;
    160160
    161 function ColorOfHealth(Health: integer): integer;
    162 var
    163   red, green: integer;
    164 begin
    165   green := 400 * Health div 100;
    166   if green > 200 then
    167     green := 200;
    168   red := 510 * (100 - Health) div 100;
    169   if red > 255 then
    170     red := 255;
    171   Result := green shl 8 + red;
    172 end;
    173 
    174 function IsMultiPlayerGame: boolean;
    175 var
    176   p1: integer;
     161function ColorOfHealth(Health: Integer): Integer;
     162var
     163  Red, Green: Integer;
     164begin
     165  Green := 400 * Health div 100;
     166  if Green > 200 then
     167    Green := 200;
     168  Red := 510 * (100 - Health) div 100;
     169  if Red > 255 then
     170    Red := 255;
     171  Result := Green shl 8 + Red;
     172end;
     173
     174function IsMultiPlayerGame: Boolean;
     175var
     176  p1: Integer;
    177177begin
    178178  Result := False;
     
    182182end;
    183183
    184 procedure ItsMeAgain(p: integer);
    185 begin
    186   if G.RO[p] <> nil then
    187     MyRO := pointer(G.RO[p])
    188   else if G.SuperVisorRO[p] <> nil then
    189     MyRO := pointer(G.SuperVisorRO[p])
     184procedure ItsMeAgain(P: Integer);
     185begin
     186  if G.RO[P] <> nil then
     187    MyRO := Pointer(G.RO[P])
     188  else if G.SuperVisorRO[P] <> nil then
     189    MyRO := Pointer(G.SuperVisorRO[P])
    190190  else
    191     exit;
    192   me := p;
    193   MyMap := pointer(MyRO.Map);
    194   MyUn := pointer(MyRO.Un);
    195   MyCity := pointer(MyRO.City);
    196   MyModel := pointer(MyRO.Model);
    197 end;
    198 
    199 function GetAge(p: integer): integer;
    200 var
    201   i: integer;
    202 begin
    203   if p = me then begin
     191    Exit;
     192  Me := P;
     193  MyMap := Pointer(MyRO.Map);
     194  MyUn := Pointer(MyRO.Un);
     195  MyCity := Pointer(MyRO.City);
     196  MyModel := Pointer(MyRO.Model);
     197end;
     198
     199function GetAge(P: Integer): Integer;
     200var
     201  I: Integer;
     202begin
     203  if P = Me then begin
    204204    Result := 0;
    205     for i := 1 to 3 do
    206       if MyRO.Tech[AgePreq[i]] >= tsApplicable then
    207         Result := i;
     205    for I := 1 to 3 do
     206      if MyRO.Tech[AgePreq[I]] >= tsApplicable then
     207        Result := I;
    208208  end else begin
    209209    Result := 0;
    210     for i := 1 to 3 do
    211       if MyRO.EnemyReport[p].Tech[AgePreq[i]] >= tsApplicable then
    212         Result := i;
    213   end;
    214 end;
    215 
    216 function IsCivilReportNew(Enemy: integer): boolean;
    217 var
    218   i: integer;
    219 begin
    220   assert(Enemy <> me);
    221   i := MyRO.EnemyReport[Enemy].TurnOfCivilReport;
    222   Result := (i = MyRO.Turn) or (i = MyRO.Turn - 1) and (Enemy > me);
    223 end;
    224 
    225 function IsMilReportNew(Enemy: integer): boolean;
    226 var
    227   i: integer;
    228 begin
    229   assert(Enemy <> me);
    230   i := MyRO.EnemyReport[Enemy].TurnOfMilReport;
    231   Result := (i = MyRO.Turn) or (i = MyRO.Turn - 1) and (Enemy > me);
    232 end;
    233 
    234 function CutCityFoodSurplus(FoodSurplus: integer; IsCityAlive: boolean;
    235   gov, size: integer): integer;
     210    for I := 1 to 3 do
     211      if MyRO.EnemyReport[P].Tech[AgePreq[I]] >= tsApplicable then
     212        Result := I;
     213  end;
     214end;
     215
     216function IsCivilReportNew(Enemy: Integer): Boolean;
     217var
     218  I: Integer;
     219begin
     220  Assert(Enemy <> Me);
     221  I := MyRO.EnemyReport[Enemy].TurnOfCivilReport;
     222  Result := (I = MyRO.Turn) or (I = MyRO.Turn - 1) and (Enemy > Me);
     223end;
     224
     225function IsMilReportNew(Enemy: Integer): Boolean;
     226var
     227  I: Integer;
     228begin
     229  Assert(Enemy <> Me);
     230  I := MyRO.EnemyReport[Enemy].TurnOfMilReport;
     231  Result := (I = MyRO.Turn) or (I = MyRO.Turn - 1) and (Enemy > Me);
     232end;
     233
     234function CutCityFoodSurplus(FoodSurplus: Integer; IsCityAlive: Boolean;
     235  gov, size: Integer): Integer;
    236236begin
    237237  Result := FoodSurplus;
     
    241241end;
    242242
    243 function CityTaxBalance(cix: integer; const CityReport: TCityReportNew): integer;
    244 var
    245   i: integer;
     243function CityTaxBalance(cix: Integer; const CityReport: TCityReportNew): Integer;
     244var
     245  I: Integer;
    246246begin
    247247  Result := 0;
     
    258258      Inc(Result, CityReport.FoodSurplus);
    259259  end;
    260   for i := nWonder to nImp - 1 do
    261     if MyCity[cix].Built[i] > 0 then
    262       Dec(Result, Imp[i].Maint);
    263 end;
    264 
    265 procedure SumCities(var TaxSum, ScienceSum: integer);
    266 var
    267   cix: integer;
     260  for I := nWonder to nImp - 1 do
     261    if MyCity[cix].Built[I] > 0 then
     262      Dec(Result, Imp[I].Maint);
     263end;
     264
     265procedure SumCities(var TaxSum, ScienceSum: Integer);
     266var
     267  cix: Integer;
    268268  CityReport: TCityReportNew;
    269269begin
     
    271271  ScienceSum := 0;
    272272  if MyRO.Government = gAnarchy then
    273     exit;
     273    Exit;
    274274  for cix := 0 to MyRO.nCity - 1 do
    275275    if MyCity[cix].Loc >= 0 then
     
    278278      CityReport.HypoTaxRate := -1;
    279279      CityReport.HypoLuxuryRate := -1;
    280       Server(sGetCityReportNew, me, cix, CityReport);
     280      Server(sGetCityReportNew, Me, cix, CityReport);
    281281      if (CityReport.HappinessBalance >= 0) { no disorder } and
    282282        (MyCity[cix].Flags and chCaptured = 0) then // not captured
     
    286286end;
    287287
    288 function JobTest(uix, Job: integer; IgnoreResults: JobResultSet): boolean;
    289 var
    290   Test: integer;
    291 begin
    292   Test := Server(sStartJob + Job shl 4 - sExecute, me, uix, nil^);
     288function JobTest(uix, Job: Integer; IgnoreResults: JobResultSet): Boolean;
     289var
     290  Test: Integer;
     291begin
     292  Test := Server(sStartJob + Job shl 4 - sExecute, Me, uix, nil^);
    293293  Result := (Test >= rExecuted) or (Test in IgnoreResults);
    294294end;
    295295
    296 procedure GetUnitInfo(Loc: integer; var uix: integer; var UnitInfo: TUnitInfo);
    297 var
    298   i, Cnt: integer;
     296procedure GetUnitInfo(Loc: Integer; var uix: Integer; var UnitInfo: TUnitInfo);
     297var
     298  I, Cnt: Integer;
    299299begin
    300300  if MyMap[Loc] and fOwned <> 0 then
    301301  begin
    302     Server(sGetDefender, me, Loc, uix);
     302    Server(sGetDefender, Me, Loc, uix);
    303303    Cnt := 0;
    304     for i := 0 to MyRO.nUn - 1 do
    305       if MyUn[i].Loc = Loc then
     304    for I := 0 to MyRO.nUn - 1 do
     305      if MyUn[I].Loc = Loc then
    306306        Inc(Cnt);
    307     MakeUnitInfo(me, MyUn[uix], UnitInfo);
     307    MakeUnitInfo(Me, MyUn[uix], UnitInfo);
    308308    if Cnt > 1 then
    309309      UnitInfo.Flags := UnitInfo.Flags or unMulti;
     
    318318end;
    319319
    320 procedure GetCityInfo(Loc: integer; var cix: integer; var CityInfo: TCityInfo);
     320procedure GetCityInfo(Loc: Integer; var cix: Integer; var CityInfo: TCityInfo);
    321321begin
    322322  if MyMap[Loc] and fOwned <> 0 then
     
    328328    with CityInfo do
    329329    begin
    330       Owner := me;
     330      Owner := Me;
    331331      ID := MyCity[cix].ID;
    332332      size := MyCity[cix].size;
     
    356356end;
    357357
    358 function UnitExhausted(uix: integer): boolean;
     358function UnitExhausted(uix: Integer): Boolean;
    359359  // check if another move of this unit is still possible
    360360var
    361   dx, dy: integer;
     361  dx, dy: Integer;
    362362begin
    363363  Result := True;
    364364  if (MyUn[uix].Movement > 0) or
    365     (MyRO.Wonder[woShinkansen].EffectiveOwner = me) then
     365    (MyRO.Wonder[woShinkansen].EffectiveOwner = Me) then
    366366    if (MyUn[uix].Movement >= 100) or
    367367      ((MyModel[MyUn[uix].mix].Kind = mkCaravan) and
     
    373373          if abs(dx) + abs(dy) = 2 then
    374374            if Server(sMoveUnit - sExecute + dx and 7 shl 4 + dy and
    375               7 shl 7, me, uix, nil^) >= rExecuted then
     375              7 shl 7, Me, uix, nil^) >= rExecuted then
    376376              Result := False;
    377377end;
    378378
    379 function ModelHash(const ModelInfo: TModelInfo): integer;
    380 var
    381   i, FeatureCode, Hash1, Hash2, Hash2r, d: cardinal;
     379function ModelHash(const ModelInfo: TModelInfo): Integer;
     380var
     381  I, FeatureCode, Hash1, Hash2, Hash2r, D: Cardinal;
    382382begin
    383383  with ModelInfo do
    384384    if Kind > mkEnemyDeveloped then
    385       Result := integer($C0000000 + Speed div 50 + Kind shl 8)
     385      Result := Integer($C0000000 + Speed div 50 + Kind shl 8)
    386386    else
    387387    begin
    388388      FeatureCode := 0;
    389       for i := mcFirstNonCap to nFeature - 1 do
    390         if 1 shl Domain and Feature[i].Domains <> 0 then
     389      for I := mcFirstNonCap to nFeature - 1 do
     390        if 1 shl Domain and Feature[I].Domains <> 0 then
    391391        begin
    392392          FeatureCode := FeatureCode * 2;
    393           if 1 shl (i - mcFirstNonCap) <> 0 then
     393          if 1 shl (I - mcFirstNonCap) <> 0 then
    394394            Inc(FeatureCode);
    395395        end;
     
    397397        dGround:
    398398        begin
    399           assert(FeatureCode < 1 shl 8);
    400           assert(Attack < 5113);
    401           assert(Defense < 2273);
    402           assert(Cost < 1611);
     399          Assert(FeatureCode < 1 shl 8);
     400          Assert(Attack < 5113);
     401          Assert(Defense < 2273);
     402          Assert(Cost < 1611);
    403403          Hash1 := (Attack * 2273 + Defense) * 9 + (Speed - 150) div 50;
    404404          Hash2 := FeatureCode * 1611 + Cost;
     
    406406        dSea:
    407407        begin
    408           assert(FeatureCode < 1 shl 9);
    409           assert(Attack < 12193);
    410           assert(Defense < 6097);
    411           assert(Cost < 4381);
     408          Assert(FeatureCode < 1 shl 9);
     409          Assert(Attack < 12193);
     410          Assert(Defense < 6097);
     411          Assert(Cost < 4381);
    412412          Hash1 := ((Attack * 6097 + Defense) * 5 +
    413413            (Speed - 350) div 100) * 2;
     
    419419        dAir:
    420420        begin
    421           assert(FeatureCode < 1 shl 5);
    422           assert(Attack < 2407);
    423           assert(Defense < 1605);
    424           assert(Bombs < 4813);
    425           assert(Cost < 2089);
     421          Assert(FeatureCode < 1 shl 5);
     422          Assert(Attack < 2407);
     423          Assert(Defense < 1605);
     424          Assert(Bombs < 4813);
     425          Assert(Cost < 2089);
    426426          Hash1 := (Attack * 1605 + Defense) shl 5 + FeatureCode;
    427427          Hash2 := ((Bombs * 7 + ATrans_Fuel) * 4 + TTrans) * 2089 + Cost;
     
    429429      end;
    430430      Hash2r := 0;
    431       for i := 0 to 7 do
     431      for I := 0 to 7 do
    432432      begin
    433433        Hash2r := Hash2r * 13;
    434         d := Hash2 div 13;
    435         Inc(Hash2r, Hash2 - d * 13);
    436         Hash2 := d;
     434        D := Hash2 div 13;
     435        Inc(Hash2r, Hash2 - D * 13);
     436        Hash2 := D;
    437437      end;
    438       Result := integer(Domain shl 30 + Hash1 xor Hash2r);
     438      Result := Integer(Domain shl 30 + Hash1 xor Hash2r);
    439439    end;
    440440end;
    441441
    442 function ProcessEnhancement(uix: integer; const Jobs: TEnhancementJobs): integer;
     442function ProcessEnhancement(uix: Integer; const Jobs: TEnhancementJobs): Integer;
    443443  { return values:
    444444    eJobDone - all applicable jobs done
     
    446446    eDied - job done and died (thurst) }
    447447var
    448   stage, NextJob, Tile: integer;
     448  stage, NextJob, Tile: Integer;
    449449  Done: set of jNone .. jPoll;
    450450begin
     
    452452  Tile := MyMap[MyUn[uix].Loc];
    453453  if Tile and fRoad <> 0 then
    454     include(Done, jRoad);
     454    Include(Done, jRoad);
    455455  if Tile and fRR <> 0 then
    456     include(Done, jRR);
     456    Include(Done, jRR);
    457457  if (Tile and fTerImp = tiIrrigation) or (Tile and fTerImp = tiFarm) then
    458     include(Done, jIrr);
     458    Include(Done, jIrr);
    459459  if Tile and fTerImp = tiFarm then
    460     include(Done, jFarm);
     460    Include(Done, jFarm);
    461461  if Tile and fTerImp = tiMine then
    462     include(Done, jMine);
     462    Include(Done, jMine);
    463463  if Tile and fPoll = 0 then
    464     include(Done, jPoll);
     464    Include(Done, jPoll);
    465465
    466466  if MyUn[uix].Job = jNone then
     
    485485      Break;
    486486    end; // tile enhancement complete
    487     Result := Server(sStartJob + NextJob shl 4, me, uix, nil^);
    488     include(Done, NextJob);
    489   end;
    490 end;
    491 
    492 function AutoBuild(cix: integer; const ImpOrder: TImpOrder): boolean;
    493 var
    494   i, NewProject: integer;
     487    Result := Server(sStartJob + NextJob shl 4, Me, uix, nil^);
     488    Include(Done, NextJob);
     489  end;
     490end;
     491
     492function AutoBuild(cix: Integer; const ImpOrder: TImpOrder): Boolean;
     493var
     494  I, NewProject: Integer;
    495495begin
    496496  Result := False;
     
    498498    (MyCity[cix].Flags and chProduction <> 0) then
    499499  begin
    500     i := 0;
     500    I := 0;
    501501    repeat
    502       while (ImpOrder[i] >= 0) and (MyCity[cix].Built[ImpOrder[i]] > 0) do
    503         Inc(i);
    504       if ImpOrder[i] < 0 then
     502      while (ImpOrder[I] >= 0) and (MyCity[cix].Built[ImpOrder[I]] > 0) do
     503        Inc(I);
     504      if ImpOrder[I] < 0 then
    505505        Break;
    506       assert(i < nImp);
    507       NewProject := cpImp + ImpOrder[i];
    508       if Server(sSetCityProject, me, cix, NewProject) >= rExecuted then
     506      Assert(I < nImp);
     507      NewProject := cpImp + ImpOrder[I];
     508      if Server(sSetCityProject, Me, cix, NewProject) >= rExecuted then
    509509      begin
    510510        Result := True;
     
    512512        Break;
    513513      end;
    514       Inc(i);
     514      Inc(I);
    515515    until False;
    516516  end;
     
    519519procedure CalculateAdvValues;
    520520var
    521   i, j: integer;
    522   known: array [0 .. nAdv - 1] of integer;
    523 
    524   procedure MarkPreqs(i: integer);
    525   begin
    526     if known[i] = 0 then
     521  I, J: Integer;
     522  known: array [0 .. nAdv - 1] of Integer;
     523
     524  procedure MarkPreqs(I: Integer);
     525  begin
     526    if known[I] = 0 then
    527527    begin
    528       known[i] := 1;
    529       if (i <> adScience) and (i <> adMassProduction) then
     528      known[I] := 1;
     529      if (I <> adScience) and (I <> adMassProduction) then
    530530      begin
    531         if (AdvPreq[i, 0] >= 0) then
    532           MarkPreqs(AdvPreq[i, 0]);
    533         if (AdvPreq[i, 1] >= 0) then
    534           MarkPreqs(AdvPreq[i, 1]);
     531        if (AdvPreq[I, 0] >= 0) then
     532          MarkPreqs(AdvPreq[I, 0]);
     533        if (AdvPreq[I, 1] >= 0) then
     534          MarkPreqs(AdvPreq[I, 1]);
    535535      end;
    536536    end;
     
    539539begin
    540540  FillChar(AdvValue, SizeOf(AdvValue), 0);
    541   for i := 0 to nAdv - 1 do
     541  for I := 0 to nAdv - 1 do
    542542  begin
    543543    FillChar(known, SizeOf(known), 0);
    544     MarkPreqs(i);
    545     for j := 0 to nAdv - 1 do
    546       if known[j] > 0 then
    547         Inc(AdvValue[i]);
    548     if i in FutureTech then
    549       Inc(AdvValue[i], 3000)
     544    MarkPreqs(I);
     545    for J := 0 to nAdv - 1 do
     546      if known[J] > 0 then
     547        Inc(AdvValue[I]);
     548    if I in FutureTech then
     549      Inc(AdvValue[I], 3000)
    550550    else if known[adMassProduction] > 0 then
    551       Inc(AdvValue[i], 2000)
     551      Inc(AdvValue[I], 2000)
    552552    else if known[adScience] > 0 then
    553       Inc(AdvValue[i], 1000);
    554   end;
    555 end;
    556 
    557 procedure DebugMessage(Level: integer; Text: string);
    558 begin
    559   Server(sMessage, me, Level, PChar(Text)^);
    560 end;
    561 
    562 function MarkCitiesAround(Loc, cixExcept: integer): boolean;
     553      Inc(AdvValue[I], 1000);
     554  end;
     555end;
     556
     557procedure DebugMessage(Level: Integer; Text: string);
     558begin
     559  Server(sMessage, Me, Level, PChar(Text)^);
     560end;
     561
     562function MarkCitiesAround(Loc, cixExcept: Integer): Boolean;
    563563  // return whether a city was marked
    564564var
    565   cix: integer;
     565  cix: Integer;
    566566begin
    567567  Result := False;
     
    576576end;
    577577
    578 procedure OptimizeCities(CheckOnly: boolean);
    579 var
    580   cix, fix, dx, dy, Loc1, OptiType: integer;
    581   Done: boolean;
     578procedure OptimizeCities(CheckOnly: Boolean);
     579var
     580  cix, fix, dx, dy, Loc1, OptiType: Integer;
     581  Done: Boolean;
    582582  Advice: TCityTileAdviceData;
    583583begin
     
    591591        begin
    592592          Advice.ResourceWeights := OfferedResourceWeights[OptiType];
    593           Server(sGetCityTileAdvice, me, cix, Advice);
     593          Server(sGetCityTileAdvice, Me, cix, Advice);
    594594          if Advice.Tiles <> MyCity[cix].Tiles then
    595595            if CheckOnly then
     
    611611                    Done := False;
    612612                end;
    613               Server(sSetCityTiles, me, cix, Advice.Tiles);
     613              Server(sSetCityTiles, Me, cix, Advice.Tiles);
    614614            end;
    615615        end;
     
    621621procedure CityOptimizer_BeginOfTurn;
    622622var
    623   cix: integer;
     623  cix: Integer;
    624624begin
    625625  FillChar(CityNeedsOptimize, MyRO.nCity - 1, 0); // false
     
    634634end;
    635635
    636 procedure CityOptimizer_CityChange(cix: integer);
     636procedure CityOptimizer_CityChange(cix: Integer);
    637637begin
    638638  if (MyRO.Government <> gAnarchy) and (cix <> -1) and (MyCity[cix].Flags and
     
    644644end;
    645645
    646 procedure CityOptimizer_TileBecomesAvailable(Loc: integer);
     646procedure CityOptimizer_TileBecomesAvailable(Loc: Integer);
    647647begin
    648648  if (MyRO.Government <> gAnarchy) and MarkCitiesAround(Loc, -1) then
     
    650650end;
    651651
    652 procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: integer);
    653 var
    654   fix, dx, dy, Loc1: integer;
    655   Done: boolean;
     652procedure CityOptimizer_ReleaseCityTiles(cix, ReleasedTiles: Integer);
     653var
     654  fix, dx, dy, Loc1: Integer;
     655  Done: Boolean;
    656656begin
    657657  if (MyRO.Government <> gAnarchy) and (ReleasedTiles <> 0) then
     
    672672end;
    673673
    674 procedure CityOptimizer_BeforeRemoveUnit(uix: integer);
    675 var
    676   uix1: integer;
     674procedure CityOptimizer_BeforeRemoveUnit(uix: Integer);
     675var
     676  uix1: Integer;
    677677begin
    678678  if MyRO.Government <> gAnarchy then
     
    698698// all cities should already be optimized here -- only check this
    699699var
    700   cix: integer;
     700  cix: Integer;
    701701begin
    702702{$IFOPT O-}
Note: See TracChangeset for help on using the changeset viewer.